Do not create expect / actual markers for parameters & enum entries
Part of KT-26957
This commit is contained in:
@@ -13,6 +13,7 @@ import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator
|
||||
import com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
||||
@@ -37,11 +38,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.isInheritable
|
||||
import org.jetbrains.kotlin.idea.core.isOverridable
|
||||
import org.jetbrains.kotlin.idea.core.toDescriptor
|
||||
import org.jetbrains.kotlin.idea.editor.fixers.startLine
|
||||
import org.jetbrains.kotlin.idea.presentation.DeclarationByModuleRenderer
|
||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.toPossiblyFakeLightMethods
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments
|
||||
import java.awt.event.MouseEvent
|
||||
import java.util.*
|
||||
@@ -340,11 +343,35 @@ private fun collectMultiplatformMarkers(
|
||||
}
|
||||
}
|
||||
|
||||
private fun Document?.areAnchorsOnOneLine(
|
||||
first: KtNamedDeclaration,
|
||||
second: KtNamedDeclaration?
|
||||
): Boolean {
|
||||
if (this == null || second == null) return false
|
||||
val firstAnchor = first.expectOrActualAnchor
|
||||
val secondAnchor = second.expectOrActualAnchor
|
||||
return firstAnchor.startLine(this) == secondAnchor.startLine(this)
|
||||
}
|
||||
|
||||
private fun KtNamedDeclaration.requiresNoMarkers(): Boolean {
|
||||
val document = PsiDocumentManager.getInstance(project).getDocument(containingFile)
|
||||
when (this) {
|
||||
is KtPrimaryConstructor -> {
|
||||
return true
|
||||
}
|
||||
is KtParameter,
|
||||
is KtEnumEntry -> if (document.areAnchorsOnOneLine(this, containingClassOrObject)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun collectActualMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
if (declaration is KtPrimaryConstructor) return
|
||||
if (declaration.requiresNoMarkers()) return
|
||||
|
||||
val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return
|
||||
val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||
@@ -374,7 +401,7 @@ private fun collectExpectedMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
if (declaration is KtPrimaryConstructor) return
|
||||
if (declaration.requiresNoMarkers()) return
|
||||
|
||||
val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return
|
||||
val platformModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// !CHECK_HIGHLIGHTING
|
||||
|
||||
expect class WithConstructor(x: Int, s: String) {
|
||||
val x: Int
|
||||
|
||||
val s: String
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
actual class <lineMarker>WithConstructor</lineMarker> actual constructor(actual val x: Int, actual val s: String)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// !CHECK_HIGHLIGHTING
|
||||
|
||||
package test
|
||||
|
||||
expect enum class Enum { A, B, C }
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
actual enum class <lineMarker>Enum</lineMarker> { A, B, C }
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
expect class <lineMarker>WithConstructor</lineMarker>(x: Int, s: String) {
|
||||
val <lineMarker>x</lineMarker>: Int
|
||||
|
||||
val <lineMarker>s</lineMarker>: String
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// !CHECK_HIGHLIGHTING
|
||||
|
||||
actual class WithConstructor actual constructor(actual val x: Int, actual val s: String)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
expect enum class <lineMarker>Enum</lineMarker> { A, B, C, D }
|
||||
@@ -0,0 +1,4 @@
|
||||
// !CHECK_HIGHLIGHTING
|
||||
package test
|
||||
|
||||
actual enum class Enum { A, B, C, D }
|
||||
Generated
+20
@@ -25,6 +25,11 @@ public class MultiModuleLineMarkerTestGenerated extends AbstractMultiModuleLineM
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("actualConstructorWithProperties")
|
||||
public void testActualConstructorWithProperties() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/actualConstructorWithProperties/");
|
||||
}
|
||||
|
||||
@TestMetadata("actualDerived")
|
||||
public void testActualDerived() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/actualDerived/");
|
||||
@@ -35,15 +40,30 @@ public class MultiModuleLineMarkerTestGenerated extends AbstractMultiModuleLineM
|
||||
runTest("idea/testData/multiModuleLineMarker/actualEnumEntries/");
|
||||
}
|
||||
|
||||
@TestMetadata("actualEnumEntriesInOneLine")
|
||||
public void testActualEnumEntriesInOneLine() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/actualEnumEntriesInOneLine/");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInMultiModuleLineMarker() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/multiModuleLineMarker"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("expectConstructorWithProperties")
|
||||
public void testExpectConstructorWithProperties() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/expectConstructorWithProperties/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectEnumEntries")
|
||||
public void testExpectEnumEntries() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/expectEnumEntries/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectEnumEntriesInOneLine")
|
||||
public void testExpectEnumEntriesInOneLine() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/expectEnumEntriesInOneLine/");
|
||||
}
|
||||
|
||||
@TestMetadata("fromActualAnnotation")
|
||||
public void testFromActualAnnotation() throws Exception {
|
||||
runTest("idea/testData/multiModuleLineMarker/fromActualAnnotation/");
|
||||
|
||||
Reference in New Issue
Block a user