Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 395021
Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam.java (+5 lines)
Added Link Here
1
package p;
2
class CtorTypeParam<E> {
3
    public <F extends E> /*[*/CtorTypeParam/*]*/(F p) {
4
    }
5
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/IntroduceFactory/Bugzilla/395021/CtorTypeParam_out.java (+9 lines)
Added Link Here
1
package p;
2
class CtorTypeParam<E> {
3
    public static <E, F extends E> CtorTypeParam<E> createCtorTypeParam(F p) {
4
		return new CtorTypeParam<E>(p);
5
	}
6
7
	private <F extends E> /*[*/CtorTypeParam/*]*/(F p) {
8
    }
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java (+5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Samrat Dhillon samrat.dhillon@gmail.com [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.refactoring;
12
package org.eclipse.jdt.ui.tests.refactoring;
12
13
Lines 725-730 Link Here
725
	public void test97507() throws Exception {
726
	public void test97507() throws Exception {
726
		singleUnitBugHelper("CtorTypeArgBounds", true);
727
		singleUnitBugHelper("CtorTypeArgBounds", true);
727
	}
728
	}
729
	
730
	public void test395021() throws Exception{
731
		singleUnitBugHelper("CtorTypeParam", true);
732
	}
728
733
729
	public void test250660() throws Exception {
734
	public void test250660() throws Exception {
730
		singleUnitBugHelper("HasAnonymous", true);
735
		singleUnitBugHelper("HasAnonymous", true);
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
10
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
11
 *     Samrat Dhillon samrat.dhillon@gmail.com  [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.corext.refactoring;
13
package org.eclipse.jdt.internal.corext.refactoring;
13
14
Lines 928-933 Link Here
928
	public static String IntroduceFactory_unexpectedInitializerNodeType;
929
	public static String IntroduceFactory_unexpectedInitializerNodeType;
929
930
930
	public static String IntroduceFactory_unsupportedNestedTypes;
931
	public static String IntroduceFactory_unsupportedNestedTypes;
932
	
933
	public static String IntroduceFactory_ambiguousTypeParams;
931
934
932
	public static String IntroduceFactoryRefactoring_declare_private;
935
	public static String IntroduceFactoryRefactoring_declare_private;
933
936
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java (-5 / +53 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Samrat Dhillon samrat.dhillon@gmail.com  [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.corext.refactoring.code;
12
package org.eclipse.jdt.internal.corext.refactoring.code;
12
13
Lines 238-243 Link Here
238
	private String fFactoryClassName;
239
	private String fFactoryClassName;
239
240
240
	private int fConstructorVisibility= Modifier.PRIVATE;
241
	private int fConstructorVisibility= Modifier.PRIVATE;
242
	
243
	private boolean hasDuplicateTypeParamName = false;
241
244
242
	/**
245
	/**
243
	 * Creates a new <code>IntroduceFactoryRefactoring</code> with the given selection
246
	 * Creates a new <code>IntroduceFactoryRefactoring</code> with the given selection
Lines 545-550 Link Here
545
548
546
			if (fCallSitesInBinaryUnits)
549
			if (fCallSitesInBinaryUnits)
547
				result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass));
550
				result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass));
551
			
552
			if(hasDuplicateTypeParamName()){
553
				result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_ambiguousTypeParams));
554
				hasDuplicateTypeParamName = true;
555
			}
548
556
549
			return result;
557
			return result;
550
		} finally {
558
		} finally {
Lines 720-726 Link Here
720
	}
728
	}
721
729
722
	/**
730
	/**
723
	 * Copies the constructor's parent type's type parameters, if any, as
731
	 * Copies the type parameters of the constructor and its parent, if any, as
724
	 * method type parameters of the new static factory method. (Recall
732
	 * method type parameters of the new static factory method. (Recall
725
	 * that static methods can't refer to type arguments of the enclosing
733
	 * that static methods can't refer to type arguments of the enclosing
726
	 * class, since they have no instance to serve as a context.)<br>
734
	 * class, since they have no instance to serve as a context.)<br>
Lines 738-750 Link Here
738
	 */
746
	 */
739
	private void copyTypeParameters(AST ast, MethodDeclaration newMethod) {
747
	private void copyTypeParameters(AST ast, MethodDeclaration newMethod) {
740
		ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters();
748
		ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters();
749
		ITypeBinding[] ctorTypeParams= fCtorBinding.getTypeParameters();
750
		if(hasDuplicateTypeParamName){
751
			ITypeBinding[] typeParams= filterDuplicates(ctorTypeParams,ctorOwnerTypeParms);
752
			copyTypeParameters(ast, newMethod, typeParams);
753
		}else{
754
			copyTypeParameters(ast, newMethod, ctorOwnerTypeParms);
755
			copyTypeParameters(ast, newMethod, ctorTypeParams);
756
		}
757
	}
758
	
759
	private void copyTypeParameters(AST ast, MethodDeclaration newMethod,ITypeBinding[] typeParms) {
741
		List<TypeParameter> factoryMethodTypeParms= newMethod.typeParameters();
760
		List<TypeParameter> factoryMethodTypeParms= newMethod.typeParameters();
742
		for(int i= 0; i < ctorOwnerTypeParms.length; i++) {
761
		for(int i= 0; i < typeParms.length; i++) {
743
            TypeParameter newParm= ast.newTypeParameter();
762
            TypeParameter newParm= ast.newTypeParameter();
744
            ITypeBinding[] parmTypeBounds= ctorOwnerTypeParms[i].getTypeBounds();
763
            ITypeBinding[] parmTypeBounds= typeParms[i].getTypeBounds();
745
            List<Type> newParmBounds= newParm.typeBounds();
764
            List<Type> newParmBounds= newParm.typeBounds();
746
765
747
            newParm.setName(ast.newSimpleName(ctorOwnerTypeParms[i].getName()));
766
            newParm.setName(ast.newSimpleName(typeParms[i].getName()));
748
            for(int b=0; b < parmTypeBounds.length; b++) {
767
            for(int b=0; b < parmTypeBounds.length; b++) {
749
            	if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null)
768
            	if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null)
750
            		continue;
769
            		continue;
Lines 756-761 Link Here
756
			factoryMethodTypeParms.add(newParm);
775
			factoryMethodTypeParms.add(newParm);
757
		}
776
		}
758
	}
777
	}
778
	
779
	private ITypeBinding[] filterDuplicates(ITypeBinding[] ctorTypeParams, ITypeBinding[] ctorOwnerTypeParms) {
780
		Map<String, ITypeBinding> uniqueTypeParamMap = new HashMap<String, ITypeBinding>();
781
		for(ITypeBinding binding: ctorTypeParams){
782
			uniqueTypeParamMap.put(binding.getName(), binding);
783
		}
784
		for(ITypeBinding binding: ctorOwnerTypeParms){
785
			if(uniqueTypeParamMap.get(binding.getName())==null){
786
				uniqueTypeParamMap.put(binding.getName(), binding);
787
			}
788
		}
789
		Collection<ITypeBinding> typeParams= uniqueTypeParamMap.values();
790
		return typeParams.toArray(new ITypeBinding[typeParams.size()]);
791
	}
792
	
793
	private boolean hasDuplicateTypeParamName() {
794
		ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters();
795
		ITypeBinding[] ctorTypeParams = fCtorBinding.getTypeParameters();
796
		Map<String, ITypeBinding> uniqueTypeParamMap = new HashMap<String, ITypeBinding>();
797
		for(ITypeBinding binding: ctorTypeParams){
798
			uniqueTypeParamMap.put(binding.getName(), binding);
799
		}
800
		for(ITypeBinding binding: ctorOwnerTypeParms){
801
			if(uniqueTypeParamMap.get(binding.getName())!=null){
802
				return true;
803
			}
804
		}
805
		return false;
806
	}
759
807
760
	/**
808
	/**
761
	 * @param argType
809
	 * @param argType
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties (-1 / +2 lines)
Lines 9-14 Link Here
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
10
#     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
11
#     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Name ambiguous return value in error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=50607
11
#     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Name ambiguous return value in error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=50607
12
#	  Samrat Dhillon samrat.dhillon@gmail.com  [introduce factory] Introduce Factory ignores a type parameter https://bugs.eclipse.org/bugs/show_bug.cgi?id=395021
12
###############################################################################
13
###############################################################################
13
# NLS properties for the Refactoring Core
14
# NLS properties for the Refactoring Core
14
15
Lines 1264-1270 Link Here
1264
IntroduceFactoryRefactoring_factory_pattern=Factory name: ''{0}''
1265
IntroduceFactoryRefactoring_factory_pattern=Factory name: ''{0}''
1265
IntroduceFactoryRefactoring_declare_private=Declare original constructor 'private'
1266
IntroduceFactoryRefactoring_declare_private=Declare original constructor 'private'
1266
IntroduceFactory_constructorInEnum=Introduce Factory is not supported for constructors of enumerated types.
1267
IntroduceFactory_constructorInEnum=Introduce Factory is not supported for constructors of enumerated types.
1267
1268
IntroduceFactory_ambiguousTypeParams=Ambiguous type Parameters on constructor and Declaring Type. Refactoring may lead to compilation error 
1268
#--- Generalize Declared Type
1269
#--- Generalize Declared Type
1269
ChangeTypeRefactoring_checking_preconditions=Checking preconditions...
1270
ChangeTypeRefactoring_checking_preconditions=Checking preconditions...
1270
ChangeTypeRefactoring_name=Generalize Declared Type
1271
ChangeTypeRefactoring_name=Generalize Declared Type

Return to bug 395021