View | Details | Raw Unified | Return to bug 48056 | Differences between
and this patch

Collapse All | Expand All

(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java (-5 / +99 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.corext.refactoring.code;
12
package org.eclipse.jdt.internal.corext.refactoring.code;
12
13
Lines 25-38 Link Here
25
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
26
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
26
import org.eclipse.jdt.core.dom.AST;
27
import org.eclipse.jdt.core.dom.AST;
27
import org.eclipse.jdt.core.dom.ASTNode;
28
import org.eclipse.jdt.core.dom.ASTNode;
29
import org.eclipse.jdt.core.dom.ASTVisitor;
28
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
30
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
29
import org.eclipse.jdt.core.dom.Assignment;
31
import org.eclipse.jdt.core.dom.Assignment;
30
import org.eclipse.jdt.core.dom.Block;
32
import org.eclipse.jdt.core.dom.Block;
31
import org.eclipse.jdt.core.dom.BodyDeclaration;
33
import org.eclipse.jdt.core.dom.BodyDeclaration;
34
import org.eclipse.jdt.core.dom.BreakStatement;
32
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
35
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
33
import org.eclipse.jdt.core.dom.CompilationUnit;
36
import org.eclipse.jdt.core.dom.CompilationUnit;
34
import org.eclipse.jdt.core.dom.ConstructorInvocation;
37
import org.eclipse.jdt.core.dom.ConstructorInvocation;
38
import org.eclipse.jdt.core.dom.ContinueStatement;
35
import org.eclipse.jdt.core.dom.DoStatement;
39
import org.eclipse.jdt.core.dom.DoStatement;
40
import org.eclipse.jdt.core.dom.EnhancedForStatement;
36
import org.eclipse.jdt.core.dom.Expression;
41
import org.eclipse.jdt.core.dom.Expression;
37
import org.eclipse.jdt.core.dom.FieldAccess;
42
import org.eclipse.jdt.core.dom.FieldAccess;
38
import org.eclipse.jdt.core.dom.ForStatement;
43
import org.eclipse.jdt.core.dom.ForStatement;
Lines 40-51 Link Here
40
import org.eclipse.jdt.core.dom.ITypeBinding;
45
import org.eclipse.jdt.core.dom.ITypeBinding;
41
import org.eclipse.jdt.core.dom.IVariableBinding;
46
import org.eclipse.jdt.core.dom.IVariableBinding;
42
import org.eclipse.jdt.core.dom.Initializer;
47
import org.eclipse.jdt.core.dom.Initializer;
48
import org.eclipse.jdt.core.dom.LabeledStatement;
43
import org.eclipse.jdt.core.dom.Message;
49
import org.eclipse.jdt.core.dom.Message;
44
import org.eclipse.jdt.core.dom.MethodDeclaration;
50
import org.eclipse.jdt.core.dom.MethodDeclaration;
45
import org.eclipse.jdt.core.dom.Name;
51
import org.eclipse.jdt.core.dom.Name;
46
import org.eclipse.jdt.core.dom.PrimitiveType;
52
import org.eclipse.jdt.core.dom.PrimitiveType;
47
import org.eclipse.jdt.core.dom.QualifiedName;
53
import org.eclipse.jdt.core.dom.QualifiedName;
48
import org.eclipse.jdt.core.dom.SimpleName;
54
import org.eclipse.jdt.core.dom.SimpleName;
55
import org.eclipse.jdt.core.dom.Statement;
49
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
56
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
50
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
57
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
51
import org.eclipse.jdt.core.dom.SwitchCase;
58
import org.eclipse.jdt.core.dom.SwitchCase;
Lines 55-60 Link Here
55
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
62
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
56
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
63
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
57
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
64
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
65
import org.eclipse.jdt.core.dom.WhileStatement;
58
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
66
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
59
67
60
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
68
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
Lines 110-116 Link Here
110
118
111
	private boolean fForceStatic;
119
	private boolean fForceStatic;
112
	private boolean fIsLastStatementSelected;
120
	private boolean fIsLastStatementSelected;
113
121
	private SimpleName fEnclosingLoopLabel;
122
	
114
	public ExtractMethodAnalyzer(ICompilationUnit unit, Selection selection) throws CoreException {
123
	public ExtractMethodAnalyzer(ICompilationUnit unit, Selection selection) throws CoreException {
115
		super(unit, selection, false);
124
		super(unit, selection, false);
116
	}
125
	}
Lines 314-322 Link Here
314
		fInputFlowInfo= flowAnalyzer.perform(getSelectedNodes());
323
		fInputFlowInfo= flowAnalyzer.perform(getSelectedNodes());
315
324
316
		if (fInputFlowInfo.branches()) {
325
		if (fInputFlowInfo.branches()) {
317
			status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_branch_mismatch, JavaStatusContext.create(fCUnit, getSelection()));
326
			String canHandleBranchesProblem= canHandleBranches();
318
			fReturnKind= ERROR;
327
			if (canHandleBranchesProblem != null) {
319
			return status;
328
				status.addFatalError(canHandleBranchesProblem, JavaStatusContext.create(fCUnit, getSelection()));
329
				fReturnKind= ERROR;
330
				return status;
331
			}
320
		}
332
		}
321
		if (fInputFlowInfo.isValueReturn()) {
333
		if (fInputFlowInfo.isValueReturn()) {
322
			fReturnKind= RETURN_STATEMENT_VALUE;
334
			fReturnKind= RETURN_STATEMENT_VALUE;
Lines 341-346 Link Here
341
		return status;
353
		return status;
342
	}
354
	}
343
355
356
	private String canHandleBranches() {
357
		if (fReturnValue != null)
358
			return RefactoringCoreMessages.ExtractMethodAnalyzer_branch_mismatch;
359
		
360
		ASTNode[] selectedNodes= getSelectedNodes();
361
		final ASTNode lastSelectedNode= selectedNodes[selectedNodes.length - 1];
362
		Statement body= getParentLoopBody(lastSelectedNode.getParent());
363
		if (!(body instanceof Block))
364
			return RefactoringCoreMessages.ExtractMethodAnalyzer_branch_mismatch;
365
		
366
		if (body != lastSelectedNode) {
367
			Block block= (Block)body;
368
			List statements= block.statements();
369
			ASTNode lastStatementInLoop= (ASTNode)statements.get(statements.size() - 1);
370
			if (lastSelectedNode != lastStatementInLoop)
371
				return RefactoringCoreMessages.ExtractMethodAnalyzer_branch_mismatch;
372
		}
373
		
374
		final String continueMatchesLoopProblem[]= { null };
375
		for (int i= 0; i < selectedNodes.length; i++) {
376
			final ASTNode astNode= selectedNodes[i];
377
			astNode.accept(new ASTVisitor() {
378
				ArrayList fLocalLoopLabels= new ArrayList();
379
				
380
				public boolean visit(BreakStatement node) {
381
					SimpleName label= node.getLabel();
382
					if (label != null && !fLocalLoopLabels.contains(label.getIdentifier())) {
383
						continueMatchesLoopProblem[0]= Messages.format(
384
								RefactoringCoreMessages.ExtractMethodAnalyzer_branch_break_mismatch,
385
								new Object[] { ("break " + label.getIdentifier()) }); //$NON-NLS-1$
386
					}
387
					return false;
388
				}
389
				
390
				public boolean visit(LabeledStatement node) {
391
					SimpleName label= node.getLabel();
392
					if (label != null)
393
						fLocalLoopLabels.add(label.getIdentifier());
394
					return true;
395
				}
396
				
397
				public void endVisit(ContinueStatement node) {
398
					SimpleName label= node.getLabel();
399
					if (label != null && !fLocalLoopLabels.contains(label.getIdentifier())) {
400
						if (fEnclosingLoopLabel == null || ! label.getIdentifier().equals(fEnclosingLoopLabel.getIdentifier())) {
401
							continueMatchesLoopProblem[0]= Messages.format(
402
									RefactoringCoreMessages.ExtractMethodAnalyzer_branch_continue_mismatch,
403
									new Object[] { "continue " + label.getIdentifier() }); //$NON-NLS-1$
404
						}
405
					}
406
				}
407
			});
408
		}
409
		return continueMatchesLoopProblem[0];
410
	}
411
412
	private Statement getParentLoopBody(ASTNode node) {
413
		Statement stmt= null;
414
		ASTNode start= node;
415
		while (start != null
416
				&& !(start instanceof ForStatement)
417
				&& !(start instanceof DoStatement)
418
				&& !(start instanceof WhileStatement)
419
				&& !(start instanceof EnhancedForStatement)) {
420
			start= start.getParent();
421
		}
422
		if (start instanceof ForStatement) {
423
			stmt= ((ForStatement)start).getBody();
424
		} else if (start instanceof DoStatement) {
425
			stmt= ((DoStatement)start).getBody();
426
		} else if (start instanceof WhileStatement) {
427
			stmt= ((WhileStatement)start).getBody();
428
		} else if (start instanceof EnhancedForStatement) {
429
			stmt= ((EnhancedForStatement)start).getBody();
430
		}
431
		if (start.getParent() instanceof LabeledStatement) {
432
			LabeledStatement labeledStatement= (LabeledStatement)start.getParent();
433
			fEnclosingLoopLabel= labeledStatement.getLabel();
434
		}
435
		return stmt;
436
	}
437
344
	private boolean isVoidMethod() {
438
	private boolean isVoidMethod() {
345
		// if we have an initializer
439
		// if we have an initializer
346
		if (fEnclosingMethodBinding == null)
440
		if (fEnclosingMethodBinding == null)
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java (+83 lines)
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] 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
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.corext.refactoring.code;
13
package org.eclipse.jdt.internal.corext.refactoring.code;
13
14
Lines 16-21 Link Here
16
import java.util.HashMap;
17
import java.util.HashMap;
17
import java.util.HashSet;
18
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.Iterator;
20
import java.util.LinkedList;
19
import java.util.List;
21
import java.util.List;
20
import java.util.Map;
22
import java.util.Map;
21
import java.util.Set;
23
import java.util.Set;
Lines 54-69 Link Here
54
import org.eclipse.jdt.core.dom.BodyDeclaration;
56
import org.eclipse.jdt.core.dom.BodyDeclaration;
55
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
57
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
56
import org.eclipse.jdt.core.dom.CompilationUnit;
58
import org.eclipse.jdt.core.dom.CompilationUnit;
59
import org.eclipse.jdt.core.dom.ContinueStatement;
60
import org.eclipse.jdt.core.dom.DoStatement;
61
import org.eclipse.jdt.core.dom.EnhancedForStatement;
57
import org.eclipse.jdt.core.dom.EnumDeclaration;
62
import org.eclipse.jdt.core.dom.EnumDeclaration;
58
import org.eclipse.jdt.core.dom.Expression;
63
import org.eclipse.jdt.core.dom.Expression;
59
import org.eclipse.jdt.core.dom.ExpressionStatement;
64
import org.eclipse.jdt.core.dom.ExpressionStatement;
60
import org.eclipse.jdt.core.dom.FieldAccess;
65
import org.eclipse.jdt.core.dom.FieldAccess;
61
import org.eclipse.jdt.core.dom.FieldDeclaration;
66
import org.eclipse.jdt.core.dom.FieldDeclaration;
67
import org.eclipse.jdt.core.dom.ForStatement;
62
import org.eclipse.jdt.core.dom.IMethodBinding;
68
import org.eclipse.jdt.core.dom.IMethodBinding;
63
import org.eclipse.jdt.core.dom.ITypeBinding;
69
import org.eclipse.jdt.core.dom.ITypeBinding;
64
import org.eclipse.jdt.core.dom.IVariableBinding;
70
import org.eclipse.jdt.core.dom.IVariableBinding;
65
import org.eclipse.jdt.core.dom.Initializer;
71
import org.eclipse.jdt.core.dom.Initializer;
66
import org.eclipse.jdt.core.dom.Javadoc;
72
import org.eclipse.jdt.core.dom.Javadoc;
73
import org.eclipse.jdt.core.dom.LabeledStatement;
67
import org.eclipse.jdt.core.dom.MethodDeclaration;
74
import org.eclipse.jdt.core.dom.MethodDeclaration;
68
import org.eclipse.jdt.core.dom.MethodInvocation;
75
import org.eclipse.jdt.core.dom.MethodInvocation;
69
import org.eclipse.jdt.core.dom.Modifier;
76
import org.eclipse.jdt.core.dom.Modifier;
Lines 71-82 Link Here
71
import org.eclipse.jdt.core.dom.ReturnStatement;
78
import org.eclipse.jdt.core.dom.ReturnStatement;
72
import org.eclipse.jdt.core.dom.SimpleName;
79
import org.eclipse.jdt.core.dom.SimpleName;
73
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
80
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
81
import org.eclipse.jdt.core.dom.Statement;
74
import org.eclipse.jdt.core.dom.Type;
82
import org.eclipse.jdt.core.dom.Type;
75
import org.eclipse.jdt.core.dom.TypeDeclaration;
83
import org.eclipse.jdt.core.dom.TypeDeclaration;
76
import org.eclipse.jdt.core.dom.TypeParameter;
84
import org.eclipse.jdt.core.dom.TypeParameter;
77
import org.eclipse.jdt.core.dom.VariableDeclaration;
85
import org.eclipse.jdt.core.dom.VariableDeclaration;
78
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
86
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
79
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
87
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
88
import org.eclipse.jdt.core.dom.WhileStatement;
80
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
89
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
81
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
90
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
82
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
91
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
Lines 506-511 Link Here
506
			}
515
			}
