Search in sources :

Example 1 with AnnotationDescr

use of org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr in project kie-wb-common by kiegroup.

the class ParserTestUtil method createAnnotation.

public static AnnotationDescr createAnnotation(String className, String defaultValue, String[][] paramValues) {
    AnnotationDescr annotationDescr = new AnnotationDescr();
    annotationDescr.setQualifiedName(new QualifiedNameDescr(className, -1, -1, -1, -1));
    if (defaultValue != null) {
        annotationDescr.setParamsStartParen(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_LBRACE, "(", -1, -1, -1, -1));
        annotationDescr.setElementValue(new ElementValueDescr(defaultValue, -1, -1, -1, -1));
        annotationDescr.setParamsStopParen(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_RBRACE, ")", -1, -1, -1, -1));
    } else if (paramValues != null) {
        annotationDescr.setParamsStartParen(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_LBRACE, "(", -1, -1, -1, -1));
        if (paramValues.length > 0) {
            ElementValuePairListDescr valuePairs = new ElementValuePairListDescr();
            for (int i = 0; i < paramValues.length; i++) {
                ElementValuePairDescr valuePair = new ElementValuePairDescr();
                valuePair.setIdentifier(new IdentifierDescr(paramValues[i][0], -1, -1, -1, -1));
                valuePair.setValue(new ElementValueDescr(paramValues[i][1], -1, -1, -1, -1));
                valuePairs.addValuePair(valuePair);
            }
            annotationDescr.setElementValuePairs(valuePairs);
        }
        annotationDescr.setParamsStopParen(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_RBRACE, ")", -1, -1, -1, -1));
    }
    return annotationDescr;
}
Also used : ElementValuePairDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr) QualifiedNameDescr(org.kie.workbench.common.services.datamodeller.parser.descr.QualifiedNameDescr) ElementValuePairListDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairListDescr) AnnotationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr) JavaTokenDescr(org.kie.workbench.common.services.datamodeller.parser.descr.JavaTokenDescr) IdentifierDescr(org.kie.workbench.common.services.datamodeller.parser.descr.IdentifierDescr) ElementValueDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)

Example 2 with AnnotationDescr

use of org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr in project kie-wb-common by kiegroup.

the class AnnotationParsing1Test method init.

private void init() {
    FieldDescr fieldDeclaration;
    VariableDeclarationDescr variableDecl;
    AnnotationDescr annotationDescr;
    // @TestAnnotation()
    // public int field1;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field1", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation", null, new String[][] {}));
    fieldDeclaration.addModifier(new ModifierDescr("public", -1, -1, -1, -1, "public"));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation
    // private int field2;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field2", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation", null, null));
    fieldDeclaration.addModifier(new ModifierDescr("private", -1, -1, -1, -1, "private"));
    expectedFields.add(fieldDeclaration);
    // public
    // @TestAnnotation1
    // static int field3;
    fieldDeclaration = ParserTestUtil.createField(new String[] { "public" }, "field3", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation1", null, null));
    fieldDeclaration.addModifier(new ModifierDescr("static", -1, -1, -1, -1, "static"));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation1("value")
    // int field4;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field4", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation1", "\"value\"", null));
    expectedFields.add(fieldDeclaration);
    // protected
    // @TestAnnotation1( value = "value")
    // int field5;
    fieldDeclaration = ParserTestUtil.createField(new String[] { "protected" }, "field5", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation1", null, new String[][] { { "value", "\"value\"" } }));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation2( method1 = "param1", method2 = "param2")
    // int field6;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field6", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation2", null, new String[][] { { "method1", "\"param1\"" }, { "method2", "\"param2\"" } }));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation2(method2 = "param2")
    // int field7;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field7", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation2", null, new String[][] { { "method2", "\"param2\"" } }));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation3( value = "value", method1 = "param1", method2 = "param2")
    // int field8;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field8", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation3", null, new String[][] { { "value", "\"value\"" }, { "method1", "\"param1\"" }, { "method2", "\"param2\"" } }));
    expectedFields.add(fieldDeclaration);
    // @TestAnnotation
    // @TestAnnotation1("value")
    // @TestAnnotation2( method1 = "param1", method2 = "param2")
    // @TestAnnotation3( value = "value", method1 = "param1", method2 = "param2" )
    // int field9;
    fieldDeclaration = ParserTestUtil.createField(new String[] {}, "field9", "int", null);
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation", null, null));
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation1", "\"value\"", null));
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation2", null, new String[][] { { "method1", "\"param1\"" }, { "method2", "\"param2\"" } }));
    fieldDeclaration.addAnnotation(ParserTestUtil.createAnnotation("TestAnnotation3", null, new String[][] { { "value", "\"value\"" }, { "method1", "\"param1\"" }, { "method2", "\"param2\"" } }));
    expectedFields.add(fieldDeclaration);
}
Also used : VariableDeclarationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.VariableDeclarationDescr) FieldDescr(org.kie.workbench.common.services.datamodeller.parser.descr.FieldDescr) ModifierDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ModifierDescr) AnnotationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr)

Example 3 with AnnotationDescr

use of org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr in project kie-wb-common by kiegroup.

the class DefaultJavaModelAnnotationDriver method buildAnnotation.

@Override
public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException {
    AnnotationDescr javaAnnotationToken = (AnnotationDescr) annotationToken;
    AnnotationImpl annotation = new AnnotationImpl(annotationDefinition);
    if (annotationDefinition.isMarker()) {
        return annotation;
    } else {
        // try to read annotation parameters
        if (javaAnnotationToken.hasElementValue()) {
            for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
                if ("value".equals(annotationMember.getName())) {
                    annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), javaAnnotationToken.getElementValue().getValue()));
                }
            }
        } else if (javaAnnotationToken.hasElementValuePairs()) {
            ElementValuePairListDescr valuePairListDescr = javaAnnotationToken.getElementValuePairs();
            if (valuePairListDescr != null && valuePairListDescr.getValuePairs() != null) {
                Map<String, ElementValueDescr> valuePairValues = new HashMap<String, ElementValueDescr>();
                for (ElementValuePairDescr valuePair : valuePairListDescr.getValuePairs()) {
                    valuePairValues.put(valuePair.getIdentifier().getIdentifier(), valuePair.getValue());
                }
                for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
                    ElementValueDescr value = valuePairValues.get(annotationMember.getName());
                    if (value != null) {
                        annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), value.getValue()));
                    }
                }
            }
        }
    }
    return annotation;
}
Also used : ElementValuePairDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr) ElementValuePairListDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairListDescr) AnnotationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) HashMap(java.util.HashMap) Map(java.util.Map) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) ElementValueDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)

Aggregations

AnnotationDescr (org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr)3 ElementValueDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)2 ElementValuePairDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr)2 ElementValuePairListDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairListDescr)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)1 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)1 FieldDescr (org.kie.workbench.common.services.datamodeller.parser.descr.FieldDescr)1 IdentifierDescr (org.kie.workbench.common.services.datamodeller.parser.descr.IdentifierDescr)1 JavaTokenDescr (org.kie.workbench.common.services.datamodeller.parser.descr.JavaTokenDescr)1 ModifierDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ModifierDescr)1 QualifiedNameDescr (org.kie.workbench.common.services.datamodeller.parser.descr.QualifiedNameDescr)1 VariableDeclarationDescr (org.kie.workbench.common.services.datamodeller.parser.descr.VariableDeclarationDescr)1