private void appendNodecontent(AstNode node) throws IOException { writer.append(node.getName()); if (node.getTokenValue() != null) { writer.append(" tokenValue=\"" + node.getTokenValue() + "\""); } if (node.hasToken()) { writer.append(" tokenLine=\"" + node.getTokenLine() + "\" tokenColumn=\"" + node.getToken().getColumn() + "\""); } }
private void checkParameters(AstNode functionDef) { for (AstNode paramIdentifier : Function.getParametersIdentifiers(functionDef)) { String paramName = paramIdentifier.getTokenValue(); AstNode field = classStack.peek().getFieldNamed(paramName); if (field != null) { addIssue(MessageFormat.format(MESSAGE, paramName, field.getToken().getLine()), paramIdentifier); } } }
/** * {@inheritDoc} */ @Override public void createLineViolation(CodeCheck check, String message, AstNode node, Object... messageParameters) { createLineViolation(check, message, node.getToken(), messageParameters); }
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String className = astNode.getFirstDescendant(ErlangGrammarImpl.moduleAttr).getFirstChild(ErlangGrammarImpl.atom).getTokenValue(); SourceClass cls = new SourceClass(className + ":" + astNode.getToken().getLine()); cls.setStartAtLine(astNode.getTokenLine()); return cls; } }, ErlangGrammarImpl.module));
private InternalSyntaxToken(AstNode astNode) { super(astNode); this.token = astNode.getToken(); this.trivias = createTrivias(token); }
private static Token extractDocstringFromSimpleStmt(@Nullable AstNode firstSimpleStmt) { if (firstSimpleStmt != null) { Token token = firstSimpleStmt.getToken(); if (token.getType().equals(PythonTokenType.STRING)) { return token; } } return null; }
/** {@inheritDoc} */ @Override public void createLineViolation(CodeCheck check, String message, AstNode node, Object... messageParameters) { createLineViolation(check, message, node.getToken(), messageParameters); }
private InternalSyntaxToken(AstNode astNode) { super(astNode); this.token = astNode.getToken(); this.trivias = createTrivias(token); }
public JavaTree(@Nullable AstNode astNode) { super( astNode == null ? NULL_NODE : astNode.getType(), astNode == null ? NULL_NODE.toString() : astNode.getType().toString(), astNode == null ? null : astNode.getToken()); this.astNode = astNode; }
private void checkBranch(List<AstNode> branches, int index) { for (int j = 0; j < index; j++) { if (CheckUtils.equalNodes(branches.get(j), branches.get(index))) { String message = String.format(MESSAGE, branches.get(j).getToken().getLine() + 1); getContext().createLineViolation(this, message, branches.get(index).getToken().getLine() + 1); return; } } }
public static InternalSyntaxToken create(AstNode astNode) { Preconditions.checkArgument(astNode.hasToken(), "has no token"); Preconditions.checkArgument(astNode.getToken() == astNode.getLastToken(), "has several tokens"); return new InternalSyntaxToken(astNode.getType(), astNode.getToken(), astNode.getFromIndex(), astNode.getToIndex()); }
private void checkParenthesis(@Nullable AstNode child, String keyword, AstNode errorNode) { if (child != null && child.getToken().getType().equals(PythonPunctuator.LPARENTHESIS) && isOnASingleLine(child)) { getContext().createLineViolation(this, "Remove the parentheses after this \"{0}\" keyword", errorNode, keyword); } }
@Override public void visitNode(AstNode astNode) { Token token = astNode.getToken(); if (token.getColumn() != 0 || token.getLine() != 1 || !OPENING_TAG.matcher(token.getOriginalValue()).matches()) { getContext().createLineViolation(this, "Remove the extra characters before the open tag.", astNode); } }
private void retrieveTypeFromDoc(AstNode varDeclaration) { Token varDecToken = varDeclaration.getToken(); for (Trivia comment : varDecToken.getTrivia()) { for (String line : comment.getToken().getValue().split("[" + LexicalConstant.LINE_TERMINATOR + "]++")) { retrieveTypeFromCommentLine(line); } } }
private void addSimpleField(AstNode test) { Token token = test.getToken(); if (test.getNumberOfChildren() == 1 && test.getFirstChild().is(PythonGrammar.ATOM) && token.getType().equals(GenericTokenType.IDENTIFIER) && !CheckUtils.containsValue(symbols, token.getValue())) { symbols.add(token); } }
private static boolean returnReturnNone(AstNode stmt) { return stmt.is(PythonGrammar.RETURN_STMT) && (stmt.getFirstChild(PythonGrammar.TESTLIST) == null || stmt.getFirstChild(PythonGrammar.TESTLIST).getToken().getValue().equals(PythonKeyword.NONE.getValue())); }
@Nullable private SyntaxToken getBrace(JavaPunctuator leftOrRightBrace) { if (is(Kind.ANNOTATION_TYPE)) { return new InternalSyntaxToken(getAstNode().getFirstChild(leftOrRightBrace).getToken()); } else if (getAstNode().is(Kind.CLASS, Kind.ENUM, Kind.INTERFACE)) { return new InternalSyntaxToken(getAstNode().getFirstChild(leftOrRightBrace).getToken()); } return new InternalSyntaxToken(getAstNode().getFirstChild(JavaLexer.CLASS_BODY, JavaLexer.INTERFACE_BODY, JavaLexer.ENUM_BODY) .getFirstChild(leftOrRightBrace).getToken()); }
private static Token getPreviousToken(AstNode node) { AstNode result = node.getPreviousAstNode(); while (result != null && !result.hasToken()) { while (result != null && !result.hasToken()) { result = result.getPreviousAstNode(); } while (result != null && result.getLastChild() != null) { result = result.getLastChild(); } } return result == null ? null : result.getToken(); }
@Override public void visitNode(AstNode node) { AstNode suite = node.getLastChild(PythonGrammar.SUITE); if (suite.getPreviousSibling().getPreviousSibling().is(PythonKeyword.ELSE)) { return; } AstNode singleIfChild = singleIfChild(suite); if (singleIfChild != null && !hasElseOrElif(singleIfChild)) { addIssue(singleIfChild.getToken(), MESSAGE) .secondary(node.getFirstChild(), "enclosing"); } }