Search in sources :

Example 11 with PsiErrorElement

use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.

the class MissingArrayInitializerBraceFixer method apply.

@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
    if (!(psiElement instanceof PsiArrayInitializerExpression))
        return;
    PsiArrayInitializerExpression expr = (PsiArrayInitializerExpression) psiElement;
    if (!expr.getText().endsWith("}")) {
        PsiErrorElement err = ContainerUtil.findInstance(expr.getChildren(), PsiErrorElement.class);
        int endOffset = (err != null ? err : expr).getTextRange().getEndOffset();
        editor.getDocument().insertString(endOffset, "}");
    }
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) PsiArrayInitializerExpression(com.intellij.psi.PsiArrayInitializerExpression)

Example 12 with PsiErrorElement

use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.

the class ASTShallowComparator method textMatches.

private ThreeState textMatches(ASTNode oldNode, ASTNode newNode) {
    myIndicator.checkCanceled();
    String oldText = TreeUtil.isCollapsedChameleon(oldNode) ? oldNode.getText() : null;
    String newText = TreeUtil.isCollapsedChameleon(newNode) ? newNode.getText() : null;
    if (oldText != null && newText != null)
        return oldText.equals(newText) ? ThreeState.YES : ThreeState.UNSURE;
    if (oldText != null) {
        return compareTreeToText((TreeElement) newNode, oldText) ? ThreeState.YES : ThreeState.UNSURE;
    }
    if (newText != null) {
        return compareTreeToText((TreeElement) oldNode, newText) ? ThreeState.YES : ThreeState.UNSURE;
    }
    if (oldNode instanceof ForeignLeafPsiElement) {
        return newNode instanceof ForeignLeafPsiElement && oldNode.getText().equals(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
    }
    if (newNode instanceof ForeignLeafPsiElement)
        return ThreeState.NO;
    if (oldNode instanceof LeafElement) {
        return ((LeafElement) oldNode).textMatches(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
    }
    if (newNode instanceof LeafElement) {
        return ((LeafElement) newNode).textMatches(oldNode.getText()) ? ThreeState.YES : ThreeState.NO;
    }
    if (oldNode instanceof PsiErrorElement && newNode instanceof PsiErrorElement) {
        final PsiErrorElement e1 = (PsiErrorElement) oldNode;
        final PsiErrorElement e2 = (PsiErrorElement) newNode;
        if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription()))
            return ThreeState.NO;
    }
    return ThreeState.UNSURE;
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement)

Example 13 with PsiErrorElement

use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.

the class PsiTreeDebugBuilder method psiToBuffer.

private void psiToBuffer(PsiElement root, int indent, boolean showRanges, boolean showChildrenRanges) {
    if (!myShowWhiteSpaces && root instanceof PsiWhiteSpace)
        return;
    if (!myShowErrorElements && root instanceof PsiErrorElement)
        return;
    for (int i = 0; i < indent; i++) {
        myBuffer.append(' ');
    }
    final String rootStr = root.toString();
    myBuffer.append(rootStr);
    PsiElement child = root.getFirstChild();
    if (child == null) {
        String text = root.getText();
        assert text != null : "text is null for <" + root + ">";
        text = StringUtil.replace(text, "\n", "\\n");
        text = StringUtil.replace(text, "\r", "\\r");
        text = StringUtil.replace(text, "\t", "\\t");
        myBuffer.append("('");
        myBuffer.append(text);
        myBuffer.append("')");
    }
    if (showRanges)
        myBuffer.append(root.getTextRange());
    myBuffer.append("\n");
    while (child != null) {
        psiToBuffer(child, indent + 2, showChildrenRanges, showChildrenRanges);
        child = child.getNextSibling();
    }
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 14 with PsiErrorElement

use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.

the class CodeErrorReport method createReport.

public String createReport() {
    StringBuilder builder = new StringBuilder("\n\n\n");
    builder.append("Language: ").append(myLang.getDisplayName()).append(". Setting: ").append(mySettingsType).append(". Errors found: ").append(myErrors.size()).append('\n');
    for (PsiErrorElement error : myErrors) {
        builder.append("   ").append(error.getErrorDescription()).append(". Previous sibling: ").append(error.getPrevSibling()).append('\n');
    }
    builder.append("\nCode sample:\n").append(myCode).append('\n');
    return builder.toString();
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement)

Example 15 with PsiErrorElement

use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.

the class PyListSelectionHandler method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    TextRange stringRange = e.getTextRange();
    PsiElement firstChild = e.getFirstChild().getNextSibling();
    if (firstChild instanceof PsiErrorElement) {
        return Collections.emptyList();
    }
    int startShift = 1;
    if (firstChild instanceof PsiWhiteSpace)
        startShift += firstChild.getTextLength();
    PsiElement lastChild = e.getLastChild().getPrevSibling();
    int endShift = 1;
    if (lastChild instanceof PsiWhiteSpace && lastChild != firstChild)
        endShift += lastChild.getTextLength();
    final TextRange offsetRange = new TextRange(stringRange.getStartOffset() + startShift, stringRange.getEndOffset() - endShift);
    if (offsetRange.contains(cursorOffset) && offsetRange.getLength() > 1) {
        return Collections.singletonList(offsetRange);
    }
    return Collections.emptyList();
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

PsiErrorElement (com.intellij.psi.PsiErrorElement)20 PsiElement (com.intellij.psi.PsiElement)12 XmlTag (com.intellij.psi.xml.XmlTag)4 PsiFile (com.intellij.psi.PsiFile)3 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)3 XmlToken (com.intellij.psi.xml.XmlToken)3 NotNull (org.jetbrains.annotations.NotNull)3 ASTNode (com.intellij.lang.ASTNode)2 Document (com.intellij.openapi.editor.Document)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 IElementType (com.intellij.psi.tree.IElementType)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlText (com.intellij.psi.xml.XmlText)2 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 EquivalenceDescriptorProvider (com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider)1 Language (com.intellij.lang.Language)1 Annotation (com.intellij.lang.annotation.Annotation)1 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)1 XMLLanguage (com.intellij.lang.xml.XMLLanguage)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1