/*
* 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 defines a member of a Java class:
* a variable, a method, or an inner class.
*
* 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
protected long where;
protected int modifiers;
protected boolean superAccessMethod;
/**
* Constructor
*/
}
}
/**
* Constructor for an inner class.
* Inner classes are represented as fields right along with
* variables and methods for simplicity of data structure,
* and to reflect properly the textual declaration order.
* <p>
* This constructor calls the generic constructor for this
* class, extracting all necessary values from the innerClass.
*/
this(innerClass.getWhere(),
this.innerClass = innerClass;
}
/**
* A cache of previously created proxy members. Used to ensure
* uniqueness of proxy objects. See the makeProxyMember method
* defined below.
*/
/**
* Create a member which is externally the same as `field' but
* is defined in class `classDef'. This is used by code
* in sun.tools.tree.(MethodExpression,FieldExpression) as
* part of the fix for bug 4135692.
*
* Proxy members should not be added, ala addMember(), to classes.
* They are merely "stand-ins" to produce modified MethodRef
* constant pool entries during code generation.
*
* We keep a cache of previously created proxy members not to
* save time or space, but to ensure uniqueness of the proxy
* member for any (field,classDef) pair. If these are not made
* unique then we can end up generating duplicate MethodRef
* constant pool entries during code generation.
*/
Environment env) {
if (proxyCache == null) {
proxyCache = new HashMap();
}
// System.out.println("Key is : " + key);
return proxy;
null);
return proxy;
}
/**
* Get the position in the input
*/
public final long getWhere() {
return where;
}
/**
* Get the class declaration
*/
return clazz.getClassDeclaration();
}
/**
* A stub. Subclasses can do more checking.
*/
}
/**
* Get the class declaration in which the field is actually defined
*/
return getClassDeclaration();
}
/**
* Get the class definition
*/
return clazz;
}
/**
* Get the field's top-level enclosing class
*/
return clazz.getTopClass();
}
/**
* Get the field's modifiers
*/
public final int getModifiers() {
return modifiers;
}
}
}
/**
* Get the field's type
*/
return type;
}
/**
* Get the field's name
*/
return name;
}
/**
* Get arguments (a vector of LocalMember)
*/
}
/**
* Get the exceptions that are thrown by this method.
*/
else
// we should have translated this already!
throw new CompilerError("getExceptions "+this);
}
return exp;
}
return expIds;
}
/**
* Get an inner class.
*/
return innerClass;
}
/**
* Is this a synthetic field which holds a copy of,
* or reference to, a local variable or enclosing instance?
*/
public boolean isUplevelValue() {
return false;
}
}
public boolean isAccessMethod() {
// This no longer works, because access methods
// for constructors do not use the standard naming
// scheme.
// return isSynthetic() && isMethod()
// && name.toString().startsWith(prefixAccess);
// Assume that a method is an access method if it has
// an access peer. NOTE: An access method will not be
// recognized as such until 'setAccessMethodTarget' has
// been called on it.
}
/**
* Is this a synthetic method which provides access to a
* visible private member?
*/
if (isAccessMethod()) {
// perhaps skip over another access for the same field
if (!f.isAccessMethod()) {
return f;
}
}
}
return null;
}
if (getAccessMethodTarget() != target) {
/*-------------------*
if (!isAccessMethod() || accessPeer != null ||
target.accessPeer != null) {
throw new CompilerError("accessPeer");
}
*-------------------*/
throw new CompilerError("accessPeer");
}
accessPeer = target;
}
}
/**
* If this method is a getter for a private field, return the setter.
*/
if (isAccessMethod()) {
if (f.isAccessMethod()) {
return f;
}
}
}
return null;
}
if (getAccessUpdateMember() != updater) {
if (!isAccessMethod() ||
throw new CompilerError("accessPeer");
}
}
}
/**
* Is this an access method for a field selection or method call
* of the form '...super.foo' or '...super.foo()'?
*/
public final boolean isSuperAccessMethod() {
return superAccessMethod;
}
/**
* Mark this member as an access method for a field selection
* or method call via the 'super' keyword.
*/
public final void setIsSuperAccessMethod(boolean b) {
superAccessMethod = b;
}
/**
* Tell if this is a final variable without an initializer.
* Such variables are subject to definite single assignment.
*/
public final boolean isBlankFinal() {
}
public boolean isNeverNull() {
if (isUplevelValue()) {
// loc$x and this$C are never null
}
return false;
}
/**
* Get the field's final value (may return null)
*/
return value;
}
return value;
}
}
return null;
}
/**
* Get the next field or the next match
*/
return nextMember;
}
return nextMatch;
}
/**
* Get the field's documentation
*/
return documentation;
}
/**
* Request a check of the field definition.
*/
}
/**
* Really check the field definition.
*/
return vset;
}
/**
* Generate code
*/
throw new CompilerError("code");
}
throw new CompilerError("codeInit");
}
/**
* Tells whether to report a deprecation error for this field.
*/
}
/**
* Check if a field can reach another field (only considers
* forward references, not the access modifiers).
*/
return true;
// They are located in the same class, and are either both
// static or both non-static. Check the initialization order.
while (((f = f.getNextMember()) != null) && (f != this));
return f != null;
}
return true;
}
//-----------------------------------------------------------------
// The code in this section is intended to test certain kinds of
// compatibility between methods. There are two kinds of compatibility
// that the compiler may need to test. The first is whether one
// method can legally override another. The second is whether two
// method definitions can legally coexist. We use the word `meet'
// to mean the intersection of two legally coexisting methods.
// For more information on these kinds of compatibility, see the
/**
* Constants used by getAccessLevel() to represent the access
* modifiers as numbers.
*/
/**
* Return the access modifier of this member as a number. The idea
* is that this number may be used to check properties like "the
* access modifier of x is more restrictive than the access
* modifier of y" with a simple inequality test:
* "x.getAccessLevel() > y.getAccessLevel.
*
* This is an internal utility method.
*/
private int getAccessLevel() {
// Could just compute this once instead of recomputing.
// Check to see if this is worth it.
if (isPublic()) {
return PUBLIC_ACCESS;
} else if (isProtected()) {
return PROTECTED_ACCESS;
} else if (isPackagePrivate()) {
return PACKAGE_ACCESS;
} else if (isPrivate()) {
return PRIVATE_ACCESS;
} else {
throw new CompilerError("getAccessLevel()");
}
}
/**
* Munge our error message to report whether the override conflict
* came from an inherited method or a declared method.
*/
// For example:
// "Instance method BLAH inherited from CLASSBLAH1 cannot be
// overridden by the static method declared in CLASSBLAH2."
this, getClassDeclaration(),
} else {
// For example:
// "In CLASSBLAH1, instance method BLAH inherited from CLASSBLAH2
// cannot be overridden by the static method inherited from
// CLASSBLAH3."
//"inherit." + errorString,
//clazz,
this, getClassDeclaration(),
}
}
/**
* Convenience method to see if two methods return the same type
*/
// Make sure both are methods.
throw new CompilerError("sameReturnType: not method");
}
return (myReturnType == yourReturnType);
}
/**
* responsible for verifying that `method' has the same signature
* as `this'. Caller is also responsible for verifying that
* `method' is visible to the class where this override is occurring.
* This method is called for the case when class B extends A and both
* A and B define some method.
* <pre>
* A - void foo() throws e1
* |
* |
* B - void foo() throws e2
* </pre>
*/
}
/**
* Checks whether `this' can override `method'. It `clazz' is
* null, it reports the errors in the class where `this' is
* declared. If `clazz' is not null, it reports the error in `clazz'.
*/
// This section of code is largely based on section 8.4.6.3
// of the JLS.
boolean success = true;
// Sanity
if (!isMethod()) {
throw new CompilerError("checkOverride(), expected method");
}
// Suppress checks for synthetic methods, as the compiler presumably
// knows what it is doing, e.g., access methods.
if (isSynthetic()) {
// Sanity check: We generally do not intend for one synthetic
// method to override another, though hiding of static members
// is expected. This check may need to be changed if new uses
// of synthetic methods are devised.
//
// Query: this code was copied from elsewhere. What
// exactly is the role of the !isStatic() in the test?
(!method.isConstructor() &&
////////////////////////////////////////////////////////////
// NMG 2003-01-28 removed the following test because it is
// invalidated by bridge methods inserted by the "generic"
// (1.5) Java compiler. In 1.5, this code is used,
// indirectly, by rmic
////////////////////////////////////////////////////////////
// throw new CompilerError("checkOverride() synthetic");
////////////////////////////////////////////////////////////
}
// We trust the compiler. (Ha!) We're done checking.
return true;
}
// Our caller should have verified that the method had the
// same signature.
throw new CompilerError("checkOverride(), signature mismatch");
}
// It is forbidden to `override' a static method with an instance
// method.
success = false;
}
// It is forbidden to `hide' an instance method with a static
// method.
success = false;
}
// We cannot override a final method.
success = false;
}
// Give a warning when we override a deprecated method with
// a non-deprecated one.
//
// We bend over backwards to suppress this warning if
// the `method' has not been already compiled or
// `this' has been already compiled.
}
// Visibility may not be more restrictive
success = false;
}
// Return type equality
if (!sameReturnType(method)) {
////////////////////////////////////////////////////////////
// PCJ 2003-07-30 removed the following error because it is
// invalidated by the covariant return type feature of the
// 1.5 compiler. The resulting check is now much looser
// than the actual 1.5 language spec, but that should be OK
// because this code is only still used by rmic. See 4892308.
////////////////////////////////////////////////////////////
// reportError(env, "override.different.return", clazz, method);
// success = false;
////////////////////////////////////////////////////////////
}
// Exception agreeement
success = false;
}
return success;
}
/**
* Check to see if two method definitions are compatible, that is
* do they have a `meet'. The meet of two methods is essentially
* and `intersection' of
* two methods. This method is called when some class C inherits
* declarations for some method foo from two parents (superclass,
* interfaces) but it does not, itself, have a declaration of foo.
* Caller is responsible for making sure that both methods are
* indeed visible in clazz.
* <pre>
* A - void foo() throws e1
* \
* \ B void foo() throws e2
* \ /
* \ /
* C
* </pre>
*/
// This section of code is largely based on Section 8.4.6
// and 9.4.1 of the JLS.
// Sanity
if (!isMethod()) {
throw new CompilerError("checkMeet(), expected method");
}
// Check for both non-abstract.
throw new CompilerError("checkMeet(), no abstract method");
}
// If either method is non-abstract, then we need to check that
// the abstract method can be properly overridden. We call
// the checkOverride method to check this and generate any errors.
// This test must follow the previous test.
else if (!isAbstract()) {
} else if (!method.isAbstract()) {
}
// Both methods are abstract.
// Our caller should have verified that the method has the
// same signature.
throw new CompilerError("checkMeet(), signature mismatch");
}
// Check for return type equality
if (!sameReturnType(method)) {
// More args?
"meet.different.return",
this, this.getClassDeclaration(),
return false;
}
// We don't have to check visibility -- there always
// potentially exists a meet. Similarly with exceptions.
// There does exist a meet.
return true;
}
/**
* This method is meant to be used to determine if one of two inherited
* methods could override the other. Unlike checkOverride(), failure
* is not an error. This method is only meant to be called after
* checkMeet() has succeeded on the two methods.
*
* If you call couldOverride() without doing a checkMeet() first, then
* you are on your own.
*/
// Sanity
if (!isMethod()) {
throw new CompilerError("coulcOverride(), expected method");
}
// couldOverride() is only called with `this' and `method' both
// being inherited methods. Neither of them is defined in the
// class which we are currently working on. Even though an
// abstract method defined *in* a class can override a non-abstract
// method defined in a superclass, an abstract method inherited
// from an interface *never* can override a non-abstract method.
// This comment may sound odd, but that's the way inheritance is.
// The following check makes sure we aren't trying to override
// an inherited non-abstract definition with an abstract definition
// from an interface.
if (!method.isAbstract()) {
return false;
}
// Visibility should be less restrictive
return false;
}
// Exceptions
return false;
}
// Potentially some deprecation warnings could be given here
// when we merge two abstract methods, one of which is deprecated.
// This is not currently reported.
return true;
}
/**
* Check to see if the exceptions of `this' fit within the
* exceptions of `method'.
*/
// This code is taken nearly verbatim from the old implementation
// of checkOverride() in SourceClass.
try {
continue outer;
}
}
continue outer;
continue outer;
// the throws was neither something declared by a parent,
// nor one of the ignorables.
return false;
} catch (ClassNotFound ee) {
// We were unable to find one of the exceptions.
}
}
// All of the exceptions `fit'.
return true;
}
//-----------------------------------------------------------------
/**
* Checks
*/
public final boolean isPublic() {
}
public final boolean isPrivate() {
}
public final boolean isProtected() {
}
public final boolean isPackagePrivate() {
}
public final boolean isFinal() {
}
public final boolean isStatic() {
}
public final boolean isSynchronized() {
}
public final boolean isAbstract() {
}
public final boolean isNative() {
}
public final boolean isVolatile() {
}
public final boolean isTransient() {
}
public final boolean isMethod() {
}
public final boolean isVariable() {
}
public final boolean isSynthetic() {
}
public final boolean isDeprecated() {
}
public final boolean isStrict() {
}
public final boolean isInnerClass() {
return innerClass != null;
}
public final boolean isInitializer() {
}
public final boolean isConstructor() {
}
public boolean isLocal() {
return false;
}
!(isSynchronized() || isNative());
}
/**
* Check if constant: Will it inline away to a constant?
*/
public boolean isConstant() {
try {
// If an infinite regress requeries this name,
// deny that it is a constant.
} finally {
}
}
return false;
}
/**
* toString
*/
if (isInitializer()) {
} else if (isConstructor()) {
if (i > 0) {
}
}
} else if (isInnerClass()) {
return getInnerClass().toString();
}
}
/**
* Print for debugging
*/
if (isPublic()) {
}
if (isPrivate()) {
}
if (isProtected()) {
}
if (isFinal()) {
}
if (isStatic()) {
}
if (isSynchronized()) {
}
if (isAbstract()) {
}
if (isNative()) {
}
if (isVolatile()) {
}
if (isTransient()) {
}
}
int cost = 0;
if (isPrivate() || isInitializer()) {
} else if ((cost =
>= Statement.MAXINLINECOST) {
// will never be inlined
} else {
try {
if (!isInlineable(null, true)) {
}
}
catch (ClassNotFound ee) { }
}
cost + " expression cost units remain]");
}
} else if (isVariable()) {
}
}
}
}