List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeIds T_JavaLangThrowable
int T_JavaLangThrowable
To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeIds T_JavaLangThrowable.
Click Source Link
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
public void computeId() { // try to avoid multiple checks against a package/type name switch (this.compoundName.length) { case 3:// w w w . j a v a2 s. co m if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) return; char[] packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe char[] typeName = this.compoundName[2]; if (typeName.length == 0) return; // just to be safe // remaining types MUST be in java.*.* if (!CharOperation.equals(TypeConstants.LANG, this.compoundName[1])) { switch (packageName[0]) { case 'i': if (CharOperation.equals(packageName, TypeConstants.IO)) { switch (typeName[0]) { case 'E': if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_EXTERNALIZABLE[2])) this.id = TypeIds.T_JavaIoExternalizable; return; case 'I': if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_IOEXCEPTION[2])) this.id = TypeIds.T_JavaIoException; return; case 'O': if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_OBJECTSTREAMEXCEPTION[2])) this.id = TypeIds.T_JavaIoObjectStreamException; return; case 'P': if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_PRINTSTREAM[2])) this.id = TypeIds.T_JavaIoPrintStream; return; case 'S': if (CharOperation.equals(typeName, TypeConstants.JAVA_IO_SERIALIZABLE[2])) this.id = TypeIds.T_JavaIoSerializable; return; } } return; 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; case 'I': if (CharOperation.equals(typeName, TypeConstants.JAVA_UTIL_ITERATOR[2])) this.id = TypeIds.T_JavaUtilIterator; return; } } return; } return; } // remaining types MUST be in java.lang.* switch (typeName[0]) { case 'A': switch (typeName.length) { case 13: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_AUTOCLOSEABLE[2])) this.id = TypeIds.T_JavaLangAutoCloseable; return; case 14: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ASSERTIONERROR[2])) this.id = TypeIds.T_JavaLangAssertionError; return; } return; case 'B': switch (typeName.length) { case 4: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_BYTE[2])) this.id = TypeIds.T_JavaLangByte; return; case 7: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_BOOLEAN[2])) this.id = TypeIds.T_JavaLangBoolean; return; } return; case 'C': switch (typeName.length) { case 5: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CLASS[2])) this.id = TypeIds.T_JavaLangClass; return; 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; case 22: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_CLASSNOTFOUNDEXCEPTION[2])) this.id = TypeIds.T_JavaLangClassNotFoundException; return; } return; case 'D': switch (typeName.length) { case 6: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_DOUBLE[2])) this.id = TypeIds.T_JavaLangDouble; return; case 10: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_DEPRECATED[2])) this.id = TypeIds.T_JavaLangDeprecated; return; } return; case 'E': switch (typeName.length) { case 4: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ENUM[2])) this.id = TypeIds.T_JavaLangEnum; return; case 5: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ERROR[2])) this.id = TypeIds.T_JavaLangError; return; case 9: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_EXCEPTION[2])) this.id = TypeIds.T_JavaLangException; return; } return; case 'F': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_FLOAT[2])) this.id = TypeIds.T_JavaLangFloat; return; case 'I': switch (typeName.length) { case 7: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_INTEGER[2])) this.id = TypeIds.T_JavaLangInteger; return; case 8: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ITERABLE[2])) this.id = TypeIds.T_JavaLangIterable; return; case 24: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ILLEGALARGUMENTEXCEPTION[2])) this.id = TypeIds.T_JavaLangIllegalArgumentException; return; } return; case 'L': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_LONG[2])) this.id = TypeIds.T_JavaLangLong; return; case 'N': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_NOCLASSDEFERROR[2])) this.id = TypeIds.T_JavaLangNoClassDefError; return; case 'O': switch (typeName.length) { case 6: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_OBJECT[2])) this.id = TypeIds.T_JavaLangObject; return; case 8: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_OVERRIDE[2])) this.id = TypeIds.T_JavaLangOverride; return; } return; case 'R': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION[2])) this.id = TypeIds.T_JavaLangRuntimeException; break; case 'S': switch (typeName.length) { case 5: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SHORT[2])) this.id = TypeIds.T_JavaLangShort; return; 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; case 11: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SAFEVARARGS[2])) this.id = TypeIds.T_JavaLangSafeVarargs; return; case 12: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_STRINGBUFFER[2])) this.id = TypeIds.T_JavaLangStringBuffer; return; case 13: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_STRINGBUILDER[2])) this.id = TypeIds.T_JavaLangStringBuilder; return; case 16: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS[2])) this.id = TypeIds.T_JavaLangSuppressWarnings; return; } return; case 'T': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_THROWABLE[2])) this.id = TypeIds.T_JavaLangThrowable; return; case 'V': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_VOID[2])) this.id = TypeIds.T_JavaLangVoid; return; } break; case 4: if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) return; packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe packageName = this.compoundName[2]; if (packageName.length == 0) return; // just to be safe typeName = this.compoundName[3]; if (typeName.length == 0) return; // just to be safe switch (packageName[0]) { case 'a': if (CharOperation.equals(packageName, TypeConstants.ANNOTATION)) { switch (typeName[0]) { case 'A': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_ANNOTATION[3])) this.id = TypeIds.T_JavaLangAnnotationAnnotation; return; case 'D': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_DOCUMENTED[3])) this.id = TypeIds.T_JavaLangAnnotationDocumented; return; case 'E': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_ELEMENTTYPE[3])) this.id = TypeIds.T_JavaLangAnnotationElementType; return; case 'I': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_INHERITED[3])) this.id = TypeIds.T_JavaLangAnnotationInherited; return; case 'R': switch (typeName.length) { case 9: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_RETENTION[3])) this.id = TypeIds.T_JavaLangAnnotationRetention; return; case 15: if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_RETENTIONPOLICY[3])) this.id = TypeIds.T_JavaLangAnnotationRetentionPolicy; return; } return; case 'T': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_ANNOTATION_TARGET[3])) this.id = TypeIds.T_JavaLangAnnotationTarget; return; } } return; case 'i': if (CharOperation.equals(packageName, TypeConstants.INVOKE)) { if (typeName.length == 0) return; // just to be safe switch (typeName[0]) { case 'M': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_INVOKE_METHODHANDLE_$_POLYMORPHICSIGNATURE[3])) this.id = TypeIds.T_JavaLangInvokeMethodHandlePolymorphicSignature; return; } } return; 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; case 'F': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_REFLECT_FIELD[2])) this.id = TypeIds.T_JavaLangReflectField; return; case 'M': if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_REFLECT_METHOD[2])) this.id = TypeIds.T_JavaLangReflectMethod; return; } } return; } break; case 5: if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) return; packageName = this.compoundName[1]; if (packageName.length == 0) return; // just to be safe if (CharOperation.equals(TypeConstants.LANG, packageName)) { packageName = this.compoundName[2]; if (packageName.length == 0) return; // just to be safe switch (packageName[0]) { case 'i': if (CharOperation.equals(packageName, TypeConstants.INVOKE)) { typeName = this.compoundName[3]; if (typeName.length == 0) return; // just to be safe switch (typeName[0]) { case 'M': char[] memberTypeName = this.compoundName[4]; if (memberTypeName.length == 0) return; // just to be safe 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; } } return; } return; } } }
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#isThrowable() *//*from ww w . java 2 s.c om*/ public boolean isThrowable() { ReferenceBinding current = this; do { switch (current.id) { case TypeIds.T_JavaLangThrowable: case TypeIds.T_JavaLangError: case TypeIds.T_JavaLangRuntimeException: case TypeIds.T_JavaLangException: return true; } } while ((current = current.superclass()) != null); return false; }
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * JLS 11.5 ensures that Throwable, Exception, RuntimeException and Error are directly connected. * (Throwable<- Exception <- RumtimeException, Throwable <- Error). Thus no need to check #isCompatibleWith * but rather check in type IDs so as to avoid some eager class loading for JCL writers. * When 'includeSupertype' is true, answers true if the given type can be a supertype of some unchecked exception * type (i.e. Throwable or Exception).//w w w . j av a 2 s. c o m * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#isUncheckedException(boolean) */ public boolean isUncheckedException(boolean includeSupertype) { switch (this.id) { case TypeIds.T_JavaLangError: case TypeIds.T_JavaLangRuntimeException: return true; case TypeIds.T_JavaLangThrowable: case TypeIds.T_JavaLangException: return includeSupertype; } ReferenceBinding current = this; while ((current = current.superclass()) != null) { switch (current.id) { case TypeIds.T_JavaLangError: case TypeIds.T_JavaLangRuntimeException: return true; case TypeIds.T_JavaLangThrowable: case TypeIds.T_JavaLangException: return false; } } return false; }
From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java
License:Open Source License
public MethodBinding resolveTypesFor(MethodBinding method) { if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0) return method; if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { if ((method.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0) method.modifiers |= ClassFileConstants.AccDeprecated; }//from w w w . ja va 2s . c o m if (isViewedAsDeprecated() && !method.isDeprecated()) method.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; if (hasRestrictedAccess()) method.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess; AbstractMethodDeclaration methodDecl = method.sourceMethod(); // GROOVY /* old { if (methodDecl == null) return null; // method could not be resolved in previous iteration } new*/ if (methodDecl == null) { if (method instanceof LazilyResolvedMethodBinding) { LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method; // the rest is a copy of the code below but doesn't depend on the method declaration // nothing to do for method type parameters (there are none) // nothing to do for method exceptions (there are none) TypeBinding ptb = lrMethod.getParameterTypeBinding(); if (ptb == null) { method.parameters = Binding.NO_PARAMETERS; } else { method.parameters = new TypeBinding[] { ptb }; } method.returnType = lrMethod.getReturnTypeBinding(); method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved; return method; } // returning null is what this clause would have done anyway return null; } // FIXASC - end TypeParameter[] typeParameters = methodDecl.typeParameters(); if (typeParameters != null) { methodDecl.scope.connectTypeVariables(typeParameters, true); // Perform deferred bound checks for type variables (only done after type variable hierarchy is connected) for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) typeParameters[i].checkBounds(methodDecl.scope); } TypeReference[] exceptionTypes = methodDecl.thrownExceptions; if (exceptionTypes != null) { int size = exceptionTypes.length; method.thrownExceptions = new ReferenceBinding[size]; int count = 0; ReferenceBinding resolvedExceptionType; for (int i = 0; i < size; i++) { resolvedExceptionType = (ReferenceBinding) exceptionTypes[i].resolveType(methodDecl.scope, true /* check bounds*/); if (resolvedExceptionType == null) continue; if (resolvedExceptionType.isBoundParameterizedType()) { methodDecl.scope.problemReporter().invalidParameterizedExceptionType(resolvedExceptionType, exceptionTypes[i]); continue; } if (resolvedExceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null) { if (resolvedExceptionType.isValidBinding()) { methodDecl.scope.problemReporter().cannotThrowType(exceptionTypes[i], resolvedExceptionType); continue; } } if ((resolvedExceptionType.tagBits & TagBits.HasMissingType) != 0) { method.tagBits |= TagBits.HasMissingType; } method.modifiers |= (resolvedExceptionType.modifiers & ExtraCompilerModifiers.AccGenericSignature); method.thrownExceptions[count++] = resolvedExceptionType; } if (count < size) System.arraycopy(method.thrownExceptions, 0, method.thrownExceptions = new ReferenceBinding[count], 0, count); } final boolean reportUnavoidableGenericTypeProblems = this.scope .compilerOptions().reportUnavoidableGenericTypeProblems; boolean foundArgProblem = false; Argument[] arguments = methodDecl.arguments; if (arguments != null) { int size = arguments.length; method.parameters = Binding.NO_PARAMETERS; TypeBinding[] newParameters = new TypeBinding[size]; for (int i = 0; i < size; i++) { Argument arg = arguments[i]; if (arg.annotations != null) { method.tagBits |= TagBits.HasParameterAnnotations; } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && !method.isConstructor() && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0; TypeBinding parameterType; if (deferRawTypeCheck) { arg.type.bits |= ASTNode.IgnoreRawTypeCheck; } try { parameterType = arg.type.resolveType(methodDecl.scope, true /* check bounds*/); } finally { if (deferRawTypeCheck) { arg.type.bits &= ~ASTNode.IgnoreRawTypeCheck; } } if (parameterType == null) { foundArgProblem = true; } else if (parameterType == TypeBinding.VOID) { methodDecl.scope.problemReporter().argumentTypeCannotBeVoid(this, methodDecl, arg); foundArgProblem = true; } else { if ((parameterType.tagBits & TagBits.HasMissingType) != 0) { method.tagBits |= TagBits.HasMissingType; } TypeBinding leafType = parameterType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) method.modifiers |= ExtraCompilerModifiers.AccGenericSignature; newParameters[i] = parameterType; arg.binding = new LocalVariableBinding(arg, parameterType, arg.modifiers, true); } } // only assign parameters if no problems are found if (!foundArgProblem) { method.parameters = newParameters; } } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337799 if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) { if ((method.tagBits & TagBits.AnnotationSafeVarargs) != 0) { if (!method.isVarargs()) { methodDecl.scope.problemReporter().safeVarargsOnFixedArityMethod(method); } else if (!method.isStatic() && !method.isFinal() && !method.isConstructor()) { methodDecl.scope.problemReporter().safeVarargsOnNonFinalInstanceMethod(method); } } else if (method.parameters != null && method.parameters.length > 0 && method.isVarargs()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 if (!method.parameters[method.parameters.length - 1].isReifiable()) { methodDecl.scope.problemReporter() .possibleHeapPollutionFromVararg(methodDecl.arguments[methodDecl.arguments.length - 1]); } } } boolean foundReturnTypeProblem = false; if (!method.isConstructor()) { TypeReference returnType = methodDecl instanceof MethodDeclaration ? ((MethodDeclaration) methodDecl).returnType : null; if (returnType == null) { methodDecl.scope.problemReporter().missingReturnType(methodDecl); method.returnType = null; foundReturnTypeProblem = true; } else { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0; TypeBinding methodType; if (deferRawTypeCheck) { returnType.bits |= ASTNode.IgnoreRawTypeCheck; } try { methodType = returnType.resolveType(methodDecl.scope, true /* check bounds*/); } finally { if (deferRawTypeCheck) { returnType.bits &= ~ASTNode.IgnoreRawTypeCheck; } } if (methodType == null) { foundReturnTypeProblem = true; } else if (methodType.isArrayType() && ((ArrayBinding) methodType).leafComponentType == TypeBinding.VOID) { methodDecl.scope.problemReporter().returnTypeCannotBeVoidArray((MethodDeclaration) methodDecl); foundReturnTypeProblem = true; } else { if ((methodType.tagBits & TagBits.HasMissingType) != 0) { method.tagBits |= TagBits.HasMissingType; } method.returnType = methodType; TypeBinding leafType = methodType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) method.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } } } if (foundArgProblem) { methodDecl.binding = null; method.parameters = Binding.NO_PARAMETERS; // see 107004 // nullify type parameter bindings as well as they have a backpointer to the method binding // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=81134) if (typeParameters != null) for (int i = 0, length = typeParameters.length; i < length; i++) typeParameters[i].binding = null; return null; } if (foundReturnTypeProblem) return method; // but its still unresolved with a null return type & is still connected to its method declaration method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved; return method; }