Migrate JavaClassResolver from PSI to JavaClass
Several places are still left and need special handling. The overall behavior of the resolver should not change in this commit (except for maybe different small operations like creating names, fq-names, ...)
This commit is contained in:
+6
-6
@@ -40,9 +40,9 @@ public final class DescriptorResolverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCompiledKotlinPackageClass(@NotNull JavaClass javaClass) {
|
public static boolean isCompiledKotlinPackageClass(@NotNull JavaClass javaClass) {
|
||||||
if (javaClass.getPsiClass() instanceof ClsClassImpl) {
|
if (javaClass.getPsi() instanceof ClsClassImpl) {
|
||||||
String fqName = javaClass.getFqName();
|
FqName fqName = javaClass.getFqName();
|
||||||
if (fqName != null && PackageClassUtils.isPackageClassFqName(new FqName(fqName))) {
|
if (fqName != null && PackageClassUtils.isPackageClassFqName(fqName)) {
|
||||||
return hasAnnotation(javaClass, JvmAnnotationNames.KOTLIN_PACKAGE.getFqName());
|
return hasAnnotation(javaClass, JvmAnnotationNames.KOTLIN_PACKAGE.getFqName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public final class DescriptorResolverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCompiledKotlinClass(@NotNull JavaClass javaClass) {
|
public static boolean isCompiledKotlinClass(@NotNull JavaClass javaClass) {
|
||||||
if (javaClass.getPsiClass() instanceof ClsClassImpl) {
|
if (javaClass.getPsi() instanceof ClsClassImpl) {
|
||||||
return hasAnnotation(javaClass, JvmAnnotationNames.KOTLIN_CLASS.getFqName());
|
return hasAnnotation(javaClass, JvmAnnotationNames.KOTLIN_CLASS.getFqName());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -153,11 +153,11 @@ public final class DescriptorResolverUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Collection<JavaClass> filterDuplicateClasses(@NotNull Collection<JavaClass> classes) {
|
public static Collection<JavaClass> filterDuplicateClasses(@NotNull Collection<JavaClass> classes) {
|
||||||
Set<String> addedQualifiedNames = new HashSet<String>(classes.size());
|
Set<FqName> addedQualifiedNames = new HashSet<FqName>(classes.size());
|
||||||
List<JavaClass> result = new ArrayList<JavaClass>(classes.size());
|
List<JavaClass> result = new ArrayList<JavaClass>(classes.size());
|
||||||
|
|
||||||
for (JavaClass javaClass : classes) {
|
for (JavaClass javaClass : classes) {
|
||||||
String fqName = javaClass.getFqName();
|
FqName fqName = javaClass.getFqName();
|
||||||
if (fqName != null && addedQualifiedNames.add(fqName)) {
|
if (fqName != null && addedQualifiedNames.add(fqName)) {
|
||||||
result.add(javaClass);
|
result.add(javaClass);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -123,7 +123,7 @@ public final class MembersCache {
|
|||||||
|
|
||||||
private void process() {
|
private void process() {
|
||||||
for (JavaClass javaClass : javaClasses) {
|
for (JavaClass javaClass : javaClasses) {
|
||||||
PsiClass psiClass = javaClass.getPsiClass();
|
PsiClass psiClass = javaClass.getPsi();
|
||||||
|
|
||||||
if (!(psiClass instanceof JetJavaMirrorMarker)) { // to filter out JetLightClasses
|
if (!(psiClass instanceof JetJavaMirrorMarker)) { // to filter out JetLightClasses
|
||||||
if (SingleAbstractMethodUtils.isSamInterface(psiClass)) {
|
if (SingleAbstractMethodUtils.isSamInterface(psiClass)) {
|
||||||
@@ -145,7 +145,7 @@ public final class MembersCache {
|
|||||||
private final boolean staticMembers;
|
private final boolean staticMembers;
|
||||||
|
|
||||||
private ClassMemberProcessor(@NotNull JavaClass javaClass, boolean staticMembers) {
|
private ClassMemberProcessor(@NotNull JavaClass javaClass, boolean staticMembers) {
|
||||||
this.psiClass = javaClass.getPsiClass();
|
this.psiClass = javaClass.getPsi();
|
||||||
this.staticMembers = staticMembers;
|
this.staticMembers = staticMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+42
-71
@@ -23,8 +23,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
|||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiMethod;
|
|
||||||
import com.intellij.psi.PsiModifier;
|
|
||||||
import gnu.trove.THashMap;
|
import gnu.trove.THashMap;
|
||||||
import gnu.trove.TObjectHashingStrategy;
|
import gnu.trove.TObjectHashingStrategy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -39,8 +37,8 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmByte
|
|||||||
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.scope.JavaClassNonStaticMembersScope;
|
import org.jetbrains.jet.lang.resolve.java.scope.JavaClassNonStaticMembersScope;
|
||||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||||
import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder;
|
import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder;
|
||||||
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqNameBase;
|
import org.jetbrains.jet.lang.resolve.name.FqNameBase;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
@@ -254,14 +252,13 @@ public final class JavaClassResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Class may have been resolved previously by different Java resolver instance, and we are reusing its trace
|
// Class may have been resolved previously by different Java resolver instance, and we are reusing its trace
|
||||||
ClassDescriptor alreadyResolved = trace.get(BindingContext.CLASS, javaClass.getPsiClass());
|
ClassDescriptor alreadyResolved = trace.get(BindingContext.CLASS, javaClass.getPsi());
|
||||||
if (alreadyResolved != null) {
|
if (alreadyResolved != null) {
|
||||||
return alreadyResolved;
|
return alreadyResolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiClass psiClass = javaClass.getPsiClass();
|
|
||||||
//TODO: code duplication
|
//TODO: code duplication
|
||||||
ClassOrNamespaceDescriptor containingDeclaration = resolveParentDescriptor(qualifiedName, isContainedInClass(psiClass));
|
ClassOrNamespaceDescriptor containingDeclaration = resolveParentDescriptor(qualifiedName, javaClass.getOuterClass() != null);
|
||||||
// class may be resolved during resolution of parent
|
// class may be resolved during resolution of parent
|
||||||
ClassDescriptor cachedDescriptor = classDescriptorCache.get(javaClassToKotlinFqName(qualifiedName));
|
ClassDescriptor cachedDescriptor = classDescriptorCache.get(javaClassToKotlinFqName(qualifiedName));
|
||||||
if (cachedDescriptor != null) {
|
if (cachedDescriptor != null) {
|
||||||
@@ -270,8 +267,8 @@ public final class JavaClassResolver {
|
|||||||
assert (!unresolvedCache
|
assert (!unresolvedCache
|
||||||
.contains(qualifiedName)) : "We can resolve the class, so it can't be 'unresolved' during parent resolution";
|
.contains(qualifiedName)) : "We can resolve the class, so it can't be 'unresolved' during parent resolution";
|
||||||
|
|
||||||
checkFqNamesAreConsistent(psiClass, qualifiedName);
|
checkFqNamesAreConsistent(javaClass, qualifiedName);
|
||||||
checkPsiClassIsNotJet(psiClass);
|
checkPsiClassIsNotJet(javaClass);
|
||||||
|
|
||||||
|
|
||||||
return doCreateClassDescriptor(qualifiedName, javaClass, tasks, containingDeclaration);
|
return doCreateClassDescriptor(qualifiedName, javaClass, tasks, containingDeclaration);
|
||||||
@@ -296,47 +293,46 @@ public final class JavaClassResolver {
|
|||||||
@NotNull PostponedTasks taskList,
|
@NotNull PostponedTasks taskList,
|
||||||
@NotNull ClassOrNamespaceDescriptor containingDeclaration
|
@NotNull ClassOrNamespaceDescriptor containingDeclaration
|
||||||
) {
|
) {
|
||||||
PsiClass psiClass = javaClass.getPsiClass();
|
ClassDescriptorFromJvmBytecode classDescriptor = new ClassDescriptorFromJvmBytecode(containingDeclaration, javaClass.getKind(),
|
||||||
|
isInnerClass(javaClass));
|
||||||
ClassDescriptorFromJvmBytecode classDescriptor = new ClassDescriptorFromJvmBytecode(containingDeclaration, getClassKind(psiClass),
|
|
||||||
isInnerClass(psiClass));
|
|
||||||
|
|
||||||
cache(javaClassToKotlinFqName(fqName), classDescriptor);
|
cache(javaClassToKotlinFqName(fqName), classDescriptor);
|
||||||
|
|
||||||
classDescriptor.setName(Name.identifier(psiClass.getName()));
|
classDescriptor.setName(javaClass.getName());
|
||||||
|
|
||||||
List<JavaSignatureResolver.TypeParameterDescriptorInitialization> typeParameterDescriptorInitializations
|
List<JavaSignatureResolver.TypeParameterDescriptorInitialization> typeParameterDescriptorInitializations
|
||||||
= JavaSignatureResolver.createUninitializedClassTypeParameters(psiClass, classDescriptor);
|
= JavaSignatureResolver.createUninitializedClassTypeParameters(javaClass, classDescriptor);
|
||||||
|
|
||||||
classDescriptor.setTypeParameterDescriptors(getTypeParametersDescriptors(typeParameterDescriptorInitializations));
|
classDescriptor.setTypeParameterDescriptors(getTypeParametersDescriptors(typeParameterDescriptorInitializations));
|
||||||
List<JetType> supertypes = Lists.newArrayList();
|
List<JetType> supertypes = Lists.newArrayList();
|
||||||
classDescriptor.setSupertypes(supertypes);
|
classDescriptor.setSupertypes(supertypes);
|
||||||
classDescriptor.setVisibility(DescriptorResolverUtils.resolveVisibility(psiClass));
|
classDescriptor.setVisibility(javaClass.getVisibility());
|
||||||
classDescriptor.setModality(resolveModality(psiClass, classDescriptor));
|
classDescriptor.setModality(javaClass.getModality());
|
||||||
classDescriptor.createTypeConstructor();
|
classDescriptor.createTypeConstructor();
|
||||||
|
|
||||||
JavaClassNonStaticMembersScope scope = new JavaClassNonStaticMembersScope(classDescriptor, javaClass, false, javaDescriptorResolver);
|
JavaClassNonStaticMembersScope scope = new JavaClassNonStaticMembersScope(classDescriptor, javaClass, false, javaDescriptorResolver);
|
||||||
classDescriptor.setScopeForMemberLookup(scope);
|
classDescriptor.setScopeForMemberLookup(scope);
|
||||||
classDescriptor.setScopeForConstructorResolve(scope);
|
classDescriptor.setScopeForConstructorResolve(scope);
|
||||||
|
|
||||||
String context = "class " + psiClass.getQualifiedName();
|
signatureResolver.initializeTypeParameters(typeParameterDescriptorInitializations, classDescriptor,
|
||||||
signatureResolver.initializeTypeParameters(typeParameterDescriptorInitializations, classDescriptor, context);
|
"class " + javaClass.getFqName());
|
||||||
|
|
||||||
// TODO: ugly hack: tests crash if initializeTypeParameters called with class containing proper supertypes
|
// TODO: ugly hack: tests crash if initializeTypeParameters called with class containing proper supertypes
|
||||||
List<TypeParameterDescriptor> classTypeParameters = classDescriptor.getTypeConstructor().getParameters();
|
List<TypeParameterDescriptor> classTypeParameters = classDescriptor.getTypeConstructor().getParameters();
|
||||||
supertypes.addAll(supertypesResolver.getSupertypes(classDescriptor, psiClass, classTypeParameters));
|
supertypes.addAll(supertypesResolver.getSupertypes(classDescriptor, javaClass, classTypeParameters));
|
||||||
|
|
||||||
if (psiClass.isEnum()) {
|
if (javaClass.isEnum()) {
|
||||||
ClassDescriptorFromJvmBytecode classObjectDescriptor = createClassObjectDescriptorForEnum(classDescriptor, javaClass);
|
ClassDescriptorFromJvmBytecode classObjectDescriptor = createClassObjectDescriptorForEnum(classDescriptor, javaClass);
|
||||||
cache(getFqNameForClassObject(psiClass), classObjectDescriptor);
|
cache(getFqNameForClassObject(javaClass), classObjectDescriptor);
|
||||||
classDescriptor.getBuilder().setClassObjectDescriptor(classObjectDescriptor);
|
classDescriptor.getBuilder().setClassObjectDescriptor(classObjectDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PsiClass psiClass = javaClass.getPsi();
|
||||||
classDescriptor.setAnnotations(annotationResolver.resolveAnnotations(psiClass, taskList));
|
classDescriptor.setAnnotations(annotationResolver.resolveAnnotations(psiClass, taskList));
|
||||||
|
|
||||||
trace.record(BindingContext.CLASS, psiClass, classDescriptor);
|
trace.record(BindingContext.CLASS, psiClass, classDescriptor);
|
||||||
|
|
||||||
PsiMethod samInterfaceMethod = SingleAbstractMethodUtils.getSamInterfaceMethod(psiClass);
|
JavaMethod samInterfaceMethod = SingleAbstractMethodUtils.getSamInterfaceMethod(javaClass, psiClass.getProject());
|
||||||
if (samInterfaceMethod != null) {
|
if (samInterfaceMethod != null) {
|
||||||
SimpleFunctionDescriptor abstractMethod = resolveFunctionOfSamInterface(samInterfaceMethod, classDescriptor);
|
SimpleFunctionDescriptor abstractMethod = resolveFunctionOfSamInterface(samInterfaceMethod, classDescriptor);
|
||||||
classDescriptor.setFunctionTypeForSamInterface(SingleAbstractMethodUtils.getFunctionTypeForAbstractMethod(abstractMethod));
|
classDescriptor.setFunctionTypeForSamInterface(SingleAbstractMethodUtils.getFunctionTypeForAbstractMethod(abstractMethod));
|
||||||
@@ -346,25 +342,24 @@ public final class JavaClassResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static FqNameUnsafe getFqNameForClassObject(@NotNull PsiClass psiClass) {
|
private static FqNameUnsafe getFqNameForClassObject(@NotNull JavaClass javaClass) {
|
||||||
String qualifiedName = psiClass.getQualifiedName();
|
FqName fqName = javaClass.getFqName();
|
||||||
assert qualifiedName != null : "Reading java class with no qualified name";
|
assert fqName != null : "Reading java class with no qualified name";
|
||||||
return new FqNameUnsafe(qualifiedName + "." + getClassObjectName(psiClass.getName()).asString());
|
return fqName.toUnsafe().child(getClassObjectName(javaClass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SimpleFunctionDescriptor resolveFunctionOfSamInterface(
|
private SimpleFunctionDescriptor resolveFunctionOfSamInterface(
|
||||||
@NotNull PsiMethod samInterfaceMethod,
|
@NotNull JavaMethod samInterfaceMethod,
|
||||||
@NotNull ClassDescriptorFromJvmBytecode samInterface
|
@NotNull ClassDescriptorFromJvmBytecode samInterface
|
||||||
) {
|
) {
|
||||||
PsiClass methodContainer = samInterfaceMethod.getContainingClass();
|
JavaClass methodContainer = samInterfaceMethod.getContainingClass();
|
||||||
assert methodContainer != null : "method container is null for " + samInterfaceMethod;
|
assert methodContainer != null : "method container is null for " + samInterfaceMethod;
|
||||||
String containerQualifiedName = methodContainer.getQualifiedName();
|
FqName containerFqName = methodContainer.getFqName();
|
||||||
assert containerQualifiedName != null : "qualified name is null for " + methodContainer;
|
assert containerFqName != null : "qualified name is null for " + methodContainer;
|
||||||
|
|
||||||
if (DescriptorUtils.getFQName(samInterface).asString().equals(containerQualifiedName)) {
|
if (DescriptorUtils.getFQName(samInterface).equalsTo(containerFqName)) {
|
||||||
SimpleFunctionDescriptor abstractMethod =
|
SimpleFunctionDescriptor abstractMethod = functionResolver.resolveFunctionMutely(samInterfaceMethod, samInterface);
|
||||||
functionResolver.resolveFunctionMutely(new PsiMethodWrapper(samInterfaceMethod), samInterface);
|
|
||||||
assert abstractMethod != null : "couldn't resolve method " + samInterfaceMethod;
|
assert abstractMethod != null : "couldn't resolve method " + samInterfaceMethod;
|
||||||
return abstractMethod;
|
return abstractMethod;
|
||||||
}
|
}
|
||||||
@@ -373,6 +368,7 @@ public final class JavaClassResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private static SimpleFunctionDescriptor findFunctionWithMostSpecificReturnType(@NotNull Set<JetType> supertypes) {
|
private static SimpleFunctionDescriptor findFunctionWithMostSpecificReturnType(@NotNull Set<JetType> supertypes) {
|
||||||
List<SimpleFunctionDescriptor> candidates = Lists.newArrayList();
|
List<SimpleFunctionDescriptor> candidates = Lists.newArrayList();
|
||||||
for (JetType supertype : supertypes) {
|
for (JetType supertype : supertypes) {
|
||||||
@@ -386,7 +382,10 @@ public final class JavaClassResolver {
|
|||||||
}
|
}
|
||||||
SimpleFunctionDescriptor currentMostSpecificType = candidates.get(0);
|
SimpleFunctionDescriptor currentMostSpecificType = candidates.get(0);
|
||||||
for (SimpleFunctionDescriptor candidate : candidates) {
|
for (SimpleFunctionDescriptor candidate : candidates) {
|
||||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(candidate.getReturnType(), currentMostSpecificType.getReturnType())) {
|
JetType candidateReturnType = candidate.getReturnType();
|
||||||
|
JetType currentMostSpecificReturnType = currentMostSpecificType.getReturnType();
|
||||||
|
assert candidateReturnType != null && currentMostSpecificReturnType != null : candidate + ", " + currentMostSpecificReturnType;
|
||||||
|
if (JetTypeChecker.INSTANCE.isSubtypeOf(candidateReturnType, currentMostSpecificReturnType)) {
|
||||||
currentMostSpecificType = candidate;
|
currentMostSpecificType = candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,31 +413,18 @@ public final class JavaClassResolver {
|
|||||||
return typeParameters;
|
return typeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private void checkFqNamesAreConsistent(@NotNull JavaClass javaClass, @NotNull FqName desiredFqName) {
|
||||||
private static Modality resolveModality(@NotNull PsiClass psiClass, @NotNull ClassDescriptor classDescriptor) {
|
FqName fqName = javaClass.getFqName();
|
||||||
if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
|
assert desiredFqName.equals(fqName) : "Inconsistent FQ names: " + fqName + ", " + desiredFqName;
|
||||||
return Modality.FINAL;
|
|
||||||
}
|
|
||||||
return Modality.convertFromFlags(
|
|
||||||
psiClass.hasModifierProperty(PsiModifier.ABSTRACT) || psiClass.isInterface(),
|
|
||||||
!psiClass.hasModifierProperty(PsiModifier.FINAL));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkFqNamesAreConsistent(@NotNull PsiClass psiClass, @NotNull FqName desiredFqName) {
|
|
||||||
String qualifiedName = psiClass.getQualifiedName();
|
|
||||||
assert qualifiedName != null;
|
|
||||||
|
|
||||||
FqName fqName = new FqName(qualifiedName);
|
|
||||||
assert fqName.equals(desiredFqName);
|
|
||||||
FqNameUnsafe correctedName = javaClassToKotlinFqName(fqName);
|
FqNameUnsafe correctedName = javaClassToKotlinFqName(fqName);
|
||||||
if (classDescriptorCache.containsKey(correctedName) || unresolvedCache.contains(correctedName)) {
|
if (classDescriptorCache.containsKey(correctedName) || unresolvedCache.contains(correctedName)) {
|
||||||
throw new IllegalStateException(qualifiedName);
|
throw new IllegalStateException("Cache already contains FQ name: " + fqName.asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkPsiClassIsNotJet(@NotNull PsiClass psiClass) {
|
private static void checkPsiClassIsNotJet(@NotNull JavaClass javaClass) {
|
||||||
if (psiClass instanceof JetJavaMirrorMarker) {
|
if (javaClass.getPsi() instanceof JetJavaMirrorMarker) {
|
||||||
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + psiClass.getQualifiedName());
|
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + javaClass.getFqName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,23 +464,8 @@ public final class JavaClassResolver {
|
|||||||
return new FqNameUnsafe(StringUtil.join(correctedSegments, "."));
|
return new FqNameUnsafe(StringUtil.join(correctedSegments, "."));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isContainedInClass(@NotNull PsiClass psiClass) {
|
private static boolean isInnerClass(@NotNull JavaClass javaClass) {
|
||||||
return psiClass.getContainingClass() != null;
|
return javaClass.getOuterClass() != null && !javaClass.isStatic();
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isInnerClass(@NotNull PsiClass psiClass) {
|
|
||||||
return isContainedInClass(psiClass) && !psiClass.hasModifierProperty(PsiModifier.STATIC);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static ClassKind getClassKind(@NotNull PsiClass psiClass) {
|
|
||||||
if (psiClass.isInterface()) {
|
|
||||||
return (psiClass.isAnnotationType() ? ClassKind.ANNOTATION_CLASS : ClassKind.TRAIT);
|
|
||||||
}
|
|
||||||
if (psiClass.isEnum()) {
|
|
||||||
return ClassKind.ENUM_CLASS;
|
|
||||||
}
|
|
||||||
return ClassKind.CLASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ public final class JavaConstructorResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<ConstructorDescriptor> resolveConstructors(@NotNull JavaClass javaClass, @NotNull ClassDescriptor containingClass) {
|
public Collection<ConstructorDescriptor> resolveConstructors(@NotNull JavaClass javaClass, @NotNull ClassDescriptor containingClass) {
|
||||||
PsiClass psiClass = javaClass.getPsiClass();
|
PsiClass psiClass = javaClass.getPsi();
|
||||||
|
|
||||||
Collection<ConstructorDescriptor> constructors = Lists.newArrayList();
|
Collection<ConstructorDescriptor> constructors = Lists.newArrayList();
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmByte
|
|||||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSignatureData;
|
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSignatureData;
|
||||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesPropagationData;
|
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesPropagationData;
|
||||||
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||||
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
@@ -89,16 +90,18 @@ public final class JavaFunctionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
SimpleFunctionDescriptor resolveFunctionMutely(@NotNull PsiMethodWrapper method, @NotNull ClassOrNamespaceDescriptor owner) {
|
SimpleFunctionDescriptor resolveFunctionMutely(@NotNull JavaMethod method, @NotNull ClassOrNamespaceDescriptor owner) {
|
||||||
return resolveMethodToFunctionDescriptor(method, owner, false);
|
return resolveMethodToFunctionDescriptor(method, owner, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private SimpleFunctionDescriptor resolveMethodToFunctionDescriptor(
|
private SimpleFunctionDescriptor resolveMethodToFunctionDescriptor(
|
||||||
@NotNull PsiMethodWrapper method,
|
@NotNull JavaMethod javaMethod,
|
||||||
@NotNull ClassOrNamespaceDescriptor ownerDescriptor,
|
@NotNull ClassOrNamespaceDescriptor ownerDescriptor,
|
||||||
boolean record
|
boolean record
|
||||||
) {
|
) {
|
||||||
|
PsiMethodWrapper method = new PsiMethodWrapper(javaMethod.getPsi());
|
||||||
|
|
||||||
if (!DescriptorResolverUtils.isCorrectOwnerForEnumMember(ownerDescriptor, method.getPsiMember())) {
|
if (!DescriptorResolverUtils.isCorrectOwnerForEnumMember(ownerDescriptor, method.getPsiMember())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -244,7 +247,7 @@ public final class JavaFunctionResolver {
|
|||||||
|
|
||||||
Set<SimpleFunctionDescriptor> functionsFromCurrent = Sets.newHashSet();
|
Set<SimpleFunctionDescriptor> functionsFromCurrent = Sets.newHashSet();
|
||||||
for (PsiMethodWrapper method : members.getMethods()) {
|
for (PsiMethodWrapper method : members.getMethods()) {
|
||||||
SimpleFunctionDescriptor function = resolveMethodToFunctionDescriptor(method, owner, true);
|
SimpleFunctionDescriptor function = resolveMethodToFunctionDescriptor(new JavaMethod(method.getPsiMethod()), owner, true);
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
functionsFromCurrent.add(function);
|
functionsFromCurrent.add(function);
|
||||||
ContainerUtil.addIfNotNull(functionsFromCurrent, resolveSamAdapter(function));
|
ContainerUtil.addIfNotNull(functionsFromCurrent, resolveSamAdapter(function));
|
||||||
@@ -374,7 +377,8 @@ public final class JavaFunctionResolver {
|
|||||||
JetType transformedType = typeTransformer.transformToType(returnType, typeUsage, typeVariableResolver);
|
JetType transformedType = typeTransformer.transformToType(returnType, typeUsage, typeVariableResolver);
|
||||||
|
|
||||||
if (JavaAnnotationResolver
|
if (JavaAnnotationResolver
|
||||||
.findAnnotationWithExternal(method.getPsiMethod(), JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().asString()) !=
|
.findAnnotationWithExternal(method.getPsiMethod(),
|
||||||
|
JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().asString()) !=
|
||||||
null) {
|
null) {
|
||||||
return TypeUtils.makeNullableAsSpecified(transformedType, false);
|
return TypeUtils.makeNullableAsSpecified(transformedType, false);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -176,7 +176,7 @@ public final class JavaNamespaceResolver {
|
|||||||
|
|
||||||
// Otherwise (if psiClass is null or doesn't have a supported Kotlin annotation), it's a Java class and the package is empty
|
// Otherwise (if psiClass is null or doesn't have a supported Kotlin annotation), it's a Java class and the package is empty
|
||||||
if (record) {
|
if (record) {
|
||||||
trace.record(BindingContext.NAMESPACE, javaPackage.getPsiPackage(), namespaceDescriptor);
|
trace.record(BindingContext.NAMESPACE, javaPackage.getPsi(), namespaceDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JavaPackageScope(namespaceDescriptor, javaPackage, fqName, javaDescriptorResolver);
|
return new JavaPackageScope(namespaceDescriptor, javaPackage, fqName, javaDescriptorResolver);
|
||||||
@@ -190,7 +190,7 @@ public final class JavaNamespaceResolver {
|
|||||||
if (DescriptorResolverUtils.isCompiledKotlinClassOrPackageClass(javaClass)) {
|
if (DescriptorResolverUtils.isCompiledKotlinClassOrPackageClass(javaClass)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PsiClass psiClass = javaClass.getPsiClass();
|
PsiClass psiClass = javaClass.getPsi();
|
||||||
if (!hasStaticMembers(psiClass)) {
|
if (!hasStaticMembers(psiClass)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ public final class JavaNamespaceResolver {
|
|||||||
List<Name> result = new ArrayList<Name>(classes.size());
|
List<Name> result = new ArrayList<Name>(classes.size());
|
||||||
for (JavaClass javaClass : classes) {
|
for (JavaClass javaClass : classes) {
|
||||||
if (DescriptorResolverUtils.isCompiledKotlinClass(javaClass)) {
|
if (DescriptorResolverUtils.isCompiledKotlinClass(javaClass)) {
|
||||||
result.add(Name.identifier(javaClass.getName()));
|
result.add(javaClass.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-15
@@ -30,13 +30,16 @@ import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer;
|
import org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer;
|
||||||
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
||||||
import org.jetbrains.jet.lang.resolve.java.TypeVariableResolver;
|
import org.jetbrains.jet.lang.resolve.java.TypeVariableResolver;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassType;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -52,14 +55,14 @@ public final class JavaSignatureResolver {
|
|||||||
public static class TypeParameterDescriptorInitialization {
|
public static class TypeParameterDescriptorInitialization {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final TypeParameterDescriptorImpl descriptor;
|
private final TypeParameterDescriptorImpl descriptor;
|
||||||
private final PsiTypeParameter psiTypeParameter;
|
private final JavaTypeParameter javaTypeParameter;
|
||||||
|
|
||||||
private TypeParameterDescriptorInitialization(
|
private TypeParameterDescriptorInitialization(
|
||||||
@NotNull TypeParameterDescriptorImpl descriptor,
|
@NotNull TypeParameterDescriptorImpl descriptor,
|
||||||
@NotNull PsiTypeParameter psiTypeParameter
|
@NotNull JavaTypeParameter javaTypeParameter
|
||||||
) {
|
) {
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
this.psiTypeParameter = psiTypeParameter;
|
this.javaTypeParameter = javaTypeParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -76,7 +79,7 @@ public final class JavaSignatureResolver {
|
|||||||
List<TypeParameterDescriptorInitialization> result = Lists.newArrayList();
|
List<TypeParameterDescriptorInitialization> result = Lists.newArrayList();
|
||||||
for (PsiTypeParameter typeParameter : typeParameters) {
|
for (PsiTypeParameter typeParameter : typeParameters) {
|
||||||
TypeParameterDescriptorInitialization typeParameterDescriptor =
|
TypeParameterDescriptorInitialization typeParameterDescriptor =
|
||||||
makeUninitializedTypeParameter(containingDeclaration, typeParameter);
|
makeUninitializedTypeParameter(containingDeclaration, new JavaTypeParameter(typeParameter));
|
||||||
result.add(typeParameterDescriptor);
|
result.add(typeParameterDescriptor);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -85,17 +88,17 @@ public final class JavaSignatureResolver {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static TypeParameterDescriptorInitialization makeUninitializedTypeParameter(
|
private static TypeParameterDescriptorInitialization makeUninitializedTypeParameter(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull PsiTypeParameter psiTypeParameter
|
@NotNull JavaTypeParameter javaTypeParameter
|
||||||
) {
|
) {
|
||||||
TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||||
false,
|
false,
|
||||||
Variance.INVARIANT,
|
Variance.INVARIANT,
|
||||||
Name.identifier(psiTypeParameter.getName()),
|
javaTypeParameter.getName(),
|
||||||
psiTypeParameter.getIndex()
|
javaTypeParameter.getIndex()
|
||||||
);
|
);
|
||||||
return new TypeParameterDescriptorInitialization(typeParameterDescriptor, psiTypeParameter);
|
return new TypeParameterDescriptorInitialization(typeParameterDescriptor, javaTypeParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeTypeParameter(
|
private void initializeTypeParameter(
|
||||||
@@ -103,13 +106,14 @@ public final class JavaSignatureResolver {
|
|||||||
TypeVariableResolver typeVariableByPsiResolver
|
TypeVariableResolver typeVariableByPsiResolver
|
||||||
) {
|
) {
|
||||||
TypeParameterDescriptorImpl typeParameterDescriptor = typeParameter.descriptor;
|
TypeParameterDescriptorImpl typeParameterDescriptor = typeParameter.descriptor;
|
||||||
PsiClassType[] referencedTypes = typeParameter.psiTypeParameter.getExtendsList().getReferencedTypes();
|
Collection<JavaClassType> upperBounds = typeParameter.javaTypeParameter.getUpperBounds();
|
||||||
if (referencedTypes.length == 0) {
|
if (upperBounds.isEmpty()) {
|
||||||
typeParameterDescriptor.addUpperBound(KotlinBuiltIns.getInstance().getNullableAnyType());
|
typeParameterDescriptor.addUpperBound(KotlinBuiltIns.getInstance().getNullableAnyType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (PsiClassType referencedType : referencedTypes) {
|
for (JavaClassType upperBound : upperBounds) {
|
||||||
JetType transformedType = typeTransformer.transformToType(referencedType, TypeUsage.UPPER_BOUND, typeVariableByPsiResolver);
|
PsiClassType psiClassType = upperBound.getPsi();
|
||||||
|
JetType transformedType = typeTransformer.transformToType(psiClassType, TypeUsage.UPPER_BOUND, typeVariableByPsiResolver);
|
||||||
typeParameterDescriptor.addUpperBound(transformedType);
|
typeParameterDescriptor.addUpperBound(transformedType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,10 +142,10 @@ public final class JavaSignatureResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<TypeParameterDescriptorInitialization> createUninitializedClassTypeParameters(
|
public static List<TypeParameterDescriptorInitialization> createUninitializedClassTypeParameters(
|
||||||
PsiClass psiClass, ClassDescriptor classDescriptor
|
JavaClass javaClass, ClassDescriptor classDescriptor
|
||||||
) {
|
) {
|
||||||
List<TypeParameterDescriptorInitialization> result = Lists.newArrayList();
|
List<TypeParameterDescriptorInitialization> result = Lists.newArrayList();
|
||||||
for (PsiTypeParameter typeParameter : psiClass.getTypeParameters()) {
|
for (JavaTypeParameter typeParameter : javaClass.getTypeParameters()) {
|
||||||
TypeParameterDescriptorInitialization typeParameterDescriptor = makeUninitializedTypeParameter(classDescriptor, typeParameter);
|
TypeParameterDescriptorInitialization typeParameterDescriptor = makeUninitializedTypeParameter(classDescriptor, typeParameter);
|
||||||
result.add(typeParameterDescriptor);
|
result.add(typeParameterDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-32
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java.resolver;
|
package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||||
|
|
||||||
import com.intellij.psi.PsiClass;
|
|
||||||
import com.intellij.psi.PsiClassType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
@@ -28,6 +26,8 @@ import org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
||||||
import org.jetbrains.jet.lang.resolve.java.TypeVariableResolver;
|
import org.jetbrains.jet.lang.resolve.java.TypeVariableResolver;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassType;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.IGNORE_KOTLIN_SOURCES;
|
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.IGNORE_KOTLIN_SOURCES;
|
||||||
@@ -63,46 +64,45 @@ public final class JavaSupertypeResolver {
|
|||||||
this.classResolver = classResolver;
|
this.classResolver = classResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public Collection<JetType> getSupertypes(
|
public Collection<JetType> getSupertypes(
|
||||||
@NotNull ClassDescriptor classDescriptor,
|
@NotNull ClassDescriptor classDescriptor,
|
||||||
@NotNull PsiClass psiClass,
|
@NotNull JavaClass javaClass,
|
||||||
@NotNull List<TypeParameterDescriptor> typeParameters
|
@NotNull List<TypeParameterDescriptor> typeParameters
|
||||||
) {
|
) {
|
||||||
|
TypeVariableResolver typeVariableResolver = new TypeVariableResolver(typeParameters, classDescriptor,
|
||||||
|
"class " + javaClass.getFqName());
|
||||||
|
|
||||||
List<JetType> result = new ArrayList<JetType>();
|
List<JetType> result = transformSupertypeList(javaClass.getSupertypes(), typeVariableResolver);
|
||||||
|
|
||||||
String context = "class " + psiClass.getQualifiedName();
|
|
||||||
|
|
||||||
TypeVariableResolver typeVariableResolverForSupertypes = new TypeVariableResolver(typeParameters, classDescriptor, context);
|
|
||||||
transformSupertypeList(result, psiClass.getExtendsListTypes(), typeVariableResolverForSupertypes);
|
|
||||||
transformSupertypeList(result, psiClass.getImplementsListTypes(), typeVariableResolverForSupertypes);
|
|
||||||
|
|
||||||
reportIncompleteHierarchyForErrorTypes(classDescriptor, result);
|
reportIncompleteHierarchyForErrorTypes(classDescriptor, result);
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
addBaseClass(psiClass, classDescriptor, result);
|
return Collections.singletonList(getDefaultSupertype(javaClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBaseClass(@NotNull PsiClass psiClass, @NotNull ClassDescriptor classDescriptor, @NotNull List<JetType> result) {
|
@NotNull
|
||||||
if (OBJECT_FQ_NAME.asString().equals(psiClass.getQualifiedName()) || classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
|
private JetType getDefaultSupertype(@NotNull JavaClass javaClass) {
|
||||||
result.add(KotlinBuiltIns.getInstance().getAnyType());
|
if (OBJECT_FQ_NAME.equals(javaClass.getFqName()) || javaClass.getKind() == ClassKind.ANNOTATION_CLASS) {
|
||||||
|
return KotlinBuiltIns.getInstance().getAnyType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClassDescriptor object = classResolver.resolveClass(OBJECT_FQ_NAME, IGNORE_KOTLIN_SOURCES);
|
ClassDescriptor object = classResolver.resolveClass(OBJECT_FQ_NAME, IGNORE_KOTLIN_SOURCES);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
result.add(object.getDefaultType());
|
return object.getDefaultType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//TODO: hack here
|
//TODO: hack here
|
||||||
result.add(KotlinBuiltIns.getInstance().getAnyType());
|
return KotlinBuiltIns.getInstance().getAnyType();
|
||||||
// throw new IllegalStateException("Could not resolve java.lang.Object");
|
// throw new IllegalStateException("Could not resolve java.lang.Object");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportIncompleteHierarchyForErrorTypes(ClassDescriptor classDescriptor, List<JetType> result) {
|
private void reportIncompleteHierarchyForErrorTypes(@NotNull ClassDescriptor classDescriptor, @NotNull List<JetType> result) {
|
||||||
for (JetType supertype : result) {
|
for (JetType supertype : result) {
|
||||||
if (ErrorUtils.isErrorType(supertype)) {
|
if (ErrorUtils.isErrorType(supertype)) {
|
||||||
trace.record(BindingContext.INCOMPLETE_HIERARCHY, classDescriptor);
|
trace.record(BindingContext.INCOMPLETE_HIERARCHY, classDescriptor);
|
||||||
@@ -110,28 +110,27 @@ public final class JavaSupertypeResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformSupertypeList(
|
@NotNull
|
||||||
List<JetType> result,
|
private List<JetType> transformSupertypeList(
|
||||||
PsiClassType[] extendsListTypes,
|
@NotNull Collection<JavaClassType> supertypes,
|
||||||
TypeVariableResolver typeVariableResolver
|
@NotNull TypeVariableResolver typeVariableResolver
|
||||||
) {
|
) {
|
||||||
for (PsiClassType type : extendsListTypes) {
|
List<JetType> result = new ArrayList<JetType>(supertypes.size());
|
||||||
PsiClass resolved = type.resolve();
|
for (JavaClassType type : supertypes) {
|
||||||
|
JavaClass resolved = type.resolve();
|
||||||
if (resolved != null) {
|
if (resolved != null) {
|
||||||
String qualifiedName = resolved.getQualifiedName();
|
FqName fqName = resolved.getFqName();
|
||||||
assert qualifiedName != null;
|
assert fqName != null : "Unresolved supertype: " + resolved;
|
||||||
if (JvmAbi.JET_OBJECT.getFqName().equalsTo(qualifiedName)) {
|
if (JvmAbi.JET_OBJECT.getFqName().equals(fqName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType transform = typeTransformer
|
JetType transformed = typeTransformer.transformToType(type.getPsi(), TypeUsage.SUPERTYPE, typeVariableResolver);
|
||||||
.transformToType(type, TypeUsage.SUPERTYPE, typeVariableResolver);
|
if (!ErrorUtils.isErrorType(transformed)) {
|
||||||
if (ErrorUtils.isErrorType(transform)) {
|
result.add(TypeUtils.makeNotNullable(transformed));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.add(TypeUtils.makeNotNullable(transform));
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-24
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.java.sam;
|
package org.jetbrains.jet.lang.resolve.java.sam;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
@@ -31,6 +32,10 @@ import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
|
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
||||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassType;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
@@ -316,26 +321,26 @@ public class SingleAbstractMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSamInterface(@NotNull PsiClass psiClass) {
|
public static boolean isSamInterface(@NotNull PsiClass psiClass) {
|
||||||
return getSamInterfaceMethod(psiClass) != null;
|
return getSamInterfaceMethod(new JavaClass(psiClass), psiClass.getProject()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns null if not SAM interface
|
// Returns null if not SAM interface
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiMethod getSamInterfaceMethod(@NotNull PsiClass psiClass) {
|
public static JavaMethod getSamInterfaceMethod(@NotNull JavaClass javaClass, @NotNull Project project) {
|
||||||
String qualifiedName = psiClass.getQualifiedName();
|
FqName fqName = javaClass.getFqName();
|
||||||
if (qualifiedName == null || qualifiedName.startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.asString() + ".")) {
|
if (fqName == null || fqName.firstSegmentIs(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!psiClass.isInterface() || psiClass.isAnnotationType()) {
|
if (!javaClass.isInterface() || javaClass.isAnnotationType()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return findOnlyAbstractMethod(psiClass);
|
return findOnlyAbstractMethod(javaClass, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static PsiMethod findOnlyAbstractMethod(@NotNull PsiClass psiClass) {
|
private static JavaMethod findOnlyAbstractMethod(@NotNull JavaClass javaClass, @NotNull Project project) {
|
||||||
PsiClassType classType = JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(psiClass);
|
JavaClassType classType = new JavaClassType(JavaPsiFacade.getElementFactory(project).createType(javaClass.getPsi()));
|
||||||
|
|
||||||
OnlyAbstractMethodFinder finder = new OnlyAbstractMethodFinder();
|
OnlyAbstractMethodFinder finder = new OnlyAbstractMethodFinder();
|
||||||
if (finder.find(classType)) {
|
if (finder.find(classType)) {
|
||||||
@@ -370,39 +375,40 @@ public class SingleAbstractMethodUtils {
|
|||||||
private static class OnlyAbstractMethodFinder {
|
private static class OnlyAbstractMethodFinder {
|
||||||
private MethodSignatureBackedByPsiMethod found;
|
private MethodSignatureBackedByPsiMethod found;
|
||||||
|
|
||||||
private boolean find(@NotNull PsiClassType classType) {
|
private boolean find(@NotNull JavaClassType classType) {
|
||||||
PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
|
PsiClassType.ClassResolveResult classResolveResult = classType.getPsi().resolveGenerics();
|
||||||
PsiSubstitutor classSubstitutor = classResolveResult.getSubstitutor();
|
PsiSubstitutor classSubstitutor = classResolveResult.getSubstitutor();
|
||||||
PsiClass psiClass = classResolveResult.getElement();
|
JavaClass javaClass = classType.resolve();
|
||||||
if (psiClass == null) {
|
if (javaClass == null) {
|
||||||
return false; // can't resolve class -> not a SAM interface
|
return false; // can't resolve class -> not a SAM interface
|
||||||
}
|
}
|
||||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) {
|
if (new FqName(CommonClassNames.JAVA_LANG_OBJECT).equals(javaClass.getFqName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (PsiMethod method : psiClass.getMethods()) {
|
for (JavaMethod method : javaClass.getMethods()) {
|
||||||
if (DescriptorResolverUtils.isObjectMethod(method)) { // e.g., ignore toString() declared in interface
|
PsiMethod psiMethod = method.getPsi();
|
||||||
|
if (DescriptorResolverUtils.isObjectMethod(psiMethod)) { // e.g., ignore toString() declared in interface
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.hasTypeParameters()) {
|
if (!method.getTypeParameters().isEmpty()) {
|
||||||
return false; // if interface has generic methods, it is not a SAM interface
|
return false; // if interface has generic methods, it is not a SAM interface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
found = (MethodSignatureBackedByPsiMethod) method.getSignature(classSubstitutor);
|
found = (MethodSignatureBackedByPsiMethod) psiMethod.getSignature(classSubstitutor);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!found.getName().equals(method.getName())) {
|
if (!found.getName().equals(method.getName().asString())) {
|
||||||
return false; // optimizing heuristic
|
return false; // optimizing heuristic
|
||||||
}
|
}
|
||||||
MethodSignatureBackedByPsiMethod current = (MethodSignatureBackedByPsiMethod) method.getSignature(classSubstitutor);
|
MethodSignatureBackedByPsiMethod current = (MethodSignatureBackedByPsiMethod) psiMethod.getSignature(classSubstitutor);
|
||||||
if (!areSignaturesErasureEqual(current, found) || isVarargMethod(method) != isVarargMethod(found.getMethod())) {
|
if (!areSignaturesErasureEqual(current, found) || isVarargMethod(psiMethod) != isVarargMethod(found.getMethod())) {
|
||||||
return false; // different signatures
|
return false; // different signatures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PsiType t : classType.getSuperTypes()) {
|
for (JavaClassType t : classType.getSupertypes()) {
|
||||||
if (!find((PsiClassType) t)) {
|
if (!find(t)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,8 +417,8 @@ public class SingleAbstractMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
PsiMethod getFoundMethod() {
|
private JavaMethod getFoundMethod() {
|
||||||
return found == null ? null : found.getMethod();
|
return found == null ? null : new JavaMethod(found.getMethod());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -43,13 +43,13 @@ public final class JavaClassNonStaticMembersScope extends JavaClassMembersScope
|
|||||||
public JavaClassNonStaticMembersScope(
|
public JavaClassNonStaticMembersScope(
|
||||||
@NotNull ClassDescriptor descriptor,
|
@NotNull ClassDescriptor descriptor,
|
||||||
@NotNull JavaClass javaClass,
|
@NotNull JavaClass javaClass,
|
||||||
boolean staticMembersOfPsiClass,
|
boolean staticMembersOfClass,
|
||||||
@NotNull JavaDescriptorResolver javaDescriptorResolver
|
@NotNull JavaDescriptorResolver javaDescriptorResolver
|
||||||
) {
|
) {
|
||||||
super(descriptor, MembersProvider.forClass(javaClass, staticMembersOfPsiClass), javaDescriptorResolver);
|
super(descriptor, MembersProvider.forClass(javaClass, staticMembersOfClass), javaDescriptorResolver);
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
this.javaClass = javaClass;
|
this.javaClass = javaClass;
|
||||||
this.staticMembersOfPsiClass = staticMembersOfPsiClass;
|
this.staticMembersOfPsiClass = staticMembersOfClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -98,10 +98,10 @@ public final class JavaClassNonStaticMembersScope extends JavaClassMembersScope
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ClassDescriptor resolveInnerClass(@NotNull JavaClass innerClass) {
|
private ClassDescriptor resolveInnerClass(@NotNull JavaClass innerClass) {
|
||||||
String name = innerClass.getFqName();
|
FqName fqName = innerClass.getFqName();
|
||||||
assert name != null : "Inner class has no qualified name: " + innerClass;
|
assert fqName != null : "Inner class has no qualified name: " + innerClass;
|
||||||
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(new FqName(name), IGNORE_KOTLIN_SOURCES);
|
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(fqName, IGNORE_KOTLIN_SOURCES);
|
||||||
assert classDescriptor != null : "Couldn't resolve inner class " + name;
|
assert classDescriptor != null : "Couldn't resolve inner class " + fqName;
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ public final class JavaClassStaticMembersScope extends JavaClassMembersScope {
|
|||||||
protected Collection<DeclarationDescriptor> computeAllDescriptors() {
|
protected Collection<DeclarationDescriptor> computeAllDescriptors() {
|
||||||
Collection<DeclarationDescriptor> result = super.computeAllDescriptors();
|
Collection<DeclarationDescriptor> result = super.computeAllDescriptors();
|
||||||
for (JavaClass nested : javaClass.getInnerClasses()) {
|
for (JavaClass nested : javaClass.getInnerClasses()) {
|
||||||
ContainerUtil.addIfNotNull(result, getNamespace(Name.identifier(nested.getName())));
|
ContainerUtil.addIfNotNull(result, getNamespace(nested.getName()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -90,8 +90,7 @@ public final class JavaPackageScope extends JavaBaseScope {
|
|||||||
Collection<DeclarationDescriptor> result = Sets.newHashSet();
|
Collection<DeclarationDescriptor> result = Sets.newHashSet();
|
||||||
|
|
||||||
for (JavaPackage subPackage : javaPackage.getSubPackages()) {
|
for (JavaPackage subPackage : javaPackage.getSubPackages()) {
|
||||||
FqName fqName = new FqName(subPackage.getFqName());
|
NamespaceDescriptor childNs = javaDescriptorResolver.resolveNamespace(subPackage.getFqName(), IGNORE_KOTLIN_SOURCES);
|
||||||
NamespaceDescriptor childNs = javaDescriptorResolver.resolveNamespace(fqName, IGNORE_KOTLIN_SOURCES);
|
|
||||||
if (childNs != null) {
|
if (childNs != null) {
|
||||||
result.add(childNs);
|
result.add(childNs);
|
||||||
}
|
}
|
||||||
@@ -102,13 +101,12 @@ public final class JavaPackageScope extends JavaBaseScope {
|
|||||||
|
|
||||||
if (isKotlinLightClass(javaClass)) continue;
|
if (isKotlinLightClass(javaClass)) continue;
|
||||||
|
|
||||||
if (!javaClass.getPsiClass().hasModifierProperty(PsiModifier.PUBLIC)) continue;
|
if (!javaClass.getPsi().hasModifierProperty(PsiModifier.PUBLIC)) continue;
|
||||||
|
|
||||||
ProgressIndicatorProvider.checkCanceled();
|
ProgressIndicatorProvider.checkCanceled();
|
||||||
|
|
||||||
String qualifiedName = javaClass.getFqName();
|
FqName fqName = javaClass.getFqName();
|
||||||
if (qualifiedName == null) continue;
|
if (fqName == null) continue;
|
||||||
FqName fqName = new FqName(qualifiedName);
|
|
||||||
|
|
||||||
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(fqName, IGNORE_KOTLIN_SOURCES);
|
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(fqName, IGNORE_KOTLIN_SOURCES);
|
||||||
if (classDescriptor != null) {
|
if (classDescriptor != null) {
|
||||||
@@ -125,7 +123,7 @@ public final class JavaPackageScope extends JavaBaseScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isKotlinLightClass(@NotNull JavaClass javaClass) {
|
private static boolean isKotlinLightClass(@NotNull JavaClass javaClass) {
|
||||||
return javaClass.getPsiClass() instanceof JetJavaMirrorMarker;
|
return javaClass.getPsi() instanceof JetJavaMirrorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+115
-22
@@ -18,48 +18,49 @@ package org.jetbrains.jet.lang.resolve.java.structure;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiAnnotation;
|
import com.intellij.psi.PsiAnnotation;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiModifier;
|
||||||
import com.intellij.psi.PsiModifierList;
|
import com.intellij.psi.PsiModifierList;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.Visibilities;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaVisibilities;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class JavaClass {
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.*;
|
||||||
private final PsiClass psiClass;
|
|
||||||
|
|
||||||
|
public class JavaClass extends JavaElementImpl implements JavaNamedElement, JavaModifierListOwner, JavaTypeParameterListOwner {
|
||||||
public JavaClass(@NotNull PsiClass psiClass) {
|
public JavaClass(@NotNull PsiClass psiClass) {
|
||||||
this.psiClass = psiClass;
|
super(psiClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PsiClass getPsiClass() {
|
@Override
|
||||||
return psiClass;
|
public PsiClass getPsi() {
|
||||||
}
|
return (PsiClass) super.getPsi();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
/* package */ static Collection<JavaClass> javaClassesFromPsi(@NotNull PsiClass[] classes) {
|
|
||||||
List<JavaClass> result = new ArrayList<JavaClass>(classes.length);
|
|
||||||
for (PsiClass psiClass : classes) {
|
|
||||||
result.add(new JavaClass(psiClass));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<JavaClass> getInnerClasses() {
|
public Collection<JavaClass> getInnerClasses() {
|
||||||
return javaClassesFromPsi(psiClass.getInnerClasses());
|
return classes(getPsi().getInnerClasses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getFqName() {
|
public FqName getFqName() {
|
||||||
return psiClass.getQualifiedName();
|
String qualifiedName = getPsi().getQualifiedName();
|
||||||
|
return qualifiedName == null ? null : new FqName(qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JavaAnnotation findAnnotation(@NotNull String fqName) {
|
public JavaAnnotation findAnnotation(@NotNull String fqName) {
|
||||||
PsiModifierList modifierList = psiClass.getModifierList();
|
PsiModifierList modifierList = getPsi().getModifierList();
|
||||||
if (modifierList != null) {
|
if (modifierList != null) {
|
||||||
PsiAnnotation annotation = modifierList.findAnnotation(fqName);
|
PsiAnnotation annotation = modifierList.findAnnotation(fqName);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
@@ -70,7 +71,99 @@ public class JavaClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getName() {
|
@Override
|
||||||
return psiClass.getName();
|
public Name getName() {
|
||||||
|
return Name.identifier(getPsi().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInterface() {
|
||||||
|
return getPsi().isInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAnnotationType() {
|
||||||
|
return getPsi().isAnnotationType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnum() {
|
||||||
|
return getPsi().isEnum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ClassKind getKind() {
|
||||||
|
if (isInterface()) {
|
||||||
|
return isAnnotationType() ? ClassKind.ANNOTATION_CLASS : ClassKind.TRAIT;
|
||||||
|
}
|
||||||
|
return isEnum() ? ClassKind.ENUM_CLASS : ClassKind.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JavaClass getOuterClass() {
|
||||||
|
PsiClass outer = getPsi().getContainingClass();
|
||||||
|
return outer == null ? null : new JavaClass(outer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Modality getModality() {
|
||||||
|
return isAnnotationType() ? Modality.FINAL : Modality.convertFromFlags(isAbstract() || isInterface(), !isFinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAbstract() {
|
||||||
|
return getPsi().hasModifierProperty(PsiModifier.ABSTRACT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinal() {
|
||||||
|
return getPsi().hasModifierProperty(PsiModifier.FINAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStatic() {
|
||||||
|
return getPsi().hasModifierProperty(PsiModifier.STATIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Visibility getVisibility() {
|
||||||
|
if (getPsi().hasModifierProperty(PsiModifier.PUBLIC)) {
|
||||||
|
return Visibilities.PUBLIC;
|
||||||
|
}
|
||||||
|
if (getPsi().hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||||
|
return Visibilities.PRIVATE;
|
||||||
|
}
|
||||||
|
if (getPsi().hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||||
|
return isStatic() ? JavaVisibilities.PROTECTED_STATIC_VISIBILITY : JavaVisibilities.PROTECTED_AND_PACKAGE;
|
||||||
|
}
|
||||||
|
return JavaVisibilities.PACKAGE_VISIBILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<JavaAnnotation> getAnnotations() {
|
||||||
|
PsiModifierList modifierList = getPsi().getModifierList();
|
||||||
|
if (modifierList != null) {
|
||||||
|
return annotations(modifierList.getAnnotations());
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<JavaTypeParameter> getTypeParameters() {
|
||||||
|
return typeParameters(getPsi().getTypeParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@NotNull
|
||||||
|
public Collection<JavaClassType> getSupertypes() {
|
||||||
|
// TODO: getPsi().getSuperTypes() ?
|
||||||
|
Collection<JavaClassType> superClasses = classTypes(getPsi().getExtendsListTypes());
|
||||||
|
Collection<JavaClassType> superInterfaces = classTypes(getPsi().getImplementsListTypes());
|
||||||
|
return ContainerUtil.collect(ContainerUtil.concat(superClasses, superInterfaces).iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Collection<JavaMethod> getMethods() {
|
||||||
|
return methods(getPsi().getMethods());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiClassType;
|
||||||
|
import com.intellij.psi.PsiType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JavaClassType {
|
||||||
|
private final PsiClassType psiClassType;
|
||||||
|
|
||||||
|
public JavaClassType(@NotNull PsiClassType psiClassType) {
|
||||||
|
this.psiClassType = psiClassType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public PsiClassType getPsi() {
|
||||||
|
return psiClassType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JavaClass resolve() {
|
||||||
|
PsiClass psiClass = getPsi().resolve();
|
||||||
|
return psiClass == null ? null : new JavaClass(psiClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Collection<JavaClassType> getSupertypes() {
|
||||||
|
PsiType[] psiTypes = getPsi().getSuperTypes();
|
||||||
|
if (psiTypes.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaClassType> result = new ArrayList<JavaClassType>(psiTypes.length);
|
||||||
|
for (PsiType psiType : psiTypes) {
|
||||||
|
if (!(psiType instanceof PsiClassType)) {
|
||||||
|
throw new IllegalStateException("Supertype should be a class: " + psiType + ", type: " + getPsi());
|
||||||
|
}
|
||||||
|
result.add(new JavaClassType((PsiClassType) psiType));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface JavaElement {
|
||||||
|
@NotNull
|
||||||
|
PsiElement getPsi();
|
||||||
|
}
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.*;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/* package */ class JavaElementCollectionFromPsiArrayUtil {
|
||||||
|
private JavaElementCollectionFromPsiArrayUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaClass> classes(@NotNull PsiClass[] classes) {
|
||||||
|
if (classes.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaClass> result = new ArrayList<JavaClass>(classes.length);
|
||||||
|
for (PsiClass psiClass : classes) {
|
||||||
|
result.add(new JavaClass(psiClass));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaPackage> packages(@NotNull PsiPackage[] packages) {
|
||||||
|
if (packages.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaPackage> result = new ArrayList<JavaPackage>(packages.length);
|
||||||
|
for (PsiPackage psiPackage : packages) {
|
||||||
|
result.add(new JavaPackage(psiPackage));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaMethod> methods(@NotNull PsiMethod[] methods) {
|
||||||
|
if (methods.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaMethod> result = new ArrayList<JavaMethod>(methods.length);
|
||||||
|
for (PsiMethod psiMethod : methods) {
|
||||||
|
result.add(new JavaMethod(psiMethod));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaTypeParameter> typeParameters(@NotNull PsiTypeParameter[] typeParameters) {
|
||||||
|
if (typeParameters.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaTypeParameter> result = new ArrayList<JavaTypeParameter>(typeParameters.length);
|
||||||
|
for (PsiTypeParameter psiTypeParameter : typeParameters) {
|
||||||
|
result.add(new JavaTypeParameter(psiTypeParameter));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaClassType> classTypes(@NotNull PsiClassType[] classTypes) {
|
||||||
|
if (classTypes.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaClassType> result = new ArrayList<JavaClassType>(classTypes.length);
|
||||||
|
for (PsiClassType psiClassType : classTypes) {
|
||||||
|
result.add(new JavaClassType(psiClassType));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<JavaAnnotation> annotations(@NotNull PsiAnnotation[] annotations) {
|
||||||
|
if (annotations.length == 0) return Collections.emptyList();
|
||||||
|
List<JavaAnnotation> result = new ArrayList<JavaAnnotation>(annotations.length);
|
||||||
|
for (PsiAnnotation psiAnnotation : annotations) {
|
||||||
|
result.add(new JavaAnnotation(psiAnnotation));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class JavaElementImpl implements JavaElement {
|
||||||
|
private final PsiElement psiElement;
|
||||||
|
|
||||||
|
protected JavaElementImpl(@NotNull PsiElement psiElement) {
|
||||||
|
this.psiElement = psiElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiElement getPsi() {
|
||||||
|
return psiElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface JavaMember extends JavaElement {
|
||||||
|
// TODO: NotNull ?
|
||||||
|
@Nullable
|
||||||
|
JavaClass getContainingClass();
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiMethod;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.typeParameters;
|
||||||
|
|
||||||
|
public class JavaMethod extends JavaElementImpl implements JavaTypeParameterListOwner, JavaNamedElement, JavaMember {
|
||||||
|
public JavaMethod(@NotNull PsiMethod psiMethod) {
|
||||||
|
super(psiMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiMethod getPsi() {
|
||||||
|
return (PsiMethod) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Name getName() {
|
||||||
|
return Name.identifier(getPsi().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: NotNull?
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JavaClass getContainingClass() {
|
||||||
|
PsiClass psiClass = getPsi().getContainingClass();
|
||||||
|
return psiClass == null ? null : new JavaClass(psiClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<JavaTypeParameter> getTypeParameters() {
|
||||||
|
return typeParameters(getPsi().getTypeParameters());
|
||||||
|
}
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface JavaModifierListOwner extends JavaElement {
|
||||||
|
boolean isAbstract();
|
||||||
|
|
||||||
|
boolean isStatic();
|
||||||
|
|
||||||
|
boolean isFinal();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
Visibility getVisibility();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
Collection<JavaAnnotation> getAnnotations();
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
public interface JavaNamedElement extends JavaElement {
|
||||||
|
@NotNull
|
||||||
|
Name getName();
|
||||||
|
}
|
||||||
+12
-26
@@ -18,50 +18,36 @@ package org.jetbrains.jet.lang.resolve.java.structure;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JavaPackage {
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.classes;
|
||||||
private final PsiPackage psiPackage;
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.packages;
|
||||||
|
|
||||||
|
public class JavaPackage extends JavaElementImpl {
|
||||||
public JavaPackage(@NotNull PsiPackage psiPackage) {
|
public JavaPackage(@NotNull PsiPackage psiPackage) {
|
||||||
this.psiPackage = psiPackage;
|
super(psiPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PsiPackage getPsiPackage() {
|
@Override
|
||||||
return psiPackage;
|
public PsiPackage getPsi() {
|
||||||
}
|
return (PsiPackage) super.getPsi();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static Collection<JavaPackage> javaPackagesFromPsi(@NotNull PsiPackage[] packages) {
|
|
||||||
List<JavaPackage> result = new ArrayList<JavaPackage>(packages.length);
|
|
||||||
for (PsiPackage psiPackage : packages) {
|
|
||||||
result.add(new JavaPackage(psiPackage));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<JavaClass> getClasses() {
|
public Collection<JavaClass> getClasses() {
|
||||||
return JavaClass.javaClassesFromPsi(psiPackage.getClasses());
|
return classes(getPsi().getClasses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<JavaPackage> getSubPackages() {
|
public Collection<JavaPackage> getSubPackages() {
|
||||||
return javaPackagesFromPsi(psiPackage.getSubPackages());
|
return packages(getPsi().getSubPackages());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getFqName() {
|
public FqName getFqName() {
|
||||||
return psiPackage.getQualifiedName();
|
return new FqName(getPsi().getQualifiedName());
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getName() {
|
|
||||||
String name = psiPackage.getName();
|
|
||||||
return name == null ? "" : name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiTypeParameter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.classTypes;
|
||||||
|
|
||||||
|
public class JavaTypeParameter extends JavaElementImpl implements JavaNamedElement {
|
||||||
|
public JavaTypeParameter(@NotNull PsiTypeParameter psiTypeParameter) {
|
||||||
|
super(psiTypeParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiTypeParameter getPsi() {
|
||||||
|
return (PsiTypeParameter) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return getPsi().getIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Name getName() {
|
||||||
|
return Name.identifier(getPsi().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Collection<JavaClassType> getUpperBounds() {
|
||||||
|
return classTypes(getPsi().getExtendsList().getReferencedTypes());
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface JavaTypeParameterListOwner extends JavaElement {
|
||||||
|
@NotNull
|
||||||
|
Collection<JavaTypeParameter> getTypeParameters();
|
||||||
|
}
|
||||||
@@ -366,12 +366,7 @@ public class DescriptorUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Name getClassObjectName(@NotNull Name className) {
|
public static Name getClassObjectName(@NotNull Name className) {
|
||||||
return getClassObjectName(className.asString());
|
return Name.special("<class-object-for-" + className.asString() + ">");
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Name getClassObjectName(@NotNull String className) {
|
|
||||||
return Name.special("<class-object-for-" + className + ">");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEnumClassObject(@NotNull DeclarationDescriptor descriptor) {
|
public static boolean isEnumClassObject(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
|||||||
// build descriptors for such class objects.
|
// build descriptors for such class objects.
|
||||||
final JetClassLikeInfo classObjectInfo = parentClassDescriptor.getClassObjectInfo(classObject);
|
final JetClassLikeInfo classObjectInfo = parentClassDescriptor.getClassObjectInfo(classObject);
|
||||||
if (classObjectInfo != null) {
|
if (classObjectInfo != null) {
|
||||||
final Name name = DescriptorUtils.getClassObjectName(parentClassDescriptor.getName().asString());
|
final Name name = DescriptorUtils.getClassObjectName(parentClassDescriptor.getName());
|
||||||
return storageManager.compute(new Computable<LazyClassDescriptor>() {
|
return storageManager.compute(new Computable<LazyClassDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
public LazyClassDescriptor compute() {
|
public LazyClassDescriptor compute() {
|
||||||
|
|||||||
Reference in New Issue
Block a user