< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java

Print this page

  1 /*
  2  * Copyright (c) 1999, 2024, 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

 38 import javax.lang.model.SourceVersion;
 39 import javax.tools.JavaFileManager;
 40 import javax.tools.JavaFileManager.Location;
 41 import javax.tools.JavaFileObject;
 42 import javax.tools.JavaFileObject.Kind;
 43 import javax.tools.StandardJavaFileManager;
 44 import javax.tools.StandardLocation;
 45 
 46 import com.sun.tools.javac.code.Scope.WriteableScope;
 47 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 48 import com.sun.tools.javac.code.Symbol.Completer;
 49 import com.sun.tools.javac.code.Symbol.CompletionFailure;
 50 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
 51 import com.sun.tools.javac.code.Symbol.PackageSymbol;
 52 import com.sun.tools.javac.code.Symbol.TypeSymbol;
 53 import com.sun.tools.javac.comp.Annotate;
 54 import com.sun.tools.javac.file.JRTIndex;
 55 import com.sun.tools.javac.file.JavacFileManager;
 56 import com.sun.tools.javac.jvm.ClassReader;
 57 import com.sun.tools.javac.jvm.Profile;

 58 import com.sun.tools.javac.main.Option;
 59 import com.sun.tools.javac.platform.PlatformDescription;
 60 import com.sun.tools.javac.resources.CompilerProperties.Fragments;
 61 import com.sun.tools.javac.util.*;
 62 
 63 import static javax.tools.StandardLocation.*;
 64 
 65 import static com.sun.tools.javac.code.Flags.*;
 66 import static com.sun.tools.javac.code.Kinds.Kind.*;
 67 import com.sun.tools.javac.code.Symbol;
 68 import com.sun.tools.javac.code.Symbol.CompletionFailure;
 69 import com.sun.tools.javac.main.DelegatingJavaFileManager;
 70 
 71 import com.sun.tools.javac.util.Dependencies.CompletionCause;
 72 
 73 /**
 74  *  This class provides operations to locate class definitions
 75  *  from the source and class files on the paths provided to javac.
 76  *
 77  *  <p><b>This is NOT part of any supported API.
 78  *  If you write code that depends on this, you do so at your own risk.
 79  *  This code and its internal interfaces are subject to change or
 80  *  deletion without notice.</b>
 81  */
 82 public class ClassFinder {
 83     /** The context key for the class finder. */
 84     protected static final Context.Key<ClassFinder> classFinderKey = new Context.Key<>();
 85 
 86     ClassReader reader;
 87 
 88     private final Annotate annotate;

201         cacheCompletionFailure = options.isUnset("dev");
202         preferSource = "source".equals(options.get("-Xprefer"));
203         userPathsFirst = options.isSet(Option.XXUSERPATHSFIRST);
204 
205         completionFailureName =
206             options.isSet("failcomplete")
207             ? names.fromString(options.get("failcomplete"))
208             : null;
209 
210         // Temporary, until more info is available from the module system.
211         boolean useCtProps;
212         JavaFileManager fm = context.get(JavaFileManager.class);
213         if (fm instanceof DelegatingJavaFileManager delegatingJavaFileManager) {
214             fm = delegatingJavaFileManager.getBaseFileManager();
215         }
216         if (fm instanceof JavacFileManager javacFileManager) {
217             useCtProps = javacFileManager.isDefaultBootClassPath() && javacFileManager.isSymbolFileEnabled();
218         } else {
219             useCtProps = false;
220         }
221         jrtIndex = useCtProps && JRTIndex.isAvailable() ? JRTIndex.getSharedInstance() : null;







222 
223         profile = Profile.instance(context);
224         cachedCompletionFailure = new CompletionFailure(null, () -> null, dcfh);
225         cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
226     }
227 
228 
229 /* **********************************************************************
230  * Temporary ct.sym replacement
231  *
232  * The following code is a temporary substitute for the ct.sym mechanism
233  * used in JDK 6 thru JDK 8.
234  * This mechanism will eventually be superseded by the Jigsaw module system.
235  ***********************************************************************/
236 
237     /**
238      * Returns any extra flags for a class symbol.
239      * This information used to be provided using private annotations
240      * in the class file in ct.sym; in time, this information will be
241      * available from the module system.

  1 /*
  2  * Copyright (c) 1999, 2025, 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

 38 import javax.lang.model.SourceVersion;
 39 import javax.tools.JavaFileManager;
 40 import javax.tools.JavaFileManager.Location;
 41 import javax.tools.JavaFileObject;
 42 import javax.tools.JavaFileObject.Kind;
 43 import javax.tools.StandardJavaFileManager;
 44 import javax.tools.StandardLocation;
 45 
 46 import com.sun.tools.javac.code.Scope.WriteableScope;
 47 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 48 import com.sun.tools.javac.code.Symbol.Completer;
 49 import com.sun.tools.javac.code.Symbol.CompletionFailure;
 50 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
 51 import com.sun.tools.javac.code.Symbol.PackageSymbol;
 52 import com.sun.tools.javac.code.Symbol.TypeSymbol;
 53 import com.sun.tools.javac.comp.Annotate;
 54 import com.sun.tools.javac.file.JRTIndex;
 55 import com.sun.tools.javac.file.JavacFileManager;
 56 import com.sun.tools.javac.jvm.ClassReader;
 57 import com.sun.tools.javac.jvm.Profile;
 58 import com.sun.tools.javac.main.JavaCompiler;
 59 import com.sun.tools.javac.main.Option;

 60 import com.sun.tools.javac.resources.CompilerProperties.Fragments;
 61 import com.sun.tools.javac.util.*;
 62 
 63 import static javax.tools.StandardLocation.*;
 64 
 65 import static com.sun.tools.javac.code.Flags.*;
 66 import static com.sun.tools.javac.code.Kinds.Kind.*;
 67 

 68 import com.sun.tools.javac.main.DelegatingJavaFileManager;
 69 
 70 import com.sun.tools.javac.util.Dependencies.CompletionCause;
 71 
 72 /**
 73  *  This class provides operations to locate class definitions
 74  *  from the source and class files on the paths provided to javac.
 75  *
 76  *  <p><b>This is NOT part of any supported API.
 77  *  If you write code that depends on this, you do so at your own risk.
 78  *  This code and its internal interfaces are subject to change or
 79  *  deletion without notice.</b>
 80  */
 81 public class ClassFinder {
 82     /** The context key for the class finder. */
 83     protected static final Context.Key<ClassFinder> classFinderKey = new Context.Key<>();
 84 
 85     ClassReader reader;
 86 
 87     private final Annotate annotate;

200         cacheCompletionFailure = options.isUnset("dev");
201         preferSource = "source".equals(options.get("-Xprefer"));
202         userPathsFirst = options.isSet(Option.XXUSERPATHSFIRST);
203 
204         completionFailureName =
205             options.isSet("failcomplete")
206             ? names.fromString(options.get("failcomplete"))
207             : null;
208 
209         // Temporary, until more info is available from the module system.
210         boolean useCtProps;
211         JavaFileManager fm = context.get(JavaFileManager.class);
212         if (fm instanceof DelegatingJavaFileManager delegatingJavaFileManager) {
213             fm = delegatingJavaFileManager.getBaseFileManager();
214         }
215         if (fm instanceof JavacFileManager javacFileManager) {
216             useCtProps = javacFileManager.isDefaultBootClassPath() && javacFileManager.isSymbolFileEnabled();
217         } else {
218             useCtProps = false;
219         }
220         if (useCtProps && JRTIndex.isAvailable()) {
221             Preview preview = Preview.instance(context);
222             JavaCompiler comp = JavaCompiler.instance(context);
223             jrtIndex = JRTIndex.instance(preview.isEnabled());
224             comp.closeables = comp.closeables.prepend(jrtIndex);
225         } else {
226             jrtIndex = null;
227         }
228 
229         profile = Profile.instance(context);
230         cachedCompletionFailure = new CompletionFailure(null, () -> null, dcfh);
231         cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
232     }
233 
234 
235 /* **********************************************************************
236  * Temporary ct.sym replacement
237  *
238  * The following code is a temporary substitute for the ct.sym mechanism
239  * used in JDK 6 thru JDK 8.
240  * This mechanism will eventually be superseded by the Jigsaw module system.
241  ***********************************************************************/
242 
243     /**
244      * Returns any extra flags for a class symbol.
245      * This information used to be provided using private annotations
246      * in the class file in ct.sym; in time, this information will be
247      * available from the module system.
< prev index next >