Search in sources :

Example 16 with AnnotationValuePairDefinition

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

the class AnnotationListItem method loadAnnotation.

public void loadAnnotation(Annotation annotation, AnnotationSource annotationSource) {
    this.annotation = annotation;
    view.setHeadingTitle(annotation.getClassName());
    if (annotation.getAnnotationDefinition() != null && annotation.getAnnotationDefinition().getValuePairs() != null) {
        for (AnnotationValuePairDefinition valuePairDefinition : annotation.getAnnotationDefinition().getValuePairs()) {
            AnnotationValuePairListItem valuePairListItem = createListItem();
            valuePairListItem.loadValuePair(annotation, valuePairDefinition, annotationSource);
            valuePairListItem.setClearValuePairHandler(new AdvancedAnnotationListEditorView.ClearValuePairHandler() {

                @Override
                public void onClearValuePair(Annotation annotation, String valuePair) {
                    if (clearValuePairHandler != null) {
                        clearValuePairHandler.onClearValuePair(annotation, valuePair);
                    }
                }
            });
            valuePairListItem.setEditValuePairHandler(new AdvancedAnnotationListEditorView.EditValuePairHandler() {

                @Override
                public void onEditValuePair(Annotation annotation, String valuePair) {
                    if (editValuePairHandler != null) {
                        editValuePairHandler.onEditValuePair(annotation, valuePair);
                    }
                }
            });
            view.addItem(valuePairListItem);
            items.add(valuePairListItem);
        }
    }
}
Also used : AdvancedAnnotationListEditorView(org.kie.workbench.common.screens.datamodeller.client.widgets.advanceddomain.annotationlisteditor.AdvancedAnnotationListEditorView) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 17 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition 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 18 with AnnotationValuePairDefinition

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

the class DefaultDataModelOracleAnnotationDriver method buildAnnotation.

@Override
public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException {
    org.kie.soup.project.datamodel.oracle.Annotation oracleAnnotationToken = (org.kie.soup.project.datamodel.oracle.Annotation) annotationToken;
    AnnotationImpl annotation = new AnnotationImpl(annotationDefinition);
    if (annotationDefinition.isMarker()) {
        return annotation;
    } else if (oracleAnnotationToken.getParameters() != null) {
        Object currentAttributeValue;
        for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
            currentAttributeValue = oracleAnnotationToken.getParameters().get(annotationMember.getName());
            if (currentAttributeValue != null) {
                annotation.setValue(annotationMember.getName(), currentAttributeValue);
            }
        }
    }
    return annotation;
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 19 with AnnotationValuePairDefinition

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

the class DefaultJavaModelAnnotationDriver method buildAnnotation.

@Override
public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException {
    AnnotationDescr javaAnnotationToken = (AnnotationDescr) annotationToken;
    AnnotationImpl annotation = new AnnotationImpl(annotationDefinition);
    if (annotationDefinition.isMarker()) {
        return annotation;
    } else {
        // try to read annotation parameters
        if (javaAnnotationToken.hasElementValue()) {
            for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
                if ("value".equals(annotationMember.getName())) {
                    annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), javaAnnotationToken.getElementValue().getValue()));
                }
            }
        } else if (javaAnnotationToken.hasElementValuePairs()) {
            ElementValuePairListDescr valuePairListDescr = javaAnnotationToken.getElementValuePairs();
            if (valuePairListDescr != null && valuePairListDescr.getValuePairs() != null) {
                Map<String, ElementValueDescr> valuePairValues = new HashMap<String, ElementValueDescr>();
                for (ElementValuePairDescr valuePair : valuePairListDescr.getValuePairs()) {
                    valuePairValues.put(valuePair.getIdentifier().getIdentifier(), valuePair.getValue());
                }
                for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
                    ElementValueDescr value = valuePairValues.get(annotationMember.getName());
                    if (value != null) {
                        annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), value.getValue()));
                    }
                }
            }
        }
    }
    return annotation;
}
Also used : ElementValuePairDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr) ElementValuePairListDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairListDescr) AnnotationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) HashMap(java.util.HashMap) Map(java.util.Map) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) ElementValueDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)

Example 20 with AnnotationValuePairDefinition

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

the class DefaultJavaRoasterModelAnnotationDriver method buildAnnotation.

@Override
public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException {
    AnnotationSource javaAnnotationToken = (AnnotationSource) annotationToken;
    AnnotationImpl annotation = new AnnotationImpl(annotationDefinition);
    if (annotationDefinition.isMarker()) {
        return annotation;
    } else {
        if (javaAnnotationToken.getValues() != null) {
            List<ValuePair> values = javaAnnotationToken.getValues();
            if (values != null && values.size() > 0) {
                for (AnnotationValuePairDefinition valuePairDefinition : annotationDefinition.getValuePairs()) {
                    Object annotationValue = buildAnnotationValue(javaAnnotationToken, valuePairDefinition);
                    if (annotationValue != null) {
                        annotation.setValue(valuePairDefinition.getName(), annotationValue);
                    }
                }
            }
        }
    }
    return annotation;
}
Also used : ValuePair(org.jboss.forge.roaster.model.ValuePair) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Aggregations

AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)33 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)8 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)8 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)3 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entity (javax.persistence.Entity)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AdvancedAnnotationListEditorView (org.kie.workbench.common.screens.datamodeller.client.widgets.advanceddomain.annotationlisteditor.AdvancedAnnotationListEditorView)1 GenerationTools (org.kie.workbench.common.services.datamodeller.codegen.GenerationTools)1 AnnotationDefinitionRequest (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest)1 AnnotationDefinitionResponse (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse)1 AnnotationDescr (org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr)1 ElementValueDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)1 ElementValuePairDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr)1