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

The following examples show how to use com.github.javaparser.resolution.types.ResolvedType#isVoid() . 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();
}