diff --git a/idea/resources/inspectionDescriptions/IfThenToSafeAccess.html b/idea/resources/inspectionDescriptions/IfThenToSafeAccess.html
new file mode 100644
index 00000000000..cf6fff1bd95
--- /dev/null
+++ b/idea/resources/inspectionDescriptions/IfThenToSafeAccess.html
@@ -0,0 +1,5 @@
+
+
+This inspection reports any if-then expressions that can be folded into safe-access (?.) expressions
+
+
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 62e41feb49d..6d7c4686e3c 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -673,6 +673,13 @@
level="WARNING"
/>
+
+
diff --git a/idea/src/org/jetbrains/jet/plugin/inspections/IfThenToSafeAccessInspection.kt b/idea/src/org/jetbrains/jet/plugin/inspections/IfThenToSafeAccessInspection.kt
new file mode 100644
index 00000000000..10de83c51ff
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/inspections/IfThenToSafeAccessInspection.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2010-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 org.jetbrains.jet.plugin.inspections
+
+import org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
+import org.jetbrains.jet.lang.psi.JetIfExpression
+
+public class IfThenToSafeAccessInspection : IntentionBasedInspection(IfThenToSafeAccessIntention())
diff --git a/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/expected.xml b/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/expected.xml
new file mode 100644
index 00000000000..24ef90af04b
--- /dev/null
+++ b/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/expected.xml
@@ -0,0 +1,114 @@
+
+
+ rhsNotEqualsNull.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ rhsEqualsNull.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ noThenBlock.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ noElseBlock.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ lhsNotEqualsNull.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ lhsEqualsNull.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ ifAsExpression.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ ifAndElseNotInBlocks.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ ifAndElseBothInBlocks.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ emptyThenBlock.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ emptyElseBlock.kt
+ 7
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ doesNotinlineValueOutsideOfScope.kt
+ 8
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ doesNotinlineValueIfUsedMoreThanOnce.kt
+ 10
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
+ willNotInlineClassProperty.kt
+ 3
+ light_idea_test_case
+
+ If-Then foldable to '?.'
+ Replace 'if' expression with safe access expression
+
+
diff --git a/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test b/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test
new file mode 100644
index 00000000000..a2552cc8cc2
--- /dev/null
+++ b/idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test
@@ -0,0 +1 @@
+// INSPECTION_CLASS: org.jetbrains.jet.plugin.inspections.IfThenToSafeAccessInspection
diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java
index 42f1f5651e5..f19fe976751 100644
--- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java
+++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java
@@ -46,4 +46,9 @@ public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
doTest("idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test");
}
+ @TestMetadata("branched/ifThenToSafeAccess/inspectionData/inspections.test")
+ public void testBranched_ifThenToSafeAccess_inspectionData_Inspections_test() throws Exception {
+ doTest("idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test");
+ }
+
}
diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java
index 78569dc468a..234432a2138 100644
--- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java
+++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java
@@ -363,6 +363,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
}
@TestMetadata("idea/testData/intentions/branched/ifThenToSafeAccess")
+ @InnerTestClasses({})
public static class IfThenToSafeAccess extends AbstractCodeTransformationTest {
public void testAllFilesPresentInIfThenToSafeAccess() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/branched/ifThenToSafeAccess"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -538,6 +539,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
doTestIfThenToSafeAccess("idea/testData/intentions/branched/ifThenToSafeAccess/willNotInlineClassProperty.kt");
}
+ public static Test innerSuite() {
+ TestSuite suite = new TestSuite("IfThenToSafeAccess");
+ suite.addTestSuite(IfThenToSafeAccess.class);
+ return suite;
+ }
}
@TestMetadata("idea/testData/intentions/branched/folding/ifToAssignment")
@@ -3426,7 +3432,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
suite.addTestSuite(ElvisToIfThen.class);
suite.addTest(IfThenToElvis.innerSuite());
suite.addTestSuite(SafeAccessToIfThen.class);
- suite.addTestSuite(IfThenToSafeAccess.class);
+ suite.addTest(IfThenToSafeAccess.innerSuite());
suite.addTestSuite(IfToAssignment.class);
suite.addTestSuite(IfToReturn.class);
suite.addTestSuite(IfToReturnAsymmetrically.class);