507
516
508
			replaceDuplicates(result);
517
			replaceDuplicates(result);
518
			replaceBranches(result); //TODO: move into createNewMethod()??
509
519
510
			if (fImportRewriter.hasRecordedChanges()) {
520
			if (fImportRewriter.hasRecordedChanges()) {
511
				TextEdit edit= fImportRewriter.rewriteImports(null);
521
				TextEdit edit= fImportRewriter.rewriteImports(null);
Lines 523-528 Link Here
523
533
524
	}
534
	}
525
535
536
	private void replaceBranches(final CompilationUnitChange result) {
537
		ASTNode[] selectedNodes= fAnalyzer.getSelectedNodes();
538
		for (int i= 0; i < selectedNodes.length; i++) {
539
			ASTNode astNode= selectedNodes[i];
540
			astNode.accept(new ASTVisitor() {
541
				private LinkedList fOpenLoopLabels= new LinkedList();
542
543
				private void registerLoopLabel(Statement node) {
544
					String identifier;
545
					if (node.getParent() instanceof LabeledStatement) {
546
						LabeledStatement labeledStatement= (LabeledStatement)node.getParent();
547
						identifier= labeledStatement.getLabel().getIdentifier();
548
					} else {
549
						identifier= null;
550
					}
551
					fOpenLoopLabels.add(identifier);
552
				}
553
				
554
				public boolean visit(ForStatement node) {
555
					registerLoopLabel(node);
556
					return super.visit(node);
557
				}
558
559
				public void endVisit(ForStatement node) {
560
					fOpenLoopLabels.removeLast();
561
				}
562
563
				public boolean visit(WhileStatement node) {
564
					registerLoopLabel(node);
565
					return super.visit(node);
566
				}
567
568
				public void endVisit(WhileStatement node) {
569
					fOpenLoopLabels.removeLast();
570
				}
571
572
				public boolean visit(EnhancedForStatement node) {
573
					registerLoopLabel(node);
574
					return super.visit(node);
575
				}
576
577
				public void endVisit(EnhancedForStatement node) {
578
					fOpenLoopLabels.removeLast();
579
				}
580
581
				public boolean visit(DoStatement node) {
582
					registerLoopLabel(node);
583
					return super.visit(node);
584
				}
585
586
				public void endVisit(DoStatement node) {
587
					fOpenLoopLabels.removeLast();
588
				}
589
590
				public void endVisit(ContinueStatement node) {
591
					final SimpleName label= node.getLabel();
592
					if (fOpenLoopLabels.isEmpty() || (label != null && !fOpenLoopLabels.contains(label.getIdentifier()))) {
593
						TextEditGroup description= new TextEditGroup(RefactoringCoreMessages.ExtractMethodRefactoring_replace_continue);
594
						result.addTextEditGroup(description);
595
596
						ReturnStatement rs= fAST.newReturnStatement();
597
						IVariableBinding returnValue= fAnalyzer.getReturnValue();
598
						if (returnValue != null) {
599
							rs.setExpression(fAST.newSimpleName(getName(returnValue)));
600
						}
601
602
						fRewriter.replace(node, rs, description);
603
					}
604
				}
605
			});
606
		}
607
	}
