Java Code Examples for com.intellij.psi.TokenType

The following examples show how to use com.intellij.psi.TokenType. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: idea-php-typo3-plugin   Source File: FluidFileHighlighter.java    License: MIT License 6 votes vote down vote up
@NotNull
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(FluidTypes.FIELD_CHAIN) || tokenType.equals(FluidTypes.IDENTIFIER) || tokenType.equals(FluidTypes.NAMESPACE)) {
        return IDENTIFIER_KEYS;
    } else if (tokenType.equals(FluidTypes.EXPR_END) || tokenType.equals(FluidTypes.EXPR_START)) {
        return BRACES_KEYS;
    } else if (tokenType.equals(FluidTypes.TEMPLATE_COMMENT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(FluidTypes.STRING_LITERAL) || tokenType.equals(FluidTypes.DOUBLE_QUOTED_STRING) || tokenType.equals(FluidTypes.SINGLE_QUOTED_STRING)) {
        return STRING_KEYS;
    } else if (tokenType.equals(FluidTypes.ARROW)) {
        return OPERATION_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 2
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(TypoScriptTypes.DOT)) {
        return SEPARATOR_KEYS;
    } else if (tokenType.equals(TypoScriptTypes.IDENTIFIER)) {
        return KEY_KEYS;
    } else if (tokenType.equals(TypoScriptTypes.VALUE)) {
        return VALUE_KEYS;
    } else if (tokenType.equals(TypoScriptTypes.COMMENT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 3
Source Project: bamboo-soy   Source File: SoyLexer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public MergeFunction getMergeFunction() {
  return ((final IElementType type, final Lexer originalLexer) -> {
    if (type == SoyTypes.OTHER || type == TokenType.WHITE_SPACE) {
      IElementType returnType =  type;
      while (originalLexer.getTokenType() == SoyTypes.OTHER
          || originalLexer.getTokenType() == TokenType.WHITE_SPACE) {
        if (originalLexer.getTokenType() == SoyTypes.OTHER) {
          returnType = SoyTypes.OTHER;
        }
        originalLexer.advance();
      }
      return returnType;
    }

    return type;
  });
}
 
Example 4
Source Project: idea-php-dotenv-plugin   Source File: DotEnvSyntaxHighlighter.java    License: MIT License 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(DotEnvTypes.SEPARATOR)) {
        return SEPARATOR_KEYS;
    } else if (tokenType.equals(DotEnvTypes.KEY_CHARS)) {
        return KEY_KEYS;
    } else if (tokenType.equals(DotEnvTypes.VALUE_CHARS)) {
        return VALUE_KEYS;
    } else if (tokenType.equals(DotEnvTypes.COMMENT) || tokenType.equals(DotEnvTypes.EXPORT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 5
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(CsvTypes.COMMA)) {
        return COMMA_KEYS;
    } else if (tokenType.equals(CsvTypes.QUOTE)) {
        return QUOTE_KEYS;
    } else if (tokenType.equals(CsvTypes.TEXT)) {
        return TEXT_KEYS;
    } else if (tokenType.equals(CsvTypes.ESCAPED_TEXT)) {
        return ESCAPED_TEXT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 6
@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 7
private static PsiElement findFurthestSiblingOfSameType(@NotNull PsiElement anchor, boolean after) {
    ASTNode node = anchor.getNode();
    final IElementType expectedType = node.getElementType();
    ASTNode lastSeen = node;
    while (node != null) {
        final IElementType elementType = node.getElementType();
        if (elementType == expectedType) {
            lastSeen = node;
        } else if (elementType == TokenType.WHITE_SPACE) {
            if (expectedType == token(LINE_COMMENT)
                    && node.getText().indexOf('\n', 1) != -1) {
                break;
            }
        } else if (!COMMENT_TOKEN_SET.contains(elementType) || COMMENT_TOKEN_SET.contains(expectedType)) {
            break;
        }
        node = after ? node.getTreeNext() : node.getTreePrev();
    }
    return lastSeen.getPsi();
}
 
Example 8
Source Project: Intellij-Dust   Source File: DustSyntaxHighlighter.java    License: MIT License 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  if (isPartOfComment(tokenType)) {
    return COMMENT_KEYS;
  } else if (tokenType.equals(DustTypes.NUMBER)) {
    return NUMBER_KEYS;
  } else if (tokenType.equals(DustTypes.IDENTIFIER)) {
    return IDENTIFIER_KEYS;
  } else if (isPartOfTag(tokenType)) {
    return TAG_KEYS;
  } else if (tokenType.equals(DustTypes.STRING) || tokenType.equals(DustTypes.STRING_START) || tokenType.equals(DustTypes.STRING_END)) {
    return STRING_KEYS;
  } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
    return BAD_CHAR_KEYS;
  } else {
    return EMPTY_KEYS;
  }
}
 
Example 9
Source Project: js-graphql-intellij-plugin   Source File: GraphQLBlock.java    License: MIT License 6 votes vote down vote up
@Override
protected List<Block> buildChildren() {
    if (blocks == null) {
        blocks = ContainerUtil.mapNotNull(myNode.getChildren(null), node -> {
            if(node.getTextLength() == 0) {
                return null;
            }
            if(node.getElementType() == TokenType.WHITE_SPACE) {
                if(node.getText().contains(",")) {
                    // non-significant comma, but not empty text according to IDEA
                    return new GraphQLBlock(node, null, null);
                }
                return null;
            }
            return new GraphQLBlock(node, null, null);
        });
    }
    return blocks;
}
 
Example 10
@Override
protected List<Block> buildChildren() {

	List<Block> blocks = new ArrayList<>();
	ASTNode child = myNode.getFirstChildNode();
	while (child != null) {
		if (!TokenType.WHITE_SPACE.equals(child.getElementType()) && !TokenType.BAD_CHARACTER.equals(child.getElementType())) {
			if (!child.getTextRange().isEmpty()) {
				JSGraphQLEndpointBlock block = new JSGraphQLEndpointBlock(this, child, null, null, spacingBuilder);
				blocks.add(block);
			}
		}
		child = child.getTreeNext();
	}

	return blocks;
}
 
Example 11
Source Project: Buck-IntelliJ-Plugin   Source File: BuckBlock.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Recursively build sub blocks
 */
private List<BuckBlock> buildSubBlocks() {
  final List<BuckBlock> blocks = new ArrayList<BuckBlock>();
  for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) {
    final IElementType childType = child.getElementType();

    if (child.getTextRange().isEmpty()) {
      continue;
    }
    if (childType == TokenType.WHITE_SPACE) {
      continue;
    }
    // In most cases, glob block doesn't need reformatting. So just ignore it for now.
    if (childType == BuckTypes.GLOB_BLOCK) {
      continue;
    }
    blocks.add(buildSubBlock(child));
  }
  return Collections.unmodifiableList(blocks);
}
 
Example 12
Source Project: consulo   Source File: FormatterUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static ASTNode getWsCandidate(@Nullable ASTNode node) {
  if (node == null) return null;
  ASTNode treePrev = node.getTreePrev();
  if (treePrev != null) {
    if (treePrev.getElementType() == TokenType.WHITE_SPACE) {
      return treePrev;
    }
    else if (treePrev.getTextLength() == 0) {
      return getWsCandidate(treePrev);
    }
    else {
      return node;
    }
  }
  final ASTNode treeParent = node.getTreeParent();

  if (treeParent == null || treeParent.getTreeParent() == null) {
    return node;
  }
  else {
    return getWsCandidate(treeParent);
  }
}
 
Example 13
Source Project: BashSupport   Source File: PrefixSuffixAddingLexerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue333() throws Exception {
    PrefixSuffixAddingLexer lexer = new PrefixSuffixAddingLexer(new BashLexer(BashVersion.Bash_v4), "\"", TokenType.WHITE_SPACE, "\"", TokenType.WHITE_SPACE);
    //Lexer lexer = new BashLexer(BashVersion.Bash_v4);
    lexer.start("\"x$a\"");

    Assert.assertEquals(TokenType.WHITE_SPACE, lexer.getTokenType());
    Assert.assertEquals("\"", lexer.getTokenText());

    lexer.advance();
    Assert.assertEquals(BashTokenTypes.WORD, lexer.getTokenType());
    Assert.assertEquals("x", lexer.getTokenText());

    lexer.advance();
    Assert.assertEquals(BashTokenTypes.VARIABLE, lexer.getTokenType());
    Assert.assertEquals("$a", lexer.getTokenText());

    lexer.advance();
    Assert.assertEquals(BashTokenTypes.WHITESPACE, lexer.getTokenType());
    Assert.assertEquals("\"", lexer.getTokenText());
}
 
Example 14
Source Project: intellij-sdk-docs   Source File: SimpleSyntaxHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  if (tokenType.equals(SimpleTypes.SEPARATOR)) {
    return SEPARATOR_KEYS;
  } else if (tokenType.equals(SimpleTypes.KEY)) {
    return KEY_KEYS;
  } else if (tokenType.equals(SimpleTypes.VALUE)) {
    return VALUE_KEYS;
  } else if (tokenType.equals(SimpleTypes.COMMENT)) {
    return COMMENT_KEYS;
  } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
    return BAD_CHAR_KEYS;
  } else {
    return EMPTY_KEYS;
  }
}
 
