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

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java (-1 / +284 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 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 5635-5638 Link Here
5635
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_combineSelectedStrings);
5635
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_combineSelectedStrings);
5636
5636
5637
	}
5637
	}
5638
5639
	public void testConvertToIfReturn1() throws Exception {
5640
		// positive cases
5641
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
5642
		StringBuffer buf= new StringBuffer();
5643
		buf.append("package test1;\n");
5644
		buf.append("public class E {\n");
5645
		buf.append("    public void foo1() {\n");
5646
		buf.append("        if (a) {\n");
5647
		buf.append("            System.out.println(\"1\");\n");
5648
		buf.append("            System.out.println(\"11\");\n");
5649
		buf.append("        }\n");
5650
		buf.append("    }\n\n");
5651
		buf.append("    public void foo2() {\n");
5652
		buf.append("        bar();\n");
5653
		buf.append("        if (b) {\n");
5654
		buf.append("            System.out.println(\"2\");\n");
5655
		buf.append("            System.out.println(\"22\");\n");
5656
		buf.append("        }\n");
5657
		buf.append("    }\n\n");
5658
		buf.append("    public void foo3() {\n");
5659
		buf.append("        if (c) {\n");
5660
		buf.append("            if (d) {\n");
5661
		buf.append("                System.out.println(\"3\");\n");
5662
		buf.append("                System.out.println(\"33\");\n");
5663
		buf.append("        	}\n");
5664
		buf.append("        }\n");
5665
		buf.append("    }\n");
5666
		buf.append("}\n");
5667
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
5668
5669
		String str= "if (a)";
5670
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5671
		List proposals= collectAssists(context, false);
5672
		assertNumberOfProposals(proposals, 3);
5673
		assertCorrectLabels(proposals);
5674
		StringBuffer buf1= new StringBuffer();
5675
		buf1.append("package test1;\n");
5676
		buf1.append("public class E {\n");
5677
		buf1.append("    public void foo1() {\n");
5678
		buf1.append("        if (!a)\n");
5679
		buf1.append("            return;\n");
5680
		buf1.append("        System.out.println(\"1\");\n");
5681
		buf1.append("        System.out.println(\"11\");\n");
5682
		buf1.append("    }\n\n");
5683
		buf1.append("    public void foo2() {\n");
5684
		buf1.append("        bar();\n");
5685
		buf1.append("        if (b) {\n");
5686
		buf1.append("            System.out.println(\"2\");\n");
5687
		buf1.append("            System.out.println(\"22\");\n");
5688
		buf1.append("        }\n");
5689
		buf1.append("    }\n\n");
5690
		buf1.append("    public void foo3() {\n");
5691
		buf1.append("        if (c) {\n");
5692
		buf1.append("            if (d) {\n");
5693
		buf1.append("                System.out.println(\"3\");\n");
5694
		buf1.append("                System.out.println(\"33\");\n");
5695
		buf1.append("        	}\n");
5696
		buf1.append("        }\n");
5697
		buf1.append("    }\n");
5698
		buf1.append("}\n");
5699
		String expected1= buf1.toString();
5700
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
5701
5702
		str= "if (b)";
5703
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5704
		proposals= collectAssists(context, false);
5705
		assertNumberOfProposals(proposals, 3);
5706
		assertCorrectLabels(proposals);
5707
		buf1= new StringBuffer();
5708
		buf1.append("package test1;\n");
5709
		buf1.append("public class E {\n");
5710
		buf1.append("    public void foo1() {\n");
5711
		buf1.append("        if (a) {\n");
5712
		buf1.append("            System.out.println(\"1\");\n");
5713
		buf1.append("            System.out.println(\"11\");\n");
5714
		buf1.append("        }\n");
5715
		buf1.append("    }\n\n");
5716
		buf1.append("    public void foo2() {\n");
5717
		buf1.append("        bar();\n");
5718
		buf1.append("        if (!b)\n");
5719
		buf1.append("            return;\n");
5720
		buf1.append("        System.out.println(\"2\");\n");
5721
		buf1.append("        System.out.println(\"22\");\n");
5722
		buf1.append("    }\n\n");
5723
		buf1.append("    public void foo3() {\n");
5724
		buf1.append("        if (c) {\n");
5725
		buf1.append("            if (d) {\n");
5726
		buf1.append("                System.out.println(\"3\");\n");
5727
		buf1.append("                System.out.println(\"33\");\n");
5728
		buf1.append("        	}\n");
5729
		buf1.append("        }\n");
5730
		buf1.append("    }\n");
5731
		buf1.append("}\n");
5732
		String expected2= buf1.toString();
5733
		assertExpectedExistInProposals(proposals, new String[] { expected2 });
5734
5735
		str= "if (d)";
5736
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5737
		proposals= collectAssists(context, false);
5738
		assertNumberOfProposals(proposals, 5);
5739
		assertCorrectLabels(proposals);
5740
		buf1= new StringBuffer();
5741
		buf1.append("package test1;\n");
5742
		buf1.append("public class E {\n");
5743
		buf1.append("    public void foo1() {\n");
5744
		buf1.append("        if (a) {\n");
5745
		buf1.append("            System.out.println(\"1\");\n");
5746
		buf1.append("            System.out.println(\"11\");\n");
5747
		buf1.append("        }\n");
5748
		buf1.append("    }\n\n");
5749
		buf1.append("    public void foo2() {\n");
5750
		buf1.append("        bar();\n");
5751
		buf1.append("        if (b) {\n");
5752
		buf1.append("            System.out.println(\"2\");\n");
5753
		buf1.append("            System.out.println(\"22\");\n");
5754
		buf1.append("        }\n");
5755
		buf1.append("    }\n\n");
5756
		buf1.append("    public void foo3() {\n");
5757
		buf1.append("        if (c) {\n");
5758
		buf1.append("            if (!d)\n");
5759
		buf1.append("                return;\n");
5760
		buf1.append("            System.out.println(\"3\");\n");
5761
		buf1.append("            System.out.println(\"33\");\n");
5762
		buf1.append("        }\n");
5763
		buf1.append("    }\n");
5764
		buf1.append("}\n");
5765
		String expected3= buf1.toString();
5766
		assertExpectedExistInProposals(proposals, new String[] { expected3 });
5767
	}
5768
5769
	public void testConvertToIfReturn2() throws Exception {
5770
		// negative cases
5771
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
5772
		StringBuffer buf= new StringBuffer();
5773
		buf.append("package test1;\n");
5774
		buf.append("public class E {\n");
5775
		buf.append("    public void foo1() {\n");
5776
		buf.append("        if (true) {\n");
5777
		buf.append("            System.out.println(\"1\");\n");
5778
		buf.append("            System.out.println(\"2\");\n");
5779
		buf.append("        }\n");
5780
		buf.append("        bar();");
5781
		buf.append("    }\n\n");
5782
		buf.append("    public void foo2() {\n");
5783
		buf.append("        if (a) \n");
5784
		buf.append("            if (b) {\n");
5785
		buf.append("                System.out.println(\"1\");\n");
5786
		buf.append("                System.out.println(\"2\");\n");
5787
		buf.append("        	}\n");
5788
		buf.append("    }\n\n");
5789
		buf.append("    public void foo3() {\n");
5790
		buf.append("        if (c) {\n");
5791
		buf.append("            return;\n");
5792
		buf.append("        }\n");
5793
		buf.append("    }\n");
5794
		buf.append("}\n");
5795
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
5796
5797
		String str= "if (true)"; // not the last executable statement in the method
5798
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5799
		List proposals= collectAssists(context, false);
5800
		assertNumberOfProposals(proposals, 2);
5801
		assertCorrectLabels(proposals);
5802
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5803
5804
		str= "if (b)"; // not present in a block
5805
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5806
		proposals= collectAssists(context, false);
5807
		assertNumberOfProposals(proposals, 4);
5808
		assertCorrectLabels(proposals);
5809
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5810
5811
		str= "if (c)"; // no other statement in 'then' part other than 'return'
5812
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5813
		proposals= collectAssists(context, false);
5814
		assertNumberOfProposals(proposals, 4);
5815
		assertCorrectLabels(proposals);
5816
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5817
	}
5818
5819
	public void testConvertToIfReturn3() throws Exception {
5820
		// 'if' should be in a 'method' returning 'void'
5821
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
5822
		StringBuffer buf= new StringBuffer();
5823
		buf.append("package test1;\n");
5824
		buf.append("public class E {\n");
5825
		buf.append("    static {\n");
5826
		buf.append("        if (a) {\n");
5827
		buf.append("            System.out.println(\"1\");\n");
5828
		buf.append("        }\n");
5829
		buf.append("    }\n");
5830
		buf.append("    public String foo1() {\n");
5831
		buf.append("        if (b) {\n");
5832
		buf.append("            System.out.println(\"1\");\n");
5833
		buf.append("            return \"foo\"\n");
5834
		buf.append("        }\n");
5835
		buf.append("    }\n\n");
5836
5837
		buf.append("}\n");
5838
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
5839
5840
		String str= "if (a)"; // not in a method
5841
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5842
		List proposals= collectAssists(context, false);
5843
		assertNumberOfProposals(proposals, 3);
5844
		assertCorrectLabels(proposals);
5845
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5846
5847
		str= "if (b)"; // method does not return 'void'
5848
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5849
		proposals= collectAssists(context, false);
5850
		assertNumberOfProposals(proposals, 2);
5851
		assertCorrectLabels(proposals);
5852
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5853
	}
5854
5855
	public void testConvertToIfReturn4() throws Exception {
5856
		// 'if' should not be in a loop
5857
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
5858
		StringBuffer buf= new StringBuffer();
5859
		buf.append("package test1;\n");
5860
		buf.append("public class E {\n");
5861
		buf.append("    public void foo1() {\n");
5862
		buf.append("        for (int i; i < 3; i++) {\n");
5863
		buf.append("            if (a) {\n");
5864
		buf.append("                System.out.println(\"1\");\n");
5865
		buf.append("        	}\n");
5866
		buf.append("        }\n");
5867
		buf.append("    }\n\n");
5868
		buf.append("    public void foo2() {\n");
5869
		buf.append("        List<String> strs= new ArrayList<String>;\n");
5870
		buf.append("        for (String s : strs) {\n");
5871
		buf.append("            if (b) {\n");
5872
		buf.append("                System.out.println(\"2\");\n");
5873
		buf.append("        	}\n");
5874
		buf.append("        }\n");
5875
		buf.append("    }\n\n");
5876
		buf.append("    public void foo3() {\n");
5877
		buf.append("        do {\n");
5878
		buf.append("            if (c) {\n");
5879
		buf.append("                System.out.println(\"3\");\n");
5880
		buf.append("        	}\n");
5881
		buf.append("        } while (true)\n");
5882
		buf.append("    }\n\n");
5883
		buf.append("    public void foo4() {\n");
5884
		buf.append("        while (true) {\n");
5885
		buf.append("            if (d) {\n");
5886
		buf.append("                System.out.println(\"4\");\n");
5887
		buf.append("        	}\n");
5888
		buf.append("        }\n");
5889
		buf.append("    }\n");
5890
		buf.append("}\n");
5891
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
5892
5893
		String str= "if (a)";
5894
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5895
		List proposals= collectAssists(context, false);
5896
		assertNumberOfProposals(proposals, 4);
5897
		assertCorrectLabels(proposals);
5898
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5899
5900
		str= "if (b)";
5901
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5902
		proposals= collectAssists(context, false);
5903
		assertNumberOfProposals(proposals, 3);
5904
		assertCorrectLabels(proposals);
5905
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5906
5907
		str= "if (c)";
5908
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5909
		proposals= collectAssists(context, false);
5910
		assertNumberOfProposals(proposals, 3);
5911
		assertCorrectLabels(proposals);
5912
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5913
5914
		str= "if (d)";
5915
		context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
5916
		proposals= collectAssists(context, false);
5917
		assertNumberOfProposals(proposals, 4);
5918
		assertCorrectLabels(proposals);
5919
		assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn);
5920
	}
5638
}
5921
}
(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java (-62 / +2027 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 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 620-628 Link Here
620
		AssistContext context= getCorrectionContext(cu, offset, string.length());
620
		AssistContext context= getCorrectionContext(cu, offset, string.length());
621
		List proposals= collectAssists(context, false);
621
		List proposals= collectAssists(context, false);
622
622
623
		assertNumberOfProposals(proposals, 3);
623
		assertCorrectLabels(proposals);
624
		assertCorrectLabels(proposals);
624
625
625
		String[] expected= new String[2];
626
		String[] expected= new String[3];
626
627
627
		buf= new StringBuffer();
628
		buf= new StringBuffer();
628
		buf.append("package test1;\n");
629
		buf.append("package test1;\n");
Lines 644-649 Link Here
644
		buf.append("    }\n");
645
		buf.append("    }\n");
645
		buf.append("}\n");
646
		buf.append("}\n");
646
		expected[1]= buf.toString();
647
		expected[1]= buf.toString();
648
649
		buf= new StringBuffer();
650
		buf.append("package test1;\n");
651
		buf.append("public class E {\n");
652
		buf.append("    private int[] fField;\n");
653
		buf.append("    private int i;\n");
654
		buf.append("    public void foo() {\n");
655
		buf.append("        i = fField[0];\n");
656
		buf.append("    }\n");
657
		buf.append("}\n");
658
		buf.append("\n");
659
		buf.append("package test1;\n");
660
		buf.append("public class E {\n");
661
		buf.append("    private int[] fField;\n");
662
		buf.append("    public void foo() {\n");
663
		buf.append("        extracted();\n");
664
		buf.append("    }\n");
665
		buf.append("    private void extracted() {\n");
666
		buf.append("        fField[0];\n");
667
		buf.append("    }\n");
668
		buf.append("}\n");
669
		expected[2]= buf.toString();
647
670
648
		assertExpectedExistInProposals(proposals, expected);
671
		assertExpectedExistInProposals(proposals, expected);
649
	}
672
	}
Lines 850-856 Link Here
850
		assertNumberOfProposals(proposals, 5);
873
		assertNumberOfProposals(proposals, 5);
851
		assertCorrectLabels(proposals);
874
		assertCorrectLabels(proposals);
852
875
853
		String[] expecteds= new String[2];
876
		String[] expecteds= new String[5];
854
		
877
		
855
		buf= new StringBuffer();
878
		buf= new StringBuffer();
856
		buf.append("package test1;\n");
879
		buf.append("package test1;\n");
Lines 872-877 Link Here
872
		buf.append("}\n");
895
		buf.append("}\n");
873
		expecteds[1]= buf.toString();
896
		expecteds[1]= buf.toString();
874
		
897
		
898
		buf= new StringBuffer();
899
		buf.append("package test1;\n");
900
		buf.append("public class Timer {\n");
901
		buf.append("    public static void main(String[] args) {\n");
902
		buf.append("        java.util.Timer timer = new java.util.Timer();\n");
903
		buf.append("    }\n");
904
		buf.append("}\n");
905
		expecteds[2]= buf.toString();
906
907
		buf= new StringBuffer();
908
		buf.append("package test1;\n");
909
		buf.append("public class Timer {\n");
910
		buf.append("    public static void main(String[] args) {\n");
911
		buf.append("        java.util.Timer timer = new java.util.Timer();\n");
912
		buf.append("    }\n");
913
		buf.append("}\n");
914
		expecteds[3]= buf.toString();
915
916
		buf= new StringBuffer();
917
		buf.append("package test1;\n");
918
		buf.append("public class Timer {\n");
919
		buf.append("    private static final java.util.Timer TIMER = new java.util.Timer();\n");
920
		buf.append("\n");
921
		buf.append("    public static void main(String[] args) {\n");
922
		buf.append("        new java.util.Timer();\n");
923
		buf.append("    }\n");
924
		buf.append("}\n");
925
		expecteds[4]= buf.toString();
926
875
		assertExpectedExistInProposals(proposals, expecteds);
927
		assertExpectedExistInProposals(proposals, expecteds);
876
	}
928
	}
877
929
Lines 1297-1303 Link Here
1297
		buf.append("}\n");
1349
		buf.append("}\n");
1298
		String ex1= buf.toString();
1350
		String ex1= buf.toString();
1299
1351
1300
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1352
		buf= new StringBuffer();
1353
		buf.append("package test1;\n");
1354
		buf.append("public class E {\n");
1355
		buf.append("    public E() {\n");
1356
		buf.append("        int a = 1;\n");
1357
		buf.append("        int b = 1;\n");
1358
		buf.append("        int i = a + b;\n");
1359
		buf.append("        int d = i;\n");
1360
		buf.append("    }\n");
1361
		buf.append("}\n");
1362
		String ex2= buf.toString();
1363
1364
		buf= new StringBuffer();
1365
		buf.append("package test1;\n");
1366
		buf.append("public class E {\n");
1367
		buf.append("    public E() {\n");
1368
		buf.append("        int a = 1;\n");
1369
		buf.append("        int b = 1;\n");
1370
		buf.append("        int d = extracted(a, b);\n");
1371
		buf.append("    }\n");
1372
		buf.append("\n");
1373
		buf.append("    private int extracted(int a, int b) {\n");
1374
		buf.append("        return a + b;\n");
1375
		buf.append("    }\n");
1376
		buf.append("}\n");
1377
		String ex3= buf.toString();
1378
1379
		buf= new StringBuffer();
1380
		buf.append("package test1;\n");
1381
		buf.append("public class E {\n");
1382
		buf.append("    public E() {\n");
1383
		buf.append("        int a = 1;\n");
1384
		buf.append("        int b = 1;\n");
1385
		buf.append("        int d = (a + b);\n");
1386
		buf.append("    }\n");
1387
		buf.append("}\n");
1388
		String ex4= buf.toString();
1389
1390
		buf= new StringBuffer();
1391
		buf.append("package test1;\n");
1392
		buf.append("public class E {\n");
1393
		buf.append("    public E() {\n");
1394
		buf.append("        int a = 1;\n");
1395
		buf.append("        int b = 1;\n");
1396
		buf.append("        int d = b + a;\n");
1397
		buf.append("    }\n");
1398
		buf.append("}\n");
1399
		String ex5= buf.toString();
1400
1401
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4, ex5 });
1301
	}
1402
	}
