public void scanFile(PerlVisitorContext context) { this.context = context; AstNode tree = context.rootTree(); if (tree != null) { visitFile(tree); scanNode(tree, subscribedKinds()); leaveFile(tree); } }
@Override public String getName() { return name(); }
public void scanNode(AstNode node) { scanNode(node, subscribedKinds()); }
public static PerlVisitorContext createContext(File file) { Parser<Grammar> parser = PerlParser.create(new PerlConfiguration(StandardCharsets.UTF_8)); TestPerlFile perlFile = new TestPerlFile(file); AstNode rootTree = parser.parse(perlFile.content()); return new PerlVisitorContext(rootTree, perlFile); }
private void highlight(Token token, TypeOfText typeOfText) { TokenLocation tokenLocation = new TokenLocation(token); newHighlighting.highlight(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), typeOfText); }
@Test public void test_one_line() { TokenLocation tokenLocation = new TokenLocation(lex("foo").get(0)); assertOffsets(tokenLocation, 1, 0, 1, 3); }
public static void scanFile(File file, PerlVisitor... visitors) { PerlVisitorContext context = createContext(file); for (PerlVisitor visitor : visitors) { visitor.scanFile(context); } }
@Override public void visitNode(AstNode node) { atomValues.add(node.getTokenValue()); fileName = getContext().perlFile().fileName(); }
@Test public void should_execute_on_simple_project() { String relativePath = "basic/lib/Sample/Project.pm"; inputFile(relativePath); createSensor().execute(context); String key = "moduleKey:" + relativePath; assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(15); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(26); assertThat(context.measure(key, CoreMetrics.CLASSES).value()).isEqualTo(1); assertThat(context.measure(key, CoreMetrics.FUNCTIONS).value()).isEqualTo(3); }
/** * Allows to know if the given file name has a valid suffix. * * @param fileName * String representing the file name * @return boolean <code>true</code> if the file name's suffix is known, * <code>false</code> any other way */ public boolean hasValidSuffixes(String fileName) { String pathLowerCase = fileName.toLowerCase(); for (String suffix : getFileSuffixes()) { if (pathLowerCase.endsWith("." + suffix.toLowerCase())) { return true; } } return false; }
private List extensions(SonarRuntime runtime) { Plugin.Context context = new Plugin.Context(runtime); new PerlPlugin().define(context); return context.getExtensions(); } }
public static PerlFile create(InputFile inputFile) { return new Sq62File(inputFile); }
private GlobalSensor createSensor() { return new GlobalSensor(); }
public void scanFiles() { for (InputFile pythonFile : inputFiles) { if (context.isCancelled()) { return; } scanFile(pythonFile); } }
@Override public String[] getFileSuffixes() { String[] suffixes = filterEmptyStrings(config.getStringArray(PerlPlugin.FILE_SUFFIXES_KEY)); if (suffixes.length == 0) { suffixes = PerlPlugin.DEFAULT_FILE_SUFFIXES.split(",\\s*"); } return suffixes; }
public static PerlVisitorContext createContext(File file) { Parser<Grammar> parser = PerlParser.create(new PerlConfiguration(StandardCharsets.UTF_8)); TestPerlFile pythonFile = new TestPerlFile(file); AstNode rootTree = parser.parse(pythonFile.content()); return new PerlVisitorContext(rootTree, pythonFile); }
@Test public void test_newline_token() { TokenLocation tokenLocation = new TokenLocation(lex("foo\n").get(1)); assertOffsets(tokenLocation, 1, 3, 2, 0); }
public static void scanFile(File file, PerlVisitor... visitors) { PerlVisitorContext context = createContext(file); for (PerlVisitor visitor : visitors) { visitor.scanFile(context); } }
@Test public void test_comment() { TokenLocation commentLocation = new TokenLocation(lex("#comment\n").get(0).getTrivia().get(0).getToken()); assertOffsets(commentLocation, 1, 0, 1, 8); }