use of com.intellij.psi.PsiErrorElement in project intellij-elixir by KronicDeth.
the class CallDefinitionHead method stripGuard.
/**
* The head without the guard clause
*
* @param head {@code name(arg, ...) when ...}
* @return {@code name(arg, ...)}. {@code head} if no guard clause.
*/
@NotNull
public static PsiElement stripGuard(@NotNull final PsiElement head) {
PsiElement stripped = head;
if (head instanceof ElixirMatchedWhenOperation) {
ElixirMatchedWhenOperation whenOperation = (ElixirMatchedWhenOperation) head;
PsiElement[] children = whenOperation.getChildren();
int operatorIndex = operatorIndex(children);
int onlyNonErrorIndex = -1;
for (int i = 0; i < operatorIndex; i++) {
if (!(children[i] instanceof PsiErrorElement)) {
if (onlyNonErrorIndex == -1) {
// first
onlyNonErrorIndex = i;
} else {
// more than one
onlyNonErrorIndex = -1;
break;
}
}
}
if (onlyNonErrorIndex != -1) {
stripped = stripGuard(children[onlyNonErrorIndex]);
}
}
return stripped;
}
use of com.intellij.psi.PsiErrorElement in project Main by SpartanRefactoring.
the class Playground method spartanizeButtonClicked.
private void spartanizeButtonClicked() {
if (inputArea.getText().trim().isEmpty()) {
return;
}
Toolbox.getInstance().playground = true;
PsiFile file = null;
final boolean[] worked = { true };
int i;
for (i = 0; worked[0] && i < before.length; i++, worked[0] = true) {
file = PsiFileFactory.getInstance(Utils.getProject()).createFileFromText(JavaLanguage.INSTANCE, before[i] + inputArea.getText() + after[i]);
file.accept(new JavaRecursiveElementVisitor() {
@Override
public void visitErrorElement(PsiErrorElement element) {
worked[0] = false;
super.visitErrorElement(element);
}
});
if (worked[0]) {
break;
}
}
if (i < before.length && file != null) {
Spartanizer.spartanizeFileOnePass(file);
outputArea.setText(fixString(file.getText(), i));
} else {
outputArea.setText(inputArea.getText());
}
Toolbox.getInstance().playground = false;
}
use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.
the class RemoveExtraClosingTagIntentionAction method doFix.
private static void doFix(@NotNull final PsiElement element) throws IncorrectOperationException {
final XmlToken endNameToken = (XmlToken) element;
final PsiElement tagElement = endNameToken.getParent();
if (!(tagElement instanceof XmlTag) && !(tagElement instanceof PsiErrorElement))
return;
if (tagElement instanceof PsiErrorElement) {
tagElement.delete();
} else {
final ASTNode astNode = tagElement.getNode();
if (astNode != null) {
final ASTNode endTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(astNode);
if (endTagStart != null) {
final Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(tagElement.getContainingFile());
if (document != null) {
document.deleteString(endTagStart.getStartOffset(), tagElement.getLastChild().getTextRange().getEndOffset());
}
}
}
}
}
use of com.intellij.psi.PsiErrorElement in project kotlin by JetBrains.
the class CheckerTestUtil method getDiagnosticsIncludingSyntaxErrors.
@NotNull
public static List<ActualDiagnostic> getDiagnosticsIncludingSyntaxErrors(@NotNull BindingContext bindingContext, @NotNull PsiElement root, boolean markDynamicCalls, @Nullable List<DeclarationDescriptor> dynamicCallDescriptors, @Nullable String platform) {
List<ActualDiagnostic> diagnostics = new ArrayList<ActualDiagnostic>();
for (Diagnostic diagnostic : bindingContext.getDiagnostics().all()) {
if (PsiTreeUtil.isAncestor(root, diagnostic.getPsiElement(), false)) {
diagnostics.add(new ActualDiagnostic(diagnostic, platform));
}
}
for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) {
diagnostics.add(new ActualDiagnostic(new SyntaxErrorDiagnostic(errorElement), platform));
}
diagnostics.addAll(getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls, dynamicCallDescriptors, platform));
return diagnostics;
}
use of com.intellij.psi.PsiErrorElement in project intellij-community by JetBrains.
the class GroovySpacingProcessorBasic method getSpacing.
public static Spacing getSpacing(GroovyBlock child1, GroovyBlock child2, FormattingContext context) {
ASTNode leftNode = child1.getNode();
ASTNode rightNode = child2.getNode();
final PsiElement left = leftNode.getPsi();
final PsiElement right = rightNode.getPsi();
IElementType leftType = leftNode.getElementType();
IElementType rightType = rightNode.getElementType();
final CommonCodeStyleSettings settings = context.getSettings();
final GroovyCodeStyleSettings groovySettings = context.getGroovySettings();
if (!(mirrorsAst(child1) && mirrorsAst(child2))) {
return NO_SPACING;
}
if (child2 instanceof ClosureBodyBlock) {
return settings.SPACE_WITHIN_BRACES ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
if (child1 instanceof ClosureBodyBlock) {
return createDependentSpacingForClosure(settings, groovySettings, (GrClosableBlock) left.getParent(), false);
}
if (leftType == GroovyDocElementTypes.GROOVY_DOC_COMMENT) {
return COMMON_SPACING_WITH_NL;
}
if (right instanceof GrTypeArgumentList) {
return NO_SPACING_WITH_NEWLINE;
}
/********** punctuation marks ************/
if (GroovyTokenTypes.mCOMMA == leftType) {
return settings.SPACE_AFTER_COMMA ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
if (GroovyTokenTypes.mCOMMA == rightType) {
return settings.SPACE_BEFORE_COMMA ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
if (GroovyTokenTypes.mSEMI == leftType) {
return settings.SPACE_AFTER_SEMICOLON ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
if (GroovyTokenTypes.mSEMI == rightType) {
return settings.SPACE_BEFORE_SEMICOLON ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
// For dots, commas etc.
if ((TokenSets.DOTS.contains(rightType)) || (GroovyTokenTypes.mCOLON.equals(rightType) && !(right.getParent() instanceof GrConditionalExpression))) {
return NO_SPACING_WITH_NEWLINE;
}
if (TokenSets.DOTS.contains(leftType)) {
return NO_SPACING_WITH_NEWLINE;
}
//todo:check it for multiple assignments
if ((GroovyElementTypes.VARIABLE_DEFINITION.equals(leftType) || GroovyElementTypes.VARIABLE_DEFINITION.equals(rightType)) && !(leftNode.getTreeNext() instanceof PsiErrorElement)) {
return Spacing.createSpacing(0, 0, 1, false, 100);
}
// For regexes
if (leftNode.getTreeParent().getElementType() == GroovyTokenTypes.mREGEX_LITERAL || leftNode.getTreeParent().getElementType() == GroovyTokenTypes.mDOLLAR_SLASH_REGEX_LITERAL) {
return NO_SPACING;
}
// For << and >> ...
if ((GroovyTokenTypes.mLT.equals(leftType) && GroovyTokenTypes.mLT.equals(rightType)) || (GroovyTokenTypes.mGT.equals(leftType) && GroovyTokenTypes.mGT.equals(rightType))) {
return NO_SPACING_WITH_NEWLINE;
}
// Unary and postfix expressions
if (SpacingTokens.PREFIXES.contains(leftType) || SpacingTokens.POSTFIXES.contains(rightType) || (SpacingTokens.PREFIXES_OPTIONAL.contains(leftType) && left.getParent() instanceof GrUnaryExpression)) {
return NO_SPACING_WITH_NEWLINE;
}
if (SpacingTokens.RANGES.contains(leftType) || SpacingTokens.RANGES.contains(rightType)) {
return NO_SPACING_WITH_NEWLINE;
}
if (GroovyDocTokenTypes.mGDOC_ASTERISKS == leftType && GroovyDocTokenTypes.mGDOC_COMMENT_DATA == rightType) {
String text = rightNode.getText();
if (!text.isEmpty() && !StringUtil.startsWithChar(text, ' ')) {
return COMMON_SPACING;
}
return NO_SPACING;
}
if (leftType == GroovyDocTokenTypes.mGDOC_TAG_VALUE_TOKEN && rightType == GroovyDocTokenTypes.mGDOC_COMMENT_DATA) {
return LAZY_SPACING;
}
if (left instanceof GrStatement && right instanceof GrStatement && left.getParent() instanceof GrStatementOwner && right.getParent() instanceof GrStatementOwner) {
return COMMON_SPACING_WITH_NL;
}
if (rightType == GroovyDocTokenTypes.mGDOC_INLINE_TAG_END || leftType == GroovyDocTokenTypes.mGDOC_INLINE_TAG_START || rightType == GroovyDocTokenTypes.mGDOC_INLINE_TAG_START || leftType == GroovyDocTokenTypes.mGDOC_INLINE_TAG_END) {
return NO_SPACING;
}
if ((leftType == GroovyDocElementTypes.GDOC_INLINED_TAG && rightType == GroovyDocTokenTypes.mGDOC_COMMENT_DATA) || (leftType == GroovyDocTokenTypes.mGDOC_COMMENT_DATA && rightType == GroovyDocElementTypes.GDOC_INLINED_TAG)) {
// Keep formatting between groovy doc text and groovy doc reference tag as is.
return NO_SPACING;
}
if (leftType == GroovyElementTypes.CLASS_TYPE_ELEMENT && rightType == GroovyTokenTypes.mTRIPLE_DOT) {
return NO_SPACING;
}
// diamonds
if (rightType == GroovyTokenTypes.mLT || rightType == GroovyTokenTypes.mGT) {
if (right.getParent() instanceof GrCodeReferenceElement) {
PsiElement p = right.getParent().getParent();
if (p instanceof GrNewExpression || p instanceof GrAnonymousClassDefinition) {
return NO_SPACING;
}
}
}
return COMMON_SPACING;
}
Aggregations