From 0157164131baf4355d9d9fb8c5a82ae8fb94db9b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 12 Apr 2024 11:34:37 -0400 Subject: [PATCH] Implement JavacAnnotationBinding.getKey Closes #218 Signed-off-by: David Thompson --- .../javac/dom/JavacAnnotationBinding.java | 17 ++++++++++++----- .../internal/javac/dom/JavacMethodBinding.java | 4 ++-- .../internal/javac/dom/JavacTypeBinding.java | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java index 0773f711cdc..10f6375bf02 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java @@ -23,12 +23,16 @@ public class JavacAnnotationBinding implements IAnnotationBinding { - private JavacBindingResolver resolver; - private Compound annotation; + private final JavacBindingResolver resolver; + private final Compound annotation; - public JavacAnnotationBinding(Compound ann, JavacBindingResolver resolver) { + private transient String key; + private final IBinding recipient; + + public JavacAnnotationBinding(Compound ann, JavacBindingResolver resolver, IBinding recipient) { this.resolver = resolver; this.annotation = ann; + this.recipient = recipient; } @Override @@ -68,8 +72,11 @@ public IJavaElement getJavaElement() { @Override public String getKey() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'getKey'"); + StringBuilder builder = new StringBuilder(); + builder.append(this.recipient.getKey()); + builder.append('@'); + builder.append(this.getAnnotationType().getKey()); + return builder.toString(); } @Override diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java index 6d0b5f82254..131ef4e3dcb 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java @@ -51,7 +51,7 @@ public JavacMethodBinding(MethodSymbol sym, JavacBindingResolver resolver, List< @Override public IAnnotationBinding[] getAnnotations() { - return methodSymbol.getAnnotationMirrors().stream().map(ann -> new JavacAnnotationBinding(ann, this.resolver)).toArray(IAnnotationBinding[]::new); + return methodSymbol.getAnnotationMirrors().stream().map(ann -> new JavacAnnotationBinding(ann, this.resolver, this)).toArray(IAnnotationBinding[]::new); } @Override @@ -217,7 +217,7 @@ public Object getDefaultValue() { public IAnnotationBinding[] getParameterAnnotations(int paramIndex) { VarSymbol parameter = this.methodSymbol.params.get(paramIndex); return parameter.getAnnotationMirrors().stream() // - .map(annotation -> new JavacAnnotationBinding(annotation, this.resolver)) // + .map(annotation -> new JavacAnnotationBinding(annotation, this.resolver, this)) // .toArray(IAnnotationBinding[]::new); } diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java index ef0ee2ab596..5c23f762ffd 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java @@ -71,7 +71,7 @@ public JavacTypeBinding(final Type type, final JavacBindingResolver resolver, fi @Override public IAnnotationBinding[] getAnnotations() { return typeSymbol.getAnnotationMirrors().stream() - .map(am -> new JavacAnnotationBinding(am, resolver)) + .map(am -> new JavacAnnotationBinding(am, resolver, this)) .toArray(IAnnotationBinding[]::new); } @@ -340,7 +340,7 @@ public ITypeBinding getSuperclass() { @Override public IAnnotationBinding[] getTypeAnnotations() { return this.typeSymbol.getAnnotationMirrors().stream() // - .map(annotation -> new JavacAnnotationBinding(annotation, this.resolver)) // + .map(annotation -> new JavacAnnotationBinding(annotation, this.resolver, this)) // .toArray(IAnnotationBinding[]::new); }