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

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.Binding#PARAMETERIZED_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: 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 2
Source File: PatchVal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static TypeBinding getForEachComponentType(Expression collection, BlockScope scope) {
	if (collection != null) {
		TypeBinding resolved = collection.resolvedType;
		if (resolved == null) resolved = collection.resolveType(scope);
		if (resolved == null) return null;
		if (resolved.isArrayType()) {
			resolved = ((ArrayBinding) resolved).elementsType();
			return resolved;
		} else if (resolved instanceof ReferenceBinding) {
			ReferenceBinding iterableType = ((ReferenceBinding)resolved).findSuperTypeOriginatingFrom(TypeIds.T_JavaLangIterable, false);
			
			TypeBinding[] arguments = null;
			if (iterableType != null) switch (iterableType.kind()) {
				case Binding.GENERIC_TYPE : // for (T t : Iterable<T>) - in case used inside Iterable itself
					arguments = iterableType.typeVariables();
					break;
				case Binding.PARAMETERIZED_TYPE : // for(E e : Iterable<E>)
					arguments = ((ParameterizedTypeBinding)iterableType).arguments;
					break;
				case Binding.RAW_TYPE : // for(Object e : Iterable)
					return null;
			}
			
			if (arguments != null && arguments.length == 1) {
				return arguments[0];
			}
		}
	}
	
	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: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ITypeBinding[] getTypeParameters() {
	if (this.prototype != null) {
		return this.prototype.getTypeParameters();
	}
	if (this.typeParameters != null) {
		return this.typeParameters;
	}
	switch(this.binding.kind()) {
		case Binding.RAW_TYPE :
		case Binding.PARAMETERIZED_TYPE :
			return this.typeParameters = NO_TYPE_BINDINGS;
	}
	TypeVariableBinding[] typeVariableBindings = this.binding.typeVariables();
	int typeVariableBindingsLength = typeVariableBindings == null ? 0 : typeVariableBindings.length;
	if (typeVariableBindingsLength != 0) {
		ITypeBinding[] newTypeParameters = new ITypeBinding[typeVariableBindingsLength];
		for (int i = 0; i < typeVariableBindingsLength; i++) {
			ITypeBinding typeBinding = this.resolver.getTypeBinding(typeVariableBindings[i]);
			if (typeBinding == null) {
				return this.typeParameters = NO_TYPE_BINDINGS;
			}
			newTypeParameters[i] = typeBinding;
		}
		return this.typeParameters = newTypeParameters;
	}
	return this.typeParameters = NO_TYPE_BINDINGS;
}
 
Example 5
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 6
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public String getName() {
	StringBuffer buffer;
	switch (this.binding.kind()) {

		case Binding.WILDCARD_TYPE :
		case Binding.INTERSECTION_TYPE:
			WildcardBinding wildcardBinding = (WildcardBinding) this.binding;
			buffer = new StringBuffer();
			buffer.append(TypeConstants.WILDCARD_NAME);
			if (wildcardBinding.bound != null) {
				switch(wildcardBinding.boundKind) {
			        case Wildcard.SUPER :
			        	buffer.append(TypeConstants.WILDCARD_SUPER);
			            break;
			        case Wildcard.EXTENDS :
			        	buffer.append(TypeConstants.WILDCARD_EXTENDS);
				}
				buffer.append(getBound().getName());
			}
			return String.valueOf(buffer);

		case Binding.TYPE_PARAMETER :
			if (isCapture()) {
				return NO_NAME;
			}
			TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this.binding;
			return new String(typeVariableBinding.sourceName);

		case Binding.PARAMETERIZED_TYPE :
			ParameterizedTypeBinding parameterizedTypeBinding = (ParameterizedTypeBinding) this.binding;
			buffer = new StringBuffer();
			buffer.append(parameterizedTypeBinding.sourceName());
			ITypeBinding[] tArguments = getTypeArguments();
			final int typeArgumentsLength = tArguments.length;
			if (typeArgumentsLength != 0) {
				buffer.append('<');
				for (int i = 0; i < typeArgumentsLength; i++) {
					if (i > 0) {
						buffer.append(',');
					}
					buffer.append(tArguments[i].getName());
				}
				buffer.append('>');
			}
			return String.valueOf(buffer);

		case Binding.RAW_TYPE :
			return getTypeDeclaration().getName();

		case Binding.ARRAY_TYPE :
			ITypeBinding elementType = getElementType();
			if (elementType.isLocal() || elementType.isAnonymous() || elementType.isCapture()) {
				return NO_NAME;
			}
			int dimensions = getDimensions();
			char[] brackets = new char[dimensions * 2];
			for (int i = dimensions * 2 - 1; i >= 0; i -= 2) {
				brackets[i] = ']';
				brackets[i - 1] = '[';
			}
			buffer = new StringBuffer(elementType.getName());
			buffer.append(brackets);
			return String.valueOf(buffer);

		default :
			if (isPrimitive() || isNullType()) {
				BaseTypeBinding baseTypeBinding = (BaseTypeBinding) this.binding;
				return new String(baseTypeBinding.simpleName);
			}
			if (isAnonymous()) {
				return NO_NAME;
			}
			return new String(this.binding.sourceName());
	}
}
 
Example 7
Source File: UnionTypeReference.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) {
	// return the lub (least upper bound of all type binding) 
	int length = this.typeReferences.length;
	TypeBinding[] allExceptionTypes = new TypeBinding[length];
	boolean hasError = false;
	for (int i = 0; i < length; i++) {
		TypeBinding exceptionType = this.typeReferences[i].resolveType(scope, checkBounds, location);
		if (exceptionType == null) {
			return null;
		}
		switch(exceptionType.kind()) {
			case Binding.PARAMETERIZED_TYPE :
				if (exceptionType.isBoundParameterizedType()) {
					hasError = true;
					scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this.typeReferences[i]);
					// fall thru to create the variable - avoids additional errors because the variable is missing
				}
				break;
			case Binding.TYPE_PARAMETER :
				scope.problemReporter().invalidTypeVariableAsException(exceptionType, this.typeReferences[i]);
				hasError = true;
				// fall thru to create the variable - avoids additional errors because the variable is missing
				break;
		}
		if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null
				&& exceptionType.isValidBinding()) {
			scope.problemReporter().cannotThrowType(this.typeReferences[i], exceptionType);
			hasError = true;
		}
		allExceptionTypes[i] = exceptionType;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486, ensure types are of union type.
		for (int j = 0; j < i; j++) {
			if (allExceptionTypes[j].isCompatibleWith(exceptionType)) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[j],
						allExceptionTypes[j],
						exceptionType);
				hasError = true;
			} else if (exceptionType.isCompatibleWith(allExceptionTypes[j])) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[i],
						exceptionType,
						allExceptionTypes[j]);
				hasError = true;
			}
		}
	}
	if (hasError) {
		return null;
	}
	// compute lub
	return (this.resolvedType = scope.lowerUpperBound(allExceptionTypes));
}