Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#isRawType()

The following examples show how to use org.eclipse.jdt.core.dom.ITypeBinding#isRawType() . 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: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the appropriate ParameterizedType node. Recursion is needed to
 * handle the nested case (e.g., Vector<Vector<String>>).
 * @param ast
 * @param typeBinding
 * @return the created type
 */
private Type createParameterizedType(AST ast, ITypeBinding typeBinding){
	if (typeBinding.isParameterizedType() && !typeBinding.isRawType()){
		Type baseType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeBinding.getErasure().getName()));
		ParameterizedType newType= ast.newParameterizedType(baseType);
		for (int i=0; i < typeBinding.getTypeArguments().length; i++){
			ITypeBinding typeArg= typeBinding.getTypeArguments()[i];
			Type argType= createParameterizedType(ast, typeArg); // recursive call
			newType.typeArguments().add(argType);
		}
		return newType;
	} else {
		if (!typeBinding.isTypeVariable()){
			return ast.newSimpleType(ASTNodeFactory.newName(ast, typeBinding.getErasure().getName()));
		} else {
			return ast.newSimpleType(ast.newSimpleName(typeBinding.getName()));
		}
	}
}
 
Example 2
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static Set<ITypeBinding> getTypeBoundsForSubsignature(ITypeBinding typeParameter) {
	ITypeBinding[] typeBounds= typeParameter.getTypeBounds();
	int count= typeBounds.length;
	if (count == 0)
		return Collections.emptySet();

	Set<ITypeBinding> result= new HashSet<ITypeBinding>(typeBounds.length);
	for (int i= 0; i < typeBounds.length; i++) {
		ITypeBinding bound= typeBounds[i];
		if ("java.lang.Object".equals(typeBounds[0].getQualifiedName())) //$NON-NLS-1$
			continue;
		else if (containsTypeVariables(bound))
			result.add(bound.getErasure()); // try to achieve effect of "rename type variables"
		else if (bound.isRawType())
			result.add(bound.getTypeDeclaration());
		else
			result.add(bound);
	}
	return result;
}
 
Example 3
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ASTNode getNewQualifiedNameNode(ITypeBinding[] parameters, Name name) {
	final AST ast= name.getAST();
	boolean raw= false;
	final ITypeBinding binding= name.resolveTypeBinding();
	if (binding != null && binding.isRawType())
		raw= true;
	if (parameters != null && parameters.length > 0 && !raw) {
		final ParameterizedType type= ast.newParameterizedType(ast.newSimpleType(ast.newName(fQualifiedTypeName)));
		for (int index= 0; index < parameters.length; index++)
			type.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
		return type;
	}
	return ast.newName(fQualifiedTypeName);
}
 
Example 4
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ASTNode getNewUnqualifiedTypeNode(ITypeBinding[] parameters, Name name) {
	final AST ast= name.getAST();
	boolean raw= false;
	final ITypeBinding binding= name.resolveTypeBinding();
	if (binding != null && binding.isRawType())
		raw= true;
	if (parameters != null && parameters.length > 0 && !raw) {
		final ParameterizedType type= ast.newParameterizedType(ast.newSimpleType(ast.newSimpleName(fType.getElementName())));
		for (int index= 0; index < parameters.length; index++)
			type.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
		return type;
	}
	return ast.newSimpleType(ast.newSimpleName(fType.getElementName()));
}
 
Example 5
Source File: TypeEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TType create(ITypeBinding binding) {
	if (binding.isPrimitive()) {
		return createPrimitiveType(binding);
	} else if (binding.isArray()) {
		return createArrayType(binding);
	} else if (binding.isRawType()) {
		return createRawType(binding);
	} else if (binding.isGenericType()) {
		return createGenericType(binding);
	} else if (binding.isParameterizedType()) {
		return createParameterizedType(binding);
	} else if (binding.isTypeVariable()) {
		return createTypeVariable(binding);
	} else if (binding.isWildcardType()) {
		if (binding.getBound() == null) {
			return createUnboundWildcardType(binding);
		} else if (binding.isUpperbound()) {
			return createExtendsWildCardType(binding);
		} else {
			return createSuperWildCardType(binding);
		}
	} else if (binding.isCapture()) {
		if (fRemoveCapures) {
			return create(binding.getWildcard());
		} else {
			return createCaptureType(binding);
		}
	}
	if ("null".equals(binding.getName())) //$NON-NLS-1$
		return NULL;
	return createStandardType(binding);
}
 
