|
From: <mir...@us...> - 2006-10-31 12:27:28
|
Revision: 1634
http://svn.sourceforge.net/rubyeclipse/?rev=1634&view=rev
Author: mirkostocker
Date: 2006-10-31 04:27:07 -0800 (Tue, 31 Oct 2006)
Log Message:
-----------
added an additional action to the astviewer that dumps the selected node and its children to a console.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.astviewer/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/AstViewerPreferencePage.java
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceConstants.java
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceInitializer.java
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstView.java
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.astviewer/icons/dump.gif
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstUtility.java
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstViewConsole.java
Modified: trunk/org.rubypeople.rdt.astviewer/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/META-INF/MANIFEST.MF 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/META-INF/MANIFEST.MF 2006-10-31 12:27:07 UTC (rev 1634)
@@ -13,7 +13,8 @@
org.eclipse.jface.text,
org.rubypeople.rdt.core,
org.eclipse.ui.editors,
- org.eclipse.ui.workbench.texteditor
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.ui.console
Eclipse-LazyStart: true
Export-Package: org.rubypeople.rdt.astviewer,
org.rubypeople.rdt.astviewer.views
Added: trunk/org.rubypeople.rdt.astviewer/icons/dump.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.astviewer/icons/dump.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/AstViewerPreferencePage.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/AstViewerPreferencePage.java 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/AstViewerPreferencePage.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -1,3 +1,31 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
package org.rubypeople.rdt.astviewer.preferences;
import org.eclipse.jface.preference.*;
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceConstants.java 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceConstants.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -1,3 +1,31 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
package org.rubypeople.rdt.astviewer.preferences;
/**
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceInitializer.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceInitializer.java 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/preferences/PreferenceInitializer.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -1,3 +1,31 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
package org.rubypeople.rdt.astviewer.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
Added: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstUtility.java (rev 0)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstUtility.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -0,0 +1,78 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
+package org.rubypeople.rdt.astviewer.views;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.jruby.ast.Node;
+
+public class AstUtility {
+
+ public static ArrayList<Node> findAllNodes(Node rootNode) {
+ ArrayList<Node> nodes = new ArrayList<Node>();
+ if(rootNode == null)
+ return nodes;
+ nodes.add(rootNode);
+ for(Object o : rootNode.childNodes()) {
+ nodes.addAll(findAllNodes((Node) o));
+ }
+ return nodes;
+ }
+
+ public static String nodeList(ArrayList<Node> nodes) {
+ StringBuilder str = new StringBuilder();
+ Iterator it = nodes.iterator();
+ while(it.hasNext()) {
+ String name = ((Node) it.next()).getClass().getName();
+ str.append(name.substring(name.lastIndexOf(".") + 1, name.length()));
+ if(it.hasNext())
+ str.append(", ");
+ }
+ return str.toString();
+ }
+
+ public static String formatedPosition(Node n) {
+ if(n == null)
+ return "";
+
+ StringBuilder posString = new StringBuilder();
+ posString.append("Lines [");
+ posString.append(n.getPosition().getStartLine());
+ posString.append(":");
+ posString.append(n.getPosition().getEndLine());
+ posString.append("], Offset [");
+ posString.append(n.getPosition().getStartOffset());
+ posString.append(":");
+ posString.append(n.getPosition().getEndOffset());
+ posString.append("]");
+ return posString.toString();
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstView.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstView.java 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstView.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -61,6 +61,7 @@
private TreeViewer viewer;
private DrillDownAdapter drillDownAdapter;
private Action refreshAction;
+ private Action dumpToConsoleAction;
private Action doubleClickAction;
private Action clickAction;
private ViewContentProvider viewContentProvider;
@@ -152,10 +153,12 @@
private void fillLocalPullDown(IMenuManager manager) {
manager.add(refreshAction);
+ manager.add(dumpToConsoleAction);
}
private void fillContextMenu(IMenuManager manager) {
manager.add(refreshAction);
+ manager.add(dumpToConsoleAction);
drillDownAdapter.addNavigationActions(manager);
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
@@ -163,10 +166,30 @@
private void fillLocalToolBar(IToolBarManager manager) {
manager.add(refreshAction);
+ manager.add(dumpToConsoleAction);
drillDownAdapter.addNavigationActions(manager);
}
+
+
private void makeActions() {
+ makeRefreshAction();
+ makeDumpAction();
+ }
+
+ private void makeDumpAction() {
+ dumpToConsoleAction = new Action() {
+ public void run() {
+ AstViewConsole.print(AstUtility.nodeList(AstUtility.findAllNodes(getSelectedNode())));
+ }
+ };
+
+ dumpToConsoleAction.setText("Dump Node");
+ dumpToConsoleAction.setToolTipText("Dumps node and all child-nodes to the console.");
+ dumpToConsoleAction.setImageDescriptor(Activator.getImageDescriptor("icons/dump.gif"));
+ }
+
+ private void makeRefreshAction() {
refreshAction = new Action() {
public void run() {
viewContentProvider.forceUpdateContent();
@@ -186,28 +209,11 @@
editor.selectAndReveal(n.getPosition().getStartOffset(), n.getPosition().getEndOffset() - n.getPosition().getStartOffset() + 1);
}
- private String formatedPosition(Node n) {
- if(n == null)
- return "";
-
- StringBuilder posString = new StringBuilder();
- posString.append("Lines [");
- posString.append(n.getPosition().getStartLine());
- posString.append(":");
- posString.append(n.getPosition().getEndLine());
- posString.append("], Offset [");
- posString.append(n.getPosition().getStartOffset());
- posString.append(":");
- posString.append(n.getPosition().getEndOffset());
- posString.append("]");
- return posString.toString();
- }
-
private void hookClickAction() {
clickAction = new Action(){
public void run() {
- detailsViewer.getDocument().set(formatedPosition(getSelectedNode()));
+ detailsViewer.getDocument().set(AstUtility.formatedPosition(getSelectedNode()));
}
};
Added: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstViewConsole.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstViewConsole.java (rev 0)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/AstViewConsole.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -0,0 +1,79 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
+package org.rubypeople.rdt.astviewer.views;
+
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleConstants;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.IConsoleView;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+
+public class AstViewConsole {
+
+ private static final String name = "AST Viewer";
+
+ private static MessageConsole findConsole(String name) {
+ ConsolePlugin plugin = ConsolePlugin.getDefault();
+ IConsoleManager conMan = plugin.getConsoleManager();
+ IConsole[] existing = conMan.getConsoles();
+ for (int i = 0; i < existing.length; i++)
+ if (name.equals(existing[i].getName()))
+ return (MessageConsole) existing[i];
+ //no console found, so create a new one
+ MessageConsole myConsole = new MessageConsole(name, null);
+ conMan.addConsoles(new IConsole[] { myConsole });
+ return myConsole;
+ }
+
+ public static void print(String text) {
+ revealConsole();
+ MessageConsole myConsole = findConsole(name);
+ MessageConsoleStream out = myConsole.newMessageStream();
+ out.println(text);
+ }
+
+ private static void revealConsole() {
+ IConsole myConsole = findConsole(name);
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ String id = IConsoleConstants.ID_CONSOLE_VIEW;
+ IConsoleView view;
+ try {
+ view = (IConsoleView) page.showView(id);
+ view.display(myConsole);
+ } catch (PartInitException e) {
+ return;
+ }
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java 2006-10-30 00:39:27 UTC (rev 1633)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java 2006-10-31 12:27:07 UTC (rev 1634)
@@ -118,9 +118,8 @@
lexerSource = new LexerSource(getFile().getName(), new InputStreamReader(getFile().getContents()));
return parser.parse(lexerSource).getAST();
} catch (CoreException e) {
- e.printStackTrace();
+ return null;
}
- return null;
}
private void initialize() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|