use of org.kie.workbench.common.services.datamodeller.parser.descr.VariableInitializerDescr 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;
}
Aggregations