608
526
	private ExtractMethodDescriptor getRefactoringDescriptor() {
609
	private ExtractMethodDescriptor getRefactoringDescriptor() {
527
		final Map arguments= new HashMap();
610
		final Map arguments= new HashMap();
528
		String project= null;
611
		String project= null;
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties (-1 / +4 lines)
Lines 127-133 Link Here
127
ExtractMethodAnalyzer_after_do_keyword=Selection may not start immediately after the \'do\' keyword.
127
ExtractMethodAnalyzer_after_do_keyword=Selection may not start immediately after the \'do\' keyword.
128
ExtractMethodAnalyzer_super_or_this=Cannot extract super or this call from constructor.
128
ExtractMethodAnalyzer_super_or_this=Cannot extract super or this call from constructor.
129
ExtractMethodAnalyzer_cannot_determine_return_type=Cannot determine expression's return type. Using void instead.
129
ExtractMethodAnalyzer_cannot_determine_return_type=Cannot determine expression's return type. Using void instead.
130
ExtractMethodAnalyzer_branch_mismatch=Selection contains branch statement but corresponding branch target is not selected.
130
ExtractMethodAnalyzer_branch_break_mismatch=Selection contains ''{0}'', but corresponding branch target is not selected.
131
ExtractMethodAnalyzer_branch_continue_mismatch=Selection contains ''{0}'', but corresponding branch target (or its complete loop body) is not selected.
132
ExtractMethodAnalyzer_branch_mismatch=Selection contains branch statement but corresponding branch target (or the complete loop body) is not selected.
131
ExtractMethodAnalyzer_parent_mismatch=Not all selected statements are enclosed by the same parent statement.
133
ExtractMethodAnalyzer_parent_mismatch=Not all selected statements are enclosed by the same parent statement.
132
ExtractMethodAnalyzer_cannot_extract_anonymous_type=Cannot extract the body of a anonymous type declaration. Select whole declaration.
134
ExtractMethodAnalyzer_cannot_extract_anonymous_type=Cannot extract the body of a anonymous type declaration. Select whole declaration.
133
ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment=Cannot extract a variable declaration fragment. Select whole declaration statement.
135
ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment=Cannot extract a variable declaration fragment. Select whole declaration statement.
Lines 160-165 Link Here
160
ExtractMethodRefactoring_error_nameInUse=''{0}'' is already used as a name in the selected code
162
ExtractMethodRefactoring_error_nameInUse=''{0}'' is already used as a name in the selected code
161
ExtractMethodRefactoring_error_sameParameter=A parameter ''{0}'' already exists
163
ExtractMethodRefactoring_error_sameParameter=A parameter ''{0}'' already exists
162
ExtractMethodRefactoring_visibility_pattern=Declared visibility: ''{0}''
164
ExtractMethodRefactoring_visibility_pattern=Declared visibility: ''{0}''
165
ExtractMethodRefactoring_replace_continue=Replace continue with return
163
ExtractMethodRefactoring_replace_occurrences=Replace occurrences of statements with method
166
ExtractMethodRefactoring_replace_occurrences=Replace occurrences of statements with method
164
ExtractMethodRefactoring_error_vararg_ordering=The variable arity parameter ''{0}'' cannot be followed by another parameter
167
ExtractMethodRefactoring_error_vararg_ordering=The variable arity parameter ''{0}'' cannot be followed by another parameter
165
ExtractMethodRefactoring_descriptor_description=Extract method ''{0}'' from ''{1}'' to ''{2}''
168
ExtractMethodRefactoring_descriptor_description=Extract method ''{0}'' from ''{1}'' to ''{2}''
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java (+7 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
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.corext.refactoring;
12
package org.eclipse.jdt.internal.corext.refactoring;
12
13
Lines 558-563 Link Here
558
559
559
	public static String ExtractMethodAnalyzer_assignments_to_local;
560
	public static String ExtractMethodAnalyzer_assignments_to_local;
560
561
562
	public static String ExtractMethodAnalyzer_branch_break_mismatch;
563
564
	public static String ExtractMethodAnalyzer_branch_continue_mismatch;
565
561
	public static String ExtractMethodAnalyzer_branch_mismatch;
566
	public static String ExtractMethodAnalyzer_branch_mismatch;
562
567
563
	public static String ExtractMethodAnalyzer_cannot_determine_return_type;
568
	public static String ExtractMethodAnalyzer_cannot_determine_return_type;
Lines 634-639 Link Here
634
639
635
	public static String ExtractMethodRefactoring_organize_imports;
640
	public static String ExtractMethodRefactoring_organize_imports;
636
641
642
	public static String ExtractMethodRefactoring_replace_continue;
643
637
	public static String ExtractMethodRefactoring_replace_occurrences;
644
	public static String ExtractMethodRefactoring_replace_occurrences;
638
645
639
	public static String ExtractMethodRefactoring_substitute_with_call;
646
	public static String ExtractMethodRefactoring_substitute_with_call;
(-)test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java (+63 lines)
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] Missing return value, while extracting code out of a loop - https://bugs.eclipse.org/bugs/show_bug.cgi?id=213519
11
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Missing return value, while extracting code out of a loop - https://bugs.eclipse.org/bugs/show_bug.cgi?id=213519
12
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] missing return type when code can throw exception - https://bugs.eclipse.org/bugs/show_bug.cgi?id=97413
12
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] missing return type when code can throw exception - https://bugs.eclipse.org/bugs/show_bug.cgi?id=97413
13
 *     Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.ui.tests.refactoring;
