use of org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl in project kie-wb-common by kiegroup.
the class GenerationEngineTest method testMethodStringGeneration.
@Test
public void testMethodStringGeneration() {
DataModel dataModel = dataModelOracleDriver.createModel();
Parameter parameter1 = new ParameterImpl(new TypeImpl("com.test.Object1"), "o1");
Parameter parameter2 = new ParameterImpl(new TypeImpl("com.test.Object1"), "o2");
Type returnType = new TypeImpl("com.test.Object1");
Method method = new MethodImpl("test", Arrays.asList(parameter1, parameter2), "return o1;", returnType, Visibility.PUBLIC);
DataObject object = dataModel.addDataObject("com.test.Object1");
object.addMethod(method);
GenerationContext generationContext = new GenerationContext(dataModel);
try {
String result = engine.generateMethodString(generationContext, method);
assertEquals(results.getProperty("testMethodStringGeneration"), results.getProperty("testMethodStringGeneration"), result);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method createMethodsUpdateTest.
private DataObject createMethodsUpdateTest() {
DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package4", "MethodsUpdateTest", null);
Type methodReturnType = new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl(String.class.getName())));
Parameter parameter = new ParameterImpl(new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTest"))), "methodUpdateTestList");
Method methodImpl = new MethodImpl("getTestString", Arrays.asList(parameter), "return Arrays.asList(\"testString\");", methodReturnType, Visibility.PUBLIC);
Annotation testAnnotation = createAnnotation(TestAnnotation.class);
methodImpl.addAnnotation(testAnnotation);
dataObject.addMethod(methodImpl);
methodImpl = new MethodImpl("noOpMethodWithTestAnnotation", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
Annotation testAnnotation1 = createAnnotation(Generated.class);
testAnnotation1.setValue("value", "foo.bar.Generator");
methodImpl.addAnnotation(testAnnotation1);
Annotation testAnnotation2 = createAnnotation(TestAnnotation1.class);
testAnnotation2.setValue("value", "annotationParameter");
methodImpl.addAnnotation(testAnnotation2);
dataObject.addMethod(methodImpl);
return dataObject;
}
use of org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method createNestedClassUpdateTestResult.
private DataObject createNestedClassUpdateTestResult() {
DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package5", "NestedClassUpdateTestResult", null);
JavaClass nestedClass = new JavaClassImpl("", "UpdatedNestedClass");
nestedClass.addInterface("java.io.Serializable");
nestedClass.addInterface("ParametrizedInterface<Double>");
Annotation generatedAnnotation = createAnnotation(Generated.class);
generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
nestedClass.addAnnotation(generatedAnnotation);
MethodImpl method = new MethodImpl("updatedMethod", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
generatedAnnotation = createAnnotation(Generated.class);
generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
method.addAnnotation(generatedAnnotation);
nestedClass.addMethod(method);
dataObject.addNestedClass(nestedClass);
return dataObject;
}
use of org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl in project kie-wb-common by kiegroup.
the class DataModelerEventTest method createEvent.
@Test
public void createEvent() {
DataObject currentDataObject = new DataObjectImpl();
ObjectProperty currentField = new ObjectPropertyImpl();
Method currentMethod = new MethodImpl();
Module currentModule = new Module();
String source = "testSource";
String contextId = "testContextId";
Path path = new PathFactory.PathImpl();
DataModelerEvent event = new DataModelerEvent().withCurrentDataObject(currentDataObject).withCurrentField(currentField).withCurrentMethod(currentMethod).withCurrentProject(currentModule).withSource(source).withContextId(contextId).withPath(path);
assertEquals(currentDataObject, event.getCurrentDataObject());
assertEquals(currentField, event.getCurrentField());
assertEquals(currentMethod, event.getCurrentMethod());
assertEquals(currentModule, event.getCurrentModule());
assertEquals(source, event.getSource());
assertEquals(contextId, event.getContextId());
assertEquals(path, event.getPath());
}
use of org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method addMethod.
private void addMethod(org.kie.workbench.common.services.datamodeller.core.JavaClass javaClass, Method method, ClassTypeResolver classTypeResolver) throws ClassNotFoundException, ModelDriverException {
List<Parameter> parameters = method.getParameters();
List<org.kie.workbench.common.services.datamodeller.core.Parameter> modelParameters = new ArrayList<>();
if (parameters != null) {
for (Parameter parameter : parameters) {
modelParameters.add(new org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl(new org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl(resolveTypeName(classTypeResolver, parameter.getType().getName()), resolveTypeArguments(parameter.getType().getTypeArguments())), parameter.getName()));
}
}
org.kie.workbench.common.services.datamodeller.core.Type returnType = null;
if (method.getReturnType() != null) {
returnType = new org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl(resolveTypeName(classTypeResolver, method.getReturnType().getName()), resolveTypeArguments(method.getReturnType().getTypeArguments()));
}
Visibility visibility = Visibility.PACKAGE_PRIVATE;
if (method.getVisibility() != null) {
visibility = DriverUtils.buildVisibility(method.getVisibility());
}
MethodImpl dataObjectMethod = new MethodImpl(method.getName(), modelParameters, method.getBody(), returnType, visibility);
List<AnnotationSource<JavaClassSource>> annotations = method.getAnnotations();
if (annotations != null) {
for (AnnotationSource annotation : annotations) {
dataObjectMethod.addAnnotation(createAnnotation(annotation, classTypeResolver));
}
}
javaClass.addMethod(dataObjectMethod);
}
Aggregations