Skip to content
Snippets Groups Projects
Commit e6513b17 authored by Simon Barner's avatar Simon Barner
Browse files

Merge branch 'master' of https://git.fortiss.org/af3/kernel.git into 4310

parents 37047402 b41ae985
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
Pipeline #39360 failed
Pipeline: maven-releng

#39361

    /*-------------------------------------------------------------------------+
    | Copyright 2023 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.variability.analysis;
    import java.util.List;
    import org.eclipse.emf.ecore.EObject;
    import org.fortiss.variability.model.features.configuration.VariantConfiguration;
    /**
    * Class representing one error identified by a product line analysis run.
    *
    * @author bayha
    */
    public class ProductLineConstraintViolation {
    /** The model elements which cause a constraint violation. */
    protected List<EObject> violatingElements;
    /** The violated constraint. */
    protected IProductLineConstraint constraint;
    /** The configuration which will result in a model variant which violates the constraint. */
    private VariantConfiguration violatingConfiguration;
    /** Constructor. */
    public ProductLineConstraintViolation(IProductLineConstraint constraint,
    List<EObject> violatingElements, VariantConfiguration violatingConfiguration) {
    this.constraint = constraint;
    this.violatingElements = violatingElements;
    this.violatingConfiguration = violatingConfiguration;
    }
    /**
    * Returns the elements which causes the violation.
    *
    * @return The elements which causes the violation.
    */
    public List<EObject> getViolatingElements() {
    return violatingElements;
    }
    /**
    * Returns the error message.
    *
    * @return The error message.
    */
    public String getErrorMessage() {
    return constraint.createErrorMessage(violatingElements, violatingConfiguration);
    }
    /**
    * Returns the constraint that has been violated.
    *
    * @return The constraint that has been violated.
    */
    public IProductLineConstraint getConstraint() {
    return constraint;
    }
    /**
    * Returns the configuration which will violate the constraint.
    *
    * @return The configuration which will violate the constraint.
    */
    public VariantConfiguration getViolatingConfiguration() {
    return violatingConfiguration;
    }
    }
    VariabilityModelElementFactory.java 5a50d78b0fc94a20329b95991b519a3e3fbf4410 GREEN
    VariabilityStaticImpl.java 96bc4364ebe635c94fafbd3ef60b8237b18c17c6 GREEN
    VariabilityStaticImpl.java 9d913de8c14b22b07d318084abd911c6d5692977 GREEN
    ......@@ -17,10 +17,12 @@ package org.fortiss.variability.model;
    import static java.util.stream.Collectors.toList;
    import static org.eclipse.emf.ecore.util.EcoreUtil.delete;
    import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
    import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
    import static org.fortiss.variability.model.VariabilityModelElementFactory.createAndPC;
    import static org.fortiss.variability.model.VariabilityModelElementFactory.createLiteralPC;
    import static org.fortiss.variability.model.VariabilityModelElementFactory.createNotPC;
    import static org.fortiss.variability.model.VariabilityModelElementFactory.createOrPC;
    import java.util.List;
    import java.util.stream.Stream;
    ......@@ -335,4 +337,62 @@ public class VariabilityStaticImpl {
    return target.getClass() == subject.getClass() &&
    ((AbstractFeature)target).getName().equals(subject.getName());
    }
    /**
    * Creates a new {@link PresenceConditionTerm} which is semantically equivalent to the given
    * {@link AndPC} but only uses features as literals.
    *
    * @param and
    * The {@link AndPC} to resolve.
    * @return A {@link PresenceConditionTerm} with features as literals, only.
    */
    public static PresenceConditionTerm resolveToFeatureLiterals(AndPC and) {
    return createAndPC(and.getOperand1().resolveToFeatureLiterals(),
    and.getOperand2().resolveToFeatureLiterals(), "");
    }
    /**
    * Creates a new {@link PresenceConditionTerm} which is semantically equivalent to the given
    * {@link OrPC} but only uses features as literals.
    *
    * @param or
    * The {@link OrPC} to resolve.
    * @return A {@link PresenceConditionTerm} with features as literals, only.
    */
    public static PresenceConditionTerm resolveToFeatureLiterals(OrPC or) {
    return createOrPC(or.getOperand1().resolveToFeatureLiterals(),
    or.getOperand2().resolveToFeatureLiterals(), "");
    }
    /**
    * Creates a new {@link PresenceConditionTerm} which is semantically equivalent to the given
    * {@link NotPC} but only uses features as literals.
    *
    * @param not
    * The {@link NotPC} to resolve.
    * @return A {@link PresenceConditionTerm} with features as literals, only.
    */
    public static PresenceConditionTerm resolveToFeatureLiterals(NotPC not) {
    return createNotPC(not.getOperand().resolveToFeatureLiterals(), "");
    }
    /**
    * Creates a new {@link PresenceConditionTerm} which is semantically equivalent to the given
    * {@link LiteralPC} but only uses features as literals.
    *
    * In case the given literal refers to a feature already, the result will be syntactically
    * equivalent.
    *
    * @param literal
    * The {@link LiteralPC} to resolve.
    * @return A {@link PresenceConditionTerm} with features as literals, only.
    */
    public static PresenceConditionTerm resolveToFeatureLiterals(LiteralPC literal) {
    ILiteralReferencable reference = literal.getLiteralReference();
    if(reference == null || reference instanceof AbstractFeature) {
    return copy(literal);
    }
    return reference.resolveToFeatureLiterals();
    }
    }
    FeatureModelTransformationUtils.java b38702296dcb48ff311b382bb9c05d2590e2dfac GREEN
    Pair.java 2dfd7dc65f7b9ba09a120f1a6058d1e8e9556a37 GREEN
    VariabilityUtils.java 3e57a37ced6396076c71227aea8de534381b6ace GREEN
    VariabilityUtilsInternal.java 9c781a47513bb0c4ddcd13be1c27d62b70f25998 GREEN
    VariabilityUtilsInternal.java 612c248ae391aeeb0ad80a23abc50974004c5349 GREEN
    ......@@ -16,9 +16,14 @@
    +--------------------------------------------------------------------------*/
    package org.fortiss.variability.util;
    import static org.eclipse.core.runtime.IStatus.ERROR;
    import static org.eclipse.core.runtime.IStatus.INFO;
    import static org.eclipse.core.runtime.IStatus.WARNING;
    import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
    import static org.eclipse.emf.ecore.util.EcoreUtil.getRootContainer;
    import static org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer.find;
    import static org.fortiss.variability.VariabilityActivator.getDefault;
    import static org.fortiss.variability.model.VariabilityModelElementFactory.createAndPC;
    import java.util.Collection;
    import java.util.LinkedList;
    ......@@ -27,6 +32,9 @@ import java.util.Map;
    import java.util.Queue;
    import java.util.function.Predicate;
    import org.eclipse.core.runtime.IStatus;
    import org.eclipse.core.runtime.Plugin;
    import org.eclipse.core.runtime.Status;
    import org.eclipse.emf.common.util.BasicEList;
    import org.eclipse.emf.common.util.EList;
    import org.eclipse.emf.common.util.TreeIterator;
    ......@@ -35,10 +43,15 @@ import org.eclipse.emf.ecore.EStructuralFeature;
    import org.eclipse.emf.ecore.resource.Resource;
    import org.eclipse.emf.ecore.resource.ResourceSet;
    import org.eclipse.emf.ecore.util.EcoreUtil;
    import org.fortiss.variability.model.presence.IHasPresenceCondition;
    import org.fortiss.variability.model.presence.PresenceConditionTerm;
    /**
    * Utility functions that are used within the variability layers.
    *
    * This class contains duplicates of EcoreUtils of the fortiss Tooling Kernel to enable a usage of
    * this variability plugin independent of the tooling kernel.
    *
    * @author bayha
    */
    public class VariabilityUtilsInternal {
    ......@@ -222,4 +235,93 @@ public class VariabilityUtilsInternal {
    return usages;
    }
    /**
    * Calculates a self contained presence condition of the given element which takes into account
    * all presence conditions of parent objects in the containment hierarchy.
    *
    * Note, that this util method should only be used internally in this plugin, as the variation
    * point implementation could be different in higher level plugins.
    *
    * @param elem
    * The {@link EObject} object for which to calculate a global
    * {@link PresenceConditionTerm}.
    * @return A {@link PresenceConditionTerm} which expresses the presence condition including
    * constraints of all parents; 'null' if there is no restriction.
    */
    public static PresenceConditionTerm calculateGlobalPresenceCondition(EObject elem) {
    EObject parent = elem.eContainer();
    PresenceConditionTerm parentPC = null;
    if(parent != null) {
    parentPC = calculateGlobalPresenceCondition(parent);
    }
    PresenceConditionTerm rest = null;
    if(elem instanceof IHasPresenceCondition) {
    // Here, DEFAULT literals need to be resolved.
    rest = ((IHasPresenceCondition)elem).getPresenceCondition().resolveToFeatureLiterals();
    }
    if(parentPC != null) {
    if(rest != null) {
    return createAndPC(parentPC, rest, "");
    }
    return parentPC;
    }
    return rest;
    }
    /**
    * Logs a message that occurred in the context of the given plug-in with the
    * given severity and a given {@link Throwable} that originally caused this
    * log message.
    */
    private static void log(Plugin plugin, String message, int severity, Throwable cause) {
    String pluginId = plugin.getBundle().getSymbolicName();
    IStatus status = new Status(severity, pluginId, message, cause);
    plugin.getLog().log(status);
    }
    /**
    * Logs an info message that occurred in the context of the variability plug-in.
    *
    * @param message
    * The {@link String} with the info message to be logged.
    */
    public static void logInfo(String message) {
    log(getDefault(), message, INFO, null);
    }
    /**
    * Logs a warning that occurred in the context of the variability plug-in.
    *
    * @param message
    * The {@link String} with the warning message to be logged.
    */
    public static void logWarning(String message) {
    log(getDefault(), message, WARNING, null);
    }
    /**
    * Logs an error that occurred in the context of the variability plug-in.
    *
    * @param message
    * The {@link String} with the error message to be logged.
    * @param exception
    * The {@link Exception} that originally caused this log message.
    */
    public static void logError(String message, Exception exception) {
    log(getDefault(), message, ERROR, exception);
    }
    /**
    * Logs an error that occurred in the context of the variability plug-in.
    *
    * @param message
    * The {@link String} with the error message to be logged.
    */
    public static void logError(String message) {
    log(getDefault(), message, ERROR, null);
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment