diff options
| author | Vikas Chandra | 2019-05-15 09:00:50 +0000 |
|---|---|---|
| committer | Vikas Chandra | 2019-05-15 09:13:23 +0000 |
| commit | f78e921f52642545aaea9251961eed2dde5bc99b (patch) | |
| tree | 5436119ff4a9a79f2f2aa9e312a2fea138fdac07 | |
| parent | e4a4c956865a93dfad7faf1e932f00c0dffd5dc4 (diff) | |
| download | eclipse.pde.ui-f78e921f52642545aaea9251961eed2dde5bc99b.tar.gz eclipse.pde.ui-f78e921f52642545aaea9251961eed2dde5bc99b.tar.xz eclipse.pde.ui-f78e921f52642545aaea9251961eed2dde5bc99b.zip | |
Bug 547296 - API builder should detect leaked return types ( package
visible types)
Change-Id: I9e645492a7c3ad6cd3330330495f50283154c2bd
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
6 files changed, 144 insertions, 4 deletions
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/MethodReturnTypeLeak.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/MethodReturnTypeLeak.java index a08986b31a..b7bb22dbb5 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/MethodReturnTypeLeak.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/leak/MethodReturnTypeLeak.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 IBM Corporation and others. + * Copyright (c) 2008, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -504,8 +504,9 @@ public class MethodReturnTypeLeak extends LeakTest { } /** - * Tests that a protected method(s) in a final class does not report any return type leaks - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=257113 + * Tests that a protected method(s) in a final class does not report any + * return type leaks https://bugs.eclipse.org/bugs/show_bug.cgi?id=257113 + * * @param inc */ private void x19(boolean inc) { @@ -514,4 +515,42 @@ public class MethodReturnTypeLeak extends LeakTest { deployLeakTest(typename+".java", inc); //$NON-NLS-1$ } + public void testMethodReturnType21F() { + x21(false); + } + + public void testMethodReturnType21I() { + x21(true); + } + + /** + * Tests that a protected method(s) in a final class does not report any + * return type leaks https://bugs.eclipse.org/bugs/show_bug.cgi?id=257113 + * + * @param inc + */ + private void x21(boolean inc) { + expectingNoProblems(); + String typename = "testMRL21"; //$NON-NLS-1$ + deployLeakTest(typename + ".java", inc); //$NON-NLS-1$ + } + + public void testMethodReturnType22F() { + x22(false); + } + + public void testMethodReturnType22I() { + x22(true); + } + + + private void x22(boolean inc) { + setExpectedProblemIds(getDefaultProblemIdSet(1)); + + expectingNoProblems(); + String typename = "testMRL22"; //$NON-NLS-1$ + setExpectedMessageArgs(new String[][] { { "classDefault", typename, "m1()" } }); //$NON-NLS-1$ //$NON-NLS-2$ + deployLeakTest(typename + ".java", inc); //$NON-NLS-1$ + } + } diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL21.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL21.java new file mode 100644 index 0000000000..42f7530cec --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL21.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2019 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.classPublic; + +public class testMRL21 { + + public classPublic m1() { + return null; + + } + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL22.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL22.java new file mode 100644 index 0000000000..0a75862c51 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leak/method/testMRL22.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2019 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.classDefault; + +public class testMRL22 { + + public classDefault m1() { + return null; + + } + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classDefault.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classDefault.java new file mode 100644 index 0000000000..977603e1d4 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classDefault.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2019 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; + + +class classDefault { + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classPublic.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classPublic.java new file mode 100644 index 0000000000..b8f099bf5a --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/leakprojects/leakproject/src/x/y/z/classPublic.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2019 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; + + +public class classPublic { + + +}
\ No newline at end of file diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakReturnTypeDetector.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakReturnTypeDetector.java index 8ab891f610..de29d5043a 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakReturnTypeDetector.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/LeakReturnTypeDetector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 IBM Corporation and others. + * Copyright (c) 2008, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,7 +15,9 @@ package org.eclipse.pde.api.tools.internal.builder; import java.util.Set; +import org.eclipse.jdt.core.Flags; import org.eclipse.pde.api.tools.internal.provisional.builder.IReference; +import org.eclipse.pde.api.tools.internal.provisional.model.IApiType; import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemTypes; @@ -48,4 +50,14 @@ public class LeakReturnTypeDetector extends MethodLeakDetector { return IApiProblem.LEAK_RETURN_TYPE; } + @Override + protected boolean isProblem(IReference reference) { + if (super.isProblem(reference) == true) { + return true; + } + IApiType type = (IApiType) reference.getResolvedReference(); + int modifiers = type.getModifiers(); + return Flags.isPackageDefault(modifiers); + } + } |
