Commit 69e1aaad authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Feature Model: Added check for uniqueness of feature names

Feature names are now checked to be unique among all literals.

Issure-ref: 4278
Issue-URL: #4278



Signed-off-by: Andreas Bayha's avatarAndreas Bayha <bayha@fortiss.org>
parent 82dbb08c
Pipeline #37104 passed with stage
in 10 minutes and 58 seconds
......@@ -53,6 +53,12 @@
modelElementClass="org.fortiss.variability.model.features.AbstractFeature">
</modelElementClass>
</modelElementConstraintChecker>
<modelElementConstraintChecker
checker="org.fortiss.af3.variability.featuremodel.constraint.FeatureNameUniqueConstraintChecker">
<modelElementClass
modelElementClass="org.fortiss.variability.model.features.AbstractFeature">
</modelElementClass>
</modelElementConstraintChecker>
</extension>
</plugin>
FeatureNameConstraintChecker.java 208ffa2246c1b4b7acb90065bf7004dc3ea038f4 GREEN
FeatureNameConstraintChecker.java 4c9c711aef731acae2d703eb0ac39e9ee59cbd79 YELLOW
FeatureNameUniqueConstraintChecker.java aa2de4c71083f36f61d5b280efde31af8bf250e9 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2022 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.variability.featuremodel.constraint;
import static java.util.Collections.singletonList;
import static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity.ERROR;
import static org.fortiss.variability.util.VariabilityUtils.getLiteralsWithName;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.base.ConstraintCheckerBase;
import org.fortiss.tooling.kernel.extension.base.ConstraintViolationBase;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.variability.model.features.AbstractFeature;
import org.fortiss.variability.model.presence.ILiteralReferencable;
/**
* Checks feature names to be unique among all literals.
*
* @author bayha
*/
public class FeatureNameUniqueConstraintChecker extends ConstraintCheckerBase<AbstractFeature> {
/** {@inheritDoc} */
@Override
public List<? extends IConstraintViolation<? extends EObject>>
apply(AbstractFeature modelElement) {
String featureName = modelElement.getName();
List<ILiteralReferencable> literals = getLiteralsWithName(modelElement, featureName);
for(ILiteralReferencable l : literals) {
if(l != modelElement) {
// other object with same name found.
return singletonList(new ConstraintViolationBase<EObject>(modelElement, ERROR,
"The feature name \"" + featureName + "\" is not unique!"));
}
}
return super.apply(modelElement);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment