Skip to content

Commit

Permalink
Fixing import bug & resolve setter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed May 19, 2024
1 parent d442520 commit cc2e121
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
## 1.5.4
* Bugfix: import would be displayed as unused if last reference in a file was a fully qualified reference.
* Bugfix: Fixing problem with resolving setter method reference from property.
* Bugfix: Imports would not be added automatically when package statement was missing.
* Improvement: major rework of completion suggestions
- Added completion for constructors
- Added public static members to completion suggestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class HaxeResolver implements ResolveCache.AbstractResolver<HaxeReference

public static final HaxeResolver INSTANCE = new HaxeResolver();

public static ThreadLocal<Stack<PsiElement>> referencesProcessing = ThreadLocal.withInitial(() -> new Stack<PsiElement>());
public static ThreadLocal<Stack<PsiElement>> referencesProcessing = ThreadLocal.withInitial(Stack::new);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public HaxeMethodModel getGetterMethod() {
}

public HaxeMethodModel getSetterMethod() {
if (getGetterType() != HaxeAccessorType.SET) return null;
if (getSetterType() != HaxeAccessorType.SET) return null;
HaxeClassModel declaringClass = this.getDeclaringClass();
if (declaringClass != null) {
return declaringClass.getMethod("set_" + this.getName(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ public static HaxeImportStatement addImport(String path, PsiFile file) {
final PsiElement[] children = file.getChildren();

PsiElement child = children[positionIndex];
// find HaxePackageStatement position
while (!(child instanceof HaxePackageStatement)) {
// search for package or first import
while (!(child instanceof HaxePackageStatement)
&& !(child instanceof HaxeImportStatement)) {
if (++positionIndex < children.length) {
child = children[positionIndex];
}else {
log.warn("Unable to insert Import statement");
return null;
} else {
child = null;
break;
}
}
// find last whitespace line before docs or code and after last import
Expand All @@ -53,13 +54,17 @@ public static HaxeImportStatement addImport(String path, PsiFile file) {
if (++positionIndex < children.length) {
child = children[positionIndex];
}else {
log.warn("Unable to insert Import statement");
return null;
child = null;
break;
}
}

assert child != null;
return insertImportBefore(path, file, child);
if(child != null) {
return insertImportBefore(path, file, child);
}else {
// if no package or import found (probably first import), we just add it to the top of the file
return insertImportTop(path, file);
}
}

private static HaxeImportStatement insertImportBefore(String path, PsiFile file, PsiElement child) {
Expand All @@ -74,4 +79,17 @@ private static HaxeImportStatement insertImportBefore(String path, PsiFile file,
file.addBefore(importStatement, child);
return importStatement;
}
private static HaxeImportStatement insertImportTop(String path, PsiFile file) {
final HaxeImportStatement importStatement =
HaxeElementGenerator.createImportStatementFromPath(file.getProject(), path);
if (importStatement == null) {
return null;
}

final PsiElement newLineElement = PsiParserFacade.getInstance(file.getProject()).createWhiteSpaceFromText("\n");
PsiElement child = file.getFirstChild();
file.addBefore(newLineElement, child);
file.addBefore(importStatement, child);
return importStatement;
}
}

0 comments on commit cc2e121

Please sign in to comment.