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 =
|
||||
InspectionLikeProcessingGroup(
|
||||
RemoveRedundantVisibilityModifierProcessing(),
|
||||
RemoveRedundantModalityModifierProcessing(),
|
||||
RemoveRedundantConstructorKeywordProcessing(),
|
||||
RemoveExplicitOpenInInterfaceProcessing(),
|
||||
generalInspectionBasedProcessing(ExplicitThisInspection()),
|
||||
@@ -174,7 +182,6 @@ private val inspectionLikePostProcessingGroup =
|
||||
inspectionBasedProcessing(IfThenToElvisInspection(highlightStatement = true)),
|
||||
inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()),
|
||||
inspectionBasedProcessing(ReplaceGetOrSetInspection()),
|
||||
inspectionBasedProcessing(AddOperatorModifierInspection()),
|
||||
intentionBasedProcessing(ObjectLiteralToLambdaIntention()),
|
||||
intentionBasedProcessing(AnonymousFunctionToLambdaIntention()),
|
||||
intentionBasedProcessing(RemoveUnnecessaryParenthesesIntention()),
|
||||
@@ -226,6 +233,7 @@ private val processings: List<NamedPostProcessingGroup> = listOf(
|
||||
"Cleaning up Kotlin code",
|
||||
listOf(
|
||||
errorsFixingDiagnosticBasedPostProcessingGroup,
|
||||
addOrRemoveModifiersInspectionProcessing,
|
||||
inspectionLikePostProcessingGroup,
|
||||
cleaningUpDiagnosticBasedPostProcessingGroup
|
||||
)
|
||||
|
||||
+8
-4
@@ -32,11 +32,14 @@ import kotlin.reflect.KClass
|
||||
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)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
@@ -90,7 +94,7 @@ class InspectionLikeProcessingGroup(val inspectionLikeProcessings: List<Inspecti
|
||||
super.visitElement(element)
|
||||
|
||||
if (rangeResult == RangeFilterResult.PROCESS) {
|
||||
inspectionLikeProcessings.forEach { processing ->
|
||||
processings.forEach { processing ->
|
||||
val action = processing.createAction(element, context.converter.settings)
|
||||
if (action != null) {
|
||||
availableActions.add(
|
||||
|
||||
+13
-15
@@ -317,11 +317,11 @@ class RemoveRedundantConstructorKeywordProcessing :
|
||||
|
||||
class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
||||
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean {
|
||||
val modalityModifier = element.modalityModifier() ?: return false
|
||||
val modalityModifierType = modalityModifier.node.elementType
|
||||
val implicitModality = element.implicitModality()
|
||||
|
||||
return modalityModifierType == implicitModality
|
||||
if (element.hasModifier(KtTokens.FINAL_KEYWORD)) {
|
||||
return !element.hasModifier(KtTokens.OVERRIDE_KEYWORD)
|
||||
}
|
||||
val modalityModifierType = element.modalityModifierType() ?: return false
|
||||
return modalityModifierType == element.implicitModality()
|
||||
}
|
||||
|
||||
override fun apply(element: KtDeclaration) {
|
||||
@@ -331,16 +331,14 @@ class RemoveRedundantModalityModifierProcessing : ApplicabilityBasedInspectionLi
|
||||
|
||||
|
||||
class RemoveRedundantVisibilityModifierProcessing : ApplicabilityBasedInspectionLikeProcessing<KtDeclaration>(KtDeclaration::class) {
|
||||
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?): Boolean {
|
||||
val visibilityModifier = element.visibilityModifier() ?: return false
|
||||
val implicitVisibility = element.implicitVisibility()
|
||||
return when {
|
||||
visibilityModifier.node.elementType == implicitVisibility ->
|
||||
true
|
||||
element.hasModifier(KtTokens.INTERNAL_KEYWORD) && element.containingClassOrObject?.isLocal == true ->
|
||||
true
|
||||
else -> false
|
||||
}
|
||||
override fun isApplicableTo(element: KtDeclaration, settings: ConverterSettings?) = when {
|
||||
element.hasModifier(KtTokens.PUBLIC_KEYWORD) && element.hasModifier(KtTokens.OVERRIDE_KEYWORD) ->
|
||||
false
|
||||
element.hasModifier(KtTokens.INTERNAL_KEYWORD) && element.containingClassOrObject?.isLocal == true ->
|
||||
true
|
||||
element.visibilityModifierType() == element.implicitVisibility() ->
|
||||
true
|
||||
else -> false
|
||||
}
|
||||
|
||||
override fun apply(element: KtDeclaration) {
|
||||
|
||||
Reference in New Issue
Block a user