public static VariableDeclaration parseField(String source) throws AstException { Source s = new Source(source, "fieldSnippet"); s.parseMember(); return process(s, "field", VariableDeclaration.class); }
private String preProcess() { preprocessed = rawInput; this.lineEndings = calculateLineEndings(); applyBackslashU(); // applyBraceMatching(); return preprocessed; }
public Source(String rawInput, String name) { this.rawInput = rawInput; this.name = name; clear(); }
public static Statement parseStatement(String source) throws AstException { Source s = new Source(source, "statementSnippet"); s.parseStatement(); return process(s, "statement", Statement.class); }
public static Expression parseExpression(String source) throws AstException { Source s = new Source(source, "expressionSnippet"); s.parseExpression(); return process(s, "expression", Expression.class); }
private void postProcess() { for (ParseError error : parsingResult.parseErrors) { int errStart = error.getStartIndex(); int errEnd = error.getEndIndex(); problems.add(new ParseProblem(new Position(mapPosition(errStart), mapPosition(errEnd)), error.toString())); } if (parsingResult.parseTreeRoot != null) { nodes.add(parsingResult.parseTreeRoot.getValue()); gatherComments(parsingResult.parseTreeRoot); } comments = Collections.unmodifiableList(comments); nodes = Collections.unmodifiableList(nodes); problems = Collections.unmodifiableList(problems); rtrimPositions(nodes, comments); //TODO Write test case with javadoc intermixed with empty declares. //TODO test javadoc on a package declaration. //TODO javadoc in between keywords. associateJavadoc(comments, nodes); fixPositions(nodes); fixPositions(comments); parsed = true; }
public String getOverviewProfileInformation() { clear(); preProcess(); ParserGroup group = new ParserGroup(this); ProfilerParseRunner<Node> runner = new ProfilerParseRunner<Node>(group.structures.compilationUnitEoi(), preprocessed); this.parsingResult = runner.run(); StringBuilder out = new StringBuilder(); out.append(runner.getOverviewReport()); postProcess(); return out.toString(); }
@Override public Node process(Source in, Void irrelevant) throws ConversionProblem { List<Node> nodes = in.getNodes(); List<ParseProblem> problems = in.getProblems(); if (problems.size() > 0) throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), problems.get(0))); if (nodes.size() == 1) return nodes.get(0); if (nodes.size() == 0) throw new ConversionProblem("No nodes parsed by lombok.ast"); throw new ConversionProblem("More than 1 node parsed by lombok.ast"); } };
public Map<Node, Collection<SourceStructure>> getSourceStructures() { if (cachedSourceStructures != null) return cachedSourceStructures; parseCompilationUnit(); ListMultimap<Node, SourceStructure> map = LinkedListMultimap.create(); org.parboiled.Node<Node> pNode = parsingResult.parseTreeRoot; buildSourceStructures(pNode, null, map); Map<Node, Collection<SourceStructure>> result = map.asMap(); for (Collection<SourceStructure> structures : result.values()) { for (SourceStructure structure : structures) { structure.setPosition(new Position( mapPosition(structure.getPosition().getStart()), mapPosition(structure.getPosition().getEnd()))); } } return cachedSourceStructures = result; }
@Override public JCCompilationUnit process(Source in, Void irrelevant) throws ConversionProblem { Context context = new Context(); Options.instance(context).put(OptionName.ENCODING, charset.name()); JavaCompiler compiler = new JavaCompiler(context); compiler.genEndPos = true; compiler.keepComments = true; JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(in.getName(), in.getRawInput())); return cu; } };
private void buildSourceStructures(org.parboiled.Node<Node> pNode, Node owner, ListMultimap<Node, SourceStructure> map) { Node target = registeredStructures.remove(pNode); if (target != null || pNode.getChildren().isEmpty()) { int start = pNode.getStartIndex(); int end = pNode.getEndIndex(); String text = preprocessed.substring(start, end); SourceStructure structure = new SourceStructure(new Position(start, end), text); if (target != null) addSourceStructure(map, target, structure); else if (pNode.getValue() != null && !(pNode.getValue() instanceof TemporaryNode)) addSourceStructure(map, pNode.getValue(), structure); else if (owner != null) addSourceStructure(map, owner, structure); } else { Node possibleOwner = pNode.getValue(); if (possibleOwner instanceof TemporaryNode) possibleOwner = null; for (org.parboiled.Node<Node> child : pNode.getChildren()) { if (child.getValue() == null || child.getValue() instanceof TemporaryNode) continue; /* If the next if holds true, then we aren't the true generator; the child generated the node and this pNode adopted it */ if (child.getValue() == possibleOwner) possibleOwner = null; } if (possibleOwner != null) owner = possibleOwner; for (org.parboiled.Node<Node> child : pNode.getChildren()) { buildSourceStructures(child, owner, map); } } }
public EcjTreeBuilder(lombok.ast.grammar.Source source, CompilerOptions options) { this(source, createDefaultProblemReporter(options), createSilentProblemReporter(options), new CompilationResult(source.getName().toCharArray(), 0, 0, 0)); }
/** * Delves through the parboiled node tree to find comments. */ private boolean gatherComments(org.parboiled.Node<Node> parsed) { boolean foundComments = false; for (org.parboiled.Node<Node> child : parsed.getChildren()) { foundComments |= gatherComments(child); } List<Comment> cmts = registeredComments.get(parsed); if (cmts != null) for (Comment c : cmts) { comments.add(c); return true; } return foundComments; }
Source source = new Source(Files.toString(in, charset), in.getCanonicalPath()); Object transfer = null; String chain = "/";
private void postProcess() { for (ParseError error : parsingResult.parseErrors) { int errStart = error.getStartIndex(); int errEnd = error.getEndIndex(); problems.add(new ParseProblem(new Position(mapPosition(errStart), mapPosition(errEnd)), error.toString())); } if (parsingResult.parseTreeRoot != null) { nodes.add(parsingResult.parseTreeRoot.getValue()); gatherComments(parsingResult.parseTreeRoot); } comments = Collections.unmodifiableList(comments); nodes = Collections.unmodifiableList(nodes); problems = Collections.unmodifiableList(problems); rtrimPositions(nodes, comments); //TODO Write test case with javadoc intermixed with empty declares. //TODO test javadoc on a package declaration. //TODO javadoc in between keywords. associateJavadoc(comments, nodes); fixPositions(nodes); fixPositions(comments); parsed = true; }
public String getOverviewProfileInformation() { clear(); preProcess(); ParserGroup group = new ParserGroup(this); ProfilerParseRunner<Node> runner = new ProfilerParseRunner<Node>(group.structures.compilationUnitEoi(), preprocessed); this.parsingResult = runner.run(); StringBuilder out = new StringBuilder(); out.append(runner.getOverviewReport()); postProcess(); return out.toString(); }
@Override public Node process(Source in, Void irrelevant) throws ConversionProblem { List<Node> nodes = in.getNodes(); List<ParseProblem> problems = in.getProblems(); if (problems.size() > 0) throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), problems.get(0))); if (nodes.size() == 1) return nodes.get(0); if (nodes.size() == 0) throw new ConversionProblem("No nodes parsed by lombok.ast"); throw new ConversionProblem("More than 1 node parsed by lombok.ast"); } };
public Map<Node, Collection<SourceStructure>> getSourceStructures() { if (cachedSourceStructures != null) return cachedSourceStructures; parseCompilationUnit(); ListMultimap<Node, SourceStructure> map = LinkedListMultimap.create(); org.parboiled.Node<Node> pNode = parsingResult.parseTreeRoot; buildSourceStructures(pNode, null, map); Map<Node, Collection<SourceStructure>> result = map.asMap(); for (Collection<SourceStructure> structures : result.values()) { for (SourceStructure structure : structures) { structure.setPosition(new Position( mapPosition(structure.getPosition().getStart()), mapPosition(structure.getPosition().getEnd()))); } } return cachedSourceStructures = result; }
@Override public JCCompilationUnit process(Source in, Void irrelevant) throws ConversionProblem { Context context = new Context(); Options.instance(context).put(OptionName.ENCODING, charset.name()); JavaCompiler compiler = new JavaCompiler(context); compiler.genEndPos = true; compiler.keepComments = true; JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(in.getName(), in.getRawInput())); return cu; } };
public static Statement parseStatement(String source) throws AstException { Source s = new Source(source, "statementSnippet"); s.parseStatement(); return process(s, "statement", Statement.class); }