diff options
Diffstat (limited to 'java/java-tests')
58 files changed, 903 insertions, 163 deletions
diff --git a/java/java-tests/testData/codeInsight/clsHighlighting/IDEA127714.java b/java/java-tests/testData/codeInsight/clsHighlighting/IDEA127714.java new file mode 100644 index 000000000000..08713f898f15 --- /dev/null +++ b/java/java-tests/testData/codeInsight/clsHighlighting/IDEA127714.java @@ -0,0 +1,9 @@ +import a.A; + +class IDEA127714 { + { + A<E, String> strings = new A<>(E.class); + } +} + +enum E {}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/clsHighlighting/libs/IDEA127714.jar b/java/java-tests/testData/codeInsight/clsHighlighting/libs/IDEA127714.jar Binary files differnew file mode 100644 index 000000000000..915d3a074810 --- /dev/null +++ b/java/java-tests/testData/codeInsight/clsHighlighting/libs/IDEA127714.jar diff --git a/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch.java b/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch.java new file mode 100644 index 000000000000..d8ea6191cef8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch.java @@ -0,0 +1,12 @@ + +class Foo { + { + try + { + + } catch (Ex<caret>ception e) + { + + } + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch_after.java b/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch_after.java new file mode 100644 index 000000000000..f4874b45962e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/AlreadyCompleteCatch_after.java @@ -0,0 +1,12 @@ + +class Foo { + { + try + { + + } catch (Exception e) + { + <caret> + } + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/MulticaretCompletionFromNonPrimaryCaret.java b/java/java-tests/testData/codeInsight/completion/normal/MulticaretCompletionFromNonPrimaryCaret.java new file mode 100644 index 000000000000..077ff80bd5c7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/MulticaretCompletionFromNonPrimaryCaret.java @@ -0,0 +1,4 @@ +class Foo {{ + System.<caret> + System.<caret> +}} diff --git a/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics-out.java b/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics-out.java new file mode 100644 index 000000000000..41f3d57525a2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics-out.java @@ -0,0 +1,16 @@ +class Main { + void foo(List<? extends Number> list) { + list.forEach(new Consumer<Number>() { + @Override + public void consume(Number number) { + <caret> + } + }); + } +} + +class List<T> { + void forEach(Consumer<? super T> consumer); +} + +interface Consumer<T> { void consume(T t); }
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics.java b/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics.java new file mode 100644 index 000000000000..b1d18904a6fb --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/DontSuggestWildcardGenerics.java @@ -0,0 +1,11 @@ +class Main { + void foo(List<? extends Number> list) { + list.forEach(new <caret>); + } +} + +class List<T> { + void forEach(Consumer<? super T> consumer); +} + +interface Consumer<T> { void consume(T t); }
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferFieldsToConstants.java b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferFieldsToConstants.java new file mode 100644 index 000000000000..2b47bb58a498 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferFieldsToConstants.java @@ -0,0 +1,17 @@ +public class Foo { + + private LocalDate dateField; + + void foo(LocalDate date) { + + } + + void bar() { + foo(<caret>) + } +} + +class LocalDate { + public static final LocalDate MAX; + public static final LocalDate MIN; +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PolymorphicTypeCast.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PolymorphicTypeCast.java index 8be16fc1db85..8ba3ea4f8037 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PolymorphicTypeCast.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PolymorphicTypeCast.java @@ -94,4 +94,96 @@ class C { void asLongs(Integer i) { long l = (long) i; } + + void foo(Object o) {} + public void cast2(Byte operand) { + foo((<warning descr="Casting 'operand' to 'byte' is redundant">byte</warning>)operand); + foo((short)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Byte' to 'char'">(char)operand</error>); + foo((int)operand); + foo((long)operand); + foo((float)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Byte' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Short operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'byte'">(byte)operand</error>); + foo((<warning descr="Casting 'operand' to 'short' is redundant">short</warning>)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'char'">(char)operand</error>); + foo((int)operand); + foo((long)operand); + foo((float)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Character operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'short'">(short)operand</error>); + foo((<warning descr="Casting 'operand' to 'char' is redundant">char</warning>)operand); + foo((int)operand); + foo((long)operand); + foo((float)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Integer operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'short'">(short)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'char'">(char)operand</error>); + foo((<warning descr="Casting 'operand' to 'int' is redundant">int</warning>)operand); + foo((long)operand); + foo((float)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Long operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'short'">(short)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'char'">(char)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">(int)operand</error>); + foo((<warning descr="Casting 'operand' to 'long' is redundant">long</warning>)operand); + foo((float)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Float operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'short'">(short)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'char'">(char)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'int'">(int)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'long'">(long)operand</error>); + foo((<warning descr="Casting 'operand' to 'float' is redundant">float</warning>)operand); + foo((double)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Double operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'short'">(short)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'char'">(char)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'int'">(int)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'long'">(long)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'float'">(float)operand</error>); + foo((<warning descr="Casting 'operand' to 'double' is redundant">double</warning>)operand); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'boolean'">(boolean)operand</error>); + } + public void cast2(Boolean operand) { + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'byte'">(byte)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'short'">(short)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'char'">(char)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'int'">(int)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'long'">(long)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'float'">(float)operand</error>); + foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'double'">(double)operand</error>); + foo((<warning descr="Casting 'operand' to 'boolean' is redundant">boolean</warning>)operand); + } + public void cast2(Object operand) { + foo((<warning descr="Casting 'operand' to 'byte' is redundant">byte</warning>)operand); + foo((<warning descr="Casting 'operand' to 'short' is redundant">short</warning>)operand); + foo((<warning descr="Casting 'operand' to 'char' is redundant">char</warning>)operand); + foo((<warning descr="Casting 'operand' to 'int' is redundant">int</warning>)operand); + foo((<warning descr="Casting 'operand' to 'long' is redundant">long</warning>)operand); + foo((<warning descr="Casting 'operand' to 'float' is redundant">float</warning>)operand); + foo((<warning descr="Casting 'operand' to 'double' is redundant">double</warning>)operand); + foo((<warning descr="Casting 'operand' to 'boolean' is redundant">boolean</warning>)operand); + } }
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128101.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128101.java new file mode 100644 index 000000000000..42be49b62f04 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128101.java @@ -0,0 +1,29 @@ +class TestIDEA128101 { + + static class Attribute<Y> {}; + static class Path<X> {}; + + static Attribute<Integer> integerAttribute; + static Attribute<String> stringAttribute; + + static <Y> Path<Y> createPath(Attribute<Y> attribute) { + return new Path<>(); + } + static <Y> Path<Y> createPath1(Attribute<Y> attribute) { + return new Path<>(); + } + static <T> void construct(Class<T> aClass, Path<?>... paths) {} + static <T, K> void construct1(Class<T> aClass, Path<K>... paths) {} + static <T, K> void construct2(Class<T> aClass, Path<? extends K>... paths) {} + static <T, K> void construct3(Class<T> aClass, Path<? super K>... paths) {} + static <T, K> void construct4(Class<T> aClass, Path<? super K> path1, Path<? super K> path2) {} + + public static void test() { + construct(String.class, createPath(integerAttribute), createPath(stringAttribute)); + construct1<error descr="Cannot resolve method 'construct1(java.lang.Class<java.lang.String>, TestIDEA128101.Path<java.lang.Integer>, TestIDEA128101.Path<java.lang.String>)'">(String.class, createPath(integerAttribute), createPath(stringAttribute))</error>; + construct2(String.class, createPath(integerAttribute), createPath(stringAttribute)); + <error descr="Type parameter K has incompatible upper bounds: Integer and String">construct3(String.class, createPath(integerAttribute), createPath(stringAttribute));</error> + <error descr="Type parameter K has incompatible upper bounds: Integer and String">construct4(String.class, createPath(integerAttribute), createPath(stringAttribute));</error> + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128174.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128174.java new file mode 100644 index 000000000000..650114b06e50 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IDEA128174.java @@ -0,0 +1,24 @@ +import java.util.Collection; +import java.util.List; + +class Test { + + { + Matcher<? super List<String>> m = not(empty()); + } + + static <E> Matcher<Collection<E>> empty() { + return null; + } + + static <T> Matcher<T> not(Matcher<T> matcher) { + return null; + } + + static <T> Matcher<T> not(T value) { + return null; + } + + static class Matcher<K> {} +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/InferFromConditionalExpressionCondition.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/InferFromConditionalExpressionCondition.java new file mode 100644 index 000000000000..8fad96c118ed --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/InferFromConditionalExpressionCondition.java @@ -0,0 +1,14 @@ +class Test { + static class TKey<T> { + } + + public interface Getter { + <T> T getValue(TKey<T> key); + } + + static final TKey<Boolean> KEY_B = new TKey<>(); + + public static void f(Getter getter) { + String name = getter.getValue(KEY_B) ? "foo" : "bar"; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveWrapperConditionInReturnConstraint.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveWrapperConditionInReturnConstraint.java new file mode 100644 index 000000000000..6788a98b215c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveWrapperConditionInReturnConstraint.java @@ -0,0 +1,15 @@ +class Test { + static class TKey<T> { + } + + public interface Getter { + <T> T getValue(TKey<T> key); + } + + static final TKey<Integer> KEY_I = null; + + + public static void f(Getter getter, TKey<Integer> key) { + double d1 = getter.getValue (key); + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java index 254ec7191a47..92b268394994 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java @@ -39,7 +39,7 @@ public class XXX { void m3(int x, boolean cond) { int y; if (cond) y = 1; - foo(() -> x+<error descr="Variable used in lambda expression should be effectively final">y</error>); + foo(() -> x+<error descr="Variable 'y' might not have been initialized">y</error>); } void m4(int x, boolean cond) { @@ -128,3 +128,17 @@ class IDEA114737 { }; } } + +class IDEA128196 { + void a() { + int value; + + try { + value = 1; + } catch (Exception e) { + return; + } + + new Thread(() -> System.out.println(value)); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/IDEA127765.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/IDEA127765.java new file mode 100644 index 000000000000..095448e262b3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/IDEA127765.java @@ -0,0 +1,19 @@ +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; + +class IDEA127765 { + void a(final Map<String, Optional<Double>> allValues, final Function<Optional<Double>, Double> get) { + final Map<String, Double> presentValues = transformValues(filterValues(allValues, Optional::isPresent), get); + } + + public static <K, V1, V2> Map<K, V2> transformValues(Map<K, V1> fromMap, Function<? super V1, V2> function) { + return null; + } + + public static <K, V> Map<K, V> filterValues(Map<K, V> unfiltered, Predicate<? super V> valuePredicate) { + return null; + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterOnVarargsPlace.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterOnVarargsPlace.java new file mode 100644 index 000000000000..82e3cc9aa3e6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterOnVarargsPlace.java @@ -0,0 +1,10 @@ +// "Replace with lambda" "true" +class Test2 { + + void f(Runnable... rs){} + { + f(null, () -> { + + }); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeOnVarargsPlace.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeOnVarargsPlace.java new file mode 100644 index 000000000000..af9db7767997 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeOnVarargsPlace.java @@ -0,0 +1,13 @@ +// "Replace with lambda" "true" +class Test2 { + + void f(Runnable... rs){} + { + f(null, new Run<caret>nable() { + @Override + public void run() { + + } + }); + } +} diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored.java b/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored.java new file mode 100644 index 000000000000..1af8cd0813a9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored.java @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + !.null<caret> + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored_after.java new file mode 100644 index 000000000000..1334be6b7029 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/null/singleExclamationIgnored_after.java @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + !.null <caret> + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_after.java b/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_after.java new file mode 100644 index 000000000000..08b2afd09cb9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_after.java @@ -0,0 +1,7 @@ +class Foo { + public static void main(String[] args) { + String s = ""; + s.replaceAll("\\<caret>"); + System.out.println(); + } +} diff --git a/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_before.java b/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_before.java new file mode 100644 index 000000000000..bee6f10053c2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/typing/invalidInitialSyntax_before.java @@ -0,0 +1,7 @@ +class Foo { + public static void main(String[] args) { + String s = ""; + s.replaceAll("<caret>"); + System.out.println(); + } +} diff --git a/java/java-tests/testData/find/findInEditor/BasicFind.gold b/java/java-tests/testData/find/findInEditor/BasicFind.gold index 14e4182499b7..46486765486d 100644 --- a/java/java-tests/testData/find/findInEditor/BasicFind.gold +++ b/java/java-tests/testData/find/findInEditor/BasicFind.gold @@ -3,8 +3,7 @@ myStringToFind =a myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -22,6 +21,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- diff --git a/java/java-tests/testData/find/findInEditor/EmacsLikeFallback.gold b/java/java-tests/testData/find/findInEditor/EmacsLikeFallback.gold index a2168ba66e2a..bfda616a3ac1 100644 --- a/java/java-tests/testData/find/findInEditor/EmacsLikeFallback.gold +++ b/java/java-tests/testData/find/findInEditor/EmacsLikeFallback.gold @@ -3,8 +3,7 @@ myStringToFind =a myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -22,6 +21,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- @@ -37,8 +37,7 @@ myStringToFind =ab myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -56,6 +55,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- @@ -70,8 +70,7 @@ myStringToFind =a myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -89,6 +88,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- diff --git a/java/java-tests/testData/find/findInEditor/ReplacementWithEmptyString.gold b/java/java-tests/testData/find/findInEditor/ReplacementWithEmptyString.gold index 478eb649684d..a4d44cbfa445 100644 --- a/java/java-tests/testData/find/findInEditor/ReplacementWithEmptyString.gold +++ b/java/java-tests/testData/find/findInEditor/ReplacementWithEmptyString.gold @@ -3,8 +3,7 @@ myStringToFind = myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -22,6 +21,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- @@ -33,8 +33,7 @@ myStringToFind =a myStringToReplace = isReplaceState =false isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -52,6 +51,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- @@ -65,8 +65,7 @@ myStringToFind =a myStringToReplace = isReplaceState =true isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -84,6 +83,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- Replacement Preview: <Empty string> @@ -99,8 +99,7 @@ myStringToFind =a myStringToReplace = isReplaceState =true isWholeWordsOnly =false -isInStringLiterals =false -isInComments =false +searchContext =ANY isFromCursor =true isForward =true isGlobal =true @@ -118,6 +117,7 @@ isWithSubdirectories =true fileFilter =null moduleName =null customScopeName =null +searchInProjectFiles =false -- diff --git a/java/java-tests/testData/inspection/dataFlow/CheckedExceptionDominance/src/Test.java b/java/java-tests/testData/inspection/dataFlow/CheckedExceptionDominance/src/Test.java index 4a0a690f0e21..4f0586d30a96 100644 --- a/java/java-tests/testData/inspection/dataFlow/CheckedExceptionDominance/src/Test.java +++ b/java/java-tests/testData/inspection/dataFlow/CheckedExceptionDominance/src/Test.java @@ -19,6 +19,6 @@ } public static void bar() throws CheckedException { - throw new CheckedException(); + if (new Random().nextInt() > 2) throw new CheckedException(); } } diff --git a/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/expected.xml b/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/expected.xml index bb6256f74012..4a088210968c 100644 --- a/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/expected.xml +++ b/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/expected.xml @@ -7,7 +7,7 @@ </problem> <problem> <file>IDEADEV10489.java</file> - <line>12</line> + <line>8</line> <description>Method invocation 's.length()' may produce NullPointerException</description> </problem> </problems>
\ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/src/IDEADEV10489.java b/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/src/IDEADEV10489.java index 60259479d353..ee41e588dd3e 100644 --- a/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/src/IDEADEV10489.java +++ b/java/java-tests/testData/inspection/dataFlow/IDEADEV10489/src/IDEADEV10489.java @@ -1,7 +1,5 @@ class IDEADEV10489 { - static String getS() { - return null; - } + static native String getS(); static void f() { String s = getS(); @@ -17,7 +15,5 @@ class IDEADEV10489 { } } - private static boolean foo() { - return false; - } + private static native boolean foo(); }
\ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java b/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java index 93fcf6d5c2d2..55c7c2b51de0 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java @@ -18,7 +18,5 @@ class Test { } } - private static @NotNull String createString() { - throw new NullPointerException(); - } + private static native @NotNull String createString(); }
\ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/CatchThrowable.java b/java/java-tests/testData/inspection/dataFlow/fixture/CatchThrowable.java index ecb9b264bb62..a30d934f64b6 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/CatchThrowable.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/CatchThrowable.java @@ -1,3 +1,5 @@ +import java.util.Random; + class BrokenAlignment { public static void main(String[] args) { @@ -20,7 +22,7 @@ class BrokenAlignment { } public static void doSomething() { - throw new RuntimeException("dummy"); + if (new Random().nextInt() > 2) throw new RuntimeException("dummy"); } }
\ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ContractWithNoArgs.java b/java/java-tests/testData/inspection/dataFlow/fixture/ContractWithNoArgs.java new file mode 100644 index 000000000000..006c2e3407ec --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ContractWithNoArgs.java @@ -0,0 +1,24 @@ +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +class Doo { + + @NotNull + public String doSomething() { + String s = getSomeString(); + if (s == null) { + throwSomeError(); + } + return s; + } + + private static void throwSomeError() { + throw new RuntimeException(); + } + + @Nullable + public String getSomeString() { + return Math.random() > 0.5 ? null : "Yeah"; + } + +} diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java b/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java new file mode 100644 index 000000000000..e9ec6b1dbe11 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java @@ -0,0 +1,25 @@ +import foo.*; +import org.jetbrains.annotations.NotNull; + +class Some { + void foo(@NotNull String s) { + NotNullClass.foo(null); + if (<warning descr="Condition 'NotNullClass.foo(s) == null' is always 'false'">NotNullClass.foo(s) == null</warning>) {} + + NullableClass.foo(null); + if (NullableClass.foo("a") == null) {} + + AnotherPackageNotNull.foo(null); + if (<warning descr="Condition 'AnotherPackageNotNull.foo(s) == null' is always 'false'">AnotherPackageNotNull.foo(s) == null</warning>) {} + } + +} + +@bar.MethodsAreNotNullByDefault +class NotNullClass { + static native Object foo(String s); + +} +class NullableClass { + static native Object foo(String s); +}
\ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/FloatComparisons.java b/java/java-tests/testData/inspection/dataFlow/fixture/FloatComparisons.java new file mode 100644 index 000000000000..5c553bcba0bf --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/FloatComparisons.java @@ -0,0 +1,7 @@ +class Test { + public static void testFunc(final float width, final float height) { + if (width < 0f || height < 0f) { + throw new IllegalArgumentException("Size must be non-negative"); + } + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java b/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java new file mode 100644 index 000000000000..dd815139efa5 --- /dev/null +++ b/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java @@ -0,0 +1,9 @@ +class Test { + + static void f<caret>oo() {} + static void foo2(int i) {} + + { + Runnable r = Test :: foo; + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java.after b/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java.after new file mode 100644 index 000000000000..8dab0803fcec --- /dev/null +++ b/java/java-tests/testData/refactoring/renameCollisions/RenameMethodNoCollisionWithOtherSignatureMethodRef.java.after @@ -0,0 +1,9 @@ +class Test { + + static void foo2() {} + static void foo2(int i) {} + + { + Runnable r = Test ::foo2; + } +}
\ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java index ae0ec20ab4d2..8383550b3e5c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ClsGenerics18HighlightingTest.java @@ -20,6 +20,8 @@ import com.intellij.pom.java.LanguageLevel; public class ClsGenerics18HighlightingTest extends ClsGenericsHighlightingTest { public void testIDEA121866() { doTest(); } + public void testIDEA127714() { doTest(); } + @Override protected LanguageLevel getLanguageLevel() { return LanguageLevel.JDK_1_8; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java index 2eecdaa9b221..3f199d44ea13 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java @@ -17,9 +17,6 @@ package com.intellij.codeInsight; import com.intellij.JavaTestUtil; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; @@ -54,6 +51,18 @@ public class CompleteStatementTest extends EditorActionTestCase { public void testCompleteCatchLParen() throws Exception { doTest(); } + public void testAlreadyCompleteCatch() throws Exception { + CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + int old = settings.BRACE_STYLE; + settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; + try { + doTest(); + } + finally { + settings.BRACE_STYLE = old; + } + } + public void testCompleteCatchWithExpression() throws Exception { doTest(); } public void testCompleteCatchBody() throws Exception { doTest(); } @@ -171,8 +180,6 @@ public class CompleteStatementTest extends EditorActionTestCase { } public void testSCR36110() throws Exception { - JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject()); - LanguageLevel old = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel(); doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java index f59162a6d5b2..9ca3b6084a43 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaTypingTest.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.psi.PsiDocumentManager; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; @@ -65,6 +66,14 @@ public class JavaTypingTest extends LightPlatformCodeInsightFixtureTestCase { myFixture.checkResultByFile(getTestName(true) + "_after.java"); } + public void testInvalidInitialSyntax() { + myFixture.configureByFile(getTestName(true) + "_before.java"); + myFixture.type('\\'); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // emulates background commit after typing first character + myFixture.type('\\'); + myFixture.checkResultByFile(getTestName(true) + "_after.java"); + } + private void doTest(char c) { myFixture.configureByFile(getTestName(true) + "_before.java"); myFixture.type(c); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 77b4c0cc64a7..f5fc39041106 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1423,6 +1423,11 @@ class XInternalError {} checkResult() } + public void testMulticaretCompletionFromNonPrimaryCaret() { + configure() + myFixture.assertPreferredCompletionItems(0, "arraycopy") + } + public void "test complete lowercase class name"() { myFixture.addClass("package foo; public class myClass {}") myFixture.configureByText "a.java", """ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy index 1d258fe01367..f37b90e21523 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy @@ -160,6 +160,10 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { checkPreferredItems(0, "myVersion", "getVersion", "getSelectedVersion", "calculateVersion"); } + public void testPreferFieldsToConstants() { + checkPreferredItems(0, "dateField", "LocalDate.MAX", "LocalDate.MIN"); + } + public void testPreferParametersToGetters() throws Throwable { checkPreferredItems(0, "a", "I._1", "getLastI", "valueOf"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index d2e8825cc16d..5153f19fe94a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -716,7 +716,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testMethodColon() throws Exception { doFirstItemTest(':'); } public void testVariableColon() throws Exception { doFirstItemTest(':'); } - private void doFirstItemTest(char c) throws Exception { + private void doFirstItemTest(char c) { configureByTestName(); select(c); checkResultByTestName(); @@ -824,6 +824,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doActionTest(); } + public void testDontSuggestWildcardGenerics() { doItemTest(); } + public void testCastWith2TypeParameters() throws Throwable { doTest(); } public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); } public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); } @@ -1141,7 +1143,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { checkResultByTestName(); } - private void doItemTest() throws Exception { + private void doItemTest() { doFirstItemTest('\n'); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 79506280a778..6ccefa35ae51 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -188,6 +188,22 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testInferFromConditionalExpressionCondition() throws Exception { + doTest(); + } + + public void testPrimitiveWrapperConditionInReturnConstraint() throws Exception { + doTest(); + } + + public void testIDEA128174() throws Exception { + doTest(); + } + + public void testIDEA128101() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java index fbf8036e8e35..156aac5613c1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java @@ -106,6 +106,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testIDEA127765() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java new file mode 100644 index 000000000000..b94e54d91323 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingGotoTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.folding; + +import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.FoldingModelEx; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; + +public class JavaFoldingGotoTest extends JavaCodeInsightFixtureTestCase { + + public void testIDEA127145() { + PsiFile file = myFixture.addFileToProject("Program.java", + "import java.io.InputStream;\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "class Program {\n" + + " private static InputStream getFile(String name, Map<String, Object> args) {\n" + + " return Program.class.getResourceAsStream(name);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " // Ctrl + B or Ctrl + Left Mouse Button work correctly for following string:\n" + + " final String name = \"file.sql\";\n" + + " // But it jumps only to folder in following case:\n" + + " final InputStream inputStream = getFile(\"dir/fil<caret>e.sql\", new HashMap<String, Object>());\n" + + " }\n" + + "}"); + + PsiFile fileSql = myFixture.addFileToProject("dir/file.sql", "select 1;"); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + + Editor editor = myFixture.getEditor(); + CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(editor); + FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); + foldingModel.rebuild(); + myFixture.doHighlighting(); + + PsiElement element = GotoDeclarationAction.findTargetElement(getProject(), editor, editor.getCaretModel().getOffset()); + assertTrue("Should navigate to: file.sql instead of " + element, element != null && element.equals(fileSql)); + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy index 5d823e001f82..095de51543af 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy @@ -568,14 +568,20 @@ class Test { public void "test fold one-line methods"() { configure """class Foo { + @Override int someMethod() { return 0; } + int someOtherMethod( + int param) { + return 0; + } + }""" PsiClass fooClass = JavaPsiFacade.getInstance(project).findClass('Foo', GlobalSearchScope.allScope(project)) def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset } - assert regions.size() == 2 + assert regions.size() == 3 checkAccessorFolding(regions[0], regions[1], fooClass.methods[0]) } @@ -792,13 +798,14 @@ public class CharSymbol { assert regions[3].placeholderText == 'seq: "Hi!"' } - public void "test inline negative numbers (IDEA-126753)"() { + public void "test inline negative and positive numbers"() { def text = """ public class CharSymbol { public void main() { Object obj = new Object(); count(-1, obj); + count(+1, obj); } public void count(int test, Object obj) { @@ -809,10 +816,13 @@ public class CharSymbol { """ configure text def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset } - assert regions.size() == 3 + assert regions.size() == 4 checkRangeOffsetByPositionInText(regions[1], text, "-1") assert regions[1].placeholderText == "test: -1" + + checkRangeOffsetByPositionInText(regions[2], text, "+1") + assert regions[2].placeholderText == "test: +1" } public void "test inline constructor literal arguments names"() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java index 7f47795881bc..70061e56afa9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/NullPostfixTemplateTest.java @@ -38,4 +38,9 @@ public class NullPostfixTemplateTest extends PostfixTemplateTestCase { public void testSecondStatement() { doTest(); } + + + public void testSingleExclamationIgnored() { + doTest(); + } }
\ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index 23eac589e2db..89762efe5dd2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -228,6 +228,34 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == [] } + public void "test boolean autoboxing in delegation"() { + def c = inferContracts(""" + static Boolean test04(String s) { + return test03(s); + } + static boolean test03(String s) { + return s == null; + } + """) + assert c == [] + } + + public void "test boolean auto-unboxing"() { + def c = inferContracts(""" + static boolean test02(String s) { + return test01(s); + } + + static Boolean test01(String s) { + if (s == null) + return new Boolean(false); + else + return null; + } + """) + assert c == [] + } + public void "test non-returning delegation"() { def c = inferContracts(""" static void test2(Object o) { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 4cba2ab918a7..33eb32eb0ec6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -18,6 +18,7 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; @@ -251,15 +252,17 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testRootThrowableCause() { doTest(); } public void testUseInferredContracts() { doTest(); } + public void testContractWithNoArgs() { doTest(); } public void testContractInferenceBewareOverriding() { doTest(); } public void testNumberComparisonsWhenValueIsKnown() { doTest(); } + public void testFloatComparisons() { doTest(); } public void testAccessingSameArrayElements() { doTest(); } public void testParametersAreNonnullByDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}"); + addJavaxNullabilityAnnotations(myFixture); + addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addClass("package foo; public class AnotherPackageNotNull { public static void foo(String s) {}}"); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); @@ -267,6 +270,37 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { doTest(); } + public static void addJavaxDefaultNullabilityAnnotations(final JavaCodeInsightTestFixture fixture) { + fixture.addClass("package javax.annotation;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.PARAMETER) @javax.annotation.Nonnull " + + "public @interface ParametersAreNonnullByDefault {}"); + fixture.addClass("package javax.annotation;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.PARAMETER) @javax.annotation.Nullable " + + "public @interface ParametersAreNullableByDefault {}"); + } + + public static void addJavaxNullabilityAnnotations(final JavaCodeInsightTestFixture fixture) { + fixture.addClass("package javax.annotation;" + + "public @interface Nonnull {}"); + fixture.addClass("package javax.annotation;" + + "public @interface Nullable {}"); + fixture.addClass("package javax.annotation.meta;" + + "public @interface TypeQualifierDefault { java.lang.annotation.ElementType[] value() default {};}"); + } + + public void testCustomTypeQualifierDefault() { + addJavaxNullabilityAnnotations(myFixture); + myFixture.addClass("package bar;" + + "@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.METHOD) @javax.annotation.Nonnull " + + "public @interface MethodsAreNotNullByDefault {}"); + + myFixture.addClass("package foo; public class AnotherPackageNotNull { public static native Object foo(String s); }"); + myFixture.addFileToProject("foo/package-info.java", "@bar.MethodsAreNotNullByDefault package foo;"); + + myFixture.enableInspections(new DataFlowInspection()); + myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); + } + public void testTrueOrEqualsSomething() { doTest(); myFixture.launchAction(myFixture.findSingleIntention("Remove redundant assignment")); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java index e925dd49a8ea..3520ec08d750 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java @@ -40,8 +40,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorSuperParameterDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface Nullable {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.addClass("import javax.annotation.*; package foo; public interface NullableFunction { void fun(@Nullable Object o); }"); @@ -51,7 +51,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorThisParameterDefault() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java")); @@ -60,8 +61,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase } public void testHonorParameterDefaultInSetters() { - myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}"); - myFixture.addClass("package javax.annotation; public @interface Nullable {}"); + DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); + DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture); myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;"); myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java")); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java index 09fa87fa95e9..9d26fd804f68 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisTest.java @@ -183,7 +183,7 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase { private void checkCompoundId(Method method, PsiMethod psiMethod, boolean noKey) throws IOException { Direction direction = new Out(); - int psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction); + long psiKey = myBytecodeAnalysisConverter.mkPsiKey(psiMethod, direction); if (noKey) { assertTrue(-1 == psiKey); return; @@ -192,7 +192,7 @@ public class BytecodeAnalysisTest extends JavaCodeInsightFixtureTestCase { assertFalse(-1 == psiKey); } - int asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true)); + long asmKey = myBytecodeAnalysisConverter.mkAsmKey(new Key(method, direction, true)); Assert.assertEquals(asmKey, psiKey); } diff --git a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java index 02f8c589c43b..3cc6c19618a1 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java @@ -19,7 +19,9 @@ import com.intellij.find.editorHeaderActions.*; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.util.Getter; +import com.intellij.testFramework.fixtures.EditorMouseFixture; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; import javax.swing.text.JTextComponent; @@ -58,7 +60,7 @@ public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureT assertNull(getEditorSearchComponent()); } - public void testActionsWorkFromEditor() throws IOException { + public void testActionsInEditorWorkIndependently() throws IOException { init("abc\n" + "abc\n" + "abc"); @@ -67,27 +69,29 @@ public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureT checkResultByText("a<selection>b<caret></selection>c\n" + "abc\n" + "abc"); + new EditorMouseFixture((EditorImpl)myFixture.getEditor()).clickAt(0, 1); addOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + + addOccurrenceFromEditor(); + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + "abc"); nextOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + - "a<selection>b<caret></selection>c"); + "<selection>a<caret>bc</selection>"); prevOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + "abc"); removeOccurrenceFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + + checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + "abc"); allOccurrencesFromEditor(); - checkResultByText("a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c\n" + - "a<selection>b<caret></selection>c"); - assertNull(getEditorSearchComponent()); + checkResultByText("<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>\n" + + "<selection>a<caret>bc</selection>"); + assertNotNull(getEditorSearchComponent()); } public void testCloseRetainsMulticaretSelection() throws IOException { diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java index 92caad03d8ef..f83d836bb55a 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java @@ -579,7 +579,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { FindModel findModel = FindManagerTestUtils.configureFindModel("done"); String text = "/** done done done */"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text); findModel.setRegularExpressions(true); @@ -592,7 +592,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { String prefix = "/*"; String text = prefix + "done*/"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); LightVirtualFile file = new LightVirtualFile("A.java", text); FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); @@ -615,8 +615,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { FindModel findModel = FindManagerTestUtils.configureFindModel("^done$"); findModel.setRegularExpressions(true); - findModel.setInStringLiteralsOnly(true); - findModel.setInCommentsOnly(false); + findModel.setSearchContext(FindModel.SearchContext.IN_STRING_LITERALS); String text = "\"done\"; 'done'; 'done' \"done2\""; FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java"); @@ -633,7 +632,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { String text = "/** do ne do ne do ne */"; - findModel.setInCommentsOnly(true); + findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS); FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java"); } @@ -651,4 +650,42 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { findModel.setWholeWordsOnly(true); assertSize(1, findUsages(findModel)); } + + public void testFindExceptComments() { + FindModel findModel = FindManagerTestUtils.configureFindModel("done"); + + String prefix = "/*"; + String text = prefix + "done*/done"; + + findModel.setSearchContext(FindModel.SearchContext.EXCEPT_COMMENTS); + LightVirtualFile file = new LightVirtualFile("A.java", text); + + FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + + findModel.setRegularExpressions(true); + findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + } + + public void testFindExceptLiterals() { + FindModel findModel = FindManagerTestUtils.configureFindModel("done"); + + String prefix = "\""; + String text = prefix + "done\"done"; + + findModel.setSearchContext(FindModel.SearchContext.EXCEPT_STRING_LITERALS); + LightVirtualFile file = new LightVirtualFile("A.java", text); + + FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + + findModel.setRegularExpressions(true); + findResult = myFindManager.findString(text, prefix.length(), findModel, file); + assertTrue(findResult.isStringFound()); + assertTrue(findResult.getStartOffset() > prefix.length()); + } } diff --git a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy index dabe06ba79fa..9a97a825964a 100644 --- a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy +++ b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy @@ -24,7 +24,6 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.Consumer import com.intellij.util.concurrency.Semaphore import org.jetbrains.annotations.NotNull - /** * @author peter */ @@ -197,6 +196,33 @@ class Intf { assert getPopupElements(new GotoClassModel2(project), 'Bar:[2,3]') == [c] } + public void "test dollar"() { + def bar = myFixture.addClass("package foo; class Bar { class Foo {} }") + def foo = bar.innerClasses[0] + myFixture.addClass("package goo; class Goo { }") + assert getPopupElements(new GotoClassModel2(project), 'Bar$Foo') == [foo] + assert getPopupElements(new GotoClassModel2(project), 'foo.Bar$Foo') == [foo] + assert getPopupElements(new GotoClassModel2(project), 'foo.B$F') == [foo] + assert !getPopupElements(new GotoClassModel2(project), 'foo$Foo') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Bar') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Bar$Foo') + assert !getPopupElements(new GotoClassModel2(project), 'foo$Goo') + } + + public void "test anonymous classes"() { + def goo = myFixture.addClass("package goo; class Goo { Runnable r = new Runnable() {}; }") + assert getPopupElements(new GotoClassModel2(project), 'Goo$1') == [goo] + } + + public void "test qualified name matching"() { + def bar = myFixture.addClass("package foo.bar; class Bar { }") + def bar2 = myFixture.addClass("package goo.baz; class Bar { }") + assert getPopupElements(new GotoClassModel2(project), 'foo.Bar') == [bar] + assert getPopupElements(new GotoClassModel2(project), 'foo.bar.Bar') == [bar] + assert getPopupElements(new GotoClassModel2(project), 'goo.Bar') == [bar2] + assert getPopupElements(new GotoClassModel2(project), 'goo.baz.Bar') == [bar2] + } + public void "test super method in jdk"() { def ourRun = myFixture.addClass("package foo.bar; class Goo implements Runnable { public void run() {} }").methods[0] def sdkRun diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index 1e3e08a33ae7..56624594bb0e 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -49,7 +49,7 @@ import static java.util.Collections.singletonList; public class DirectoryIndexTest extends IdeaTestCase { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.DirectoryIndexTest"); - private DirectoryIndex myIndex; + private DirectoryIndexImpl myIndex; private Module myModule2, myModule3; private VirtualFile myRootVFile; @@ -65,6 +65,7 @@ public class DirectoryIndexTest extends IdeaTestCase { private VirtualFile myModule1OutputDir; private VirtualFile myResDir, myTestResDir; private VirtualFile myExcludedLibSrcDir, myExcludedLibClsDir; + private ProjectFileIndex myFileIndex; @Override protected void setUp() throws Exception { @@ -176,7 +177,8 @@ public class DirectoryIndexTest extends IdeaTestCase { } }); - myIndex = DirectoryIndex.getInstance(myProject); + myIndex = (DirectoryIndexImpl)DirectoryIndex.getInstance(myProject); + myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); // to not interfere with previous test firing vfs events VirtualFileManager.getInstance().syncRefresh(); } @@ -221,12 +223,12 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile cvs = myPack1Dir.createChildDirectory(this, "CVS"); assertNotInProject(cvs); - assertNull(ProjectRootManager.getInstance(myProject).getFileIndex().getPackageNameByDirectory(cvs)); + assertNull(myFileIndex.getPackageNameByDirectory(cvs)); } public void testDirsByPackageName() throws IOException { - checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibSrc, myFileLibCls, mySrcDir2, myLibSrcDir, myLibClsDir); - checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibCls, mySrcDir2, myLibClsDir); + checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibSrcDir, myLibClsDir); + checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibClsDir); checkPackage("pack1", true, myPack1Dir); checkPackage("pack1", false, myPack1Dir); @@ -257,6 +259,18 @@ public class DirectoryIndexTest extends IdeaTestCase { checkPackage("pack1", true, myPack1Dir, myModule3Dir); } + public void testPackageDirectoriesWithDots() throws IOException { + VirtualFile fooBar = mySrcDir1.createChildDirectory(this, "foo.bar"); + VirtualFile goo1 = fooBar.createChildDirectory(this, "goo"); + VirtualFile foo = mySrcDir2.createChildDirectory(this, "foo"); + VirtualFile bar = foo.createChildDirectory(this, "bar"); + VirtualFile goo2 = bar.createChildDirectory(this, "goo"); + + checkPackage("foo", false, foo); + checkPackage("foo.bar", false, bar, fooBar); + checkPackage("foo.bar.goo", false, goo2, goo1); + } + public void testCreateDir() throws Exception { String path = mySrcDir1.getPath().replace('/', File.separatorChar); assertTrue(new File(path + File.separatorChar + "dir1" + File.separatorChar + "dir2").mkdirs()); @@ -362,7 +376,8 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile ignoredFile = myModule1Dir.createChildData(this, "CVS"); DirectoryInfo info = myIndex.getInfoForFile(ignoredFile); assertTrue(info.isIgnored()); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(ignoredFile)); + assertTrue(myFileIndex.isExcluded(ignoredFile)); + assertTrue(myFileIndex.isUnderIgnored(ignoredFile)); } public void testAddModule() throws Exception { @@ -386,10 +401,12 @@ public class DirectoryIndexTest extends IdeaTestCase { public void testModuleUnderIgnoredDir() throws IOException { final VirtualFile ignored = myRootVFile.createChildDirectory(this, "RCS"); assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored)); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(ignored)); + assertTrue(myFileIndex.isExcluded(ignored)); + assertTrue(myFileIndex.isUnderIgnored(ignored)); final VirtualFile module4 = ignored.createChildDirectory(this, "module4"); assertFalse(FileTypeManager.getInstance().isFileIgnored(module4)); - assertTrue(ProjectRootManager.getInstance(myProject).getFileIndex().isExcluded(module4)); + assertTrue(myFileIndex.isExcluded(module4)); + assertTrue(myFileIndex.isUnderIgnored(module4)); new WriteCommandAction.Simple(getProject()) { @Override @@ -425,11 +442,12 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testExcludedDirsInLibraries() { - ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex(); - assertFalse(index.isInLibraryClasses(myExcludedLibClsDir)); - assertTrue(index.isExcluded(myExcludedLibClsDir)); - assertFalse(index.isInLibrarySource(myExcludedLibSrcDir)); - assertTrue(index.isExcluded(myExcludedLibSrcDir)); + assertFalse(myFileIndex.isInLibraryClasses(myExcludedLibClsDir)); + assertTrue(myFileIndex.isExcluded(myExcludedLibClsDir)); + assertFalse(myFileIndex.isUnderIgnored(myExcludedLibClsDir)); + assertFalse(myFileIndex.isInLibrarySource(myExcludedLibSrcDir)); + assertTrue(myFileIndex.isExcluded(myExcludedLibSrcDir)); + assertFalse(myFileIndex.isUnderIgnored(myExcludedLibSrcDir)); } public void testExplicitExcludeOfInner() throws Exception { @@ -469,12 +487,12 @@ public class DirectoryIndexTest extends IdeaTestCase { ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Collections.<String>emptyList(), Arrays.asList(mySrcDir1.getUrl())); checkInfo(mySrcDir1, myModule, false, true, "", JavaSourceRootType.SOURCE, myModule, myModule); - OrderEntry[] entries = myIndex.getInfoForFile(mySrcDir1).getOrderEntries(); + OrderEntry[] entries = myIndex.getOrderEntries(myIndex.getInfoForFile(mySrcDir1)); assertInstanceOf(entries[0], LibraryOrderEntry.class); assertInstanceOf(entries[1], ModuleSourceOrderEntry.class); checkInfo(myTestSrc1, myModule, false, true, "testSrc", JavaSourceRootType.TEST_SOURCE, myModule, myModule); - entries = myIndex.getInfoForFile(myTestSrc1).getOrderEntries(); + entries = myIndex.getOrderEntries(myIndex.getInfoForFile(myTestSrc1)); assertInstanceOf(entries[0], LibraryOrderEntry.class); assertInstanceOf(entries[1], ModuleSourceOrderEntry.class); } @@ -482,7 +500,7 @@ public class DirectoryIndexTest extends IdeaTestCase { public void testModuleSourceAsLibraryClasses() throws Exception { ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Arrays.asList(mySrcDir1.getUrl()), Collections.<String>emptyList()); checkInfo(mySrcDir1, myModule, true, false, "", JavaSourceRootType.SOURCE, myModule); - assertInstanceOf(assertOneElement(assertInProject(mySrcDir1).getOrderEntries()), ModuleSourceOrderEntry.class); + assertInstanceOf(assertOneElement(myIndex.getOrderEntries(assertInProject(mySrcDir1))), ModuleSourceOrderEntry.class); } public void testModulesWithSameSourceContentRoot() { @@ -645,7 +663,7 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule, myModule3); checkInfo(myResDir, myModule, true, false, "", JavaResourceRootType.RESOURCE, myModule); - assertInstanceOf(assertOneElement(assertInProject(myResDir).getOrderEntries()), ModuleSourceOrderEntry.class); + assertInstanceOf(assertOneElement(myIndex.getOrderEntries(assertInProject(myResDir))), ModuleSourceOrderEntry.class); checkInfo(myExcludedLibSrcDir, null, true, false, "lib.src.exc", null, myModule3, myModule); checkInfo(myExcludedLibClsDir, null, true, false, "lib.cls.exc", null, myModule3); @@ -661,10 +679,10 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testExcludeCompilerOutputOutsideOfContentRoot() throws Exception { - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - assertTrue(fileIndex.isExcluded(myOutputDir)); - assertTrue(fileIndex.isExcluded(myModule1OutputDir)); - assertFalse(fileIndex.isExcluded(myOutputDir.getParent())); + assertTrue(myFileIndex.isExcluded(myOutputDir)); + assertFalse(myFileIndex.isUnderIgnored(myOutputDir)); + assertTrue(myFileIndex.isExcluded(myModule1OutputDir)); + assertFalse(myFileIndex.isExcluded(myOutputDir.getParent())); assertExcludedFromProject(myOutputDir); assertExcludedFromProject(myModule1OutputDir); String moduleOutputUrl = myModule1OutputDir.getUrl(); @@ -677,7 +695,7 @@ public class DirectoryIndexTest extends IdeaTestCase { assertExcludedFromProject(myOutputDir); assertExcludedFromProject(myModule1OutputDir); - assertTrue(fileIndex.isExcluded(myModule1OutputDir)); + assertTrue(myFileIndex.isExcluded(myModule1OutputDir)); PsiTestUtil.setCompilerOutputPath(myModule, moduleOutputUrl, true); PsiTestUtil.setCompilerOutputPath(myModule2, moduleOutputUrl, false); @@ -703,49 +721,47 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileContentAndSourceRoots() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileRoot = myRootVFile.createChildData(this, "fileRoot.txt"); VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); VirtualFile fileTestSourceRoot = myRootVFile.createChildData(this, "fileTestSourceRoot.txt"); assertNotInProject(fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot)); ContentEntry contentEntry = PsiTestUtil.addContentRoot(myModule, fileRoot); assertEquals(fileRoot, contentEntry.getFile()); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertFalse(fileIndex.isInSource(fileRoot)); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInSource(fileRoot)); PsiTestUtil.addContentRoot(myModule, fileSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); PsiTestUtil.addContentRoot(myModule, fileTestSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileTestSourceRoot, true); checkInfo(fileTestSourceRoot, myModule, false, false, "", JavaSourceRootType.TEST_SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileTestSourceRoot)); - assertTrue(fileIndex.isInSource(fileTestSourceRoot)); + assertTrue(myFileIndex.isInContent(fileTestSourceRoot)); + assertTrue(myFileIndex.isInSource(fileTestSourceRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); // removing file source root PsiTestUtil.removeSourceRoot(myModule, fileTestSourceRoot); checkInfo(fileTestSourceRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileTestSourceRoot)); - assertFalse(fileIndex.isInSource(fileTestSourceRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); + assertTrue(myFileIndex.isInContent(fileTestSourceRoot)); + assertFalse(myFileIndex.isInSource(fileTestSourceRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); // removing file content root - PsiTestUtil.removeContentEntry(myModule, contentEntry); + PsiTestUtil.removeContentEntry(myModule, contentEntry.getFile()); assertNotInProject(fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); - assertFalse(fileIndex.isInSource(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInSource(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot)); } private void assertIteratedContent(ProjectFileIndex fileIndex, @@ -764,63 +780,57 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileSourceRootsUnderDirContentRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileSourceRoot = myModule1Dir.createChildData(this, "fileSourceRoot.txt"); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); // removing file source root PsiTestUtil.removeSourceRoot(myModule, fileSourceRoot); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); } public void testFileModuleExcludeRootUnderDirectoryRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileExcludeRoot = mySrcDir1.createChildData(this, "fileExcludeRoot.txt"); - assertTrue(fileIndex.isInContent(fileExcludeRoot)); - assertTrue(fileIndex.isInSource(fileExcludeRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null); + assertTrue(myFileIndex.isInContent(fileExcludeRoot)); + assertTrue(myFileIndex.isInSource(fileExcludeRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null); PsiTestUtil.addExcludedRoot(myModule, fileExcludeRoot); - assertFalse(fileIndex.isInContent(fileExcludeRoot)); - assertFalse(fileIndex.isInSource(fileExcludeRoot)); + assertFalse(myFileIndex.isInContent(fileExcludeRoot)); + assertFalse(myFileIndex.isInSource(fileExcludeRoot)); assertExcluded(fileExcludeRoot, myModule); - assertIteratedContent(fileIndex, null, Arrays.asList(fileExcludeRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileExcludeRoot)); // removing file exclude root PsiTestUtil.removeExcludedRoot(myModule, fileExcludeRoot); - assertTrue(fileIndex.isInContent(fileExcludeRoot)); - assertTrue(fileIndex.isInSource(fileExcludeRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileExcludeRoot), null); + assertTrue(myFileIndex.isInContent(fileExcludeRoot)); + assertTrue(myFileIndex.isInSource(fileExcludeRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null); } public void testFileModuleExcludeRootUnderFileRoot() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile fileRoot = myRootVFile.createChildData(this, "fileRoot.txt"); PsiTestUtil.addContentRoot(myModule, fileRoot); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot), null); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null); PsiTestUtil.addExcludedRoot(myModule, fileRoot); - assertFalse(fileIndex.isInContent(fileRoot)); + assertFalse(myFileIndex.isInContent(fileRoot)); assertExcluded(fileRoot, myModule); - assertIteratedContent(fileIndex, null, Arrays.asList(fileRoot)); + assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot)); // removing file exclude root PsiTestUtil.removeExcludedRoot(myModule, fileRoot); checkInfo(fileRoot, myModule, false, false, "", null); - assertTrue(fileIndex.isInContent(fileRoot)); - assertIteratedContent(fileIndex, Arrays.asList(fileRoot), null); + assertTrue(myFileIndex.isInContent(fileRoot)); + assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null); } public void testFileLibraryInsideFolderLibrary() throws IOException { @@ -835,8 +845,6 @@ public class DirectoryIndexTest extends IdeaTestCase { } public void testFileContentRootsModifications() throws IOException { - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - VirtualFile temp = myRootVFile.createChildDirectory(this, "temp"); VirtualFile fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); @@ -845,54 +853,54 @@ public class DirectoryIndexTest extends IdeaTestCase { PsiTestUtil.addContentRoot(myModule, fileSourceRoot); PsiTestUtil.addSourceRoot(myModule, fileSourceRoot); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and recreate fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = myRootVFile.createChildData(this, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and move from another dir fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot.move(this, myRootVFile); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and copy from another dir fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = temp.createChildData(this, "fileSourceRoot.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot = fileSourceRoot.copy(this, myRootVFile, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); // delete and rename from another file fileSourceRoot.delete(this); assertNotInProject(fileSourceRoot); - assertFalse(fileIndex.isInContent(fileSourceRoot)); - assertFalse(fileIndex.isInSource(fileSourceRoot)); + assertFalse(myFileIndex.isInContent(fileSourceRoot)); + assertFalse(myFileIndex.isInSource(fileSourceRoot)); fileSourceRoot = myRootVFile.createChildData(this, "temp_file.txt"); assertNotInProject(fileSourceRoot); fileSourceRoot.rename(this, "fileSourceRoot.txt"); checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule); - assertTrue(fileIndex.isInContent(fileSourceRoot)); - assertTrue(fileIndex.isInSource(fileSourceRoot)); + assertTrue(myFileIndex.isInContent(fileSourceRoot)); + assertTrue(myFileIndex.isInSource(fileSourceRoot)); } private void checkInfo(VirtualFile file, @@ -914,15 +922,14 @@ public class DirectoryIndexTest extends IdeaTestCase { assertEquals(isInLibrary, info.hasLibraryClassRoot()); assertEquals(isInLibrarySource, info.isInLibrarySource()); - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); if (file.isDirectory()) { - assertEquals(packageName, fileIndex.getPackageNameByDirectory(file)); + assertEquals(packageName, myFileIndex.getPackageNameByDirectory(file)); } - assertEquals(Arrays.toString(info.getOrderEntries()), modulesOfOrderEntries.length, info.getOrderEntries().length); + assertEquals(Arrays.toString(myIndex.getOrderEntries(info)), modulesOfOrderEntries.length, myIndex.getOrderEntries(info).length); for (Module aModule : modulesOfOrderEntries) { - OrderEntry found = info.findOrderEntryWithOwnerModule(aModule); - assertNotNull("not found: " + aModule + " in " + Arrays.toString(info.getOrderEntries()), found); + OrderEntry found = myIndex.findOrderEntryWithOwnerModule(info, aModule); + assertNotNull("not found: " + aModule + " in " + Arrays.toString(myIndex.getOrderEntries(info)), found); } } @@ -941,7 +948,7 @@ public class DirectoryIndexTest extends IdeaTestCase { private DirectoryInfo assertInProject(VirtualFile file) { DirectoryInfo info = myIndex.getInfoForFile(file); assertTrue(file.toString(), info.isInProject()); - info.assertConsistency(); + myIndex.assertConsistency(info); return info; } @@ -957,6 +964,11 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY); assertNotNull(actualDirs); assertOrderedEquals(actualDirs, expectedDirs); + + for (VirtualFile dir : expectedDirs) { + String actualName = myIndex.getPackageName(dir); + assertEquals("Invalid package name for dir " + dir + ": " + packageName, packageName, actualName); + } } } diff --git a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java index 096547c4f4db..61414ab0b416 100644 --- a/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/MiscPsiTest.java @@ -260,4 +260,20 @@ public class MiscPsiTest extends LightCodeInsightFixtureTestCase { assertEquals("some.unknown.Foo<? extends String>", type.getCanonicalText()); } + public void testNoPsiModificationsInUncommittedDocument() { + final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{}"); + Document document = file.getViewProvider().getDocument(); + document.insertString(0, " "); + + PsiClass psiClass = file.getClasses()[0]; + try { + psiClass.addBefore(PsiParserFacade.SERVICE.getInstance(getProject()).createWhiteSpaceFromText(" "), psiClass.getLBrace()); + fail(); + } + catch (IllegalStateException e) { + assertEquals("Attempt to modify PSI for non-committed Document!", e.getMessage()); + } + assertEquals("class A{}", psiClass.getText()); + assertEquals(" class A{}", document.getText()); + } } diff --git a/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy index d11a34f6e376..7b1861b9daec 100644 --- a/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerFieldReferenceTest.groovy @@ -385,4 +385,28 @@ public class test { ] ) } + + void "test IDEA-128071"() { + doTest( + initial: ''' +public class FormatTest { + public int a = 3; + private static final String FACEBOOK_CLIENT_ID = ""; + public static final String FACEBOOK_OAUTH_URL = "".concat(FACEBOOK_CLIENT_ID).concat(""); +} +''', + expected: ''' +public class FormatTest { + private static final String FACEBOOK_CLIENT_ID = ""; + public static final String FACEBOOK_OAUTH_URL = "".concat(FACEBOOK_CLIENT_ID).concat(""); + public int a = 3; +} +''', + rules: [ + rule(PUBLIC, STATIC, FINAL), + rule(PRIVATE, STATIC, FINAL), + rule(PUBLIC) + ] + ) + } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java index 204525cb6822..e830594db39f 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java @@ -208,6 +208,10 @@ public class RenameCollisionsTest extends LightRefactoringTestCase { doTest("foo2"); } + public void testRenameMethodNoCollisionWithOtherSignatureMethodRef() throws Exception { + doTest("foo2"); + } + public void testRenameNoStaticOverridingInInterfaces() throws Exception { doTest("foo"); } diff --git a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java index 514348e5913b..0ad26a34eec5 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ModuleScopesTest.java @@ -105,15 +105,21 @@ public class ModuleScopesTest extends ModuleTestCase { } private Module addDependentModule(final Module moduleA, final DependencyScope scope) { - final Module moduleB = createModule("b.iml", StdModuleTypes.JAVA); + return addDependentModule("b", moduleA, scope, false); + } + + private Module addDependentModule(final String name, final Module moduleA, + final DependencyScope scope, + final boolean exported) { + final Module moduleB = createModule(name + ".iml", StdModuleTypes.JAVA); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - VirtualFile rootB = myFixture.findOrCreateDir("b"); + VirtualFile rootB = myFixture.findOrCreateDir(name); VirtualFile outB = myFixture.findOrCreateDir("out"); - ModuleRootModificationUtil.addDependency(moduleA, moduleB, scope, false); + ModuleRootModificationUtil.addDependency(moduleA, moduleB, scope, exported); PsiTestUtil.addSourceRoot(moduleB, rootB); PsiTestUtil.setCompilerOutputPath(moduleB, outB.getUrl(), false); @@ -123,6 +129,25 @@ public class ModuleScopesTest extends ModuleTestCase { return moduleB; } + public void testModuleTwiceInDependents() throws IOException { + Module m = createModule("m.iml", StdModuleTypes.JAVA); + Module a = createModule("a.iml", StdModuleTypes.JAVA); + Module b = createModule("b.iml", StdModuleTypes.JAVA); + Module c = createModule("c.iml", StdModuleTypes.JAVA); + + ModuleRootModificationUtil.addDependency(a, m, DependencyScope.COMPILE, false); + ModuleRootModificationUtil.addDependency(b, m, DependencyScope.COMPILE, true); + ModuleRootModificationUtil.addDependency(a, b, DependencyScope.COMPILE, true); + ModuleRootModificationUtil.addDependency(c, a, DependencyScope.COMPILE, true); + + VirtualFile root = myFixture.findOrCreateDir("c"); + PsiTestUtil.addSourceContentToRoots(c, root); + VirtualFile file = root.createChildData(this, "x.txt"); + + GlobalSearchScope deps = m.getModuleWithDependentsScope(); + assertTrue(deps.contains(file)); + } + public void testTestOnlyLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); addLibrary(m, DependencyScope.TEST); diff --git a/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java b/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java index 6e34ebf5f939..b6d8840059ba 100644 --- a/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/slicer/SliceTreeTest.java @@ -49,7 +49,8 @@ public class SliceTreeTest extends SliceTestCase { SliceUsage usage = SliceUsage.createRootUsage(element, params); - SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, ToolWindowHeadlessManagerImpl.HEADLESS_WINDOW) { + ToolWindowHeadlessManagerImpl.MockToolWindow toolWindow = new ToolWindowHeadlessManagerImpl.MockToolWindow(myProject); + SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, toolWindow) { @Override protected void close() { } |