diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java index 4a1bad4..30600ab 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java @@ -147,11 +147,12 @@ */ public BinaryTypeBinding(PackageBinding packageBinding, IBinaryType binaryType, LookupEnvironment environment) { this.compoundName = CharOperation.splitOn('/', binaryType.getName()); + this.fPackage = packageBinding; + this.modifiers = binaryType.getModifiers(); computeId(); this.tagBits |= TagBits.IsBinaryBinding; this.environment = environment; - this.fPackage = packageBinding; this.fileName = binaryType.getFileName(); /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, even in a 1.4 project, we @@ -165,7 +166,6 @@ : Binding.NO_TYPE_VARIABLES; this.sourceName = binaryType.getSourceName(); - this.modifiers = binaryType.getModifiers(); if ((binaryType.getTagBits() & TagBits.HierarchyHasProblems) != 0) this.tagBits |= TagBits.HierarchyHasProblems; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java index b6f3133..bf8d90c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java @@ -65,9 +65,6 @@ if (this.knownTypes == null) this.knownTypes = new HashtableOfType(25); this.knownTypes.put(element.compoundName[element.compoundName.length - 1], element); - if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) - if (element.isAnnotationType() || element instanceof UnresolvedReferenceBinding) // unresolved types don't yet have the modifiers set - checkIfNullAnnotationType(element); } void clearMissingTagBit() { @@ -260,27 +257,6 @@ if (!CharOperation.equals(packageName[i], typeName[i])) return false; return true; -} - -void checkIfNullAnnotationType(ReferenceBinding type) { - // check if type is one of the configured null annotation types - // if so mark as a well known type using the corresponding typeID: - if (this.environment.nullableAnnotationPackage == this - && CharOperation.equals(type.compoundName, this.environment.getNullableAnnotationName())) { - type.id = TypeIds.T_ConfiguredAnnotationNullable; - if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type - this.environment.nullableAnnotationPackage = null; // don't check again - } else if (this.environment.nonnullAnnotationPackage == this - && CharOperation.equals(type.compoundName, this.environment.getNonNullAnnotationName())) { - type.id = TypeIds.T_ConfiguredAnnotationNonNull; - if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type - this.environment.nonnullAnnotationPackage = null; // don't check again - } else if (this.environment.nonnullByDefaultAnnotationPackage == this - && CharOperation.equals(type.compoundName, this.environment.getNonNullByDefaultAnnotationName())) { - type.id = TypeIds.T_ConfiguredAnnotationNonNullByDefault; - if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type - this.environment.nonnullByDefaultAnnotationPackage = null; // don't check again - } } public TypeBinding getNullnessDefaultAnnotation(Scope scope) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index 75de854..6427540 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -377,12 +377,13 @@ public void computeId() { // try to avoid multiple checks against a package/type name + outerSwitch: switch (this.compoundName.length) { case 3 : if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0]) && !CharOperation.equals(TypeConstants.JAVAX, this.compoundName[0])) - return; + break outerSwitch; char[] packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe @@ -397,10 +398,10 @@ this.id = TypeIds.T_JavaxAnnotationPostConstruct; if (CharOperation.equals(typeName, TypeConstants.JAVAX_ANNOTATION_PREDESTROY[2])) this.id = TypeIds.T_JavaxAnnotationPreDestroy; - return; + break outerSwitch; } } - return; + break outerSwitch; } if (!CharOperation.equals(TypeConstants.LANG, this.compoundName[1])) { switch (packageName[0]) { @@ -410,46 +411,46 @@ case 'C' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_CLOSEABLE[2])) this.typeBits |= TypeIds.BitCloseable; // don't assign id, only typeBit (for analysis of resource leaks) - return; + break outerSwitch; case 'E' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_EXTERNALIZABLE[2])) this.id = TypeIds.T_JavaIoExternalizable; - return; + break outerSwitch; case 'I' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_IOEXCEPTION[2])) this.id = TypeIds.T_JavaIoException; - return; + break outerSwitch; case 'O' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_OBJECTSTREAMEXCEPTION[2])) this.id = TypeIds.T_JavaIoObjectStreamException; - return; + break outerSwitch; case 'P' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_PRINTSTREAM[2])) this.id = TypeIds.T_JavaIoPrintStream; - return; + break outerSwitch; case 'S' : if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_SERIALIZABLE[2])) this.id = TypeIds.T_JavaIoSerializable; - return; + break outerSwitch; } } - return; + break outerSwitch; case 'u' : if (CharOperation.equals(packageName, TypeConstants.UTIL)) { switch (typeName[0]) { case 'C' : if (CharOperation.equals(typeName, TypeConstants.JAVA_UTIL_COLLECTION[2])) this.id = TypeIds.T_JavaUtilCollection; - return; + break outerSwitch; case 'I' : if (CharOperation.equals(typeName, TypeConstants.JAVA_UTIL_ITERATOR[2])) this.id = TypeIds.T_JavaUtilIterator; - return; + break outerSwitch; } } - return; + break outerSwitch; } - return; + break outerSwitch; } // remaining types MUST be in java.lang.* @@ -461,111 +462,111 @@ this.id = TypeIds.T_JavaLangAutoCloseable; this.typeBits |= TypeIds.BitAutoCloseable; } - return; + break outerSwitch; case 14: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ASSERTIONERROR[2])) this.id = TypeIds.T_JavaLangAssertionError; - return; + break outerSwitch; } - return; + break outerSwitch; case 'B' : switch (typeName.length) { case 4 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_BYTE[2])) this.id = TypeIds.T_JavaLangByte; - return; + break outerSwitch; case 7 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_BOOLEAN[2])) this.id = TypeIds.T_JavaLangBoolean; - return; + break outerSwitch; } - return; + break outerSwitch; case 'C' : switch (typeName.length) { case 5 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CLASS[2])) this.id = TypeIds.T_JavaLangClass; - return; + break outerSwitch; case 9 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CHARACTER[2])) this.id = TypeIds.T_JavaLangCharacter; else if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CLONEABLE[2])) this.id = TypeIds.T_JavaLangCloneable; - return; + break outerSwitch; case 22 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CLASSNOTFOUNDEXCEPTION[2])) this.id = TypeIds.T_JavaLangClassNotFoundException; - return; + break outerSwitch; } - return; + break outerSwitch; case 'D' : switch (typeName.length) { case 6 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_DOUBLE[2])) this.id = TypeIds.T_JavaLangDouble; - return; + break outerSwitch; case 10 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_DEPRECATED[2])) this.id = TypeIds.T_JavaLangDeprecated; - return; + break outerSwitch; } - return; + break outerSwitch; case 'E' : switch (typeName.length) { case 4 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ENUM[2])) this.id = TypeIds.T_JavaLangEnum; - return; + break outerSwitch; case 5 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ERROR[2])) this.id = TypeIds.T_JavaLangError; - return; + break outerSwitch; case 9 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_EXCEPTION[2])) this.id = TypeIds.T_JavaLangException; - return; + break outerSwitch; } - return; + break outerSwitch; case 'F' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_FLOAT[2])) this.id = TypeIds.T_JavaLangFloat; - return; + break outerSwitch; case 'I' : switch (typeName.length) { case 7 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_INTEGER[2])) this.id = TypeIds.T_JavaLangInteger; - return; + break outerSwitch; case 8 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ITERABLE[2])) this.id = TypeIds.T_JavaLangIterable; - return; + break outerSwitch; case 24 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ILLEGALARGUMENTEXCEPTION[2])) this.id = TypeIds.T_JavaLangIllegalArgumentException; - return; + break outerSwitch; } - return; + break outerSwitch; case 'L' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_LONG[2])) this.id = TypeIds.T_JavaLangLong; - return; + break outerSwitch; case 'N' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_NOCLASSDEFERROR[2])) this.id = TypeIds.T_JavaLangNoClassDefError; - return; + break outerSwitch; case 'O' : switch (typeName.length) { case 6 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_OBJECT[2])) this.id = TypeIds.T_JavaLangObject; - return; + break outerSwitch; case 8 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_OVERRIDE[2])) this.id = TypeIds.T_JavaLangOverride; - return; + break outerSwitch; } - return; + break outerSwitch; case 'R' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION[2])) this.id = TypeIds.T_JavaLangRuntimeException; @@ -575,45 +576,45 @@ case 5 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SHORT[2])) this.id = TypeIds.T_JavaLangShort; - return; + break outerSwitch; case 6 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_STRING[2])) this.id = TypeIds.T_JavaLangString; else if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SYSTEM[2])) this.id = TypeIds.T_JavaLangSystem; - return; + break outerSwitch; case 11 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SAFEVARARGS[2])) this.id = TypeIds.T_JavaLangSafeVarargs; - return; + break outerSwitch; case 12 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_STRINGBUFFER[2])) this.id = TypeIds.T_JavaLangStringBuffer; - return; + break outerSwitch; case 13 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_STRINGBUILDER[2])) this.id = TypeIds.T_JavaLangStringBuilder; - return; + break outerSwitch; case 16 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS[2])) this.id = TypeIds.T_JavaLangSuppressWarnings; - return; + break outerSwitch; } - return; + break outerSwitch; case 'T' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_THROWABLE[2])) this.id = TypeIds.T_JavaLangThrowable; - return; + break outerSwitch; case 'V' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_VOID[2])) this.id = TypeIds.T_JavaLangVoid; - return; + break outerSwitch; } break; case 4: if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) - return; + break outerSwitch; packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe @@ -628,38 +629,38 @@ case 'A' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_ANNOTATION[3])) this.id = TypeIds.T_JavaLangAnnotationAnnotation; - return; + break outerSwitch; case 'D' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_DOCUMENTED[3])) this.id = TypeIds.T_JavaLangAnnotationDocumented; - return; + break outerSwitch; case 'E' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_ELEMENTTYPE[3])) this.id = TypeIds.T_JavaLangAnnotationElementType; - return; + break outerSwitch; case 'I' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_INHERITED[3])) this.id = TypeIds.T_JavaLangAnnotationInherited; - return; + break outerSwitch; case 'R' : switch (typeName.length) { case 9 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_RETENTION[3])) this.id = TypeIds.T_JavaLangAnnotationRetention; - return; + break outerSwitch; case 15 : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_RETENTIONPOLICY[3])) this.id = TypeIds.T_JavaLangAnnotationRetentionPolicy; - return; + break outerSwitch; } - return; + break outerSwitch; case 'T' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_TARGET[3])) this.id = TypeIds.T_JavaLangAnnotationTarget; - return; + break outerSwitch; } } - return; + break outerSwitch; case 'i': if (CharOperation.equals(packageName, TypeConstants.INVOKE)) { if (typeName.length == 0) return; // just to be safe @@ -667,33 +668,33 @@ case 'M' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_INVOKE_METHODHANDLE_$_POLYMORPHICSIGNATURE[3])) this.id = TypeIds.T_JavaLangInvokeMethodHandlePolymorphicSignature; - return; + break outerSwitch; } } - return; + break outerSwitch; case 'r' : if (CharOperation.equals(packageName, TypeConstants.REFLECT)) { switch (typeName[0]) { case 'C' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_REFLECT_CONSTRUCTOR[2])) this.id = TypeIds.T_JavaLangReflectConstructor; - return; + break outerSwitch; case 'F' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_REFLECT_FIELD[2])) this.id = TypeIds.T_JavaLangReflectField; - return; + break outerSwitch; case 'M' : if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_REFLECT_METHOD[2])) this.id = TypeIds.T_JavaLangReflectMethod; - return; + break outerSwitch; } } - return; + break outerSwitch; } break; case 5 : if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) - return; + break outerSwitch; packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe @@ -712,14 +713,39 @@ if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_INVOKE_METHODHANDLE_POLYMORPHICSIGNATURE[3]) && CharOperation.equals(memberTypeName, TypeConstants.JAVA_LANG_INVOKE_METHODHANDLE_POLYMORPHICSIGNATURE[4])) this.id = TypeIds.T_JavaLangInvokeMethodHandlePolymorphicSignature; - return; + break outerSwitch; } } - return; + break outerSwitch; } - return; + break outerSwitch; } } + if (this.fPackage != null) { + LookupEnvironment env = this.fPackage.environment; + if (env.globalOptions.isAnnotationBasedNullAnalysisEnabled) { + if (isAnnotationType() || this instanceof UnresolvedReferenceBinding) {// unresolved types don't yet have the modifiers set + // check if type is one of the configured null annotation types + // if so mark as a well known type using the corresponding typeID: + if (env.nullableAnnotationPackage == this.fPackage + && CharOperation.equals(this.compoundName, env.getNullableAnnotationName())) { + this.id = TypeIds.T_ConfiguredAnnotationNullable; + if (!(this instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type + env.nullableAnnotationPackage = null; // don't check again + } else if (env.nonnullAnnotationPackage == this.fPackage + && CharOperation.equals(this.compoundName, env.getNonNullAnnotationName())) { + this.id = TypeIds.T_ConfiguredAnnotationNonNull; + if (!(this instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type + env.nonnullAnnotationPackage = null; // don't check again + } else if (env.nonnullByDefaultAnnotationPackage == this.fPackage + && CharOperation.equals(this.compoundName, env.getNonNullByDefaultAnnotationName())) { + this.id = TypeIds.T_ConfiguredAnnotationNonNullByDefault; + if (!(this instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type + env.nonnullByDefaultAnnotationPackage = null; // don't check again + } + } + } + } } /**