Skip to content

Commit

Permalink
Invoke JavaParser.clearInstances after AST creation
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierpinho committed Apr 25, 2024
1 parent f4b534e commit b564995
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class JavaSrc2Cpg extends X2CpgFrontend[Config] {
val astCreationPass = new AstCreationPass(config, cpg)
astCreationPass.createAndApply()
astCreationPass.sourceParser.cleanupDelombokOutput()
astCreationPass.clearJavaParserCaches()
new ConfigFileCreationPass(cpg).createAndApply()
if (!config.skipTypeInfPass) {
TypeNodePass.withRegisteredTypes(astCreationPass.global.usedTypes.keys().asScala.toList, cpg).createAndApply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.javaparser.ParserConfiguration.LanguageLevel
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node.Parsedness
import com.github.javaparser.symbolsolver.JavaSymbolSolver
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade
import com.github.javaparser.symbolsolver.resolution.typesolvers.{
ClassLoaderTypeSolver,
JarTypeSolver,
Expand Down Expand Up @@ -58,6 +59,13 @@ class AstCreationPass(config: Config, cpg: Cpg, sourcesOverride: Option[List[Str
}
}

/** Clear JavaParser caches. Should only be invoked after we no longer need JavaParser, e.g. as soon as we've built
* the AST layer for all files.
*/
def clearJavaParserCaches(): Unit = {
JavaParserFacade.clearInstances()
}

private def initParserAndUtils(config: Config): (SourceParser, JavaSymbolSolver) = {
val dependencies = getDependencyList(config.inputPath)
val sourceParser = SourceParser(config, sourcesOverride)
Expand Down

0 comments on commit b564995

Please sign in to comment.