use of com.yahoo.aptutils.model.TypeName in project squidb by yahoo.
the class ConstantCopyingPlugin method afterProcessVariableElements.
@Override
public void afterProcessVariableElements() {
// Look for additional constants in @Constant annotated inner classes
List<? extends Element> elements = modelSpec.getModelSpecElement().getEnclosedElements();
for (Element element : elements) {
if (element instanceof TypeElement && element.getAnnotation(Constants.class) != null) {
if (!element.getModifiers().containsAll(Arrays.asList(Modifier.PUBLIC, Modifier.STATIC))) {
utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "@Constants annotated class is not " + "public static, will be ignored", element);
continue;
}
TypeElement constantClass = (TypeElement) element;
List<VariableElement> constantList = new ArrayList<>();
innerClassConstants.put(constantClass.getSimpleName().toString(), constantList);
for (Element e : constantClass.getEnclosedElements()) {
if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) {
TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType());
if (!(typeName instanceof DeclaredTypeName)) {
utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e);
} else {
processVariableElement((VariableElement) e, constantList);
}
}
}
}
}
}
use of com.yahoo.aptutils.model.TypeName in project squidb by yahoo.
the class JSONPropertyGenerator method getTypeExpression.
private Expression getTypeExpression(DeclaredTypeName fieldType) {
List<? extends TypeName> typeArgs = fieldType.getTypeArgs();
if (AptUtils.isEmpty(typeArgs)) {
return Expressions.classObject(fieldType);
} else {
List<Expression> parameterizedTypeBuilderArgs = new ArrayList<>();
parameterizedTypeBuilderArgs.add(Expressions.classObject(fieldType));
for (TypeName typeArg : typeArgs) {
// The cast to DeclaredTypeName is safe because we recursively check all type args before constructing
// an instance of this property generator
parameterizedTypeBuilderArgs.add(getTypeExpression((DeclaredTypeName) typeArg));
}
return Expressions.staticMethod(JSONTypes.PARAMETERIZED_TYPE_BUILDER, "build", parameterizedTypeBuilderArgs);
}
}
Aggregations