summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2004-11-19 15:58:09 +0000
committerIulian Dragos <jaguarul@gmail.com>2004-11-19 15:58:09 +0000
commitc9e33b2023e4a2019f9bfd1623a634fbe3837181 (patch)
tree296431de24f2f190e384073675b49d5850610711 /sources
parent02dc24e06886d3ecc2180f4ac53c2c48a643de1b (diff)
downloadscala-c9e33b2023e4a2019f9bfd1623a634fbe3837181.tar.gz
scala-c9e33b2023e4a2019f9bfd1623a634fbe3837181.tar.bz2
scala-c9e33b2023e4a2019f9bfd1623a634fbe3837181.zip
Added symbol and type information to the right ...
Added symbol and type information to the right panel
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalac/ast/printer/SwingPrinter.scala42
-rw-r--r--sources/scala/tools/scalac/ast/printer/TreeInfo.scala19
2 files changed, 48 insertions, 13 deletions
diff --git a/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala b/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala
index b8c7d98969..2f970d9f1f 100644
--- a/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala
+++ b/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala
@@ -140,12 +140,13 @@ class ASTTreeModel extends TreeModel {
class WindowFrame {
val frame = new JFrame("Scala AST");
val topPane = new JPanel(new BorderLayout());
- val topRightPane = new JPanel();
+ val topRightPane = new JPanel(new BorderLayout());
val bottomPane = new JPanel(new BorderLayout());
var splitPane: JSplitPane = _;
var treeModel: TreeModel = _;
val textArea: JTextArea = new JTextArea(20, 50);
+ val infoPanel = new InfoPanel();
/** Create a frame that displays the AST.
@@ -166,11 +167,6 @@ class WindowFrame {
override def windowClosed(e: WindowEvent): Unit = lock.release;
});
- topPane.setMinimumSize(new java.awt.Dimension(150, 200));
- bottomPane.setMinimumSize(new java.awt.Dimension(150, 200));
-
- splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPane, bottomPane);
-
val tree = new JTree(treeModel) {
/** Return the string for a tree node. */
override def convertValueToText(value: Any, sel: Boolean,
@@ -193,18 +189,20 @@ class WindowFrame {
tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
def valueChanged(e: javax.swing.event.TreeSelectionEvent): Unit = {
textArea.setText(e.getPath().getLastPathComponent().toString());
+ infoPanel.update(e.getPath().getLastPathComponent());
}
});
+ val topSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPane, topRightPane);
topPane.add(new JScrollPane(tree), BorderLayout.CENTER);
- topPane.add(topRightPane, BorderLayout.EAST);
- topRightPane.add(new InfoPanel());
+ topRightPane.add(infoPanel, BorderLayout.CENTER);
bottomPane.add(new JScrollPane(textArea), BorderLayout.CENTER);
textArea.setFont(new Font("monospaced", Font.PLAIN, 14));
textArea.setEditable(false);
+ splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplitPane, bottomPane);
frame.getContentPane().add(splitPane);
frame.pack();
frame.setVisible(true);
@@ -213,17 +211,18 @@ class WindowFrame {
def setTreeModel(tm: TreeModel): Unit = treeModel = tm;
}
-
+/** Pannel that shows some information about the selected
+ * tree node (like symbol, type, etc) */
class InfoPanel extends JPanel() {
val symbolLine = Box.createHorizontalBox();
val symbolAttLine = Box.createHorizontalBox();
val symbolTypeLine = Box.createHorizontalBox();
val treeTypeLine = Box.createHorizontalBox();
- val symLabel = new JLabel("some");
- val attLabel = new JLabel("[private, final, synthetic]");
- val stypeLabel = new JLabel("...");
- val ttypeLabel = new JLabel(".......");
+ val symLabel = new JLabel("");
+ val attLabel = new JLabel("");
+ val stypeLabel = new JLabel("");
+ val ttypeLabel = new JLabel("");
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
@@ -247,6 +246,23 @@ class InfoPanel extends JPanel() {
add(symbolAttLine);
add(symbolTypeLine);
add(treeTypeLine);
+
+ def update(v: AnyRef): Unit =
+ if (v.isInstanceOf[Tree]) {
+ val t = v.asInstanceOf[Tree];
+
+ symLabel.setText(TreeInfo.symbolText(t));
+ stypeLabel.setText(TreeInfo.symbolTypeText(t));
+ ttypeLabel.setText(t.`type`().toString());
+ } else
+ reset;
+
+ def reset: Unit = {
+ symLabel.setText("");
+ stypeLabel.setText("");
+ ttypeLabel.setText("");
+ attLabel.setText("");
+ }
}
} // package
diff --git a/sources/scala/tools/scalac/ast/printer/TreeInfo.scala b/sources/scala/tools/scalac/ast/printer/TreeInfo.scala
index d84e164c87..0f4dd4a040 100644
--- a/sources/scala/tools/scalac/ast/printer/TreeInfo.scala
+++ b/sources/scala/tools/scalac/ast/printer/TreeInfo.scala
@@ -327,7 +327,26 @@ object TreeInfo {
Nil;
}
+ /** Return a textual representation of this t's symbol */
+ def symbolText(t: Tree): String = {
+ var prefix = "";
+ if (t.hasSymbol())
+ prefix = "[has] ";
+ if (t.definesSymbol())
+ prefix = "[defines] ";
+
+ prefix + t.symbol()
+ }
+
+ /** Return t's symbol type */
+ def symbolTypeText(t: Tree): String = {
+ val s = t.symbol();
+ if (s != null)
+ s.`type`().toString();
+ else
+ "";
+ }
}
} // package