aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwannheden2009-08-06 11:10:02 (EDT)
committersefftinge2009-08-06 11:10:02 (EDT)
commite1689d122663538007627a52da73cfa8f0340c8b (patch)
tree9b5384af99306fa93b5a25fbecb84af675c773eb
parent89bc768e8753cddcf439db35f0619c6c6fff92a8 (diff)
downloadorg.eclipse.xtext-e1689d122663538007627a52da73cfa8f0340c8b.zip
org.eclipse.xtext-e1689d122663538007627a52da73cfa8f0340c8b.tar.gz
org.eclipse.xtext-e1689d122663538007627a52da73cfa8f0340c8b.tar.bz2
Fix: Use value from parse tree in DefaultLinkingService#getLinkText() if reference cannot be resolved - https://bugs.eclipse.org/bugs/show_bug.cgi?id=285826
-rwxr-xr-xtests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/linking/CrossRefTest.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/linking/CrossRefTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/linking/CrossRefTest.java
index acdbad6..6586e3d 100755
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/linking/CrossRefTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/linking/CrossRefTest.java
@@ -9,6 +9,13 @@ import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.Group;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.linking.impl.DefaultLinkingService;
+import org.eclipse.xtext.linking.langATestLanguage.LangATestLanguagePackage;
+import org.eclipse.xtext.linking.langATestLanguage.Main;
+import org.eclipse.xtext.linking.langATestLanguage.Type;
+import org.eclipse.xtext.linking.lazy.LazyLinkingTestLanguageStandaloneSetup;
+import org.eclipse.xtext.linking.lazy.lazyLinking.LazyLinkingPackage;
+import org.eclipse.xtext.linking.lazy.lazyLinking.Model;
+import org.eclipse.xtext.linking.lazy.lazyLinking.Property;
import org.eclipse.xtext.linking.services.LangATestLanguageGrammarAccess;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
@@ -49,4 +56,65 @@ public class CrossRefTest extends AbstractGeneratorTest {
assertEquals(1, linkingService.getLinkedObjects(context, ref, leaf).size());
}
+ public void testGetSingleValuedLinkText() throws Exception {
+ XtextResource r = getResourceFromString("type TypeA extends ^extends type ^extends extends ^type");
+ Main model = (Main) r.getContents().get(0);
+ assertEquals(2, model.getTypes().size());
+
+ Type type = model.getTypes().get(0);
+ assertEquals("TypeA", type.getName());
+ Type superType = type.getExtends();
+ assertEquals("extends", superType.getName());
+ String linkText = linkingService.getLinkText(superType, LangATestLanguagePackage.Literals.TYPE__EXTENDS, type);
+ assertEquals("^extends", linkText);
+
+ type = superType;
+ superType = type.getExtends();
+ assertTrue(superType.eIsProxy());
+ linkText = linkingService.getLinkText(superType, LangATestLanguagePackage.Literals.TYPE__EXTENDS, type);
+ assertEquals("^type", linkText);
+
+ type.eAdapters().remove(NodeUtil.getNodeAdapter(type));
+ linkText = linkingService.getLinkText(superType, LangATestLanguagePackage.Literals.TYPE__EXTENDS, type);
+ assertNull(linkText);
+ }
+
+ public void testGetMultiValuedLinkText() throws Exception {
+ with(LazyLinkingTestLanguageStandaloneSetup.class);
+ linkingService = (DefaultLinkingService) get(ILinkingService.class);
+
+ XtextResource r = getResourceFromString("type TypeA {} type TypeB { TypeA TypeC TypeB p1; }");
+ Model model = (Model) r.getContents().get(0);
+ assertEquals(2, model.getTypes().size());
+
+ org.eclipse.xtext.linking.lazy.lazyLinking.Type type = model.getTypes().get(1);
+ assertEquals("TypeB", type.getName());
+ assertEquals(1, type.getProperties().size());
+
+ Property prop = type.getProperties().get(0);
+ assertEquals("p1", prop.getName());
+ assertEquals(3, prop.getType().size());
+
+ org.eclipse.xtext.linking.lazy.lazyLinking.Type propType = prop.getType().get(0);
+ assertFalse(propType.eIsProxy());
+ String linkText = linkingService.getLinkText(propType, LazyLinkingPackage.Literals.PROPERTY__TYPE, prop);
+ assertEquals("TypeA", linkText);
+
+ propType = prop.getType().get(1);
+ assertTrue(propType.eIsProxy());
+ linkText = linkingService.getLinkText(propType, LazyLinkingPackage.Literals.PROPERTY__TYPE, prop);
+ assertEquals("TypeC", linkText);
+
+ propType = prop.getType().get(2);
+ assertFalse(propType.eIsProxy());
+ linkText = linkingService.getLinkText(propType, LazyLinkingPackage.Literals.PROPERTY__TYPE, prop);
+ assertEquals("TypeB", linkText);
+
+ prop.eAdapters().remove(NodeUtil.getNodeAdapter(prop));
+ propType = prop.getType().get(1);
+ assertTrue(propType.eIsProxy());
+ linkText = linkingService.getLinkText(propType, LazyLinkingPackage.Literals.PROPERTY__TYPE, prop);
+ assertNull(linkText);
+ }
+
}