Class Environment
- All Implemented Interfaces:
Constants
,RuntimeConstants
- Direct Known Subclasses:
BatchEnvironment
,ContextEnvironment
,ImportEnvironment
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static boolean
private static boolean
Debug tracing.private static boolean
Enable diagnostic dump of class modifier bits, including those in InnerClasses attributes, as they are written to the classfile.(package private) String
External character encoding name(package private) Environment
The actual environment to which everything is forwarded.(package private) Object
The object that is currently being parsed/compiled.Fields inherited from interface org.glassfish.rmic.tools.java.Constants
ABSTRACT, ACCM_CLASS, ACCM_FIELD, ACCM_INNERCLASS, ACCM_MEMBER, ACCM_METHOD, ADD, AND, ARRAY, ARRAYACCESS, ASGADD, ASGBITAND, ASGBITOR, ASGBITXOR, ASGDIV, ASGLSHIFT, ASGMUL, ASGREM, ASGRSHIFT, ASGSUB, ASGURSHIFT, ASSIGN, ATT_ALL, ATT_ALLCLASSES, ATT_CODE, BITAND, BITNOT, BITOR, BITXOR, BOOLEAN, BOOLEANVAL, BREAK, BYTE, BYTEVAL, CASE, CAST, CATCH, CHAR, CHARVAL, CLASS, COLON, COMMA, COMMENT, COND, CONST, CONTINUE, CONVERT, CS_BINARY, CS_CHECKED, CS_COMPILED, CS_NOTFOUND, CS_PARSED, CS_SOURCE, CS_UNDECIDED, CS_UNDEFINED, CT_BLOCK, CT_BRANCH_FALSE, CT_BRANCH_TRUE, CT_CASE, CT_FIKT_METHOD, CT_FIKT_RET, CT_FIRST_KIND, CT_LAST_KIND, CT_METHOD, CT_SWITH_WO_DEF, DEC, DECLARATION, DEFAULT, DIV, DO, DOUBLE, DOUBLEVAL, ELSE, EQ, ERROR, EXPR, EXPRESSION, EXTENDS, F_COVDATA, F_COVERAGE, F_DEBUG_LINES, F_DEBUG_SOURCE, F_DEBUG_VARS, F_DEPENDENCIES, F_DEPRECATION, F_DUMP, F_ERRORSREPORTED, F_OPT, F_OPT_INTERCLASS, F_PRINT_DEPENDENCIES, F_STRICTDEFAULT, F_VERBOSE, F_VERSION12, F_WARNINGS, FALSE, FIELD, FINAL, FINALLY, FLOAT, FLOATVAL, FOR, GE, GOTO, GT, idAppend, idClass, idClassInit, idClone, idCode, idConstantValue, idCoverageTable, idDeprecated, idDocumentation, IDENT, idExceptions, idFinallyReturnValue, idGetClass, idInit, idInnerClasses, idJavaIoSerializable, idJavaLang, idJavaLangClass, idJavaLangCloneable, idJavaLangError, idJavaLangException, idJavaLangObject, idJavaLangRuntimeException, idJavaLangString, idJavaLangStringBuffer, idJavaLangThrowable, idLength, idLineNumberTable, idLocalVariableTable, idNew, idNull, idSourceFile, idStar, idSuper, idSynthetic, idThis, idToString, idTYPE, idValueOf, IF, IMPLEMENTS, IMPORT, INC, INLINEMETHOD, INLINENEWINSTANCE, INLINERETURN, INSTANCEOF, INT, INTERFACE, INTVAL, LBRACE, LE, LENGTH, LONG, LONGVAL, LPAREN, LSHIFT, LSQBRACKET, LT, M_ABSTRACT, M_ANONYMOUS, M_DEPRECATED, M_FINAL, M_INLINEABLE, M_INTERFACE, M_LOCAL, M_NATIVE, M_PRIVATE, M_PROTECTED, M_PUBLIC, M_STATIC, M_STRICTFP, M_SYNCHRONIZED, M_SYNTHETIC, M_TRANSIENT, M_VOLATILE, MAXFILESIZE, MAXLINENUMBER, METHOD, MM_CLASS, MM_FIELD, MM_MEMBER, MM_METHOD, MUL, NATIVE, NE, NEG, NEW, NEWARRAY, NEWFROMNAME, NEWINSTANCE, NOT, NULL, opNames, opPrecedence, OR, PACKAGE, paraDeprecated, POS, POSTDEC, POSTINC, PREDEC, prefixAccess, prefixArray, prefixClass, prefixLoc, prefixThis, prefixVal, PREINC, PRIVATE, PROTECTED, PUBLIC, QUESTIONMARK, RBRACE, REM, RETURN, RPAREN, RSHIFT, RSQBRACKET, SEMICOLON, SHORT, SHORTVAL, SIG_INNERCLASS, SIGC_INNERCLASS, STAT, STATIC, STRICTFP, STRINGVAL, SUB, SUPER, SWITCH, SYNCHRONIZED, TC_ARRAY, TC_BOOLEAN, TC_BYTE, TC_CHAR, TC_CLASS, TC_DOUBLE, TC_ERROR, TC_FLOAT, TC_INT, TC_LONG, TC_METHOD, TC_NULL, TC_SHORT, TC_VOID, THIS, THROW, THROWS, TM_ARRAY, TM_BOOLEAN, TM_BYTE, TM_CHAR, TM_CLASS, TM_DOUBLE, TM_ERROR, TM_FLOAT, TM_INT, TM_INT32, TM_INTEGER, TM_LONG, TM_METHOD, TM_NULL, TM_NUM32, TM_NUM64, TM_NUMBER, TM_REAL, TM_REFERENCE, TM_SHORT, TM_VOID, tracing, TRANSIENT, TRUE, TRY, TYPE, URSHIFT, VARDECLARATION, VOID, VOLATILE, WHEREOFFSETBITS, WHILE
Fields inherited from interface org.glassfish.rmic.tools.java.RuntimeConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_CLASS, CONSTANT_DOUBLE, CONSTANT_FIELD, CONSTANT_FLOAT, CONSTANT_INTEGER, CONSTANT_INTERFACEMETHOD, CONSTANT_INVOKEDYNAMIC, CONSTANT_LONG, CONSTANT_METHOD, CONSTANT_METHODHANDLE, CONSTANT_METHODTYPE, CONSTANT_NAMEANDTYPE, CONSTANT_STRING, CONSTANT_UNICODE, CONSTANT_UTF8, JAVA_DEFAULT_MINOR_VERSION, JAVA_DEFAULT_VERSION, JAVA_MAGIC, JAVA_MAX_SUPPORTED_MINOR_VERSION, JAVA_MAX_SUPPORTED_VERSION, JAVA_MIN_SUPPORTED_VERSION, opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_athrow, opc_baload, opc_bastore, opc_bipush, opc_breakpoint, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dead, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokedynamic, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_label, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_try, opc_wide, opcLengths, opcNames, SIG_ARRAY, SIG_BOOLEAN, SIG_BYTE, SIG_CHAR, SIG_CLASS, SIG_DOUBLE, SIG_ENDCLASS, SIG_ENDMETHOD, SIG_FLOAT, SIG_INT, SIG_LONG, SIG_METHOD, SIG_PACKAGE, SIG_SHORT, SIG_VOID, SIGC_ARRAY, SIGC_BOOLEAN, SIGC_BYTE, SIGC_CHAR, SIGC_CLASS, SIGC_DOUBLE, SIGC_ENDCLASS, SIGC_ENDMETHOD, SIGC_FLOAT, SIGC_INT, SIGC_LONG, SIGC_METHOD, SIGC_PACKAGE, SIGC_SHORT, SIGC_VOID, T_BOOLEAN, T_BYTE, T_CHAR, T_CLASS, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check if a class exists (without actually loading it).final boolean
classExists
(Type t) final boolean
covdata()
get flag of generation the coverage data filefinal boolean
coverage()
get coverage flagfinal boolean
Debugging flags.final boolean
final boolean
static void
debugOutput
(Object msg) final boolean
Dependenciesfinal boolean
Deprecation warnings are enabled.void
void
void
final boolean
dump()
Dump debugging stuffboolean
final void
final void
final void
final void
void
Issue an error.boolean
explicitCast
(Type from, Type to) Return true if an explicit cast from this type to the given type is allowed.Return character encoding nameReturn a class declaration given a fully qualified class name.Return a class declaration given a type.final ClassDefinition
Return a class definition given a fully qualified class name.final ClassDefinition
Return a class definition given a type.Return the coverage data fileint
getFlags()
Flags.Get the imports used to resolve class names.short
Return major version to use in generated class files.short
Return minor version to use in generated class files.getPackage
(Identifier pkg) Get the package path for a packagefinal ClassDefinition
getQualifiedClassDefinition
(long where, Identifier nm, ClassDefinition ctxClass, boolean isExtends) Like 'getClassDefinition(env)', but check access on each component.final Object
Return the source of the environment (ie: the thing being compiled/parsed).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 argumentsboolean
Tells whether an Identifier refers to a package which should be exempt from the "exists" check in Imports#resolve().boolean
isMoreSpecific
(MemberDefinition best, MemberDefinition other) Returns true if "best" is in every argument at least as good as "other"boolean
isMoreSpecific
(Type from, Type to) Returns true if "from" is a more specific type than "to"void
Load the definition of a class.makeClassDefinition
(Environment origEnv, long where, IdentifierToken name, String doc, int modifiers, IdentifierToken superClass, IdentifierToken[] interfaces, ClassDefinition outerClass) Create a new class.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
void
Output a string.final boolean
Print Dependencies to stdoutboolean
resolve
(long where, ClassDefinition c, Type t) Resolve a type.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.private boolean
resolveByName
(long where, ClassDefinition c, Identifier nm, boolean isExtends) boolean
resolveExtendsByName
(long where, ClassDefinition c, Identifier nm) resolveName
(Identifier name) Resolve a class name, using only package and import directives.resolveNames
(ClassDefinition c, Type t, boolean synth) Resolve the names within a type, returning the adjusted type.final Identifier
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 namevoid
shutdown()
Release resources, if any.final boolean
Floating point is strict by defaultfinal boolean
verbose()
Verbosefinal boolean
Do not support virtual machines before version 1.2.final boolean
warnings()
Verbose
-
Field Details
-
env
Environment envThe actual environment to which everything is forwarded. -
encoding
String encodingExternal character encoding name -
source
Object sourceThe object that is currently being parsed/compiled. It is either a file name (String) or a field (MemberDefinition) or a class (ClassDeclaration or ClassDefinition). -
debugging
private static boolean debugging -
dependtrace
private static boolean dependtraceDebug tracing. Currently, this code is used only for tracing the loading and checking of classes, particularly the demand-driven aspects. This code should probably be integrated with 'debugOutput' above, but we need to give more thought to the issue of classifying debugging messages and allowing those only those of interest to be enabled. Calls to these methods are generally conditioned on the final variable 'Constants.tracing', which allows the calls to be completely omitted in a production release to avoid space and time overhead. -
dumpmodifiers
private static boolean dumpmodifiersEnable diagnostic dump of class modifier bits, including those in InnerClasses attributes, as they are written to the classfile. In the future, may also enable dumping field and method modifiers.
-
-
Constructor Details
-
Environment
-
Environment
public Environment()
-
-
Method Details
-
isExemptPackage
Tells whether an Identifier refers to a package which should be exempt from the "exists" check in Imports#resolve(). -
getClassDeclaration
Return a class declaration given a fully qualified class name. -
getClassDefinition
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
-
getClassDeclaration
Return a class declaration given a type. Only works for class types. -
getClassDefinition
Return a class definition given a type. Only works for class types.- Throws:
ClassNotFound
-
classExists
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
-
getPackage
Get the package path for a package- Throws:
IOException
-
loadDefinition
Load the definition of a class. -
getSource
Return the source of the environment (ie: the thing being compiled/parsed). -
resolve
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
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. -
resolveExtendsByName
-
resolveByName
-
getQualifiedClassDefinition
public final ClassDefinition getQualifiedClassDefinition(long where, Identifier nm, ClassDefinition ctxClass, boolean isExtends) throws ClassNotFound 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
-
resolveNames
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)
-
resolveName
Resolve a class name, using only package and import directives. Report no errors. -
resolvePackageQualifiedName
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.
-
resolve
Resolve a class name, using only package and import directives.- Throws:
ClassNotFound
-
getImports
Get the imports used to resolve class names. -
makeClassDefinition
public ClassDefinition makeClassDefinition(Environment origEnv, long where, IdentifierToken name, String doc, int modifiers, IdentifierToken superClass, IdentifierToken[] interfaces, ClassDefinition outerClass) Create a new class. -
makeMemberDefinition
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. -
isApplicable
Returns true if the given method is applicable to the given arguments- Throws:
ClassNotFound
-
isMoreSpecific
Returns true if "best" is in every argument at least as good as "other"- Throws:
ClassNotFound
-
isMoreSpecific
Returns true if "from" is a more specific type than "to"- Throws:
ClassNotFound
-
implicitCast
Return true if an implicit cast from this type to the given type is allowed.- Throws:
ClassNotFound
-
explicitCast
Return true if an explicit cast from this type to the given type is allowed.- Throws:
ClassNotFound
-
getFlags
public int getFlags()Flags. -
debug_lines
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). -
debug_vars
public final boolean debug_vars() -
debug_source
public final boolean debug_source() -
opt
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. -
opt_interclass
public final boolean opt_interclass() -
verbose
public final boolean verbose()Verbose -
dump
public final boolean dump()Dump debugging stuff -
warnings
public final boolean warnings()Verbose -
dependencies
public final boolean dependencies()Dependencies -
print_dependencies
public final boolean print_dependencies()Print Dependencies to stdout -
deprecation
public final boolean deprecation()Deprecation warnings are enabled. -
version12
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. -
strictdefault
public final boolean strictdefault()Floating point is strict by default -
shutdown
public void shutdown()Release resources, if any. -
error
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) -
error
-
error
-
error
-
error
-
output
Output a string. This can either be an error message or something for debugging. This should be used instead of println. -
debugOutput
-
setCharacterEncoding
set character encoding name -
getCharacterEncoding
Return character encoding name -
getMajorVersion
public short getMajorVersion()Return major version to use in generated class files. -
getMinorVersion
public short getMinorVersion()Return minor version to use in generated class files. -
coverage
public final boolean coverage()get coverage flag -
covdata
public final boolean covdata()get flag of generation the coverage data file -
getcovFile
Return the coverage data file -
dtEnter
-
dtExit
-
dtEvent
-
dumpModifiers
public boolean dumpModifiers()
-