New J2K: run add/remove modifiers post-processings only single time && do not call resolve in them for some corner cases
This commit is contained in:
+11
-3
@@ -133,10 +133,18 @@ private val errorsFixingDiagnosticBasedPostProcessingGroup =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
private val addOrRemoveModifiersInspectionProcessing =
|
||||||
|
InspectionLikeProcessingGroup(
|
||||||
|
runSingleTime = true,
|
||||||
|
processings = listOf(
|
||||||
|
RemoveRedundantVisibilityModifierProcessing(),
|
||||||
|
RemoveRedundantModalityModifierProcessing(),
|
||||||
|
inspectionBasedProcessing(AddOperatorModifierInspection())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
private val inspectionLikePostProcessingGroup =
|
private val inspectionLikePostProcessingGroup =
|
||||||
InspectionLikeProcessingGroup(
|
InspectionLikeProcessingGroup(
|
||||||
RemoveRedundantVisibilityModifierProcessing(),
|
|
||||||
RemoveRedundantModalityModifierProcessing(),
|
|
||||||
RemoveRedundantConstructorKeywordProcessing(),
|
RemoveRedundantConstructorKeywordProcessing(),
|
||||||
RemoveExplicitOpenInInterfaceProcessing(),
|
RemoveExplicitOpenInInterfaceProcessing(),
|
||||||
generalInspectionBasedProcessing(ExplicitThisInspection()),
|
generalInspectionBasedProcessing(ExplicitThisInspection()),
|
||||||
@@ -174,7 +182,6 @@ private val inspectionLikePostProcessingGroup =
|
|||||||
inspectionBasedProcessing(IfThenToElvisInspection(highlightStatement = true)),
|
inspectionBasedProcessing(IfThenToElvisInspection(highlightStatement = true)),
|
||||||
inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()),
|
inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()),
|
||||||
inspectionBasedProcessing(ReplaceGetOrSetInspection()),
|
inspectionBasedProcessing(ReplaceGetOrSetInspection()),
|
||||||
inspectionBasedProcessing(AddOperatorModifierInspection()),
|
|
||||||
intentionBasedProcessing(ObjectLiteralToLambdaIntention()),
|
intentionBasedProcessing(ObjectLiteralToLambdaIntention()),
|
||||||
intentionBasedProcessing(AnonymousFunctionToLambdaIntention()),
|
intentionBasedProcessing(AnonymousFunctionToLambdaIntention()),
|
||||||
intentionBasedProcessing(RemoveUnnecessaryParenthesesIntention()),
|
intentionBasedProcessing(RemoveUnnecessaryParenthesesIntention()),
|
||||||
@@ -226,6 +233,7 @@ private val processings: List<NamedPostProcessingGroup> = listOf(
|
|||||||
"Cleaning up Kotlin code",
|
"Cleaning up Kotlin code",
|
||||||
listOf(
|
listOf(
|
||||||
errorsFixingDiagnosticBasedPostProcessingGroup,
|
errorsFixingDiagnosticBasedPostProcessingGroup,
|
||||||
|
addOrRemoveModifiersInspectionProcessing,
|
||||||
inspectionLikePostProcessingGroup,
|
inspectionLikePostProcessingGroup,
|
||||||
cleaningUpDiagnosticBasedPostProcessingGroup
|
cleaningUpDiagnosticBasedPostProcessingGroup
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-4
@@ -32,11 +32,14 @@ import kotlin.reflect.KClass
|
|||||||
import kotlin.reflect.full.isSubclassOf
|
import kotlin.reflect.full.isSubclassOf
|
||||||
|
|
||||||
|
|
||||||
class InspectionLikeProcessingGroup(val inspectionLikeProcessings: List<InspectionLikeProcessing>) : ProcessingGroup {
|
class InspectionLikeProcessingGroup(
|
||||||
|
private val runSingleTime: Boolean = false,
|
||||||
|
private val processings: List<InspectionLikeProcessing>
|
||||||
|
) : ProcessingGroup {
|
||||||
|
|
||||||
constructor(vararg inspectionLikeProcessings: InspectionLikeProcessing) : this(inspectionLikeProcessings.toList())
|
constructor(vararg processings: InspectionLikeProcessing) : this(false, processings.toList())
|
||||||
|
|
||||||
private val processingsToPriorityMap = inspectionLikeProcessings.mapToIndex()
|
private val processingsToPriorityMap = processings.mapToIndex()
|
||||||
fun priority(processing: InspectionLikeProcessing): Int = processingsToPriorityMap.getValue(processing)
|
fun priority(processing: InspectionLikeProcessing): Int = processingsToPriorityMap.getValue(processing)
|
||||||
|
|
||||||
override suspend fun runProcessing(file: KtFile, rangeMarker: RangeMarker?, converterContext: NewJ2kConverterContext) {
|
override suspend fun runProcessing(file: KtFile, rangeMarker: RangeMarker?, converterContext: NewJ2kConverterContext) {
|
||||||
@@ -62,6 +65,7 @@ class InspectionLikeProcessingGroup(val inspectionLikeProcessings: List<Inspecti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (runSingleTime) break
|
||||||
} while (modificationStamp != file.modificationStamp && elementToActions.isNotEmpty())
|
} while (modificationStamp != file.modificationStamp && elementToActions.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +94,7 @@ class InspectionLikeProcessingGroup(val inspectionLikeProcessings: List<Inspecti
|
|||||||
super.visitElement(element)
|
super.visitElement(element)
|
||||||
|
|
||||||
if (rangeResult == RangeFilterResult.PROCESS) {
|
if (rangeResult == RangeFilterResult.PROCESS) {
|
||||||
inspectionLikeProcessings.forEach { processing ->
|
processings.forEach { processing ->
|
||||||
val action = processing.createAction(element, context.converter.settings)
|
val action = processing.createAction(element, context.converter.settings)
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
availableActions.add(
|
availableActions.add(
|
||||||
|
|||||||
+13
-15
@@ -317,11 +317,11 @@ class RemoveRedundantConstructorKeywordProcessing :
|
|||||||
|
|
||||||
class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
||||||
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean {
|
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean {
|
||||||
val modalityModifier = element.modalityModifier() ?: return false
|
if (element.hasModifier(KtTokens.FINAL_KEYWORD)) {
|
||||||
val modalityModifierType = modalityModifier.node.elementType
|
return !element.hasModifier(KtTokens.OVERRIDE_KEYWORD)
|
||||||
val implicitModality = element.implicitModality()
|
}
|
||||||
|
val modalityModifierType = element.modalityModifierType() ?: return false
|
||||||
return modalityModifierType == implicitModality
|
return modalityModifierType == element.implicitModality()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(element: KtDeclaration) {
|
override fun apply(element: KtDeclaration) {
|
||||||
@@ -331,16 +331,14 @@ class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLi
|
|||||||
|
|
||||||
|
|
||||||
class RemoveRedundantVisibilityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
class RemoveRedundantVisibilityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
||||||
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean {
|
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?) = when {
|
||||||
val visibilityModifier = element.visibilityModifier() ?: return false
|
element.hasModifier(KtTokens.PUBLIC_KEYWORD) && element.hasModifier(KtTokens.OVERRIDE_KEYWORD) ->
|
||||||
val implicitVisibility = element.implicitVisibility()
|
false
|
||||||
return when {
|
element.hasModifier(KtTokens.INTERNAL_KEYWORD) && element.containingClassOrObject?.isLocal == true ->
|
||||||
visibilityModifier.node.elementType == implicitVisibility ->
|
true
|
||||||
true
|
element.visibilityModifierType() == element.implicitVisibility() ->
|
||||||
element.hasModifier(KtTokens.INTERNAL_KEYWORD) && element.containingClassOrObject?.isLocal == true ->
|
true
|
||||||
true
|
else -> false
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(element: KtDeclaration) {
|
override fun apply(element: KtDeclaration) {
|
||||||
|
|||||||
Reference in New Issue
Block a user