Skip to content

Commit 73d4bdf

Browse files
🐛 Improve method matching to catch static methods declared on class fields (#150) (#156)
* Improve method matching to catch static methods declared on class fields # Conflicts: # java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java * Remove unnecessary line --------- Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com> Signed-off-by: Cherry Picker <noreply@github.com> Co-authored-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
1 parent 81caa68 commit 73d4bdf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import org.eclipse.jdt.core.IClassFile;
99
import org.eclipse.jdt.core.ICompilationUnit;
10+
import org.eclipse.jdt.core.IField;
1011
import org.eclipse.jdt.core.IJavaElement;
1112
import org.eclipse.jdt.core.IMethod;
12-
import org.eclipse.jdt.core.ITypeRoot;
1313
import org.eclipse.jdt.core.compiler.IProblem;
1414
import org.eclipse.jdt.core.dom.AST;
1515
import org.eclipse.jdt.core.dom.ASTParser;
@@ -32,15 +32,21 @@ public List<SymbolInformation> get(SearchMatch match) {
3232
// For Method Calls we will need to do the local variable trick
3333
try {
3434
MethodReferenceMatch m = (MethodReferenceMatch) match;
35-
IMethod e = (IMethod) m.getElement();
35+
IJavaElement e = (IJavaElement) m.getElement();
3636
SymbolInformation symbol = new SymbolInformation();
3737
Location location = getLocation((IJavaElement) match.getElement(), match);
3838
symbol.setName(e.getElementName());
3939
symbol.setKind(convertSymbolKind(e));
4040
symbol.setContainerName(e.getParent().getElementName());
4141
symbol.setLocation(location);
4242
if (this.query.contains(".")) {
43-
ICompilationUnit unit = e.getCompilationUnit();
43+
ICompilationUnit unit = null;
44+
if (m.getElement() instanceof IMethod) {
45+
unit = ((IMethod) m.getElement()).getCompilationUnit();
46+
} else if (m.getElement() instanceof IField) {
47+
unit = ((IField) m.getElement()).getCompilationUnit();
48+
}
49+
4450
if (unit == null) {
4551
IClassFile cls = (IClassFile) ((IJavaElement) e).getAncestor(IJavaElement.CLASS_FILE);
4652
if (cls != null) {

0 commit comments

Comments
 (0)