Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/EnvExample2.ecore30
-rw-r--r--tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asLookup.ocl4
-rw-r--r--tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asV2Lookup.ocl8
-rw-r--r--tests/org.eclipse.qvtd.cs2as.compiler.tests/tests-gen/example2/classes/lookup/util/ClassesSingleResultLookupEnvironment.java56
4 files changed, 69 insertions, 29 deletions
diff --git a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/EnvExample2.ecore b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/EnvExample2.ecore
index 946f0ea0a..501c9db39 100644
--- a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/EnvExample2.ecore
+++ b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/EnvExample2.ecore
@@ -12,7 +12,7 @@
<eClassifiers xsi:type="ecore:EClass" name="LookupEnvironment" eSuperTypes="#//Env4CG">
<eOperations name="addElements" lowerBound="1" eType="#//LookupEnvironment">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
- <details key="body" value="LookupEnvironment{&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;namedElements = namedElements->includingAll(elements),&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;parentEnv = parentEnv&#x9;&#xA;&#x9;&#x9;&#x9;&#x9;}"/>
+ <details key="body" value="elements->iterate(x : classes::NamedElement ; acc : LookupEnvironment = self | acc.addElement(x))"/>
</eAnnotations>
<eTypeParameters name="NE">
<eBounds eClassifier="ecore:EClass Classes.ecore#//NamedElement"/>
@@ -25,12 +25,25 @@
</eOperations>
<eOperations name="addElement" lowerBound="1" eType="#//LookupEnvironment">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
- <details key="body" value="LookupEnvironment{&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;namedElements = namedElements->including(element),&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;parentEnv = parentEnv&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;}"/>
+ <details key="body" value="addElementWithName(element.name, element)"/>
</eAnnotations>
- <eParameters name="element" eType="ecore:EClass Classes.ecore#//NamedElement"/>
+ <eParameters name="element" lowerBound="1" eType="ecore:EClass Classes.ecore#//NamedElement"/>
</eOperations>
- <eStructuralFeatures xsi:type="ecore:EReference" name="namedElements" upperBound="-1"
- eType="ecore:EClass Classes.ecore#//NamedElement"/>
+ <eOperations name="addElementWithName" lowerBound="1" eType="#//LookupEnvironment">
+ <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
+ <details key="body" value="let entry = entries->select(name = entryName)&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;in LookupEnvironment {&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;entries = if entry = null &#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;then entries->including( EnvEntry {name=entryName, namedElements = OrderedSet{element}} )&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;else entries->excluding(entry)->including( EnvEntry {name=entryName, namedElements = entry.namedElements->including(element)})&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;endif&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;}&#xA;&#x9;&#x9;&#x9;&#xA;&#x9;&#x9;&#x9;"/>
+ </eAnnotations>
+ <eParameters name="entryName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eParameters name="element" lowerBound="1" eType="ecore:EClass Classes.ecore#//NamedElement"/>
+ </eOperations>
+ <eOperations name="getNamedElements" upperBound="-1" eType="ecore:EClass Classes.ecore#//NamedElement">
+ <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
+ <details key="body" value="let entry = entries->select(name = entryName)&#xA;&#x9;&#x9;&#x9;&#x9;in if entry = null then OrderedSet(classes::NamedElement){} else entry.namedElements endif"/>
+ </eAnnotations>
+ <eParameters name="entryName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="entries" upperBound="-1"
+ eType="#//EnvEntry" containment="true" eOpposite="#//EnvEntry/env"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parentEnv" eType="#//LookupEnvironment"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Env4CG" abstract="true" interface="true">
@@ -45,6 +58,13 @@
</eAnnotations>
</eOperations>
</eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EnvEntry">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="namedElements" lowerBound="1"
+ upperBound="-1" eType="ecore:EClass Classes.ecore#//NamedElement"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="env" eType="#//LookupEnvironment"
+ eOpposite="#//LookupEnvironment/entries"/>
+ </eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Executor" instanceClassName="org.eclipse.ocl.pivot.evaluation.Executor"
abstract="true" interface="true"/>
</ecore:EPackage>
diff --git a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asLookup.ocl b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asLookup.ocl
index a63a28672..4a1166059 100644
--- a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asLookup.ocl
+++ b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asLookup.ocl
@@ -82,7 +82,7 @@ def : _unqualified_env_Class(child : ocl::OclElement) : lookup::LookupEnvironmen
context Visitable
-- Package lookup
def : _lookupPackage(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Package) =
-let foundPackage = env.namedElements->selectByKind(Package)->select(name = pName)
+let foundPackage = env.getNamedElements(pName)->selectByKind(Package)
in if foundPackage->isEmpty() and not (env.parentEnv = null)
then _lookupPackage(env.parentEnv, pName)
else foundPackage
@@ -114,7 +114,7 @@ def : lookupPackage(segments : OrderedSet(cs::PathElementCS)) : Package[?] =
-- Class lookup
def : _lookupClass(env : lookup::LookupEnvironment, cName : String) : OrderedSet(Class) =
-let foundClass = env.namedElements->selectByKind(Class)->select(name = cName)
+let foundClass = env.getNamedElements(cName)->selectByKind(Class)
in if foundClass->isEmpty() and not (env.parentEnv = null)
then _lookupClass(env.parentEnv, cName)
else foundClass
diff --git a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asV2Lookup.ocl b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asV2Lookup.ocl
index c4a4b6669..1b5a56220 100644
--- a/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asV2Lookup.ocl
+++ b/tests/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example2/classescs2asV2Lookup.ocl
@@ -187,7 +187,7 @@ def : _appliesFilter_Operation(args : OrderedSet(Argument)) : Boolean =
context Visitable
-- Package lookup
def : _lookupPackage(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Package) =
-let foundPackage = env.namedElements->selectByKind(Package)->select(name = pName)
+let foundPackage = env.getNamedElements(pName)->selectByKind(Package)
in if foundPackage->isEmpty() and not (env.parentEnv = null)
then _lookupPackage(env.parentEnv, pName)
else foundPackage
@@ -219,7 +219,7 @@ def : lookupPackage(segments : OrderedSet(cs::PathElementCS)) : Package[?] =
-- Class lookup
def : _lookupClass(env : lookup::LookupEnvironment, cName : String) : OrderedSet(Class) =
-let foundClass = env.namedElements->selectByKind(Class)->select(name = cName)
+let foundClass = env.getNamedElements(cName)->selectByKind(Class)
in if foundClass->isEmpty() and not (env.parentEnv = null)
then _lookupClass(env.parentEnv, cName)
else foundClass
@@ -281,7 +281,7 @@ def : lookupPropertyFrom(exporter : Class, segments : OrderedSet(cs::PathElement
endif
-- Operation lookup
def : _lookupOperation(env : lookup::LookupEnvironment, oName : String, args : OrderedSet(Argument)) : OrderedSet(Operation) =
-let foundOperation = env.namedElements->selectByKind(Operation)->select(name = oName)
+let foundOperation = env.getNamedElements(oName)->selectByKind(Operation)
->select(_appliesFilter_Operation(args))
in if foundOperation->isEmpty() and not (env.parentEnv = null)
then _lookupOperation(env.parentEnv, oName, args)
@@ -314,7 +314,7 @@ def : lookupOperation(segments : OrderedSet(cs::PathElementCS), args : OrderedSe
-- Property lookup
def : _lookupProperty(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Property) =
-let foundProperty = env.namedElements->selectByKind(Property)->select(name = pName)
+let foundProperty = env.getNamedElements(pName)->selectByKind(Property)
in if foundProperty->isEmpty() and not (env.parentEnv = null)
then _lookupProperty(env.parentEnv, pName)
else foundProperty
diff --git a/tests/org.eclipse.qvtd.cs2as.compiler.tests/tests-gen/example2/classes/lookup/util/ClassesSingleResultLookupEnvironment.java b/tests/org.eclipse.qvtd.cs2as.compiler.tests/tests-gen/example2/classes/lookup/util/ClassesSingleResultLookupEnvironment.java
index 344a22533..50b9ba1cc 100644
--- a/tests/org.eclipse.qvtd.cs2as.compiler.tests/tests-gen/example2/classes/lookup/util/ClassesSingleResultLookupEnvironment.java
+++ b/tests/org.eclipse.qvtd.cs2as.compiler.tests/tests-gen/example2/classes/lookup/util/ClassesSingleResultLookupEnvironment.java
@@ -13,8 +13,12 @@ package example2.classes.lookup.util;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import org.eclipse.emf.common.util.ECollections;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@@ -29,8 +33,10 @@ public class ClassesSingleResultLookupEnvironment extends LookupEnvironmentImpl
private @NonNull Executor executor;
private @NonNull String name;
private @NonNull EClass typeFilter;
+ private @NonNull Map<@NonNull String, List<NamedElement>> entries = new LinkedHashMap<@NonNull String,List<NamedElement>>();
private @Nullable ClassesLookupFilter expFilter;
+
public ClassesSingleResultLookupEnvironment(@NonNull Executor executor, @NonNull EClass typeFilter, @NonNull String name, @Nullable ClassesLookupFilter expFilter) {
this.executor = executor;
this.name = name;
@@ -50,23 +56,41 @@ public class ClassesSingleResultLookupEnvironment extends LookupEnvironmentImpl
@Override
public boolean hasFinalResult() {
- for (NamedElement element : getNamedElements()) {
- if (name.equals(element.getName())) {
- return true;
- }
- }
- return false;
+ return getNamedElements(name).size() > 0;
}
@Override
@NonNull
public LookupEnvironment addElement(@Nullable NamedElement namedElement) {
+ if (namedElement == null) {
+ return this;
+ }
+ return addElementWithName(namedElement.getName(), namedElement);
+ }
+
+ @Override
+ @NonNull
+ public <NE extends NamedElement > LookupEnvironment addElements(
+ @Nullable Collection<NE> namedElements) {
+
+ if (namedElements != null) {
+ for (NamedElement namedElement : namedElements) {
+ addElement(namedElement);
+ }
+ }
+ return this;
+ }
+
+
+ @Override
+ @NonNull
+ public LookupEnvironment addElementWithName(String entryName, NamedElement namedElement) {
if (namedElement != null) {
- if (name.equals(namedElement.getName())) {
+ if (name.equals(entryName)) {
if (typeFilter.isInstance(namedElement)) {
ClassesLookupFilter expFilter2 = expFilter;
if (expFilter2 == null || expFilter2.matches(namedElement)) {
- List<NamedElement> elements = getNamedElements();
+ List<NamedElement> elements = getNamedElements(entryName);
if (!elements.contains(namedElement)) { // FIXME use a set ?
elements.add(namedElement);
}
@@ -79,21 +103,17 @@ public class ClassesSingleResultLookupEnvironment extends LookupEnvironmentImpl
@Override
@NonNull
- public <NE extends NamedElement > LookupEnvironment addElements(
- @Nullable Collection<NE> namedElements) {
-
- if (namedElements != null) {
- for (NamedElement namedElement : namedElements) {
- addElement(namedElement);
- }
- }
- return this;
+ @SuppressWarnings("null")
+ public EList<NamedElement> getNamedElements(String entryName) {
+ List<NamedElement> namedElements = entries.get(entryName);
+ return namedElements == null ? ECollections.emptyEList() : ECollections.asEList(namedElements);
}
+ @NonNull
@SuppressWarnings("unchecked")
public <NE extends NamedElement> List<NE> getNamedElementsByKind(Class<NE> class_) {
List<NE> result = new ArrayList<NE>();
- for (NamedElement namedElement : getNamedElements()) {
+ for (NamedElement namedElement : getNamedElements(name)) {
if (class_.isAssignableFrom(namedElement.getClass())) {
result.add((NE)namedElement);
}

Back to the top