Skip to content

Commit

Permalink
Use resolved key for binary elements too
Browse files Browse the repository at this point in the history
+ suffix exception types
  • Loading branch information
mickaelistria committed Dec 16, 2024
1 parent e828297 commit 5ad966d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypeParameter;
import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException;
import org.eclipse.jdt.internal.core.BinaryMethod;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.Member;
import org.eclipse.jdt.internal.core.ResolvedBinaryMethod;
import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
import org.eclipse.jdt.internal.core.SourceMethod;
import org.eclipse.jdt.internal.core.util.Util;
Expand Down Expand Up @@ -230,7 +233,7 @@ public IJavaElement getJavaElement() {
.toArray(String[]::new);
IMethod[] methods = currentType.findMethods(currentType.getMethod(getName(), parametersResolved));
if (methods != null && methods.length > 0) {
return methods[0];
return resolved(methods[0]);
}
var parametersNotResolved = this.methodSymbol.params().stream()
.map(varSymbol -> varSymbol.type)
Expand All @@ -240,7 +243,7 @@ public IJavaElement getJavaElement() {
.toArray(String[]::new);
methods = currentType.findMethods(currentType.getMethod(getName(), parametersNotResolved));
if (methods != null && methods.length > 0) {
return methods[0];
return resolved(methods[0]);
}
}
// nothing found: move up in hierarchy
Expand Down Expand Up @@ -294,8 +297,11 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho
}

private IMethod resolved(IMethod from) {
if (from instanceof SourceMethod sourceMethod && !(from instanceof ResolvedSourceMethod)) {
return new ResolvedSourceMethod(sourceMethod.getParent(), sourceMethod.getElementName(), sourceMethod.getParameterTypes(), getKey(), sourceMethod.getOccurrenceCount());
if (from instanceof SourceMethod && !(from instanceof ResolvedSourceMethod)) {
return new ResolvedSourceMethod((JavaElement)from.getParent(), from.getElementName(), from.getParameterTypes(), getKey(), from.getOccurrenceCount());
}
if (from instanceof BinaryMethod && !(from instanceof ResolvedBinaryMethod)) {
return new ResolvedBinaryMethod((JavaElement)from.getParent(), from.getElementName(), from.getParameterTypes(), getKey(), from.getOccurrenceCount());
}
return from;
}
Expand Down Expand Up @@ -338,7 +344,7 @@ public String getKey() {
try {
StringBuilder builder = new StringBuilder();
getKey(builder, this.methodSymbol, this.methodType, this.parentType, this.resolver);
return builder.toString();
return builder.toString() + Arrays.stream(getExceptionTypes()).map(ITypeBinding::getKey).map(key -> '|' + key).collect(Collectors.joining());
} catch(BindingKeyException bke) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException;
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
import org.eclipse.jdt.internal.core.BinaryType;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedBinaryType;
import org.eclipse.jdt.internal.core.ResolvedSourceType;
import org.eclipse.jdt.internal.core.SourceType;

Expand Down Expand Up @@ -269,6 +271,9 @@ private IType resolved(IType type) {
if (type instanceof SourceType && !(type instanceof ResolvedSourceType)) {
return new ResolvedSourceType((JavaElement)type.getParent(), type.getElementName(), getKey(), type.getOccurrenceCount());
}
if (type instanceof BinaryType && !(type instanceof ResolvedBinaryType)) {
return new ResolvedBinaryType((JavaElement)type.getParent(), type.getElementName(), getKey(), type.getOccurrenceCount());
}
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException;
import org.eclipse.jdt.internal.core.BinaryMember;
import org.eclipse.jdt.internal.core.DOMToModelPopulator;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.LambdaMethod;
import org.eclipse.jdt.internal.core.LocalVariable;
import org.eclipse.jdt.internal.core.ResolvedBinaryField;
import org.eclipse.jdt.internal.core.ResolvedSourceField;
import org.eclipse.jdt.internal.core.SourceField;
import org.eclipse.jdt.internal.core.util.Util;
Expand Down Expand Up @@ -157,8 +159,11 @@ public IJavaElement getJavaElement() {
}

private IField resolved(IField field) {
if (field instanceof SourceField sourceField && !(sourceField instanceof ResolvedSourceField)) {
return new ResolvedSourceField(sourceField.getParent(), sourceField.getElementName(), getKey(), sourceField.getOccurrenceCount());
if (field instanceof SourceField && !(field instanceof ResolvedSourceField)) {
return new ResolvedSourceField((JavaElement)field.getParent(), field.getElementName(), getKey(), field.getOccurrenceCount());
}
if (field instanceof BinaryMember && !(field instanceof ResolvedBinaryField)) {
return new ResolvedBinaryField((JavaElement)field.getParent(), field.getElementName(), getKey(), field.getOccurrenceCount());
}
return field;
}
Expand Down

0 comments on commit 5ad966d

Please sign in to comment.