New J2K: don't allow open modifier on top-level/private declarations
This commit is contained in:
@@ -177,6 +177,7 @@ private val removeRedundantElementsProcessingGroup =
|
|||||||
RemoveExplicitTypeArgumentsProcessing(),
|
RemoveExplicitTypeArgumentsProcessing(),
|
||||||
RemoveJavaStreamsCollectCallTypeArgumentsProcessing(),
|
RemoveJavaStreamsCollectCallTypeArgumentsProcessing(),
|
||||||
ExplicitThisInspectionBasedProcessing(),
|
ExplicitThisInspectionBasedProcessing(),
|
||||||
|
RemoveOpenModifierOnTopLevelDeclarationsProcessing(),
|
||||||
intentionBasedProcessing(RemoveEmptyClassBodyIntention())
|
intentionBasedProcessing(RemoveEmptyClassBodyIntention())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
+12
@@ -504,3 +504,15 @@ class MoveLambdaOutsideParenthesesProcessing :
|
|||||||
element.moveFunctionLiteralOutsideParentheses()
|
element.moveFunctionLiteralOutsideParentheses()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RemoveOpenModifierOnTopLevelDeclarationsProcessing :
|
||||||
|
InspectionLikeProcessingForElement<KtDeclaration>(KtDeclaration::class.java) {
|
||||||
|
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean =
|
||||||
|
element.hasModifier(KtTokens.OPEN_KEYWORD)
|
||||||
|
&& (element is KtFunction || element is KtProperty)
|
||||||
|
&& element.parent is KtFile
|
||||||
|
|
||||||
|
override fun apply(element: KtDeclaration) {
|
||||||
|
element.removeModifier(KtTokens.OPEN_KEYWORD)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ class ModalityConversion(context: NewJ2kConverterContext) : RecursiveApplicableC
|
|||||||
val psi = method.psi<PsiMethod>() ?: return
|
val psi = method.psi<PsiMethod>() ?: return
|
||||||
val containingClass = method.parentOfType<JKClass>() ?: return
|
val containingClass = method.parentOfType<JKClass>() ?: return
|
||||||
when {
|
when {
|
||||||
|
method.visibility == Visibility.PRIVATE -> {
|
||||||
|
method.modality = Modality.FINAL
|
||||||
|
}
|
||||||
method.modality != Modality.ABSTRACT
|
method.modality != Modality.ABSTRACT
|
||||||
&& psi.findSuperMethods().isNotEmpty() -> {
|
&& psi.findSuperMethods().isNotEmpty() -> {
|
||||||
method.modality = Modality.FINAL
|
method.modality = Modality.FINAL
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
fun x() {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
<selection>void x() {}</selection>
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<caret>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
private fun x() {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
<selection>private void x() {}</selection>
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<caret>
|
||||||
+10
@@ -183,6 +183,16 @@ public class NewJavaToKotlinCopyPasteConversionTestGenerated extends AbstractNew
|
|||||||
runTest("nj2k/testData/copyPaste/OnlyQualifier.java");
|
runTest("nj2k/testData/copyPaste/OnlyQualifier.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("OpenPublicFunctionToTopLevel.java")
|
||||||
|
public void testOpenPublicFunctionToTopLevel() throws Exception {
|
||||||
|
runTest("nj2k/testData/copyPaste/OpenPublicFunctionToTopLevel.java");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PrivateFunctionToTopLevel.java")
|
||||||
|
public void testPrivateFunctionToTopLevel() throws Exception {
|
||||||
|
runTest("nj2k/testData/copyPaste/PrivateFunctionToTopLevel.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("RawTypeRef.java")
|
@TestMetadata("RawTypeRef.java")
|
||||||
public void testRawTypeRef() throws Exception {
|
public void testRawTypeRef() throws Exception {
|
||||||
runTest("nj2k/testData/copyPaste/RawTypeRef.java");
|
runTest("nj2k/testData/copyPaste/RawTypeRef.java");
|
||||||
|
|||||||
Reference in New Issue
Block a user