diff options
Diffstat (limited to 'language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java')
-rw-r--r-- | language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java | 94 |
1 files changed, 54 insertions, 40 deletions
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 edb25a1c..4d932a92 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 | |||
@@ -24,56 +24,70 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) { | 26 | public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) { |
27 | if (eObject instanceof Variable) { | 27 | if (!shouldExport(eObject)) { |
28 | return false; | 28 | return false; |
29 | } | 29 | } |
30 | if (eObject instanceof NamedElement) { | 30 | if (!(eObject instanceof NamedElement)) { |
31 | NamedElement namedElement = (NamedElement) eObject; | 31 | return true; |
32 | String name = namedElement.getName(); | 32 | } |
33 | if (name == null || name.isEmpty()) { | 33 | NamedElement namedElement = (NamedElement) eObject; |
34 | return true; | 34 | String name = namedElement.getName(); |
35 | } | 35 | if (name == null || name.isEmpty()) { |
36 | Problem problem = EcoreUtil2.getContainerOfType(namedElement, Problem.class); | 36 | return true; |
37 | QualifiedName problemQualifiedName = null; | 37 | } |
38 | if (problem != null) { | 38 | Problem problem = EcoreUtil2.getContainerOfType(namedElement, Problem.class); |
39 | String problemName = problem.getName(); | 39 | QualifiedName problemQualifiedName = null; |
40 | if (problemName != null && !problemName.isEmpty()) { | 40 | if (problem != null) { |
41 | problemQualifiedName = qualifiedNameConverter.toQualifiedName(problemName); | 41 | String problemName = problem.getName(); |
42 | } | 42 | if (problemName != null && !problemName.isEmpty()) { |
43 | } | 43 | problemQualifiedName = qualifiedNameConverter.toQualifiedName(problemName); |
44 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(namedElement.getName()); | ||
45 | boolean nameExported; | ||
46 | if (shouldExportSimpleName(namedElement)) { | ||
47 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); | ||
48 | nameExported = true; | ||
49 | } else { | ||
50 | nameExported = false; | ||
51 | } | 44 | } |
52 | EObject parent = namedElement.eContainer(); | 45 | } |
53 | while (parent != null && parent != problem) { | 46 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(namedElement.getName()); |
54 | if (parent instanceof NamedElement) { | 47 | boolean nameExported; |
55 | NamedElement namedParent = (NamedElement) parent; | 48 | if (shouldExportSimpleName(namedElement)) { |
56 | String parentName = namedParent.getName(); | 49 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); |
57 | if (parentName != null || !name.isEmpty()) { | 50 | nameExported = true; |
58 | QualifiedName parentQualifiedName = qualifiedNameConverter.toQualifiedName(parentName); | 51 | } else { |
59 | qualifiedName = parentQualifiedName.append(qualifiedName); | 52 | nameExported = false; |
60 | if (shouldExportSimpleName(parent)) { | 53 | } |
61 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); | 54 | EObject parent = namedElement.eContainer(); |
62 | nameExported = true; | 55 | while (parent != null && parent != problem) { |
63 | } else { | 56 | if (parent instanceof NamedElement) { |
64 | nameExported = false; | 57 | NamedElement namedParent = (NamedElement) parent; |
65 | } | 58 | String parentName = namedParent.getName(); |
59 | if (parentName != null || !name.isEmpty()) { | ||
60 | QualifiedName parentQualifiedName = qualifiedNameConverter.toQualifiedName(parentName); | ||
61 | qualifiedName = parentQualifiedName.append(qualifiedName); | ||
62 | if (shouldExportSimpleName(namedParent)) { | ||
63 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); | ||
64 | nameExported = true; | ||
65 | } else { | ||
66 | nameExported = false; | ||
66 | } | 67 | } |
67 | } | 68 | } |
68 | parent = parent.eContainer(); | ||
69 | } | ||
70 | if (!nameExported) { | ||
71 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); | ||
72 | } | 69 | } |
70 | parent = parent.eContainer(); | ||
71 | } | ||
72 | if (!nameExported) { | ||
73 | acceptEObjectDescription(namedElement, problemQualifiedName, qualifiedName, acceptor); | ||
73 | } | 74 | } |
74 | return true; | 75 | return true; |
75 | } | 76 | } |
76 | 77 | ||
78 | protected boolean shouldExport(EObject eObject) { | ||
79 | if (eObject instanceof Variable) { | ||
80 | // Variables are always private to the containing predicate definition. | ||
81 | return false; | ||
82 | } | ||
83 | if (eObject instanceof Node) { | ||
84 | Node node = (Node) eObject; | ||
85 | // Only enum literals and new nodes are visible across problem files. | ||
86 | return ProblemUtil.isEnumLiteral(node) || ProblemUtil.isNewNode(node); | ||
87 | } | ||
88 | return true; | ||
89 | } | ||
90 | |||
77 | protected boolean shouldExportSimpleName(EObject eObject) { | 91 | protected boolean shouldExportSimpleName(EObject eObject) { |
78 | if (eObject instanceof Node) { | 92 | if (eObject instanceof Node) { |
79 | return !ProblemUtil.isNewNode((Node) eObject); | 93 | return !ProblemUtil.isNewNode((Node) eObject); |