diff options
| author | Markus Keller | 2015-07-31 13:50:25 +0000 |
|---|---|---|
| committer | Lars Vogel | 2015-09-11 14:38:04 +0000 |
| commit | 4f5169287422584658daa624ce779ba77b45c5c7 (patch) | |
| tree | 0e54277b6548fe33e58908808adde24c53a77710 | |
| parent | fc0ae315e364266cc6e1cf012827a447786b7c27 (diff) | |
| download | eclipse.pde.ui-4f5169287422584658daa624ce779ba77b45c5c7.tar.gz eclipse.pde.ui-4f5169287422584658daa624ce779ba77b45c5c7.tar.xz eclipse.pde.ui-4f5169287422584658daa624ce779ba77b45c5c7.zip | |
Bug 474038: Wrongly reports addition of first type parameter to a generic method
Change-Id: I9fa4ec0afaadd7d63e62c02ded5f24beb7430b51
Signed-off-by: Markus Keller <markus_keller@ch.ibm.com>
9 files changed, 153 insertions, 24 deletions
diff --git a/apitools/org.eclipse.pde.api.tools.tests/API Tools Test Suite.launch b/apitools/org.eclipse.pde.api.tools.tests/API Tools Test Suite.launch index c690f6b6df..8eca3d02b7 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/API Tools Test Suite.launch +++ b/apitools/org.eclipse.pde.api.tools.tests/API Tools Test Suite.launch @@ -10,8 +10,10 @@ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
+<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;org.eclipse.pde.api.tools&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
-<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="true"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/MethodCompatibilityTypeParameterTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/MethodCompatibilityTypeParameterTests.java index 19342373fc..32dab15d4c 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/MethodCompatibilityTypeParameterTests.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/MethodCompatibilityTypeParameterTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,17 +10,17 @@ *******************************************************************************/ package org.eclipse.pde.api.tools.builder.tests.compatibility; -import junit.framework.Test; - import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory; import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta; import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; +import junit.framework.Test; + /** - * Tests that the builder correctly reports compatibility problems - * related method modifiers and visibility. + * Tests that the builder correctly reports compatibility problems related to + * method type parameters and varargs. * * @since 1.0 */ @@ -68,6 +68,22 @@ public class MethodCompatibilityTypeParameterTests extends MethodCompatibilityTe } /** + * Tests adding the first type parameter to a method -- a compatible change. + */ + private void xAddFirstTypeParameter(boolean incremental) throws Exception { + IPath filePath = WORKSPACE_CLASSES_PACKAGE_A.append("AddFirstTypeParameter.java"); //$NON-NLS-1$ + performCompatibilityTest(filePath, incremental); + } + + public void testAddFirstTypeParameterI() throws Exception { + xAddFirstTypeParameter(true); + } + + public void testAddFirstTypeParameterF() throws Exception { + xAddFirstTypeParameter(false); + } + + /** * Tests adding a type parameter to a method */ private void xAddTypeParameter(boolean incremental) throws Exception { diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/comparator/tests/MethodDeltaTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/comparator/tests/MethodDeltaTests.java index 73c9b973e5..8d3b7ec1a2 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/comparator/tests/MethodDeltaTests.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/comparator/tests/MethodDeltaTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.pde.api.tools.comparator.tests; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.eclipse.jdt.core.Flags; import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers; import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; @@ -23,6 +20,9 @@ import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; import org.eclipse.pde.api.tools.internal.util.Util; +import junit.framework.Test; +import junit.framework.TestSuite; + /** * Delta tests for method */ @@ -725,7 +725,7 @@ public class MethodDeltaTests extends DeltaTestSetup { } /** - * Add type parameters + * Add new type parameter */ public void test31() { deployBundles("test31"); //$NON-NLS-1$ @@ -747,7 +747,31 @@ public class MethodDeltaTests extends DeltaTestSetup { } /** - * Add type parameter + * Add new type parameter to a method that did not have a type parameter but + * that had a generic signature. + */ + public void test31a() { + deployBundles("test31a"); //$NON-NLS-1$ + IApiBaseline before = getBeforeState(); + IApiBaseline after = getAfterState(); + IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); + assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ + IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); + assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ + IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); + assertNotNull("No delta", delta); //$NON-NLS-1$ + IDelta[] allLeavesDeltas = collectLeaves(delta); + assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ + IDelta child = allLeavesDeltas[0]; + assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ + assertEquals("Wrong flag", IDelta.TYPE_PARAMETERS, child.getFlags()); //$NON-NLS-1$ + assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ + assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ + assertEquals("foo<U:Ljava/lang/Number;>(TU;Ljava/util/List<TU;>;)V", child.getKey()); //$NON-NLS-1$ + } + + /** + * Add another type parameter */ public void test32() { deployBundles("test32"); //$NON-NLS-1$ @@ -766,6 +790,7 @@ public class MethodDeltaTests extends DeltaTestSetup { assertEquals("Wrong flag", IDelta.TYPE_PARAMETER, child.getFlags()); //$NON-NLS-1$ assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ + assertEquals("foo<U:Ljava/lang/Object;V:Ljava/lang/Object;>(TU;)V", child.getKey()); //$NON-NLS-1$ } /** diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.a/src/a/methods/typeparameters/AddFirstTypeParameter.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.a/src/a/methods/typeparameters/AddFirstTypeParameter.java new file mode 100644 index 0000000000..3247f565f2 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.a/src/a/methods/typeparameters/AddFirstTypeParameter.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2008, 2015 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package a.methods.typeparameters; + +/** + * + */ +public class AddFirstTypeParameter { + + public void method(Number n) {} +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/compat/methods/typeparameters/AddFirstTypeParameter.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/compat/methods/typeparameters/AddFirstTypeParameter.java new file mode 100644 index 0000000000..8345af3a28 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/compat/methods/typeparameters/AddFirstTypeParameter.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2008, 2015 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package a.methods.typeparameters; + +/** + * + */ +public class AddFirstTypeParameter { + + public <T extends Number> void method(T t) {} +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/after/X.java b/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/after/X.java new file mode 100644 index 0000000000..92a1614af6 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/after/X.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2008, 2015 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +import java.util.List; + +public class X { + public <U extends Number> void foo(U u, List<U> l) {} +}
\ No newline at end of file diff --git a/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/before/X.java b/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/before/X.java new file mode 100644 index 0000000000..99a662cc39 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/tests-deltas/method/test31a/before/X.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2008, 2015 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +import java.util.List; + +public class X { + public void foo(Number n, List<Number> l) {} +}
\ No newline at end of file diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/comparator/ClassFileComparator.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/comparator/ClassFileComparator.java index 3aa2c8e6a9..99dbdefe97 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/comparator/ClassFileComparator.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/comparator/ClassFileComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 IBM Corporation and others. + * Copyright (c) 2008, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -542,9 +542,11 @@ public class ClassFileComparator { SignatureDescriptor signatureDescriptor2 = getSignatureDescriptor(signature2); TypeParameterDescriptor[] typeParameterDescriptors = signatureDescriptor2.getTypeParameterDescriptors(); if (typeParameterDescriptors.length != 0) { - this.addDelta(getElementType(element1), IDelta.ADDED, IDelta.TYPE_PARAMETERS, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { getDataFor(element1, this.type1) }); + this.addDelta(getElementType(element1), IDelta.ADDED, IDelta.TYPE_PARAMETERS, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { + getDataFor(element1, this.type1) }); } else if (signatureDescriptor2.getTypeArguments().length != 0) { - this.addDelta(getElementType(element1), IDelta.ADDED, IDelta.TYPE_ARGUMENTS, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { getDataFor(element1, this.type1) }); + this.addDelta(getElementType(element1), IDelta.ADDED, IDelta.TYPE_ARGUMENTS, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { + getDataFor(element1, this.type1) }); } } } else if (signature2 == null) { @@ -555,7 +557,7 @@ public class ClassFileComparator { if (length != 0) { for (int i = 0; i < length; i++) { TypeParameterDescriptor typeParameterDescriptor = typeParameterDescriptors[i]; - this.addDelta(getElementType(element1), IDelta.REMOVED, IDelta.TYPE_PARAMETER, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + this.addDelta(getElementType(element1), IDelta.REMOVED, IDelta.TYPE_PARAMETER, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), typeParameterDescriptor.name }); } @@ -565,7 +567,7 @@ public class ClassFileComparator { if (length != 0) { for (int i = 0; i < length; i++) { String typeArgument = typeArguments[i]; - this.addDelta(getElementType(element1), IDelta.REMOVED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + this.addDelta(getElementType(element1), IDelta.REMOVED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), typeArgument }); } } @@ -657,7 +659,7 @@ public class ClassFileComparator { boolean added = boundsMax == size2; for (; index < boundsMax; index++) { String currentInterfaceBound = added ? (String) interfaceBounds2.get(index) : (String) interfaceBounds1.get(index); - this.addDelta(IDelta.TYPE_PARAMETER_ELEMENT_TYPE, added ? IDelta.ADDED : IDelta.REMOVED, IDelta.INTERFACE_BOUND, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + this.addDelta(IDelta.TYPE_PARAMETER_ELEMENT_TYPE, added ? IDelta.ADDED : IDelta.REMOVED, IDelta.INTERFACE_BOUND, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), name, currentInterfaceBound }); } @@ -670,7 +672,9 @@ public class ClassFileComparator { boolean added = max == length2; for (; i < max; i++) { TypeParameterDescriptor currentTypeParameter = added ? typeParameterDescriptors2[i] : typeParameterDescriptors1[i]; - this.addDelta(getElementType(element1), added ? IDelta.ADDED : IDelta.REMOVED, IDelta.TYPE_PARAMETER, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + int kind = added ? IDelta.ADDED : IDelta.REMOVED; + int flags = added && length == 0 ? IDelta.TYPE_PARAMETERS : IDelta.TYPE_PARAMETER; + this.addDelta(getElementType(element1), kind, flags, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), currentTypeParameter.name }); } @@ -693,7 +697,7 @@ public class ClassFileComparator { String currentTypeArgument = typeArguments[i]; String newTypeArgument = typeArguments2[i]; if (!currentTypeArgument.equals(newTypeArgument)) { - this.addDelta(getElementType(element1), IDelta.CHANGED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + this.addDelta(getElementType(element1), IDelta.CHANGED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), currentTypeArgument, newTypeArgument }); } @@ -704,7 +708,7 @@ public class ClassFileComparator { boolean added = max == length2; for (; i < max; i++) { String currentTypeArgument = added ? typeArguments2[i] : typeArguments[i]; - this.addDelta(getElementType(element1), added ? IDelta.ADDED : IDelta.REMOVED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, element1.getName(), new String[] { + this.addDelta(getElementType(element1), added ? IDelta.ADDED : IDelta.REMOVED, IDelta.TYPE_ARGUMENT, this.currentDescriptorRestrictions, element1.getModifiers(), element2.getModifiers(), this.type1, getKeyFor(element2, this.type1), new String[] { getDataFor(element1, type1), currentTypeArgument }); } } @@ -768,6 +772,20 @@ public class ClassFileComparator { return null; } + private String getKeyFor(IApiMember member, IApiType type) { + switch (member.getType()) { + case IApiElement.TYPE: + return member.getName(); + case IApiElement.METHOD: + return getKeyForMethod((IApiMethod) member, type); + case IApiElement.FIELD: + return member.getName(); + default: + break; + } + return null; + } + /** * Returns a new {@link Delta} to use, and resets the status of creating a * delta diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/IDelta.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/IDelta.java index e5c24878e5..cfabbe7382 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/IDelta.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/IDelta.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -591,8 +591,8 @@ public interface IDelta { */ public static final int TYPE_PARAMETER_NAME = 50; /** - * Delta kind flag that denotes parameters have been added or removed from a - * type. <br> + * Delta kind flag that denotes type parameters have been added to a type + * that didn't have type parameters before. <br> * Applies to kinds: * <ul> * <li>{@link #ADDED}</li> |
