Skip to content
Browse files

Outline View using custom LabelProvider

  • Loading branch information...
1 parent 12737b0 commit 5ac3908371bdaa4ef67057eea3c6ddf9ee817f4d @tvo committed Sep 14, 2011
Showing with 101 additions and 4 deletions.
  1. +2 −1 META-INF/MANIFEST.MF
  2. +2 −2 editor/Lua-Outliner.esv
  3. +93 −0 editor/java/lua/LuaLabelProvider.java
  4. +4 −1 plugin.xml
View
3 META-INF/MANIFEST.MF
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.strategoxt.imp.runtime,
org.spoofax.aterm,
org.spoofax.jsglr,
- org.junit
+ org.junit,
+ org.spoofax.terms
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: lua
View
4 editor/Lua-Outliner.esv
@@ -1,9 +1,9 @@
module Lua-Outliner
-imports Lua-Outliner.generated
+// imports Lua-Outliner.generated
outliner
-
+
// This file can be used for custom outliner rules.
//
// See the imported file for a brief introduction and examples.
View
93 editor/java/lua/LuaLabelProvider.java
@@ -0,0 +1,93 @@
+package lua;
+
+import static org.spoofax.jsglr.client.imploder.ImploderAttachment.getSort;
+import static org.spoofax.terms.Term.tryGetName;
+
+import org.eclipse.imp.services.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+import org.spoofax.interpreter.terms.IStrategoList;
+import org.spoofax.interpreter.terms.IStrategoString;
+import org.spoofax.interpreter.terms.IStrategoTerm;
+import org.strategoxt.imp.runtime.Environment;
+import org.strategoxt.imp.runtime.parser.ast.AstNodeLocator;
+
+/**
+ * Copied parts of org.strategoxt.imp.runtime.services.LabelProvider
+ *
+ * @author Tobi Vollebregt
+ */
+public class LuaLabelProvider implements ILabelProvider {
+
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ IStrategoTerm node = AstNodeLocator.impObjectToAstNode(element);
+ String caption = getCaption(node);
+
+ if (caption == null) {
+ Environment.logException("Unable to infer the caption of this AST node: "
+ + getSort(node) + "." + tryGetName(node));
+ caption = tryGetName(node);
+ }
+ return caption;
+
+ }
+
+ private String getCaption(IStrategoTerm node) {
+ // FIXME: Get rid of this once Spoofax supports specifying caption...
+ String constructor = node == null ? null : tryGetName(node);
+
+ if ("MethodName".equals(constructor)) {
+ StringBuilder sb = new StringBuilder();
+ appendStrategoList(sb, (IStrategoList) node.getSubterm(0));
+ sb.append(":");
+ sb.append(((IStrategoString) node.getSubterm(1)).stringValue());
+ return sb.toString();
+ }
+ else if ("FunctionName".equals(constructor)) {
+ StringBuilder sb = new StringBuilder();
+ appendStrategoList(sb, (IStrategoList) node.getSubterm(0));
+ return sb.toString();
+ }
+ else if ("FunctionDecl".equals(constructor)) {
+ return getCaption(node.getSubterm(0));
+ }
+ else if ("LocalFunctionDecl".equals(constructor)) {
+ return ((IStrategoString) node.getSubterm(0)).stringValue();
+ }
+ else {
+ return null;
+ }
+ }
+
+ private void appendStrategoList(StringBuilder sb, IStrategoList list) {
+ while (!list.isEmpty()) {
+ IStrategoString name = (IStrategoString) list.head();
+ sb.append(name.stringValue());
+ list = list.tail();
+ if (!list.isEmpty()) {
+ sb.append(".");
+ }
+ }
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return true; // TODO: Optimize LabelProvider.isLabelProperty?
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ // Do nothing
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ // Do nothing
+ }
+
+ public void dispose() {
+ // Do nothing
+ }
+
+}
View
5 plugin.xml
@@ -8,5 +8,8 @@
<extension id="lua.parser" name="Lua Parser" point="org.eclipse.imp.runtime.parser">
<parser class="lua.LuaParseController" language="Lua">
</parser>
- </extension>
+ </extension>
+ <extension point="org.eclipse.imp.runtime.labelProvider">
+ <labelProvider class="lua.LuaLabelProvider" language="Lua"></labelProvider>
+ </extension>
</plugin>

0 comments on commit 5ac3908

Please sign in to comment.
Something went wrong with that request. Please try again.