summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-05 10:25:53 (EST)
committer sefftinge2009-03-05 10:25:53 (EST)
commitea066a2e89a233942ac9d895f863a5d659e11335 (patch)
tree83b1b4ed76874f95987ceb82d2dcd2fbf35f3bbd
parent917bb1d7265aba1805232a50a9382f596f7bc1e6 (diff)
downloadorg.eclipse.xtext-ea066a2e89a233942ac9d895f863a5d659e11335.zip
org.eclipse.xtext-ea066a2e89a233942ac9d895f863a5d659e11335.tar.gz
org.eclipse.xtext-ea066a2e89a233942ac9d895f863a5d659e11335.tar.bz2
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=267193
Sugar and minor fixes for Xtext outline
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/AbstractSemanticModelTransformer.java13
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/LazyTransformingTreeProvider.java14
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src-gen/org/eclipse/xtext/actions/ParserTest.java150
3 files changed, 18 insertions, 159 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/AbstractSemanticModelTransformer.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/AbstractSemanticModelTransformer.java
index e9d1533..d9c2fba 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/AbstractSemanticModelTransformer.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/AbstractSemanticModelTransformer.java
@@ -11,6 +11,7 @@ package org.eclipse.xtext.ui.common.editor.outline.impl;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -59,7 +60,7 @@ public abstract class AbstractSemanticModelTransformer implements ISemanticModel
}
private EObject[] sortChildren(EObject semanticNode) {
- EObject[] result = semanticNode.eContents().toArray(new EObject[semanticNode.eContents().size()]);
+ EObject[] result = getChildren(semanticNode).toArray(new EObject[semanticNode.eContents().size()]);
if (sorted) {
Arrays.sort(result, new Comparator<EObject>() {
public int compare(EObject arg0, EObject arg1) {
@@ -72,6 +73,10 @@ public abstract class AbstractSemanticModelTransformer implements ISemanticModel
return result;
}
+ protected List<EObject> getChildren(EObject semanticNode) {
+ return semanticNode.eContents();
+ }
+
public void setSorted(boolean on) {
this.sorted = on;
}
@@ -88,7 +93,7 @@ public abstract class AbstractSemanticModelTransformer implements ISemanticModel
filters.remove(filterSpec.getClass());
}
}
-
+
public boolean isFilterActive(IOutlineFilter filterSpec) {
if (filters != null) {
return filters.containsKey(filterSpec.getClass());
@@ -97,7 +102,7 @@ public abstract class AbstractSemanticModelTransformer implements ISemanticModel
return false;
}
}
-
+
public boolean isFilterActive(Class clazz) {
if (filters != null) {
return filters.containsKey(clazz);
@@ -106,7 +111,7 @@ public abstract class AbstractSemanticModelTransformer implements ISemanticModel
return false;
}
}
-
+
protected abstract boolean doSortChildren(EObject semanticNode);
protected abstract ContentOutlineNode createOutlineNode(EObject semanticNode, ContentOutlineNode outlineParentNode);
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/LazyTransformingTreeProvider.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/LazyTransformingTreeProvider.java
index b18e82a..0e33ae4 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/LazyTransformingTreeProvider.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/outline/impl/LazyTransformingTreeProvider.java
@@ -38,12 +38,12 @@ import com.google.inject.Inject;
public class LazyTransformingTreeProvider extends LabelProvider implements ILazyTreeProvider, ISortableContentProvider, IFilterableContentProvider {
final static Logger logger = Logger.getLogger(LazyTransformingTreeProvider.class);
-
- private LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
+
+ private final LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
private TreeViewer viewer;
private ContentOutlineNode outlineModel;
-
+
@Override
public void dispose() {
super.dispose();
@@ -60,7 +60,11 @@ public class LazyTransformingTreeProvider extends LabelProvider implements ILazy
outlineModel = document.readOnly(new UnitOfWork<ContentOutlineNode>() {
public ContentOutlineNode exec(XtextResource resource) throws Exception {
EObject semanticModelRoot = resource.getParseResult().getRootASTElement();
- return transformSemanticModelToOutlineModel(semanticModelRoot);
+ if (semanticModelRoot != null)
+ return transformSemanticModelToOutlineModel(semanticModelRoot);
+ ContentOutlineNode errorNode = new ContentOutlineNode();
+ errorNode.setLabel("Error: No model available.");
+ return errorNode;
}
});
}
@@ -133,7 +137,7 @@ public class LazyTransformingTreeProvider extends LabelProvider implements ILazy
}
return super.getImage(element);
}
-
+
public void setSorted(boolean on) {
semanticModelTransformer.setSorted(on);
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src-gen/org/eclipse/xtext/actions/ParserTest.java b/tests/org.eclipse.xtext.generator.tests/src-gen/org/eclipse/xtext/actions/ParserTest.java
deleted file mode 100644
index 7de7928..0000000
--- a/tests/org.eclipse.xtext.generator.tests/src-gen/org/eclipse/xtext/actions/ParserTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*******************************************************************************
- * 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.actions;
-
-import org.eclipse.xtext.junit.AbstractXtextTests;
-import org.eclipse.xtext.parser.IParser;
-import org.eclipse.xtext.parser.ParserTestHelper;
-import org.eclipse.xtext.parsetree.AbstractNode;
-import org.eclipse.xtext.parsetree.CompositeNode;
-import org.eclipse.xtext.parsetree.LeafNode;
-import org.eclipse.xtext.parsetree.NodeAdapter;
-import org.eclipse.xtext.parsetree.NodeUtil;
-import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.testlanguages.ActionTestLanguageStandaloneSetup;
-import org.eclipse.xtext.testlanguages.actionLang.ActionLangPackage;
-import org.eclipse.xtext.testlanguages.actionLang.Model;
-import org.eclipse.xtext.testlanguages.actionLang.Parent;
-import org.eclipse.xtext.testlanguages.services.ActionTestLanguageGrammarAccess;
-
-/**
- * @author Sebastian Zarnekow - Initial contribution and API
- */
-public abstract class ParserTest extends AbstractXtextTests {
-
- private ActionTestLanguageGrammarAccess grammarAccess;
- private ParserTestHelper helper;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- with(ActionTestLanguageStandaloneSetup.class);
- grammarAccess = get(ActionTestLanguageGrammarAccess.class);
- helper = new ParserTestHelper(getResourceFactory(), getParser(), get(Keys.RESOURCE_SET_KEY));
- }
-
- @Override
- protected void tearDown() throws Exception {
- grammarAccess = null;
- super.tearDown();
- }
-
- public static class Antlr extends ParserTest {
- @Override
- protected IParser getParser() {
- return getAntlrParser();
- }
- }
-
- public static class Packrat extends ParserTest {
- @Override
- protected IParser getParser() {
- return getPackratParser();
- }
- }
-
- /**
- * Model: '<code>myID</code>'
- * The following parse tree is expected:
- * <pre>
- * CompositeNode (GrammarElement: Rule[Model], Element: null)
- * |
- * CompositeNode (GrammarElement: RuleCall[Child], Element: Child[myID])
- * |
- * LeafNode (GrammarElement: RuleCall[ID], Element: null)
- * </pre>
- */
- public void testParseWithoutActionCall() throws Exception {
- XtextResource resource = helper.getResourceFromString("myID");
- assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
- Model model = (Model) resource.getContents().get(0);
- assertNotNull("model", model);
- assertEquals(model.eClass().getName(), ActionLangPackage.Literals.CHILD, model.eClass());
- NodeAdapter adapter = NodeUtil.getNodeAdapter(model);
- assertNotNull("adapter", adapter);
- CompositeNode node = adapter.getParserNode();
- assertNotNull("node", node);
- assertEquals("node.grammarElement", grammarAccess.prModel().ele0ParserRuleCallChild(), node.getGrammarElement());
- assertEquals(node.getChildren().toString(), 1, node.getChildren().size());
- AbstractNode childNode = node.getChildren().get(0);
- assertTrue(childNode.toString(), childNode instanceof LeafNode);
- assertEquals("childNode.grammarElement", grammarAccess.prChild().ele0TerminalRuleCallID(), childNode.getGrammarElement());
- assertNull("childNode.element", childNode.getElement());
-
- CompositeNode rootNode = resource.getParseResult().getRootNode();
- assertNotNull("rootNode", rootNode);
- assertEquals("rootNode.grammarElement", grammarAccess.prModel().getRule(), rootNode.getGrammarElement());
- assertEquals(rootNode.getChildren().toString(), 1, rootNode.getChildren().size());
- assertEquals("node is child of rootNode", rootNode, node.getParent());
- assertNull("rootNode.element", rootNode.getElement());
- }
-
- /**
- * Model: '<code>myID otherID</code>'
- * The following parse tree is expected:
- * <pre>
- * CompositeNode (GrammarElement: Action, Element: Parent[left: Child[myID], right: Child[otherID]])
- * |________________________________________________________________________,
- * CompositeNode (GrammarElement: Rule[Model], Element: null) CompositeNode (GrammarElement: RuleCall[Child], Element: Child[otherID])
- * | |________________,
- * CompositeNode (GrammarElement: RuleCall[Child], Element: Child[myID]) LeafNode (WS) LeafNode (GrammarElement: RuleCall[ID], Element: null)
- * |
- * LeafNode (GrammarElement: RuleCall[ID], Element: null)
- * </pre>
- */
- public void testParseWithActionCall() throws Exception {
- XtextResource resource = helper.getResourceFromString("myID otherID");
- assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
- Model model = (Model) resource.getContents().get(0);
- assertNotNull("model", model);
- assertEquals(model.eClass().getName(), ActionLangPackage.Literals.PARENT, model.eClass());
- NodeAdapter adapter = NodeUtil.getNodeAdapter(model);
- assertNotNull("adapter", adapter);
- CompositeNode node = adapter.getParserNode();
- assertNotNull("node", node);
- assertEquals("node.grammarElement", grammarAccess.prModel().ele10ActionParentleft(), node.getGrammarElement());
- assertEquals(node.getChildren().toString(), 2, node.getChildren().size());
- CompositeNode firstChildNode = (CompositeNode) node.getChildren().get(0);
- assertEquals("firstChildNode.grammarElement", grammarAccess.prModel().getRule(), firstChildNode.getGrammarElement());
- assertNull("firstChildNode.element", firstChildNode.getElement());
- assertEquals(firstChildNode.getChildren().toString(), 1, firstChildNode.getChildren().size());
-
- AbstractNode childNode = firstChildNode.getChildren().get(0);
- assertTrue(childNode.toString(), childNode instanceof CompositeNode);
- assertEquals("childNode.grammarElement", grammarAccess.prModel().ele0ParserRuleCallChild(), childNode.getGrammarElement());
- assertEquals("childNode.element", ((Parent)model).getLeft(), childNode.getElement());
- assertEquals(((CompositeNode) childNode).getChildren().toString(), 1, ((CompositeNode) childNode).getChildren().size());
- assertEquals("childNode.children[0].grammarElement", grammarAccess.prChild().ele0TerminalRuleCallID(),
- ((CompositeNode) childNode).getChildren().get(0).getGrammarElement());
-
- CompositeNode secondChildNode = (CompositeNode) node.getChildren().get(1);
- assertEquals("childNode.grammarElement", grammarAccess.prModel().ele110ParserRuleCallChild(), secondChildNode.getGrammarElement());
- assertEquals("childNode.element", ((Parent)model).getRight(), secondChildNode.getElement());
-
- AbstractNode otherChildNode = secondChildNode.getChildren().get(1);
- assertTrue(otherChildNode.toString(), otherChildNode instanceof LeafNode);
- assertEquals("otherChildNode.grammarElement", grammarAccess.prChild().ele0TerminalRuleCallID(), otherChildNode.getGrammarElement());
-
- CompositeNode rootNode = resource.getParseResult().getRootNode();
- assertNotNull("rootNode", rootNode);
- assertEquals("rootNode.grammarElement", grammarAccess.prModel().ele10ActionParentleft(), rootNode.getGrammarElement());
- assertEquals(node, rootNode);
- }
-
-
-}