Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.Binding#BASE_TYPE

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.Binding#BASE_TYPE . 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: RecoveredTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IPackageBinding getPackage() {
	if (this.binding != null) {
		switch (this.binding.kind()) {
			case Binding.BASE_TYPE :
			case Binding.ARRAY_TYPE :
			case Binding.TYPE_PARAMETER : // includes capture scenario
			case Binding.WILDCARD_TYPE :
			case Binding.INTERSECTION_TYPE:
				return null;
		}
		IPackageBinding packageBinding = this.resolver.getPackageBinding(this.binding.getPackage());
		if (packageBinding != null) return packageBinding;
	}
	if (this.innerTypeBinding != null && this.dimensions > 0) {
		return null;
	}
	CompilationUnitScope scope = this.resolver.scope();
	if (scope != null) {
		return this.resolver.getPackageBinding(scope.getCurrentPackage());
	}
	return null;
}
 
Example 2
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
	switch (binding.kind()) {
		case Binding.PACKAGE:
			return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
		case Binding.TYPE:
		case Binding.BASE_TYPE:
		case Binding.GENERIC_TYPE:
		case Binding.PARAMETERIZED_TYPE:
		case Binding.RAW_TYPE:
			return getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
		case Binding.ARRAY_TYPE:
		case Binding.TYPE_PARAMETER:
			return new TypeBinding(this, (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
		case Binding.METHOD:
			return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) binding);
		case Binding.FIELD:
		case Binding.LOCAL:
			return getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
	}
	return null;
}
 
Example 3
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new element that knows what kind it is even if the binding is unresolved.
 */
public Element newElement(Binding binding, ElementKind kindHint) {
	if (binding == null)
		return null;
	switch (binding.kind()) {
	case Binding.FIELD:
	case Binding.LOCAL:
	case Binding.VARIABLE:
		return new VariableElementImpl(_env, (VariableBinding) binding);
	case Binding.TYPE:
	case Binding.GENERIC_TYPE:
		ReferenceBinding referenceBinding = (ReferenceBinding)binding;
		if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) {
			return new ErrorTypeElement(this._env, referenceBinding);
		}
		if (CharOperation.equals(referenceBinding.sourceName, TypeConstants.PACKAGE_INFO_NAME)) {
			return new PackageElementImpl(_env, referenceBinding.fPackage);
		}
		return new TypeElementImpl(_env, referenceBinding, kindHint);
	case Binding.METHOD:
		return new ExecutableElementImpl(_env, (MethodBinding)binding);
	case Binding.RAW_TYPE:
	case Binding.PARAMETERIZED_TYPE:
		return new TypeElementImpl(_env, ((ParameterizedTypeBinding)binding).genericType(), kindHint);
	case Binding.PACKAGE:
		return new PackageElementImpl(_env, (PackageBinding)binding);
	case Binding.TYPE_PARAMETER:
		return new TypeParameterElementImpl(_env, (TypeVariableBinding)binding);
		// TODO: fill in the rest of these
	case Binding.IMPORT:
	case Binding.ARRAY_TYPE:
	case Binding.BASE_TYPE:
	case Binding.WILDCARD_TYPE:
	case Binding.INTERSECTION_TYPE:
		throw new UnsupportedOperationException("NYI: binding type " + binding.kind()); //$NON-NLS-1$
	}
	return null;
}
 
Example 4
Source File: TypesImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return true if t1 is a subtype of t2, or if t1 == t2.
 */
@Override
public boolean isSubtype(TypeMirror t1, TypeMirror t2) {
	if (t1 instanceof NoTypeImpl) {
		if (t2 instanceof NoTypeImpl) {
			return ((NoTypeImpl) t1).getKind() == ((NoTypeImpl) t2).getKind();
		}
		return false;
	} else if (t2 instanceof NoTypeImpl) {
		return false;
	}
    if (!(t1 instanceof TypeMirrorImpl) || !(t2 instanceof TypeMirrorImpl)) {
        return false;
    }
    if (t1 == t2) {
        return true;
    }
    Binding b1 = ((TypeMirrorImpl)t1).binding();
    Binding b2 = ((TypeMirrorImpl)t2).binding();
    if (b1 == b2) {
        return true;
    }
    if (!(b1 instanceof TypeBinding) || !(b2 instanceof TypeBinding)) {
        // package, method, import, etc.
        return false;
    }
    if (b1.kind() == Binding.BASE_TYPE || b2.kind() == Binding.BASE_TYPE) {
        if (b1.kind() != b2.kind()) {
            return false;
        }
        else {
            // for primitives, compatibility implies subtype
            return ((TypeBinding)b1).isCompatibleWith((TypeBinding)b2);
        }
    }
    return ((TypeBinding)b1).isCompatibleWith((TypeBinding)b2);
}
 
Example 5
Source File: TypesImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public PrimitiveType unboxedType(TypeMirror t) {
    if (!(((TypeMirrorImpl)t)._binding instanceof ReferenceBinding)) {
        // Not an unboxable type - could be primitive, array, not a type at all, etc.
        throw new IllegalArgumentException("Given type mirror cannot be unboxed"); //$NON-NLS-1$
    }
    ReferenceBinding boxed = (ReferenceBinding)((TypeMirrorImpl)t)._binding;
    TypeBinding unboxed = _env.getLookupEnvironment().computeBoxingType(boxed);
    if (unboxed.kind() != Binding.BASE_TYPE) {
        // No boxing conversion was found
        throw new IllegalArgumentException();
    }
    return (PrimitiveType) _env.getFactory().newTypeMirror((BaseTypeBinding)unboxed);
}
 
