List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding superInterfaces
@Override
public ReferenceBinding[] superInterfaces()
From source file:com.android.tools.lint.psi.EcjPsiJavaEvaluator.java
License:Apache License
/** Checks whether the given class extends or implements a class with the given name */ private static boolean isInheritor(@Nullable ReferenceBinding cls, @NonNull String name) { while (cls != null) { ReferenceBinding[] interfaces = cls.superInterfaces(); for (ReferenceBinding binding : interfaces) { if (isInheritor(binding, name)) { return true; }//from ww w. j a va2s .c o m } if (equalsCompound(name, cls.compoundName)) { return true; } try { cls = cls.superclass(); } catch (AbortCompilation ignore) { // Encountered symbol that couldn't be resolved (e.g. compiled class references // class not found on the classpath break; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private ReferenceBinding getMatchingSuper(ReferenceBinding binding) { if (binding == null) return null; ReferenceBinding superBinding = binding.superclass(); int level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, superBinding);/* w w w .java 2 s . c o m*/ if (level != IMPOSSIBLE_MATCH) return superBinding; // matches superclass if (!binding.isInterface() && !CharOperation.equals(binding.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { superBinding = getMatchingSuper(superBinding); if (superBinding != null) return superBinding; } // matches interfaces ReferenceBinding[] interfaces = binding.superInterfaces(); if (interfaces == null) return null; for (int i = 0; i < interfaces.length; i++) { level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, interfaces[i]); if (level != IMPOSSIBLE_MATCH) return interfaces[i]; superBinding = getMatchingSuper(interfaces[i]); if (superBinding != null) return superBinding; } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean matchOverriddenMethod(ReferenceBinding type, MethodBinding method, MethodBinding matchMethod) { if (type == null || this.pattern.selector == null) return false; // matches superclass if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { ReferenceBinding superClass = type.superclass(); if (superClass.isParameterizedType()) { MethodBinding[] methods = superClass.getMethods(this.pattern.selector); int length = methods.length; for (int i = 0; i < length; i++) { if (methods[i].areParametersEqual(method)) { if (matchMethod == null) { if (methodParametersEqualsPattern(methods[i].original())) return true; } else { if (methods[i].original().areParametersEqual(matchMethod)) return true; }//from w w w . ja v a 2 s . c o m } } } if (matchOverriddenMethod(superClass, method, matchMethod)) { return true; } } // matches interfaces ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; int iLength = interfaces.length; for (int i = 0; i < iLength; i++) { if (interfaces[i].isParameterizedType()) { MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector); int length = methods.length; for (int j = 0; j < length; j++) { if (methods[j].areParametersEqual(method)) { if (matchMethod == null) { if (methodParametersEqualsPattern(methods[j].original())) return true; } else { if (methods[j].original().areParametersEqual(matchMethod)) return true; } } } } if (matchOverriddenMethod(interfaces[i], method, matchMethod)) { return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
/** * Returns whether the given reference type binding matches or is a subtype of a type * that matches the given qualified pattern. * Returns ACCURATE_MATCH if it does./*from w ww . ja v a 2 s. co m*/ * Returns INACCURATE_MATCH if resolve fails * Returns IMPOSSIBLE_MATCH if it doesn't. */ protected int resolveLevelAsSubtype(char[] simplePattern, char[] qualifiedPattern, ReferenceBinding type, char[] methodName, TypeBinding[] argumentTypes, char[] packageName, boolean isDefault) { if (type == null) return INACCURATE_MATCH; int level = resolveLevelForType(simplePattern, qualifiedPattern, type); if (level != IMPOSSIBLE_MATCH) { if (isDefault && !CharOperation.equals(packageName, type.qualifiedPackageName())) { return IMPOSSIBLE_MATCH; } MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, methodName, argumentTypes); if (((method != null && !method.isAbstract()) || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden level |= OVERRIDDEN_METHOD_FLAVOR; } return level; } // matches superclass if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, type.superclass(), methodName, argumentTypes, packageName, isDefault); if (level != IMPOSSIBLE_MATCH) { if (argumentTypes != null) { // need to verify if method may be overridden MethodBinding method = getMethodBinding(type, methodName, argumentTypes); if (method != null) { // one method match in hierarchy if ((level & OVERRIDDEN_METHOD_FLAVOR) != 0) { // this method is already overridden on a super class, current match is impossible return IMPOSSIBLE_MATCH; } if (!method.isAbstract() && !type.isInterface()) { // store the fact that the method is overridden level |= OVERRIDDEN_METHOD_FLAVOR; } } } return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level } } // matches interfaces ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return INACCURATE_MATCH; for (int i = 0; i < interfaces.length; i++) { level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, interfaces[i], methodName, null, packageName, isDefault); if (level != IMPOSSIBLE_MATCH) { if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden level |= OVERRIDDEN_METHOD_FLAVOR; } return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level } } return IMPOSSIBLE_MATCH; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean resolveLevelAsSuperInvocation(ReferenceBinding type, TypeBinding[] argumentTypes, char[][][] superTypeNames, boolean methodAlreadyVerified) { char[][] compoundName = type.compoundName; for (int i = 0, max = superTypeNames.length; i < max; i++) { if (CharOperation.equals(superTypeNames[i], compoundName)) { // need to verify if the type implements the pattern method if (methodAlreadyVerified) return true; // already verified before enter into this method (see resolveLevel(MessageSend)) MethodBinding[] methods = type.getMethods(this.pattern.selector); for (int j = 0, length = methods.length; j < length; j++) { MethodBinding method = methods[j]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { boolean found = true; for (int k = 0, l = parameters.length; k < l; k++) { if (parameters[k].erasure() != argumentTypes[k].erasure()) { found = false; break; }/*from www.java2 s . c om*/ } if (found) { return true; } } } break; } } // If the given type is an interface then a common super interface may be found // in a parallel branch of the super hierarchy, so we need to verify all super interfaces. // If it's a class then there's only one possible branch for the hierarchy and // this branch has been already verified by the test above if (type.isInterface()) { ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; for (int i = 0; i < interfaces.length; i++) { if (resolveLevelAsSuperInvocation(interfaces[i], argumentTypes, superTypeNames, false)) { return true; } } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeNamesCollector.java
License:Open Source License
/** * Collects the names of all the supertypes of the given type. *//* ww w . java 2 s.co m*/ protected void collectSuperTypeNames(ReferenceBinding binding, char[][] path) { ReferenceBinding superclass = binding.superclass(); if (path != null && superclass != null) { boolean samePackage = addIfSamePackage(superclass.compoundName, path); if (!samePackage) path = null; } if (superclass != null) { addToResult(superclass.compoundName); collectSuperTypeNames(superclass, path); } ReferenceBinding[] interfaces = binding.superInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { ReferenceBinding interfaceBinding = interfaces[i]; addToResult(interfaceBinding.compoundName); collectSuperTypeNames(interfaceBinding, path); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeReferenceLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof ReferenceBinding)) return IMPOSSIBLE_MATCH; ReferenceBinding type = (ReferenceBinding) binding; int level = IMPOSSIBLE_MATCH; if (this.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES) { level = resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, type.superclass());/*from ww w . ja va 2 s . c o m*/ if (level == ACCURATE_MATCH) return ACCURATE_MATCH; } if (this.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_CLASSES) { ReferenceBinding[] superInterfaces = type.superInterfaces(); for (int i = 0, max = superInterfaces.length; i < max; i++) { int newLevel = resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, superInterfaces[i]); if (newLevel > level) { if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH; level = newLevel; } } } return level; }
From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java
License:Apache License
private boolean process(ReferenceBinding binding) { JDeclaredType type = (JDeclaredType) getType(binding); try {/*from w w w. ja v a 2s. c o m*/ // Create an override for getClass(). if (type instanceof JClassType && type != program.getTypeJavaLangObject()) { SourceInfo info = type.getSourceInfo().makeChild(); JMethod getClassMethod = program.createMethod(info, "getClass", type, program.getTypeJavaLangClass(), false, false, false, AccessModifier.PUBLIC, false); assert (type.getMethods().get(2) == getClassMethod); getClassMethod.freezeParamTypes(); getClassMethod.setSynthetic(); info.addCorrelation(info.getCorrelator().by(getClassMethod)); } if (binding.isNestedType() && !binding.isStatic() && !(binding instanceof BinaryTypeBinding)) { // TODO(tobyr) Do something here for binary types? // add synthetic fields for outer this and locals assert (type instanceof JClassType); NestedTypeBinding nestedBinding = (NestedTypeBinding) binding; if (nestedBinding.enclosingInstances != null) { for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) { SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i]; createField(arg, type, Disposition.THIS_REF); } } if (nestedBinding.outerLocalVariables != null) { for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) { SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i]; // See InnerClassTest.testOuterThisFromSuperCall(). boolean isReallyThisRef = false; if (arg.actualOuterLocalVariable instanceof SyntheticArgumentBinding) { SyntheticArgumentBinding outer = (SyntheticArgumentBinding) arg.actualOuterLocalVariable; if (outer.matchingField != null) { JField field = (JField) typeMap.get(outer.matchingField); if (field.isThisRef()) { isReallyThisRef = true; } } } createField(arg, type, isReallyThisRef ? Disposition.THIS_REF : Disposition.FINAL); } } } ReferenceBinding superClassBinding = binding.superclass(); if (type instanceof JClassType && superClassBinding != null) { // TODO: handle separately? assert (binding.superclass().isClass() || binding.superclass().isEnum()); JClassType superClass = (JClassType) getType(superClassBinding); ((JClassType) type).setSuperClass(superClass); } ReferenceBinding[] superInterfaces = binding.superInterfaces(); for (ReferenceBinding superInterfaceBinding : superInterfaces) { assert (superInterfaceBinding.isInterface()); JInterfaceType superInterface = (JInterfaceType) getType(superInterfaceBinding); type.addImplements(superInterface); } ReferenceBinding enclosingBinding = binding.enclosingType(); if (enclosingBinding != null) { type.setEnclosingType((JDeclaredType) getType(enclosingBinding)); } if (type instanceof JEnumType) { processEnumType(binding, (JEnumType) type); } return true; } catch (VirtualMachineError e) { // Always rethrow VM errors (an attempt to wrap may fail). throw e; } catch (InternalCompilerException ice) { ice.addNode(type); throw ice; } catch (Throwable e) { throw new InternalCompilerException(type, "Error building type map", e); } }
From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java
License:Apache License
public JType get(TypeBinding binding) { binding = binding.erasure();//from w w w.j a va2 s .c o m String key = JdtUtil.signature(binding); JReferenceType sourceType = sourceTypes.get(key); if (sourceType != null) { assert !sourceType.isExternal(); return sourceType; } JType type = types.get(key); if (type != null) { assert type instanceof JPrimitiveType || type == JNullType.INSTANCE || type.isExternal(); return type; } assert !(binding instanceof BaseTypeBinding); if (binding instanceof ArrayBinding) { ArrayBinding arrayBinding = (ArrayBinding) binding; JArrayType arrayType = new JArrayType(get(arrayBinding.elementsType())); if (arrayType.isExternal()) { types.put(key, arrayType); } else { sourceTypes.put(key, arrayType); } return arrayType; } else { ReferenceBinding refBinding = (ReferenceBinding) binding; JDeclaredType declType = createType(refBinding); try { if (declType instanceof JClassType) { ReferenceBinding superclass = refBinding.superclass(); if (superclass != null && superclass.isValidBinding()) { ((JClassType) declType).setSuperClass((JClassType) get(superclass)); } } ReferenceBinding[] superInterfaces = refBinding.superInterfaces(); if (superInterfaces != null) { for (ReferenceBinding intf : superInterfaces) { if (intf.isValidBinding()) { declType.addImplements((JInterfaceType) get(intf)); } } } } catch (AbortCompilation ignored) { /* * The currently-compiling unit has no errors; however, we're running * into a case where it references something with a bad hierarchy. This * doesn't cause an error in the current unit, but it does mean we run * into a wall here trying to construct the hierarchy. Catch the error * so that compilation can proceed; the error units themselves will * eventually cause the full compile to error out. */ } // Emulate clinit method for super clinit calls. JMethod clinit = new JMethod(SourceOrigin.UNKNOWN, GwtAstBuilder.CLINIT_NAME, declType, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); clinit.freezeParamTypes(); clinit.setSynthetic(); declType.addMethod(clinit); declType.setExternal(true); types.put(key, declType); return declType; } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTMethod.java
License:Open Source License
boolean isDefinedInSuperInterfaces(ReferenceBinding declaringType) { ReferenceBinding[] superInterfaces = declaringType.superInterfaces(); if (superInterfaces == null) { return false; }//from w w w . ja v a 2 s . c o m for (ReferenceBinding superInterface : superInterfaces) { if (isDefinedInType(superInterface)) { return true; } if (isDefinedInSuperInterfaces(superInterface)) { return true; } } return false; }