From 25a06e78fba9c8e4e8bb41ec33bfe0b1c9ae50f4 Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Mon, 22 Jan 2024 10:37:42 +0100 Subject: [PATCH] A noextend API class that implements noimplement interface isn't a leak https://github.com/eclipse-pde/eclipse.pde/discussions/1064 --- .../tests/leak/ClassImplementsLeak.java | 15 ++++++++++++ .../test-builder/leak/class/test37.java | 24 +++++++++++++++++++ .../LeakImplementsProblemDetector.java | 4 +++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/class/test37.java diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/ClassImplementsLeak.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/ClassImplementsLeak.java index fa56fec2bf..529ea3e8a0 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/ClassImplementsLeak.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/ClassImplementsLeak.java @@ -340,5 +340,20 @@ private void x12(boolean inc) { deployLeakTest(typename + ".java", inc); //$NON-NLS-1$ } + /** + * Tests that an noextend API class that implements noimplement interface + * is not a leak + */ + public void testNoExtendClassImplementsNoImplementInterface13F() { + x13(false); + } + public void testNoExtendClassImplementsNoImplementInterface13I() { + x13(true); + } + + private void x13(boolean inc) { + String typename = "test37"; //$NON-NLS-1$ + deployLeakTest(typename + ".java", inc); //$NON-NLS-1$ + } } diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/class/test37.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/class/test37.java new file mode 100644 index 0000000000..c6e19b95c7 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/class/test37.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package x.y.z; + +import x.y.z.interfaceNoImplement; + +/** +* @noextend +*/ +public class test37 implements interfaceNoImplement { + public void exposeMethod() {} +} + diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakImplementsProblemDetector.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakImplementsProblemDetector.java index a6cdaacd74..992c09a30a 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakImplementsProblemDetector.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakImplementsProblemDetector.java @@ -64,7 +64,9 @@ public boolean isProblem(IReference reference, IProgressMonitor monitor) { if (annotations != null) { if (RestrictionModifiers.isImplementRestriction(annotations.getRestrictions())) { IApiAnnotations annotationsSource = member.getApiComponent().getApiDescription().resolveAnnotations(sourceMember.getHandle()); - if (annotationsSource != null && !RestrictionModifiers.isImplementRestriction(annotationsSource.getRestrictions())) { + if (annotationsSource != null + && !RestrictionModifiers.isImplementRestriction(annotationsSource.getRestrictions()) + && !RestrictionModifiers.isExtendRestriction(annotationsSource.getRestrictions())) { isProb= true; } }