Example 15
Source Project: Intellij-Plugin   Source File: ConceptSyntaxHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(ConceptTokenTypes.CONCEPT_HEADING)) {
        return HighlighterTokens.SPEC_HEADING_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.STEP)) {
        return HighlighterTokens.STEP_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.COMMENT)) {
        return HighlighterTokens.COMMENT_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.TABLE_HEADER)) {
        return HighlighterTokens.TABLE_HEADER_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.TABLE_ROW_VALUE)) {
        return HighlighterTokens.TABLE_ROW_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.TABLE_BORDER)) {
        return HighlighterTokens.TABLE_BORDER_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.ARG_START) || tokenType.equals(ConceptTokenTypes.ARG) || tokenType.equals(ConceptTokenTypes.ARG_END)) {
        return HighlighterTokens.ARG_ATTRIBUTE;
    } else if (tokenType.equals(ConceptTokenTypes.DYNAMIC_ARG_START) || tokenType.equals(ConceptTokenTypes.DYNAMIC_ARG) || tokenType.equals(ConceptTokenTypes.DYNAMIC_ARG_END)) {
        return HighlighterTokens.DYNAMIC_ARG_ATTRIBUTE;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return HighlighterTokens.BAD_CHAR_KEYS;
    } else {
        return HighlighterTokens.EMPTY_KEYS;
    }
}
 
