summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-04-19 08:47:20 (EDT)
committer sefftinge2009-04-19 08:47:20 (EDT)
commit0c1c85bfeb85c1ae6b56512da03787e89cc7be3b (patch)
tree100e5844ff0bfd790cc5da18017fd7473ff2c4eb
parentc9cb331fadea61eea80a5353f814c823a2634020 (diff)
downloadorg.eclipse.xtext-0c1c85bfeb85c1ae6b56512da03787e89cc7be3b.zip
org.eclipse.xtext-0c1c85bfeb85c1ae6b56512da03787e89cc7be3b.tar.gz
org.eclipse.xtext-0c1c85bfeb85c1ae6b56512da03787e89cc7be3b.tar.bz2
Fix: https://bugs.eclipse.org/bugs/show_bug.cgi?id=270963 - scopes can take rootModel into account to calculate the visible elements
-rw-r--r--examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinker.java8
-rw-r--r--examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinkingService.java4
-rw-r--r--examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslScopeProvider.java8
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java4
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/XtextTemplateContextType.java3
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/HyperlinkHelper.java8
-rw-r--r--plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/contentassist/ContentAssistHelper.java4
-rw-r--r--plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/Scope.java2
-rwxr-xr-xplugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/XtendScopeProvider.java36
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java2
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DeclarativeScopeProviderTest.java31
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/PartialLinkingTest.java6
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java1
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java12
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextScopingTest.java65
-rw-r--r--tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.ext4
-rw-r--r--tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.java5
17 files changed, 131 insertions, 72 deletions
diff --git a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinker.java b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinker.java
index a87d454..c04cc11 100644
--- a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinker.java
+++ b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinker.java
@@ -27,12 +27,12 @@ public class EcoreDslLinker extends Linker {
protected final Logger logger = Logger.getLogger(getClass());
@Override
- protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) {
+ protected void setDefaultValueImpl(EObject rootModel, EObject obj, EReference ref, IDiagnosticProducer producer) {
//hack: ePackage always needs an eFactoryInstance (gets cleared in #clearReferences?)
if (ref.getName().equalsIgnoreCase("eFactoryInstance")) {
((EPackage) obj).setEFactoryInstance(EcoreFactory.eINSTANCE.createEFactory());
}
- super.setDefaultValueImpl(obj, ref, producer);
+ super.setDefaultValueImpl(rootModel, obj, ref, producer);
}
@Override
@@ -42,8 +42,8 @@ public class EcoreDslLinker extends Linker {
// hack: exceptions when eType, eExceptions are null
for (EReference ref : allReferences) {
try {
- if (ref.isContainment() ||
- ref.isContainer() ||
+ if (ref.isContainment() ||
+ ref.isContainer() ||
ref.isDerived() || obj.eGet(ref) == null || ref.getName() == null
|| (obj instanceof ETypedElement && ref.getName().equalsIgnoreCase("eType"))
|| (obj instanceof ETypedElement && ref.getName().equalsIgnoreCase("eExceptions"))) {
diff --git a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinkingService.java b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinkingService.java
index 10d70c8..332df2a 100644
--- a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinkingService.java
+++ b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslLinkingService.java
@@ -40,11 +40,11 @@ public class EcoreDslLinkingService extends DefaultLinkingService {
private IValueConverterService valueConverterService;
@Override
- public List<EObject> getLinkedObjects(EObject context, EReference ref,
+ public List<EObject> getLinkedObjects(EObject rootModel, EObject context, EReference ref,
AbstractNode node) throws IllegalNodeException {
if (ref == EcoredslPackage.eINSTANCE.getReferencedMetamodel_EPackage())
return getPackage((ReferencedMetamodel) context, (LeafNode) node);
- return super.getLinkedObjects(context, ref, node);
+ return super.getLinkedObjects(rootModel, context, ref, node);
}
private List<EObject> getPackage(ReferencedMetamodel context, LeafNode text) {
diff --git a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslScopeProvider.java b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslScopeProvider.java
index 7a9b0c0..0d2c27d 100644
--- a/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslScopeProvider.java
+++ b/examples/org.eclipse.xtext.example.ecoredsl/src/org/eclipse/xtext/example/linker/EcoreDslScopeProvider.java
@@ -40,17 +40,17 @@ public class EcoreDslScopeProvider extends DefaultScopeProvider {
private IValueConverterService valueConverterService;
@Override
- protected IScope createScope(Resource resource, EClass type) {
+ protected IScope createScope(EObject rootModel, Resource resource, EClass type) {
if (EcorePackage.Literals.EPACKAGE == type) {
EcoreDsl ecoreDsl = (EcoreDsl) resource.getResourceSet()
.getEObject(resource.getURI().appendFragment("/"), true);
return createEPackageScope(ecoreDsl);
}
- return super.createScope(resource, type);
+ return super.createScope(rootModel, resource, type);
}
@Override
- public IScope getScope(EObject context, EReference reference) {
+ public IScope getScope(EObject rootModel, EObject context, EReference reference) {
if (reference.getEType()
.equals(EcorePackage.eINSTANCE.getEClassifier())) {
EcoreDsl ecoreDsl = (EcoreDsl) context.eResource().getResourceSet()
@@ -68,7 +68,7 @@ public class EcoreDslScopeProvider extends DefaultScopeProvider {
allClassifiers.addAll(ecoreDsl.getPackage().getEClassifiers());
return createClassifierScope(allClassifiers);
}
- return super.getScope(context, reference);
+ return super.getScope(rootModel, context, reference);
}
private IScope createEPackageScope(final EcoreDsl ecoreDsl) {
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
index 07a5e5e..0ee0f6b 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
@@ -16,6 +16,7 @@ import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateContextType;
@@ -213,7 +214,8 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
EClass eClass = (EClass) containingParserRule.getType().getClassifier();
EReference ref = GrammarUtil.getReference(crossReference,eClass);
String trimmedPrefix = contentAssistContext.getMatchString().trim();
- IScope scope = scopeProvider.getScope(contentAssistContext.getModel(), ref);
+ EObject context = contentAssistContext.getModel();
+ IScope scope = scopeProvider.getScope(EcoreUtil.getRootContainer(context), context, ref);
Iterable<IScopedElement> candidates = scope.getAllContents();
for (IScopedElement candidate : candidates) {
if (null != candidate.name() && isCandidateMatchingPrefix(contentAssistContext
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/XtextTemplateContextType.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/XtextTemplateContextType.java
index ea30041..bd40cc4 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/XtextTemplateContextType.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/XtextTemplateContextType.java
@@ -62,8 +62,9 @@ public class XtextTemplateContextType extends TemplateContextType {
EReference reference = getReference(classReferencePair[0], classReferencePair[1], getGrammar(xtextTemplateContext));
+ EObject eContext = xtextTemplateContext.getContentAssistContext().getModel();
Iterable<IScopedElement> linkingCandidates = xtextTemplateContext.getScopeProvider()
- .getScope(xtextTemplateContext.getContentAssistContext().getModel(), reference).getAllContents();
+ .getScope(EcoreUtil.getRootContainer(eContext), eContext, reference).getAllContents();
List<String> names = new ArrayList<String>();
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/HyperlinkHelper.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/HyperlinkHelper.java
index c681c48..ba1600c 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/HyperlinkHelper.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/HyperlinkHelper.java
@@ -57,7 +57,7 @@ public class HyperlinkHelper {
Assert.isNotNull(parseResult);
AbstractNode abstractNode = ParseTreeUtil.getCurrentOrFollowingNodeByOffset(parseResult.getRootNode(), offset);
final Wrapper<Region> location = Wrapper.wrap(new Region(abstractNode.getOffset(), abstractNode.getLength()));
- List<EObject> crossLinkedEObjects = findCrossLinkedEObject(abstractNode, location);
+ List<EObject> crossLinkedEObjects = findCrossLinkedEObject(resource.getContents().get(0), abstractNode, location);
if (crossLinkedEObjects.isEmpty())
return null;
final URIConverter uriConverter = resource.getResourceSet().getURIConverter();
@@ -75,7 +75,7 @@ public class HyperlinkHelper {
public OpenDeclarationAction getOpenDeclarationAction(XtextResource resource, int offset) {
AbstractNode node = ParseTreeUtil.getCurrentOrFollowingNodeByOffset(resource.getParseResult().getRootNode(), offset);
- List<EObject> crossLinkedEObject = findCrossLinkedEObject(node, null);
+ List<EObject> crossLinkedEObject = findCrossLinkedEObject(resource.getContents().get(0), node, null);
if (crossLinkedEObject.isEmpty())
return null;
final URI uri = EcoreUtil.getURI(crossLinkedEObject.get(0));
@@ -83,7 +83,7 @@ public class HyperlinkHelper {
return new OpenDeclarationAction(normalized, locationProvider);
}
- protected List<EObject> findCrossLinkedEObject(AbstractNode node, Wrapper<Region> location) {
+ protected List<EObject> findCrossLinkedEObject(EObject rootModel, AbstractNode node, Wrapper<Region> location) {
AbstractNode nodeToCheck = node;
while(nodeToCheck != null && !(nodeToCheck.getGrammarElement() instanceof Assignment)) {
if (nodeToCheck.getGrammarElement() instanceof CrossReference) {
@@ -93,7 +93,7 @@ public class HyperlinkHelper {
try {
if (location != null)
location.set(new Region(nodeToCheck.getOffset(), nodeToCheck.getLength()));
- return linkingService.getLinkedObjects(semanticModel, eReference, nodeToCheck);
+ return linkingService.getLinkedObjects(rootModel, semanticModel, eReference, nodeToCheck);
} catch (IllegalNodeException ex) {
return Collections.emptyList();
}
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/contentassist/ContentAssistHelper.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/contentassist/ContentAssistHelper.java
index 6d76b85..26d0797 100644
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/contentassist/ContentAssistHelper.java
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/contentassist/ContentAssistHelper.java
@@ -9,6 +9,7 @@ package org.eclipse.xtext.xtend.contentassist;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.crossref.IScope;
@@ -30,7 +31,8 @@ public class ContentAssistHelper {
public static IScope getScope(IScopeProvider scopeProvider, Object context, Object reference) {
if (reference == null)
return null;
- IScope scope = scopeProvider.getScope((EObject) context, (EReference) reference);
+ EObject eContext = (EObject) context;
+ IScope scope = scopeProvider.getScope(EcoreUtil.getRootContainer(eContext), eContext, (EReference) reference);
return scope;
}
}
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/Scope.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/Scope.java
index 89c7e5f..50f0e3a 100644
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/Scope.java
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/Scope.java
@@ -22,7 +22,7 @@ import com.google.common.collect.Collections2;
* @author Sven Efftinge - Initial contribution and API
*
*/
-public class Scope extends AbstractScope implements IScope {
+public class Scope extends AbstractScope {
private List<IScopedElement> elements;
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/XtendScopeProvider.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/XtendScopeProvider.java
index 1d80a95..c790425 100755
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/XtendScopeProvider.java
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/scoping/XtendScopeProvider.java
@@ -28,14 +28,14 @@ import com.google.inject.name.Named;
*
* IScope scope_<ExpectedTypeName>(<MyContextType> ctx, EReference ref) : ...
*
- * Where
+ * Where
* 1) ExpectedTypeName refers to ref.getEType().getName() and
* 2) MyContextType refers to the type (or any super type) of the source element.
*
* If no such declaration can be found it will sitch the ctx to ctx.eContainer and try again.
* Example:
- * If you have Classes containing Features which have a cross reference to a Class.
- * The implementation will first look for
+ * If you have Classes containing Features which have a cross reference to a Class.
+ * The implementation will first look for
*
* IScope scope_Class(Feature ctx,EReference ref) : ...
*
@@ -50,9 +50,9 @@ import com.google.inject.name.Named;
public class XtendScopeProvider extends AbstractXtendService implements IScopeProvider {
public final static String EXTENSION_FILE = "ScopeExtensions";
- private String extensionFile;
+ private final String extensionFile;
- private DefaultScopeProvider defaultScopeProvider;
+ private final DefaultScopeProvider defaultScopeProvider;
@Inject
public XtendScopeProvider(@Named(EXTENSION_FILE) String name, DefaultScopeProvider defaultScopeProvider) {
@@ -64,23 +64,22 @@ public class XtendScopeProvider extends AbstractXtendService implements IScopePr
private static final String SCOPE_EXTENSION_PREFIX = "scope_";
- public IScope getScope(EObject context, final EReference reference) {
+ public IScope getScope(EObject rootModel, EObject context, final EReference reference) {
try {
while (true) {
Object result = null;
try {
String extensionName = extensionName(context, reference);
- result = invokeExtension(extensionName, Lists.newArrayList(context, reference));
+ result = invokeExtension(extensionName, Lists.newArrayList(rootModel, context, reference));
} catch (NoSuchExtensionException e) {
// ignore
}
if (result != null)
return (IScope) result;
if (context.eContainer() != null) {
- return getScope(context.eContainer(), reference);
- } else {
- computeDefaultScope(context, reference);
+ return getScope(rootModel, context.eContainer(), reference);
}
+ computeDefaultScope(rootModel, context, reference);
}
} catch (Throwable e) {
log.error("Error invoking scope extension", e);
@@ -88,23 +87,22 @@ public class XtendScopeProvider extends AbstractXtendService implements IScopePr
return null;
}
- public IScope getScope(EObject context, final EClass type) {
+ public IScope getScope(EObject rootModel, EObject context, final EClass type) {
try {
while (true) {
Object result = null;
try {
String extensionName = extensionName(context, type);
- result = invokeExtension(extensionName, Lists.newArrayList(context, type));
+ result = invokeExtension(extensionName, Lists.newArrayList(rootModel, context, type));
} catch (NoSuchExtensionException e) {
// ignore
}
if (result != null)
return (IScope) result;
if (context.eContainer() != null) {
- return getScope(context.eContainer(), type);
- } else {
- computeDefaultScope(context, type);
+ return getScope(rootModel, context.eContainer(), type);
}
+ computeDefaultScope(rootModel, context, type);
}
} catch (Throwable e) {
log.error("Error invoking scope extension", e);
@@ -112,12 +110,12 @@ public class XtendScopeProvider extends AbstractXtendService implements IScopePr
return null;
}
- protected IScope computeDefaultScope(EObject ctx, EReference reference) {
- return this.defaultScopeProvider.getScope(ctx, reference);
+ protected IScope computeDefaultScope(EObject rootModel, EObject ctx, EReference reference) {
+ return this.defaultScopeProvider.getScope(rootModel, ctx, reference);
}
- protected IScope computeDefaultScope(EObject ctx, EClass type) {
- return this.defaultScopeProvider.getScope(ctx, type);
+ protected IScope computeDefaultScope(EObject rootModel, EObject ctx, EClass type) {
+ return this.defaultScopeProvider.getScope(rootModel, ctx, type);
}
private String extensionName(EObject context, EReference reference) {
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
index 1725dbb..7988e15 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
@@ -47,7 +47,7 @@ public class CrossRefTest extends AbstractGeneratorTest {
CrossReference xref = (CrossReference) asExtends.getTerminal();
EReference ref = GrammarUtil.getReference(xref, context.eClass());
- assertEquals(1, linkingService.getLinkedObjects(context, ref, leaf).size());
+ assertEquals(1, linkingService.getLinkedObjects(model, context, ref, leaf).size());
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DeclarativeScopeProviderTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DeclarativeScopeProviderTest.java
index 64e3fc8..d207924 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DeclarativeScopeProviderTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DeclarativeScopeProviderTest.java
@@ -13,6 +13,7 @@ import java.util.Collections;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
@@ -37,13 +38,13 @@ public class DeclarativeScopeProviderTest extends TestCase {
public void testSimple() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
- private IScope scope_EClass(EClass clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClass clazz, EReference ref) {
return a;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
- assertEquals(a,provider.getScope(details, details));
+ assertEquals(a,provider.getScope(details.eClass().getEPackage(), details, details));
}
@SuppressWarnings("unused")
@@ -52,17 +53,17 @@ public class DeclarativeScopeProviderTest extends TestCase {
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
- private IScope scope_EClass(EClass clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClass clazz, EReference ref) {
return a;
}
- private IScope scope_EClass(EReference ctx, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EReference ctx, EReference ref) {
return b;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
- assertEquals(b,provider.getScope(details, details));
- assertEquals(a,provider.getScope(details.getEContainingClass(), details));
+ assertEquals(b,provider.getScope(details.eClass().getEPackage(), details, details));
+ assertEquals(a,provider.getScope(details.eClass().getEPackage(), details.getEContainingClass(), details));
}
@SuppressWarnings("unused")
@@ -72,22 +73,22 @@ public class DeclarativeScopeProviderTest extends TestCase {
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
- private IScope scope_EClass(EClassifier clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClassifier clazz, EReference ref) {
return a;
}
- private IScope scope_EClass(EClass clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClass clazz, EReference ref) {
return c;
}
- private IScope scope_EClass(EReference ctx, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EReference ctx, EReference ref) {
return b;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
- assertEquals(b,provider.getScope(details, details));
- assertEquals(c,provider.getScope(details.getEContainingClass(), details));
+ assertEquals(b,provider.getScope(details.eClass().getEPackage(), details, details));
+ assertEquals(c,provider.getScope(details.eClass().getEPackage(), details.getEContainingClass(), details));
}
@SuppressWarnings("unused")
@@ -96,15 +97,15 @@ public class DeclarativeScopeProviderTest extends TestCase {
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
- private IScope scope_EClass(EClassifier clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClassifier clazz, EReference ref) {
return a;
}
- private IScope scope_EClass(EClass clazz, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EClass clazz, EReference ref) {
return c;
}
- private IScope scope_EClass(EReference ctx, EReference ref) {
+ private IScope scope_EClass(EPackage rootModel, EReference ctx, EReference ref) {
return b;
}
};
@@ -115,6 +116,6 @@ public class DeclarativeScopeProviderTest extends TestCase {
resourceSet.getResources().add(res);
EReference details = (EReference) EcoreUtil.copy(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
res.getContents().add(details);
- assertNotNull(provider.getScope(details, details.eClass()));
+ assertNotNull(provider.getScope(details, details, details.eClass()));
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/PartialLinkingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/PartialLinkingTest.java
index ad0a6bd..56ceb86 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/PartialLinkingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/PartialLinkingTest.java
@@ -71,13 +71,13 @@ public class PartialLinkingTest extends AbstractGeneratorTest implements IScopeP
/**
* We try to emulate a changed scope after a partial parsing so we mock the ScopeService.
*/
- public IScope getScope(EObject context, EReference reference) {
+ public IScope getScope(EObject rootModel, EObject context, EReference reference) {
if (doFakeScope && context == this.context && reference == this.reference)
return IScope.NULLSCOPE;
- return scopeProvider.getScope(context, reference);
+ return scopeProvider.getScope(rootModel, context, reference);
}
- public IScope getScope(EObject context, EClass type) {
+ public IScope getScope(EObject rootModel, EObject context, EClass type) {
throw new UnsupportedOperationException();
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
index 1db3ff2..4366480 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
@@ -94,6 +94,7 @@ public class PluginTestSuite {
suite.addTestSuite(org.eclipse.xtext.xtext.ResourceLoadTest.class);
suite.addTestSuite(org.eclipse.xtext.xtext.parser.packrat.XtextPackratParserTest.class);
suite.addTestSuite(org.eclipse.xtext.xtext.XtextValidationTest.class);
+ suite.addTestSuite(org.eclipse.xtext.xtext.XtextScopingTest.class);
return suite;
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
index 615b733..138a5f3 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
@@ -18,11 +18,8 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.GrammarUtil;
-import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.TypeRef;
-import org.eclipse.xtext.crossref.ILinkingService;
import org.eclipse.xtext.grammarinheritance.ametamodel.AmetamodelPackage;
-import org.eclipse.xtext.grammarinheritance.services.ConcreteTestLanguageGrammarAccess;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import com.google.common.base.Function;
@@ -66,13 +63,4 @@ public class InheritanceTest extends AbstractGeneratorTest {
}
assertTrue(expectedNames.toString(), expectedNames.isEmpty());
}
-
- //see https://bugs.eclipse.org/bugs/show_bug.cgi?id=270963
- public void _testScoping() {
- ILinkingService l = getLinkingService();
- ConcreteTestLanguageGrammarAccess ga = (ConcreteTestLanguageGrammarAccess) getGrammarAccess();
- RuleCall rc = ga.getAbstractCallOverridenParserRuleAccess().getElementsOverridableParserRuleParserRuleCall_1_0();
- String ref = l.getLinkText(rc.getRule(), rc.eContainmentFeature(), rc);
- assertNotNull(ref);
- }
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextScopingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextScopingTest.java
new file mode 100644
index 0000000..5189ebd
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextScopingTest.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.xtext;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtext.AbstractRule;
+import org.eclipse.xtext.Assignment;
+import org.eclipse.xtext.Grammar;
+import org.eclipse.xtext.GrammarUtil;
+import org.eclipse.xtext.Group;
+import org.eclipse.xtext.ParserRule;
+import org.eclipse.xtext.RuleCall;
+import org.eclipse.xtext.XtextPackage;
+import org.eclipse.xtext.XtextStandaloneSetup;
+import org.eclipse.xtext.junit.AbstractXtextTests;
+import org.eclipse.xtext.resource.XtextResourceSet;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class XtextScopingTest extends AbstractXtextTests {
+
+ private Grammar grammar;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(XtextStandaloneSetup.class);
+ XtextResourceSet resourceSet = get(XtextResourceSet.class);
+ resourceSet.setClasspathURIContext(getClass().getClassLoader());
+ Resource resource = resourceSet.getResource(
+ URI.createURI("classpath:/org/eclipse/xtext/grammarinheritance/ConcreteTestLanguage.xtext"), true);
+ grammar = (Grammar) resource.getContents().get(0);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ grammar = null;
+ super.tearDown();
+ }
+
+ public void testSetup() {
+ assertNotNull(grammar);
+ }
+
+ public void testScope_01() {
+ ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "AbstractCallOverridenParserRule");
+ assertNotNull(rule);
+ Group group = (Group) rule.getAlternatives();
+ Assignment ass = (Assignment) group.getTokens().get(1);
+ assertNotNull(ass);
+ RuleCall call = (RuleCall) ass.getTerminal();
+ AbstractRule calledRule = call.getRule();
+ assertNotNull(calledRule);
+ String text = getLinkingService().getLinkText(grammar, calledRule, XtextPackage.Literals.RULE_CALL__RULE, call);
+ assertNotNull(text);
+ assertEquals(calledRule.getName(), text);
+ }
+}
diff --git a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.ext b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.ext
index 35815ff..8af73d4 100644
--- a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.ext
+++ b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.ext
@@ -4,10 +4,10 @@ import org::eclipse::xtext::xtend::scoping;
extension org::eclipse::xtext::xtend::scoping::ScopeProvider;
-create Scope scope_EClass(EPackage pack, EReference ref) :
+create Scope scope_EClass(EPackage rootModel, EPackage pack, EReference ref) :
setElements(pack.EClassifiers.typeSelect(EClass).scopedElement()) ->
setOuterScope(IScope::NULLSCOPE);
-create Scope scope_EClass(EClass class, EReference ref) :
+create Scope scope_EClass(EPackage rootModel, EClass class, EReference ref) :
setElements({class.scopedElement()}) ->
setOuterScope(IScope::NULLSCOPE);
diff --git a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.java b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.java
index eb5ae5f..f79694b 100644
--- a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.java
+++ b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/XtendScopeProviderTest.java
@@ -33,6 +33,7 @@ import com.google.inject.Provider;
public class XtendScopeProviderTest extends TestCase {
private XtendScopeProvider scopeProvider;
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -52,7 +53,7 @@ public class XtendScopeProviderTest extends TestCase {
EcorePackage p = EcorePackage.eINSTANCE;
EReference reference = p.getEClass_EAllSuperTypes();
- IScope scope = scopeProvider.getScope(p, reference);
+ IScope scope = scopeProvider.getScope(p, p, reference);
Iterator<IScopedElement> iterator = scope.getAllContents().iterator();
int i = 0;
while(iterator.hasNext()) {
@@ -67,7 +68,7 @@ public class XtendScopeProviderTest extends TestCase {
public void testSimple2() throws Exception {
EcorePackage p = EcorePackage.eINSTANCE;
EReference reference = p.getEClass_EAllSuperTypes();
- IScope scope = scopeProvider.getScope(reference, reference);
+ IScope scope = scopeProvider.getScope(p, reference, reference);
Iterator<IScopedElement> iterator = scope.getAllContents().iterator();
IScopedElement element = iterator.next();
assertFalse(iterator.hasNext());