use of com.squareup.javapoet.TypeName in project Rocket by mozilla-tw.
the class ProcessorUtil method getJavadocSafeName.
/**
* Returns a safe String to use in a Javadoc that will function in a link.
*
* <p>This method exists because by Javadoc doesn't handle type parameters({@literal <T>}
* in {@literal RequestOptions<T>} for example).
*/
private TypeName getJavadocSafeName(Element element) {
Types typeUtils = processingEnv.getTypeUtils();
TypeMirror type = element.asType();
if (typeUtils.asElement(type) == null) {
// If there is no Element, it's a primitive and can't have additional types, so we're done.
return ClassName.get(element.asType());
}
Name simpleName = typeUtils.asElement(type).getSimpleName();
return ClassName.bestGuess(simpleName.toString());
}
use of com.squareup.javapoet.TypeName in project butterknife by JakeWharton.
the class ClasspathBindingSet method bestGuess.
private static TypeName bestGuess(String type) {
switch(type) {
case "void":
return TypeName.VOID;
case "boolean":
return TypeName.BOOLEAN;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "int":
return TypeName.INT;
case "long":
return TypeName.LONG;
case "short":
return TypeName.SHORT;
default:
int left = type.indexOf('<');
if (left != -1) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
left = type.indexOf('<', left + 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName, typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
use of com.squareup.javapoet.TypeName in project webofneeds by researchstudio-sat.
the class UnionEmulationPostprocessor method addUnionEmulationPatternMethodsToInterface.
private TypeSpec addUnionEmulationPatternMethodsToInterface(TypeSpec interfaceType, Set<TypeSpec> implementingClasses, Shacl2JavaConfig config) {
// 1. add the the when-method to the interface
// 2. add the sub-interface with the is-methods to the interface
TypeSpec.Builder interfaceBuilder = interfaceType.toBuilder();
TypeVariableName R = TypeVariableName.get("R");
ClassName subInterfaceName = ClassName.get(config.getPackageName(), interfaceType.name, "Cases");
TypeName casesType = ParameterizedTypeName.get(subInterfaceName, R);
interfaceBuilder.addMethod(MethodSpec.methodBuilder("when").addModifiers(PUBLIC, ABSTRACT).addTypeVariable(R).addParameter(casesType, "option").returns(R).build());
TypeSpec.Builder subInterfaceBuilder = TypeSpec.interfaceBuilder("Cases").addModifiers(PUBLIC, STATIC).addTypeVariable(R);
for (TypeSpec impl : implementingClasses) {
subInterfaceBuilder.addMethod(MethodSpec.methodBuilder("is").addModifiers(DEFAULT, PUBLIC).addParameter(ClassName.get(config.getPackageName(), impl.name), "option").addStatement("return null").returns(R).build());
}
interfaceBuilder.addType(subInterfaceBuilder.build());
return interfaceBuilder.build();
}
use of com.squareup.javapoet.TypeName in project raml-for-jax-rs by mulesoft-labs.
the class CurrentBuild method fetchType.
public V10GType fetchType(String name, TypeDeclaration typeDeclaration) {
TypeName typeName = fetchRamlToPojoBuilder().fetchType(name, typeDeclaration);
V10RamlToPojoGType type = new V10RamlToPojoGType(typeDeclaration);
type.setJavaType(typeName);
return type;
}
use of com.squareup.javapoet.TypeName in project raml-for-jax-rs by mulesoft-labs.
the class CurrentBuild method fetchType.
public V10GType fetchType(Resource resource, Method method, Response response, TypeDeclaration typeDeclaration) {
if (typeDeclaration instanceof JSONTypeDeclaration) {
return (V10GType) ((JsonSchemaTypeGenerator) builtTypes.get(typeDeclaration.type())).getType();
}
if (typeDeclaration instanceof XMLTypeDeclaration) {
return (V10GType) ((XmlSchemaTypeGenerator) builtTypes.get(typeDeclaration.type())).getType();
}
RamlToPojo ramlToPojo = fetchRamlToPojoBuilder();
if (ramlToPojo.isInline(typeDeclaration)) {
TypeName typeName = fetchRamlToPojoBuilder().fetchType(Names.javaTypeName(resource, method, response, typeDeclaration), typeDeclaration);
V10RamlToPojoGType type = new V10RamlToPojoGType(Names.javaTypeName(resource, method, response, typeDeclaration), typeDeclaration);
type.setJavaType(typeName);
return type;
} else {
TypeName typeName = fetchRamlToPojoBuilder().fetchType(typeDeclaration.type(), typeDeclaration);
V10RamlToPojoGType type = new V10RamlToPojoGType(typeDeclaration.type(), typeDeclaration);
type.setJavaType(typeName);
return type;
}
}
Aggregations