Kapt: Refactor kapt type wrappers. Now every ordinary (not NoType) type has a backed PsiType so it's easy to call utility functions from IntelliJ.
(cherry picked from commit 0a684aa)
This commit is contained in:
committed by
Yan Zhulanow
parent
84d62f37eb
commit
6eb3d7e002
+1
-1
@@ -51,7 +51,7 @@ private class JeEnumValueAnnotationValue(val psi: PsiEnumConstant) : AnnotationV
|
||||
}
|
||||
|
||||
private class JeTypeAnnotationValue(val psi: PsiClassObjectAccessExpression) : AnnotationValue {
|
||||
override fun getValue() = psi.operand.type.toJeType()
|
||||
override fun getValue() = psi.operand.type.toJeType(psi.manager)
|
||||
override fun <R : Any?, P : Any?> accept(v: AnnotationValueVisitor<R, P>, p: P) = v.visitType(value, p)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -36,7 +36,7 @@ class JeMethodExecutableElement(override val psi: PsiMethod) : JeElement(), Exec
|
||||
return JeName(psi.name)
|
||||
}
|
||||
|
||||
override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType() }
|
||||
override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager) }
|
||||
|
||||
override fun getTypeParameters() = psi.typeParameters.map { JeTypeParameterElement(it, this) }
|
||||
|
||||
@@ -48,7 +48,7 @@ class JeMethodExecutableElement(override val psi: PsiMethod) : JeElement(), Exec
|
||||
return JeAnnotationValue(defaultValue)
|
||||
}
|
||||
|
||||
override fun getReturnType() = psi.returnType?.let { it.toJeType() } ?: JeNoneType
|
||||
override fun getReturnType() = psi.returnType?.let { it.toJeType(psi.manager) } ?: JeNoneType
|
||||
|
||||
override fun getReceiverType() = psi.getReceiverTypeMirror()
|
||||
|
||||
@@ -89,7 +89,7 @@ fun PsiMethod.getReceiverTypeMirror(): TypeMirror {
|
||||
val containingClass = containingClass
|
||||
if (containingClass != null && !containingClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
containingClass.containingClass?.let {
|
||||
return PsiTypesUtil.getClassType(it).toJeType()
|
||||
return PsiTypesUtil.getClassType(it).toJeType(manager)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,6 @@ fun PsiMethod.getReceiverTypeMirror(): TypeMirror {
|
||||
}
|
||||
|
||||
val containingClass = containingClass ?: return JeNoneType
|
||||
return PsiTypesUtil.getClassType(containingClass).toJeType()
|
||||
return PsiTypesUtil.getClassType(containingClass).toJeType(manager)
|
||||
|
||||
}
|
||||
+3
-3
@@ -41,10 +41,10 @@ class JeTypeElement(override val psi: PsiClass) : JeElement(), TypeElement, JeAn
|
||||
|
||||
override fun getSuperclass(): TypeMirror {
|
||||
val superClass = psi.superClass ?: return JeNoneType
|
||||
return PsiTypesUtil.getClassType(superClass).toJeType()
|
||||
return PsiTypesUtil.getClassType(superClass).toJeType(psi.manager)
|
||||
}
|
||||
|
||||
override fun getInterfaces() = psi.interfaces.map { PsiTypesUtil.getClassType(it).toJeType() }
|
||||
override fun getInterfaces() = psi.interfaces.map { PsiTypesUtil.getClassType(it).toJeType(psi.manager) }
|
||||
|
||||
override fun getTypeParameters() = psi.typeParameters.map { JeTypeParameterElement(it, this) }
|
||||
|
||||
@@ -79,7 +79,7 @@ class JeTypeElement(override val psi: PsiClass) : JeElement(), TypeElement, JeAn
|
||||
else -> ElementKind.CLASS
|
||||
}
|
||||
|
||||
override fun asType() = PsiTypesUtil.getClassType(psi).toJeType()
|
||||
override fun asType() = PsiTypesUtil.getClassType(psi).toJeType(psi.manager)
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: ElementVisitor<R, P>, p: P) = v.visitType(this, p)
|
||||
|
||||
|
||||
+2
-2
@@ -39,13 +39,13 @@ class JeTypeParameterElement(
|
||||
|
||||
override fun getKind() = ElementKind.TYPE_PARAMETER
|
||||
|
||||
override fun asType() = PsiTypesUtil.getClassType(psi).toJeType()
|
||||
override fun asType() = PsiTypesUtil.getClassType(psi).toJeType(psi.manager)
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: ElementVisitor<R, P>, p: P) = v.visitTypeParameter(this, p)
|
||||
|
||||
override fun getEnclosedElements() = emptyList<Element>()
|
||||
|
||||
override fun getBounds() = psi.superTypes.map { it.toJeType() }
|
||||
override fun getBounds() = psi.superTypes.map { it.toJeType(psi.manager) }
|
||||
|
||||
override fun getGenericElement() = parent
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class JeVariableElement(override val psi: PsiVariable) : JeElement(), VariableEl
|
||||
else -> ElementKind.LOCAL_VARIABLE
|
||||
}
|
||||
|
||||
override fun asType() = psi.type.toJeType()
|
||||
override fun asType() = psi.type.toJeType(psi.manager)
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: ElementVisitor<R, P>, p: P) = v.visitVariable(this, p)
|
||||
|
||||
|
||||
+3
-2
@@ -17,14 +17,15 @@
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiArrayType
|
||||
import com.intellij.psi.PsiManager
|
||||
import javax.lang.model.type.ArrayType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeArrayType(override val psiType: PsiArrayType) : JeAbstractType(), ArrayType {
|
||||
class JeArrayType(override val psiType: PsiArrayType, override val psiManager: PsiManager) : JePsiType(), JeTypeWithManager, ArrayType {
|
||||
override fun getKind() = TypeKind.ARRAY
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitArray(this, p)
|
||||
override fun getComponentType() = psiType.componentType.toJeType()
|
||||
override fun getComponentType() = psiType.componentType.toJeType(psiManager)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
+5
-1
@@ -17,14 +17,18 @@
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiClassInitializer
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiModifier
|
||||
import javax.lang.model.type.*
|
||||
|
||||
class JeClassInitializerExecutableTypeMirror(val initializer: PsiClassInitializer) : JeTypeBase(), ExecutableType {
|
||||
class JeClassInitializerExecutableTypeMirror(val initializer: PsiClassInitializer) : JeTypeMirror, JeTypeWithManager, ExecutableType {
|
||||
override fun getKind() = TypeKind.EXECUTABLE
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitExecutable(this, p)
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = initializer.manager
|
||||
|
||||
override fun getReturnType() = CustomJeNoneType(TypeKind.VOID)
|
||||
|
||||
override fun getReceiverType() = JeNoneType
|
||||
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiType
|
||||
import javax.lang.model.element.TypeElement
|
||||
import javax.lang.model.type.DeclaredType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeMirror
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeCompoundDeclaredType(
|
||||
val psiClass: PsiClass,
|
||||
val baseType: TypeElement,
|
||||
val enclosingTypeMirror: TypeMirror?,
|
||||
val typeArgs: List<PsiType>,
|
||||
val typeArgMirrors: List<TypeMirror>
|
||||
) : JeTypeBase(), DeclaredType {
|
||||
override fun getKind() = TypeKind.DECLARED
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitDeclared(this, p)
|
||||
|
||||
override fun getTypeArguments() = typeArgMirrors
|
||||
override fun asElement() = baseType
|
||||
override fun getEnclosingType() = enclosingTypeMirror ?: JeNoneType
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
|
||||
other as JeCompoundDeclaredType
|
||||
|
||||
if (baseType != other.baseType) return false
|
||||
if (enclosingTypeMirror != other.enclosingTypeMirror) return false
|
||||
if (typeArgs != other.typeArgs) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int{
|
||||
var result = baseType.hashCode()
|
||||
result = 31 * result + (enclosingTypeMirror?.hashCode() ?: 0)
|
||||
result = 31 * result + typeArgs.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return baseType.toString() + typeArgs.joinToString(prefix = "<", postfix = ">")
|
||||
}
|
||||
}
|
||||
+26
-4
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiClassType
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.light.LightClassReferenceExpression
|
||||
import com.intellij.psi.impl.source.PsiClassReferenceType
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
|
||||
import javax.lang.model.type.DeclaredType
|
||||
@@ -25,17 +30,34 @@ import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeMirror
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeDeclaredType(override val psiType: PsiClassType, val psiClass: PsiClass) : JeAbstractType(), DeclaredType {
|
||||
fun createDeclaredType(psiClass: PsiClass, typeArgs: List<PsiType>): PsiClassReferenceType? {
|
||||
val params = typeArgs.toTypedArray()
|
||||
val text = (psiClass.name ?: return null) + typeArgs.joinToString(prefix = "<", postfix = ">")
|
||||
return PsiClassReferenceType(object : LightClassReferenceExpression(psiClass.manager, text, psiClass) {
|
||||
override fun getTypeParameters() = params
|
||||
}, LanguageLevel.JDK_1_8)
|
||||
}
|
||||
|
||||
class JeDeclaredType(
|
||||
override val psiType: PsiClassType,
|
||||
val psiClass: PsiClass,
|
||||
val enclosingDeclaredType: DeclaredType? = null,
|
||||
val typeArgumentMirrors: List<TypeMirror>? = null
|
||||
) : JePsiType(), JeTypeWithManager, DeclaredType {
|
||||
override fun getKind() = TypeKind.DECLARED
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitDeclared(this, p)
|
||||
|
||||
override fun getTypeArguments() = psiType.parameters.map { it.toJeType() }
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = psiClass.manager
|
||||
|
||||
override fun getTypeArguments() = typeArgumentMirrors ?: psiType.parameters.map { it.toJeType(psiManager) }
|
||||
|
||||
override fun asElement() = JeTypeElement(psiClass)
|
||||
|
||||
override fun getEnclosingType(): TypeMirror {
|
||||
if (enclosingDeclaredType != null) return enclosingDeclaredType
|
||||
val psiClass = psiClass.containingClass ?: return JeNoneType
|
||||
return PsiTypesUtil.getClassType(psiClass).toJeType()
|
||||
return PsiTypesUtil.getClassType(psiClass).toJeType(psiManager)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean{
|
||||
|
||||
+6
-2
@@ -17,12 +17,16 @@
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiIntersectionType
|
||||
import com.intellij.psi.PsiManager
|
||||
import javax.lang.model.type.IntersectionType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeIntersectionType(override val psiType: PsiIntersectionType) : JeAbstractType(), IntersectionType {
|
||||
class JeIntersectionType(
|
||||
override val psiType: PsiIntersectionType,
|
||||
override val psiManager: PsiManager
|
||||
) : JePsiType(), JeTypeWithManager, IntersectionType {
|
||||
override fun getKind() = TypeKind.INTERSECTION
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitIntersection(this, p)
|
||||
override fun getBounds() = psiType.superTypes.map { it.toJeType() }
|
||||
override fun getBounds() = psiType.superTypes.map { it.toJeType(psiManager) }
|
||||
}
|
||||
+15
-11
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.util.MethodSignature
|
||||
@@ -27,37 +28,40 @@ import javax.lang.model.type.TypeMirror
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeMethodExecutableTypeMirror(
|
||||
val method: PsiMethod,
|
||||
val psi: PsiMethod,
|
||||
val signature: MethodSignature? = null,
|
||||
val returnType: PsiType? = null
|
||||
) : JeTypeBase(), ExecutableType {
|
||||
) : JeTypeMirror, JeTypeWithManager, ExecutableType {
|
||||
override fun getKind() = TypeKind.EXECUTABLE
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitExecutable(this, p)
|
||||
|
||||
override fun getReturnType() = (returnType ?: method.returnType)?.let { it.toJeType() } ?: CustomJeNoneType(TypeKind.VOID)
|
||||
override fun getReturnType() = (returnType ?: psi.returnType)?.let { it.toJeType(psi.manager) } ?: CustomJeNoneType(TypeKind.VOID)
|
||||
|
||||
override fun getReceiverType() = method.getReceiverTypeMirror()
|
||||
override fun getReceiverType() = psi.getReceiverTypeMirror()
|
||||
|
||||
override fun getThrownTypes() = method.throwsList.referencedTypes.map { it.toJeType() }
|
||||
override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager) }
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = psi.manager
|
||||
|
||||
override fun getParameterTypes(): List<TypeMirror> {
|
||||
signature?.parameterTypes?.let { types -> return types.map { it.toJeType() } }
|
||||
return method.parameterList.parameters.map { it.type.toJeType() }
|
||||
signature?.parameterTypes?.let { types -> return types.map { it.toJeType(psi.manager) } }
|
||||
return psi.parameterList.parameters.map { it.type.toJeType(psi.manager) }
|
||||
}
|
||||
|
||||
override fun getTypeVariables(): List<JeTypeVariableType> {
|
||||
val typeParameters = signature?.typeParameters ?: method.typeParameters
|
||||
val typeParameters = signature?.typeParameters ?: psi.typeParameters
|
||||
return typeParameters.map { JeTypeVariableType(PsiTypesUtil.getClassType(it), it) }
|
||||
}
|
||||
|
||||
override fun toString() = (method.containingClass?.qualifiedName?.let { it + "." } ?: "") + method.name
|
||||
override fun toString() = (psi.containingClass?.qualifiedName?.let { it + "." } ?: "") + psi.name
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
return method == (other as JeMethodExecutableTypeMirror).method
|
||||
return psi == (other as JeMethodExecutableTypeMirror).psi
|
||||
}
|
||||
|
||||
override fun hashCode() = method.hashCode()
|
||||
override fun hashCode() = psi.hashCode()
|
||||
}
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import javax.lang.model.type.NullType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
object JeNullType : JeAbstractType(), NullType {
|
||||
object JeNullType : JeTypeMirror, NullType {
|
||||
override fun getKind() = TypeKind.NULL
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNull(this, p)
|
||||
override val psiType = PsiType.NULL
|
||||
override fun toString() = "null"
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ import javax.lang.model.type.PrimitiveType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JePrimitiveType(override val psiType: PsiPrimitiveType) : JeAbstractType(), PrimitiveType {
|
||||
class JePrimitiveType(override val psiType: PsiPrimitiveType) : JePsiType(), PrimitiveType {
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitPrimitive(this, p)
|
||||
|
||||
override fun getKind() = when (psiType) {
|
||||
|
||||
+2
-2
@@ -18,14 +18,14 @@ package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
|
||||
abstract class JeAbstractType : JeTypeBase() {
|
||||
abstract class JePsiType : JeTypeMirror {
|
||||
abstract val psiType: PsiType
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
|
||||
other as JeAbstractType
|
||||
other as JePsiType
|
||||
|
||||
if (kind != other.kind) return false
|
||||
if (psiType != other.psiType) return false
|
||||
+1
-1
@@ -20,7 +20,7 @@ import javax.lang.model.element.AnnotationMirror
|
||||
import javax.lang.model.type.TypeMirror
|
||||
|
||||
//TODO support type annotations
|
||||
abstract class JeTypeBase : TypeMirror {
|
||||
interface JeTypeMirror : TypeMirror {
|
||||
override fun getAnnotationMirrors() = emptyList<AnnotationMirror>()
|
||||
|
||||
override fun <A : Annotation> getAnnotation(annotationClass: Class<A>?) = null
|
||||
+7
-1
@@ -24,10 +24,16 @@ import javax.lang.model.type.TypeMirror
|
||||
import javax.lang.model.type.TypeVariable
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeTypeVariableType(override val psiType: PsiClassType, val parameter: PsiTypeParameter) : JeAbstractType(), TypeVariable {
|
||||
class JeTypeVariableType(
|
||||
override val psiType: PsiClassType,
|
||||
val parameter: PsiTypeParameter
|
||||
) : JePsiType(), JeTypeWithManager, TypeVariable {
|
||||
override fun getKind() = TypeKind.TYPEVAR
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitTypeVariable(this, p)
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = parameter.manager
|
||||
|
||||
override fun getLowerBound(): TypeMirror? {
|
||||
//TODO support captured lower bounds
|
||||
return JeNullType
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiManager
|
||||
|
||||
interface JeTypeWithManager : JeTypeMirror {
|
||||
val psiManager: PsiManager
|
||||
}
|
||||
+10
-12
@@ -16,18 +16,23 @@
|
||||
|
||||
package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiWildcardType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeMirror
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
import javax.lang.model.type.WildcardType
|
||||
|
||||
class JeWildcardType(override val psiType: PsiWildcardType) : JeAbstractType(), WildcardType {
|
||||
class JeWildcardType(override val psiType: PsiWildcardType) : JePsiType(), JeTypeWithManager, WildcardType {
|
||||
override fun getKind() = TypeKind.WILDCARD
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitWildcard(this, p)
|
||||
override fun getSuperBound() = psiType.superBound.toJeType()
|
||||
override fun getExtendsBound() = psiType.extendsBound.toJeType()
|
||||
override fun equals(other: Any?): Boolean{
|
||||
|
||||
override fun getSuperBound() = psiType.superBound.toJeType(psiManager)
|
||||
override fun getExtendsBound() = psiType.extendsBound.toJeType(psiManager)
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = psiType.manager
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (!super.equals(other)) return false
|
||||
@@ -40,11 +45,4 @@ class JeWildcardType(override val psiType: PsiWildcardType) : JeAbstractType(),
|
||||
result = 31 * result + psiType.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class JeWildcardTypeWithBounds(private val extendsType: TypeMirror, private val superType: TypeMirror) : JeTypeBase(), WildcardType {
|
||||
override fun getKind() = TypeKind.WILDCARD
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitWildcard(this, p)
|
||||
override fun getSuperBound() = superType
|
||||
override fun getExtendsBound() = extendsType
|
||||
}
|
||||
@@ -18,32 +18,34 @@ package org.jetbrains.kotlin.java.model.types
|
||||
|
||||
import javax.lang.model.type.*
|
||||
|
||||
object JePackageTypeMirror : JeTypeBase(), NoType {
|
||||
interface JeNoType : JeTypeMirror, NoType
|
||||
|
||||
object JePackageTypeMirror : JeNoType {
|
||||
override fun getKind() = TypeKind.PACKAGE
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
}
|
||||
|
||||
object JeNoneType : JeTypeBase(), NoType {
|
||||
object JeNoneType : JeNoType {
|
||||
override fun getKind() = TypeKind.NONE
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
}
|
||||
|
||||
object JeVoidType : JeTypeBase(), NoType {
|
||||
object JeVoidType : JeNoType {
|
||||
override fun getKind() = TypeKind.VOID
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
}
|
||||
|
||||
class CustomJeNoneType(private val _kind: TypeKind) : JeTypeBase(), NoType {
|
||||
class CustomJeNoneType(private val _kind: TypeKind) : JeNoType {
|
||||
override fun getKind() = _kind
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
}
|
||||
|
||||
object JeErrorType : JeTypeBase(), NoType {
|
||||
object JeErrorType : JeNoType {
|
||||
override fun getKind() = TypeKind.ERROR
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
}
|
||||
|
||||
object JeDeclaredErrorType : JeTypeBase(), DeclaredType, NoType {
|
||||
object JeDeclaredErrorType : JeNoType, DeclaredType {
|
||||
override fun getKind() = TypeKind.ERROR
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitNoType(this, p)
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ fun TypeKind?.toJePrimitiveType() = PSI_PRIMITIVES_MAP[TYPE_KIND_TO_PSI_PRIMITIV
|
||||
|
||||
fun PsiType.toJePrimitiveType() = PSI_PRIMITIVES_MAP[this]
|
||||
|
||||
fun PsiType.toJeType(): TypeMirror = when (this) {
|
||||
fun PsiType.toJeType(manager: PsiManager): TypeMirror = when (this) {
|
||||
PsiType.VOID -> JeVoidType
|
||||
PsiType.NULL -> JeNullType
|
||||
is PsiPrimitiveType -> PSI_PRIMITIVES_MAP[this] ?: JeErrorType
|
||||
is PsiArrayType -> JeArrayType(this)
|
||||
is PsiArrayType -> JeArrayType(this, manager)
|
||||
is PsiWildcardType -> JeWildcardType(this)
|
||||
is PsiClassType -> {
|
||||
val resolvedClass = this.resolve()
|
||||
@@ -55,7 +55,7 @@ fun PsiType.toJeType(): TypeMirror = when (this) {
|
||||
else -> JeErrorType
|
||||
}
|
||||
}
|
||||
is PsiIntersectionType -> JeIntersectionType(this)
|
||||
is PsiIntersectionType -> JeIntersectionType(this, manager)
|
||||
else -> JeErrorType
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user