equal
deleted
inserted
replaced
172 private DocTreeMaker docTreeMaker; |
172 private DocTreeMaker docTreeMaker; |
173 private BreakIterator breakIterator; |
173 private BreakIterator breakIterator; |
174 private JavaFileManager fileManager; |
174 private JavaFileManager fileManager; |
175 private ParserFactory parser; |
175 private ParserFactory parser; |
176 private Symtab syms; |
176 private Symtab syms; |
177 private Map<JavaFileObject, PackageSymbol> javaFileObjectToPackageMap; |
|
178 |
177 |
179 // called reflectively from Trees.instance(CompilationTask task) |
178 // called reflectively from Trees.instance(CompilationTask task) |
180 public static JavacTrees instance(JavaCompiler.CompilationTask task) { |
179 public static JavacTrees instance(JavaCompiler.CompilationTask task) { |
181 if (!(task instanceof BasicJavacTask)) |
180 if (!(task instanceof BasicJavacTask)) |
182 throw new IllegalArgumentException(); |
181 throw new IllegalArgumentException(); |
196 instance = new JavacTrees(context); |
195 instance = new JavacTrees(context); |
197 return instance; |
196 return instance; |
198 } |
197 } |
199 |
198 |
200 protected JavacTrees(Context context) { |
199 protected JavacTrees(Context context) { |
201 javaFileObjectToPackageMap = new HashMap<>(); |
|
202 this.breakIterator = null; |
200 this.breakIterator = null; |
203 context.put(JavacTrees.class, this); |
201 context.put(JavacTrees.class, this); |
204 init(context); |
202 init(context); |
205 } |
203 } |
206 |
204 |
1037 |
1035 |
1038 return new DocCommentParser(parser, diagSource, comment).parse(); |
1036 return new DocCommentParser(parser, diagSource, comment).parse(); |
1039 } |
1037 } |
1040 |
1038 |
1041 @Override @DefinedBy(Api.COMPILER_TREE) |
1039 @Override @DefinedBy(Api.COMPILER_TREE) |
1042 public DocTreePath getDocTreePath(FileObject fileObject) { |
1040 public DocTreePath getDocTreePath(FileObject fileObject, PackageElement packageElement) { |
1043 JavaFileObject jfo = asJavaFileObject(fileObject); |
1041 JavaFileObject jfo = asJavaFileObject(fileObject); |
1044 DocCommentTree docCommentTree = getDocCommentTree(jfo); |
1042 DocCommentTree docCommentTree = getDocCommentTree(jfo); |
1045 return new DocTreePath(makeTreePath(jfo, docCommentTree), docCommentTree); |
1043 TreePath treePath = makeTreePath((PackageSymbol)packageElement, jfo, docCommentTree); |
|
1044 return new DocTreePath(treePath, docCommentTree); |
1046 } |
1045 } |
1047 |
1046 |
1048 @Override @DefinedBy(Api.COMPILER_TREE) |
1047 @Override @DefinedBy(Api.COMPILER_TREE) |
1049 public void setBreakIterator(BreakIterator breakiterator) { |
1048 public void setBreakIterator(BreakIterator breakiterator) { |
1050 this.breakIterator = breakiterator; |
1049 this.breakIterator = breakiterator; |
1158 } else { |
1157 } else { |
1159 return v.type; |
1158 return v.type; |
1160 } |
1159 } |
1161 } |
1160 } |
1162 |
1161 |
1163 /** |
1162 private TreePath makeTreePath(final PackageSymbol psym, final JavaFileObject jfo, |
1164 * Register a file object, such as for a package.html, that provides |
1163 DocCommentTree dcTree) { |
1165 * doc comments for a package. |
|
1166 * @param psym the PackageSymbol representing the package. |
|
1167 * @param jfo the JavaFileObject for the given package. |
|
1168 */ |
|
1169 public void putJavaFileObject(PackageSymbol psym, JavaFileObject jfo) { |
|
1170 javaFileObjectToPackageMap.putIfAbsent(jfo, psym); |
|
1171 } |
|
1172 |
|
1173 private TreePath makeTreePath(final JavaFileObject jfo, DocCommentTree dcTree) { |
|
1174 JCCompilationUnit jcCompilationUnit = new JCCompilationUnit(List.nil()) { |
1164 JCCompilationUnit jcCompilationUnit = new JCCompilationUnit(List.nil()) { |
1175 public int getPos() { |
1165 public int getPos() { |
1176 return Position.FIRSTPOS; |
1166 return Position.FIRSTPOS; |
1177 } |
1167 } |
1178 |
1168 |
1188 return Position.makeLineMap(s.toCharArray(), s.length(), true); |
1178 return Position.makeLineMap(s.toCharArray(), s.length(), true); |
1189 } catch (IOException ignore) {} |
1179 } catch (IOException ignore) {} |
1190 return null; |
1180 return null; |
1191 } |
1181 } |
1192 }; |
1182 }; |
1193 |
|
1194 PackageSymbol psym = javaFileObjectToPackageMap.getOrDefault(jfo, |
|
1195 syms.unnamedModule.unnamedPackage); |
|
1196 |
1183 |
1197 jcCompilationUnit.docComments = new DocCommentTable() { |
1184 jcCompilationUnit.docComments = new DocCommentTable() { |
1198 @Override |
1185 @Override |
1199 public boolean hasComment(JCTree tree) { |
1186 public boolean hasComment(JCTree tree) { |
1200 return false; |
1187 return false; |