langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java
changeset 44388 4d0903f1f311
parent 44189 dd311cfb920b
child 45417 f7479ee8de69
equal deleted inserted replaced
44387:8efb26290858 44388:4d0903f1f311
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.toolkit.taglets;
    26 package jdk.javadoc.internal.doclets.toolkit.taglets;
    27 
    27 
    28 import java.io.*;
    28 import java.io.*;
       
    29 import java.lang.reflect.InvocationTargetException;
    29 import java.util.*;
    30 import java.util.*;
    30 
    31 
    31 import javax.lang.model.element.Element;
    32 import javax.lang.model.element.Element;
    32 import javax.lang.model.element.ExecutableElement;
    33 import javax.lang.model.element.ExecutableElement;
    33 import javax.lang.model.element.ModuleElement;
    34 import javax.lang.model.element.ModuleElement;
    37 import javax.lang.model.util.SimpleElementVisitor9;
    38 import javax.lang.model.util.SimpleElementVisitor9;
    38 import javax.tools.JavaFileManager;
    39 import javax.tools.JavaFileManager;
    39 import javax.tools.StandardJavaFileManager;
    40 import javax.tools.StandardJavaFileManager;
    40 
    41 
    41 import com.sun.source.doctree.DocTree;
    42 import com.sun.source.doctree.DocTree;
       
    43 import jdk.javadoc.doclet.Doclet;
       
    44 import jdk.javadoc.doclet.DocletEnvironment;
    42 import jdk.javadoc.internal.doclets.toolkit.Configuration;
    45 import jdk.javadoc.internal.doclets.toolkit.Configuration;
    43 import jdk.javadoc.internal.doclets.toolkit.Messages;
    46 import jdk.javadoc.internal.doclets.toolkit.Messages;
    44 import jdk.javadoc.internal.doclets.toolkit.Resources;
    47 import jdk.javadoc.internal.doclets.toolkit.Resources;
    45 
    48 
    46 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
    49 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
   123     /**
   126     /**
   124      * The array of custom tags that can appear in the serialized form.
   127      * The array of custom tags that can appear in the serialized form.
   125      */
   128      */
   126     private List<Taglet> serializedFormTags;
   129     private List<Taglet> serializedFormTags;
   127 
   130 
       
   131     private final DocletEnvironment docEnv;
       
   132     private final Doclet doclet;
       
   133 
   128     private final Messages messages;
   134     private final Messages messages;
   129     private final Resources resources;
   135     private final Resources resources;
   130 
   136 
   131     /**
   137     /**
   132      * Keep track of standard tags.
   138      * Keep track of standard tags.
   182      * Construct a new <code>TagletManager</code>.
   188      * Construct a new <code>TagletManager</code>.
   183      * @param nosince true if we do not want to use @since tags.
   189      * @param nosince true if we do not want to use @since tags.
   184      * @param showversion true if we want to use @version tags.
   190      * @param showversion true if we want to use @version tags.
   185      * @param showauthor true if we want to use @author tags.
   191      * @param showauthor true if we want to use @author tags.
   186      * @param javafx indicates whether javafx is active.
   192      * @param javafx indicates whether javafx is active.
   187      * @param message the message retriever to print warnings.
   193      * @param configuration the configuration for this taglet manager
   188      */
   194      */
   189     public TagletManager(boolean nosince, boolean showversion,
   195     public TagletManager(boolean nosince, boolean showversion,
   190                          boolean showauthor, boolean javafx,
   196                          boolean showauthor, boolean javafx,
   191                          Configuration configuration) {
   197                          Configuration configuration) {
   192         overridenStandardTags = new HashSet<>();
   198         overridenStandardTags = new HashSet<>();
   197         customTags = new LinkedHashMap<>();
   203         customTags = new LinkedHashMap<>();
   198         this.nosince = nosince;
   204         this.nosince = nosince;
   199         this.showversion = showversion;
   205         this.showversion = showversion;
   200         this.showauthor = showauthor;
   206         this.showauthor = showauthor;
   201         this.javafx = javafx;
   207         this.javafx = javafx;
       
   208         this.docEnv = configuration.docEnv;
       
   209         this.doclet = configuration.doclet;
   202         this.messages = configuration.getMessages();
   210         this.messages = configuration.getMessages();
   203         this.resources = configuration.getResources();
   211         this.resources = configuration.getResources();
   204         initStandardTaglets();
   212         initStandardTaglets();
   205         initStandardTagsLowercase();
   213         initStandardTagsLowercase();
   206     }
   214     }
   234      * @param fileManager the filemanager to load classes and resources.
   242      * @param fileManager the filemanager to load classes and resources.
   235      * @param tagletPath  the path to the class representing the custom tag.
   243      * @param tagletPath  the path to the class representing the custom tag.
   236      */
   244      */
   237     public void addCustomTag(String classname, JavaFileManager fileManager, String tagletPath) {
   245     public void addCustomTag(String classname, JavaFileManager fileManager, String tagletPath) {
   238         try {
   246         try {
   239             ClassLoader tagClassLoader = null;
   247             ClassLoader tagClassLoader;
   240             if (!fileManager.hasLocation(TAGLET_PATH)) {
   248             if (!fileManager.hasLocation(TAGLET_PATH)) {
   241                 List<File> paths = new ArrayList<>();
   249                 List<File> paths = new ArrayList<>();
   242                 if (tagletPath != null) {
   250                 if (tagletPath != null) {
   243                     for (String pathname : tagletPath.split(File.pathSeparator)) {
   251                     for (String pathname : tagletPath.split(File.pathSeparator)) {
   244                         paths.add(new File(pathname));
   252                         paths.add(new File(pathname));
   247                 if (fileManager instanceof StandardJavaFileManager) {
   255                 if (fileManager instanceof StandardJavaFileManager) {
   248                     ((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, paths);
   256                     ((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, paths);
   249                 }
   257                 }
   250             }
   258             }
   251             tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
   259             tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
   252             Class<?> customTagClass = tagClassLoader.loadClass(classname);
   260             Class<? extends jdk.javadoc.doclet.Taglet> customTagClass =
   253             Object instance = customTagClass.getConstructor().newInstance();
   261                     tagClassLoader.loadClass(classname).asSubclass(jdk.javadoc.doclet.Taglet.class);
   254             Taglet newLegacy = new UserTaglet((jdk.javadoc.doclet.Taglet)instance);
   262             jdk.javadoc.doclet.Taglet instance = customTagClass.getConstructor().newInstance();
       
   263             instance.init(docEnv, doclet);
       
   264             Taglet newLegacy = new UserTaglet(instance);
   255             String tname = newLegacy.getName();
   265             String tname = newLegacy.getName();
   256             Taglet t = customTags.get(tname);
   266             Taglet t = customTags.get(tname);
   257             if (t != null) {
   267             if (t != null) {
   258                 customTags.remove(tname);
   268                 customTags.remove(tname);
   259             }
   269             }