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

The following examples show how to use org.eclipse.jdt.core.dom.ITypeBinding#isGenericType() . 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: InJavaImporter.java    From jdt2famix with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: InJavaImporter.java    From jdt2famix with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 3
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 4
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 5
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 6
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 7
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;
}