blnCurrentListEmpty=false;
while (iter.hasNext())
{
final PersistentArrayMap entry=(PersistentArrayMap)iter.next();
//final String entry=(String)iter.next();
if ((blnCurrentListEmpty) && (!gettingMethods))
CurrentList.add(entry);
String displaystr=(String)entry.get(Keyword.intern(Symbol.create("display")));
String fullclassstr=(String)entry.get(Keyword.intern(Symbol.create("fullclassname")));
Boolean isClojure= (Boolean)entry.get(Keyword.intern(Symbol.create("isclojure")));
Boolean isNamespaceOrPackage= (Boolean)entry.get(Keyword.intern(Symbol.create("isnamespaceorpkg")));
Boolean isMethodOrFunction= (Boolean)entry.get(Keyword.intern(Symbol.create("ismethodorfunction")));
Boolean isConstructor= (Boolean)entry.get(Keyword.intern(Symbol.create("isconstructor")));
String namespace=(String)entry.get(Keyword.intern(Symbol.create("namespace")));
String method=(String)entry.get(Keyword.intern(Symbol.create("method")));
Integer priority=(Integer)entry.get(Keyword.intern(Symbol.create("priority")));
pInfo.put("display", handleNullString(displaystr));
pInfo.put("fullclassname", handleNullString(fullclassstr));
pInfo.put("isClojure", isClojure);
pInfo.put("isNamespaceOrPackage",isNamespaceOrPackage);
pInfo.put("isMethodOrFunction", isMethodOrFunction);
pInfo.put("namespace",handleNullString(namespace));
pInfo.put("method",handleNullString(method));
pInfo.put("priority",handleNullInteger(priority));
pInfo.put("isConstructor", handleNullBoolean(isConstructor));
if (isClojure)
pInfo.put("source", "Clojure");
else
pInfo.put("source", "Java");
String origFilter=(String)pInfo.get("origFilter");
int layout=(Integer)pInfo.get("layout");
if (addFilter)
{
if (isMethodOrFunction && (!isClojure)) //if this is a java method
{
if ((filter != null) && (displaystr.startsWith(filter.trim())))
completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr,begLine,caretOffset,pInfo));
}
else
{
if (layout != backSlashAfterParen && layout != backSlashNoParen)
{
if (isNamespaceOrPackage)
{
if ((filter != null) && (displaystr.contains(origFilter.trim())))
completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr,begLine,caretOffset,pInfo));
}
else
{
if ((filter != null) && (displaystr.contains(filter.trim())))
completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr,begLine,caretOffset,pInfo));
}
}
else
{
if ((filter != null) && (displaystr.startsWith(filter.trim())))
completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr,begLine,caretOffset,pInfo));
}
}
}
else
completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr,begLine,caretOffset,pInfo));
}
}
private int getLayout(String filter, boolean isDotPressed)
{
//private static final int LowercaseAfterParen = 0;
//private static final int UppercaseAfterParen = 1;
//private static final int LowercaseAfterParenWithDot = 2;
//private static final int UppercaseAfterParenWithDot = 3;
//private static final int LowercaseNoParen = 4;
//private static final int UppercaseNoParen = 5;
//private static final int LowercaseNoParenWithDot = 6;
//private static final int UppercaseNoParenWithDot = 7;
//private static final int FirstDotAfterParen = 8;
//private static final int FirstDotNoParen = 9;
try{
if (filter.startsWith("("))
{
filter=filter.substring(1);
if (backSlashPressed(filter))
{
if ((filter != null) && (filter.trim().length() > 0))
return backSlashAfterParen;
else return -1;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt(0)))
{
return UppercaseAfterParenWithDot;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && (filter.trim().charAt(0)=='.'))
{
//a dot was pressed first
//get all java methods available
return FirstDotAfterParen;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isLowerCase(filter.trim().charAt((0))))
return LowercaseAfterParenWithDot;
else
{
if ((filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt((0))))
return UppercaseAfterParen;
else //lowercase
return LowercaseAfterParen;
}
}
}
}
}
else //No Paren
{
if (backSlashPressed(filter))
{
if ((filter != null) && (filter.trim().length() > 0))
return backSlashNoParen;
else return -1;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt(0)))
{
return UppercaseNoParenWithDot;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && (filter.trim().charAt(0)=='.'))
{
return FirstDotNoParen;
}
else
{
if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isLowerCase(filter.trim().charAt((0))))
return LowercaseNoParenWithDot;
else
{
if ((filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt((0))))
return UppercaseNoParen;
else //lowercase
return LowercaseNoParen;
}
}
}
}
}
}
catch (Exception ex)
{Exceptions.printStackTrace(ex);}
return -1;
}
private Iterator processLayout(Hashtable processInfo)
{
//private static final int LowercaseAfterParen = 0;
//private static final int UppercaseAfterParen = 1;
//private static final int LowercaseAfterParenWithDot = 2;
//private static final int UppercaseAfterParenWithDot = 3;
//private static final int LowercaseNoParen = 4;
//private static final int UppercaseNoParen = 5;
//private static final int LowercaseNoParenWithDot = 6;
//private static final int UppercaseNoParenWithDot = 7;
//private static final int FirstDotAfterParen = 8;
//private static final int FirstDotNoParen = 9;
int layout=(Integer)processInfo.get("layout");
String filter=(String)processInfo.get("filter");
String begFilter;
String origFilter="";
int begLine=(Integer)processInfo.get("begLine");
int dotpos;
Iterator iter=null;
try
{
filter=filter.trim();
switch(layout) {
case LowercaseAfterParen:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
addFilter=true;
iter=getResultsForScenario2(filter);
begLine=begLine +1;
break;
case UppercaseAfterParen:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
addFilter=true;
iter=getResultsForScenario2(filter);
begLine=begLine +1;
break;
case LowercaseAfterParenWithDot:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
dotpos=filter.lastIndexOf(".");
begFilter=filter.substring(0,dotpos);
addFilter=true;
//iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + "."); //check java classes
iter=getResultsForScenario1(getClsForFilter(begFilter),origFilter); //check java classes
//iter=getAllClojureNamespaces1(origFilter);
filter=filter.substring(dotpos+1);
//filter=origFilter;
begLine=begLine + 1;
break;
case UppercaseAfterParenWithDot:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
dotpos=filter.lastIndexOf(".");
begFilter=filter.substring(0,dotpos);
addFilter=true;
//iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + "."); //check java classes
iter=getResultsForScenario1(getClsForFilter(begFilter),origFilter ); //check java classes
filter=filter.substring(dotpos+1);
//filter=origFilter;
begLine=begLine + 1;
break;
case backSlashAfterParen:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
dotpos=filter.lastIndexOf("/");
begFilter=filter.substring(0,dotpos);
addFilter=true;
iter=getResultsForScenario3(getClsForFilter(begFilter),begFilter);
filter=filter.substring(dotpos+1);
begLine=begLine +1;
break;
case FirstDotAfterParen:
filter=filter.substring(1); //remove the paranthesis
origFilter=filter;
addFilter=true;
if (filter.equalsIgnoreCase("."))
filter="";
else
{
dotpos=filter.lastIndexOf(".");
filter=filter.substring(dotpos+1);
}
iter=getResultsForScenario4();
begLine=begLine +2;
break;
case UppercaseNoParen:
origFilter=filter;
addFilter=true;
iter=getResultsForScenario2(filter);
break;
case UppercaseNoParenWithDot:
origFilter=filter;
dotpos=filter.lastIndexOf(".");
begFilter=filter.substring(0,dotpos);
addFilter=true;
//iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + "."); //check java classes
iter=getResultsForScenario1(getClsForFilter(begFilter),origFilter); //check java classes
filter=filter.substring(dotpos+1);
//filter=origFilter;
break;
case FirstDotNoParen:
origFilter=filter;
addFilter=true;
if (filter.equalsIgnoreCase("."))
filter="";
else
{
dotpos=filter.lastIndexOf(".");
filter=filter.substring(dotpos+1);
}
iter=getResultsForScenario4();
begLine=begLine +1;
break;
case LowercaseNoParenWithDot:
origFilter=filter;
dotpos=filter.lastIndexOf(".");
begFilter=filter.substring(0,dotpos);
addFilter=true;
//iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + "."); //check java classes
iter=getResultsForScenario1(getClsForFilter(begFilter),origFilter); //check java classes
filter=filter.substring(dotpos+1);
//filter=origFilter;
break;
case LowercaseNoParen:
origFilter=filter;
addFilter=true;
iter=getResultsForScenario2(filter);
break;
case backSlashNoParen:
origFilter=filter;
dotpos=filter.lastIndexOf("/");
begFilter=filter.substring(0,dotpos);
addFilter=true;
iter=getResultsForScenario3(getClsForFilter(begFilter),begFilter);
filter=filter.substring(dotpos+1);
break;
}
processInfo.put("layout",layout);
processInfo.put("filter", filter);
processInfo.put("begLine", begLine);
processInfo.put("isClojure",isClojure);
processInfo.put("origFilter", origFilter);
return iter;
}
catch (Exception ex)
{
Exceptions.printStackTrace(ex);
}
return iter;
}
private Iterator getiterator()
{
try {
return ((Iterable)getnamesfn.invoke(Symbol.create("clojure.core"))).iterator();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
private Iterator getclojureiterator()
{
try {
return ((Iterable)getclojurenamesfn.invoke(Symbol.create("clojure.core"))).iterator();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
private Iterator getclojurefunctionsforns(String nspart)
{
try {
java.lang.Object iter=(getclojurefunctionsfornsfn.invoke(nspart));
if (iter !=null)
return ((Iterable)iter).iterator();
//return ((Iterable)getclojurefunctionsfornsfn.invoke(nspart)).iterator();
else
return null;
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getJavaMethods(String classname)
{
try {
return ((Iterable)getjavamethodsfn.invoke(Class.forName(classname))).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getStaticJavaMethods(String classname)
{
try {
return ((Iterable)getstaticjavamethodsfn.invoke(Class.forName(classname))).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllJavaMethods()
{
try {
return ((Iterable)getalljavamethodsfn.invoke(Symbol.create("clojure.core"))).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllJavaInstanceMethods(String classname)
{
try {
return ((Iterable)getalljavainstancemethodsfn.invoke(Class.forName(classname))).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllClojureNamespaces1(String filter)
{
try {
return ((Iterable)getallclojurenamespaces1fn.invoke(1)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getResultsForScenario1(String classname,String filter)
{
try {
gettingMethods=false;
if (ctype==CompletionProvider.COMPLETION_ALL_QUERY_TYPE)
{
completionResultSet.setHasAdditionalItems(true);
getExtLibs=true;
}
else
{
completionResultSet.setHasAdditionalItems(false);
getExtLibs=false;
}
Project proj=ReplTopComponent.GetProjectFromDocument(document);
if (!getExtLibs)
{
proj=null;
CurrentList=Scenario1List;
}
else
CurrentList=Scenario1ListExtLib;
int listSize = CurrentList.size();
if (classname==null)
{
if (listSize > 0)
return CurrentList.iterator();
else
return ((Iterable)getresultsforscenario1fn.invoke(proj,jTextComponent,null,filter)).iterator();
}
else
{
gettingMethods=true;
return ((Iterable)getresultsforscenario1fn.invoke(proj,jTextComponent,Class.forName(classname),filter)).iterator();
}
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getResultsForScenario2(String filter)
{
try {
gettingMethods=false;
if (ctype==CompletionProvider.COMPLETION_ALL_QUERY_TYPE)
{
completionResultSet.setHasAdditionalItems(true);
getExtLibs=true;
}
else
{
completionResultSet.setHasAdditionalItems(false);
getExtLibs=false;
}
Project proj=ReplTopComponent.GetProjectFromDocument(document);
if (!getExtLibs)
{
proj=null;
CurrentList=Scenario2List;
}
else
CurrentList=Scenario2ListExtLib;
int listSize = CurrentList.size();
if (listSize > 0)
return CurrentList.iterator();
else
return ((Iterable)getresultsforscenario2fn.invoke(proj,jTextComponent,Symbol.create("clojure.core"),filter)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getResultsForScenario3(String classname,String filter)
{
try {
gettingMethods=false;
CurrentList=Scenario3List;
if (classname==null)
{
gettingMethods=true;
return ((Iterable)getresultsforscenario3fn.invoke(null,filter)).iterator();
}
else
{
gettingMethods=true;
return ((Iterable)getresultsforscenario3fn.invoke(Class.forName(classname),filter)).iterator();
}
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getResultsForScenario4()
{
try {
gettingMethods=false;
if (ctype==CompletionProvider.COMPLETION_ALL_QUERY_TYPE)
{
completionResultSet.setHasAdditionalItems(true);
getExtLibs=true;
}
else
{
completionResultSet.setHasAdditionalItems(false);
getExtLibs=false;
}
Project proj=ReplTopComponent.GetProjectFromDocument(document);
if (!getExtLibs)
{
proj=null;
CurrentList=Scenario4List;
}
else
CurrentList=Scenario4List;
int listSize = CurrentList.size();
if (listSize > 0)
return CurrentList.iterator();
else
return ((Iterable)getresultsforscenario4fn.invoke(proj)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllJavaClasses()
{
try {
return ((Iterable)getalljavaclassesfn.invoke(jTextComponent)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllJavaClasses(String filter)
{
try {
return ((Iterable)getalljavaclassesbyfilterfn.invoke(jTextComponent,filter)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getAllClojureNamespaces(String filter)
{
try {
return ((Iterable)getallclojurenamespacesfn.invoke(jTextComponent,filter)).iterator();
} catch (Exception ex) {
//Exceptions.printStackTrace(ex);
return null;
}
}
private Iterator getFullJavaClasses()
{
try {
return ((Iterable)getfulljavaclassesfn.invoke(Symbol.create("clojure.core"))).iterator();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
private Iterator getEnclosingFormMap(JTextComponent jTextComponent)
{
try {
return ((Iterable)selectcurrentformfn.invoke(jTextComponent)).iterator();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
private String getClsForFilter(String filterstr)
{
Iterator iter;
iter=getAllJavaClasses();
if (iter!=null)
{
while (iter.hasNext())
{
final String entry=(String)iter.next();
if ((entry.endsWith("." + filterstr)) || (entry.equals(filterstr)))
return entry;
}
return null;
}
else
return null;
}
private boolean containsFilter(Iterator iter,String filter)
{
try {
if (iter!=null)
{
while (iter.hasNext())
{
final String entry=(String)iter.next();
if ((filter != null) && (entry.startsWith(filter)))
return true;
}
}
return false;