1302
1403
1303
	public void testExtractToLocalVariable2() throws Exception {
1404
	public void testExtractToLocalVariable2() throws Exception {
Lines 1336-1342 Link Here
1336
		buf.append("}\n");
1437
		buf.append("}\n");
1337
		String ex1= buf.toString();
1438
		String ex1= buf.toString();
1338
1439
1339
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1440
		buf= new StringBuffer();
1441
		buf.append("package test1;\n");
1442
		buf.append("public class E {\n");
1443
		buf.append("    public E() {\n");
1444
		buf.append("        int a = 1;\n");
1445
		buf.append("        int b = 1;\n");
1446
		buf.append("        int c = 1;\n");
1447
		buf.append("        int i = b + c;\n");
1448
		buf.append("        int d = a + i;\n");
1449
		buf.append("    }\n");
1450
		buf.append("}\n");
1451
		String ex2= buf.toString();
1452
1453
		buf= new StringBuffer();
1454
		buf.append("package test1;\n");
1455
		buf.append("public class E {\n");
1456
		buf.append("    public E() {\n");
1457
		buf.append("        int a = 1;\n");
1458
		buf.append("        int b = 1;\n");
1459
		buf.append("        int c = 1;\n");
1460
		buf.append("        int d = c + a + b;\n");
1461
		buf.append("    }\n");
1462
		buf.append("}\n");
1463
		String ex3= buf.toString();
1464
1465
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3 });
1340
	}
1466
	}
1341
1467
1342
	public void testExtractToLocalVariable3() throws Exception {
1468
	public void testExtractToLocalVariable3() throws Exception {
Lines 1377-1383 Link Here
1377
		buf.append("}\n");
1503
		buf.append("}\n");
1378
		String ex1= buf.toString();
1504
		String ex1= buf.toString();
1379
1505
1380
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1506
		buf= new StringBuffer();
1507
		buf.append("package test1;\n");
1508
		buf.append("public class E {\n");
1509
		buf.append("    public E() {\n");
1510
		buf.append("        int a = 1;\n");
1511
		buf.append("        int b = 1;\n");
1512
		buf.append("        int c = 1;\n");
1513
		buf.append("        int i = b + c;\n");
1514
		buf.append("        int d = a + i;\n");
1515
		buf.append("        int e = a + b + c;\n");
1516
		buf.append("    }\n");
1517
		buf.append("}\n");
1518
		String ex2= buf.toString();
1519
1520
		buf= new StringBuffer();
1521
		buf.append("package test1;\n");
1522
		buf.append("public class E {\n");
1523
		buf.append("    public E() {\n");
1524
		buf.append("        int a = 1;\n");
1525
		buf.append("        int b = 1;\n");
1526
		buf.append("        int c = 1;\n");
1527
		buf.append("        int d = c + a + b;\n");
1528
		buf.append("        int e = a + b + c;\n");
1529
		buf.append("    }\n");
1530
		buf.append("}\n");
1531
		String ex3= buf.toString();
1532
1533
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3 });
1381
	}
1534
	}
1382
1535
1383
	public void testExtractToMethod1() throws Exception {
1536
	public void testExtractToMethod1() throws Exception {
Lines 1417-1423 Link Here
1417
		buf.append("}\n");
1570
		buf.append("}\n");
1418
		String ex1= buf.toString();
1571
		String ex1= buf.toString();
1419
1572
1420
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1573
		buf= new StringBuffer();
1574
		buf.append("package test1;\n");
1575
		buf.append("public class E {\n");
1576
		buf.append("    public E() {\n");
1577
		buf.append("        int a = 1;\n");
1578
		buf.append("        int b = 1;\n");
1579
		buf.append("        int i = a + b;\n");
1580
		buf.append("        int d = i;\n");
1581
		buf.append("    }\n");
1582
		buf.append("}\n");
1583
		String ex2= buf.toString();
1584
1585
		buf= new StringBuffer();
1586
		buf.append("package test1;\n");
1587
		buf.append("public class E {\n");
1588
		buf.append("    public E() {\n");
1589
		buf.append("        int a = 1;\n");
1590
		buf.append("        int b = 1;\n");
1591
		buf.append("        int i = a + b;\n");
1592
		buf.append("        int d = i;\n");
1593
		buf.append("    }\n");
1594
		buf.append("}\n");
1595
		String ex3= buf.toString();
1596
1597
		buf= new StringBuffer();
1598
		buf.append("package test1;\n");
1599
		buf.append("public class E {\n");
1600
		buf.append("    public E() {\n");
1601
		buf.append("        int a = 1;\n");
1602
		buf.append("        int b = 1;\n");
1603
		buf.append("        int d = (a + b);\n");
1604
		buf.append("    }\n");
1605
		buf.append("}\n");
1606
		String ex4= buf.toString();
1607
1608
		buf= new StringBuffer();
1609
		buf.append("package test1;\n");
1610
		buf.append("public class E {\n");
1611
		buf.append("    public E() {\n");
1612
		buf.append("        int a = 1;\n");
1613
		buf.append("        int b = 1;\n");
1614
		buf.append("        int d = b + a;\n");
1615
		buf.append("    }\n");
1616
		buf.append("}\n");
1617
		String ex5= buf.toString();
1618
1619
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4, ex5 });
1421
	}
1620
	}
1422
1621
1423
	public void testExtractToMethod2() throws Exception {
1622
	public void testExtractToMethod2() throws Exception {
Lines 1457-1463 Link Here
1457
		buf.append("}\n");
1656
		buf.append("}\n");
1458
		String ex1= buf.toString();
1657
		String ex1= buf.toString();
1459
1658
1460
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1659
		buf= new StringBuffer();
1660
		buf.append("package test1;\n");
1661
		buf.append("public class E {\n");
1662
		buf.append("    void foo() {\n");
1663
		buf.append("        int a = 1;\n");
1664
		buf.append("        final int b = 1;\n");
1665
		buf.append("        final int d = a + b;\n");
1666
		buf.append("    }\n");
1667
		buf.append("}\n");
1668
		String ex2= buf.toString();
1669
1670
		buf= new StringBuffer();
1671
		String ex3= null; // Wrap in buf.append() (to clipboard)
1672
1673
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3 });
1461
	}
1674
	}
1462
1675
1463
	public void testExtractToMethod3() throws Exception {
1676
	public void testExtractToMethod3() throws Exception {
Lines 1497-1503 Link Here
1497
		buf.append("}\n");
1710
		buf.append("}\n");
1498
		String ex1= buf.toString();
1711
		String ex1= buf.toString();
1499
1712
1500
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1713
		buf= new StringBuffer();
1714
		buf.append("package test1;\n");
1715
		buf.append("public class E {\n");
1716
		buf.append("    void foo() {\n");
1717
		buf.append("        final int a = 1;\n");
1718
		buf.append("        final int b = 1;\n");
1719
		buf.append("        final int d = a + b;\n");
1720
		buf.append("    }\n");
1721
		buf.append("}\n");
1722
		String ex2= buf.toString();
1723
1724
		buf= new StringBuffer();
1725
		String ex3= null; // Wrap in buf.append() (to clipboard)
1726
1727
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3 });
1501
	}
1728
	}
1502
1729
1503
	public void testExtractToMethod4() throws Exception {
1730
	public void testExtractToMethod4() throws Exception {
Lines 1540-1546 Link Here
1540
		buf.append("}\n");
1767
		buf.append("}\n");
1541
		String ex1= buf.toString();
1768
		String ex1= buf.toString();
1542
1769
1543
		assertExpectedExistInProposals(proposals, new String[] { ex1 });
1770
		buf= new StringBuffer();
1771
		buf.append("package test1;\n");
1772
		buf.append("public class E {\n");
1773
		buf.append("    void foo() {\n");
1774
		buf.append("        int i = 0;\n");
1775
		buf.append("        for (; true;) {\n");
1776
		buf.append("            int j = i++;\n");
1777
		buf.append("        }\n");
1778
		buf.append("    }\n");
1779
		buf.append("}\n");
1780
		String ex2= buf.toString();
1781
1782
		buf= new StringBuffer();
1783
		buf.append("package test1;\n");
1784
		buf.append("public class E {\n");
1785
		buf.append("    private int j;\n");
1786
		buf.append("\n");
1787
		buf.append("    void foo() {\n");
1788
		buf.append("        int i = 0;\n");
1789
		buf.append("        for (; true;)\n");
1790
		buf.append("            j = i++;\n");
1791
		buf.append("    }\n");
1792
		buf.append("}\n");
1793
		String ex3= buf.toString();
1794
1795
		buf= new StringBuffer();
1796
		buf.append("package test1;\n");
1797
		buf.append("public class E {\n");
1798
		buf.append("    void foo() {\n");
1799
		buf.append("        int i = 0;\n");
1800
		buf.append("        for (; true;) {\n");
1801
		buf.append("            i++;\n");
1802
		buf.append("        }\n");
1803
		buf.append("    }\n");
1804
		buf.append("}\n");
1805
		String ex4= buf.toString();
1806
1807
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4 });
1544
	}
1808
	}
1545
1809
1546
	public void testReplaceCatchClauseWithThrowsWithFinally() throws Exception {
1810
	public void testReplaceCatchClauseWithThrowsWithFinally() throws Exception {
Lines 1705-1710 Link Here
1705
		buf.append("    }\n");
1969
		buf.append("    }\n");
1706
		buf.append("}\n");
1970
		buf.append("}\n");
1707
		assertEqualString(preview, buf.toString());
1971
		assertEqualString(preview, buf.toString());
1972
1973
		proposal= (CUCorrectionProposal)proposals.get(1);
1974
		preview= getPreviewContent(proposal);
1975
1976
		buf= new StringBuffer();
1977
		buf.append("package test1;\n");
1978
		buf.append("public class E {\n");
1979
		buf.append("    public void foo() {\n");
1980
		buf.append("        for (int i= 0; i < 3; i++)\n");
1981
		buf.append("            goo();\n");
1982
		buf.append("    }\n");
1983
		buf.append("}\n");
1984
		assertEqualString(preview, buf.toString());
1708
	}
1985
	}
1709
1986
1710
	public void testUnwrapDoStatement() throws Exception {
1987
	public void testUnwrapDoStatement() throws Exception {
Lines 1802-1808 Link Here
1802
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
2079
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
1803
		List proposals= collectAssists(context, false);
2080
		List proposals= collectAssists(context, false);
1804
2081
1805
		assertNumberOfProposals(proposals, 3);
2082
		assertNumberOfProposals(proposals, 4);
1806
		assertCorrectLabels(proposals);
2083
		assertCorrectLabels(proposals);
1807
2084
1808
		CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
2085
		CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
Lines 1838-1844 Link Here
1838
		buf.append("}\n");
2115
		buf.append("}\n");
1839
		String expected2= buf.toString();
2116
		String expected2= buf.toString();
1840
2117
1841
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
2118
		proposal= (CUCorrectionProposal)proposals.get(2);
2119
		String preview3= getPreviewContent(proposal);
2120
2121
		buf= new StringBuffer();
2122
		buf.append("package test1;\n");
2123
		buf.append("public class E {\n");
2124
		buf.append("    public void foo() {\n");
2125
		buf.append("        if (1+ 3 != 6)\n");
2126
		buf.append("            return;\n");
2127
		buf.append("        StringBuffer buf= new StringBuffer();\n");
2128
		buf.append("        buf.append(1);\n");
2129
		buf.append("        buf.append(2);\n");
2130
		buf.append("        buf.append(3);\n");
2131
		buf.append("    }\n");
2132
		buf.append("}\n");
2133
		String expected3= buf.toString();
2134
2135
		proposal= (CUCorrectionProposal)proposals.get(3);
2136
		String preview4= getPreviewContent(proposal);
2137
2138
		buf= new StringBuffer();
2139
		buf.append("package test1;\n");
2140
		buf.append("public class E {\n");
2141
		buf.append("    public void foo() {\n");
2142
		buf.append("        switch (6) {\n");
2143
		buf.append("            case 1+ 3 :\n");
2144
		buf.append("                StringBuffer buf= new StringBuffer();\n");
2145
		buf.append("                buf.append(1);\n");
2146
		buf.append("                buf.append(2);\n");
2147
		buf.append("                buf.append(3);\n");
2148
		buf.append("                break;\n");
2149
		buf.append("        }\n");
2150
		buf.append("    }\n");
2151
		buf.append("}\n");
2152
		String expected4= buf.toString();
2153
2154
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4 }, new String[] { expected1, expected2, expected3, expected4 });
1842
	}
2155
	}
1843
2156
1844
	public void testUnwrapTryStatement() throws Exception {
2157
	public void testUnwrapTryStatement() throws Exception {
Lines 1973-1978 Link Here
1973
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
2286
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
1974
		List proposals= collectAssists(context, false);
2287
		List proposals= collectAssists(context, false);
1975
2288
2289
		assertNumberOfProposals(proposals, 4);
2290
		assertCorrectLabels(proposals);
2291
1976
		buf= new StringBuffer();
2292
		buf= new StringBuffer();
1977
		buf.append("package test1;\n");
2293
		buf.append("package test1;\n");
1978
		buf.append("public class E {\n");
2294
		buf.append("public class E {\n");
Lines 1982-1988 Link Here
1982
		buf.append("}\n");
2298
		buf.append("}\n");
1983
		String expected1= buf.toString();
2299
		String expected1= buf.toString();
1984
2300
1985
		assertExpectedExistInProposals(proposals, new String[] {expected1});
2301
		buf= new StringBuffer();
2302
		buf.append("package test1;\n");
2303
		buf.append("public class E {\n");
2304
		buf.append("    public int foo() {\n");
2305
		buf.append("        int abs = Math.abs(9+ 8);\n");
2306
		buf.append("        return abs;\n");
2307
		buf.append("    }\n");
2308
		buf.append("}\n");
2309
		String expected2= buf.toString();
2310
2311
		buf= new StringBuffer();
2312
		buf.append("package test1;\n");
2313
		buf.append("public class E {\n");
2314
		buf.append("    public int foo() {\n");
2315
		buf.append("        int abs = Math.abs(9+ 8);\n");
2316
		buf.append("        return abs;\n");
2317
		buf.append("    }\n");
2318
		buf.append("}\n");
2319
		String expected3= buf.toString();
2320
2321
		buf= new StringBuffer();
2322
		buf.append("package test1;\n");
2323
		buf.append("public class E {\n");
2324
		buf.append("    private static final int ABS = Math.abs(9+ 8);\n");
2325
		buf.append("\n");
2326
		buf.append("    public int foo() {\n");
2327
		buf.append("        return ABS;\n");
2328
		buf.append("    }\n");
2329
		buf.append("}\n");
2330
		String expected4= buf.toString();
2331
2332
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
1986
	}
2333
	}
1987
2334
1988
	public void testSplitDeclaration1() throws Exception {
2335
	public void testSplitDeclaration1() throws Exception {
Lines 2077-2083 Link Here
2077
		buf.append("        i = null;\n");
2424
		buf.append("        i = null;\n");
2078
		buf.append("    }\n");
2425
		buf.append("    }\n");
2079
		buf.append("}\n");
2426
		buf.append("}\n");
2080
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2427
		String ex1= buf.toString();
2428
2429
		buf= new StringBuffer();
2430
		buf.append("package test1;\n");
2431
		buf.append("public class E {\n");
2432
		buf.append("    private int is[];\n");
2433
		buf.append("\n");
2434
		buf.append("    public void foo() {\n");
2435
		buf.append("        is = null;\n");
2436
		buf.append("    }\n");
2437
		buf.append("}\n");
2438
		String ex2= buf.toString();
2439
2440
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
2081
	}
2441
	}
2082
2442
2083
	public void testSplitDeclaration4() throws Exception {
2443
	public void testSplitDeclaration4() throws Exception {
Lines 2236-2243 Link Here
2236
		buf.append("        foo();\n");
2596
		buf.append("        foo();\n");
2237
		buf.append("    }\n");
2597
		buf.append("    }\n");
2238
		buf.append("}\n");
2598
		buf.append("}\n");
2599
		String ex1= buf.toString();
2239
2600
2240
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2601
		buf= new StringBuffer();
2602
		buf.append("package test1;\n");
2603
		buf.append("public class E {\n");
2604
		buf.append("    private int vars[];\n");
2605
		buf.append("\n");
2606
		buf.append("    public void foo() {\n");
2607
		buf.append("        foo();\n");
2608
		buf.append("        vars = null;\n");
2609
		buf.append("    }\n");
2610
		buf.append("}\n");
2611
		String ex2= buf.toString();
2612
2613
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
2241
	}
2614
	}
2242
2615
2243
2616
Lines 2258-2263 Link Here
2258
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
2631
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
2259
		List proposals= collectAssists(context, false);
2632
		List proposals= collectAssists(context, false);
2260
2633
2634
		assertNumberOfProposals(proposals, 4);
2261
		assertCorrectLabels(proposals);
2635
		assertCorrectLabels(proposals);
2262
2636
2263
		buf= new StringBuffer();
2637
		buf= new StringBuffer();
Lines 2270-2276 Link Here
2270
		buf.append("}\n");
2644
		buf.append("}\n");
2271
		String expected1= buf.toString();
2645
		String expected1= buf.toString();
2272
2646
2273
		assertExpectedExistInProposals(proposals, new String[] {expected1});
2647
		buf= new StringBuffer();
2648
		buf.append("package test1;\n");
2649
		buf.append("public class E {\n");
2650
		buf.append("    public void foo() {\n");
2651
		buf.append("        int var[];\n");
2652
		buf.append("        foo();\n");
2653
		buf.append("        int[] var2 = var;\n");
2654
		buf.append("        var = null;\n");
2655
		buf.append("    }\n");
2656
		buf.append("}\n");
2657
		String expected2= buf.toString();
2658
2659
		buf= new StringBuffer();
2660
		buf.append("package test1;\n");
2661
		buf.append("public class E {\n");
2662
		buf.append("    public void foo() {\n");
2663
		buf.append("        int var[];\n");
2664
		buf.append("        foo();\n");
2665
		buf.append("        int[] var2 = var;\n");
2666
		buf.append("        var = null;\n");
2667
		buf.append("    }\n");
2668
		buf.append("}\n");
2669
		String expected3= buf.toString();
2670
2671
		buf= new StringBuffer();
2672
		buf.append("package test1;\n");
2673
		buf.append("public class E {\n");
2674
		buf.append("    private int vars[];\n");
2675
		buf.append("\n");
2676
		buf.append("    public void foo() {\n");
2677
		buf.append("        foo();\n");
2678
		buf.append("        vars = null;\n");
2679
		buf.append("    }\n");
2680
		buf.append("}\n");
2681
		String expected4= buf.toString();
2682
2683
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
2274
	}
2684
	}
2275
2685
2276
	public void testJoinDeclaration3() throws Exception {
2686
	public void testJoinDeclaration3() throws Exception {
Lines 2301-2308 Link Here
2301
		buf.append("        foo();\n");
2711
		buf.append("        foo();\n");
2302
		buf.append("    }\n");
2712
		buf.append("    }\n");
2303
		buf.append("}\n");
2713
		buf.append("}\n");
2714
		String ex1= buf.toString();
2304
2715
2305
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2716
		buf= new StringBuffer();
2717
		buf.append("package test1;\n");
2718
		buf.append("public class E {\n");
2719
		buf.append("    public void foo() {\n");
2720
		buf.append("        int var[];\n");
2721
		buf.append("        var = null;\n");
2722
		buf.append("        foo();\n");
2723
		buf.append("        var = new int[10];\n");
2724
		buf.append("    }\n");
2725
		buf.append("}\n");
2726
		String ex2= buf.toString();
2727
2728
		buf= new StringBuffer();
2729
		buf.append("package test1;\n");
2730
		buf.append("public class E {\n");
2731
		buf.append("    private int vars[];\n");
2732
		buf.append("\n");
2733
		buf.append("    public void foo() {\n");
2734
		buf.append("        vars = null;\n");
2735
		buf.append("        foo();\n");
2736
		buf.append("        vars = new int[10];\n");
2737
		buf.append("    }\n");
2738
		buf.append("}\n");
2739
		String ex3= buf.toString();
2740
2741
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3 });
2306
	}
