Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#superclass()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#superclass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
/** Computes the super method, if any, given a method binding */ private static MethodBinding findSuperMethodBinding(@NonNull MethodBinding binding) { try { ReferenceBinding superclass = binding.declaringClass.superclass(); while (superclass != null) { MethodBinding[] methods = superclass.getMethods(binding.selector, binding.parameters.length); for (MethodBinding method : methods) { if (method.areParameterErasuresEqual(binding)) { return method; } } superclass = superclass.superclass(); } } catch (Exception ignore) { // Work around ECJ bugs; see https://code.google.com/p/android/issues/detail?id=172268 } return null; }
Example 2
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@Override public boolean isSubclassOf(@NonNull String name, boolean strict) { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; if (strict) { cls = cls.superclass(); } for (; cls != null; cls = cls.superclass()) { if (sameChars(name, cls.readableName())) { return true; } } } return false; }
Example 3
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public ResolvedField getField(@NonNull String name, boolean includeInherited) { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; while (cls != null) { FieldBinding[] fields = cls.fields(); if (fields != null) { for (FieldBinding field : fields) { if (sameChars(name, field.name)) { return new EcjResolvedField(field); } } } if (includeInherited) { cls = cls.superclass(); } else { break; } } } return null; }
Example 4
Source File: TypesImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public List<? extends TypeMirror> directSupertypes(TypeMirror t) { switch(t.getKind()) { case PACKAGE : case EXECUTABLE : throw new IllegalArgumentException("Invalid type mirror for directSupertypes"); //$NON-NLS-1$ default: break; } TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) t; Binding binding = typeMirrorImpl._binding; if (binding instanceof ReferenceBinding) { ReferenceBinding referenceBinding = (ReferenceBinding) binding; ArrayList<TypeMirror> list = new ArrayList<TypeMirror>(); ReferenceBinding superclass = referenceBinding.superclass(); if (superclass != null) { list.add(this._env.getFactory().newTypeMirror(superclass)); } for (ReferenceBinding interfaceBinding : referenceBinding.superInterfaces()) { list.add(this._env.getFactory().newTypeMirror(interfaceBinding)); } return Collections.unmodifiableList(list); } return Collections.emptyList(); }
Example 5
Source File: RoundEnvImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Check whether an element has a superclass that is annotated with an @Inherited annotation. * @param element must be a class (not an interface, enum, etc.). * @param anno must be an annotation type, and must be @Inherited * @return true if element has a superclass that is annotated with anno */ private boolean inheritsAnno(ReferenceBinding element, ReferenceBinding anno) { ReferenceBinding searchedElement = element; do { if (searchedElement instanceof ParameterizedTypeBinding) { searchedElement = ((ParameterizedTypeBinding) searchedElement).genericType(); } AnnotationBinding[] annos = Factory.getPackedAnnotationBindings(searchedElement.getAnnotations()); for (AnnotationBinding annoBinding : annos) { if (annoBinding.getAnnotationType() == anno) { //$IDENTITY-COMPARISON$ // element is annotated with anno return true; } } } while (null != (searchedElement = searchedElement.superclass())); return false; }
Example 6
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public ResolvedClass getSuperClass() { if (mBinding instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) mBinding; ReferenceBinding superClass = refBinding.superclass(); if (superClass != null) { return new EcjResolvedClass(superClass); } } return null; }
Example 7
Source File: ElementsImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Compute a list of all the visible entities in this type. Specifically: * <ul> * <li>All nested types declared in this type, including interfaces and enums</li> * <li>All protected or public nested types declared in this type's superclasses * and superinterfaces, that are not hidden by a name collision</li> * <li>All methods declared in this type, including constructors but not * including static or instance initializers, and including abstract * methods and unimplemented methods declared in interfaces</li> * <li>All protected or public methods declared in this type's superclasses, * that are not overridden by another method, but not including constructors * or initializers. Includes abstract methods and methods declared in * superinterfaces but not implemented</li> * <li>All fields declared in this type, including constants</li> * <li>All non-private fields declared in this type's superclasses and * superinterfaces, that are not hidden by a name collision.</li> * </ul> */ @Override public List<? extends Element> getAllMembers(TypeElement type) { if (null == type || !(type instanceof TypeElementImpl)) { return Collections.emptyList(); } ReferenceBinding binding = (ReferenceBinding)((TypeElementImpl)type)._binding; // Map of element simple name to binding Map<String, ReferenceBinding> types = new HashMap<String, ReferenceBinding>(); // Javac implementation does not take field name collisions into account List<FieldBinding> fields = new ArrayList<FieldBinding>(); // For methods, need to compare parameters, not just names Map<String, Set<MethodBinding>> methods = new HashMap<String, Set<MethodBinding>>(); Set<ReferenceBinding> superinterfaces = new LinkedHashSet<ReferenceBinding>(); boolean ignoreVisibility = true; while (null != binding) { addMembers(binding, ignoreVisibility, types, fields, methods); Set<ReferenceBinding> newfound = new LinkedHashSet<ReferenceBinding>(); collectSuperInterfaces(binding, superinterfaces, newfound); for (ReferenceBinding superinterface : newfound) { addMembers(superinterface, false, types, fields, methods); } superinterfaces.addAll(newfound); binding = binding.superclass(); ignoreVisibility = false; } List<Element> allMembers = new ArrayList<Element>(); for (ReferenceBinding nestedType : types.values()) { allMembers.add(_env.getFactory().newElement(nestedType)); } for (FieldBinding field : fields) { allMembers.add(_env.getFactory().newElement(field)); } for (Set<MethodBinding> sameNamedMethods : methods.values()) { for (MethodBinding method : sameNamedMethods) { allMembers.add(_env.getFactory().newElement(method)); } } return allMembers; }
Example 8
Source File: TypeElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public TypeMirror getSuperclass() { ReferenceBinding binding = (ReferenceBinding)_binding; ReferenceBinding superBinding = binding.superclass(); if (null == superBinding || binding.isInterface()) { return _env.getFactory().getNoType(TypeKind.NONE); } // superclass of a type must be a DeclaredType return _env.getFactory().newTypeMirror(superBinding); }
Example 9
Source File: SuperReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType(); if (!checkAccess(scope, enclosingReceiverType)) return null; if (enclosingReceiverType.id == T_JavaLangObject) { scope.problemReporter().cannotUseSuperInJavaLangObject(this); return null; } return this.resolvedType = enclosingReceiverType.superclass(); }
Example 10
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void searchVisibleMethods( ReferenceBinding receiverType, Scope scope, InvocationSite invocationSite, Scope invocationScope, boolean onlyStaticMethods, boolean notInJavadoc, ObjectVector methodsFound) { ReferenceBinding currentType = receiverType; if (notInJavadoc) { if (receiverType.isInterface()) { searchVisibleInterfaceMethods( new ReferenceBinding[]{currentType}, receiverType, scope, invocationSite, invocationScope, onlyStaticMethods, methodsFound); currentType = scope.getJavaLangObject(); } } boolean hasPotentialDefaultAbstractMethods = true; while (currentType != null) { MethodBinding[] methods = currentType.availableMethods(); if (methods != null) { searchVisibleLocalMethods( methods, receiverType, scope, invocationSite, invocationScope, onlyStaticMethods, methodsFound); } if (notInJavadoc && hasPotentialDefaultAbstractMethods && (currentType.isAbstract() || currentType.isTypeVariable() || currentType.isIntersectionType() || currentType.isEnum())){ ReferenceBinding[] superInterfaces = currentType.superInterfaces(); if (superInterfaces != null && currentType.isIntersectionType()) { for (int i = 0; i < superInterfaces.length; i++) { superInterfaces[i] = (ReferenceBinding)superInterfaces[i].capture(invocationScope, invocationSite.sourceEnd()); } } searchVisibleInterfaceMethods( superInterfaces, receiverType, scope, invocationSite, invocationScope, onlyStaticMethods, methodsFound); } else { hasPotentialDefaultAbstractMethods = false; } if(currentType.isParameterizedType()) { currentType = ((ParameterizedTypeBinding)currentType).genericType().superclass(); } else { currentType = currentType.superclass(); } } }
Example 11
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(FieldBinding fieldBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (fieldBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (fieldBinding.isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the receiverType is the invocationType or its subclass // OR the field is a static field accessed directly through a type if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (invocationType.fPackage == fieldBinding.declaringClass.fPackage) return true; if (fieldBinding.declaringClass.isSuperclassOf(invocationType)) { if (invocationSite.isSuperAccess()) return true; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; if (invocationType.isSuperclassOf((ReferenceBinding) receiverType)) return true; if (fieldBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (fieldBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, fieldBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, fieldBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = fieldBinding.declaringClass; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } if (TypeBinding.notEquals(outerInvocationType, outerDeclaringClass)) return false; } return true; } // isDefault() if (invocationType.fPackage != fieldBinding.declaringClass.fPackage) return false; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; ReferenceBinding type = (ReferenceBinding) receiverType; PackageBinding declaringPackage = fieldBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = fieldBinding.declaringClass .original(); do { if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 if (TypeBinding.equalsEquals(originalDeclaringClass, type.erasure().original())) return true; } else { if (TypeBinding.equalsEquals(originalDeclaringClass, type.original())) return true; } if (declaringPackage != type.fPackage) return false; } while ((type = type.superclass()) != null); return false; }
Example 12
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(MethodBinding methodBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (methodBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (methodBinding.isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the receiverType is the invocationType or its subclass // OR the method is a static method accessed directly through a type if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (invocationType.fPackage == methodBinding.declaringClass.fPackage) return true; if (methodBinding.declaringClass.isSuperclassOf(invocationType)) { if (invocationSite.isSuperAccess()) return true; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; if (invocationType.isSuperclassOf((ReferenceBinding) receiverType)) return true; if (methodBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (methodBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, methodBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, methodBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = methodBinding.declaringClass; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } if (TypeBinding.notEquals(outerInvocationType, outerDeclaringClass)) return false; } return true; } // isDefault() if (invocationType.fPackage != methodBinding.declaringClass.fPackage) return false; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; ReferenceBinding type = (ReferenceBinding) receiverType; PackageBinding declaringPackage = methodBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = methodBinding.declaringClass .original(); do { if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 if (TypeBinding.equalsEquals(originalDeclaringClass, type.erasure().original())) return true; } else { if (TypeBinding.equalsEquals(originalDeclaringClass, type.original())) return true; } if (declaringPackage != type.fPackage) return false; } while ((type = type.superclass()) != null); return false; }
Example 13
Source File: IntersectionCastTypeReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int location) { int length = this.typeReferences.length; ReferenceBinding[] intersectingTypes = new ReferenceBinding[length]; boolean hasError = false; int typeCount = 0; nextType: for (int i = 0; i < length; i++) { final TypeReference typeReference = this.typeReferences[i]; TypeBinding type = typeReference.resolveType(scope, checkBounds, location); if (type == null || ((type.tagBits & TagBits.HasMissingType) != 0)) { hasError = true; continue; } if (i == 0) { if (type.isBaseType()) { // rejected in grammar for i > 0 scope.problemReporter().onlyReferenceTypesInIntersectionCast(typeReference); hasError = true; continue; } if (type.isArrayType()) { // javac rejects the pedantic cast: (X[] & Serializable & Cloneable) new X[0], what is good for the goose ... scope.problemReporter().illegalArrayTypeInIntersectionCast(typeReference); hasError = true; continue; } } else if (!type.isInterface()) { scope.problemReporter().boundMustBeAnInterface(typeReference, type); hasError = true; continue; } for (int j = 0; j < typeCount; j++) { final ReferenceBinding priorType = intersectingTypes[j]; if (TypeBinding.equalsEquals(priorType, type)) { scope.problemReporter().duplicateBoundInIntersectionCast(typeReference); hasError = true; continue; } if (!priorType.isInterface()) continue; if (TypeBinding.equalsEquals(type.findSuperTypeOriginatingFrom(priorType), priorType)) { intersectingTypes[j] = (ReferenceBinding) type; continue nextType; } if (TypeBinding.equalsEquals(priorType.findSuperTypeOriginatingFrom(type), type)) continue nextType; } intersectingTypes[typeCount++] = (ReferenceBinding) type; } if (hasError) { return null; } if (typeCount != length) { if (typeCount == 1) { return this.resolvedType = intersectingTypes[0]; } System.arraycopy(intersectingTypes, 0, intersectingTypes = new ReferenceBinding[typeCount], 0, typeCount); } IntersectionCastTypeBinding intersectionType = (IntersectionCastTypeBinding) scope.environment().createIntersectionCastType(intersectingTypes); // check for parameterized interface collisions (when different parameterizations occur) ReferenceBinding itsSuperclass = null; ReferenceBinding[] interfaces = intersectingTypes; ReferenceBinding firstType = intersectingTypes[0]; if (firstType.isClass()) { itsSuperclass = firstType.superclass(); System.arraycopy(intersectingTypes, 1, interfaces = new ReferenceBinding[typeCount - 1], 0, typeCount - 1); } Map invocations = new HashMap(2); nextInterface: for (int i = 0, interfaceCount = interfaces.length; i < interfaceCount; i++) { ReferenceBinding one = interfaces[i]; if (one == null) continue nextInterface; if (itsSuperclass != null && scope.hasErasedCandidatesCollisions(itsSuperclass, one, invocations, intersectionType, this)) continue nextInterface; nextOtherInterface: for (int j = 0; j < i; j++) { ReferenceBinding two = interfaces[j]; if (two == null) continue nextOtherInterface; if (scope.hasErasedCandidatesCollisions(one, two, invocations, intersectionType, this)) continue nextInterface; } } if ((intersectionType.tagBits & TagBits.HierarchyHasProblems) != 0) return null; return (this.resolvedType = intersectionType); }