Search in sources :

Example 16 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class CheckEmptyTagInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlTag(final XmlTag tag) {
            if (!isTagWithEmptyEndNotAllowed(tag)) {
                return;
            }
            final ASTNode child = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.getNode());
            if (child == null) {
                return;
            }
            final LocalQuickFix fix = new MyLocalQuickFix();
            holder.registerProblem(tag, XmlBundle.message("html.inspections.check.empty.script.message"), tag.getContainingFile().getContext() != null ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) ASTNode(com.intellij.lang.ASTNode) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ASTNode

use of com.intellij.lang.ASTNode in project kotlin by JetBrains.

the class KotlinInplaceVariableIntroducer method runWriteActionAndRestartRefactoring.

protected final void runWriteActionAndRestartRefactoring(final Runnable runnable) {
    final Ref<Boolean> greedyToRight = new Ref<Boolean>();
    new WriteCommandAction(myProject, getCommandName(), getCommandName()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
            ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
            if (identifier != null) {
                TextRange range = identifier.getTextRange();
                RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
                for (RangeHighlighter highlighter : highlighters) {
                    if (highlighter.getStartOffset() == range.getStartOffset()) {
                        if (highlighter.getEndOffset() == range.getEndOffset()) {
                            greedyToRight.set(highlighter.isGreedyToRight());
                            highlighter.setGreedyToRight(false);
                        }
                    }
                }
            }
            runnable.run();
            TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
            if (templateState != null) {
                myEditor.putUserData(INTRODUCE_RESTART, true);
                templateState.cancelTemplate();
            }
        }
    }.execute();
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
            if (identifier != null) {
                TextRange range = identifier.getTextRange();
                RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
                for (RangeHighlighter highlighter : highlighters) {
                    if (highlighter.getStartOffset() == range.getStartOffset()) {
                        if (highlighter.getEndOffset() == range.getEndOffset()) {
                            highlighter.setGreedyToRight(greedyToRight.get());
                        }
                    }
                }
            }
        }
    });
    if (myEditor.getUserData(INTRODUCE_RESTART) == Boolean.TRUE) {
        myInitialName = myDeclaration.getName();
        performInplaceRefactoring(getSuggestionsForNextRun());
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) ASTNode(com.intellij.lang.ASTNode) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) Result(com.intellij.openapi.application.Result)

Example 18 with ASTNode

use of com.intellij.lang.ASTNode in project kotlin by JetBrains.

the class KtInvokeFunctionReference method getRanges.

@Override
public List<TextRange> getRanges() {
    List<TextRange> list = new ArrayList<TextRange>();
    KtValueArgumentList valueArgumentList = getExpression().getValueArgumentList();
    if (valueArgumentList != null) {
        if (valueArgumentList.getArguments().size() > 0) {
            ASTNode valueArgumentListNode = valueArgumentList.getNode();
            ASTNode lPar = valueArgumentListNode.findChildByType(KtTokens.LPAR);
            if (lPar != null) {
                list.add(getRange(lPar));
            }
            ASTNode rPar = valueArgumentListNode.findChildByType(KtTokens.RPAR);
            if (rPar != null) {
                list.add(getRange(rPar));
            }
        } else {
            list.add(getRange(valueArgumentList.getNode()));
        }
    }
    List<KtLambdaArgument> functionLiteralArguments = getExpression().getLambdaArguments();
    for (KtLambdaArgument functionLiteralArgument : functionLiteralArguments) {
        KtLambdaExpression functionLiteralExpression = functionLiteralArgument.getLambdaExpression();
        list.add(getRange(functionLiteralExpression.getLeftCurlyBrace()));
        ASTNode rightCurlyBrace = functionLiteralExpression.getRightCurlyBrace();
        if (rightCurlyBrace != null) {
            list.add(getRange(rightCurlyBrace));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange)

Example 19 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class ExpressionGenerator method visitBuiltinTypeClassExpression.

@Override
public void visitBuiltinTypeClassExpression(@NotNull GrBuiltinTypeClassExpression expression) {
    PsiElement firstChild = expression.getFirstChild();
    LOG.assertTrue(firstChild != null);
    ASTNode node = firstChild.getNode();
    LOG.assertTrue(node != null);
    final IElementType type = node.getElementType();
    final String boxed = TypesUtil.getBoxedTypeName(type);
    builder.append(boxed);
    if (expression.getParent() instanceof GrIndexProperty) {
        builder.append("[]");
    }
    builder.append(".class");
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrIndexProperty(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty) ASTNode(com.intellij.lang.ASTNode) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 20 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class I18nMessageGotoDeclarationHandler method getGotoDeclarationTarget.

@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement element, Editor editor) {
    if (!(element instanceof PsiJavaToken))
        return null;
    //some street magic
    int i = 4;
    while (element != null && i > 0) {
        final ASTNode node = element.getNode();
        if (node != null && node.getUserData(KEY) instanceof PropertyFoldingBuilder) {
            break;
        } else {
            i--;
            element = element.getParent();
        }
    }
    //case: "literalAnnotatedWithPropertyKey"
    if (element instanceof PsiLiteralExpression) {
        return resolve(element);
    }
    //case: MyBundle.message("literalAnnotatedWithPropertyKey", param1, param2)
    if (element instanceof PsiMethodCallExpression) {
        final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) element;
        FoldRegion foldRegion = null;
        for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) {
            final PsiElement psiElement = EditorFoldingInfo.get(editor).getPsiElement(region);
            if (methodCall.equals(psiElement)) {
                foldRegion = region;
            }
        }
        if (foldRegion == null || foldRegion.isExpanded())
            return null;
        for (PsiExpression expression : methodCall.getArgumentList().getExpressions()) {
            if (expression instanceof PsiLiteralExpression && PropertyFoldingBuilder.isI18nProperty((PsiLiteralExpression) expression)) {
                return resolve(expression);
            }
        }
    }
    return null;
}
Also used : ASTNode(com.intellij.lang.ASTNode) FoldRegion(com.intellij.openapi.editor.FoldRegion)

Aggregations

ASTNode (com.intellij.lang.ASTNode)839 NotNull (org.jetbrains.annotations.NotNull)154 PsiElement (com.intellij.psi.PsiElement)152 IElementType (com.intellij.psi.tree.IElementType)152 Nullable (org.jetbrains.annotations.Nullable)113 TextRange (com.intellij.openapi.util.TextRange)97 ArrayList (java.util.ArrayList)60 PsiFile (com.intellij.psi.PsiFile)36 IncorrectOperationException (com.intellij.util.IncorrectOperationException)35 Annotation (com.intellij.lang.annotation.Annotation)25 AbstractBlock (com.intellij.psi.formatter.common.AbstractBlock)22 CharTable (com.intellij.util.CharTable)22 FileASTNode (com.intellij.lang.FileASTNode)20 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)20 Document (com.intellij.openapi.editor.Document)20 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)18 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)18 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)18 Project (com.intellij.openapi.project.Project)17 XmlTag (com.intellij.psi.xml.XmlTag)17