diff options
author | 2021-10-02 20:51:58 +0200 | |
---|---|---|
committer | 2021-10-02 20:51:58 +0200 | |
commit | 9b8236dd7499510577c32f0d87dfd52d34f6b023 (patch) | |
tree | d9e35fa5692e3b08d0bcf1fbbd538c65ed4b58e1 /language/src | |
parent | build: simplify Eclipse project generation (diff) | |
download | refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.tar.gz refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.tar.zst refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.zip |
chore: fix Java 17 Sonar warnings
Had to disable code coverage measurement in the Quality Gate, we should
switch it on again once we have a complete test suite.
Diffstat (limited to 'language/src')
7 files changed, 30 insertions, 42 deletions
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java b/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java index 1581186c..a2938274 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java | |||
@@ -74,8 +74,8 @@ public final class ProblemUtil { | |||
74 | if (!found.contains(current)) { | 74 | if (!found.contains(current)) { |
75 | found.add(current); | 75 | found.add(current); |
76 | for (Relation superType : current.getSuperTypes()) { | 76 | for (Relation superType : current.getSuperTypes()) { |
77 | if (superType instanceof ClassDeclaration) { | 77 | if (superType instanceof ClassDeclaration superDeclaration) { |
78 | queue.addLast((ClassDeclaration) superType); | 78 | queue.addLast(superDeclaration); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java index 1b0146b6..2789f590 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java | |||
@@ -45,8 +45,7 @@ public class DerivedVariableComputer { | |||
45 | 45 | ||
46 | public void installDerivedVariables(Problem problem, Set<String> nodeNames) { | 46 | public void installDerivedVariables(Problem problem, Set<String> nodeNames) { |
47 | for (Statement statement : problem.getStatements()) { | 47 | for (Statement statement : problem.getStatements()) { |
48 | if (statement instanceof PredicateDefinition) { | 48 | if (statement instanceof PredicateDefinition definition) { |
49 | PredicateDefinition definition = (PredicateDefinition) statement; | ||
50 | installDerivedPredicateDefinitionState(definition, nodeNames); | 49 | installDerivedPredicateDefinitionState(definition, nodeNames); |
51 | } | 50 | } |
52 | } | 51 | } |
@@ -69,16 +68,14 @@ public class DerivedVariableComputer { | |||
69 | protected void installDeriveConjunctionState(Conjunction conjunction, Set<String> knownVariables) { | 68 | protected void installDeriveConjunctionState(Conjunction conjunction, Set<String> knownVariables) { |
70 | Set<String> newVariables = new HashSet<>(); | 69 | Set<String> newVariables = new HashSet<>(); |
71 | for (Literal literal : conjunction.getLiterals()) { | 70 | for (Literal literal : conjunction.getLiterals()) { |
72 | if (literal instanceof Atom) { | 71 | if (literal instanceof Atom atom) { |
73 | var atom = (Atom) literal; | ||
74 | createSigletonVariablesAndCollectVariables(atom, knownVariables, newVariables); | 72 | createSigletonVariablesAndCollectVariables(atom, knownVariables, newVariables); |
75 | } | 73 | } |
76 | } | 74 | } |
77 | createVariables(conjunction, newVariables); | 75 | createVariables(conjunction, newVariables); |
78 | newVariables.addAll(knownVariables); | 76 | newVariables.addAll(knownVariables); |
79 | for (Literal literal : conjunction.getLiterals()) { | 77 | for (Literal literal : conjunction.getLiterals()) { |
80 | if (literal instanceof NegativeLiteral) { | 78 | if (literal instanceof NegativeLiteral negativeLiteral) { |
81 | var negativeLiteral = (NegativeLiteral) literal; | ||
82 | installDeriveNegativeLiteralState(negativeLiteral, newVariables); | 79 | installDeriveNegativeLiteralState(negativeLiteral, newVariables); |
83 | } | 80 | } |
84 | } | 81 | } |
@@ -93,8 +90,7 @@ public class DerivedVariableComputer { | |||
93 | protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, | 90 | protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, |
94 | Set<String> newVariables) { | 91 | Set<String> newVariables) { |
95 | for (Argument argument : atom.getArguments()) { | 92 | for (Argument argument : atom.getArguments()) { |
96 | if (argument instanceof VariableOrNodeArgument) { | 93 | if (argument instanceof VariableOrNodeArgument variableOrNodeArgument) { |
97 | var variableOrNodeArgument = (VariableOrNodeArgument) argument; | ||
98 | IScope scope = scopeProvider.getScope(variableOrNodeArgument, | 94 | IScope scope = scopeProvider.getScope(variableOrNodeArgument, |
99 | ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE); | 95 | ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE); |
100 | List<INode> nodes = NodeModelUtils.findNodesForFeature(variableOrNodeArgument, | 96 | List<INode> nodes = NodeModelUtils.findNodesForFeature(variableOrNodeArgument, |
@@ -159,8 +155,8 @@ public class DerivedVariableComputer { | |||
159 | 155 | ||
160 | public void discardDerivedVariables(Problem problem) { | 156 | public void discardDerivedVariables(Problem problem) { |
161 | for (Statement statement : problem.getStatements()) { | 157 | for (Statement statement : problem.getStatements()) { |
162 | if (statement instanceof PredicateDefinition) { | 158 | if (statement instanceof PredicateDefinition predicateDefinition) { |
163 | discardPredicateDefinitionState((PredicateDefinition) statement); | 159 | discardPredicateDefinitionState(predicateDefinition); |
164 | } | 160 | } |
165 | } | 161 | } |
166 | } | 162 | } |
@@ -169,11 +165,10 @@ public class DerivedVariableComputer { | |||
169 | for (Conjunction body : definition.getBodies()) { | 165 | for (Conjunction body : definition.getBodies()) { |
170 | body.getImplicitVariables().clear(); | 166 | body.getImplicitVariables().clear(); |
171 | for (Literal literal : body.getLiterals()) { | 167 | for (Literal literal : body.getLiterals()) { |
172 | if (literal instanceof Atom) { | 168 | if (literal instanceof Atom atom) { |
173 | discardDerivedAtomState((Atom) literal); | 169 | discardDerivedAtomState(atom); |
174 | } | 170 | } |
175 | if (literal instanceof NegativeLiteral) { | 171 | if (literal instanceof NegativeLiteral negativeLiteral) { |
176 | var negativeLiteral = (NegativeLiteral) literal; | ||
177 | negativeLiteral.getImplicitVariables().clear(); | 172 | negativeLiteral.getImplicitVariables().clear(); |
178 | discardDerivedAtomState(negativeLiteral.getAtom()); | 173 | discardDerivedAtomState(negativeLiteral.getAtom()); |
179 | } | 174 | } |
@@ -186,8 +181,7 @@ public class DerivedVariableComputer { | |||
186 | return; | 181 | return; |
187 | } | 182 | } |
188 | for (Argument argument : atom.getArguments()) { | 183 | for (Argument argument : atom.getArguments()) { |
189 | if (argument instanceof VariableOrNodeArgument) { | 184 | if (argument instanceof VariableOrNodeArgument variableOrNodeArgument) { |
190 | var variableOrNodeArgument = (VariableOrNodeArgument) argument; | ||
191 | variableOrNodeArgument.setSingletonVariable(null); | 185 | variableOrNodeArgument.setSingletonVariable(null); |
192 | } | 186 | } |
193 | } | 187 | } |
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java index e9533c25..415db9a9 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java | |||
@@ -52,10 +52,10 @@ public class NodeNameCollector { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | protected void collectStatementNodeNames(Statement statement) { | 54 | protected void collectStatementNodeNames(Statement statement) { |
55 | if (statement instanceof Assertion) { | 55 | if (statement instanceof Assertion assertion) { |
56 | collectAssertionNodeNames((Assertion) statement); | 56 | collectAssertionNodeNames(assertion); |
57 | } else if (statement instanceof NodeValueAssertion) { | 57 | } else if (statement instanceof NodeValueAssertion nodeValueAssertion) { |
58 | collectNodeValueAssertionNodeNames((NodeValueAssertion) statement); | 58 | collectNodeValueAssertionNodeNames(nodeValueAssertion); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java index a2d0eef6..3c6c8273 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java | |||
@@ -62,8 +62,8 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
62 | return null; | 62 | return null; |
63 | } | 63 | } |
64 | EObject object = contents.get(0); | 64 | EObject object = contents.get(0); |
65 | if (object instanceof Problem) { | 65 | if (object instanceof Problem problem) { |
66 | return (Problem) object; | 66 | return problem; |
67 | } | 67 | } |
68 | return null; | 68 | return null; |
69 | } | 69 | } |
@@ -79,12 +79,10 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
79 | 79 | ||
80 | protected void installNewNodes(Problem problem, Adapter adapter) { | 80 | protected void installNewNodes(Problem problem, Adapter adapter) { |
81 | for (Statement statement : problem.getStatements()) { | 81 | for (Statement statement : problem.getStatements()) { |
82 | if (statement instanceof ClassDeclaration) { | 82 | if (statement instanceof ClassDeclaration declaration && !declaration.isAbstract() |
83 | var declaration = (ClassDeclaration) statement; | 83 | && declaration.getNewNode() == null) { |
84 | if (!declaration.isAbstract() && declaration.getNewNode() == null) { | 84 | var newNode = adapter.createNodeIfAbsent(declaration, key -> createNode(NEW_NODE)); |
85 | var newNode = adapter.createNodeIfAbsent(declaration, key -> createNode(NEW_NODE)); | 85 | declaration.setNewNode(newNode); |
86 | declaration.setNewNode(newNode); | ||
87 | } | ||
88 | } | 86 | } |
89 | } | 87 | } |
90 | } | 88 | } |
@@ -120,8 +118,7 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
120 | Set<ClassDeclaration> classDeclarations = new HashSet<>(); | 118 | Set<ClassDeclaration> classDeclarations = new HashSet<>(); |
121 | problem.getNodes().clear(); | 119 | problem.getNodes().clear(); |
122 | for (Statement statement : problem.getStatements()) { | 120 | for (Statement statement : problem.getStatements()) { |
123 | if (statement instanceof ClassDeclaration) { | 121 | if (statement instanceof ClassDeclaration classDeclaration) { |
124 | var classDeclaration = (ClassDeclaration) statement; | ||
125 | classDeclaration.setNewNode(null); | 122 | classDeclaration.setNewNode(null); |
126 | classDeclarations.add(classDeclaration); | 123 | classDeclarations.add(classDeclaration); |
127 | } | 124 | } |
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java index 80bbdb0f..bd05e8cf 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java | |||
@@ -10,8 +10,8 @@ import org.eclipse.xtext.util.ITextRegion; | |||
10 | public class ProblemLocationInFileProvider extends DefaultLocationInFileProvider { | 10 | public class ProblemLocationInFileProvider extends DefaultLocationInFileProvider { |
11 | @Override | 11 | @Override |
12 | protected ITextRegion doGetTextRegion(EObject obj, RegionDescription query) { | 12 | protected ITextRegion doGetTextRegion(EObject obj, RegionDescription query) { |
13 | if (obj instanceof Node) { | 13 | if (obj instanceof Node node) { |
14 | return getNodeTextRegion((Node) obj, query); | 14 | return getNodeTextRegion(node, query); |
15 | } | 15 | } |
16 | if (obj instanceof ImplicitVariable) { | 16 | if (obj instanceof ImplicitVariable) { |
17 | return ITextRegion.EMPTY_REGION; | 17 | return ITextRegion.EMPTY_REGION; |
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java index 012606d6..cd5020e7 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java | |||
@@ -80,8 +80,7 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
80 | // Variables are always private to the containing predicate definition. | 80 | // Variables are always private to the containing predicate definition. |
81 | return false; | 81 | return false; |
82 | } | 82 | } |
83 | if (eObject instanceof Node) { | 83 | if (eObject instanceof Node node) { |
84 | var node = (Node) eObject; | ||
85 | // Only enum literals and new nodes are visible across problem files. | 84 | // Only enum literals and new nodes are visible across problem files. |
86 | return ProblemUtil.isUniqueNode(node) || ProblemUtil.isNewNode(node); | 85 | return ProblemUtil.isUniqueNode(node) || ProblemUtil.isNewNode(node); |
87 | } | 86 | } |
@@ -89,8 +88,8 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
89 | } | 88 | } |
90 | 89 | ||
91 | protected boolean shouldExportSimpleName(EObject eObject) { | 90 | protected boolean shouldExportSimpleName(EObject eObject) { |
92 | if (eObject instanceof Node) { | 91 | if (eObject instanceof Node node) { |
93 | return !ProblemUtil.isNewNode((Node) eObject); | 92 | return !ProblemUtil.isNewNode(node); |
94 | } | 93 | } |
95 | return true; | 94 | return true; |
96 | } | 95 | } |
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java index 33f8c50f..56de6b1b 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java | |||
@@ -57,16 +57,14 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider { | |||
57 | protected IScope getVariableScope(EObject context, IScope delegateScope) { | 57 | protected IScope getVariableScope(EObject context, IScope delegateScope) { |
58 | List<Variable> variables = new ArrayList<>(); | 58 | List<Variable> variables = new ArrayList<>(); |
59 | EObject currentContext = context; | 59 | EObject currentContext = context; |
60 | if (context instanceof VariableOrNodeArgument) { | 60 | if (context instanceof VariableOrNodeArgument argument) { |
61 | VariableOrNodeArgument argument = (VariableOrNodeArgument) context; | ||
62 | Variable singletonVariable = argument.getSingletonVariable(); | 61 | Variable singletonVariable = argument.getSingletonVariable(); |
63 | if (singletonVariable != null) { | 62 | if (singletonVariable != null) { |
64 | variables.add(singletonVariable); | 63 | variables.add(singletonVariable); |
65 | } | 64 | } |
66 | } | 65 | } |
67 | while (currentContext != null && !(currentContext instanceof PredicateDefinition)) { | 66 | while (currentContext != null && !(currentContext instanceof PredicateDefinition)) { |
68 | if (currentContext instanceof ExistentialQuantifier) { | 67 | if (currentContext instanceof ExistentialQuantifier quantifier) { |
69 | ExistentialQuantifier quantifier = (ExistentialQuantifier) currentContext; | ||
70 | variables.addAll(quantifier.getImplicitVariables()); | 68 | variables.addAll(quantifier.getImplicitVariables()); |
71 | } | 69 | } |
72 | currentContext = currentContext.eContainer(); | 70 | currentContext = currentContext.eContainer(); |