| java.lang.Object sun.tools.java.Environment
All known Subclasses: sun.tools.javac.BatchEnvironment,
Environment | public class Environment implements Constants(Code) | | This class defines the environment for a compilation.
It is used to load classes, resolve class names and
report errors. It is an abstract class, a subclass
must define implementations for some of the functions.
An environment has a source object associated with it.
This is the thing against which errors are reported, it
is usually a file name, a field or a class.
Environments can be nested to change the source object.
WARNING: The contents of this source file are not part of any
supported API. Code that depends on them does so at its own risk:
they are subject to change or removal without notice.
author: Arthur van Hoff version: 1.82, 05/05/07 |
Method Summary | |
public boolean | classExists(Identifier nm) Check if a class exists (without actually loading it). | final public boolean | classExists(Type t) | final public boolean | covdata() | final public boolean | coverage() | public static void | debugOutput(Object msg) | final public boolean | debug_lines() Debugging flags. | final public boolean | debug_source() | final public boolean | debug_vars() | final public boolean | dependencies() | final public boolean | deprecation() Deprecation warnings are enabled. | public void | dtEnter(String s) | public void | dtEvent(String s) | public void | dtExit(String s) | final public boolean | dump() | public boolean | dumpModifiers() | public void | error(Object source, long where, String err, Object arg1, Object arg2, Object arg3) Issue an error. | final public void | error(long where, String err, Object arg1, Object arg2, Object arg3) | final public void | error(long where, String err, Object arg1, Object arg2) | final public void | error(long where, String err, Object arg1) | final public void | error(long where, String err) | public boolean | explicitCast(Type from, Type to) Return true if an explicit cast from this type to
the given type is allowed. | public String | getCharacterEncoding() | public ClassDeclaration | getClassDeclaration(Identifier nm) Return a class declaration given a fully qualified class name. | public ClassDeclaration | getClassDeclaration(Type t) Return a class declaration given a type. | final public ClassDefinition | getClassDefinition(Identifier nm) Return a class definition given a fully qualified class name. | final public ClassDefinition | getClassDefinition(Type t) Return a class definition given a type. | public int | getFlags() Flags. | public Imports | getImports() Get the imports used to resolve class names. | public short | getMajorVersion() Return major version to use in generated class files. | public short | getMinorVersion() Return minor version to use in generated class files. | public Package | getPackage(Identifier pkg) | final public ClassDefinition | getQualifiedClassDefinition(long where, Identifier nm, ClassDefinition ctxClass, boolean isExtends) Like 'getClassDefinition(env)', but check access on each component.
Currently called only by 'resolve' above. | final public Object | getSource() Return the source of the environment (ie: the thing being compiled/parsed). | public File | getcovFile() | public boolean | implicitCast(Type from, Type to) Return true if an implicit cast from this type to
the given type is allowed. | public boolean | isApplicable(MemberDefinition m, Type args) | public boolean | isExemptPackage(Identifier id) Tells whether an Identifier refers to a package which should be
exempt from the "exists" check in Imports#resolve(). | public boolean | isMoreSpecific(MemberDefinition best, MemberDefinition other) | public boolean | isMoreSpecific(Type from, Type to) | public void | loadDefinition(ClassDeclaration c) Load the definition of a class. | public ClassDefinition | makeClassDefinition(Environment origEnv, long where, IdentifierToken name, String doc, int modifiers, IdentifierToken superClass, IdentifierToken interfaces, ClassDefinition outerClass) Create a new class. | public MemberDefinition | makeMemberDefinition(Environment origEnv, long where, ClassDefinition clazz, String doc, int modifiers, Type type, Identifier name, IdentifierToken argNames, IdentifierToken expIds, Object value) Create a new field. | final public boolean | opt() Optimization flags. | final public boolean | opt_interclass() | public void | output(String msg) Output a string. | final public boolean | print_dependencies() | public boolean | resolve(long where, ClassDefinition c, Type t) Resolve a type. | public Identifier | resolve(Identifier nm) Resolve a class name, using only package and import directives. | public boolean | resolveByName(long where, ClassDefinition c, Identifier nm) Given its fully-qualified name, verify that a class is defined and accessible. | public boolean | resolveExtendsByName(long where, ClassDefinition c, Identifier nm) | public Identifier | resolveName(Identifier name) Resolve a class name, using only package and import directives. | public Type | resolveNames(ClassDefinition c, Type t, boolean synth) Resolve the names within a type, returning the adjusted type.
Adjust class names to reflect scoping.
Do not report errors.
NOTE: It would be convenient to check for errors here, such as
verifying that each component of a qualified name exists and is
accessible. | final public Identifier | resolvePackageQualifiedName(Identifier name) Discover if name consists of a package prefix, followed by the
name of a class (that actually exists), followed possibly by
some inner class names. | public void | setCharacterEncoding(String encoding) | public void | shutdown() Release resources, if any. | final public boolean | strictdefault() | final public boolean | verbose() | final public boolean | version12() Do not support virtual machines before version 1.2. | final public boolean | warnings() |
encoding | String encoding(Code) | | External character encoding name
|
source | Object source(Code) | | The object that is currently being parsed/compiled.
It is either a file name (String) or a field (MemberDefinition)
or a class (ClassDeclaration or ClassDefinition).
|
Environment | public Environment()(Code) | | |
classExists | public boolean classExists(Identifier nm)(Code) | | Check if a class exists (without actually loading it).
(Since inner classes cannot in general be examined without
loading source, this method does not accept inner names.)
|
classExists | final public boolean classExists(Type t)(Code) | | |
covdata | final public boolean covdata()(Code) | | get flag of generation the coverage data file
|
coverage | final public boolean coverage()(Code) | | get coverage flag
|
debug_lines | final public boolean debug_lines()(Code) | | Debugging flags. There used to be a method debug()
that has been replaced because -g has changed meaning
(it now cooperates with -O and line number, variable
range and source file info can be toggled separately).
|
debug_source | final public boolean debug_source()(Code) | | |
debug_vars | final public boolean debug_vars()(Code) | | |
dependencies | final public boolean dependencies()(Code) | | Dependencies
|
deprecation | final public boolean deprecation()(Code) | | Deprecation warnings are enabled.
|
dump | final public boolean dump()(Code) | | Dump debugging stuff
|
dumpModifiers | public boolean dumpModifiers()(Code) | | |
error | public void error(Object source, long where, String err, Object arg1, Object arg2, Object arg3)(Code) | | Issue an error.
source - the input source, usually a file name string
offset - the offset in the source of the error
err - the error number (as defined in this interface)
arg1 - an optional argument to the error (null if not applicable)
arg2 - a second optional argument to the error (null if not applicable)
arg3 - a third optional argument to the error (null if not applicable)
|
explicitCast | public boolean explicitCast(Type from, Type to) throws ClassNotFound(Code) | | Return true if an explicit cast from this type to
the given type is allowed.
|
getCharacterEncoding | public String getCharacterEncoding()(Code) | | Return character encoding name
|
getClassDeclaration | public ClassDeclaration getClassDeclaration(Type t)(Code) | | Return a class declaration given a type. Only works for
class types.
|
getClassDefinition | final public ClassDefinition getClassDefinition(Identifier nm) throws ClassNotFound(Code) | | Return a class definition given a fully qualified class name.
Should be called only with 'internal' class names, i.e., the result
of a call to 'resolveName' or a synthetic class name.
|
getFlags | public int getFlags()(Code) | | Flags.
|
getImports | public Imports getImports()(Code) | | Get the imports used to resolve class names.
|
getMajorVersion | public short getMajorVersion()(Code) | | Return major version to use in generated class files.
|
getMinorVersion | public short getMinorVersion()(Code) | | Return minor version to use in generated class files.
|
getQualifiedClassDefinition | final public ClassDefinition getQualifiedClassDefinition(long where, Identifier nm, ClassDefinition ctxClass, boolean isExtends) throws ClassNotFound(Code) | | Like 'getClassDefinition(env)', but check access on each component.
Currently called only by 'resolve' above. It is doubtful that calls
to 'getClassDefinition(env)' are appropriate now.
|
getSource | final public Object getSource()(Code) | | Return the source of the environment (ie: the thing being compiled/parsed).
|
getcovFile | public File getcovFile()(Code) | | Return the coverage data file
|
implicitCast | public boolean implicitCast(Type from, Type to) throws ClassNotFound(Code) | | Return true if an implicit cast from this type to
the given type is allowed.
|
isExemptPackage | public boolean isExemptPackage(Identifier id)(Code) | | Tells whether an Identifier refers to a package which should be
exempt from the "exists" check in Imports#resolve().
|
isMoreSpecific | public boolean isMoreSpecific(Type from, Type to) throws ClassNotFound(Code) | | Returns true if "from" is a more specific type than "to"
|
opt | final public boolean opt()(Code) | | Optimization flags. There used to be a method optimize()
that has been replaced because -O has changed meaning in
javac to be replaced with -O and -O:interclass.
|
opt_interclass | final public boolean opt_interclass()(Code) | | |
output | public void output(String msg)(Code) | | Output a string. This can either be an error message or something
for debugging. This should be used instead of println.
|
print_dependencies | final public boolean print_dependencies()(Code) | | Print Dependencies to stdout
|
resolve | public boolean resolve(long where, ClassDefinition c, Type t)(Code) | | Resolve a type. Make sure that all the classes referred to by
the type have a definition. Report errors. Return true if
the type is well-formed. Presently used for types appearing
in member declarations, which represent named types internally as
qualified identifiers. Type names appearing in local variable
declarations and within expressions are represented as identifier
or field expressions, and are resolved by 'toType', which delegates
handling of the non-inner portion of the name to this method.
In 'toType', the various stages of qualification are represented by
separate AST nodes. Here, we are given a single identifier which
contains the entire qualification structure. It is not possible in
general to set the error location to the exact position of a component
that is in error, so an error message must refer to the entire qualified
name. An attempt to keep track of the string length of the components of
the name and to offset the location accordingly fails because the initial
prefix of the name may have been rewritten by an earlier call to
'resolveName'. See 'SourceMember.resolveTypeStructure'. The situation
is actually even worse than this, because only a single location is
passed in for an entire declaration, which may contain many type names.
All error messages are thus poorly localized. These checks should be
done while traversing the parse tree for the type, not the type descriptor.
DESIGN NOTE:
As far as I can tell, the two-stage resolution of names represented in
string form is an artifact of the late implementation of inner classes
and the use of mangled names internally within the compiler. All
qualified names should have their hiearchical structure made explicit
in the parse tree at the phase at which they are presented for static
semantic checking. This would affect class names appearing in 'extends',
'implements', and 'throws' clauses, as well as in member declarations.
|
resolveByName | public boolean resolveByName(long where, ClassDefinition c, Identifier nm)(Code) | | Given its fully-qualified name, verify that a class is defined and accessible.
Used to check components of qualified names in contexts where a class is expected.
Like 'resolve', but is given a single type name, not a type descriptor.
|
resolveName | public Identifier resolveName(Identifier name)(Code) | | Resolve a class name, using only package and import directives.
Report no errors.
|
resolveNames | public Type resolveNames(ClassDefinition c, Type t, boolean synth)(Code) | | Resolve the names within a type, returning the adjusted type.
Adjust class names to reflect scoping.
Do not report errors.
NOTE: It would be convenient to check for errors here, such as
verifying that each component of a qualified name exists and is
accessible. Why must this be done in a separate phase?
If the 'synth' argument is true, indicating that the member whose
type is being resolved is synthetic, names are resolved with respect
to the package scope. (Fix for 4097882)
|
resolvePackageQualifiedName | final public Identifier resolvePackageQualifiedName(Identifier name)(Code) | | Discover if name consists of a package prefix, followed by the
name of a class (that actually exists), followed possibly by
some inner class names. If we can't find a class that exists,
return the name unchanged.
This routine is used after a class name fails to
be resolved by means of imports or inner classes.
However, import processing uses this routine directly,
since import names must be exactly qualified to start with.
|
setCharacterEncoding | public void setCharacterEncoding(String encoding)(Code) | | set character encoding name
|
shutdown | public void shutdown()(Code) | | Release resources, if any.
|
strictdefault | final public boolean strictdefault()(Code) | | Floating point is strict by default
|
verbose | final public boolean verbose()(Code) | | Verbose
|
version12 | final public boolean version12()(Code) | | Do not support virtual machines before version 1.2.
This option is not supported and is only here for testing purposes.
|
warnings | final public boolean warnings()(Code) | | Verbose
|
|
|