View | Details | Raw Unified | Return to bug 201762
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (+223 lines)
Lines 7832-7835 Link Here
7832
		expectedFullUnitToString,
7832
		expectedFullUnitToString,
7833
		expectedCompletionDietUnitToString, testName);
7833
		expectedCompletionDietUnitToString, testName);
7834
}
7834
}
7835
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201762
7836
public void test127() {
7837
	String s =
7838
		"import org.eclipse.swt.*;\n" + 
7839
		"import org.eclipse.swt.events.*;\n" + 
7840
		"import org.eclipse.swt.widgets.*;\n" + 
7841
		"\n" + 
7842
		"public class Try {\n" + 
7843
		"\n" + 
7844
		"    void main(Shell shell) {\n" + 
7845
		"\n" + 
7846
		"        final Label label= new Label(shell, SWT.WRAP);\n" + 
7847
		"        label.addPaintListener(new PaintListener() {\n" + 
7848
		"            public void paintControl(PaintEvent e) {\n" + 
7849
		"                e.gc.setLineCap(SWT.CAP_); // content assist after CAP_\n" + 
7850
		"            }\n" + 
7851
		"        });\n" + 
7852
		"\n" + 
7853
		"        shell.addControlListener(new ControlAdapter() { });\n" + 
7854
		"\n" + 
7855
		"        while (!shell.isDisposed()) { }\n" + 
7856
		"    }\n" + 
7857
		"}\n" + 
7858
		"\n";
7859
7860
	String expectedDietUnitToString =
7861
		"import org.eclipse.swt.*;\n" + 
7862
		"import org.eclipse.swt.events.*;\n" + 
7863
		"import org.eclipse.swt.widgets.*;\n" + 
7864
		"public class Try {\n" + 
7865
		"  public Try() {\n" + 
7866
		"  }\n" + 
7867
		"  void main(Shell shell) {\n" + 
7868
		"  }\n" + 
7869
		"}\n";
7870
7871
	String expectedDietPlusBodyUnitToString =
7872
		"import org.eclipse.swt.*;\n" + 
7873
		"import org.eclipse.swt.events.*;\n" + 
7874
		"import org.eclipse.swt.widgets.*;\n" + 
7875
		"public class Try {\n" + 
7876
		"  public Try() {\n" + 
7877
		"    super();\n" + 
7878
		"  }\n" + 
7879
		"  void main(Shell shell) {\n" + 
7880
		"    final Label label = new Label(shell, SWT.WRAP);\n" + 
7881
		"    label.addPaintListener(new PaintListener() {\n" + 
7882
		"  public void paintControl(PaintEvent e) {\n" + 
7883
		"    e.gc.setLineCap(SWT.CAP_);\n" + 
7884
		"  }\n" + 
7885
		"});\n" + 
7886
		"    shell.addControlListener(new ControlAdapter() {\n" + 
7887
		"});\n" + 
7888
		"    while ((! shell.isDisposed()))      {\n" + 
7889
		"      }\n" + 
7890
		"  }\n" + 
7891
		"}\n";
7892
7893
	String expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7894
		"import org.eclipse.swt.*;\n" + 
7895
		"import org.eclipse.swt.events.*;\n" + 
7896
		"import org.eclipse.swt.widgets.*;\n" + 
7897
		"public class Try {\n" + 
7898
		"  public Try() {\n" + 
7899
		"    super();\n" + 
7900
		"  }\n" + 
7901
		"  void main(Shell shell) {\n" + 
7902
		"    final Label label = new Label(shell, SWT.WRAP);\n" + 
7903
		"    label.addPaintListener(new PaintListener() {\n" + 
7904
		"  public void paintControl(PaintEvent e) {\n" + 
7905
		"    e.gc.setLineCap(SWT.CAP_);\n" + 
7906
		"  }\n" + 
7907
		"});\n" + 
7908
		"    shell.addControlListener(new ControlAdapter() {\n" + 
7909
		"});\n" + 
7910
		"    while ((! shell.isDisposed()))      {\n" + 
7911
		"      }\n" + 
7912
		"  }\n" + 
7913
		"}\n";
7914
7915
	String expectedFullUnitToString =
7916
		"import org.eclipse.swt.*;\n" + 
7917
		"import org.eclipse.swt.events.*;\n" + 
7918
		"import org.eclipse.swt.widgets.*;\n" + 
7919
		"public class Try {\n" + 
7920
		"  public Try() {\n" + 
7921
		"    super();\n" + 
7922
		"  }\n" + 
7923
		"  void main(Shell shell) {\n" + 
7924
		"    final Label label = new Label(shell, SWT.WRAP);\n" + 
7925
		"    label.addPaintListener(new PaintListener() {\n" + 
7926
		"  public void paintControl(PaintEvent e) {\n" + 
7927
		"    e.gc.setLineCap(SWT.CAP_);\n" + 
7928
		"  }\n" + 
7929
		"});\n" + 
7930
		"    shell.addControlListener(new ControlAdapter() {\n" + 
7931
		"});\n" + 
7932
		"    while ((! shell.isDisposed()))      {\n" + 
7933
		"      }\n" + 
7934
		"  }\n" + 
7935
		"}\n";
7936
7937
	String expectedCompletionDietUnitToString =
7938
		"import org.eclipse.swt.*;\n" + 
7939
		"import org.eclipse.swt.events.*;\n" + 
7940
		"import org.eclipse.swt.widgets.*;\n" + 
7941
		"public class Try {\n" + 
7942
		"  public Try() {\n" + 
7943
		"  }\n" + 
7944
		"  void main(Shell shell) {\n" + 
7945
		"  }\n" + 
7946
		"}\n";
7947
7948
	String testName = "test";
7949
	checkParse(
7950
		s.toCharArray(),
7951
		expectedDietUnitToString,
7952
		expectedDietPlusBodyUnitToString,
7953
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString,
7954
		expectedFullUnitToString,
7955
		expectedCompletionDietUnitToString, testName);
7956
}
7957
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201762
7958
public void test128() {
7959
	String s =
7960
		"import org.eclipse.swt.*;\n" + 
7961
		"import org.eclipse.swt.events.*;\n" + 
7962
		"import org.eclipse.swt.widgets.*;\n" + 
7963
		"\n" + 
7964
		"public class Try {\n" + 
7965
		"\n" + 
7966
		"    void main(Shell shell) {\n" + 
7967
		"\n" + 
7968
		"        final Label label= new Label(shell, SWT.WRAP);\n" + 
7969
		"        label.addPaintListener(new PaintListener() {\n" + 
7970
		"            public void paintControl(PaintEvent e) {\n" + 
7971
		"                e.gc.setLineCap(SWT.CAP_#); // content assist after CAP_\n" + 
7972
		"            }\n" + 
7973
		"        });\n" + 
7974
		"\n" + 
7975
		"        shell.addControlListener(new ControlAdapter() { });\n" + 
7976
		"\n" + 
7977
		"        while (!shell.isDisposed()) { }\n" + 
7978
		"    }\n" + 
7979
		"}\n" + 
7980
		"\n";
7981
7982
	String expectedDietUnitToString =
7983
		"import org.eclipse.swt.*;\n" + 
7984
		"import org.eclipse.swt.events.*;\n" + 
7985
		"import org.eclipse.swt.widgets.*;\n" + 
7986
		"public class Try {\n" + 
7987
		"  public Try() {\n" + 
7988
		"  }\n" + 
7989
		"  void main(Shell shell) {\n" + 
7990
		"  }\n" + 
7991
		"}\n";
7992
7993
	String expectedDietPlusBodyUnitToString =
7994
		"import org.eclipse.swt.*;\n" + 
7995
		"import org.eclipse.swt.events.*;\n" + 
7996
		"import org.eclipse.swt.widgets.*;\n" + 
7997
		"public class Try {\n" + 
7998
		"  public Try() {\n" + 
7999
		"    super();\n" + 
8000
		"  }\n" + 
8001
		"  void main(Shell shell) {\n" + 
8002
		"  }\n" + 
8003
		"}\n";
8004
8005
	String expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
8006
		"import org.eclipse.swt.*;\n" + 
8007
		"import org.eclipse.swt.events.*;\n" + 
8008
		"import org.eclipse.swt.widgets.*;\n" + 
8009
		"public class Try {\n" + 
8010
		"  public Try() {\n" + 
8011
		"    super();\n" + 
8012
		"  }\n" + 
8013
		"  void main(Shell shell) {\n" + 
8014
		"    final Label label = new Label(shell, SWT.WRAP);\n" + 
8015
		"    label.addPaintListener(new PaintListener() {\n" + 
8016
		"  public void paintControl(PaintEvent e) {\n" + 
8017
		"    e.gc.setLineCap(SWT.CAP_);\n" + 
8018
		"  }\n" + 
8019
		"});\n" + 
8020
		"    shell.addControlListener(new ControlAdapter() {\n" + 
8021
		"});\n" + 
8022
		"    while ((! shell.isDisposed()))      {\n" + 
8023
		"      }\n" + 
8024
		"  }\n" + 
8025
		"}\n";
8026
8027
	String expectedFullUnitToString =
8028
		"import org.eclipse.swt.*;\n" + 
8029
		"import org.eclipse.swt.events.*;\n" + 
8030
		"import org.eclipse.swt.widgets.*;\n" + 
8031
		"public class Try {\n" + 
8032
		"  public Try() {\n" + 
8033
		"  }\n" + 
8034
		"  void main(Shell shell) {\n" + 
8035
		"  }\n" + 
8036
		"}\n";
8037
8038
	String expectedCompletionDietUnitToString =
8039
		"import org.eclipse.swt.*;\n" + 
8040
		"import org.eclipse.swt.events.*;\n" + 
8041
		"import org.eclipse.swt.widgets.*;\n" + 
8042
		"public class Try {\n" + 
8043
		"  public Try() {\n" + 
8044
		"  }\n" + 
8045
		"  void main(Shell shell) {\n" + 
8046
		"  }\n" + 
8047
		"}\n";
8048
8049
	String testName = "test";
8050
	checkParse(
8051
		s.toCharArray(),
8052
		expectedDietUnitToString,
8053
		expectedDietPlusBodyUnitToString,
8054
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString,
8055
		expectedFullUnitToString,
8056
		expectedCompletionDietUnitToString, testName);
8057
}
7835
}
8058
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/CompletionRecoveryTest.java (+55 lines)
Lines 1028-1031 Link Here
1028
		"<complete after dot number>"
