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
-7
@@ -317,12 +317,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
var disableDefaultScriptingPlugin: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xapi-mode",
|
||||
valueDescription = "{enable|disable|migration}",
|
||||
description = "Enable api mode, force compiler to report errors an all public API declarations without explicit visibility.\n" +
|
||||
"Use 'migration' level to issue warnings instead of errors."
|
||||
value = "-Xexplicit-api",
|
||||
valueDescription = "{strict|warning|disable}",
|
||||
description = "Force compiler to report errors an all public API declarations without explicit visibility.\n" +
|
||||
"Use 'warning' level to issue warnings instead of errors."
|
||||
)
|
||||
var apiMode: String by FreezableVar(ApiMode.DISABLED.state)
|
||||
var explicitApi: String by FreezableVar(ExplicitApiMode.DISABLED.state)
|
||||
|
||||
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, Any>().apply {
|
||||
@@ -332,9 +332,9 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
put(AnalysisFlags.useExperimental, useExperimental?.toList().orEmpty())
|
||||
put(AnalysisFlags.explicitApiVersion, apiVersion != null)
|
||||
put(AnalysisFlags.allowResultReturnType, allowResultReturnType)
|
||||
ApiMode.fromString(apiMode)?.also { put(AnalysisFlags.apiMode, it) } ?: collector.report(
|
||||
ExplicitApiMode.fromString(explicitApi)?.also { put(AnalysisFlags.explicitApiMode, it) } ?: collector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"Unknown value for parameter -Xapi-mode: '$apiMode'. Value should be one of ${ApiMode.availableValues()}"
|
||||
"Unknown value for parameter -Xexplicit-api: '$explicitApi'. Value should be one of ${ExplicitApiMode.availableValues()}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ object AnalysisFlags {
|
||||
val allowResultReturnType by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@JvmStatic
|
||||
val apiMode by AnalysisFlag.Delegates.ApiModeDisabledByDefault
|
||||
val explicitApiMode by AnalysisFlag.Delegates.ApiModeDisabledByDefault
|
||||
|
||||
@JvmStatic
|
||||
val constraintSystemForOverloadResolution by AnalysisFlag.Delegates.ConstraintSystemForOverloadResolution
|
||||
|
||||
@@ -207,10 +207,10 @@ public interface Errors {
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> DEPRECATED_MODIFIER_FOR_TARGET = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken> DEPRECATED_MODIFIER = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> REDUNDANT_MODIFIER_FOR_TARGET = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory1<PsiElement, DeclarationDescriptor> NO_EXPLICIT_VISIBILITY_IN_API_MODE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> NO_EXPLICIT_RETURN_TYPE_IN_API_MODE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, DeclarationDescriptor> NO_EXPLICIT_VISIBILITY_IN_API_MODE_MIGRATION = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_MIGRATION = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory1<KtDeclaration, DeclarationDescriptor> NO_EXPLICIT_VISIBILITY_IN_API_MODE = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> NO_EXPLICIT_RETURN_TYPE_IN_API_MODE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory1<KtDeclaration, DeclarationDescriptor> NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> WRONG_MODIFIER_CONTAINING_DECLARATION = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> DEPRECATED_MODIFIER_CONTAINING_DECLARATION = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory1<PsiElement, KtModifierKeywordToken> ILLEGAL_INLINE_PARAMETER_MODIFIER = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+2
-2
@@ -121,8 +121,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(REDUNDANT_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is redundant for ''{1}''", TO_STRING, TO_STRING);
|
||||
MAP.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE, "Declaration ''{0}'' is effectively public API and API mode is on, but no visibility is specified", NAME);
|
||||
MAP.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE, "This declaration is effectively public API and API mode is on, but no explicit return type is specified");
|
||||
MAP.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE_MIGRATION, "Declaration ''{0}'' is effectively public API and API mode is on, but no visibility is specified", NAME);
|
||||
MAP.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_MIGRATION, "This declaration is effectively public API and API mode is on, but no explicit return type is specified");
|
||||
MAP.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING, "Declaration ''{0}'' is effectively public API and API mode is on, but no visibility is specified", NAME);
|
||||
MAP.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING, "This declaration is effectively public API and API mode is on, but no explicit return type is specified");
|
||||
MAP.put(WRONG_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is not applicable inside ''{1}''", TO_STRING, TO_STRING);
|
||||
MAP.put(DEPRECATED_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is deprecated inside ''{1}''", TO_STRING, TO_STRING);
|
||||
MAP.put(ILLEGAL_INLINE_PARAMETER_MODIFIER, "Modifier ''{0}'' is allowed only for function parameters of an inline function", TO_STRING);
|
||||
|
||||
@@ -32,7 +32,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf(
|
||||
ReservedMembersAndConstructsForInlineClass(),
|
||||
ResultClassInReturnTypeChecker(),
|
||||
LocalVariableTypeParametersChecker(),
|
||||
ApiModeDeclarationChecker(),
|
||||
ExplicitApiDeclarationChecker(),
|
||||
TailrecFunctionChecker,
|
||||
TrailingCommaDeclarationChecker
|
||||
)
|
||||
|
||||
+17
-16
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.resolve.checkers
|
||||
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.ApiMode
|
||||
import org.jetbrains.kotlin.config.ExplicitApiMode
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -15,13 +15,12 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifier
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyPublicApi
|
||||
|
||||
class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
class ExplicitApiDeclarationChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
val state = isEnabled(context.languageVersionSettings)
|
||||
if (state == ApiMode.DISABLED) return
|
||||
if (state == ExplicitApiMode.DISABLED) return
|
||||
|
||||
val isApi = (descriptor as? DeclarationDescriptorWithVisibility)?.isEffectivelyPublicApi ?: return
|
||||
if (!isApi) return
|
||||
@@ -31,7 +30,7 @@ class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
private fun checkVisibilityModifier(
|
||||
state: ApiMode,
|
||||
state: ExplicitApiMode,
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptorWithVisibility,
|
||||
context: DeclarationCheckerContext
|
||||
@@ -41,15 +40,15 @@ class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
|
||||
if (excludeForDiagnostic(descriptor)) return
|
||||
val diagnostic =
|
||||
if (state == ApiMode.ENABLED)
|
||||
if (state == ExplicitApiMode.STRICT)
|
||||
Errors.NO_EXPLICIT_VISIBILITY_IN_API_MODE.on(declaration, descriptor)
|
||||
else
|
||||
Errors.NO_EXPLICIT_VISIBILITY_IN_API_MODE_MIGRATION.on(declaration, descriptor)
|
||||
Errors.NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING.on(declaration, descriptor)
|
||||
context.trace.reportDiagnosticOnce(diagnostic)
|
||||
}
|
||||
|
||||
private fun checkExplicitReturnType(
|
||||
state: ApiMode,
|
||||
state: ExplicitApiMode,
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
context: DeclarationCheckerContext
|
||||
@@ -65,10 +64,10 @@ class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
)
|
||||
if (shouldReport) {
|
||||
val diagnostic =
|
||||
if (state == ApiMode.ENABLED)
|
||||
if (state == ExplicitApiMode.STRICT)
|
||||
Errors.NO_EXPLICIT_RETURN_TYPE_IN_API_MODE.on(declaration)
|
||||
else
|
||||
Errors.NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_MIGRATION
|
||||
Errors.NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING
|
||||
.on(declaration)
|
||||
context.trace.reportDiagnosticOnce(diagnostic)
|
||||
}
|
||||
@@ -77,8 +76,9 @@ class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
/**
|
||||
* Exclusion list:
|
||||
* 1. Primary constructors of public API classes
|
||||
* 3. Members of public API interfaces
|
||||
* 4. do not report overrides of public API? effectively, this means 'no report on overrides at all'
|
||||
* 2. Members of public API interfaces
|
||||
* 3. do not report overrides of public API? effectively, this means 'no report on overrides at all'
|
||||
* 4. Getters and setters (because getters can't change visibility and setter-only explicit visibility looks ugly)
|
||||
*
|
||||
* Do we need something like @PublicApiFile to disable (or invert) this inspection per-file?
|
||||
*/
|
||||
@@ -86,14 +86,15 @@ class ApiModeDeclarationChecker : DeclarationChecker {
|
||||
/* 1. */ if ((descriptor as? ClassConstructorDescriptor)?.isPrimary == true) return true
|
||||
val isMemberOfPublicInterface =
|
||||
(descriptor.containingDeclaration as? ClassDescriptor)?.let { DescriptorUtils.isInterface(it) && it.effectiveVisibility().publicApi }
|
||||
/* 3. */ if (descriptor is CallableDescriptor && isMemberOfPublicInterface == true) return true
|
||||
/* 4. */ if ((descriptor as? CallableDescriptor)?.overriddenDescriptors?.isNotEmpty() == true) return true
|
||||
/* 2. */ if (descriptor is CallableDescriptor && isMemberOfPublicInterface == true) return true
|
||||
/* 3. */ if ((descriptor as? CallableDescriptor)?.overriddenDescriptors?.isNotEmpty() == true) return true
|
||||
/* 4. */ if (descriptor is PropertyAccessorDescriptor) return true
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun isEnabled(settings: LanguageVersionSettings): ApiMode {
|
||||
return settings.getFlag(AnalysisFlags.apiMode)
|
||||
fun isEnabled(settings: LanguageVersionSettings): ExplicitApiMode {
|
||||
return settings.getFlag(AnalysisFlags.explicitApiMode)
|
||||
}
|
||||
|
||||
fun returnTypeRequired(
|
||||
+3
-3
@@ -11,9 +11,6 @@ where advanced options include:
|
||||
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||
-Xapi-mode={enable|disable|migration}
|
||||
Enable api mode, force compiler to report errors an all public API declarations without explicit visibility.
|
||||
Use 'migration' level to issue warnings instead of errors.
|
||||
-Xcheck-phase-conditions Check pre- and postconditions on phases
|
||||
-Xcheck-sticky-phase-conditions
|
||||
Run sticky condition checks on subsequent phases as well. Implies -Xcheck-phase-conditions
|
||||
@@ -29,6 +26,9 @@ where advanced options include:
|
||||
-Xdump-perf=<path> Dump detailed performance statistics to the specified file
|
||||
-Xeffect-system Enable experimental language feature: effect system
|
||||
-Xexperimental=<fq.name> Enable and propagate usages of experimental API for marker annotation with the given fully qualified name
|
||||
-Xexplicit-api={strict|warning|disable}
|
||||
Force compiler to report errors an all public API declarations without explicit visibility.
|
||||
Use 'warning' level to issue warnings instead of errors.
|
||||
-Xinline-classes Enable experimental inline classes
|
||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
|
||||
|
||||
+3
-3
@@ -70,9 +70,6 @@ where advanced options include:
|
||||
-Xuse-type-table Use type table in metadata serialization
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||
-Xapi-mode={enable|disable|migration}
|
||||
Enable api mode, force compiler to report errors an all public API declarations without explicit visibility.
|
||||
Use 'migration' level to issue warnings instead of errors.
|
||||
-Xcheck-phase-conditions Check pre- and postconditions on phases
|
||||
-Xcheck-sticky-phase-conditions
|
||||
Run sticky condition checks on subsequent phases as well. Implies -Xcheck-phase-conditions
|
||||
@@ -88,6 +85,9 @@ where advanced options include:
|
||||
-Xdump-perf=<path> Dump detailed performance statistics to the specified file
|
||||
-Xeffect-system Enable experimental language feature: effect system
|
||||
-Xexperimental=<fq.name> Enable and propagate usages of experimental API for marker annotation with the given fully qualified name
|
||||
-Xexplicit-api={strict|warning|disable}
|
||||
Force compiler to report errors an all public API declarations without explicit visibility.
|
||||
Use 'warning' level to issue warnings instead of errors.
|
||||
-Xinline-classes Enable experimental inline classes
|
||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
|
||||
|
||||
@@ -39,7 +39,7 @@ class AnalysisFlag<out T> internal constructor(
|
||||
}
|
||||
|
||||
object ApiModeDisabledByDefault {
|
||||
operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Delegate(property.name, ApiMode.DISABLED)
|
||||
operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Delegate(property.name, ExplicitApiMode.DISABLED)
|
||||
}
|
||||
|
||||
object ListOfStrings {
|
||||
|
||||
+4
-4
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
enum class ApiMode(val state: String) {
|
||||
enum class ExplicitApiMode(val state: String) {
|
||||
DISABLED("disable"),
|
||||
ENABLED("enable"),
|
||||
MIGRATION("migration");
|
||||
STRICT("strict"),
|
||||
WARNING("warning");
|
||||
|
||||
companion object {
|
||||
fun fromString(string: String): ApiMode? = values().find { it.state == string }
|
||||
fun fromString(string: String): ExplicitApiMode? = values().find { it.state == string }
|
||||
|
||||
fun availableValues() = values().joinToString(prefix = "{", postfix = "}") { it.state }
|
||||
}
|
||||
@@ -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