Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactoring of metamodel #5

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Deploy Java Parser
name: Test Java Parser

on:
push
Expand Down
19 changes: 9 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.universal-variability-language</groupId>
<artifactId>fm-metamodel</artifactId>
<version>1.0</version>
<version>1.1</version>

<name>UVL Java Metamodel</name>
<description>This project host a java feature model metamodel for UVL </description>
Expand Down Expand Up @@ -47,10 +45,11 @@
</developers>

<scm><!-- TODO-->
<connection>scm:git:[email protected]:Universal-Variability-Language/java-uvl-metamodel.git</connection>
<developerConnection>scm:git:[email protected]:Universal-Variability-Language/java-uvl-metamodel.git</developerConnection>
<url>https://github.com/Universal-Variability-Language/java-uvl-metamodel</url>
</scm>
<connection>scm:git:[email protected]:Universal-Variability-Language/java-fm-metamodel.git</connection>
<developerConnection>scm:git:[email protected]:Universal-Variability-Language/java-fm-metamodel.git</developerConnection>
<url>https://github.com/Universal-Variability-Language/java-fm-metamodel</url>
<tag>HEAD</tag>
</scm>

<distributionManagement>
<snapshotRepository>
Expand All @@ -65,8 +64,8 @@

<properties>
<antlr4.version>4.13.1</antlr4.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/de/vill/conversion/ConvertAggregateFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ private void replaceAggregateFunctionInExpression(Expression parentExpression, A
} else {
rootFeature = aggregateFunctionExpression.getRootFeature();
}
List<Feature> attributes = collectAttributes(rootFeature, aggregateFunctionExpression.getAttributeName());
List<Feature> attributes = collectAttributes(rootFeature, aggregateFunctionExpression.getAttribute().getIdentifier());
Expression newExpression = null;
if (aggregateFunctionExpression instanceof SumAggregateFunctionExpression) {
newExpression = getSum(attributes, aggregateFunctionExpression.getAttributeName());
newExpression = getSum(attributes, aggregateFunctionExpression.getAttribute().getIdentifier());
} else if (aggregateFunctionExpression instanceof AvgAggregateFunctionExpression) {
newExpression = getAvg(attributes, aggregateFunctionExpression.getAttributeName());
newExpression = getAvg(attributes, aggregateFunctionExpression.getAttribute().getIdentifier());
}
parentExpression.replaceExpressionSubPart(aggregateFunctionExpression, newExpression);
}
Expand All @@ -80,44 +80,42 @@ private void replaceAggregateFunctionInExpressionConstraint(ExpressionConstraint
} else {
rootFeature = aggregateFunctionExpression.getRootFeature();
}
List<Feature> attributes = collectAttributes(rootFeature, aggregateFunctionExpression.getAttributeName());
List<Feature> attributes = collectAttributes(rootFeature, aggregateFunctionExpression.getAttribute().getIdentifier());
Expression newExpression = null;
if (aggregateFunctionExpression instanceof SumAggregateFunctionExpression) {
newExpression = getSum(attributes, aggregateFunctionExpression.getAttributeName());
newExpression = getSum(attributes, aggregateFunctionExpression.getAttribute().getIdentifier());
} else if (aggregateFunctionExpression instanceof AvgAggregateFunctionExpression) {
newExpression = getAvg(attributes, aggregateFunctionExpression.getAttributeName());
newExpression = getAvg(attributes, aggregateFunctionExpression.getAttribute().getIdentifier());
}
parentExpression.replaceExpressionSubPart(aggregateFunctionExpression, newExpression);
}

