From 15bf1d18e311ccbaa34a702f3985245c812db9a1 Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Thu, 5 Sep 2024 11:30:22 +0200 Subject: [PATCH] IApiAnnotations.isExact for CompositeApiDescription.resolveAnnotations - CompositeApiDescription.resolveAnnotations should be able to properly find the best match annotation using IApiAnnotations.isExact which is now also implemented by TypeAnnotations.isExact. https://github.com/eclipse-pde/eclipse.pde/issues/1386 --- .../org.eclipse.pde.api.tools/META-INF/MANIFEST.MF | 2 +- .../pde/api/tools/internal/ApiAnnotations.java | 1 + .../api/tools/internal/CompositeApiDescription.java | 11 +++-------- .../pde/api/tools/internal/TypeAnnotations.java | 4 ++++ .../tools/internal/provisional/IApiAnnotations.java | 13 +++++++++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF b/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF index b11dda30a0..7fbad0b9c6 100644 --- a/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF +++ b/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.pde.api.tools;singleton:=true -Bundle-Version: 1.3.500.qualifier +Bundle-Version: 1.3.600.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnnotations.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnnotations.java index 48a88f295c..46268ea730 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnnotations.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnnotations.java @@ -72,6 +72,7 @@ public void setExact(boolean equals) { isExact = equals; } + @Override public boolean isExact() { return isExact; } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/CompositeApiDescription.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/CompositeApiDescription.java index f950b6a58a..bb60abdef3 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/CompositeApiDescription.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/CompositeApiDescription.java @@ -63,17 +63,12 @@ public IApiAnnotations resolveAnnotations(IElementDescriptor element) { IApiAnnotations bestMatchAnnotation = null; for (IApiDescription fDescription : fDescriptions) { IApiAnnotations ann = fDescription.resolveAnnotations(element); - boolean isExact = false; if (ann != null) { bestMatchAnnotation = ann; + if (ann.isExact()) { + return ann; // if exact, return else keep looking for best match + } } - if (ann instanceof ApiAnnotations) { - isExact = ((ApiAnnotations) ann).isExact(); - } - if (isExact) { - return ann; // if exact, return else keep looking for best match - } - } return bestMatchAnnotation; } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/TypeAnnotations.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/TypeAnnotations.java index db14eb0ee7..777288e56d 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/TypeAnnotations.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/TypeAnnotations.java @@ -42,4 +42,8 @@ public int getRestrictions() { return fAnnotations.getRestrictions(); } + @Override + public boolean isExact() { + return fAnnotations != null && fAnnotations.isExact(); + } } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/IApiAnnotations.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/IApiAnnotations.java index e3eab332f2..8dcaa2fb2d 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/IApiAnnotations.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/IApiAnnotations.java @@ -35,4 +35,17 @@ public interface IApiAnnotations { */ public int getRestrictions(); + /** + * Returns whether these API annotations are based on an exact match of the + * originating element. + * + * @return whether these API annotations are based on an exact match of the + * originating element. + * + * @since 1.3.600 + */ + default boolean isExact() { + return false; + } + }