| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,8 +140,15 @@ public void actionPerformed(ActionEvent e) { | |||
| 140 | 140 | hasJavaTabs = checkForJavaTabs(); | |
| 141 | 141 | //initializeErrorChecker(); | |
| 142 | 142 | ||
| 143 | - errorCheckerService = new ErrorCheckerService(this); | ||
| 144 | - errorCheckerService.start(); | ||
| 143 | + { // Init error checker | ||
| 144 | + errorCheckerService = new ErrorCheckerService(this); | ||
| 145 | + Document currentDocument = currentDocument(); | ||
| 146 | + if (currentDocument != null) { | ||
| 147 | + errorCheckerService.addListener(currentDocument); | ||
| 148 | + } | ||
| 149 | + errorCheckerService.start(); | ||
| 150 | + errorCheckerService.request(); | ||
| 151 | + } | ||
| 145 | 152 | ||
| 146 | 153 | // hack to add a JPanel to the right-hand side of the text area | |
| 147 | 154 | JPanel textAndError = new JPanel(); | |
@@ -2330,10 +2337,18 @@ public boolean isInCurrentTab(LineID line) { | |||
| 2330 | 2337 | */ | |
| 2331 | 2338 | @Override | |
| 2332 | 2339 | public void setCode(SketchCode code) { | |
| 2340 | + | ||
| 2341 | + Document oldDoc = code.getDocument(); | ||
| 2342 | + | ||
| 2333 | 2343 | //System.out.println("tab switch: " + code.getFileName()); | |
| 2334 | 2344 | // set the new document in the textarea, etc. need to do this first | |
| 2335 | 2345 | super.setCode(code); | |
| 2336 | 2346 | ||
| 2347 | + Document newDoc = code.getDocument(); | ||
| 2348 | + if (oldDoc != newDoc && errorCheckerService != null) { | ||
| 2349 | + errorCheckerService.addListener(newDoc); | ||
| 2350 | + } | ||
| 2351 | + | ||
| 2337 | 2352 | // set line background colors for tab | |
| 2338 | 2353 | final JavaTextArea ta = getJavaTextArea(); | |
| 2339 | 2354 | // can be null when setCode is called the first time (in constructor) | |
@@ -2729,13 +2744,14 @@ private boolean checkForJavaTabs() { | |||
| 2729 | 2744 | } | |
| 2730 | 2745 | ||
| 2731 | 2746 | ||
| 2747 | + @Override | ||
| 2732 | 2748 | protected void applyPreferences() { | |
| 2733 | 2749 | super.applyPreferences(); | |
| 2734 | 2750 | if (jmode != null) { | |
| 2735 | 2751 | jmode.loadPreferences(); | |
| 2736 | 2752 | Messages.log("Applying prefs"); | |
| 2737 | 2753 | // trigger it once to refresh UI | |
| 2738 | - errorCheckerService.request(); | ||
| 2754 | + errorCheckerService.handleErrorCheckingToggle(); | ||
| 2739 | 2755 | } | |
| 2740 | 2756 | } | |
| 2741 | 2757 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,7 +235,6 @@ public ErrorCheckerService(JavaEditor debugEditor) { | |||
| 235 | 235 | astGenerator = new ASTGenerator(this); | |
| 236 | 236 | errorMsgSimplifier = new ErrorMessageSimplifier(); | |
| 237 | 237 | tempErrorLog = new TreeMap<>(); | |
| 238 | - sketchChangedListener = new SketchChangedListener(); | ||
| 239 | 238 | // for (final SketchCode sc : editor.getSketch().getCode()) { | |
| 240 | 239 | // sc.getDocument().addDocumentListener(sketchChangedListener); | |
| 241 | 240 | // } | |
@@ -275,7 +274,6 @@ public void run() { | |||
| 275 | 274 | astGenerator.buildAST(lastCodeCheckResult.sourceCode, | |
| 276 | 275 | lastCodeCheckResult.compilationUnit); | |
| 277 | 276 | } | |
| 278 | - handleErrorCheckingToggle(); | ||
| 279 | 277 | ||
| 280 | 278 | while (running) { | |
| 281 | 279 | try { | |
@@ -288,16 +286,16 @@ public void run() { | |||
| 288 | 286 | try { | |
| 289 | 287 | ||
| 290 | 288 | Messages.log("Starting error check"); | |
| 291 | - lastCodeCheckResult = checkCode(); | ||
| 289 | + CodeCheckResult result = checkCode(); | ||
| 292 | 290 | ||
| 293 | 291 | if (!JavaMode.errorCheckEnabled) { | |
| 294 | 292 | lastCodeCheckResult.problems.clear(); | |
| 295 | 293 | Messages.log("Error Check disabled, so not updating UI."); | |
| 296 | 294 | } | |
| 297 | 295 | ||
| 298 | - checkForMissingImports(); | ||
| 296 | + lastCodeCheckResult = result; | ||
| 299 | 297 | ||
| 300 | - updateSketchCodeListeners(); | ||
| 298 | + checkForMissingImports(lastCodeCheckResult); | ||
| 301 | 299 | ||
| 302 | 300 | if (JavaMode.errorCheckEnabled) { | |
| 303 | 301 | if (scheduledUiUpdate != null) { | |
@@ -320,7 +318,6 @@ public void run() { | |||
| 320 | 318 | editor.updateErrorBar(result.problems); | |
| 321 | 319 | editor.getTextArea().repaint(); | |
| 322 | 320 | editor.updateErrorToggle(result.containsErrors); | |
| 323 | - updateSketchCodeListeners(); | ||
| 324 | 321 | } | |
| 325 | 322 | }); | |
| 326 | 323 | } | |
@@ -376,35 +373,15 @@ public void request() { | |||
| 376 | 373 | } | |
| 377 | 374 | ||
| 378 | 375 | ||
| 379 | - protected void updateSketchCodeListeners() { | ||
| 380 | - for (SketchCode sc : editor.getSketch().getCode()) { | ||
| 381 | - SyntaxDocument doc = (SyntaxDocument) sc.getDocument(); | ||
| 382 | - if (!hasSketchChangedListener(doc)) { | ||
| 383 | - doc.addDocumentListener(sketchChangedListener); | ||
| 384 | - } | ||
| 385 | - } | ||
| 376 | + public void addListener(Document doc) { | ||
| 377 | + doc.addDocumentListener(sketchChangedListener); | ||
| 386 | 378 | } | |
| 387 | 379 | ||
| 388 | 380 | ||
| 389 | - boolean hasSketchChangedListener(SyntaxDocument doc) { | ||
| 390 | - if (doc != null && doc.getDocumentListeners() != null) { | ||
| 391 | - for (DocumentListener dl : doc.getDocumentListeners()) { | ||
| 392 | - if (dl.equals(sketchChangedListener)) { | ||
| 393 | - return true; | ||
| 394 | - } | ||
| 395 | - } | ||
| 396 | - } | ||
| 397 | - return false; | ||
| 398 | - } | ||
| 399 | - | ||
| 400 | - | ||
| 401 | - protected void checkForMissingImports() { | ||
| 402 | - // Atomic access | ||
| 403 | - CodeCheckResult lastCodeCheckResult = this.lastCodeCheckResult; | ||
| 404 | - | ||
| 381 | + protected void checkForMissingImports(CodeCheckResult result) { | ||
| 405 | 382 | if (Preferences.getBoolean(JavaMode.SUGGEST_IMPORTS_PREF)) { | |
| 406 | - for (Problem p : lastCodeCheckResult.problems) { | ||
| 407 | - if(p.getIProblem().getID() == IProblem.UndefinedType) { | ||
| 383 | + for (Problem p : result.problems) { | ||
| 384 | + if (p.getIProblem().getID() == IProblem.UndefinedType) { | ||
| 408 | 385 | String args[] = p.getIProblem().getArguments(); | |
| 409 | 386 | if (args.length > 0) { | |
| 410 | 387 | String missingClass = args[0]; | |
@@ -424,37 +401,22 @@ public ASTGenerator getASTGenerator() { | |||
| 424 | 401 | } | |
| 425 | 402 | ||
| 426 | 403 | ||
| 427 | - protected SketchChangedListener sketchChangedListener; | ||
| 428 | - protected class SketchChangedListener implements DocumentListener{ | ||
| 429 | - | ||
| 430 | - private SketchChangedListener(){ | ||
| 431 | - } | ||
| 432 | - | ||
| 404 | + protected final DocumentListener sketchChangedListener = new DocumentListener() { | ||
| 433 | 405 | @Override | |
| 434 | 406 | public void insertUpdate(DocumentEvent e) { | |
| 435 | - if (JavaMode.errorCheckEnabled) { | ||
| 436 | - request(); | ||
| 437 | - //log("doc insert update, man error check.."); | ||
| 438 | - } | ||
| 407 | + if (JavaMode.errorCheckEnabled) request(); | ||
| 439 | 408 | } | |
| 440 | 409 | ||
| 441 | 410 | @Override | |
| 442 | 411 | public void removeUpdate(DocumentEvent e) { | |
| 443 | - if (JavaMode.errorCheckEnabled){ | ||
| 444 | - request(); | ||
| 445 | - //log("doc remove update, man error check.."); | ||
| 446 | - } | ||
| 412 | + if (JavaMode.errorCheckEnabled) request(); | ||
| 447 | 413 | } | |
| 448 | 414 | ||
| 449 | 415 | @Override | |
| 450 | 416 | public void changedUpdate(DocumentEvent e) { | |
| 451 | - if (JavaMode.errorCheckEnabled){ | ||
| 452 | - request(); | ||
| 453 | - //log("doc changed update, man error check.."); | ||
| 454 | - } | ||
| 417 | + if (JavaMode.errorCheckEnabled) request(); | ||
| 455 | 418 | } | |
| 456 | - | ||
| 457 | - } | ||
| 419 | + }; | ||
| 458 | 420 | ||
| 459 | 421 | public static class CodeCheckResult { | |
| 460 | 422 | ||
@@ -1556,18 +1518,18 @@ public static String substituteUnicode(String program) { | |||
| 1556 | 1518 | return new String(p2, 0, index); | |
| 1557 | 1519 | } | |
| 1558 | 1520 | ||
| 1521 | + | ||
| 1559 | 1522 | public void handleErrorCheckingToggle() { | |
| 1560 | 1523 | if (!JavaMode.errorCheckEnabled) { | |
| 1561 | - Messages.log(editor.getSketch().getName() + " Error Checker paused."); | ||
| 1562 | - //editor.clearErrorPoints(); | ||
| 1524 | + Messages.log(editor.getSketch().getName() + " Error Checker disabled."); | ||
| 1563 | 1525 | editor.getErrorPoints().clear(); | |
| 1564 | 1526 | lastCodeCheckResult.problems.clear(); | |
| 1565 | 1527 | updateErrorTable(Collections.<Problem>emptyList()); | |
| 1566 | 1528 | updateEditorStatus(); | |
| 1567 | 1529 | editor.getTextArea().repaint(); | |
| 1568 | 1530 | editor.repaintErrorBar(); | |
| 1569 | 1531 | } else { | |
| 1570 | - Messages.log(editor.getSketch().getName() + " Error Checker resumed."); | ||
| 1532 | + Messages.log(editor.getSketch().getName() + " Error Checker enabled."); | ||
| 1571 | 1533 | request(); | |
| 1572 | 1534 | } | |
| 1573 | 1535 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments