@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { seq++; SourceFunction function = new SourceFunction("function:" + seq); function.setStartAtLine(astNode.getTokenLine()); return function; } }, FlexGrammar.FUNCTION_DEF, FlexGrammar.FUNCTION_EXPR));
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String functionKey = getFunctionKey(astNode); SourceFunction function = new SourceFunction(functionKey); function.setStartAtLine(astNode.getTokenLine()); return function; }
/** * 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; }; }
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String functionName = astNode.getFirstChild(PythonGrammar.FUNCNAME).getFirstChild().getTokenValue(); SourceFunction function = new SourceFunction(functionName + ":" + astNode.getToken().getLine()); function.setStartAtLine(astNode.getTokenLine()); return function; } }, PythonGrammar.FUNCDEF));
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { AstNode identifier = astNode.getFirstChild(EcmaScriptTokenType.IDENTIFIER, EcmaScriptGrammar.PROPERTY_NAME, Kind.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()); function.setStartAtLine(astNode.getTokenLine()); return function; } }, FUNCTION_NODES));