Search in sources :

Example 1 with FqNameUnsafe

use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.

the class SignaturesPropagationData method getSuperFunctionsForMethod.

private static List<FunctionDescriptor> getSuperFunctionsForMethod(@NotNull JavaMethod method, @NotNull JavaMethodDescriptor autoMethodDescriptor, @NotNull ClassDescriptor containingClass) {
    List<FunctionDescriptor> superFunctions = Lists.newArrayList();
    // TODO: Add propagation for other kotlin descriptors (KT-3621)
    Name name = method.getName();
    Method autoSignature = null;
    boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
    for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
        Collection<SimpleFunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
        if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates))
            continue;
        if (autoSignature == null) {
            autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
        }
        for (FunctionDescriptor candidate : superFunctionCandidates) {
            // TODO: remove this continue when KT-15747 is fixed
            if (candidate.isSuspend())
                continue;
            Method candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
            if (KotlinToJvmSignatureMapperKt.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
                superFunctions.add(candidate);
            }
        }
    }
    // sorting for diagnostic stability
    Collections.sort(superFunctions, new Comparator<FunctionDescriptor>() {

        @Override
        public int compare(@NotNull FunctionDescriptor fun1, @NotNull FunctionDescriptor fun2) {
            FqNameUnsafe fqName1 = getFqName(fun1.getContainingDeclaration());
            FqNameUnsafe fqName2 = getFqName(fun2.getContainingDeclaration());
            return fqName1.asString().compareTo(fqName2.asString());
        }
    });
    return superFunctions;
}
Also used : FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) KotlinType(org.jetbrains.kotlin.types.KotlinType) JavaMethod(org.jetbrains.kotlin.load.java.structure.JavaMethod) Method(org.jetbrains.org.objectweb.asm.commons.Method) DescriptorUtils.getFqName(org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName) Name(org.jetbrains.kotlin.name.Name)

Example 2 with FqNameUnsafe

use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.

the class AbstractClassTypeConstructor method equals.

@Override
public boolean equals(Object other) {
    if (!(other instanceof TypeConstructor))
        return false;
    // performance optimization: getFqName is slow method
    if (other.hashCode() != hashCode())
        return false;
    // To avoid problems in type checker we suppose that it is different type constructors.
    if (((TypeConstructor) other).getParameters().size() != getParameters().size())
        return false;
    ClassifierDescriptor myDescriptor = getDeclarationDescriptor();
    ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
    // descriptor for type is created once per module
    if (myDescriptor == otherDescriptor)
        return true;
    // All error types have the same descriptor
    if (!hasMeaningfulFqName(myDescriptor) || otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
        return this == other;
    }
    if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
        FqNameUnsafe otherFqName = DescriptorUtils.getFqName(otherDescriptor);
        FqNameUnsafe myFqName = DescriptorUtils.getFqName(myDescriptor);
        return myFqName.equals(otherFqName);
    }
    return false;
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) ClassifierDescriptor(org.jetbrains.kotlin.descriptors.ClassifierDescriptor)

Example 3 with FqNameUnsafe

use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.

the class RangeCodegenUtil method getPrimitiveRangeOrProgressionElementType.

@Nullable
private static PrimitiveType getPrimitiveRangeOrProgressionElementType(@NotNull KotlinType rangeOrProgression, @NotNull ImmutableMap<FqName, PrimitiveType> map) {
    ClassifierDescriptor declarationDescriptor = rangeOrProgression.getConstructor().getDeclarationDescriptor();
    if (declarationDescriptor == null)
        return null;
    FqNameUnsafe fqName = DescriptorUtils.getFqName(declarationDescriptor);
    if (!fqName.isSafe())
        return null;
    return map.get(fqName.toSafe());
}
Also used : FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with FqNameUnsafe

use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.

the class Namer method getFunctionTag.

@NotNull
public static String getFunctionTag(@NotNull CallableDescriptor functionDescriptor) {
    functionDescriptor = (CallableDescriptor) JsDescriptorUtils.findRealInlineDeclaration(functionDescriptor);
    String moduleName = getModuleName(functionDescriptor);
    FqNameUnsafe fqNameParent = DescriptorUtils.getFqName(functionDescriptor).parent();
    String qualifier = null;
    if (!fqNameParent.isRoot()) {
        qualifier = fqNameParent.asString();
    }
    SuggestedName suggestedName = new NameSuggestion().suggest(functionDescriptor);
    assert suggestedName != null : "Suggested name can be null only for module descriptors: " + functionDescriptor;
    String mangledName = suggestedName.getNames().get(0);
    return StringUtil.join(Arrays.asList(moduleName, qualifier, mangledName), ".");
}
Also used : NameSuggestion(org.jetbrains.kotlin.js.naming.NameSuggestion) FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) SuggestedName(org.jetbrains.kotlin.js.naming.SuggestedName) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FqNameUnsafe

use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.

the class RangeCodegenUtil method isPrimitiveRangeSpecializationOfType.

/*
     * Checks whether for expression 'x in a..b' a..b is primitive integral range
     * with same type as x.
     */
public static boolean isPrimitiveRangeSpecializationOfType(@NotNull Type argumentType, @NotNull KtExpression rangeExpression, @NotNull BindingContext bindingContext) {
    if (rangeExpression instanceof KtBinaryExpression && ((KtBinaryExpression) rangeExpression).getOperationReference().getReferencedNameElementType() == KtTokens.RANGE) {
        KotlinType kotlinType = bindingContext.getType(rangeExpression);
        assert kotlinType != null;
        DeclarationDescriptor descriptor = kotlinType.getConstructor().getDeclarationDescriptor();
        if (descriptor != null) {
            FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
            if (fqName.equals(KotlinBuiltIns.FQ_NAMES.longRange)) {
                return argumentType == Type.LONG_TYPE;
            }
            if (fqName.equals(KotlinBuiltIns.FQ_NAMES.charRange) || fqName.equals(KotlinBuiltIns.FQ_NAMES.intRange)) {
                return AsmUtil.isIntPrimitive(argumentType);
            }
        }
    }
    return false;
}
Also used : FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

FqNameUnsafe (org.jetbrains.kotlin.name.FqNameUnsafe)7 Nullable (org.jetbrains.annotations.Nullable)2 AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 NotNull (org.jetbrains.annotations.NotNull)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 ClassifierDescriptor (org.jetbrains.kotlin.descriptors.ClassifierDescriptor)1 NameSuggestion (org.jetbrains.kotlin.js.naming.NameSuggestion)1 SuggestedName (org.jetbrains.kotlin.js.naming.SuggestedName)1 JavaMethod (org.jetbrains.kotlin.load.java.structure.JavaMethod)1 Name (org.jetbrains.kotlin.name.Name)1 DescriptorUtils.getFqName (org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1