Explicit Api mode: Renamings after design discussions
Change CLI flag to -Xexplicit-api=strict|warning. 'Disable' state and 'mode' suffix are left out as implementation details. Change intention title to 'make X public explicitly' Do not report 'no explicit visibility' on property accessors Set DECLARATION_SIGNATURE as a range for report Rename internal diagnostic from _MIGRATION to _WARNING
This commit is contained in:
@@ -7,11 +7,11 @@ package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.ApiMode
|
||||
import org.jetbrains.kotlin.config.ExplicitApiMode
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.checkers.ApiModeDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExplicitApiDeclarationChecker
|
||||
import javax.swing.JComponent
|
||||
|
||||
class PublicApiImplicitTypeInspection(
|
||||
@@ -19,11 +19,11 @@ class PublicApiImplicitTypeInspection(
|
||||
@JvmField var reportPrivate: Boolean = false
|
||||
) : AbstractImplicitTypeInspection(
|
||||
{ element, inspection ->
|
||||
val shouldCheckForPublic = element.languageVersionSettings.getFlag(AnalysisFlags.apiMode) == ApiMode.DISABLED
|
||||
val shouldCheckForPublic = element.languageVersionSettings.getFlag(AnalysisFlags.explicitApiMode) == ExplicitApiMode.DISABLED
|
||||
val callableMemberDescriptor = element.resolveToDescriptorIfAny() as? CallableMemberDescriptor
|
||||
val forInternal = (inspection as PublicApiImplicitTypeInspection).reportInternal
|
||||
val forPrivate = inspection.reportPrivate
|
||||
ApiModeDeclarationChecker.returnTypeRequired(element, callableMemberDescriptor, shouldCheckForPublic, forInternal, forPrivate)
|
||||
ExplicitApiDeclarationChecker.returnTypeRequired(element, callableMemberDescriptor, shouldCheckForPublic, forInternal, forPrivate)
|
||||
}
|
||||
) {
|
||||
|
||||
|
||||
+2
-2
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.idea.inspections
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.ApiMode
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.config.ExplicitApiMode
|
||||
import org.jetbrains.kotlin.idea.core.implicitVisibility
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
class RedundantVisibilityModifierInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return declarationVisitor(fun(declaration: KtDeclaration) {
|
||||
val isInApiMode = declaration.languageVersionSettings.getFlag(AnalysisFlags.apiMode) != ApiMode.DISABLED
|
||||
val isInApiMode = declaration.languageVersionSettings.getFlag(AnalysisFlags.explicitApiMode) != ExplicitApiMode.DISABLED
|
||||
if (isInApiMode) return@declarationVisitor
|
||||
|
||||
if (declaration is KtPropertyAccessor && declaration.isGetter) return // There is a quick fix for REDUNDANT_MODIFIER_IN_GETTER
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.idea.util.getResolvableApproximations
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.checkers.ApiModeDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExplicitApiDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
@@ -51,7 +51,7 @@ class SpecifyTypeExplicitlyIntention : SelfTargetingRangeIntention<KtCallableDec
|
||||
), HighPriorityAction {
|
||||
|
||||
override fun applicabilityRange(element: KtCallableDeclaration): TextRange? {
|
||||
if (!ApiModeDeclarationChecker.returnTypeCheckIsApplicable(element)) return null
|
||||
if (!ExplicitApiDeclarationChecker.returnTypeCheckIsApplicable(element)) return null
|
||||
|
||||
text = if (element is KtFunction) "Specify return type explicitly" else "Specify type explicitly"
|
||||
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
@@ -44,8 +33,8 @@ import org.jetbrains.kotlin.resolve.ExposedVisibilityChecker
|
||||
|
||||
open class ChangeVisibilityFix(
|
||||
element: KtModifierListOwner,
|
||||
private val elementName: String,
|
||||
private val visibilityModifier: KtModifierKeywordToken,
|
||||
protected val elementName: String,
|
||||
protected val visibilityModifier: KtModifierKeywordToken,
|
||||
private val addImplicitVisibilityModifier: Boolean = false
|
||||
) : KotlinQuickFixAction<KtModifierListOwner>(element) {
|
||||
|
||||
@@ -97,6 +86,16 @@ open class ChangeVisibilityFix(
|
||||
}
|
||||
}
|
||||
|
||||
protected class ChangeToPublicExplicitlyFix(element: KtModifierListOwner, elementName: String) : ChangeVisibilityFix(
|
||||
element,
|
||||
elementName,
|
||||
KtTokens.PUBLIC_KEYWORD,
|
||||
addImplicitVisibilityModifier = true
|
||||
), HighPriorityAction {
|
||||
override fun getText() = "Make '$elementName' $visibilityModifier explicitly"
|
||||
override fun getFamilyName() = "Make $visibilityModifier explicitly"
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(
|
||||
declaration: KtModifierListOwner,
|
||||
@@ -124,11 +123,9 @@ open class ChangeVisibilityFix(
|
||||
val descriptor = factory.cast(diagnostic).a as? DeclarationDescriptorWithVisibility ?: return emptyList()
|
||||
val element = diagnostic.psiElement as? KtModifierListOwner ?: return emptyList()
|
||||
return listOf(
|
||||
ChangeVisibilityFix(
|
||||
ChangeToPublicExplicitlyFix(
|
||||
element,
|
||||
descriptor.name.asString(),
|
||||
KtTokens.PUBLIC_KEYWORD,
|
||||
addImplicitVisibilityModifier = true
|
||||
descriptor.name.asString()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
FORBIDDEN_BINARY_MOD.registerFactory(RenameModToRemFix.Factory)
|
||||
|
||||
NO_EXPLICIT_VISIBILITY_IN_API_MODE.registerFactory(ChangeVisibilityFix.SetExplicitVisibilityFactory)
|
||||
NO_EXPLICIT_VISIBILITY_IN_API_MODE_MIGRATION.registerFactory(ChangeVisibilityFix.SetExplicitVisibilityFactory)
|
||||
NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING.registerFactory(ChangeVisibilityFix.SetExplicitVisibilityFactory)
|
||||
NO_EXPLICIT_RETURN_TYPE_IN_API_MODE.registerActions(SpecifyTypeExplicitlyFix())
|
||||
NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_MIGRATION.registerActions(SpecifyTypeExplicitlyFix())
|
||||
NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING.registerActions(SpecifyTypeExplicitlyFix())
|
||||
|
||||
|
||||
UNRESOLVED_REFERENCE.registerFactory(ImportFix)
|
||||
|
||||
Reference in New Issue
Block a user