Search in sources :

Example 1 with MethodImpl

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();
    }
}
Also used : Type(org.kie.workbench.common.services.datamodeller.core.Type) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) Method(org.kie.workbench.common.services.datamodeller.core.Method) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl) Test(org.junit.Test)

Example 2 with MethodImpl

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;
}
Also used : Type(org.kie.workbench.common.services.datamodeller.core.Type) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) List(java.util.List) ArrayList(java.util.ArrayList) Method(org.kie.workbench.common.services.datamodeller.core.Method) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)

Example 3 with MethodImpl

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;
}
Also used : JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Generated(javax.annotation.Generated) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)

Example 4 with MethodImpl

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());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Path(org.uberfire.backend.vfs.Path) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Method(org.kie.workbench.common.services.datamodeller.core.Method) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 5 with MethodImpl

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);
}
Also used : ArrayList(java.util.ArrayList) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) Parameter(org.jboss.forge.roaster.model.Parameter) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility)

Aggregations

MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)7 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)6 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)5 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)4 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)4 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)4 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)4 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)4 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)4 Method (org.kie.workbench.common.services.datamodeller.core.Method)4 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)4 ArrayList (java.util.ArrayList)3 Parameter (org.kie.workbench.common.services.datamodeller.core.Parameter)3 Type (org.kie.workbench.common.services.datamodeller.core.Type)3 ParameterImpl (org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl)3 List (java.util.List)2 Generated (javax.annotation.Generated)2 Test (org.junit.Test)2 JavaClass (org.kie.workbench.common.services.datamodeller.core.JavaClass)2 JavaClassImpl (org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl)2