< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java

Print this page




  41 import java.util.ServiceLoader;
  42 import java.util.Set;
  43 import java.util.TreeSet;
  44 
  45 import javax.lang.model.element.Element;
  46 import javax.lang.model.element.ExecutableElement;
  47 import javax.lang.model.element.ModuleElement;
  48 import javax.lang.model.element.PackageElement;
  49 import javax.lang.model.element.TypeElement;
  50 import javax.lang.model.element.VariableElement;
  51 import javax.lang.model.util.SimpleElementVisitor14;
  52 import javax.tools.JavaFileManager;
  53 import javax.tools.StandardJavaFileManager;
  54 
  55 import com.sun.source.doctree.DocTree;
  56 
  57 import jdk.javadoc.doclet.Doclet;
  58 import jdk.javadoc.doclet.DocletEnvironment;
  59 import jdk.javadoc.doclet.Taglet.Location;
  60 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;

  61 import jdk.javadoc.internal.doclets.toolkit.DocletElement;
  62 import jdk.javadoc.internal.doclets.toolkit.Messages;
  63 import jdk.javadoc.internal.doclets.toolkit.Resources;
  64 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
  65 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
  66 
  67 import static com.sun.source.doctree.DocTree.Kind.AUTHOR;
  68 import static com.sun.source.doctree.DocTree.Kind.EXCEPTION;
  69 import static com.sun.source.doctree.DocTree.Kind.HIDDEN;
  70 import static com.sun.source.doctree.DocTree.Kind.LINK;
  71 import static com.sun.source.doctree.DocTree.Kind.LINK_PLAIN;
  72 import static com.sun.source.doctree.DocTree.Kind.PROVIDES;
  73 import static com.sun.source.doctree.DocTree.Kind.SEE;
  74 import static com.sun.source.doctree.DocTree.Kind.SERIAL;
  75 import static com.sun.source.doctree.DocTree.Kind.SERIAL_DATA;
  76 import static com.sun.source.doctree.DocTree.Kind.SERIAL_FIELD;
  77 import static com.sun.source.doctree.DocTree.Kind.SINCE;
  78 import static com.sun.source.doctree.DocTree.Kind.THROWS;
  79 import static com.sun.source.doctree.DocTree.Kind.USES;
  80 import static com.sun.source.doctree.DocTree.Kind.VERSION;


 160     /**
 161      * True if we want to use @version tags.
 162      */
 163     private final boolean showversion;
 164 
 165     /**
 166      * True if we want to use @author tags.
 167      */
 168     private final boolean showauthor;
 169 
 170     /**
 171      * True if we want to use JavaFX-related tags (@defaultValue, @treatAsPrivate).
 172      */
 173     private final boolean javafx;
 174 
 175     /**
 176      * Show the taglets table when it has been initialized.
 177      */
 178     private final boolean showTaglets;
 179 


 180     /**
 181      * Construct a new {@code TagletManager}.
 182      * @param nosince true if we do not want to use @since tags.
 183      * @param showversion true if we want to use @version tags.
 184      * @param showauthor true if we want to use @author tags.
 185      * @param javafx indicates whether javafx is active.
 186      * @param configuration the configuration for this taglet manager
 187      */
 188     public TagletManager(boolean nosince, boolean showversion,
 189                          boolean showauthor, boolean javafx,
 190                          BaseConfiguration configuration) {
 191         overriddenStandardTags = new HashSet<>();
 192         potentiallyConflictingTags = new HashSet<>();
 193         standardTags = new HashSet<>();
 194         standardTagsLowercase = new HashSet<>();
 195         unseenCustomTags = new HashSet<>();
 196         allTaglets = new LinkedHashMap<>();
 197         this.nosince = nosince;
 198         this.showversion = showversion;
 199         this.showauthor = showauthor;
 200         this.javafx = javafx;

 201         this.docEnv = configuration.docEnv;
 202         this.doclet = configuration.doclet;
 203         this.messages = configuration.getMessages();
 204         this.resources = configuration.getResources();
 205         this.showTaglets = configuration.showTaglets;
 206         this.utils = configuration.utils;

 207         initStandardTaglets();
 208     }
 209 
 210     /**
 211      * Add a new {@code Taglet}.  This is used to add a Taglet from within
 212      * a Doclet.  No message is printed to indicate that the Taglet is properly
 213      * registered because these Taglets are typically added for every execution of the
 214      * Doclet.  We don't want to see this type of error message every time.
 215      * @param customTag the new {@code Taglet} to add.
 216      */
 217     public void addCustomTag(Taglet customTag) {
 218         if (customTag != null) {
 219             String name = customTag.getName();
 220             allTaglets.remove(name);
 221             allTaglets.put(name, customTag);
 222             checkTagName(name);
 223         }
 224     }
 225 
 226     public Set<String> getAllTagletNames() {
 227         return allTaglets.keySet();
 228     }
 229 
 230     /**
 231      * Initializes the location TAGLET_PATH which is used to locate the custom taglets.
 232      * @param fileManager the file manager to load classes and resources.
 233      * @param tagletPath the path to the custom taglet.
 234      * @throws IOException if an error occurs while setting the location.
 235      */
 236     public void initTagletPath(JavaFileManager fileManager, String tagletPath) throws IOException {
 237         if (fileManager instanceof StandardJavaFileManager) {
 238             StandardJavaFileManager sfm = (StandardJavaFileManager)fileManager;
 239             if (tagletPath != null) {
 240                 List<File> paths = new ArrayList<>();
 241                 for (String pathname : tagletPath.split(File.pathSeparator)) {
 242                     paths.add(new File(pathname));
 243                 }
 244                 sfm.setLocation(TAGLET_PATH, paths);
 245             } else if (!sfm.hasLocation(TAGLET_PATH)) {
 246                 sfm.setLocation(TAGLET_PATH, Collections.emptyList());
 247             }
 248         } else if (tagletPath != null) {
 249             messages.error("doclet.not_standard_file_manager");
 250         }
 251     }
 252 
 253     /**
 254      * Adds a new {@code Taglet}.  Print a message to indicate whether or not
 255      * the Taglet was registered properly.
 256      * @param classname  the name of the class representing the custom tag.




  41 import java.util.ServiceLoader;
  42 import java.util.Set;
  43 import java.util.TreeSet;
  44 
  45 import javax.lang.model.element.Element;
  46 import javax.lang.model.element.ExecutableElement;
  47 import javax.lang.model.element.ModuleElement;
  48 import javax.lang.model.element.PackageElement;
  49 import javax.lang.model.element.TypeElement;
  50 import javax.lang.model.element.VariableElement;
  51 import javax.lang.model.util.SimpleElementVisitor14;
  52 import javax.tools.JavaFileManager;
  53 import javax.tools.StandardJavaFileManager;
  54 
  55 import com.sun.source.doctree.DocTree;
  56 
  57 import jdk.javadoc.doclet.Doclet;
  58 import jdk.javadoc.doclet.DocletEnvironment;
  59 import jdk.javadoc.doclet.Taglet.Location;
  60 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
  61 import jdk.javadoc.internal.doclets.toolkit.BaseOptions;
  62 import jdk.javadoc.internal.doclets.toolkit.DocletElement;
  63 import jdk.javadoc.internal.doclets.toolkit.Messages;
  64 import jdk.javadoc.internal.doclets.toolkit.Resources;
  65 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
  66 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
  67 
  68 import static com.sun.source.doctree.DocTree.Kind.AUTHOR;
  69 import static com.sun.source.doctree.DocTree.Kind.EXCEPTION;
  70 import static com.sun.source.doctree.DocTree.Kind.HIDDEN;
  71 import static com.sun.source.doctree.DocTree.Kind.LINK;
  72 import static com.sun.source.doctree.DocTree.Kind.LINK_PLAIN;
  73 import static com.sun.source.doctree.DocTree.Kind.PROVIDES;
  74 import static com.sun.source.doctree.DocTree.Kind.SEE;
  75 import static com.sun.source.doctree.DocTree.Kind.SERIAL;
  76 import static com.sun.source.doctree.DocTree.Kind.SERIAL_DATA;
  77 import static com.sun.source.doctree.DocTree.Kind.SERIAL_FIELD;
  78 import static com.sun.source.doctree.DocTree.Kind.SINCE;
  79 import static com.sun.source.doctree.DocTree.Kind.THROWS;
  80 import static com.sun.source.doctree.DocTree.Kind.USES;
  81 import static com.sun.source.doctree.DocTree.Kind.VERSION;


 161     /**
 162      * True if we want to use @version tags.
 163      */
 164     private final boolean showversion;
 165 
 166     /**
 167      * True if we want to use @author tags.
 168      */
 169     private final boolean showauthor;
 170 
 171     /**
 172      * True if we want to use JavaFX-related tags (@defaultValue, @treatAsPrivate).
 173      */
 174     private final boolean javafx;
 175 
 176     /**
 177      * Show the taglets table when it has been initialized.
 178      */
 179     private final boolean showTaglets;
 180 
 181     private final String tagletPath;
 182 
 183     /**
 184      * Construct a new {@code TagletManager}.




 185      * @param configuration the configuration for this taglet manager
 186      */
 187     public TagletManager(BaseConfiguration configuration) {


 188         overriddenStandardTags = new HashSet<>();
 189         potentiallyConflictingTags = new HashSet<>();
 190         standardTags = new HashSet<>();
 191         standardTagsLowercase = new HashSet<>();
 192         unseenCustomTags = new HashSet<>();
 193         allTaglets = new LinkedHashMap<>();
 194         BaseOptions options = configuration.getOptions();
 195         this.nosince = options.noSince;
 196         this.showversion = options.showVersion;
 197         this.showauthor = options.showAuthor;
 198         this.javafx = options.javafx;
 199         this.docEnv = configuration.docEnv;
 200         this.doclet = configuration.doclet;
 201         this.messages = configuration.getMessages();
 202         this.resources = configuration.getResources();
 203         this.showTaglets = options.showTaglets;
 204         this.utils = configuration.utils;
 205         this.tagletPath = options.tagletPath;
 206         initStandardTaglets();
 207     }
 208 
 209     /**
 210      * Add a new {@code Taglet}.  This is used to add a Taglet from within
 211      * a Doclet.  No message is printed to indicate that the Taglet is properly
 212      * registered because these Taglets are typically added for every execution of the
 213      * Doclet.  We don't want to see this type of error message every time.
 214      * @param customTag the new {@code Taglet} to add.
 215      */
 216     public void addCustomTag(Taglet customTag) {
 217         if (customTag != null) {
 218             String name = customTag.getName();
 219             allTaglets.remove(name);
 220             allTaglets.put(name, customTag);
 221             checkTagName(name);
 222         }
 223     }
 224 
 225     public Set<String> getAllTagletNames() {
 226         return allTaglets.keySet();
 227     }
 228 
 229     /**
 230      * Initializes the location TAGLET_PATH which is used to locate the custom taglets.
 231      * @param fileManager the file manager to load classes and resources.

 232      * @throws IOException if an error occurs while setting the location.
 233      */
 234     public void initTagletPath(JavaFileManager fileManager) throws IOException {
 235         if (fileManager instanceof StandardJavaFileManager) {
 236             StandardJavaFileManager sfm = (StandardJavaFileManager)fileManager;
 237             if (tagletPath != null) {
 238                 List<File> paths = new ArrayList<>();
 239                 for (String pathname : tagletPath.split(File.pathSeparator)) {
 240                     paths.add(new File(pathname));
 241                 }
 242                 sfm.setLocation(TAGLET_PATH, paths);
 243             } else if (!sfm.hasLocation(TAGLET_PATH)) {
 244                 sfm.setLocation(TAGLET_PATH, Collections.emptyList());
 245             }
 246         } else if (tagletPath != null) {
 247             messages.error("doclet.not_standard_file_manager");
 248         }
 249     }
 250 
 251     /**
 252      * Adds a new {@code Taglet}.  Print a message to indicate whether or not
 253      * the Taglet was registered properly.
 254      * @param classname  the name of the class representing the custom tag.


< prev index next >