diff options
Diffstat (limited to 'java/java-tests/testSrc/com')
7 files changed, 480 insertions, 25 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrls7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrls7Test.java new file mode 100644 index 000000000000..dce86df31fa3 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrls7Test.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight; + +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.annotations.NotNull; + +public class ExternalJavadocUrls7Test extends ExternalJavadocUrlsTest { + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_1_7; + } + + @Override + public void testVarargs() { + doTest("class Test {\n" + + " void <caret>foo(Class<?>... cl) { }\n" + + "}", + + "foo(java.lang.Class...)", "foo(java.lang.Class<?>...)" + ); + } + + @Override + public void testTypeParams() { + doTest("class Test {\n" + + " <T> void <caret>sort(T[] a, Comparator<? super T> c) { }\n" + + "}\n" + + "class Comparator<X>{}", + + "sort(T[], Comparator)", "sort(T[], Comparator<? super T>)" + ); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrlsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrlsTest.java index 9ec54f425d69..28fb79a594ed 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrlsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ExternalJavadocUrlsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,34 +19,51 @@ import com.intellij.lang.java.JavaDocumentationProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; + +import java.util.List; -/** - * User: anna - * Date: 11/27/11 - */ public class ExternalJavadocUrlsTest extends LightCodeInsightFixtureTestCase { - private void doTest(String text, String... expectedSignature) { - myFixture.configureByText("Test.java", text); - final PsiElement elementAtCaret = myFixture.getElementAtCaret(); - final PsiMethod member = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethod.class, false); - assertNotNull(member); - final String signature = JavaDocumentationProvider.formatMethodSignature(member); - assertNotNull(signature); - assertEquals("found:" + signature, expectedSignature[0], signature); + @Override + protected void setUp() throws Exception { + super.setUp(); + PsiTestUtil.setJavadocUrls(myModule, "http://doc" ); } public void testVarargs() { doTest("class Test {\n" + - " void fo<caret>o(Class<?>... cl){}\n" + - "}", "foo(java.lang.Class...)"); + " void <caret>foo(Class<?>... cl) { }\n" + + "}", + + "foo-java.lang.Class...-", "foo-java.lang.Class<?>...-"); } - + public void testTypeParams() { doTest("class Test {\n" + - " <T> void so<caret>rt(T[] a, Comparator<? super T> c) {}\n" + + " <T> void <caret>sort(T[] a, Comparator<? super T> c) { }\n" + "}\n" + - " class Comparator<X>{}", "sort(T[], Comparator)"); + "class Comparator<X>{}", + + "sort-T:A-Comparator-", "sort-T:A-Comparator<? super T>-"); + } + + protected void doTest(String text, String... expected) { + myFixture.configureByText("Test.java", text); + PsiElement elementAtCaret = myFixture.getElementAtCaret(); + PsiMethod member = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethod.class, false); + assertNotNull(member); + List<String> urls = JavaDocumentationProvider.getExternalJavaDocUrl(member); + assertNotNull(urls); + List<String> actual = ContainerUtil.map(urls, new Function<String, String>() { + @Override + public String fun(String url) { + return url.substring(url.indexOf('#') + 1); + } + }); + assertOrderedEquals(actual, expected); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy index 669f0f53bed2..4cad78b0c467 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy @@ -61,6 +61,44 @@ $some_long_variable_name<caret> } + public void testFromAnotherFile2() { + myFixture.configureByText "b.txt", ''' +foo function foo2 +''' + myFixture.configureByText "a.txt", ''' +f<caret> +''' + + complete() + myFixture.checkResult ''' +foo2<caret> +''' + complete() + myFixture.checkResult ''' +function<caret> +''' + complete() + myFixture.checkResult ''' +foo<caret> +''' + myFixture.configureByText "a.txt", ''' +f<caret> +''' + backComplete() + myFixture.checkResult ''' +foo<caret> +''' + + backComplete() + myFixture.checkResult ''' +function<caret> +''' + backComplete() + myFixture.checkResult ''' +foo2<caret> +''' + } + public void "test no middle matching"() { myFixture.configureByText "a.txt", ''' fooExpression diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy index 01af09c888b7..2f69074960ef 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -76,7 +76,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { final LookupImpl lookup = invokeCompletion(getTestName(false) + ".html"); assertPreferredItems(0, "p", "param", "pre"); incUseCount(lookup, 2); - assertPreferredItems(1, "p", "pre", "param"); + assertPreferredItems(0, "p", "pre", "param"); } public void testUppercaseMatters2() throws Throwable { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/CanBeFinalTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/CanBeFinalTest.java index f01ecb243249..bb77b6b9bb18 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/CanBeFinalTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/CanBeFinalTest.java @@ -42,6 +42,10 @@ public class CanBeFinalTest extends InspectionTestCase { doTest(); } + public void testanonymous() throws Exception { + doTest(); + } + public void testmethodInheritance() throws Exception { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaCodeBlockBracesPlacementTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaCodeBlockBracesPlacementTest.java new file mode 100644 index 000000000000..dbd5beba9d57 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaCodeBlockBracesPlacementTest.java @@ -0,0 +1,352 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.formatter.java; + +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; + +public class JavaCodeBlockBracesPlacementTest extends AbstractJavaFormatterTest { + + public void testSimpleTryBlock() throws Exception { + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + + String before = "try {} catch (Exception e) {\n" + + " System.out.println(\"AA!\");\n" + + "}"; + + String endOfLine = "try {} catch (Exception e) {\n" + + " System.out.println(\"AA!\");\n" + + "}"; + + String nextLine = "try {} catch (Exception e)\n" + + "{\n" + + " System.out.println(\"AA!\");\n" + + "}"; + + String nextLineShifted = "try {} catch (Exception e)\n" + + " {\n" + + " System.out.println(\"AA!\");\n" + + " }"; + + String nextLineShiftedEach = "try {} catch (Exception e)\n" + + " {\n" + + " System.out.println(\"AA!\");\n" + + " }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleCatchBlock() throws Exception { + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + + String before = "try {\n" + + " System.out.println(\"AA!\");\n" + + "} catch (Exception e) { System.out.println(\"AA!\"); }"; + + String endOfLine = "try {\n" + + " System.out.println(\"AA!\");\n" + + "} catch (Exception e) { System.out.println(\"AA!\"); }"; + + String nextLine = "try\n" + + "{\n" + + " System.out.println(\"AA!\");\n" + + "} catch (Exception e) { System.out.println(\"AA!\"); }"; + + String nextLineShifted = "try\n" + + " {\n" + + " System.out.println(\"AA!\");\n" + + " } catch (Exception e) { System.out.println(\"AA!\"); }"; + + String nextLineShiftedEach = "try\n" + + " {\n" + + " System.out.println(\"AA!\");\n" + + " } catch (Exception e) { System.out.println(\"AA!\"); }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleCatchAndTryBlock() throws Exception { + String before = "try {} catch (Exception e) { System.out.println(\"AA!\"); }"; + String after = "try {} catch (Exception e) { System.out.println(\"AA!\"); }"; + String afterExpanded = "try {\n" + + "} catch (Exception e) {\n" + + " System.out.println(\"AA!\");\n" + + "}"; + + doMethodTest(before, afterExpanded); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + + public void testDoWhileStatement() throws Exception { + String before = "do {\n" + + " System.out.println(\"AAA!\");\n" + + "} while (1 == 1);"; + + String endOfLine = "do {\n" + + " System.out.println(\"AAA!\");\n" + + "} while (1 == 1);"; + + String nextLine = "do\n" + + "{\n" + + " System.out.println(\"AAA!\");\n" + + "} while (1 == 1);"; + + String nextLineShifted = "do\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " } while (1 == 1);"; + + String nextLineShiftedEach = "do\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " } while (1 == 1);"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleDoWhileStatement() throws Exception { + String before = "do { System.out.println(\"AAA!\"); } while (1 == 1);"; + String after = "do { System.out.println(\"AAA!\"); } while (1 == 1);"; + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + public void testForEachStatement() throws Exception { + String before = "for (String arg : args) {\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String endOfLine = "for (String arg : args) {\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String nextLine = "for (String arg : args)\n" + + "{\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String nextLineShifted = "for (String arg : args)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }"; + + String nextLineShiftedEach = "for (String arg : args)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleForEachStatement() throws Exception { + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + + String before = "for (String arg : args) { System.out.println(\"AAA!\"); }"; + String after = "for (String arg : args) { System.out.println(\"AAA!\"); }"; + + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + public void testForStatement() throws Exception { + String before = "for (int i = 0; i < 10; i = i + 3) {\n" + + " System.out.println(\"AAA!\");\n" + + "}\n"; + + String endOfLine = "for (int i = 0; i < 10; i = i + 3) {\n" + + " System.out.println(\"AAA!\");\n" + + "}\n"; + + String nextLine = "for (int i = 0; i < 10; i = i + 3)\n" + + "{\n" + + " System.out.println(\"AAA!\");\n" + + "}\n"; + + String nextLineShifted = "for (int i = 0; i < 10; i = i + 3)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }\n"; + + String nextLineShiftedEach = "for (int i = 0; i < 10; i = i + 3)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }\n"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleForStatement() throws Exception { + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + + String before = "for (int i = 0; i < 10; i = i + 3) { System.out.println(\"AAA!\"); }"; + String after = "for (int i = 0; i < 10; i = i + 3) { System.out.println(\"AAA!\"); }"; + + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + + public void testSwitchStatement() throws Exception { + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; + + String before = "switch (timeUnit) {\n" + + " case DAYS:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + "}"; + + String endOfLine = "switch (timeUnit) {\n" + + " case DAYS:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + "}"; + + String nextLine = "switch (timeUnit)\n" + + "{\n" + + " case DAYS:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + "}"; + + String nextLineShifted = "switch (timeUnit)\n" + + " {\n" + + " case DAYS:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }"; + + String nextLineShiftedEach = "switch (timeUnit)\n" + + " {\n" + + " case DAYS:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSynchronizedStatement() throws Exception { + String before = "synchronized (this) {\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String endOfLine = "synchronized (this) {\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String nextLine = "synchronized (this)\n" + + "{\n" + + " System.out.println(\"AAA!\");\n" + + "}"; + + String nextLineShifted = "synchronized (this)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }"; + + String nextLineShiftedEach = "synchronized (this)\n" + + " {\n" + + " System.out.println(\"AAA!\");\n" + + " }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleSynchronizedStatement() throws Exception { + String before = "synchronized (this) { System.out.println(\"AAA!\"); }"; + String after = "synchronized (this) { System.out.println(\"AAA!\"); }"; + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + public void testWhileStatement() throws Exception { + String before = "while (true) {\n" + + " System.out.println(\"AAA\");\n" + + "}"; + + String endOfLine = "while (true) {\n" + + " System.out.println(\"AAA\");\n" + + "}"; + + String nextLine = "while (true)\n" + + "{\n" + + " System.out.println(\"AAA\");\n" + + "}"; + + String nextLineShifted = "while (true)\n" + + " {\n" + + " System.out.println(\"AAA\");\n" + + " }"; + + String nextLineShiftedEach = "while (true)\n" + + " {\n" + + " System.out.println(\"AAA\");\n" + + " }"; + + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, endOfLine, nextLine, nextLineShifted, nextLineShiftedEach); + } + + public void testSimpleWhileStatement() throws Exception { + String before = "while (true) { System.out.println(\"AAA\"); }"; + String after = "while (true) { System.out.println(\"AAA\"); }"; + + getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + checkFormatterWithDifferentBraceStyles(before, after, after, after, after); + } + + private void checkFormatterWithDifferentBraceStyles(String before, + String endOfLine, + String nextLine, + String nextLineShifted, + String nextLineShiftedEach) throws Exception + { + formatAndCheck(CommonCodeStyleSettings.END_OF_LINE, before, endOfLine); + formatAndCheck(CommonCodeStyleSettings.NEXT_LINE, before, nextLine); + formatAndCheck(CommonCodeStyleSettings.NEXT_LINE_SHIFTED, before, nextLineShifted); + formatAndCheck(CommonCodeStyleSettings.NEXT_LINE_SHIFTED2, before, nextLineShiftedEach); + } + + private void formatAndCheck(int braceStyle, String before, String after) throws Exception { + getSettings().BRACE_STYLE = braceStyle; + doMethodTest(before, after); + } +} diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterTest.java index b9b652d92417..8adb06b24d19 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterTest.java @@ -2195,12 +2195,8 @@ public void testSCR260() throws Exception { getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true; getSettings().ALIGN_MULTILINE_PARAMETERS = true; getSettings().METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; - doTextTest("class TEst {\n" + - " void foo(A a,B b){ /* compiled code */ }\n" + - "}", - "class TEst {\n" + - " void foo(A a,\n" + - " B b) { /* compiled code */ }\n" + "}"); + doTextTest("class TEst {\n" + "void foo(A a,B b){ /* compiled code */ }\n" + "}", + "class TEst {\n" + " void foo(A a, B b)\n" + " { /* compiled code */ }\n" + "}"); } public void testSCR1615() throws Exception { |