public static String loadFragment(File file, Location location) { try (Stream<String> lines = new BufferedReader(new InputStreamReader(new FileInputStream(file))).lines() .skip(location.startLine() - 1) .limit(location.endLine() - location.startLine() + 1)) { return lines.collect(Collectors.joining("\n")); } catch (IOException e) { throw KEMException.criticalError("Could not read from file " + file.getAbsolutePath(), e); } }
private static boolean sourceShortEnough(Rule rule) { Location location = rule.getLocation(); return location != null && location.endLine() - location.startLine() <= 20; }
/** Marks 'node' with the start position in 'locPrefix' and the end position of the last token. Returns 'node' (which simplifies many uses of this function). */ private <T extends ASTNode> T markLoc(Location locPrefix, T node) { return markLocExplicit(Location.apply(locPrefix.startLine(), locPrefix.startColumn(), token.endLine, token.endColumn), node); }
&& rule.getLocation().startLine() == options.auditingLine) { matchedRules.add(rule);
public K gen(Rule r, K body) { if (!cover || !r.att().getOptional(Source.class).isPresent()) { return body; } K left = RewriteToTop.toLeft(body); K right = RewriteToTop.toRight(body); String file = r.att().get(Source.class).source(); if (file.startsWith(JarInfo.getKBase())) { return body; } int line = r.att().get(Location.class).startLine(); int col = r.att().get(Location.class).startColumn(); String loc = file + ":" + line + ":" + col; String id = r.att().get("UNIQUE_ID"); allRulesFile.print(id); allRulesFile.print(" "); allRulesFile.println(loc); if (r.att().contains("macro") || r.att().contains("alias")) { //handled by macro expander return body; } return KRewrite(left, KSequence(KApply(KLabel("#logToFile"), KToken(StringUtil.enquoteKString(files.resolveKompiled("coverage.txt").getAbsolutePath()), Sorts.String()), KToken(StringUtil.enquoteKString(id + '\n'), Sorts.String())), right)); }