aboutsummaryrefslogtreecommitdiff
path: root/java/com/google/turbine/binder/bound/ModuleInfo.java
blob: f21213bda0a19eb2bcd99c9a369cb5c1e330f22e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Copyright 2018 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.turbine.binder.bound;

import com.google.common.collect.ImmutableList;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.type.AnnoInfo;
import org.checkerframework.checker.nullness.qual.Nullable;

/** A bound module declaration (see JLS §7.7). */
public class ModuleInfo {

  private final String name;
  @Nullable private final String version;
  private final int flags;
  private final ImmutableList<AnnoInfo> annos;
  private final ImmutableList<RequireInfo> requires;
  private final ImmutableList<ExportInfo> exports;
  private final ImmutableList<OpenInfo> opens;
  private final ImmutableList<UseInfo> uses;
  private final ImmutableList<ProvideInfo> provides;

  public ModuleInfo(
      String name,
      @Nullable String version,
      int flags,
      ImmutableList<AnnoInfo> annos,
      ImmutableList<RequireInfo> requires,
      ImmutableList<ExportInfo> exports,
      ImmutableList<OpenInfo> opens,
      ImmutableList<UseInfo> uses,
      ImmutableList<ProvideInfo> provides) {
    this.name = name;
    this.version = version;
    this.flags = flags;
    this.annos = annos;
    this.requires = requires;
    this.exports = exports;
    this.opens = opens;
    this.uses = uses;
    this.provides = provides;
  }

  public String name() {
    return name;
  }

  @Nullable
  public String version() {
    return version;
  }

  public int flags() {
    return flags;
  }

  public ImmutableList<AnnoInfo> annos() {
    return annos;
  }

  public ImmutableList<RequireInfo> requires() {
    return requires;
  }

  public ImmutableList<ExportInfo> exports() {
    return exports;
  }

  public ImmutableList<OpenInfo> opens() {
    return opens;
  }

  public ImmutableList<UseInfo> uses() {
    return uses;
  }

  public ImmutableList<ProvideInfo> provides() {
    return provides;
  }

  /** A JLS §7.7.1 requires directive. */
  public static class RequireInfo {

    private final String moduleName;
    private final int flags;
    private final String version;

    public RequireInfo(String moduleName, int flags, String version) {
      this.moduleName = moduleName;
      this.flags = flags;
      this.version = version;
    }

    public String moduleName() {
      return moduleName;
    }

    public int flags() {
      return flags;
    }

    public String version() {
      return version;
    }
  }

  /** A JLS §7.7.2 exports directive. */
  public static class ExportInfo {

    private final String packageName;
    private final ImmutableList<String> modules;

    public ExportInfo(String packageName, ImmutableList<String> modules) {
      this.packageName = packageName;
      this.modules = modules;
    }

    public String packageName() {
      return packageName;
    }

    public ImmutableList<String> modules() {
      return modules;
    }
  }

  /** A JLS §7.7.2 opens directive. */
  public static class OpenInfo {

    private final String packageName;
    private final ImmutableList<String> modules;

    public OpenInfo(String packageName, ImmutableList<String> modules) {
      this.packageName = packageName;
      this.modules = modules;
    }

    public String packageName() {
      return packageName;
    }

    public ImmutableList<String> modules() {
      return modules;
    }
  }

  /** A JLS §7.7.3 uses directive. */
  public static class UseInfo {

    private final ClassSymbol sym;

    public UseInfo(ClassSymbol sym) {
      this.sym = sym;
    }

    public ClassSymbol sym() {
      return sym;
    }
  }

  /** A JLS §7.7.4 provides directive. */
  public static class ProvideInfo {

    private final ClassSymbol sym;
    private final ImmutableList<ClassSymbol> impls;

    public ProvideInfo(ClassSymbol sym, ImmutableList<ClassSymbol> impls) {
      this.sym = sym;
      this.impls = impls;
    }

    public ClassSymbol sym() {
      return sym;
    }

    public ImmutableList<ClassSymbol> impls() {
      return impls;
    }
  }
}