langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
changeset 40587 1c355ea550ed
parent 40511 1b3c502e0bdc
child 40605 926c13175b67
equal deleted inserted replaced
40519:e17429a7e843 40587:1c355ea550ed
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.toolkit.util;
    26 package jdk.javadoc.internal.doclets.toolkit.util;
    27 
    27 
    28 import java.io.*;
       
    29 import java.lang.annotation.Documented;
    28 import java.lang.annotation.Documented;
    30 import java.lang.ref.SoftReference;
    29 import java.lang.ref.SoftReference;
    31 import java.text.CollationKey;
    30 import java.text.CollationKey;
    32 import java.text.Collator;
    31 import java.text.Collator;
    33 import java.util.*;
    32 import java.util.*;
    76 import com.sun.source.util.TreePath;
    75 import com.sun.source.util.TreePath;
    77 import com.sun.tools.javac.util.DefinedBy;
    76 import com.sun.tools.javac.util.DefinedBy;
    78 import com.sun.tools.javac.util.DefinedBy.Api;
    77 import com.sun.tools.javac.util.DefinedBy.Api;
    79 import jdk.javadoc.internal.doclets.toolkit.CommentUtils.DocCommentDuo;
    78 import jdk.javadoc.internal.doclets.toolkit.CommentUtils.DocCommentDuo;
    80 import jdk.javadoc.internal.doclets.toolkit.Configuration;
    79 import jdk.javadoc.internal.doclets.toolkit.Configuration;
       
    80 import jdk.javadoc.internal.doclets.toolkit.Messages;
    81 import jdk.javadoc.internal.doclets.toolkit.WorkArounds;
    81 import jdk.javadoc.internal.doclets.toolkit.WorkArounds;
    82 
    82 
    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 
       
    89 import jdk.javadoc.internal.doclets.toolkit.Messages;
       
    90 
       
    91 import static jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.MAX_CONSTANT_VALUE_INDEX_LENGTH;
    88 import static jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.MAX_CONSTANT_VALUE_INDEX_LENGTH;
    92 
    89 
    93 
    90 
    94 /**
    91 /**
    95  * Utilities Class for Doclets.
    92  * Utilities Class for Doclets.
   272      * to the generated documentation directory. For example for a package
   269      * to the generated documentation directory. For example for a package
   273      * java.lang this method find out the source location of the package using
   270      * java.lang this method find out the source location of the package using
   274      * {@link SourcePath} and if given directory is found in the source
   271      * {@link SourcePath} and if given directory is found in the source
   275      * directory structure, copy the entire directory, to the generated
   272      * directory structure, copy the entire directory, to the generated
   276      * documentation hierarchy.
   273      * documentation hierarchy.
   277      * @param pe
   274      *
   278      */
   275      * @param pe the package containing the doc files to be copied
   279     public void copyDocFiles(PackageElement pe) {
   276      * @throws DocFileIOException if there is a problem while copying the documentation files
       
   277      */
       
   278     public void copyDocFiles(PackageElement pe) throws DocFileIOException {
   280         copyDocFiles(DocPath.forPackage(pe).resolve(DocPaths.DOC_FILES));
   279         copyDocFiles(DocPath.forPackage(pe).resolve(DocPaths.DOC_FILES));
   281     }
   280     }
   282 
   281 
   283     public void copyDocFiles(DocPath dir) {
   282     /**
   284         try {
   283      * This method is obsolete, should not be used, and should be deleted.
   285             boolean first = true;
   284      * It does not take module locations into account!
   286             for (DocFile f : DocFile.list(configuration, StandardLocation.SOURCE_PATH, dir)) {
   285      *
   287                 if (!f.isDirectory()) {
   286      * @throws DocFileIOException if there is a problem while copying the documentation files
   288                     continue;
   287      */
   289                 }
   288     public void copyDocFiles(DocPath dir) throws DocFileIOException {
   290                 DocFile srcdir = f;
   289         boolean first = true;
   291                 DocFile destdir = DocFile.createFileForOutput(configuration, dir);
   290         for (DocFile f : DocFile.list(configuration, StandardLocation.SOURCE_PATH, dir)) {
   292                 if (srcdir.isSameFile(destdir)) {
   291             if (!f.isDirectory()) {
   293                     continue;
   292                 continue;
   294                 }
   293             }
       
   294             DocFile srcdir = f;
       
   295             DocFile destdir = DocFile.createFileForOutput(configuration, dir);
       
   296             if (srcdir.isSameFile(destdir)) {
       
   297                 continue;
       
   298             }
   295 
   299 
   296                 for (DocFile srcfile: srcdir.list()) {
   300                 for (DocFile srcfile: srcdir.list()) {
   297                     DocFile destfile = destdir.resolve(srcfile.getName());
   301                 DocFile destfile = destdir.resolve(srcfile.getName());
   298                     if (srcfile.isFile()) {
   302                 if (srcfile.isFile()) {
   299                         if (destfile.exists() && !first) {
   303                     if (destfile.exists() && !first) {
   300                             messages.warning("doclet.Copy_Overwrite_warning",
   304                         messages.warning("doclet.Copy_Overwrite_warning",
   301                                     srcfile.getPath(), destdir.getPath());
   305                                 srcfile.getPath(), destdir.getPath());
   302                         } else {
   306                     } else {
   303                             messages.notice("doclet.Copying_File_0_To_Dir_1",
   307                         messages.notice("doclet.Copying_File_0_To_Dir_1",
   304                                     srcfile.getPath(), destdir.getPath());
   308                                 srcfile.getPath(), destdir.getPath());
   305                             destfile.copyFile(srcfile);
   309                         destfile.copyFile(srcfile);
   306                         }
       
   307                     } else if (srcfile.isDirectory()) {
       
   308                         if (configuration.copydocfilesubdirs
       
   309                                 && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
       
   310                             copyDocFiles(dir.resolve(srcfile.getName()));
       
   311                         }
       
   312                     }
   310                     }
   313                 }
   311                 } else if (srcfile.isDirectory()) {
   314 
   312                     if (configuration.copydocfilesubdirs
   315                 first = false;
   313                             && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
   316             }
   314                         copyDocFiles(dir.resolve(srcfile.getName()));
   317         } catch (SecurityException | IOException exc) {
   315                     }
   318             throw new DocletAbortException(exc);
   316                 }
       
   317             }
       
   318 
       
   319             first = false;
   319         }
   320         }
   320     }
   321     }
   321 
   322 
   322     public boolean isAnnotated(TypeMirror e) {
   323     public boolean isAnnotated(TypeMirror e) {
   323         return !e.getAnnotationMirrors().isEmpty();
   324         return !e.getAnnotationMirrors().isEmpty();
  1565             secondaryCollator = new DocCollator(configuration.locale, Collator.SECONDARY);
  1566             secondaryCollator = new DocCollator(configuration.locale, Collator.SECONDARY);
  1566         }
  1567         }
  1567         return secondaryCollator.compare(s1, s2);
  1568         return secondaryCollator.compare(s1, s2);
  1568     }
  1569     }
  1569 
  1570 
  1570     public void copyDocFiles(Configuration configuration, Location locn, DocPath dir) {
  1571     /**
  1571         try {
  1572      * @param configuration the configuration for this doclet
  1572             boolean first = true;
  1573      * @param locn the location from which to read files
  1573             for (DocFile f : DocFile.list(configuration, locn, dir)) {
  1574      * @param dir the path for the files to be copied
  1574                 if (!f.isDirectory()) {
  1575      * @throws DocFileIOException if there is a problem copying the files
  1575                     continue;
  1576      */
  1576                 }
  1577     public void copyDocFiles(Configuration configuration, Location locn, DocPath dir)
  1577                 DocFile srcdir = f;
  1578             throws DocFileIOException {
  1578                 DocFile destdir = DocFile.createFileForOutput(configuration, dir);
  1579         boolean first = true;
  1579                 if (srcdir.isSameFile(destdir)) {
  1580         for (DocFile f : DocFile.list(configuration, locn, dir)) {
  1580                     continue;
  1581             if (!f.isDirectory()) {
  1581                 }
  1582                 continue;
  1582 
  1583             }
  1583                 for (DocFile srcfile: srcdir.list()) {
  1584             DocFile srcdir = f;
  1584                     DocFile destfile = destdir.resolve(srcfile.getName());
  1585             DocFile destdir = DocFile.createFileForOutput(configuration, dir);
  1585                     if (srcfile.isFile()) {
  1586             if (srcdir.isSameFile(destdir)) {
  1586                         if (destfile.exists() && !first) {
  1587                 continue;
  1587                             messages.warning("doclet.Copy_Overwrite_warning",
  1588             }
  1588                                     srcfile.getPath(), destdir.getPath());
  1589 
  1589                         } else {
  1590             for (DocFile srcfile: srcdir.list()) {
  1590                             messages.notice("doclet.Copying_File_0_To_Dir_1",
  1591                 DocFile destfile = destdir.resolve(srcfile.getName());
  1591                                     srcfile.getPath(), destdir.getPath());
  1592                 if (srcfile.isFile()) {
  1592                             destfile.copyFile(srcfile);
  1593                     if (destfile.exists() && !first) {
  1593                         }
  1594                         messages.warning("doclet.Copy_Overwrite_warning",
  1594                     } else if (srcfile.isDirectory()) {
  1595                                 srcfile.getPath(), destdir.getPath());
  1595                         if (configuration.copydocfilesubdirs
  1596                     } else {
  1596                                 && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
  1597                         messages.notice("doclet.Copying_File_0_To_Dir_1",
  1597                             copyDocFiles(configuration, locn, dir.resolve(srcfile.getName()));
  1598                                 srcfile.getPath(), destdir.getPath());
  1598                         }
  1599                         destfile.copyFile(srcfile);
  1599                     }
  1600                     }
  1600                 }
  1601                 } else if (srcfile.isDirectory()) {
  1601 
  1602                     if (configuration.copydocfilesubdirs
  1602                 first = false;
  1603                             && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
  1603             }
  1604                         copyDocFiles(configuration, locn, dir.resolve(srcfile.getName()));
  1604         } catch (SecurityException | IOException exc) {
  1605                     }
  1605             throw new DocletAbortException(exc);
  1606                 }
       
  1607             }
       
  1608 
       
  1609             first = false;
  1606         }
  1610         }
  1607     }
  1611     }
  1608 
  1612 
  1609     private static class DocCollator {
  1613     private static class DocCollator {
  1610         private final Map<String, CollationKey> keys;
  1614         private final Map<String, CollationKey> keys;