public class

Environment

extends Object
implements Constants
java.lang.Object
   ↳ sun.tools.java.Environment
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

[Expand]
Inherited Constants
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
[Expand]
Inherited Fields
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Public Constructors
Environment(Environment env, Object source)
Environment()
Public Methods
boolean classExists(Identifier nm)
Check if a class exists (without actually loading it).
final boolean classExists(Type t)
final boolean covdata()
get flag of generation the coverage data file
final boolean coverage()
get coverage flag
static void debugOutput(Object msg)
final boolean debug_lines()
Debugging flags.
final boolean debug_source()
final boolean debug_vars()
final boolean dependencies()
Dependencies
final boolean deprecation()
Deprecation warnings are enabled.
void dtEnter(String s)
void dtEvent(String s)
void dtExit(String s)
final boolean dump()
Dump debugging stuff
boolean dumpModifiers()
final void error(long where, String err)
void error(Object source, long where, String err, Object arg1, Object arg2, Object arg3)
Issue an error.
final void error(long where, String err, Object arg1, Object arg2)
final void error(long where, String err, Object arg1, Object arg2, Object arg3)
final void error(long where, String err, Object arg1)
boolean explicitCast(Type from, Type to)
Return true if an explicit cast from this type to the given type is allowed.
String getCharacterEncoding()
Return character encoding name
ClassDeclaration getClassDeclaration(Identifier nm)
Return a class declaration given a fully qualified class name.
ClassDeclaration getClassDeclaration(Type t)
Return a class declaration given a type.
final ClassDefinition getClassDefinition(Identifier nm)
Return a class definition given a fully qualified class name.
final ClassDefinition getClassDefinition(Type t)
Return a class definition given a type.
int getFlags()
Flags.
Imports getImports()
Get the imports used to resolve class names.
short getMajorVersion()
Return major version to use in generated class files.
short getMinorVersion()
Return minor version to use in generated class files.
Package getPackage(Identifier pkg)
Get the package path for a package
final ClassDefinition getQualifiedClassDefinition(long where, Identifier nm, ClassDefinition ctxClass, boolean isExtends)
Like 'getClassDefinition(env)', but check access on each component.
final Object getSource()
Return the source of the environment (ie: the thing being compiled/parsed).
File getcovFile()
Return the coverage data file
boolean implicitCast(Type from, Type to)
Return true if an implicit cast from this type to the given type is allowed.
boolean isApplicable(MemberDefinition m, Type[] args)
Returns true if the given method is applicable to the given arguments
boolean isExemptPackage(Identifier id)
Tells whether an Identifier refers to a package which should be exempt from the "exists" check in Imports#resolve().
boolean isMoreSpecific(Type from, Type to)
Returns true if "from" is a more specific type than "to"
boolean isMoreSpecific(MemberDefinition best, MemberDefinition other)
Returns true if "best" is in every argument at least as good as "other"
void loadDefinition(ClassDeclaration c)
Load the definition of a class.
ClassDefinition makeClassDefinition(Environment origEnv, long where, IdentifierToken name, String doc, int modifiers, IdentifierToken superClass, IdentifierToken[] interfaces, ClassDefinition outerClass)
Create a new class.
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 boolean opt()
Optimization flags.
final boolean opt_interclass()
void output(String msg)
Output a string.
final boolean print_dependencies()
Print Dependencies to stdout
boolean resolve(long where, ClassDefinition c, Type t)
Resolve a type.
Identifier resolve(Identifier nm)
Resolve a class name, using only package and import directives.
boolean resolveByName(long where, ClassDefinition c, Identifier nm)
Given its fully-qualified name, verify that a class is defined and accessible.
boolean resolveExtendsByName(long where, ClassDefinition c, Identifier nm)
Identifier resolveName(Identifier name)
Resolve a class name, using only package and import directives.
Type resolveNames(ClassDefinition c, Type t, boolean synth)
Resolve the names within a type, returning the adjusted type.
final 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.
void setCharacterEncoding(String encoding)
set character encoding name
void shutdown()
Release resources, if any.
final boolean strictdefault()
Floating point is strict by default
final boolean verbose()
Verbose
final boolean version12()
Do not support virtual machines before version 1.2.
final boolean warnings()
Verbose
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Environment (Environment env, Object source)

public Environment ()

Public Methods

public boolean classExists (Identifier nm)

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.)

public final boolean classExists (Type t)

public final boolean covdata ()

get flag of generation the coverage data file

public final boolean coverage ()

get coverage flag

public static void debugOutput (Object msg)

public final boolean debug_lines ()

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).

public final boolean debug_source ()

public final boolean debug_vars ()

public final boolean dependencies ()

Dependencies

public final boolean deprecation ()

Deprecation warnings are enabled.

public void dtEnter (String s)

public void dtEvent (String s)

public void dtExit (String s)

public final boolean dump ()

Dump debugging stuff

public boolean dumpModifiers ()

public final void error (long where, String err)

public void error (Object source, long where, String err, Object arg1, Object arg2, Object arg3)

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)

public final void error (long where, String err, Object arg1, Object arg2)

public final void error (long where, String err, Object arg1, Object arg2, Object arg3)

public final void error (long where, String err, Object arg1)

public boolean explicitCast (Type from, Type to)

Return true if an explicit cast from this type to the given type is allowed.

Throws
ClassNotFound

public String getCharacterEncoding ()

Return character encoding name

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. Only works for class types.

public final ClassDefinition getClassDefinition (Identifier nm)

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.

Throws
ClassNotFound

public final ClassDefinition getClassDefinition (Type t)

Return a class definition given a type. Only works for class types.

Throws
ClassNotFound

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)

Get the package path for a package

Throws
IOException

public final 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. It is doubtful that calls to 'getClassDefinition(env)' are appropriate now.

Throws
ClassNotFound

public final Object getSource ()

Return the source of the environment (ie: the thing being compiled/parsed).

public File getcovFile ()

Return the coverage data file

public boolean implicitCast (Type from, Type to)

Return true if an implicit cast from this type to the given type is allowed.

Throws
ClassNotFound

public boolean isApplicable (MemberDefinition m, Type[] args)

Returns true if the given method is applicable to the given arguments

Throws
ClassNotFound

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 (Type from, Type to)

Returns true if "from" is a more specific type than "to"

Throws
ClassNotFound

public boolean isMoreSpecific (MemberDefinition best, MemberDefinition other)

Returns true if "best" is in every argument at least as good as "other"

Throws
ClassNotFound

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.

public final boolean opt ()

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.

public final boolean opt_interclass ()

public void output (String msg)

Output a string. This can either be an error message or something for debugging. This should be used instead of println.

public final boolean print_dependencies ()

Print Dependencies to stdout

public boolean resolve (long where, ClassDefinition c, Type t)

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.

public Identifier resolve (Identifier nm)

Resolve a class name, using only package and import directives.

Throws
ClassNotFound

public boolean resolveByName (long where, ClassDefinition c, Identifier nm)

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.

public boolean resolveExtendsByName (long where, ClassDefinition c, Identifier nm)

public Identifier resolveName (Identifier name)

Resolve a class name, using only package and import directives. Report no errors.

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. 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)

public final 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. 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.

public void setCharacterEncoding (String encoding)

set character encoding name

public void shutdown ()

Release resources, if any.

public final boolean strictdefault ()

Floating point is strict by default

public final boolean verbose ()

Verbose

public final boolean version12 ()

Do not support virtual machines before version 1.2. This option is not supported and is only here for testing purposes.

public final boolean warnings ()

Verbose