diff --git a/pdex/Todo, GSoC 2013.txt b/pdex/Todo, GSoC 2013.txt index 17238b399..75653d4d0 100644 --- a/pdex/Todo, GSoC 2013.txt +++ b/pdex/Todo, GSoC 2013.txt @@ -27,13 +27,13 @@ x! Should I implement wrapper for ASTNode? - possibly needed for code completion x Differentiating between multiple statements on the same line. How to? Done with offset handling. Finer details -*! - Ignore String case while finding completion candidates -* - Multiple 3rd party classes found in various packages +x! - Ignore String case while finding completion candidates +x - Multiple 3rd party classes found in various packages. Not a chance no more. x Obj a1; a1.-> completion doesn't work before it is instantiated. Look into that. Began working again by itself. Yay! * printStuff(int,float,String) - completion endings have to be appropriate. Right now it's just printStuff(,,). Cursor positioning also needs to be taken care of. Argument list as tooltip if possible? x Cursor positioning should be after the first ( if arguments present, else after () -* Display the type of Completion(method return type, variable type) in the popup. - - facing some issues for local types +x Display the type of Completion(method return type, variable type) in the popup. + - facing some issues for local types. Fixed. * Sorted list of completion candidates - fields, then methods. It's unsorted presently. *! p5 enhanced stuff in java, how does it fit in with everything else, and edge cases. Possibly add support for them. Offset handling improvements should help here. * - Diamond opertaor isn't supported for now. Bummer. diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 653a46982..76aa69879 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Stack; import java.util.TreeMap; +import java.util.regex.Pattern; import javax.swing.BorderFactory; import javax.swing.Box; @@ -366,11 +367,7 @@ public class ASTGenerator { List vdfs = null; switch (node.getNodeType()) { case ASTNode.TYPE_DECLARATION: - return new CompletionCandidate[] { new CompletionCandidate( - getNodeAsString2(node), - ((TypeDeclaration) node) - .getName() - .toString()) }; + return new CompletionCandidate[] { new CompletionCandidate((TypeDeclaration) node) }; case ASTNode.METHOD_DECLARATION: MethodDeclaration md = (MethodDeclaration) node; @@ -793,7 +790,7 @@ public class ASTGenerator { CompletionCandidate[] types = checkForTypes(cnode); if (types != null) { for (int i = 0; i < types.length; i++) { - if (types[i].getElementName().startsWith(word2)) + if (types[i].getElementName().toLowerCase().startsWith(word2.toLowerCase())) candidates.add(types[i]); } } @@ -806,7 +803,7 @@ public class ASTGenerator { CompletionCandidate[] types = checkForTypes(clnode); if (types != null) { for (int i = 0; i < types.length; i++) { - if (types[i].getElementName().startsWith(word2)) + if (types[i].getElementName().toLowerCase().startsWith(word2.toLowerCase())) candidates.add(types[i]); } } @@ -815,22 +812,29 @@ public class ASTGenerator { } nearestNode = nearestNode.getParent(); } - if(candidates.isEmpty()){ - // We're seeing a simple name that's not defined locally or in - // the parent class. So most probably a pre-defined type. - System.out.println("Empty can. " + word2); - RegExpResourceFilter regExpResourceFilter; - regExpResourceFilter = new RegExpResourceFilter(".*", word2 + "[a-zA-Z_0-9]*.class"); - String[] resources = classPath.findResources("", regExpResourceFilter); - for (String matchedClass : resources) { - matchedClass = matchedClass.substring(0, - matchedClass.length() - 6); - matchedClass = matchedClass.replace('/', '.'); - int d = matchedClass.lastIndexOf('.'); - matchedClass = matchedClass.substring(d + 1); - candidates.add(new CompletionCandidate(matchedClass)); - //System.out.println("-> " + className); - } + // We're seeing a simple name that's not defined locally or in + // the parent class. So most probably a pre-defined type. + System.out.println("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); + int d = matchedClass.lastIndexOf('.'); + matchedClass = matchedClass.substring(d + 1); + candidates + .add(new CompletionCandidate(matchedClass, matchedClass + " : " + + matchedClass2.substring(0, d), matchedClass, + CompletionCandidate.PREDEF_CLASS)); + //System.out.println("-> " + className); } } else { diff --git a/pdex/src/processing/mode/experimental/CompletionCandidate.java b/pdex/src/processing/mode/experimental/CompletionCandidate.java index 8dab29c6b..6fed141c1 100644 --- a/pdex/src/processing/mode/experimental/CompletionCandidate.java +++ b/pdex/src/processing/mode/experimental/CompletionCandidate.java @@ -7,12 +7,11 @@ import java.util.List; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; public class CompletionCandidate implements Comparable{ - private String definingClass; - private String elementName; // private String label; // the toString value @@ -21,27 +20,28 @@ public class CompletionCandidate implements Comparable{ private int type; - public static final int METHOD = 0, FIELD = 1, LOCAL_VAR = 3; + public static final int PREDEF_CLASS = 0, PREDEF_FIELD = 1, + PREDEF_METHOD = 2, LOCAL_CLASS = 3, LOCAL_METHOD = 4, LOCAL_FIELD = 5, + LOCAL_VAR = 6; - public CompletionCandidate(String name, String className, String label, - int TYPE) { - definingClass = className; - elementName = name; - if (label.length() > 0) - this.label = label; - else - this.label = name; - this.type = TYPE; - if (type == METHOD) { - this.label += "()"; - } - completionString = this.label; - } +// public CompletionCandidate(String name, String className, String label, +// int TYPE) { +// elementName = name; +// if (label.length() > 0) +// this.label = label; +// else +// this.label = name; +// this.type = TYPE; +// if (type == LOCAL_METHOD) { +// this.label += "()"; +// } +// completionString = this.label; +// } public CompletionCandidate(Method method) { - definingClass = method.getDeclaringClass().getName(); + method.getDeclaringClass().getName(); elementName = method.getName(); - type = METHOD; + type = LOCAL_METHOD; StringBuffer label = new StringBuffer(method.getName() + "("); StringBuffer cstr = new StringBuffer(method.getName() + "("); for (int i = 0; i < method.getParameterTypes().length; i++) { @@ -59,13 +59,14 @@ public class CompletionCandidate implements Comparable{ cstr.append(")"); this.label = label.toString(); this.completionString = cstr.toString(); + type = PREDEF_METHOD; } public CompletionCandidate(SingleVariableDeclaration svd) { completionString = svd.getName().toString(); elementName = svd.getName().toString(); type = LOCAL_VAR; - label = svd.getName() + " : " + svd.getType(); + label = svd.getName() + " : " + svd.getType(); } public CompletionCandidate(VariableDeclarationFragment vdf) { @@ -77,9 +78,8 @@ public class CompletionCandidate implements Comparable{ public CompletionCandidate(MethodDeclaration method) { System.out.println("ComCan " + method.getName()); - definingClass = ""; elementName = method.getName().toString(); - type = METHOD; + type = LOCAL_METHOD; List params = (List) method .getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY); StringBuffer label = new StringBuffer(elementName + "("); @@ -100,31 +100,34 @@ public class CompletionCandidate implements Comparable{ this.label = label.toString(); this.completionString = cstr.toString(); } + + public CompletionCandidate(TypeDeclaration td){ + type = LOCAL_CLASS; + elementName = td.getName().toString(); + label = elementName; + completionString = elementName; + } public CompletionCandidate(Field f) { - definingClass = f.getDeclaringClass().getName(); + f.getDeclaringClass().getName(); elementName = f.getName(); - type = FIELD; + type = PREDEF_FIELD; label = f.getName() + " : " + f.getType().getSimpleName(); completionString = elementName; } - public CompletionCandidate(String name, String className) { - definingClass = className; + public CompletionCandidate(String name, String labelStr, String completionStr, int type) { + elementName = name; + label = labelStr; + completionString = completionStr; + this.type = type; + } + + public CompletionCandidate(String name, int type) { elementName = name; label = name; completionString = name; - } - - public CompletionCandidate(String name) { - definingClass = ""; - elementName = name; - label = name; - completionString = name; - } - - public String getDefiningClass() { - return definingClass; + this.type = type; } public String getElementName() { diff --git a/pdex/src/processing/mode/experimental/CompletionPanel.java b/pdex/src/processing/mode/experimental/CompletionPanel.java index b3e4fe363..9f6d5d6b6 100644 --- a/pdex/src/processing/mode/experimental/CompletionPanel.java +++ b/pdex/src/processing/mode/experimental/CompletionPanel.java @@ -105,8 +105,10 @@ public class CompletionPanel { String selectedSuggestion = ((CompletionCandidate) completionList .getSelectedValue()).getCompletionString().substring(subWord.length()); System.err.println(subWord+" <= subword,Inserting suggestion=> " + selectedSuggestion); - textarea.getDocument().insertString(insertionPosition, - selectedSuggestion, null); + textarea.getDocument().remove(insertionPosition-subWord.length(), subWord.length()); + textarea.getDocument().insertString(insertionPosition-subWord.length(), + ((CompletionCandidate) completionList + .getSelectedValue()).getCompletionString(), null); if(selectedSuggestion.endsWith(")")) { if(!selectedSuggestion.endsWith("()")){