本文整理汇总了Java中com.sonar.sslr.api.AstNodeType类的典型用法代码示例。如果您正苦于以下问题:Java AstNodeType类的具体用法?Java AstNodeType怎么用?Java AstNodeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AstNodeType类属于com.sonar.sslr.api包,在下文中一共展示了AstNodeType类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMetrics
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
/**
* Sets the default apex metrics in {@link AstScanner}.
*
* @param config apex configuration.
* @param builder scanner builder.
*/
private static void setMetrics(ApexConfiguration config, AstScanner.Builder<Grammar> builder) {
builder.withSquidAstVisitor(new LinesVisitor<>(ApexMetric.LINES));
builder.withSquidAstVisitor(new LinesOfCodeVisitor<>(ApexMetric.LINES_OF_CODE));
AstNodeType[] complexityAstNodeType = new AstNodeType[]{
METHOD_DECLARATION,
WHILE_STATEMENT,
FOR_STATEMENT,
IF_STATEMENT,
RETURN_STATEMENT
};
builder.withSquidAstVisitor(ComplexityVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.COMPLEXITY)
.subscribeTo(complexityAstNodeType)
.build());
builder.withSquidAstVisitor(CommentsVisitor.<Grammar>builder()
.withCommentMetric(ApexMetric.COMMENT_LINES)
.withNoSonar(Boolean.TRUE)
.withIgnoreHeaderComment(config.getIgnoreHeaderComments())
.build());
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.STATEMENTS)
.subscribeTo(STATEMENT)
.build());
}
示例2: setMetrics
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
private static void setMetrics(FlowConfiguration conf, AstScanner.Builder<Grammar> builder) {
builder.withMetrics(FlowMetric.values());
builder.setFilesMetric(FlowMetric.FILES);
builder.withSquidAstVisitor(new LinesVisitor<Grammar>(FlowMetric.LINES));
builder.withSquidAstVisitor(new FlowLinesOfCodeVisitor<Grammar>(FlowMetric.LINES_OF_CODE));
builder.withSquidAstVisitor(new DependencyVisitor<Grammar>());
AstNodeType[] complexityAstNodeType = new AstNodeType[]{
FlowGrammar.LOOP,
FlowGrammar.BRANCH,
FlowGrammar.SEQUENCE,
FlowGrammar.RETRY
};
builder.withSquidAstVisitor(ComplexityVisitor.<Grammar>builder()
.setMetricDef(FlowMetric.COMPLEXITY)
.subscribeTo(complexityAstNodeType)
.build());
builder.withSquidAstVisitor(CommentsVisitor.<Grammar>builder().withCommentMetric(FlowMetric.COMMENT_LINES)
.withNoSonar(true)
.build());
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(FlowMetric.MAPS)
.subscribeTo(FlowGrammar.MAP)
.build());
}
示例3: buildCallback
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
/**
* Builds and returns a source code builder callback.
*
* @param nodeName node type to identify a name.
* @param isClass define a SourceClass or SourceFunction.
* @return the builder callback.
*/
private static SourceCodeBuilderCallback buildCallback(AstNodeType nodeName, boolean isClass) {
return (SourceCode sourceCode, AstNode astNode) -> {
String key = generateKey(astNode, nodeName);
sourceCode = isClass ? new SourceClass(key) : new SourceFunction(key);
sourceCode.setStartAtLine(astNode.getTokenLine());
return sourceCode;
};
}
示例4: init
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
@Override
public void init() {
subscribeTo(BLOCK_TYPES.toArray(new AstNodeType[BLOCK_TYPES.size()]));
}
示例5: registerHardcodedVariables
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
/**
* Given the list of hard-coded values, analyzes them if they match with the
* SFDC ID regular expression and if this value belongs to an ID type
* variable if so then registers this node into a list of hard-coded
* variables detected.
*
* @param variableInitializers list of hard-coded values found.
* @param variableDeclarationType the node type of variable declarations,
* according the situation defines what nodes to look for
* @param variableValueNodeType the node type of variable values, according
* the situation defines what nodes to look for
* @param classOrInterfaceBodyNode a superior node where some nodes are
* visited from.
*/
void registerHardcodedVariables(AstSelect variableInitializers, AstNodeType variableDeclarationType,
AstNodeType variableValueNodeType, AstNode classOrInterfaceBodyNode) {
for (AstNode current : variableInitializers) {
String variableName = current.getParent()
.getFirstDescendant(variableValueNodeType).getTokenOriginalValue();
if (current.getTokenOriginalValue().matches(ID_PATTERN)
&& isIdTypeVariable(variableName, classOrInterfaceBodyNode
.getDescendants(variableDeclarationType))) {
hardcodedVariables.put(variableName, current.getParent());
}
}
}
示例6: generateKey
import com.sonar.sslr.api.AstNodeType; //导入依赖的package包/类
/**
* Generates and returns the unique key for a node.
*
* @param node node type to identify a name
* @param nodeName current node to be analyzed.
* @return the key.
*/
private static String generateKey(AstNode node, AstNodeType nodeName) {
String name = node.getFirstDescendant(nodeName).getTokenValue();
int line = node.getToken().getLine();
return String.format(KEY_PATTERN, name, line);
}