From a21ae3bc2c0309eb138bc586ee22a22a7b1b27ac Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Fri, 6 Jun 2014 01:30:29 +0530 Subject: [PATCH] A possible solution to #68 --- .../mode/experimental/ASTGenerator.java | 4 +- .../experimental/ErrorCheckerService.java | 43 +++++++++++++++---- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 141c3888c..641578757 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -899,11 +899,11 @@ public class ASTGenerator { } // find nearest ASTNode - nearestNode = findClosestNode(lineNumber, (ASTNode) compilationUnit.types() + nearestNode = findClosestNode(lineNumber, (ASTNode) errorCheckerService.getLastCorrectCU().types() .get(0)); if (nearestNode == null) { // Make sure nearestNode is not NULL if couldn't find a closeset node - nearestNode = (ASTNode) compilationUnit.types().get(0); + nearestNode = (ASTNode) errorCheckerService.getLastCorrectCU().types().get(0); } logE(lineNumber + " Nearest ASTNode to PRED " + getNodeAsString(nearestNode)); diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 757be96ca..181d02dab 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -135,7 +135,17 @@ public class ErrorCheckerService implements Runnable{ /** * Compilation Unit for current sketch */ - protected CompilationUnit cu, lastCorrectCu; + protected CompilationUnit cu; + + /** + * The Compilation Unit generated during compile check + */ + protected CompilationUnit compileCheckCU; + + /** + * This Compilation Unit points to the last error free CU + */ + protected CompilationUnit lastCorrectCU; /** * If true, compilation checker will be reloaded with updated classpath @@ -431,6 +441,9 @@ public class ErrorCheckerService implements Runnable{ // No syntax errors, proceed for compilation check, Stage 2. //if(hasSyntaxErrors()) astGenerator.buildAST(null); + if (!hasSyntaxErrors()) { + + } if (problems.length == 0 && editor.compilationCheckEnabled) { //mainClassOffset++; // just a hack. @@ -535,10 +548,11 @@ public class ErrorCheckerService implements Runnable{ if (problems.length == 0) { syntaxErrors.set(false); containsErrors.set(false); - lastCorrectCu = cu; + parser.setSource(sourceCode.toCharArray()); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setCompilerOptions(options); + lastCorrectCU = (CompilationUnit) parser.createAST(null); } else { - CompilationUnit cuTemp = null; - lastCorrectCu = cuTemp; syntaxErrors.set(true); containsErrors.set(true); } @@ -563,14 +577,17 @@ public class ErrorCheckerService implements Runnable{ options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); - if (cu == null) - cu = (CompilationUnit) parser.createAST(null); + if (compileCheckCU == null) + compileCheckCU = (CompilationUnit) parser.createAST(null); else { - synchronized (cu) { - if (!hasSyntaxErrors()) - cu = (CompilationUnit) parser.createAST(null); + synchronized (compileCheckCU) { + compileCheckCU = (CompilationUnit) parser.createAST(null); } } + if(!hasSyntaxErrors()) + lastCorrectCU = compileCheckCU; + cu = compileCheckCU; + compilationUnitState = 2; // Currently (Sept, 2012) I'm using Java's reflection api to load the // CompilationChecker class(from CompilationChecker.jar) that houses the @@ -722,6 +739,14 @@ public class ErrorCheckerService implements Runnable{ // log("Compilecheck, Done."); } + public CompilationUnit getLastCorrectCU(){ + return lastCorrectCU; + } + + public CompilationUnit getLatestCU(){ + return compileCheckCU; + } + private int loadClassCounter = 0; public URLClassLoader getSketchClassLoader() { loadClassCounter++;