diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/.ratings b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/.ratings index 8fd98fd2d04b97fa3bb7a55145e9589c71db4fb1..da06f1f9f005d0cc2c68437bb55349018a7e3c0b 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/.ratings +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/.ratings @@ -1 +1 @@ -ToolingReuseActivator.java 3a735e7e2c75e9b048f94bf1adeb172b83301639 GREEN +ToolingReuseActivator.java 52b9208684334f60ee8c0bc074c86f06f6248227 GREEN diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/ToolingReuseActivator.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/ToolingReuseActivator.java index 3a735e7e2c75e9b048f94bf1adeb172b83301639..52b9208684334f60ee8c0bc074c86f06f6248227 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/ToolingReuseActivator.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/ToolingReuseActivator.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2021 fortiss GmbH | +| 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. | @@ -16,6 +16,8 @@ package org.fortiss.tooling.ext.reuse; import org.eclipse.core.runtime.Plugin; +import org.fortiss.tooling.ext.reuse.model.ReuseLibrary; +import org.fortiss.tooling.kernel.service.IConstraintCheckerService; import org.osgi.framework.BundleContext; /** @@ -36,6 +38,12 @@ public class ToolingReuseActivator extends Plugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; + + // Objects within a ReuseLibrary do not need to comply with the constraint checks with which + // they should comply when they are outside of it (in a normal project). This is why the + // ReuseLibrary needs to be registered as an exclusion for all the usual constraint checks. + IConstraintCheckerService ccs = IConstraintCheckerService.getInstance(); + ccs.registerTypeAsExcludedParentForConstraintChecks(ReuseLibrary.class); } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings index 1909826b62851eefe523cae3710501c02a39b8fa..f96feef16f57e0193a0c6c6a76223b4e1a5c5126 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings @@ -1,7 +1,7 @@ CommandLineInterfaceService.java 6b5c94c52702f773c60b181eff52204ab379b248 GREEN CommandStackService.java 957bda69b5feb91f002aed4d25ed334e92801e7e GREEN ConnectionCompositorService.java 5a52f8a3e88c167ae6909c3d9eb3fb4706177e8b GREEN -ConstraintCheckerService.java abd4667ceef11c47235e20a6566d8943f3417cf3 GREEN +ConstraintCheckerService.java df7b4e8c99e8895e14ff45a96cc85ef8403a8658 GREEN DummyTopLevelElement.java 21807bbdafec2e0ef28f0ee9090218f90bd73aee GREEN ElementCompositorService.java b1924b5b349118a70149cfac5b48544897d26e9e GREEN LoggingService.java da784259f7b456b54bf75c41ec268f64919ce78d GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintCheckerService.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintCheckerService.java index abd4667ceef11c47235e20a6566d8943f3417cf3..df7b4e8c99e8895e14ff45a96cc85ef8403a8658 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintCheckerService.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintCheckerService.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2011 fortiss GmbH | +| 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. | @@ -17,6 +17,7 @@ package org.fortiss.tooling.kernel.internal; import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableMap; +import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWithType; import java.util.ArrayList; import java.util.Collections; @@ -60,6 +61,13 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain /** The constraint checker handler attribute name. */ private static final String HANDLER_CLASS_ATTRIBUTE_NAME = "checker"; + /** + * A list of all the classes whose elements are excluded from constraint checks. This exclusion + * also applies to all of their children, i.e., if an element has a parent whose class is stored + * in this list, it will also be excluded from all constraint checks. + */ + private static List<Class<? extends EObject>> constraintCheckExclusionTypes = new ArrayList<>(); + /** {@inheritDoc} */ @Override public void startService() { @@ -73,6 +81,12 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain addHandler(modelElementClass, checker); } + /** {@inheritDoc} */ + @Override + public void registerTypeAsExcludedParentForConstraintChecks(Class<? extends EObject> clazz) { + constraintCheckExclusionTypes.add(clazz); + } + /** {@inheritDoc} */ @Override public String getIntrospectionDescription() { @@ -109,12 +123,23 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain } /** - * Performs all constraint checks on the given model element. Violations are - * added to the given list. Constraint checks on content elements are not - * considered. + * Performs all constraint checks on the given model element if itself or its parents are not + * excluded from such checks. Violations are added to the given list. Constraint checks on + * content elements are not considered. */ private void performConstraintCheck(EObject modelElement, List<IConstraintViolation<? extends EObject>> violationList) { + + // Skip constraint checks if the given element itself is excluded from checks or if it + // exists within an excluded element. + for(Class<? extends EObject> excludedClass : constraintCheckExclusionTypes) { + Object foundExcludedParent = getFirstParentWithType(modelElement, excludedClass); + Class<?> givenClass = modelElement.getClass(); + if(givenClass.isAssignableFrom(excludedClass) || foundExcludedParent != null) { + return; + } + } + List<IConstraintChecker<EObject>> handlers = getRegisteredHandlers(modelElement.getClass()); if(handlers == null) { return; diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/.ratings index 7b59a6c1817ab30aaab2e5b51622a26e3736a3bd..3697f4effdd95c8570df4d662566f770759e3143 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/.ratings @@ -1,7 +1,7 @@ ICommandLineInterfaceService.java c3e3ba08b2a1b8125b43abd1c29b7dc0a0be2b80 GREEN ICommandStackService.java 678dcd1a6ab435ed0870fa2a9ec48ce47f25a187 GREEN IConnectionCompositorService.java 0cdf4568b2cd3e95ea195df90a84699eff36442b GREEN -IConstraintCheckerService.java 291e53297aaea213e07e78f63350938ee2c7b155 GREEN +IConstraintCheckerService.java dc04965ac0265f77cb846f472d76620fb05a491a GREEN IEclipseResourceStorageService.java b1155ca15cd9474d4d533d6cb2725e8a22040ec9 GREEN IElementCompositorService.java acd462ec15f3bcc247b544b46ceebee971fe1408 GREEN IKernelIntrospectionSystemService.java 7005c3acb4c6f978729d93279c595765e94e38eb GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintCheckerService.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintCheckerService.java index 291e53297aaea213e07e78f63350938ee2c7b155..dc04965ac0265f77cb846f472d76620fb05a491a 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintCheckerService.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintCheckerService.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2011 fortiss GmbH | +| 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. | @@ -63,4 +63,11 @@ public interface IConstraintCheckerService { /** Registers the given checker with the service. */ void registerConstraintChecker(IConstraintChecker<EObject> checker, Class<?> modelElementClass); + + /** + * Registers the given {@link Class} as an exclusion for all constraint checks, i.e., for all + * elements of this {@link Class} and for all children of such elements the existing constraint + * checks will be skipped. + */ + void registerTypeAsExcludedParentForConstraintChecks(Class<? extends EObject> clazz); }