Java Code Examples for com.github.javaparser.resolution.types.ResolvedType#isPrimitive()

The following examples show how to use com.github.javaparser.resolution.types.ResolvedType#isPrimitive() . 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: JavaParserUtil.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * Converts the resolved type to an internal representation.
 * If the type is an array the component type's internal name is returned.
 * Primitives return their boxed names.
 *
 * @param type
 * 		JavaParser resolved type.
 *
 * @return Internalized representation.
 */
public static String toInternal(ResolvedType type) {
	if(type.isVoid() || type.isPrimitive())
		return type.asPrimitive().getBoxTypeQName().replace(".", "/");
	if(type.isArray())
		return toInternal(type.asArrayType().getComponentType());
	if(type.isReference()) {
		if(type.asReferenceType().getTypeDeclaration() != null)
			return toInternal(type.asReferenceType().getTypeDeclaration().get());
		else
			return type.asReferenceType().getQualifiedName().replace(".", "/");
	}
	// The above cases should have internalized the name...
	// If not lets be alerted of a uncaught case.
	throw new IllegalStateException("Cannot internalize type: " + type);
}
 
Example 2
Source File: JavaParserUtil.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param type
 *            JavaParser type. Must be an object type.
 * @return Internal descriptor from type, assuming the type is available.
 */
private static String typeToDesc(ResolvedType type) {
	String qualified = null;
	if(type instanceof ResolvedTypeVariable)
		qualified = ((ResolvedTypeVariable) type).qualifiedName();
	else if(type instanceof ResolvedTypeParameterDeclaration)
		qualified = type.asTypeParameter().getQualifiedName();
	else if(type.isPrimitive())
		return primTypeToDesc(type.asPrimitive());
	else if(type.isVoid())
		return "V";
	else
		qualified = toInternal(type);
	if(qualified == null)
		return null;
	// Substring out generics
	if(qualified.contains("<") && qualified.contains(">"))
		qualified = qualified.substring(0, qualified.indexOf('<'));
	StringBuilder sbDesc = new StringBuilder();
	for(int i = 0; i < type.arrayLevel(); i++)
		sbDesc.append("[");
	sbDesc.append("L");
	sbDesc.append(qualified.replace('.', '/'));
	sbDesc.append(";");
	return sbDesc.toString();
}
 
Example 3
Source File: ParserTypeUtil.java    From JRemapper with MIT License 6 votes vote down vote up
/**
 * @param type
 *            JavaParser type. Must be an object type.
 * @return Internal descriptor from type, assuming the type is available.
 */
private static String typeToDesc(ResolvedType type) {
	String qualified = null;
	if (type instanceof ResolvedTypeVariable) {
		qualified = ((ResolvedTypeVariable) type).qualifiedName();
	} else if (type instanceof ResolvedTypeParameterDeclaration) {
		qualified = type.asTypeParameter().getQualifiedName();;
	} else if(type.isPrimitive()) {
		return primTypeToDesc(type.asPrimitive());
	} else if(type.isVoid()) {
		return "V";
	} else {
		qualified = type.describe();
	}
	if (qualified == null)
		return null;
	StringBuilder sbDesc = new StringBuilder();
	for (int i = 0; i < type.arrayLevel(); i++)
		sbDesc.append("[");
	sbDesc.append("L");
	sbDesc.append(qualified.replace('.', '/'));
	sbDesc.append(";");
	return sbDesc.toString();
}
 
Example 4
Source File: PrimitiveTypeResolver.java    From apigcc with MIT License 5 votes vote down vote up
@Override
public TypeDescription resolve(ResolvedType type) {
    if (type.isPrimitive()) {
        return new PrimitiveTypeDescription(type.asPrimitive());
    } else {
        return new PrimitiveTypeDescription(type.asReferenceType());
    }
}
 
Example 5
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isNumberType(ResolvedType type) {
    if (type.isPrimitive()) {
        ResolvedPrimitiveType resolvedPrimitiveType = type.asPrimitive();
        return resolvedPrimitiveType != ResolvedPrimitiveType.BOOLEAN
                && resolvedPrimitiveType != ResolvedPrimitiveType.CHAR;
    } else {
        return isTypeOf(type, Number.class);
    }
}
 
Example 6
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isBooleanType(ResolvedType type) {
    if (type.isPrimitive()) {
        return type.asPrimitive() == ResolvedPrimitiveType.BOOLEAN;
    } else {
        return isTypeOf(type, Boolean.class);
    }
}
 
Example 7
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isStringType(ResolvedType type) {
    if (type.isPrimitive()) {
        return type.asPrimitive() == ResolvedPrimitiveType.CHAR;
    } else {
        return isTypeOf(type, String.class, Character.class);
    }
}
 
Example 8
Source File: PrimitiveTypeResolver.java    From apigcc with MIT License 4 votes vote down vote up
@Override
public boolean accept(ResolvedType type) {
    return type.isPrimitive() || isBoxing(type);
}
 
Example 9
Source File: SchemaResolver.java    From flow with Apache License 2.0 4 votes vote down vote up
private boolean isCollectionType(ResolvedType type) {
    return !type.isPrimitive() && isTypeOf(type, Collection.class);
}
 
Example 10
Source File: SchemaResolver.java    From flow with Apache License 2.0 4 votes vote down vote up
private boolean isMapType(ResolvedType type) {
    return !type.isPrimitive() && isTypeOf(type, Map.class);
}
 
Example 11
Source File: JavaParserUtil.java    From Recaf with MIT License 2 votes vote down vote up
/**
 * @param type
 * 		JavaParser type.
 *
 * @return Internal descriptor from type, assuming the type is available or if it is a
 * primitive or void type.
 */
public static String getDescriptor(ResolvedType type) {
	if (type.isArray())
		return "[" + getDescriptor(type.asArrayType().getComponentType());
	return type.isPrimitive() ? primTypeToDesc(type) : typeToDesc(type);
}
 
Example 12
Source File: ParserTypeUtil.java    From JRemapper with MIT License 2 votes vote down vote up
/**
 * @param type
 * 		JavaParser type.
 *
 * @return Internal descriptor from type, assuming the type is available or if it is a
 * primitive or void type.
 */
private static String getDescriptor(ResolvedType type) {
	if (type.isArray())
		return "[" + getDescriptor(type.asArrayType().getComponentType());
	return type.isPrimitive() ? primTypeToDesc(type) : typeToDesc(type);
}