use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class TranslationUtils method hasCorrespondingFunctionIntrinsic.
public static boolean hasCorrespondingFunctionIntrinsic(@NotNull TranslationContext context, @NotNull KtOperationExpression expression) {
CallableDescriptor operationDescriptor = getCallableDescriptorForOperationExpression(context.bindingContext(), expression);
if (operationDescriptor == null || !(operationDescriptor instanceof FunctionDescriptor))
return true;
KotlinType returnType = operationDescriptor.getReturnType();
if (returnType != null && (KotlinBuiltIns.isChar(returnType) || KotlinBuiltIns.isLong(returnType) || KotlinBuiltIns.isInt(returnType))) {
return false;
}
if (context.intrinsics().getFunctionIntrinsic((FunctionDescriptor) operationDescriptor).exists())
return true;
return false;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class QuickFixUtil method getDeclarationReturnType.
@Nullable
public static KotlinType getDeclarationReturnType(KtNamedDeclaration declaration) {
PsiFile file = declaration.getContainingFile();
if (!(file instanceof KtFile))
return null;
DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(declaration, BodyResolveMode.FULL);
if (!(descriptor instanceof CallableDescriptor))
return null;
KotlinType type = ((CallableDescriptor) descriptor).getReturnType();
if (type instanceof DeferredType) {
type = ((DeferredType) type).getDelegate();
}
return type;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class DescriptorUtils method getSuperclassDescriptors.
@NotNull
public static List<ClassDescriptor> getSuperclassDescriptors(@NotNull ClassDescriptor classDescriptor) {
Collection<KotlinType> superclassTypes = classDescriptor.getTypeConstructor().getSupertypes();
List<ClassDescriptor> superClassDescriptors = new ArrayList<ClassDescriptor>();
for (KotlinType type : superclassTypes) {
ClassDescriptor result = getClassDescriptorForType(type);
if (!isAny(result)) {
superClassDescriptors.add(result);
}
}
return superClassDescriptors;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class SamWrapperCodegen method genWrapper.
@NotNull
public Type genWrapper(@NotNull KtFile file) {
// Name for generated class, in form of whatever$1
FqName fqName = getWrapperName(file);
Type asmType = asmTypeByFqNameWithoutInnerClasses(fqName);
// e.g. (T, T) -> Int
KotlinType functionType = samType.getKotlinFunctionType();
ClassDescriptor classDescriptor = new ClassDescriptorImpl(samType.getJavaClassDescriptor().getContainingDeclaration(), fqName.shortName(), Modality.FINAL, ClassKind.CLASS, Collections.singleton(samType.getType()), SourceElement.NO_SOURCE, /* isExternal = */
false);
// e.g. compare(T, T)
SimpleFunctionDescriptor erasedInterfaceFunction = samType.getAbstractMethod().getOriginal().copy(classDescriptor, Modality.FINAL, Visibilities.PUBLIC, CallableMemberDescriptor.Kind.SYNTHESIZED, /*copyOverrides=*/
false);
ClassBuilder cv = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(erasedInterfaceFunction), asmType, file);
cv.defineClass(file, state.getClassFileVersion(), ACC_FINAL | ACC_SUPER | visibility, asmType.getInternalName(), null, OBJECT_TYPE.getInternalName(), new String[] { typeMapper.mapType(samType.getType()).getInternalName() });
cv.visitSource(file.getName(), null);
WriteAnnotationUtilKt.writeSyntheticClassMetadata(cv, state);
// e.g. ASM type for Function2
Type functionAsmType = typeMapper.mapType(functionType);
cv.newField(JvmDeclarationOriginKt.OtherOrigin(erasedInterfaceFunction), ACC_SYNTHETIC | ACC_PRIVATE | ACC_FINAL, FUNCTION_FIELD_NAME, functionAsmType.getDescriptor(), null, null);
generateConstructor(asmType, functionAsmType, cv);
generateMethod(asmType, functionAsmType, cv, erasedInterfaceFunction, functionType);
cv.done();
return asmType;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class CodegenAnnotatingVisitor method visitCallableReferenceExpression.
@Override
public void visitCallableReferenceExpression(@NotNull KtCallableReferenceExpression expression) {
ResolvedCall<?> referencedFunction = CallUtilKt.getResolvedCall(expression.getCallableReference(), bindingContext);
if (referencedFunction == null)
return;
CallableDescriptor target = referencedFunction.getResultingDescriptor();
CallableDescriptor callableDescriptor;
Collection<KotlinType> supertypes;
KtExpression receiverExpression = expression.getReceiverExpression();
KotlinType receiverType = receiverExpression != null ? bindingContext.getType(receiverExpression) : null;
if (target instanceof FunctionDescriptor) {
callableDescriptor = bindingContext.get(FUNCTION, expression);
if (callableDescriptor == null)
return;
supertypes = runtimeTypes.getSupertypesForFunctionReference((FunctionDescriptor) target, receiverType != null);
} else if (target instanceof PropertyDescriptor) {
callableDescriptor = bindingContext.get(VARIABLE, expression);
if (callableDescriptor == null)
return;
//noinspection ConstantConditions
supertypes = Collections.singleton(runtimeTypes.getSupertypeForPropertyReference((PropertyDescriptor) target, ReflectionTypes.Companion.isNumberedKMutablePropertyType(callableDescriptor.getReturnType()), receiverType != null));
} else {
return;
}
String name = inventAnonymousClassName();
ClassDescriptor classDescriptor = recordClassForCallable(expression, callableDescriptor, supertypes, name);
MutableClosure closure = recordClosure(classDescriptor, name);
if (receiverType != null) {
closure.setCaptureReceiverType(receiverType);
}
super.visitCallableReferenceExpression(expression);
}
Aggregations