use of org.kie.workbench.common.services.datamodeller.parser.descr.VariableDeclarationDescr in project kie-wb-common by kiegroup.
the class ParserTestUtil method createField.
public static FieldDescr createField(String[] modifiers, String name, String type, String initializer) {
FieldDescr fieldDescr = new FieldDescr();
if (modifiers != null) {
fieldDescr.setModifiers(new ModifierListDescr());
for (int i = 0; i < modifiers.length; i++) {
fieldDescr.addModifier(new ModifierDescr(modifiers[i], -1, -1, -1, -1, modifiers[i]));
}
}
if (NamingUtils.isPrimitiveTypeId(type)) {
fieldDescr.setType(new TypeDescr());
fieldDescr.getType().setPrimitiveType(new PrimitiveTypeDescr(type, -1, -1, -1, -1, type));
} else {
fieldDescr.setType(new TypeDescr());
fieldDescr.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr(type, -1, -1, -1, -1));
}
VariableDeclarationDescr variableDecl = new VariableDeclarationDescr();
variableDecl.setIdentifier(new IdentifierDescr(name, -1, -1, -1));
fieldDescr.addVariableDeclaration(variableDecl);
if (initializer != null) {
variableDecl.setVariableInitializer(new VariableInitializerDescr(initializer, -1, -1, -1, -1, initializer));
}
fieldDescr.setEndSemiColon(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_SEMI_COLON, ";", -1, -1, -1, -1));
return fieldDescr;
}
use of org.kie.workbench.common.services.datamodeller.parser.descr.VariableDeclarationDescr 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);
}
Aggregations