001/*
002 * JDrupes MDoclet
003 * Copyright (C) 2021 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.mdoclet;
020
021import java.util.Set;
022
023import javax.lang.model.SourceVersion;
024import javax.lang.model.element.Element;
025import javax.lang.model.element.TypeElement;
026import javax.lang.model.util.Elements;
027import javax.lang.model.util.Types;
028import javax.tools.JavaFileManager;
029import javax.tools.JavaFileObject.Kind;
030
031import jdk.javadoc.internal.tool.DocEnvImpl;
032
033import com.sun.source.util.DocTrees;
034
035import jdk.javadoc.doclet.DocletEnvironment;
036
037/**
038 * Wraps the {@link DocEnvImpl} passed to the doclet for the
039 * sole purpose of inserting a wrapper for the doctrees access.
040 */
041public class MDocletEnvironment extends DocEnvImpl
042        implements DocletEnvironment {
043
044    DocletEnvironment defaultEnvironment;
045    DocTreesWrapper docTrees;
046
047    public MDocletEnvironment(MDoclet doclet, DocletEnvironment environment) {
048        super(((DocEnvImpl) environment).toolEnv,
049            ((DocEnvImpl) environment).etable);
050        this.defaultEnvironment = environment;
051        docTrees = new DocTreesWrapper(doclet, this, environment.getDocTrees());
052    }
053
054    /**
055     * Delegates to the environment passed in the constructor.
056     * 
057     * {@inheritDoc}
058     * @see jdk.javadoc.doclet.DocletEnvironment#getSpecifiedElements()
059     */
060    public Set<? extends Element> getSpecifiedElements() {
061        return defaultEnvironment.getSpecifiedElements();
062    }
063
064    /**
065     * Delegates to the environment passed in the constructor.
066     * 
067     * {@inheritDoc}
068     * @see jdk.javadoc.doclet.DocletEnvironment#getIncludedElements()
069     */
070    public Set<? extends Element> getIncludedElements() {
071        return defaultEnvironment.getIncludedElements();
072    }
073
074    /**
075     * Wraps the doctrees from the environment passed in the constructor
076     * in a {@link DocTreesWrapper}.
077     * 
078     * {@inheritDoc}
079     * @see jdk.javadoc.doclet.DocletEnvironment#getDocTrees()
080     */
081    public DocTrees getDocTrees() {
082        return docTrees;
083    }
084
085    /**
086     * Delegates to the environment passed in the constructor.
087     * 
088     * {@inheritDoc}
089     * @see jdk.javadoc.doclet.DocletEnvironment#getElementUtils()
090     */
091    public Elements getElementUtils() {
092        return defaultEnvironment.getElementUtils();
093    }
094
095    /**
096     * Delegates to the environment passed in the constructor.
097     * 
098     * {@inheritDoc}
099     * @see jdk.javadoc.doclet.DocletEnvironment#getTypeUtils()
100     */
101    public Types getTypeUtils() {
102        return defaultEnvironment.getTypeUtils();
103    }
104
105    /**
106     * Delegates to the environment passed in the constructor.
107     * 
108     * {@inheritDoc}
109     * @see jdk.javadoc.doclet.DocletEnvironment#isIncluded(javax.lang.model.element.Element)
110     */
111    public boolean isIncluded(Element e) {
112        return defaultEnvironment.isIncluded(e);
113    }
114
115    /**
116     * Delegates to the environment passed in the constructor.
117     * 
118     * {@inheritDoc}
119     * @see jdk.javadoc.doclet.DocletEnvironment#isSelected(javax.lang.model.element.Element)
120     */
121    public boolean isSelected(Element e) {
122        return defaultEnvironment.isSelected(e);
123    }
124
125    /**
126     * Delegates to the environment passed in the constructor.
127     * 
128     * {@inheritDoc}
129     * @see jdk.javadoc.doclet.DocletEnvironment#getJavaFileManager()
130     */
131    public JavaFileManager getJavaFileManager() {
132        return defaultEnvironment.getJavaFileManager();
133    }
134
135    /**
136     * Delegates to the environment passed in the constructor.
137     * 
138     * {@inheritDoc}
139     * @see jdk.javadoc.doclet.DocletEnvironment#getSourceVersion()
140     */
141    public SourceVersion getSourceVersion() {
142        return defaultEnvironment.getSourceVersion();
143    }
144
145    /**
146     * Delegates to the environment passed in the constructor.
147     * 
148     * @return the module mode
149     * @see jdk.javadoc.doclet.DocletEnvironment#getModuleMode()
150     */
151    public ModuleMode getModuleMode() {
152        return defaultEnvironment.getModuleMode();
153    }
154
155    /**
156     * Delegates to the environment passed in the constructor.
157     * 
158     * {@inheritDoc}
159     * @see jdk.javadoc.doclet.DocletEnvironment#getFileKind(javax.lang.model.element.TypeElement)
160     */
161    public Kind getFileKind(TypeElement type) {
162        return defaultEnvironment.getFileKind(type);
163    }
164
165}