< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java

Print this page




3015                 : tagName;
3016         for (DocTree dt : getBlockTags(element, kind)) {
3017             if (dt.getKind() == kind) {
3018                 if (tname == null || ch.getTagName(dt).equals(tname)) {
3019                     return true;
3020                 }
3021             }
3022         }
3023         return false;
3024     }
3025 
3026     /**
3027      * Gets a TreePath for an Element. Note this method is called very
3028      * frequently, care must be taken to ensure this method is lithe
3029      * and efficient.
3030      * @param e an Element
3031      * @return TreePath
3032      */
3033     public TreePath getTreePath(Element e) {
3034         DocCommentDuo duo = dcTreeCache.get(e);
3035         if (duo != null && duo.treePath != null) {
3036             return duo.treePath;
3037         }
3038         duo = configuration.cmtUtils.getSyntheticCommentDuo(e);
3039         if (duo != null && duo.treePath != null) {
3040             return duo.treePath;
3041         }
3042         Map<Element, TreePath> elementToTreePath = configuration.workArounds.getElementToTreePath();
3043         TreePath path = elementToTreePath.get(e);
3044         if (path != null || elementToTreePath.containsKey(e)) {
3045             // expedite the path and one that is a null
3046             return path;
3047         }
3048         return elementToTreePath.computeIfAbsent(e, docTrees::getPath);
3049     }
3050 
3051     private final Map<Element, DocCommentDuo> dcTreeCache = new LinkedHashMap<>();
3052 
3053     /**
3054      * Retrieves the doc comments for a given element.
3055      * @param element
3056      * @return DocCommentTree for the Element
3057      */
3058     public DocCommentTree getDocCommentTree0(Element element) {
3059 
3060         DocCommentDuo duo = null;
3061 
3062         ElementKind kind = element.getKind();
3063         if (kind == ElementKind.PACKAGE || kind == ElementKind.OTHER) {
3064             duo = dcTreeCache.get(element); // local cache
3065             if (duo == null && kind == ElementKind.PACKAGE) {
3066                 // package-info.java
3067                 duo = getDocCommentTuple(element);
3068             }
3069             if (duo == null) {
3070                 // package.html or overview.html
3071                 duo = configuration.cmtUtils.getHtmlCommentDuo(element); // html source
3072             }
3073         } else {
3074             duo = configuration.cmtUtils.getSyntheticCommentDuo(element);
3075             if (duo == null) {
3076                 duo = dcTreeCache.get(element); // local cache
3077             }
3078             if (duo == null) {
3079                 duo = getDocCommentTuple(element); // get the real mccoy
3080             }
3081         }
3082 
3083         DocCommentTree docCommentTree = isValidDuo(duo) ? duo.dcTree : null;
3084         TreePath path = isValidDuo(duo) ? duo.treePath : null;
3085         if (!dcTreeCache.containsKey(element)) {
3086             if (docCommentTree != null && path != null) {
3087                 if (!configuration.isAllowScriptInComments()) {
3088                     try {
3089                         javaScriptScanner.scan(docCommentTree, path, p -> {
3090                             throw new JavaScriptScanner.Fault();
3091                         });
3092                     } catch (JavaScriptScanner.Fault jsf) {
3093                         String text = resources.getText("doclet.JavaScript_in_comment");
3094                         throw new UncheckedDocletException(new SimpleDocletException(text, jsf));
3095                     }
3096                 }
3097                 configuration.workArounds.runDocLint(path);
3098             }




3015                 : tagName;
3016         for (DocTree dt : getBlockTags(element, kind)) {
3017             if (dt.getKind() == kind) {
3018                 if (tname == null || ch.getTagName(dt).equals(tname)) {
3019                     return true;
3020                 }
3021             }
3022         }
3023         return false;
3024     }
3025 
3026     /**
3027      * Gets a TreePath for an Element. Note this method is called very
3028      * frequently, care must be taken to ensure this method is lithe
3029      * and efficient.
3030      * @param e an Element
3031      * @return TreePath
3032      */
3033     public TreePath getTreePath(Element e) {
3034         DocCommentDuo duo = dcTreeCache.get(e);
3035         if (isValidDuo(duo) && duo.treePath != null) {
3036             return duo.treePath;
3037         }
3038         duo = configuration.cmtUtils.getSyntheticCommentDuo(e);
3039         if (isValidDuo(duo) && duo.treePath != null) {
3040             return duo.treePath;
3041         }
3042         Map<Element, TreePath> elementToTreePath = configuration.workArounds.getElementToTreePath();
3043         TreePath path = elementToTreePath.get(e);
3044         if (path != null || elementToTreePath.containsKey(e)) {
3045             // expedite the path and one that is a null
3046             return path;
3047         }
3048         return elementToTreePath.computeIfAbsent(e, docTrees::getPath);
3049     }
3050 
3051     private final Map<Element, DocCommentDuo> dcTreeCache = new LinkedHashMap<>();
3052 
3053     /**
3054      * Retrieves the doc comments for a given element.
3055      * @param element
3056      * @return DocCommentTree for the Element
3057      */
3058     public DocCommentTree getDocCommentTree0(Element element) {
3059 
3060         DocCommentDuo duo = null;
3061 
3062         ElementKind kind = element.getKind();
3063         if (kind == ElementKind.PACKAGE || kind == ElementKind.OTHER) {
3064             duo = dcTreeCache.get(element); // local cache
3065             if (!isValidDuo(duo) && kind == ElementKind.PACKAGE) {
3066                 // package-info.java
3067                 duo = getDocCommentTuple(element);
3068             }
3069             if (!isValidDuo(duo)) {
3070                 // package.html or overview.html
3071                 duo = configuration.cmtUtils.getHtmlCommentDuo(element); // html source
3072             }
3073         } else {
3074             duo = configuration.cmtUtils.getSyntheticCommentDuo(element);
3075             if (!isValidDuo(duo)) {
3076                 duo = dcTreeCache.get(element); // local cache
3077             }
3078             if (!isValidDuo(duo)) {
3079                 duo = getDocCommentTuple(element); // get the real mccoy
3080             }
3081         }
3082 
3083         DocCommentTree docCommentTree = isValidDuo(duo) ? duo.dcTree : null;
3084         TreePath path = isValidDuo(duo) ? duo.treePath : null;
3085         if (!dcTreeCache.containsKey(element)) {
3086             if (docCommentTree != null && path != null) {
3087                 if (!configuration.isAllowScriptInComments()) {
3088                     try {
3089                         javaScriptScanner.scan(docCommentTree, path, p -> {
3090                             throw new JavaScriptScanner.Fault();
3091                         });
3092                     } catch (JavaScriptScanner.Fault jsf) {
3093                         String text = resources.getText("doclet.JavaScript_in_comment");
3094                         throw new UncheckedDocletException(new SimpleDocletException(text, jsf));
3095                     }
3096                 }
3097                 configuration.workArounds.runDocLint(path);
3098             }


< prev index next >