Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 236747 Details for
Bug 395021
[introduce factory] Introduce Factory ignores a type parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed fix and Test
Bug 395021.patch (text/plain), 11.00 KB, created by
Samrat Dhillon
on 2013-10-21 21:59:41 EDT
(
hide
)
Description:
Proposed fix and Test
Filename:
MIME Type:
Creator:
Samrat Dhillon
Created:
2013-10-21 21:59:41 EDT
Size:
11.00 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam.java b/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam.java >new file mode 100644 >index 0000000..0fc7fa3 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam.java >@@ -0,0 +1,5 @@ >+package p; >+class CtorTypeParam<E> { >+ public <F extends E> /*[*/CtorTypeParam/*]*/(F p) { >+ } >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam_out.java >new file mode 100644 >index 0000000..818278c >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam_out.java >@@ -0,0 +1,9 @@ >+package p; >+class CtorTypeParam<E> { >+ public static <E, F extends E> CtorTypeParam<E> createCtorTypeParam(F p) { >+ return new CtorTypeParam<E>(p); >+ } >+ >+ private <F extends E> /*[*/CtorTypeParam/*]*/(F p) { >+ } >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java >index de4e2d1..d6682c4 100644 >--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java >+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Samrat Dhillon samrat.dhillon@gmail.com [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.refactoring; > >@@ -725,6 +726,10 @@ > public void test97507() throws Exception { > singleUnitBugHelper("CtorTypeArgBounds", true); > } >+ >+ public void test395021() throws Exception{ >+ singleUnitBugHelper("CtorTypeParam", true); >+ } > > public void test250660() throws Exception { > singleUnitBugHelper("HasAnonymous", true); >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >index 2c6aef5..291eb57 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 >+ * Samrat Dhillon samrat.dhillon@gmail.com [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021 > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring; > >@@ -928,6 +929,8 @@ > public static String IntroduceFactory_unexpectedInitializerNodeType; > > public static String IntroduceFactory_unsupportedNestedTypes; >+ >+ public static String IntroduceFactory_ambiguousTypeParams; > > public static String IntroduceFactoryRefactoring_declare_private; > >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java >index 83a45b2..7ffb710 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Samrat Dhillon samrat.dhillon@gmail.com [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021 > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > >@@ -238,6 +239,8 @@ > private String fFactoryClassName; > > private int fConstructorVisibility= Modifier.PRIVATE; >+ >+ private boolean hasDuplicateTypeParamName = false; > > /** > * Creates a new <code>IntroduceFactoryRefactoring</code> with the given selection >@@ -545,6 +548,11 @@ > > if (fCallSitesInBinaryUnits) > result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass)); >+ >+ if(hasDuplicateTypeParamName()){ >+ result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_ambiguousTypeParams)); >+ hasDuplicateTypeParamName = true; >+ } > > return result; > } finally { >@@ -720,7 +728,7 @@ > } > > /** >- * Copies the constructor's parent type's type parameters, if any, as >+ * Copies the type parameters of the constructor and its parent, if any, as > * method type parameters of the new static factory method. (Recall > * that static methods can't refer to type arguments of the enclosing > * class, since they have no instance to serve as a context.)<br> >@@ -738,13 +746,24 @@ > */ > private void copyTypeParameters(AST ast, MethodDeclaration newMethod) { > ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters(); >+ ITypeBinding[] ctorTypeParams= fCtorBinding.getTypeParameters(); >+ if(hasDuplicateTypeParamName){ >+ ITypeBinding[] typeParams= filterDuplicates(ctorTypeParams,ctorOwnerTypeParms); >+ copyTypeParameters(ast, newMethod, typeParams); >+ }else{ >+ copyTypeParameters(ast, newMethod, ctorOwnerTypeParms); >+ copyTypeParameters(ast, newMethod, ctorTypeParams); >+ } >+ } >+ >+ private void copyTypeParameters(AST ast, MethodDeclaration newMethod,ITypeBinding[] typeParms) { > List<TypeParameter> factoryMethodTypeParms= newMethod.typeParameters(); >- for(int i= 0; i < ctorOwnerTypeParms.length; i++) { >+ for(int i= 0; i < typeParms.length; i++) { > TypeParameter newParm= ast.newTypeParameter(); >- ITypeBinding[] parmTypeBounds= ctorOwnerTypeParms[i].getTypeBounds(); >+ ITypeBinding[] parmTypeBounds= typeParms[i].getTypeBounds(); > List<Type> newParmBounds= newParm.typeBounds(); > >- newParm.setName(ast.newSimpleName(ctorOwnerTypeParms[i].getName())); >+ newParm.setName(ast.newSimpleName(typeParms[i].getName())); > for(int b=0; b < parmTypeBounds.length; b++) { > if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null) > continue; >@@ -756,6 +775,35 @@ > factoryMethodTypeParms.add(newParm); > } > } >+ >+ private ITypeBinding[] filterDuplicates(ITypeBinding[] ctorTypeParams, ITypeBinding[] ctorOwnerTypeParms) { >+ Map<String, ITypeBinding> uniqueTypeParamMap = new HashMap<String, ITypeBinding>(); >+ for(ITypeBinding binding: ctorTypeParams){ >+ uniqueTypeParamMap.put(binding.getName(), binding); >+ } >+ for(ITypeBinding binding: ctorOwnerTypeParms){ >+ if(uniqueTypeParamMap.get(binding.getName())==null){ >+ uniqueTypeParamMap.put(binding.getName(), binding); >+ } >+ } >+ Collection<ITypeBinding> typeParams= uniqueTypeParamMap.values(); >+ return typeParams.toArray(new ITypeBinding[typeParams.size()]); >+ } >+ >+ private boolean hasDuplicateTypeParamName() { >+ ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters(); >+ ITypeBinding[] ctorTypeParams = fCtorBinding.getTypeParameters(); >+ Map<String, ITypeBinding> uniqueTypeParamMap = new HashMap<String, ITypeBinding>(); >+ for(ITypeBinding binding: ctorTypeParams){ >+ uniqueTypeParamMap.put(binding.getName(), binding); >+ } >+ for(ITypeBinding binding: ctorOwnerTypeParms){ >+ if(uniqueTypeParamMap.get(binding.getName())!=null){ >+ return true; >+ } >+ } >+ return false; >+ } > > /** > * @param argType >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >index ca77d2b..c7524ea 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >@@ -9,6 +9,7 @@ > # IBM Corporation - initial API and implementation > # Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 > # Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Name ambiguous return value in error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=50607 >+# Samrat Dhillon samrat.dhillon@gmail.com [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021 > ############################################################################### > # NLS properties for the Refactoring Core > >@@ -1264,7 +1265,7 @@ > IntroduceFactoryRefactoring_factory_pattern=Factory name: ''{0}'' > IntroduceFactoryRefactoring_declare_private=Declare original constructor 'private' > IntroduceFactory_constructorInEnum=Introduce Factory is not supported for constructors of enumerated types. >- >+IntroduceFactory_ambiguousTypeParams=Ambiguous type Parameters on constructor and Declaring Type. Refactoring may lead to compilation error > #--- Generalize Declared Type > ChangeTypeRefactoring_checking_preconditions=Checking preconditions... > ChangeTypeRefactoring_name=Generalize Declared Type
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 395021
: 236747