fixed bug in parsing imports with auto completion

This commit is contained in:
Manindra Moharana
2016-02-15 01:55:57 -08:00
parent b6f067484c
commit d3a0e98fd3
2 changed files with 39 additions and 6 deletions

View File

@@ -1296,8 +1296,16 @@ public class ASTGenerator {
for (ImportStatement impS : imports) {
String temp = impS.getPackageName();
if (impS.isStarredImport() && className.indexOf('.') == -1) {
temp = impS.getPackageName() + "." + className;
if (impS.isStarredImport()) { // case of starred import: pkg.foo.*
if (className.indexOf('.') == -1) {
temp = impS.getPackageName() + "." + className;
} else {
continue;
}
} else { // case of class import: pkg.foo.MyClass
if (!impS.getImportedClassName().equals(className)) {
continue;
}
}
tehClass = loadClass(temp);
if (tehClass != null) {
@@ -1309,8 +1317,16 @@ public class ASTGenerator {
for (ImportStatement impS : errorCheckerService.codeFolderImports) {
String temp = impS.getPackageName();
if (impS.isStarredImport() && className.indexOf('.') == -1) {
temp = impS.getPackageName() + "." + className;
if (impS.isStarredImport()) { // case of starred import: pkg.foo.*
if (className.indexOf('.') == -1) {
temp = impS.getPackageName() + "." + className;
} else {
continue;
}
} else { // case of class import: pkg.foo.MyClass
if (!impS.getImportedClassName().equals(className)) {
continue;
}
}
tehClass = loadClass(temp);
if (tehClass != null) {

View File

@@ -78,9 +78,26 @@ public class ImportStatement {
}
public boolean isStarredImport() {
String ret = new String(importName.trim());
if(ret.endsWith(";"))
String ret = importName.trim();
if(ret.endsWith(";")) {
ret = ret.substring(0, ret.length() - 1).trim();
}
return ret.endsWith(".*");
}
public String getImportedClassName() {
if (isStarredImport()) {
return null;
} else {
String ret = importName.trim();
if(ret.endsWith(";")) {
ret = ret.substring(0, ret.length() - 1).trim();
}
if (ret.lastIndexOf('.') != -1) {
return ret.substring(ret.lastIndexOf('.') + 1);
} else {
return null;
}
}
}
}