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, ")");
}
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;
}
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);
}
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();
}
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;
}
Aggregations