Skip to content

Commit

Permalink
Fix one unknown test and part of testTypeReference26
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Nov 19, 2024
1 parent 130a969 commit 97e8732
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IParent;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.JavaModelException;
Expand All @@ -26,7 +28,7 @@ public static IJavaElement getEnclosingJavaElement(ASTNode node) {
if (node instanceof AbstractTypeDeclaration
|| node instanceof MethodDeclaration
|| node instanceof FieldDeclaration
//|| node instanceof VariableDeclaration
|| node instanceof Initializer
|| node instanceof CompilationUnit
|| node instanceof AnnotationTypeMemberDeclaration) {
return getDeclaringJavaElement(node);
Expand Down Expand Up @@ -57,6 +59,34 @@ private static IJavaElement findElementForNodeCustom(ASTNode key) {
}
}
}
if( key instanceof Initializer i) {
ASTNode parentNode = i.getParent();
int domOccurance = -1;
if( parentNode instanceof AbstractTypeDeclaration typeDecl) {
List parentBody = typeDecl.bodyDeclarations();
for( int z = 0; z < parentBody.size() && domOccurance == -1; z++ ) {
if( parentBody.get(z) == key) {
domOccurance = z + 1;
}
}
}
IJavaElement parentEl = findElementForNodeViaDirectBinding(parentNode);
if( parentEl instanceof IParent parentElement) {
try {
IJavaElement[] kiddos = parentElement.getChildren();
for( int q = 0; q < kiddos.length; q++ ) {
if( kiddos[q] instanceof IMember kiddoMember) {
int count = kiddoMember.getOccurrenceCount();
if( count == domOccurance ) {
return kiddos[q];
}
}
}
} catch( JavaModelException jme) {
// ignore
}
}
}
return null;
}

Expand Down

0 comments on commit 97e8732

Please sign in to comment.