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