2742
	}
2307
2743
2308
	public void testJoinDeclaration4() throws Exception {
2744
	public void testJoinDeclaration4() throws Exception {
Lines 2345-2352 Link Here
2345
		buf.append("        // 3;\n");
2781
		buf.append("        // 3;\n");
2346
		buf.append("    }\n");
2782
		buf.append("    }\n");
2347
		buf.append("}\n");
2783
		buf.append("}\n");
2784
		String ex1= buf.toString();
2785
2786
		buf= new StringBuffer();
2787
		buf.append("package test1;\n");
2788
		buf.append("public class E {\n");
2789
		buf.append("    private String message;\n");
2790
		buf.append("\n");
2791
		buf.append("    public void foo() {\n");
2792
		buf.append("        // 1;\n");
2793
		buf.append("        \n");
2794
		buf.append("        \n");
2795
		buf.append("        \n");
2796
		buf.append("        // 2;\n");
2797
		buf.append("        \n");
2798
		buf.append("        message = \"\";\n");
2799
		buf.append("        \n");
2800
		buf.append("        // 3;\n");
2801
		buf.append("    }\n");
2802
		buf.append("}\n");
2803
		String ex2= buf.toString();
2348
		
2804
		
2349
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2805
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
2350
	}
2806
	}
2351
	
2807
	
2352
	public void testJoinDeclaration5() throws Exception {
2808
	public void testJoinDeclaration5() throws Exception {
Lines 2390-2397 Link Here
2390
		buf.append("        // 3;\n");
2846
		buf.append("        // 3;\n");
2391
		buf.append("    }\n");
2847
		buf.append("    }\n");
2392
		buf.append("}\n");
2848
		buf.append("}\n");
2849
		String ex1= buf.toString();
2850
2851
		buf= new StringBuffer();
2852
		buf.append("package test1;\n");
2853
		buf.append("public class E {\n");
2854
		buf.append("    public void foo() {\n");
2855
		buf.append("        // 1;\n");
2856
		buf.append("        \n");
2857
		buf.append("        String message;\n");
2858
		buf.append("        \n");
2859
		buf.append("        // 2;\n");
2860
		buf.append("        \n");
2861
		buf.append("        String message2 = message;\n");
2862
		buf.append("        message = \"\";\n");
2863
		buf.append("        \n");
2864
		buf.append("        // 3;\n");
2865
		buf.append("    }\n");
2866
		buf.append("}\n");
2867
		String ex2= buf.toString();
2868
2869
		buf= new StringBuffer();
2870
		buf.append("package test1;\n");
2871
		buf.append("public class E {\n");
2872
		buf.append("    public void foo() {\n");
2873
		buf.append("        // 1;\n");
2874
		buf.append("        \n");
2875
		buf.append("        String message;\n");
2876
		buf.append("        \n");
2877
		buf.append("        // 2;\n");
2878
		buf.append("        \n");
2879
		buf.append("        String message2 = message;\n");
2880
		buf.append("        message = \"\";\n");
2881
		buf.append("        \n");
2882
		buf.append("        // 3;\n");
2883
		buf.append("    }\n");
2884
		buf.append("}\n");
2885
		String ex3= buf.toString();
2886
2887
		buf= new StringBuffer();
2888
		buf.append("package test1;\n");
2889
		buf.append("public class E {\n");
2890
		buf.append("    private String message;\n");
2891
		buf.append("\n");
2892
		buf.append("    public void foo() {\n");
2893
		buf.append("        // 1;\n");
2894
		buf.append("        \n");
2895
		buf.append("        \n");
2896
		buf.append("        \n");
2897
		buf.append("        // 2;\n");
2898
		buf.append("        \n");
2899
		buf.append("        message = \"\";\n");
2900
		buf.append("        \n");
2901
		buf.append("        // 3;\n");
2902
		buf.append("    }\n");
2903
		buf.append("}\n");
2904
		String ex4= buf.toString();
2393
		
2905
		
2394
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2906
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4 });
2395
	}
2907
	}
2396
	
2908
	
2397
	private static final Class[] FILTER_EQ= { LinkedNamesAssistProposal.class, RenameRefactoringProposal.class, AssignToVariableAssistProposal.class };
2909
	private static final Class[] FILTER_EQ= { LinkedNamesAssistProposal.class, RenameRefactoringProposal.class, AssignToVariableAssistProposal.class };
Lines 2473-2486 Link Here
2473
        buf.append("        \"a\".equals(s);\n");
2985
        buf.append("        \"a\".equals(s);\n");
2474
        buf.append("    }\n");
2986
        buf.append("    }\n");
2475
        buf.append("}\n");
2987
        buf.append("}\n");
2476
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
2988
		String ex1= buf.toString();
2477
2989
2478
        cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null);
2990
		buf= new StringBuffer();
2991
		buf.append("package test1;\n");
2992
		buf.append("public class E {\n");
2993
		buf.append("    public void foo() {\n");
2994
		buf.append("        String s= \"a\";\n");
2995
		buf.append("        boolean equals = s.equals(\"a\");\n");
2996
		buf.append("    }\n");
2997
		buf.append("}\n");
2998
		String ex2= buf.toString();
2999
3000
		buf= new StringBuffer();
3001
		buf.append("package test1;\n");
3002
		buf.append("public class E {\n");
3003
		buf.append("    public void foo() {\n");
3004
		buf.append("        String s= \"a\";\n");
3005
		buf.append("        boolean equals = s.equals(\"a\");\n");
3006
		buf.append("    }\n");
3007
		buf.append("}\n");
3008
		String ex3= buf.toString();
3009
3010
		buf= new StringBuffer();
3011
		buf.append("package test1;\n");
3012
		buf.append("public class E {\n");
3013
		buf.append("    public void foo() {\n");
3014
		buf.append("        String s= \"a\";\n");
3015
		buf.append("        extracted(s);\n");
3016
		buf.append("    }\n");
3017
		buf.append("\n");
3018
		buf.append("    private boolean extracted(String s) {\n");
3019
		buf.append("        return s.equals(\"a\");\n");
3020
		buf.append("    }\n");
3021
		buf.append("}\n");
3022
		String ex4= buf.toString();
3023
3024
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4 });
3025
3026
		cu= pack1.createCompilationUnit("E.java", ex1, true, null);
2479
        str= "\"a\".equals(s)";
3027
        str= "\"a\".equals(s)";
2480
        context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
3028
		context= getCorrectionContext(cu, ex1.indexOf(str), 0);
2481
        proposals= collectAssists(context, FILTER_EQ);
3029
        proposals= collectAssists(context, FILTER_EQ);
2482
3030
2483
        assertNumberOfProposals(proposals, 5);
3031
		assertNumberOfProposals(proposals, 5);
2484
        assertCorrectLabels(proposals);
3032
        assertCorrectLabels(proposals);
2485
3033
2486
        buf= new StringBuffer();
3034
        buf= new StringBuffer();
Lines 2491-2497 Link Here
2491
        buf.append("        s.equals(\"a\");\n");
3039
        buf.append("        s.equals(\"a\");\n");
2492
        buf.append("    }\n");
3040
        buf.append("    }\n");
2493
        buf.append("}\n");
3041
        buf.append("}\n");
2494
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
3042
		ex1= buf.toString();
3043
3044
		buf= new StringBuffer();
3045
		buf.append("package test1;\n");
3046
		buf.append("public class E {\n");
3047
		buf.append("    public void foo() {\n");
3048
		buf.append("        String string = \"a\";\n");
3049
		buf.append("        String s= string;\n");
3050
		buf.append("        string.equals(s);\n");
3051
		buf.append("    }\n");
3052
		buf.append("}\n");
3053
		ex2= buf.toString();
3054
3055
		buf= new StringBuffer();
3056
		buf.append("package test1;\n");
3057
		buf.append("public class E {\n");
3058
		buf.append("    public void foo() {\n");
3059
		buf.append("        String s= \"a\";\n");
3060
		buf.append("        String string = \"a\";\n");
3061
		buf.append("        string.equals(s);\n");
3062
		buf.append("    }\n");
3063
		buf.append("}\n");
3064
		ex3= buf.toString();
3065
3066
		buf= new StringBuffer();
3067
		buf.append("package test1;\n");
3068
		buf.append("public class E {\n");
3069
		buf.append("    private static final String A = \"a\";\n");
3070
		buf.append("\n");
3071
		buf.append("    public void foo() {\n");
3072
		buf.append("        String s= A;\n");
3073
		buf.append("        A.equals(s);\n");
3074
		buf.append("    }\n");
3075
		buf.append("}\n");
3076
		ex4= buf.toString();
3077
3078
		buf= new StringBuffer();
3079
		buf.append("package test1;\n");
3080
		buf.append("public class E {\n");
3081
		buf.append("    public void foo() {\n");
3082
		buf.append("        String s= \"a\";\n");
3083
		buf.append("        \"A\".equals(s);\n");
3084
		buf.append("    }\n");
3085
		buf.append("}\n");
3086
		String ex5= buf.toString();
3087
3088
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4, ex5 });
2495
    }
3089
    }
2496
3090
2497
    public void testInvertEquals3() throws Exception {
3091
    public void testInvertEquals3() throws Exception {
Lines 2822-2831 Link Here
2822
        buf.append("        return \"a\";\n");
3416
        buf.append("        return \"a\";\n");
2823
        buf.append("    }\n");
3417
        buf.append("    }\n");
2824
        buf.append("}\n");
3418
        buf.append("}\n");
2825
        assertEqualString(preview, buf.toString());
3419
		String ex1= buf.toString();
3420
		assertEqualString(preview, ex1);
2826
3421
2827
        cu= pack1.createCompilationUnit("E.java", buf.toString(), true, null);
3422
		proposal= (CUCorrectionProposal)proposals.get(1);
2828
        context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
3423
		preview= getPreviewContent(proposal);
3424
3425
		buf= new StringBuffer();
3426
		buf.append("package test1;\n");
3427
		buf.append("public class E {\n");
3428
		buf.append("    public void foo() {\n");
3429
		buf.append("        boolean x = (false && \"a\".equals(get()));\n");
3430
		buf.append("    }\n");
3431
		buf.append("    String get() {\n");
3432
		buf.append("        return \"a\";\n");
3433
		buf.append("    }\n");
3434
		buf.append("}\n");
3435
		String ex2= buf.toString();
3436
		assertEqualString(preview, ex2);
3437
3438
		cu= pack1.createCompilationUnit("E.java", ex1, true, null);
3439
		context= getCorrectionContext(cu, ex1.indexOf(str), 0);
2829
        proposals= collectAssists(context, FILTER_EQ);
3440
        proposals= collectAssists(context, FILTER_EQ);
2830
3441
2831
		assertNumberOfProposals(proposals, 2);
3442
		assertNumberOfProposals(proposals, 2);
Lines 2845-2850 Link Here
2845
        buf.append("    }\n");
3456
        buf.append("    }\n");
2846
        buf.append("}\n");
3457
        buf.append("}\n");
2847
        assertEqualString(preview, buf.toString());
3458
        assertEqualString(preview, buf.toString());
3459
3460
		proposal= (CUCorrectionProposal)proposals.get(1);
3461
		preview= getPreviewContent(proposal);
3462
3463
		buf= new StringBuffer();
3464
		buf.append("package test1;\n");
3465
		buf.append("public class E {\n");
3466
		buf.append("    public void foo() {\n");
3467
		buf.append("        boolean x = (false && get().equals(\"a\"));\n");
3468
		buf.append("    }\n");
3469
		buf.append("    String get() {\n");
3470
		buf.append("        return \"a\";\n");
3471
		buf.append("    }\n");
3472
		buf.append("}\n");
3473
		assertEqualString(preview, buf.toString());
2848
    }
3474
    }
2849
3475
2850
    public void testInvertEquals9() throws Exception {
3476
    public void testInvertEquals9() throws Exception {
Lines 3650-3656 Link Here
3650
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
4276
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
3651
		List proposals= collectAssists(context, false);
4277
		List proposals= collectAssists(context, false);
3652
4278
3653
		assertNumberOfProposals(proposals, 3);
4279
		assertNumberOfProposals(proposals, 4);
3654
		assertCorrectLabels(proposals);
4280
		assertCorrectLabels(proposals);
3655
4281
3656
		buf= new StringBuffer();
4282
		buf= new StringBuffer();
Lines 3685-3691 Link Here
3685
		buf.append("}\n");
4311
		buf.append("}\n");
3686
		String expected3= buf.toString();
4312
		String expected3= buf.toString();
3687
4313
3688
		assertExpectedExistInProposals(proposals, new String[] {expected1, expected2, expected3});
4314
		buf= new StringBuffer();
4315
		buf.append("package test1;\n");
4316
		buf.append("public class E {\n");
4317
		buf.append("    public void foo() {\n");
4318
		buf.append("        if (false)\n");
4319
		buf.append("            return;\n");
4320
		buf.append("        ;\n");
4321
		buf.append("    }\n");
4322
		buf.append("}\n");
4323
		String expected4= buf.toString();
4324
4325
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
3689
	}
4326
	}
3690
4327
3691
	public void testChangeElseStatementToBlock() throws Exception {
4328
	public void testChangeElseStatementToBlock() throws Exception {
Lines 4095-4101 Link Here
4095
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
4732
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0);
4096
		List proposals= collectAssists(context, false);
4733
		List proposals= collectAssists(context, false);
4097
4734
4098
		assertNumberOfProposals(proposals, 3);
4735
		assertNumberOfProposals(proposals, 4);
4099
		assertCorrectLabels(proposals);
4736
		assertCorrectLabels(proposals);
4100
4737
4101
		buf= new StringBuffer();
4738
		buf= new StringBuffer();
Lines 4129-4135 Link Here
4129
		buf.append("}\n");
4766
		buf.append("}\n");
4130
		String expected3= buf.toString();
4767
		String expected3= buf.toString();
4131
4768
4132
		assertExpectedExistInProposals(proposals, new String[] {expected1, expected2, expected3});
4769
		buf= new StringBuffer();
4770
		buf.append("package test1;\n");
4771
		buf.append("public class E {\n");
4772
		buf.append("    public void foo() {\n");
4773
		buf.append("        if (false)\n");
4774
		buf.append("            return;\n");
4775
		buf.append("        ;\n");
4776
		buf.append("    }\n");
4777
		buf.append("}\n");
4778
		String expected4= buf.toString();
4779
4780
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
4133
	}
4781
	}
4134
4782
4135
	public void testRemoveIfBlock02() throws Exception {
4783
	public void testRemoveIfBlock02() throws Exception {
Lines 4291-4296 Link Here
4291
		AssistContext context= getCorrectionContext(cu, indexOf, 0);
4939
		AssistContext context= getCorrectionContext(cu, indexOf, 0);
4292
		List proposals= collectAssists(context, false);
4940
		List proposals= collectAssists(context, false);
4293
4941
4942
		assertNumberOfProposals(proposals, 4);
4294
		assertCorrectLabels(proposals);
4943
		assertCorrectLabels(proposals);
4295
4944
4296
		buf= new StringBuffer();
4945
		buf= new StringBuffer();
Lines 4305-4311 Link Here
4305
		buf.append("}\n");
4954
		buf.append("}\n");
4306
		String expected1= buf.toString();
4955
		String expected1= buf.toString();
4307
4956
4308
		assertExpectedExistInProposals(proposals, new String[] {expected1});
4957
		buf= new StringBuffer();
4958
		buf.append("package test1;\n");
4959
		buf.append("public class E {\n");
4960
		buf.append("    public int foo() {\n");
4961
		buf.append("        if (true) {\n");
4962
		buf.append("            return 1; /* comment*/\n");
4963
		buf.append("        } else {\n");
4964
		buf.append("            return 2;\n");
4965
		buf.append("        }\n");
4966
		buf.append("    }\n");
4967
		buf.append("}\n");
4968
		String expected2= buf.toString();
4969
		
4970
		buf= new StringBuffer();
4971
		buf.append("package test1;\n");
4972
		buf.append("public class E {\n");
4973
		buf.append("    public int foo() {\n");
4974
		buf.append("        if (false)\n");
4975
		buf.append("            return 2;\n");
4976
		buf.append("        else\n");
4977
		buf.append("            return 1; /* comment*/\n");
4978
		buf.append("    }\n");
4979
		buf.append("}\n");
4980
		String expected3= buf.toString();
4981
		
4982
		buf= new StringBuffer();
4983
		buf.append("package test1;\n");
4984
		buf.append("public class E {\n");
4985
		buf.append("    public int foo() {\n");
4986
		buf.append("        return true ? 1 : 2;\n");
4987
		buf.append("    }\n");
4988
		buf.append("}\n");
4989
		String expected4= buf.toString();
4990
		
4991
		assertExpectedExistInProposals(proposals, new String[] {expected1, expected2, expected3, expected4});
4309
	}
4992
	}
4310
4993
4311
4994
Lines 4746-4751 Link Here
4746
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5429
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4747
		List proposals= collectAssists(context, false);
5430
		List proposals= collectAssists(context, false);
4748
5431
5432
		assertNumberOfProposals(proposals, 2);
4749
		assertCorrectLabels(proposals);
5433
		assertCorrectLabels(proposals);
4750
5434
4751
		buf= new StringBuffer();
5435
		buf= new StringBuffer();
Lines 4758-4764 Link Here
4758
		buf.append("}\n");
5442
		buf.append("}\n");
4759
		String expected1= buf.toString();
5443
		String expected1= buf.toString();
4760
5444
4761
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
5445
		String expected2= null; // Wrap in buf.append() (to clipboard)
5446
5447
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 });
4762
	}
5448
	}
4763
5449
4764
	public void testMakeFinal02() throws Exception {
5450
	public void testMakeFinal02() throws Exception {
Lines 4778-4784 Link Here
4778
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5464
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4779
		List proposals= collectAssists(context, false);
5465
		List proposals= collectAssists(context, false);
4780
5466
5467
		assertNumberOfProposals(proposals, 1);
4781
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5468
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5469
5470
		buf= new StringBuffer();
5471
		String expected1= null; // Wrap in buf.append() (to clipboard)
5472
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
4782
	}
5473
	}
