diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt index 58216816ff0..9e69e6701f5 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt @@ -60,7 +60,17 @@ public object ShortenReferences { process(listOf(file), { element -> if (rangeMarker.isValid()) { val range = TextRange(rangeMarker.getStartOffset(), rangeMarker.getEndOffset()) - val elementRange = element.getTextRange()!! + + var elementRange = element.getTextRange()!! + + // for qualified call expression take only the part without parenthesis + val calleeExpression = ((element as? JetDotQualifiedExpression) + ?.getSelectorExpression() as? JetCallExpression) + ?.getCalleeExpression() + if (calleeExpression != null) { + elementRange = TextRange(elementRange.getStartOffset(), calleeExpression.getTextRange()!!.getEndOffset()) + } + when { range.contains(elementRange) -> FilterResult.PROCESS range.intersects(elementRange) -> FilterResult.GO_INSIDE diff --git a/idea/testData/completion/handlers/ClassCompletionInMiddle.kt b/idea/testData/completion/handlers/ClassCompletionInMiddle.kt new file mode 100644 index 00000000000..d34d87e0de0 --- /dev/null +++ b/idea/testData/completion/handlers/ClassCompletionInMiddle.kt @@ -0,0 +1,5 @@ +import java.util.TimeZone + +fun foo() { + TimeZone() +} diff --git a/idea/testData/completion/handlers/ClassCompletionInMiddle.kt.after b/idea/testData/completion/handlers/ClassCompletionInMiddle.kt.after new file mode 100644 index 00000000000..1ed43f66071 --- /dev/null +++ b/idea/testData/completion/handlers/ClassCompletionInMiddle.kt.after @@ -0,0 +1,5 @@ +import java.util.TimeZone + +fun foo() { + TimeZone() +} diff --git a/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt b/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt new file mode 100644 index 00000000000..d901d1ccd2a --- /dev/null +++ b/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt @@ -0,0 +1 @@ +val x = java.util.Date(1) diff --git a/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt.after b/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt.after new file mode 100644 index 00000000000..f9e53eb2f09 --- /dev/null +++ b/idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt.after @@ -0,0 +1,3 @@ +import java.util.Date + +val x = Date(1) diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt index 46918dee26b..56225548d0e 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt +++ b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt @@ -26,6 +26,8 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){ fun testClassCompletionImport() = doTest(2, "SortedSet", null, '\n') + fun testClassCompletionInMiddle() = doTest(1, "TimeZone", " (java.util)", '\t') + fun testDoNotInsertImportForAlreadyImported() = doTest() fun testDoNotInsertDefaultJsImports() = doTest() diff --git a/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java b/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java index 3c1c1e5a1d8..abafceffd05 100644 --- a/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java @@ -16,17 +16,14 @@ package org.jetbrains.jet.shortenRefs; -import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestSuite; - -import java.io.File; -import java.util.regex.Pattern; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; -import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest; +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") @@ -113,6 +110,11 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { doTest("idea/testData/shortenRefs/constructor/NoImportNeeded3.kt"); } + @TestMetadata("WorksForClassNameRange.kt") + public void testWorksForClassNameRange() throws Exception { + doTest("idea/testData/shortenRefs/constructor/WorksForClassNameRange.kt"); + } + } @TestMetadata("idea/testData/shortenRefs/java")