Example 16
Source Project: intellij-latte   Source File: LatteBlock.java    License: MIT License 6 votes vote down vote up
@NotNull
@Override
protected Indent getChildIndent(@NotNull ASTNode astNode) {
	if (isBellowType(astNode, LatteTypes.MACRO_CONTENT)
		&& astNode.getTreePrev() != null
		&& astNode.getTreePrev().getElementType() == TokenType.WHITE_SPACE) {
		return Indent.getNormalIndent();
	}
	if (!isPair || isOpening(astNode) || isClosing(astNode)) {
		return Indent.getNoneIndent();
	}
	if (!(astNode.getPsi() instanceof LatteMacroClassic)) {
		return Indent.getNormalIndent();
	}
	PsiElement el = astNode.getPsi();
	LatteMacroTag openTag = ((LatteMacroClassic) el).getOpenTag();
	if (openTag.matchMacroName("else") || openTag.matchMacroName("elseif") || openTag.matchMacroName("elseifset")) {
		return Indent.getNoneIndent();
	}
	return Indent.getNormalIndent();
}
 
Example 17
Source Project: intellij-haxe   Source File: HXMLSyntaxHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  if (tokenType.equals(HXMLTypes.KEY_TOKEN)) {
    return KEY_KEYS;
  }
  else if (tokenType.equals(HXMLTypes.QUALIFIEDCLASSNAME)) {
    return CLASS_NAME_KEYS;
  }
  else if (tokenType.equals(HXMLTypes.VALUE_TOKEN)) {
    return VALUE_KEYS;
  }
  else if (tokenType.equals(HXMLTypes.COMMENT)) {
    return COMMENT_KEYS;
  }
  else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
    return BAD_CHAR_KEYS;
  }
  if (tokenType.equals(HXMLTypes.HXML_FILE)) {
    return INCLUDE_KEYS;
  }
  else {
    return EMPTY_KEYS;
  }
}
 
Example 18
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  if (tokenType.equals(LombokConfigTypes.SEPARATOR) || tokenType.equals(LombokConfigTypes.SIGN)) {
    return SEPARATOR_KEYS;
  } else if (tokenType.equals(LombokConfigTypes.CLEAR)) {
    return CLEAR_KEYS;
  } else if (tokenType.equals(LombokConfigTypes.KEY)) {
    return KEY_KEYS;
  } else if (tokenType.equals(LombokConfigTypes.VALUE)) {
    return VALUE_KEYS;
  } else if (tokenType.equals(LombokConfigTypes.COMMENT)) {
    return COMMENT_KEYS;
  } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
    return BAD_CHAR_KEYS;
  } else {
    return EMPTY_KEYS;
  }
}
 
