FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fixed bug in parsing imports with auto completion · luk92/processing@344dcb3 · GitHub

Repository navigation

Commit 344dcb3

Browse files
committed
fixed bug in parsing imports with auto completion
1 parent cb7e08d commit 344dcb3

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎java/src/processing/mode/java/pdex/ASTGenerator.java‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,16 @@ protected Class<?> findClassIfExists(String className){
12961296

12971297
for (ImportStatement impS : imports) {
12981298
String temp = impS.getPackageName();
1299-
if (impS.isStarredImport() && className.indexOf('.') == -1) {
1300-
temp = impS.getPackageName() + "." + className;
1299+
if (impS.isStarredImport()) { // case of starred import: pkg.foo.*
1300+
if (className.indexOf('.') == -1) {
1301+
temp = impS.getPackageName() + "." + className;
1302+
} else {
1303+
continue;
1304+
}
1305+
} else { // case of class import: pkg.foo.MyClass
1306+
if (!impS.getImportedClassName().equals(className)) {
1307+
continue;
1308+
}
13011309
}
13021310
tehClass = loadClass(temp);
13031311
if (tehClass != null) {
@@ -1309,8 +1317,16 @@ protected Class<?> findClassIfExists(String className){
13091317

13101318
for (ImportStatement impS : errorCheckerService.codeFolderImports) {
13111319
String temp = impS.getPackageName();
1312-
if (impS.isStarredImport() && className.indexOf('.') == -1) {
1313-
temp = impS.getPackageName() + "." + className;
1320+
if (impS.isStarredImport()) { // case of starred import: pkg.foo.*
1321+
if (className.indexOf('.') == -1) {
1322+
temp = impS.getPackageName() + "." + className;
1323+
} else {
1324+
continue;
1325+
}
1326+
} else { // case of class import: pkg.foo.MyClass
1327+
if (!impS.getImportedClassName().equals(className)) {
1328+
continue;
1329+
}
13141330
}
13151331
tehClass = loadClass(temp);
13161332
if (tehClass != null) {

‎java/src/processing/mode/java/pdex/ImportStatement.java‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,26 @@ public int getLineNumber() {
7878
}
7979

8080
public boolean isStarredImport() {
81-
String ret = new String(importName.trim());
82-
if(ret.endsWith(";"))
81+
String ret = importName.trim();
82+
if(ret.endsWith(";")) {
8383
ret = ret.substring(0, ret.length() - 1).trim();
84+
}
8485
return ret.endsWith(".*");
8586
}
87+
88+
public String getImportedClassName() {
89+
if (isStarredImport()) {
90+
return null;
91+
} else {
92+
String ret = importName.trim();
93+
if(ret.endsWith(";")) {
94+
ret = ret.substring(0, ret.length() - 1).trim();
95+
}
96+
if (ret.lastIndexOf('.') != -1) {
97+
return ret.substring(ret.lastIndexOf('.') + 1);
98+
} else {
99+
return null;
100+
}
101+
}
102+
}
86103
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL