• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.turbine.binder.bound;
18 
19 import com.google.common.collect.ImmutableList;
20 import com.google.turbine.binder.sym.ClassSymbol;
21 import com.google.turbine.type.AnnoInfo;
22 import org.jspecify.annotations.Nullable;
23 
24 /** A bound module declaration (see JLS §7.7). */
25 public class ModuleInfo {
26 
27   private final String name;
28   private final @Nullable String version;
29   private final int flags;
30   private final ImmutableList<AnnoInfo> annos;
31   private final ImmutableList<RequireInfo> requires;
32   private final ImmutableList<ExportInfo> exports;
33   private final ImmutableList<OpenInfo> opens;
34   private final ImmutableList<UseInfo> uses;
35   private final ImmutableList<ProvideInfo> provides;
36 
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)37   public ModuleInfo(
38       String name,
39       @Nullable String version,
40       int flags,
41       ImmutableList<AnnoInfo> annos,
42       ImmutableList<RequireInfo> requires,
43       ImmutableList<ExportInfo> exports,
44       ImmutableList<OpenInfo> opens,
45       ImmutableList<UseInfo> uses,
46       ImmutableList<ProvideInfo> provides) {
47     this.name = name;
48     this.version = version;
49     this.flags = flags;
50     this.annos = annos;
51     this.requires = requires;
52     this.exports = exports;
53     this.opens = opens;
54     this.uses = uses;
55     this.provides = provides;
56   }
57 
name()58   public String name() {
59     return name;
60   }
61 
version()62   public @Nullable String version() {
63     return version;
64   }
65 
flags()66   public int flags() {
67     return flags;
68   }
69 
annos()70   public ImmutableList<AnnoInfo> annos() {
71     return annos;
72   }
73 
requires()74   public ImmutableList<RequireInfo> requires() {
75     return requires;
76   }
77 
exports()78   public ImmutableList<ExportInfo> exports() {
79     return exports;
80   }
81 
opens()82   public ImmutableList<OpenInfo> opens() {
83     return opens;
84   }
85 
uses()86   public ImmutableList<UseInfo> uses() {
87     return uses;
88   }
89 
provides()90   public ImmutableList<ProvideInfo> provides() {
91     return provides;
92   }
93 
94   /** A JLS §7.7.1 requires directive. */
95   public static class RequireInfo {
96 
97     private final String moduleName;
98     private final int flags;
99     private final @Nullable String version;
100 
RequireInfo(String moduleName, int flags, @Nullable String version)101     public RequireInfo(String moduleName, int flags, @Nullable String version) {
102       this.moduleName = moduleName;
103       this.flags = flags;
104       this.version = version;
105     }
106 
moduleName()107     public String moduleName() {
108       return moduleName;
109     }
110 
flags()111     public int flags() {
112       return flags;
113     }
114 
version()115     public @Nullable String version() {
116       return version;
117     }
118   }
119 
120   /** A JLS §7.7.2 exports directive. */
121   public static class ExportInfo {
122 
123     private final String packageName;
124     private final ImmutableList<String> modules;
125 
ExportInfo(String packageName, ImmutableList<String> modules)126     public ExportInfo(String packageName, ImmutableList<String> modules) {
127       this.packageName = packageName;
128       this.modules = modules;
129     }
130 
packageName()131     public String packageName() {
132       return packageName;
133     }
134 
modules()135     public ImmutableList<String> modules() {
136       return modules;
137     }
138   }
139 
140   /** A JLS §7.7.2 opens directive. */
141   public static class OpenInfo {
142 
143     private final String packageName;
144     private final ImmutableList<String> modules;
145 
OpenInfo(String packageName, ImmutableList<String> modules)146     public OpenInfo(String packageName, ImmutableList<String> modules) {
147       this.packageName = packageName;
148       this.modules = modules;
149     }
150 
packageName()151     public String packageName() {
152       return packageName;
153     }
154 
modules()155     public ImmutableList<String> modules() {
156       return modules;
157     }
158   }
159 
160   /** A JLS §7.7.3 uses directive. */
161   public static class UseInfo {
162 
163     private final ClassSymbol sym;
164 
UseInfo(ClassSymbol sym)165     public UseInfo(ClassSymbol sym) {
166       this.sym = sym;
167     }
168 
sym()169     public ClassSymbol sym() {
170       return sym;
171     }
172   }
173 
174   /** A JLS §7.7.4 provides directive. */
175   public static class ProvideInfo {
176 
177     private final ClassSymbol sym;
178     private final ImmutableList<ClassSymbol> impls;
179 
ProvideInfo(ClassSymbol sym, ImmutableList<ClassSymbol> impls)180     public ProvideInfo(ClassSymbol sym, ImmutableList<ClassSymbol> impls) {
181       this.sym = sym;
182       this.impls = impls;
183     }
184 
sym()185     public ClassSymbol sym() {
186       return sym;
187     }
188 
impls()189     public ImmutableList<ClassSymbol> impls() {
190       return impls;
191     }
192   }
193 }
194