mirror of
https://github.com/processing/processing4.git
synced 2026-02-26 08:44:39 +01:00
improved completion sorting, fixes to ignore case completion
This commit is contained in:
@@ -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<VariableDeclarationFragment> 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 {
|
||||
|
||||
@@ -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<CompletionCandidate>{
|
||||
|
||||
private String definingClass;
|
||||
|
||||
private String elementName; //
|
||||
|
||||
private String label; // the toString value
|
||||
@@ -21,27 +20,28 @@ public class CompletionCandidate implements Comparable<CompletionCandidate>{
|
||||
|
||||
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<CompletionCandidate>{
|
||||
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<CompletionCandidate>{
|
||||
|
||||
public CompletionCandidate(MethodDeclaration method) {
|
||||
System.out.println("ComCan " + method.getName());
|
||||
definingClass = "";
|
||||
elementName = method.getName().toString();
|
||||
type = METHOD;
|
||||
type = LOCAL_METHOD;
|
||||
List<ASTNode> params = (List<ASTNode>) method
|
||||
.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
|
||||
StringBuffer label = new StringBuffer(elementName + "(");
|
||||
@@ -100,31 +100,34 @@ public class CompletionCandidate implements Comparable<CompletionCandidate>{
|
||||
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() {
|
||||
|
||||
@@ -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("()")){
|
||||
|
||||
Reference in New Issue
Block a user