本文整理了Java中com.sonar.sslr.api.AstNode
类的一些代码示例,展示了AstNode
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AstNode
类的具体详情如下:
包路径:com.sonar.sslr.api.AstNode
类名称:AstNode
[英]the parser is in charge to construct an abstract syntax tree (AST) which is a tree representation of the abstract syntactic structure of source code. Each node of the tree is an AstNode and each node denotes a construct occurring in the source code which starts at a given Token.
[中]解析器负责构造抽象语法树(AST),它是源代码抽象语法结构的树表示。树的每个节点都是一个AstNode,每个节点表示源代码中的一个构造,该构造从给定的令牌开始。
代码示例来源:origin: org.codehaus.sonar-plugins.erlang/erlang-squid
@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));
代码示例来源:origin: org.sonarsource.flex/flex-checks
public static List
Preconditions.checkArgument(classDefNode.is(FlexGrammar.CLASS_DEF));
return classDefNode
.getFirstChild(FlexGrammar.BLOCK)
.getFirstChild(FlexGrammar.DIRECTIVES)
.getChildren(FlexGrammar.DIRECTIVE);
}
代码示例来源:origin: org.codehaus.sonar-plugins.dotnet.csharp/csharp-squid
private String extractPropertySignature(AstNode astNode) {
StringBuilder signature = new StringBuilder(astNode.getPreviousSibling().getLastToken().getValue());
signature.append("_");
AstNode delcaratiOnNode= astNode.getParent().getParent().getParent();
if (delcarationNode.is(CSharpGrammar.INDEXER_DECLARATION)) {
signature.append("Item");
} else {
signature.append(delcarationNode.getFirstChild(CSharpGrammar.MEMBER_NAME).getTokenValue());
}
signature.append(":");
signature.append(astNode.getTokenLine());
return signature.toString();
}
代码示例来源:origin: org.codehaus.sonar-plugins.dotnet.csharp/csharp-checks
private AstNode getFirstAncestor(AstNode node, AstNodeType t1, AstNodeType t2) {
AstNode result = node;
while (result != null && !result.is(t1, t2)) {
result = result.getParent();
}
return result;
}
代码示例来源:origin: org.codehaus.sonar-plugins.flex/flex-checks
public static int getNumberOfLine(AstNode functionNode) {
AstNode blockNode = functionNode.getFirstChild(FlexGrammar.FUNCTION_COMMON).getFirstChild(FlexGrammar.BLOCK);
// Is not an abstract method
if (blockNode != null) {
int firstLine = blockNode.getFirstChild(FlexPunctuator.LCURLYBRACE).getTokenLine();
int lastLine = blockNode.getFirstChild(FlexPunctuator.RCURLYBRACE).getTokenLine();
return lastLine - firstLine + 1;
}
return 0;
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks
private static boolean isNotVariableVariables(AstNode compoundNode) {
AstNode compoundParentPreviousNode = compoundNode.getParent().getPreviousAstNode();
return compoundParentPreviousNode != null && compoundParentPreviousNode.isNot(PHPGrammar.SIMPLE_INDIRECT_REFERENCE);
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.python/python-checks
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);
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks
private int getLineStartingColumn(AstNode node) {
int line = node.getTokenLine();
AstNode previousNode = node.getPreviousAstNode();
int column = node.getToken().getColumn();
while (previousNode != null && previousNode.getToken().getLine() == line) {
column = previousNode.getToken().getColumn();
previousNode = previousNode.getParent();
}
return column;
}
代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks
private boolean isFirstOnline(AstNode curlyBrace) {
Token previousToken = curlyBrace.getPreviousAstNode().getLastToken();
// In one case, clonsing parenthesis can be on the same line as the opening curly brace
if (previousToken.getType().equals(PHPPunctuator.RPARENTHESIS)) {
previousToken = curlyBrace.getPreviousAstNode().getPreviousAstNode().getLastToken();
}
return previousToken.getLine() != curlyBrace.getTokenLine();
}
代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks
/**
* Check that else, catch or finally keywords are on the same line as the previous closing curly brace.
*/
private void checkRCurlyBraceOnSameLine(FormattingStandardCheck formattingCheck, AstNode node) {
Token previsouToken = node.getPreviousAstNode().getLastToken();
String keyword = node.getFirstChild(PHPKeyword.ELSE, PHPKeyword.CATCH, PHPKeyword.FINALLY).getTokenOriginalValue();
if (previsouToken.getType().equals(PHPPunctuator.RCURLYBRACE) && previsouToken.getLine() != node.getTokenLine()) {
formattingCheck.reportIssue("Move this \"" + keyword + "\" to the same line as the previous closing curly brace.", node);
}
}
代码示例来源:origin: org.sonarsource.sslr/sslr-core
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() + "\"");
}
}
代码示例来源:origin: org.sonarsource.python/python-checks
private void addSelfField(AstNode test) {
if ("self".equals(test.getTokenValue())) {
AstNode trailer = test.getFirstDescendant(PythonGrammar.TRAILER);
if (trailer != null && trailer.getFirstChild(PythonGrammar.NAME) != null) {
Token token = trailer.getFirstChild(PythonGrammar.NAME).getToken();
if (!CheckUtils.containsValue(symbols, token.getValue())) {
symbols.add(token);
}
}
}
}
代码示例来源:origin: felipebz/sonar-plsql
@Override
public void visitNode(AstNode node) {
if (node.hasParent(PlSqlGrammar.VARIABLE_DECLARATION)) {
AstNode datatype = node.getParent().getFirstChild(PlSqlGrammar.DATATYPE);
AstNode expression = node.getLastChild();
if (expression.is(PlSqlGrammar.METHOD_CALL) && !datatype.getTokenValue().equals(expression.getTokenValue())) {
addLineIssue(getLocalizedMessage(CHECK_KEY), node.getTokenLine());
}
}
}
代码示例来源:origin: felipebz/sonar-plsql
@Override
public void visitNode(AstNode node) {
AstNode parent = node.getParent();
if (parentIsNotExpression(parent) &&
node.getNumberOfChildren() == 3) {
AstNode foundCandidate = node.getLastChild();
AstNode percentCandidate = foundCandidate.getPreviousAstNode();
if (percentCandidate.is(PlSqlPunctuator.MOD) && "FOUND".equals(foundCandidate.getTokenValue())) {
addLineIssue(getLocalizedMessage(CHECK_KEY), node.getTokenLine());
}
}
}
代码示例来源:origin: org.sonarsource.python/python-checks
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()));
}
代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks
/**
* Check there is not space between a function's name and the opening parenthesis.
*/
private void checkSpaceAfterFunctionName(FormattingStandardCheck formattingCheck, AstNode node) {
Token lParenToken = node.getFirstChild(PHPPunctuator.LPARENTHESIS).getToken();
Token funcNameToken = node.is(PHPGrammar.FUNCTION_CALL_PARAMETER_LIST) ?
node.getPreviousAstNode().getLastToken() : node.getFirstChild(PHPGrammar.IDENTIFIER).getToken();
if (getNbSpaceBetween(funcNameToken, lParenToken) != 0) {
formattingCheck.reportIssue("Remove all space between the method name \"" + funcNameToken.getOriginalValue() + "\" and the opening parenthesis.", node);
}
}
代码示例来源:origin: SonarSource/sonar-python
public static boolean isOnASingleLine(AstNode parent) {
List
if (statements.isEmpty()) {
return true;
}
return statements.get(0).getTokenLine() == statements.get(statements.size() - 1).getLastToken().getLine();
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.flex/flex-checks
private static boolean isOverridingParentFunction(AstNode attributesNode) {
if (attributesNode != null && attributesNode.is(FlexGrammar.ATTRIBUTES)) {
for (AstNode attribute : attributesNode.getChildren()) {
if (attribute.getFirstChild().is(FlexGrammar.ATTRIBUTE_EXPR)
&& attribute.getFirstChild().getNumberOfChildren() == 1
&& attribute.getFirstChild().getFirstChild(FlexGrammar.IDENTIFIER).getTokenValue().equals(FlexKeyword.OVERRIDE.getValue())) {
return true;
}
}
}
return false;
}
代码示例来源:origin: org.codehaus.sonar-plugins.flex/flex-checks
private void getCountersFromListExpression(Set
for (AstNode assignmentExpr : initialiserExpr.getChildren(FlexGrammar.ASSIGNMENT_EXPR_NO_IN)) {
AstNode exprFirstChild = assignmentExpr.getFirstChild();
if (assignmentExpr.hasDirectChildren(FlexGrammar.ASSIGNMENT_OPERATOR)) {
counters.add(Expression.exprToString(exprFirstChild));
} else if (exprFirstChild.is(FlexGrammar.UNARY_EXPR)) {
counters.add(Expression.exprToString(exprFirstChild.getLastChild()));
} else if (exprFirstChild.is(FlexGrammar.POSTFIX_EXPR)) {
counters.add(Expression.exprToString(exprFirstChild.getFirstChild()));
}
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.flex/flex-checks
public static String exprToString(AstNode expression) {
StringBuilder builder = new StringBuilder();
for (Token t : expression.getTokens()) {
builder.append(t.getValue());
}
return builder.toString();
}