4783
5474
4784
	public void testMakeFinal03() throws Exception {
5475
	public void testMakeFinal03() throws Exception {
Lines 4797-4803 Link Here
4797
		AssistContext context= getCorrectionContext(cu, offset, 1);
5488
		AssistContext context= getCorrectionContext(cu, offset, 1);
4798
		List proposals= collectAssists(context, false);
5489
		List proposals= collectAssists(context, false);
4799
5490
5491
		assertNumberOfProposals(proposals, 1);
4800
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5492
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5493
5494
		buf= new StringBuffer();
5495
		buf.append("package test;\n");
5496
		buf.append("public class E {\n");
5497
		buf.append("    private int i= 0;\n");
5498
		buf.append("    private void foo() {\n");
5499
		buf.append("        System.out.println(getI());\n");
5500
		buf.append("    }\n");
5501
		buf.append("    public int getI() {\n");
5502
		buf.append("        return i;\n");
5503
		buf.append("    }\n");
5504
		buf.append("    public void setI(int i) {\n");
5505
		buf.append("        this.i = i;\n");
5506
		buf.append("    }\n");
5507
		buf.append("}\n");
5508
		String expected1= buf.toString();
5509
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
4801
	}
5510
	}
4802
5511
4803
	public void testMakeFinal04() throws Exception {
5512
	public void testMakeFinal04() throws Exception {
Lines 4883-4889 Link Here
4883
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5592
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4884
		List proposals= collectAssists(context, false);
5593
		List proposals= collectAssists(context, false);
4885
5594
5595
		assertNumberOfProposals(proposals, 1);
4886
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5596
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5597
5598
		assertExpectedExistInProposals(proposals, new String[] { null }); // Wrap in buf.append() (to clipboard)
4887
	}
5599
	}
4888
5600
4889
	public void testMakeFinal07() throws Exception {
5601
	public void testMakeFinal07() throws Exception {
Lines 4906-4911 Link Here
4906
		AssistContext context= getCorrectionContext(cu, offset, length);
5618
		AssistContext context= getCorrectionContext(cu, offset, length);
4907
		List proposals= collectAssists(context, false);
5619
		List proposals= collectAssists(context, false);
4908
5620
5621
		assertNumberOfProposals(proposals, 0);
4909
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5622
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
4910
	}
5623
	}
4911
5624
Lines 4929-4935 Link Here
4929
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5642
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4930
		List proposals= collectAssists(context, false);
5643
		List proposals= collectAssists(context, false);
4931
5644
5645
		assertNumberOfProposals(proposals, 1);
4932
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5646
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5647
5648
		assertExpectedExistInProposals(proposals, new String[] { null }); // Wrap in buf.append() (to clipboard)
4933
	}
5649
	}
4934
5650
4935
	public void testMakeFinal09() throws Exception {
5651
	public void testMakeFinal09() throws Exception {
Lines 4952-4958 Link Here
4952
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5668
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4953
		List proposals= collectAssists(context, false);
5669
		List proposals= collectAssists(context, false);
4954
5670
5671
		assertNumberOfProposals(proposals, 1);
4955
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5672
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5673
5674
		assertExpectedExistInProposals(proposals, new String[] { null }); // Wrap in buf.append() (to clipboard)
4956
	}
5675
	}
4957
5676
4958
	public void testMakeFinal10() throws Exception {
5677
	public void testMakeFinal10() throws Exception {
Lines 4975-4981 Link Here
4975
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5694
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4976
		List proposals= collectAssists(context, false);
5695
		List proposals= collectAssists(context, false);
4977
5696
5697
		assertNumberOfProposals(proposals, 1);
4978
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5698
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5699
5700
		assertExpectedExistInProposals(proposals, new String[] { null }); // Wrap in buf.append() (to clipboard)
4979
	}
5701
	}
4980
5702
4981
	public void testMakeFinal11() throws Exception {
5703
	public void testMakeFinal11() throws Exception {
Lines 4996-5002 Link Here
4996
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5718
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
4997
		List proposals= collectAssists(context, false);
5719
		List proposals= collectAssists(context, false);
4998
5720
5721
		assertNumberOfProposals(proposals, 1);
4999
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5722
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5723
5724
		assertExpectedExistInProposals(proposals, new String[] { null }); // Wrap in buf.append() (to clipboard)
5000
	}
5725
	}
5001
5726
5002
	public void testMakeFinal12() throws Exception {
5727
	public void testMakeFinal12() throws Exception {
Lines 5069-5075 Link Here
5069
		buf.append("        System.out.println(h);\n");
5794
		buf.append("        System.out.println(h);\n");
5070
		buf.append("    }\n");
5795
		buf.append("    }\n");
5071
		buf.append("}\n");
5796
		buf.append("}\n");
5072
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
5797
		String ex1= buf.toString();
5798
5799
		buf= new StringBuffer();
5800
		buf.append("package test;\n");
5801
		buf.append("public class E {\n");
5802
		buf.append("    public void foo() {\n");
5803
		buf.append("        int i= 1, j, h= j + 1;\n");
5804
		buf.append("        j = i + 1;\n");
5805
		buf.append("        System.out.println(i);\n");
5806
		buf.append("        System.out.println(j);\n");
5807
		buf.append("        System.out.println(h);\n");
5808
		buf.append("    }\n");
5809
		buf.append("}\n");
5810
		String ex2= buf.toString();
5811
5812
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
5073
	}
5813
	}
5074
5814
5075
	public void testMakeFinal14() throws Exception {
5815
	public void testMakeFinal14() throws Exception {
Lines 5105-5111 Link Here
5105
		buf.append("        System.out.println(h);\n");
5845
		buf.append("        System.out.println(h);\n");
5106
		buf.append("    }\n");
5846
		buf.append("    }\n");
5107
		buf.append("}\n");
5847
		buf.append("}\n");
5108
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
5848
		String ex1= buf.toString();
5849
5850
		buf= new StringBuffer();
5851
		buf.append("package test;\n");
5852
		buf.append("public class E {\n");
5853
		buf.append("    public void foo() {\n");
5854
		buf.append("        int i= 1, j= i + 1, h;\n");
5855
		buf.append("        h = j + 1;\n");
5856
		buf.append("        System.out.println(i);\n");
5857
		buf.append("        System.out.println(j);\n");
5858
		buf.append("        System.out.println(h);\n");
5859
		buf.append("    }\n");
5860
		buf.append("}\n");
5861
		String ex2= buf.toString();
5862
5863
		assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
5109
	}
5864
	}
5110
5865
5111
	public void testMakeFinal15() throws Exception {
5866
	public void testMakeFinal15() throws Exception {
Lines 5132-5137 Link Here
5132
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5887
		AssistContext context= getCorrectionContext(cu, offset1, offset2 - offset1);
5133
		List proposals= collectAssists(context, false);
5888
		List proposals= collectAssists(context, false);
5134
5889
5890
		assertNumberOfProposals(proposals, 2);
5135
		assertCorrectLabels(proposals);
5891
		assertCorrectLabels(proposals);
5136
5892
5137
		buf= new StringBuffer();
5893
		buf= new StringBuffer();
Lines 5151-5157 Link Here
5151
		buf.append("}\n");
5907
		buf.append("}\n");
5152
		String expected1= buf.toString();
5908
		String expected1= buf.toString();
5153
5909
5154
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
5910
		String expected2= null; // Wrap in buf.append() (to clipboard)
5911
5912
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 });
5155
	}
5913
	}
5156
5914
5157
	public void testMakeFinal16() throws Exception {
5915
	public void testMakeFinal16() throws Exception {
Lines 5171-5176 Link Here
5171
		AssistContext context= getCorrectionContext(cu, offset, length);
5929
		AssistContext context= getCorrectionContext(cu, offset, length);
5172
		List proposals= collectAssists(context, false);
5930
		List proposals= collectAssists(context, false);
5173
5931
5932
		assertNumberOfProposals(proposals, 0);
5174
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5933
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5175
	}
5934
	}
5176
5935
Lines 5189-5196 Link Here
5189
		int offset= buf.toString().indexOf("i=");
5948
		int offset= buf.toString().indexOf("i=");
5190
		AssistContext context= getCorrectionContext(cu, offset, 1);
5949
		AssistContext context= getCorrectionContext(cu, offset, 1);
5191
		List proposals= collectAssists(context, false);
5950
		List proposals= collectAssists(context, false);
5192
	
5951
5952
		assertNumberOfProposals(proposals, 1);
5193
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5953
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5954
		
5955
		buf= new StringBuffer();
5956
		buf.append("package test;\n");
5957
		buf.append("public class E {\n");
5958
		buf.append("    private int i= 0;\n");
5959
		buf.append("    private void foo() {\n");
5960
		buf.append("        System.out.println(getI());\n");
5961
		buf.append("    }\n");
5962
		buf.append("    public int getI() {\n");
5963
		buf.append("        return i;\n");
5964
		buf.append("    }\n");
5965
		buf.append("    public void setI(int i) {\n");
5966
		buf.append("        this.i = i;\n");
5967
		buf.append("    }\n");
5968
		buf.append("}\n");
5969
		assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
5194
	}
5970
	}
5195
5971
5196
	public void testMakeFinal18() throws Exception {
5972
	public void testMakeFinal18() throws Exception {
Lines 5209-5214 Link Here
5209
		AssistContext context= getCorrectionContext(cu, offset, 1);
5985
		AssistContext context= getCorrectionContext(cu, offset, 1);
5210
		List proposals= collectAssists(context, false);
5986
		List proposals= collectAssists(context, false);
5211
5987
5988
		assertNumberOfProposals(proposals, 0);
5212
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5989
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5213
	}
5990
	}
5214
5991
Lines 5229-5234 Link Here
5229
		AssistContext context= getCorrectionContext(cu, offset, length);
6006
		AssistContext context= getCorrectionContext(cu, offset, length);
5230
		List proposals= collectAssists(context, false);
6007
		List proposals= collectAssists(context, false);
5231
6008
6009
		assertNumberOfProposals(proposals, 0);
5232
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
6010
		assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL);
5233
	}
6011
	}
5234
6012
Lines 5373-5378 Link Here
5373
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
6151
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
5374
		List proposals= collectAssists(context, false);
6152
		List proposals= collectAssists(context, false);
5375
6153
6154
		assertNumberOfProposals(proposals, 7);
5376
		assertCorrectLabels(proposals);
6155
		assertCorrectLabels(proposals);
5377
6156
5378
		buf= new StringBuffer();
6157
		buf= new StringBuffer();
Lines 5387-5395 Link Here
5387
		buf.append("        String strX = stringBuilder.toString();\n");
6166
		buf.append("        String strX = stringBuilder.toString();\n");
5388
		buf.append("    }\n");
6167
		buf.append("    }\n");
5389
		buf.append("}\n");
6168
		buf.append("}\n");
5390
		String expected= buf.toString();
6169
		String expected1= buf.toString();
5391
6170
5392
		assertExpectedExistInProposals(proposals, new String[] { expected });
6171
		buf= new StringBuffer();
6172
		buf.append("package test1;\n");
6173
		buf.append("public class A {\n");
6174
		buf.append("    public void foo() {\n");
6175
		buf.append("        String string = \"foo\";\n");
6176
		buf.append("        String strX = string+\"bar\"+\"baz\"+\"biz\";\n");
6177
		buf.append("    }\n");
6178
		buf.append("}\n");
6179
		String expected2= buf.toString();
6180
6181
		buf= new StringBuffer();
6182
		buf.append("package test1;\n");
6183
		buf.append("public class A {\n");
6184
		buf.append("    public void foo() {\n");
6185
		buf.append("        String string = \"foo\";\n");
6186
		buf.append("        String strX = string+\"bar\"+\"baz\"+\"biz\";\n");
6187
		buf.append("    }\n");
6188
		buf.append("}\n");
6189
		String expected3= buf.toString();
6190
6191
		buf= new StringBuffer();
6192
		buf.append("package test1;\n");
6193
		buf.append("public class A {\n");
6194
		buf.append("    private static final String FOO = \"foo\";\n");
6195
		buf.append("\n");
6196
		buf.append("    public void foo() {\n");
6197
		buf.append("        String strX = FOO+\"bar\"+\"baz\"+\"biz\";\n");
6198
		buf.append("    }\n");
6199
		buf.append("}\n");
6200
		String expected4= buf.toString();
6201
6202
		buf= new StringBuffer();
6203
		buf.append("package test1;\n");
6204
		buf.append("public class A {\n");
6205
		buf.append("    public void foo() {\n");
6206
		buf.append("        String strX = (\"foo\"+\"bar\"+\"baz\"+\"biz\");\n");
6207
		buf.append("    }\n");
6208
		buf.append("}\n");
6209
		String expected5= buf.toString();
6210
6211
		buf= new StringBuffer();
6212
		buf.append("package test1;\n");
6213
		buf.append("public class A {\n");
6214
		buf.append("    public void foo() {\n");
6215
		buf.append("        String strX = \"foobarbazbiz\";\n");
6216
		buf.append("    }\n");
6217
		buf.append("}\n");
6218
		String expected6= buf.toString();
6219
6220
		buf= new StringBuffer();
6221
		buf.append("package test1;\n");
6222
		buf.append("public class A {\n");
6223
		buf.append("    public void foo() {\n");
6224
		buf.append("        String strX = \"FOO\"+\"bar\"+\"baz\"+\"biz\";\n");
6225
		buf.append("    }\n");
6226
		buf.append("}\n");
6227
		String expected7= buf.toString();
6228
6229
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5393
	}
6230
	}
5394
6231
5395
	public void testConvertToStringBufferStringAndVar() throws Exception {
6232
	public void testConvertToStringBufferStringAndVar() throws Exception {
Lines 5408-5413 Link Here
5408
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
6245
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
5409
		List proposals= collectAssists(context, false);
6246
		List proposals= collectAssists(context, false);
5410
6247
6248
		assertNumberOfProposals(proposals, 5);
5411
		assertCorrectLabels(proposals);
6249
		assertCorrectLabels(proposals);
5412
6250
5413
		buf= new StringBuffer();
6251
		buf= new StringBuffer();
Lines 5423-5431 Link Here
5423
		buf.append("        String strX = stringBuilder.toString();\n");
6261
		buf.append("        String strX = stringBuilder.toString();\n");
5424
		buf.append("    }\n");
6262
		buf.append("    }\n");
5425
		buf.append("}\n");
6263
		buf.append("}\n");
5426
		String expected= buf.toString();
6264
		String expected1= buf.toString();
5427
6265
5428
		assertExpectedExistInProposals(proposals, new String[] { expected });
6266
		buf= new StringBuffer();
6267
		buf.append("package test1;\n");
6268
		buf.append("public class A {\n");
6269
		buf.append("    public void foo() {\n");
6270
		buf.append("        String foo = \"foo\";\n");
6271
		buf.append("        String fuu = \"fuu\";\n");
6272
		buf.append("        String strX;\n");
6273
		buf.append("        strX = foo+\"bar\"+fuu;\n");
6274
		buf.append("    }\n");
6275
		buf.append("}\n");
6276
		String expected2= buf.toString();
6277
6278
		buf= new StringBuffer();
6279
		buf.append("package test1;\n");
6280
		buf.append("public class A {\n");
6281
		buf.append("    public void foo() {\n");
6282
		buf.append("        String foo = \"foo\";\n");
6283
		buf.append("        String fuu = \"fuu\";\n");
6284
		buf.append("    }\n");
6285
		buf.append("}\n");
6286
		String expected3= buf.toString();
6287
6288
		buf= new StringBuffer();
6289
		buf.append("package test1;\n");
6290
		buf.append("public class A {\n");
6291
		buf.append("    private String strX;\n");
6292
		buf.append("\n");
6293
		buf.append("    public void foo() {\n");
6294
		buf.append("        String foo = \"foo\";\n");
6295
		buf.append("        String fuu = \"fuu\";\n");
6296
		buf.append("        strX = foo+\"bar\"+fuu;\n");
6297
		buf.append("    }\n");
6298
		buf.append("}\n");
6299
		String expected4= buf.toString();
6300
6301
		buf= new StringBuffer();
6302
		buf.append("package test1;\n");
6303
		buf.append("\n");
6304
		buf.append("import java.text.MessageFormat;\n");
6305
		buf.append("\n");
6306
		buf.append("public class A {\n");
6307
		buf.append("    public void foo() {\n");
6308
		buf.append("        String foo = \"foo\";\n");
6309
		buf.append("        String fuu = \"fuu\";\n");
6310
		buf.append("        String strX = MessageFormat.format(\"{0}bar{1}\", foo, fuu);\n");
6311
		buf.append("    }\n");
6312
		buf.append("}\n");
6313
		String expected5= buf.toString();
6314
6315
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5 });
5429
	}
6316
	}
5430
6317
5431
	public void testConvertToStringBufferNoFixWithoutString() throws Exception {
6318
	public void testConvertToStringBufferNoFixWithoutString() throws Exception {
Lines 5442-5448 Link Here
5442
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
6329
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
5443
		List proposals= collectAssists(context, false);
6330
		List proposals= collectAssists(context, false);
5444
6331
6332
		assertNumberOfProposals(proposals, 3);
5445
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6333
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6334
6335
		buf= new StringBuffer();
6336
		buf.append("package test1;\n");
6337
		buf.append("public class A {\n");
6338
		buf.append("    public void foo() {\n");
6339
		buf.append("        int strX;\n");
6340
		buf.append("        strX = 5+1;\n");
6341
		buf.append("    }\n");
6342
		buf.append("}\n");
6343
		String expected1= buf.toString();
6344
6345
		buf= new StringBuffer();
6346
		buf.append("package test1;\n");
6347
		buf.append("public class A {\n");
6348
		buf.append("    public void foo() {\n");
6349
		buf.append("    }\n");
6350
		buf.append("}\n");
6351
		String expected2= buf.toString();
6352
6353
		buf= new StringBuffer();
6354
		buf.append("package test1;\n");
6355
		buf.append("public class A {\n");
6356
		buf.append("    private int strX;\n");
6357
		buf.append("\n");
6358
		buf.append("    public void foo() {\n");
6359
		buf.append("        strX = 5+1;\n");
6360
		buf.append("    }\n");
6361
		buf.append("}\n");
6362
		String expected3= buf.toString();
6363
6364
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 });
6365
5446
	}
6366
	}
