Convert Java model to Kotlin, put in several files
Also move JavaPropertyInitializerEvaluator to ../components/
This commit is contained in:
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.load.java.components.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||
import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl
|
||||
package org.jetbrains.kotlin.load.java.components
|
||||
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator
|
||||
import com.intellij.psi.util.PsiUtil
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPropertyInitializerEvaluator
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class JavaMethodImpl extends JavaMemberImpl<PsiMethod> implements JavaMet
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnnotationParameterDefaultValue() {
|
||||
public boolean getHasAnnotationParameterDefaultValue() {
|
||||
PsiMethod psiMethod = getPsi();
|
||||
return psiMethod instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) psiMethod).getDefaultValue() != null;
|
||||
}
|
||||
|
||||
+4
-2
@@ -35,7 +35,9 @@ class JavaPackageImpl(psiPackage: PsiPackage, private val scope: GlobalSearchSco
|
||||
return classes(psiClasses)
|
||||
}
|
||||
|
||||
override fun getSubPackages() = packages(psi.getSubPackages(scope), scope)
|
||||
override val subPackages: Collection<JavaPackage>
|
||||
get() = packages(psi.getSubPackages(scope), scope)
|
||||
|
||||
override fun getFqName() = FqName(psi.qualifiedName)
|
||||
override val fqName: FqName
|
||||
get() = FqName(psi.qualifiedName)
|
||||
}
|
||||
|
||||
+2
-5
@@ -29,7 +29,7 @@ abstract class VirtualFileKotlinClassFinder : JvmVirtualFileFinder {
|
||||
|
||||
override fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass? {
|
||||
var file = (javaClass as JavaClassImpl).psi.containingFile!!.virtualFile ?: return null
|
||||
if (javaClass.getOuterClass() != null) {
|
||||
if (javaClass.outerClass != null) {
|
||||
// For nested classes we get a file of the containing class, to get the actual class file for A.B.C,
|
||||
// we take the file for A, take its parent directory, then in this directory we look for A$B$C.class
|
||||
file = file.parent!!.findChild(classFileName(javaClass) + ".class").sure { "Virtual file not found for $javaClass" }
|
||||
@@ -39,10 +39,7 @@ abstract class VirtualFileKotlinClassFinder : JvmVirtualFileFinder {
|
||||
}
|
||||
|
||||
private fun classFileName(jClass: JavaClass): String {
|
||||
val outerClass = jClass.outerClass
|
||||
if (outerClass == null) {
|
||||
return jClass.name.asString()
|
||||
}
|
||||
val outerClass = jClass.outerClass ?: return jClass.name.asString()
|
||||
|
||||
return classFileName(outerClass) + "$" + jClass.name.asString()
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure
|
||||
package org.jetbrains.kotlin.load.java.components
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
|
||||
interface JavaPropertyInitializerEvaluator {
|
||||
@@ -23,13 +23,9 @@ import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.java.JavaClassFinder
|
||||
import org.jetbrains.kotlin.load.java.components.ExternalAnnotationResolver
|
||||
import org.jetbrains.kotlin.load.java.components.SignaturePropagator
|
||||
import org.jetbrains.kotlin.load.java.components.JavaResolverCache
|
||||
import org.jetbrains.kotlin.load.java.components.SamConversionResolver
|
||||
import org.jetbrains.kotlin.load.java.components.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElementFactory
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPropertyInitializerEvaluator
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameterListOwner
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
) : AnnotationDescriptor {
|
||||
|
||||
private val fqName = c.storageManager.createNullableLazyValue {
|
||||
javaAnnotation.getClassId()?.asSingleFqName()
|
||||
javaAnnotation.classId?.asSingleFqName()
|
||||
}
|
||||
|
||||
private val type = c.storageManager.createLazyValue {
|
||||
|
||||
+3
-3
@@ -75,7 +75,7 @@ class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
internal val constructors = c.storageManager.createLazyValue {
|
||||
val constructors = jClass.getConstructors()
|
||||
val constructors = jClass.constructors
|
||||
val result = ArrayList<JavaConstructorDescriptor>(constructors.size)
|
||||
for (constructor in constructors) {
|
||||
val descriptor = resolveConstructor(constructor)
|
||||
@@ -599,7 +599,7 @@ class LazyJavaClassMemberScope(
|
||||
method.name,
|
||||
// Parameters of annotation constructors in Java are never nullable
|
||||
TypeUtils.makeNotNullable(returnType),
|
||||
method.hasAnnotationParameterDefaultValue(),
|
||||
method.hasAnnotationParameterDefaultValue,
|
||||
/* isCrossinline = */ false,
|
||||
/* isNoinline = */ false,
|
||||
// Nulls are not allowed in annotation arguments in Java
|
||||
@@ -649,7 +649,7 @@ class LazyJavaClassMemberScope(
|
||||
= nestedClassIndex().keys + enumEntryIndex().keys
|
||||
|
||||
override fun getPropertyNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
if (jClass.isAnnotationType()) return memberIndex().getMethodNames(nameFilter)
|
||||
if (jClass.isAnnotationType) return memberIndex().getMethodNames(nameFilter)
|
||||
|
||||
return memberIndex().getAllFieldNames() +
|
||||
ownerDescriptor.getTypeConstructor().getSupertypes().flatMapTo(LinkedHashSet<Name>()) { supertype ->
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.storage.getValue
|
||||
class LazyJavaPackageFragment(
|
||||
private val c: LazyJavaResolverContext,
|
||||
private val jPackage: JavaPackage
|
||||
) : PackageFragmentDescriptorImpl(c.module, jPackage.getFqName()) {
|
||||
) : PackageFragmentDescriptorImpl(c.module, jPackage.fqName) {
|
||||
private val scope by c.storageManager.createLazyValue {
|
||||
LazyJavaPackageScope(c, jPackage, this)
|
||||
}
|
||||
|
||||
+1
-1
@@ -172,7 +172,7 @@ class LazyJavaPackageScope(
|
||||
|
||||
private val subPackages = c.storageManager.createRecursionTolerantLazyValue(
|
||||
{
|
||||
jPackage.getSubPackages().map { sp -> sp.getFqName() }
|
||||
jPackage.subPackages.map { sp -> sp.fqName }
|
||||
},
|
||||
// This breaks infinite recursion between loading Java descriptors and building light classes
|
||||
onRecursiveCall = listOf()
|
||||
|
||||
+1
-1
@@ -231,7 +231,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
val properties = ArrayList<PropertyDescriptor>()
|
||||
|
||||
val field = memberIndex().findFieldByName(name)
|
||||
if (field != null && !field.isEnumEntry()) {
|
||||
if (field != null && !field.isEnumEntry) {
|
||||
properties.add(resolveProperty(field))
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -62,10 +62,10 @@ open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember
|
||||
|
||||
override fun findMethodsByName(name: Name): Collection<JavaMethod> = methods[name] ?: listOf()
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> =
|
||||
jClass.getAllMemberNames(methodFilter) { getMethods() }
|
||||
jClass.getAllMemberNames(methodFilter) { methods }
|
||||
|
||||
override fun findFieldByName(name: Name): JavaField? = fields[name]
|
||||
override fun getAllFieldNames(): Collection<Name> = jClass.getAllMemberNames(memberFilter) { getFields() }
|
||||
override fun getAllFieldNames(): Collection<Name> = jClass.getAllMemberNames(memberFilter) { fields }
|
||||
}
|
||||
|
||||
private fun JavaClass.getNonDeclaredMethodNames(): List<Name> {
|
||||
|
||||
+3
-3
@@ -100,7 +100,7 @@ class LazyJavaTypeResolver(
|
||||
) : AbstractLazyType(c.storageManager) {
|
||||
private val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
|
||||
|
||||
private val classifier = c.storageManager.createNullableLazyValue { javaType.getClassifier() }
|
||||
private val classifier = c.storageManager.createNullableLazyValue { javaType.classifier }
|
||||
|
||||
override fun computeTypeConstructor(): TypeConstructor {
|
||||
val classifier = classifier()
|
||||
@@ -109,7 +109,7 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
return when (classifier) {
|
||||
is JavaClass -> {
|
||||
val fqName = classifier.getFqName().sure { "Class type should have a FQ name: $classifier" }
|
||||
val fqName = classifier.fqName.sure { "Class type should have a FQ name: $classifier" }
|
||||
|
||||
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
||||
|
||||
@@ -222,7 +222,7 @@ class LazyJavaTypeResolver(
|
||||
else {
|
||||
createProjection(
|
||||
type = transformJavaType(bound, UPPER_BOUND.toAttributes()),
|
||||
projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE,
|
||||
projectionKind = if (javaType.isExtends) OUT_VARIANCE else IN_VARIANCE,
|
||||
typeParameterDescriptor = typeParameter
|
||||
)
|
||||
}
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface JavaAnnotation extends JavaElement {
|
||||
@NotNull
|
||||
Collection<JavaAnnotationArgument> getArguments();
|
||||
|
||||
@Nullable
|
||||
ClassId getClassId();
|
||||
|
||||
@Nullable
|
||||
JavaClass resolve();
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface JavaAnnotationOwner extends JavaElement {
|
||||
@NotNull
|
||||
Collection<JavaAnnotation> getAnnotations();
|
||||
|
||||
@Nullable
|
||||
JavaAnnotation findAnnotation(@NotNull FqName fqName);
|
||||
|
||||
boolean isDeprecatedInJavaDoc();
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface JavaArrayType extends JavaType {
|
||||
@NotNull
|
||||
JavaType getComponentType();
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface JavaClass extends JavaClassifier, JavaTypeParameterListOwner, JavaModifierListOwner {
|
||||
@NotNull
|
||||
Collection<JavaClass> getInnerClasses();
|
||||
|
||||
@Nullable
|
||||
FqName getFqName();
|
||||
|
||||
boolean isInterface();
|
||||
|
||||
boolean isAnnotationType();
|
||||
|
||||
boolean isEnum();
|
||||
|
||||
boolean isKotlinLightClass();
|
||||
|
||||
@Nullable
|
||||
JavaClass getOuterClass();
|
||||
|
||||
@NotNull
|
||||
Collection<JavaClassifierType> getSupertypes();
|
||||
|
||||
@NotNull
|
||||
Collection<JavaMethod> getMethods();
|
||||
|
||||
@NotNull
|
||||
Collection<JavaField> getFields();
|
||||
|
||||
@NotNull
|
||||
Collection<JavaConstructor> getConstructors();
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
public interface JavaClassifier extends JavaNamedElement, JavaAnnotationOwner {
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JavaClassifierType extends JavaType, JavaAnnotationOwner {
|
||||
@Nullable
|
||||
JavaClassifier getClassifier();
|
||||
|
||||
@NotNull
|
||||
String getPresentableText();
|
||||
|
||||
boolean isRaw();
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JavaType> getTypeArguments();
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JavaConstructor extends JavaMember, JavaTypeParameterListOwner {
|
||||
@NotNull
|
||||
List<JavaValueParameter> getValueParameters();
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
public interface JavaElement {
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface JavaField extends JavaMember {
|
||||
boolean isEnumEntry();
|
||||
|
||||
@NotNull
|
||||
JavaType getType();
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface JavaMember extends JavaModifierListOwner, JavaAnnotationOwner, JavaNamedElement {
|
||||
@NotNull
|
||||
JavaClass getContainingClass();
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JavaMethod extends JavaMember, JavaTypeParameterListOwner {
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JavaValueParameter> getValueParameters();
|
||||
|
||||
boolean hasAnnotationParameterDefaultValue();
|
||||
|
||||
@NotNull
|
||||
JavaType getReturnType();
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.Visibility;
|
||||
|
||||
public interface JavaModifierListOwner extends JavaElement {
|
||||
boolean isAbstract();
|
||||
|
||||
boolean isStatic();
|
||||
|
||||
boolean isFinal();
|
||||
|
||||
@NotNull
|
||||
Visibility getVisibility();
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
public interface JavaNamedElement extends JavaElement {
|
||||
@NotNull
|
||||
Name getName();
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
|
||||
public interface JavaPrimitiveType extends JavaType {
|
||||
/** {@code null} means the {@code void} type. */
|
||||
@Nullable
|
||||
PrimitiveType getType();
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
public interface JavaType {
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface JavaTypeParameter extends JavaClassifier {
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
Collection<JavaClassifierType> getUpperBounds();
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JavaTypeParameterListOwner extends JavaElement {
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JavaTypeParameter> getTypeParameters();
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
public interface JavaValueParameter extends JavaAnnotationOwner {
|
||||
@Nullable
|
||||
Name getName();
|
||||
|
||||
@NotNull
|
||||
JavaType getType();
|
||||
|
||||
boolean isVararg();
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.load.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface JavaWildcardType extends JavaType {
|
||||
@Nullable
|
||||
JavaType getBound();
|
||||
|
||||
boolean isExtends();
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.load.java.structure
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
interface JavaElement
|
||||
|
||||
interface JavaNamedElement : JavaElement {
|
||||
val name: Name
|
||||
}
|
||||
|
||||
interface JavaAnnotationOwner : JavaElement {
|
||||
val annotations: Collection<JavaAnnotation>
|
||||
fun findAnnotation(fqName: FqName): JavaAnnotation?
|
||||
|
||||
val isDeprecatedInJavaDoc: Boolean
|
||||
}
|
||||
|
||||
interface JavaModifierListOwner : JavaElement {
|
||||
val isAbstract: Boolean
|
||||
val isStatic: Boolean
|
||||
val isFinal: Boolean
|
||||
val visibility: Visibility
|
||||
}
|
||||
|
||||
interface JavaTypeParameterListOwner : JavaElement {
|
||||
val typeParameters: List<JavaTypeParameter>
|
||||
}
|
||||
|
||||
interface JavaAnnotation : JavaElement {
|
||||
val arguments: Collection<JavaAnnotationArgument>
|
||||
val classId: ClassId?
|
||||
|
||||
fun resolve(): JavaClass?
|
||||
}
|
||||
|
||||
interface JavaPackage : JavaElement {
|
||||
val fqName: FqName
|
||||
val subPackages: Collection<JavaPackage>
|
||||
|
||||
fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
||||
}
|
||||
|
||||
interface JavaClassifier : JavaNamedElement, JavaAnnotationOwner
|
||||
|
||||
interface JavaClass : JavaClassifier, JavaTypeParameterListOwner, JavaModifierListOwner {
|
||||
val fqName: FqName?
|
||||
|
||||
val supertypes: Collection<JavaClassifierType>
|
||||
val innerClasses: Collection<JavaClass>
|
||||
val outerClass: JavaClass?
|
||||
|
||||
val isInterface: Boolean
|
||||
val isAnnotationType: Boolean
|
||||
val isEnum: Boolean
|
||||
val isKotlinLightClass: Boolean
|
||||
|
||||
val methods: Collection<JavaMethod>
|
||||
val fields: Collection<JavaField>
|
||||
val constructors: Collection<JavaConstructor>
|
||||
}
|
||||
|
||||
interface JavaMember : JavaModifierListOwner, JavaAnnotationOwner, JavaNamedElement {
|
||||
val containingClass: JavaClass
|
||||
}
|
||||
|
||||
interface JavaMethod : JavaMember, JavaTypeParameterListOwner {
|
||||
val valueParameters: List<JavaValueParameter>
|
||||
val returnType: JavaType
|
||||
|
||||
val hasAnnotationParameterDefaultValue: Boolean
|
||||
}
|
||||
|
||||
interface JavaField : JavaMember {
|
||||
val isEnumEntry: Boolean
|
||||
val type: JavaType
|
||||
}
|
||||
|
||||
interface JavaConstructor : JavaMember, JavaTypeParameterListOwner {
|
||||
val valueParameters: List<JavaValueParameter>
|
||||
}
|
||||
|
||||
interface JavaValueParameter : JavaAnnotationOwner {
|
||||
val name: Name?
|
||||
val type: JavaType
|
||||
val isVararg: Boolean
|
||||
}
|
||||
|
||||
interface JavaTypeParameter : JavaClassifier {
|
||||
val upperBounds: Collection<JavaClassifierType>
|
||||
}
|
||||
+24
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -16,13 +16,29 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
|
||||
interface JavaPackage : JavaElement {
|
||||
fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
||||
interface JavaType
|
||||
|
||||
fun getSubPackages(): Collection<JavaPackage>
|
||||
|
||||
fun getFqName(): FqName
|
||||
interface JavaArrayType : JavaType {
|
||||
val componentType: JavaType
|
||||
}
|
||||
|
||||
interface JavaClassifierType : JavaType, JavaAnnotationOwner {
|
||||
val classifier: JavaClassifier?
|
||||
val typeArguments: List<JavaType>
|
||||
|
||||
val isRaw: Boolean
|
||||
|
||||
val presentableText: String
|
||||
}
|
||||
|
||||
interface JavaPrimitiveType : JavaType {
|
||||
/** `null` means the `void` type. */
|
||||
val type: PrimitiveType?
|
||||
}
|
||||
|
||||
interface JavaWildcardType : JavaType {
|
||||
val bound: JavaType?
|
||||
val isExtends: Boolean
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ class KotlinJvmBinaryPackageSourceElement(
|
||||
result
|
||||
}
|
||||
|
||||
override fun toString(): String = "Binary package ${jPackage.getFqName()}: ${implClassNameToBinaryClass.keys}"
|
||||
override fun toString(): String = "Binary package ${jPackage.fqName}: ${implClassNameToBinaryClass.keys}"
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
|
||||
fun getRepresentativeBinaryClass(): KotlinJvmBinaryClass {
|
||||
|
||||
+6
-5
@@ -18,19 +18,20 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class ReflectJavaAnnotation(val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
|
||||
override fun getArguments(): Collection<JavaAnnotationArgument> {
|
||||
return annotation.annotationClass.java.declaredMethods.map { method ->
|
||||
override val arguments: Collection<JavaAnnotationArgument>
|
||||
get() = annotation.annotationClass.java.declaredMethods.map { method ->
|
||||
ReflectJavaAnnotationArgument.create(method.invoke(annotation), Name.identifier(method.name))
|
||||
}
|
||||
}
|
||||
|
||||
override val classId: ClassId
|
||||
get() = annotation.annotationClass.java.classId
|
||||
|
||||
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
|
||||
|
||||
override fun getClassId() = annotation.annotationClass.java.classId
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaAnnotation && annotation == other.annotation
|
||||
|
||||
override fun hashCode() = annotation.hashCode()
|
||||
|
||||
+6
-3
@@ -23,11 +23,14 @@ import java.lang.reflect.AnnotatedElement
|
||||
interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
||||
val element: AnnotatedElement?
|
||||
|
||||
override fun getAnnotations() = element?.declaredAnnotations?.getAnnotations() ?: emptyList()
|
||||
override val annotations: List<ReflectJavaAnnotation>
|
||||
get() = element?.declaredAnnotations?.getAnnotations() ?: emptyList()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = element?.declaredAnnotations?.findAnnotation(fqName)
|
||||
override fun findAnnotation(fqName: FqName) =
|
||||
element?.declaredAnnotations?.findAnnotation(fqName)
|
||||
|
||||
override fun isDeprecatedInJavaDoc() = false
|
||||
override val isDeprecatedInJavaDoc: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
fun Array<Annotation>.getAnnotations(): List<ReflectJavaAnnotation> {
|
||||
|
||||
+3
-5
@@ -20,14 +20,12 @@ import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
||||
import java.lang.reflect.GenericArrayType
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class ReflectJavaArrayType(override val type: Type) : ReflectJavaType(), JavaArrayType {
|
||||
private val componentType: ReflectJavaType = with (type) {
|
||||
class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(), JavaArrayType {
|
||||
override val componentType: ReflectJavaType = with (reflectType) {
|
||||
when {
|
||||
this is GenericArrayType -> ReflectJavaType.create(genericComponentType)
|
||||
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
|
||||
else -> throw IllegalArgumentException("Not an array type (${type.javaClass}): $type")
|
||||
else -> throw IllegalArgumentException("Not an array type (${reflectType.javaClass}): $reflectType")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getComponentType() = componentType
|
||||
}
|
||||
|
||||
+60
-46
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
@@ -29,37 +30,42 @@ class ReflectJavaClass(
|
||||
|
||||
override val modifiers: Int get() = klass.modifiers
|
||||
|
||||
override fun getInnerClasses() = klass.declaredClasses
|
||||
.asSequence()
|
||||
.filterNot {
|
||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are in fact
|
||||
// anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private nested class
|
||||
// constructor accessed from the outer class
|
||||
it.simpleName.isEmpty()
|
||||
}
|
||||
.map(::ReflectJavaClass)
|
||||
.toList()
|
||||
|
||||
override fun getFqName() = klass.classId.asSingleFqName()
|
||||
|
||||
override fun getOuterClass() = klass.declaringClass?.let(::ReflectJavaClass)
|
||||
|
||||
override fun getSupertypes(): Collection<JavaClassifierType> {
|
||||
if (klass == Any::class.java) return emptyList()
|
||||
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
||||
}
|
||||
|
||||
override fun getMethods() = klass.declaredMethods
|
||||
.asSequence()
|
||||
.filter { method ->
|
||||
when {
|
||||
method.isSynthetic -> false
|
||||
isEnum -> !isEnumValuesOrValueOf(method)
|
||||
else -> true
|
||||
override val innerClasses: List<ReflectJavaClass>
|
||||
get() = klass.declaredClasses
|
||||
.asSequence()
|
||||
.filterNot {
|
||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are
|
||||
// in fact anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private
|
||||
// nested class constructor accessed from the outer class
|
||||
it.simpleName.isEmpty()
|
||||
}
|
||||
}
|
||||
.map(::ReflectJavaMethod)
|
||||
.toList()
|
||||
.map(::ReflectJavaClass)
|
||||
.toList()
|
||||
|
||||
override val fqName: FqName
|
||||
get() = klass.classId.asSingleFqName()
|
||||
|
||||
override val outerClass: ReflectJavaClass?
|
||||
get() = klass.declaringClass?.let(::ReflectJavaClass)
|
||||
|
||||
override val supertypes: Collection<JavaClassifierType>
|
||||
get() {
|
||||
if (klass == Any::class.java) return emptyList()
|
||||
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
||||
}
|
||||
|
||||
override val methods: List<ReflectJavaMethod>
|
||||
get() = klass.declaredMethods
|
||||
.asSequence()
|
||||
.filter { method ->
|
||||
when {
|
||||
method.isSynthetic -> false
|
||||
isEnum -> !isEnumValuesOrValueOf(method)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
.map(::ReflectJavaMethod)
|
||||
.toList()
|
||||
|
||||
private fun isEnumValuesOrValueOf(method: Method): Boolean {
|
||||
return when (method.name) {
|
||||
@@ -69,27 +75,35 @@ class ReflectJavaClass(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFields() = klass.declaredFields
|
||||
.asSequence()
|
||||
.filter { field -> !field.isSynthetic }
|
||||
.map(::ReflectJavaField)
|
||||
.toList()
|
||||
override val fields: List<ReflectJavaField>
|
||||
get() = klass.declaredFields
|
||||
.asSequence()
|
||||
.filter { field -> !field.isSynthetic }
|
||||
.map(::ReflectJavaField)
|
||||
.toList()
|
||||
|
||||
override fun getConstructors() = klass.declaredConstructors
|
||||
.asSequence()
|
||||
.filter { constructor -> !constructor.isSynthetic }
|
||||
.map(::ReflectJavaConstructor)
|
||||
.toList()
|
||||
override val constructors: List<ReflectJavaConstructor>
|
||||
get() = klass.declaredConstructors
|
||||
.asSequence()
|
||||
.filter { constructor -> !constructor.isSynthetic }
|
||||
.map(::ReflectJavaConstructor)
|
||||
.toList()
|
||||
|
||||
override fun isKotlinLightClass() = false
|
||||
override val isKotlinLightClass: Boolean
|
||||
get() = false
|
||||
|
||||
override fun getName() = Name.identifier(klass.simpleName)
|
||||
override val name: Name
|
||||
get() = Name.identifier(klass.simpleName)
|
||||
|
||||
override fun getTypeParameters() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
override val typeParameters: List<ReflectJavaTypeParameter>
|
||||
get() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
|
||||
override fun isInterface() = klass.isInterface
|
||||
override fun isAnnotationType() = klass.isAnnotation
|
||||
override fun isEnum() = klass.isEnum
|
||||
override val isInterface: Boolean
|
||||
get() = klass.isInterface
|
||||
override val isAnnotationType: Boolean
|
||||
get() = klass.isAnnotation
|
||||
override val isEnum: Boolean
|
||||
get() = klass.isEnum
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaClass && klass == other.klass
|
||||
|
||||
|
||||
+15
-14
@@ -25,9 +25,9 @@ import java.lang.reflect.ParameterizedType
|
||||
import java.lang.reflect.Type
|
||||
import java.lang.reflect.TypeVariable
|
||||
|
||||
class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaType(), JavaClassifierType {
|
||||
private val classifier: JavaClassifier = run {
|
||||
val type = type
|
||||
class ReflectJavaClassifierType(public override val reflectType: Type) : ReflectJavaType(), JavaClassifierType {
|
||||
override val classifier: JavaClassifier = run {
|
||||
val type = reflectType
|
||||
val classifier: JavaClassifier = when (type) {
|
||||
is Class<*> -> ReflectJavaClass(type)
|
||||
is TypeVariable<*> -> ReflectJavaTypeParameter(type)
|
||||
@@ -37,25 +37,26 @@ class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaTyp
|
||||
classifier
|
||||
}
|
||||
|
||||
override fun getClassifier(): JavaClassifier = classifier
|
||||
override val presentableText: String
|
||||
get() = reflectType.toString()
|
||||
|
||||
override fun getPresentableText(): String = type.toString()
|
||||
override val isRaw: Boolean
|
||||
get() = with(reflectType) { this is Class<*> && getTypeParameters().isNotEmpty() }
|
||||
|
||||
override fun isRaw(): Boolean = with(type) { this is Class<*> && getTypeParameters().isNotEmpty() }
|
||||
|
||||
override fun getTypeArguments(): List<JavaType> {
|
||||
return generateSequence({type as? ParameterizedType}, { it.ownerType as? ParameterizedType }).flatMap {
|
||||
override val typeArguments: List<JavaType>
|
||||
get() = generateSequence({ reflectType as? ParameterizedType }, { it.ownerType as? ParameterizedType }).flatMap {
|
||||
it.actualTypeArguments.asSequence().map { ReflectJavaType.create(it) }
|
||||
}.toList()
|
||||
}
|
||||
|
||||
override fun getAnnotations(): Collection<JavaAnnotation> {
|
||||
return emptyList() // TODO
|
||||
}
|
||||
override val annotations: Collection<JavaAnnotation>
|
||||
get() {
|
||||
return emptyList() // TODO
|
||||
}
|
||||
|
||||
override fun findAnnotation(fqName: FqName): JavaAnnotation? {
|
||||
return null // TODO
|
||||
}
|
||||
|
||||
override fun isDeprecatedInJavaDoc() = false
|
||||
override val isDeprecatedInJavaDoc: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
+20
-19
@@ -17,33 +17,34 @@
|
||||
package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaConstructor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
class ReflectJavaConstructor(override val member: Constructor<*>) : ReflectJavaMember(), JavaConstructor {
|
||||
// TODO: test local/anonymous classes
|
||||
override fun getValueParameters(): List<JavaValueParameter> {
|
||||
val types = member.genericParameterTypes
|
||||
if (types.isEmpty()) return emptyList()
|
||||
override val valueParameters: List<JavaValueParameter>
|
||||
get() {
|
||||
val types = member.genericParameterTypes
|
||||
if (types.isEmpty()) return emptyList()
|
||||
|
||||
val klass = member.declaringClass
|
||||
val klass = member.declaringClass
|
||||
|
||||
val realTypes = when {
|
||||
klass.declaringClass != null && !Modifier.isStatic(klass.modifiers) -> types.copyOfRange(1, types.size)
|
||||
else -> types
|
||||
val realTypes = when {
|
||||
klass.declaringClass != null && !Modifier.isStatic(klass.modifiers) -> types.copyOfRange(1, types.size)
|
||||
else -> types
|
||||
}
|
||||
|
||||
val annotations = member.parameterAnnotations
|
||||
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)
|
||||
else -> annotations
|
||||
}
|
||||
|
||||
return getValueParameters(realTypes, realAnnotations, member.isVarArgs)
|
||||
}
|
||||
|
||||
val annotations = member.parameterAnnotations
|
||||
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)
|
||||
else -> annotations
|
||||
}
|
||||
|
||||
return getValueParameters(realTypes, realAnnotations, member.isVarArgs)
|
||||
}
|
||||
|
||||
override fun getTypeParameters() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
override val typeParameters: List<ReflectJavaTypeParameter>
|
||||
get() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
}
|
||||
|
||||
+4
-2
@@ -20,7 +20,9 @@ import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaField {
|
||||
override fun isEnumEntry() = member.isEnumConstant
|
||||
override val isEnumEntry: Boolean
|
||||
get() = member.isEnumConstant
|
||||
|
||||
override fun getType() = ReflectJavaType.create(member.genericType)
|
||||
override val type: ReflectJavaType
|
||||
get() = ReflectJavaType.create(member.genericType)
|
||||
}
|
||||
|
||||
+4
-2
@@ -33,9 +33,11 @@ abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOw
|
||||
|
||||
override val modifiers: Int get() = member.modifiers
|
||||
|
||||
override fun getName() = member.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
||||
override val name: Name
|
||||
get() = member.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
||||
|
||||
override fun getContainingClass() = ReflectJavaClass(member.declaringClass)
|
||||
override val containingClass: ReflectJavaClass
|
||||
get() = ReflectJavaClass(member.declaringClass)
|
||||
|
||||
protected fun getValueParameters(
|
||||
parameterTypes: Array<Type>,
|
||||
|
||||
+8
-5
@@ -21,12 +21,15 @@ import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class ReflectJavaMethod(override val member: Method) : ReflectJavaMember(), JavaMethod {
|
||||
override fun getValueParameters(): List<JavaValueParameter> =
|
||||
getValueParameters(member.genericParameterTypes, member.parameterAnnotations, member.isVarArgs)
|
||||
override val valueParameters: List<JavaValueParameter>
|
||||
get() = getValueParameters(member.genericParameterTypes, member.parameterAnnotations, member.isVarArgs)
|
||||
|
||||
override fun getReturnType() = ReflectJavaType.create(member.genericReturnType)
|
||||
override val returnType: ReflectJavaType
|
||||
get() = ReflectJavaType.create(member.genericReturnType)
|
||||
|
||||
override fun hasAnnotationParameterDefaultValue() = member.defaultValue != null
|
||||
override val hasAnnotationParameterDefaultValue: Boolean
|
||||
get() = member.defaultValue != null
|
||||
|
||||
override fun getTypeParameters() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
override val typeParameters: List<ReflectJavaTypeParameter>
|
||||
get() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
}
|
||||
|
||||
+18
-12
@@ -25,18 +25,24 @@ import java.lang.reflect.Modifier
|
||||
interface ReflectJavaModifierListOwner : JavaModifierListOwner {
|
||||
/* protected // KT-3029 */ val modifiers: Int
|
||||
|
||||
override fun isAbstract() = Modifier.isAbstract(modifiers)
|
||||
override fun isStatic() = Modifier.isStatic(modifiers)
|
||||
override fun isFinal() = Modifier.isFinal(modifiers)
|
||||
override val isAbstract: Boolean
|
||||
get() = Modifier.isAbstract(modifiers)
|
||||
|
||||
override fun getVisibility(): Visibility = modifiers.let { modifiers ->
|
||||
when {
|
||||
Modifier.isPublic(modifiers) -> Visibilities.PUBLIC
|
||||
Modifier.isPrivate(modifiers) -> Visibilities.PRIVATE
|
||||
Modifier.isProtected(modifiers) ->
|
||||
if (Modifier.isStatic(modifiers)) JavaVisibilities.PROTECTED_STATIC_VISIBILITY
|
||||
else JavaVisibilities.PROTECTED_AND_PACKAGE
|
||||
else -> JavaVisibilities.PACKAGE_VISIBILITY
|
||||
override val isStatic: Boolean
|
||||
get() = Modifier.isStatic(modifiers)
|
||||
|
||||
override val isFinal: Boolean
|
||||
get() = Modifier.isFinal(modifiers)
|
||||
|
||||
override val visibility: Visibility
|
||||
get() = modifiers.let { modifiers ->
|
||||
when {
|
||||
Modifier.isPublic(modifiers) -> Visibilities.PUBLIC
|
||||
Modifier.isPrivate(modifiers) -> Visibilities.PRIVATE
|
||||
Modifier.isProtected(modifiers) ->
|
||||
if (Modifier.isStatic(modifiers)) JavaVisibilities.PROTECTED_STATIC_VISIBILITY
|
||||
else JavaVisibilities.PROTECTED_AND_PACKAGE
|
||||
else -> JavaVisibilities.PACKAGE_VISIBILITY
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -21,18 +21,17 @@ import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
||||
override fun getFqName() = fqName
|
||||
|
||||
class ReflectJavaPackage(override val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
||||
override fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass> {
|
||||
// A package at runtime can't know what classes it has and has not
|
||||
return listOf()
|
||||
}
|
||||
|
||||
override fun getSubPackages(): Collection<JavaPackage> {
|
||||
// A package at runtime can't know what sub packages it has and has not
|
||||
return listOf()
|
||||
}
|
||||
override val subPackages: Collection<JavaPackage>
|
||||
get() {
|
||||
// A package at runtime can't know what sub packages it has and has not
|
||||
return listOf()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaPackage && fqName == other.fqName
|
||||
|
||||
|
||||
+7
-4
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPrimitiveType
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
|
||||
class ReflectJavaPrimitiveType(override val type: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
||||
override fun getType() =
|
||||
if (type == Void.TYPE) null
|
||||
else JvmPrimitiveType.get(type.name).primitiveType
|
||||
class ReflectJavaPrimitiveType(override val reflectType: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
||||
override val type: PrimitiveType?
|
||||
get() = if (reflectType == Void.TYPE)
|
||||
null
|
||||
else
|
||||
JvmPrimitiveType.get(reflectType.name).primitiveType
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import java.lang.reflect.Type
|
||||
import java.lang.reflect.WildcardType
|
||||
|
||||
abstract class ReflectJavaType : JavaType {
|
||||
protected abstract val type: Type
|
||||
protected abstract val reflectType: Type
|
||||
|
||||
companion object Factory {
|
||||
fun create(type: Type): ReflectJavaType {
|
||||
@@ -35,9 +35,9 @@ abstract class ReflectJavaType : JavaType {
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaType && type == other.type
|
||||
override fun equals(other: Any?) = other is ReflectJavaType && reflectType == other.reflectType
|
||||
|
||||
override fun hashCode() = type.hashCode()
|
||||
override fun hashCode() = reflectType.hashCode()
|
||||
|
||||
override fun toString() = javaClass.name + ": " + type
|
||||
override fun toString() = javaClass.name + ": " + reflectType
|
||||
}
|
||||
|
||||
+8
-6
@@ -24,17 +24,19 @@ import java.lang.reflect.TypeVariable
|
||||
class ReflectJavaTypeParameter(
|
||||
val typeVariable: TypeVariable<*>
|
||||
) : ReflectJavaElement(), JavaTypeParameter, ReflectJavaAnnotationOwner {
|
||||
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
|
||||
val bounds = typeVariable.bounds.map { bound -> ReflectJavaClassifierType(bound) }
|
||||
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
|
||||
return bounds
|
||||
}
|
||||
override val upperBounds: List<ReflectJavaClassifierType>
|
||||
get() {
|
||||
val bounds = typeVariable.bounds.map { bound -> ReflectJavaClassifierType(bound) }
|
||||
if (bounds.singleOrNull()?.reflectType == Any::class.java) return emptyList()
|
||||
return bounds
|
||||
}
|
||||
|
||||
override val element: AnnotatedElement?
|
||||
// TypeVariable is AnnotatedElement only in JDK8
|
||||
get() = typeVariable as? AnnotatedElement
|
||||
|
||||
override fun getName() = Name.identifier(typeVariable.name)
|
||||
override val name: Name
|
||||
get() = Name.identifier(typeVariable.name)
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaTypeParameter && typeVariable == other.typeVariable
|
||||
|
||||
|
||||
+13
-11
@@ -21,20 +21,22 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class ReflectJavaValueParameter(
|
||||
private val returnType: ReflectJavaType,
|
||||
private val annotations: Array<Annotation>,
|
||||
private val name: String?,
|
||||
private val isVararg: Boolean
|
||||
override val type: ReflectJavaType,
|
||||
private val reflectAnnotations: Array<Annotation>,
|
||||
private val reflectName: String?,
|
||||
override val isVararg: Boolean
|
||||
) : ReflectJavaElement(), JavaValueParameter {
|
||||
override fun getAnnotations() = annotations.getAnnotations()
|
||||
override val annotations: List<ReflectJavaAnnotation>
|
||||
get() = reflectAnnotations.getAnnotations()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotations.findAnnotation(fqName)
|
||||
override fun findAnnotation(fqName: FqName) =
|
||||
reflectAnnotations.findAnnotation(fqName)
|
||||
|
||||
override fun isDeprecatedInJavaDoc() = false
|
||||
override val isDeprecatedInJavaDoc: Boolean
|
||||
get() = false
|
||||
|
||||
override fun getName() = name?.let(Name::guessByFirstCharacter)
|
||||
override fun getType() = returnType
|
||||
override fun isVararg() = isVararg
|
||||
override val name: Name?
|
||||
get() = reflectName?.let(Name::guessByFirstCharacter)
|
||||
|
||||
override fun toString() = javaClass.name + ": " + (if (isVararg) "vararg " else "") + getName() + ": " + returnType
|
||||
override fun toString() = javaClass.name + ": " + (if (isVararg) "vararg " else "") + name + ": " + type
|
||||
}
|
||||
|
||||
+15
-13
@@ -19,19 +19,21 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType
|
||||
import java.lang.reflect.WildcardType
|
||||
|
||||
class ReflectJavaWildcardType(override val type: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||
override fun getBound(): ReflectJavaType? {
|
||||
val upperBounds = type.upperBounds
|
||||
val lowerBounds = type.lowerBounds
|
||||
if (upperBounds.size > 1 || lowerBounds.size > 1) {
|
||||
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
|
||||
class ReflectJavaWildcardType(override val reflectType: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||
override val bound: ReflectJavaType?
|
||||
get() {
|
||||
val upperBounds = reflectType.upperBounds
|
||||
val lowerBounds = reflectType.lowerBounds
|
||||
if (upperBounds.size > 1 || lowerBounds.size > 1) {
|
||||
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $reflectType")
|
||||
}
|
||||
return when {
|
||||
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
|
||||
}
|
||||
}
|
||||
return when {
|
||||
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.upperBounds.firstOrNull() != Any::class.java
|
||||
override val isExtends: Boolean
|
||||
get() = reflectType.upperBounds.firstOrNull() != Any::class.java
|
||||
}
|
||||
|
||||
-1
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||
import org.jetbrains.kotlin.load.java.reflect.ReflectJavaClassFinder
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPropertyInitializerEvaluator
|
||||
import org.jetbrains.kotlin.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
|
||||
|
||||
Reference in New Issue
Block a user