js: cleanup 'public', property access syntax
This commit is contained in:
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.types.DynamicTypesAllowed
|
||||
|
||||
public fun createTopDownAnalyzerForJs(
|
||||
fun createTopDownAnalyzerForJs(
|
||||
moduleContext: ModuleContext,
|
||||
bindingTrace: BindingTrace,
|
||||
declarationProviderFactory: DeclarationProviderFactory
|
||||
|
||||
@@ -18,14 +18,14 @@ package org.jetbrains.kotlin.js
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
public enum class PredefinedAnnotation(fqName: String) {
|
||||
enum class PredefinedAnnotation(fqName: String) {
|
||||
LIBRARY("kotlin.js.library"),
|
||||
NATIVE("kotlin.js.native"),
|
||||
NATIVE_INVOKE("kotlin.js.nativeInvoke"),
|
||||
NATIVE_GETTER("kotlin.js.nativeGetter"),
|
||||
NATIVE_SETTER("kotlin.js.nativeSetter");
|
||||
|
||||
public val fqName: FqName = FqName(fqName)
|
||||
val fqName: FqName = FqName(fqName)
|
||||
|
||||
companion object {
|
||||
val WITH_CUSTOM_NAME = setOf(LIBRARY, NATIVE)
|
||||
|
||||
@@ -33,27 +33,27 @@ import org.jetbrains.kotlin.resolve.diagnostics.SuppressDiagnosticsByAnnotations
|
||||
|
||||
private val NATIVE_ANNOTATIONS = arrayOf(NATIVE.fqName, NATIVE_INVOKE.fqName, NATIVE_GETTER.fqName, NATIVE_SETTER.fqName)
|
||||
|
||||
public class SuppressUnusedParameterForJsNative : SuppressDiagnosticsByAnnotations(listOf(Errors.UNUSED_PARAMETER), *NATIVE_ANNOTATIONS)
|
||||
class SuppressUnusedParameterForJsNative : SuppressDiagnosticsByAnnotations(listOf(Errors.UNUSED_PARAMETER), *NATIVE_ANNOTATIONS)
|
||||
|
||||
public class SuppressNoBodyErrorsForNativeDeclarations : SuppressDiagnosticsByAnnotations(FUNCTION_NO_BODY_ERRORS + PROPERTY_NOT_INITIALIZED_ERRORS, *NATIVE_ANNOTATIONS)
|
||||
class SuppressNoBodyErrorsForNativeDeclarations : SuppressDiagnosticsByAnnotations(FUNCTION_NO_BODY_ERRORS + PROPERTY_NOT_INITIALIZED_ERRORS, *NATIVE_ANNOTATIONS)
|
||||
|
||||
public class SuppressUninitializedErrorsForNativeDeclarations : DiagnosticSuppressor {
|
||||
class SuppressUninitializedErrorsForNativeDeclarations : DiagnosticSuppressor {
|
||||
override fun isSuppressed(diagnostic: Diagnostic): Boolean {
|
||||
if (diagnostic.getFactory() != Errors.UNINITIALIZED_VARIABLE) return false
|
||||
if (diagnostic.factory != Errors.UNINITIALIZED_VARIABLE) return false
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<KtSimpleNameExpression, VariableDescriptor>
|
||||
|
||||
val variableDescriptor = diagnosticWithParameters.getA()
|
||||
val variableDescriptor = diagnosticWithParameters.a
|
||||
|
||||
return AnnotationsUtils.isNativeObject(variableDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
public class SuppressWarningsFromExternalModules : DiagnosticSuppressor {
|
||||
class SuppressWarningsFromExternalModules : DiagnosticSuppressor {
|
||||
override fun isSuppressed(diagnostic: Diagnostic): Boolean {
|
||||
val file = diagnostic.getPsiFile()
|
||||
return diagnostic.getSeverity() == Severity.WARNING &&
|
||||
val file = diagnostic.psiFile
|
||||
return diagnostic.severity == Severity.WARNING &&
|
||||
file is KtFile && file.getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME) != null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,13 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
|
||||
public class JsAnalysisResult(
|
||||
public val bindingTrace: BindingTrace,
|
||||
class JsAnalysisResult(
|
||||
val bindingTrace: BindingTrace,
|
||||
moduleDescriptor: ModuleDescriptor
|
||||
) : AnalysisResult(bindingTrace.getBindingContext(), moduleDescriptor) {
|
||||
) : AnalysisResult(bindingTrace.bindingContext, moduleDescriptor) {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
public fun success(trace: BindingTrace, module: ModuleDescriptor): JsAnalysisResult {
|
||||
@JvmStatic fun success(trace: BindingTrace, module: ModuleDescriptor): JsAnalysisResult {
|
||||
return JsAnalysisResult(trace, module)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,28 +24,28 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public val KotlinType.nameIfStandardType: Name?
|
||||
val KotlinType.nameIfStandardType: Name?
|
||||
get() {
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
val descriptor = constructor.declarationDescriptor
|
||||
|
||||
if (descriptor?.getContainingDeclaration() == descriptor?.builtIns?.getBuiltInsPackageFragment()) {
|
||||
return descriptor?.getName()
|
||||
if (descriptor?.containingDeclaration == descriptor?.builtIns?.builtInsPackageFragment) {
|
||||
return descriptor?.name
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
public fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
val declaration = requireNotNull(getConstructor().getDeclarationDescriptor())
|
||||
fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
val declaration = requireNotNull(constructor.declarationDescriptor)
|
||||
if (declaration is TypeParameterDescriptor) {
|
||||
return StringUtil.join(declaration.getUpperBounds(), { type -> type.getJetTypeFqName(printTypeArguments) }, "&")
|
||||
return StringUtil.join(declaration.upperBounds, { type -> type.getJetTypeFqName(printTypeArguments) }, "&")
|
||||
}
|
||||
|
||||
val typeArguments = getArguments()
|
||||
val typeArguments = arguments
|
||||
val typeArgumentsAsString: String
|
||||
|
||||
if (printTypeArguments && !typeArguments.isEmpty()) {
|
||||
val joinedTypeArguments = StringUtil.join(typeArguments, { projection -> projection.getType().getJetTypeFqName(false) }, ", ")
|
||||
val joinedTypeArguments = StringUtil.join(typeArguments, { projection -> projection.type.getJetTypeFqName(false) }, ", ")
|
||||
|
||||
typeArgumentsAsString = "<" + joinedTypeArguments + ">"
|
||||
} else {
|
||||
@@ -55,4 +55,4 @@ public fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
return DescriptorUtils.getFqName(declaration).asString() + typeArgumentsAsString
|
||||
}
|
||||
|
||||
public fun ClassDescriptor.hasPrimaryConstructor(): Boolean = getUnsubstitutedPrimaryConstructor() != null
|
||||
fun ClassDescriptor.hasPrimaryConstructor(): Boolean = unsubstitutedPrimaryConstructor != null
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
|
||||
public object JsPlatform : TargetPlatform("JS") {
|
||||
object JsPlatform : TargetPlatform("JS") {
|
||||
override val defaultModuleParameters = object : ModuleParameters {
|
||||
override val defaultImports: List<ImportPath> = ImmutableList.of(
|
||||
ImportPath("java.lang.*"),
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.types.DynamicTypesAllowed
|
||||
|
||||
public object JsPlatformConfigurator : PlatformConfigurator(
|
||||
object JsPlatformConfigurator : PlatformConfigurator(
|
||||
DynamicTypesAllowed(),
|
||||
additionalDeclarationCheckers = listOf(NativeInvokeChecker(), NativeGetterChecker(), NativeSetterChecker(), ClassDeclarationChecker()),
|
||||
additionalCallCheckers = listOf(),
|
||||
|
||||
+1
-1
@@ -42,6 +42,6 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultErrorMessagesJs : DefaultErrorMessages.Extension {
|
||||
class DefaultErrorMessagesJs : DefaultErrorMessages.Extension {
|
||||
override fun getMap(): DiagnosticFactoryToRendererMap = DIAGNOSTIC_FACTORY_TO_RENDERER
|
||||
}
|
||||
|
||||
@@ -46,21 +46,19 @@ import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
public class JsCallChecker(
|
||||
class JsCallChecker(
|
||||
private val constantExpressionEvaluator: ConstantExpressionEvaluator
|
||||
) : CallChecker {
|
||||
|
||||
companion object {
|
||||
private val JS_PATTERN: DescriptorPredicate = PatternBuilder.pattern("kotlin.js.js(String)")
|
||||
|
||||
@JvmStatic
|
||||
public fun <F : CallableDescriptor?> ResolvedCall<F>.isJsCall(): Boolean {
|
||||
val descriptor = getResultingDescriptor()
|
||||
@JvmStatic fun <F : CallableDescriptor?> ResolvedCall<F>.isJsCall(): Boolean {
|
||||
val descriptor = resultingDescriptor
|
||||
return descriptor is SimpleFunctionDescriptor && JS_PATTERN.apply(descriptor)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun extractStringValue(compileTimeConstant: CompileTimeConstant<*>?): String? {
|
||||
@JvmStatic fun extractStringValue(compileTimeConstant: CompileTimeConstant<*>?): String? {
|
||||
return ((compileTimeConstant as? TypedCompileTimeConstant<*>)?.constantValue as? StringValue)?.value
|
||||
}
|
||||
}
|
||||
@@ -68,10 +66,10 @@ public class JsCallChecker(
|
||||
override fun <F : CallableDescriptor> check(resolvedCall: ResolvedCall<F>, context: BasicCallResolutionContext) {
|
||||
if (context.isAnnotationContext || !resolvedCall.isJsCall()) return
|
||||
|
||||
val expression = resolvedCall.getCall().getCallElement()
|
||||
val expression = resolvedCall.call.callElement
|
||||
if (expression !is KtCallExpression) return
|
||||
|
||||
val arguments = expression.getValueArgumentList()?.getArguments()
|
||||
val arguments = expression.valueArgumentList?.arguments
|
||||
val argument = arguments?.firstOrNull()?.getArgumentExpression() ?: return
|
||||
|
||||
val trace = TemporaryBindingTrace.create(context.trace, "JsCallChecker")
|
||||
@@ -127,7 +125,7 @@ class JsCodeErrorReporter(
|
||||
JsCallData(reportRange, message)
|
||||
}
|
||||
else -> {
|
||||
val reportRange = nodeToReport.getTextRange()
|
||||
val reportRange = nodeToReport.textRange
|
||||
val codeRange = TextRange(code.offsetOf(startPosition), code.offsetOf(endPosition))
|
||||
JsCallDataWithCode(reportRange, message, code, codeRange)
|
||||
}
|
||||
@@ -139,8 +137,8 @@ class JsCodeErrorReporter(
|
||||
|
||||
private val CodePosition.absoluteOffset: Int
|
||||
get() {
|
||||
val quotesLength = nodeToReport.getFirstChild().getTextLength()
|
||||
return nodeToReport.getTextOffset() + quotesLength + code.offsetOf(this)
|
||||
val quotesLength = nodeToReport.firstChild.textLength
|
||||
return nodeToReport.textOffset + quotesLength + code.offsetOf(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +172,7 @@ private fun String.offsetOf(position: CodePosition): Int {
|
||||
}
|
||||
|
||||
private val KtExpression.isConstantStringLiteral: Boolean
|
||||
get() = this is KtStringTemplateExpression && getEntries().all { it is KtLiteralStringTemplateEntry }
|
||||
get() = this is KtStringTemplateExpression && entries.all { it is KtLiteralStringTemplateEntry }
|
||||
|
||||
open class JsCallData(val reportRange: TextRange, val message: String)
|
||||
|
||||
|
||||
+2
-2
@@ -26,11 +26,11 @@ import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallData
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
||||
|
||||
public object JsCodePositioningStrategy : PositioningStrategy<PsiElement>() {
|
||||
object JsCodePositioningStrategy : PositioningStrategy<PsiElement>() {
|
||||
override fun markDiagnostic(diagnostic: ParametrizedDiagnostic<out PsiElement>): List<TextRange> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<KtExpression, JsCallData>
|
||||
val textRange = diagnosticWithParameters.getA().reportRange
|
||||
val textRange = diagnosticWithParameters.a.reportRange
|
||||
return listOf(textRange)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.renderer.Renderer
|
||||
|
||||
object RenderFirstLineOfElementText : Renderer<PsiElement> {
|
||||
override fun render(element: PsiElement): String {
|
||||
val text = element.getText()
|
||||
val text = element.text
|
||||
val index = text.indexOf('\n')
|
||||
return if (index == -1) text else text.substring(0, index) + "..."
|
||||
}
|
||||
@@ -42,15 +42,15 @@ abstract class JsCallDataRenderer : Renderer<JsCallData> {
|
||||
object JsCallDataTextRenderer : JsCallDataRenderer() {
|
||||
override fun format(data: JsCallDataWithCode): String {
|
||||
val codeRange = data.codeRange
|
||||
val code = data.code.underlineAsText(codeRange.getStartOffset(), codeRange.getEndOffset())
|
||||
val code = data.code.underlineAsText(codeRange.startOffset, codeRange.endOffset)
|
||||
return "${data.message} in code:\n${code}"
|
||||
}
|
||||
}
|
||||
|
||||
public object JsCallDataHtmlRenderer : JsCallDataRenderer() {
|
||||
object JsCallDataHtmlRenderer : JsCallDataRenderer() {
|
||||
override fun format(data: JsCallDataWithCode): String {
|
||||
val codeRange = data.codeRange
|
||||
val code = data.code.underlineAsHtml(codeRange.getStartOffset(), codeRange.getEndOffset())
|
||||
val code = data.code.underlineAsHtml(codeRange.startOffset, codeRange.endOffset)
|
||||
return "${data.message} in code:<br><pre>${code}</pre>"
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public object JsCallDataHtmlRenderer : JsCallDataRenderer() {
|
||||
* var = 10;
|
||||
* ^^^^
|
||||
*/
|
||||
public fun String.underlineAsText(from: Int, to: Int): String {
|
||||
fun String.underlineAsText(from: Int, to: Int): String {
|
||||
val lines = StringBuilder()
|
||||
var marks = StringBuilder()
|
||||
var lineWasMarked = false
|
||||
@@ -98,7 +98,7 @@ public fun String.underlineAsText(from: Int, to: Int): String {
|
||||
return lines.toString()
|
||||
}
|
||||
|
||||
public fun String.underlineAsHtml(from: Int, to: Int): String {
|
||||
fun String.underlineAsHtml(from: Int, to: Int): String {
|
||||
val lines = StringBuilder()
|
||||
var openMarker = false
|
||||
val underlineStart = "<u>"
|
||||
|
||||
@@ -44,19 +44,19 @@ internal abstract class AbstractNativeAnnotationsChecker(private val requiredAnn
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val annotationDescriptor = descriptor.getAnnotations().findAnnotation(requiredAnnotation.fqName) ?: return
|
||||
val annotationDescriptor = descriptor.annotations.findAnnotation(requiredAnnotation.fqName) ?: return
|
||||
|
||||
if (declaration !is KtNamedFunction || descriptor !is FunctionDescriptor) {
|
||||
return
|
||||
}
|
||||
|
||||
val isMember = !DescriptorUtils.isTopLevelDeclaration(descriptor) && descriptor.getVisibility() != Visibilities.LOCAL
|
||||
val isMember = !DescriptorUtils.isTopLevelDeclaration(descriptor) && descriptor.visibility != Visibilities.LOCAL
|
||||
val isExtension = DescriptorUtils.isExtension(descriptor)
|
||||
|
||||
if (isMember && (isExtension || !AnnotationsUtils.isNativeObject(descriptor)) ||
|
||||
!isMember && !isExtension
|
||||
) {
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.getType()))
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.type))
|
||||
}
|
||||
|
||||
additionalCheck(declaration, descriptor, diagnosticHolder)
|
||||
@@ -72,14 +72,14 @@ internal abstract class AbstractNativeIndexerChecker(
|
||||
) : AbstractNativeAnnotationsChecker(requiredAnnotation) {
|
||||
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
val parameters = descriptor.getValueParameters()
|
||||
val parameters = descriptor.valueParameters
|
||||
val builtIns = descriptor.builtIns
|
||||
if (parameters.size > 0) {
|
||||
val firstParamClassDescriptor = DescriptorUtils.getClassDescriptorForType(parameters.get(0).getType())
|
||||
val firstParamClassDescriptor = DescriptorUtils.getClassDescriptorForType(parameters.get(0).type)
|
||||
if (firstParamClassDescriptor != builtIns.string &&
|
||||
!DescriptorUtils.isSubclass(firstParamClassDescriptor, builtIns.number)
|
||||
) {
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER.on(declaration.getValueParameters().firstOrNull(), indexerKind))
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER.on(declaration.valueParameters.firstOrNull(), indexerKind))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ internal abstract class AbstractNativeIndexerChecker(
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT.on(declaration, requiredParametersCount, indexerKind))
|
||||
}
|
||||
|
||||
for (parameter in declaration.getValueParameters()) {
|
||||
for (parameter in declaration.valueParameters) {
|
||||
if (parameter.hasDefaultValue()) {
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS.on(parameter, indexerKind))
|
||||
}
|
||||
@@ -99,7 +99,7 @@ internal class NativeGetterChecker : AbstractNativeIndexerChecker(PredefinedAnno
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
super.additionalCheck(declaration, descriptor, diagnosticHolder)
|
||||
|
||||
val returnType = descriptor.getReturnType()
|
||||
val returnType = descriptor.returnType
|
||||
if (returnType != null && !TypeUtils.isNullableType(returnType)) {
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE.on(declaration))
|
||||
}
|
||||
@@ -110,13 +110,13 @@ internal class NativeSetterChecker : AbstractNativeIndexerChecker(PredefinedAnno
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
super.additionalCheck(declaration, descriptor, diagnosticHolder)
|
||||
|
||||
val returnType = descriptor.getReturnType()
|
||||
val returnType = descriptor.returnType
|
||||
if (returnType == null || KotlinBuiltIns.isUnit(returnType)) return
|
||||
|
||||
val parameters = descriptor.getValueParameters()
|
||||
val parameters = descriptor.valueParameters
|
||||
if (parameters.size < 2) return
|
||||
|
||||
val secondParameterType = parameters.get(1).getType()
|
||||
val secondParameterType = parameters.get(1).type
|
||||
if (secondParameterType.isSubtypeOf(returnType)) return
|
||||
|
||||
diagnosticHolder.report(ErrorsJs.NATIVE_SETTER_WRONG_RETURN_TYPE.on(declaration))
|
||||
|
||||
Reference in New Issue
Block a user