5447
6367
5448
	public void testConvertToStringBufferNoFixWithoutString2() throws Exception {
6368
	public void testConvertToStringBufferNoFixWithoutString2() throws Exception {
Lines 5460-5466 Link Here
5460
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
6380
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
5461
		List proposals= collectAssists(context, false);
6381
		List proposals= collectAssists(context, false);
5462
6382
6383
		assertNumberOfProposals(proposals, 4);
5463
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6384
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6385
6386
		buf= new StringBuffer();
6387
		buf.append("package test1;\n");
6388
		buf.append("public class A {\n");
6389
		buf.append("    public void foo() {\n");
6390
		buf.append("        int strX = 5+1;\n");
6391
		buf.append("    }\n");
6392
		buf.append("}\n");
6393
		String expected1= buf.toString();
6394
6395
		buf= new StringBuffer();
6396
		buf.append("package test1;\n");
6397
		buf.append("public class A {\n");
6398
		buf.append("    public void foo() {\n");
6399
		buf.append("        int strX;\n");
6400
		buf.append("        int strX2 = strX;\n");
6401
		buf.append("        strX = 5+1;\n");
6402
		buf.append("    }\n");
6403
		buf.append("}\n");
6404
		String expected2= buf.toString();
6405
6406
		buf= new StringBuffer();
6407
		buf.append("package test1;\n");
6408
		buf.append("public class A {\n");
6409
		buf.append("    public void foo() {\n");
6410
		buf.append("        int strX;\n");
6411
		buf.append("        int strX2 = strX;\n");
6412
		buf.append("        strX = 5+1;\n");
6413
		buf.append("    }\n");
6414
		buf.append("}\n");
6415
		String expected3= buf.toString();
6416
6417
		buf= new StringBuffer();
6418
		buf.append("package test1;\n");
6419
		buf.append("public class A {\n");
6420
		buf.append("    private int strX;\n");
6421
		buf.append("\n");
6422
		buf.append("    public void foo() {\n");
6423
		buf.append("        strX = 5+1;\n");
6424
		buf.append("    }\n");
6425
		buf.append("}\n");
6426
		String expected4= buf.toString();
6427
6428
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
5464
	}
6429
	}
5465
6430
5466
	public void testConvertToStringBufferNoFixOutsideMethod() throws Exception {
6431
	public void testConvertToStringBufferNoFixOutsideMethod() throws Exception {
Lines 5477-5483 Link Here
5477
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
6442
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
5478
		List proposals= collectAssists(context, false);
6443
		List proposals= collectAssists(context, false);
5479
6444
6445
		assertNumberOfProposals(proposals, 1);
5480
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6446
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
6447
6448
		buf= new StringBuffer();
6449
		buf.append("package test1;\n");
6450
		buf.append("public class A {\n");
6451
		buf.append("    private String strX = \"foo\"+\"bar\"\n");
6452
		buf.append("    public void foo() {\n");
6453
		buf.append("    }\n");
6454
		buf.append("    public String getStrX() {\n");
6455
		buf.append("        return strX;\n");
6456
		buf.append("    }\n");
6457
		buf.append("    public void setStrX(String strX) {\n");
6458
		buf.append("        this.strX = strX;\n");
6459
		buf.append("    }\n");
6460
		buf.append("}\n");
6461
		String expected1= buf.toString();
6462
6463
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
5481
	}
6464
	}
5482
6465
5483
	public void testConvertToStringBufferDupVarName() throws Exception {
6466
	public void testConvertToStringBufferDupVarName() throws Exception {
Lines 5497-5503 Link Here
5497
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
6480
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
5498
		List proposals= collectAssists(context, false);
6481
		List proposals= collectAssists(context, false);
5499
6482
6483
		assertNumberOfProposals(proposals, 4);
5500
		assertCorrectLabels(proposals);
6484
		assertCorrectLabels(proposals);
6485
6486
		buf= new StringBuffer();
6487
		buf.append("package test1;\n");
6488
		buf.append("public class A {\n");
6489
		buf.append("    public void foo() {\n");
6490
		buf.append("        int stringBuilder = 5;\n");
6491
		buf.append("        String stringBuilder2;\n");
6492
		buf.append("        StringBuilder stringBuilder3 = null;\n");
6493
		buf.append("        String strX;\n");
6494
		buf.append("        strX = \"foo\"+\"bar\";\n");
6495
		buf.append("    }\n");
6496
		buf.append("}\n");
6497
		String expected1= buf.toString();
6498
6499
		buf= new StringBuffer();
6500
		buf.append("package test1;\n");
6501
		buf.append("public class A {\n");
6502
		buf.append("    public void foo() {\n");
6503
		buf.append("        int stringBuilder = 5;\n");
6504
		buf.append("        String stringBuilder2;\n");
6505
		buf.append("        StringBuilder stringBuilder3 = null;\n");
6506
		buf.append("    }\n");
6507
		buf.append("}\n");
6508
		String expected2= buf.toString();
6509
6510
		buf= new StringBuffer();
6511
		buf.append("package test1;\n");
6512
		buf.append("public class A {\n");
6513
		buf.append("    private String strX;\n");
6514
		buf.append("\n");
6515
		buf.append("    public void foo() {\n");
6516
		buf.append("        int stringBuilder = 5;\n");
6517
		buf.append("        String stringBuilder2;\n");
6518
		buf.append("        StringBuilder stringBuilder3 = null;\n");
6519
		buf.append("        strX = \"foo\"+\"bar\";\n");
6520
		buf.append("    }\n");
6521
		buf.append("}\n");
6522
		String expected3= buf.toString();
5501
6523
5502
		buf= new StringBuffer();
6524
		buf= new StringBuffer();
5503
		buf.append("package test1;\n");
6525
		buf.append("package test1;\n");
Lines 5512-5520 Link Here
5512
		buf.append("        String strX = stringBuilder4.toString();\n");
6534
		buf.append("        String strX = stringBuilder4.toString();\n");
5513
		buf.append("    }\n");
6535
		buf.append("    }\n");
5514
		buf.append("}\n");
6536
		buf.append("}\n");
5515
		String expected= buf.toString();
6537
		String expected4= buf.toString();
5516
6538
5517
		assertExpectedExistInProposals(proposals, new String[] { expected });
6539
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4 });
5518
	}
6540
	}
5519
6541
5520
	public void testConvertToStringBufferInIfStatement() throws Exception {
6542
	public void testConvertToStringBufferInIfStatement() throws Exception {
Lines 5532-5537 Link Here
5532
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
6554
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
5533
		List proposals= collectAssists(context, false);
6555
		List proposals= collectAssists(context, false);
5534
6556
6557
		assertNumberOfProposals(proposals, 7);
5535
		assertCorrectLabels(proposals);
6558
		assertCorrectLabels(proposals);
5536
6559
5537
		buf= new StringBuffer();
6560
		buf= new StringBuffer();
Lines 5547-5555 Link Here
5547
		buf.append("        }\n");
6570
		buf.append("        }\n");
5548
		buf.append("    }\n");
6571
		buf.append("    }\n");
5549
		buf.append("}\n");
6572
		buf.append("}\n");
5550
		String expected= buf.toString();
6573
		String expected1= buf.toString();
5551
6574
5552
		assertExpectedExistInProposals(proposals, new String[] { expected });
6575
		buf= new StringBuffer();
6576
		buf.append("package test1;\n");
6577
		buf.append("public class A {\n");
6578
		buf.append("    public void foo() {\n");
6579
		buf.append("        String strX;\n");
6580
		buf.append("        if(true) {\n");
6581
		buf.append("            String string = \"foo\";\n");
6582
		buf.append("            strX = string+\"bar\";\n");
6583
		buf.append("        }\n");
6584
		buf.append("    }\n");
6585
		buf.append("}\n");
6586
		String expected2= buf.toString();
6587
6588
		buf= new StringBuffer();
6589
		buf.append("package test1;\n");
6590
		buf.append("public class A {\n");
6591
		buf.append("    private static final String FOO = \"foo\";\n");
6592
		buf.append("\n");
6593
		buf.append("    public void foo() {\n");
6594
		buf.append("        String strX;\n");
6595
		buf.append("        if(true) strX = FOO+\"bar\";\n");
6596
		buf.append("    }\n");
6597
		buf.append("}\n");
6598
		String expected3= buf.toString();
6599
6600
		buf= new StringBuffer();
6601
		buf.append("package test1;\n");
6602
		buf.append("public class A {\n");
6603
		buf.append("    public void foo() {\n");
6604
		buf.append("        String strX;\n");
6605
		buf.append("        if(true) {\n");
6606
		buf.append("            String string = \"foo\";\n");
6607
		buf.append("            strX = string+\"bar\";\n");
6608
		buf.append("        }\n");
6609
		buf.append("    }\n");
6610
		buf.append("}\n");
6611
		String expected4= buf.toString();
6612
6613
		buf= new StringBuffer();
6614
		buf.append("package test1;\n");
6615
		buf.append("public class A {\n");
6616
		buf.append("    public void foo() {\n");
6617
		buf.append("        String strX;\n");
6618
		buf.append("        if(true) strX = (\"foo\"+\"bar\");\n");
6619
		buf.append("    }\n");
6620
		buf.append("}\n");
6621
		String expected5= buf.toString();
6622
6623
		buf= new StringBuffer();
6624
		buf.append("package test1;\n");
6625
		buf.append("public class A {\n");
6626
		buf.append("    public void foo() {\n");
6627
		buf.append("        String strX;\n");
6628
		buf.append("        if(true) strX = \"foobar\";\n");
6629
		buf.append("    }\n");
6630
		buf.append("}\n");
6631
		String expected6= buf.toString();
6632
6633
		buf= new StringBuffer();
6634
		buf.append("package test1;\n");
6635
		buf.append("public class A {\n");
6636
		buf.append("    public void foo() {\n");
6637
		buf.append("        String strX;\n");
6638
		buf.append("        if(true) strX = \"FOO\"+\"bar\";\n");
6639
		buf.append("    }\n");
6640
		buf.append("}\n");
6641
		String expected7= buf.toString();
6642
6643
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5553
	}
6644
	}
5554
6645
5555
	public void testConvertToStringBufferAsParamter() throws Exception {
6646
	public void testConvertToStringBufferAsParamter() throws Exception {
Lines 5566-5571 Link Here
5566
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
6657
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
5567
		List proposals= collectAssists(context, false);
6658
		List proposals= collectAssists(context, false);
5568
6659
6660
		assertNumberOfProposals(proposals, 7);
5569
		assertCorrectLabels(proposals);
6661
		assertCorrectLabels(proposals);
5570
6662
5571
		buf= new StringBuffer();
6663
		buf= new StringBuffer();
Lines 5580-5586 Link Here
5580
		buf.append("}\n");
6672
		buf.append("}\n");
5581
		String expected1= buf.toString();
6673
		String expected1= buf.toString();
5582
6674
5583
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
6675
		buf= new StringBuffer();
6676
		buf.append("package test1;\n");
6677
		buf.append("public class A {\n");
6678
		buf.append("    public void foo() {\n");
6679
		buf.append("        String string = \"foo\";\n");
6680
		buf.append("        System.out.println(string+\"bar\");\n");
6681
		buf.append("    }\n");
6682
		buf.append("}\n");
6683
		String expected2= buf.toString();
6684
6685
		buf= new StringBuffer();
6686
		buf.append("package test1;\n");
6687
		buf.append("public class A {\n");
6688
		buf.append("    public void foo() {\n");
6689
		buf.append("        String string = \"foo\";\n");
6690
		buf.append("        System.out.println(string+\"bar\");\n");
6691
		buf.append("    }\n");
6692
		buf.append("}\n");
6693
		String expected3= buf.toString();
6694
6695
		buf= new StringBuffer();
6696
		buf.append("package test1;\n");
6697
		buf.append("public class A {\n");
6698
		buf.append("    private static final String FOO = \"foo\";\n");
6699
		buf.append("\n");
6700
		buf.append("    public void foo() {\n");
6701
		buf.append("        System.out.println(FOO+\"bar\");\n");
6702
		buf.append("    }\n");
6703
		buf.append("}\n");
6704
		String expected4= buf.toString();
6705
6706
		buf= new StringBuffer();
6707
		buf.append("package test1;\n");
6708
		buf.append("public class A {\n");
6709
		buf.append("    public void foo() {\n");
6710
		buf.append("        System.out.println((\"foo\"+\"bar\"));\n");
6711
		buf.append("    }\n");
6712
		buf.append("}\n");
6713
		String expected5= buf.toString();
6714
6715
		buf= new StringBuffer();
6716
		buf.append("package test1;\n");
6717
		buf.append("public class A {\n");
6718
		buf.append("    public void foo() {\n");
6719
		buf.append("        System.out.println(\"foobar\");\n");
6720
		buf.append("    }\n");
6721
		buf.append("}\n");
6722
		String expected6= buf.toString();
6723
6724
		buf= new StringBuffer();
6725
		buf.append("package test1;\n");
6726
		buf.append("public class A {\n");
6727
		buf.append("    public void foo() {\n");
6728
		buf.append("        System.out.println(\"FOO\"+\"bar\");\n");
6729
		buf.append("    }\n");
6730
		buf.append("}\n");
6731
		String expected7= buf.toString();
6732
6733
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5584
	}
6734
	}
5585
6735
5586
	public void testConvertToStringBufferJava14() throws Exception {
6736
	public void testConvertToStringBufferJava14() throws Exception {
Lines 5604-5609 Link Here
5604
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
6754
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\"+\""), 0);
5605
			List proposals= collectAssists(context, false);
6755
			List proposals= collectAssists(context, false);
5606
6756
6757
			assertNumberOfProposals(proposals, 7);
5607
			assertCorrectLabels(proposals);
6758
			assertCorrectLabels(proposals);
5608
6759
5609
			buf= new StringBuffer();
6760
			buf= new StringBuffer();
Lines 5618-5624 Link Here
5618
			buf.append("}\n");
6769
			buf.append("}\n");
5619
			String expected1= buf.toString();
6770
			String expected1= buf.toString();
5620
6771
5621
			assertExpectedExistInProposals(proposals, new String[] { expected1 });
6772
			buf= new StringBuffer();
6773
			buf.append("package test1;\n");
6774
			buf.append("public class A {\n");
6775
			buf.append("    public void foo() {\n");
6776
			buf.append("        String string = \"foo\";\n");
6777
			buf.append("        System.out.println(string+\"bar\");\n");
6778
			buf.append("    }\n");
6779
			buf.append("}\n");
6780
			String expected2= buf.toString();
6781
6782
			buf= new StringBuffer();
6783
			buf.append("package test1;\n");
6784
			buf.append("public class A {\n");
6785
			buf.append("    public void foo() {\n");
6786
			buf.append("        String string = \"foo\";\n");
6787
			buf.append("        System.out.println(string+\"bar\");\n");
6788
			buf.append("    }\n");
6789
			buf.append("}\n");
6790
			String expected3= buf.toString();
6791
6792
			buf= new StringBuffer();
6793
			buf.append("package test1;\n");
6794
			buf.append("public class A {\n");
6795
			buf.append("    private static final String FOO = \"foo\";\n");
6796
			buf.append("\n");
6797
			buf.append("    public void foo() {\n");
6798
			buf.append("        System.out.println(FOO+\"bar\");\n");
6799
			buf.append("    }\n");
6800
			buf.append("}\n");
6801
			String expected4= buf.toString();
6802
6803
			buf= new StringBuffer();
6804
			buf.append("package test1;\n");
6805
			buf.append("public class A {\n");
6806
			buf.append("    public void foo() {\n");
6807
			buf.append("        System.out.println((\"foo\"+\"bar\"));\n");
6808
			buf.append("    }\n");
6809
			buf.append("}\n");
6810
			String expected5= buf.toString();
6811
6812
			buf= new StringBuffer();
6813
			buf.append("package test1;\n");
6814
			buf.append("public class A {\n");
6815
			buf.append("    public void foo() {\n");
6816
			buf.append("        System.out.println(\"foobar\");\n");
6817
			buf.append("    }\n");
6818
			buf.append("}\n");
6819
			String expected6= buf.toString();
6820
6821
			buf= new StringBuffer();
6822
			buf.append("package test1;\n");
6823
			buf.append("public class A {\n");
6824
			buf.append("    public void foo() {\n");
6825
			buf.append("        System.out.println(\"FOO\"+\"bar\");\n");
6826
			buf.append("    }\n");
6827
			buf.append("}\n");
6828
			String expected7= buf.toString();
6829
6830
			assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5622
		} finally {
6831
		} finally {
5623
			fJProject1.setOptions(oldOptions);
6832
			fJProject1.setOptions(oldOptions);
5624
		}
6833
		}
Lines 5639-5644 Link Here
5639
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 5"), 0);
6848
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 5"), 0);
5640
		List proposals= collectAssists(context, false);
6849
		List proposals= collectAssists(context, false);
5641
6850
6851
		assertNumberOfProposals(proposals, 9);
5642
		assertCorrectLabels(proposals);
6852
		assertCorrectLabels(proposals);
5643
6853
5644
		buf= new StringBuffer();
6854
		buf= new StringBuffer();
Lines 5652-5658 Link Here
5652
		buf.append("}\n");
6862
		buf.append("}\n");
5653
		String expected1= buf.toString();
6863
		String expected1= buf.toString();
5654
6864
5655
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
6865
		buf= new StringBuffer();
6866
		buf.append("package test1;\n");
6867
		buf.append("public class A {\n");
6868
		buf.append("    public void foo() {\n");
6869
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6870
		buf.append("        StringBuffer append = buf.append(\"high\" + 5);\n");
6871
		buf.append("    }\n");
6872
		buf.append("}\n");
6873
		String expected2= buf.toString();
6874
6875
		buf= new StringBuffer();
6876
		buf.append("package test1;\n");
6877
		buf.append("public class A {\n");
6878
		buf.append("    private StringBuffer append;\n");
6879
		buf.append("\n");
6880
		buf.append("    public void foo() {\n");
6881
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6882
		buf.append("        append = buf.append(\"high\" + 5);\n");
6883
		buf.append("    }\n");
6884
		buf.append("}\n");
6885
		String expected3= buf.toString();
6886
6887
		buf= new StringBuffer();
6888
		buf.append("package test1;\n");
6889
		buf.append("public class A {\n");
6890
		buf.append("    public void foo() {\n");
6891
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6892
		buf.append("        String string = \"high\";\n");
6893
		buf.append("        buf.append(string + 5);\n");
6894
		buf.append("    }\n");
6895
		buf.append("}\n");
6896
		String expected4= buf.toString();
6897
6898
		buf= new StringBuffer();
6899
		buf.append("package test1;\n");
6900
		buf.append("public class A {\n");
6901
		buf.append("    public void foo() {\n");
6902
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6903
		buf.append("        String string = \"high\";\n");
6904
		buf.append("        buf.append(string + 5);\n");
6905
		buf.append("    }\n");
6906
		buf.append("}\n");
6907
		String expected5= buf.toString();
6908
6909
		buf= new StringBuffer();
6910
		buf.append("package test1;\n");
6911
		buf.append("public class A {\n");
6912
		buf.append("    private static final String HIGH = \"high\";\n");
6913
		buf.append("\n");
6914
		buf.append("    public void foo() {\n");
6915
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6916
		buf.append("        buf.append(HIGH + 5);\n");
6917
		buf.append("    }\n");
6918
		buf.append("}\n");
6919
		String expected6= buf.toString();
6920
6921
		buf= new StringBuffer();
