< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java

Print this page




   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 
  26 package com.sun.tools.javac.model;
  27 

  28 import java.util.HashSet;
  29 import java.util.LinkedHashSet;
  30 import java.util.Map;
  31 import java.util.Set;
  32 import java.util.stream.Collectors;
  33 
  34 import javax.lang.model.AnnotatedConstruct;
  35 import javax.lang.model.SourceVersion;
  36 import javax.lang.model.element.*;
  37 import javax.lang.model.type.DeclaredType;
  38 import javax.lang.model.util.Elements;
  39 import javax.tools.JavaFileObject;
  40 import static javax.lang.model.util.ElementFilter.methodsIn;
  41 
  42 import com.sun.source.util.JavacTask;
  43 import com.sun.tools.javac.api.JavacTaskImpl;
  44 import com.sun.tools.javac.code.*;
  45 import com.sun.tools.javac.code.Attribute.Compound;
  46 import com.sun.tools.javac.code.Directive.ExportsDirective;
  47 import com.sun.tools.javac.code.Directive.ExportsFlag;


  97         JavacElements instance = context.get(JavacElements.class);
  98         if (instance == null)
  99             instance = new JavacElements(context);
 100         return instance;
 101     }
 102 
 103     protected JavacElements(Context context) {
 104         context.put(JavacElements.class, this);
 105         javaCompiler = JavaCompiler.instance(context);
 106         syms = Symtab.instance(context);
 107         modules = Modules.instance(context);
 108         names = Names.instance(context);
 109         types = Types.instance(context);
 110         enter = Enter.instance(context);
 111         resolve = Resolve.instance(context);
 112         JavacTask t = context.get(JavacTask.class);
 113         javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null;
 114         log = Log.instance(context);
 115         Source source = Source.instance(context);
 116         allowModules = source.allowModules();








 117     }
 118 
 119     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 120     public ModuleSymbol getModuleElement(CharSequence name) {
 121         ensureEntered("getModuleElement");
 122         if (modules.getDefaultModule() == syms.noModule)
 123             return null;
 124         String strName = name.toString();
 125         if (strName.equals(""))
 126             return syms.unnamedModule;
 127         return modules.getObservableModule(names.fromString(strName));
 128     }
 129 
 130     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 131     public PackageSymbol getPackageElement(CharSequence name) {
 132         return doGetPackageElement(null, name);
 133     }
 134 
 135     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 136     public PackageSymbol getPackageElement(ModuleElement module, CharSequence name) {




   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 
  26 package com.sun.tools.javac.model;
  27 
  28 import java.util.Collections;
  29 import java.util.HashSet;
  30 import java.util.LinkedHashSet;
  31 import java.util.Map;
  32 import java.util.Set;
  33 import java.util.stream.Collectors;
  34 
  35 import javax.lang.model.AnnotatedConstruct;
  36 import javax.lang.model.SourceVersion;
  37 import javax.lang.model.element.*;
  38 import javax.lang.model.type.DeclaredType;
  39 import javax.lang.model.util.Elements;
  40 import javax.tools.JavaFileObject;
  41 import static javax.lang.model.util.ElementFilter.methodsIn;
  42 
  43 import com.sun.source.util.JavacTask;
  44 import com.sun.tools.javac.api.JavacTaskImpl;
  45 import com.sun.tools.javac.code.*;
  46 import com.sun.tools.javac.code.Attribute.Compound;
  47 import com.sun.tools.javac.code.Directive.ExportsDirective;
  48 import com.sun.tools.javac.code.Directive.ExportsFlag;


  98         JavacElements instance = context.get(JavacElements.class);
  99         if (instance == null)
 100             instance = new JavacElements(context);
 101         return instance;
 102     }
 103 
 104     protected JavacElements(Context context) {
 105         context.put(JavacElements.class, this);
 106         javaCompiler = JavaCompiler.instance(context);
 107         syms = Symtab.instance(context);
 108         modules = Modules.instance(context);
 109         names = Names.instance(context);
 110         types = Types.instance(context);
 111         enter = Enter.instance(context);
 112         resolve = Resolve.instance(context);
 113         JavacTask t = context.get(JavacTask.class);
 114         javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null;
 115         log = Log.instance(context);
 116         Source source = Source.instance(context);
 117         allowModules = source.allowModules();
 118     }
 119 
 120     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 121     public Set<? extends ModuleElement> getAllModuleElements() {
 122         if (allowModules)
 123             return Collections.unmodifiableSet(modules.allModules());
 124         else
 125             return Collections.emptySet();
 126     }
 127 
 128     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 129     public ModuleSymbol getModuleElement(CharSequence name) {
 130         ensureEntered("getModuleElement");
 131         if (modules.getDefaultModule() == syms.noModule)
 132             return null;
 133         String strName = name.toString();
 134         if (strName.equals(""))
 135             return syms.unnamedModule;
 136         return modules.getObservableModule(names.fromString(strName));
 137     }
 138 
 139     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 140     public PackageSymbol getPackageElement(CharSequence name) {
 141         return doGetPackageElement(null, name);
 142     }
 143 
 144     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 145     public PackageSymbol getPackageElement(ModuleElement module, CharSequence name) {


< prev index next >