author | ksrini |
Sat, 14 May 2016 08:03:03 -0700 | |
changeset 37946 | e420b9f05aaf |
parent 36526 | 3b41f1c69604 |
child 42407 | f3702cff2933 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
37946
e420b9f05aaf
8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. |
36526 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import java.util.Collections; |
|
29 |
import java.util.EnumSet; |
|
30 |
import java.util.Set; |
|
31 |
||
32 |
import javax.lang.model.element.ModuleElement; |
|
33 |
import javax.lang.model.element.PackageElement; |
|
34 |
import javax.lang.model.element.TypeElement; |
|
35 |
||
36 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
37 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
|
38 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
|
39 |
import com.sun.tools.javac.util.DefinedBy; |
|
40 |
import com.sun.tools.javac.util.DefinedBy.Api; |
|
41 |
import com.sun.tools.javac.util.List; |
|
42 |
||
43 |
||
44 |
/** |
|
45 |
* Root class for the directives that may appear in module compilation units. |
|
46 |
* |
|
47 |
* <p><b>This is NOT part of any supported API. |
|
48 |
* If you write code that depends on this, you do so at your own risk. |
|
49 |
* This code and its internal interfaces are subject to change or |
|
50 |
* deletion without notice.</b> |
|
51 |
*/ |
|
52 |
public abstract class Directive implements ModuleElement.Directive { |
|
53 |
||
54 |
/** Flags for RequiresDirective. */ |
|
55 |
public enum RequiresFlag { |
|
56 |
PUBLIC(0x0020), |
|
57 |
SYNTHETIC(0x1000), |
|
58 |
MANDATED(0x8000), |
|
59 |
EXTRA(0x10000); |
|
60 |
||
61 |
// overkill? move to ClassWriter? |
|
62 |
public static int value(Set<RequiresFlag> s) { |
|
63 |
int v = 0; |
|
64 |
for (RequiresFlag f: s) |
|
65 |
v |= f.value; |
|
66 |
return v; |
|
67 |
} |
|
68 |
||
69 |
RequiresFlag(int value) { |
|
70 |
this.value = value; |
|
71 |
} |
|
72 |
||
73 |
public final int value; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* 'exports' Package ';' |
|
78 |
*/ |
|
79 |
public static class ExportsDirective extends Directive |
|
80 |
implements ModuleElement.ExportsDirective { |
|
81 |
public final PackageSymbol packge; |
|
82 |
public final List<ModuleSymbol> modules; |
|
83 |
||
84 |
public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules) { |
|
85 |
this.packge = packge; |
|
86 |
this.modules = modules; |
|
87 |
} |
|
88 |
||
89 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
90 |
public ModuleElement.DirectiveKind getKind() { |
|
91 |
return ModuleElement.DirectiveKind.EXPORTS; |
|
92 |
} |
|
93 |
||
94 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
95 |
public PackageElement getPackage() { |
|
96 |
return packge; |
|
97 |
} |
|
98 |
||
99 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
100 |
public java.util.List<? extends ModuleElement> getTargetModules() { |
|
37946
e420b9f05aaf
8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents:
36526
diff
changeset
|
101 |
return modules == null |
e420b9f05aaf
8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents:
36526
diff
changeset
|
102 |
? null |
e420b9f05aaf
8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents:
36526
diff
changeset
|
103 |
: Collections.unmodifiableList(modules); |
36526 | 104 |
} |
105 |
||
106 |
@Override |
|
107 |
public String toString() { |
|
108 |
if (modules == null) |
|
109 |
return "Exports[" + packge + "]"; |
|
110 |
else |
|
111 |
return "Exports[" + packge + ":" + modules + "]"; |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* 'provides' ServiceName 'with' QualifiedIdentifer ';' |
|
117 |
*/ |
|
118 |
public static class ProvidesDirective extends Directive |
|
119 |
implements ModuleElement.ProvidesDirective { |
|
120 |
public final ClassSymbol service; |
|
121 |
public final ClassSymbol impl; |
|
122 |
||
123 |
public ProvidesDirective(ClassSymbol service, ClassSymbol impl) { |
|
124 |
this.service = service; |
|
125 |
this.impl = impl; |
|
126 |
} |
|
127 |
||
128 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
129 |
public ModuleElement.DirectiveKind getKind() { |
|
130 |
return ModuleElement.DirectiveKind.PROVIDES; |
|
131 |
} |
|
132 |
||
133 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
134 |
public TypeElement getService() { |
|
135 |
return service; |
|
136 |
} |
|
137 |
||
138 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
139 |
public TypeElement getImplementation() { |
|
140 |
return impl; |
|
141 |
} |
|
142 |
||
143 |
@Override |
|
144 |
public String toString() { |
|
145 |
return "Provides[" + service + "," + impl + "]"; |
|
146 |
} |
|
147 |
||
148 |
@Override |
|
149 |
public boolean equals(Object obj) { |
|
150 |
if (!(obj instanceof ProvidesDirective)) { |
|
151 |
return false; |
|
152 |
} |
|
153 |
ProvidesDirective other = (ProvidesDirective)obj; |
|
154 |
return service == other.service && impl == other.impl; |
|
155 |
} |
|
156 |
||
157 |
@Override |
|
158 |
public int hashCode() { |
|
159 |
return service.hashCode() * 31 + impl.hashCode() * 37; |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* 'requires' ['public'] ModuleName ';' |
|
165 |
*/ |
|
166 |
public static class RequiresDirective extends Directive |
|
167 |
implements ModuleElement.RequiresDirective { |
|
168 |
public final ModuleSymbol module; |
|
169 |
public final Set<RequiresFlag> flags; |
|
170 |
||
171 |
public RequiresDirective(ModuleSymbol module) { |
|
172 |
this(module, EnumSet.noneOf(RequiresFlag.class)); |
|
173 |
} |
|
174 |
||
175 |
public RequiresDirective(ModuleSymbol module, Set<RequiresFlag> flags) { |
|
176 |
this.module = module; |
|
177 |
this.flags = flags; |
|
178 |
} |
|
179 |
||
180 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
181 |
public ModuleElement.DirectiveKind getKind() { |
|
182 |
return ModuleElement.DirectiveKind.REQUIRES; |
|
183 |
} |
|
184 |
||
185 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
186 |
public boolean isPublic() { |
|
187 |
return flags.contains(RequiresFlag.PUBLIC); |
|
188 |
} |
|
189 |
||
190 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
191 |
public ModuleElement getDependency() { |
|
192 |
return module; |
|
193 |
} |
|
194 |
||
195 |
@Override |
|
196 |
public String toString() { |
|
197 |
return "Requires[" + flags + "," + module + "]"; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* 'uses' ServiceName ';' |
|
203 |
*/ |
|
204 |
public static class UsesDirective extends Directive |
|
205 |
implements ModuleElement.UsesDirective { |
|
206 |
public final ClassSymbol service; |
|
207 |
||
208 |
public UsesDirective(ClassSymbol service) { |
|
209 |
this.service = service; |
|
210 |
} |
|
211 |
||
212 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
213 |
public ModuleElement.DirectiveKind getKind() { |
|
214 |
return ModuleElement.DirectiveKind.USES; |
|
215 |
} |
|
216 |
||
217 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
218 |
public TypeElement getService() { |
|
219 |
return service; |
|
220 |
} |
|
221 |
||
222 |
@Override |
|
223 |
public String toString() { |
|
224 |
return "Uses[" + service + "]"; |
|
225 |
} |
|
226 |
||
227 |
@Override |
|
228 |
public boolean equals(Object obj) { |
|
229 |
if (!(obj instanceof UsesDirective)) { |
|
230 |
return false; |
|
231 |
} |
|
232 |
UsesDirective other = (UsesDirective)obj; |
|
233 |
return service == other.service; |
|
234 |
} |
|
235 |
||
236 |
@Override |
|
237 |
public int hashCode() { |
|
238 |
return service.hashCode() * 31; |
|
239 |
} |
|
240 |
} |
|
241 |
} |