下面列出了org.eclipse.jdt.core.dom.ITypeBinding#isRawType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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()));
}
}
}
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;
}
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);
}
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()));
}
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);
}
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;
}
public static boolean isAGenericType(ITypeBinding type) {
return type.isGenericType()
|| type.isParameterizedType()
|| (type.isRawType() && type.getTypeDeclaration().isGenericType());
}
/**
* 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;
}
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;
}