Search in sources :

Example 11 with DeclarationDescriptor

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

the class CompileKotlinAgainstCustomBinariesTest method testBrokenJarWithNoClassForObject.

public void testBrokenJarWithNoClassForObject() throws Exception {
    File brokenJar = copyJarFileWithoutEntry(compileLibrary("library"), "test/Lol.class");
    Collection<DeclarationDescriptor> allDescriptors = analyzeAndGetAllDescriptors(brokenJar);
    assertEmpty("No descriptors should be found: " + allDescriptors, allDescriptors);
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 12 with DeclarationDescriptor

use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor 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;
}
Also used : DeferredType(org.jetbrains.kotlin.types.DeferredType) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) PsiFile(com.intellij.psi.PsiFile) CallableDescriptor(org.jetbrains.kotlin.descriptors.CallableDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with DeclarationDescriptor

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

the class CheckerTestUtil method getDebugInfoDiagnostics.

@SuppressWarnings("TestOnlyProblems")
@NotNull
private static List<ActualDiagnostic> getDebugInfoDiagnostics(@NotNull PsiElement root, @NotNull BindingContext bindingContext, final boolean markDynamicCalls, @Nullable final List<DeclarationDescriptor> dynamicCallDescriptors, @Nullable final String platform) {
    final List<ActualDiagnostic> debugAnnotations = new ArrayList<ActualDiagnostic>();
    DebugInfoUtil.markDebugAnnotations(root, bindingContext, new DebugInfoUtil.DebugInfoReporter() {

        @Override
        public void reportElementWithErrorType(@NotNull KtReferenceExpression expression) {
            newDiagnostic(expression, DebugInfoDiagnosticFactory.ELEMENT_WITH_ERROR_TYPE);
        }

        @Override
        public void reportMissingUnresolved(@NotNull KtReferenceExpression expression) {
            newDiagnostic(expression, DebugInfoDiagnosticFactory.MISSING_UNRESOLVED);
        }

        @Override
        public void reportUnresolvedWithTarget(@NotNull KtReferenceExpression expression, @NotNull String target) {
            newDiagnostic(expression, DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET);
        }

        @Override
        public void reportDynamicCall(@NotNull KtElement element, DeclarationDescriptor declarationDescriptor) {
            if (dynamicCallDescriptors != null) {
                dynamicCallDescriptors.add(declarationDescriptor);
            }
            if (markDynamicCalls) {
                newDiagnostic(element, DebugInfoDiagnosticFactory.DYNAMIC);
            }
        }

        private void newDiagnostic(KtElement element, DebugInfoDiagnosticFactory factory) {
            debugAnnotations.add(new ActualDiagnostic(new DebugInfoDiagnostic(element, factory), platform));
        }
    });
    //noinspection unchecked
    for (Pair<? extends WritableSlice<? extends KtExpression, ?>, DebugInfoDiagnosticFactory> factory : Arrays.asList(TuplesKt.to(BindingContext.SMARTCAST, DebugInfoDiagnosticFactory.SMARTCAST), TuplesKt.to(BindingContext.IMPLICIT_RECEIVER_SMARTCAST, DebugInfoDiagnosticFactory.IMPLICIT_RECEIVER_SMARTCAST), TuplesKt.to(BindingContext.SMARTCAST_NULL, DebugInfoDiagnosticFactory.CONSTANT), TuplesKt.to(BindingContext.LEAKING_THIS, DebugInfoDiagnosticFactory.LEAKING_THIS), TuplesKt.to(BindingContext.IMPLICIT_EXHAUSTIVE_WHEN, DebugInfoDiagnosticFactory.IMPLICIT_EXHAUSTIVE))) {
        for (KtExpression expression : bindingContext.getSliceContents(factory.getFirst()).keySet()) {
            if (PsiTreeUtil.isAncestor(root, expression, false)) {
                debugAnnotations.add(new ActualDiagnostic(new DebugInfoDiagnostic(expression, factory.getSecond()), platform));
            }
        }
    }
    return debugAnnotations;
}
Also used : KtElement(org.jetbrains.kotlin.psi.KtElement) KtReferenceExpression(org.jetbrains.kotlin.psi.KtReferenceExpression) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KtExpression(org.jetbrains.kotlin.psi.KtExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with DeclarationDescriptor

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

the class CalleeReferenceVisitorBase method visitSimpleNameExpression.

@Override
public void visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression) {
    DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
    if (descriptor == null)
        return;
    PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
    if (declaration == null)
        return;
    if (isProperty(descriptor, declaration) || isCallable(descriptor, declaration, expression)) {
        processDeclaration(expression, declaration);
    }
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) PsiElement(com.intellij.psi.PsiElement)

Example 15 with DeclarationDescriptor

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

the class KtFunctionPsiElementCellRenderer method getElementText.

@Override
public String getElementText(PsiElement element) {
    if (element instanceof KtNamedFunction) {
        KtNamedFunction function = (KtNamedFunction) element;
        DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(function, BodyResolveMode.PARTIAL);
        return DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor);
    }
    return super.getElementText(element);
}
Also used : DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction)

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