Search in sources :

Example 1 with KtElement

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

the class KotlinComponentUnwrapper method doUnwrap.

@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
    KtElement targetElement = (KtElement) element;
    KtExpression expressionToUnwrap = getExpressionToUnwrap(targetElement);
    assert expressionToUnwrap != null;
    KtElement enclosingElement = getEnclosingElement(targetElement);
    context.extractFromExpression(expressionToUnwrap, enclosingElement);
    context.delete(enclosingElement);
}
Also used : KtElement(org.jetbrains.kotlin.psi.KtElement) KtExpression(org.jetbrains.kotlin.psi.KtExpression)

Example 2 with KtElement

use of org.jetbrains.kotlin.psi.KtElement 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 3 with KtElement

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

the class AnalyzingUtils method formDebugNameForBindingTrace.

// --------------------------------------------------------------------------------------------------------------------------
public static String formDebugNameForBindingTrace(@NotNull String debugName, @Nullable Object resolutionSubjectForMessage) {
    if (WRITE_DEBUG_TRACE_NAMES) {
        StringBuilder debugInfo = new StringBuilder(debugName);
        if (resolutionSubjectForMessage instanceof KtElement) {
            KtElement element = (KtElement) resolutionSubjectForMessage;
            debugInfo.append(" ").append(DebugTextUtilKt.getDebugText(element));
            //debugInfo.append(" in ").append(element.getContainingFile().getName());
            debugInfo.append(" in ").append(element.getContainingKtFile().getName()).append(" ").append(element.getTextOffset());
        } else if (resolutionSubjectForMessage != null) {
            debugInfo.append(" ").append(resolutionSubjectForMessage);
        }
        return debugInfo.toString();
    }
    return "";
}
Also used : KtElement(org.jetbrains.kotlin.psi.KtElement)

Example 4 with KtElement

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

the class CFGraphToDotFilePrinter method dumpDot.

public static void dumpDot(File file, Collection<Pseudocode> pseudocodes) throws FileNotFoundException {
    File target = KotlinTestUtils.replaceExtension(file, "dot");
    PrintStream out = new PrintStream(target);
    out.println("digraph " + FileUtil.getNameWithoutExtension(file) + " {");
    int[] count = new int[1];
    Map<Instruction, String> nodeToName = new HashMap<Instruction, String>();
    for (Pseudocode pseudocode : pseudocodes) {
        dumpNodes(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName, Sets.newHashSet(pseudocode.getInstructions()));
    }
    int i = 0;
    for (Pseudocode pseudocode : pseudocodes) {
        String label;
        KtElement correspondingElement = pseudocode.getCorrespondingElement();
        if (correspondingElement instanceof KtNamedDeclaration) {
            KtNamedDeclaration namedDeclaration = (KtNamedDeclaration) correspondingElement;
            label = namedDeclaration.getName();
        } else {
            label = "anonymous_" + i;
        }
        out.println("subgraph cluster_" + i + " {\n" + "label=\"" + label + "\";\n" + "color=blue;\n");
        dumpEdges(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName);
        out.println("}");
        i++;
    }
    out.println("}");
    out.close();
}
Also used : PrintStream(java.io.PrintStream) KtElement(org.jetbrains.kotlin.psi.KtElement) KtNamedDeclaration(org.jetbrains.kotlin.psi.KtNamedDeclaration) Pseudocode(org.jetbrains.kotlin.cfg.pseudocode.Pseudocode) Instruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction) SubroutineSinkInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction) SubroutineExitInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction) SubroutineEnterInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction) MagicInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.MagicInstruction) LocalFunctionDeclarationInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction) File(java.io.File)

Example 5 with KtElement

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

the class KotlinDescriptorIconProvider method getIcon.

@NotNull
public static Icon getIcon(@NotNull DeclarationDescriptor descriptor, @Nullable PsiElement declaration, @Iconable.IconFlags int flags) {
    if (declaration != null && !(declaration instanceof KtElement)) {
        return declaration.getIcon(flags);
    }
    Icon result = getBaseIcon(descriptor);
    if ((flags & Iconable.ICON_FLAG_VISIBILITY) > 0) {
        RowIcon rowIcon = new RowIcon(2);
        rowIcon.setIcon(result, 0);
        rowIcon.setIcon(getVisibilityIcon(descriptor), 1);
        result = rowIcon;
    }
    return result;
}
Also used : KtElement(org.jetbrains.kotlin.psi.KtElement) RowIcon(com.intellij.ui.RowIcon) RowIcon(com.intellij.ui.RowIcon) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

KtElement (org.jetbrains.kotlin.psi.KtElement)6 NotNull (org.jetbrains.annotations.NotNull)2 KtExpression (org.jetbrains.kotlin.psi.KtExpression)2 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RowIcon (com.intellij.ui.RowIcon)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Pseudocode (org.jetbrains.kotlin.cfg.pseudocode.Pseudocode)1 Instruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction)1 MagicInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.MagicInstruction)1 LocalFunctionDeclarationInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction)1 SubroutineEnterInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction)1 SubroutineExitInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction)1 SubroutineSinkInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 KtDeclaration (org.jetbrains.kotlin.psi.KtDeclaration)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 KtNamedDeclaration (org.jetbrains.kotlin.psi.KtNamedDeclaration)1 KtReferenceExpression (org.jetbrains.kotlin.psi.KtReferenceExpression)1