Search in sources :

Example 1 with KtCodeFragment

use of org.jetbrains.kotlin.psi.KtCodeFragment in project kotlin by JetBrains.

the class DebugInfoAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
    if (!isDebugInfoEnabled() || !ProjectRootsUtil.isInProjectOrLibSource(element)) {
        return;
    }
    if (element instanceof KtFile && !(element instanceof KtCodeFragment)) {
        KtFile file = (KtFile) element;
        try {
            BindingContext bindingContext = ResolutionUtils.analyzeFully(file);
            DebugInfoUtil.markDebugAnnotations(file, bindingContext, new DebugInfoUtil.DebugInfoReporter() {

                @Override
                public void reportElementWithErrorType(@NotNull KtReferenceExpression expression) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(KotlinHighlightingColors.RESOLVED_TO_ERROR);
                }

                @Override
                public void reportMissingUnresolved(@NotNull KtReferenceExpression expression) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Reference is not resolved to anything, but is not marked unresolved").setTextAttributes(KotlinHighlightingColors.DEBUG_INFO);
                }

                @Override
                public void reportUnresolvedWithTarget(@NotNull KtReferenceExpression expression, @NotNull String target) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target).setTextAttributes(KotlinHighlightingColors.DEBUG_INFO);
                }
            });
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Throwable e) {
            // TODO
            holder.createErrorAnnotation(element, e.getClass().getCanonicalName() + ": " + e.getMessage());
            e.printStackTrace();
        }
    }
}
Also used : KtReferenceExpression(org.jetbrains.kotlin.psi.KtReferenceExpression) KtCodeFragment(org.jetbrains.kotlin.psi.KtCodeFragment) KtFile(org.jetbrains.kotlin.psi.KtFile) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) DebugInfoUtil(org.jetbrains.kotlin.checkers.DebugInfoUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 DebugInfoUtil (org.jetbrains.kotlin.checkers.DebugInfoUtil)1 KtCodeFragment (org.jetbrains.kotlin.psi.KtCodeFragment)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 KtReferenceExpression (org.jetbrains.kotlin.psi.KtReferenceExpression)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1