Example 6
Source File: TypeContextChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ITypeBinding handleBug84585(ITypeBinding typeBinding) {
	if (typeBinding == null)
		return null;
	else if (typeBinding.isGenericType() && ! typeBinding.isRawType() && ! typeBinding.isParameterizedType())
		return null; //see bug 84585
	else
		return typeBinding;
}
 
Example 7
Source File: InferTypeArgumentsTCModel.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isAGenericType(ITypeBinding type) {
	return type.isGenericType()
			|| type.isParameterizedType()
			|| (type.isRawType() && type.getTypeDeclaration().isGenericType());
}
 
Example 8
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the type to which an inlined variable initializer should be cast, or
 * <code>null</code> if no cast is necessary.
 * 
 * @param initializer the initializer expression of the variable to inline
 * @param reference the reference to the variable (which is to be inlined)
 * @return a type binding to which the initializer should be cast, or <code>null</code> iff no cast is necessary
 * @since 3.6
 */
public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) {
	ITypeBinding initializerType= initializer.resolveTypeBinding();
	ITypeBinding referenceType= reference.resolveTypeBinding();
	if (initializerType == null || referenceType == null)
		return null;
	
	if (initializerType.isPrimitive() && referenceType.isPrimitive() && ! referenceType.isEqualTo(initializerType)) {
		return referenceType;
		
	} else if (initializerType.isPrimitive() && ! referenceType.isPrimitive()) { // initializer is autoboxed
		ITypeBinding unboxedReferenceType= Bindings.getUnboxedTypeBinding(referenceType, reference.getAST());
		if (!unboxedReferenceType.isEqualTo(initializerType))
			return unboxedReferenceType;
		else if (needsExplicitBoxing(reference))
			return referenceType;
		
	} else if (! initializerType.isPrimitive() && referenceType.isPrimitive()) { // initializer is autounboxed
		ITypeBinding unboxedInitializerType= Bindings.getUnboxedTypeBinding(initializerType, reference.getAST());
		if (!unboxedInitializerType.isEqualTo(referenceType))
			return referenceType;
		
	} else if (initializerType.isRawType() && referenceType.isParameterizedType()) {
		return referenceType; // don't lose the unchecked conversion

	} else if (initializer instanceof LambdaExpression || initializer instanceof MethodReference) {
		if (isTargetAmbiguous(reference, isExplicitlyTypedLambda(initializer))) {
			return referenceType;
		} else {
			ITypeBinding targetType= getTargetType(reference);
			if (targetType == null || targetType != referenceType) {
				return referenceType;
			}
		}

	} else if (! TypeRules.canAssign(initializerType, referenceType)) {
		if (!Bindings.containsTypeVariables(referenceType))
			return referenceType;
	}
	
	return null;
}
 
Example 9
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isUseableTypeInContext(ITypeBinding type, IBinding context, boolean noWildcards) {
	if (type.isArray()) {
		type= type.getElementType();
	}
	if (type.isAnonymous()) {
		return false;
	}
	if (type.isRawType() || type.isPrimitive()) {
		return true;
	}
	if (type.isTypeVariable()) {
		return isVariableDefinedInContext(context, type);
	}
	if (type.isGenericType()) {
		ITypeBinding[] typeParameters= type.getTypeParameters();
		for (int i= 0; i < typeParameters.length; i++) {
			if (!isUseableTypeInContext(typeParameters[i], context, noWildcards)) {
				return false;
			}
		}
		return true;
	}
	if (type.isParameterizedType()) {
		ITypeBinding[] typeArguments= type.getTypeArguments();
		for (int i= 0; i < typeArguments.length; i++) {
			if (!isUseableTypeInContext(typeArguments[i], context, noWildcards)) {
				return false;
			}
		}
		return true;
	}
	if (type.isCapture()) {
		type= type.getWildcard();
	}

	if (type.isWildcardType()) {
		if (noWildcards) {
			return false;
		}
		if (type.getBound() != null) {
			return isUseableTypeInContext(type.getBound(), context, noWildcards);
		}
	}
	return true;
}