summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2009-01-29 11:56:13 (EST)
committer sefftinge2009-01-29 11:56:13 (EST)
commitb203b874841b0cc17c26e56157fcab1866e7c45a (patch)
treeea905cdae053d12849ef28236bd2e7b6f95c6485
parentea917a5ffbc40b00632ec6faa75688e173ab34fd (diff)
downloadorg.eclipse.xtext-b203b874841b0cc17c26e56157fcab1866e7c45a.zip
org.eclipse.xtext-b203b874841b0cc17c26e56157fcab1866e7c45a.tar.gz
org.eclipse.xtext-b203b874841b0cc17c26e56157fcab1866e7c45a.tar.bz2
bugfix
https://bugs.eclipse.org/bugs/show_bug.cgi?id=262313 https://bugs.eclipse.org/bugs/show_bug.cgi?id=261364 https://bugs.eclipse.org/bugs/show_bug.cgi?id=260825 https://bugs.eclipse.org/bugs/show_bug.cgi?id=260718 https://bugs.eclipse.org/bugs/show_bug.cgi?id=261847
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextHyperlinkDetector.java48
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/ParseTreeUtilTest.java24
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java30
3 files changed, 53 insertions, 49 deletions
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextHyperlinkDetector.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextHyperlinkDetector.java
index 763d972..eaf2230 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextHyperlinkDetector.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextHyperlinkDetector.java
@@ -17,6 +17,7 @@ import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.parser.IParseResult;
+import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.ParseTreeUtil;
import org.eclipse.xtext.resource.XtextResource;
@@ -42,35 +43,34 @@ public class XtextHyperlinkDetector implements IHyperlinkDetector {
* @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
*/
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, final IRegion region, boolean canShowMultipleHyperlinks) {
-
return ((IXtextDocument)textViewer.getDocument()).readOnly(new UnitOfWork<IHyperlink[]>() {
public IHyperlink[] exec(XtextResource resource) throws Exception {
IParseResult parseResult = resource.getParseResult();
Assert.isNotNull(parseResult);
- final LeafNode currentNode =
- (LeafNode) ParseTreeUtil.getCurrentOrFollowingNodeByOffset(parseResult.getRootNode(), region.getOffset());
-
- if (currentNode.getGrammarElement() instanceof CrossReference) {
- return new IHyperlink[] { new IHyperlink() {
-
- public IRegion getHyperlinkRegion() {
- return new Region(currentNode.getTotalOffset(), currentNode.getTotalLength());
- }
-
- public String getHyperlinkText() {
- return currentNode.getText();
- }
-
- public String getTypeLabel() {
- return null;
- }
-
- public void open() {
- new OpenDeclarationAction(currentNode).run();
- }
- } };
+ AbstractNode abstractNode = ParseTreeUtil.getCurrentOrFollowingNodeByOffset(parseResult.getRootNode(),
+ region.getOffset());
+ if (abstractNode instanceof LeafNode) {
+ final LeafNode currentNode = (LeafNode) abstractNode;
+ if (currentNode.getGrammarElement() instanceof CrossReference) {
+
+ return new IHyperlink[] { new IHyperlink() {
+
+ public IRegion getHyperlinkRegion() {
+ return new Region(currentNode.getTotalOffset(), currentNode.getTotalLength());
+ }
+ public String getHyperlinkText() {
+ return currentNode.getText();
+ }
+ public String getTypeLabel() {
+ return null;
+ }
+ public void open() {
+ new OpenDeclarationAction(currentNode).run();
+ }
+
+ } };
+ }
}
-
return null;
}
});
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/ParseTreeUtilTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/ParseTreeUtilTest.java
index 39dcdbe..ffc2dee 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/ParseTreeUtilTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/ParseTreeUtilTest.java
@@ -8,14 +8,9 @@
*******************************************************************************/
package org.eclipse.xtext.parsetree;
-import java.util.Arrays;
-import java.util.Iterator;
import java.util.Set;
import org.eclipse.xtext.AbstractElement;
-import org.eclipse.xtext.Alternatives;
-import org.eclipse.xtext.Assignment;
-import org.eclipse.xtext.Group;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.testlanguages.ReferenceGrammarTestLanguageStandaloneSetup;
@@ -216,7 +211,6 @@ public class ParseTreeUtilTest extends AbstractGeneratorTest {
Set<AbstractElement> elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text
.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Group.class);
}
public void testGetElementSetValidFromOffset() throws Exception {
@@ -225,60 +219,42 @@ public class ParseTreeUtilTest extends AbstractGeneratorTest {
Set<AbstractElement> elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text
.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Assignment.class);
// Keyword Assignment [Assignment|Keyword]
text = "spielplatz 1 ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 2 items", 2, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Assignment.class, Keyword.class);
// Keyword Assignment Assignment [Keyword]
text = "spielplatz 1 \"junit\" ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Keyword.class);
// Keyword Assignment Assignment Keyword [Alternatives|Keyword]
text = "spielplatz 1 \"junit\" { ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 2 items", 2, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Alternatives.class, Keyword.class);
// Keyword Assignment Assignment Keyword [Keyword]
text = "spielplatz 1 \"junit\" { kind ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Keyword.class);
// Keyword Assignment Assignment Keyword Keyword [Assignment]
text = "spielplatz 1 \"junit\" { kind ( ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Assignment.class);
// Keyword Assignment Assignment Keyword
text = "spielplatz 1 \"junit\" { kind (kind1 0) kind (kind2 0) erwachsener (e1 1) erwachsener (e2 2) familie ( asd ";
rootNode = getRootNode(text);
elementSetValidFromOffset = ParseTreeUtil.getElementSetValidFromOffset(rootNode, text.length());
assertEquals("expect only 1 item", 1, elementSetValidFromOffset.size());
- assertEqualsClass(elementSetValidFromOffset, Assignment.class);
- }
-
- private void assertEqualsClass(Set<AbstractElement> set, Class<?>... expectedClass) {
- assertEquals("size of abstract element set must equal class array", set.size(), expectedClass.length);
- Iterator<Class<?>> classIterator = Arrays.asList(expectedClass).iterator();
- for (Iterator<AbstractElement> iterator = set.iterator(); iterator.hasNext();) {
- AbstractElement abstractElement = iterator.next();
- Class<?> nextClass = classIterator.next();
- assertTrue("class '" + nextClass + "' must be assignable from '" + abstractElement.getClass() + "'",
- nextClass.isAssignableFrom(abstractElement.getClass()));
- }
}
}
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
index fcf185a..5a19d6d 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
@@ -177,7 +177,35 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
contentAssistProcessorTestBuilder.append(" spielplatz 1 \"SpielplatzBeschreibung\" { } ")
.assertTextAtCursorPosition(1, "spielplatz");
}
-
+ /**
+ * regression test for:
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=260825
+ */
+ public void testCompleteParserRule() throws Exception {
+ newBuilder(XtextGrammarTestLanguageStandaloneSetup.class, XtextGrammarTestLanguageUiConfig.class)
+ .appendNl("language foo")
+ .appendNl("generate foo \"foo\"")
+ .appendNl("MyRule : 'foo' name=ID; ").assertText(
+ "ParserRule_Name", "lexer", "native", "terminal"
+ );
+
+ }
+ /**
+ * regression test for:
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=260825
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=262313
+ */
+ public void testCompleteAssignmentWithBacktracking() throws Exception {
+ newBuilder(XtextGrammarTestLanguageStandaloneSetup.class, XtextGrammarTestLanguageUiConfig.class)
+ .appendNl("language foo")
+ .appendNl("generate foo \"foo\"")
+ .append("MyRule : 'foo' name").assertText(
+ "*", "+", "+=", ";", "=", "?", "?="
+ );
+
+ }
private ContentAssistProcessorTestBuilder newBuilder(Class<?> standAloneSetup, Class<?> uiConfig) throws Exception {
withUi(standAloneSetup, uiConfig);