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);
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations