[KAPT] Fix formatting

This commit is contained in:
Dmitriy Novozhilov
2022-07-13 11:16:12 +03:00
committed by teamcity
parent 8b960de76a
commit af8caae387
7 changed files with 44 additions and 12 deletions
@@ -40,12 +40,12 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
get() = false get() = false
override fun doAnalysis( override fun doAnalysis(
project: Project, project: Project,
module: ModuleDescriptor, module: ModuleDescriptor,
projectContext: ProjectContext, projectContext: ProjectContext,
files: Collection<KtFile>, files: Collection<KtFile>,
bindingTrace: BindingTrace, bindingTrace: BindingTrace,
componentProvider: ComponentProvider componentProvider: ComponentProvider
): AnalysisResult? { ): AnalysisResult? {
if (!analyzePartially) { if (!analyzePartially) {
return null return null
@@ -57,7 +57,8 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
val topDownAnalyzer = componentProvider.get<LazyTopDownAnalyzer>() val topDownAnalyzer = componentProvider.get<LazyTopDownAnalyzer>()
val topDownAnalysisContext = TopDownAnalysisContext( val topDownAnalysisContext = TopDownAnalysisContext(
TopDownAnalysisMode.TopLevelDeclarations, DataFlowInfo.EMPTY, declarationScopeProvider) TopDownAnalysisMode.TopLevelDeclarations, DataFlowInfo.EMPTY, declarationScopeProvider
)
for (file in files) { for (file in files) {
ForceResolveUtil.forceResolveAllContents(resolveSession.getFileAnnotations(file)) ForceResolveUtil.forceResolveAllContents(resolveSession.getFileAnnotations(file))
@@ -81,6 +82,7 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
) )
} }
} }
is PropertyDescriptor -> { is PropertyDescriptor -> {
if (declaration is KtProperty) { if (declaration is KtProperty) {
/* TODO Now we analyse body with anonymous object initializers. Check if we can't avoid it /* 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) bodyResolver.resolveProperty(topDownAnalysisContext, declaration, descriptor)
} }
} }
is FunctionDescriptor -> { is FunctionDescriptor -> {
if (declaration is KtPrimaryConstructor && (analyzeDefaultParameterValues || descriptor.isAnnotationConstructor())) { if (declaration is KtPrimaryConstructor && (analyzeDefaultParameterValues || descriptor.isAnnotationConstructor())) {
val containingScope = descriptor.containingScope val containingScope = descriptor.containingScope
@@ -115,7 +115,8 @@ class ClasspathBasedKapt3Extension(
val zipFileIndexCacheClass = Class.forName("com.sun.tools.javac.file.ZipFileIndexCache") val zipFileIndexCacheClass = Class.forName("com.sun.tools.javac.file.ZipFileIndexCache")
val zipFileIndexCacheInstance = zipFileIndexCacheClass.getMethod("getSharedInstance").invoke(null) val zipFileIndexCacheInstance = zipFileIndexCacheClass.getMethod("getSharedInstance").invoke(null)
zipFileIndexCacheClass.getMethod("clearCache").invoke(zipFileIndexCacheInstance) 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 className = (stub.defs.first { it is JCTree.JCClassDecl } as JCTree.JCClassDecl).simpleName.toString()
val packageName = stub.getPackageNameJava9Aware()?.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() packageDir.mkdirs()
val sourceFile = File(packageDir, "$className.java") val sourceFile = File(packageDir, "$className.java")
@@ -678,6 +678,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
if (className.isEmpty()) throw IllegalStateException("Invalid package facade class name: ${clazz.name}") if (className.isEmpty()) throw IllegalStateException("Invalid package facade class name: ${clazz.name}")
className className
} }
else -> if (isDefaultImpls) "DefaultImpls" else descriptor.name.asString() else -> if (isDefaultImpls) "DefaultImpls" else descriptor.name.asString()
} }
} }
@@ -846,6 +847,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
annotationNode.values = values annotationNode.values = values
return annotationNode return annotationNode
} }
is ArrayValue -> { is ArrayValue -> {
val children = value.value val children = value.value
val result = ArrayList<Any?>(children.size) val result = ArrayList<Any?>(children.size)
@@ -858,6 +860,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
} }
return result return result
} }
is BooleanValue -> value.value is BooleanValue -> value.value
is DoubleValue -> value.value is DoubleValue -> value.value
is EnumValue -> { is EnumValue -> {
@@ -865,6 +868,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
val enumType = AsmUtil.asmTypeByClassId(classId) val enumType = AsmUtil.asmTypeByClassId(classId)
return arrayOf(enumType.descriptor, name.asString()) return arrayOf(enumType.descriptor, name.asString())
} }
is FloatValue -> value.value is FloatValue -> value.value
is StringValue -> value.value is StringValue -> value.value
is NullValue -> null is NullValue -> null
@@ -1276,6 +1280,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
val receiver = tryParseTypeExpression(expression.receiverExpression) ?: return null val receiver = tryParseTypeExpression(expression.receiverExpression) ?: return null
return treeMaker.Select(receiver, treeMaker.name(selector.getReferencedName())) return treeMaker.Select(receiver, treeMaker.name(selector.getReferencedName()))
} }
else -> null else -> null
} }
} }
@@ -1296,6 +1301,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
else else
null null
} }
is KtCollectionLiteralExpression -> singleArg.getInnerExpressions() is KtCollectionLiteralExpression -> singleArg.getInnerExpressions()
is KtDotQualifiedExpression -> listOf(singleArg) is KtDotQualifiedExpression -> listOf(singleArg)
null -> args null -> args
@@ -1372,13 +1378,19 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
is Float -> is Float ->
when { when {
value.isFinite() -> treeMaker.Literal(value) 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 -> is Double ->
when { when {
value.isFinite() -> treeMaker.Literal(value) value.isFinite() -> treeMaker.Literal(value)
else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value)), treeMaker.Literal(0.0)) else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value)), treeMaker.Literal(0.0))
} }
else -> null else -> null
} }
} }
@@ -1410,11 +1422,13 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
// But enums can't extend other enums, so this should be enough. // But enums can't extend other enums, so this should be enough.
desc is EnumValue && desc.enumEntryName.asString() == valueName desc is EnumValue && desc.enumEntryName.asString() == valueName
} }
is List<*> -> { is List<*> -> {
desc is ArrayValue desc is ArrayValue
&& asm.size == desc.value.size && asm.size == desc.value.size
&& asm.zip(desc.value).all { (eAsm, eDesc) -> checkIfAnnotationValueMatches(eAsm, eDesc) } && asm.zip(desc.value).all { (eAsm, eDesc) -> checkIfAnnotationValueMatches(eAsm, eDesc) }
} }
is Type -> desc is KClassValue && typeMapper.mapType(desc.getArgumentType(kaptContext.generationState.module)) == asm is Type -> desc is KClassValue && typeMapper.mapType(desc.getArgumentType(kaptContext.generationState.module)) == asm
is AnnotationNode -> { is AnnotationNode -> {
val annotationDescriptor = (desc as? AnnotationValue)?.value ?: return false val annotationDescriptor = (desc as? AnnotationValue)?.value ?: return false
@@ -1429,6 +1443,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
true true
} }
else -> false else -> false
} }
} }
@@ -1459,12 +1474,14 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
treeMaker.Select(treeMaker.Type(enumType), treeMaker.name(valueName)) treeMaker.Select(treeMaker.Type(enumType), treeMaker.name(valueName))
} }
is List<*> -> treeMaker.NewArray(null, JavacList.nil(), mapJList(value, ::convertDeeper)) is List<*> -> treeMaker.NewArray(null, JavacList.nil(), mapJList(value, ::convertDeeper))
is Type -> { is Type -> {
checkIfValidTypeName(containingClass, value) checkIfValidTypeName(containingClass, value)
treeMaker.Select(treeMaker.Type(value), treeMaker.name("class")) treeMaker.Select(treeMaker.Type(value), treeMaker.name("class"))
} }
is AnnotationNode -> convertAnnotation(containingClass, value, packageFqName = null, filtered = false)!! is AnnotationNode -> convertAnnotation(containingClass, value, packageFqName = null, filtered = false)!!
else -> throw IllegalArgumentException("Illegal literal expression value: $value (${value::class.java.canonicalName})") 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 if (replaced != it) replaced else null
}?.let(::convertKotlinType) ?: fieldType }?.let(::convertKotlinType) ?: fieldType
} }
else -> fieldType else -> fieldType
} }
} }
@@ -99,11 +99,13 @@ class ErrorTypeCorrector(
val actualType = typeAlias?.getTypeReference() ?: return convert(target.expandedType) val actualType = typeAlias?.getTypeReference() ?: return convert(target.expandedType)
return convert(actualType, typeAlias.getSubstitutions(type)) return convert(actualType, typeAlias.getSubstitutions(type))
} }
is ClassConstructorDescriptor -> { is ClassConstructorDescriptor -> {
val asmType = KaptTypeMapper.mapType(target.constructedClass.defaultType, TypeMappingMode.GENERIC_ARGUMENT) val asmType = KaptTypeMapper.mapType(target.constructedClass.defaultType, TypeMappingMode.GENERIC_ARGUMENT)
baseExpression = converter.treeMaker.Type(asmType) baseExpression = converter.treeMaker.Type(asmType)
} }
is ClassDescriptor -> { 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, // 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. // so it's impossible it to be unboxed primitive.
@@ -111,6 +113,7 @@ class ErrorTypeCorrector(
baseExpression = converter.treeMaker.Type(asmType) baseExpression = converter.treeMaker.Type(asmType)
} }
else -> { else -> {
val referencedName = type.referencedName ?: return defaultType val referencedName = type.referencedName ?: return defaultType
val qualifier = type.qualifier val qualifier = type.qualifier
@@ -130,6 +133,7 @@ class ErrorTypeCorrector(
if (qualifierType === defaultType) return defaultType // Do not allow to use 'defaultType' as a qualifier if (qualifierType === defaultType) return defaultType // Do not allow to use 'defaultType' as a qualifier
treeMaker.Select(qualifierType, treeMaker.name(referencedName)) treeMaker.Select(qualifierType, treeMaker.name(referencedName))
} }
else -> treeMaker.SimpleName(referencedName) else -> treeMaker.SimpleName(referencedName)
} }
} }
@@ -186,8 +190,10 @@ class ErrorTypeCorrector(
projectionKind === KtProjectionKind.STAR -> treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.UNBOUND), null) projectionKind === KtProjectionKind.STAR -> treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.UNBOUND), null)
projectionKind === KtProjectionKind.IN || variance === Variance.IN_VARIANCE -> projectionKind === KtProjectionKind.IN || variance === Variance.IN_VARIANCE ->
treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.SUPER), argumentExpression) treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.SUPER), argumentExpression)
projectionKind === KtProjectionKind.OUT || variance === Variance.OUT_VARIANCE -> projectionKind === KtProjectionKind.OUT || variance === Variance.OUT_VARIANCE ->
treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.EXTENDS), argumentExpression) treeMaker.Wildcard(treeMaker.TypeBoundKind(BoundKind.EXTENDS), argumentExpression)
else -> argumentExpression // invariant else -> argumentExpression // invariant
} }
} }
@@ -215,6 +215,7 @@ class SignatureParser(private val treeMaker: KaptTreeMaker) {
expression expression
} }
TypeVariable -> treeMaker.SimpleName(node.name!!) TypeVariable -> treeMaker.SimpleName(node.name!!)
ArrayType -> treeMaker.TypeArray(parseType(node.children.single())) ArrayType -> treeMaker.TypeArray(parseType(node.children.single()))
PrimitiveType -> { PrimitiveType -> {
@@ -232,6 +233,7 @@ class SignatureParser(private val treeMaker: KaptTreeMaker) {
} }
treeMaker.TypeIdent(typeTag) treeMaker.TypeIdent(typeTag)
} }
else -> error("Unsupported type: $node") else -> error("Unsupported type: $node")
} }
} }
@@ -417,4 +419,4 @@ private class SignatureParserVisitor : SignatureVisitor(Opcodes.API_VERSION) {
} }
stack.pop() stack.pop()
} }
} }
@@ -38,7 +38,7 @@ class MessageCollectorBackedKaptLogger(
messageCollector.report(INFO, PREFIX + message) messageCollector.report(INFO, PREFIX + message)
} }
} }
override fun warn(message: String) { override fun warn(message: String) {
messageCollector.report(WARNING, PREFIX + message) messageCollector.report(WARNING, PREFIX + message)
} }
@@ -38,6 +38,7 @@ fun replaceAnonymousTypeWithSuperType(type: KotlinType): KotlinType {
type.builtIns.anyType type.builtIns.anyType
} }
} }
else -> type else -> type
} }