Reformat treeBasedTypes.kt

This commit is contained in:
Dmitriy Novozhilov
2022-08-09 16:45:39 +03:00
parent b32f9dcac2
commit 1f2f6f4067
@@ -39,9 +39,11 @@ abstract class TreeBasedType<out T : JCTree>(
get() = allAnnotations.filterTypeAnnotations() get() = allAnnotations.filterTypeAnnotations()
companion object { companion object {
fun create(tree: JCTree, compilationUnit: CompilationUnitTree, fun create(
tree: JCTree, compilationUnit: CompilationUnitTree,
javac: JavacWrapper, annotations: Collection<JavaAnnotation>, javac: JavacWrapper, annotations: Collection<JavaAnnotation>,
containingElement: JavaElement): JavaType { containingElement: JavaElement
): JavaType {
return when (tree) { return when (tree) {
is JCTree.JCPrimitiveTypeTree -> TreeBasedPrimitiveType(tree, compilationUnit, javac, annotations, containingElement) is JCTree.JCPrimitiveTypeTree -> TreeBasedPrimitiveType(tree, compilationUnit, javac, annotations, containingElement)
is JCTree.JCArrayTypeTree -> TreeBasedArrayType(tree, compilationUnit, javac, annotations, containingElement) is JCTree.JCArrayTypeTree -> TreeBasedArrayType(tree, compilationUnit, javac, annotations, containingElement)
@@ -53,6 +55,7 @@ abstract class TreeBasedType<out T : JCTree>(
.map { TreeBasedAnnotation(it, compilationUnit, javac, containingElement) } .map { TreeBasedAnnotation(it, compilationUnit, javac, containingElement) }
create(underlyingType, compilationUnit, javac, newAnnotations, containingElement) create(underlyingType, compilationUnit, javac, newAnnotations, containingElement)
} }
is JCTree.JCExpression -> TreeBasedNonGenericClassifierType(tree, compilationUnit, javac, annotations, containingElement) is JCTree.JCExpression -> TreeBasedNonGenericClassifierType(tree, compilationUnit, javac, annotations, containingElement)
else -> throw UnsupportedOperationException("Unsupported type: $tree") else -> throw UnsupportedOperationException("Unsupported type: $tree")
} }
@@ -83,8 +86,7 @@ class TreeBasedPrimitiveType(
override val type: PrimitiveType? override val type: PrimitiveType?
get() = if (tree.primitiveTypeKind == TypeKind.VOID) { get() = if (tree.primitiveTypeKind == TypeKind.VOID) {
null null
} } else {
else {
JvmPrimitiveType.get(tree.toString()).primitiveType JvmPrimitiveType.get(tree.toString()).primitiveType
} }
@@ -145,8 +147,7 @@ sealed class TreeBasedClassifierType<out T : JCTree>(
if (tree is JCTree.JCFieldAccess) { if (tree is JCTree.JCFieldAccess) {
val enclosingType = TreeBasedType.create(tree.selected, compilationUnit, javac, annotations, containingElement) val enclosingType = TreeBasedType.create(tree.selected, compilationUnit, javac, annotations, containingElement)
return (enclosingType as? JavaClassifierType)?.typeArguments ?: emptyList() return (enclosingType as? JavaClassifierType)?.typeArguments ?: emptyList()
} } else {
else {
val classifier = classifier as? JavaClass ?: return emptyList() val classifier = classifier as? JavaClass ?: return emptyList()
if (classifier is MockKotlinClassifier || classifier.isStatic) return emptyList() if (classifier is MockKotlinClassifier || classifier.isStatic) return emptyList()
@@ -217,14 +218,20 @@ class TreeBasedGenericClassifierType(
val newTree = tree.clazz val newTree = tree.clazz
if (newTree is JCTree.JCAnnotatedType) { if (newTree is JCTree.JCAnnotatedType) {
javac.resolve(newTree.underlyingType, compilationUnit, containingElement) javac.resolve(newTree.underlyingType, compilationUnit, containingElement)
} } else super.classifier
else super.classifier
} }
override val annotations: Collection<JavaAnnotation> override val annotations: Collection<JavaAnnotation>
get() { get() {
val newTree = tree.clazz val newTree = tree.clazz
return (newTree as? JCTree.JCAnnotatedType)?.annotations?.map { TreeBasedAnnotation(it, compilationUnit, javac, containingElement) } return (newTree as? JCTree.JCAnnotatedType)?.annotations?.map {
TreeBasedAnnotation(
it,
compilationUnit,
javac,
containingElement
)
}
?.toMutableList<JavaAnnotation>() ?.toMutableList<JavaAnnotation>()
?.apply { addAll(super.annotations) } ?.apply { addAll(super.annotations) }
?: super.annotations ?: super.annotations