From e307fed1b5296d979b174cd354db921ab65c6b24 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sun, 18 Aug 2013 18:05:04 +0530 Subject: [PATCH] these tiny tiny bugs.. grr --- .../mode/experimental/ASTGenerator.java | 65 ++++++++++--------- .../experimental/ErrorCheckerService.java | 6 +- .../mode/experimental/TextArea.java | 2 + 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 9302e910e..3ca76702d 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -250,6 +250,10 @@ public class ASTGenerator { getCodeComments(); codeTree = new DefaultMutableTreeNode(new ASTNodeWrapper((ASTNode) compilationUnit .types().get(0))); + log("Total CU " + compilationUnit.types().size()); + if(compilationUnit.types() == null || compilationUnit.types().isEmpty()){ + logE("No CU found!"); + } visitRecur((ASTNode) compilationUnit.types().get(0), codeTree); SwingWorker worker = new SwingWorker() { @@ -352,6 +356,7 @@ public class ASTGenerator { // } classPath = factory.createFromPath(tehPath.toString()); + log("Classpath created " + (classPath != null)); // for (String packageName : classPath.listPackages("")) { // log(packageName); // } @@ -916,30 +921,32 @@ public class ASTGenerator { // We're seeing a simple name that's not defined locally or in // the parent class. So most probably a pre-defined type. log("Empty can. " + word2); - RegExpResourceFilter regExpResourceFilter; - regExpResourceFilter = new RegExpResourceFilter( - Pattern.compile(".*"), - Pattern - .compile(word2 - + "[a-zA-Z_0-9]*.class", - Pattern.CASE_INSENSITIVE)); - String[] resources = classPath - .findResources("", regExpResourceFilter); - for (String matchedClass2 : resources) { - matchedClass2 = matchedClass2.replace('/', '.'); - String matchedClass = matchedClass2.substring(0, matchedClass2 - .length() - 6); - if(ignorableImport(matchedClass2)) - continue; - int d = matchedClass.lastIndexOf('.'); - matchedClass = matchedClass.substring(d + 1); - candidates - .add(new CompletionCandidate(matchedClass, matchedClass + " : " - + matchedClass2.substring(0, d), matchedClass, - CompletionCandidate.PREDEF_CLASS)); - //log("-> " + className); + if (classPath != null) { + RegExpResourceFilter regExpResourceFilter; + regExpResourceFilter = new RegExpResourceFilter( + Pattern + .compile(".*"), + Pattern + .compile(word2 + + "[a-zA-Z_0-9]*.class", + Pattern.CASE_INSENSITIVE)); + String[] resources = classPath.findResources("", + regExpResourceFilter); + for (String matchedClass2 : resources) { + matchedClass2 = matchedClass2.replace('/', '.'); + String matchedClass = matchedClass2.substring(0, matchedClass2 + .length() - 6); + if (ignorableImport(matchedClass2)) + continue; + int d = matchedClass.lastIndexOf('.'); + matchedClass = matchedClass.substring(d + 1); + candidates + .add(new CompletionCandidate(matchedClass, matchedClass + + " : " + matchedClass2.substring(0, d), matchedClass, + CompletionCandidate.PREDEF_CLASS)); + //log("-> " + className); + } } - } else { // ==> Complex expression of type blah.blah2().doIt,etc @@ -1366,7 +1373,6 @@ public class ASTGenerator { return node; } - @SuppressWarnings("unchecked") private static ASTNode findClosestNode(int lineNumber, ASTNode node) { ASTNode parent = findClosestParentNode(lineNumber, node); if (parent == null) @@ -1387,14 +1393,15 @@ public class ASTGenerator { } if (nodes.size() > 0) { - ASTNode retNode = nodes.get(0); - for (ASTNode cNode : nodes) { - if (getLineNumber(cNode) <= lineNumber + ASTNode retNode = parent; + for (int i = nodes.size() - 1; i >= 0; i--) { + ASTNode cNode = nodes.get(i); + if (getLineNumber(cNode) == lineNumber) + return cNode; + else if (getLineNumber(cNode) <= lineNumber && lineNumber <= getLineNumber(cNode, cNode.getStartPosition() + cNode.getLength())) retNode = cNode; - else - break; } return retNode; diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 2a446997c..f13cd237b 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -306,10 +306,11 @@ public class ErrorCheckerService implements Runnable{ log(editor.getSketch().getName() + "1 MCO " + mainClassOffset); // No syntax errors, proceed for compilation check, Stage 2. - + + astGenerator.buildAST(cu); if (problems.length == 0 && editor.compilationCheckEnabled) { //mainClassOffset++; // just a hack. - astGenerator.buildAST(cu); + sourceCode = xqpreproc.doYourThing(sourceCode, programImports); prepareCompilerClasspath(); // mainClassOffset = xqpreproc.mainClassOffset; // tiny, but @@ -392,6 +393,7 @@ public class ErrorCheckerService implements Runnable{ syntaxErrors.set(false); else syntaxErrors.set(true); + astGenerator.loadJars(); } protected URLClassLoader classLoader; private void compileCheck() { diff --git a/pdex/src/processing/mode/experimental/TextArea.java b/pdex/src/processing/mode/experimental/TextArea.java index 35c3378ae..00e1282d5 100644 --- a/pdex/src/processing/mode/experimental/TextArea.java +++ b/pdex/src/processing/mode/experimental/TextArea.java @@ -294,6 +294,7 @@ public class TextArea extends JEditTextArea { word = word.trim(); if (word.endsWith(".")) word = word.substring(0, word.length() - 1); + if(word.length() > 1) errorCheckerService.astGenerator.preparePredictions(word, line + errorCheckerService.mainClassOffset,0); return word; @@ -371,6 +372,7 @@ public class TextArea extends JEditTextArea { // if (word.endsWith(".")) // word = word.substring(0, word.length() - 1); int lineStartNonWSOffset = 0; + if(word.length() > 1) errorCheckerService.astGenerator.preparePredictions(word, line + errorCheckerService.mainClassOffset,lineStartNonWSOffset); //showSuggestionLater();