Java Code Examples for com.sonar.sslr.api.AstNode#getTokenValue()

The following examples show how to use com.sonar.sslr.api.AstNode#getTokenValue() . 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: AsyncMethodsCheck.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
/**
 * It is responsible for verifying whether the rule is met in the rule base.
 * In the event that the rule is not correct, create message error.
 *
 * @param astNode It is the node that stores all the rules.
 */
@Override
public void visitNode(AstNode astNode) {
    try {
        if (astNode.hasDescendant(ApexGrammarRuleKey.STATEMENT_EXPRESSION)) {
            List<AstNode> expressions = astNode.getDescendants(ApexGrammarRuleKey.STATEMENT_EXPRESSION);
            for (AstNode expression : expressions) {
                if (expression.hasDescendant(ApexGrammarRuleKey.PRIMARY_SUFFIX)
                        && expression.hasDescendant(ApexGrammarRuleKey.ARGUMENTS)) {
                    List<AstNode> arguments = expression.getDescendants(ApexGrammarRuleKey.ARGUMENTS);
                    for (AstNode argument : arguments) {
                        AstNode prefix = argument.getPreviousAstNode();
                        AstNode method = prefix.getFirstDescendant(ApexGrammarRuleKey.NAME,
                                ApexGrammarRuleKey.ALLOWED_KEYWORDS_AS_IDENTIFIER,
                                ApexGrammarRuleKey.ALLOWED_KEYWORDS_AS_IDENTIFIER_FOR_METHODS);
                        if (method != null) {
                            AstNode methodIdentifier = method.hasDescendant(ApexGrammarRuleKey.METHOD_IDENTIFIER)
                                    ? method.getLastChild(ApexGrammarRuleKey.METHOD_IDENTIFIER) : method;
                            String methodName = methodIdentifier.getTokenValue();
                            if (methodIsAsync(astNode, methodName)) {
                                String message = ChecksBundle.getStringFromBundle("AsyncMethodsCheckMessage");
                                getContext().createLineViolation(this,
                                        message, method,
                                        methodIdentifier.getTokenOriginalValue());
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        ChecksLogger.logCheckError(this.toString(), "visitNode", e.toString());
    }
}
 
Example 2
Source File: TryCatchCheck.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String getSequenceType(AstNode sequenceNode) {
  if (sequenceNode != null) {
    AstNode attributes = sequenceNode.getFirstChild(FlowGrammar.ATTRIBUTES);
    if (attributes != null) {
      AstNode exitOn = attributes.getFirstChild(FlowAttTypes.EXITON);
      if (exitOn != null) {
        return exitOn.getTokenValue();
      }
    }
  }
  return null;
}