Example 19
Source Project: buck   Source File: BcfgSyntaxHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(@Nullable IElementType tokenType) {
  if (BcfgTypes.COMMENT.equals(tokenType)) {
    return COMMENT_KEYS;
  } else if (BcfgTypes.L_BRACKET.equals(tokenType)
      || BcfgTypes.R_BRACKET.equals(tokenType)
      || BcfgTypes.REQUIRED_FILE.equals(tokenType)
      || BcfgTypes.OPTIONAL_FILE.equals(tokenType)
      || BcfgTypes.END_INLINE.equals(tokenType)
      || BcfgTypes.ASSIGN.equals(tokenType)) {
    return PUNCTUATION_KEYS;
  } else if (BcfgTypes.PROPERTY_VALUE_FRAGMENT.equals(tokenType)) {
    return VALUE_KEYS;
  } else if (BcfgTypes.SECTION_NAME.equals(tokenType)) {
    return SECTION_KEYS;
  } else if (BcfgTypes.PROPERTY_NAME.equals(tokenType)) {
    return PROPERTY_KEYS;
  } else if (BcfgTypes.FILE_PATH.equals(tokenType)) {
    return FILE_PATH_KEYS;
  } else if (TokenType.BAD_CHARACTER.equals(tokenType)) {
    return BAD_CHAR_KEYS;
  } else {
    return EMPTY_KEYS;
  }
}
 
Example 20
Source Project: consulo   Source File: PsiBuilderQuickTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public IElementType getTokenType() {
  if (myIndex >= myBufferEnd) {
    return null;
  }
  else if (Character.isLetter(myBuffer.charAt(myIndex))) {
    return LETTER;
  }
  else if (Character.isDigit(myBuffer.charAt(myIndex))) {
    return DIGIT;
  }
  else if (Character.isWhitespace(myBuffer.charAt(myIndex))) {
    return TokenType.WHITE_SPACE;
  }
  else if (myBuffer.charAt(myIndex) == '#') {
    return COMMENT;
  }
  else {
    return OTHER;
  }
}
 
Example 21
Source Project: consulo   Source File: DefaultASTLeafFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public LeafElement createLeaf(@Nonnull IElementType type, @Nonnull LanguageVersion languageVersion, @Nonnull CharSequence text) {
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(type.getLanguage());
  if(parserDefinition != null) {
    if(parserDefinition.getCommentTokens(languageVersion).contains(type)) {
      return new PsiCoreCommentImpl(type, text);
    }
  }

  // this is special case, then type is WHITE_SPACE, but no parser definition
  if(type == TokenType.WHITE_SPACE) {
    return new PsiWhiteSpaceImpl(text);
  }

  if (type instanceof ILeafElementType) {
    return (LeafElement)((ILeafElementType)type).createLeafNode(text);
  }
  return new LeafPsiElement(type, text);
}
 
Example 22
Source Project: Intellij-Dust   Source File: GeneratedParserUtilBase.java    License: MIT License 5 votes vote down vote up
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 23
Source Project: reasonml-idea-plugin   Source File: ORUtil.java    License: MIT License 5 votes vote down vote up
@NotNull
public static ASTNode nextSiblingNode(@NotNull ASTNode node) {
    ASTNode nextSibling = node.getTreeNext();
    while (nextSibling.getElementType() == TokenType.WHITE_SPACE) {
        nextSibling = nextSibling.getTreeNext();
    }
    return nextSibling;
}
 
Example 24
Source Project: reasonml-idea-plugin   Source File: ORUtil.java    License: MIT License 5 votes vote down vote up
@Nullable
public static String computeAlias(@Nullable PsiElement rootElement, @NotNull Language language, boolean lowerAccepted) {
    boolean isALias = true;

    PsiElement currentElement = rootElement;
    ORTypes types = language == RmlLanguage.INSTANCE ? RmlTypes.INSTANCE : OclTypes.INSTANCE;
    StringBuilder aliasName = new StringBuilder();
    IElementType elementType = currentElement == null ? null : currentElement.getNode().getElementType();
    while (elementType != null && elementType != types.SEMI) {
        if (elementType != TokenType.WHITE_SPACE && elementType != types.C_UPPER_SYMBOL && elementType != types.DOT) {
            // if last term is lower symbol, and we accept lower symbol, then it's an alias
            if (elementType != types.C_LOWER_SYMBOL || currentElement.getNextSibling() != null || !lowerAccepted) {
                isALias = false;
                break;
            }
        }

        if (elementType != TokenType.WHITE_SPACE) {
            aliasName.append(currentElement.getText());
        }

        currentElement = currentElement.getNextSibling();
        elementType = currentElement == null ? null : currentElement.getNode().getElementType();
    }

    return isALias ? aliasName.toString() : null;
}
 