1028
		"<complete after dot number>"
1029
	);
1029
	);
1030
}
1030
}
1031
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=201762
1032
public void test26() {
1033
	this.runTestCheckMethodParse(
1034
		// compilationUnit:
1035
		"import org.eclipse.swt.*;\n" + 
1036
		"import org.eclipse.swt.events.*;\n" + 
1037
		"import org.eclipse.swt.widgets.*;\n" + 
1038
		"\n" + 
1039
		"public class Try {\n" + 
1040
		"\n" + 
1041
		"    void main(Shell shell) {\n" + 
1042
		"\n" + 
1043
		"        final Label label= new Label(shell, SWT.WRAP);\n" + 
1044
		"        label.addPaintListener(new PaintListener() {\n" + 
1045
		"            public void paintControl(PaintEvent e) {\n" + 
1046
		"                e.gc.setLineCap(SWT.CAP_); // content assist after CAP_\n" + 
1047
		"            }\n" + 
1048
		"        });\n" + 
1049
		"\n" + 
1050
		"        shell.addControlListener(new ControlAdapter() { });\n" + 
1051
		"\n" + 
1052
		"        while (!shell.isDisposed()) { }\n" + 
1053
		"    }\n" + 
1054
		"}\n" + 
1055
		"\n",
1056
		// completeBehind:
1057
		"SWT.CAP_",
1058
		// expectedCompletionNodeToString:
1059
		"<CompleteOnName:SWT.CAP_>",
1060
		// expectedUnitDisplayString:
1061
		"import org.eclipse.swt.*;\n" + 
1062
		"import org.eclipse.swt.events.*;\n" + 
1063
		"import org.eclipse.swt.widgets.*;\n" + 
1064
		"public class Try {\n" + 
1065
		"  public Try() {\n" + 
1066
		"  }\n" + 
1067
		"  void main(Shell shell) {\n" + 
1068
		"    final Label label;\n" + 
1069
		"    new PaintListener() {\n" + 
1070
		"      public void paintControl(PaintEvent e) {\n" + 
1071
		"        e.gc.setLineCap(<CompleteOnName:SWT.CAP_>);\n" + 
1072
		"      }\n" + 
1073
		"    };\n" + 
1074
		"    new ControlAdapter() {\n" + 
1075
		"    };\n" + 
1076
		"  }\n" + 
1077
		"}\n",
1078
		// expectedCompletionIdentifier:
1079
		"CAP_",
1080
		// expectedReplacedSource:
1081
		"SWT.CAP_",
1082
		// test name
1083
		"<complete after dot number>"
1084
	);
1085
}
1031
}
1086
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java (+7 lines)
Lines 54-57 Link Here
54
	if (this.statement.sourceEnd == 0)
