From af8caae38725fcf67fc333ead1389108863fa4d4 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 13 Jul 2022 11:16:12 +0300 Subject: [PATCH] [KAPT] Fix formatting --- .../PartialAnalysisHandlerExtension.kt | 17 +++++++++------- .../jetbrains/kotlin/kapt3/Kapt3Extension.kt | 6 ++++-- .../stubs/ClassFileToSourceStubConverter.kt | 20 ++++++++++++++++++- .../kotlin/kapt3/stubs/ErrorTypeCorrector.kt | 6 ++++++ .../kapt3/stubs/SignatureParserVisitor.kt | 4 +++- .../util/MessageCollectorBackedKaptLogger.kt | 2 +- .../jetbrains/kotlin/kapt3/util/typeUtils.kt | 1 + 7 files changed, 44 insertions(+), 12 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/extensions/PartialAnalysisHandlerExtension.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/extensions/PartialAnalysisHandlerExtension.kt index 61e64d0e797..f68af4ad0c5 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/extensions/PartialAnalysisHandlerExtension.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/extensions/PartialAnalysisHandlerExtension.kt @@ -40,12 +40,12 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension { get() = false override fun doAnalysis( - project: Project, - module: ModuleDescriptor, - projectContext: ProjectContext, - files: Collection, - bindingTrace: BindingTrace, - componentProvider: ComponentProvider + project: Project, + module: ModuleDescriptor, + projectContext: ProjectContext, + files: Collection, + bindingTrace: BindingTrace, + componentProvider: ComponentProvider ): AnalysisResult? { if (!analyzePartially) { return null @@ -57,7 +57,8 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension { val topDownAnalyzer = componentProvider.get() val topDownAnalysisContext = TopDownAnalysisContext( - TopDownAnalysisMode.TopLevelDeclarations, DataFlowInfo.EMPTY, declarationScopeProvider) + TopDownAnalysisMode.TopLevelDeclarations, DataFlowInfo.EMPTY, declarationScopeProvider + ) for (file in files) { ForceResolveUtil.forceResolveAllContents(resolveSession.getFileAnnotations(file)) @@ -81,6 +82,7 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension { ) } } + is PropertyDescriptor -> { if (declaration is KtProperty) { /* TODO Now we analyse body with anonymous object initializers. Check if we can't avoid it @@ -88,6 +90,7 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension { bodyResolver.resolveProperty(topDownAnalysisContext, declaration, descriptor) } } + is FunctionDescriptor -> { if (declaration is KtPrimaryConstructor && (analyzeDefaultParameterValues || descriptor.isAnnotationConstructor())) { val containingScope = descriptor.containingScope diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt index 77dabc432e0..07b414c44f9 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt @@ -115,7 +115,8 @@ class ClasspathBasedKapt3Extension( val zipFileIndexCacheClass = Class.forName("com.sun.tools.javac.file.ZipFileIndexCache") val zipFileIndexCacheInstance = zipFileIndexCacheClass.getMethod("getSharedInstance").invoke(null) zipFileIndexCacheClass.getMethod("clearCache").invoke(zipFileIndexCacheInstance) - } catch (e: Throwable) {} + } catch (e: Throwable) { + } } } @@ -316,7 +317,8 @@ abstract class AbstractKapt3Extension( val className = (stub.defs.first { it is JCTree.JCClassDecl } as JCTree.JCClassDecl).simpleName.toString() val packageName = stub.getPackageNameJava9Aware()?.toString() ?: "" - val packageDir = if (packageName.isEmpty()) options.stubsOutputDir else File(options.stubsOutputDir, packageName.replace('.', '/')) + val packageDir = + if (packageName.isEmpty()) options.stubsOutputDir else File(options.stubsOutputDir, packageName.replace('.', '/')) packageDir.mkdirs() val sourceFile = File(packageDir, "$className.java") diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 9cc7dc4ef93..39b860afa8b 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -678,6 +678,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati if (className.isEmpty()) throw IllegalStateException("Invalid package facade class name: ${clazz.name}") className } + else -> if (isDefaultImpls) "DefaultImpls" else descriptor.name.asString() } } @@ -846,6 +847,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati annotationNode.values = values return annotationNode } + is ArrayValue -> { val children = value.value val result = ArrayList(children.size) @@ -858,6 +860,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati } return result } + is BooleanValue -> value.value is DoubleValue -> value.value is EnumValue -> { @@ -865,6 +868,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati val enumType = AsmUtil.asmTypeByClassId(classId) return arrayOf(enumType.descriptor, name.asString()) } + is FloatValue -> value.value is StringValue -> value.value is NullValue -> null @@ -1276,6 +1280,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati val receiver = tryParseTypeExpression(expression.receiverExpression) ?: return null return treeMaker.Select(receiver, treeMaker.name(selector.getReferencedName())) } + else -> null } } @@ -1296,6 +1301,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati else null } + is KtCollectionLiteralExpression -> singleArg.getInnerExpressions() is KtDotQualifiedExpression -> listOf(singleArg) null -> args @@ -1372,13 +1378,19 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati is Float -> when { value.isFinite() -> treeMaker.Literal(value) - else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value.toDouble()).toFloat()), treeMaker.Literal(0.0F)) + else -> treeMaker.Binary( + Tag.DIV, + treeMaker.Literal(specialFpValueNumerator(value.toDouble()).toFloat()), + treeMaker.Literal(0.0F) + ) } + is Double -> when { value.isFinite() -> treeMaker.Literal(value) else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value)), treeMaker.Literal(0.0)) } + else -> null } } @@ -1410,11 +1422,13 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati // But enums can't extend other enums, so this should be enough. desc is EnumValue && desc.enumEntryName.asString() == valueName } + is List<*> -> { desc is ArrayValue && asm.size == desc.value.size && asm.zip(desc.value).all { (eAsm, eDesc) -> checkIfAnnotationValueMatches(eAsm, eDesc) } } + is Type -> desc is KClassValue && typeMapper.mapType(desc.getArgumentType(kaptContext.generationState.module)) == asm is AnnotationNode -> { val annotationDescriptor = (desc as? AnnotationValue)?.value ?: return false @@ -1429,6 +1443,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati true } + else -> false } } @@ -1459,12 +1474,14 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati treeMaker.Select(treeMaker.Type(enumType), treeMaker.name(valueName)) } + is List<*> -> treeMaker.NewArray(null, JavacList.nil(), mapJList(value, ::convertDeeper)) is Type -> { checkIfValidTypeName(containingClass, value) treeMaker.Select(treeMaker.Type(value), treeMaker.name("class")) } + is AnnotationNode -> convertAnnotation(containingClass, value, packageFqName = null, filtered = false)!! else -> throw IllegalArgumentException("Illegal literal expression value: $value (${value::class.java.canonicalName})") } @@ -1504,6 +1521,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati if (replaced != it) replaced else null }?.let(::convertKotlinType) ?: fieldType } + else -> fieldType } } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt index 9d93c8d25b4..9784f3d10f6 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt @@ -99,11 +99,13 @@ class ErrorTypeCorrector( val actualType = typeAlias?.getTypeReference() ?: return convert(target.expandedType) return convert(actualType, typeAlias.getSubstitutions(type)) } + is ClassConstructorDescriptor -> { val asmType = KaptTypeMapper.mapType(target.constructedClass.defaultType, TypeMappingMode.GENERIC_ARGUMENT) baseExpression = converter.treeMaker.Type(asmType) } + is ClassDescriptor -> { // We only get here if some type were an error type. In other words, 'type' is either an error type or its argument, // so it's impossible it to be unboxed primitive. @@ -111,6 +113,7 @@ class ErrorTypeCorrector( baseExpression = converter.treeMaker.Type(asmType) } + else -> { val referencedName = type.referencedName ?: return defaultType val qualifier = type.qualifier @@ -130,6 +133,7 @@ class ErrorTypeCorrector( if (qualifierType === defaultType) return defaultType // Do not allow to use 'defaultType' as a qualifier treeMaker.Select(qualifierType, treeMaker.name(referencedName)) } + else -> treeMaker.SimpleName(referencedName) } } @@ -186,8 +190,10 @@ class ErrorTypeCorrector( projectionKind === KtProjectionKind.STAR -> treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.UNBOUND), null) projectionKind === KtProjectionKind.IN || variance === Variance.IN_VARIANCE -> treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.SUPER), argumentExpression) + projectionKind === KtProjectionKind.OUT || variance === Variance.OUT_VARIANCE -> treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.EXTENDS), argumentExpression) + else -> argumentExpression // invariant } } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/SignatureParserVisitor.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/SignatureParserVisitor.kt index f96d2caa700..19b83ce9fd5 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/SignatureParserVisitor.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/SignatureParserVisitor.kt @@ -215,6 +215,7 @@ class SignatureParser(private val treeMaker: KaptTreeMaker) { expression } + TypeVariable -> treeMaker.SimpleName(node.name!!) ArrayType -> treeMaker.TypeArray(parseType(node.children.single())) PrimitiveType -> { @@ -232,6 +233,7 @@ class SignatureParser(private val treeMaker: KaptTreeMaker) { } treeMaker.TypeIdent(typeTag) } + else -> error("Unsupported type: $node") } } @@ -417,4 +419,4 @@ private class SignatureParserVisitor : SignatureVisitor(Opcodes.API_VERSION) { } stack.pop() } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/MessageCollectorBackedKaptLogger.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/MessageCollectorBackedKaptLogger.kt index af27b8c0fae..8ea7f354c72 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/MessageCollectorBackedKaptLogger.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/MessageCollectorBackedKaptLogger.kt @@ -38,7 +38,7 @@ class MessageCollectorBackedKaptLogger( messageCollector.report(INFO, PREFIX + message) } } - + override fun warn(message: String) { messageCollector.report(WARNING, PREFIX + message) } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/typeUtils.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/typeUtils.kt index 534b6e1f68d..d0af6ec3930 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/typeUtils.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/util/typeUtils.kt @@ -38,6 +38,7 @@ fun replaceAnonymousTypeWithSuperType(type: KotlinType): KotlinType { type.builtIns.anyType } } + else -> type }