summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhbehrens2008-11-11 10:54:57 (EST)
committer sefftinge2008-11-11 10:54:57 (EST)
commit48dc50764f27fdaa13cbbf1ea276d31b1ced711d (patch)
tree7e81b8829856ff2277fec6b7a76233306d648182
parent10d1fbeaf45a5a7914fb8051100aca6898eff300 (diff)
downloadorg.eclipse.xtext-48dc50764f27fdaa13cbbf1ea276d31b1ced711d.zip
org.eclipse.xtext-48dc50764f27fdaa13cbbf1ea276d31b1ced711d.tar.gz
org.eclipse.xtext-48dc50764f27fdaa13cbbf1ea276d31b1ced711d.tar.bz2
Content Assist resolves EClasses of Crossrefs via alias and name (fixes 254750)
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java2
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/GrammarUtilTests.java75
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java5
3 files changed, 75 insertions, 7 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
index 38656e2..32f855b 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
@@ -12,7 +12,6 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.util.EcoreEList;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ContextInformationValidator;
@@ -35,7 +34,6 @@ import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.ParseTreeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.service.Inject;
-import org.eclipse.xtext.ui.common.editor.outline.LinkingHelper;
import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
import org.eclipse.xtext.ui.core.editor.model.XtextDocument;
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/GrammarUtilTests.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/GrammarUtilTests.java
new file mode 100644
index 0000000..ca8981b
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/GrammarUtilTests.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.xtext.crossrefs.LangAStandaloneSetup;
+import org.eclipse.xtext.crossrefs.services.LangAGrammarAccess;
+import org.eclipse.xtext.metamodelreferencing.tests.MetamodelRefTestStandaloneSetup;
+import org.eclipse.xtext.metamodelreferencing.tests.services.MetamodelRefTestGrammarAccess;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.tests.AbstractGeneratorTest;
+
+/**
+ * @author Heiko Behrens - Initial contribution and API
+ */
+public class GrammarUtilTests extends AbstractGeneratorTest {
+
+ public void testGetEPackage() throws Exception {
+ with(LangAStandaloneSetup.class);
+ Grammar grammar = (new LangAGrammarAccess()).getGrammar();
+ EObject model = getModel("type A extends A");
+ assertNotNull(model);
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+
+ assertNull(GrammarUtil.getEPackage(resourceSet, grammar, "unknownAlias"));
+
+ EPackage ePackage = GrammarUtil.getEPackage(resourceSet, grammar, null);
+ assertEquals(3, ePackage.getEClassifiers().size());
+ assertNotNull(ePackage.getEClassifier("Type"));
+ }
+
+ public void testImport() throws Exception {
+ with(MetamodelRefTestStandaloneSetup.class);
+ Grammar grammar = (new MetamodelRefTestGrammarAccess()).getGrammar();
+ EObject model = getModel("test");
+ assertNotNull(model);
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+
+ assertNull(GrammarUtil.getEPackage(resourceSet, grammar, "unknownAlias"));
+
+ EPackage ePackage = GrammarUtil.getEPackage(resourceSet, grammar, null);
+ assertEquals(1, ePackage.getEClassifiers().size());
+ assertNotNull(ePackage.getEClassifier("Foo"));
+
+ ePackage = GrammarUtil.getEPackage(resourceSet, grammar, "xtext");
+ assertEquals(16, ePackage.getEClassifiers().size());
+ assertNotNull(ePackage.getEClassifier("RuleCall"));
+ }
+
+ public void testGetEClass() throws Exception {
+ with(LangAStandaloneSetup.class);
+ XtextResource resource = getResourceFromString("type A extends A");
+
+ ParserRule prType = (new LangAGrammarAccess()).pr_Type();
+ Assignment asExtends = (Assignment)((Group)prType.getAlternatives()).getAbstractTokens().get(1);
+ CrossReference xref = (CrossReference) asExtends.getTerminal();
+
+
+ EClass referencedEClass = GrammarUtil.getReferencedEClass(resource, xref);
+ assertNotNull(referencedEClass);
+
+ EObject model = getModel(resource);
+ EObject typeA = (EObject) invokeWithXtend("types.first()", model);
+ assertEquals(typeA.eClass(), referencedEClass);
+ }
+
+}
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 2d85ef1..e4fa850 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
@@ -6,17 +6,12 @@ import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.Group;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.crossref.ILinkingService;
import org.eclipse.xtext.crossrefs.services.LangAGrammarAccess;
-import org.eclipse.xtext.parsetree.AbstractNode;
-import org.eclipse.xtext.parsetree.CompositeNode;
-import org.eclipse.xtext.parsetree.ParseTreeUtil;
-import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.service.ServiceRegistry;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import org.eclipse.xtext.util.Pair;