54
	if (this.statement.sourceEnd == 0)
55
		this.statement.sourceEnd = bodyEnd;
55
		this.statement.sourceEnd = bodyEnd;
56
}
56
}
57
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
58
	if ((--this.bracketBalance <= 0) && (this.parent != null)){
59
		this.updateSourceEndIfNecessary(braceStart, braceEnd);
60
		return this.parent.updateOnClosingBrace(braceStart, braceEnd);
61
	}
62
	return this;
63
}
57
}
64
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+96 lines)
Lines 20219-20222 Link Here
20219
			requestor.getResults());
20219
			requestor.getResults());
20220
}
20220
}
20221
20221
20222
public void test201762() throws JavaModelException {
20223
	this.workingCopies = new ICompilationUnit[8];
20224
	this.workingCopies[0] = getWorkingCopy(
20225
			"/Completion/src/test/Test201762.java",
20226
			"import test.ControlAdapter;\n" +
20227
			"import test.Label;\n" +
20228
			"import test.PaintEvent;\n" +
20229
			"import test.PaintListener;\n" +
20230
			"import test.SWT;\n" +
20231
			"import test.Shell;\n" +
20232
			"\n" +
20233
			"public class Test201762 {\n" +
20234
			"\n" +
20235
			"    void main(Shell shell) {\n" +
20236
			"\n" +
20237
			"        final Label label= new Label(shell, SWT.WRAP);\n" +
20238
			"        label.addPaintListener(new PaintListener() {\n" +
20239
			"            public void paintControl(PaintEvent e) {\n" +
20240
			"                e.gc.setLineCap(SWT.CAP_); // content assist after CAP_\n" +
20241
			"            }\n" +
20242
			"        });\n" +
20243
			"\n" +
20244
			"        shell.addControlListener(new ControlAdapter() { });\n" +
20245
			"\n" +
20246
			"        while (!shell.isDisposed()) { }\n" +
20247
			"    }\n" +
20248
			"}\n");
20249
	
20250
	this.workingCopies[1] = getWorkingCopy(
20251
			"/Completion/src/test/AnObject.java",
20252
			"package test;\n" +
20253
			"public class AnObject {\n" +
20254
			"	public void setLineCap(int capZz) {}\n" +
20255
			"}\n");
20256
	
20257
	this.workingCopies[2] = getWorkingCopy(
20258
			"/Completion/src/test/ControlAdapter.java",
20259
			"package test;\n" +
20260
			"public class ControlAdapter {\n" +
20261
			"}\n");
20262
	
20263
	this.workingCopies[3] = getWorkingCopy(
20264
			"/Completion/src/test/Label.java",
20265
			"package test;\n" +
20266
			"public class Label {\n" +
20267
			"	public Label(Shell shell, int wrap) {\n" +
20268
			"	}\n" +
20269
			"	public void addPaintListener(PaintListener paintListener) {\n" +
20270
			"	}\n" +
20271
			"}\n");
20272
	
20273
	this.workingCopies[4] = getWorkingCopy(
20274
			"/Completion/src/test/Label.java",
20275
			"package test;\n" +
20276
			"public class PaintEvent {\n" +
20277
			"	public AnObject gc;\n" +
20278
			"}\n");
20279
	
20280
	this.workingCopies[5] = getWorkingCopy(
20281
			"/Completion/src/test/PaintListener.java",
20282
			"package test;\n" +
20283
			"public interface PaintListener {\n" +
20284
			"}\n");
20285
	
20286
	this.workingCopies[6] = getWorkingCopy(
20287
			"/Completion/src/test/Shell.java",
20288
			"package test;\n" +
20289
			"public class Shell {\n" +
20290
			"	public boolean isDisposed() {\n" +
20291
			"		return false;\n" +
20292
			"	}\n" +
20293
			"	public void addControlListener(ControlAdapter controlAdapter) {\n" +
20294
			"	}\n" +
20295
			"}\n");
20296
	
20297
	this.workingCopies[7] = getWorkingCopy(
20298
			"/Completion/src/test/SWT.java",
20299
			"package test;\n" +
20300
			"public interface SWT {\n" +
20301
			"	int WRAP = 0;\n" +
20302
			"	int CAP_ZZ = 0;\n" +
20303
			"}\n");
20304
			
20305
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
20306
	String str = this.workingCopies[0].getSource();
20307
	String completeBehind = "SWT.CAP_";
20308
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20309
20310
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20311
	assertResults(
20312
			"CAP_ZZ[FIELD_REF]{CAP_ZZ, Ltest.SWT;, I, CAP_ZZ, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_NON_INHERITED + R_NON_RESTRICTED) + "}",
20313
			requestor.getResults());
20314
}
20315
20316
20317
20222
}
20318
}

Return to bug 201762