6922
		buf.append("package test1;\n");
6923
		buf.append("\n");
6924
		buf.append("import java.text.MessageFormat;\n");
6925
		buf.append("\n");
6926
		buf.append("public class A {\n");
6927
		buf.append("    public void foo() {\n");
6928
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6929
		buf.append("        buf.append(MessageFormat.format(\"high{0}\", 5));\n");
6930
		buf.append("    }\n");
6931
		buf.append("}\n");
6932
		String expected7= buf.toString();
6933
6934
		buf= new StringBuffer();
6935
		buf.append("package test1;\n");
6936
		buf.append("public class A {\n");
6937
		buf.append("    public void foo() {\n");
6938
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6939
		buf.append("        buf.append((\"high\" + 5));\n");
6940
		buf.append("    }\n");
6941
		buf.append("}\n");
6942
		String expected8= buf.toString();
6943
6944
		buf= new StringBuffer();
6945
		buf.append("package test1;\n");
6946
		buf.append("public class A {\n");
6947
		buf.append("    public void foo() {\n");
6948
		buf.append("        StringBuffer buf= new StringBuffer();\n");
6949
		buf.append("        buf.append(\"HIGH\" + 5);\n");
6950
		buf.append("    }\n");
6951
		buf.append("}\n");
6952
		String expected9= buf.toString();
6953
6954
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9 });
5656
	}
6955
	}
5657
	
6956
	
5658
	public void testConvertToStringBufferExisting2() throws Exception {
6957
	public void testConvertToStringBufferExisting2() throws Exception {
Lines 5670-5675 Link Here
5670
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 5"), 0);
6969
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 5"), 0);
5671
		List proposals= collectAssists(context, false);
6970
		List proposals= collectAssists(context, false);
5672
		
6971
		
6972
		assertNumberOfProposals(proposals, 9);
5673
		assertCorrectLabels(proposals);
6973
		assertCorrectLabels(proposals);
5674
		
6974
		
5675
		buf= new StringBuffer();
6975
		buf= new StringBuffer();
Lines 5684-5690 Link Here
5684
		buf.append("}\n");
6984
		buf.append("}\n");
5685
		String expected1= buf.toString();
6985
		String expected1= buf.toString();
5686
		
6986
		
5687
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
6987
		buf= new StringBuffer();
6988
		buf.append("package test1;\n");
6989
		buf.append("public class A {\n");
6990
		buf.append("    public void foo() {\n");
6991
		buf.append("        StringBuilder sb= new StringBuilder();\n");
6992
		buf.append("        StringBuilder append = sb.append(\"high\" + 5 + \" ho\");\n");
6993
		buf.append("    }\n");
6994
		buf.append("}\n");
6995
		String expected2= buf.toString();
6996
6997
		buf= new StringBuffer();
6998
		buf.append("package test1;\n");
6999
		buf.append("public class A {\n");
7000
		buf.append("    private StringBuilder append;\n");
7001
		buf.append("\n");
7002
		buf.append("    public void foo() {\n");
7003
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7004
		buf.append("        append = sb.append(\"high\" + 5 + \" ho\");\n");
7005
		buf.append("    }\n");
7006
		buf.append("}\n");
7007
		String expected3= buf.toString();
7008
7009
		buf= new StringBuffer();
7010
		buf.append("package test1;\n");
7011
		buf.append("public class A {\n");
7012
		buf.append("    public void foo() {\n");
7013
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7014
		buf.append("        String string = \"high\";\n");
7015
		buf.append("        sb.append(string + 5 + \" ho\");\n");
7016
		buf.append("    }\n");
7017
		buf.append("}\n");
7018
		String expected4= buf.toString();
7019
7020
		buf= new StringBuffer();
7021
		buf.append("package test1;\n");
7022
		buf.append("public class A {\n");
7023
		buf.append("    public void foo() {\n");
7024
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7025
		buf.append("        String string = \"high\";\n");
7026
		buf.append("        sb.append(string + 5 + \" ho\");\n");
7027
		buf.append("    }\n");
7028
		buf.append("}\n");
7029
		String expected5= buf.toString();
7030
7031
		buf= new StringBuffer();
7032
		buf.append("package test1;\n");
7033
		buf.append("public class A {\n");
7034
		buf.append("    private static final String HIGH = \"high\";\n");
7035
		buf.append("\n");
7036
		buf.append("    public void foo() {\n");
7037
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7038
		buf.append("        sb.append(HIGH + 5 + \" ho\");\n");
7039
		buf.append("    }\n");
7040
		buf.append("}\n");
7041
		String expected6= buf.toString();
7042
7043
		buf= new StringBuffer();
7044
		buf.append("package test1;\n");
7045
		buf.append("\n");
7046
		buf.append("import java.text.MessageFormat;\n");
7047
		buf.append("\n");
7048
		buf.append("public class A {\n");
7049
		buf.append("    public void foo() {\n");
7050
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7051
		buf.append("        sb.append(MessageFormat.format(\"high{0} ho\", 5));\n");
7052
		buf.append("    }\n");
7053
		buf.append("}\n");
7054
		String expected7= buf.toString();
7055
7056
		buf= new StringBuffer();
7057
		buf.append("package test1;\n");
7058
		buf.append("public class A {\n");
7059
		buf.append("    public void foo() {\n");
7060
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7061
		buf.append("        sb.append((\"high\" + 5 + \" ho\"));\n");
7062
		buf.append("    }\n");
7063
		buf.append("}\n");
7064
		String expected8= buf.toString();
7065
7066
		buf= new StringBuffer();
7067
		buf.append("package test1;\n");
7068
		buf.append("public class A {\n");
7069
		buf.append("    public void foo() {\n");
7070
		buf.append("        StringBuilder sb= new StringBuilder();\n");
7071
		buf.append("        sb.append(\"HIGH\" + 5 + \" ho\");\n");
7072
		buf.append("    }\n");
7073
		buf.append("}\n");
7074
		String expected9= buf.toString();
7075
7076
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9 });
5688
	}
7077
	}
5689
	
7078
	
5690
	public void testConvertToMessageFormat14() throws Exception {
7079
	public void testConvertToMessageFormat14() throws Exception {
Lines 5708-5713 Link Here
5708
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
7097
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
5709
			List proposals= collectAssists(context, false);
7098
			List proposals= collectAssists(context, false);
5710
7099
7100
			assertNumberOfProposals(proposals, 7);
5711
			assertCorrectLabels(proposals);
7101
			assertCorrectLabels(proposals);
5712
7102
5713
			buf= new StringBuffer();
7103
			buf= new StringBuffer();
Lines 5723-5729 Link Here
5723
			buf.append("}\n");
7113
			buf.append("}\n");
5724
			String expected1= buf.toString();
7114
			String expected1= buf.toString();
5725
7115
5726
			assertExpectedExistInProposals(proposals, new String[] { expected1 });
7116
			buf= new StringBuffer();
7117
			buf.append("package test1;\n");
7118
			buf.append("public class A {\n");
7119
			buf.append("    public void foo(Object o1, Object o2) {\n");
7120
			buf.append("        String string = \"foo\";\n");
7121
			buf.append("        System.out.println(string + o1 + \" \\\"bar\\\" \" + o2);\n");
7122
			buf.append("    }\n");
7123
			buf.append("}\n");
7124
			String expected2= buf.toString();
7125
7126
			buf= new StringBuffer();
7127
			buf.append("package test1;\n");
7128
			buf.append("public class A {\n");
7129
			buf.append("    public void foo(Object o1, Object o2) {\n");
7130
			buf.append("        String string = \"foo\";\n");
7131
			buf.append("        System.out.println(string + o1 + \" \\\"bar\\\" \" + o2);\n");
7132
			buf.append("    }\n");
7133
			buf.append("}\n");
7134
			String expected3= buf.toString();
7135
7136
			buf= new StringBuffer();
7137
			buf.append("package test1;\n");
7138
			buf.append("public class A {\n");
7139
			buf.append("    private static final String FOO = \"foo\";\n");
7140
			buf.append("\n");
7141
			buf.append("    public void foo(Object o1, Object o2) {\n");
7142
			buf.append("        System.out.println(FOO + o1 + \" \\\"bar\\\" \" + o2);\n");
7143
			buf.append("    }\n");
7144
			buf.append("}\n");
7145
			String expected4= buf.toString();
7146
7147
			buf= new StringBuffer();
7148
			buf.append("package test1;\n");
7149
			buf.append("public class A {\n");
7150
			buf.append("    public void foo(Object o1, Object o2) {\n");
7151
			buf.append("        StringBuffer stringBuffer = new StringBuffer();\n");
7152
			buf.append("        stringBuffer.append(\"foo\");\n");
7153
			buf.append("        stringBuffer.append(o1);\n");
7154
			buf.append("        stringBuffer.append(\" \\\"bar\\\" \");\n");
7155
			buf.append("        stringBuffer.append(o2);\n");
7156
			buf.append("        System.out.println(stringBuffer.toString());\n");
7157
			buf.append("    }\n");
7158
			buf.append("}\n");
7159
			String expected5= buf.toString();
7160
7161
			buf= new StringBuffer();
7162
			buf.append("package test1;\n");
7163
			buf.append("public class A {\n");
7164
			buf.append("    public void foo(Object o1, Object o2) {\n");
7165
			buf.append("        System.out.println((\"foo\" + o1 + \" \\\"bar\\\" \" + o2));\n");
7166
			buf.append("    }\n");
7167
			buf.append("}\n");
7168
			String expected6= buf.toString();
7169
7170
			buf= new StringBuffer();
7171
			buf.append("package test1;\n");
7172
			buf.append("public class A {\n");
7173
			buf.append("    public void foo(Object o1, Object o2) {\n");
7174
			buf.append("        System.out.println(\"FOO\" + o1 + \" \\\"bar\\\" \" + o2);\n");
7175
			buf.append("    }\n");
7176
			buf.append("}\n");
7177
			String expected7= buf.toString();
7178
7179
			assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5727
		} finally {
7180
		} finally {
5728
			fJProject1.setOptions(oldOptions);
7181
			fJProject1.setOptions(oldOptions);
5729
		}
7182
		}
Lines 5744-5752 Link Here
5744
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + \"\" + \""), 0);
7197
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + \"\" + \""), 0);
5745
		List proposals= collectAssists(context, false);
7198
		List proposals= collectAssists(context, false);
5746
7199
7200
		assertNumberOfProposals(proposals, 7);
5747
		assertCorrectLabels(proposals);
7201
		assertCorrectLabels(proposals);
5748
7202
5749
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_MESSAGE_FORMAT_ID);
7203
		assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_MESSAGE_FORMAT_ID);
7204
7205
		buf= new StringBuffer();
7206
		buf.append("package test1;\n");
7207
		buf.append("public class A {\n");
7208
		buf.append("    public void foo(Object o1, Object o2) {\n");
7209
		buf.append("        String string = \"foo\";\n");
7210
		buf.append("        System.out.println(string + \"\" + \" \\\"bar\\\" \");\n");
7211
		buf.append("    }\n");
7212
		buf.append("}\n");
7213
		String expected1= buf.toString();
7214
7215
		buf= new StringBuffer();
7216
		buf.append("package test1;\n");
7217
		buf.append("public class A {\n");
7218
		buf.append("    public void foo(Object o1, Object o2) {\n");
7219
		buf.append("        String string = \"foo\";\n");
7220
		buf.append("        System.out.println(string + \"\" + \" \\\"bar\\\" \");\n");
7221
		buf.append("    }\n");
7222
		buf.append("}\n");
7223
		String expected2= buf.toString();
7224
7225
		buf= new StringBuffer();
7226
		buf.append("package test1;\n");
7227
		buf.append("public class A {\n");
7228
		buf.append("    private static final String FOO = \"foo\";\n");
7229
		buf.append("\n");
7230
		buf.append("    public void foo(Object o1, Object o2) {\n");
7231
		buf.append("        System.out.println(FOO + \"\" + \" \\\"bar\\\" \");\n");
7232
		buf.append("    }\n");
7233
		buf.append("}\n");
7234
		String expected3= buf.toString();
7235
7236
		buf= new StringBuffer();
7237
		buf.append("package test1;\n");
7238
		buf.append("public class A {\n");
7239
		buf.append("    public void foo(Object o1, Object o2) {\n");
7240
		buf.append("        StringBuilder stringBuilder = new StringBuilder();\n");
7241
		buf.append("        stringBuilder.append(\"foo\");\n");
7242
		buf.append("        stringBuilder.append(\"\");\n");
7243
		buf.append("        stringBuilder.append(\" \\\"bar\\\" \");\n");
7244
		buf.append("        System.out.println(stringBuilder.toString());\n");
7245
		buf.append("    }\n");
7246
		buf.append("}\n");
7247
		String expected4= buf.toString();
7248
7249
		buf= new StringBuffer();
7250
		buf.append("package test1;\n");
7251
		buf.append("public class A {\n");
7252
		buf.append("    public void foo(Object o1, Object o2) {\n");
7253
		buf.append("        System.out.println((\"foo\" + \"\" + \" \\\"bar\\\" \"));\n");
7254
		buf.append("    }\n");
7255
		buf.append("}\n");
7256
		String expected5= buf.toString();
7257
7258
		buf= new StringBuffer();
7259
		buf.append("package test1;\n");
7260
		buf.append("public class A {\n");
7261
		buf.append("    public void foo(Object o1, Object o2) {\n");
7262
		buf.append("        System.out.println(\"foo \\\"bar\\\" \");\n");
7263
		buf.append("    }\n");
7264
		buf.append("}\n");
7265
		String expected6= buf.toString();
7266
7267
		buf= new StringBuffer();
7268
		buf.append("package test1;\n");
7269
		buf.append("public class A {\n");
7270
		buf.append("    public void foo(Object o1, Object o2) {\n");
7271
		buf.append("        System.out.println(\"FOO\" + \"\" + \" \\\"bar\\\" \");\n");
7272
		buf.append("    }\n");
7273
		buf.append("}\n");
7274
		String expected7= buf.toString();
7275
7276
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5750
	}
7277
	}
5751
7278
5752
	public void testConvertToMessageFormatStringBoxing14() throws Exception {
7279
	public void testConvertToMessageFormatStringBoxing14() throws Exception {
Lines 5769-5774 Link Here
5769
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("1 + \""), 0);
7296
			AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("1 + \""), 0);
5770
			List proposals= collectAssists(context, false);
7297
			List proposals= collectAssists(context, false);
5771
7298
7299
			assertNumberOfProposals(proposals, 6);
5772
			assertCorrectLabels(proposals);
7300
			assertCorrectLabels(proposals);
5773
7301
5774
			buf= new StringBuffer();
7302
			buf= new StringBuffer();
Lines 5783-5789 Link Here
5783
			buf.append("}\n");
7311
			buf.append("}\n");
5784
			String expected1= buf.toString();
7312
			String expected1= buf.toString();
5785
7313
5786
			assertExpectedExistInProposals(proposals, new String[] { expected1 });
7314
			buf= new StringBuffer();
7315
			buf.append("package test1;\n");
7316
			buf.append("public class A {\n");
7317
			buf.append("    public void foo(Object o1, Object o2) {\n");
7318
			buf.append("        int i = 1;\n");
7319
			buf.append("        System.out.println(\"foo\" + i + \" \\\"bar\\\" \");\n");
7320
			buf.append("    }\n");
7321
			buf.append("}\n");
7322
			String expected2= buf.toString();
7323
7324
			buf= new StringBuffer();
7325
			buf.append("package test1;\n");
7326
			buf.append("public class A {\n");
7327
			buf.append("    public void foo(Object o1, Object o2) {\n");
7328
			buf.append("        int i = 1;\n");
7329
			buf.append("        System.out.println(\"foo\" + i + \" \\\"bar\\\" \");\n");
7330
			buf.append("    }\n");
7331
			buf.append("}\n");
7332
			String expected3= buf.toString();
7333
7334
			buf= new StringBuffer();
7335
			buf.append("package test1;\n");
7336
			buf.append("public class A {\n");
7337
			buf.append("    private static final int _1 = 1;\n");
7338
			buf.append("\n");
7339
			buf.append("    public void foo(Object o1, Object o2) {\n");
7340
			buf.append("        System.out.println(\"foo\" + _1 + \" \\\"bar\\\" \");\n");
7341
			buf.append("    }\n");
7342
			buf.append("}\n");
7343
			String expected4= buf.toString();
7344
7345
			buf= new StringBuffer();
7346
			buf.append("package test1;\n");
7347
			buf.append("public class A {\n");
7348
			buf.append("    public void foo(Object o1, Object o2) {\n");
7349
			buf.append("        StringBuffer stringBuffer = new StringBuffer();\n");
7350
			buf.append("        stringBuffer.append(\"foo\");\n");
7351
			buf.append("        stringBuffer.append(1);\n");
7352
			buf.append("        stringBuffer.append(\" \\\"bar\\\" \");\n");
7353
			buf.append("        System.out.println(stringBuffer.toString());\n");
7354
			buf.append("    }\n");
7355
			buf.append("}\n");
7356
			String expected5= buf.toString();
7357
7358
			buf= new StringBuffer();
7359
			buf.append("package test1;\n");
7360
			buf.append("public class A {\n");
7361
			buf.append("    public void foo(Object o1, Object o2) {\n");
7362
			buf.append("        System.out.println((\"foo\" + 1 + \" \\\"bar\\\" \"));\n");
7363
			buf.append("    }\n");
7364
			buf.append("}\n");
7365
			String expected6= buf.toString();
7366
7367
			assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6 });
5787
		} finally {
7368
		} finally {
5788
			fJProject1.setOptions(oldOptions);
7369
			fJProject1.setOptions(oldOptions);
5789
		}
7370
		}
Lines 5803-5808 Link Here
5803
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 1 + \""), 0);
7384
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 1 + \""), 0);
5804
		List proposals= collectAssists(context, false);
7385
		List proposals= collectAssists(context, false);
5805
7386
7387
		assertNumberOfProposals(proposals, 7);
5806
		assertCorrectLabels(proposals);
7388
		assertCorrectLabels(proposals);
5807
7389
5808
		buf= new StringBuffer();
7390
		buf= new StringBuffer();
Lines 5817-5823 Link Here
5817
		buf.append("}\n");
7399
		buf.append("}\n");
5818
		String expected1= buf.toString();
7400
		String expected1= buf.toString();
5819
7401
5820
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
7402
		buf= new StringBuffer();
7403
		buf.append("package test1;\n");
7404
		buf.append("public class A {\n");
7405
		buf.append("    public void foo(Object o1, Object o2) {\n");
7406
		buf.append("        String string = \"foo\";\n");
7407
		buf.append("        System.out.println(string + 1 + \" \\\"bar\\\" \");\n");
7408
		buf.append("    }\n");
7409
		buf.append("}\n");
7410
		String expected2= buf.toString();
