Java Code Examples for com.intellij.psi.TokenType#ERROR_ELEMENT
The following examples show how to use
com.intellij.psi.TokenType#ERROR_ELEMENT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CsvValidationInspection.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if (element == null || !holder.getFile().getLanguage().isKindOf(CsvLanguage.INSTANCE)) { return; } IElementType elementType = CsvHelper.getElementType(element); PsiElement firstChild = element.getFirstChild(); PsiElement nextSibling = element.getNextSibling(); if (elementType == TokenType.ERROR_ELEMENT && firstChild != null && element.getText().equals(firstChild.getText())) { CsvValidationInspection.this.registerError(holder, element, UNESCAPED_SEQUENCE, fixUnescapedSequence); if (!"\"".equals(firstChild.getText())) { CsvValidationInspection.this.registerError(holder, element, SEPARATOR_MISSING, fixSeparatorMissing); } } else if ((elementType == CsvTypes.TEXT || elementType == CsvTypes.ESCAPED_TEXT) && CsvHelper.getElementType(nextSibling) == TokenType.ERROR_ELEMENT && nextSibling.getFirstChild() == null) { CsvValidationInspection.this.registerError(holder, element, CLOSING_QUOTE_MISSING, fixClosingQuoteMissing); } } }; }
Example 2
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean hashCodesEqual(@Nonnull final ASTNode n1, @Nonnull final LighterASTNode n2) { if (n1 instanceof LeafElement && n2 instanceof Token) { boolean isForeign1 = n1 instanceof ForeignLeafPsiElement; boolean isForeign2 = n2.getTokenType() instanceof ForeignLeafType; if (isForeign1 != isForeign2) return false; if (isForeign1) { return StringUtil.equals(n1.getText(), ((ForeignLeafType)n2.getTokenType()).getValue()); } return ((LeafElement)n1).textMatches(((Token)n2).getText()); } if (n1 instanceof PsiErrorElement && n2.getTokenType() == TokenType.ERROR_ELEMENT) { final PsiErrorElement e1 = (PsiErrorElement)n1; if (!Comparing.equal(e1.getErrorDescription(), getErrorMessage(n2))) return false; } return ((TreeElement)n1).hc() == ((Node)n2).hc(); }
Example 3
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static CompositeElement createComposite(@Nonnull StartMarker marker) { final IElementType type = marker.myType; if (type == TokenType.ERROR_ELEMENT) { String message = marker.myDoneMarker instanceof DoneWithErrorMarker ? ((DoneWithErrorMarker)marker.myDoneMarker).myMessage : null; return Factory.createErrorElement(message); } if (type == null) { throw new RuntimeException(UNBALANCED_MESSAGE); } return ASTFactory.composite(type); }
Example 4
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static String getErrorMessage(@Nonnull LighterASTNode node) { if (node instanceof ErrorItem) return ((ErrorItem)node).myMessage; if (node instanceof StartMarker) { final StartMarker marker = (StartMarker)node; if (marker.myType == TokenType.ERROR_ELEMENT && marker.myDoneMarker instanceof DoneWithErrorMarker) { return ((DoneWithErrorMarker)marker.myDoneMarker).myMessage; } } return null; }
Example 5
Source File: FormatterUtil.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isIncomplete(@Nullable ASTNode node) { ASTNode lastChild = node == null ? null : node.getLastChildNode(); while (lastChild != null && lastChild.getElementType() == TokenType.WHITE_SPACE) { lastChild = lastChild.getTreePrev(); } if (lastChild == null) return false; if (lastChild.getElementType() == TokenType.ERROR_ELEMENT) return true; return isIncomplete(lastChild); }
Example 6
Source File: GeneratedParserUtilBase.java From Intellij-Dust with MIT License | 5 votes |
public static boolean invalid_left_marker_guard_(PsiBuilder builder_, PsiBuilder.Marker marker_, String funcName_) { //builder_.error("Invalid left marker encountered in " + funcName_ +" at offset " + builder_.getCurrentOffset()); boolean goodMarker = marker_ != null && ((LighterASTNode)marker_).getTokenType() != TokenType.ERROR_ELEMENT; if (!goodMarker) return false; ErrorState state = ErrorState.get(builder_); Frame frame = state.levelCheck.isEmpty() ? null : state.levelCheck.getLast(); return frame == null || frame.errorReportedAt <= builder_.getCurrentOffset(); }
Example 7
Source File: MacroInsertHandler.java From intellij-latte with MIT License | 4 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { PsiElement element = context.getFile().findElementAt(context.getStartOffset()); if (element != null && element.getLanguage() == LatteLanguage.INSTANCE) { PsiElement parent = element.getParent(); String spacesBefore = ""; boolean resolvePairMacro = false; boolean lastError = parent.getLastChild().getNode().getElementType() == TokenType.ERROR_ELEMENT; String macroName = null; LatteTagSettings macro = null; if (lastError && element.getNode().getElementType() == LatteTypes.T_MACRO_NAME) { macroName = element.getText(); macro = LatteConfiguration.getInstance(element.getProject()).getTag(macroName); } else if (parent instanceof LatteMacroTag) { macroName = ((LatteMacroTag) parent).getMacroName(); macro = LatteConfiguration.getInstance(element.getProject()).getTag(macroName); } boolean isCloseTag = parent instanceof LatteMacroCloseTag; if (!isCloseTag && macro != null && macro.getType() == LatteTagSettings.Type.PAIR) { resolvePairMacro = true; } if (macroName != null) { if (resolvePairMacro && macro.isMultiLine()) { spacesBefore += LatteUtil.getSpacesBeforeCaret(context.getEditor()); } Editor editor = context.getEditor(); CaretModel caretModel = editor.getCaretModel(); String text = editor.getDocument().getText(); int spaceInserted = 0; int offset = caretModel.getOffset(); if (macro != null && !isCloseTag && macro.hasParameters() && !LatteUtil.isStringAtCaret(editor, " ")) { EditorModificationUtil.insertStringAtCaret(editor, " "); spaceInserted = 1; } int lastBraceOffset = text.indexOf("}", offset); int endOfLineOffset = text.indexOf("\n", offset); if (endOfLineOffset == -1) { endOfLineOffset = text.length(); } if (lastBraceOffset == -1 || lastBraceOffset > endOfLineOffset) { caretModel.moveToOffset(endOfLineOffset + spaceInserted); EditorModificationUtil.insertStringAtCaret(editor, "}"); lastBraceOffset = endOfLineOffset; endOfLineOffset++; } if (resolvePairMacro) { String endTag = ""; if (macro.isMultiLine()) { endTag += "\n\n" + spacesBefore; } endTag += "{/" + macroName + "}"; int endTagOffset = text.indexOf(endTag, offset); if (endTagOffset == -1 || endTagOffset > endOfLineOffset) { caretModel.moveToOffset(lastBraceOffset + spaceInserted + 1); EditorModificationUtil.insertStringAtCaret(editor, endTag); } } caretModel.moveToOffset(offset + 1); PsiDocumentManager.getInstance(context.getProject()).commitDocument(editor.getDocument()); } } }
Example 8
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void error(String message) { myType = TokenType.ERROR_ELEMENT; myBuilder.error(this, message); }
Example 9
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void errorBefore(final String message, @Nonnull final Marker before) { myType = TokenType.ERROR_ELEMENT; myBuilder.errorBefore(this, message, before); }
Example 10
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public IElementType getTokenType() { return TokenType.ERROR_ELEMENT; }
Example 11
Source File: PsiBuilderImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public ThreeState deepEqual(@Nonnull final ASTNode oldNode, @Nonnull final LighterASTNode newNode) { ProgressIndicatorProvider.checkCanceled(); boolean oldIsErrorElement = oldNode instanceof PsiErrorElement; boolean newIsErrorElement = newNode.getTokenType() == TokenType.ERROR_ELEMENT; if (oldIsErrorElement != newIsErrorElement) return ThreeState.NO; if (oldIsErrorElement) { final PsiErrorElement e1 = (PsiErrorElement)oldNode; return Comparing.equal(e1.getErrorDescription(), getErrorMessage(newNode)) ? ThreeState.UNSURE : ThreeState.NO; } if (custom != null) { ThreeState customResult = custom.fun(oldNode, newNode, myTreeStructure); if (customResult != ThreeState.UNSURE) { return customResult; } } if (newNode instanceof Token) { final IElementType type = newNode.getTokenType(); final Token token = (Token)newNode; if (oldNode instanceof ForeignLeafPsiElement) { return type instanceof ForeignLeafType && StringUtil.equals(((ForeignLeafType)type).getValue(), oldNode.getText()) ? ThreeState.YES : ThreeState.NO; } if (oldNode instanceof LeafElement) { if (type instanceof ForeignLeafType) return ThreeState.NO; return ((LeafElement)oldNode).textMatches(token.getText()) ? ThreeState.YES : ThreeState.NO; } if (type instanceof ILightLazyParseableElementType) { return ((TreeElement)oldNode).textMatches(token.getText()) ? ThreeState.YES : TreeUtil.isCollapsedChameleon(oldNode) ? ThreeState.NO // do not dive into collapsed nodes : ThreeState.UNSURE; } if (oldNode.getElementType() instanceof ILazyParseableElementType && type instanceof ILazyParseableElementType || oldNode.getElementType() instanceof ICustomParsingType && type instanceof ICustomParsingType) { return ((TreeElement)oldNode).textMatches(token.getText()) ? ThreeState.YES : ThreeState.NO; } } return ThreeState.UNSURE; }
Example 12
Source File: FormatterUtil.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isWhitespaceOrEmpty(@Nullable ASTNode node) { if (node == null) return false; IElementType type = node.getElementType(); return type == TokenType.WHITE_SPACE || (type != TokenType.ERROR_ELEMENT && node.getTextLength() == 0); }