Java Code Examples for org.eclipse.jdt.core.dom.Type#isArrayType()

The following examples show how to use org.eclipse.jdt.core.dom.Type#isArrayType() . 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: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, Type expectedType, Collection<String> excluded, boolean evaluateDefault) {
	int dim= 0;
	if (expectedType.isArrayType()) {
		ArrayType arrayType= (ArrayType)expectedType;
		dim= arrayType.getDimensions();
		expectedType= arrayType.getElementType();
	}
	if (expectedType.isParameterizedType()) {
		expectedType= ((ParameterizedType)expectedType).getType();
	}
	String typeName= ASTNodes.getTypeName(expectedType);

	if (typeName.length() > 0) {
		return getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, evaluateDefault);
	}
	return EMPTY;
}
 
Example 2
Source File: Resolver.java    From DesigniteJava with Apache License 2.0 5 votes vote down vote up
private void specifyTypes(Type type) {
	if (type.isParameterizedType()) {
		ParameterizedType parameterizedType = (ParameterizedType) type;
		List<Type> typeArgs = parameterizedType.typeArguments();

		for (int i = 0; i < typeArgs.size(); i++)
			setTypeList(typeArgs.get(i));

	} else if (type.isArrayType()) {
		Type arrayType = ((ArrayType) type).getElementType();
		setArrayType(arrayType);
	}
}
 
Example 3
Source File: ASTUtil.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String getPrettyTypeName(Type type) {
    if (type.isArrayType()) {
        return getPrettyTypeName((ArrayType) type);
    } else if (type.isParameterizedType()) {
        return getPrettyTypeName((ParameterizedType) type);
    } else if (type.isPrimitiveType()) {
        return getPrettyTypeName((PrimitiveType) type);
    } else if (type.isQualifiedType()) {
        return getPrettyTypeName((QualifiedType) type);
    } else if (type.isSimpleType()) {
        return getPrettyTypeName((SimpleType) type);
    } else {
        return "";
    }
}
 
Example 4
Source File: TypeResolver.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
/**
 * @param type
 * @return
 */
protected String getNameOfType(final Type type) {
	 String nameOfType = "";
	if (type != null) {
		if (type.isPrimitiveType()) {
			nameOfType = type.toString();
		} else if (type.isParameterizedType()) {
			nameOfType = getParametrizedType((ParameterizedType) type);
		} else if (type.isArrayType()) {
			final ArrayType array = (ArrayType) type;
			nameOfType = getNameOfType(array.getElementType()) /*+ "[]"*/;
		} else if (type.isUnionType()) {
               // TODO: this is used for exceptions till now
               // So we will just capture the first type that we encounter
			final UnionType uType = (UnionType) type;
			final StringBuilder sb = new StringBuilder();
			for (final Object unionedType : uType.types()) {
				sb.append(getNameOfType((Type) unionedType));
                   break;
			}

			nameOfType = sb.toString();
		} else if (type.isWildcardType()) {
			final WildcardType wType = (WildcardType) type;
			nameOfType = (wType.isUpperBound() ? "? extends " : "? super ")
					+ getNameOfType(wType.getBound());
		} else {
			nameOfType = getFullyQualifiedNameFor(type.toString());
		}
	}
	return nameOfType;
}
 
Example 5
Source File: JavaApproximateTypeInferencer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param type
 * @return
 */
protected String getNameOfType(final Type type) {
	final String nameOfType;
	if (type.isPrimitiveType()) {
		nameOfType = type.toString();
	} else if (type.isParameterizedType()) {
		nameOfType = getParametrizedType((ParameterizedType) type);
	} else if (type.isArrayType()) {
		final ArrayType array = (ArrayType) type;
		nameOfType = getNameOfType(array.getElementType()) + "[]";
	} else if (type.isUnionType()) {
		final UnionType uType = (UnionType) type;
		final StringBuffer sb = new StringBuffer();
		for (final Object unionedType : uType.types()) {
			sb.append(getNameOfType(((Type) unionedType)));
			sb.append(" | ");
		}
		sb.delete(sb.length() - 3, sb.length());
		nameOfType = sb.toString();
	} else if (type.isWildcardType()) {
		final WildcardType wType = (WildcardType) type;
		if (wType.getBound() == null)
			return "?";
		nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound());
	} else {
		nameOfType = getFullyQualifiedNameFor(type.toString());
	}
	return nameOfType;
}
 
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 boolean isVoidArrayType(Type type){
	if (! type.isArrayType())
		return false;

	ArrayType arrayType= (ArrayType)type;
	if (! arrayType.getElementType().isPrimitiveType())
		return false;
	PrimitiveType primitiveType= (PrimitiveType) arrayType.getElementType();
	return (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID);
}
 
Example 7
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the element type. This is a convenience method that returns its
 * argument if it is a simple type and the element type if the parameter is an array type.
 * @param type The type to get the element type from.
 * @return The element type of the type or the type itself.
 */
public static Type getElementType(Type type) {
	if (! type.isArrayType())
		return type;
	return ((ArrayType)type).getElementType();
}