Class StaticJavaParserUtil
com.github.javaparser.StaticJavaParser that does not leak memory. Also see JavaParserUtil.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.github.javaparser.ParserConfiguration.LanguageLevelThe Language Level to use when parsing if a specific level isn't applied. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.github.javaparser.ast.CompilationUnitparseCompilationUnit(File file) Parses the Java code contained in theFileand returns aCompilationUnitthat represents it.static com.github.javaparser.ast.CompilationUnitparseCompilationUnit(InputStream inputStream) Parses the Java code contained in theInputStreamand returns aCompilationUnitthat represents it.static com.github.javaparser.ast.CompilationUnitparseCompilationUnit(String javaSource) Parses the Java code contained in theStringand returns aCompilationUnitthat represents it.static com.github.javaparser.ast.expr.ExpressionparseExpression(String expression) Parses theexpressionand returns anExpressionthat represents it.static com.github.javaparser.ast.expr.ExpressionparseExpression(String expression, com.github.javaparser.ParserConfiguration.LanguageLevel languageLevel) Parses theexpressionand returns anExpressionthat represents it.static com.github.javaparser.ast.StubUnitparseStubUnit(InputStream inputStream) Parses the stub file contained in theInputStreamand returns aStubUnitthat represents it.
-
Field Details
-
DEFAULT_LANGUAGE_LEVEL
public static final com.github.javaparser.ParserConfiguration.LanguageLevel DEFAULT_LANGUAGE_LEVELThe Language Level to use when parsing if a specific level isn't applied. This should be the highest version of Java that the Checker Framework can process.
-
-
Method Details
-
parseCompilationUnit
public static com.github.javaparser.ast.CompilationUnit parseCompilationUnit(InputStream inputStream) Parses the Java code contained in theInputStreamand returns aCompilationUnitthat represents it.This is like
StaticJavaParser.parse, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.- Parameters:
inputStream- the Java source code- Returns:
- CompilationUnit representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseCompilationUnit
public static com.github.javaparser.ast.CompilationUnit parseCompilationUnit(File file) throws FileNotFoundException Parses the Java code contained in theFileand returns aCompilationUnitthat represents it.This is like
StaticJavaParser.parse, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.- Parameters:
file- the Java source code- Returns:
- CompilationUnit representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errorsFileNotFoundException- if the file was not found
-
parseCompilationUnit
Parses the Java code contained in theStringand returns aCompilationUnitthat represents it.This is like
StaticJavaParser.parse, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.Unlike the other
parseCompilationUnitmethods, this one does not preprocess unicode escapes, so that the line and column of every node is a position injavaSourceitself. When JavaParser preprocesses unicode escapes, it maps each node's position back to a position in the unpreprocessed text, but that mapping is off by one character per backslash escape: after a backslash that does not start a unicode escape, JavaParser pushes the following character back onto its input but counts it twice. A caller such asInsertAjavaAnnotationsthat converts a position into an offset intojavaSourcewould compute the wrong offset.- Parameters:
javaSource- the Java source code- Returns:
- CompilationUnit representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseStubUnit
Parses the stub file contained in theInputStreamand returns aStubUnitthat represents it.This is like
StaticJavaParser.parse, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.- Parameters:
inputStream- the stub file- Returns:
- StubUnit representing the stub file
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseExpression
Parses theexpressionand returns anExpressionthat represents it.This is like
StaticJavaParser.parseExpression, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.- Parameters:
expression- the expression string- Returns:
- the parsed expression
- Throws:
com.github.javaparser.ParseProblemException- if the expression has parser errors
-
parseExpression
public static com.github.javaparser.ast.expr.Expression parseExpression(String expression, com.github.javaparser.ParserConfiguration.LanguageLevel languageLevel) Parses theexpressionand returns anExpressionthat represents it.This is like
StaticJavaParser.parseExpression, but it does not lead to memory leaks because it creates a new instance of JavaParser each time it is invoked. Re-usingStaticJavaParsercauses memory problems because it retains too much memory.- Parameters:
expression- the expression stringlanguageLevel- the language level to use when parsing the Java source- Returns:
- the parsed expression
- Throws:
com.github.javaparser.ParseProblemException- if the expression has parser errors
-