Example 25
Source Project: reasonml-idea-plugin   Source File: ORLineBreakpointType.java    License: MIT License 5 votes vote down vote up
@Override
public boolean process(@NotNull PsiElement element) {
    IElementType elementType = element.getNode().getElementType();

    if (elementType.equals(TokenType.WHITE_SPACE) || elementType.equals(m_types.SINGLE_COMMENT) || elementType.equals(m_types.MULTI_COMMENT)) {
        return true;
    }

    if (elementType.equals(m_types.LET)) {
        m_isLineBreakpointAvailable = true;
        return false;
    }

    return true;
}
 
Example 26
Source Project: intellij-csv-validator   Source File: CsvBlock.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected List<Block> buildChildren() {
    List<ASTNode> todoNodes = new ArrayList<>();
    List<Block> blocks = new ArrayList<>();
    todoNodes.add(getNode().getFirstChildNode());
    CsvBlockField currentField = null;
    while (todoNodes.size() > 0) {
        ASTNode node = todoNodes.remove(todoNodes.size() - 1);
        if (node == null) {
            continue;
        }

        IElementType elementType = node.getElementType();
        todoNodes.add(node.getTreeNext());
        if (elementType == CsvTypes.RECORD) {
            todoNodes.add(node.getFirstChildNode());
        } else if (elementType == CsvTypes.FIELD) {
            currentField = new CsvBlockField(node, myFormattingInfo);
            if (currentField.getTextLength() > 0) {
                blocks.add(currentField);
            }
        } else if (elementType == CsvTypes.COMMA || elementType == CsvTypes.CRLF) {
            blocks.add(new CsvBlockElement(node, myFormattingInfo, currentField));
        } else if (elementType != TokenType.WHITE_SPACE && node.getTextLength() > 0) {
            blocks.add(new CsvDummyBlock(node, myFormattingInfo));
        }
    }
    validateBlocks(blocks);
    return blocks;
}
 
Example 27
Source Project: intellij-csv-validator   Source File: CsvBlockField.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected List<Block> buildChildren() {
    ASTNode node = this.getNode().getFirstChildNode();
    List<Block> blocks = new ArrayList<>();
    while (node != null) {
        if (node.getElementType() != TokenType.WHITE_SPACE) {
            CsvBlockElement block = new CsvBlockElement(node, myFormattingInfo, this);
            blocks.add(block);
        }
        node = node.getTreeNext();
    }
    return blocks;
}
 
Example 28
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
    if (!super.isAvailable(project, editor, element)) {
        return false;
    }

    return !CsvIntentionHelper.getAllElements(element.getContainingFile()).stream()
            .anyMatch(psiElement -> CsvHelper.getElementType(psiElement) == TokenType.ERROR_ELEMENT);
}
 
Example 29
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
    if (!super.isAvailable(project, editor, element)) {
        return false;
    }

    return !CsvIntentionHelper.getAllElements(element.getContainingFile()).stream()
            .anyMatch(psiElement -> CsvHelper.getElementType(psiElement) == TokenType.ERROR_ELEMENT);
}
 
Example 30
Source Project: intellij-csv-validator   Source File: CsvHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static PsiElement getParentFieldElement(final PsiElement element) {
    PsiElement currentElement = element;
    IElementType elementType = CsvHelper.getElementType(currentElement);

    if (elementType == CsvTypes.COMMA || elementType == CsvTypes.CRLF) {
        currentElement = currentElement.getPrevSibling();
        elementType = CsvHelper.getElementType(currentElement);
    }

    if (elementType == CsvTypes.RECORD) {
        currentElement = currentElement.getLastChild();
        elementType = CsvHelper.getElementType(currentElement);
    }

    if (elementType == TokenType.WHITE_SPACE) {
        if (CsvHelper.getElementType(currentElement.getParent()) == CsvTypes.FIELD) {
            currentElement = currentElement.getParent();
        } else if (CsvHelper.getElementType(currentElement.getPrevSibling()) == CsvTypes.FIELD) {
            currentElement = currentElement.getPrevSibling();
        } else if (CsvHelper.getElementType(currentElement.getNextSibling()) == CsvTypes.FIELD) {
            currentElement = currentElement.getNextSibling();
        } else {
            currentElement = null;
        }
    } else {
        while (currentElement != null && elementType != CsvTypes.FIELD) {
            currentElement = currentElement.getParent();
            elementType = CsvHelper.getElementType(currentElement);
        }
    }
    return currentElement;
}