Package com.github.javaparser
Class ParseResult<T>
- java.lang.Object
-
- com.github.javaparser.ParseResult<T>
-
public class ParseResult<T> extends Object
The results given when parsing with an instance of JavaParser.
-
-
Constructor Summary
Constructors Constructor Description ParseResult(T result, List<Problem> problems, CommentsCollection commentsCollection)General constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<CommentsCollection>getCommentsCollection()ProblemgetProblem(int i)List<Problem>getProblems()Optional<T>getResult()Optional<Path>getSourcePath()voidifSuccessful(Consumer<T> consumer)Calls the consumer with the result if parsing was succesful.booleanisSuccessful()ParseResult<T>setSourcePath(Path sourcePath)Associates a source path with this parse result.StringtoString()
-
-
-
Constructor Detail
-
ParseResult
public ParseResult(T result, List<Problem> problems, CommentsCollection commentsCollection)
General constructor.- Parameters:
result- the AST, or empty if it wasn't created.problems- a list of encountered parsing problems.
-
-
Method Detail
-
isSuccessful
public boolean isSuccessful()
- Returns:
- if parsing was successful, meaning no errors of any kind were encountered.
-
ifSuccessful
public void ifSuccessful(Consumer<T> consumer)
Calls the consumer with the result if parsing was succesful.
-
setSourcePath
public ParseResult<T> setSourcePath(Path sourcePath)
Associates a source path with this parse result. Returnsthisfor chaining.Notes: - Intended for use by infrastructure (e.g.,
SourceRoot) to publish the originating file path. - Should be called immediately after parsing and not modified afterwards to avoid surprises in concurrent contexts. - The provided path is expected to be absolute.
-
getProblems
public List<Problem> getProblems()
- Returns:
- the list of encountered parsing problems. Empty when no problems were encountered.
-
getProblem
public Problem getProblem(int i)
- Returns:
- the
i'th encountered parsing problem. May throwIndexOutOfBoundsException.
-
getCommentsCollection
public Optional<CommentsCollection> getCommentsCollection()
- Returns:
- the complete collection of comments encountered while parsing.
-
getResult
public Optional<T> getResult()
- Returns:
- the AST of the parsed source code, or empty if parsing failed completely.
-
getSourcePath
public Optional<Path> getSourcePath()
- Returns:
- the absolute path to the source file this parse result originates from, or empty if no file parsing.
-
-