31 |
31 |
32 import javax.annotation.processing.ProcessingEnvironment; |
32 import javax.annotation.processing.ProcessingEnvironment; |
33 import javax.lang.model.element.AnnotationMirror; |
33 import javax.lang.model.element.AnnotationMirror; |
34 import javax.lang.model.element.AnnotationValue; |
34 import javax.lang.model.element.AnnotationValue; |
35 import javax.lang.model.element.Element; |
35 import javax.lang.model.element.Element; |
|
36 import javax.lang.model.element.ElementKind; |
36 import javax.lang.model.element.ExecutableElement; |
37 import javax.lang.model.element.ExecutableElement; |
37 import javax.lang.model.element.TypeElement; |
38 import javax.lang.model.element.TypeElement; |
38 import javax.lang.model.type.DeclaredType; |
39 import javax.lang.model.type.DeclaredType; |
39 import javax.lang.model.type.TypeKind; |
40 import javax.lang.model.type.TypeKind; |
40 import javax.lang.model.type.TypeMirror; |
41 import javax.lang.model.type.TypeMirror; |
42 import javax.tools.JavaCompiler; |
43 import javax.tools.JavaCompiler; |
43 import javax.tools.JavaFileObject; |
44 import javax.tools.JavaFileObject; |
44 |
45 |
45 import com.sun.source.doctree.DocCommentTree; |
46 import com.sun.source.doctree.DocCommentTree; |
46 import com.sun.source.doctree.DocTree; |
47 import com.sun.source.doctree.DocTree; |
47 import com.sun.source.doctree.ReferenceTree; |
|
48 import com.sun.source.tree.CatchTree; |
48 import com.sun.source.tree.CatchTree; |
49 import com.sun.source.tree.CompilationUnitTree; |
49 import com.sun.source.tree.CompilationUnitTree; |
50 import com.sun.source.tree.Scope; |
50 import com.sun.source.tree.Scope; |
51 import com.sun.source.tree.Tree; |
51 import com.sun.source.tree.Tree; |
52 import com.sun.source.util.DocSourcePositions; |
52 import com.sun.source.util.DocSourcePositions; |
|
53 import com.sun.source.util.DocTreePath; |
53 import com.sun.source.util.DocTreeScanner; |
54 import com.sun.source.util.DocTreeScanner; |
54 import com.sun.source.util.DocTrees; |
55 import com.sun.source.util.DocTrees; |
55 import com.sun.source.util.JavacTask; |
56 import com.sun.source.util.JavacTask; |
56 import com.sun.source.util.TreePath; |
57 import com.sun.source.util.TreePath; |
57 import com.sun.tools.javac.code.Flags; |
58 import com.sun.tools.javac.code.Flags; |
312 if (treeTopLevel == null) |
313 if (treeTopLevel == null) |
313 return null; |
314 return null; |
314 return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst); |
315 return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst); |
315 } |
316 } |
316 |
317 |
317 public Element getElement(TreePath path) { |
318 public Symbol getElement(TreePath path) { |
318 JCTree tree = (JCTree) path.getLeaf(); |
319 JCTree tree = (JCTree) path.getLeaf(); |
319 Symbol sym = TreeInfo.symbolFor(tree); |
320 Symbol sym = TreeInfo.symbolFor(tree); |
320 if (sym == null) { |
321 if (sym == null) { |
321 if (TreeInfo.isDeclaration(tree)) { |
322 if (TreeInfo.isDeclaration(tree)) { |
322 for (TreePath p = path; p != null; p = p.getParentPath()) { |
323 for (TreePath p = path; p != null; p = p.getParentPath()) { |
341 } |
342 } |
342 return sym; |
343 return sym; |
343 } |
344 } |
344 |
345 |
345 @Override |
346 @Override |
346 public Element getElement(TreePath path, ReferenceTree reference) { |
347 public Element getElement(DocTreePath path) { |
347 if (!(reference instanceof DCReference)) |
348 DocTree forTree = path.getLeaf(); |
348 return null; |
349 if (forTree instanceof DCReference) |
349 DCReference ref = (DCReference) reference; |
350 return attributeDocReference(path.getTreePath(), ((DCReference) forTree)); |
350 |
351 if (forTree instanceof DCIdentifier) { |
|
352 if (path.getParentPath().getLeaf() instanceof DCParam) { |
|
353 return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf()); |
|
354 } |
|
355 } |
|
356 return null; |
|
357 } |
|
358 |
|
359 private Symbol attributeDocReference(TreePath path, DCReference ref) { |
351 Env<AttrContext> env = getAttrContext(path); |
360 Env<AttrContext> env = getAttrContext(path); |
352 |
361 |
353 Log.DeferredDiagnosticHandler deferredDiagnosticHandler = |
362 Log.DeferredDiagnosticHandler deferredDiagnosticHandler = |
354 new Log.DeferredDiagnosticHandler(log); |
363 new Log.DeferredDiagnosticHandler(log); |
355 try { |
364 try { |
423 } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file |
432 } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file |
424 return null; |
433 return null; |
425 } finally { |
434 } finally { |
426 log.popDiagnosticHandler(deferredDiagnosticHandler); |
435 log.popDiagnosticHandler(deferredDiagnosticHandler); |
427 } |
436 } |
|
437 } |
|
438 |
|
439 private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) { |
|
440 Symbol javadocSymbol = getElement(path); |
|
441 if (javadocSymbol == null) |
|
442 return null; |
|
443 ElementKind kind = javadocSymbol.getKind(); |
|
444 List<? extends Symbol> params = List.nil(); |
|
445 if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) { |
|
446 MethodSymbol ee = (MethodSymbol) javadocSymbol; |
|
447 params = ptag.isTypeParameter() |
|
448 ? ee.getTypeParameters() |
|
449 : ee.getParameters(); |
|
450 } else if (kind.isClass() || kind.isInterface()) { |
|
451 ClassSymbol te = (ClassSymbol) javadocSymbol; |
|
452 params = te.getTypeParameters(); |
|
453 } |
|
454 |
|
455 for (Symbol param : params) { |
|
456 if (param.getSimpleName() == ptag.getName().getName()) { |
|
457 return param; |
|
458 } |
|
459 } |
|
460 return null; |
428 } |
461 } |
429 |
462 |
430 /** @see com.sun.tools.javadoc.ClassDocImpl#findField */ |
463 /** @see com.sun.tools.javadoc.ClassDocImpl#findField */ |
431 private VarSymbol findField(ClassSymbol tsym, Name fieldName) { |
464 private VarSymbol findField(ClassSymbol tsym, Name fieldName) { |
432 return searchField(tsym, fieldName, new HashSet<ClassSymbol>()); |
465 return searchField(tsym, fieldName, new HashSet<ClassSymbol>()); |