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 394030 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/generics_in/A_test1253.java (+11 lines)
Added Link Here
1
package generics_in;
2
import java.util.Map;
3
4
public class A_test1253<V> {
5
    public A_test1253(Map<?, ? extends V> c) {
6
        this(/*[*/c.size()/*]*/);
7
    }
8
9
    public A_test1253(int size) {
10
    }
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/generics_in/A_test1254.java (+10 lines)
Added Link Here
1
package generics_in;
2
import java.util.ArrayList;
3
import java.util.List;
4
5
public class A_test1254{
6
	public <E> void foo() {
7
		List<? extends E> t = new ArrayList<E>();
8
		/*[*/t.size();/*]*/
9
	}
10
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/generics_out/A_test1253.java (+15 lines)
Added Link Here
1
package generics_out;
2
import java.util.Map;
3
4
public class A_test1253<V> {
5
    public A_test1253(Map<?, ? extends V> c) {
6
        this(extracted(c));
7
    }
8
9
	protected static <V> int extracted(Map<?, ? extends V> c) {
10
		return /*[*/c.size()/*]*/;
11
	}
12
13
    public A_test1253(int size) {
14
    }
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/generics_out/A_test1254.java (+14 lines)
Added Link Here
1
package generics_out;
2
import java.util.ArrayList;
3
import java.util.List;
4
5
public class A_test1254{
6
	public <E> void foo() {
7
		List<? extends E> t = new ArrayList<E>();
8
		extracted(t);
9
	}
10
11
	protected <E> void extracted(List<? extends E> t) {
12
		/*[*/t.size();/*]*/
13
	}
14
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java (-1 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013, 2012 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 13-18 Link Here
13
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
13
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
14
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004
14
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004
15
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] extracting return value results in compile error - https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606
15
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] extracting return value results in compile error - https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606
16
 *     Samrat Dhillon <samrat.dhillon@gmail.com> -  [extract method] Extracting expression of parameterized type that is passed as argument to this constructor yields compilation error https://bugs.eclipse.org/bugs/show_bug.cgi?id=394030
16
 *******************************************************************************/
17
 *******************************************************************************/
17
package org.eclipse.jdt.ui.tests.refactoring;
18
package org.eclipse.jdt.ui.tests.refactoring;
18
19
Lines 2109-2114 Link Here
2109
	public void test1252() throws Exception {
2110
	public void test1252() throws Exception {
2110
		fieldInitializerTest();
2111
		fieldInitializerTest();
2111
	}
2112
	}
2113
		
2114
	public void test1253() throws Exception {
2115
		genericTest();
2116
	}
2117
	
2118
	public void test1254() throws Exception {
2119
		genericTest();
2120
	}
2112
2121
2113
	//---- Test copied from http://c2.com/cgi/wiki?RefactoringBenchmarksForExtractMethod
2122
	//---- Test copied from http://c2.com/cgi/wiki?RefactoringBenchmarksForExtractMethod
2114
2123
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java (-6 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013, 2012 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 10-15 Link Here
10
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Does not replace similar code in parent class of anonymous class - https://bugs.eclipse.org/bugs/show_bug.cgi?id=160853
10
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Does not replace similar code in parent class of anonymous class - https://bugs.eclipse.org/bugs/show_bug.cgi?id=160853
11
 *     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] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
12
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004
12
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004
13
 *     Samrat Dhillon 	 <samrat.dhillon@gmail.com>    - [extract method] Extracting expression of parameterized type that is passed as argument to this constructor yields compilation error - https://bugs.eclipse.org/bugs/show_bug.cgi?id=394030 
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.corext.refactoring.code;
15
package org.eclipse.jdt.internal.corext.refactoring.code;
15
16
Lines 988-994 Link Here
988
			}
989
			}
989
		}
990
		}
990
991
991
		ITypeBinding[] typeVariables= computeLocalTypeVariables();
992
		ITypeBinding[] typeVariables= computeLocalTypeVariables(modifiers);
992
		List<TypeParameter> typeParameters= result.typeParameters();
993
		List<TypeParameter> typeParameters= result.typeParameters();
993
		for (int i= 0; i < typeVariables.length; i++) {
994
		for (int i= 0; i < typeVariables.length; i++) {
994
			TypeParameter parameter= fAST.newTypeParameter();
995
			TypeParameter parameter= fAST.newTypeParameter();
Lines 1027-1046 Link Here
1027
		return result;
1028
		return result;
1028
	}
1029
	}
1029
1030
1030
	private ITypeBinding[] computeLocalTypeVariables() {
1031
	private ITypeBinding[] computeLocalTypeVariables(int modifier) {
1031
		List<ITypeBinding> result= new ArrayList<ITypeBinding>(Arrays.asList(fAnalyzer.getTypeVariables()));
1032
		List<ITypeBinding> result= new ArrayList<ITypeBinding>(Arrays.asList(fAnalyzer.getTypeVariables()));
1032
		for (int i= 0; i < fParameterInfos.size(); i++) {
1033
		for (int i= 0; i < fParameterInfos.size(); i++) {
1033
			ParameterInfo info= fParameterInfos.get(i);
1034
			ParameterInfo info= fParameterInfos.get(i);
1034
			processVariable(result, info.getOldBinding());
1035
			processVariable(result, info.getOldBinding(), modifier);
1035
		}
1036
		}
1036
		IVariableBinding[] methodLocals= fAnalyzer.getMethodLocals();
1037
		IVariableBinding[] methodLocals= fAnalyzer.getMethodLocals();
1037
		for (int i= 0; i < methodLocals.length; i++) {
1038
		for (int i= 0; i < methodLocals.length; i++) {
1038
			processVariable(result, methodLocals[i]);
1039
			processVariable(result, methodLocals[i], modifier);
1039
		}
1040
		}
1040
		return result.toArray(new ITypeBinding[result.size()]);
1041
		return result.toArray(new ITypeBinding[result.size()]);
1041
	}
1042
	}
1042
1043
1043
	private void processVariable(List<ITypeBinding> result, IVariableBinding variable) {
1044
	private void processVariable(List<ITypeBinding> result, IVariableBinding variable, int modifier) {
1044
		if (variable == null)
1045
		if (variable == null)
1045
			return;
1046
			return;
1046
		ITypeBinding binding= variable.getType();
1047
		ITypeBinding binding= variable.getType();
Lines 1053-1058 Link Here
1053
					if (decl != null && decl.getParent() instanceof MethodDeclaration) {
1054
					if (decl != null && decl.getParent() instanceof MethodDeclaration) {
1054
						result.add(arg);
1055
						result.add(arg);
1055
					}
1056
					}
1057
					if(decl.getParent() instanceof TypeDeclaration && (modifier& Modifier.STATIC)==Modifier.STATIC){
1058
						result.add(arg);
1059
					}
1060
				}
1061
				if(arg.isWildcardType() && arg.getBound()!=null && !result.contains(arg.getBound())){
1062
					ASTNode decl= fRoot.findDeclaringNode(arg.getBound());
1063
					if (decl != null && decl.getParent() instanceof MethodDeclaration) {
1064
						result.add(arg.getBound());
1065
					}
1066
					if(decl.getParent() instanceof TypeDeclaration && (modifier& Modifier.STATIC)==Modifier.STATIC){
1067
						result.add(arg.getBound());
1068
					}
1056
				}
1069
				}
1057
			}
1070
			}
1058
		}
1071
		}

Return to bug 394030