Lines 10-18
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
12 |
|
12 |
|
|
|
13 |
import java.util.Iterator; |
14 |
import java.util.List; |
15 |
|
16 |
import org.eclipse.jdt.core.ICompilationUnit; |
17 |
import org.eclipse.jdt.core.IPackageFragment; |
18 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
19 |
import org.eclipse.jdt.core.JavaModelException; |
13 |
import org.eclipse.jdt.core.compiler.CharOperation; |
20 |
import org.eclipse.jdt.core.compiler.CharOperation; |
|
|
21 |
import org.eclipse.jdt.core.dom.AST; |
22 |
import org.eclipse.jdt.core.dom.ASTParser; |
23 |
import org.eclipse.jdt.core.dom.Annotation; |
24 |
import org.eclipse.jdt.core.dom.ITypeBinding; |
25 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
26 |
import org.eclipse.jdt.core.dom.IAnnotationBinding; |
27 |
import org.eclipse.jdt.core.dom.PackageDeclaration; |
28 |
import org.eclipse.jdt.internal.compiler.env.IBinaryType; |
29 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
30 |
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; |
14 |
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; |
31 |
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; |
15 |
import org.eclipse.jdt.internal.compiler.util.HashtableOfType; |
32 |
import org.eclipse.jdt.internal.compiler.util.HashtableOfType; |
|
|
33 |
import org.eclipse.jdt.internal.core.NameLookup; |
34 |
import org.eclipse.jdt.internal.core.SearchableEnvironment; |
16 |
|
35 |
|
17 |
public class PackageBinding extends Binding implements TypeConstants { |
36 |
public class PackageBinding extends Binding implements TypeConstants { |
18 |
public long tagBits = 0; // See values in the interface TagBits below |
37 |
public long tagBits = 0; // See values in the interface TagBits below |
Lines 205-210
Link Here
|
205 |
return null; |
224 |
return null; |
206 |
} |
225 |
} |
207 |
|
226 |
|
|
|
227 |
/** |
228 |
* Compute the tagbits for standard annotations. For source types, these could require |
229 |
* lazily resolving corresponding annotation nodes, in case of forward references. |
230 |
* @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() |
231 |
*/ |
232 |
public long getAnnotationTagBits() { |
233 |
|
234 |
if ((this.tagBits & TagBits.AnnotationResolved) != 0) |
235 |
return this.tagBits; |
236 |
|
237 |
this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved); |
238 |
|
239 |
if (this.compoundName == CharOperation.NO_CHAR_CHAR) |
240 |
return this.tagBits; |
241 |
|
242 |
ReferenceBinding packageInfo = this.getType(TypeConstants.PACKAGE_INFO_NAME); |
243 |
if (packageInfo != null) { |
244 |
this.tagBits |= (packageInfo.getAnnotationTagBits() & TagBits.AllStandardAnnotationsMask); |
245 |
return this.tagBits; |
246 |
} |
247 |
|
248 |
// We didn't find package-info.java. This may be due to its absence altogether in the package |
249 |
// or may merely be due to the fact that the java model hides package-info.java even when it |
250 |
// exists. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=99662. We work hard to restore |
251 |
// @Deprecated annotation if it existed in the first place. |
252 |
|
253 |
INameEnvironment nameEnvironment = this.environment.nameEnvironment; |
254 |
if (!(nameEnvironment instanceof SearchableEnvironment)) |
255 |
return this.tagBits; |
256 |
|
257 |
NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup; |
258 |
if (nameLookup == null) |
259 |
return this.tagBits; |
260 |
|
261 |
final String pkgName = new String (readableName()); |
262 |
IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/); |
263 |
if (pkgs == null) |
264 |
return this.tagBits; |
265 |
|
266 |
final String javaLangDeprecated = new String(CharOperation.concatWith(TypeConstants.JAVA_LANG_DEPRECATED, '.')); |
267 |
try { |
268 |
for (int i = 0, len = pkgs.length; i < len; i++) { |
269 |
int fragType = pkgs[i].getKind(); |
270 |
if (fragType == IPackageFragmentRoot.K_SOURCE) { |
271 |
String unitName = "package-info.java"; //$NON-NLS-1$ |
272 |
ICompilationUnit unit = pkgs[i].getCompilationUnit(unitName); |
273 |
if (unit == null || !unit.exists()) |
274 |
continue; |
275 |
|
276 |
ASTParser p = ASTParser.newParser(AST.JLS3); |
277 |
p.setSource(unit); |
278 |
p.setResolveBindings(true); |
279 |
p.setUnitName(unitName); |
280 |
p.setFocalPosition(0); |
281 |
p.setKind(ASTParser.K_COMPILATION_UNIT); |
282 |
CompilationUnit domUnit = (CompilationUnit) p.createAST(null); |
283 |
PackageDeclaration pkgDecl = domUnit.getPackage(); |
284 |
if (pkgDecl == null) |
285 |
return this.tagBits; |
286 |
|
287 |
List annos = pkgDecl.annotations(); |
288 |
if (annos == null || annos.isEmpty()) |
289 |
return this.tagBits; |
290 |
|
291 |
for (Iterator it = annos.iterator(); it.hasNext();) { |
292 |
IAnnotationBinding result; |
293 |
result = ((Annotation) it.next()).resolveAnnotationBinding(); |
294 |
ITypeBinding type = result.getAnnotationType(); |
295 |
if (type != null) { |
296 |
String name = type.getQualifiedName(); |
297 |
if (name.equals(javaLangDeprecated)) { |
298 |
this.tagBits |= TagBits.AnnotationDeprecated; |
299 |
return this.tagBits; |
300 |
} |
301 |
} |
302 |
} |
303 |
return this.tagBits; |
304 |
} |
305 |
if (fragType == IPackageFragmentRoot.K_BINARY) { |
306 |
NameEnvironmentAnswer answer = |
307 |
nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.compoundName); |
308 |
if (answer != null) { |
309 |
if (answer.isBinaryType()) { |
310 |
IBinaryType type = answer.getBinaryType(); |
311 |
this.tagBits |= (type.getTagBits() & TagBits.AllStandardAnnotationsMask); |
312 |
} |
313 |
return this.tagBits; |
314 |
} |
315 |
} |
316 |
} |
317 |
} catch(JavaModelException e) { |
318 |
return this.tagBits; |
319 |
} |
320 |
return this.tagBits; |
321 |
} |
322 |
|
208 |
/* API |
323 |
/* API |
209 |
* Answer the receiver's binding type from Binding.BindingID. |
324 |
* Answer the receiver's binding type from Binding.BindingID. |
210 |
*/ |
325 |
*/ |