List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeIds T_JavaLangObject
int T_JavaLangObject
To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeIds T_JavaLangObject.
Click Source Link
From source file:com.google.gwt.dev.jjs.impl.TypeMap.java
License:Apache License
private JNode internalGet(Binding binding, boolean failOnNull) { JNode cached = crossRefMap.get(binding); if (cached != null) { return cached; } else if (binding instanceof BaseTypeBinding) { BaseTypeBinding baseTypeBinding = (BaseTypeBinding) binding; // see org.eclipse.jdt.internal.compiler.lookup.TypeIds constants switch (baseTypeBinding.id) { case TypeIds.T_JavaLangObject: // here for consistency, should already be cached return program.getTypeJavaLangObject(); case TypeIds.T_char: return program.getTypePrimitiveChar(); case TypeIds.T_byte: return program.getTypePrimitiveByte(); case TypeIds.T_short: return program.getTypePrimitiveShort(); case TypeIds.T_boolean: return program.getTypePrimitiveBoolean(); case TypeIds.T_void: return program.getTypeVoid(); case TypeIds.T_long: return program.getTypePrimitiveLong(); case TypeIds.T_double: return program.getTypePrimitiveDouble(); case TypeIds.T_float: return program.getTypePrimitiveFloat(); case TypeIds.T_int: return program.getTypePrimitiveInt(); case TypeIds.T_JavaLangString: // here for consistency, should already be cached return program.getTypeJavaLangString(); case TypeIds.T_null: return program.getTypeNull(); case TypeIds.T_undefined: default://from ww w. j a va2 s.c o m return null; } } else if (binding instanceof ArrayBinding) { ArrayBinding arrayBinding = (ArrayBinding) binding; JType elementType = (JType) get(arrayBinding.elementsType(), failOnNull); if (elementType == null) { return null; } return program.getTypeArray(elementType); } else if (binding instanceof BinaryTypeBinding) { BinaryTypeBinding binaryBinding = (BinaryTypeBinding) binding; String name = BuildTypeMap.dotify(binaryBinding.compoundName); // There may be many BinaryTypeBindings for a single binary type JDeclaredType type = externalTypesByName.get(name); if (type != null) { put(binding, type); } return type; } else if (binding instanceof MethodBinding) { MethodBinding b = (MethodBinding) binding; JMethod cachedMethod = (JMethod) crossRefMap.get(b); if (cachedMethod == null) { JDeclaredType type = (JDeclaredType) get(b.declaringClass, failOnNull); if (type == null) { return type; } cachedMethod = getMethodForBinding(type, b); if (cachedMethod != null) { put(b, cachedMethod); } } else { // Happens sometimes when looking up the type to resolve the binding // causes us to also resolve the binding. } return cachedMethod; } else if (binding instanceof FieldBinding) { FieldBinding b = (FieldBinding) binding; JField cachedField = (JField) crossRefMap.get(b); if (cachedField == null) { JDeclaredType type = (JDeclaredType) get(b.declaringClass, failOnNull); if (type == null) { return null; } cachedField = getFieldForBinding(type, b); if (cachedField != null) { put(b, cachedField); } } else { // Happens sometimes when looking up the type to resolve the binding // causes us to also resolve the binding. } return cachedField; } return null; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.java
License:Open Source License
private ClassNode configureClass(BinaryTypeBinding type) { if (type.id == TypeIds.T_JavaLangObject) { return ClassHelper.OBJECT_TYPE; // next two clauses - see GRECLIPSE-1521 } else if (type.id == TypeIds.T_JavaLangString) { return ClassHelper.STRING_TYPE; } else if (type.id == TypeIds.T_JavaLangClass) { return ClassHelper.CLASS_Type; }/*from www. j a va 2 s . co m*/ JDTClassNode jcn = new JDTClassNode(type, resolver); return jcn; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTResolver.java
License:Open Source License
/** * Create a ClassNode based on the type of the JDT binding, this takes account of all the possible kinds of JDT binding. *//* www . j a va2 s .com*/ private ClassNode createClassNode(TypeBinding jdtTypeBinding) { if (jdtTypeBinding instanceof WildcardBinding) { return createClassNodeForWildcardBinding((WildcardBinding) jdtTypeBinding); } else if (jdtTypeBinding instanceof BaseTypeBinding) { return createClassNodeForPrimitiveBinding((BaseTypeBinding) jdtTypeBinding); } else if (jdtTypeBinding instanceof ArrayBinding) { return createClassNodeForArrayBinding((ArrayBinding) jdtTypeBinding); } else if (jdtTypeBinding instanceof TypeVariableBinding) { String typeVariableName = new String(jdtTypeBinding.sourceName()); TypeVariableBinding typeVariableBinding = (TypeVariableBinding) jdtTypeBinding; if (typeVariableBinding.declaringElement instanceof SourceTypeBinding) { GenericsType[] genericTypes = typeGenericsCurrentlyActive.peek(); GenericsType matchingGenericType = findMatchingGenericType(genericTypes, typeVariableName); if (matchingGenericType != null) { ClassNode newNode = ClassHelper.makeWithoutCaching(typeVariableName); newNode.setRedirect(matchingGenericType.getType()); newNode.setGenericsTypes(new GenericsType[] { matchingGenericType }); newNode.setGenericsPlaceHolder(true); return newNode; } // What does it means if we are here? // it means we've encountered a type variable but this class doesn't declare it. // So far this has been seen in the case where a synthetic binding is created for // a bridge method from a supertype. It appears what we can do here is collapse // that type variable to its bound (as this is meant to be a bridge method) // But what if it was bound by something a little higher up? // What other cases are there to worry about? if (typeVariableBinding.firstBound == null) { return ClassHelper.OBJECT_TYPE; } else { // c'est vrai? return convertToClassNode(typeVariableBinding.firstBound); } // throw new GroovyEclipseBug("Cannot find type variable on source type declaring element " // + typeVariableBinding.declaringElement); } else if (typeVariableBinding.declaringElement instanceof BinaryTypeBinding) { GenericsType[] genericTypes = convertToClassNode( ((BinaryTypeBinding) typeVariableBinding.declaringElement)).getGenericsTypes(); GenericsType matchingGenericType = findMatchingGenericType(genericTypes, typeVariableName); if (matchingGenericType != null) { ClassNode newNode = ClassHelper.makeWithoutCaching(typeVariableName); ClassNode[] upper = matchingGenericType.getUpperBounds(); if (upper != null && upper.length > 0) { newNode.setRedirect(upper[0]); } else { newNode.setRedirect(matchingGenericType.getType()); } newNode.setGenericsTypes(new GenericsType[] { matchingGenericType }); newNode.setGenericsPlaceHolder(true); return newNode; } throw new GroovyEclipseBug("Cannot find type variable on type declaring element " + typeVariableBinding.declaringElement); } else if (typeVariableBinding.declaringElement instanceof ParameterizedMethodBinding || typeVariableBinding.declaringElement instanceof MethodBinding) { GenericsType[] genericTypes = memberGenericsCurrentlyActive.peek(); GenericsType matchingGenericType = findMatchingGenericType(genericTypes, typeVariableName); if (matchingGenericType != null) { ClassNode newNode = ClassHelper.makeWithoutCaching(typeVariableName); newNode.setRedirect(matchingGenericType.getType()); newNode.setGenericsTypes(new GenericsType[] { matchingGenericType }); newNode.setGenericsPlaceHolder(true); return newNode; } throw new GroovyEclipseBug("Cannot find type variable on method declaring element " + typeVariableBinding.declaringElement); } throw new GroovyEclipseBug("Unexpected type variable reference. Declaring element is " + typeVariableBinding.declaringElement); // Next case handles: RawTypeBinding, ParameterizedTypeBinding, SourceTypeBinding } else if (jdtTypeBinding instanceof ReferenceBinding) { // It could be possible to unwrap SourceTypeBindings that have been built for Groovy types // (and thus get back to the original ClassNode, rather than building another one here). However, // they are not always reusable due to a link with the Groovy CompilationUnit that led to // their creation. // Unwrap code is something like: // if (sourceTypeBinding.scope != null) { // TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; // if (typeDeclaration instanceof GroovyTypeDeclaration) { // GroovyTypeDeclaration groovyTypeDeclaration = (GroovyTypeDeclaration) typeDeclaration; // ClassNode wrappedNode = groovyTypeDeclaration.getClassNode(); // return wrappedNode; // } // } if (jdtTypeBinding.id == TypeIds.T_JavaLangObject) { return ClassHelper.OBJECT_TYPE; } return new JDTClassNode((ReferenceBinding) jdtTypeBinding, this); } else { throw new GroovyEclipseBug("Unable to convert this binding: " + jdtTypeBinding.getClass()); } }
From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java
License:Open Source License
void verify() { if (this.type.isAnnotationType()) this.type.detectAnnotationCycle(); super.verify(); reportRawReferences();/*from w w w . jav a2 s . co m*/ for (int i = this.type.typeVariables.length; --i >= 0;) { TypeVariableBinding var = this.type.typeVariables[i]; // must verify bounds if the variable has more than 1 if (var.superInterfaces == Binding.NO_SUPERINTERFACES) continue; if (var.superInterfaces.length == 1 && var.superclass.id == TypeIds.T_JavaLangObject) continue; this.currentMethods = new HashtableOfObject(0); ReferenceBinding superclass = var.superclass(); if (superclass.kind() == Binding.TYPE_PARAMETER) superclass = (ReferenceBinding) superclass.erasure(); ReferenceBinding[] itsInterfaces = var.superInterfaces(); ReferenceBinding[] superInterfaces = new ReferenceBinding[itsInterfaces.length]; for (int j = itsInterfaces.length; --j >= 0;) { superInterfaces[j] = itsInterfaces[j].kind() == Binding.TYPE_PARAMETER ? (ReferenceBinding) itsInterfaces[j].erasure() : itsInterfaces[j]; } computeInheritedMethods(superclass, superInterfaces); checkTypeVariableMethods(this.type.scope.referenceContext.typeParameters[i]); } }
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 ww. j a va2 s.c om*/ 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
/** * Answer true if the receiver type can be assigned to the argument type (right) * In addition to improving performance, caching also ensures there is no infinite regression * since per nature, the compatibility check is recursive through parameterized type arguments (122775) */// w w w . j a va 2 s . c o m public boolean isCompatibleWith(TypeBinding otherType) { if (otherType == this) return true; if (otherType.id == TypeIds.T_JavaLangObject) return true; Object result; if (this.compatibleCache == null) { this.compatibleCache = new SimpleLookupTable(3); result = null; } else { result = this.compatibleCache.get(otherType); // [dbg reset] this.compatibleCache.put(otherType,null) if (result != null) { return result == Boolean.TRUE; } } this.compatibleCache.put(otherType, Boolean.FALSE); // protect from recursive call if (isCompatibleWith0(otherType)) { this.compatibleCache.put(otherType, Boolean.TRUE); return true; } return false; }
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * Answer true if the receiver type can be assigned to the argument type (right) *///from ww w . j a va 2 s .c o m private boolean isCompatibleWith0(TypeBinding otherType) { if (otherType == this) return true; if (otherType.id == TypeIds.T_JavaLangObject) return true; // equivalence may allow compatibility with array type through wildcard // bound if (isEquivalentTo(otherType)) return true; switch (otherType.kind()) { case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: return false; // should have passed equivalence check above if // wildcard case Binding.TYPE_PARAMETER: // check compatibility with capture of ? super X if (otherType.isCapture()) { CaptureBinding otherCapture = (CaptureBinding) otherType; TypeBinding otherLowerBound; if ((otherLowerBound = otherCapture.lowerBound) != null) { if (otherLowerBound.isArrayType()) return false; return isCompatibleWith(otherLowerBound); } } //$FALL-THROUGH$ case Binding.GENERIC_TYPE: case Binding.TYPE: case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: switch (kind()) { case Binding.GENERIC_TYPE: case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: if (erasure() == otherType.erasure()) return false; // should have passed equivalence check // above if same erasure } ReferenceBinding otherReferenceType = (ReferenceBinding) otherType; if (otherReferenceType.isInterface()) // could be annotation type return implementsInterface(otherReferenceType, true); if (isInterface()) // Explicit conversion from an interface // to a class is not allowed return false; return otherReferenceType.isSuperclassOf(this); default: return false; } }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public MethodBinding getImplicitMethod(char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { boolean insideStaticContext = false; boolean insideConstructorCall = false; boolean insideTypeAnnotation = false; MethodBinding foundMethod = null;//from w w w . ja va2 s.c o m MethodBinding foundProblem = null; boolean foundProblemVisible = false; Scope scope = this; int depth = 0; // in 1.4 mode (inherited visible shadows enclosing) CompilerOptions options; boolean inheritedHasPrecedence = (options = compilerOptions()).complianceLevel >= ClassFileConstants.JDK1_4; done: while (true) { // done when a COMPILATION_UNIT_SCOPE is found switch (scope.kind) { case METHOD_SCOPE: MethodScope methodScope = (MethodScope) scope; insideStaticContext |= methodScope.isStatic; insideConstructorCall |= methodScope.isConstructorCall; insideTypeAnnotation = methodScope.insideTypeAnnotation; break; case CLASS_SCOPE: ClassScope classScope = (ClassScope) scope; ReferenceBinding receiverType = classScope.enclosingReceiverType(); if (!insideTypeAnnotation) { // retrieve an exact visible match (if possible) // compilationUnitScope().recordTypeReference(receiverType); not needed since receiver is the source type MethodBinding methodBinding = classScope.findExactMethod(receiverType, selector, argumentTypes, invocationSite); if (methodBinding == null) methodBinding = classScope.findMethod(receiverType, selector, argumentTypes, invocationSite); if (methodBinding != null) { // skip it if we did not find anything if (foundMethod == null) { if (methodBinding.isValidBinding()) { if (!methodBinding.isStatic() && (insideConstructorCall || insideStaticContext)) { if (foundProblem != null && foundProblem.problemId() != ProblemReasons.NotVisible) return foundProblem; // takes precedence return new ProblemMethodBinding(methodBinding, // closest match methodBinding.selector, methodBinding.parameters, insideConstructorCall ? ProblemReasons.NonStaticReferenceInConstructorInvocation : ProblemReasons.NonStaticReferenceInStaticContext); } if (inheritedHasPrecedence || receiverType == methodBinding.declaringClass || (receiverType.getMethods(selector)) != Binding.NO_METHODS) { // found a valid method in the 'immediate' scope (i.e. not inherited) // OR in 1.4 mode (inherited visible shadows enclosing) // OR the receiverType implemented a method with the correct name // return the methodBinding if it is not declared in a superclass of the scope's binding (that is, inherited) if (foundProblemVisible) { return foundProblem; } if (depth > 0) { invocationSite.setDepth(depth); invocationSite.setActualReceiverType(receiverType); } // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type) if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS) && methodBinding.returnType.isParameterizedType()/*1.5*/) { return environment().createGetClassMethod(receiverType, methodBinding, this); } return methodBinding; } if (foundProblem == null || foundProblem.problemId() == ProblemReasons.NotVisible) { if (foundProblem != null) foundProblem = null; // only remember the methodBinding if its the first one found // remember that private methods are visible if defined directly by an enclosing class if (depth > 0) { invocationSite.setDepth(depth); invocationSite.setActualReceiverType(receiverType); } foundMethod = methodBinding; } } else { // methodBinding is a problem method if (methodBinding.problemId() != ProblemReasons.NotVisible && methodBinding.problemId() != ProblemReasons.NotFound) return methodBinding; // return the error now if (foundProblem == null) { foundProblem = methodBinding; // hold onto the first not visible/found error and keep the second not found if first is not visible } if (!foundProblemVisible && methodBinding.problemId() == ProblemReasons.NotFound) { MethodBinding closestMatch = ((ProblemMethodBinding) methodBinding).closestMatch; if (closestMatch != null && closestMatch.canBeSeenBy(receiverType, invocationSite, this)) { foundProblem = methodBinding; // hold onto the first not visible/found error and keep the second not found if first is not visible foundProblemVisible = true; } } } } else { // found a valid method so check to see if this is a hiding case if (methodBinding.problemId() == ProblemReasons.Ambiguous || (foundMethod.declaringClass != methodBinding.declaringClass && (receiverType == methodBinding.declaringClass || receiverType.getMethods(selector) != Binding.NO_METHODS))) // ambiguous case -> must qualify the method (javac generates an ambiguous error instead) // otherwise if a method was found, complain when another is found in an 'immediate' enclosing type (that is, not inherited) // NOTE: Unlike fields, a non visible method hides a visible method return new ProblemMethodBinding(methodBinding, // closest match selector, argumentTypes, ProblemReasons.InheritedNameHidesEnclosingName); } } } insideTypeAnnotation = false; depth++; insideStaticContext |= receiverType.isStatic(); // 1EX5I8Z - accessing outer fields within a constructor call is permitted // in order to do so, we change the flag as we exit from the type, not the method // itself, because the class scope is used to retrieve the fields. MethodScope enclosingMethodScope = scope.methodScope(); insideConstructorCall = enclosingMethodScope == null ? false : enclosingMethodScope.isConstructorCall; break; case COMPILATION_UNIT_SCOPE: break done; } scope = scope.parent; } if (insideStaticContext && options.sourceLevel >= ClassFileConstants.JDK1_5) { if (foundProblem != null) { if (foundProblem.declaringClass != null && foundProblem.declaringClass.id == TypeIds.T_JavaLangObject) return foundProblem; // static imports lose to methods from Object if (foundProblem.problemId() == ProblemReasons.NotFound && foundProblemVisible) { return foundProblem; // visible method selectors take precedence } } // at this point the scope is a compilation unit scope & need to check for imported static methods CompilationUnitScope unitScope = (CompilationUnitScope) scope; unitScope.faultInImports(); // field constants can cause static imports to be accessed before they're resolved ImportBinding[] imports = unitScope.imports; if (imports != null) { ObjectVector visible = null; boolean skipOnDemand = false; // set to true when matched static import of method name so stop looking for on demand methods for (int i = 0, length = imports.length; i < length; i++) { ImportBinding importBinding = imports[i]; if (importBinding.isStatic()) { Binding resolvedImport = importBinding.resolvedImport; MethodBinding possible = null; if (importBinding.onDemand) { if (!skipOnDemand && resolvedImport instanceof ReferenceBinding) // answers closest approximation, may not check argumentTypes or visibility possible = findMethod((ReferenceBinding) resolvedImport, selector, argumentTypes, invocationSite, true); } else { if (resolvedImport instanceof MethodBinding) { MethodBinding staticMethod = (MethodBinding) resolvedImport; if (CharOperation.equals(staticMethod.selector, selector)) // answers closest approximation, may not check argumentTypes or visibility possible = findMethod(staticMethod.declaringClass, selector, argumentTypes, invocationSite, true); } else if (resolvedImport instanceof FieldBinding) { // check to see if there are also methods with the same name FieldBinding staticField = (FieldBinding) resolvedImport; if (CharOperation.equals(staticField.name, selector)) { // must find the importRef's type again since the field can be from an inherited type char[][] importName = importBinding.reference.tokens; TypeBinding referencedType = getType(importName, importName.length - 1); if (referencedType != null) // answers closest approximation, may not check argumentTypes or visibility possible = findMethod((ReferenceBinding) referencedType, selector, argumentTypes, invocationSite, true); } } } if (possible != null && possible != foundProblem) { if (!possible.isValidBinding()) { if (foundProblem == null) foundProblem = possible; // answer as error case match } else if (possible.isStatic()) { MethodBinding compatibleMethod = computeCompatibleMethod(possible, argumentTypes, invocationSite); if (compatibleMethod != null) { if (compatibleMethod.isValidBinding()) { if (compatibleMethod.canBeSeenBy(unitScope.fPackage)) { if (visible == null || !visible.contains(compatibleMethod)) { ImportReference importReference = importBinding.reference; if (importReference != null) { importReference.bits |= ASTNode.Used; } if (!skipOnDemand && !importBinding.onDemand) { visible = null; // forget previous matches from on demand imports skipOnDemand = true; } if (visible == null) visible = new ObjectVector(3); visible.add(compatibleMethod); } } else if (foundProblem == null) { foundProblem = new ProblemMethodBinding(compatibleMethod, selector, compatibleMethod.parameters, ProblemReasons.NotVisible); } } else if (foundProblem == null) { foundProblem = compatibleMethod; } } else if (foundProblem == null) { foundProblem = new ProblemMethodBinding(possible, selector, argumentTypes, ProblemReasons.NotFound); } } } } } if (visible != null) { MethodBinding[] temp = new MethodBinding[visible.size]; visible.copyInto(temp); foundMethod = mostSpecificMethodBinding(temp, temp.length, argumentTypes, invocationSite, null); } } } if (foundMethod != null) { invocationSite.setActualReceiverType(foundMethod.declaringClass); return foundMethod; } if (foundProblem != null) return foundProblem; return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two) { TypeBinding[] oneParams = one.parameters; TypeBinding[] twoParams = two.parameters; int oneParamsLength = oneParams.length; int twoParamsLength = twoParams.length; if (oneParamsLength == twoParamsLength) { /* Below 1.5, discard any generics we have left in for the method verifier's benefit, (so it can detect method overriding properly in the presence of generic super types.) This is so as to allow us to determine whether we have been handed an acceptable method in 1.4 terms without all the 1.5isms below kicking in and spoiling the party. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 *//*from www . j a v a 2 s .c om*/ boolean applyErasure = environment().globalOptions.sourceLevel < ClassFileConstants.JDK1_5; next: for (int i = 0; i < oneParamsLength; i++) { TypeBinding oneParam = applyErasure ? oneParams[i].erasure() : oneParams[i]; TypeBinding twoParam = applyErasure ? twoParams[i].erasure() : twoParams[i]; if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) { if (two.declaringClass.isRawType()) continue next; TypeBinding leafComponentType = two.original().parameters[i].leafComponentType(); TypeBinding originalTwoParam = applyErasure ? leafComponentType.erasure() : leafComponentType; switch (originalTwoParam.kind()) { case Binding.TYPE_PARAMETER: if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds()) continue next; //$FALL-THROUGH$ case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: case Binding.PARAMETERIZED_TYPE: TypeBinding originalOneParam = one.original().parameters[i].leafComponentType(); switch (originalOneParam.kind()) { case Binding.TYPE: case Binding.GENERIC_TYPE: TypeBinding inheritedTwoParam = oneParam.findSuperTypeOriginatingFrom(twoParam); if (inheritedTwoParam == null || !inheritedTwoParam.leafComponentType().isRawType()) break; return false; case Binding.TYPE_PARAMETER: if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break; return false; case Binding.RAW_TYPE: // originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type return false; } } } else { if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) { TypeBinding eType = ((ArrayBinding) twoParam).elementsType(); if (oneParam == eType || oneParam.isCompatibleWith(eType)) return true; // special case to choose between 2 varargs methods when the last arg is Object[] } return false; } } return true; } if (one.isVarargs() && two.isVarargs()) { if (oneParamsLength > twoParamsLength) { // special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...) if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject) return false; } // check that each parameter before the vararg parameters are compatible (no autoboxing allowed here) for (int i = (oneParamsLength > twoParamsLength ? twoParamsLength : oneParamsLength) - 2; i >= 0; i--) if (oneParams[i] != twoParams[i] && !oneParams[i].isCompatibleWith(twoParams[i])) return false; if (parameterCompatibilityLevel(one, twoParams) == NOT_COMPATIBLE && parameterCompatibilityLevel(two, oneParams) == VARARGS_COMPATIBLE) return true; } return false; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
private TypeBinding lowerUpperBound(TypeBinding[] types, List lubStack) { int typeLength = types.length; if (typeLength == 1) { TypeBinding type = types[0];/*from www .ja va 2 s . c o m*/ return type == null ? TypeBinding.VOID : type; } // cycle detection int stackLength = lubStack.size(); nextLubCheck: for (int i = 0; i < stackLength; i++) { TypeBinding[] lubTypes = (TypeBinding[]) lubStack.get(i); int lubTypeLength = lubTypes.length; if (lubTypeLength < typeLength) continue nextLubCheck; nextTypeCheck: for (int j = 0; j < typeLength; j++) { TypeBinding type = types[j]; if (type == null) continue nextTypeCheck; // ignore for (int k = 0; k < lubTypeLength; k++) { TypeBinding lubType = lubTypes[k]; if (lubType == null) continue; // ignore if (lubType == type || lubType.isEquivalentTo(type)) continue nextTypeCheck; // type found, jump to next one } continue nextLubCheck; // type not found in current lubTypes } // all types are included in some lub, cycle detected - stop recursion by answering special value (int) return TypeBinding.INT; } lubStack.add(types); Map invocations = new HashMap(1); TypeBinding[] mecs = minimalErasedCandidates(types, invocations); if (mecs == null) return null; int length = mecs.length; if (length == 0) return TypeBinding.VOID; int count = 0; TypeBinding firstBound = null; int commonDim = -1; for (int i = 0; i < length; i++) { TypeBinding mec = mecs[i]; if (mec == null) continue; mec = leastContainingInvocation(mec, invocations.get(mec), lubStack); if (mec == null) return null; int dim = mec.dimensions(); if (commonDim == -1) { commonDim = dim; } else if (dim != commonDim) { // not all types have same dimension return null; } if (firstBound == null && !mec.leafComponentType().isInterface()) firstBound = mec.leafComponentType(); mecs[count++] = mec; // recompact them to the front } switch (count) { case 0: return TypeBinding.VOID; case 1: return mecs[0]; case 2: if ((commonDim == 0 ? mecs[1].id : mecs[1].leafComponentType().id) == TypeIds.T_JavaLangObject) return mecs[0]; if ((commonDim == 0 ? mecs[0].id : mecs[0].leafComponentType().id) == TypeIds.T_JavaLangObject) return mecs[1]; } TypeBinding[] otherBounds = new TypeBinding[count - 1]; int rank = 0; for (int i = 0; i < count; i++) { TypeBinding mec = commonDim == 0 ? mecs[i] : mecs[i].leafComponentType(); if (mec.isInterface()) { otherBounds[rank++] = mec; } } TypeBinding intersectionType = environment().createWildcard(null, 0, firstBound, otherBounds, Wildcard.EXTENDS); return commonDim == 0 ? intersectionType : environment().createArrayType(intersectionType, commonDim); }