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/codeInsight/GenerateGetterSetterTest.groovy4
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java16
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy42
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java4
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy2
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java5
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java2
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java3
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java6
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java23
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java5
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java11
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy51
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java2
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java8
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java42
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java26
-rw-r--r--java/java-tests/testSrc/com/intellij/find/FindManagerTest.java22
-rw-r--r--java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy10
-rw-r--r--java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java7
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/FindClassInDeepPackagesTest.java (renamed from java/java-tests/testSrc/com/intellij/psi/SCR17094Test.java)19
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java21
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/ClassFileUnderSourceRootTest.java (renamed from java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR17650Test.java)15
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java (renamed from java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR14423Test.java)37
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java (renamed from java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR20733Test.java)9
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java (renamed from java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR19174Test.java)15
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java89
-rw-r--r--java/java-tests/testSrc/com/intellij/psi/impl/file/impl/TempFileSystemTest.java43
-rw-r--r--java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java3
-rw-r--r--java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java119
30 files changed, 497 insertions, 164 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy
index 273ab150d8c5..4aabc1448492 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy
@@ -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.
@@ -20,6 +20,7 @@ import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
+import com.intellij.util.ui.UIUtil
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
import org.jetbrains.annotations.Nullable
/**
@@ -103,5 +104,6 @@ class Foo {
}
}.invoke(project, myFixture.editor, myFixture.file)
})
+ UIUtil.dispatchAllInvocationEvents()
}
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
index 9ca3b6084a43..37aa8852136b 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java
@@ -74,6 +74,22 @@ public class JavaTypingTest extends LightPlatformCodeInsightFixtureTestCase {
myFixture.checkResultByFile(getTestName(true) + "_after.java");
}
+ public void testFixIfByBrace() {
+ doTest('{');
+ }
+
+ public void testFixIfByBraceNewObject() {
+ doTest('{');
+ }
+
+ public void testFixIfByBraceCompositeCondition() {
+ doTest('{');
+ }
+
+ public void testFixWhileByBrace() {
+ doTest('{');
+ }
+
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 7391f93a1ab2..1dd75011d3b8 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
@@ -14,6 +14,7 @@
* limitations under the License.
*/
package com.intellij.codeInsight.completion
+
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.TargetElementUtil
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl
@@ -24,10 +25,7 @@ import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.codeInsight.lookup.PsiTypeLookupItem
import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.codeInsight.template.*
-import com.intellij.codeInsight.template.impl.LiveTemplateDocumentationProvider
-import com.intellij.codeInsight.template.impl.TemplateImpl
-import com.intellij.codeInsight.template.impl.TemplateManagerImpl
-import com.intellij.codeInsight.template.impl.TemplateSettings
+import com.intellij.codeInsight.template.impl.*
import com.intellij.ide.DataManager
import com.intellij.ide.ui.UISettings
import com.intellij.openapi.Disposable
@@ -53,6 +51,7 @@ import com.intellij.openapi.util.Disposer
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiJavaFile
+import com.intellij.psi.PsiMethod
import com.intellij.psi.statistics.StatisticsManager
import com.intellij.psi.statistics.impl.StatisticsManagerImpl
import com.intellij.testFramework.EditorTestUtil
@@ -60,6 +59,7 @@ import com.intellij.util.containers.ContainerUtil
import org.jetbrains.annotations.NotNull
import java.awt.event.KeyEvent
+
/**
* @author peter
*/
@@ -974,8 +974,15 @@ class Foo {
return ((PsiJavaFile)myFixture.file).getClasses()[0];
}
});
- def foo = cls.methods[0]
- def goo = cls.methods[2]
+
+ PsiMethod[] methods = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod[]>() {
+ @Override
+ public PsiMethod[] compute() {
+ return cls.methods;
+ }
+ })
+ def foo = methods[0]
+ def goo = methods[2]
type('x')
assertContains 'x__foo', 'x__goo'
edt {
@@ -1292,7 +1299,7 @@ class Foo {{
type '.'
assert myFixture.lookupElementStrings == ['Util.bar', 'Util.CONSTANT', 'Util.foo']
- def p = LookupElementPresentation.renderElement(myFixture.lookupElements[1])
+ def p = ApplicationManager.application.runReadAction ({ LookupElementPresentation.renderElement(myFixture.lookupElements[1]) } as Computable)
assert p.itemText == 'Util.CONSTANT'
assert p.tailText == ' (foo)'
assert p.typeText == 'int'
@@ -1653,4 +1660,25 @@ class Foo {{
type 'toStr'
assert lookup
}
+
+ public void "test show popup with single live template if show_live_tempate_in_completion option is enabled"() {
+ def oldValue = LiveTemplateCompletionContributor.ourShowTemplatesInTests
+ try {
+ LiveTemplateCompletionContributor.ourShowTemplatesInTests = false
+ myFixture.configureByText "a.java", """
+class Foo {{
+ ita<caret>
+"""
+ type 'r'
+ assert lookup == null
+
+ LiveTemplateCompletionContributor.ourShowTemplatesInTests = true
+ type '\br'
+ assert lookup
+ assert myFixture.lookupElementStrings == ['itar']
+ }
+ finally {
+ LiveTemplateCompletionContributor.ourShowTemplatesInTests = oldValue
+ }
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java
index 6b9cff3f6149..59029a2fb05a 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java
@@ -106,7 +106,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testReturnInTernary() throws Exception { doTest(1, "return"); }
public void testFinalAfterParameterAnno() throws Exception { doTest(2, "final", "float", "class"); }
public void testFinalAfterParameterAnno2() throws Exception { doTest(2, "final", "float", "class"); }
- public void testFinalAfterCase() throws Exception { doTest(3, "final", "float", "class"); }
+ public void testFinalAfterCase() { doTest(3, "final", "float", "class"); }
+ public void testFinalInCatch() { doTest(1, "final"); }
+ public void testFinalInIncompleteCatch() { doTest(1, "final"); }
public void testFinalInTryWithResources() throws Exception { doTest(1, "final", "float", "class"); }
public void testNoFinalAfterTryBody() throws Exception { doTest(1, "final", "finally"); }
public void testClassInMethod() throws Exception { doTest(2, "class", "char"); }
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy
index 900555d21ab9..821e5f31fb91 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy
@@ -638,7 +638,7 @@ interface TxANotAnno {}
}
public void testPreferThrownExceptionsInCatch() {
- checkPreferredItems 0, 'FileNotFoundException', 'File'
+ checkPreferredItems 0, 'final', 'FileNotFoundException', 'File'
}
public void testHonorFirstLetterCase() {
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 5153f19fe94a..967de28820e8 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
@@ -777,6 +777,11 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
myFixture.assertPreferredCompletionItems(0, "i", "z", "zz", "i, z, zz");
}
+ public void testSuggestTypeParametersInTypeArgumentList() {
+ configureByTestName();
+ myFixture.assertPreferredCompletionItems(0, "T", "String");
+ }
+
public void testWrongAnonymous() throws Throwable {
configureByTestName();
select();
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java
index 688e83b5b198..09225b64bc1d 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java
@@ -372,6 +372,8 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA126633() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA124363() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA78402() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
+ public void testSuperCaptureSubstitutionWhenTypeParameterHasUpperBounds() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
+ public void testParameterBoundsWithCapturedWildcard() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
//jdk should propagate LL 1.4 but actually it provides LL 1.7?!
public void testCastObjectToIntJdk14() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_4, false); }
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java
index a6a75b7c061c..2427748b22d4 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.JavaTestUtil;
+import com.intellij.idea.Bombed;
import com.intellij.psi.*;
import com.intellij.psi.search.searches.FunctionalExpressionSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
@@ -24,6 +25,7 @@ import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
+import java.util.Calendar;
import java.util.Collection;
public class FindFunctionalInterfaceTest extends LightCodeInsightFixtureTestCase {
@@ -40,6 +42,7 @@ public class FindFunctionalInterfaceTest extends LightCodeInsightFixtureTestCase
assertEquals("() -> {}", next.getText());
}
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testFieldFromAnonymousClassScope() throws Exception {
myFixture.configureByFile(getTestName(false) + ".java");
final PsiElement elementAtCaret = myFixture.getElementAtCaret();
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java
index d23dfea6daf0..a66d999b283c 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java
@@ -688,7 +688,7 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testIDEA110869() {
doTest();
}
- /*public void testIDEA110947() { doTest5(false); }*/
+ public void testIDEA110947() { doTest(false); }
public void testIDEA112122() {
doTest();
}
@@ -759,6 +759,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
doTest();
}
+ public void testIDEA128333() throws Exception {
+ doTest();
+ }
+
public void testIDEA78402() { doTest(); }
private void doTest() {
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java
index c2ab020f09f3..7585d661b289 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java
@@ -47,16 +47,20 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
- @Bombed(day = 20, month = Calendar.AUGUST)
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testInferenceFromSiblings() throws Exception {
doTest();
}
- @Bombed(day = 20, month = Calendar.AUGUST)
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testChainedInferenceTypeParamsOrderIndependent() throws Exception {
doTest();
}
+ public void testCyclicParamsDependency() throws Exception {
+ doTest();
+ }
+
public void testInferenceForFirstArg() throws Exception {
doTest();
}
@@ -216,6 +220,21 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testIDEA127928() throws Exception {
doTest();
}
+ public void testIDEA128766() throws Exception {
+ doTest();
+ }
+
+ public void testSameMethodNestedChainedCallsNearFunctionInterfaces() throws Exception {
+ doTest();
+ }
+
+ public void testInfiniteTypes() throws Exception {
+ doTest();
+ }
+
+ public void testIDEA126163() throws Exception {
+ doTest();
+ }
private void doTest() throws Exception {
doTest(false);
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 1411249b3dcc..1da75f51ba6f 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
@@ -76,8 +76,9 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA122616() { doTest(); }
public void testIDEA122700() { doTest(); }
public void testIDEA122406() { doTest(); }
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testNestedCallsInsideLambdaReturnExpression() { doTest(); }
- @Bombed(day = 20, month = Calendar.AUGUST)
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testIDEA123731() { doTest(); }
public void testIDEA123869() { doTest(); }
public void testIDEA123848() { doTest(); }
@@ -98,7 +99,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
- @Bombed(day = 20, month = Calendar.AUGUST)
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testIDEA124983() 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 c48ef71d92d4..c981137d0253 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
@@ -288,7 +288,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
- @Bombed(day = 20, month = Calendar.AUGUST)
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
public void testIDEA127275_() throws Exception {
doTest();
}
@@ -305,6 +305,15 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
+ @Bombed(day = 30, month = Calendar.SEPTEMBER)
+ public void testAdditionalConstraints3Level() throws Exception {
+ doTest();
+ }
+
+ public void testWildcardParametrization() throws Exception {
+ doTest();
+ }
+
private void doTest() {
doTest(false);
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
index 89762efe5dd2..c3bb014d8342 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
@@ -27,7 +27,7 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase {
def c = inferContract("""
String smth(String s) {
if (s == null) return null;
- return s.substring(1);
+ return smth();
}
""")
assert c == 'null -> null'
@@ -310,6 +310,55 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase {
assert c == []
}
+ public void "test skip empty declarations"() {
+ def c = inferContracts("""
+ final Object foo(Object bar) {
+ Object o = 2;
+ if (bar == null) return null;
+ return new String("abc");
+ }
+ """)
+ assert c == ['null -> null', '!null -> !null']
+ }
+
+ public void "test go inside do-while"() {
+ def c = inferContracts("""
+ final Object foo(Object bar) {
+ do {
+ if (bar == null) return null;
+ bar = smth(bar);
+ } while (smthElse());
+ return new String("abc");
+ }
+ """)
+ assert c == ['null -> null']
+ }
+
+ public void "test go inside try"() {
+ def c = inferContracts("""
+ final Object foo(Object bar) {
+ try {
+ if (bar == null) return null;
+ bar = smth(bar);
+ } finally {}
+ return new String("abc");
+ }
+ """)
+ assert c == ['null -> null']
+ }
+
+ public void "test use invoked method notnull"() {
+ def c = inferContracts("""
+ final Object foo(Object bar) {
+ if (bar == null) return null;
+ return doo();
+ }
+
+ @org.jetbrains.annotations.NotNull Object doo() {}
+ """)
+ assert c == ['null -> null', '!null -> !null']
+ }
+
private String inferContract(String method) {
return assertOneElement(inferContracts(method))
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
index 33eb32eb0ec6..a10d02d31fca 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java
@@ -109,6 +109,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testAssigningClassLiteralToNullable() throws Throwable { doTest(); }
public void testSynchronizingOnNullable() throws Throwable { doTest(); }
+ public void testSwitchOnNullable() { doTest(); }
public void testReturningNullFromVoidMethod() throws Throwable { doTest(); }
public void testCatchRuntimeException() throws Throwable { doTest(); }
@@ -214,6 +215,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testNoConfusionWithAnonymousConstantInitializer() { doTest(); }
public void testForeachOverWildcards() { doTest(); }
public void testFinalGetter() { doTest(); }
+ public void testGetterResultsNotSame() { doTest(); }
public void testByteBufferGetter() {
myFixture.addClass("package java.nio; public class MappedByteBuffer { public int getInt() {} }");
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java
index bb6195a94aa7..938a86da7587 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java
@@ -25,6 +25,7 @@
package com.intellij.codeInspection;
import com.intellij.JavaTestUtil;
+import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.magicConstant.MagicConstantInspection;
import com.intellij.codeInspection.unusedLibraries.UnusedLibrariesInspection;
@@ -37,6 +38,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.InspectionTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.PsiTestUtil;
+import org.jetbrains.annotations.NotNull;
public class UnusedLibraryInspectionTest extends InspectionTestCase {
@Override
@@ -54,5 +56,11 @@ public class UnusedLibraryInspectionTest extends InspectionTestCase {
doTest("/" + getTestName(true), new UnusedLibrariesInspection());
}
+ @NotNull
+ @Override
+ protected AnalysisScope createAnalysisScope(VirtualFile sourceDir) {
+ return new AnalysisScope(getProject());
+ }
+
public void testSimple() throws Exception { doTest(); }
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java
index 516b140cc0b1..ab6d92263162 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIntegrationTest.java
@@ -38,7 +38,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
import com.intellij.util.AsynchConsumer;
import org.jetbrains.annotations.Contract;
-import java.io.IOException;
+import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
@@ -50,7 +50,7 @@ public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestC
private InferredAnnotationsManager myInferredAnnotationsManager;
private ExternalAnnotationsManager myExternalAnnotationsManager;
-
+ private MessageDigest myMessageDigest;
private List<String> diffs = new ArrayList<String>();
@Override
@@ -62,6 +62,7 @@ public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestC
myInferredAnnotationsManager = InferredAnnotationsManager.getInstance(myModule.getProject());
myExternalAnnotationsManager = ExternalAnnotationsManager.getInstance(myModule.getProject());
+ myMessageDigest = BytecodeAnalysisConverter.getMessageDigest();
}
private void setUpLibraries() {
@@ -127,13 +128,9 @@ public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestC
}
private void checkMethodAnnotations(PsiMethod method) {
- try {
- if (ProjectBytecodeAnalysis.getKey(method) == -1) {
- return;
- }
- }
- catch (IOException e) {
- fail();
+
+ if (ProjectBytecodeAnalysis.getKey(method, myMessageDigest) == null) {
+ return;
}
// not null-result
@@ -149,12 +146,27 @@ public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestC
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);
+
+ {
+ // @NotNull
+ String externalNotNull =
+ myExternalAnnotationsManager.findExternalAnnotation(parameter, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ String inferredNotNull =
+ myInferredAnnotationsManager.findInferredAnnotation(parameter, AnnotationUtil.NOT_NULL) == null ? "null" : "@NotNull";
+ if (!externalNotNull.equals(inferredNotNull)) {
+ diffs.add(parameterKey + ": " + externalNotNull + " != " + inferredNotNull);
+ }
+ }
+
+ {
+ // @Nullable
+ String externalNullable =
+ myExternalAnnotationsManager.findExternalAnnotation(parameter, AnnotationUtil.NULLABLE) == null ? "null" : "@Nullable";
+ String inferredNullable =
+ myInferredAnnotationsManager.findInferredAnnotation(parameter, AnnotationUtil.NULLABLE) == null ? "null" : "@Nullable";
+ if (!externalNullable.equals(inferredNullable)) {
+ diffs.add(parameterKey + ": " + externalNullable + " != " + inferredNullable);
+ }
}
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java
index 9d26fd804f68..2cbf3fbdfd6c 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java
@@ -17,6 +17,7 @@ package com.intellij.codeInspection.bytecodeAnalysis;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.InferredAnnotationsManager;
+import com.intellij.codeInspection.bytecodeAnalysis.asm.LeakingParameters;
import com.intellij.codeInspection.bytecodeAnalysis.data.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -37,6 +38,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
+import java.security.MessageDigest;
import java.util.HashMap;
/**
@@ -47,15 +49,15 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase {
private final String myClassesProjectRelativePath = "/classes/" + Test01.class.getPackage().getName().replace('.', '/');
private JavaPsiFacade myJavaPsiFacade;
private InferredAnnotationsManager myInferredAnnotationsManager;
- private BytecodeAnalysisConverter myBytecodeAnalysisConverter;
+ private MessageDigest myMessageDigest;
+
@Override
protected void setUp() throws Exception {
super.setUp();
myJavaPsiFacade = JavaPsiFacade.getInstance(myModule.getProject());
myInferredAnnotationsManager = InferredAnnotationsManager.getInstance(myModule.getProject());
- myBytecodeAnalysisConverter = BytecodeAnalysisConverter.getInstance();
-
+ myMessageDigest = MessageDigest.getInstance("MD5");
setUpDataClasses();
}
@@ -93,7 +95,7 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase {
public void visitEnd() {
super.visitEnd();
try {
- map.put(method, cfg.leakingParameters(classReader.getClassName(), node));
+ map.put(method, LeakingParameters.build(classReader.getClassName(), node, false).parameters);
}
catch (AnalyzerException ignore) {}
}
@@ -183,17 +185,21 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase {
private void checkCompoundId(Method method, PsiMethod psiMethod, boolean noKey) throws IOException {
Direction direction = new Out();
- long psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction);
+ System.out.println();
+ System.out.println(method.internalClassName);
+ System.out.println(method.methodName);
+ System.out.println(method.methodDesc);
+
+
+ HKey psiKey = BytecodeAnalysisConverter.psiKey(psiMethod, direction, myMessageDigest);
if (noKey) {
- assertTrue(-1 == psiKey);
+ assertTrue(null == psiKey);
return;
}
else {
- assertFalse(-1 == psiKey);
+ assertFalse(null == psiKey);
}
-
- long asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true));
-
+ HKey asmKey = BytecodeAnalysisConverter.asmKey(new Key(method, direction, true), myMessageDigest);
Assert.assertEquals(asmKey, psiKey);
}
diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
index e40e2c160822..cf876693e2f7 100644
--- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
+++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
@@ -343,6 +343,28 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
assertSize(2, findUsages(findModel));
}
+ public void testNonRecursiveDirectory() throws Exception {
+ VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTempDirectory());
+ addSourceContentToRoots(myModule, root);
+
+ VirtualFile foo = createChildDirectory(root, "foo");
+ VirtualFile bar = createChildDirectory(foo, "bar");
+ createFile(myModule, root, "A.txt", "goo doo");
+ createFile(myModule, foo, "A.txt", "goo doo");
+ createFile(myModule, bar, "A.txt", "doo goo");
+
+ FindModel findModel = FindManagerTestUtils.configureFindModel("done");
+ findModel.setProjectScope(false);
+ findModel.setDirectoryName(foo.getPath());
+ findModel.setStringToFind("doo");
+
+ findModel.setWithSubdirectories(true);
+ assertSize(2, findUsages(findModel));
+
+ findModel.setWithSubdirectories(false);
+ assertSize(1, findUsages(findModel));
+ }
+
public void testReplaceRegexp() {
FindModel findModel = new FindModel();
findModel.setStringToFind("bug_(?=here)");
diff --git a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy
index 9a97a825964a..9c378a1e50cf 100644
--- a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy
@@ -229,8 +229,14 @@ class Intf {
edt {
sdkRun = ourRun.containingClass.interfaces[0].methods[0]
}
- assert getPopupElements(new GotoSymbolModel2(project), 'run ', true) == [sdkRun]
- assert getPopupElements(new GotoSymbolModel2(project), 'run ', false) == [ourRun]
+
+ def withLibs = getPopupElements(new GotoSymbolModel2(project), 'run ', true)
+ assert withLibs[0] == sdkRun
+ assert !(ourRun in withLibs)
+
+ def noLibs = getPopupElements(new GotoSymbolModel2(project), 'run ', false)
+ assert noLibs[0] == ourRun
+ assert !(sdkRun in noLibs)
}
private List<Object> getPopupElements(ChooseByNameModel model, String text, boolean checkboxState = false) {
diff --git a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java
index b50e2d87c71f..69cc43416b5b 100644
--- a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java
+++ b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 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.
@@ -28,6 +28,7 @@ import com.intellij.openapi.project.impl.ProjectImpl;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.testFramework.LeakHunter;
@@ -61,6 +62,8 @@ public class LoadProjectTest extends PlatformTestCase {
assertNotNull(fileA);
fileA.navigate(true);
Editor editorA = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), a), true);
+ PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
+
assertNotNull(editorA);
CodeInsightTestFixtureImpl.instantiateAndRun(fileA, editorA, new int[0], false);
@@ -70,6 +73,8 @@ public class LoadProjectTest extends PlatformTestCase {
assertNotNull(fileB);
fileB.navigate(true);
Editor editorB = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), b), true);
+ PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
+
assertNotNull(editorB);
CodeInsightTestFixtureImpl.instantiateAndRun(fileB, editorB, new int[0], false);
diff --git a/java/java-tests/testSrc/com/intellij/psi/SCR17094Test.java b/java/java-tests/testSrc/com/intellij/psi/FindClassInDeepPackagesTest.java
index 501914bce501..5e5e010df2f7 100644
--- a/java/java-tests/testSrc/com/intellij/psi/SCR17094Test.java
+++ b/java/java-tests/testSrc/com/intellij/psi/FindClassInDeepPackagesTest.java
@@ -29,9 +29,13 @@ import java.io.File;
/**
* @author dsl
*/
-public class SCR17094Test extends PsiTestCase {
- protected void setUpClasses(final String s) throws Exception {
- final String testRoot = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/scr17094";
+public class FindClassInDeepPackagesTest extends PsiTestCase {
+ @Override
+ protected void setUpJdk() {
+ }
+
+ private void setUpLibrary(final String s) throws Exception {
+ final String testRoot = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/deepPackages";
VirtualFile classesRoot = WriteCommandAction.runWriteCommandAction(null, new Computable<VirtualFile>() {
@Override
public VirtualFile compute() {
@@ -44,20 +48,15 @@ public class SCR17094Test extends PsiTestCase {
ModuleRootModificationUtil.addModuleLibrary(myModule, classesRoot.getUrl());
}
- @Override
- protected void setUpJdk() {
-
- }
-
public void testSRC() throws Exception {
- setUpClasses("classes");
+ setUpLibrary("classes");
final JavaPsiFacade psiManager = getJavaFacade();
final PsiClass classA = psiManager.findClass("a.a.a.a.e.f.i", GlobalSearchScope.moduleWithLibrariesScope(myModule));
assertNotNull(classA);
}
public void test3() throws Exception {
- setUpClasses("classes2");
+ setUpLibrary("classes2");
final JavaPsiFacade psiManager = getJavaFacade();
final PsiClass classA = psiManager.findClass("com.intellij.internal.f.a.b.a.i", GlobalSearchScope.moduleWithLibrariesScope(myModule));
assertNotNull(classA);
diff --git a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java
index 61414ab0b416..2ed8233e99fe 100644
--- a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java
@@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.impl.source.tree.LazyParseableElement;
+import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
@@ -276,4 +277,24 @@ public class MiscPsiTest extends LightCodeInsightFixtureTestCase {
assertEquals("class A{}", psiClass.getText());
assertEquals(" class A{}", document.getText());
}
+
+ public void testASTBecomesInvalidOnExternalChange() {
+ final String text = "class A{}";
+ final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", text);
+ PsiElement leaf = file.findElementAt(5);
+
+ PlatformTestUtil.tryGcSoftlyReachableObjects();
+ assertNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file));
+
+ new WriteCommandAction.Simple(getProject()) {
+ @Override
+ protected void run() throws Throwable {
+ VfsUtil.saveText(file.getVirtualFile(), text + " ");
+ }
+ }.execute();
+
+ assertTrue(file.isValid());
+ assertFalse(leaf.isValid());
+ assertNotSame(leaf, file.findElementAt(5));
+ }
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR17650Test.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/ClassFileUnderSourceRootTest.java
index 187d0c2ad80e..5311bd15dfec 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR17650Test.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/ClassFileUnderSourceRootTest.java
@@ -3,7 +3,6 @@ package com.intellij.psi.impl.cache.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -17,20 +16,15 @@ import java.io.IOException;
/**
* @author max
*/
-public class SCR17650Test extends PsiTestCase {
+public class ClassFileUnderSourceRootTest extends PsiTestCase {
private static final String TEST_ROOT = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/cls";
-
private VirtualFile myDir;
@Override
protected void setUp() throws Exception {
super.setUp();
- final File root = FileUtil.createTempFile(getName(), "");
- root.delete();
- root.mkdir();
- myFilesToDelete.add(root);
-
+ final File root = createTempDirectory();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
@@ -55,11 +49,10 @@ public class SCR17650Test extends PsiTestCase {
private static VirtualFile getClassFile() {
VirtualFile vDir = LocalFileSystem.getInstance().findFileByPath(TEST_ROOT.replace(File.separatorChar, '/'));
- VirtualFile child = vDir.findChild("pack").findChild("MyClass.class");
- return child;
+ return vDir.findFileByRelativePath("pack/MyClass.class");
}
- public void test17650() throws Exception {
+ public void testFindClass() throws Exception {
assertEquals("p.A", myJavaFacade.findClass("p.A").getQualifiedName());
assertEquals("pack.MyClass", myJavaFacade.findClass("pack.MyClass").getQualifiedName());
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR14423Test.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java
index 2870108623b1..e88027409dc0 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR14423Test.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/FindClassTest.java
@@ -18,11 +18,11 @@ package com.intellij.psi.impl.cache.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -37,7 +37,7 @@ import java.io.IOException;
/**
* @author max
*/
-public class SCR14423Test extends PsiTestCase {
+public class FindClassTest extends PsiTestCase {
private VirtualFile myPrjDir1;
private VirtualFile mySrcDir1;
private VirtualFile myPackDir;
@@ -46,11 +46,7 @@ public class SCR14423Test extends PsiTestCase {
protected void setUp() throws Exception {
super.setUp();
- final File root = FileUtil.createTempFile(getName(), "");
- root.delete();
- root.mkdir();
- myFilesToDelete.add(root);
-
+ final File root = createTempDirectory();
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
@@ -75,14 +71,12 @@ public class SCR14423Test extends PsiTestCase {
});
}
- public void testBug2() throws Exception {
+ public void testSimple() throws Exception {
PsiClass psiClass = myJavaFacade.findClass("p.A");
assertEquals("p.A", psiClass.getQualifiedName());
-
- testBug1();
}
- public void testBug1() {
+ public void testClassUnderExcludedFolder() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
PsiTestUtil.addExcludedRoot(myModule, myPackDir);
@@ -101,7 +95,7 @@ public class SCR14423Test extends PsiTestCase {
});
}
- public void testBug3() {
+ public void testClassUnderIgnoredFolder() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
PsiClass psiClass = myJavaFacade.findClass("p.A", GlobalSearchScope.allScope(myProject));
@@ -109,14 +103,15 @@ public class SCR14423Test extends PsiTestCase {
assertTrue(psiClass.isValid());
- PsiTestUtil.addExcludedRoot(myModule, myPackDir);
-
- assertFalse(psiClass.isValid());
-
- ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
- final ContentEntry content = rootModel.getContentEntries()[0];
- content.removeExcludeFolder(content.getExcludeFolders()[0]);
- rootModel.commit();
+ FileTypeManager fileTypeManager = FileTypeManager.getInstance();
+ String ignoredFilesList = fileTypeManager.getIgnoredFilesList();
+ fileTypeManager.setIgnoredFilesList(ignoredFilesList + ";p");
+ try {
+ assertFalse(psiClass.isValid());
+ }
+ finally {
+ fileTypeManager.setIgnoredFilesList(ignoredFilesList);
+ }
psiClass = myJavaFacade.findClass("p.A");
assertTrue(psiClass.isValid());
@@ -124,7 +119,7 @@ public class SCR14423Test extends PsiTestCase {
});
}
- public void testSyncrhonizationAfterChange() {
+ public void testSynchronizationAfterChange() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR20733Test.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java
index 5fef7daea7d9..1a5d5faeca7c 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR20733Test.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SameSourceRootInTwoModulesTest.java
@@ -3,7 +3,6 @@ package com.intellij.psi.impl.cache.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -18,7 +17,7 @@ import java.io.IOException;
/**
* @author max
*/
-public class SCR20733Test extends PsiTestCase {
+public class SameSourceRootInTwoModulesTest extends PsiTestCase {
private VirtualFile myPrjDir1;
private VirtualFile mySrcDir1;
private VirtualFile myPackDir;
@@ -27,11 +26,7 @@ public class SCR20733Test extends PsiTestCase {
protected void setUp() throws Exception {
super.setUp();
- final File root = FileUtil.createTempFile(getName(), "");
- root.delete();
- root.mkdir();
- myFilesToDelete.add(root);
-
+ final File root = createTempDirectory();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR19174Test.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java
index c47bbf7184e8..36baf5de0d76 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SCR19174Test.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/SourceRootAddedAsLibraryRootTest.java
@@ -2,7 +2,6 @@ package com.intellij.psi.impl.cache.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -16,7 +15,7 @@ import java.io.IOException;
/**
* @author max
*/
-public class SCR19174Test extends PsiTestCase {
+public class SourceRootAddedAsLibraryRootTest extends PsiTestCase {
private VirtualFile myDir;
private VirtualFile myVFile;
@@ -24,11 +23,7 @@ public class SCR19174Test extends PsiTestCase {
protected void setUp() throws Exception {
super.setUp();
- final File root = FileUtil.createTempFile(getName(), "");
- root.delete();
- root.mkdir();
- myFilesToDelete.add(root);
-
+ final File root = createTempDirectory();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
@@ -37,12 +32,6 @@ public class SCR19174Test extends PsiTestCase {
myDir = rootVFile.createChildDirectory(null, "contentAndLibrary");
- /*
- myVFile = myDir.createChildData(null, "A.java");
- Writer writer1 = myVFile.getWriter(null);
- writer1.write("package p; public class A{ public void foo(); }");
- writer1.close();
- */
PsiTestUtil.addSourceRoot(myModule, myDir);
}
catch (IOException e) {
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java
index 2461a4601eba..a933d5bcacf6 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java
@@ -43,13 +43,11 @@ public class PsiEventsTest extends PsiTestCase {
private VirtualFile myPrjDir1;
private VirtualFile myPrjDir2;
- private VirtualFile myPrjDir3;
private VirtualFile mySrcDir1;
private VirtualFile mySrcDir2;
private VirtualFile mySrcDir3;
- private VirtualFile mySrcDir4;
private VirtualFile myClsDir1;
- private VirtualFile myExcludedDir1;
+ private VirtualFile myIgnoredDir;
@Override
protected void setUp() throws Exception {
@@ -76,13 +74,12 @@ public class PsiEventsTest extends PsiTestCase {
myClsDir1 = myPrjDir1.createChildDirectory(null, "cls1");
- myExcludedDir1 = mySrcDir1.createChildDirectory(null, "excluded");
+ myIgnoredDir = mySrcDir1.createChildDirectory(null, "CVS");
PsiTestUtil.addContentRoot(myModule, myPrjDir1);
PsiTestUtil.addSourceRoot(myModule, mySrcDir1);
PsiTestUtil.addSourceRoot(myModule, mySrcDir2);
PsiTestUtil.addContentRoot(myModule, myPrjDir2);
- PsiTestUtil.addExcludedRoot(myModule, myExcludedDir1);
ModuleRootModificationUtil.addModuleLibrary(myModule, myClsDir1.getUrl());
PsiTestUtil.addSourceRoot(myModule, mySrcDir3);
} catch (IOException e) {
@@ -106,7 +103,7 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildAddition\n" +
"childAdded\n";
- assertEquals(expected, string);
+ assertEquals(psiDir.getName(), expected, string);
}
public void testCreateDirectory() throws Exception {
@@ -121,7 +118,7 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildAddition\n" +
"childAdded\n";
- assertEquals(expected, string);
+ assertEquals(psiDir.getName(), expected, string);
}
public void testDeleteFile() throws Exception {
@@ -139,7 +136,7 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
}
public void testDeleteDirectory() throws Exception {
@@ -157,10 +154,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
}
- public void testRenameFile1() throws Exception {
+ public void testRenameFile() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "a.txt");
PsiFile psiFile = fileManager.findFile(file);
@@ -174,10 +171,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforePropertyChange\n" +
"propertyChanged\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
}
- public void testRenameFile2() throws Exception {
+ public void testRenameFileChangingExtension() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "a.txt");
PsiFile psiFile = fileManager.findFile(file);
@@ -191,10 +188,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildReplacement\n" +
"childReplaced\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
}
- public void testRenameFile3() throws Exception {
+ public void testRenameFileToIgnored() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "a.txt");
PsiFile psiFile = fileManager.findFile(file);
@@ -208,11 +205,11 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
assertNull(fileManager.findFile(file));
}
- public void testRenameFile4() throws Exception {
+ public void testRenameFileFromIgnored() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "CVS");
PsiDirectory psiDirectory = fileManager.findDirectory(file.getParent());
@@ -226,10 +223,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildAddition\n" +
"childAdded\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
}
- public void testRenameDirectory1() throws Exception {
+ public void testRenameDirectory() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildDirectory(null, "dir1");
PsiDirectory psiDirectory = fileManager.findDirectory(file);
@@ -243,10 +240,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforePropertyChange\n" +
"propertyChanged\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
}
- public void testRenameDirectory2() throws Exception {
+ public void testRenameDirectoryToIgnored() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildDirectory(null, "dir1");
PsiDirectory psiDirectory = fileManager.findDirectory(file);
@@ -260,11 +257,11 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
assertNull(fileManager.findDirectory(file));
}
- public void testRenameDirectory3() throws Exception {
+ public void testRenameDirectoryFromIgnored() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildDirectory(null, "CVS");
PsiDirectory psiDirectory = fileManager.findDirectory(file.getParent());
@@ -278,7 +275,7 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildAddition\n" +
"childAdded\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
}
public void testMakeFileReadOnly() throws Exception {
@@ -291,7 +288,6 @@ public class PsiEventsTest extends PsiTestCase {
ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true);
- String string = listener.getEventsString();
final String expected =
"beforePropertyChange\n" +
"propertyChanged\n";
@@ -306,7 +302,7 @@ public class PsiEventsTest extends PsiTestCase {
ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false);
}
- public void testMoveFile1() throws Exception {
+ public void testMoveFile() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "a.txt");
PsiFile psiFile = fileManager.findFile(file);
@@ -320,10 +316,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildMovement\n" +
"childMoved\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
}
- public void testMoveFile2() throws Exception {
+ public void testMoveFileToIgnoredDir() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildData(null, "a.txt");
PsiFile psiFile = fileManager.findFile(file);
@@ -331,19 +327,18 @@ public class PsiEventsTest extends PsiTestCase {
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
- file.move(null, myExcludedDir1);
+ file.move(null, myIgnoredDir);
String string = listener.getEventsString();
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiFile.getName(), expected, string);
assertNull(fileManager.findFile(file));
}
- public void testMoveFile3() throws Exception {
- FileManager fileManager = myPsiManager.getFileManager();
- VirtualFile file = myExcludedDir1.createChildData(null, "a.txt");
+ public void testMoveFileFromIgnoredDir() throws Exception {
+ VirtualFile file = myIgnoredDir.createChildData(null, "a.txt");
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
@@ -357,10 +352,9 @@ public class PsiEventsTest extends PsiTestCase {
assertEquals(expected, string);
}
- public void testMoveFile4() throws Exception {
- FileManager fileManager = myPsiManager.getFileManager();
- VirtualFile file = myExcludedDir1.createChildData(null, "a.txt");
- VirtualFile subdir = myExcludedDir1.createChildDirectory(null, "subdir");
+ public void testMoveFileInsideIgnoredDir() throws Exception {
+ VirtualFile file = myIgnoredDir.createChildData(null, "a.txt");
+ VirtualFile subdir = myIgnoredDir.createChildDirectory(null, "subdir");
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
@@ -372,7 +366,7 @@ public class PsiEventsTest extends PsiTestCase {
assertEquals(expected, string);
}
- public void testMoveDirectory1() throws Exception {
+ public void testMoveDirectory() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildDirectory(null, "dir");
PsiDirectory psiDirectory = fileManager.findDirectory(file);
@@ -386,10 +380,10 @@ public class PsiEventsTest extends PsiTestCase {
String expected =
"beforeChildMovement\n" +
"childMoved\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
}
- public void testMoveDirectory2() throws Exception {
+ public void testMoveDirectoryToIgnored() throws Exception {
FileManager fileManager = myPsiManager.getFileManager();
VirtualFile file = myPrjDir1.createChildDirectory(null, "dir");
PsiDirectory psiDirectory = fileManager.findDirectory(file);
@@ -397,19 +391,18 @@ public class PsiEventsTest extends PsiTestCase {
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
- file.move(null, myExcludedDir1);
+ file.move(null, myIgnoredDir);
String string = listener.getEventsString();
String expected =
"beforeChildRemoval\n" +
"childRemoved\n";
- assertEquals(expected, string);
+ assertEquals(psiDirectory.getName(), expected, string);
assertNull(fileManager.findDirectory(file));
}
- public void testMoveDirectory3() throws Exception {
- FileManager fileManager = myPsiManager.getFileManager();
- VirtualFile file = myExcludedDir1.createChildDirectory(null, "dir");
+ public void testMoveDirectoryFromIgnored() throws Exception {
+ VirtualFile file = myIgnoredDir.createChildDirectory(null, "dir");
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
@@ -423,10 +416,9 @@ public class PsiEventsTest extends PsiTestCase {
assertEquals(expected, string);
}
- public void testMoveDirectory4() throws Exception {
- FileManager fileManager = myPsiManager.getFileManager();
- VirtualFile file = myExcludedDir1.createChildDirectory(null, "dir");
- VirtualFile subdir = myExcludedDir1.createChildDirectory(null, "subdir");
+ public void testMoveDirectoryInsideIgnored() throws Exception {
+ VirtualFile file = myIgnoredDir.createChildDirectory(null, "dir");
+ VirtualFile subdir = myIgnoredDir.createChildDirectory(null, "subdir");
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
@@ -497,7 +489,6 @@ public class PsiEventsTest extends PsiTestCase {
}
public void testModifyFileTypes() throws Exception {
- FileManager fileManager = myPsiManager.getFileManager();
EventsTestListener listener = new EventsTestListener();
myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable());
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/TempFileSystemTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/TempFileSystemTest.java
new file mode 100644
index 000000000000..dbdd61bc340b
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/TempFileSystemTest.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.psi.impl.file.impl;
+
+import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDirectory;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiManager;
+import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
+
+import java.io.IOException;
+
+public class TempFileSystemTest extends LightPlatformCodeInsightFixtureTestCase {
+ public void testMove() {
+ ProjectRootManager rootManager = ProjectRootManager.getInstance(getProject());
+ VirtualFile sourceRoot = rootManager.getContentSourceRoots()[0];
+ PsiManager psiManager = PsiManager.getInstance(getProject());
+ PsiDirectory psiSourceRoot = psiManager.findDirectory(sourceRoot);
+ PsiFile psiFile = psiSourceRoot.createFile("TestDocument.xml");
+ try {
+ psiFile.getVirtualFile().move(this, psiSourceRoot.createSubdirectory("com").getVirtualFile());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ assertTrue(psiFile.isValid());
+ psiFile.delete();
+ assertFalse(psiFile.isValid());
+ }
+} \ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java
index 9d46f072f338..ded654d4a8d3 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java
@@ -42,6 +42,9 @@ public class InlineMethodMultifileTest extends RefactoringTestCase {
public void testRemoveStaticImports() throws Exception {
doTest("Foo", "foo");
}
+ public void testPreserveStaticImportsIfOverloaded() throws Exception {
+ doTest("Foo", "foo");
+ }
private void doTest(String className, String methodName) throws Exception {
String rootBefore = getRoot() + "/before";
diff --git a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java
index e78308b4ae92..1ee498cd5d2c 100644
--- a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java
+++ b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java
@@ -1,16 +1,24 @@
package com.intellij.roots.libraries;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.RootProvider;
+import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.WriteAction;
+import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
+import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.roots.ModuleRootManagerTestCase;
+import com.intellij.testFramework.PlatformTestUtil;
+import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.util.CommonProcessors;
import org.jdom.Element;
-import org.jdom.output.XMLOutputter;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collection;
+import java.util.Collections;
/**
* @author dsl
@@ -40,11 +48,6 @@ public class LibraryTest extends ModuleRootManagerTestCase {
commit(model2);
assertFalse(listenerNotifiedOnChange[0]);
- final Element element = new Element("root");
- library.writeExternal(element);
- assertEquals("<root><library name=\"library\"><CLASSES><root url=\"file://x.jar\" /></CLASSES><JAVADOC /><SOURCES><root url=\"file://x-src.jar\" /></SOURCES></library></root>",
- new XMLOutputter().outputString(element));
-
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
@@ -53,6 +56,106 @@ public class LibraryTest extends ModuleRootManagerTestCase {
});
}
+ public void testLibrarySerialization() {
+ Library library = PsiTestUtil.addProjectLibrary(myModule, "junit", Collections.singletonList(getJDomJar()),
+ Collections.singletonList(getJDomSources()));
+ Element element = serialize(library);
+ String classesUrl = getJDomJar().getUrl();
+ String sourcesUrl = getJDomSources().getUrl();
+ PlatformTestUtil.assertElementEquals(
+ "<root><library name=\"junit\"><CLASSES><root url=\"" + classesUrl + "\" /></CLASSES>" +
+ "<JAVADOC /><SOURCES><root url=\"" + sourcesUrl + "\" /></SOURCES></library></root>",
+ element);
+ }
+
+ public void testResolveDependencyToAddedLibrary() {
+ final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
+ model.addInvalidLibrary("jdom", LibraryTablesRegistrar.PROJECT_LEVEL);
+ commit(model);
+ assertEmpty(getLibraries());
+
+ Library library = createLibrary("jdom", getJDomJar(), null);
+ assertSameElements(getLibraries(), library);
+ }
+
+ public void testResolveDependencyToRenamedLibrary() {
+ Library library = createLibrary("jdom2", getJDomJar(), null);
+
+ final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
+ model.addInvalidLibrary("jdom", LibraryTablesRegistrar.PROJECT_LEVEL);
+ commit(model);
+ assertEmpty(getLibraries());
+
+ Library.ModifiableModel libModel = library.getModifiableModel();
+ libModel.setName("jdom");
+ commit(libModel);
+ assertSameElements(getLibraries(), library);
+ }
+
+ private Collection<Library> getLibraries() {
+ CommonProcessors.CollectProcessor<Library> processor = new CommonProcessors.CollectProcessor<Library>();
+ ModuleRootManager.getInstance(myModule).orderEntries().forEachLibrary(processor);
+ return processor.getResults();
+ }
+
+ private static void commit(final ModifiableRootModel model) {
+ new WriteAction() {
+ protected void run(@NotNull final Result result) {
+ model.commit();
+ }
+ }.execute();
+ }
+
+ public void testNativePathSerialization() {
+ LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
+ Library library = table.createLibrary("native");
+ Library.ModifiableModel model = library.getModifiableModel();
+ model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
+ commit(model);
+
+ Element element = serialize(library);
+ PlatformTestUtil.assertElementEquals(
+ "<root><library name=\"native\"><CLASSES /><JAVADOC />" +
+ "<NATIVE><root url=\"file://native-lib-root\" /></NATIVE>" +
+ "<SOURCES /></library></root>",
+ element);
+ }
+
+ public void testJarDirectoriesSerialization() {
+ LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
+ Library library = table.createLibrary("jarDirs");
+ Library.ModifiableModel model = library.getModifiableModel();
+ model.addJarDirectory("file://jar-dir", false, OrderRootType.CLASSES);
+ model.addJarDirectory("file://jar-dir-src", false, OrderRootType.SOURCES);
+ commit(model);
+
+ Element element = serialize(library);
+ PlatformTestUtil.assertElementEquals("<root>\n" +
+ " <library name=\"jarDirs\">\n" +
+ " <CLASSES>\n" +
+ " <root url=\"file://jar-dir\" />\n" +
+ " </CLASSES>\n" +
+ " <JAVADOC />\n" +
+ " <SOURCES>\n" +
+ " <root url=\"file://jar-dir-src\" />\n" +
+ " </SOURCES>\n" +
+ " <jarDirectory url=\"file://jar-dir\" recursive=\"false\" />\n" +
+ " <jarDirectory url=\"file://jar-dir-src\" recursive=\"false\" type=\"SOURCES\" />\n" +
+ " </library>\n" +
+ "</root>" , element);
+ }
+
+ private static Element serialize(Library library) {
+ try {
+ Element element = new Element("root");
+ library.writeExternal(element);
+ return element;
+ }
+ catch (WriteExternalException e) {
+ throw new AssertionError(e);
+ }
+ }
+
public void testAddRemoveExcludedRoot() {
VirtualFile jar = getJDomJar();
LibraryEx library = (LibraryEx)createLibrary("junit", jar, null);