All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.uom.java.xmi.annotation.source.ValueSourceAnnotation Maven / Gradle / Ivy

package gr.uom.java.xmi.annotation.source;

import gr.uom.java.xmi.SourceAnnotation;
import gr.uom.java.xmi.UMLAnnotation;
import gr.uom.java.xmi.UMLModel;
import gr.uom.java.xmi.UMLOperation;
import gr.uom.java.xmi.decomposition.AbstractExpression;
import gr.uom.java.xmi.decomposition.LeafExpression;
import gr.uom.java.xmi.annotation.NormalAnnotation;

import java.util.*;

public class ValueSourceAnnotation extends SourceAnnotation implements NormalAnnotation {
    public static final String ANNOTATION_TYPENAME = "ValueSource";
    private final Map memberValuePairs;
    private final List> testParameters;
    private Set numberKeys = Set.of(
            "bytes",
            "doubles",
            "floats",
            "ints",
            "longs",
            "shorts"
    );
    private Set stringKeys = Set.of(
            "strings",
            "chars"
    );

    private List extractLiterals(AbstractExpression annotationParameterValue, String memberKey) {
        if (numberKeys.contains(memberKey)) {
            return annotationParameterValue.getNumberLiterals();
        } else if (stringKeys.contains(memberKey)) {
            return annotationParameterValue.getStringLiterals();
        } else if (memberKey.equals("booleans")) {
            return annotationParameterValue.getBooleanLiterals();
        } else if (memberKey.equals("classes")) {
            return annotationParameterValue.getTypeLiterals();
        }
        return Collections.emptyList();
    }

    public ValueSourceAnnotation(UMLAnnotation annotation, UMLOperation operation, UMLModel model) {
        super(annotation, ANNOTATION_TYPENAME);
        memberValuePairs = annotation.getMemberValuePairs();
        Set providedKeys = memberValuePairs.keySet();
        testParameters = new ArrayList<>();
        for (String key : providedKeys) {
            AbstractExpression annotationParameterValue = memberValuePairs.get(key);
            for (LeafExpression literal : extractLiterals(annotationParameterValue, key)) {
                testParameters.add(Collections.singletonList(sanitizeLiteral(literal.getString())));
            }
        }

    }

    @Override
    public List> getTestParameters() {
        return testParameters;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy