summaryrefslogtreecommitdiff
path: root/java/java-tests/testSrc
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-tests/testSrc')
-rw-r--r--java/java-tests/testSrc/com/intellij/TestClassesFilterTest.java27
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java8
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy11
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy10
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy12
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java13
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java10
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java4
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java262
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java8
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java1
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RenameWrongReferenceTest.java16
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy85
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy60
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java8
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy26
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/CastPostfixTemplateTest.java3
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy64
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java61
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java2
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java177
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java67
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java209
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectContract.java30
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectLeaking.java26
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNoPsiKey.java26
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNotNull.java26
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/LeakingParametersData.java43
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test01.java78
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test02.java33
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test03.java34
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestAnnotation.java26
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestConverterData.java81
-rw-r--r--java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java27
-rw-r--r--java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java222
-rw-r--r--java/java-tests/testSrc/com/intellij/find/FindInEditorTest.java13
-rw-r--r--java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java223
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java15
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java32
-rw-r--r--java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java3
-rw-r--r--java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java4
41 files changed, 1704 insertions, 382 deletions
diff --git a/java/java-tests/testSrc/com/intellij/TestClassesFilterTest.java b/java/java-tests/testSrc/com/intellij/TestClassesFilterTest.java
index 2bbdb91be897..802189ddff83 100644
--- a/java/java-tests/testSrc/com/intellij/TestClassesFilterTest.java
+++ b/java/java-tests/testSrc/com/intellij/TestClassesFilterTest.java
@@ -21,6 +21,8 @@ import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collections;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -41,7 +43,7 @@ public class TestClassesFilterTest {
"com.intellij.package6.ExcludedTest\n" +
"com.intellij.package7.*package8";
- TestClassesFilter classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), "Group1");
+ TestClassesFilter classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), Collections.singletonList("Group1"));
assertTrue(classesFilter.matches("com.intellij.package1.Test"));
assertTrue(classesFilter.matches("com.intellij.package1.Test2"));
assertFalse(classesFilter.matches("com.intellij.package2.Test"));
@@ -59,7 +61,7 @@ public class TestClassesFilterTest {
assertFalse(classesFilter.matches("com.intellij.package7.package5.package8"));
assertFalse(classesFilter.matches("com.intellij.package7"));
- classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), "Group2");
+ classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), Collections.singletonList("Group2"));
assertFalse(classesFilter.matches("com.intellij.package1.Test"));
assertFalse(classesFilter.matches("com.intellij.package1.Test2"));
assertFalse(classesFilter.matches("com.intellij.package2.Test"));
@@ -77,18 +79,29 @@ public class TestClassesFilterTest {
assertTrue(classesFilter.matches("com.intellij.package7.package5.package8"));
assertFalse(classesFilter.matches("com.intellij.package7"));
- classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), null);
- checkForNullGroup(classesFilter);
+ classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText),
+ Collections.singletonList(GroupBasedTestClassFilter.ALL_EXCLUDE_DEFINED));
+ checkForAllExcludedDefinedGroup(classesFilter);
- classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), GroupBasedTestClassFilter.ALL_EXCLUDE_DEFINED);
- checkForNullGroup(classesFilter);
+ classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), Collections.<String>emptyList());
+ checkForAllExcludedDefinedGroup(classesFilter);
+
+ classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), Arrays.asList("Group1", "Group2"));
+ assertTrue(classesFilter.matches("com.intellij.package1.Test"));
+ assertTrue(classesFilter.matches("com.intellij.package5.Test"));
+ assertFalse(classesFilter.matches("com.intellij.package4.Test"));
+
+ classesFilter = GroupBasedTestClassFilter.createOn(getReader(filterText), Arrays.asList("Group1", GroupBasedTestClassFilter.ALL_EXCLUDE_DEFINED));
+ assertTrue(classesFilter.matches("com.intellij.package1.Test"));
+ assertFalse(classesFilter.matches("com.intellij.package5.Test"));
+ assertTrue(classesFilter.matches("com.intellij.package4.Test"));
}
private static InputStreamReader getReader(String filterText) throws UnsupportedEncodingException {
return new InputStreamReader(new ByteArrayInputStream(filterText.getBytes("UTF-8")));
}
- private static void checkForNullGroup(TestClassesFilter classesFilter) {
+ private static void checkForAllExcludedDefinedGroup(TestClassesFilter classesFilter) {
assertFalse(classesFilter.matches("com.intellij.package1.Test"));
assertFalse(classesFilter.matches("com.intellij.package1.Test2"));
assertTrue(classesFilter.matches("com.intellij.package2.Test"));
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
index 8c3837fe1722..f59162a6d5b2 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight;
+import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
@@ -57,6 +58,13 @@ public class JavaTypingTest extends LightPlatformCodeInsightFixtureTestCase {
doTest('"');
}
+ public void testColumnMode() {
+ myFixture.configureByFile(getTestName(true) + "_before.java");
+ ((EditorEx)myFixture.getEditor()).setColumnMode(true);
+ 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/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
index 8a54c9594144..7391f93a1ab2 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
@@ -42,6 +42,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.actionSystem.EditorActionManager
+import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.extensions.LoadingOrder
import com.intellij.openapi.fileEditor.FileEditor
@@ -1642,4 +1643,14 @@ class Foo {
assert lookup
assert myFixture.lookupElementStrings == ['goo']
}
+
+ public void "test in column selection mode"() {
+ myFixture.configureByText "a.java", """
+class Foo {{
+ <caret>
+}}"""
+ edt { ((EditorEx)myFixture.editor).setColumnMode(true) }
+ type 'toStr'
+ assert lookup
+ }
}
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 79a94aaa8148..77b4c0cc64a7 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy
@@ -768,6 +768,8 @@ public class ListUtils {
assertStringItems("fofoo", "fofoo");
}
+ public void testMethodMergingMinimalTail() { doTest() }
+
public void testAnnotationQualifiedName() throws Throwable {
doTest();
}
@@ -920,6 +922,9 @@ public class ListUtils {
}
public void testSmartEnterWrapsConstructorCall() throws Throwable { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
+ public void testSmartEnterNoNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
+ public void testSmartEnterWithNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
+
public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); }
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' }
@@ -1469,6 +1474,11 @@ class Bar {
doTest()
}
+ public void testUnimportedStaticInnerClass() {
+ myFixture.addClass("package foo; public class Super { public static class Inner {} }");
+ doTest()
+ }
+
public void testNoJavaLangPackagesInImport() { doAntiTest() }
public void testNoStaticDuplicatesFromExpectedMemberFactories() {
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 b19da5ac6f67..1d258fe01367 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy
@@ -52,12 +52,12 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
public void testNewListAlwaysFirst() {
def lookup = invokeCompletion(getTestName(false) + ".java")
- assertPreferredItems 1, 'List', 'AbstractList', 'AbstractSequentialList', 'ArrayList'
+ assertPreferredItems 1, 'List', 'ArrayList', 'AbstractList', 'AbstractSequentialList'
for (int i = 0; i < StatisticsManager.OBLIVION_THRESHOLD + 10; i++) {
- imitateItemSelection(lookup, 3) //ArrayList
+ imitateItemSelection(lookup, 3) //AbstractSequentialList
}
refreshSorting(lookup)
- assertPreferredItems 1, 'List', 'ArrayList', 'AbstractList', 'AbstractSequentialList'
+ assertPreferredItems 1, 'List', 'AbstractSequentialList', 'ArrayList', 'AbstractList'
}
public void testNoStatsOnUnsuccessfulAttempt() {
@@ -170,11 +170,11 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
public void testStatisticsAffectsNonPreferableExpectedItems() throws Throwable {
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
- assertPreferredItems(1, "List", "AbstractList", "AbstractSequentialList", "ArrayList");
+ assertPreferredItems(1, "List", "ArrayList", "AbstractList", "AbstractSequentialList");
incUseCount(lookup, 0);
- assertPreferredItems(1, "List", "AbstractList", "AbstractSequentialList", "ArrayList");
+ assertPreferredItems(1, "List", "ArrayList", "AbstractList", "AbstractSequentialList");
incUseCount(lookup, 0);
- assertPreferredItems(0, "List", "AbstractList", "AbstractSequentialList", "ArrayList");
+ assertPreferredItems(0, "List", "ArrayList", "AbstractList", "AbstractSequentialList");
}
public void testPreferNonRecursiveMethodParams() throws Throwable {
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 ed2b792fc5a9..d2e8825cc16d 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
@@ -1029,6 +1029,19 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("Bar", "Goo");
}
+ public void testAutoImportExpectedType() throws Throwable {
+ boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
+ CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
+ try {
+ configureByTestName();
+ performAction();
+ myFixture.assertPreferredCompletionItems(1, "List", "ArrayList", "AbstractList");
+ }
+ finally {
+ CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
+ }
+ }
+
public void testNoWrongSubstitutorFromStats() throws Throwable {
doTest();
FileDocumentManager.getInstance().saveDocument(myFixture.getEditor().getDocument());
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java
index a3b60429e297..d6831d4a2d4a 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java
@@ -34,7 +34,6 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.IdeaTestUtil;
import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -44,7 +43,7 @@ import java.util.List;
* For "heavyweight" tests use AdvHighlightingTest
*/
public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
- @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting7";
+ private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting7";
private void doTest(boolean checkWarnings, boolean checkInfos, Class<?>... classes) {
setLanguageLevel(LanguageLevel.JDK_1_7);
@@ -102,12 +101,9 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
public void testHighlightInaccessibleFromClassModifierList() { doTest(false, false); }
public void testInnerInTypeArguments() { doTest(false, false); }
public void testRawSubstitutor() { doTest(false, false); }
+ public void testIncompleteDiamonds() { doTest(false, false); }
- public void testIncompleteDiamonds() throws Exception {
- doTest(false, false);
- }
-
- public void testDynamicallyAddIgnoredAnnotations() throws Exception {
+ public void testDynamicallyAddIgnoredAnnotations() {
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
EntryPoint extension = new EntryPoint() {
@NotNull @Override public String getDisplayName() { return "duh"; }
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java
index 7a73bfed6cbd..9bb7d4801944 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java
@@ -111,6 +111,10 @@ public class MostSpecificResolutionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
+ public void testIDEA127584() throws Exception {
+ doTest();
+ }
+
private void doTest() {
doTest(true);
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java
index 6bd7654b72af..ea9ada93ca77 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 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.
@@ -31,214 +31,64 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
- new UnusedSymbolLocalInspection(),
+ new UnusedSymbolLocalInspection()
};
}
- public void testIDEA93586() throws Exception {
- doTest();
- }
-
- public void testIDEA113573() throws Exception {
- doTest();
- }
-
- public void testIDEA112922() throws Exception {
- doTest();
- }
-
- public void testIDEA113504() throws Exception {
- doTest();
- }
-
- public void testAfterAbstractPipeline2() throws Exception {
- doTest();
- }
-
- public void testIDEA116252() throws Exception {
- doTest();
- }
-
- public void testIDEA106670() throws Exception {
- doTest();
- }
-
- public void testIDEA116548() throws Exception {
- doTest();
- }
-
- public void testOverloadResolutionSAM() throws Exception {
- doTest();
- }
-
- public void testIntersectionTypesDuringInference() throws Exception {
- doTest();
- }
-
- public void testIncludeConstraintsWhenParentMethodIsDuringCalculation() throws Exception {
- doTest();
- }
-
- public void testUseCalculatedSubstitutor() throws Exception {
- doTest();
- }
-
- public void testArgumentOfAnonymousClass() throws Exception {
- doTest();
- }
-
- public void testEllipsis() throws Exception {
- doTest();
- }
-
- public void testOuterMethodPropagation() throws Exception {
- doTest();
- }
-
- public void testRecursiveCalls() throws Exception {
- doTest();
- }
-
- public void testGroundTargetTypeForImplicitLambdas() throws Exception {
- doTest();
- }
-
- public void testAdditionalConstraintsReduceOrder() throws Exception {
- doTest();
- }
-
- public void testAdditionalConstraintSubstitution() throws Exception {
- doTest();
- }
- public void testFunctionalInterfacesCalculation() throws Exception {
- doTest();
- }
-
- public void testMissedSiteSubstitutorDuringDeepAdditionalConstraintsGathering() throws Exception {
- doTest();
- }
-
- public void testIDEA120992() throws Exception {
- doTest();
- }
-
- public void testTargetTypeConflictResolverShouldNotTryToEvaluateCurrentArgumentType() throws Exception {
- doTest();
- }
-
- public void testIDEA119535() throws Exception {
- doTest();
- }
-
- public void testIDEA119003() throws Exception {
- doTest();
- }
-
- public void testIDEA117124() throws Exception {
- doTest();
- }
-
- public void testWildcardParameterization() throws Exception {
- doTest();
- }
-
- public void testDiamondInLambdaReturn() throws Exception {
- doTest();
- }
-
- public void testIDEA118965() throws Exception {
- doTest();
- }
-
- public void testIDEA121315() throws Exception {
- doTest();
- }
-
- public void testIDEA118965comment() throws Exception {
- doTest();
- }
-
- public void testIDEA122074() throws Exception {
- doTest();
- }
-
- public void testIDEA122084() throws Exception {
- doTest();
- }
-
- public void testAdditionalConstraintDependsOnNonMentionedVars() throws Exception {
- doTest();
- }
-
- public void testIDEA122616() throws Exception {
- doTest();
- }
-
- public void testIDEA122700() throws Exception {
- doTest();
- }
-
- public void testIDEA122406() throws Exception {
- doTest();
- }
-
- public void testNestedCallsInsideLambdaReturnExpression() throws Exception {
- doTest();
- }
-
- public void testIDEA123731() throws Exception {
- doTest();
- }
-
- public void testIDEA123869() throws Exception {
- doTest();
- }
-
- public void testIDEA123848() throws Exception {
- doTest();
- }
-
- public void testOnlyLambdaAtTypeParameterPlace() throws Exception {
- doTest();
- }
-
- public void testLiftedIntersectionType() throws Exception {
- doTest();
- }
-
- public void testInferenceFromReturnStatements() throws Exception {
- doTest();
- }
-
- public void testDownUpThroughLambdaReturnStatements() throws Exception {
- doTest();
- }
-
- public void testIDEA124547() throws Exception {
- doTest();
- }
-
- public void testIDEA118362() throws Exception {
- doTest();
- }
-
- public void testIDEA126056() throws Exception {
- doTest();
- }
-
- public void testIDEA125254() throws Exception {
- doTest();
- }
-
- public void testIDEA124961() throws Exception {
- doTest();
- }
-
- public void testIDEA126109() throws Exception {
- doTest();
- }
-
- public void testIDEA126809() throws Exception {
+ public void testIDEA93586() { doTest(); }
+ public void testIDEA113573() { doTest(); }
+ public void testIDEA112922() { doTest(); }
+ public void testIDEA113504() { doTest(); }
+ public void testAfterAbstractPipeline2() { doTest(); }
+ public void testIDEA116252() { doTest(); }
+ public void testIDEA106670() { doTest(); }
+ public void testIDEA116548() { doTest(); }
+ public void testOverloadResolutionSAM() { doTest(); }
+ public void testIntersectionTypesDuringInference() { doTest(); }
+ public void testIncludeConstraintsWhenParentMethodIsDuringCalculation() { doTest(); }
+ public void testUseCalculatedSubstitutor() { doTest(); }
+ public void testArgumentOfAnonymousClass() { doTest(); }
+ public void testEllipsis() { doTest(); }
+ public void testOuterMethodPropagation() { doTest(); }
+ public void testRecursiveCalls() { doTest(); }
+ public void testGroundTargetTypeForImplicitLambdas() { doTest(); }
+ public void testAdditionalConstraintsReduceOrder() { doTest(); }
+ public void testAdditionalConstraintSubstitution() { doTest(); }
+ public void testFunctionalInterfacesCalculation() { doTest(); }
+ public void testMissedSiteSubstitutorDuringDeepAdditionalConstraintsGathering() { doTest(); }
+ public void testIDEA120992() { doTest(); }
+ public void testTargetTypeConflictResolverShouldNotTryToEvaluateCurrentArgumentType() { doTest(); }
+ public void testIDEA119535() { doTest(); }
+ public void testIDEA119003() { doTest(); }
+ public void testIDEA117124() { doTest(); }
+ public void testWildcardParameterization() { doTest(); }
+ public void testDiamondInLambdaReturn() { doTest(); }
+ public void testIDEA118965() { doTest(); }
+ public void testIDEA121315() { doTest(); }
+ public void testIDEA118965comment() { doTest(); }
+ public void testIDEA122074() { doTest(); }
+ public void testIDEA122084() { doTest(); }
+ public void testAdditionalConstraintDependsOnNonMentionedVars() { doTest(); }
+ public void testIDEA122616() { doTest(); }
+ public void testIDEA122700() { doTest(); }
+ public void testIDEA122406() { doTest(); }
+ public void testNestedCallsInsideLambdaReturnExpression() { doTest(); }
+ public void testIDEA123731() { doTest(); }
+ public void testIDEA123869() { doTest(); }
+ public void testIDEA123848() { doTest(); }
+ public void testOnlyLambdaAtTypeParameterPlace() { doTest(); }
+ public void testLiftedIntersectionType() { doTest(); }
+ public void testInferenceFromReturnStatements() { doTest(); }
+ public void testDownUpThroughLambdaReturnStatements() { doTest(); }
+ public void testIDEA124547() { doTest(); }
+ public void testIDEA118362() { doTest(); }
+ public void testIDEA126056() { doTest(); }
+ public void testIDEA125254() { doTest(); }
+ public void testIDEA124961() { doTest(); }
+ public void testIDEA126109() { doTest(); }
+ public void testIDEA126809() { doTest(); }
+
+ public void testIDEA127596() throws Exception {
doTest();
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java
index 6860bc0c88fa..dd7ceb566139 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java
@@ -273,6 +273,14 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
+ public void testIDEA126969() throws Exception {
+ doTest();
+ }
+
+ public void testIDEA127506() throws Exception {
+ doTest();
+ }
+
private void doTest() {
doTest(false);
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java
index fba0c7714bef..2c5c52141ea9 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java
@@ -24,6 +24,7 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase {
public void testInsideStaticInnerClass() throws Exception { doSingleTest(); }
public void testCreateFromEquals() throws Exception { doSingleTest(); }
public void testCreateFromEqualsToPrimitiveType() throws Exception { doSingleTest(); }
+ public void testInsideInterface() throws Exception { doSingleTest(); }
public void testWithAlignment() throws Exception {
final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
boolean old = settings.ALIGN_GROUP_FIELD_DECLARATIONS;
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RenameWrongReferenceTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RenameWrongReferenceTest.java
index ae2c847128b3..7b19bbd5cd27 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RenameWrongReferenceTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RenameWrongReferenceTest.java
@@ -1,3 +1,18 @@
+/*
+ * 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.daemon.quickFix;
public class RenameWrongReferenceTest extends LightQuickFixAvailabilityTestCase {
@@ -9,4 +24,3 @@ public class RenameWrongReferenceTest extends LightQuickFixAvailabilityTestCase
return "/codeInsight/daemonCodeAnalyzer/quickFix/renameWrongReference";
}
}
-
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 2047f13b795d..5d823e001f82 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy
@@ -608,7 +608,7 @@ class Test {
configure(testNow, shouldIgnoreRoots(), fourteen, pi, title, c, file);
}
- pubic void configure(boolean testNow, boolean shouldIgnoreRoots, int times, float pi, String title, char terminate, File file) {
+ pubic void configure(boolean testNow, boolean shouldIgnoreRoots, int times, float pii, String title, char terminate, File file) {
System.out.println();
System.out.println();
}
@@ -672,7 +672,7 @@ public class VarArgTest {
assert regions[1].placeholderText == "test: 13"
}
- public void "test inline if argument length is one (EA-57555)"() {
+ public void "test do not inline if parameter length is one or two"() {
def text = """
public class CharSymbol {
@@ -681,7 +681,7 @@ public class CharSymbol {
count(1, false);
}
- public void count(int test, boolean fast) {
+ public void count(int t, boolean fa) {
int temp = test;
boolean isFast = fast;
}
@@ -689,13 +689,78 @@ public class CharSymbol {
"""
configure text
def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset }
+ assert regions.size() == 2
+ }
+
+ public void "test do not inline known subsequent parameter names"() {
+ def text = """
+public class Test {
+ public void main() {
+ test1(1, 2);
+ test2(1, 2);
+ test3(1, 2);
+ doTest("first", "second");
+ }
+
+ public void test1(int first, int second) {
+ int start = first;
+ int end = second;
+ }
+
+ public void test2(int key, int value) {
+ int start = key;
+ int end = value;
+ }
+
+ public void test3(int key, int value) {
+ int start = key;
+ int end = value;
+ }
+}
+"""
+ configure text
+ def regions = myFixture.editor.foldingModel.allFoldRegions
assert regions.size() == 4
+ }
- checkRangeOffsetByPositionInText(regions[1], text, "1")
- assert regions[1].placeholderText == "test: 1"
+ public void "test do not inline paired ranged names"() {
+ def text = """
+public class CharSymbol {
- checkRangeOffsetByPositionInText(regions[2], text, "false")
- assert regions[2].placeholderText == "fast: false"
+ public void main() {
+ String s = "AAA";
+ int last = 3;
+
+ substring1(1, last);
+ substring2(1, last);
+ substring3(1, last);
+ substring4(1, last);
+ }
+
+ public void substring1(int beginIndex, int endIndex) {
+ int start = beginIndex;
+ int end = endIndex;
+ }
+
+ public void substring2(int startIndex, int endIndex) {
+ int start = startIndex;
+ int end = endIndex;
+ }
+
+ public void substring3(int from, int to) {
+ int start = from;
+ int end = to;
+ }
+
+ public void substring4(int first, int last) {
+ int start = first;
+ int end = last;
+ }
+}
+"""
+ configure text
+ def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset }
+ assert regions.size() == 5
}
public void "test inline names if literal expression can be assigned to method parameter"() {
@@ -764,7 +829,7 @@ public class Test {
}
abstract class Checker {
- Checker(boolean applyToFirst, boolean applyToSecond) {}
+ Checker(boolean isActive, boolean requestFocus) {}
abstract void test();
}
}
@@ -773,8 +838,8 @@ public class Test {
def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset }
assert regions.length == 6
- assert regions[1].placeholderText == "applyToFirst: true"
- assert regions[2].placeholderText == "applyToSecond: false"
+ assert regions[1].placeholderText == "isActive: true"
+ assert regions[2].placeholderText == "requestFocus: false"
checkRangeOffsetByPositionInText(regions[1], text, "true")
checkRangeOffsetByPositionInText(regions[2], text, "false")
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy
index ead75a2936e2..4b169fcc9249 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy
@@ -177,6 +177,66 @@ class Test {
'''
}
+ public void "test import class in class reference expression"() {
+ myFixture.configureByText 'a.java', '''
+class Test {
+ {
+ equals(Co<caret>llection.class);
+ }
+}
+'''
+ importClass();
+ myFixture.checkResult '''import java.util.Collection;
+
+class Test {
+ {
+ equals(Co<caret>llection.class);
+ }
+}
+'''
+ }
+
+ public void "test import class in qualifier expression"() {
+ myFixture.configureByText 'a.java', '''
+class Test {
+ {
+ equals(Co<caret>llections.emptySet());
+ }
+}
+'''
+ importClass();
+ myFixture.checkResult '''import java.util.Collections;
+
+class Test {
+ {
+ equals(Co<caret>llections.emptySet());
+ }
+}
+'''
+ }
+
+ public void "test don't import class in method call argument"() {
+ myFixture.configureByText 'a.java', '''
+class Test {
+ {
+ equals(Co<caret>llection);
+ }
+}
+'''
+ assert !myFixture.filterAvailableIntentions("Import Class")
+ }
+
+ public void "test don't import class in assignment"() {
+ myFixture.configureByText 'a.java', '''
+class Test {
+ {
+ Co<caret>llection = 2;
+ }
+}
+'''
+ assert !myFixture.filterAvailableIntentions("Import Class")
+ }
+
private def importClass() {
myFixture.launchAction(myFixture.findSingleIntention("Import Class"))
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java
index 454bb7f97a58..8bac921916d3 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java
@@ -80,6 +80,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestField();
}
+ public void testAnnotationsInParams() throws Exception {
+ doTestMethod();
+ }
+
public void testLiteral() throws Exception {
doTestField();
}
@@ -88,6 +92,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestField();
}
+ public void testPInsidePre() throws Exception {
+ doTestField();
+ }
+
public void testEnumConstantOrdinal() throws Exception {
PsiClass psiClass = getTestClass();
PsiField field = psiClass.getFields() [0];
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy
index 3acb9845df66..d866ddd783cf 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy
@@ -797,4 +797,30 @@ class Foo {
}
"""
}
+
+ public void "test two static imports"() {
+ myFixture.configureByText "a.java", """
+
+class Foo {
+ {
+ <caret>
+ }
+}
+"""
+ final TemplateManager manager = TemplateManager.getInstance(getProject());
+ final Template template = manager.createTemplate("xxx", "user", 'java.lang.Math.abs(java.lang.Math.PI);');
+ template.setValue(USE_STATIC_IMPORT_IF_POSSIBLE, true);
+
+ startTemplate(template);
+ myFixture.checkResult """\
+import static java.lang.Math.PI;
+import static java.lang.Math.abs;
+
+class Foo {
+ {
+ abs(PI);<caret>
+ }
+}
+"""
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/CastPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/CastPostfixTemplateTest.java
index d5cae6ab30cf..9a50a6b353c5 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/CastPostfixTemplateTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/CastPostfixTemplateTest.java
@@ -43,4 +43,7 @@ public class CastPostfixTemplateTest extends PostfixTemplateTestCase {
public void testChainCall() {
doTest();
}
+ public void testTernary() {
+ doTest();
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
index 32982f3687df..23eac589e2db 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
@@ -220,12 +220,74 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase {
assert c == ['_ -> true']
}
+ public void "test boolean autoboxing"() {
+ def c = inferContracts("""
+ static Object test1(Object o1) {
+ return o1 == null;
+ }""")
+ assert c == []
+ }
+
+ public void "test non-returning delegation"() {
+ def c = inferContracts("""
+ static void test2(Object o) {
+ assertNotNull(o);
+ }
+
+ static boolean assertNotNull(Object o) {
+ if (o == null) {
+ throw new NullPointerException();
+ }
+ return true;
+ }
+ """)
+ assert c == ['null -> fail']
+ }
+
+ public void "test instanceof notnull"() {
+ def c = inferContracts("""
+ public boolean test2(Object o) {
+ if (o != null) {
+ return o instanceof String;
+ } else {
+ return test1(o);
+ }
+ }
+ static boolean test1(Object o1) {
+ return o1 == null;
+ }
+ """)
+ assert c == []
+ }
+
+ public void "test no duplicates in delegation"() {
+ def c = inferContracts("""
+ static boolean test2(Object o1, Object o2) {
+ return test1(o1, o1);
+ }
+ static boolean test1(Object o1, Object o2) {
+ return o1 != null && o2 != null;
+ }
+ """)
+ assert c == ['null, _ -> false', '!null, _ -> true']
+ }
+
+ public void "test take explicit parameter notnull into account"() {
+ def c = inferContracts("""
+ final Object foo(@org.jetbrains.annotations.NotNull Object bar) {
+ if (!(bar instanceof CharSequence)) return null;
+ return new String("abc");
+ }
+ """)
+ assert c == []
+ }
+
private String inferContract(String method) {
return assertOneElement(inferContracts(method))
}
private List<String> inferContracts(String method) {
- def clazz = myFixture.addClass("class Foo { $method }")
+ def clazz = myFixture.addClass("final class Foo { $method }")
return ContractInference.inferContracts(clazz.methods[0]).collect { it as String }
}
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
index 833b5196d74a..4cba2ab918a7 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
@@ -139,6 +139,12 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
+ public void testReportConstantReferences_OverloadedCall() {
+ doTestReportConstantReferences();
+ myFixture.launchAction(myFixture.findSingleIntention("Replace with 'null'"));
+ myFixture.checkResultByFile(getTestName(false) + "_after.java");
+ }
+
public void testReportConstantReferencesAfterFinalFieldAccess() { doTestReportConstantReferences(); }
private void doTestReportConstantReferences() {
@@ -148,28 +154,6 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
}
- public void _testReportConstantReferences_ReplaceWithString() {
- doTestReportConstantReferences();
- myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
- myFixture.checkResultByFile(getTestName(false) + "_after.java");
- }
- public void _testReportConstantReferences_ReplaceWithIntConstant() {
- doTestReportConstantReferences();
- myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
- myFixture.checkResultByFile(getTestName(false) + "_after.java");
- }
- public void _testReportConstantReferences_ReplaceWithEnum() {
- myFixture.addClass("package foo; public enum MyEnum { FOO }");
- doTestReportConstantReferences();
- myFixture.launchAction(myFixture.findSingleIntention("Replace with 'FOO'"));
- myFixture.checkResultByFile(getTestName(false) + "_after.java");
- }
- public void _testReportConstantReferences_NotInComplexAssignment() {
- doTestReportConstantReferences();
- assertEmpty(myFixture.filterAvailableIntentions("Replace with"));
- }
- public void _testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
-
public void testCheckFieldInitializers() {
doTest();
}
@@ -190,6 +174,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testTransientFinalField() { doTest(); }
public void testFinalFieldDuringInitialization() { doTest(); }
+ public void testFinalFieldDuringSuperInitialization() { doTest(); }
public void _testSymmetricUncheckedCast() { doTest(); } // http://youtrack.jetbrains.com/issue/IDEABKL-6871
public void testNullCheckDoesntAffectUncheckedCast() { doTest(); }
public void testThrowNull() { doTest(); }
@@ -265,6 +250,13 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testSameComparisonTwice() { doTest(); }
public void testRootThrowableCause() { doTest(); }
+ public void testUseInferredContracts() { doTest(); }
+ public void testContractInferenceBewareOverriding() { doTest(); }
+
+ public void testNumberComparisonsWhenValueIsKnown() { doTest(); }
+
+ public void testAccessingSameArrayElements() { doTest(); }
+
public void testParametersAreNonnullByDefault() {
myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}");
myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}");
@@ -280,6 +272,29 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
myFixture.launchAction(myFixture.findSingleIntention("Remove redundant assignment"));
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
-
+
+ public void testAssertThat() {
+ myFixture.addClass("package org.hamcrest; public class CoreMatchers { " +
+ "public static <T> Matcher<T> notNullValue() {}\n" +
+ "public static <T> Matcher<T> not(Matcher<T> matcher) {}\n" +
+ "public static <T> Matcher<T> equalTo(T operand) {}\n" +
+ "}");
+ myFixture.addClass("package org.hamcrest; public interface Matcher<T> {}");
+ myFixture.addClass("package org.junit; public class Assert { " +
+ "public static <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher) {}\n" +
+ "public static <T> void assertThat(String msg, T actual, org.hamcrest.Matcher<? super T> matcher) {}\n" +
+ "}");
+ myFixture.enableInspections(new DataFlowInspection());
+ myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
+ }
+
+ public void testGuavaCheckNotNull() {
+ myFixture.addClass("package com.google.common.base; public class Preconditions { " +
+ "public static <T> T checkNotNull(T reference) {}\n" +
+ "}");
+ myFixture.enableInspections(new DataFlowInspection());
+ myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
+ }
+
public void _testNullCheckBeforeInstanceof() { doTest(); } // http://youtrack.jetbrains.com/issue/IDEA-113220
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java
index 843dcbbb8bfe..e925dd49a8ea 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java
@@ -30,6 +30,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
public void testProblems2() throws Exception{ doTest(); }
public void testNullableFieldNotnullParam() throws Exception{ doTest(); }
public void testNotNullFieldNullableParam() throws Exception{ doTest(); }
+ public void testNotNullCustomException() throws Exception{ doTest(); }
+ public void testNotNullFieldNotInitialized() throws Exception{ doTest(); }
public void testGetterSetterProblems() throws Exception{ doTest(); }
public void testOverriddenMethods() throws Exception{
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java
new file mode 100644
index 000000000000..516b140cc0b1
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import com.intellij.codeInsight.AnnotationUtil;
+import com.intellij.codeInsight.ExternalAnnotationsManager;
+import com.intellij.codeInsight.InferredAnnotationsManager;
+import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.SdkModificator;
+import com.intellij.openapi.roots.AnnotationOrderRootType;
+import com.intellij.openapi.roots.ModifiableRootModel;
+import com.intellij.openapi.roots.ModuleRootModificationUtil;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileVisitor;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.util.PsiFormatUtil;
+import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
+import com.intellij.util.AsynchConsumer;
+import org.jetbrains.annotations.Contract;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author lambdamix
+ */
+public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestCase {
+ public static final String ORG_JETBRAINS_ANNOTATIONS_CONTRACT = Contract.class.getName();
+
+ private InferredAnnotationsManager myInferredAnnotationsManager;
+ private ExternalAnnotationsManager myExternalAnnotationsManager;
+
+ private List<String> diffs = new ArrayList<String>();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ setUpLibraries();
+ setUpExternalUpAnnotations();
+
+ myInferredAnnotationsManager = InferredAnnotationsManager.getInstance(myModule.getProject());
+ myExternalAnnotationsManager = ExternalAnnotationsManager.getInstance(myModule.getProject());
+ }
+
+ private void setUpLibraries() {
+ VirtualFile lib = LocalFileSystem.getInstance().refreshAndFindFileByPath(PathManagerEx.getTestDataPath() + "/../../../lib");
+ assertNotNull(lib);
+ PsiTestUtil.addLibrary(myModule, "velocity", lib.getPath(), new String[]{"/velocity.jar!/"}, new String[]{});
+ }
+
+ private void setUpExternalUpAnnotations() {
+ String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
+ final VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
+ assertNotNull(annotationsDir);
+
+ ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {
+ @Override
+ public void finished() {
+ }
+
+ @Override
+ public void consume(ModifiableRootModel modifiableRootModel) {
+ final LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
+ Library[] libs = libraryTable.getLibraries();
+ for (Library library : libs) {
+ final Library.ModifiableModel libraryModel = library.getModifiableModel();
+ libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
+ libraryModel.commit();
+ }
+ Sdk sdk = modifiableRootModel.getSdk();
+ if (sdk != null) {
+ SdkModificator sdkModificator = sdk.getSdkModificator();
+ sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
+ sdkModificator.commitChanges();
+ }
+ }
+ });
+
+ VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() { });
+ annotationsDir.refresh(false, true);
+ }
+
+ public void testSdkAndLibAnnotations() {
+
+ final PsiPackage rootPackage = JavaPsiFacade.getInstance(getProject()).findPackage("");
+ assert rootPackage != null;
+
+ final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
+ JavaRecursiveElementVisitor visitor = new JavaRecursiveElementVisitor() {
+ @Override
+ public void visitPackage(PsiPackage aPackage) {
+ for (PsiPackage subPackage : aPackage.getSubPackages(scope)) {
+ visitPackage(subPackage);
+ }
+ for (PsiClass aClass : aPackage.getClasses(scope)) {
+ for (PsiMethod method : aClass.getMethods()) {
+ checkMethodAnnotations(method);
+ }
+ }
+ }
+ };
+
+ rootPackage.accept(visitor);
+ assertEmpty(diffs);
+ }
+
+ private void checkMethodAnnotations(PsiMethod method) {
+ try {
+ if (ProjectBytecodeAnalysis.getKey(method) == -1) {
+ return;
+ }
+ }
+ catch (IOException e) {
+ fail();
+ }
+
+ // not null-result
+ String externalOutAnnotation =
+ myExternalAnnotationsManager.findExternalAnnotation(method, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ String inferredOutAnnotation =
+ myInferredAnnotationsManager.findInferredAnnotation(method, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ String methodKey = PsiFormatUtil.getExternalName(method, false, Integer.MAX_VALUE);
+
+ if (!externalOutAnnotation.equals(inferredOutAnnotation)) {
+ diffs.add(methodKey + ": " + externalOutAnnotation + " != " + inferredOutAnnotation);
+ }
+
+ for (PsiParameter parameter : method.getParameterList().getParameters()) {
+ String parameterKey = PsiFormatUtil.getExternalName(parameter, false, Integer.MAX_VALUE);
+ String externalParameterAnnotation =
+ myExternalAnnotationsManager.findExternalAnnotation(parameter, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ String inferredParameterAnnotation =
+ myInferredAnnotationsManager.findInferredAnnotation(parameter, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ if (!externalParameterAnnotation.equals(inferredParameterAnnotation)) {
+ diffs.add(parameterKey + ": " + externalParameterAnnotation + " != " + inferredParameterAnnotation);
+ }
+ }
+
+ PsiAnnotation externalContractAnnotation =
+ myExternalAnnotationsManager.findExternalAnnotation(method, ORG_JETBRAINS_ANNOTATIONS_CONTRACT);
+ PsiAnnotation inferredContractAnnotation =
+ myInferredAnnotationsManager.findInferredAnnotation(method, ORG_JETBRAINS_ANNOTATIONS_CONTRACT);
+
+ String externalContractAnnotationString =
+ externalContractAnnotation == null ? "null" : "@Contract(" + AnnotationUtil.getStringAttributeValue(externalContractAnnotation, null) + ")";
+ String inferredContractAnnotationString =
+ inferredContractAnnotation == null ? "null" : "@Contract(" + AnnotationUtil.getStringAttributeValue(inferredContractAnnotation, null) + ")";
+
+ if (!externalContractAnnotationString.equals(inferredContractAnnotationString)) {
+ diffs.add(methodKey + ": " + externalContractAnnotationString + " != " + inferredContractAnnotationString);
+ }
+
+ }
+
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java
new file mode 100644
index 000000000000..dc67871e6283
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import com.intellij.JavaTestUtil;
+import com.intellij.codeInspection.dataFlow.DataFlowInspection;
+import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.testFramework.LightProjectDescriptor;
+import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author lambdamix
+ */
+public class BytecodeAnalysisResultsHighlightingTest extends LightCodeInsightFixtureTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setUpLibraries();
+ }
+
+ @NotNull
+ @Override
+ protected LightProjectDescriptor getProjectDescriptor() {
+ return JAVA_1_7;
+ }
+
+ @Override
+ protected String getTestDataPath() {
+ return JavaTestUtil.getJavaTestDataPath() + "/codeInspection/bytecodeAnalysis/src/";
+ }
+
+ private void doTest() {
+ final DataFlowInspection inspection = new DataFlowInspection();
+ inspection.SUGGEST_NULLABLE_ANNOTATIONS = true;
+ inspection.REPORT_CONSTANT_REFERENCE_VALUES = false;
+ myFixture.enableInspections(inspection);
+ myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
+ }
+
+ public void testExample() {
+ doTest();
+ }
+
+ private void setUpLibraries() {
+ VirtualFile lib = LocalFileSystem.getInstance().refreshAndFindFileByPath(PathManagerEx.getTestDataPath() + "/../../../lib");
+ assertNotNull(lib);
+ PsiTestUtil.addLibrary(myModule, "velocity", lib.getPath(), new String[]{"/velocity.jar!/"}, new String[]{});
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java
new file mode 100644
index 000000000000..09fa87fa95e9
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java
@@ -0,0 +1,209 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import com.intellij.codeInsight.AnnotationUtil;
+import com.intellij.codeInsight.InferredAnnotationsManager;
+import com.intellij.codeInspection.bytecodeAnalysis.data.*;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.org.objectweb.asm.*;
+import org.jetbrains.org.objectweb.asm.tree.MethodNode;
+import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException;
+import org.junit.Assert;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+
+/**
+ * @author lambdamix
+ */
+public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase {
+ public static final String ORG_JETBRAINS_ANNOTATIONS_CONTRACT = Contract.class.getName();
+ private final String myClassesProjectRelativePath = "/classes/" + Test01.class.getPackage().getName().replace('.', '/');
+ private JavaPsiFacade myJavaPsiFacade;
+ private InferredAnnotationsManager myInferredAnnotationsManager;
+ private BytecodeAnalysisConverter myBytecodeAnalysisConverter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myJavaPsiFacade = JavaPsiFacade.getInstance(myModule.getProject());
+ myInferredAnnotationsManager = InferredAnnotationsManager.getInstance(myModule.getProject());
+ myBytecodeAnalysisConverter = BytecodeAnalysisConverter.getInstance();
+
+ setUpDataClasses();
+ }
+
+ public void testInference() throws IOException {
+ checkAnnotations(Test01.class);
+ checkAnnotations(Test02.class);
+ checkAnnotations(Test03.class);
+ }
+
+ public void testConverter() throws IOException {
+ checkCompoundIds(Test01.class);
+ checkCompoundIds(TestConverterData.class);
+ checkCompoundIds(TestConverterData.StaticNestedClass.class);
+ checkCompoundIds(TestConverterData.InnerClass.class);
+ checkCompoundIds(TestConverterData.GenericStaticNestedClass.class);
+ checkCompoundIds(TestAnnotation.class);
+ }
+
+ public void testLeakingParametersAnalysis() throws IOException {
+ checkLeakingParameters(LeakingParametersData.class);
+ }
+
+ private static void checkLeakingParameters(Class<?> jClass) throws IOException {
+ final HashMap<Method, boolean[]> map = new HashMap<Method, boolean[]>();
+
+ // collecting leakedParameters
+ final ClassReader classReader = new ClassReader(new FileInputStream(jClass.getResource("/" + jClass.getName().replace('.', '/') + ".class").getFile()));
+ classReader.accept(new ClassVisitor(Opcodes.ASM5) {
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+ final MethodNode node = new MethodNode(Opcodes.ASM5, access, name, desc, signature, exceptions);
+ final Method method = new Method(classReader.getClassName(), name, desc);
+ return new MethodVisitor(Opcodes.ASM5, node) {
+ @Override
+ public void visitEnd() {
+ super.visitEnd();
+ try {
+ map.put(method, cfg.leakingParameters(classReader.getClassName(), node));
+ }
+ catch (AnalyzerException ignore) {}
+ }
+ };
+ }
+ }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
+
+ for (java.lang.reflect.Method jMethod : jClass.getDeclaredMethods()) {
+ Method method = new Method(Type.getType(jClass).getInternalName(), jMethod.getName(), Type.getMethodDescriptor(jMethod));
+ Annotation[][] annotations = jMethod.getParameterAnnotations();
+ for (int i = 0; i < annotations.length; i++) {
+ boolean isLeaking = false;
+ Annotation[] parameterAnnotations = annotations[i];
+ for (Annotation parameterAnnotation : parameterAnnotations) {
+ if (parameterAnnotation.annotationType() == ExpectLeaking.class) {
+ isLeaking = true;
+ }
+ }
+ assertEquals(method.toString() + " #" + i, isLeaking, map.get(method)[i]);
+ }
+ }
+ }
+
+ private void checkAnnotations(Class<?> javaClass) {
+ PsiClass psiClass = myJavaPsiFacade.findClass(javaClass.getName(), GlobalSearchScope.moduleWithLibrariesScope(myModule));
+ assertNotNull(psiClass);
+
+ for (java.lang.reflect.Method javaMethod : javaClass.getDeclaredMethods()) {
+ PsiMethod psiMethod = psiClass.findMethodsByName(javaMethod.getName(), false)[0];
+ Annotation[][] annotations = javaMethod.getParameterAnnotations();
+
+ // not-null parameters
+ params: for (int i = 0; i < annotations.length; i++) {
+ Annotation[] parameterAnnotations = annotations[i];
+ PsiParameter psiParameter = psiMethod.getParameterList().getParameters()[i];
+ PsiAnnotation inferredAnnotation = myInferredAnnotationsManager.findInferredAnnotation(psiParameter, AnnotationUtil.NOT_NULL);
+ for (Annotation parameterAnnotation : parameterAnnotations) {
+ if (parameterAnnotation.annotationType() == ExpectNotNull.class) {
+ assertNotNull(javaMethod.toString() + " " + i, inferredAnnotation);
+ continue params;
+ }
+ }
+ assertNull(javaMethod.toString() + " " + i, inferredAnnotation);
+ }
+
+ // not-null result
+ ExpectNotNull expectedAnnotation = javaMethod.getAnnotation(ExpectNotNull.class);
+ PsiAnnotation actualAnnotation = myInferredAnnotationsManager.findInferredAnnotation(psiMethod, AnnotationUtil.NOT_NULL);
+ assertEquals(javaMethod.toString(), expectedAnnotation == null, actualAnnotation == null);
+
+
+ // contracts
+ ExpectContract expectedContract = javaMethod.getAnnotation(ExpectContract.class);
+ PsiAnnotation actualContractAnnotation = myInferredAnnotationsManager.findInferredAnnotation(psiMethod, ORG_JETBRAINS_ANNOTATIONS_CONTRACT);
+
+ assertEquals(expectedContract == null, actualContractAnnotation == null);
+
+ if (expectedContract != null) {
+ String expectedContractValue = expectedContract.value();
+ String actualContractValue = AnnotationUtil.getStringAttributeValue(actualContractAnnotation, null);
+ assertEquals(javaMethod.toString(), expectedContractValue, actualContractValue);
+ }
+
+ }
+ }
+
+ private void checkCompoundIds(Class<?> javaClass) throws IOException {
+ String javaClassName = javaClass.getCanonicalName();
+ PsiClass psiClass = myJavaPsiFacade.findClass(javaClassName, GlobalSearchScope.moduleWithLibrariesScope(myModule));
+ assertNotNull(psiClass);
+
+ for (java.lang.reflect.Method javaMethod : javaClass.getDeclaredMethods()) {
+ Method method = new Method(Type.getType(javaClass).getInternalName(), javaMethod.getName(), Type.getMethodDescriptor(javaMethod));
+ boolean noKey = javaMethod.getAnnotation(ExpectNoPsiKey.class) != null;
+ PsiMethod psiMethod = psiClass.findMethodsByName(javaMethod.getName(), false)[0];
+ checkCompoundId(method, psiMethod, noKey);
+ }
+
+ for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) {
+ Method method = new Method(Type.getType(javaClass).getInternalName(), "<init>", Type.getConstructorDescriptor(constructor));
+ boolean noKey = constructor.getAnnotation(ExpectNoPsiKey.class) != null;
+ PsiMethod[] constructors = psiClass.getConstructors();
+ PsiMethod psiMethod = constructors[0];
+ checkCompoundId(method, psiMethod, noKey);
+ }
+ }
+
+ private void checkCompoundId(Method method, PsiMethod psiMethod, boolean noKey) throws IOException {
+ Direction direction = new Out();
+ int psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction);
+ if (noKey) {
+ assertTrue(-1 == psiKey);
+ return;
+ }
+ else {
+ assertFalse(-1 == psiKey);
+ }
+
+ int asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true));
+
+ Assert.assertEquals(asmKey, psiKey);
+ }
+
+ private void setUpDataClasses() throws IOException {
+ File classesDir = new File(Test01.class.getResource("/" + Test01.class.getPackage().getName().replace('.', '/')).getFile());
+ File destDir = new File(myModule.getProject().getBaseDir().getPath() + myClassesProjectRelativePath);
+ FileUtil.copyDir(classesDir, destDir);
+ VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(destDir);
+ assertNotNull(vFile);
+ PsiTestUtil.addLibrary(myModule, "dataClasses", vFile.getPath(), new String[]{""}, ArrayUtil.EMPTY_STRING_ARRAY);
+ }
+
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectContract.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectContract.java
new file mode 100644
index 000000000000..9b78f742eb9c
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectContract.java
@@ -0,0 +1,30 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author lambdamix
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ExpectContract {
+ String value() default "";
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectLeaking.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectLeaking.java
new file mode 100644
index 000000000000..3c5ded3427ba
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectLeaking.java
@@ -0,0 +1,26 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author lambdamix
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExpectLeaking {
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNoPsiKey.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNoPsiKey.java
new file mode 100644
index 000000000000..dde06c0f153b
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNoPsiKey.java
@@ -0,0 +1,26 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author lambdamix
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExpectNoPsiKey {
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNotNull.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNotNull.java
new file mode 100644
index 000000000000..39f1c6e7f363
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/ExpectNotNull.java
@@ -0,0 +1,26 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author lambdamix
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExpectNotNull {
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/LeakingParametersData.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/LeakingParametersData.java
new file mode 100644
index 000000000000..ff5887ff2dbb
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/LeakingParametersData.java
@@ -0,0 +1,43 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectLeaking;
+
+/**
+ * @author lambdamix
+ */
+public class LeakingParametersData {
+ int z;
+
+ void test01(@ExpectLeaking Object o1, @ExpectLeaking Object o2, @ExpectLeaking Object o3) {
+ o1.toString();
+ o2.toString();
+ o3.toString();
+ }
+
+ void test02(@ExpectLeaking LeakingParametersData d) {
+ System.out.println(d.z);
+ }
+
+ void test03(int i, @ExpectLeaking LeakingParametersData d) {
+ System.out.println(d.z);
+ }
+
+ void test04(long i, @ExpectLeaking LeakingParametersData d) {
+ System.out.println(d.z);
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test01.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test01.java
new file mode 100644
index 000000000000..1b90bb640b39
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test01.java
@@ -0,0 +1,78 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectContract;
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectNotNull;
+
+/**
+ * @author lambdamix
+ */
+public class Test01 {
+ static void f(@ExpectNotNull Object o1, @ExpectNotNull Object o2) {
+ if (o1 == null) throw new NullPointerException();
+ else s(o2, o2);
+ }
+
+ static void g(@ExpectNotNull Object o, boolean b) {
+ if (b) f(o, o);
+ else s(o, o);
+ }
+
+ static void s(@ExpectNotNull Object o1, Object o2) {
+ t(o1);
+ v(o2);
+ }
+
+ static void t(@ExpectNotNull Object o) {
+ o.toString();
+ }
+
+ static void v(Object o) {
+
+ }
+
+ @ExpectContract("null->null")
+ static String toString1(Object o) {
+ return o == null ? null : o.toString();
+ }
+
+ @ExpectContract("null->!null")
+ static String toString2(Object o) {
+ return o == null ? "null" : o.toString();
+ }
+
+ @ExpectNotNull
+ static String constantString() {
+ return "s";
+ }
+
+ @ExpectContract("!null->!null;null->null")
+ static String idString(String s) {
+ return s;
+ }
+
+ @ExpectNotNull
+ public Test01 getThis() {
+ return this;
+ }
+
+ @ExpectNotNull
+ protected Test01 createRoot() {
+ return new Test01();
+ }
+
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test02.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test02.java
new file mode 100644
index 000000000000..f794ff23009b
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test02.java
@@ -0,0 +1,33 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectNotNull;
+
+/**
+ * @author lambdamix
+ */
+public final class Test02 {
+ @ExpectNotNull
+ public String notNullString() {
+ return "";
+ }
+
+ @ExpectNotNull
+ public String notNullStringDelegate() {
+ return notNullString();
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test03.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test03.java
new file mode 100644
index 000000000000..97903933190e
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/Test03.java
@@ -0,0 +1,34 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectNotNull;
+
+/**
+ * @author lambdamix
+ */
+public class Test03 {
+
+ public String toString1() {
+ return toString();
+ }
+
+ @Override
+ @ExpectNotNull
+ public String toString() {
+ return "";
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestAnnotation.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestAnnotation.java
new file mode 100644
index 000000000000..cfe55ff5cd28
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestAnnotation.java
@@ -0,0 +1,26 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author lambdamix
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestAnnotation {
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestConverterData.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestConverterData.java
new file mode 100644
index 000000000000..254db418e55c
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/data/TestConverterData.java
@@ -0,0 +1,81 @@
+/*
+ * 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.codeInspection.bytecodeAnalysis.data;
+
+import com.intellij.codeInspection.bytecodeAnalysis.BytecodeAnalysisConverter;
+import com.intellij.codeInspection.bytecodeAnalysis.ExpectNoPsiKey;
+
+/**
+ * @author lambdamix
+ */
+public class TestConverterData {
+
+ public static class StaticNestedClass {
+ public StaticNestedClass(Object o) {
+
+ }
+ public StaticNestedClass[] test01(StaticNestedClass[] ns, StaticNestedClass... ellipsis) {
+ return ns;
+ }
+ }
+
+ public class InnerClass {
+ // a reference to outer class should be inserted when translating PSI -> ASM
+ public InnerClass(Object o) {}
+
+ public InnerClass[] Inner2test01(InnerClass[] tests, InnerClass... ellipsis) {
+ return tests;
+ }
+ }
+
+ public static class GenericStaticNestedClass<A> {
+ public GenericStaticNestedClass(A a) {
+
+ }
+ public GenericStaticNestedClass[] test01(GenericStaticNestedClass[] ns, GenericStaticNestedClass... ellipsis) {
+ return ns;
+ }
+
+ public GenericStaticNestedClass<A>[] test02(GenericStaticNestedClass<A>[] ns, GenericStaticNestedClass<A>... ellipsis) {
+ return ns;
+ }
+
+ public class GenericInnerClass<B> {
+ public GenericInnerClass(B b) {}
+
+ public <C> GenericStaticNestedClass<A> test01(GenericInnerClass<C> c) {
+ return GenericStaticNestedClass.this;
+ }
+ }
+ }
+
+ public TestConverterData(int x) {}
+
+ // BytecodeAnalysisConverter class is not in the project path, so translation from PSI is impossible
+ @ExpectNoPsiKey
+ public BytecodeAnalysisConverter test01(BytecodeAnalysisConverter converter) {
+ return converter;
+ }
+
+ @TestAnnotation
+ public TestConverterData[] test02(@TestAnnotation TestConverterData[] tests) throws Exception {
+ return tests;
+ }
+
+ public boolean[] test03(boolean[] b) {
+ return b;
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java
index 498a1172fa9a..e9d1da3aaf18 100644
--- a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java
+++ b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java
@@ -67,48 +67,48 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
}
public void testSimpleReturn() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Object instance = testClass.newInstance();
Method method = testClass.getMethod("test");
verifyCallThrowsException("@NotNull method SimpleReturn.test must not return null", instance, method);
}
public void testSimpleReturnWithMessage() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Object instance = testClass.newInstance();
Method method = testClass.getMethod("test");
verifyCallThrowsException("This method cannot return null", instance, method);
}
public void testMultipleReturns() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Object instance = testClass.newInstance();
Method method = testClass.getMethod("test", int.class);
verifyCallThrowsException("@NotNull method MultipleReturns.test must not return null", instance, method, 1);
}
public void testSimpleParam() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Object instance = testClass.newInstance();
Method method = testClass.getMethod("test", Object.class);
verifyCallThrowsException("Argument 0 for @NotNull parameter of SimpleParam.test must not be null", instance, method, (Object)null);
}
public void testSimpleParamWithMessage() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Object instance = testClass.newInstance();
Method method = testClass.getMethod("test", Object.class);
verifyCallThrowsException("SimpleParamWithMessage.test(o) cant be null", instance, method, (Object)null);
}
public void testConstructorParam() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Constructor method = testClass.getConstructor(Object.class);
verifyCallThrowsException("Argument 0 for @NotNull parameter of ConstructorParam.<init> must not be null", null, method, (Object)null);
}
public void testConstructorParamWithMessage() throws Exception {
- Class testClass = prepareTest();
+ Class<?> testClass = prepareTest();
Constructor method = testClass.getConstructor(Object.class);
verifyCallThrowsException("ConstructorParam.ConstructorParam.o cant be null", null, method, (Object)null);
}
@@ -132,6 +132,19 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
assertNotNull(field);
}
+ public void testCustomExceptionType() throws Exception {
+ Class<?> testClass = prepareTest();
+ try {
+ testClass.getMethod("foo", Object.class, Object.class).invoke(testClass.newInstance(), null, null);
+ fail();
+ }
+ catch (InvocationTargetException e) {
+ //noinspection ThrowableResultOfMethodCallIgnored
+ assertInstanceOf(e.getCause(), NullPointerException.class);
+ assertEquals("Argument 1 for @NotNull parameter of CustomExceptionType.foo must not be null", e.getCause().getMessage());
+ }
+ }
+
public void testEnumConstructorSecondParam() throws Exception {
Class testClass = prepareTest();
Object field = testClass.getField("Value");
diff --git a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java
new file mode 100644
index 000000000000..02f8c589c43b
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java
@@ -0,0 +1,222 @@
+/*
+ * 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.find;
+
+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.util.Getter;
+import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
+
+import javax.swing.text.JTextComponent;
+import java.io.IOException;
+
+public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureTestCase {
+ public void testBasic() throws IOException {
+ init("abc\n" +
+ "abc\n" +
+ "abc");
+ initFind();
+ setTextToFind("b");
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "abc\n" +
+ "abc");
+ addOccurrence();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "abc");
+ nextOccurrence();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "abc\n" +
+ "a<selection>b<caret></selection>c");
+ prevOccurrence();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "abc");
+ removeOccurrence();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "abc\n" +
+ "abc");
+ allOccurrences();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c");
+ assertNull(getEditorSearchComponent());
+ }
+
+ public void testActionsWorkFromEditor() throws IOException {
+ init("abc\n" +
+ "abc\n" +
+ "abc");
+ initFind();
+ setTextToFind("b");
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "abc\n" +
+ "abc");
+ addOccurrenceFromEditor();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "abc");
+ nextOccurrenceFromEditor();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "abc\n" +
+ "a<selection>b<caret></selection>c");
+ prevOccurrenceFromEditor();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "abc");
+ removeOccurrenceFromEditor();
+ checkResultByText("a<selection>b<caret></selection>c\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());
+ }
+
+ public void testCloseRetainsMulticaretSelection() throws IOException {
+ init("abc\n" +
+ "abc\n" +
+ "abc");
+ initFind();
+ setTextToFind("b");
+ addOccurrence();
+ closeFind();
+ checkResultByText("a<selection>b<caret></selection>c\n" +
+ "a<selection>b<caret></selection>c\n" +
+ "abc");
+ }
+
+ public void testTextModificationRemovesOldSelections() throws IOException {
+ init("abc\n" +
+ "abc\n" +
+ "abc");
+ initFind();
+ setTextToFind("b");
+ addOccurrence();
+ setTextToFind("bc");
+
+ assertEquals(1, myFixture.getEditor().getCaretModel().getCaretCount());
+ assertEquals("bc", myFixture.getEditor().getSelectionModel().getSelectedText());
+ }
+
+ public void testSecondFindNavigatesToTheSameOccurrence() throws IOException {
+ init("ab<caret>c\n" +
+ "abc\n" +
+ "abc");
+ initFind();
+ setTextToFind("abc");
+ checkResultByText("abc\n" +
+ "<selection>abc<caret></selection>\n" +
+ "abc");
+ closeFind();
+ initFind();
+ setTextToFind("abc");
+ checkResultByText("abc\n" +
+ "<selection>abc<caret></selection>\n" +
+ "abc");
+ }
+
+ private void setTextToFind(String text) {
+ EditorSearchComponent editorSearchComponent = getEditorSearchComponent();
+ assertNotNull(editorSearchComponent);
+ JTextComponent searchField = editorSearchComponent.getSearchField();
+ assertNotNull(searchField);
+ for (int i = 0; i <= text.length(); i++) {
+ searchField.setText(text.substring(0, i)); // emulate typing chars one by one
+ }
+ }
+
+ private void nextOccurrence() {
+ final EditorSearchComponent editorSearchComponent = getEditorSearchComponent();
+ executeAction(new NextOccurrenceAction(editorSearchComponent, new Getter<JTextComponent>() {
+ @Override
+ public JTextComponent get() {
+ return editorSearchComponent.getSearchField();
+ }
+ }));
+ }
+
+ private void prevOccurrence() {
+ final EditorSearchComponent editorSearchComponent = getEditorSearchComponent();
+ executeAction(new PrevOccurrenceAction(editorSearchComponent, new Getter<JTextComponent>() {
+ @Override
+ public JTextComponent get() {
+ return editorSearchComponent.getSearchField();
+ }
+ }));
+ }
+
+ private void addOccurrence() {
+ executeAction(new AddOccurrenceAction(getEditorSearchComponent()));
+ }
+
+ private void removeOccurrence() {
+ executeAction(new RemoveOccurrenceAction(getEditorSearchComponent()));
+ }
+
+ private void allOccurrences() {
+ executeAction(new SelectAllAction(getEditorSearchComponent()));
+ }
+
+ private void nextOccurrenceFromEditor() {
+ myFixture.performEditorAction(IdeActions.ACTION_FIND_NEXT);
+ }
+
+ private void prevOccurrenceFromEditor() {
+ myFixture.performEditorAction(IdeActions.ACTION_FIND_PREVIOUS);
+ }
+
+ private void addOccurrenceFromEditor() {
+ myFixture.performEditorAction(IdeActions.ACTION_SELECT_NEXT_OCCURENCE);
+ }
+
+ private void removeOccurrenceFromEditor() {
+ myFixture.performEditorAction(IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE);
+ }
+
+ private void allOccurrencesFromEditor() {
+ myFixture.performEditorAction(IdeActions.ACTION_SELECT_ALL_OCCURRENCES);
+ }
+
+ private void closeFind() {
+ EditorSearchComponent editorSearchComponent = getEditorSearchComponent();
+ executeAction(new CloseOnESCAction(editorSearchComponent, editorSearchComponent.getSearchField()));
+ }
+
+ private static void executeAction(EditorHeaderAction action) {
+ action.actionPerformed(AnActionEvent.createFromInputEvent(action, null, ActionPlaces.EDITOR_TOOLBAR));
+ }
+
+ private void initFind() {
+ myFixture.performEditorAction("Find");
+ }
+
+ private EditorSearchComponent getEditorSearchComponent() {
+ return (EditorSearchComponent)myFixture.getEditor().getHeaderComponent();
+ }
+
+ private void init(String text) {
+ myFixture.configureByText(getTestName(false) + ".txt", text);
+ }
+
+ private void checkResultByText(String text) {
+ myFixture.checkResult(text);
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/find/FindInEditorTest.java b/java/java-tests/testSrc/com/intellij/find/FindInEditorTest.java
index cfe9cdde2273..043c755f8ca9 100644
--- a/java/java-tests/testSrc/com/intellij/find/FindInEditorTest.java
+++ b/java/java-tests/testSrc/com/intellij/find/FindInEditorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 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.
@@ -15,10 +15,14 @@
*/
package com.intellij.find;
+import com.intellij.codeInsight.hint.EditorHintListener;
import com.intellij.find.impl.livePreview.LivePreview;
import com.intellij.find.impl.livePreview.LivePreviewController;
import com.intellij.find.impl.livePreview.SearchResults;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.project.Project;
import com.intellij.testFramework.LightCodeInsightTestCase;
+import com.intellij.ui.LightweightHint;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@@ -39,6 +43,13 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
myOutputStream = new ByteArrayOutputStream();
LivePreview.ourTestOutput = new PrintStream(myOutputStream);
+ EditorHintListener listener = new EditorHintListener() {
+ @Override
+ public void hintShown(Project project, LightweightHint hint, int flags) {
+ LivePreview.processNotFound();
+ }
+ };
+ ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, listener);
}
private void initFind() {
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 23895d64a39e..1e3e08a33ae7 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
@@ -188,7 +188,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
}
public void testDirInfos() throws IOException {
- checkInfoNull(myRootVFile);
+ assertNotInProject(myRootVFile);
// beware: files in directory index
checkInfo(myFileLibSrc, null, false, true, "", null, myModule);
@@ -206,21 +206,21 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfo(myLibSrcDir, myModule, false, true, "", null, myModule2, myModule3);
checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2, myModule3);
- assertEquals(myLibSrcDir, checkInfoNotNull(myLibSrcDir).getSourceRoot());
+ assertEquals(myLibSrcDir, assertInProject(myLibSrcDir).getSourceRoot());
checkInfo(myModule2Dir, myModule2, false, false, null, null);
checkInfo(mySrcDir2, myModule2, false, false, "", JavaSourceRootType.SOURCE, myModule2, myModule3);
- checkInfoNull(myCvsDir);
- checkInfoNull(myExcludeDir);
- checkInfoNull(myExcludedLibClsDir);
- checkInfoNull(myExcludedLibSrcDir);
+ assertNotInProject(myCvsDir);
+ assertExcluded(myExcludeDir, myModule2);
+ assertExcluded(myExcludedLibClsDir, myModule);
+ assertExcluded(myExcludedLibSrcDir, myModule);
- assertEquals(myModule1Dir, checkInfoNotNull(myLibClsDir).getContentRoot());
+ assertEquals(myModule1Dir, assertInProject(myLibClsDir).getContentRoot());
checkInfo(myModule3Dir, myModule3, false, false, null, null);
VirtualFile cvs = myPack1Dir.createChildDirectory(this, "CVS");
- checkInfoNull(cvs);
+ assertNotInProject(cvs);
assertNull(ProjectRootManager.getInstance(myProject).getFileIndex().getPackageNameByDirectory(cvs));
}
@@ -332,7 +332,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile newDir = myModule1Dir.createChildDirectory(this, "newDir");
myIndex.checkConsistency();
- checkInfoNotNull(newDir);
+ assertInProject(newDir);
final FileTypeManagerEx fileTypeManager = (FileTypeManagerEx)FileTypeManager.getInstance();
final String list = fileTypeManager.getIgnoredFilesList();
@@ -345,7 +345,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
}
});
myIndex.checkConsistency();
- checkInfoNull(newDir);
+ assertNotInProject(newDir);
}
finally {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@@ -354,10 +354,17 @@ public class DirectoryIndexTest extends IdeaTestCase {
fileTypeManager.setIgnoredFilesList(list);
}
});
- checkInfoNotNull(newDir);
+ assertInProject(newDir);
}
}
+ public void testIgnoredFile() throws IOException {
+ VirtualFile ignoredFile = myModule1Dir.createChildData(this, "CVS");
+ DirectoryInfo info = myIndex.getInfoForFile(ignoredFile);
+ assertTrue(info.isIgnored());
+ assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(ignoredFile));
+ }
+
public void testAddModule() throws Exception {
myIndex.checkConsistency();
@@ -379,16 +386,18 @@ 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));
final VirtualFile module4 = ignored.createChildDirectory(this, "module4");
assertFalse(FileTypeManager.getInstance().isFileIgnored(module4));
-
+ assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(module4));
+
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
PsiTestUtil.addContentRoot(module, module4);
- checkInfoNull(ignored);
+ assertNotInProject(ignored);
checkInfo(module4, module, false, false, null, null);
}
}.execute().throwException();
@@ -418,9 +427,9 @@ public class DirectoryIndexTest extends IdeaTestCase {
public void testExcludedDirsInLibraries() {
ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
assertFalse(index.isInLibraryClasses(myExcludedLibClsDir));
- assertTrue(index.isIgnored(myExcludedLibClsDir));
+ assertTrue(index.isExcluded(myExcludedLibClsDir));
assertFalse(index.isInLibrarySource(myExcludedLibSrcDir));
- assertTrue(index.isIgnored(myExcludedLibSrcDir));
+ assertTrue(index.isExcluded(myExcludedLibSrcDir));
}
public void testExplicitExcludeOfInner() throws Exception {
@@ -436,20 +445,20 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile output1 = myModule1Dir.createChildDirectory(this, "output1");
VirtualFile output2 = myModule1Dir.createChildDirectory(this, "output2");
- checkInfoNotNull(output1);
- checkInfoNotNull(output2);
+ assertInProject(output1);
+ assertInProject(output2);
getCompilerProjectExtension().setCompilerOutputUrl(output1.getUrl());
fireRootsChanged();
- checkInfoNull(output1);
- checkInfoNotNull(output2);
+ assertExcluded(output1, myModule);
+ assertInProject(output2);
getCompilerProjectExtension().setCompilerOutputUrl(output2.getUrl());
fireRootsChanged();
- checkInfoNotNull(output1);
- checkInfoNull(output2);
+ assertInProject(output1);
+ assertExcluded(output2, myModule);
}
private void fireRootsChanged() {
@@ -460,12 +469,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.getInfoForDirectory(mySrcDir1).getOrderEntries();
+ OrderEntry[] entries = myIndex.getInfoForFile(mySrcDir1).getOrderEntries();
assertInstanceOf(entries[0], LibraryOrderEntry.class);
assertInstanceOf(entries[1], ModuleSourceOrderEntry.class);
checkInfo(myTestSrc1, myModule, false, true, "testSrc", JavaSourceRootType.TEST_SOURCE, myModule, myModule);
- entries = myIndex.getInfoForDirectory(myTestSrc1).getOrderEntries();
+ entries = myIndex.getInfoForFile(myTestSrc1).getOrderEntries();
assertInstanceOf(entries[0], LibraryOrderEntry.class);
assertInstanceOf(entries[1], ModuleSourceOrderEntry.class);
}
@@ -473,7 +482,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(checkInfoNotNull(mySrcDir1).getOrderEntries()), ModuleSourceOrderEntry.class);
+ assertInstanceOf(assertOneElement(assertInProject(mySrcDir1).getOrderEntries()), ModuleSourceOrderEntry.class);
}
public void testModulesWithSameSourceContentRoot() {
@@ -487,7 +496,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfo(myResDir, myModule, false, false, "", JavaResourceRootType.RESOURCE, myModule);
checkInfo(mySrcDir2, myModule2, false, false, "", JavaSourceRootType.SOURCE, myModule2, myModule3);
- assertEquals(myModule2Dir, myIndex.getInfoForDirectory(mySrcDir2).getContentRoot());
+ assertEquals(myModule2Dir, myIndex.getInfoForFile(mySrcDir2).getContentRoot());
}
public void testModuleWithSameSourceRoot() {
@@ -503,7 +512,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
public void testSameSourceAndOutput() {
PsiTestUtil.setCompilerOutputPath(myModule, mySrcDir1.getUrl(), false);
- checkInfoNull(mySrcDir1);
+ assertExcluded(mySrcDir1, myModule);
}
public void testExcludedDirShouldBeExcludedRightAfterItsCreation() throws Exception {
@@ -512,10 +521,10 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile module2Output = myModule1Dir.createChildDirectory(this, "module2Output");
VirtualFile module2TestOutput = myModule2Dir.createChildDirectory(this, "module2TestOutput");
- checkInfoNotNull(excluded);
- checkInfoNotNull(projectOutput);
- checkInfoNotNull(module2Output);
- checkInfoNotNull(module2TestOutput);
+ assertInProject(excluded);
+ assertInProject(projectOutput);
+ assertInProject(module2Output);
+ assertInProject(module2TestOutput);
getCompilerProjectExtension().setCompilerOutputUrl(projectOutput.getUrl());
@@ -524,15 +533,10 @@ public class DirectoryIndexTest extends IdeaTestCase {
PsiTestUtil.setCompilerOutputPath(myModule2, module2TestOutput.getUrl(), true);
PsiTestUtil.setExcludeCompileOutput(myModule2, true);
- checkInfoNull(excluded);
- checkInfoNull(projectOutput);
- checkInfoNull(module2Output);
- checkInfoNull(module2TestOutput);
-
- assertFalse(myIndex.isProjectExcludeRoot(excluded));
- assertFalse(myIndex.isProjectExcludeRoot(projectOutput));
- assertFalse(myIndex.isProjectExcludeRoot(module2Output));
- assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput));
+ assertExcluded(excluded, myModule);
+ assertExcluded(projectOutput, myModule);
+ assertExcluded(module2Output, myModule);
+ assertExcluded(module2TestOutput, myModule2);
excluded.delete(this);
projectOutput.delete(this);
@@ -544,46 +548,26 @@ public class DirectoryIndexTest extends IdeaTestCase {
@Override
public void fileCreated(@NotNull VirtualFileEvent e) {
VirtualFile file = e.getFile();
- checkInfoNull(file);
- created.add(file);
-
String fileName = e.getFileName();
- if (fileName.equals("projectOutput")) {
- assertFalse(myIndex.isProjectExcludeRoot(file));
- }
- if (fileName.equals("module2Output")) {
- assertFalse(myIndex.isProjectExcludeRoot(file));
- }
- if (fileName.equals("module2TestOutput")) {
- assertFalse(myIndex.isProjectExcludeRoot(file));
- }
+ assertExcluded(file, fileName.contains("module2TestOutput") ? myModule2 : myModule);
+ created.add(file);
}
};
VirtualFileManager.getInstance().addVirtualFileListener(l, getTestRootDisposable());
excluded = myModule1Dir.createChildDirectory(this, excluded.getName());
- assertFalse(myIndex.isProjectExcludeRoot(excluded));
-
+ assertExcluded(excluded, myModule);
+
projectOutput = myModule1Dir.createChildDirectory(this, projectOutput.getName());
- assertFalse(myIndex.isProjectExcludeRoot(projectOutput));
-
+ assertExcluded(projectOutput, myModule);
+
module2Output = myModule1Dir.createChildDirectory(this, module2Output.getName());
- assertFalse(myIndex.isProjectExcludeRoot(module2Output));
-
- module2TestOutput = myModule2Dir.createChildDirectory(this, module2TestOutput.getName());
- assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput));
+ assertExcluded(module2Output, myModule);
- checkInfoNull(excluded);
- checkInfoNull(projectOutput);
- checkInfoNull(module2Output);
- checkInfoNull(module2TestOutput);
+ module2TestOutput = myModule2Dir.createChildDirectory(this, module2TestOutput.getName());
+ assertExcluded(module2TestOutput, myModule2);
assertEquals(created.toString(), 4, created.size());
-
- assertFalse(myIndex.isProjectExcludeRoot(excluded));
- assertFalse(myIndex.isProjectExcludeRoot(projectOutput));
- assertFalse(myIndex.isProjectExcludeRoot(module2Output));
- assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput));
}
public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception {
@@ -607,9 +591,9 @@ public class DirectoryIndexTest extends IdeaTestCase {
assertEquals("dir", e.getFileName());
VirtualFile file = e.getFile();
- checkInfoNotNull(file);
- checkInfoNull(file.findFileByRelativePath("excluded"));
- checkInfoNull(file.findFileByRelativePath("excluded/foo"));
+ assertInProject(file);
+ assertExcluded(file.findFileByRelativePath("excluded"), myModule);
+ assertExcluded(file.findFileByRelativePath("excluded/foo"), myModule);
}
};
@@ -638,8 +622,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
});
- checkInfoNull(LocalFileSystem.getInstance().findFileByIoFile(f.getParentFile().getParentFile()));
- checkInfoNotNull(LocalFileSystem.getInstance().findFileByIoFile(f));
+ assertExcluded(LocalFileSystem.getInstance().findFileByIoFile(f.getParentFile().getParentFile()), myModule);
+ assertInProject(LocalFileSystem.getInstance().findFileByIoFile(f));
}
public void testLibraryDirInContent() throws Exception {
@@ -661,7 +645,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule, myModule3);
checkInfo(myResDir, myModule, true, false, "", JavaResourceRootType.RESOURCE, myModule);
- assertInstanceOf(assertOneElement(checkInfoNotNull(myResDir).getOrderEntries()), ModuleSourceOrderEntry.class);
+ assertInstanceOf(assertOneElement(assertInProject(myResDir).getOrderEntries()), ModuleSourceOrderEntry.class);
checkInfo(myExcludedLibSrcDir, null, true, false, "lib.src.exc", null, myModule3, myModule);
checkInfo(myExcludedLibClsDir, null, true, false, "lib.cls.exc", null, myModule3);
@@ -678,11 +662,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
public void testExcludeCompilerOutputOutsideOfContentRoot() throws Exception {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
- assertTrue(fileIndex.isIgnored(myOutputDir));
- assertTrue(fileIndex.isIgnored(myModule1OutputDir));
- assertFalse(fileIndex.isIgnored(myOutputDir.getParent()));
- assertTrue(myIndex.isProjectExcludeRoot(myOutputDir));
- assertFalse(myIndex.isProjectExcludeRoot(myModule1OutputDir));
+ assertTrue(fileIndex.isExcluded(myOutputDir));
+ assertTrue(fileIndex.isExcluded(myModule1OutputDir));
+ assertFalse(fileIndex.isExcluded(myOutputDir.getParent()));
+ assertExcludedFromProject(myOutputDir);
+ assertExcludedFromProject(myModule1OutputDir);
String moduleOutputUrl = myModule1OutputDir.getUrl();
myOutputDir.delete(this);
@@ -691,9 +675,9 @@ public class DirectoryIndexTest extends IdeaTestCase {
myOutputDir = myRootVFile.createChildDirectory(this, "out");
myModule1OutputDir = myOutputDir.createChildDirectory(this, "module1");
- assertTrue(myIndex.isProjectExcludeRoot(myOutputDir));
- assertTrue(myIndex.isProjectExcludeRoot(myModule1OutputDir));
- assertTrue(fileIndex.isIgnored(myModule1OutputDir));
+ assertExcludedFromProject(myOutputDir);
+ assertExcludedFromProject(myModule1OutputDir);
+ assertTrue(fileIndex.isExcluded(myModule1OutputDir));
PsiTestUtil.setCompilerOutputPath(myModule, moduleOutputUrl, true);
PsiTestUtil.setCompilerOutputPath(myModule2, moduleOutputUrl, false);
@@ -702,20 +686,20 @@ public class DirectoryIndexTest extends IdeaTestCase {
PsiTestUtil.setCompilerOutputPath(myModule3, moduleOutputUrl, true);
// now no module inherits project output dir, but it still should be project-excluded
- assertTrue(myIndex.isProjectExcludeRoot(myOutputDir));
+ assertExcludedFromProject(myOutputDir);
// project output inside module content shouldn't be projectExcludeRoot
VirtualFile projectOutputUnderContent = myModule1Dir.createChildDirectory(this, "projectOutputUnderContent");
getCompilerProjectExtension().setCompilerOutputUrl(projectOutputUnderContent.getUrl());
fireRootsChanged();
- assertFalse(myIndex.isProjectExcludeRoot(myOutputDir));
- assertFalse(myIndex.isProjectExcludeRoot(projectOutputUnderContent));
-
+ assertNotExcluded(myOutputDir);
+ assertExcluded(projectOutputUnderContent, myModule);
+
projectOutputUnderContent.delete(this);
projectOutputUnderContent = myModule1Dir.createChildDirectory(this, "projectOutputUnderContent");
- assertFalse(myIndex.isProjectExcludeRoot(myOutputDir));
- assertFalse(myIndex.isProjectExcludeRoot(projectOutputUnderContent));
+ assertNotExcluded(myOutputDir);
+ assertExcluded(projectOutputUnderContent, myModule);
}
public void testFileContentAndSourceRoots() throws IOException {
@@ -725,7 +709,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt");
VirtualFile fileTestSourceRoot = myRootVFile.createChildData(this, "fileTestSourceRoot.txt");
- checkInfoNull(fileRoot);
+ assertNotInProject(fileRoot);
assertFalse(fileIndex.isInContent(fileRoot));
assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot));
@@ -758,7 +742,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
// removing file content root
PsiTestUtil.removeContentEntry(myModule, contentEntry);
- checkInfoNull(fileRoot);
+ assertNotInProject(fileRoot);
assertFalse(fileIndex.isInContent(fileRoot));
assertFalse(fileIndex.isInSource(fileRoot));
assertIteratedContent(fileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot));
@@ -785,7 +769,6 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile fileSourceRoot = myModule1Dir.createChildData(this, "fileSourceRoot.txt");
assertTrue(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
- checkInfoNull(fileSourceRoot);
PsiTestUtil.addSourceRoot(myModule, fileSourceRoot);
assertTrue(fileIndex.isInContent(fileSourceRoot));
@@ -796,7 +779,6 @@ public class DirectoryIndexTest extends IdeaTestCase {
PsiTestUtil.removeSourceRoot(myModule, fileSourceRoot);
assertTrue(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
- checkInfoNull(fileSourceRoot);
}
public void testFileModuleExcludeRootUnderDirectoryRoot() throws IOException {
@@ -805,20 +787,18 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile fileExcludeRoot = mySrcDir1.createChildData(this, "fileExcludeRoot.txt");
assertTrue(fileIndex.isInContent(fileExcludeRoot));
assertTrue(fileIndex.isInSource(fileExcludeRoot));
- checkInfoNull(fileExcludeRoot);
assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null);
PsiTestUtil.addExcludedRoot(myModule, fileExcludeRoot);
assertFalse(fileIndex.isInContent(fileExcludeRoot));
assertFalse(fileIndex.isInSource(fileExcludeRoot));
- checkInfoNull(fileExcludeRoot);
+ assertExcluded(fileExcludeRoot, myModule);
assertIteratedContent(fileIndex, null, Arrays.asList(fileExcludeRoot));
// removing file exclude root
PsiTestUtil.removeExcludedRoot(myModule, fileExcludeRoot);
assertTrue(fileIndex.isInContent(fileExcludeRoot));
assertTrue(fileIndex.isInSource(fileExcludeRoot));
- checkInfoNull(fileExcludeRoot);
assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null);
}
@@ -833,7 +813,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
PsiTestUtil.addExcludedRoot(myModule, fileRoot);
assertFalse(fileIndex.isInContent(fileRoot));
- checkInfoNull(fileRoot);
+ assertExcluded(fileRoot, myModule);
assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot));
// removing file exclude root
@@ -860,7 +840,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
VirtualFile temp = myRootVFile.createChildDirectory(this, "temp");
VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt");
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
PsiTestUtil.addContentRoot(myModule, fileSourceRoot);
PsiTestUtil.addSourceRoot(myModule, fileSourceRoot);
@@ -870,7 +850,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
// delete and recreate
fileSourceRoot.delete(this);
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
assertFalse(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt");
@@ -880,11 +860,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
// delete and move from another dir
fileSourceRoot.delete(this);
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
assertFalse(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt");
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
fileSourceRoot.move(this, myRootVFile);
checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule);
assertTrue(fileIndex.isInContent(fileSourceRoot));
@@ -892,11 +872,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
// delete and copy from another dir
fileSourceRoot.delete(this);
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
assertFalse(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt");
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
fileSourceRoot = fileSourceRoot.copy(this, myRootVFile, "fileSourceRoot.txt");
checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule);
assertTrue(fileIndex.isInContent(fileSourceRoot));
@@ -904,25 +884,25 @@ public class DirectoryIndexTest extends IdeaTestCase {
// delete and rename from another file
fileSourceRoot.delete(this);
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
assertFalse(fileIndex.isInContent(fileSourceRoot));
assertFalse(fileIndex.isInSource(fileSourceRoot));
fileSourceRoot = myRootVFile.createChildData(this, "temp_file.txt");
- checkInfoNull(fileSourceRoot);
+ assertNotInProject(fileSourceRoot);
fileSourceRoot.rename(this, "fileSourceRoot.txt");
checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule);
assertTrue(fileIndex.isInContent(fileSourceRoot));
assertTrue(fileIndex.isInSource(fileSourceRoot));
}
- private void checkInfo(VirtualFile dir,
+ private void checkInfo(VirtualFile file,
@Nullable Module module,
boolean isInLibrary,
boolean isInLibrarySource,
@Nullable String packageName,
@Nullable final JpsModuleSourceRootType<?> moduleSourceRootType,
Module... modulesOfOrderEntries) {
- DirectoryInfo info = checkInfoNotNull(dir);
+ DirectoryInfo info = assertInProject(file);
assertEquals(module, info.getModule());
if (moduleSourceRootType != null) {
assertTrue("isInModuleSource", info.isInModuleSource());
@@ -935,8 +915,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
assertEquals(isInLibrarySource, info.isInLibrarySource());
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
- if (dir.isDirectory()) {
- assertEquals(packageName, fileIndex.getPackageNameByDirectory(dir));
+ if (file.isDirectory()) {
+ assertEquals(packageName, fileIndex.getPackageNameByDirectory(file));
}
assertEquals(Arrays.toString(info.getOrderEntries()), modulesOfOrderEntries.length, info.getOrderEntries().length);
@@ -946,16 +926,33 @@ public class DirectoryIndexTest extends IdeaTestCase {
}
}
- private void checkInfoNull(VirtualFile dir) {
- assertNull(myIndex.getInfoForDirectory(dir));
+ private void assertNotInProject(VirtualFile file) {
+ DirectoryInfo info = myIndex.getInfoForFile(file);
+ assertFalse(info.toString(), info.isInProject());
+ assertFalse(info.toString(), info.isExcluded());
+ }
+
+ private void assertExcluded(VirtualFile file, Module module) {
+ DirectoryInfo info = myIndex.getInfoForFile(file);
+ assertTrue(info.toString(), info.isExcluded());
+ assertEquals(module, info.getModule());
}
- private DirectoryInfo checkInfoNotNull(VirtualFile output2) {
- DirectoryInfo info = myIndex.getInfoForDirectory(output2);
- assertNotNull(output2.toString(), info);
+
+ private DirectoryInfo assertInProject(VirtualFile file) {
+ DirectoryInfo info = myIndex.getInfoForFile(file);
+ assertTrue(file.toString(), info.isInProject());
info.assertConsistency();
return info;
}
+ private void assertNotExcluded(VirtualFile file) {
+ assertFalse(myIndex.getInfoForFile(file).isExcluded());
+ }
+
+ private void assertExcludedFromProject(VirtualFile file) {
+ assertExcluded(file, null);
+ }
+
private void checkPackage(String packageName, boolean includeLibrarySources, VirtualFile... expectedDirs) {
VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY);
assertNotNull(actualDirs);
diff --git a/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java b/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java
index 8f6956808dea..dd0611f53175 100644
--- a/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/CodeFragmentsTest.java
@@ -1,6 +1,10 @@
package com.intellij.psi;
import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
+import com.intellij.openapi.util.EmptyRunnable;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.testFramework.LightVirtualFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.PsiTestCase;
@@ -30,4 +34,15 @@ public class CodeFragmentsTest extends PsiTestCase{
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertEquals("ab", PsiDocumentManager.getInstance(myProject).getDocument(fragment).getText());
}
+
+ public void testDontRecreateFragmentPsi() {
+ PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment("a", null, null, true);
+ VirtualFile file = fragment.getViewProvider().getVirtualFile();
+ assertInstanceOf(file, LightVirtualFile.class);
+
+ ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.getInstance(), false, true);
+
+ assertSame(fragment, PsiManager.getInstance(myProject).findFile(file));
+ assertTrue(fragment.isValid());
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java
index bf11a587f2c3..fe005a84db3f 100644
--- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java
@@ -400,4 +400,36 @@ public class JavaFormatterBlankLinesTest extends AbstractJavaFormatterTest {
"}"
);
}
+
+ public void testIDEA126836() {
+ doTextTest(
+ "public class JavaClass { // comment\n" +
+ " public void doSomething() {\n" +
+ " int a = 3;\n" +
+ " }\n" +
+ "}",
+ "public class JavaClass { // comment\n" +
+ " public void doSomething() {\n" +
+ " int a = 3;\n" +
+ " }\n" +
+ "}"
+ );
+ }
+
+ public void testBlankLinesAfterClassHeaderWithComment() {
+ getSettings().BLANK_LINES_AFTER_CLASS_HEADER = 5;
+ doTextTest(
+ "public class JavaClass { // comment\n" +
+ " public void doSomething() {\n" +
+ " int a = 3;\n" +
+ " }\n" +
+ "}",
+ "public class JavaClass { // comment\n" +
+ "\n\n\n\n\n" +
+ " public void doSomething() {\n" +
+ " int a = 3;\n" +
+ " }\n" +
+ "}"
+ );
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java
index f0d4e771ed1a..665afec47ec9 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java
@@ -163,6 +163,9 @@ public class PullUpTest extends LightRefactoringTestCase {
public void testPreserveOverride() {
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
}
+ public void testAsDefaultMethodOverAbstract() {
+ doTest(false, "Class <b><code>Test.Printer</code></b> already contains a method <b><code>foo()</code></b>", new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
+ }
public void testPublicMethodFromPrivateClassConflict() {
doTest(false, new RefactoringTestUtil.MemberDescriptor("HM", PsiClass.class), new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java
index 99de5eb68dc4..922d5e04c3bc 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java
@@ -268,6 +268,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
doTest();
}
+ public void testThisNameConflict() throws Exception {
+ doTest();
+ }
+
private void doTestInlineThisOnly() {
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
configureByFile(fileName);