/* Files */
builder.setFilesMetric(EcmaScriptMetric.FILES);
/* Classes */
builder.withSquidAstVisitor(new SourceCodeBuilderVisitor<LexerlessGrammar>(new SourceCodeBuilderCallback() {
private int seq = 0;
@Override
public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) {
seq++;
SourceClass cls = new SourceClass("class:" + seq);
cls.setStartAtLine(astNode.getTokenLine());
return cls;
}
}, EcmaScriptGrammar.CLASS_DECLARATION));
builder.withSquidAstVisitor(CounterVisitor.<LexerlessGrammar>builder().setMetricDef(EcmaScriptMetric.CLASSES)
.subscribeTo(EcmaScriptGrammar.CLASS_DECLARATION)
.build());
/* Functions */
builder.withSquidAstVisitor(CounterVisitor.<LexerlessGrammar> builder()
.setMetricDef(EcmaScriptMetric.FUNCTIONS)
.subscribeTo(FUNCTION_NODES)
.build());
builder.withSquidAstVisitor(new SourceCodeBuilderVisitor<LexerlessGrammar>(new SourceCodeBuilderCallback() {
public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) {
AstNode identifier = astNode.getFirstChild(EcmaScriptTokenType.IDENTIFIER, EcmaScriptGrammar.PROPERTY_NAME, EcmaScriptGrammar.BINDING_IDENTIFIER);
final String functionName = identifier == null ? "anonymous" : identifier.getTokenValue();
final String fileKey = parentSourceCode.isType(SourceFile.class) ? parentSourceCode.getKey() : parentSourceCode.getParent(SourceFile.class).getKey();
SourceFunction function = new SourceFunction(fileKey + ":" + functionName + ":" + astNode.getToken().getLine() + ":" + astNode.getToken().getColumn());