|
30 | 30 | import java.util.TreeSet; |
31 | 31 | import java.util.function.Function; |
32 | 32 | import java.util.regex.Pattern; |
33 | | -import javassist.ClassPool; |
34 | 33 |
|
35 | 34 | import com.github.javaparser.JavaParser; |
36 | 35 | import com.github.javaparser.ParseResult; |
37 | | -import com.github.javaparser.ParserConfiguration; |
38 | | -import com.github.javaparser.ParserConfiguration.LanguageLevel; |
39 | 36 | import com.github.javaparser.ast.CompilationUnit; |
40 | 37 | import com.github.javaparser.ast.ImportDeclaration; |
41 | 38 | import com.github.javaparser.ast.Node; |
|
56 | 53 | import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; |
57 | 54 | import com.github.javaparser.resolution.types.ResolvedType; |
58 | 55 | import com.github.javaparser.symbolsolver.JavaSymbolSolver; |
59 | | -import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; |
60 | | -import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; |
61 | | -import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; |
62 | | -import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; |
63 | 56 |
|
64 | 57 | import com.diffplug.spotless.FormatterFunc; |
65 | 58 | import com.diffplug.spotless.LineEnding; |
|
68 | 61 | public class ExpandWildcardsFormatterFunc implements FormatterFunc.NeedsFile { |
69 | 62 |
|
70 | 63 | private final JavaParser parser; |
71 | | - static { |
72 | | - // If ClassPool is allowed to cache class files, it does not free the file-lock |
73 | | - ClassPool.cacheOpenedJarFile = false; |
74 | | - } |
75 | 64 |
|
76 | 65 | public ExpandWildcardsFormatterFunc(Collection<File> typeSolverClasspath) throws IOException { |
77 | | - // JavaParser defaults to Java 11 and rejects newer syntax such as records; align with JavaParserTypeSolver's default. |
78 | | - this.parser = new JavaParser(new ParserConfiguration().setLanguageLevel(LanguageLevel.BLEEDING_EDGE)); |
79 | | - |
80 | | - CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(); |
81 | | - combinedTypeSolver.add(new ReflectionTypeSolver(ReflectionTypeSolver.JCL_ONLY)); |
82 | | - for (File element : typeSolverClasspath) { |
83 | | - if (element.isFile() && element.getName().endsWith(".jar")) { |
84 | | - combinedTypeSolver.add(new JarTypeSolver(element)); |
85 | | - } else if (element.isDirectory()) { |
86 | | - combinedTypeSolver.add(new JavaParserTypeSolver(element)); |
87 | | - } // gracefully ignore non-existing src-directories |
88 | | - } |
89 | | - |
90 | | - SymbolResolver symbolSolver = new JavaSymbolSolver(combinedTypeSolver); |
| 66 | + this.parser = SymbolResolution.parser(); |
| 67 | + SymbolResolver symbolSolver = new JavaSymbolSolver(SymbolResolution.typeSolver(typeSolverClasspath)); |
91 | 68 | parser.getParserConfiguration().setSymbolResolver(symbolSolver); |
92 | 69 | } |
93 | 70 |
|
|
0 commit comments