rename DebugTree for clarity, move out of PDEX

This commit is contained in:
Ben Fry
2020-01-28 10:34:24 -05:00
parent 06f7a18429
commit 69718c6f29
3 changed files with 31 additions and 31 deletions

View File

@@ -24,13 +24,13 @@ import processing.app.ui.ZoomTreeCellRenderer;
import processing.mode.java.PreprocessedSketch.SketchInterval;
class DebugTree {
class ASTViewer {
final JDialog window;
final JTree tree;
final Consumer<PreprocessedSketch> updateListener;
DebugTree(JavaEditor editor, PreprocessingService pps) {
ASTViewer(JavaEditor editor, PreprocessingService pps) {
updateListener = this::buildAndUpdateTree;
window = new JDialog(editor);

View File

@@ -90,6 +90,10 @@ public class JavaEditor extends Editor {
protected PreprocessingService preprocessingService;
protected PDEX pdex;
// set true to show AST debugging window
static private final boolean SHOW_AST_VIEWER = false;
private ASTViewer astViewer;
protected JavaEditor(Base base, String path, EditorState state,
Mode mode) throws EditorException {
@@ -128,6 +132,10 @@ public class JavaEditor extends Editor {
preprocessingService = new PreprocessingService(this);
pdex = new PDEX(this, preprocessingService);
if (SHOW_AST_VIEWER) {
astViewer = new ASTViewer(this, preprocessingService);
}
Toolkit.setMenuMnemonics(textarea.getRightClickPopup());
// ensure completion is hidden when editor loses focus
@@ -1338,6 +1346,9 @@ public class JavaEditor extends Editor {
}
preprocessingService.dispose();
pdex.dispose();
if (astViewer != null) {
astViewer.dispose();
}
super.dispose();
}

View File

@@ -8,8 +8,6 @@ import processing.app.SketchCode;
public class PDEX {
static private final boolean SHOW_DEBUG_TREE = false;
private boolean enabled = true;
private ErrorChecker errorChecker;
@@ -17,7 +15,6 @@ public class PDEX {
private InspectMode inspect;
private ShowUsage usage;
private Rename rename;
private DebugTree debugTree;
private PreprocessingService pps;
@@ -33,10 +30,6 @@ public class PDEX {
inspect = new InspectMode(editor, pps, usage);
rename = new Rename(editor, pps, usage);
if (SHOW_DEBUG_TREE) {
debugTree = new DebugTree(editor, pps);
}
for (SketchCode code : editor.getSketch().getCode()) {
Document document = code.getDocument();
addDocumentListener(document);
@@ -47,28 +40,27 @@ public class PDEX {
public void addDocumentListener(Document doc) {
if (doc != null) doc.addDocumentListener(sketchChangedListener);
if (doc != null) {
doc.addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
sketchChanged();
}
@Override
public void removeUpdate(DocumentEvent e) {
sketchChanged();
}
@Override
public void changedUpdate(DocumentEvent e) {
sketchChanged();
}
});
}
}
final DocumentListener sketchChangedListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
sketchChanged();
}
@Override
public void removeUpdate(DocumentEvent e) {
sketchChanged();
}
@Override
public void changedUpdate(DocumentEvent e) {
sketchChanged();
}
};
public void sketchChanged() {
errorChecker.notifySketchChanged();
pps.notifySketchChanged();
@@ -94,9 +86,6 @@ public class PDEX {
errorChecker.dispose();
usage.dispose();
rename.dispose();
if (debugTree != null) {
debugTree.dispose();
}
}