diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index ebda1f9ea..141c3888c 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -240,7 +240,7 @@ public class ASTGenerator { /** * Toggle AST View window */ - public static final boolean SHOWAST = !true; + public static final boolean SHOWAST = true; protected DefaultMutableTreeNode buildAST(String source, CompilationUnit cu) { if (cu == null) { @@ -794,6 +794,13 @@ public class ASTGenerator { private AtomicBoolean predictionOngoing; + /** + * The main function that calculates possible code completion candidates + * + * @param word + * @param line + * @param lineStartNonWSOffset + */ public void preparePredictions(final String word, final int line, final int lineStartNonWSOffset) { if(predictionOngoing.get()) return; @@ -890,11 +897,14 @@ public class ASTGenerator { MethodInvocation mi = (MethodInvocation)testnode; System.out.println(mi.getName() + "," + mi.getExpression() + "," + mi.typeArguments().size()); } + + // find nearest ASTNode nearestNode = findClosestNode(lineNumber, (ASTNode) compilationUnit.types() .get(0)); - if (nearestNode == null) - //Make sure nearestNode is not NULL if couldn't find a closeset node + if (nearestNode == null) { + // Make sure nearestNode is not NULL if couldn't find a closeset node nearestNode = (ASTNode) compilationUnit.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 92948c09a..e4885a37f 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -36,11 +36,9 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.swing.JCheckBoxMenuItem; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; -import javax.swing.text.AbstractDocument; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.IProblem; @@ -137,7 +135,7 @@ public class ErrorCheckerService implements Runnable{ /** * Compilation Unit for current sketch */ - protected CompilationUnit cu; + protected CompilationUnit cu, lastCorrectCu; /** * If true, compilation checker will be reloaded with updated classpath @@ -537,7 +535,10 @@ public class ErrorCheckerService implements Runnable{ if (problems.length == 0) { syntaxErrors.set(false); containsErrors.set(false); + lastCorrectCu = cu; } else { + CompilationUnit cuTemp = null; + lastCorrectCu = cuTemp; syntaxErrors.set(true); containsErrors.set(true); } @@ -548,7 +549,8 @@ public class ErrorCheckerService implements Runnable{ protected void compileCheck() { - // CU needs to be updated coz before compileCheck xqpreprocessor is run on the source code which makes some further changes + // CU needs to be updated coz before compileCheck xqpreprocessor is run on + // the source code which makes some further changes //TODO Check if this breaks things parser.setSource(sourceCode.toCharArray()); @@ -565,6 +567,7 @@ public class ErrorCheckerService implements Runnable{ cu = (CompilationUnit) parser.createAST(null); else { synchronized (cu) { + if (!hasSyntaxErrors()) cu = (CompilationUnit) parser.createAST(null); } }