From 5ff68d71b0d0856b593ae1c609accb6b10a8544a Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 26 Jun 2015 13:07:05 +0300 Subject: [PATCH] stream api: shorten class references when replace with foreach --- .../codeInspection/StreamApiMigrationInspection.java | 2 +- .../streamApiMigration/afterForeachMethodRef.java | 10 ++++++++++ .../streamApiMigration/beforeForeachMethodRef.java | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/afterForeachMethodRef.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeForeachMethodRef.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java index 265e1b6d9946..ae8d9c8d07eb 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java @@ -303,7 +303,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo simplifyRedundantCast(callStatement); - CodeStyleManager.getInstance(project).reformat(callStatement); + CodeStyleManager.getInstance(project).reformat(JavaCodeStyleManager.getInstance(project).shortenClassReferences(callStatement)); } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/afterForeachMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/afterForeachMethodRef.java new file mode 100644 index 000000000000..e111bcfc5af7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/afterForeachMethodRef.java @@ -0,0 +1,10 @@ +// "Replace with forEach" "true" +import java.util.ArrayList; +import java.util.List; + +class Sample { + List foo = new ArrayList<>(); + { + foo.forEach(Exception::printStackTrace); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeForeachMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeForeachMethodRef.java new file mode 100644 index 000000000000..7bdf09c3abd8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeForeachMethodRef.java @@ -0,0 +1,12 @@ +// "Replace with forEach" "true" +import java.util.ArrayList; +import java.util.List; + +class Sample { + List foo = new ArrayList<>(); + { + for (Exception e : foo) { + e.printStackTrace(); + } + } +}