Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#isInterface()

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#isInterface() . 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: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ElementKind getKind() {
	if (null != _kindHint) {
		return _kindHint;
	}
	ReferenceBinding refBinding = (ReferenceBinding)_binding;
	// The order of these comparisons is important: e.g., enum is subset of class
	if (refBinding.isEnum()) {
		return ElementKind.ENUM;
	}
	else if (refBinding.isAnnotationType()) {
		return ElementKind.ANNOTATION_TYPE;
	}
	else if (refBinding.isInterface()) {
		return ElementKind.INTERFACE;
	}
	else if (refBinding.isClass()) {
		return ElementKind.CLASS;
	}
	else {
		throw new IllegalArgumentException("TypeElement " + new String(refBinding.shortReadableName()) +  //$NON-NLS-1$
				" has unexpected attributes " + refBinding.modifiers); //$NON-NLS-1$
	}
}
 
Example 2
Source File: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<Modifier> getModifiers()
{
	ReferenceBinding refBinding = (ReferenceBinding)_binding;
	int modifiers = refBinding.modifiers;
	if (refBinding.isInterface() && refBinding.isNestedType()) {
		modifiers |= ClassFileConstants.AccStatic;
	}
	return Factory.getModifiers(modifiers, getKind(), refBinding.isBinaryBinding());
}
 
Example 3
Source File: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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 4
Source File: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
	MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, null);
	if (exactMethod != null){
		if (receiverType.isInterface() || canBeSeenByForCodeSnippet(exactMethod, receiverType, invocationSite, this))
			return exactMethod;
	}
	return null;
}
 
Example 5
Source File: Expression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void getAllInheritedMethods0(ReferenceBinding binding, ArrayList<MethodBinding> collector) {
	if (!binding.isInterface()) return;
	MethodBinding[] methodBindings = binding.methods();
	for (int i = 0, max = methodBindings.length; i < max; i++) {
		collector.add(methodBindings[i]);
	}
	ReferenceBinding[] superInterfaces = binding.superInterfaces();
	for (int i = 0, max = superInterfaces.length; i < max; i++) {
		getAllInheritedMethods0(superInterfaces[i], collector);
	}
}
 
Example 6
Source File: InternalExtendedCompletionContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 7
Source File: IntersectionCastTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
	}