IDEA-136406 Complete current statement doesn't insert a method body for default metho...
[idea/community.git] / java / java-tests / testSrc / com / intellij / codeInsight / CompleteStatementTest.java
1 /*
2  * Copyright 2000-2011 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.codeInsight;
17
18 import com.intellij.JavaTestUtil;
19 import com.intellij.openapi.actionSystem.IdeActions;
20 import com.intellij.psi.codeStyle.CodeStyleSettings;
21 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
22 import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
23 import com.intellij.testFramework.EditorActionTestCase;
24 import com.intellij.testFramework.TestDataPath;
25 import org.jetbrains.annotations.NotNull;
26
27 /**
28  * @author max
29  */
30 @TestDataPath("$CONTENT_ROOT/testData")
31 public class CompleteStatementTest extends EditorActionTestCase {
32   public void testAddMissingSemicolon() throws Exception { doTest(); }
33   
34   public void testAddMissingSemicolonToPackageStatement() { doTest(); }
35
36   public void testAddMissingParen() throws Exception { doTest(); }
37
38   public void testCompleteIf() throws Exception { doTest(); }
39
40   public void testCompleteIfKeyword() throws Exception { doTest(); }
41
42   public void testCompleteIfStatementGoesToThen() throws Exception { doTest(); }
43
44   public void testCompleteIfKeywordStatementGoesToThen() throws Exception { doTest(); }
45
46   public void testIndentation() throws Exception { doTest(); }
47
48   public void testErrorNavigation() throws Exception { doTest(); }
49
50   public void testStringLiteral() throws Exception { doTest(); }
51
52   public void testCompleteCatch() throws Exception { doTest(); }
53   
54   public void testCompleteCatchLParen() throws Exception { doTest(); }
55
56   public void testAlreadyCompleteCatch() throws Exception {
57     CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
58     int old = settings.BRACE_STYLE;
59     settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
60     try {
61       doTest();
62     }
63     finally {
64       settings.BRACE_STYLE = old;
65     }
66   }
67
68   public void testCompleteCatchWithExpression() throws Exception { doTest(); }
69
70   public void testCompleteCatchBody() throws Exception { doTest(); }
71
72   public void testSCR11147() throws Exception { doTest(); }
73
74   public void testNoErrors() throws Exception { doTest(); }
75
76   public void testThrow() throws Exception { doTest(); }
77
78   public void testReturn() throws Exception { doTest(); }
79
80   public void testEmptyLine() throws Exception { doTest(); }
81
82   public void testBlock() throws Exception { doTest(); }
83
84   public void testTwoStatementsInLine() throws Exception { doTest(); }
85
86   public void testFor() throws Exception { doTest(); }
87
88   public void testForEach() throws Exception { doTest(); }
89
90   public void testForBlock() throws Exception { doTest(); }
91
92   public void testForIncrementExpressionAndBody() throws Exception { doTest(); }
93
94   public void testEmptyBeforeReturn() throws Exception { doTest(); }
95
96   public void testIf() throws Exception { doTest(); }
97
98   public void testBeforeStatement() throws Exception { doTest(); }
99
100   public void testTry1() throws Exception { doTest(); }
101
102   public void testBlock1() throws Exception { doTest(); }
103
104   public void testAfterFor() throws Exception { doTest(); }
105
106   public void testBeforeFor() throws Exception { doTest(); }
107
108   public void testAtBlockEnd() throws Exception { doTest(); }
109
110   public void testForceBlock() throws Exception { doTest(); }
111
112   public void testElseIf() throws Exception { doTest(); }
113
114   public void testIncompleteElseIf() throws Exception { doTest(); }
115
116   public void testField() throws Exception { doTest(); }
117
118   public void testMethod() throws Exception { doTest(); }
119
120   public void testClass() throws Exception { doTest(); }
121   
122   public void testInnerEnumBeforeMethod() { doTest(); }
123   
124   public void testInnerEnumBeforeMethodWithSpace() { doTest(); }
125
126   public void testCompleteElseIf() throws Exception { doTest(); }
127
128   public void testCompleteStringLiteral() throws Exception {
129     doTest();
130   }
131
132   public void testNonAbstractMethodWithSemicolon() throws Exception { doTest(); }
133
134   public void testReturnFromNonVoid() throws Exception { doTest(); }
135
136   public void testReturnFromVoid() throws Exception { doTest(); }
137
138   public void testIncompleteCall() throws Exception { doTest(); }
139
140   public void testCompleteCall() throws Exception { doTest(); }
141
142   public void testStartNewBlock() throws Exception { doTest(); }
143
144   public void testInPreceedingBlanks() throws Exception { doTest(); }
145
146   public void testNoBlockReturn() throws Exception { doTest(); }
147
148   public void testInComment() throws Exception { doTest(); }
149
150   public void testInComment2() throws Exception { doTest(); }
151   public void testInComment3() throws Exception { doTest(); }
152   public void testInComment4() throws Exception { doTest(); }
153
154   public void testSCR22904() throws Exception { doTest(); }
155   public void testSCR30227() throws Exception { doTest(); }
156
157   public void testFieldWithInitializer() throws Exception { doTest(); }
158
159   public void testFieldBeforeAnnotation() throws Exception { doTest(); }
160   public void testMethodBeforeAnnotation() throws Exception { doTest(); }
161   public void testMethodBeforeCommentField() throws Exception { doTest(); }
162   public void testMethodBeforeCommentMethod() throws Exception { doTest(); }
163
164   public void testParenthesized() throws Exception { doTest(); }
165
166   public void testCompleteBreak() throws Exception {
167     doTest();
168   }
169
170   public void testCompleteIfNextLineBraceStyle() throws Exception {
171     CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
172     settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
173     doTest();
174     settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
175   }
176
177   public void testCompleteIfNextLineBraceStyle2() throws Exception {
178     CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
179     settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
180     doTest();
181     settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
182   }
183
184   public void testSCR36110() throws Exception {
185     doTest();
186   }
187
188   public void testSCR37331() throws Exception { doTest(); }
189   public void testIDEADEV434() throws Exception {
190     CodeStyleSettingsManager.getSettings(getProject()).KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
191     doTest();
192     CodeStyleSettingsManager.getSettings(getProject()).KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
193     doTest();
194   }
195
196   public void testIDEADEV1093() throws Exception { doTest(); }
197
198   public void testIDEADEV1710() throws Exception { doTest(); }
199
200   public void testInterfaceMethodSemicolon() throws Exception { doTest(); }
201
202   public void testSynchronized() throws Exception { doTest(); }
203
204   public void testCdrEndlessLoop() throws Exception { doTest(); }
205
206   public void testFollowedByComment() throws Exception { doTest(); }
207
208   public void testBraceFixeNewLine() throws Exception { doTest(); }
209
210   public void testSwitchKeyword() throws Exception { doTest(); }
211
212   public void testSwitchKeywordWithCondition() throws Exception { doTest(); }
213   public void testCaseColon() { doTest(); }
214
215   public void testNewInParentheses() throws Exception { doTest(); }
216   
217   public void testIDEADEV20713() throws Exception { doTest(); }
218
219   public void testIDEA22125() throws Exception { doTest(); }
220   
221   public void testIDEA22385() throws Exception { doTest(); }
222
223   public void testIDEADEV40479() throws Exception { doTest(); }
224
225   public void testMultilineReturn() throws Exception { doTest(); }
226   public void testMultilineCall() throws Exception { doTest(); }
227
228   public void testIDEADEV13019() throws Exception {
229     doTestBracesNextLineStyle();
230   }
231
232   public void testIDEA25139() throws Exception {
233     doTestBracesNextLineStyle();
234   }
235   
236   public void testBeforeIfRBrace() throws Exception {
237     CodeStyleSettingsManager.getSettings(getProject()).KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
238     doTest();
239   }
240
241   public void testNoUnnecessaryEmptyLineAtCodeBlock() throws Exception { doTest(); }
242
243   public void testForStatementGeneration() throws Exception { doTest(); }
244
245   public void testSpaceAfterSemicolon() throws Exception {
246     CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = true;
247     doTest();
248   }
249
250   public void testNoSpaceAfterSemicolon() throws Exception {
251     CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = false;
252     doTest();
253   }
254   
255   public void testForUpdateGeneration() throws Exception { doTest(); }
256
257   public void testValidCodeBlock() throws Exception { doTest(); }
258
259   public void testValidCodeBlockWithEmptyLineAfterIt() throws Exception { doTest(); }
260   
261   public void testFromJavadocParameterDescriptionEndToNextParameter() throws Exception { doTest(); }
262
263   public void testFromJavadocParameterDescriptionMiddleToNextParameter() throws Exception { doTest(); }
264
265   public void testLastJavadocParameterDescription() throws Exception { doTest(); }
266   
267   public void testLastJavadocParameterDescriptionToReturn() throws Exception { doTest(); }
268   
269   public void testCompleteMethodCallAtReturn() throws Exception { doTest(); }
270   
271   public void testGenericMethodBody() throws Exception { doTest(); }
272
273   public void testDefaultMethodBody() { doTest(); }
274
275   public void testArrayInitializerRBracket() throws Exception { doTest(); }
276   
277   public void testReturnInLambda() { doTest(); }
278   
279   private void doTestBracesNextLineStyle() throws Exception {
280     CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
281     settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
282     settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
283     settings.CLASS_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
284     try {
285       doTest();
286     }
287     finally {
288       settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
289       settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
290       settings.CLASS_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
291     }
292   }
293
294   private void doTest() {
295     doTest("java");
296   }
297
298   private void doTest(String ext) {
299     String path = "/codeInsight/completeStatement/";
300     doFileTest(path + getTestName(false) + "." + ext, path + getTestName(false) + "_after." + ext, true);
301   }
302
303   @Override
304   protected String getActionId() {
305     return IdeActions.ACTION_EDITOR_COMPLETE_STATEMENT;
306   }
307
308   @NotNull
309   @Override
310   protected String getTestDataPath() {
311     return JavaTestUtil.getJavaTestDataPath();
312   }
313 }