Cleanup in core modules

This commit is contained in:
Ilya Gorbunov
2015-12-25 10:43:19 +03:00
parent b71b336a69
commit 911adfd04d
42 changed files with 134 additions and 134 deletions
@@ -23,20 +23,20 @@ import java.lang.reflect.Method
public class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
override fun findArgument(name: Name): JavaAnnotationArgument? {
return getArgumentValue(annotation.annotationType().getDeclaredMethod(name.asString()))
return getArgumentValue(annotation.annotationClass.java.getDeclaredMethod(name.asString()))
}
override fun getArguments(): Collection<JavaAnnotationArgument> {
return annotation.annotationType().getDeclaredMethods().map { getArgumentValue(it) }
return annotation.annotationClass.java.getDeclaredMethods().map { getArgumentValue(it) }
}
private fun getArgumentValue(argument: Method): ReflectJavaAnnotationArgument {
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.getName())) }
}
override fun resolve() = ReflectJavaClass(annotation.annotationType())
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
override fun getClassId() = annotation.annotationType().classId
override fun getClassId() = annotation.annotationClass.java.classId
override fun equals(other: Any?) = other is ReflectJavaAnnotation && annotation == other.annotation
@@ -54,7 +54,7 @@ class ReflectJavaEnumValueAnnotationArgument(
override fun resolve(): ReflectJavaField {
val clazz = value.javaClass
val enumClass = if (clazz.isEnum()) clazz else clazz.getEnclosingClass()
return ReflectJavaField(enumClass.getDeclaredField(value.name()))
return ReflectJavaField(enumClass.getDeclaredField(value.name))
}
}
@@ -35,5 +35,5 @@ fun getAnnotations(annotations: Array<Annotation>): List<ReflectJavaAnnotation>
}
fun findAnnotation(annotations: Array<Annotation>, fqName: FqName): ReflectJavaAnnotation? {
return annotations.firstOrNull { it.annotationType().classId.asSingleFqName() == fqName }?.let { ReflectJavaAnnotation(it) }
return annotations.firstOrNull { it.annotationClass.java.classId.asSingleFqName() == fqName }?.let { ReflectJavaAnnotation(it) }
}
@@ -47,8 +47,8 @@ public class ReflectJavaClass(
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
override fun getSupertypes(): Collection<JavaClassifierType> {
if (klass == javaClass<Any>()) return emptyList()
return listOf(klass.genericSuperclass ?: javaClass<Any>(), *klass.genericInterfaces).map(::ReflectJavaClassifierType)
if (klass == Any::class.java) return emptyList()
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
}
override fun getMethods() = klass.getDeclaredMethods()
@@ -66,7 +66,7 @@ public class ReflectJavaClass(
private fun isEnumValuesOrValueOf(method: Method): Boolean {
return when (method.getName()) {
"values" -> method.getParameterTypes().isEmpty()
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(javaClass<String>()))
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(String::class.java))
else -> false
}
}
@@ -31,14 +31,14 @@ public class ReflectJavaConstructor(override val member: Constructor<*>) : Refle
val klass = member.getDeclaringClass()
val realTypes = when {
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size())
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size)
else -> types
}
val annotations = member.getParameterAnnotations()
val realAnnotations = when {
annotations.size() < realTypes.size() -> throw IllegalStateException("Illegal generic signature: $member")
annotations.size() > realTypes.size() -> annotations.copyOfRange(annotations.size() - realTypes.size(), annotations.size())
annotations.size < realTypes.size -> throw IllegalStateException("Illegal generic signature: $member")
annotations.size > realTypes.size -> annotations.copyOfRange(annotations.size - realTypes.size, annotations.size)
else -> annotations
}
@@ -42,7 +42,7 @@ public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnot
parameterAnnotations: Array<Array<Annotation>>,
isVararg: Boolean
): List<JavaValueParameter> {
val result = ArrayList<JavaValueParameter>(parameterTypes.size())
val result = ArrayList<JavaValueParameter>(parameterTypes.size)
val names = Java8ParameterNamesLoader.loadParameterNames(member)
for (i in parameterTypes.indices) {
val type = ReflectJavaType.create(parameterTypes[i])
@@ -30,7 +30,7 @@ public class ReflectJavaTypeParameter(
) : ReflectJavaElement(), JavaTypeParameter {
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
val bounds = typeVariable.getBounds().map { bound -> ReflectJavaClassifierType(bound) }
if (bounds.singleOrNull()?.type == javaClass<Any>()) return emptyList()
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
return bounds
}
@@ -24,17 +24,17 @@ public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJa
override fun getBound(): ReflectJavaType? {
val upperBounds = type.getUpperBounds()
val lowerBounds = type.getLowerBounds()
if (upperBounds.size() > 1 || lowerBounds.size() > 1) {
if (upperBounds.size > 1 || lowerBounds.size > 1) {
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
}
return when {
lowerBounds.size() == 1 -> ReflectJavaType.create(lowerBounds.single())
upperBounds.size() == 1 -> upperBounds.single().let { ub -> if (ub != javaClass<Any>()) ReflectJavaType.create(ub) else null }
lowerBounds.size == 1 -> ReflectJavaType.create(lowerBounds.single())
upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) ReflectJavaType.create(ub) else null }
else -> null
}
}
override fun isExtends() = type.getUpperBounds().firstOrNull() != javaClass<Any>()
override fun isExtends() = type.getUpperBounds().firstOrNull() != Any::class.java
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
}
@@ -25,7 +25,7 @@ public val Class<*>.safeClassLoader: ClassLoader
get() = classLoader ?: ClassLoader.getSystemClassLoader()
public fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
javaClass<Enum<*>>().isAssignableFrom(this)
Enum::class.java.isAssignableFrom(this)
/**
* NOTE: does not perform a Java -> Kotlin mapping. If this is not expected, consider using KClassImpl#classId instead
@@ -98,7 +98,7 @@ private object ReflectClassStructure {
for ((parameterIndex, annotations) in method.getParameterAnnotations().withIndex()) {
for (annotation in annotations) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitParameterAnnotation(parameterIndex, annotationType.classId, ReflectAnnotationSource(annotation))?.let {
processAnnotationArguments(it, annotation, annotationType)
}
@@ -125,11 +125,11 @@ private object ReflectClassStructure {
// - local/anonymous classes may have many parameters for captured values
// At the moment this seems like a working heuristic for computing number of synthetic parameters for Kotlin classes,
// although this is wrong and likely to change, see KT-6886
val shift = constructor.getParameterTypes().size() - parameterAnnotations.size()
val shift = constructor.getParameterTypes().size - parameterAnnotations.size
for ((parameterIndex, annotations) in parameterAnnotations.withIndex()) {
for (annotation in annotations) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitParameterAnnotation(
parameterIndex + shift, annotationType.classId, ReflectAnnotationSource(annotation)
)?.let {
@@ -156,7 +156,7 @@ private object ReflectClassStructure {
}
private fun processAnnotation(visitor: KotlinJvmBinaryClass.AnnotationVisitor, annotation: Annotation) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitAnnotation(annotationType.classId, ReflectAnnotationSource(annotation))?.let {
processAnnotationArguments(it, annotation, annotationType)
}
@@ -182,9 +182,9 @@ private object ReflectClassStructure {
clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
// isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
val classId = (if (clazz.isEnum()) clazz else clazz.getEnclosingClass()).classId
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name()))
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
}
javaClass<Annotation>().isAssignableFrom(clazz) -> {
Annotation::class.java.isAssignableFrom(clazz) -> {
val annotationClass = clazz.getInterfaces().single()
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
processAnnotationArguments(v, value as Annotation, annotationClass)
@@ -195,7 +195,7 @@ private object ReflectClassStructure {
if (componentType.isEnum()) {
val enumClassId = componentType.classId
for (element in value as Array<*>) {
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name()))
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
}
}
else {
@@ -40,6 +40,6 @@ class RuntimePackagePartProvider(val classLoader : ClassLoader) : PackagePartPro
override fun findPackageParts(packageFqName: String): List<String> {
return module2Mapping.values().map { it.value.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
return module2Mapping.values.map { it.value.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
}
}