/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This class represents an Java class as it is read from
* an Java source file.
*
* 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.
*/
public
/**
* The toplevel environment, shared with the parser
*/
/**
* The default constructor
*/
/**
* The constant pool
*/
/**
* The list of class dependencies
*/
/**
* The field used to represent "this" in all of my code.
*/
/**
* Last token of class, as reported by parser.
*/
long endPosition;
/**
* Access methods for constructors are distinguished from
* the constructors themselves by a dummy first argument.
* A unique type used for this purpose and shared by all
* constructor access methods within a package-member class is
* maintained here.
* <p>
* This field is null except in an outermost class containing
* one or more classes needing such an access method.
*/
/**
* Constructor
*/
this.toplevelEnv = env;
this.documentation = documentation;
this.modifiers |= M_DEPRECATED;
}
// Check for a package level class which is declared static.
}
// Inner classes cannot be static, nor can they be interfaces
// (which are implicitly static). Static classes and interfaces
// can only occur as top-level entities.
//
// Note that we do not have to check for local classes declared
// to be static (this is currently caught by the parser) but
// we check anyway in case the parser is modified to allow this.
if (isInterface()) {
} else if (isStatic()) {
if (innerClassMember != null) {
}
}
}
}
this.modifiers &=~ M_PROTECTED;
}
/*----*
if ((isPublic() || isProtected()) && isInsideLocal()) {
env.error(where, "warn.public.local.class", this);
}
*----*/
// maybe define an uplevel "A.this" current instance field
if (!isTopLevel() && !isLocal()) {
}
// Set simple, unmangled local name for a local or anonymous class.
// NOTE: It would be OK to do this unconditionally, as null is the
// correct value for a member (non-local) class.
// Check for inner class with same simple name as one of
// its enclosing classes. Note that 'getLocalName' returns
// the simple, unmangled source-level name of any class.
// The previous version of this code was not careful to avoid
// mangled local class names. This version fixes 4047746.
// Test above suppresses error for nested anonymous classes,
// which have an internal "name", but are not named in source code.
}
}
}
/**
* Return last position in this class.
* @see #getWhere
*/
public long getEndPosition() {
return endPosition;
}
this.endPosition = endPosition;
}
// JCOV
/**
* Return absolute name of source file
*/
return AbsName;
}
//end JCOV
/**
* Return imports
*/
return toplevelEnv.getImports();
}
/**
* Find or create my "this" argument, which is used for all methods.
*/
}
return thisArg;
}
/**
* Add a dependency
*/
}
// If doing -xdepend option, save away list of class dependencies
// making sure to NOT include duplicates or the class we are in
// (Hashtable's put() makes sure we don't have duplicates)
}
}
/**
* Add a field (check it first)
*/
// Make sure the access permissions are self-consistent:
case M_PUBLIC:
case M_PRIVATE:
case M_PROTECTED:
case 0:
break;
default:
// Cut out the more restrictive modifier(s):
if (f.isPublic()) {
} else {
}
break;
}
// Note exemption for synthetic members below.
if (f.isMethod()) {
f.subModifiers(M_STATIC);
} else if (f.isVariable()) {
if (!f.isFinal() || f.isBlankFinal()) {
f.subModifiers(M_STATIC);
}
// Even if a static passes this test, there is still another
// check in 'SourceMember.check'. The check is delayed so
// that the initializer may be inspected more closely, using
// 'isConstant()'. Part of fix for 4095568.
} else {
// Static inner classes are diagnosed in 'SourceClass.<init>'.
f.subModifiers(M_STATIC);
}
}
if (f.isMethod()) {
if (f.isConstructor()) {
if (f.getClassDefinition().isInterface()) {
return;
}
if (f.isNative() || f.isAbstract() ||
}
} else if (f.isInitializer()) {
if (f.getClassDefinition().isInterface()) {
return;
}
}
// f is not allowed to return an array of void
}
if (f.getClassDefinition().isInterface() &&
}
if (f.isTransient()) {
}
if (f.isVolatile()) {
}
if (f.isAbstract()) {
if (f.isPrivate()) {
}
if (f.isStatic()) {
f.subModifiers(M_STATIC);
}
if (f.isFinal()) {
f.subModifiers(M_FINAL);
}
if (f.isNative()) {
f.subModifiers(M_NATIVE);
}
if (f.isSynchronized()) {
}
}
if (f.isAbstract() || f.isNative()) {
}
} else {
if (f.isConstructor()) {
} else {
}
}
}
// arguments can be null if this is an implicit abstract method
if (arg instanceof MemberDefinition) {
}
// (arg should be an Identifier now)
|| argTypes[i].isVoidArray()) {
}
}
}
} else if (f.isInnerClass()) {
if (f.isVolatile() ||
}
// same check as for fields, below:
if (f.getClassDefinition().isInterface() &&
(f.isPrivate() || f.isProtected())) {
f.addModifiers(M_PUBLIC);
// Fix up the class itself to agree with
// the inner-class member.
ClassDefinition c = f.getInnerClass();
c.addModifiers(M_PUBLIC);
}
} else {
// REMIND: set type to error
return;
}
}
if (f.isStrict()) {
}
if (f.isTransient() && isInterface()) {
}
}
f.subModifiers(M_FINAL);
}
if (f.getClassDefinition().isInterface() &&
(f.isPrivate() || f.isProtected())) {
f.addModifiers(M_PUBLIC);
}
}
// Do not check for repeated methods here: Types are not yet resolved.
if (!f.isInitializer()) {
return;
!f.getInnerClass().isLocal() &&
// Found a duplicate inner-class member.
// Duplicate local classes are detected in
// 'VarDeclarationStatement.checkDeclaration'.
return;
}
}
}
}
/**
* Create an environment suitable for checking this class.
* Make sure the source and imports are set right.
* Make sure the environment contains no context information.
* (Actually, throw away env altogether and use toplevelEnv instead.)
*/
// In some cases, we go to some trouble to create the 'env' argument
// that is discarded. We should remove the 'env' argument entirely
// as well as the vestigial code that supports it. See comments on
// 'newEnvironment' in 'checkInternal' below.
return new Environment(toplevelEnv, this);
}
/**
* A source class never reports deprecation, since the compiler
* allows access to deprecated features that are being compiled
* in the same job.
*/
return false;
}
/**
* See if the source file of this class is right.
* @see ClassDefinition#noteUsedBy
*/
// If this class is not public, watch for cross-file references.
ClassDefinition def = this;
while (def.isInnerClass()) {
}
return; // already checked
}
while (ref.isInnerClass()) {
}
return; // intra-file reference
}
}
/**
* Check this class and all its fields.
*/
if (isInsideLocal()) {
// An inaccessible class gets checked when the surrounding
// block is checked.
// QUERY: Should this case ever occur?
// What would invoke checking of a local class aside from
// checking the surrounding method body?
getOuterClass().getName());
} else {
if (isInnerClass()) {
getOuterClass().getName());
// Make sure the outer is checked first.
}
if (tracing)
// drop vset here
}
}
// Check this class now, if it has not yet been checked.
// Cf. Main.compile(). Perhaps this code belongs there somehow.
// Set it first to avoid vicious circularity:
c.setDefinition(this, CS_CHECKED);
}
}
throws ClassNotFound {
}
// Save context enclosing class for later access
// by 'ClassDefinition.resolveName.'
classContext = ctx;
// At present, the call to 'newEnvironment' is not needed.
// The incoming environment to 'basicCheck' is always passed to
// 'setupEnv', which discards it completely. This is also the
// only call to 'newEnvironment', which is now apparently dead code.
// Validate access for all inner-class components
// of a qualified name, not just the last one, which
// is checked below. Yes, this is a dirty hack...
// Much of this code was cribbed from 'checkSupers'.
// Part of fix for 4094658.
}
// Error localization fails here if interfaces were
// elided during error recovery from an invalid one.
if (interfaceIds != null
}
}
// Does the name already exist in an imported package?
// See JLS 8.1 for the precise rules.
if (!isInnerClass() && !isInsideLocal()) {
// Discard package qualification for the import checks.
try {
// We want this to throw a ClassNotFound exception
} catch (AmbiguousClass e) {
// At least one of e.name1 and e.name2 must be different
} catch (ClassNotFound e) {
// we want this to happen
}
// Make sure that no package with the same fully qualified
// name exists. This is required by JLS 7.1. We only need
// to perform this check for top level classes -- it isn't
// necessary for inner classes. (bug 4101529)
//
// This change has been backed out because, on WIN32, it
// failed to distinguish between java.awt.event and
// java.awt.Event when looking for a directory. We will
// add this back in later.
//
// try {
// if (env.getPackage(nm).exists()) {
// env.error(where, "class.package.conflict", nm);
// }
// } catch (java.io.IOException ee) {
// env.error(where, "io.exception.package", nm);
// }
// Make sure it was defined in the right file
if (isPublic()) {
}
}
return vset;
}
private boolean sourceFileChecked = false;
/**
* See if the source file of this class is of the right name.
*/
// one error per offending class is sufficient
if (sourceFileChecked) return;
sourceFileChecked = true;
if (isPublic()) {
} else {
}
}
}
// Set true if superclass (but not necessarily superinterfaces) have
// been checked. If the superclass is still unresolved, then an error
// message should have been issued, and we assume that no further
// resolution is possible.
private boolean supersChecked = false;
/**
* Overrides 'ClassDefinition.getSuperClass'.
*/
// Superclass may fail to be set because of error recovery,
// so resolve types here only if 'checkSupers' has not yet
// completed its checks on the superclass.
// QUERY: Can we eliminate the need to resolve superclasses on demand?
// See comments in 'checkSupers' and in 'ClassDefinition.getInnerClass'.
// We used to report an error here if the superclass was not
// resolved. Having moved the call to 'checkSupers' from 'basicCheck'
// into 'resolveTypeStructure', the errors reported here should have
// already been reported. Furthermore, error recovery can null out
// the superclass, which would cause a spurious error from the test here.
}
return superClass;
}
/**
* Check that all superclasses and superinterfaces are defined and
* well formed. Among other checks, verify that the inheritance
* graph is acyclic. Called from 'resolveTypeStructure'.
*/
// *** DEBUG ***
supersCheckStarted = true;
if (isInterface()) {
if (isFinal()) {
// Interfaces have no superclass. Superinterfaces
// are checked below, in code shared with the class case.
}
} else {
// Check superclass.
// Call to 'getSuperClass(env)' (note argument) attempts
// 'resolveTypeStructure' if superclass has not successfully
// been resolved. Since we have just now called 'resolveSupers'
// (see our call in 'resolveTypeStructure'), it is not clear
// that this can do any good. Why not 'getSuperClass()' here?
try {
// Resolve superclass and its ancestors.
// Access to the superclass should be checked relative
// to the surrounding context, not as if the reference
// appeared within the class body. Changed 'canAccess'
// to 'extendsCanAccess' to fix 4087314.
// Might it be a better recovery to let the access go through?
superClass = null;
// Might it be a better recovery to let the access go through?
superClass = null;
} else if (def.isInterface()) {
superClass = null;
superClass = null;
} else {
}
if (superClass == null) {
} else {
// If we have a valid superclass, check its
// supers as well, and so on up to root class.
// Call to 'enclosingClassOf' will raise
// 'NullPointerException' if 'def' is null,
// so omit this check as error recovery.
for (;;) {
if (enclosingClassOf(sup)) {
// Do we need a similar test for
// interfaces? See bugid 4038529.
superClass = null;
break;
}
// Since we resolved the superclass and its
// ancestors above, we should not discover
// any unresolved classes on the superclass
// chain. It should thus be sufficient to
// call 'getSuperClass()' (no argument) here.
if (s == null) {
// Superclass not resolved due to error.
break;
}
}
}
} catch (ClassNotFound e) {
// Error is detected in call to 'getClassDefinition'.
// The class may actually exist but be ambiguous.
// Call env.resolve(e.name) to see if it is.
// env.resolve(name) will definitely tell us if the
// class is ambiguous, but may not necessarily tell
// us if the class is not found.
// (part of solution for 4059855)
reportError: {
try {
} catch (AmbiguousClass ee) {
superClass = null;
break reportError;
} catch (ClassNotFound ee) {
// fall through
}
superClass = null;
} // The break exits this block
}
} else {
// Superclass was null on entry, after call to
// 'resolveSupers'. This should normally not happen,
// as 'resolveSupers' sets 'superClass' to a non-null
// value for all named classes, except for one special
// case: 'java.lang.Object', which has no superclass.
if (isAnonymous()) {
// checker should have filled it in first
throw new CompilerError("anonymous super");
throw new CompilerError("unresolved super");
}
}
}
// At this point, if 'superClass' is null due to an error
// in the user program, a message should have been issued.
supersChecked = true;
// Check interfaces
if (interfaceIds != null
}
try {
// Resolve superinterface and its ancestors.
// Check superinterface access in the correct context.
// Changed 'canAccess' to 'extendsCanAccess' to fix 4087314.
} else {
// Interface is OK, leave it in the interface list.
continue;
}
} catch (ClassNotFound e) {
// The interface may actually exist but be ambiguous.
// Call env.resolve(e.name) to see if it is.
// env.resolve(name) will definitely tell us if the
// interface is ambiguous, but may not necessarily tell
// us if the interface is not found.
// (part of solution for 4059855)
reportError2: {
try {
} catch (AmbiguousClass ee) {
superClass = null;
break reportError2;
} catch (ClassNotFound ee) {
// fall through
}
superClass = null;
} // The break exits this block
}
// Remove this interface from the list of interfaces
// as recovery from an error.
newInterfaces.length - i);
--i;
}
}
/**
* Check all of the members of this class.
* <p>
* Inner classes are checked in the following way. Any class which
* is immediately contained in a block (anonymous and local classes)
* is checked along with its containing method; see the
* SourceMember.check() method for more information. Member classes
* of this class are checked immediately after this class, unless this
* class is insideLocal(), in which case, they are checked with the
* rest of the members.
*/
throws ClassNotFound {
// bail out if there were any errors
if (getError()) {
return vset;
}
// Make sure that all of our member classes have been
// basicCheck'ed before we check the rest of our members.
// If our member classes haven't been basicCheck'ed, then they
// may not have <init> methods. It is important that they
// have <init> methods so we can process NewInstanceExpressions
// correctly. This problem didn't occur before 1.2beta1.
// This is a fix for bug 4082816.
for (MemberDefinition f = getFirstMember();
f != null; f = f.getNextMember()) {
if (f.isInnerClass()) {
// System.out.println("Considering " + f + " in " + this);
}
}
}
if (isFinal() && isAbstract()) {
}
// This class should be abstract if there are any abstract methods
// in our parent classes and interfaces which we do not override.
// There are odd cases when, even though we cannot access some
// abstract method from our superclass, that abstract method can
// still force this class to be abstract. See the discussion in
// bug id 1240831.
// Set the class abstract.
modifiers |= M_ABSTRACT;
// Tell the user which methods force this class to be abstract.
// First list all of the "unimplementable" abstract methods.
// We couldn't override this method even if we
// wanted to. Try to make the error message
// as non-confusing as possible.
}
// Now list all of the traditional abstract methods.
// For each method, check if it is abstract. If it is,
// output an appropriate error message.
if (method.isAbstract()) {
}
}
}
// Check the instance variables in a pre-pass before any constructors.
// This lets constructors "in-line" any initializers directly.
// It also lets us do some definite assignment checks on variables.
// Do definite assignment checking on blank finals.
// Other variables do not need such checks. The simple textual
// ordering constraints implemented by MemberDefinition.canReach()
// are necessary and sufficient for the other variables.
// Note that within non-static code, all statics are always
// definitely assigned, and vice-versa.
for (MemberDefinition f = getFirstMember();
f != null; f = f.getNextMember()) {
if (f.isVariable() && f.isBlankFinal()) {
// The following allocates a LocalMember object as a proxy
// to represent the field.
if (f.isStatic()) {
} else {
}
}
}
// For instance variable checks, use a context with a "this" parameter.
// Do all the initializers in order, checking the definite
// assignment of blank finals. Separate static from non-static.
for (MemberDefinition f = getFirstMember();
f != null; f = f.getNextMember()) {
try {
if (f.isVariable() || f.isInitializer()) {
if (f.isStatic()) {
} else {
}
}
} catch (ClassNotFound ee) {
}
}
// Check the rest of the field definitions.
// (Note: Re-checking a field is a no-op.)
for (MemberDefinition f = getFirstMember();
f != null; f = f.getNextMember()) {
try {
if (f.isConstructor()) {
// When checking a constructor, an explicit call to
// 'this(...)' makes all blank finals definitely assigned.
// See 'MethodExpression.checkValue'.
// May issue multiple messages for the same variable!!
// (drop vsCon here)
} else {
// (drop vsFld here)
}
} catch (ClassNotFound ee) {
}
}
// Must mark class as checked before visiting inner classes,
// as they may in turn request checking of the current class
// as an outer class. Fix for bug id 4056774.
// Also check other classes in the same nest.
// All checking of this nest must be finished before any
// of its classes emit bytecode.
// Otherwise, the inner classes might not have a chance to
// add access or class literal fields to the outer class.
for (MemberDefinition f = getFirstMember();
f != null; f = f.getNextMember()) {
if (f.isInnerClass()) {
if (!cdef.isInsideLocal()) {
}
}
}
// Note: Since inner classes cannot set up-level variables,
// the returned vset is always equal to the passed-in vset.
// Still, we'll return it for the sake of regularity.
return vset;
}
/** Make sure all my blank finals exist now. */
boolean isStatic) {
&& ff.getClassDefinition() == this) {
}
}
}
}
/**
* Check this class has its superclass and its interfaces. Also
* force it to have an <init> method (if it doesn't already have one)
* and to have all the abstract methods of its parents.
*/
private boolean basicChecking = false;
private boolean basicCheckDone = false;
super.basicCheck(env);
if (basicChecking || basicCheckDone) {
return;
}
basicChecking = true;
}
// Check the existence of the superclass and all interfaces.
// Also responsible for breaking inheritance cycles. This call
// has been moved to 'resolveTypeStructure', just after the call
// to 'resolveSupers', as inheritance cycles must be broken before
// resolving types within the members. Fixes 4073739.
// checkSupers(env);
if (!isInterface()) {
// Add implicit <init> method, if necessary.
// QUERY: What keeps us from adding an implicit constructor
// when the user explicitly declares one? Is it truly guaranteed
// that the declaration for such an explicit constructor will have
// been processed by the time we arrive here? In general, 'basicCheck'
// is called very early, prior to the normal member checking phase.
if (!hasConstructor()) {
// Default constructors inherit the access modifiers of their
// class. For non-inner classes, this follows from JLS 8.6.7,
// as the only possible modifier is 'public'. For the sake of
// robustness in the presence of errors, we ignore any other
// modifiers. For inner classes, the rule needs to be extended
// in some way to account for the possibility of private and
// protected classes. We make the 'obvious' extension, however,
// the inner classes spec is silent on this issue, and a definitive
// resolution is needed. See bugid 4087421.
// WORKAROUND: A private constructor might need an access method,
// but it is not possible to create one due to a restriction in
// the verifier. (This is a known problem -- see 4015397.)
// We therefore do not inherit the 'private' modifier from the class,
// allowing the default constructor to be package private. This
// workaround can be observed via reflection, but is otherwise
// undetectable, as the constructor is always accessible within
// the class in which its containing (private) class appears.
int accessModifiers = getModifiers() &
}
}
// Only do the inheritance/override checks if they are turned on.
// The idea here is that they will be done in javac, but not
// in javadoc. See the comment for turnOffChecks(), above.
if (doInheritanceChecks) {
// Verify the compatibility of all inherited method definitions
// by collecting all of our inheritable methods.
}
basicChecking = false;
basicCheckDone = true;
}
/**
* Add a group of methods to this class as miranda methods.
*
* For a definition of Miranda methods, see the comment above the
* method addMirandaMethods() in the file
*/
//System.out.println("adding miranda method " + newMethod +
// " to " + this);
}
}
/**
* <em>After parsing is complete</em>, resolve all names
* except those inside method bodies or initializers.
* In particular, this is the point at which we find out what
* kinds of variables and methods there are in the classes,
* and therefore what is each class's interface to the world.
* <p>
* Also perform certain other transformations, such as inserting
* "this$C" arguments into constructors, and reorganizing structure
* to flatten qualified member names.
* <p>
* Do not perform type-based or name-based consistency checks
* or normalizations (such as default nullary constructors),
* and do not attempt to compile code against this class,
* until after this phase.
*/
private boolean resolving = false;
if (tracing)
// Resolve immediately enclosing type, which in turn
// forces resolution of all enclosing type declarations.
// Do the outer class first, always.
// (Note: this.resolved is probably true at this point.)
}
// Punt if we've already resolved this class, or are currently
// in the process of doing so.
if (tracing)
return;
}
// Previously, 'resolved' was set here, and served to prevent
// duplicate resolutions here as well as its function in
// 'ClassDefinition.addMember'. Now, 'resolving' serves the
// former purpose, distinct from that of 'resolved'.
resolving = true;
if (tracing)
// Resolve superclass names to class declarations
// for the immediate superclass and superinterfaces.
// Check all ancestor superclasses for various
// errors, verifying definition of all superclasses
// and superinterfaces. Also breaks inheritance cycles.
// Calls 'resolveTypeStructure' recursively for ancestors
// This call used to appear in 'basicCheck', but was not
// performed early enough. Most of the compiler will barf
// on inheritance cycles!
try {
} catch (ClassNotFound ee) {
// Undefined classes should be reported by 'checkSupers'.
}
for (MemberDefinition
if (f instanceof SourceMember)
}
resolving = false;
// Mark class as resolved. If new members are subsequently
// added to the class, they will be resolved at that time.
// See 'ClassDefinition.addMember'. Previously, this variable was
// set prior to the calls to 'checkSupers' and 'resolveTypeStructure'
// (which may engender further calls to 'checkSupers'). This could
// lead to duplicate resolution of implicit constructors, as the call to
// 'basicCheck' from 'checkSupers' could add the constructor while
// its class is marked resolved, and thus would resolve the constructor,
// believing it to be a "late addition". It would then be resolved
// redundantly during the normal traversal of the members, which
// immediately follows in the code above.
resolved = true;
// Now we have enough information to detect method repeats.
for (MemberDefinition
if (f.isInitializer()) continue;
if (!f.isMethod()) continue;
continue;
}
continue;
}
}
}
if (tracing)
}
if (tracing)
// Find the super class
// Special-case java.lang.Object here (not in the parser).
// In all other cases, if we have a valid 'superClassId',
// we return with a valid and non-null 'superClass' value.
if (superClass == getClassDeclaration()
superClass = null;
superClassId = null;
}
}
// Find interfaces
for (int j = 0; j < i; j++) {
if (interfaces[i] == interfaces[j]) {
}
}
}
}
if (tracing)
}
if (tracing)
if (isInnerClass())
else
// Result is never null, as a new 'ClassDeclaration' is
// created if one with the given name does not exist.
return result;
}
/**
* During the type-checking of an outer method body or initializer,
* this routine is called to check a local class body
* in the proper context.
* @param sup the named super class or interface (if anonymous)
* @param args the actual arguments (if anonymous)
*/
) throws ClassNotFound {
throw new CompilerError("resolveAnonymousStructure");
}
if (isAnonymous()) {
}
// Run the checks in the lexical context from the outer class.
// This is now done by 'checkInternal' via its call to 'checkMembers'.
// getClassDeclaration().setDefinition(this, CS_CHECKED);
return vset;
}
/**
* As with checkLocalClass, run the inline phase for a local class.
*/
for (MemberDefinition
continue; // inlined inside of constructors only
}
try {
} catch (ClassNotFound ee) {
}
}
inlinedLocalClass = true;
// add more constructor arguments for uplevel references
for (MemberDefinition
if (f.isConstructor()) {
//((SourceMember)f).addUplevelArguments(false);
((SourceMember)f).addUplevelArguments();
}
}
}
}
private boolean inlinedLocalClass = false;
/**
* Check a class which is inside a local class, but is not itself local.
*/
throws ClassNotFound {
if (!isInsideLocal() || isLocal()) {
throw new CompilerError("checkInsideClass");
}
}
/**
* Just before checking an anonymous class, decide its true
* inheritance, and build its (sole, implicit) constructor.
*/
) throws ClassNotFound {
this + ", super " + sup);
// Decide now on the superclass.
// This check has been removed as part of the fix for 4055017.
// In the anonymous class created to hold the 'class$' method
// of an interface, 'superClassId' refers to 'java.lang.Object'.
/*---------------------*
if (!(superClass == null && superClassId.getName() == idNull)) {
throw new CompilerError("superclass "+superClass);
}
*---------------------*/
if (sup.isInterface()) {
// allow an interface in the "super class" position
if (ni > 0) {
}
}
interfaces = i1;
}
if (hasConstructor()) {
throw new CompilerError("anonymous constructor");
}
// Synthesize an appropriate constructor.
}
}
if (outerArg == 0) {
} else {
}
}
/**
* Convert class modifiers to a string for diagnostic purposes.
* Accepts modifiers applicable to inner classes and that appear
* in the InnerClasses attribute only, as well as those that may
* appear in the class modifier proper.
*/
private static int classModifierBits[] =
{ "PUBLIC", "PRIVATE", "PROTECTED", "STATIC", "FINAL",
"INTERFACE", "ABSTRACT", "SUPER", "ANONYMOUS", "LOCAL",
"STRICTFP", "STRICT"};
String s = "";
s = s + " " + classModifierNames[i];
mods &= ~classModifierBits[i];
}
}
if (mods != 0) {
}
return s;
}
/**
* Find or create an access method for a private member,
* or return null if this is not possible.
*/
}
if (!field.isVariable()) {
throw new CompilerError("method");
}
}
boolean isUpdate,
boolean isSuper) {
// The 'isSuper' argument is really only meaningful when the
// target member is a method, in which case an 'invokespecial'
// is needed. For fields, 'getfield' and 'putfield' instructions
// are generated in either case, and 'isSuper' currently plays
// no essential role. Nonetheless, we maintain the distinction
// consistently for the time being.
// Find pre-existing access method.
// In the case of a field access method, we only look for the getter.
// A getter is always created whenever a setter is.
// QUERY: Why doesn't the 'MemberDefinition' object for the field
// itself just have fields for its getter and setter?
break;
}
// Distinguish the getter and the setter by the number of
// arguments.
// This was (nargs == (isStatic ? 0 : 1) + (isUpdate ? 1 : 0))
// in order to find a setter as well as a getter. This caused
// allocation of multiple getters.
break;
}
}
}
if (!isUpdate) {
return af;
} else {
return uf;
}
}
} else if (isUpdate) {
// must find or create the getter before creating the setter
}
// If we arrive here, we are creating a new access member.
if (field.isConstructor()) {
// For a constructor, we use the same name as for all
// constructors ("<init>"), but add a distinguishing
// argument of an otherwise unused "dummy" type.
// Get the dummy class, creating it if necessary.
// Create dummy class.
IdentifierToken interfaces[] = {};
// If an interface has a public inner class, the dummy class for
// the constructor must always be accessible. Fix for 4221648.
if (outerMostClass.isInterface()) {
}
// Check the class.
// It is likely that a full check is not really necessary,
// but it is essential that the class be marked as parsed.
Expression argsX[] = {};
try {
} catch (ClassNotFound ee) {};
// Get class type.
}
} else {
// Otherwise, we use the name "access$N", for the
// smallest value of N >= 0 yielding an unused name.
for (int i = 0; ; i++) {
break;
}
}
}
if (isStatic) {
if (!isMethod) {
if (!isUpdate) {
} else {
}
} else {
// Since constructors are never static, we don't
// have to worry about a dummy argument here.
argTypes = t.getArgumentTypes();
}
} else {
// All access methods for non-static members get an explicit
// 'this' pointer as an extra argument, as the access methods
// themselves must be static. EXCEPTION: Access methods for
// constructors are non-static.
if (!isMethod) {
if (!isUpdate) {
} else {
}
} else {
// Target is a method, possibly a constructor.
if (field.isConstructor()) {
// Access method is a constructor.
// Requires a dummy argument.
if (outerThisArg != null) {
// Outer instance link must be the first argument.
// The following is a sanity check that will catch
// most cases in which in this requirement is violated.
throw new CompilerError("misplaced outer this");
}
// Strip outer 'this' argument.
// It will be added back when the access method is checked.
for (int i = 1; i < nargs; i++) {
}
} else {
// There is no outer instance.
for (int i = 0; i < nargs; i++) {
}
}
} else {
// Access method is static.
// Requires an explicit 'this' argument.
for (int i = 0; i < nargs; i++) {
}
}
}
}
for (int i = 0; i < nlen; i++) {
}
if (isStatic) {
for (int i = 0 ; i < nlen ; i++) {
}
} else {
if (field.isConstructor()) {
// Constructor access method is non-static, so
// 'this' works normally.
// Remove dummy argument, as it is not
// passed to the target method.
for (int i = 1 ; i < nlen ; i++) {
}
} else {
// Non-constructor access method is static, so
// we use the first argument as 'this'.
// Remove first argument.
for (int i = 1 ; i < nlen ; i++) {
}
}
}
if (!isMethod) {
if (isUpdate) {
}
} else {
// If true, 'isSuper' forces a non-virtual call.
}
} else {
}
// Access methods are now static (constructors excepted), and no longer final.
// This change was mandated by the interaction of the access method
// naming conventions and the restriction against overriding final
// methods.
int mod = M_SYNTHETIC;
if (!field.isConstructor()) {
}
// Create the synthetic method within the class in which the referenced
// private member appears. The 'env' argument to 'makeMemberDefinition'
// is suspect because it represents the environment at the point at
// which a reference takes place, while it should represent the
// environment in which the definition of the synthetic method appears.
// We get away with this because 'env' is used only to access globals
// such as 'Environment.error', and also as an argument to
// 'resolveTypeStructure', which immediately discards it using
// 'setupEnv'. Apparently, the current definition of 'setupEnv'
// represents a design change that has not been thoroughly propagated.
// An access method is declared with same list of exceptions as its
// target. As the exceptions are simply listed by name, the correctness
// of this approach requires that the access method be checked
// (name-resolved) in the same context as its target method This
// should always be the case.
// Just to be safe, copy over the name-resolved exceptions from the
// target so that the context in which the access method is checked
// doesn't matter.
if (isUpdate) {
}
// The call to 'check' is not needed, as the access method will be
// checked by the containing class after it is added. This is the
// idiom followed in the implementation of class literals. (See
// 'FieldExpression.java'.) In any case, the context is wrong in the
// call below. The access method must be checked in the context in
// which it is declared, i.e., the class containing the referenced
// private member, not the (inner) class in which the original member
// reference occurs.
//
// try {
// newf.check(env, ctx, new Vset());
// } catch (ClassNotFound ee) {
// env.error(where, "class.not.found", ee.name, this);
// }
// The comment above is inaccurate. While it is often the case
// that the containing class will check the access method, this is
// by no means guaranteed. In fact, an access method may be added
// after the checking of its class is complete. In this case, however,
// the context in which the class was checked will have been saved in
// the class definition object (by the fix for 4095716), allowing us
// to check the field now, and in the correct context.
// This fixes bug 4098093.
if (checkContext != null) {
//System.out.println("checking late addition: " + this);
try {
} catch (ClassNotFound ee) {
}
}
//System.out.println("[Access member '" +
// newf + "' created for field '" +
// field +"' in class '" + this + "']");
return newf;
}
/**
* Find an inner class of 'this', chosen arbitrarily.
* Result is always an actual class, never an interface.
* Returns null if none found.
*/
// Look for an immediate inner class.
for (MemberDefinition f = getFirstMember();
f != null;
f = f.getNextMember()) {
if (f.isInnerClass()) {
if (!ic.isInterface()) {
return ic;
}
}
}
// Look for a class nested within an immediate inner interface.
// At this point, we have given up on finding a minimally-nested
// class (which would require a breadth-first traversal). It doesn't
// really matter which inner class we find.
for (MemberDefinition f = getFirstMember();
f != null;
f = f.getNextMember()) {
if (f.isInnerClass()) {
return lc;
}
}
}
// No inner classes.
return null;
}
/**
* Get helper method for class literal lookup.
*/
// If we have already created a lookup method, reuse it.
return lookup;
}
// If the current class is a nested class, make sure we put the
// lookup method in the outermost class. Set 'lookup' for the
// intervening inner classes so we won't have to do the search
// again.
if (outerClass != null) {
return lookup;
}
// If we arrive here, there was no existing 'class$' method.
ClassDefinition c = this;
boolean needNewClass = false;
if (isInterface()) {
// The top-level type is an interface. Try to find an existing
// inner class in which to create the helper method. Any will do.
c = findLookupContext();
if (c == null) {
// The interface has no inner classes. Create an anonymous
// inner class to hold the helper method, as an interface must
// not have any methods. The tests above for prior creation
// of a 'class$' method assure that only one such class is
// allocated for each outermost class containing a class
// literal embedded somewhere within. Part of fix for 4055017.
needNewClass = true;
IdentifierToken interfaces[] = {};
c = (SourceClass)
sup, interfaces, this);
}
}
// The name of the class-getter stub is "class$"
// Some sanity checks of questionable value.
//
// This check became useless after matchMethod() was modified
// to not return synthetic methods.
//
//try {
// lookup = c.matchMethod(toplevelEnv, c, idDClass, strarg);
//} catch (ClassNotFound ee) {
// throw new CompilerError("unexpected missing class");
//} catch (AmbiguousMember ee) {
// throw new CompilerError("synthetic name clash");
//}
//if (lookup != null && lookup.getClassDefinition() == c) {
// // Error if method found was not inherited.
// throw new CompilerError("unexpected duplicate");
//}
// Some sanity checks of questionable value.
/* // The helper function looks like this.
* // It simply maps a checked exception to an unchecked one.
* static Class class$(String class$) {
* try { return Class.forName(class$); }
* catch (ClassNotFoundException forName) {
* throw new NoClassDefFoundError(forName.getMessage());
* }
* }
*/
long w = c.getWhere();
Expression a1[] = { e };
// map the exceptions
e = new IdentifierExpression(w, idForName);
Expression a2[] = { e };
new IdentifierToken(idForName),
new ThrowStatement(w, e));
// Use default (package) access. If private, an access method would
// be needed in the event that the class literal belonged to an interface.
// Also, making it private tickles bug 4098316.
c, null,
// If a new class was created to contain the helper method,
// check it now.
if (needNewClass) {
throw new CompilerError("duplicate check");
}
Expression argsX[] = {};
try {
} catch (ClassNotFound ee) {};
}
return lookup;
}
/**
* A list of active ongoing compilations. This list
* is used to stop two compilations from saving the
* same class.
*/
/**
* Compile this class
*/
throws InterruptedException, IOException {
synchronized (active) {
}
}
try {
} catch (ClassNotFound e) {
throw new CompilerError(e);
} finally {
synchronized (active) {
}
}
}
/**
* Verify that the modifier bits included in 'required' are
* all present in 'mods', otherwise signal an internal error.
* Note that errors in the source program may corrupt the modifiers,
* thus we rely on the fact that 'CompilerError' exceptions are
* silently ignored after an error message has been issued.
*/
throw new CompilerError("illegal class modifiers");
}
}
throws IOException, ClassNotFound {
CompilerMember init = new CompilerMember(new MemberDefinition(getWhere(), this, M_STATIC, Type.tMethod(Type.tVoid), idClassInit, null, null), new Assembler());
}
// Reverse the order, so that outer levels come first:
for (int i = ncsize; --i >= 0; )
for (int i = ncsize; --i >= 0; )
// System.out.println("compile class " + getName());
boolean haveDeprecated = this.isDeprecated();
boolean haveSynthetic = this.isSynthetic();
boolean haveConstantValue = false;
boolean haveExceptions = false;
// Generate code for all fields
//System.out.println("compile field " + field.getName());
try {
if (field.isInitializer()) {
}
} else {
CompilerMember f =
methods.addElement(f);
}
} else if (field.isInnerClass()) {
} else if (field.isVariable()) {
variables.addElement(f);
}
}
} catch (CompilerError ee) {
}
}
}
// bail out if there were any errors
if (getNestError()) {
return;
}
int nClassAttrs = 0;
// Insert constants
}
if (haveConstantValue) {
}
if (env.debug_source()) {
nClassAttrs += 1;
}
if (haveExceptions) {
}
if (env.debug_lines()) {
}
if (haveDeprecated) {
if (this.isDeprecated()) {
nClassAttrs += 1;
}
}
if (haveSynthetic) {
if (this.isSynthetic()) {
nClassAttrs += 1;
}
}
// JCOV
}
// end JCOV
if (env.debug_vars()) {
}
}
// JCOV
long timeStamp = 0;
}
// end JCOV
if (getSuperClass() != null) {
}
}
// Sort the methods in order to make sure both constant pool
// entries and methods are in a deterministic order from run
// to run (this allows comparing class files for a fixed point
// to validate the compiler)
// Optimize Code and Collect method constants
try {
}
}
}
// Collect field constants
}
}
// Collect inner class constants
e.hasMoreElements() ; ) {
// If the inner class is local, we do not need to add its
// outer class here -- the outer_class_info_index is zero.
}
// If the local name of the class is idNull, don't bother to
// add it to the constant pool. We won't need it.
if (inner_local_name != idNull) {
}
}
// Write header
// Write class information
// Certain modifiers are implied:
// 1. Any interface (nested or not) is implicitly deemed to be abstract,
// whether it is explicitly marked so or not. (Java 1.0.)
// 2. A interface which is a member of a type is implicitly deemed to
// be static, whether it is explicitly marked so or not.
// 3a. A type which is a member of an interface is implicitly deemed
// to be public, whether it is explicitly marked so or not.
// 3b. A type which is a member of an interface is implicitly deemed
// to be static, whether it is explicitly marked so or not.
// All of these rules are implemented in 'BatchParser.beginClass',
// but the results are verified here.
if (isInterface()) {
// Rule 1.
// The VM spec states that ACC_ABSTRACT must be set when
// ACC_INTERFACE is; this was not done by javac prior to 1.2,
// and the runtime compensates by setting it. Making sure
// it is set here will allow the runtime hack to eventually
// be removed. Rule 2 doesn't apply to transformed modifiers.
} else {
// Contrary to the JVM spec, we only set ACC_SUPER for classes,
// not interfaces. This is a workaround for a bug in IE3.0,
// which refuses interfaces with ACC_SUPER on.
}
// If this is a nested class, transform access modifiers.
if (outerClass != null) {
// If private, transform to default (package) access.
// If protected, transform to public.
// M_PRIVATE and M_PROTECTED are already masked off by MM_CLASS above.
// cmods &= ~(M_PRIVATE | M_PROTECTED);
// Rule 3a. Note that Rule 3b doesn't apply to transformed modifiers.
if (outerClass.isInterface()) {
}
}
if (env.dumpModifiers()) {
Identifier nm =
}
}
// write variables
data.writeShort(tab.index((val instanceof String) ? new StringExpression(f.field.getWhere(), (String)val) : val));
}
if (dep) {
}
if (syn) {
}
}
// write methods
// Transform floating point modifiers. M_STRICTFP
// of member + status of enclosing class turn into
// ACC_STRICT bit.
xmods |= ACC_STRICT;
} else {
// Use the default
if (env.strictdefault()) {
xmods |= ACC_STRICT;
}
}
int natts = 0;
if (env.debug_lines()) {
natts++;
}
// JCOV
natts++;
}
// end JCOV
if (env.debug_vars()) {
natts++;
}
if (env.debug_lines()) {
}
//JCOV
f.asm.writeCoverageTable(env, (ClassDefinition)this, new DataOutputStream(attbuf), tab, f.field.getWhere());
}
// end JCOV
if (env.debug_vars()) {
}
} else {
//JCOV
// end JCOV
}
}
}
if (dep) {
}
if (syn) {
}
}
// class attributes
if (env.debug_source()) {
}
if (this.isDeprecated()) {
}
if (this.isSynthetic()) {
}
// JCOV
}
// end JCOV
e.hasMoreElements() ; ) {
// For each inner class name transformation, we have a record
// with the following fields:
//
// u2 inner_class_info_index; // CONSTANT_Class_info index
// u2 outer_class_info_index; // CONSTANT_Class_info index
// u2 inner_name_index; // CONSTANT_Utf8_info index
// u2 inner_class_access_flags; // access_flags bitmask
//
// The spec states that outer_class_info_index is 0 iff
// the inner class is not a member of its enclosing class (i.e.
// it is a local or anonymous class). The spec also states
// that if a class is anonymous then inner_name_index should
// be 0.
//
// See also the initInnerClasses() method in BinaryClass.java.
// Generate inner_class_info_index.
// Generate outer_class_info_index.
//
// Checking isLocal() should probably be enough here,
// but the check for isAnonymous is added for good
// measure.
} else {
// Query: what about if inner.isInsideLocal()?
// For now we continue to generate a nonzero
// outer_class_info_index.
}
// Generate inner_name_index.
if (inner_name == idNull) {
if (!inner.isAnonymous()) {
throw new CompilerError("compileClass(), anonymous");
}
} else {
}
// Generate inner_class_access_flags.
// Certain modifiers are implied for nested types.
// See rules 1, 2, 3a, and 3b enumerated above.
// All of these rules are implemented in 'BatchParser.beginClass',
// but are verified here.
if (inner.isInterface()) {
// Rules 1 and 2.
}
// Rules 3a and 3b.
}
if (env.dumpModifiers()) {
Identifier nm =
}
}
}
// Cleanup
// JCOV
// generate coverage data
}
// end JCOV
}
/**
* Print out the dependencies for this class (-xdepend) option
*/
// Only do this if the -xdepend flag is on
if ( toplevelEnv.print_dependencies() ) {
// Name of java source file this class was in (full path)
// Class name, fully qualified
// e.g. "java.lang.Object" or "FooBar" or "sun.tools.javac.Main"
// Inner class names must be mangled, as ordinary '.' qualification
// is used internally where the spec requires '$' separators.
// String className = getName().toString();
// Line number where class starts in the src file
// Line number where class ends in the src file (not used yet)
// First line looks like:
// CLASS:src,startLine,endLine,className
+ src + ","
+ startLine + ","
+ endLine + ","
+ className);
// For each class this class is dependent on:
// CLDEP:className1,className2
// where className1 is the name of the class we are in, and
// classname2 is the name of the class className1
// is dependent on.
// Mangle name of class dependend on.
}
}
}
}