Search in sources :

Example 1 with TypeName

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);
                    }
                }
            }
        }
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeName(com.yahoo.aptutils.model.TypeName) DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement)

Example 2 with TypeName

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);
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeName(com.yahoo.aptutils.model.TypeName) DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) Expression(com.yahoo.aptutils.writer.expressions.Expression) ArrayList(java.util.ArrayList)

Aggregations

DeclaredTypeName (com.yahoo.aptutils.model.DeclaredTypeName)2 TypeName (com.yahoo.aptutils.model.TypeName)2 ArrayList (java.util.ArrayList)2 Expression (com.yahoo.aptutils.writer.expressions.Expression)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1