diff options
Diffstat (limited to 'java/java-tests/testSrc/com/intellij')
24 files changed, 469 insertions, 134 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java index ae0ec20ab4d2..8383550b3e5c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java @@ -20,6 +20,8 @@ import com.intellij.pom.java.LanguageLevel; public class ClsGenerics18HighlightingTest extends ClsGenericsHighlightingTest { public void testIDEA121866() { doTest(); } + public void testIDEA127714() { doTest(); } + @Override protected LanguageLevel getLanguageLevel() { return LanguageLevel.JDK_1_8; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java index 2eecdaa9b221..3f199d44ea13 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java @@ -17,9 +17,6 @@ package com.intellij.codeInsight; import com.intellij.JavaTestUtil; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; @@ -54,6 +51,18 @@ public class CompleteStatementTest extends EditorActionTestCase { public void testCompleteCatchLParen() throws Exception { doTest(); } + public void testAlreadyCompleteCatch() throws Exception { + CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + int old = settings.BRACE_STYLE; + settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; + try { + doTest(); + } + finally { + settings.BRACE_STYLE = old; + } + } + public void testCompleteCatchWithExpression() throws Exception { doTest(); } public void testCompleteCatchBody() throws Exception { doTest(); } @@ -171,8 +180,6 @@ public class CompleteStatementTest extends EditorActionTestCase { } public void testSCR36110() throws Exception { - JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject()); - LanguageLevel old = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel(); doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java index f59162a6d5b2..9ca3b6084a43 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.psi.PsiDocumentManager; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; @@ -65,6 +66,14 @@ public class JavaTypingTest extends LightPlatformCodeInsightFixtureTestCase { myFixture.checkResultByFile(getTestName(true) + "_after.java"); } + public void testInvalidInitialSyntax() { + myFixture.configureByFile(getTestName(true) + "_before.java"); + myFixture.type('\\'); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // emulates background commit after typing first character + myFixture.type('\\'); + myFixture.checkResultByFile(getTestName(true) + "_after.java"); + } + private void doTest(char c) { myFixture.configureByFile(getTestName(true) + "_before.java"); myFixture.type(c); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 77b4c0cc64a7..f5fc39041106 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1423,6 +1423,11 @@ class XInternalError {} checkResult() } + public void testMulticaretCompletionFromNonPrimaryCaret() { + configure() + myFixture.assertPreferredCompletionItems(0, "arraycopy") + } + public void "test complete lowercase class name"() { myFixture.addClass("package foo; public class myClass {}") myFixture.configureByText "a.java", """ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy index 1d258fe01367..f37b90e21523 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy @@ -160,6 +160,10 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { checkPreferredItems(0, "myVersion", "getVersion", "getSelectedVersion", "calculateVersion"); } + public void testPreferFieldsToConstants() { + checkPreferredItems(0, "dateField", "LocalDate.MAX", "LocalDate.MIN"); + } + public void testPreferParametersToGetters() throws Throwable { checkPreferredItems(0, "a", "I._1", "getLastI", "valueOf"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index d2e8825cc16d..5153f19fe94a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -716,7 +716,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testMethodColon() throws Exception { doFirstItemTest(':'); } public void testVariableColon() throws Exception { doFirstItemTest(':'); } - private void doFirstItemTest(char c) throws Exception { + private void doFirstItemTest(char c) { configureByTestName(); select(c); checkResultByTestName(); @@ -824,6 +824,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doActionTest(); } + public void testDontSuggestWildcardGenerics() { doItemTest(); } + public void testCastWith2TypeParameters() throws Throwable { doTest(); } public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); } public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); } @@ -1141,7 +1143,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { checkResultByTestName(); } - private void doItemTest() throws Exception { + private void doItemTest() { doFirstItemTest('\n'); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 79506280a778..6ccefa35ae51 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -188,6 +188,22 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testInferFromConditionalExpressionCondition() throws Exception { + doTest(); + } + + public void testPrimitiveWrapperConditionInReturnConstraint() throws Exception { + doTest(); + } + + public void testIDEA128174() throws Exception { + doTest(); + } + + public void testIDEA128101() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java index fbf8036e8e35..156aac5613c1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java @@ -106,6 +106,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testIDEA127765() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java new file mode 100644 index 000000000000..b94e54d91323 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java @@ -0,0 +1,59 @@ +/* + * 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.folding; + +import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.FoldingModelEx; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; + +public class JavaFoldingGotoTest extends JavaCodeInsightFixtureTestCase { + + public void testIDEA127145() { + PsiFile file = myFixture.addFileToProject("Program.java", + "import java.io.InputStream;\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "class Program {\n" + + " private static InputStream getFile(String name, Map<String, Object> args) {\n" + + " return Program.class.getResourceAsStream(name);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " // Ctrl + B or Ctrl + Left Mouse Button work correctly for following string:\n" + + " final String name = \"file.sql\";\n" + + " // But it jumps only to folder in following case:\n" + + " final InputStream inputStream = getFile(\"dir/fil<caret>e.sql\", new HashMap<String, Object>());\n" + + " }\n" + + "}"); + + PsiFile fileSql = myFixture.addFileToProject("dir/file.sql", "select 1;"); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + + Editor editor = myFixture.getEditor(); + CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(editor); + FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); + foldingModel.rebuild(); + myFixture.doHighlighting(); + + PsiElement element = GotoDeclarationAction.findTargetElement(getProject(), editor, editor.getCaretModel().getOffset()); + assertTrue("Should navigate to: file.sql instead of " + element, element != null && element.equals(fileSql)); + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy index 5d823e001f82..095de51543af 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy @@ -568,14 +568,20 @@ class Test { public void "test fold one-line methods"() { configure """class Foo { + @Override int someMethod() { return 0; } + int someOtherMethod( + int param) { + return 0; + } + }""" PsiClass fooClass = JavaPsiFacade.getInstance(project).findClass('Foo', GlobalSearchScope.allScope(project)) def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset } - assert regions.size() == 2 + assert regions.size() == 3 checkAccessorFolding(regions[0], regions[1], fooClass.methods[0]) } @@ -792,13 +798,14 @@ public class CharSymbol { assert regions[3].placeholderText == 'seq: "Hi!"' } - public void "test inline negative numbers (IDEA-126753)"() { + public void "test inline negative and positive numbers"() { def text = """ public class CharSymbol { public void main() { Object obj = new Object(); count(-1, obj); + count(+1, obj); } public void count(int test, Object obj) { @@ -809,10 +816,13 @@ public class CharSymbol { """ configure text def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset } - assert regions.size() == 3 + assert regions.size() == 4 checkRangeOffsetByPositionInText(regions[1], text, "-1") assert regions[1].placeholderText == "test: -1" + + checkRangeOffsetByPositionInText(regions[2], text, "+1") + assert regions[2].placeholderText == "test: +1" } public void "test inline constructor literal arguments names"() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java index 7f47795881bc..70061e56afa9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java @@ -38,4 +38,9 @@ public class NullPostfixTemplateTest extends PostfixTemplateTestCase { public void testSecondStatement() { doTest(); } + + + public void testSingleExclamationIgnored() { + doTest(); + } }
\ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index 23eac589e2db..89762efe5dd2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -228,6 +228,34 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == [] } + public void "test boolean autoboxing in delegation"() { + def c = inferContracts(""" + static Boolean test04(String s) { + return test03(s); + } + static boolean test03(String s) { + return s == null; + } + """) + assert c == [] + } + + public void "test boolean auto-unboxing"() { + def c = inferContracts(""" + static boolean test02(String s) { + return test01(s); + } + + static Boolean test01(String s) { + if (s == null) + return new Boolean(false); + else + return null; + } + """) + assert c == [] + } + public void "test non-returning delegation"() { def c = inferContracts(""" static void test2(Object o) { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 4cba2ab918a7..33eb32eb0ec6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -18,6 +18,7 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; @@ -251,15 +252,17 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testRootThrowableCause() { doTest(); } public void testUseInferredContracts() { doTest(); } + public void testContractWithNoArgs() { doTest(); } public void testContractInferenceBewareOverriding() { doTest(); } public void testNumberComparisonsWhenValueIsKnown() { doTest(); } + public void testFloatComparisons() { doTest(); } public void testAccessingSameArrayElements() { doTest(); } public void testParametersAreNonnullByDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}"); + addJavaxNullabilityAnnotations(myFixture); + addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addClass("package foo; public class AnotherPackageNotNull { public static void foo(String s) {}}"); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); @@ -267,6 +270,37 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { doTest(); } + public static void addJavaxDefaultNullabilityAnnotations(final JavaCodeInsightTestFixture fixture) { + fixture.addClass("package javax.annotation;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.PARAMETER) @javax.annotation.Nonnull " + + "public @interface ParametersAreNonnullByDefault {}"); + fixture.addClass("package javax.annotation;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.PARAMETER) @javax.annotation.Nullable " + + "public @interface ParametersAreNullableByDefault {}"); + } + + public static void addJavaxNullabilityAnnotations(final JavaCodeInsightTestFixture fixture) { + fixture.addClass("package javax.annotation;" + + "public @interface Nonnull {}"); + fixture.addClass("package javax.annotation;" + + "public @interface Nullable {}"); + fixture.addClass("package javax.annotation.meta;" + + "public @interface TypeQualifierDefault { java.lang.annotation.ElementType[] value() default {};}"); + } + + public void testCustomTypeQualifierDefault() { + addJavaxNullabilityAnnotations(myFixture); + myFixture.addClass("package bar;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.METHOD) @javax.annotation.Nonnull " + + "public @interface MethodsAreNotNullByDefault {}"); + + myFixture.addClass("package foo; public class AnotherPackageNotNull { public static native Object foo(String s); }"); + myFixture.addFileToProject("foo/package-info.java", "@bar.MethodsAreNotNullByDefault package foo;"); + + myFixture.enableInspections(new DataFlowInspection()); + myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); + } + public void testTrueOrEqualsSomething() { doTest(); myFixture.launchAction(myFixture.findSingleIntention("Remove redundant assignment")); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java index e925dd49a8ea..3520ec08d750 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java @@ -40,8 +40,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorSuperParameterDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface Nullable {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.addClass("import javax.annotation.*; package foo; public interface NullableFunction { void fun(@Nullable Object o); }"); @@ -51,7 +51,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorThisParameterDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java")); @@ -60,8 +61,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorParameterDefaultInSetters() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface Nullable {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java")); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java index 09fa87fa95e9..9d26fd804f68 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java @@ -183,7 +183,7 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase { private void checkCompoundId(Method method, PsiMethod psiMethod, boolean noKey) throws IOException { Direction direction = new Out(); - int psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction); + long psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction); if (noKey) { assertTrue(-1 == psiKey); return; @@ -192,7 +192,7 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase { assertFalse(-1 == psiKey); } - int asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true)); + long asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true)); Assert.assertEquals(asmKey, psiKey); } diff --git a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java index 02f8c589c43b..3cc6c19618a1 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java @@ -19,7 +19,9 @@ import com.intellij.find.editorHeaderActions.*; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.util.Getter; +import com.intellij.testFramework.fixtures.EditorMouseFixture; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; import javax.swing.text.JTextComponent; @@ -58,7 +60,7 @@ public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureT assertNull(getEditorSearchComponent()); } - public void testActionsWorkFromEditor() throws IOException { + public void testActionsInEditorWorkIndependently() throws IOException { init("abc\n" + "abc\n" + "abc"); @@ -67,27 +69,29 @@ public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureT checkResultByText("a<selection>b<caret></selection>c\n" + "abc\n" + "abc"); + new EditorMouseFixture((EditorImpl)myFixture.getEditor()).clickAt(0, 1); addOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + + addOccurrenceFromEditor(); + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + "abc"); nextOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + - "a<selection>b<caret></selection>c"); + "<selection>a<caret>bc</selection>"); prevOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + "abc"); removeOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + "abc"); allOccurrencesFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c"); - assertNull(getEditorSearchComponent()); + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>"); + assertNotNull(getEditorSearchComponent()); } public void testCloseRetainsMulticaretSelection() throws IOException { diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java index 92caad03d8ef..f83d836bb55a 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java @@ -579,7 +579,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { FindModel findModel = FindManagerTestUtils.configureFindModel("done"); String text = "/** done done done */"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text); findModel.setRegularExpressions(true); @@ -592,7 +592,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { String prefix = "/*"; String text = prefix + "done*/"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); LightVirtualFile file = new LightVirtualFile("A.java", text); FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); @@ -615,8 +615,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { FindModel findModel = FindManagerTestUtils.configureFindModel("^done$"); findModel.setRegularExpressions(true); - findModel.setInStringLiteralsOnly(true); - findModel.setInCommentsOnly(false); + findModel.setSearchContext(FindModel.SearchContext.IN_STRING_LITERALS); String text = "\"done\"; 'done'; 'done' \"done2\""; FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java"); @@ -633,7 +632,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { String text = "/** do ne do ne do ne */"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java"); } @@ -651,4 +650,42 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { findModel.setWholeWordsOnly(true); assertSize(1, findUsages(findModel)); } + + public void testFindExceptComments() { + FindModel findModel = FindManagerTestUtils.configureFindModel("done"); + + String prefix = "/*"; + String text = prefix + "done*/done"; + + findModel.setSearchContext(FindModel.SearchContext.EXCEPT_COMMENTS); + LightVirtualFile file = new LightVirtualFile("A.java", text); + + FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + + findModel.setRegularExpressions(true); + findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + } + + public void testFindExceptLiterals() { + FindModel findModel = FindManagerTestUtils.configureFindModel("done"); + + String prefix = "\""; + String text = prefix + "done\"done"; + + findModel.setSearchContext(FindModel.SearchContext.EXCEPT_STRING_LITERALS); + LightVirtualFile file = new LightVirtualFile("A.java", text); + + FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + + findModel.setRegularExpressions(true); + findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + } } diff --git a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy index dabe06ba79fa..9a97a825964a 100644 --- a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy +++ b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy @@ -24,7 +24,6 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.Consumer import com.intellij.util.concurrency.Semaphore import org.jetbrains.annotations.NotNull - /** * @author peter */ @@ -197,6 +196,33 @@ class Intf { assert getPopupElements(new GotoClassModel2(project), 'Bar:[2,3]') == [c] } + public void "test dollar"() { + def bar = myFixture.addClass("package foo; class Bar { class Foo {} }") + def foo = bar.innerClasses[0] + myFixture.addClass("package goo; class Goo { }") + assert getPopupElements(new GotoClassModel2(project), 'Bar$Foo') == [foo] + assert getPopupElements(new GotoClassModel2(project), 'foo.Bar$Foo') == [foo] + assert getPopupElements(new GotoClassModel2(project), 'foo.B$F') == [foo] + assert !getPopupElements(new GotoClassModel2(project), 'foo$Foo') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Bar') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Bar$Foo') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Goo') + } + + public void "test anonymous classes"() { + def goo = myFixture.addClass("package goo; class Goo { Runnable r = new Runnable() {}; }") + assert getPopupElements(new GotoClassModel2(project), 'Goo$1') == [goo] + } + + public void "test qualified name matching"() { + def bar = myFixture.addClass("package foo.bar; class Bar { }") + def bar2 = myFixture.addClass("package goo.baz; class Bar { }") + assert getPopupElements(new GotoClassModel2(project), 'foo.Bar') == [bar] + assert getPopupElements(new GotoClassModel2(project), 'foo.bar.Bar') == [bar] + assert getPopupElements(new GotoClassModel2(project), 'goo.Bar') == [bar2] + assert getPopupElements(new GotoClassModel2(project), 'goo.baz.Bar') == [bar2] + } + public void "test super method in jdk"() { def ourRun = myFixture.addClass("package foo.bar; class Goo implements Runnable { public void run() {} }").methods[0] def sdkRun diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index 1e3e08a33ae7..56624594bb0e 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -49,7 +49,7 @@ import static java.util.Collections.singletonList; public class DirectoryIndexTest extends IdeaTestCase { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.DirectoryIndexTest"); - private DirectoryIndex myIndex; + private DirectoryIndexImpl myIndex; private Module myModule2, myModule3; private VirtualFile myRootVFile; @@ -65,6 +65,7 @@ public class DirectoryIndexTest extends IdeaTestCase { private VirtualFile myModule1OutputDir; private VirtualFile myResDir, myTestResDir; private VirtualFile myExcludedLibSrcDir, myExcludedLibClsDir; + private ProjectFileIndex myFileIndex; @Override protected void setUp() throws Exception { @@ -176,7 +177,8 @@ public class DirectoryIndexTest extends IdeaTestCase { } }); - myIndex = DirectoryIndex.getInstance(myProject); + myIndex = (DirectoryIndexImpl)DirectoryIndex.getInstance(myProject); + myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); // to not interfere with previous test firing vfs events VirtualFileManager.getInstance().syncRefresh(); } @@ -221,12 +223,12 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile cvs = myPack1Dir.createChildDirectory(this, "CVS"); assertNotInProject(cvs); - assertNull(ProjectRootManager.getInstance(myProject).getFileIndex().getPackageNameByDirectory(cvs)); + assertNull(myFileIndex.getPackageNameByDirectory(cvs)); } public void testDirsByPackageName() throws IOException { - checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibSrc, myFileLibCls, mySrcDir2, myLibSrcDir, myLibClsDir); - checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibCls, mySrcDir2, myLibClsDir); + checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibSrcDir, myLibClsDir); + checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibClsDir); checkPackage("pack1", true, myPack1Dir); checkPackage("pack1", false, myPack1Dir); @@ -257,6 +259,18 @@ public class DirectoryIndexTest extends IdeaTestCase { checkPackage("pack1", true, myPack1Dir, myModule3Dir); } + public void testPackageDirectoriesWithDots() throws IOException { + VirtualFile fooBar = mySrcDir1.createChildDirectory(this, "foo.bar"); + VirtualFile goo1 = fooBar.createChildDirectory(this, "goo"); + VirtualFile foo = mySrcDir2.createChildDirectory(this, "foo"); + VirtualFile bar = foo.createChildDirectory(this, "bar"); + VirtualFile goo2 = bar.createChildDirectory(this, "goo"); + + checkPackage("foo", false, foo); + checkPackage("foo.bar", false, bar, fooBar); + checkPackage("foo.bar.goo", false, goo2, goo1); + } + public void testCreateDir() throws Exception { String path = mySrcDir1.getPath().replace('/', File.separatorChar); assertTrue(new File(path + File.separatorChar + "dir1" + File.separatorChar + "dir2").mkdirs()); @@ -362,7 +376,8 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile ignoredFile = myModule1Dir.createChildData(this, "CVS"); DirectoryInfo info = myIndex.getInfoForFile(ignoredFile); assertTrue(info.isIgnored()); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(ignoredFile)); + assertTrue(myFileIndex.isExcluded(ignoredFile)); + assertTrue(myFileIndex.isUnderIgnored(ignoredFile)); } public void testAddModule() throws Exception { @@ -386,10 +401,12 @@ public class DirectoryIndexTest extends IdeaTestCase { public void testModuleUnderIgnoredDir() throws IOException { final VirtualFile ignored = myRootVFile.createChildDirectory(this, "RCS"); assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored)); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(ignored)); + assertTrue(myFileIndex.isExcluded(ignored)); + assertTrue(myFileIndex.isUnderIgnored(ignored)); final VirtualFile module4 = ignored.createChildDirectory(this, "module4"); assertFalse(FileTypeManager.getInstance().isFileIgnored(module4)); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(module4)); + assertTrue(myFileIndex.isExcluded(module4)); + assertTrue(myFileIndex.isUnderIgnored(module4)); new WriteCommandAction.Simple(getProject()) { @Override @@ -425,11 +442,12 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testExcludedDirsInLibraries() { - ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex(); - assertFalse(index.isInLibraryClasses(myExcludedLibClsDir)); - assertTrue(index.isExcluded(myExcludedLibClsDir)); - assertFalse(index.isInLibrarySource(myExcludedLibSrcDir)); - assertTrue(index.isExcluded(myExcludedLibSrcDir)); + assertFalse(myFileIndex.isInLibraryClasses(myExcludedLibClsDir)); + assertTrue(myFileIndex.isExcluded(myExcludedLibClsDir)); + assertFalse(myFileIndex.isUnderIgnored(myExcludedLibClsDir)); + assertFalse(myFileIndex.isInLibrarySource(myExcludedLibSrcDir)); + assertTrue(myFileIndex.isExcluded(myExcludedLibSrcDir)); + assertFalse(myFileIndex.isUnderIgnored(myExcludedLibSrcDir)); } public void testExplicitExcludeOfInner() throws Exception { @@ -469,12 +487,12 @@ public class DirectoryIndexTest extends IdeaTestCase { ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Collections.<String>emptyList(), Arrays.asList(mySrcDir1.getUrl())); checkInfo(mySrcDir1, myModule, false, true, "", JavaSourceRootType.SOURCE, myModule, myModule); - OrderEntry[] entries = myIndex.getInfoForFile(mySrcDir1).getOrderEntries(); + OrderEntry[] entries = myIndex.getOrderEntries(myIndex.getInfoForFile(mySrcDir1)); assertInstanceOf(entries[0], LibraryOrderEntry.class); assertInstanceOf(entries[1], ModuleSourceOrderEntry.class); checkInfo(myTestSrc1, myModule, false, true, "testSrc", JavaSourceRootType.TEST_SOURCE, myModule, myModule); - entries = myIndex.getInfoForFile(myTestSrc1).getOrderEntries(); + entries = myIndex.getOrderEntries(myIndex.getInfoForFile(myTestSrc1)); assertInstanceOf(entries[0], LibraryOrderEntry.class); assertInstanceOf(entries[1], ModuleSourceOrderEntry.class); } @@ -482,7 +500,7 @@ public class DirectoryIndexTest extends IdeaTestCase { public void testModuleSourceAsLibraryClasses() throws Exception { ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Arrays.asList(mySrcDir1.getUrl()), Collections.<String>emptyList()); checkInfo(mySrcDir1, myModule, true, false, "", JavaSourceRootType.SOURCE, myModule); - assertInstanceOf(assertOneElement(assertInProject(mySrcDir1).getOrderEntries()), ModuleSourceOrderEntry.class); + assertInstanceOf(assertOneElement(myIndex.getOrderEntries(assertInProject(mySrcDir1))), ModuleSourceOrderEntry.class); } public void testModulesWithSameSourceContentRoot() { @@ -645,7 +663,7 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule, myModule3); checkInfo(myResDir, myModule, true, false, "", JavaResourceRootType.RESOURCE, myModule); - assertInstanceOf(assertOneElement(assertInProject(myResDir).getOrderEntries()), ModuleSourceOrderEntry.class); + assertInstanceOf(assertOneElement(myIndex.getOrderEntries(assertInProject(myResDir))), ModuleSourceOrderEntry.class); checkInfo(myExcludedLibSrcDir, null, true, false, "lib.src.exc", null, myModule3, myModule); checkInfo(myExcludedLibClsDir, null, true, false, "lib.cls.exc", null, myModule3); @@ -661,10 +679,10 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testExcludeCompilerOutputOutsideOfContentRoot() throws Exception { - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - assertTrue(fileIndex.isExcluded(myOutputDir)); - assertTrue(fileIndex.isExcluded(myModule1OutputDir)); - assertFalse(fileIndex.isExcluded(myOutputDir.getParent())); + assertTrue(myFileIndex.isExcluded(myOutputDir)); + assertFalse(myFileIndex.isUnderIgnored(myOutputDir)); + assertTrue(myFileIndex.isExcluded(myModule1OutputDir)); + assertFalse(myFileIndex.isExcluded(myOutputDir.getParent())); assertExcludedFromProject(myOutputDir); assertExcludedFromProject(myModule1OutputDir); String moduleOutputUrl = myModule1OutputDir.getUrl(); @@ -677,7 +695,7 @@ public class DirectoryIndexTest extends IdeaTestCase { assertExcludedFromProject(myOutputDir); assertExcludedFromProject(myModule1OutputDir); - assertTrue(fileIndex.isExcluded(myModule1OutputDir)); + assertTrue(myFileIndex.isExcluded(myModule1OutputDir)); PsiTestUtil.setCompilerOutputPath(myModule, moduleOutputUrl, true); PsiTestUtil.setCompilerOutputPath(myModule2, moduleOutputUrl, false); @@ -703,49 +721,47 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileContentAndSourceRoots() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileRoot = myRootVFile.createChildData(this, "fileRoot.txt"); VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); VirtualFile fileTestSourceRoot = myRootVFile.createChildData(this, "fileTestSourceRoot.txt"); assertNotInProject(fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot)); ContentEntry contentEntry = PsiTestUtil.addContentRoot(myModule, fileRoot); assertEquals(fileRoot, contentEntry.getFile()); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertFalse(fileIndex.isInSource(fileRoot)); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInSource(fileRoot)); PsiTestUtil.addContentRoot(myModule, fileSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); PsiTestUtil.addContentRoot(myModule, fileTestSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileTestSourceRoot, true); checkInfo(fileTestSourceRoot, myModule, false, false, "", JavaSourceRootType.TEST_SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileTestSourceRoot)); - assertTrue(fileIndex.isInSource(fileTestSourceRoot)); + assertTrue(myFileIndex.isInContent(fileTestSourceRoot)); + assertTrue(myFileIndex.isInSource(fileTestSourceRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); // removing file source root PsiTestUtil.removeSourceRoot(myModule, fileTestSourceRoot); checkInfo(fileTestSourceRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileTestSourceRoot)); - assertFalse(fileIndex.isInSource(fileTestSourceRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); + assertTrue(myFileIndex.isInContent(fileTestSourceRoot)); + assertFalse(myFileIndex.isInSource(fileTestSourceRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); // removing file content root - PsiTestUtil.removeContentEntry(myModule, contentEntry); + PsiTestUtil.removeContentEntry(myModule, contentEntry.getFile()); assertNotInProject(fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); - assertFalse(fileIndex.isInSource(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInSource(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot)); } private void assertIteratedContent(ProjectFileIndex fileIndex, @@ -764,63 +780,57 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileSourceRootsUnderDirContentRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileSourceRoot = myModule1Dir.createChildData(this, "fileSourceRoot.txt"); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); // removing file source root PsiTestUtil.removeSourceRoot(myModule, fileSourceRoot); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); } public void testFileModuleExcludeRootUnderDirectoryRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileExcludeRoot = mySrcDir1.createChildData(this, "fileExcludeRoot.txt"); - assertTrue(fileIndex.isInContent(fileExcludeRoot)); - assertTrue(fileIndex.isInSource(fileExcludeRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null); + assertTrue(myFileIndex.isInContent(fileExcludeRoot)); + assertTrue(myFileIndex.isInSource(fileExcludeRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null); PsiTestUtil.addExcludedRoot(myModule, fileExcludeRoot); - assertFalse(fileIndex.isInContent(fileExcludeRoot)); - assertFalse(fileIndex.isInSource(fileExcludeRoot)); + assertFalse(myFileIndex.isInContent(fileExcludeRoot)); + assertFalse(myFileIndex.isInSource(fileExcludeRoot)); assertExcluded(fileExcludeRoot, myModule); - assertIteratedContent(fileIndex, null, Arrays.asList(fileExcludeRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileExcludeRoot)); // removing file exclude root PsiTestUtil.removeExcludedRoot(myModule, fileExcludeRoot); - assertTrue(fileIndex.isInContent(fileExcludeRoot)); - assertTrue(fileIndex.isInSource(fileExcludeRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null); + assertTrue(myFileIndex.isInContent(fileExcludeRoot)); + assertTrue(myFileIndex.isInSource(fileExcludeRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null); } public void testFileModuleExcludeRootUnderFileRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileRoot = myRootVFile.createChildData(this, "fileRoot.txt"); PsiTestUtil.addContentRoot(myModule, fileRoot); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot), null); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null); PsiTestUtil.addExcludedRoot(myModule, fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); assertExcluded(fileRoot, myModule); - assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot)); // removing file exclude root PsiTestUtil.removeExcludedRoot(myModule, fileRoot); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot), null); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null); } public void testFileLibraryInsideFolderLibrary() throws IOException { @@ -835,8 +845,6 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileContentRootsModifications() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile temp = myRootVFile.createChildDirectory(this, "temp"); VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); @@ -845,54 +853,54 @@ public class DirectoryIndexTest extends IdeaTestCase { PsiTestUtil.addContentRoot(myModule, fileSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and recreate fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and move from another dir fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot.move(this, myRootVFile); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and copy from another dir fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot = fileSourceRoot.copy(this, myRootVFile, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and rename from another file fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = myRootVFile.createChildData(this, "temp_file.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot.rename(this, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); } private void checkInfo(VirtualFile file, @@ -914,15 +922,14 @@ public class DirectoryIndexTest extends IdeaTestCase { assertEquals(isInLibrary, info.hasLibraryClassRoot()); assertEquals(isInLibrarySource, info.isInLibrarySource()); - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); if (file.isDirectory()) { - assertEquals(packageName, fileIndex.getPackageNameByDirectory(file)); + assertEquals(packageName, myFileIndex.getPackageNameByDirectory(file)); } - assertEquals(Arrays.toString(info.getOrderEntries()), modulesOfOrderEntries.length, info.getOrderEntries().length); + assertEquals(Arrays.toString(myIndex.getOrderEntries(info)), modulesOfOrderEntries.length, myIndex.getOrderEntries(info).length); for (Module aModule : modulesOfOrderEntries) { - OrderEntry found = info.findOrderEntryWithOwnerModule(aModule); - assertNotNull("not found: " + aModule + " in " + Arrays.toString(info.getOrderEntries()), found); + OrderEntry found = myIndex.findOrderEntryWithOwnerModule(info, aModule); + assertNotNull("not found: " + aModule + " in " + Arrays.toString(myIndex.getOrderEntries(info)), found); } } @@ -941,7 +948,7 @@ public class DirectoryIndexTest extends IdeaTestCase { private DirectoryInfo assertInProject(VirtualFile file) { DirectoryInfo info = myIndex.getInfoForFile(file); assertTrue(file.toString(), info.isInProject()); - info.assertConsistency(); + myIndex.assertConsistency(info); return info; } @@ -957,6 +964,11 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY); assertNotNull(actualDirs); assertOrderedEquals(actualDirs, expectedDirs); + + for (VirtualFile dir : expectedDirs) { + String actualName = myIndex.getPackageName(dir); + assertEquals("Invalid package name for dir " + dir + ": " + packageName, packageName, actualName); + } } } diff --git a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java index 096547c4f4db..61414ab0b416 100644 --- a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java @@ -260,4 +260,20 @@ public class MiscPsiTest extends LightCodeInsightFixtureTestCase { assertEquals("some.unknown.Foo<? extends String>", type.getCanonicalText()); } + public void testNoPsiModificationsInUncommittedDocument() { + final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{}"); + Document document = file.getViewProvider().getDocument(); + document.insertString(0, " "); + + PsiClass psiClass = file.getClasses()[0]; + try { + psiClass.addBefore(PsiParserFacade.SERVICE.getInstance(getProject()).createWhiteSpaceFromText(" "), psiClass.getLBrace()); + fail(); + } + catch (IllegalStateException e) { + assertEquals("Attempt to modify PSI for non-committed Document!", e.getMessage()); + } + assertEquals("class A{}", psiClass.getText()); + assertEquals(" class A{}", document.getText()); + } } diff --git a/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy index d11a34f6e376..7b1861b9daec 100644 --- a/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy @@ -385,4 +385,28 @@ public class test { ] ) } + + void "test IDEA-128071"() { + doTest( + initial: ''' +public class FormatTest { + public int a = 3; + private static final String FACEBOOK_CLIENT_ID = ""; + public static final String FACEBOOK_OAUTH_URL = "".concat(FACEBOOK_CLIENT_ID).concat(""); +} +''', + expected: ''' +public class FormatTest { + private static final String FACEBOOK_CLIENT_ID = ""; + public static final String FACEBOOK_OAUTH_URL = "".concat(FACEBOOK_CLIENT_ID).concat(""); + public int a = 3; +} +''', + rules: [ + rule(PUBLIC, STATIC, FINAL), + rule(PRIVATE, STATIC, FINAL), + rule(PUBLIC) + ] + ) + } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java index 204525cb6822..e830594db39f 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java @@ -208,6 +208,10 @@ public class RenameCollisionsTest extends LightRefactoringTestCase { doTest("foo2"); } + public void testRenameMethodNoCollisionWithOtherSignatureMethodRef() throws Exception { + doTest("foo2"); + } + public void testRenameNoStaticOverridingInInterfaces() throws Exception { doTest("foo"); } diff --git a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java index 514348e5913b..0ad26a34eec5 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java @@ -105,15 +105,21 @@ public class ModuleScopesTest extends ModuleTestCase { } private Module addDependentModule(final Module moduleA, final DependencyScope scope) { - final Module moduleB = createModule("b.iml", StdModuleTypes.JAVA); + return addDependentModule("b", moduleA, scope, false); + } + + private Module addDependentModule(final String name, final Module moduleA, + final DependencyScope scope, + final boolean exported) { + final Module moduleB = createModule(name + ".iml", StdModuleTypes.JAVA); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - VirtualFile rootB = myFixture.findOrCreateDir("b"); + VirtualFile rootB = myFixture.findOrCreateDir(name); VirtualFile outB = myFixture.findOrCreateDir("out"); - ModuleRootModificationUtil.addDependency(moduleA, moduleB, scope, false); + ModuleRootModificationUtil.addDependency(moduleA, moduleB, scope, exported); PsiTestUtil.addSourceRoot(moduleB, rootB); PsiTestUtil.setCompilerOutputPath(moduleB, outB.getUrl(), false); @@ -123,6 +129,25 @@ public class ModuleScopesTest extends ModuleTestCase { return moduleB; } + public void testModuleTwiceInDependents() throws IOException { + Module m = createModule("m.iml", StdModuleTypes.JAVA); + Module a = createModule("a.iml", StdModuleTypes.JAVA); + Module b = createModule("b.iml", StdModuleTypes.JAVA); + Module c = createModule("c.iml", StdModuleTypes.JAVA); + + ModuleRootModificationUtil.addDependency(a, m, DependencyScope.COMPILE, false); + ModuleRootModificationUtil.addDependency(b, m, DependencyScope.COMPILE, true); + ModuleRootModificationUtil.addDependency(a, b, DependencyScope.COMPILE, true); + ModuleRootModificationUtil.addDependency(c, a, DependencyScope.COMPILE, true); + + VirtualFile root = myFixture.findOrCreateDir("c"); + PsiTestUtil.addSourceContentToRoots(c, root); + VirtualFile file = root.createChildData(this, "x.txt"); + + GlobalSearchScope deps = m.getModuleWithDependentsScope(); + assertTrue(deps.contains(file)); + } + public void testTestOnlyLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); addLibrary(m, DependencyScope.TEST); diff --git a/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java b/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java index 6e34ebf5f939..b6d8840059ba 100644 --- a/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java @@ -49,7 +49,8 @@ public class SliceTreeTest extends SliceTestCase { SliceUsage usage = SliceUsage.createRootUsage(element, params); - SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, ToolWindowHeadlessManagerImpl.HEADLESS_WINDOW) { + ToolWindowHeadlessManagerImpl.MockToolWindow toolWindow = new ToolWindowHeadlessManagerImpl.MockToolWindow(myProject); + SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, toolWindow) { @Override protected void close() { } |