Minor, use module.resolveTopLevelClass() utility
This commit is contained in:
+1
-3
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -140,8 +139,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
);
|
||||
}
|
||||
|
||||
Collection<ClassDescriptor> classDescriptors =
|
||||
ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(getModule(), fqName, Predicates.<ClassDescriptor>alwaysTrue());
|
||||
Collection<ClassDescriptor> classDescriptors = ResolveSessionUtils.getClassDescriptorsByFqName(getModule(), fqName);
|
||||
|
||||
return ContainerUtil.mapNotNull(classDescriptors, new Function<ClassDescriptor, JetClassOrObject>() {
|
||||
@Override
|
||||
|
||||
@@ -38,28 +38,12 @@ import java.util.Collections;
|
||||
|
||||
public class ResolveSessionUtils {
|
||||
|
||||
public static final Predicate<ClassDescriptor> NON_SINGLETON_FILTER = new Predicate<ClassDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable ClassDescriptor descriptor) {
|
||||
assert descriptor != null;
|
||||
return !descriptor.getKind().isSingleton();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Predicate<ClassDescriptor> SINGLETON_FILTER = new Predicate<ClassDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable ClassDescriptor descriptor) {
|
||||
assert descriptor != null;
|
||||
return descriptor.getKind().isSingleton();
|
||||
}
|
||||
};
|
||||
|
||||
private ResolveSessionUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<ClassDescriptor> getClassDescriptorsByFqName(@NotNull ModuleDescriptor moduleDescriptor, @NotNull FqName fqName) {
|
||||
return getClassOrObjectDescriptorsByFqName(moduleDescriptor, fqName, NON_SINGLETON_FILTER);
|
||||
return getClassOrObjectDescriptorsByFqName(moduleDescriptor, fqName, Predicates.<ClassDescriptor>alwaysTrue());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+4
-5
@@ -45,12 +45,12 @@ import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPropertyDelegate
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||
import org.jetbrains.kotlin.psi.JetAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
|
||||
private fun JetType.contains(inner: JetType): Boolean {
|
||||
return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() }
|
||||
@@ -175,10 +175,9 @@ fun JetExpression.guessTypes(
|
||||
}
|
||||
parent is JetPropertyDelegate && module != null -> {
|
||||
val property = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.getParent() as JetProperty] as PropertyDescriptor
|
||||
val delegateClassName = if (property.isVar() ) "ReadWriteProperty" else "ReadOnlyProperty"
|
||||
val delegateClass =
|
||||
ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.properties.$delegateClassName")).firstOrNull()
|
||||
?: return array(builtIns.getAnyType())
|
||||
val delegateClassName = if (property.isVar()) "ReadWriteProperty" else "ReadOnlyProperty"
|
||||
val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName"))
|
||||
?: return array(builtIns.getAnyType())
|
||||
val receiverType = (property.getExtensionReceiverParameter() ?: property.getDispatchReceiverParameter())?.getType()
|
||||
?: builtIns.getNullableNothingType()
|
||||
val typeArguments = listOf(TypeProjectionImpl(receiverType), TypeProjectionImpl(property.getType()))
|
||||
|
||||
+3
-3
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.idea.refactoring.extractFunction.OutputValue.Express
|
||||
import org.jetbrains.kotlin.psi.JetReturnExpression
|
||||
import org.jetbrains.kotlin.idea.refactoring.extractFunction.OutputValue.Jump
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import kotlin.properties.Delegates
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
@@ -57,6 +56,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.idea.util.isUnit
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
|
||||
trait Parameter {
|
||||
val argumentText: String
|
||||
@@ -206,8 +206,8 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
fun getType(): JetType {
|
||||
val boxingClass = when (outputValues.size()) {
|
||||
1 -> return outputValues.first().valueType
|
||||
2 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Pair")).first()
|
||||
3 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Triple")).first()
|
||||
2 -> module.resolveTopLevelClass(FqName("kotlin.Pair"))!!
|
||||
3 -> module.resolveTopLevelClass(FqName("kotlin.Triple"))!!
|
||||
else -> return DEFAULT_RETURN_TYPE
|
||||
}
|
||||
return TypeUtils.substituteParameters(boxingClass, outputValueTypes)
|
||||
|
||||
Reference in New Issue
Block a user