Search in sources :

Example 6 with PsiErrorElement

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

the class GrMethodCallFixer method apply.

@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
    final GrArgumentList argList = psiElement instanceof GrCall ? ((GrCall) psiElement).getArgumentList() : null;
    if (argList == null || argList instanceof GrCommandArgumentList)
        return;
    GrCall call = (GrCall) psiElement;
    PsiElement parenth = argList.getLastChild();
    if (parenth != null && ")".equals(parenth.getText()) || PsiImplUtil.hasClosureArguments(call))
        return;
    int endOffset = -1;
    for (PsiElement child = argList.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (!(child instanceof PsiErrorElement))
            continue;
        final PsiErrorElement errorElement = (PsiErrorElement) child;
        if (errorElement.getErrorDescription().contains("')'")) {
            endOffset = errorElement.getTextRange().getStartOffset();
            break;
        }
    }
    if (endOffset == -1) {
        endOffset = argList.getTextRange().getEndOffset();
    }
    final GrExpression[] params = argList.getExpressionArguments();
    if (params.length > 0 && GrForBodyFixer.startLine(editor.getDocument(), argList) != GrForBodyFixer.startLine(editor.getDocument(), params[0])) {
        endOffset = argList.getTextRange().getStartOffset() + 1;
    }
    endOffset = CharArrayUtil.shiftBackward(editor.getDocument().getCharsSequence(), endOffset - 1, " \t\n") + 1;
    editor.getDocument().insertString(endOffset, ")");
}
Also used : GrCommandArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList) PsiErrorElement(com.intellij.psi.PsiErrorElement) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiErrorElement

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

the class XmlCharFilter method isWithinTag.

public static boolean isWithinTag(Lookup lookup) {
    if (isInXmlContext(lookup)) {
        PsiElement psiElement = lookup.getPsiElement();
        final PsiElement parentElement = psiElement != null ? psiElement.getParent() : null;
        if (parentElement instanceof XmlTag)
            return true;
        if (parentElement instanceof PsiErrorElement && parentElement.getParent() instanceof XmlDocument)
            return true;
        return (parentElement instanceof XmlDocument || parentElement instanceof XmlText) && (psiElement.textMatches("<") || psiElement.textMatches("\""));
    }
    return false;
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlText(com.intellij.psi.xml.XmlText) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with PsiErrorElement

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

the class DuplocatorUtil method isIgnoredNode.

public static boolean isIgnoredNode(PsiElement element) {
    if (element instanceof PsiWhiteSpace || element instanceof PsiErrorElement || element instanceof PsiComment) {
        return true;
    }
    if (!(element instanceof LeafElement)) {
        return false;
    }
    if (CharArrayUtil.containsOnlyWhiteSpaces(element.getText())) {
        return true;
    }
    EquivalenceDescriptorProvider descriptorProvider = EquivalenceDescriptorProvider.getInstance(element);
    if (descriptorProvider == null) {
        return false;
    }
    final IElementType elementType = ((LeafElement) element).getElementType();
    return descriptorProvider.getIgnoredTokens().contains(elementType);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiErrorElement(com.intellij.psi.PsiErrorElement) PsiComment(com.intellij.psi.PsiComment) EquivalenceDescriptorProvider(com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 9 with PsiErrorElement

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

the class ASTShallowComparator method hashCodesEqual.

@Override
public boolean hashCodesEqual(@NotNull final ASTNode n1, @NotNull final ASTNode n2) {
    if (n1 instanceof LeafElement && n2 instanceof LeafElement) {
        return textMatches(n1, n2) == ThreeState.YES;
    }
    if (n1 instanceof PsiErrorElement && n2 instanceof PsiErrorElement) {
        final PsiErrorElement e1 = (PsiErrorElement) n1;
        final PsiErrorElement e2 = (PsiErrorElement) n2;
        if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription()))
            return false;
    }
    return ((TreeElement) n1).hc() == ((TreeElement) n2).hc();
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement)

Example 10 with PsiErrorElement

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

the class AngularJSErrorFilter method shouldHighlightErrorElement.

@Override
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
    final Project project = error.getProject();
    final Language language = error.getLanguage();
    if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null && AngularIndexUtil.hasAngularJS(project)) {
        final PsiFile file = error.getContainingFile();
        PsiErrorElement nextError = error;
        while (nextError != null) {
            if (hasAngularInjectionAt(project, file, nextError.getTextOffset()))
                return false;
            nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
        }
    }
    if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
        final PsiElement parent = error.getParent();
        final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
        return !(descriptor instanceof AngularJSTagDescriptor);
    }
    if (XMLLanguage.INSTANCE.is(language) && error.getErrorDescription().equals(XmlErrorMessages.message("xml.parsing.unexpected.tokens"))) {
        return !error.getParent().getLanguage().is(Angular2HTMLLanguage.INSTANCE);
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Language(com.intellij.lang.Language) Angular2HTMLLanguage(org.angularjs.html.Angular2HTMLLanguage) XMLLanguage(com.intellij.lang.xml.XMLLanguage) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) PsiFile(com.intellij.psi.PsiFile) AngularJSTagDescriptor(org.angularjs.codeInsight.tags.AngularJSTagDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

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