Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2018-06-22 13:29:20 +0000
committerBenoit Maggi2018-06-25 11:50:22 +0000
commita1fb9d3bd28792386e25c71e89b16ad812b5da32 (patch)
treed3cbc902c1d0263ccc752ee1a816f98c989331e7 /plugins
parente6b916a145ba0c72e3c6c09b2548381ab0b701b6 (diff)
downloadorg.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.tar.gz
org.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.tar.xz
org.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.zip
Bug 536183 - [AFViewpoints] NPE in Policychecker
- fix NPE in PolicyChecker.isInViewpoint - add unit test for PolicyChecker - add test in infra Test suite (to be executed in build) - quality fix in policy plugin - remove remaining pom of a deleted plugin Change-Id: I532ef62dcccbfcd11f8ceda5d190705fffa36c36 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF1
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java2
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java8
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java3
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java18
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java4
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java2
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java4
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java11
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java6
10 files changed, 23 insertions, 36 deletions
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
index 4a6119408ca..85e4bb88406 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
@@ -3,6 +3,7 @@ Export-Package: org.eclipse.papyrus.infra.viewpoints.configuration,
org.eclipse.papyrus.infra.viewpoints.configuration.impl,
org.eclipse.papyrus.infra.viewpoints.configuration.util,
org.eclipse.papyrus.infra.viewpoints.policy,
+ org.eclipse.papyrus.infra.viewpoints.policy.providers,
org.eclipse.papyrus.infra.viewpoints.policy.query,
org.eclipse.papyrus.infra.viewpoints.style,
org.eclipse.papyrus.infra.viewpoints.style.impl,
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java
index 2b4d148b5cf..d0911f8459c 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java
@@ -75,7 +75,7 @@ public class ModelAddData {
public ModelAddData(boolean permit, EList<PathElement> insertionPath) {
this.permit = permit;
if (insertionPath != null && !insertionPath.isEmpty()) {
- this.path = new ArrayList<EReference>(insertionPath.size());
+ this.path = new ArrayList<>(insertionPath.size());
for (int i = 0; i != insertionPath.size(); i++) {
path.add(insertionPath.get(i).getFeature());
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java
index b4f38600bab..882d538a8f7 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java
@@ -35,7 +35,7 @@ import org.eclipse.papyrus.infra.architecture.representation.ModelRule;
*/
public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule> {
- protected final Map<ModelRule, List<Constraint>> modelRule2Constraints = new HashMap<ModelRule, List<Constraint>>();
+ protected final Map<ModelRule, List<Constraint>> modelRule2Constraints = new HashMap<>();
/** singleton instance */
private static ModelRuleConstraintEngine instance;
@@ -62,7 +62,7 @@ public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule
public boolean matchesRule(ModelRule rule, EObject element) {
Collection<EObject> selection = Collections.singletonList(element);
List<Constraint> constraints = getConstraintsFor(rule);
- if (constraints == null || constraints.size() == 0) {
+ if (constraints == null || constraints.isEmpty()) {
return true;
}
for (Constraint c : constraints) {
@@ -103,11 +103,11 @@ public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule
*/
protected List<Constraint> initializeConstraints(ModelRule rule) {
List<ConstraintDescriptor> descriptors = rule.getConstraints();
- if (descriptors == null || descriptors.size() == 0) {
+ if (descriptors == null || descriptors.isEmpty()) {
return Collections.emptyList();
}
- List<Constraint> constraints = new ArrayList<Constraint>();
+ List<Constraint> constraints = new ArrayList<>();
for (ConstraintDescriptor descriptor : descriptors) {
try {
Constraint constraint = ConstraintFactory.getInstance().createFromModel(descriptor);
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java
index 5dc2f91b291..4948648d28c 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java
@@ -116,7 +116,7 @@ public class NotationUtils {
}
IAdaptable input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput();
if (input != null) {
- EObject obj = (EObject) input.getAdapter(EObject.class);
+ EObject obj = input.getAdapter(EObject.class);
return tryGetNotationResources(obj);
}
return null;
@@ -177,6 +177,7 @@ public class NotationUtils {
return result;
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
index 0e2d531e6d0..408e3c76ac8 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
@@ -311,14 +311,9 @@ public class PolicyChecker {
* @since 2.0
*/
public boolean isInViewpoint(PapyrusRepresentationKind kind) {
- for (MergedArchitectureViewpoint viewpoint : getViewpoints()) {
- for (RepresentationKind aKind : viewpoint.getRepresentationKinds()) {
- if (aKind.getQualifiedName().equals(kind.getQualifiedName())) {
- return true;
- }
- }
- }
- return false;
+ return kind!=null && getViewpoints().stream()
+ .flatMap(viewpoint -> viewpoint.getRepresentationKinds().stream())
+ .anyMatch(representationKinds -> representationKinds.getQualifiedName().equals(kind.getQualifiedName()));
}
/**
@@ -327,7 +322,7 @@ public class PolicyChecker {
* @return A collection of view prototypes
*/
public Collection<ViewPrototype> getAllPrototypes() {
- Collection<ViewPrototype> result = new ArrayList<ViewPrototype>();
+ Collection<ViewPrototype> result = new ArrayList<>();
for (MergedArchitectureViewpoint viewpoint : getViewpoints()) {
for (RepresentationKind kind : viewpoint.getRepresentationKinds()) {
PapyrusRepresentationKind view = (PapyrusRepresentationKind) kind;
@@ -348,7 +343,7 @@ public class PolicyChecker {
* @return A list of the prototypes that can be instantiated
*/
public Collection<ViewPrototype> getPrototypesFor(EObject element) {
- Collection<ViewPrototype> result = new LinkedHashSet<ViewPrototype>();
+ Collection<ViewPrototype> result = new LinkedHashSet<>();
Collection<EPackage> profiles = profileHelper.getAppliedProfiles(element);
Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(element);
for (MergedArchitectureViewpoint viewpoint : getViewpoints()) {
@@ -397,8 +392,7 @@ public class PolicyChecker {
public OwningRule getOwningRuleFor(ViewPrototype prototype, EObject owner) {
Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(owner);
int count = prototype.getOwnedViewCount(owner);
- OwningRule rule = matchesCreationOwner(prototype.representationKind, owner, stereotypes, count);
- return rule;
+ return matchesCreationOwner(prototype.representationKind, owner, stereotypes, count);
}
/**
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java
index 082307e1dca..93664c93b23 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java
@@ -84,14 +84,14 @@ public class ProfileUtils {
* @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedProfiles(org.eclipse.emf.ecore.EObject)
*/
public Collection<EPackage> getAppliedProfiles(EObject model) {
- return new ArrayList<EPackage>(0);
+ return new ArrayList<>(0);
}
/**
* @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedStereotypes(org.eclipse.emf.ecore.EObject)
*/
public Collection<EClass> getAppliedStereotypes(EObject object) {
- return new ArrayList<EClass>(0);
+ return new ArrayList<>(0);
}
}
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java
index 34a249dcabd..a6a60955b56 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java
@@ -39,7 +39,7 @@ public class RuleConstraintManager {
public boolean matchRule(ModelRule rule, EObject element) {
// if no rule, return true
List<ConstraintDescriptor> constraintDescriptors = rule.getConstraints();
- if (constraintDescriptors == null || constraintDescriptors.size() == 0) {
+ if (constraintDescriptors == null || constraintDescriptors.isEmpty()) {
return true;
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
index b7ac8b6b91c..917ba0f0a64 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
@@ -81,7 +81,7 @@ public abstract class ViewPrototype {
// Sort by priority
Collections.sort(elements, helperConfigComparator());
- Collection<IViewTypeHelper> result = new ArrayList<IViewTypeHelper>();
+ Collection<IViewTypeHelper> result = new ArrayList<>();
for (IConfigurationElement element : elements) {
try {
IViewTypeHelper instance = (IViewTypeHelper) element.createExecutableExtension("class");
@@ -371,7 +371,7 @@ public abstract class ViewPrototype {
* @author Laurent Wouters
*/
public static class Comp implements Comparator<ViewPrototype> {
- private static final Map<Class<? extends PapyrusRepresentationKind>, Integer> priorities = new HashMap<Class<? extends PapyrusRepresentationKind>, Integer>();
+ private static final Map<Class<? extends PapyrusRepresentationKind>, Integer> priorities = new HashMap<>();
{
priorities.put(PapyrusDiagram.class, 1);
priorities.put(PapyrusTable.class, 2);
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java
index 06d9951d47d..e2dd28f92e7 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java
@@ -33,7 +33,6 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils;
-import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureDescriptionLanguage;
import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureFramework;
@@ -96,16 +95,12 @@ public class ViewpointExplorer extends ViewPart {
contentProvider = new AdapterFactoryContentProvider(adapterFactory);
labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, null, new HashMap<Resource, Boolean>()) {
- public boolean isReadOnly(Resource resource) {
+ @Override
+ public boolean isReadOnly(Resource resource) {
return true; // to make the editing domain non-editable
}
};
}
-
- @Override
- public void init(IViewSite site) throws PartInitException {
- super.init(site);
- }
/*
* (non-Javadoc)
@@ -285,7 +280,7 @@ public class ViewpointExplorer extends ViewPart {
* @since 3.0
*/
public Object[] getPropertySources(Object[] objects) {
- ArrayList<Object> propertySources = new ArrayList<Object>();
+ ArrayList<Object> propertySources = new ArrayList<>();
for (Object object : objects) {
propertySources.add(getPropertySource(object));
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java
index eb58c6e3087..2d92dc1663b 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java
@@ -63,11 +63,7 @@ public class IsContainedByProfileQuery implements JavaQuery {
}
String eclassName = eclass.getName();
- if ("Profile".equals(eclassName)) {
- return true;
- }
- return false;
-
+ return "Profile".equals(eclassName);
}
}

Back to the top