15
package org.eclipse.jdt.ui.tests.refactoring;
15
16
Lines 651-656 Link Here
651
	public void test196() throws Exception {
652
	public void test196() throws Exception {
652
		invalidSelectionTest();
653
		invalidSelectionTest();
653
	}
654
	}
655
	
656
	//---- continue not possible
657
	
658
	public void test197() throws Exception {
659
		invalidSelectionTest();
660
	}
654
661
655
662
656
663
Lines 1616-1621 Link Here
1616
		branchTest();
1623
		branchTest();
1617
	}
1624
	}
1618
1625
1626
	public void test756() throws Exception {
1627
		branchTest();
1628
	}
1629
1630
	public void test757() throws Exception {
1631
		branchTest();
1632
	}
1633
1634
	public void test758() throws Exception {
1635
		branchTest();
1636
	}
1637
	
1638
	public void test759() throws Exception {
1639
		branchTest();
1640
	}
1641
	
1642
	public void test760() throws Exception {
1643
		branchTest();
1644
	}
1645
	
1646
	public void test761() throws Exception {
1647
		branchTest();
1648
	}
1649
	
1650
	public void test762() throws Exception {
1651
		branchTest();
1652
	}
1653
	
1654
	public void test763() throws Exception {
1655
		branchTest();
1656
	}
