org.eclipse.jdt.core.dom.ITypeBinding#isGenericType ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.ITypeBinding#isGenericType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdt2famix   文件: InJavaImporter.java
Type createTypeFromTypeBinding(ITypeBinding binding) {
	if (binding.isPrimitive())
		return new PrimitiveType();
	if (binding.isParameterizedType())
		return new ParameterizedType();
	if (binding.isGenericType()) {
		ParameterizableClass parameterizableClass = new ParameterizableClass();
		parameterizableClass.setIsInterface(binding.isInterface());
		return parameterizableClass;
	}
	if (binding.isEnum())
		return new Enum();
	if (binding.isArray())
		return createTypeFromTypeBinding(binding.getElementType());
	if (binding.isAnnotation())
		return new AnnotationType();
	Class clazz = new Class();
	clazz.setIsInterface(binding.isInterface());
	return clazz;
}
 
源代码2 项目: jdt2famix   文件: InJavaImporter.java
public Type ensureTypeFromTypeBinding(ITypeBinding binding) {
	String qualifiedName = binding.getQualifiedName();
	if (types.has(qualifiedName))
		return types.named(qualifiedName);
	Type type = createTypeFromTypeBinding(binding);
	type.setName(binding.getName());
	types.add(qualifiedName, type);
	type.setIsStub(true);
	extractBasicModifiersFromBinding(binding.getModifiers(), type);
	type.setContainer(ensureContainerEntityForTypeBinding(binding));
	if (binding.getSuperclass() != null)
		createInheritanceFromSubtypeToSuperTypeBinding(type, binding.getSuperclass());
	for (ITypeBinding interfaceBinding : binding.getInterfaces()) {
		createInheritanceFromSubtypeToSuperTypeBinding(type, interfaceBinding);
	}
	if (binding.isParameterizedType()) {
		/*
		 * This if duplicates the condition from the create method because we want to
		 * break possible infinite loops induced by the below ensure calls. This is
		 * achieved by having this condition after the addition of the type in the types
		 * map.
		 */
		ParameterizedType parameterizedType = ((ParameterizedType) type);
		if (ensureTypeFromTypeBinding(binding.getErasure()) instanceof ParameterizableClass)
			parameterizedType.setParameterizableClass(
					(ParameterizableClass) ensureTypeFromTypeBinding(binding.getErasure()));
		List<Type> arguments = Stream.of(binding.getTypeArguments()).map(arg -> ensureTypeFromTypeBinding(arg))
				.collect(Collectors.toList());
		parameterizedType.setArguments(arguments);
	}
	if (binding.isGenericType()) {
		ParameterizableClass parameterizableClass = (ParameterizableClass) type;
		Stream.of(binding.getTypeParameters())
				.forEach(p -> createParameterType(p.getName().toString(), parameterizableClass));
	}
	return type;
}
 
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 String getRawName(ITypeBinding binding) {
	String name= binding.getName();
	if (binding.isParameterizedType() || binding.isGenericType()) {
		int idx= name.indexOf('<');
		if (idx != -1) {
			return name.substring(0, idx);
		}
	}
	return name;
}
 
public static boolean isAGenericType(ITypeBinding type) {
	return type.isGenericType()
			|| type.isParameterizedType()
			|| (type.isRawType() && type.getTypeDeclaration().isGenericType());
}
 
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;
}