diff --git a/idea/resources/inspectionDescriptions/ExplicitGet.html b/idea/resources/inspectionDescriptions/ExplicitGet.html new file mode 100644 index 00000000000..5bc1cae187d --- /dev/null +++ b/idea/resources/inspectionDescriptions/ExplicitGet.html @@ -0,0 +1,5 @@ + + +This inspection reports any explicit calls of 'get' which can be replaced by indexing operator [] + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index ce8ccfcb0cb..8012da58c76 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -623,6 +623,13 @@ org.jetbrains.jet.plugin.intentions.ConvertNegatedExpressionWithDemorgansLawIntention Kotlin + + org.jetbrains.jet.plugin.intentions.SwapBinaryExpression diff --git a/idea/src/org/jetbrains/jet/plugin/inspections/ExplicitGetInspection.kt b/idea/src/org/jetbrains/jet/plugin/inspections/ExplicitGetInspection.kt new file mode 100644 index 00000000000..3a8b0e05306 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/inspections/ExplicitGetInspection.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.lang.psi.* +import org.jetbrains.jet.plugin.intentions.attributeCallReplacements.ReplaceGetIntention + +public class ExplicitGetInspection : IntentionBasedInspection(ReplaceGetIntention()) \ No newline at end of file diff --git a/idea/testData/codeInsight/inspections/replaceGet/expected.xml b/idea/testData/codeInsight/inspections/replaceGet/expected.xml new file mode 100644 index 00000000000..e0440b9c359 --- /dev/null +++ b/idea/testData/codeInsight/inspections/replaceGet/expected.xml @@ -0,0 +1,10 @@ + + + main.kt + 3 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + \ No newline at end of file diff --git a/idea/testData/codeInsight/inspections/replaceGet/options.test b/idea/testData/codeInsight/inspections/replaceGet/options.test new file mode 100644 index 00000000000..c7faacf242f --- /dev/null +++ b/idea/testData/codeInsight/inspections/replaceGet/options.test @@ -0,0 +1 @@ +// INSPECTION_CLASS: org.jetbrains.jet.plugin.inspections.ExplicitGetInspection \ No newline at end of file diff --git a/idea/testData/codeInsight/inspections/replaceGet/src/main.kt b/idea/testData/codeInsight/inspections/replaceGet/src/main.kt new file mode 100644 index 00000000000..1d0f1ba3c10 --- /dev/null +++ b/idea/testData/codeInsight/inspections/replaceGet/src/main.kt @@ -0,0 +1,4 @@ +fun foo() { + val a = Array(10) { it } + println(a.get(5)) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java new file mode 100644 index 00000000000..96b9d918431 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java @@ -0,0 +1,38 @@ +/* + * 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.codeInsight; + +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.TestMetadata; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/codeInsight/inspections") +public class JetInspectionTestGenerated extends AbstractJetInspectionTest { + public void testAllFilesPresentInInspections() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/codeInsight/inspections"), Pattern.compile("^([^\\.]+)$"), false); + } + + @TestMetadata("replaceGet") + public void testReplaceGet() throws Exception { + doTest("idea/testData/codeInsight/inspections/replaceGet"); + } + +}