| author | szarnekow | 2009-03-09 12:21:58 (EDT) |
|---|---|---|
| committer | sefftinge | 2009-03-09 12:21:58 (EDT) |
| commit | 64b62dc8bee14f657b1d095193df22f6866cf61d (patch) (side-by-side diff) | |
| tree | eab429afcd88723d2ba5220d36a3eaeeb034fa78 | |
| parent | 1540fe864a5a6062a724cc78c82ce796adb3aac5 (diff) | |
| download | org.eclipse.xtext-64b62dc8bee14f657b1d095193df22f6866cf61d.zip org.eclipse.xtext-64b62dc8bee14f657b1d095193df22f6866cf61d.tar.gz org.eclipse.xtext-64b62dc8bee14f657b1d095193df22f6866cf61d.tar.bz2 | |
API: new method IScopeProvider.getScope(EObject context, EClass type)
4 files changed, 47 insertions, 4 deletions
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Activator.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Activator.java index b3311a6..76f00bf 100644 --- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Activator.java +++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Activator.java @@ -13,7 +13,7 @@ public class Activator extends AbstractUIPlugin { // The shared instance private static Activator plugin; - + /** * The constructor */ @@ -24,6 +24,7 @@ public class Activator extends AbstractUIPlugin { * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ + @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; @@ -33,6 +34,7 @@ public class Activator extends AbstractUIPlugin { * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ + @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java index ce55fb6..957effa 100644 --- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java +++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.List; 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.xtext.crossref.IScope; @@ -34,11 +35,33 @@ public abstract class AbstractXtendScopeProvider extends AbstractXtendService im private static final String SCOPE_EXTENSION_PREFIX = "scope_"; + public IScope getScope(EObject context, final EClass type) { + throw new UnsupportedOperationException(); +// try { +// List<IScopedElement> scopedElements = invokeExtension(extensionName(context, type), +// Collections.singletonList(context)); +// final Collection<String> names = new HashSet<String>(scopedElements.size()); +// return new XtendScope(list(filter(scopedElements, new Filter<IScopedElement>() { +// public boolean matches(IScopedElement param) { +// boolean result = type.isSuperTypeOf(param.element().eClass()); +// if (result) { +// result = names.add(param.name()); +// } +// return result; +// } +// }))); +// } +// catch (Throwable e) { +// log.error("Error invoking scope extension", e); +// } +// return null; + } + public IScope getScope(EObject context, final EReference reference) { try { List<IScopedElement> scopedElements = invokeExtension(extensionName(context, reference), Collections .singletonList(context)); - final Collection<String> names = new HashSet<String>(scopedElements.size()); + final Collection<String> names = new HashSet<String>(scopedElements.size()); return new XtendScope(list(filter(scopedElements, new Filter<IScopedElement>() { public boolean matches(IScopedElement param) { boolean result = reference.getEReferenceType().isSuperTypeOf(param.element().eClass()); @@ -61,7 +84,7 @@ public abstract class AbstractXtendScopeProvider extends AbstractXtendService im public static class XtendScope implements IScope { - private Iterable<IScopedElement> scopedElements; + private final Iterable<IScopedElement> scopedElements; public XtendScope(List<IScopedElement> scopedElements) { this.scopedElements = scopedElements; 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 2c87bb1..ad0a6bd 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 @@ -10,6 +10,7 @@ package org.eclipse.xtext.crossrefs; import java.util.Iterator; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.xtext.crossref.IScope; @@ -76,6 +77,10 @@ public class PartialLinkingTest extends AbstractGeneratorTest implements IScopeP return scopeProvider.getScope(context, reference); } + public IScope getScope(EObject context, EClass type) { + throw new UnsupportedOperationException(); + } + @SuppressWarnings("unchecked") public void testPartialLinking() { int idx = modelAsText.indexOf("Bommel2 2"); diff --git a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java index 3e2ce58..d161bab 100644 --- a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java +++ b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java @@ -11,6 +11,7 @@ import static org.eclipse.xtext.util.CollectionUtils.*; import java.util.List; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; @@ -26,8 +27,12 @@ import org.eclipse.xtext.util.Function; */ public class CrossrefTest extends AbstractXtextTests { - public void testCrossRef() throws Exception { + @Override + protected void setUp() throws Exception { + super.setUp(); with(ReferenceGrammarTestLanguageStandaloneSetup.class); + } + public void testCrossRef() throws Exception { EObject spielplatz = getModel("spielplatz 1 \"SpielplatzBeschreibung\" { kind(k1 0) kind(k2 0) erwachsener(v1 1) erwachsener(m1 1) }"); EObject familie = getASTFactory().create(spielplatz.eClass().getEPackage().getEClassifier("Familie")); getASTFactory().add(spielplatz, "familie", familie, null, null); @@ -37,6 +42,14 @@ public class CrossrefTest extends AbstractXtextTests { assertInScope(familie, familie.eClass().getEStructuralFeature("mutter"), "v1", "m1"); } + public void testUnsupportedOperationException() { + try { + getScopeProvider().getScope(null, (EClass) null); + fail("Expected: UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } private void assertInScope(EObject familie, EStructuralFeature eReference, String... names) { IScopeProvider scopeProvider = getScopeProvider(); assertTrue(scopeProvider instanceof AbstractXtendScopeProvider); |

