Search in sources :

Example 1 with Name

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

the class AbstractAnnotationDescriptorResolveTest method getPropertyDescriptor.

@NotNull
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
    Name propertyName = Name.identifier(name);
    MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
    Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
    assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
    return properties.iterator().next();
}
Also used : MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Name

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

the class AbstractAnnotationDescriptorResolveTest method getClassDescriptor.

@NotNull
protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
    Name className = Name.identifier(name);
    ClassifierDescriptor aClass = packageView.getMemberScope().getContributedClassifier(className, NoLookupLocation.FROM_TEST);
    assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
    assert aClass instanceof ClassDescriptor : "Not a class: " + aClass;
    return (ClassDescriptor) aClass;
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Name

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

the class SignaturesPropagationData method modifyValueParametersAccordingToSuperMethods.

private ValueParameters modifyValueParametersAccordingToSuperMethods(@NotNull List<ValueParameterDescriptor> parameters) {
    KotlinType resultReceiverType = null;
    List<ValueParameterDescriptor> resultParameters = new ArrayList<ValueParameterDescriptor>(parameters.size());
    boolean shouldBeExtension = checkIfShouldBeExtension();
    for (final ValueParameterDescriptor originalParam : parameters) {
        final int originalIndex = originalParam.getIndex();
        List<TypeAndName> typesFromSuperMethods = ContainerUtil.map(superFunctions, new Function<FunctionDescriptor, TypeAndName>() {

            @Override
            public TypeAndName fun(FunctionDescriptor superFunction) {
                ReceiverParameterDescriptor receiver = superFunction.getExtensionReceiverParameter();
                int index = receiver != null ? originalIndex - 1 : originalIndex;
                if (index == -1) {
                    assert receiver != null : "can't happen: index is -1, while function is not extension";
                    return new TypeAndName(receiver.getType(), originalParam.getName());
                }
                ValueParameterDescriptor parameter = superFunction.getValueParameters().get(index);
                return new TypeAndName(parameter.getType(), parameter.getName());
            }
        });
        VarargCheckResult varargCheckResult = checkVarargInSuperFunctions(originalParam);
        KotlinType altType = varargCheckResult.parameterType;
        if (shouldBeExtension && originalIndex == 0) {
            resultReceiverType = altType;
        } else {
            Name stableName = null;
            for (int i = 0; i < superFunctions.size(); i++) {
                if (superFunctions.get(i).hasStableParameterNames()) {
                    // When there's more than one stable name in super functions, we pick the first one. This behaviour is similar to
                    // the compiler front-end, except that it reports a warning in such cases
                    // TODO: report a warning somewhere if there's more than one stable name in super functions
                    stableName = typesFromSuperMethods.get(i).name;
                    break;
                }
            }
            resultParameters.add(new ValueParameterDescriptorImpl(originalParam.getContainingDeclaration(), null, shouldBeExtension ? originalIndex - 1 : originalIndex, originalParam.getAnnotations(), stableName != null ? stableName : originalParam.getName(), altType, originalParam.declaresDefaultValue(), originalParam.isCrossinline(), originalParam.isNoinline(), varargCheckResult.isVararg ? DescriptorUtilsKt.getBuiltIns(originalParam).getArrayElementType(altType) : null, SourceElement.NO_SOURCE));
        }
    }
    boolean hasStableParameterNames = CollectionsKt.any(superFunctions, new Function1<FunctionDescriptor, Boolean>() {

        @Override
        public Boolean invoke(FunctionDescriptor descriptor) {
            return descriptor.hasStableParameterNames();
        }
    });
    return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) DescriptorUtils.getFqName(org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName) Name(org.jetbrains.kotlin.name.Name) ValueParameterDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl)

Example 4 with Name

use of org.jetbrains.kotlin.name.Name 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 5 with Name

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

the class KtAnnotationEntryElementType method createStub.

@Override
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
    Name shortName = KtPsiUtil.getShortName(psi);
    String resultName = shortName != null ? shortName.asString() : psi.getText();
    KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
    boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
    return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments);
}
Also used : KotlinAnnotationEntryStubImpl(org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationEntryStubImpl) KtValueArgumentList(org.jetbrains.kotlin.psi.KtValueArgumentList) Name(org.jetbrains.kotlin.name.Name)

Aggregations

Name (org.jetbrains.kotlin.name.Name)37 FqName (org.jetbrains.kotlin.name.FqName)18 NotNull (org.jetbrains.annotations.NotNull)16 Nullable (org.jetbrains.annotations.Nullable)10 KotlinType (org.jetbrains.kotlin.types.KotlinType)6 MemberScope (org.jetbrains.kotlin.resolve.scopes.MemberScope)5 PsiElement (com.intellij.psi.PsiElement)4 IElementType (com.intellij.psi.tree.IElementType)3 Annotations (org.jetbrains.kotlin.descriptors.annotations.Annotations)3 CompositeAnnotations (org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations)3 ExpressionReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver)3 List (java.util.List)2 AnnotationSplitter (org.jetbrains.kotlin.descriptors.annotations.AnnotationSplitter)2 DescriptorUtils.getFqName (org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName)2 TemporaryBindingTrace (org.jetbrains.kotlin.resolve.TemporaryBindingTrace)2 ASTNode (com.intellij.lang.ASTNode)1 PsiClass (com.intellij.psi.PsiClass)1 Function (com.intellij.util.Function)1 ArrayList (java.util.ArrayList)1 Pair (kotlin.Pair)1