Search in sources :

Example 6 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testDuplicateObjectInBinaryAndSources.

public void testDuplicateObjectInBinaryAndSources() throws Exception {
    Collection<DeclarationDescriptor> allDescriptors = analyzeAndGetAllDescriptors(compileLibrary("library"));
    assertEquals(allDescriptors.toString(), 2, allDescriptors.size());
    for (DeclarationDescriptor descriptor : allDescriptors) {
        assertTrue("Wrong name: " + descriptor, descriptor.getName().asString().equals("Lol"));
        assertTrue("Should be an object: " + descriptor, isObject(descriptor));
    }
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor)

Example 7 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.

the class KotlinOverridingDialog method formatElement.

private static String formatElement(PsiElement element) {
    element = KtPsiUtil.ascendIfPropertyAccessor(element);
    if (element instanceof KtNamedFunction || element instanceof KtProperty) {
        BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
        DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
        if (declarationDescriptor instanceof CallableMemberDescriptor) {
            DeclarationDescriptor containingDescriptor = declarationDescriptor.getContainingDeclaration();
            if (containingDescriptor instanceof ClassDescriptor) {
                return KotlinBundle.message("x.in.y", DescriptorRenderer.COMPACT.render(declarationDescriptor), IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor));
            }
        }
    }
    assert element instanceof PsiMethod : "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found";
    return RenderingUtilsKt.formatPsiMethod((PsiMethod) element, true, false);
}
Also used : KtProperty(org.jetbrains.kotlin.psi.KtProperty) ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) PsiMethod(com.intellij.psi.PsiMethod) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) CallableMemberDescriptor(org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)

Example 8 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.

the class JsInliner method inline.

private void inline(@NotNull JsInvocation call, @NotNull JsContext context) {
    DeclarationDescriptor callDescriptor = MetadataProperties.getDescriptor(call);
    if (isSuspendWithCurrentContinuation(callDescriptor)) {
        inlineSuspendWithCurrentContinuation(call, context);
        return;
    }
    JsInliningContext inliningContext = getInliningContext();
    InlineableResult inlineableResult = getInlineableCallReplacement(call, inliningContext);
    JsStatement inlineableBody = inlineableResult.getInlineableBody();
    JsExpression resultExpression = inlineableResult.getResultExpression();
    JsContext<JsStatement> statementContext = inliningContext.getStatementContext();
    // body of inline function can contain call to lambdas that need to be inlined
    JsStatement inlineableBodyWithLambdasInlined = accept(inlineableBody);
    assert inlineableBody == inlineableBodyWithLambdasInlined;
    statementContext.addPrevious(flattenStatement(inlineableBody));
    /*
         * Assumes, that resultExpression == null, when result is not needed.
         * @see FunctionInlineMutator.isResultNeeded()
         */
    if (resultExpression == null) {
        statementContext.removeMe();
        return;
    }
    resultExpression = accept(resultExpression);
    MetadataProperties.setSynthetic(resultExpression, true);
    context.replaceMe(resultExpression);
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor)

Example 9 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.

the class BuiltInsReferenceResolverTest method getAllStandardDescriptors.

private static Collection<DeclarationDescriptor> getAllStandardDescriptors() {
    final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
    PackageFragmentDescriptor builtinsPackageFragment = DefaultBuiltIns.getInstance().getBuiltInsPackageFragment();
    for (DeclarationDescriptor packageMember : DescriptorUtils.getAllDescriptors(builtinsPackageFragment.getMemberScope())) {
        packageMember.acceptVoid(new DeclarationDescriptorVisitorEmptyBodies<Void, Void>() {

            @Override
            public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
                descriptors.add(descriptor);
                for (DeclarationDescriptor classMember : DescriptorUtils.getAllDescriptors(descriptor.getDefaultType().getMemberScope())) {
                    classMember.acceptVoid(this);
                }
                return null;
            }

            @Override
            public Void visitDeclarationDescriptor(DeclarationDescriptor descriptor, Void data) {
                descriptors.add(descriptor);
                return null;
            }
        });
    }
    return descriptors;
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) ArrayList(java.util.ArrayList) PackageFragmentDescriptor(org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor)

Example 10 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.

the class AssignmentTranslator method isReferenceToBackingFieldFromConstructor.

private static boolean isReferenceToBackingFieldFromConstructor(@NotNull KtExpression expression, @NotNull TranslationContext context) {
    if (expression instanceof KtSimpleNameExpression) {
        KtSimpleNameExpression nameExpression = (KtSimpleNameExpression) expression;
        DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), nameExpression);
        return isReferenceToBackingFieldFromConstructor(descriptor, context);
    } else if (expression instanceof KtDotQualifiedExpression) {
        KtDotQualifiedExpression qualifiedExpression = (KtDotQualifiedExpression) expression;
        if (qualifiedExpression.getReceiverExpression() instanceof KtThisExpression && qualifiedExpression.getSelectorExpression() instanceof KtSimpleNameExpression) {
            KtSimpleNameExpression nameExpression = (KtSimpleNameExpression) qualifiedExpression.getSelectorExpression();
            DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), nameExpression);
            return isReferenceToBackingFieldFromConstructor(descriptor, context);
        }
    }
    return false;
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor)

Aggregations

DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)18 NotNull (org.jetbrains.annotations.NotNull)5 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)3 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 CallableDescriptor (org.jetbrains.kotlin.descriptors.CallableDescriptor)2 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)2 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)2 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 ResolvedCall (org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)2 VariableAsFunctionResolvedCall (org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 Trinity (com.intellij.openapi.util.Trinity)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 IElementType (com.intellij.psi.tree.IElementType)1 File (java.io.File)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 JarFile (java.util.jar.JarFile)1