7411
7412
		buf= new StringBuffer();
7413
		buf.append("package test1;\n");
7414
		buf.append("public class A {\n");
7415
		buf.append("    public void foo(Object o1, Object o2) {\n");
7416
		buf.append("        String string = \"foo\";\n");
7417
		buf.append("        System.out.println(string + 1 + \" \\\"bar\\\" \");\n");
7418
		buf.append("    }\n");
7419
		buf.append("}\n");
7420
		String expected3= buf.toString();
7421
7422
		buf= new StringBuffer();
7423
		buf.append("package test1;\n");
7424
		buf.append("public class A {\n");
7425
		buf.append("    private static final String FOO = \"foo\";\n");
7426
		buf.append("\n");
7427
		buf.append("    public void foo(Object o1, Object o2) {\n");
7428
		buf.append("        System.out.println(FOO + 1 + \" \\\"bar\\\" \");\n");
7429
		buf.append("    }\n");
7430
		buf.append("}\n");
7431
		String expected4= buf.toString();
7432
7433
		buf= new StringBuffer();
7434
		buf.append("package test1;\n");
7435
		buf.append("public class A {\n");
7436
		buf.append("    public void foo(Object o1, Object o2) {\n");
7437
		buf.append("        StringBuilder stringBuilder = new StringBuilder();\n");
7438
		buf.append("        stringBuilder.append(\"foo\");\n");
7439
		buf.append("        stringBuilder.append(1);\n");
7440
		buf.append("        stringBuilder.append(\" \\\"bar\\\" \");\n");
7441
		buf.append("        System.out.println(stringBuilder.toString());\n");
7442
		buf.append("    }\n");
7443
		buf.append("}\n");
7444
		String expected5= buf.toString();
7445
7446
		buf= new StringBuffer();
7447
		buf.append("package test1;\n");
7448
		buf.append("public class A {\n");
7449
		buf.append("    public void foo(Object o1, Object o2) {\n");
7450
		buf.append("        System.out.println((\"foo\" + 1 + \" \\\"bar\\\" \"));\n");
7451
		buf.append("    }\n");
7452
		buf.append("}\n");
7453
		String expected6= buf.toString();
7454
7455
		buf= new StringBuffer();
7456
		buf.append("package test1;\n");
7457
		buf.append("public class A {\n");
7458
		buf.append("    public void foo(Object o1, Object o2) {\n");
7459
		buf.append("        System.out.println(\"FOO\" + 1 + \" \\\"bar\\\" \");\n");
7460
		buf.append("    }\n");
7461
		buf.append("}\n");
7462
		String expected7= buf.toString();
7463
7464
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5821
	}
7465
	}
5822
7466
5823
	public void testConvertToMessageFormat15() throws Exception {
7467
	public void testConvertToMessageFormat15() throws Exception {
Lines 5835-5840 Link Here
5835
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
7479
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
5836
		List proposals= collectAssists(context, false);
7480
		List proposals= collectAssists(context, false);
5837
7481
7482
		assertNumberOfProposals(proposals, 7);
5838
		assertCorrectLabels(proposals);
7483
		assertCorrectLabels(proposals);
5839
7484
5840
		buf= new StringBuffer();
7485
		buf= new StringBuffer();
Lines 5849-5855 Link Here
5849
		buf.append("}\n");
7494
		buf.append("}\n");
5850
		String expected1= buf.toString();
7495
		String expected1= buf.toString();
5851
7496
5852
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
7497
		buf= new StringBuffer();
7498
		buf.append("package test1;\n");
7499
		buf.append("public class A {\n");
7500
		buf.append("    public void foo(Object o1, Object o2) {\n");
7501
		buf.append("        String string = \"foo\";\n");
7502
		buf.append("        System.out.println(string + o1 + \" \\\"bar\\\" \" + o2);\n");
7503
		buf.append("    }\n");
7504
		buf.append("}\n");
7505
		String expected2= buf.toString();
7506
7507
		buf= new StringBuffer();
7508
		buf.append("package test1;\n");
7509
		buf.append("public class A {\n");
7510
		buf.append("    public void foo(Object o1, Object o2) {\n");
7511
		buf.append("        String string = \"foo\";\n");
7512
		buf.append("        System.out.println(string + o1 + \" \\\"bar\\\" \" + o2);\n");
7513
		buf.append("    }\n");
7514
		buf.append("}\n");
7515
		String expected3= buf.toString();
7516
7517
		buf= new StringBuffer();
7518
		buf.append("package test1;\n");
7519
		buf.append("public class A {\n");
7520
		buf.append("    private static final String FOO = \"foo\";\n");
7521
		buf.append("\n");
7522
		buf.append("    public void foo(Object o1, Object o2) {\n");
7523
		buf.append("        System.out.println(FOO + o1 + \" \\\"bar\\\" \" + o2);\n");
7524
		buf.append("    }\n");
7525
		buf.append("}\n");
7526
		String expected4= buf.toString();
7527
7528
		buf= new StringBuffer();
7529
		buf.append("package test1;\n");
7530
		buf.append("public class A {\n");
7531
		buf.append("    public void foo(Object o1, Object o2) {\n");
7532
		buf.append("        StringBuilder stringBuilder = new StringBuilder();\n");
7533
		buf.append("        stringBuilder.append(\"foo\");\n");
7534
		buf.append("        stringBuilder.append(o1);\n");
7535
		buf.append("        stringBuilder.append(\" \\\"bar\\\" \");\n");
7536
		buf.append("        stringBuilder.append(o2);\n");
7537
		buf.append("        System.out.println(stringBuilder.toString());\n");
7538
		buf.append("    }\n");
7539
		buf.append("}\n");
7540
		String expected5= buf.toString();
7541
7542
		buf= new StringBuffer();
7543
		buf.append("package test1;\n");
7544
		buf.append("public class A {\n");
7545
		buf.append("    public void foo(Object o1, Object o2) {\n");
7546
		buf.append("        System.out.println((\"foo\" + o1 + \" \\\"bar\\\" \" + o2));\n");
7547
		buf.append("    }\n");
7548
		buf.append("}\n");
7549
		String expected6= buf.toString();
7550
7551
		buf= new StringBuffer();
7552
		buf.append("package test1;\n");
7553
		buf.append("public class A {\n");
7554
		buf.append("    public void foo(Object o1, Object o2) {\n");
7555
		buf.append("        System.out.println(\"FOO\" + o1 + \" \\\"bar\\\" \" + o2);\n");
7556
		buf.append("    }\n");
7557
		buf.append("}\n");
7558
		String expected7= buf.toString();
7559
7560
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5853
	}
7561
	}
5854
7562
5855
	public void testConvertToMessageFormatApostrophe() throws Exception {
7563
	public void testConvertToMessageFormatApostrophe() throws Exception {
Lines 5867-5872 Link Here
5867
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
7575
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + o1 + \""), 0);
5868
		List proposals= collectAssists(context, false);
7576
		List proposals= collectAssists(context, false);
5869
7577
7578
		assertNumberOfProposals(proposals, 7);
5870
		assertCorrectLabels(proposals);
7579
		assertCorrectLabels(proposals);
5871
7580
5872
		buf= new StringBuffer();
7581
		buf= new StringBuffer();
Lines 5881-5887 Link Here
5881
		buf.append("}\n");
7590
		buf.append("}\n");
5882
		String expected1= buf.toString();
7591
		String expected1= buf.toString();
5883
7592
5884
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
7593
		buf= new StringBuffer();
7594
		buf.append("package test1;\n");
7595
		buf.append("public class A {\n");
7596
		buf.append("    public void foo(Object o1, Object o2) {\n");
7597
		buf.append("        String string = \"foo'\";\n");
7598
		buf.append("        System.out.println(string + o1 + \"' \\\"bar\\\" \" + o2);\n");
7599
		buf.append("    }\n");
7600
		buf.append("}\n");
7601
		String expected2= buf.toString();
7602
7603
		buf= new StringBuffer();
7604
		buf.append("package test1;\n");
7605
		buf.append("public class A {\n");
7606
		buf.append("    public void foo(Object o1, Object o2) {\n");
7607
		buf.append("        String string = \"foo'\";\n");
7608
		buf.append("        System.out.println(string + o1 + \"' \\\"bar\\\" \" + o2);\n");
7609
		buf.append("    }\n");
7610
		buf.append("}\n");
7611
		String expected3= buf.toString();
7612
7613
		buf= new StringBuffer();
7614
		buf.append("package test1;\n");
7615
		buf.append("public class A {\n");
7616
		buf.append("    private static final String FOO = \"foo'\";\n");
7617
		buf.append("\n");
7618
		buf.append("    public void foo(Object o1, Object o2) {\n");
7619
		buf.append("        System.out.println(FOO + o1 + \"' \\\"bar\\\" \" + o2);\n");
7620
		buf.append("    }\n");
7621
		buf.append("}\n");
7622
		String expected4= buf.toString();
7623
7624
		buf= new StringBuffer();
7625
		buf.append("package test1;\n");
7626
		buf.append("public class A {\n");
7627
		buf.append("    public void foo(Object o1, Object o2) {\n");
7628
		buf.append("        StringBuilder stringBuilder = new StringBuilder();\n");
7629
		buf.append("        stringBuilder.append(\"foo'\");\n");
7630
		buf.append("        stringBuilder.append(o1);\n");
7631
		buf.append("        stringBuilder.append(\"' \\\"bar\\\" \");\n");
7632
		buf.append("        stringBuilder.append(o2);\n");
7633
		buf.append("        System.out.println(stringBuilder.toString());\n");
7634
		buf.append("    }\n");
7635
		buf.append("}\n");
7636
		String expected5= buf.toString();
7637
7638
		buf= new StringBuffer();
7639
		buf.append("package test1;\n");
7640
		buf.append("public class A {\n");
7641
		buf.append("    public void foo(Object o1, Object o2) {\n");
7642
		buf.append("        System.out.println((\"foo'\" + o1 + \"' \\\"bar\\\" \" + o2));\n");
7643
		buf.append("    }\n");
7644
		buf.append("}\n");
7645
		String expected6= buf.toString();
7646
7647
		buf= new StringBuffer();
7648
		buf.append("package test1;\n");
7649
		buf.append("public class A {\n");
7650
		buf.append("    public void foo(Object o1, Object o2) {\n");
7651
		buf.append("        System.out.println(\"FOO'\" + o1 + \"' \\\"bar\\\" \" + o2);\n");
7652
		buf.append("    }\n");
7653
		buf.append("}\n");
7654
		String expected7= buf.toString();
7655
7656
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 });
5885
	}
7657
	}
5886
	
7658
	
5887
	public void testConvertToMessageFormatExtendedOperands() throws Exception {
7659
	public void testConvertToMessageFormatExtendedOperands() throws Exception {
Lines 5898-5903 Link Here
5898
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(" + "), 0);
7670
		AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(" + "), 0);
5899
		List proposals= collectAssists(context, false);
7671
		List proposals= collectAssists(context, false);
5900
		
7672
		
7673
		assertNumberOfProposals(proposals, 8);
5901
		assertCorrectLabels(proposals);
7674
		assertCorrectLabels(proposals);
5902
		
7675
		
5903
		buf= new StringBuffer();
7676
		buf= new StringBuffer();
Lines 5930-5936 Link Here
5930
		buf.append("}\n");
7703
		buf.append("}\n");
5931
		String expected2= buf.toString();
7704
		String expected2= buf.toString();
5932
		
7705
		
5933
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 });
7706
		buf= new StringBuffer();
7707
		buf.append("package test1;\n");
7708
		buf.append("public class A {\n");
7709
		buf.append("    public void foo() {\n");
7710
		buf.append("        String string = \"a\";\n");
7711
		buf.append("        String s2= string + \"b\" + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7712
		buf.append("    }\n");
7713
		buf.append("}\n");
7714
		String expected3= buf.toString();
7715
7716
		buf= new StringBuffer();
7717
		buf.append("package test1;\n");
7718
		buf.append("public class A {\n");
7719
		buf.append("    private static final String A = \"a\";\n");
7720
		buf.append("\n");
7721
		buf.append("    public void foo() {\n");
7722
		buf.append("        String s2= A + \"b\" + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7723
		buf.append("    }\n");
7724
		buf.append("}\n");
7725
		String expected4= buf.toString();
7726
7727
		buf= new StringBuffer();
7728
		buf.append("package test1;\n");
7729
		buf.append("public class A {\n");
7730
		buf.append("    public void foo() {\n");
7731
		buf.append("        String s2= (\"a\" + \"b\") + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7732
		buf.append("    }\n");
7733
		buf.append("}\n");
7734
		String expected5= buf.toString();
7735
7736
		buf= new StringBuffer();
7737
		buf.append("package test1;\n");
7738
		buf.append("public class A {\n");
7739
		buf.append("    public void foo() {\n");
7740
		buf.append("        String s2= \"ab\" + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7741
		buf.append("    }\n");
7742
		buf.append("}\n");
7743
		String expected6= buf.toString();
7744
7745
		buf= new StringBuffer();
7746
		buf.append("package test1;\n");
7747
		buf.append("public class A {\n");
7748
		buf.append("    public void foo() {\n");
7749
		buf.append("        String string = \"a\";\n");
7750
		buf.append("        String s2= string + \"b\" + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7751
		buf.append("    }\n");
7752
		buf.append("}\n");
7753
		String expected7= buf.toString();
7754
7755
		buf= new StringBuffer();
7756
		buf.append("package test1;\n");
7757
		buf.append("public class A {\n");
7758
		buf.append("    public void foo() {\n");
7759
		buf.append("        String s2= \"A\" + \"b\" + 3L + \"c\" + (4-2) + \"d\" + \"e\" + \"f\";\n");
7760
		buf.append("    }\n");
7761
		buf.append("}\n");
7762
		String expected8= buf.toString();
7763
7764
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8 });
5934
	}
7765
	}
5935
	
7766
	
5936
	public void testMissingEnumConstantsInCase1() throws Exception {
7767
	public void testMissingEnumConstantsInCase1() throws Exception {
Lines 5957-5963 Link Here
5957
		assertCorrectLabels(proposals);
7788
		assertCorrectLabels(proposals);
5958
		assertNumberOfProposals(proposals, 3);
7789
		assertNumberOfProposals(proposals, 3);
5959
7790
5960
		String[] expected= new String[2];
7791
		String[] expected= new String[3];
5961
		buf= new StringBuffer();
7792
		buf= new StringBuffer();
5962
		buf.append("package p;\n");
7793
		buf.append("package p;\n");
5963
		buf.append("\n");
7794
		buf.append("\n");
Lines 5999-6004 Link Here
5999
		buf.append("    }\n");
7830
		buf.append("    }\n");
6000
		buf.append("}\n");
7831
		buf.append("}\n");
6001
		expected[1]= buf.toString();
7832
		expected[1]= buf.toString();
7833
7834
		buf= new StringBuffer();
7835
		buf.append("package p;\n");
7836
		buf.append("\n");
7837
		buf.append("public class E {\n");
7838
		buf.append("    enum MyEnum {\n");
7839
		buf.append("        X1, X2, X3\n");
7840
		buf.append("    }\n");
7841
		buf.append("    \n");
7842
		buf.append("    public void foo(MyEnum x) {\n");
7843
		buf.append("    }\n");
7844
		buf.append("}\n");
7845
		expected[2]= buf.toString();
6002
7846
6003
		assertExpectedExistInProposals(proposals, expected);
7847
		assertExpectedExistInProposals(proposals, expected);
6004
	}
7848
	}
Lines 6029-6035 Link Here
6029
		assertCorrectLabels(proposals);
7873
		assertCorrectLabels(proposals);
6030
		assertNumberOfProposals(proposals, 3);
7874
		assertNumberOfProposals(proposals, 3);
6031
7875
6032
		String[] expected= new String[2];
7876
		String[] expected= new String[3];
6033
		buf= new StringBuffer();
7877
		buf= new StringBuffer();
6034
		buf.append("package p;\n");
7878
		buf.append("package p;\n");
6035
		buf.append("\n");
7879
		buf.append("\n");
Lines 6073-6078 Link Here
6073
		buf.append("    }\n");
7917
		buf.append("    }\n");
6074
		buf.append("}\n");
7918
		buf.append("}\n");
6075
		expected[1]= buf.toString();
7919
		expected[1]= buf.toString();
7920
7921
		buf= new StringBuffer();
7922
		buf.append("package p;\n");
7923
		buf.append("\n");
7924
		buf.append("public class E {\n");
7925
		buf.append("    enum MyEnum {\n");
7926
		buf.append("        X1, X2, X3\n");
7927
		buf.append("    }\n");
7928
		buf.append("    \n");
7929
		buf.append("    public void foo(MyEnum x) {\n");
7930
		buf.append("        if (x == MyEnum.X1) {\n");
7931
		buf.append("        }\n");
7932
		buf.append("    }\n");
7933
		buf.append("}\n");
7934
		expected[2]= buf.toString();
6076
7935
6077
		assertExpectedExistInProposals(proposals, expected);
7936
		assertExpectedExistInProposals(proposals, expected);
6078
	}
7937
	}
Lines 6236-6242 Link Here
6236
		assertCorrectLabels(proposals);
8095
		assertCorrectLabels(proposals);
6237
		assertNumberOfProposals(proposals, 2);
8096
		assertNumberOfProposals(proposals, 2);
6238
8097
6239
		String[] expected= new String[1];
8098
		String[] expected= new String[2];
6240
		buf= new StringBuffer();
8099
		buf= new StringBuffer();
6241
		buf.append("package p;\n");
8100
		buf.append("package p;\n");
6242
		buf.append("\n");
8101
		buf.append("\n");
Lines 6261-6266 Link Here
6261
		buf.append("}\n");
8120
		buf.append("}\n");
6262
		expected[0]= buf.toString();
8121
		expected[0]= buf.toString();
6263
8122
8123
		buf= new StringBuffer();
8124
		buf.append("package p;\n");
8125
		buf.append("\n");
8126
		buf.append("public class E {\n");
8127
		buf.append("    enum MyEnum {\n");
8128
		buf.append("        X1, X2, X3\n");
8129
		buf.append("    }\n");
8130
		buf.append("    \n");
8131
		buf.append("    public void foo(MyEnum x) {\n");
8132
		buf.append("        if (x == MyEnum.X1) {\n");
8133
		buf.append("        } else if (x == MyEnum.X2) {\n");
8134
		buf.append("        } else if (x == MyEnum.X3) {\n");
8135
		buf.append("        }\n");
8136
		buf.append("    }\n");
8137
		buf.append("}\n");
8138
		expected[1]= buf.toString();
8139
6264
		assertExpectedExistInProposals(proposals, expected);
8140
		assertExpectedExistInProposals(proposals, expected);
6265
	}
8141
	}
6266
8142
Lines 6283-6289 Link Here
6283
		assertNumberOfProposals(proposals, 3);
