Search in sources :

Example 1 with JAnnotationArrayMember

use of com.helger.jcodemodel.JAnnotationArrayMember in project adt4j by sviperll.

the class FinalValueClassModel method buildFactory.

JMethod buildFactory(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
    JDefinedClass factory = buildFactoryClass(constructorMethods);
    JFieldVar factoryField = environment.buildValueClassField(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, factory, "FACTORY");
    JAnnotationUse fieldAnnotationUse = factoryField.annotate(SuppressWarnings.class);
    JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
    paramArray.param("unchecked");
    paramArray.param("rawtypes");
    factoryField.init(JExpr._new(factory));
    JMethod factoryMethod = environment.buildValueClassMethod(Source.toJMod(environment.factoryMethodAccessLevel()) | JMod.STATIC, "factory");
    Source.annotateNonnull(factoryMethod);
    JAnnotationUse methodAnnotationUse = factoryMethod.annotate(SuppressWarnings.class);
    methodAnnotationUse.param("value", "unchecked");
    for (JTypeVar visitorTypeParameter : environment.getValueTypeParameters()) {
        JTypeVar typeParameter = factoryMethod.generify(visitorTypeParameter.name());
        typeParameter.boundLike(visitorTypeParameter);
    }
    AbstractJClass usedValueClassType = environment.wrappedValueClassType(factoryMethod.typeParams());
    factoryMethod.type(environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException).getVisitorType());
    factoryMethod.body()._return(factoryField);
    return factoryMethod;
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JFieldVar(com.helger.jcodemodel.JFieldVar) JTypeVar(com.helger.jcodemodel.JTypeVar) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JAnnotationArrayMember(com.helger.jcodemodel.JAnnotationArrayMember) JMethod(com.helger.jcodemodel.JMethod)

Example 2 with JAnnotationArrayMember

use of com.helger.jcodemodel.JAnnotationArrayMember in project androidannotations by androidannotations.

the class APTCodeModelHelper method addSuppressWarnings.

public void addSuppressWarnings(IJAnnotatable generatedElement, String annotationValue) {
    Collection<JAnnotationUse> annotations = generatedElement.annotations();
    for (JAnnotationUse annotationUse : annotations) {
        if (SuppressWarnings.class.getCanonicalName().equals(annotationUse.getAnnotationClass().fullName())) {
            AbstractJAnnotationValue value = annotationUse.getParam("value");
            StringWriter code = new StringWriter();
            JFormatter formatter = new JFormatter(code);
            formatter.generable(value);
            if (!code.toString().contains(annotationValue)) {
                if (value instanceof JAnnotationArrayMember) {
                    ((JAnnotationArrayMember) value).param(annotationValue);
                } else {
                    String foundValue = code.toString().substring(1, code.toString().length() - 1);
                    JAnnotationArrayMember newParamArray = annotationUse.paramArray("value");
                    newParamArray.param(foundValue).param(annotationValue);
                }
            }
            return;
        }
    }
    generatedElement.annotate(SuppressWarnings.class).param("value", annotationValue);
}
Also used : StringWriter(java.io.StringWriter) AbstractJAnnotationValue(com.helger.jcodemodel.AbstractJAnnotationValue) JFormatter(com.helger.jcodemodel.JFormatter) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) JAnnotationArrayMember(com.helger.jcodemodel.JAnnotationArrayMember)

Aggregations

JAnnotationArrayMember (com.helger.jcodemodel.JAnnotationArrayMember)2 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)2 AbstractJAnnotationValue (com.helger.jcodemodel.AbstractJAnnotationValue)1 AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JFormatter (com.helger.jcodemodel.JFormatter)1 JMethod (com.helger.jcodemodel.JMethod)1 JTypeVar (com.helger.jcodemodel.JTypeVar)1 StringWriter (java.io.StringWriter)1