DocEnvImpl.java revision 3595:81692f730015
1/* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package jdk.javadoc.internal.tool; 27 28import java.util.LinkedHashSet; 29import java.util.List; 30import java.util.Set; 31import java.util.stream.Collectors; 32 33import javax.lang.model.SourceVersion; 34import javax.lang.model.element.Element; 35import javax.lang.model.element.ModuleElement; 36import javax.lang.model.element.PackageElement; 37import javax.lang.model.element.TypeElement; 38import javax.lang.model.util.Elements; 39import javax.lang.model.util.Types; 40import javax.tools.JavaFileManager; 41 42import com.sun.source.util.DocTrees; 43import com.sun.tools.javac.code.Source; 44import jdk.javadoc.doclet.DocletEnvironment; 45 46/** 47 * This class holds the information from one run of javadoc. 48 * Particularly the packages, classes and options specified 49 * by the user. 50 * 51 * <p><b>This is NOT part of any supported API. 52 * If you write code that depends on this, you do so at your own risk. 53 * This code and its internal interfaces are subject to change or 54 * deletion without notice.</b> 55 * 56 * @author Robert Field 57 * @author Atul M Dambalkar 58 * @author Neal Gafter (rewrite) 59 */ 60public class DocEnvImpl implements DocletEnvironment { 61 62 public final ElementsTable etable; 63 64 public final ToolEnvironment toolEnv; 65 66 /** 67 * Construct a doclet environment. 68 * 69 * @param toolEnv the tool environment 70 * @param etable the includes table, providing all the information 71 * with respect to specified, included/selected elements. 72 */ 73 public DocEnvImpl(ToolEnvironment toolEnv, ElementsTable etable) { 74 this.toolEnv = toolEnv; 75 this.etable = etable; 76 } 77 78 @Override 79 public Set<ModuleElement> getIncludedModuleElements() { 80 return etable.getIncludedModuleElements(); 81 } 82 83 @Override 84 public Set<PackageElement> getIncludedPackageElements() { 85 return etable.getIncludedPackageElements(); 86 } 87 88 /** 89 * Return all TypeElements (including those inside 90 * packages) to be documented. 91 */ 92 @Override 93 public Set<TypeElement> getIncludedTypeElements() { 94 return etable.getIncludedTypeElements(); 95 } 96 97 @Override 98 public boolean isIncluded(Element e) { 99 return etable.isIncluded(e); 100 } 101 102 @Override 103 public DocTrees getDocTrees() { 104 return toolEnv.docTrees; 105 } 106 107 @Override 108 public Elements getElementUtils() { 109 return toolEnv.elements; 110 } 111 112 @Override 113 public List<Element> getSelectedElements(List<? extends Element> elements) { 114 return elements.stream() 115 .filter(e -> isIncluded(e)) 116 .collect(Collectors.<Element>toList()); 117 } 118 119 @Override 120 public Set<Element> getSpecifiedElements() { 121 Set<Element> out = new LinkedHashSet<>(); 122 out.addAll(etable.getSpecifiedModuleElements()); 123 out.addAll(etable.getSpecifiedPackageElements()); 124 out.addAll(etable.getSpecifiedTypeElements()); 125 return out; 126 } 127 128 @Override 129 public Types getTypeUtils() { 130 return toolEnv.typeutils; 131 } 132 133 @Override 134 public JavaFileManager getJavaFileManager() { 135 return toolEnv.fileManager; 136 } 137 138 @Override 139 public SourceVersion getSourceVersion() { 140 return Source.toSourceVersion(toolEnv.source); 141 } 142 143 @Override 144 public ModuleMode getModuleMode() { 145 return etable.getModuleMode(); 146 } 147} 148