use of org.kie.workbench.common.services.datamodeller.parser.descr.ModifierDescr 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.ModifierDescr 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);
}
use of org.kie.workbench.common.services.datamodeller.parser.descr.ModifierDescr in project kie-wb-common by kiegroup.
the class MehodParsing1Test method init.
private void init() {
methodSentences = new ArrayList<String>();
methodSentences.add("public MethodParsing1() { this(null); }");
methodSentences.add("public MethodParsing1(String field1) { this.field1 = field1; }");
methodSentences.add("public MethodParsing1(int a, int b) { this(a, b, (byte)1); }");
methodSentences.add("public MethodParsing1(int a, int b, byte c) { super(); }");
methodSentences.add("public String getField1() { return field1; }");
methodSentences.add("public void setField1(String field1) { this.field1 = field1; }");
methodSentences.add("private int method1() { return -1; }");
methodSentences.add("private void method2() {}");
methodSentences.add("public static java.lang.String method3() { return null; }");
methodSentences.add("public static final Integer method4() { return null; }");
methodSentences.add("public void method5(java.lang.Integer param1, int param2) {}");
methodSentences.add("java.util.List<java.lang.String> method6() { return null; }");
methodSentences.add("protected java.util.AbstractList<String> method7 ( final int param1 , java.lang.Integer param2 , java.util.List<java.lang.Integer> param3 ) { return null ; }");
methodSentences.add("int method8 ( final int param1 , java.lang.Integer param2 ) [ ] [ ] { return null; }");
methodSentences.add("int method9 ( final Object ... param1) { return -1;}");
methodSentences.add("private java.util.AbstractList<Object> method10 ( final java.lang.String param1, int param2 , List<java.util.List<String>>...param3) { return null; }");
expectedMethods = new ArrayList<MethodDescr>();
MethodDescr method;
NormalParameterDescr param1;
NormalParameterDescr param2;
NormalParameterDescr param3;
EllipsisParameterDescr ellipsisParam;
ParameterListDescr parmsList;
// public MethodParsing1() { this(null); }
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setIdentifier(new IdentifierDescr("MethodParsing1", -1, -1, -1, -1));
expectedMethods.add(method);
// public MethodParsing1(String field1) { this.field1 = field1; }
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setIdentifier(new IdentifierDescr("MethodParsing1", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
// param1.setModifiers( new ModifierListDescr( ) );
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("String", -1, -1));
param1.setIdentifier(new IdentifierDescr("field1", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
method.setParamsList(parmsList);
expectedMethods.add(method);
// public MethodParsing1(int a, int b) { this(a, b, (byte)1); }
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setIdentifier(new IdentifierDescr("MethodParsing1", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
// param1.setModifiers( new ModifierListDescr( ) );
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param1.setIdentifier(new IdentifierDescr("a", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param2.setIdentifier(new IdentifierDescr("b", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
method.setParamsList(parmsList);
expectedMethods.add(method);
// public MethodParsing1(int a, int b, byte c) { super(); }
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setIdentifier(new IdentifierDescr("MethodParsing1", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
// param1.setModifiers( new ModifierListDescr( ) );
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param1.setIdentifier(new IdentifierDescr("a", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param2.setIdentifier(new IdentifierDescr("b", -1, -1, -1, -1));
param3 = new NormalParameterDescr();
// param3.setModifiers( new ModifierListDescr( ) );
param3.setType(new TypeDescr(null, -1, -1));
param3.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "byte"));
param3.setIdentifier(new IdentifierDescr("c", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
parmsList.addParameter(param3);
method.setParamsList(parmsList);
expectedMethods.add(method);
// "public String getField1() { return field1; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("String", -1, -1));
method.setIdentifier(new IdentifierDescr("getField1", -1, -1, -1, -1));
expectedMethods.add(method);
// "public void setField1(String field1) { this.field1 = field1; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setType(new TypeDescr());
method.getType().setVoidType(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_VOID, "void", -1, -1, -1, -1));
method.setIdentifier(new IdentifierDescr("setField1", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
// param1.setModifiers( new ModifierListDescr( ) );
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("String", -1, -1));
param1.setIdentifier(new IdentifierDescr("field1", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
method.setParamsList(parmsList);
expectedMethods.add(method);
// "private int method1() { return -1; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "private"));
method.setType(new TypeDescr(null, -1, -1));
method.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
method.setIdentifier(new IdentifierDescr("method1", -1, -1, -1, 1));
expectedMethods.add(method);
// "private void method2() {}"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "private"));
method.setType(new TypeDescr());
method.getType().setVoidType(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_VOID, "void", -1, -1, -1, -1));
method.setIdentifier(new IdentifierDescr("method2", -1, -1, -1, -1));
expectedMethods.add(method);
// "public static java.lang.String method3() { return null; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.addModifier(new ModifierDescr(null, -1, -1, "static"));
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.lang.String", -1, -1));
method.setIdentifier(new IdentifierDescr("method3", -1, -1, -1, -1));
expectedMethods.add(method);
// "public static final Integer method4() { return null; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.addModifier(new ModifierDescr(null, -1, -1, "static"));
method.addModifier(new ModifierDescr(null, -1, -1, "final"));
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("Integer", -1, -1));
method.setIdentifier(new IdentifierDescr("method4", -1, -1, -1, -1));
expectedMethods.add(method);
// "public void method5(java.lang.Integer param1, int param2) {}"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "public"));
method.setType(new TypeDescr());
method.getType().setVoidType(new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_VOID, "void", -1, -1, -1, -1));
method.setIdentifier(new IdentifierDescr("method5", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
// param1.setModifiers( new ModifierListDescr( ) );
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.lang.Integer", -1, -1));
param1.setIdentifier(new IdentifierDescr("param1", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param2.setIdentifier(new IdentifierDescr("param2", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
method.setParamsList(parmsList);
expectedMethods.add(method);
// "java.util.List<java.lang.String> method6() { return null; }"
method = new MethodDescr(null, -1, -1);
// method.setModifiers( new ModifierListDescr( ) );
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.util.List<java.lang.String>", -1, -1));
method.setIdentifier(new IdentifierDescr("method6", -1, -1, -1, -1));
expectedMethods.add(method);
// "protected java.util.AbstractList<String> method7 ( final int param1 , java.lang.Integer param2 , java.util.List<java.lang.Integer> param3 ) { return null ; }"
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.addModifier(new ModifierDescr(null, -1, -1, "protected"));
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.util.AbstractList<String>", -1, -1));
method.setIdentifier(new IdentifierDescr("method7", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
param1.setModifiers(new ModifierListDescr());
param1.addModifier(new ModifierDescr(null, -1, -1, "final"));
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param1.setIdentifier(new IdentifierDescr("param1", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.lang.Integer", -1, -1));
param2.setIdentifier(new IdentifierDescr("param2", -1, -1, -1, -1));
param3 = new NormalParameterDescr();
// param3.setModifiers( new ModifierListDescr( ) );
param3.setType(new TypeDescr(null, -1, -1));
param3.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.util.List<java.lang.Integer>", -1, -1));
param3.setIdentifier(new IdentifierDescr("param3", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
parmsList.addParameter(param3);
method.setParamsList(parmsList);
expectedMethods.add(method);
// "int method8 ( final int param1 , java.lang.Integer param2)[][] { return null; }"
method = new MethodDescr(null, -1, -1);
// method.setModifiers( new ModifierListDescr( ) );
method.setType(new TypeDescr(null, -1, -1));
method.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
method.setIdentifier(new IdentifierDescr("method8", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
param1.setModifiers(new ModifierListDescr());
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param1.addModifier(new ModifierDescr(null, -1, -1, "final"));
param1.setIdentifier(new IdentifierDescr("param1", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.lang.Integer", -1, -1));
param2.setIdentifier(new IdentifierDescr("param2", -1, -1, -1, -1));
method.addDimension(new DimensionDescr("", -1, -1, -1, -1, new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_LBRACKET, "[", -1, -1, -1, -1), new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_RBRACKET, "]", -1, -1, -1, -1)));
method.addDimension(new DimensionDescr("", -1, -1, -1, -1, new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_LBRACKET, "[", -1, -1, -1, -1), new JavaTokenDescr(ElementDescriptor.ElementType.JAVA_RBRACKET, "]", -1, -1, -1, -1)));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
method.setParamsList(parmsList);
expectedMethods.add(method);
// "int method9 ( final Object ... param1) { return -1;}"
method = new MethodDescr(null, -1, -1);
// method.setModifiers( new ModifierListDescr( ) );
method.setType(new TypeDescr(null, -1, -1));
method.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
method.setIdentifier(new IdentifierDescr("method9", -1, -1, -1, -1));
ellipsisParam = new EllipsisParameterDescr();
ellipsisParam.setModifiers(new ModifierListDescr());
ellipsisParam.setType(new TypeDescr(null, -1, -1));
ellipsisParam.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("Object", -1, -1));
ellipsisParam.addModifier(new ModifierDescr(null, -1, -1, "final"));
ellipsisParam.setIdentifier(new IdentifierDescr("param1", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(ellipsisParam);
method.setParamsList(parmsList);
expectedMethods.add(method);
// private java.util.AbstractList<Object> method10 ( final java.lang.String param1, int param2 , List<java.util.List<String>>...param3) { return null; }
method = new MethodDescr(null, -1, -1);
method.setModifiers(new ModifierListDescr());
method.setType(new TypeDescr(null, -1, -1));
method.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.util.AbstractList<Object>", -1, -1));
method.addModifier(new ModifierDescr(null, -1, -1, "private"));
method.setIdentifier(new IdentifierDescr("method10", -1, -1, -1, -1));
param1 = new NormalParameterDescr();
param1.setModifiers(new ModifierListDescr());
param1.addModifier(new ModifierDescr(null, -1, -1, "final"));
param1.setType(new TypeDescr(null, -1, -1));
param1.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("java.lang.String", -1, -1));
param1.setIdentifier(new IdentifierDescr("param1", -1, -1, -1, -1));
param2 = new NormalParameterDescr();
// param2.setModifiers( new ModifierListDescr( ) );
param2.setType(new TypeDescr(null, -1, -1));
param2.getType().setPrimitiveType(new PrimitiveTypeDescr(null, -1, -1, "int"));
param2.setIdentifier(new IdentifierDescr("param2", -1, -1, -1, -1));
ellipsisParam = new EllipsisParameterDescr();
// ellipsisParam.setModifiers( new ModifierListDescr( ) );
ellipsisParam.setType(new TypeDescr(null, -1, -1));
ellipsisParam.getType().setClassOrInterfaceType(new ClassOrInterfaceTypeDescr("List<java.util.List<String>>", -1, -1));
ellipsisParam.setIdentifier(new IdentifierDescr("param3", -1, -1, -1, -1));
parmsList = new ParameterListDescr();
parmsList.addParameter(param1);
parmsList.addParameter(param2);
parmsList.addParameter(ellipsisParam);
method.setParamsList(parmsList);
expectedMethods.add(method);
}
Aggregations