1657
	
1658
	public void test764() throws Exception {
1659
		branchTest();
1660
	}
1661
	
1662
	public void test765() throws Exception {
1663
		branchTest();
1664
	}
1665
	
1666
	public void test766() throws Exception {
1667
		branchTest();
1668
	}
1669
	
1670
	public void test767() throws Exception {
1671
		branchTest();
1672
	}
1673
	
1674
	public void test768() throws Exception {
1675
		branchTest();
1676
	}
1677
	
1678
	public void test769() throws Exception {
1679
		branchTest();
1680
	}
1681
	
1619
	//---- Test for CUs with compiler errors
1682
	//---- Test for CUs with compiler errors
1620
1683
1621
	public void test800() throws Exception {
1684
	public void test800() throws Exception {
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test768.java (+21 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test768 {
4
5
	public void foo() {
6
		int i = 0;
7
		do {
8
			extracted(i);
9
		} while ( i < 10 );
10
	}
11
12
	protected void extracted(int i) {
13
		/*[*/
14
		if( i == 3 ) {
15
			return;
16
		}
17
		System.out.println();
18
		/*]*/
19
	}
20
}
21
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test765.java (+19 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test765 {
4
5
	public void foo() {
6
		int x = 0;
7
		for (int i= 0; i < 3; i++) {
8
			/*[*/
9
			if(i == 2) {
10
				x = (i*3);
11
				continue;
12
			}
13
			System.out.println();
14
			/*]*/
15
		}
16
		System.out.println(x);
17
	}
18
}
19
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test763.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test763 {
4
5
	public void foo() {
6
		inner: for (int i= 0; i < 3; i++) {
7
			/*[*/
8
			if(i == 2) {
9
				continue inner;
10
			}
11
			System.out.println();
12
			/*]*/
13
		}
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test766.java (+19 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test766 {
4
5
	public void foo() {
6
		int x = 0;
7
		foo: for (int i= 0; i < 3; i++) {
8
			/*[*/
9
			if(i == 2) {
10
				x = (i*3);
11
				continue;
12
			}
13
			System.out.println();
14
			/*]*/
15
		}
16
		System.out.println(x);
17
	}
18
}
19
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test762.java (+24 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test762 {
4
5
	public void foo() {
6
		outer: for (int i= 0; i < 3; i++) {
7
			extracted();
8
		}
9
	}
10
11
	protected void extracted() {
12
		/*[*/
13
		for (int j= 0; j < 3; j++) {
14
			for (int k= 0; k < 3; k++) {
15
				if(j == 3) {
16
					return;
17
				}
18
				System.out.println();
19
			}
20
		}
21
		/*]*/
22
	}
23
}
24
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/invalidSelection/A_test197.java (+18 lines)
Added Link Here
1
package invalidSelection;
2
3
public class A_test197 {
4
5
	public void foo() {
6
		outer: for (int i= 0; i < 3; i++) {
7
			for (int j= 0; j < 3; j++) {
8
				/*[*/
9
				if(j == 3) {
10
					continue outer;
11
				}
12
				System.out.println();
13
				/*]*/
14
			}
15
		}
16
	}
17
}
18
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test757.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test757 {
4
5
	public void foo() {
6
		extracted();
7
	}
8
9
	protected void extracted() {
10
		/*[*/
11
		for (int i= 0; i < 3; i++) {
12
			if(i == 2) {
13
				continue;
14
			}
15
			System.out.println();
16
		}
17
		/*]*/
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test759.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test759 {
4
5
	public void foo(int a) {
6
		/*[*/
7
		while (a > 0) {
8
			if(a == 3) {
9
				continue;
10
			}
11
			System.out.println();
12
		}
13
		/*]*/
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test762.java (+20 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test762 {
4
5
	public void foo() {
6
		outer: for (int i= 0; i < 3; i++) {
7
			/*[*/
8
			for (int j= 0; j < 3; j++) {
9
				for (int k= 0; k < 3; k++) {
10
					if(j == 3) {
11
						continue outer;
12
					}
13
					System.out.println();
14
				}
15
			}
16
			/*]*/
17
		}
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test769.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test769 {
4
5
	public void foo(int[] a) {
6
		for(int i : a) {
7
			extracted(i);
8
		}
9
	}
10
11
	protected void extracted(int i) {
12
		/*[*/
13
		if( i == 3 ) {
14
			return;
15
		}
16
		System.out.println();
17
		/*]*/
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test765.java (+24 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test765 {
4
5
	public void foo() {
6
		int x = 0;
7
		for (int i= 0; i < 3; i++) {
8
			x = extracted(x, i);
9
		}
10
		System.out.println(x);
11
	}
12
13
	protected int extracted(int x, int i) {
14
		/*[*/
15
		if(i == 2) {
16
			x = (i*3);
17
			return x;
18
		}
19
		System.out.println();
20
		/*]*/
21
		return x;
22
	}
23
}
24
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test764.java (+24 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test764 {
4
5
	public void foo() {
6
		int x = 0;
7
		for (int i= 0; i < 3; i++) {
8
			x = extracted(x, i);
9
		}
10
		System.out.println(x);
11
	}
12
13
	protected int extracted(int x, int i) {
14
		/*[*/
15
		if(i == 2) {
16
			x = 2;
17
			return x;
18
		}
19
		System.out.println();
20
		/*]*/
21
		return x;
22
	}
23
}
24
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test758.java (+18 lines)
Added Link Here
1
package branch_in;
2
3
import java.util.List;
4
5
public class A_test758 {
6
7
	public void foo(List a) {
8
		/*[*/
9
		for (Object x : a) {
10
			if(x == null) {
11
				continue;
12
			}
13
			System.out.println();
14
		}
15
		/*]*/
16
	}
17
}
18
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test758.java (+22 lines)
Added Link Here
1
package branch_out;
2
3
import java.util.List;
4
5
public class A_test758 {
6
7
	public void foo(List a) {
8
		extracted(a);
9
	}
10
11
	protected void extracted(List a) {
12
		/*[*/
13
		for (Object x : a) {
14
			if(x == null) {
15
				continue;
16
			}
17
			System.out.println();
18
		}
19
		/*]*/
20
	}
21
}
22
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test767.java (+22 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test767 {
4
5
	public void foo() {
6
		for (int i = 0; i < 3; i++) {
7
			extracted();
8
		}
9
	}
10
11
	protected void extracted() {
12
		/*[*/
13
		inner: for (int j = 0; j < 10; j++) {
14
			if (j == 2) {
15
				System.out.println();
16
				continue inner;
17
			}
18
		}
19
		/*]*/
20
	}
21
}
22
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test756.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test756 {
4
5
	public void foo() {
6
		for (int i= 0; i < 3; i++) {
7
			/*[*/
8
			if(i == 2) {
9
				continue;
10
			}
11
			System.out.println();
12
			/*]*/
13
		}
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test769.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test769 {
4
5
	public void foo(int[] a) {
6
		for(int i : a) {
7
			/*[*/
8
			if( i == 3 ) {
9
				continue;
10
			}
11
			System.out.println();
12
			/*]*/
13
		}
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test761.java (+18 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test761 {
4
5
	public void foo() {
6
		outer: for (int i= 0; i < 3; i++) {
7
			/*[*/
8
			for (int j= 0; j < 3; j++) {
9
				if(j == 3) {
10
					continue outer;
11
				}
12
				System.out.println();
13
			}
14
			/*]*/
15
		}
16
	}
17
}
18
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test763.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test763 {
4
5
	public void foo() {
6
		inner: for (int i= 0; i < 3; i++) {
7
			extracted(i);
8
		}
9
	}
10
11
	protected void extracted(int i) {
12
		/*[*/
13
		if(i == 2) {
14
			return;
15
		}
16
		System.out.println();
17
		/*]*/
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test766.java (+24 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test766 {
4
5
	public void foo() {
6
		int x = 0;
7
		foo: for (int i= 0; i < 3; i++) {
8
			x = extracted(x, i);
9
		}
10
		System.out.println(x);
11
	}
12
13
	protected int extracted(int x, int i) {
14
		/*[*/
15
		if(i == 2) {
16
			x = (i*3);
17
			return x;
18
		}
19
		System.out.println();
20
		/*]*/
21
		return x;
22
	}
23
}
24
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test764.java (+19 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test764 {
4
5
	public void foo() {
6
		int x = 0;
7
		for (int i= 0; i < 3; i++) {
8
			/*[*/
9
			if(i == 2) {
10
				x = 2;
11
				continue;
12
			}
13
			System.out.println();
14
			/*]*/
15
		}
16
		System.out.println(x);
17
	}
18
}
19
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test761.java (+22 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test761 {
4
5
	public void foo() {
6
		outer: for (int i= 0; i < 3; i++) {
7
			extracted();
8
		}
9
	}
10
11
	protected void extracted() {
12
		/*[*/
13
		for (int j= 0; j < 3; j++) {
14
			if(j == 3) {
15
				return;
16
			}
17
			System.out.println();
18
		}
19
		/*]*/
20
	}
21
}
22
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test767.java (+18 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test767 {
4
5
	public void foo() {
6
		for (int i = 0; i < 3; i++) {
7
			/*[*/
8
			inner: for (int j = 0; j < 10; j++) {
9
				if (j == 2) {
10
					System.out.println();
11
					continue inner;
12
				}
13
			}
14
			/*]*/
15
		}
16
	}
17
}
18
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test760.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test760 {
4
5
	public void foo(int a) {
6
		extracted(a);
7
	}
8
9
	protected void extracted(int a) {
10
		/*[*/
11
		do {
12
			if(a == 3) {
13
				continue;
14
			}
15
			System.out.println();
16
		} while (a > 0);
17
		/*]*/
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test760.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test760 {
4
5
	public void foo(int a) {
6
		/*[*/
7
		do {
8
			if(a == 3) {
9
				continue;
10
			}
11
			System.out.println();
12
		} while (a > 0);
13
		/*]*/
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test759.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test759 {
4
5
	public void foo(int a) {
6
		extracted(a);
7
	}
8
9
	protected void extracted(int a) {
10
		/*[*/
11
		while (a > 0) {
12
			if(a == 3) {
13
				continue;
14
			}
15
			System.out.println();
16
		}
17
		/*]*/
18
	}
19
}
20
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test757.java (+16 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test757 {
4
5
	public void foo() {
6
		/*[*/
7
		for (int i= 0; i < 3; i++) {
8
			if(i == 2) {
9
				continue;
10
			}
11
			System.out.println();
12
		}
13
		/*]*/
14
	}
15
}
16
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_in/A_test768.java (+17 lines)
Added Link Here
1
package branch_in;
2
3
public class A_test768 {
4
5
	public void foo() {
6
		int i = 0;
7
		do {
8
			/*[*/
9
			if( i == 3 ) {
10
				continue;
11
			}
12
			System.out.println();
13
			/*]*/
14
		} while ( i < 10 );
15
	}
16
}
17
(-)resources/ExtractMethodWorkSpace/ExtractMethodTests/branch_out/A_test756.java (+20 lines)
Added Link Here
1
package branch_out;
2
3
public class A_test756 {
4
5
	public void foo() {
6
		for (int i= 0; i < 3; i++) {
7
			extracted(i);
8
		}
9
	}
10
11
	protected void extracted(int i) {
12
		/*[*/
13
		if(i == 2) {
14
			return;
15
		}
16
		System.out.println();
17
		/*]*/
18
	}
19
}
20

Return to bug 48056