langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
changeset 37009 476d8d615222
parent 36526 3b41f1c69604
child 37752 4243173b58db
equal deleted inserted replaced
37008:55c73d04e57c 37009:476d8d615222
    83 import static javax.lang.model.element.ElementKind.*;
    83 import static javax.lang.model.element.ElementKind.*;
    84 import static javax.lang.model.element.Modifier.*;
    84 import static javax.lang.model.element.Modifier.*;
    85 import static javax.lang.model.type.TypeKind.*;
    85 import static javax.lang.model.type.TypeKind.*;
    86 
    86 
    87 import static com.sun.source.doctree.DocTree.Kind.*;
    87 import static com.sun.source.doctree.DocTree.Kind.*;
       
    88 import com.sun.source.util.SimpleDocTreeVisitor;
    88 import static jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.MAX_CONSTANT_VALUE_INDEX_LENGTH;
    89 import static jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.MAX_CONSTANT_VALUE_INDEX_LENGTH;
    89 
    90 
    90 
    91 
    91 /**
    92 /**
    92  * Utilities Class for Doclets.
    93  * Utilities Class for Doclets.
  1229         TypeMirror superType = te.getSuperclass();
  1230         TypeMirror superType = te.getSuperclass();
  1230         if (isNoType(superType)) {
  1231         if (isNoType(superType)) {
  1231             superType = getObjectType();
  1232             superType = getObjectType();
  1232         }
  1233         }
  1233         TypeElement superClass = asTypeElement(superType);
  1234         TypeElement superClass = asTypeElement(superType);
  1234 
  1235         // skip "hidden" classes
  1235         while (superClass != null && !isPublic(superClass) && !isLinkable(superClass)) {
  1236         while ((superClass != null && isHidden(superClass))
       
  1237                 || (superClass != null &&  !isPublic(superClass) && !isLinkable(superClass))) {
  1236             TypeMirror supersuperType = superClass.getSuperclass();
  1238             TypeMirror supersuperType = superClass.getSuperclass();
  1237             TypeElement supersuperClass = asTypeElement(supersuperType);
  1239             TypeElement supersuperClass = asTypeElement(supersuperType);
  1238             if (supersuperClass == null
  1240             if (supersuperClass == null
  1239                     || supersuperClass.getQualifiedName().equals(superClass.getQualifiedName())) {
  1241                     || supersuperClass.getQualifiedName().equals(superClass.getQualifiedName())) {
  1240                 break;
  1242                 break;
  1446         return propertyName.substring(0, 1).toLowerCase(configuration.getLocale())
  1448         return propertyName.substring(0, 1).toLowerCase(configuration.getLocale())
  1447                 + propertyName.substring(1);
  1449                 + propertyName.substring(1);
  1448     }
  1450     }
  1449 
  1451 
  1450     /**
  1452     /**
       
  1453      * Returns true if the element is included, contains @hidden tag,
       
  1454      * or if javafx flag is present and element contains @treatAsPrivate
       
  1455      * tag.
       
  1456      * @param e the queried element
       
  1457      * @return true if it exists, false otherwise
       
  1458      */
       
  1459     public boolean isHidden(Element e) {
       
  1460         // prevent needless tests on elements which are not included
       
  1461         if (!isIncluded(e)) {
       
  1462             return false;
       
  1463         }
       
  1464         if (configuration.javafx &&
       
  1465                 hasBlockTag(e, DocTree.Kind.UNKNOWN_BLOCK_TAG, "treatAsPrivate")) {
       
  1466             return true;
       
  1467         }
       
  1468         return hasBlockTag(e, DocTree.Kind.HIDDEN);
       
  1469     }
       
  1470 
       
  1471     /**
  1451      * In case of JavaFX mode on, filters out classes that are private,
  1472      * In case of JavaFX mode on, filters out classes that are private,
  1452      * package private or having the @treatAsPrivate annotation. Those are not
  1473      * package private, these are not documented in JavaFX mode, also
  1453      * documented in JavaFX mode.
  1474      * remove those classes that have @hidden or @treatAsPrivate comment tag.
  1454      *
  1475      *
  1455      * @param classlist a collection of TypeElements
  1476      * @param classlist a collection of TypeElements
  1456      * @param javafx set to true if in JavaFX mode.
  1477      * @param javafx set to true if in JavaFX mode.
  1457      * @return list of filtered classes.
  1478      * @return list of filtered classes.
  1458      */
  1479      */
  1460             boolean javafx) {
  1481             boolean javafx) {
  1461         SortedSet<TypeElement> filteredOutClasses =
  1482         SortedSet<TypeElement> filteredOutClasses =
  1462                 new TreeSet<>(makeGeneralPurposeComparator());
  1483                 new TreeSet<>(makeGeneralPurposeComparator());
  1463         if (!javafx) {
  1484         if (!javafx) {
  1464             for (Element te : classlist) {
  1485             for (Element te : classlist) {
  1465                 filteredOutClasses.add((TypeElement)te);
  1486                 if (!isHidden(te)) {
       
  1487                     filteredOutClasses.add((TypeElement)te);
       
  1488                 }
  1466             }
  1489             }
  1467             return filteredOutClasses;
  1490             return filteredOutClasses;
  1468         }
  1491         }
  1469         for (Element e : classlist) {
  1492         for (Element e : classlist) {
  1470             if (isPrivate(e) || isPackagePrivate(e)) {
  1493             if (isPrivate(e) || isPackagePrivate(e) || isHidden(e)) {
  1471                 continue;
       
  1472             }
       
  1473             List<? extends DocTree> aspTags = getBlockTags(e, "treatAsPrivate");
       
  1474             if (aspTags != null && !aspTags.isEmpty()) {
       
  1475                 continue;
  1494                 continue;
  1476             }
  1495             }
  1477             filteredOutClasses.add((TypeElement)e);
  1496             filteredOutClasses.add((TypeElement)e);
  1478         }
  1497         }
  1479         return filteredOutClasses;
  1498         return filteredOutClasses;
  2709     public List<? extends DocTree> getBlockTags(Element element, String tagName) {
  2728     public List<? extends DocTree> getBlockTags(Element element, String tagName) {
  2710         DocTree.Kind kind = null;
  2729         DocTree.Kind kind = null;
  2711         switch (tagName) {
  2730         switch (tagName) {
  2712             case "author":
  2731             case "author":
  2713             case "deprecated":
  2732             case "deprecated":
       
  2733             case "hidden":
  2714             case "param":
  2734             case "param":
  2715             case "return":
  2735             case "return":
  2716             case "see":
  2736             case "see":
  2717             case "serial":
  2737             case "serial":
  2718             case "since":
  2738             case "since":
  2732                 break;
  2752                 break;
  2733         }
  2753         }
  2734         List<? extends DocTree> blockTags = getBlockTags(element, kind);
  2754         List<? extends DocTree> blockTags = getBlockTags(element, kind);
  2735         List<DocTree> out = new ArrayList<>();
  2755         List<DocTree> out = new ArrayList<>();
  2736         String tname = tagName.startsWith("@") ? tagName.substring(1) : tagName;
  2756         String tname = tagName.startsWith("@") ? tagName.substring(1) : tagName;
  2737         CommentHelper ch = wksMap.get(element);
  2757         CommentHelper ch = getCommentHelper(element);
  2738         for (DocTree dt : blockTags) {
  2758         for (DocTree dt : blockTags) {
  2739             if (ch.getTagName(dt).equals(tname)) {
  2759             if (ch.getTagName(dt).equals(tname)) {
  2740                 out.add(dt);
  2760                 out.add(dt);
  2741             }
  2761             }
  2742         }
  2762         }
  2743         return out;
  2763         return out;
       
  2764     }
       
  2765 
       
  2766     public boolean hasBlockTag(Element element, DocTree.Kind kind) {
       
  2767         return hasBlockTag(element, kind, null);
       
  2768     }
       
  2769 
       
  2770     public boolean hasBlockTag(Element element, DocTree.Kind kind, final String tagName) {
       
  2771         CommentHelper ch = getCommentHelper(element);
       
  2772         String tname = tagName != null && tagName.startsWith("@")
       
  2773                 ? tagName.substring(1)
       
  2774                 : tagName;
       
  2775         for (DocTree dt : getBlockTags(element, kind)) {
       
  2776             if (dt.getKind() == kind) {
       
  2777                 if (tname == null || ch.getTagName(dt).equals(tname)) {
       
  2778                     return true;
       
  2779                 }
       
  2780             }
       
  2781         }
       
  2782         return false;
  2744     }
  2783     }
  2745 
  2784 
  2746     /**
  2785     /**
  2747      * Gets a TreePath for an Element. Note this method is called very
  2786      * Gets a TreePath for an Element. Note this method is called very
  2748      * frequently, care must be taken to ensure this method is lithe
  2787      * frequently, care must be taken to ensure this method is lithe