Methods in KotlinBuiltIns made static where already possible

This commit is contained in:
Andrey Breslav
2014-12-02 15:50:16 +03:00
parent 75c887048e
commit ea4f0ab214
25 changed files with 68 additions and 72 deletions
@@ -232,7 +232,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
builder.addAll(suppressStringProvider.get(annotationDescriptor));
}
if (!KotlinBuiltIns.getInstance().isSuppressAnnotation(annotationDescriptor)) continue;
if (!KotlinBuiltIns.isSuppressAnnotation(annotationDescriptor)) continue;
// We only add strings and skip other values to facilitate recovery in presence of erroneous code
for (CompileTimeConstant<?> arrayValue : annotationDescriptor.getAllValueArguments().values()) {
@@ -98,12 +98,12 @@ public class FunctionDescriptorUtil {
@NotNull Visibility visibility
) {
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(functionType);
functionDescriptor.initialize(KotlinBuiltIns.getInstance().getReceiverType(functionType),
assert KotlinBuiltIns.isFunctionOrExtensionFunctionType(functionType);
functionDescriptor.initialize(KotlinBuiltIns.getReceiverType(functionType),
dispatchReceiverParameter,
Collections.<TypeParameterDescriptorImpl>emptyList(),
KotlinBuiltIns.getInstance().getValueParameters(functionDescriptor, functionType),
KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(functionType),
KotlinBuiltIns.getValueParameters(functionDescriptor, functionType),
KotlinBuiltIns.getReturnTypeFromFunctionType(functionType),
modality,
visibility);
}
@@ -78,7 +78,7 @@ public class ArgumentTypeResolver {
}
private static boolean isFunctionOrErrorType(@NotNull JetType supertype) {
return KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(supertype) || supertype.isError();
return KotlinBuiltIns.isFunctionOrExtensionFunctionType(supertype) || supertype.isError();
}
public void checkTypesWithNoCallee(@NotNull CallResolutionContext<?> context) {
@@ -42,7 +42,7 @@ public class CallResolverUtil {
public static boolean hasUnknownFunctionParameter(@NotNull JetType type) {
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type);
assert KotlinBuiltIns.isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
// last argument is return type of function type
List<TypeProjection> functionParameters = arguments.subList(0, arguments.size() - 1);
@@ -56,13 +56,13 @@ public class CallResolverUtil {
}
public static boolean hasUnknownReturnType(@NotNull JetType type) {
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type);
JetType returnTypeFromFunctionType = KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(type);
assert KotlinBuiltIns.isFunctionOrExtensionFunctionType(type);
JetType returnTypeFromFunctionType = KotlinBuiltIns.getReturnTypeFromFunctionType(type);
return ErrorUtils.containsErrorType(returnTypeFromFunctionType);
}
public static JetType replaceReturnTypeByUnknown(@NotNull JetType type) {
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type);
assert KotlinBuiltIns.isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
List<TypeProjection> newArguments = Lists.newArrayList();
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
@@ -250,7 +250,7 @@ public class CandidateResolver {
if (expectedType == null || TypeUtils.isDontCarePlaceholder(expectedType)) {
expectedType = argumentTypeResolver.getShapeTypeOfFunctionLiteral(functionLiteralExpression, context.scope, context.trace, false);
}
if (expectedType == null || !KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)
if (expectedType == null || !KotlinBuiltIns.isFunctionOrExtensionFunctionType(expectedType)
|| CallResolverUtil.hasUnknownFunctionParameter(expectedType)) {
return;
}
@@ -221,7 +221,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
JetType type = descriptor.getReturnType();
return type != null &&
KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(type) &&
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) &&
!type.isNullable() &&
!InlineUtil.hasNoinlineAnnotation(descriptor);
}
@@ -234,7 +234,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
boolean isInvoke = descriptor.getName().asString().equals("invoke") &&
containingDeclaration instanceof ClassDescriptor &&
KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType());
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType());
return isInvoke ||
//or inline extension
@@ -54,7 +54,7 @@ private fun getSuperClassesReachableByClassInheritance(
): Set<ClassDescriptor> {
val superClass = getSuperClass(descriptor)
result.add(superClass)
if (!KotlinBuiltIns.getInstance().isAny(superClass)) {
if (!KotlinBuiltIns.isAny(superClass)) {
getSuperClassesReachableByClassInheritance(superClass, result)
}
return result
@@ -91,7 +91,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy {
}
private void functionExpectedOrNoReceiverAllowed(BindingTrace trace) {
if (KotlinBuiltIns.getInstance().isFunctionType(calleeType)) {
if (KotlinBuiltIns.isFunctionType(calleeType)) {
LOG.assertTrue(call.getExplicitReceiver().exists(),
"'Invoke' is not found on expression of function type (" + calleeType + "): "
+ PsiUtilPackage.getTextWithLocation(call.getCallElement()));
@@ -149,9 +149,8 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
@NotNull CallableDescriptor functionDescriptor,
@Nullable BindingTrace trace
) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
JetType type = parameter.getReturnType();
if (type != null && builtIns.isExactFunctionOrExtensionFunctionType(type)) {
if (type != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
if (type.isNullable()) {
if (trace != null) {
@@ -500,7 +500,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
new Function0<Supertypes>() {
@Override
public Supertypes invoke() {
if (KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) {
if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) {
return new Supertypes(Collections.<JetType>emptyList());
}
@@ -107,7 +107,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
if (!expression.getFunctionLiteral().hasBody()) return null;
JetType expectedType = context.expectedType;
boolean functionTypeExpected = !noExpectedType(expectedType) && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(
boolean functionTypeExpected = !noExpectedType(expectedType) && KotlinBuiltIns.isFunctionOrExtensionFunctionType(
expectedType);
AnonymousFunctionDescriptor functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
@@ -118,7 +118,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
List<JetType> valueParametersTypes = ExpressionTypingUtils.getValueParametersTypes(functionDescriptor.getValueParameters());
JetType resultType = KotlinBuiltIns.getInstance().getFunctionType(
Annotations.EMPTY, receiver, valueParametersTypes, safeReturnType);
if (!noExpectedType(expectedType) && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)) {
if (!noExpectedType(expectedType) && KotlinBuiltIns.isFunctionOrExtensionFunctionType(expectedType)) {
// all checks were done before
return JetTypeInfo.create(resultType, context.dataFlowInfo);
}
@@ -145,7 +145,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetType effectiveReceiverType;
if (receiverTypeRef == null) {
if (functionTypeExpected) {
effectiveReceiverType = KotlinBuiltIns.getInstance().getReceiverType(context.expectedType);
effectiveReceiverType = KotlinBuiltIns.getReceiverType(context.expectedType);
}
else {
effectiveReceiverType = null;
@@ -177,7 +177,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
List<JetParameter> declaredValueParameters = functionLiteral.getValueParameters();
List<ValueParameterDescriptor> expectedValueParameters = (functionTypeExpected)
? KotlinBuiltIns.getInstance().getValueParameters(functionDescriptor, context.expectedType)
? KotlinBuiltIns.getValueParameters(functionDescriptor, context.expectedType)
: null;
JetParameterList valueParameterList = functionLiteral.getValueParameterList();
@@ -261,7 +261,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
@NotNull SimpleFunctionDescriptorImpl functionDescriptor,
boolean functionTypeExpected
) {
JetType expectedReturnType = functionTypeExpected ? KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(context.expectedType) : null;
JetType expectedReturnType = functionTypeExpected ? KotlinBuiltIns.getReturnTypeFromFunctionType(context.expectedType) : null;
JetType returnType = computeUnsafeReturnType(expression, context, functionDescriptor, expectedReturnType);
if (!expression.getFunctionLiteral().hasDeclaredReturnType() && functionTypeExpected) {
@@ -236,7 +236,7 @@ public class DescriptorValidator {
Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes();
if (supertypes.isEmpty() && descriptor.getKind() != ClassKind.TRAIT
&& !KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(descriptor)) {
&& !KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor)) {
report(collector, descriptor, "No supertypes for non-trait");
}
validateTypes(descriptor, collector, supertypes);
@@ -367,9 +367,8 @@ public class ConstraintSystemImpl implements ConstraintSystem {
assert superType != TypeUtils.PLACEHOLDER_FUNCTION_TYPE : "The type for " + constraintPosition + " shouldn't be a placeholder for function type";
KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance();
if (subType == TypeUtils.PLACEHOLDER_FUNCTION_TYPE) {
if (!kotlinBuiltIns.isFunctionOrExtensionFunctionType(superType)) {
if (!KotlinBuiltIns.isFunctionOrExtensionFunctionType(superType)) {
if (isMyTypeVariable(superType)) {
// a constraint binds type parameter and any function type, so there is no new info and no error
return;
@@ -383,7 +382,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
// function literal without declaring receiver type { x -> ... }
// can be considered as extension function if one is expected
// (special type constructor for function/ extension function should be introduced like PLACEHOLDER_FUNCTION_TYPE)
if (constraintKind == SUB_TYPE && kotlinBuiltIns.isFunctionType(subType) && kotlinBuiltIns.isExtensionFunctionType(superType)) {
if (constraintKind == SUB_TYPE && KotlinBuiltIns.isFunctionType(subType) && KotlinBuiltIns.isExtensionFunctionType(superType)) {
subType = createCorrespondingExtensionFunctionType(subType, DONT_CARE);
}
@@ -522,7 +521,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull
public static JetType createCorrespondingExtensionFunctionType(@NotNull JetType functionType, @NotNull JetType receiverType) {
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
assert KotlinBuiltIns.isFunctionType(functionType);
List<TypeProjection> typeArguments = functionType.getArguments();
assert !typeArguments.isEmpty();
@@ -103,7 +103,7 @@ public class KotlinBuiltIns {
private final Map<JetType, JetType> primitiveJetTypeToJetArrayType;
private final Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
private final FqNames fqNames = new FqNames();
private static final FqNames FQ_NAMES = new FqNames();
private KotlinBuiltIns() {
builtInsModule = new ModuleDescriptorImpl(
@@ -734,11 +734,11 @@ public class KotlinBuiltIns {
// Functions
public boolean isFunctionOrExtensionFunctionType(@NotNull JetType type) {
public static boolean isFunctionOrExtensionFunctionType(@NotNull JetType type) {
return isFunctionType(type) || isExtensionFunctionType(type);
}
public boolean isFunctionType(@NotNull JetType type) {
public static boolean isFunctionType(@NotNull JetType type) {
if (isExactFunctionType(type)) return true;
for (JetType superType : type.getConstructor().getSupertypes()) {
@@ -748,7 +748,7 @@ public class KotlinBuiltIns {
return false;
}
public boolean isExtensionFunctionType(@NotNull JetType type) {
public static boolean isExtensionFunctionType(@NotNull JetType type) {
if (isExactExtensionFunctionType(type)) return true;
for (JetType superType : type.getConstructor().getSupertypes()) {
@@ -758,16 +758,16 @@ public class KotlinBuiltIns {
return false;
}
public boolean isExactFunctionOrExtensionFunctionType(@NotNull JetType type) {
public static boolean isExactFunctionOrExtensionFunctionType(@NotNull JetType type) {
return isExactFunctionType(type) || isExactExtensionFunctionType(type);
}
public boolean isExactFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, fqNames.functionClasses);
public static boolean isExactFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, FQ_NAMES.functionClasses);
}
public boolean isExactExtensionFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, fqNames.extensionFunctionClasses);
public static boolean isExactExtensionFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, FQ_NAMES.extensionFunctionClasses);
}
private static boolean isTypeConstructorFqNameInSet(@NotNull JetType type, @NotNull Set<FqNameUnsafe> classes) {
@@ -780,7 +780,7 @@ public class KotlinBuiltIns {
}
@Nullable
public JetType getReceiverType(@NotNull JetType type) {
public static JetType getReceiverType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type) : type;
if (isExtensionFunctionType(type)) {
return type.getArguments().get(0).getType();
@@ -789,7 +789,7 @@ public class KotlinBuiltIns {
}
@NotNull
public List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
public static List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> parameterTypes = getParameterTypeProjectionsFromFunctionType(type);
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(parameterTypes.size());
@@ -805,14 +805,14 @@ public class KotlinBuiltIns {
}
@NotNull
public JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
public static JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
return arguments.get(arguments.size() - 1).getType();
}
@NotNull
public List<TypeProjection> getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) {
public static List<TypeProjection> getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
int first = isExtensionFunctionType(type) ? 1 : 0;
@@ -826,13 +826,13 @@ public class KotlinBuiltIns {
// Recognized & special
public boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
return fqNames.any.equals(fqName) || fqNames.nothing.equals(fqName);
return FQ_NAMES.any.equals(fqName) || FQ_NAMES.nothing.equals(fqName);
}
public boolean isAny(@NotNull ClassDescriptor descriptor) {
return fqNames.any.equals(DescriptorUtils.getFqName(descriptor));
public static boolean isAny(@NotNull ClassDescriptor descriptor) {
return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor));
}
public boolean isNothing(@NotNull JetType type) {
@@ -861,8 +861,8 @@ public class KotlinBuiltIns {
return getStringType().equals(type);
}
public boolean isCloneable(@NotNull ClassDescriptor descriptor) {
return fqNames.cloneable.equals(DescriptorUtils.getFqName(descriptor));
public static boolean isCloneable(@NotNull ClassDescriptor descriptor) {
return FQ_NAMES.cloneable.equals(DescriptorUtils.getFqName(descriptor));
}
public boolean isData(@NotNull ClassDescriptor classDescriptor) {
@@ -877,9 +877,9 @@ public class KotlinBuiltIns {
return containsAnnotation(declarationDescriptor, getTailRecursiveAnnotationClass());
}
public boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
public static boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
ClassifierDescriptor classifier = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor();
return classifier != null && fqNames.suppress.equals(DescriptorUtils.getFqName(classifier));
return classifier != null && FQ_NAMES.suppress.equals(DescriptorUtils.getFqName(classifier));
}
static boolean containsAnnotation(DeclarationDescriptor descriptor, ClassDescriptor annotationClass) {
@@ -43,7 +43,6 @@ import org.jetbrains.jet.utils.UtilsPackage;
import java.util.*;
import static org.jetbrains.jet.lang.types.TypeUtils.CANT_INFER_LAMBDA_PARAM_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.DONT_CARE;
public class DescriptorRendererImpl implements DescriptorRenderer {
@@ -360,7 +359,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
}
private boolean shouldRenderAsPrettyFunctionType(@NotNull JetType type) {
return KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(type) && prettyFunctionTypes;
return KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && prettyFunctionTypes;
}
@NotNull
@@ -484,16 +483,16 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private String renderFunctionType(@NotNull JetType type) {
StringBuilder sb = new StringBuilder();
JetType receiverType = KotlinBuiltIns.getInstance().getReceiverType(type);
JetType receiverType = KotlinBuiltIns.getReceiverType(type);
if (receiverType != null) {
sb.append(renderNormalizedType(receiverType));
sb.append(".");
}
sb.append("(");
appendTypeProjections(KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(type), sb);
appendTypeProjections(KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(type), sb);
sb.append(") ").append(arrow()).append(" ");
sb.append(renderNormalizedType(KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(type)));
sb.append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)));
if (type.isNullable()) {
return "(" + sb + ")?";
@@ -91,7 +91,7 @@ public class DescriptorSerializer {
builder.addTypeParameter(typeParameter(typeParameterDescriptor));
}
if (!KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(classDescriptor)) {
if (!KotlinBuiltIns.isSpecialClassWithNoSupertypes(classDescriptor)) {
// Special classes (Any, Nothing) have no supertypes
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
builder.addSupertype(type(supertype));
@@ -103,15 +103,14 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
return false;
}
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
JetType defaultType = ((ClassDescriptor) parent).getDefaultType();
if (builtIns.isFunctionOrExtensionFunctionType(defaultType)) {
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(defaultType)) {
return true;
}
for (JetType supertype : TypeUtils.getAllSupertypes(defaultType)) {
if (builtIns.isFunctionOrExtensionFunctionType(supertype)) {
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(supertype)) {
return true;
}
}
@@ -135,7 +135,7 @@ public class KotlinSuppressIntentionAction(
val context = annotated.analyze()
for (entry in annotated.getAnnotationEntries()) {
val annotationDescriptor = context.get(BindingContext.ANNOTATION, entry)
if (annotationDescriptor != null && KotlinBuiltIns.getInstance().isSuppressAnnotation(annotationDescriptor)) {
if (annotationDescriptor != null && KotlinBuiltIns.isSuppressAnnotation(annotationDescriptor)) {
return entry
}
}
@@ -130,7 +130,7 @@ public class FindImplicitNothingAction : AnAction() {
return when {
builtIns.isNothing(this) -> true
builtIns.isExactFunctionOrExtensionFunctionType(this) -> builtIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(this) -> KotlinBuiltIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()
else -> false
}
@@ -133,8 +133,8 @@ public open class LookupElementFactory protected() {
1 -> {
val parameterType = parameters.single().getType()
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(parameterType)) {
val parameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(parameterType).size()
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameterType)) {
val parameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size()
if (parameterCount <= 1) {
// otherwise additional item with lambda template is to be added
return KotlinFunctionInsertHandler(CaretPosition.IN_BRACKETS, GenerateLambdaInfo(parameterType, false))
@@ -79,8 +79,8 @@ class LookupElementsCollector(
val parameters = descriptor.getValueParameters()
if (parameters.size() == 1) {
val parameterType = parameters.get(0).getType()
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(parameterType)) {
val parameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(parameterType).size()
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameterType)) {
val parameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size()
if (parameterCount > 1) {
val lookupElement = boldImmediateLookupElementFactory.createLookupElement(resolutionFacade, descriptor)
addElement(object : LookupElementDecorator<LookupElement>(lookupElement) {
@@ -86,11 +86,11 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
val resolutionFacade = file.getResolutionFacade()
val bindingContext = resolutionFacade.analyzeWithPartialBodyResolve(expression)
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade).calculate(expression) ?: return false
val functionTypes = expectedInfos.map { it.type }.filter { KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(it) }.toSet()
val functionTypes = expectedInfos.map { it.type }.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it) }.toSet()
if (functionTypes.size <= 1) return false
val lambdaParameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(lambdaType).size
return functionTypes.filter { KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(it).size == lambdaParameterCount }.size > 1
val lambdaParameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(lambdaType).size
return functionTypes.filter { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size == lambdaParameterCount }.size > 1
}
private fun buildTemplate(lambdaType: JetType, explicitParameterTypes: Boolean, project: Project): Template {
@@ -138,4 +138,4 @@ private class ParameterNameExpression(val nameSuggestions: Array<String>) : Expr
}
fun functionParameterTypes(functionType: JetType): List<JetType>
= KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(functionType).map { it.getType() }
= KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(functionType).map { it.getType() }
@@ -31,7 +31,7 @@ object LambdaItems {
val distinctTypes = functionExpectedInfos.map { it.type }.toSet()
val singleType = if (distinctTypes.size == 1) distinctTypes.single() else null
val singleSignatureLength = singleType?.let { KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(it).size }
val singleSignatureLength = singleType?.let { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size }
val offerNoParametersLambda = singleSignatureLength == 0 || singleSignatureLength == 1
if (offerNoParametersLambda) {
val lookupElement = LookupElementBuilder.create("{...}")
@@ -119,7 +119,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
val itemsToSkip = calcItemsToSkip(expressionWithType)
val functionExpectedInfos = expectedInfos.filter { KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(it.type) }
val functionExpectedInfos = expectedInfos.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.type) }
fun filterDeclaration(descriptor: DeclarationDescriptor): Collection<LookupElement> {
val result = ArrayList<LookupElement>()
@@ -87,7 +87,7 @@ class TypeInstantiationItems(
type: JetType,
tail: Tail?
) {
if (KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(type)) return // do not show "object: ..." for function types
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) return // do not show "object: ..." for function types
val classifier = type.getConstructor().getDeclarationDescriptor()
if (classifier !is ClassDescriptor) return
@@ -97,7 +97,7 @@ class TypeInstantiationItems(
val typeArgs = type.getArguments()
items.addIfNotNull(createTypeInstantiationItem(classifier, typeArgs, tail))
if (!KotlinBuiltIns.getInstance().isAny(classifier)) { // do not search inheritors of Any
if (!KotlinBuiltIns.isAny(classifier)) { // do not search inheritors of Any
inheritanceSearchers.addInheritorSearcher(classifier, classifier, typeArgs, tail)
val javaAnalogFqName = KotlinToJavaTypesMap.getInstance().getKotlinToJavaFqName(DescriptorUtils.getFqNameSafe(classifier))