8159
		assertNumberOfProposals(proposals, 3);
6284
		assertCorrectLabels(proposals);
8160
		assertCorrectLabels(proposals);
6285
8161
6286
		String[] expected= new String[1];
8162
		String[] expected= new String[3];
6287
		buf= new StringBuffer();
8163
		buf= new StringBuffer();
6288
		buf.append("package test1;\n");
8164
		buf.append("package test1;\n");
6289
		buf.append("public class E {\n");
8165
		buf.append("public class E {\n");
Lines 6295-6300 Link Here
6295
		buf.append("    }\n");
8171
		buf.append("    }\n");
6296
		buf.append("}\n");
8172
		buf.append("}\n");
6297
		expected[0]= buf.toString();
8173
		expected[0]= buf.toString();
8174
8175
		buf= new StringBuffer();
8176
		buf.append("package test1;\n");
8177
		buf.append("public class E {\n");
8178
		buf.append("    public static void main(String... args) {\n");
8179
		buf.append("        System.out.print(arg);\n");
8180
		buf.append("    }\n");
8181
		buf.append("}\n");
8182
		expected[1]= buf.toString();
8183
8184
		buf= new StringBuffer();
8185
		buf.append("package test1;\n");
8186
		buf.append("public class E {\n");
8187
		buf.append("    public static void main(String... args) {\n");
8188
		buf.append("        for (final @Deprecated String arg : args)\n");
8189
		buf.append("            System.out.print(arg);\n");
8190
		buf.append("    }\n");
8191
		buf.append("}\n");
8192
		expected[2]= buf.toString();
6298
8193
6299
		assertExpectedExistInProposals(proposals, expected);
8194
		assertExpectedExistInProposals(proposals, expected);
6300
	}
8195
	}
Lines 6323-6329 Link Here
6323
		assertNumberOfProposals(proposals, 2);
8218
		assertNumberOfProposals(proposals, 2);
6324
		assertCorrectLabels(proposals);
8219
		assertCorrectLabels(proposals);
6325
8220
6326
		String[] expected= new String[1];
8221
		String[] expected= new String[2];
6327
		buf= new StringBuffer();
8222
		buf= new StringBuffer();
6328
		buf.append("package test1;\n");
8223
		buf.append("package test1;\n");
6329
		buf.append("public class E {\n");
8224
		buf.append("public class E {\n");
Lines 6341-6346 Link Here
6341
		buf.append("    }\n");
8236
		buf.append("    }\n");
6342
		buf.append("}\n");
8237
		buf.append("}\n");
6343
		expected[0]= buf.toString();
8238
		expected[0]= buf.toString();
8239
8240
		buf= new StringBuffer();
8241
		buf.append("package test1;\n");
8242
		buf.append("public class E {\n");
8243
		buf.append("    public void foo(int[][][] ints) {\n");
8244
		buf.append("        outer: //convert this\n");
8245
		buf.append("        for (int i : is) {\n");
8246
		buf.append("            System.out.print(i);\n");
8247
		buf.append("            System.out.print(\", \");\n");
8248
		buf.append("        }\n");
8249
		buf.append("        System.out.println();\n");
8250
		buf.append("    }\n");
8251
		buf.append("}\n");
8252
		expected[1]= buf.toString();
6344
8253
6345
		assertExpectedExistInProposals(proposals, expected);
8254
		assertExpectedExistInProposals(proposals, expected);
6346
	}
8255
	}
Lines 6369-6375 Link Here
6369
		assertNumberOfProposals(proposals, 4);
8278
		assertNumberOfProposals(proposals, 4);
6370
		assertCorrectLabels(proposals);
8279
		assertCorrectLabels(proposals);
6371
8280
6372
		String[] expected= new String[2];
8281
		String[] expected= new String[4];
6373
		buf= new StringBuffer();
8282
		buf= new StringBuffer();
6374
		buf.append("package test1;\n");
8283
		buf.append("package test1;\n");
6375
		buf.append("import java.util.Arrays;\n");
8284
		buf.append("import java.util.Arrays;\n");
Lines 6407-6412 Link Here
6407
		buf.append("}\n");
8316
		buf.append("}\n");
6408
		expected[1]= buf.toString();
8317
		expected[1]= buf.toString();
6409
		
8318
		
8319
		buf= new StringBuffer();
8320
		buf.append("package test1;\n");
8321
		buf.append("import java.util.Arrays;\n");
8322
		buf.append("import java.util.List;\n");
8323
		buf.append("public class E {\n");
8324
		buf.append("    void foo() {\n");
8325
		buf.append("        System.out.println(number.doubleValue());\n");
8326
		buf.append("    }\n");
8327
		buf.append("    private List<? extends Number> getNums() {\n");
8328
		buf.append("        return Arrays.asList(1, 2.34, 0xFFFF);\n");
8329
		buf.append("    }\n");
8330
		buf.append("}\n");
8331
		expected[2]= buf.toString();
8332
8333
		buf= new StringBuffer();
8334
		buf.append("package test1;\n");
8335
		buf.append("import java.util.Arrays;\n");
8336
		buf.append("import java.util.List;\n");
8337
		buf.append("public class E {\n");
8338
		buf.append("    void foo() {\n");
8339
		buf.append("        for (Number number : getNums())\n");
8340
		buf.append("            System.out.println(number.doubleValue());\n");
8341
		buf.append("    }\n");
8342
		buf.append("    private List<? extends Number> getNums() {\n");
8343
		buf.append("        return Arrays.asList(1, 2.34, 0xFFFF);\n");
8344
		buf.append("    }\n");
8345
		buf.append("}\n");
8346
		expected[3]= buf.toString();
8347
6410
		assertExpectedExistInProposals(proposals, expected);
8348
		assertExpectedExistInProposals(proposals, expected);
6411
	}
8349
	}
6412
8350
Lines 6433-6439 Link Here
6433
		assertNumberOfProposals(proposals, 3);
8371
		assertNumberOfProposals(proposals, 3);
6434
		assertCorrectLabels(proposals);
8372
		assertCorrectLabels(proposals);
6435
	
8373
	
6436
		String[] expected= new String[1];
8374
		String[] expected= new String[3];
6437
		buf= new StringBuffer();
8375
		buf= new StringBuffer();
6438
		buf.append("package test1;\n");
8376
		buf.append("package test1;\n");
6439
		buf.append("import java.util.Collection;\n");
8377
		buf.append("import java.util.Collection;\n");
Lines 6451-6456 Link Here
6451
		buf.append("    }\n");
8389
		buf.append("    }\n");
6452
		buf.append("}\n");
8390
		buf.append("}\n");
6453
		expected[0]= buf.toString();
8391
		expected[0]= buf.toString();
8392
8393
		buf= new StringBuffer();
8394
		buf.append("package test1;\n");
8395
		buf.append("import java.util.Collection;\n");
8396
		buf.append("import java.util.List;\n");
8397
		buf.append("public class E {\n");
8398
		buf.append("    void foo(Collection<? extends List<? extends Number>> allNums) {\n");
8399
		buf.append("        for (Number number : nums) {\n");
8400
		buf.append("            System.out.println(number.doubleValue());\n");
8401
		buf.append("        }\n");
8402
		buf.append("    }\n");
8403
		buf.append("}\n");
8404
		expected[1]= buf.toString();
8405
8406
		buf= new StringBuffer();
8407
		buf.append("package test1;\n");
8408
		buf.append("import java.util.Collection;\n");
8409
		buf.append("import java.util.List;\n");
8410
		buf.append("public class E {\n");
8411
		buf.append("    void foo(Collection<? extends List<? extends Number>> allNums) {\n");
8412
		buf.append("        for (List<? extends Number> nums : allNums)\n");
8413
		buf.append("            for (Number number : nums) {\n");
8414
		buf.append("                System.out.println(number.doubleValue());\n");
8415
		buf.append("            }\n");
8416
		buf.append("    }\n");
8417
		buf.append("}\n");
8418
		expected[2]= buf.toString();
6454
	
8419
	
6455
		assertExpectedExistInProposals(proposals, expected);
8420
		assertExpectedExistInProposals(proposals, expected);
6456
	}
8421
	}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java (-3 / +105 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 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 46-51 Link Here
46
import org.eclipse.jdt.core.dom.ConstructorInvocation;
46
import org.eclipse.jdt.core.dom.ConstructorInvocation;
47
import org.eclipse.jdt.core.dom.ContinueStatement;
47
import org.eclipse.jdt.core.dom.ContinueStatement;
48
import org.eclipse.jdt.core.dom.DoStatement;
48
import org.eclipse.jdt.core.dom.DoStatement;
49
import org.eclipse.jdt.core.dom.EnhancedForStatement;
49
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
50
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
50
import org.eclipse.jdt.core.dom.Expression;
51
import org.eclipse.jdt.core.dom.Expression;
51
import org.eclipse.jdt.core.dom.ExpressionStatement;
52
import org.eclipse.jdt.core.dom.ExpressionStatement;
Lines 129-135 Link Here
129
		ASTNode coveringNode= context.getCoveringNode();
130
		ASTNode coveringNode= context.getCoveringNode();
130
		if (coveringNode != null) {
131
		if (coveringNode != null) {
131
			ArrayList<ASTNode> coveredNodes= getFullyCoveredNodes(context, coveringNode);
132
			ArrayList<ASTNode> coveredNodes= getFullyCoveredNodes(context, coveringNode);
132
			return getInverseIfProposals(context, coveringNode, null)
133
			return getConvertToIfReturnProposals(context, coveringNode, null)
134
					|| getInverseIfProposals(context, coveringNode, null)
133
					|| getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, null)
135
					|| getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, null)
134
					|| getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, null)
136
					|| getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, null)
135
					|| getInverseIfIntoContinueInLoopsProposals(context, coveringNode, null)
137
					|| getInverseIfIntoContinueInLoopsProposals(context, coveringNode, null)
Lines 173-178 Link Here
173
			getReplaceConditionalWithIfElseProposals(context, coveringNode, resultingCollections);
175
			getReplaceConditionalWithIfElseProposals(context, coveringNode, resultingCollections);
174
176
175
			if (QuickAssistProcessor.noErrorsAtLocation(locations)) {
177
			if (QuickAssistProcessor.noErrorsAtLocation(locations)) {
178
				getConvertToIfReturnProposals(context, coveringNode, resultingCollections);
176
				getInverseIfProposals(context, coveringNode, resultingCollections);
179
				getInverseIfProposals(context, coveringNode, resultingCollections);
177
				getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, resultingCollections);
180
				getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, resultingCollections);
178
				getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, resultingCollections);
181
				getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, resultingCollections);
Lines 206-211 Link Here
206
		return null;
209
		return null;
207
	}
210
	}
208
211
212
	private static boolean getConvertToIfReturnProposals(IInvocationContext context, ASTNode coveringNode, ArrayList<ICommandAccess> resultingCollections) {
213
		if (!(coveringNode instanceof IfStatement)) {
214
			return false;
215
		}
216
		IfStatement ifStatement= (IfStatement) coveringNode;
217
		if (ifStatement.getElseStatement() != null) {
218
			return false;
219
		}
220
		MethodDeclaration coveringMetod= ASTResolving.findParentMethodDeclaration(ifStatement);
221
		if (coveringMetod == null) {
222
			return false;
223
		}
224
		// method should return 'void'
225
		Type returnType= coveringMetod.getReturnType2();
226
		if (!isVoid(returnType)) {
227
			return false;
228
		}
229
		// should be present in a block
230
		if (!(ifStatement.getParent() instanceof Block)) {
231
			return false;
232
		}
233
		// should have at least one statement in 'then' part other than 'return'
234
		Statement thenStatement= ifStatement.getThenStatement();
235
		if (thenStatement instanceof ReturnStatement) {
236
			return false;
237
		}
238
		if (thenStatement instanceof Block) {
239
			List<Statement> thenStatements= ((Block) thenStatement).statements();
240
			if (thenStatements.isEmpty() || (thenStatements.size() == 1 && (thenStatements.get(0) instanceof ReturnStatement))) {
241
				return false;
242
			}
243
		}
244
		// should have no further executable statement
245
		if (!isLastExecutableStatementInMethod(ifStatement)) {
246
			return false;
247
		}
248
		//  we could produce quick assist
249
		if (resultingCollections == null) {
250
			return true;
251
		}
252
253
		AST ast= coveringNode.getAST();
254
		ASTRewrite rewrite= ASTRewrite.create(ast);
255
256
		// create inverted 'if' statement
257
		Expression inversedExpression= getInversedExpression(rewrite, ifStatement.getExpression());
258
		IfStatement newIf= ast.newIfStatement();
259
		newIf.setExpression(inversedExpression);
260
		newIf.setThenStatement(ast.newReturnStatement());
261
		ListRewrite listRewriter= rewrite.getListRewrite(ifStatement.getParent(), (ChildListPropertyDescriptor) ifStatement.getLocationInParent());
262
		listRewriter.replace(ifStatement, newIf, null);
263
		// remove last 'return' in 'then' block
264
		ArrayList<Statement> statements= getUnwrappedStatements(ifStatement.getThenStatement());
265
		Statement lastStatement= statements.get(statements.size() - 1);
266
		if (lastStatement instanceof ReturnStatement) {
267
			statements.remove(lastStatement);
268
		}
269
		// add statements from 'then' to the end of block
270
		for (Statement statement : statements) {
271
			listRewriter.insertLast(rewrite.createMoveTarget(statement), null);
272
		}
273
274
		// add correction proposal
275
		String label= CorrectionMessages.AdvancedQuickAssistProcessor_convertToIfReturn;
276
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
277
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_TO_IF_RETURN, image);
278
		resultingCollections.add(proposal);
279
		return true;
280
	}
281
282
	private static boolean isVoid(Type type) {
283
		if (!(type instanceof PrimitiveType) || ((PrimitiveType) type).getPrimitiveTypeCode() != PrimitiveType.VOID) {
284
			return false;
285
		}
286
		return true;
287
	}
288
289
	private static boolean isLastExecutableStatementInMethod(Statement statement) {
290
		ASTNode currentStructure= statement;
291
		ASTNode currentParent= statement.getParent();
292
		while (!(currentParent instanceof MethodDeclaration)) {
293
			// should not be in a loop
294
			if (currentParent instanceof ForStatement || currentParent instanceof EnhancedForStatement
295
					|| currentParent instanceof WhileStatement || currentParent instanceof DoStatement) {
296
				return false;
297
			}
298
			if (currentParent instanceof Block) {
299
				Block parentBlock= (Block) currentParent;
300
				if (parentBlock.statements().indexOf(currentStructure) != parentBlock.statements().size() - 1) { // not last statement in the block
301
					return false;
302
				}
303
			}
304
			currentStructure= currentParent;
305
			currentParent= currentParent.getParent();
306
		}
307
		return true;
308
	}
309
209
	private static boolean getIfReturnIntoIfElseAtEndOfVoidMethodProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
310
	private static boolean getIfReturnIntoIfElseAtEndOfVoidMethodProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
210
		if (!(covering instanceof IfStatement)) {
311
		if (!(covering instanceof IfStatement)) {
211
			return false;
312
			return false;
Lines 230-237 Link Here
230
			return false;
331
			return false;
231
		}
332
		}
232
		Type returnType= coveringMetod.getReturnType2();
333
		Type returnType= coveringMetod.getReturnType2();
233
		if (!(returnType instanceof PrimitiveType) || ((PrimitiveType) returnType).getPrimitiveTypeCode() != PrimitiveType.VOID)
334
		if (!isVoid(returnType)) {
234
			return false;
335
			return false;
336
		}
235
		//
337
		//
236
		List<Statement> statements= coveringMetod.getBody().statements();
338
		List<Statement> statements= coveringMetod.getBody().statements();
237
		int ifIndex= statements.indexOf(ifStatement);
339
		int ifIndex= statements.indexOf(ifStatement);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java (+1 lines)
Lines 296-301 Link Here
296
	public static String TypeChangeCompletionProposal_method_name;
296
	public static String TypeChangeCompletionProposal_method_name;
297
	public static String ImplementInterfaceProposal_name;
297
	public static String ImplementInterfaceProposal_name;
298
	public static String AddUnimplementedMethodsOperation_AddMissingMethod_group;
298
	public static String AddUnimplementedMethodsOperation_AddMissingMethod_group;
299
	public static String AdvancedQuickAssistProcessor_convertToIfReturn;
299
	public static String AdvancedQuickAssistProcessor_combineSelectedStrings;
300
	public static String AdvancedQuickAssistProcessor_combineSelectedStrings;
300
	public static String AdvancedQuickAssistProcessor_convertToIfElse_description;
301
	public static String AdvancedQuickAssistProcessor_convertToIfElse_description;
301
	public static String AdvancedQuickAssistProcessor_inverseIf_description;
302
	public static String AdvancedQuickAssistProcessor_inverseIf_description;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties (+1 lines)
Lines 376-381 Link Here
376
ImplementInterfaceProposal_name=Let ''{0}'' implement ''{1}''
376
ImplementInterfaceProposal_name=Let ''{0}'' implement ''{1}''
377
377
378
AddUnimplementedMethodsOperation_AddMissingMethod_group=Add missing method
378
AddUnimplementedMethodsOperation_AddMissingMethod_group=Add missing method
379
AdvancedQuickAssistProcessor_convertToIfReturn=Convert to 'if-return'
379
AdvancedQuickAssistProcessor_combineSelectedStrings=Combine to single String
380
AdvancedQuickAssistProcessor_combineSelectedStrings=Combine to single String
380
AdvancedQuickAssistProcessor_convertToIfElse_description=Convert to 'if-else'
381
AdvancedQuickAssistProcessor_convertToIfElse_description=Convert to 'if-else'
381
AdvancedQuickAssistProcessor_inverseIf_description=Invert 'if' statement
382
AdvancedQuickAssistProcessor_inverseIf_description=Invert 'if' statement
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
2
 * Copyright (c) 2012, 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 255-260 Link Here
255
	public static final int ASSIGN_PARAM_TO_EXISTING_FIELD= 1;
255
	public static final int ASSIGN_PARAM_TO_EXISTING_FIELD= 1;
256
	public static final int INSERT_INFERRED_TYPE_ARGUMENTS_ERROR= 1;
256
	public static final int INSERT_INFERRED_TYPE_ARGUMENTS_ERROR= 1;
257
	public static final int RETURN_ALLOCATED_OBJECT_VOID= 1;
257
	public static final int RETURN_ALLOCATED_OBJECT_VOID= 1;
258
	public static final int CONVERT_TO_IF_RETURN= 1;
258
259
259
	public static final int CONVERT_TO_MESSAGE_FORMAT= 0;
260
	public static final int CONVERT_TO_MESSAGE_FORMAT= 0;
260
	public static final int COPY_ANNOTATION_JAR= 0;
261
	public static final int COPY_ANNOTATION_JAR= 0;

Return to bug 119181