Example 6
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IPackageBinding getPackage() {
	switch (this.binding.kind()) {
		case Binding.BASE_TYPE :
		case Binding.ARRAY_TYPE :
		case Binding.TYPE_PARAMETER : // includes capture scenario
		case Binding.WILDCARD_TYPE :
		case Binding.INTERSECTION_TYPE:
		case Binding.INTERSECTION_CAST_TYPE:
			return null;
	}
	ReferenceBinding referenceBinding = (ReferenceBinding) this.binding;
	return this.resolver.getPackageBinding(referenceBinding.getPackage());
}
 
Example 7
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public synchronized ITypeBinding getSuperclass() {
	if (this.binding == null)
		return null;
	switch (this.binding.kind()) {
		case Binding.ARRAY_TYPE :
		case Binding.BASE_TYPE :
			return null;
		default:
			// no superclass for interface types (interface | annotation type)
			if (this.binding.isInterface())
				return null;
	}
	ReferenceBinding superclass = null;
	try {
		superclass = ((ReferenceBinding)this.binding).superclass();
	} catch (RuntimeException e) {
		/* in case a method cannot be resolvable due to missing jars on the classpath
		 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=57871
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
		 */
		org.eclipse.jdt.internal.core.util.Util.log(e, "Could not retrieve superclass"); //$NON-NLS-1$
		return this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	}
	if (superclass == null) {
		return null;
	}
	return this.resolver.getTypeBinding(superclass);
}
 
Example 8
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Given a binding of uncertain type, try to create the right sort of TypeMirror for it.
 */
public TypeMirror newTypeMirror(Binding binding) {
	switch (binding.kind()) {
	case Binding.FIELD:
	case Binding.LOCAL:
	case Binding.VARIABLE:
		// For variables, return the type of the variable
		return newTypeMirror(((VariableBinding)binding).type);
		
	case Binding.PACKAGE:
		return getNoType(TypeKind.PACKAGE);
		
	case Binding.IMPORT:
		throw new UnsupportedOperationException("NYI: import type " + binding.kind()); //$NON-NLS-1$

	case Binding.METHOD:
		return new ExecutableTypeImpl(_env, (MethodBinding) binding);
		
	case Binding.TYPE:
	case Binding.RAW_TYPE:
	case Binding.GENERIC_TYPE:
	case Binding.PARAMETERIZED_TYPE:
		ReferenceBinding referenceBinding = (ReferenceBinding) binding;
		if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) {
			return getErrorType(referenceBinding);
		}
		return new DeclaredTypeImpl(_env, (ReferenceBinding)binding);
		
	case Binding.ARRAY_TYPE:
		return new ArrayTypeImpl(_env, (ArrayBinding)binding);
		
	case Binding.BASE_TYPE:
		BaseTypeBinding btb = (BaseTypeBinding)binding;
		switch (btb.id) {
			case TypeIds.T_void:
				return getNoType(TypeKind.VOID);
			case TypeIds.T_null:
				return getNullType();
			default:
				return getPrimitiveType(btb);
		}

	case Binding.WILDCARD_TYPE:
	case Binding.INTERSECTION_TYPE: // TODO compatible, but shouldn't it really be an intersection type?
		return new WildcardTypeImpl(_env, (WildcardBinding) binding);

	case Binding.TYPE_PARAMETER:
		return new TypeVariableImpl(_env, (TypeVariableBinding) binding);
	}
	return null;
}
 
Example 9
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public synchronized ITypeBinding[] getInterfaces() {
	if (this.prototype != null) {
		return this.prototype.getInterfaces();
	}
	if (this.interfaces != null) {
		return this.interfaces;
	}
	if (this.binding == null)
		return this.interfaces = NO_TYPE_BINDINGS;
	switch (this.binding.kind()) {
		case Binding.ARRAY_TYPE :
		case Binding.BASE_TYPE :
			return this.interfaces = NO_TYPE_BINDINGS;
	}
	ReferenceBinding referenceBinding = (ReferenceBinding) this.binding;
	ReferenceBinding[] internalInterfaces = null;
	try {
		internalInterfaces = referenceBinding.superInterfaces();
	} catch (RuntimeException e) {
		/* in case a method cannot be resolvable due to missing jars on the classpath
		 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=57871
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
		 */
		org.eclipse.jdt.internal.core.util.Util.log(e, "Could not retrieve interfaces"); //$NON-NLS-1$
	}
	int length = internalInterfaces == null ? 0 : internalInterfaces.length;
	if (length != 0) {
		ITypeBinding[] newInterfaces = new ITypeBinding[length];
		int interfacesCounter = 0;
		for (int i = 0; i < length; i++) {
			ITypeBinding typeBinding = this.resolver.getTypeBinding(internalInterfaces[i]);
			if (typeBinding == null) {
				continue;
			}
			newInterfaces[interfacesCounter++] = typeBinding;
		}
		if (length != interfacesCounter) {
			System.arraycopy(newInterfaces, 0, (newInterfaces = new ITypeBinding[interfacesCounter]), 0, interfacesCounter);
		}
		return this.interfaces = newInterfaces;
	}
	return this.interfaces = NO_TYPE_BINDINGS;
}