Search in sources :

Example 11 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.

the class GenerationTools method resolveAnnotationType.

public String resolveAnnotationType(Annotation annotation) {
    StringBuffer type = new StringBuffer();
    AnnotationDefinition annotationDefinition = annotation.getAnnotationDefinition();
    if (annotationDefinition == null) {
        logger.warn("Annotation definition for annotation: " + annotation + " is not defined.");
        return type.toString();
    }
    if (annotationDefinition.isMarker()) {
        return type.toString();
    }
    // finally we can process annotation members.
    Object memberValue;
    int memberCount = 0;
    for (AnnotationValuePairDefinition memberDefinition : annotationDefinition.getValuePairs()) {
        if ((memberValue = annotation.getValue(memberDefinition.getName())) != null) {
            // a value has been set for this member.
            if (memberCount == 0) {
                type.append("(");
            }
            if (memberCount > 0) {
                type.append(", ");
            }
            type.append(resolveMemberType(memberDefinition, memberValue));
            memberCount++;
        }
    }
    if (memberCount > 0) {
        type.append(")");
    }
    return type.toString();
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 12 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.

the class NumericValuePairEditorBaseTest method createEditor.

protected NumericValuePairEditor createEditor(NumberType numberType, String paramName) {
    NumericValuePairEditor numericEditor = new NumericValuePairEditor(singleEditorView);
    AnnotationDefinition annotationDefinition = createAnnotationDefinition(numberType);
    AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair(paramName);
    numericEditor.init(valuePairDefinition);
    return numericEditor;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 13 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method createAnnotation.

private Annotation createAnnotation(AnnotationSource annotationToken, ClassTypeResolver classTypeResolver) throws ModelDriverException {
    AnnotationDefinition annotationDefinition;
    Annotation annotation = null;
    annotationDefinition = buildAnnotationDefinition(annotationToken, classTypeResolver);
    if (annotationDefinition != null) {
        AnnotationDriver annotationDriver = new DefaultJavaRoasterModelAnnotationDriver();
        annotation = annotationDriver.buildAnnotation(annotationDefinition, annotationToken);
    } else {
        logger.warn("Annotation: " + annotationToken.getName() + " is not configured for this ModelDriver driver.");
    }
    return annotation;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDriver(org.kie.workbench.common.services.datamodeller.driver.AnnotationDriver) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 14 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method addAnnotation.

public AnnotationSource<?> addAnnotation(AnnotationTargetSource annotationTargetSource, Annotation annotation) {
    AnnotationSource<?> newAnnotationSource = annotationTargetSource.addAnnotation();
    newAnnotationSource.setName(annotation.getClassName());
    AnnotationDefinition annotationDefinition = annotation.getAnnotationDefinition();
    if (!annotationDefinition.isMarker()) {
        for (AnnotationValuePairDefinition memberDefinition : annotationDefinition.getValuePairs()) {
            Object value = annotation.getValue(memberDefinition.getName());
            if (value != null) {
                addMemberValue(newAnnotationSource, memberDefinition, value);
            }
        }
    }
    return newAnnotationSource;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 15 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.

the class DefaultJavaRoasterModelAnnotationDriver method parseAnnotationValue.

private Object parseAnnotationValue(AnnotationSource javaAnnotationToken, AnnotationValuePairDefinition valuePairDefinition) throws ModelDriverException {
    String value = javaAnnotationToken.getLiteralValue(valuePairDefinition.getName());
    AnnotationDefinition annotationDefinition = valuePairDefinition.getAnnotationDefinition();
    Object result = null;
    if (value == null)
        return null;
    if (annotationDefinition == null) {
        return value;
    }
    if (valuePairDefinition.isArray()) {
        AnnotationSource[] javaAnnotationTokenValueArray = javaAnnotationToken.getAnnotationArrayValue(valuePairDefinition.getName());
        List<Annotation> annotationList = new ArrayList<Annotation>();
        Annotation annotation;
        if (javaAnnotationTokenValueArray != null) {
            for (int i = 0; i < javaAnnotationTokenValueArray.length; i++) {
                annotation = buildAnnotation(annotationDefinition, javaAnnotationTokenValueArray[i]);
                if (annotation != null) {
                    annotationList.add(annotation);
                }
            }
        }
        result = annotationList.size() > 0 ? annotationList : null;
    } else {
        AnnotationSource javaAnnotationTokenValue = javaAnnotationToken.getAnnotationValue(valuePairDefinition.getName());
        if (javaAnnotationTokenValue != null) {
            result = buildAnnotation(annotationDefinition, javaAnnotationTokenValue);
        }
    }
    return result;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) ArrayList(java.util.ArrayList) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)21 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)8 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)6 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 ArrayList (java.util.ArrayList)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 AnnotationDriver (org.kie.workbench.common.services.datamodeller.driver.AnnotationDriver)2 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Before (org.junit.Before)1 Description (org.kie.api.definition.type.Description)1 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1 DomainHandler (org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler)1 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)1