private Expression getSum(List<Feature> relevantFeatures, String attributeName) {
if (relevantFeatures.size() == 0) {
if (relevantFeatures.isEmpty()) {
return new NumberExpression(0);
} else if (relevantFeatures.size() == 1) {
LiteralExpression literalExpression = new LiteralExpression(relevantFeatures.get(0), attributeName);
LiteralExpression literalExpression = new LiteralExpression(relevantFeatures.get(0).getAttributes().get(attributeName));
relevantFeatures.remove(0);

return literalExpression;
} else {
LiteralExpression literalExpression = new LiteralExpression(relevantFeatures.get(0), attributeName);
LiteralExpression literalExpression = new LiteralExpression(relevantFeatures.get(0).getAttributes().get(attributeName));
relevantFeatures.remove(0);

return new AddExpression(literalExpression, getSum(relevantFeatures, attributeName));
}
}

private Expression getAvg(List<Feature> relevantFeatures, String attributeName) {
if (relevantFeatures.size() == 0) {
if (relevantFeatures.isEmpty()) {
return new NumberExpression(0);
} else {
for (Feature feature : relevantFeatures) {
feature.getAttributes().put("avg_counter__", new Attribute<Long>("avg_counter__", 1L));
feature.getAttributes().put("avg_counter__", new Attribute<Long>("avg_counter__", 1L, feature));
}
Expression n = getSum(new LinkedList<>(relevantFeatures), "avg_counter__");
Expression sum = getSum(relevantFeatures, attributeName);
Expression avg = new ParenthesisExpression(new DivExpression(new ParenthesisExpression(sum), new ParenthesisExpression(n)));

return avg;
return new ParenthesisExpression(new DivExpression(new ParenthesisExpression(sum), new ParenthesisExpression(n)));
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/main/java/de/vill/conversion/ConvertFeatureCardinality.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void convertFeatureModel(FeatureModel rootFeatureModel, FeatureModel feat

private void traverseFeatures(Feature feature, FeatureModel featureModel) {
if (!feature.isSubmodelRoot()) {
if (feature.getLowerBound() != null) {
if (feature.getCardinality() != null) {
List<Feature> subTreeFeatures = new LinkedList<>();
for (Group group : feature.getChildren()) {
subTreeFeatures.addAll(getFeatureFromSubTree(group));
Expand All @@ -44,16 +44,15 @@ private void traverseFeatures(Feature feature, FeatureModel featureModel) {
}

private void removeFeatureCardinality(Feature feature, FeatureModel featureModel, List<Constraint> constraintsToClone) {
int min = Integer.parseInt(feature.getLowerBound());
int max = Integer.parseInt(feature.getUpperBound());
int min = feature.getCardinality().lower;
int max = feature.getCardinality().upper;
Group newChildren = new Group(Group.GroupType.ALTERNATIVE);

feature.setLowerBound(null);
feature.setUpperBound(null);
feature.setCardinality(null);

for (int i = min; i <= max; i++) {
Feature newChild = new Feature(feature.getFeatureName() + "-" + i);
newChild.getAttributes().put("abstract", new Attribute<Boolean>("abstract", true));
newChild.getAttributes().put("abstract", new Attribute<Boolean>("abstract", true, feature));
newChildren.getFeatures().add(newChild);
newChild.setParentGroup(newChildren);
Group mandatoryGroup = new Group(Group.GroupType.MANDATORY);
Expand Down Expand Up @@ -120,8 +119,8 @@ private List<Feature> getFeatureFromSubTree(Group group) {
private boolean constraintContains(Constraint constraint, List<Feature> subTreeFeatures) {
List<Constraint> subParts = constraint.getConstraintSubParts();
for (Constraint subPart : subParts) {
if (subPart instanceof LiteralConstraint) {
Feature feature = ((LiteralConstraint) subPart).getFeature();
if (subPart instanceof LiteralConstraint && ((LiteralConstraint) subPart).getReference() instanceof Feature) {
Feature feature = (Feature) ((LiteralConstraint) subPart).getReference();
if (subTreeFeatures.contains(feature)) {
return true;
}
Expand All @@ -148,12 +147,10 @@ private void adaptConstraint(Feature subTreeRoot, Constraint constraint, Map<Str
List<Constraint> subParts = constraint.getConstraintSubParts();
for (Constraint subPart : subParts) {
if (subPart instanceof LiteralConstraint) {
String toReplace = ((LiteralConstraint) subPart).getLiteral();
String toReplace = ((LiteralConstraint) subPart).getReference().getIdentifier();
if (featureReplacementMap.containsKey(toReplace)) {
LiteralConstraint subTreeRootConstraint = new LiteralConstraint(subTreeRoot.getFeatureName());
subTreeRootConstraint.setFeature(subTreeRoot);
LiteralConstraint newLiteral = new LiteralConstraint(featureReplacementMap.get(toReplace).getFeatureName());
newLiteral.setFeature(featureReplacementMap.get(toReplace));
LiteralConstraint subTreeRootConstraint = new LiteralConstraint(subTreeRoot);
LiteralConstraint newLiteral = new LiteralConstraint(featureReplacementMap.get(toReplace));
constraint.replaceConstraintSubPart(subPart, new ParenthesisConstraint(new ImplicationConstraint(subTreeRootConstraint, newLiteral)));
}
} else {
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/de/vill/conversion/ConvertGroupCardinality.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ private void removeGroupCardinality(Group group, FeatureModel featureModel) {

Set<Feature> groupMembers = new HashSet<>(group.getFeatures());

int lowerBound = Integer.parseInt(group.getLowerBound());
int upperBound = 0;
if (group.getUpperBound().equals("*")) {
upperBound = groupMembers.size();
} else {
upperBound = Integer.parseInt(group.getUpperBound());
}

int lowerBound = group.getCardinality().lower;
int upperBound = Math.max(group.getCardinality().upper, groupMembers.size());
Set<Set<Feature>> featureCombinations = new HashSet<>();
for (int i = lowerBound; i <= upperBound; i++) {
featureCombinations.addAll(Sets.combinations(groupMembers, i));
Expand All @@ -63,18 +57,17 @@ private void removeGroupCardinality(Group group, FeatureModel featureModel) {
disjunction.add(createConjunction(configuration, new HashSet<>(groupMembers)));
}

featureModel.getOwnConstraints().add(new ImplicationConstraint(new LiteralConstraint(group.getParentFeature().getFeatureName()), new ParenthesisConstraint(createDisjunction(disjunction))));
featureModel.getOwnConstraints().add(new ImplicationConstraint(new LiteralConstraint(group.getParentFeature()), new ParenthesisConstraint(createDisjunction(disjunction))));
}

private Constraint createConjunction(Set<Feature> selectedFeatures, Set<Feature> allFeatures) {
Constraint constraint;
Feature feature = null;
if (allFeatures.size() >= 1) {
if (!allFeatures.isEmpty()) {
feature = allFeatures.iterator().next();
allFeatures.remove(feature);
}
Constraint literalConstraint = new LiteralConstraint(feature.getFeatureName());
((LiteralConstraint) literalConstraint).setFeature(feature);
Constraint literalConstraint = new LiteralConstraint(feature);
if (!selectedFeatures.contains(feature)) {
literalConstraint = new NotConstraint(literalConstraint);
}
Expand Down
Loading
Loading