You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [22/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/...
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClass.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClass.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClass.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClass.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,38 +12,29 @@
*/
package serp.bytecode;
-import serp.bytecode.lowlevel.*;
-
-import serp.bytecode.visitor.*;
-
-import serp.util.*;
-
import java.io.*;
-
import java.net.*;
-
import java.util.*;
-
+import serp.bytecode.lowlevel.*;
+import serp.bytecode.visitor.*;
+import serp.util.*;
/**
- * <p>The BCClass represents a class object in the bytecode framework, in many
- * ways mirroring the {@link Class} class of Java reflection. The represented
- * class might be a primitive, array, existing object type, or some new user-
- * defined type. As with most entities in the bytecode framework, the BCClass
- * contains methods to manipulate the low-level state of the class (constant
- * pool indexes, etc), but these can and should be ignored in
- * favor of the available high-level methods.</p>
- *
- * <p>A BCClass instance is loaded from a {@link Project} and remains
- * attached to that project for its lifetime. If a BCClass is removed from
- * its project, the result of any further operations on the class are
- * undefined.</p>
- *
- * <p>Note that if a BCClass represents a primitive or array type, all of the
- * available mutator methods and any methods that access the constant pool
- * will throw {@link UnsupportedOperationException}s.</p>
- *
- * @author Abe White
+ * The BCClass represents a class object in the bytecode framework, in many
+ * ways mirroring the {@link Class} class of Java reflection. The represented
+ * class might be a primitive, array, existing object type, or some new user-
+ * defined type. As with most entities in the bytecode framework, the BCClass
+ * contains methods to manipulate the low-level state of the class(constant
+ * pool indexes, etc), but these can and should be ignored in
+ * favor of the available high-level methods.
+ * A BCClass instance is loaded from a {@link Project} and remains
+ * attached to that project for its lifetime. If a BCClass is removed from
+ * its project, the result of any further operations on the class are undefined.
+ * Note that if a BCClass represents a primitive or array type, all of the
+ * available mutator methods and any methods that access the constant pool
+ * will throw {@link UnsupportedOperationException}s.
+ *
+ * @author Abe White
*/
public class BCClass extends Attributes implements VisitAcceptor {
private Project _project = null;
@@ -54,21 +42,21 @@
private ClassLoader _loader = null;
/**
- * Hide constructor. For use by the owning project only.
+ * Hide constructor. For use by the owning project only.
*/
BCClass(Project project) {
_project = project;
}
/**
- * Set the class state. For use by the owning project only.
+ * Set the class state. For use by the owning project only.
*/
void setState(State state) {
_state = state;
}
/**
- * Invalidate this class.
+ * Invalidate this class.
*/
void invalidate() {
_project = null;
@@ -80,25 +68,19 @@
//////////////////
/**
- * Initialize from the class definition in the given file. For use by
- * the owning project only.
+ * Initialize from the class definition in the given file. For use by
+ * the owning project only.
*/
void read(File classFile, ClassLoader loader) throws IOException {
InputStream in = new FileInputStream(classFile);
-
- try {
- read(in, loader);
- } finally {
- in.close();
- }
+ try { read(in, loader); } finally { in.close(); }
}
/**
- * Initialize from the class definition in the given stream. For use by
- * the owning project only.
+ * Initialize from the class definition in the given stream. For use by
+ * the owning project only.
*/
- void read(InputStream instream, ClassLoader loader)
- throws IOException {
+ void read(InputStream instream, ClassLoader loader) throws IOException {
DataInput in = new DataInputStream(instream);
// header information
@@ -118,19 +100,15 @@
Collection interfaces = _state.getInterfacesHolder();
interfaces.clear();
-
int interfaceCount = in.readUnsignedShort();
-
for (int i = 0; i < interfaceCount; i++)
interfaces.add(Numbers.valueOf(in.readUnsignedShort()));
// fields
Collection fields = _state.getFieldsHolder();
fields.clear();
-
int fieldCount = in.readUnsignedShort();
BCField field;
-
for (int i = 0; i < fieldCount; i++) {
field = new BCField(this);
fields.add(field);
@@ -140,10 +118,8 @@
// methods
Collection methods = _state.getMethodsHolder();
methods.clear();
-
int methodCount = in.readUnsignedShort();
BCMethod method;
-
for (int i = 0; i < methodCount; i++) {
method = new BCMethod(this);
methods.add(method);
@@ -155,8 +131,8 @@
}
/**
- * Initialize from the bytecode of the definition of the given class.
- * For use by the owning project only.
+ * Initialize from the bytecode of the definition of the given class.
+ * For use by the owning project only.
*/
void read(Class type) throws IOException {
// find out the length of the package name
@@ -167,21 +143,17 @@
// attempt to get the class file for the class as a stream
InputStream in = type.getResourceAsStream(className + ".class");
-
- try {
- read(in, type.getClassLoader());
- } finally {
- in.close();
- }
+ try { read(in, type.getClassLoader()); } finally { in.close(); }
}
/**
- * Initialize from the given parsed bytecode.
- * For use by the owning project only.
+ * Initialize from the given parsed bytecode.
+ * For use by the owning project only.
*/
void read(BCClass orig) {
try {
- ByteArrayInputStream in = new ByteArrayInputStream(orig.toByteArray());
+ ByteArrayInputStream in = new ByteArrayInputStream
+ (orig.toByteArray());
read(in, orig.getClassLoader());
in.close();
} catch (IOException ioe) {
@@ -190,9 +162,9 @@
}
/**
- * Write the class bytecode to the .class file in the proper directory of
- * the CLASSPATH. The file must exist already, so this method only works
- * on existing classes.
+ * Write the class bytecode to the .class file in the proper directory of
+ * the CLASSPATH. The file must exist already, so this method only works
+ * on existing classes.
*/
public void write() throws IOException {
String name = getName();
@@ -204,31 +176,21 @@
// attempt to get the class file for the class as a stream;
// we need to use the url decoder in case the target directory
// has spaces in it
- OutputStream out = new FileOutputStream(URLDecoder.decode(
- type.getResource(name + ".class").getFile()));
-
- try {
- write(out);
- } finally {
- out.close();
- }
+ OutputStream out = new FileOutputStream(URLDecoder.decode
+ (type.getResource(name + ".class").getFile()));
+ try { write(out); } finally { out.close(); }
}
/**
- * Write the class bytecode to the specified file.
+ * Write the class bytecode to the specified file.
*/
public void write(File classFile) throws IOException {
OutputStream out = new FileOutputStream(classFile);
-
- try {
- write(out);
- } finally {
- out.close();
- }
+ try { write(out); } finally { out.close(); }
}
/**
- * Write the class bytecode to the specified stream.
+ * Write the class bytecode to the specified stream.
*/
public void write(OutputStream outstream) throws IOException {
DataOutput out = new DataOutputStream(outstream);
@@ -251,21 +213,18 @@
// interfaces
Collection interfaces = _state.getInterfacesHolder();
out.writeShort(interfaces.size());
-
for (Iterator itr = interfaces.iterator(); itr.hasNext();)
out.writeShort(((Number) itr.next()).intValue());
// fields
Collection fields = _state.getFieldsHolder();
out.writeShort(fields.size());
-
for (Iterator itr = fields.iterator(); itr.hasNext();)
((BCField) itr.next()).write(out);
// methods
Collection methods = _state.getMethodsHolder();
out.writeShort(methods.size());
-
for (Iterator itr = methods.iterator(); itr.hasNext();)
((BCMethod) itr.next()).write(out);
@@ -274,24 +233,20 @@
}
/**
- * Return the bytecode of this class as a byte array, possibly for use
- * in a custom {@link ClassLoader}.
+ * Return the bytecode of this class as a byte array, possibly for use
+ * in a custom {@link ClassLoader}.
*/
public byte[] toByteArray() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
-
try {
write(out);
out.flush();
-
return out.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException(ioe.toString());
- } finally {
- try {
- out.close();
- } catch (IOException ioe) {
- }
+ }
+ finally {
+ try { out.close(); } catch (IOException ioe) {}
}
}
@@ -300,169 +255,166 @@
/////////////////////
/**
- * Return the magic number for this class; if this is a valid type, this
- * should be equal to {@link Constants#VALID_MAGIC} (the default value).
+ * Return the magic number for this class; if this is a valid type, this
+ * should be equal to {@link Constants#VALID_MAGIC} (the default value).
*/
public int getMagic() {
return _state.getMagic();
}
/**
- * Set the magic number for this class; if this is a valid type, this
- * should be equal to {@link Constants#VALID_MAGIC} (the default value).
+ * Set the magic number for this class; if this is a valid type, this
+ * should be equal to {@link Constants#VALID_MAGIC} (the default value).
*/
public void setMagic(int magic) {
_state.setMagic(magic);
}
/**
- * Return the major version of the bytecode spec used for this class.
- * JVMs are only required to operate with versions that they understand;
- * leaving the default value of {@link Constants#MAJOR_VERSION} is safe.
+ * Return the major version of the bytecode spec used for this class.
+ * JVMs are only required to operate with versions that they understand;
+ * leaving the default value of {@link Constants#MAJOR_VERSION} is safe.
*/
public int getMajorVersion() {
return _state.getMajorVersion();
}
/**
- * Set the major version of the bytecode spec used for this class.
- * JVMs are only required to operate with versions that they understand;
- * leaving the default value of {@link Constants#MAJOR_VERSION} is safe.
+ * Set the major version of the bytecode spec used for this class.
+ * JVMs are only required to operate with versions that they understand;
+ * leaving the default value of {@link Constants#MAJOR_VERSION} is safe.
*/
public void setMajorVersion(int majorVersion) {
_state.setMajorVersion(majorVersion);
}
/**
- * Get the minor version of the bytecode spec used for this class.
- * JVMs are only required to operate with versions that they understand;
- * leaving the default value of {@link Constants#MINOR_VERSION} is safe.
+ * Get the minor version of the bytecode spec used for this class.
+ * JVMs are only required to operate with versions that they understand;
+ * leaving the default value of {@link Constants#MINOR_VERSION} is safe.
*/
public int getMinorVersion() {
return _state.getMinorVersion();
}
/**
- * Set the minor version of the bytecode spec used for this class.
- * JVMs are only required to operate with versions that they understand;
- * leaving the default value of {@link Constants#MINOR_VERSION} is safe.
+ * Set the minor version of the bytecode spec used for this class.
+ * JVMs are only required to operate with versions that they understand;
+ * leaving the default value of {@link Constants#MINOR_VERSION} is safe.
*/
public void setMinorVersion(int minorVersion) {
_state.setMinorVersion(minorVersion);
}
/**
- * Return the access flags for this class as a bit array of
- * ACCESS_XXX constants from {@link Constants}. This can be used to
- * transfer access flags between classes without getting/setting each
- * possible flag.
+ * Return the access flags for this class as a bit array of
+ * ACCESS_XXX constants from {@link Constants}. This can be used to
+ * transfer access flags between classes without getting/setting each
+ * possible flag.
*/
public int getAccessFlags() {
return _state.getAccessFlags();
}
/**
- * Set the access flags for this class as a bit array of
- * ACCESS_XXX constants from {@link Constants}. This can be used to
- * transfer access flags between classes without getting/setting each
- * possible flag.
+ * Set the access flags for this class as a bit array of
+ * ACCESS_XXX constants from {@link Constants}. This can be used to
+ * transfer access flags between classes without getting/setting each
+ * possible flag.
*/
public void setAccessFlags(int access) {
_state.setAccessFlags(access);
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public boolean isPublic() {
- return (getAccessFlags() & Constants.ACCESS_PUBLIC) > 0;
+ return(getAccessFlags() & Constants.ACCESS_PUBLIC) > 0;
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public void makePublic() {
setAccessFlags(getAccessFlags() | Constants.ACCESS_PUBLIC);
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public boolean isPackage() {
return !isPublic();
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public void makePackage() {
setAccessFlags(getAccessFlags() & ~Constants.ACCESS_PUBLIC);
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public boolean isFinal() {
- return (getAccessFlags() & Constants.ACCESS_FINAL) > 0;
+ return(getAccessFlags() & Constants.ACCESS_FINAL) > 0;
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public void setFinal(boolean on) {
- if (on) {
+ if (on)
setAccessFlags(getAccessFlags() | Constants.ACCESS_FINAL);
- } else {
+ else
setAccessFlags(getAccessFlags() & ~Constants.ACCESS_FINAL);
- }
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public boolean isInterface() {
- return (getAccessFlags() & Constants.ACCESS_INTERFACE) > 0;
+ return(getAccessFlags() & Constants.ACCESS_INTERFACE) > 0;
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public void setInterface(boolean on) {
if (on) {
setAccessFlags(getAccessFlags() | Constants.ACCESS_INTERFACE);
setAbstract(true);
- } else {
+ } else
setAccessFlags(getAccessFlags() & ~Constants.ACCESS_INTERFACE);
- }
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public boolean isAbstract() {
- return (getAccessFlags() & Constants.ACCESS_ABSTRACT) > 0;
+ return(getAccessFlags() & Constants.ACCESS_ABSTRACT) > 0;
}
/**
- * Manipulate the class access flags.
+ * Manipulate the class access flags.
*/
public void setAbstract(boolean on) {
- if (on) {
+ if (on)
setAccessFlags(getAccessFlags() | Constants.ACCESS_ABSTRACT);
- } else {
+ else
setAccessFlags(getAccessFlags() & ~Constants.ACCESS_ABSTRACT);
- }
}
/**
- * Return true if this class is a primitive type.
+ * Return true if this class is a primitive type.
*/
public boolean isPrimitive() {
return _state.isPrimitive();
}
/**
- * Return true if this class is an array type.
+ * Return true if this class is an array type.
*/
public boolean isArray() {
return _state.isArray();
@@ -473,85 +425,75 @@
/////////////////////////
/**
- * Return the {@link ConstantPool} index of the
- * {@link ClassEntry} for this class. Returns 0 if the class does not
- * have a constant pool (such as a primitive or array).
+ * Return the {@link ConstantPool} index of the
+ * {@link ClassEntry} for this class. Returns 0 if the class does not
+ * have a constant pool(such as a primitive or array).
*/
public int getIndex() {
return _state.getIndex();
}
/**
- * Set the {@link ConstantPool} index of the {@link ClassEntry} for this
- * class. Unlike most other low-level methods, the index
- * will be checked against the pool immediately;
- * classes must have a valid name at all times.
+ * Set the {@link ConstantPool} index of the {@link ClassEntry} for this
+ * class. Unlike most other low-level methods, the index
+ * will be checked against the pool immediately;
+ * classes must have a valid name at all times.
*/
public void setIndex(int index) {
String oldName = getName();
- String newName = ((ClassEntry) getPool().getEntry(index)).getNameEntry()
- .getValue();
+ String newName = ((ClassEntry) getPool().getEntry(index)).
+ getNameEntry().getValue();
beforeRename(oldName, newName);
_state.setIndex(index);
}
/**
- * Return the name of this class, including package name. The name will
- * be in a form suitable for a {@link Class#forName} call.
+ * Return the name of this class, including package name. The name will
+ * be in a form suitable for a {@link Class#forName} call.
*/
public String getName() {
return _state.getName();
}
/**
- * Return the name of the class only, without package.
+ * Return the name of the class only, without package.
*/
public String getClassName() {
- String name = _project.getNameCache().getExternalForm(getName(), true);
-
+ String name = _project.getNameCache(). getExternalForm(getName(), true);
return name.substring(name.lastIndexOf('.') + 1);
}
/**
- * Return the package name only, without class, or null if none.
+ * Return the package name only, without class, or null if none.
*/
public String getPackageName() {
- String name = _project.getNameCache().getExternalForm(getName(), true);
+ String name = _project.getNameCache(). getExternalForm(getName(), true);
int index = name.lastIndexOf('.');
-
- if (index == -1) {
+ if (index == -1)
return null;
- }
-
return name.substring(0, index);
}
/**
- * Set the name of this class, including package name.
+ * Set the name of this class, including package name.
*/
public void setName(String name) {
name = _project.getNameCache().getExternalForm(name, false);
-
String oldName = getName();
// get a reference to the class entry for this class
int index = getIndex();
-
- if (index == 0) {
+ if (index == 0)
index = getPool().findClassEntry(name, true);
- }
-
ClassEntry entry = (ClassEntry) getPool().getEntry(index);
// make sure the rename is ok with the project
beforeRename(oldName, name);
// reset the name index of the class entry to the new name
- int nameIndex = getPool()
- .findUTF8Entry(_project.getNameCache()
- .getInternalForm(name, false),
- true);
+ int nameIndex = getPool().findUTF8Entry(_project.getNameCache().
+ getInternalForm(name, false), true);
entry.setNameIndex(nameIndex);
// we might have just added a new entry; set the index
@@ -559,43 +501,37 @@
}
/**
- * Return the {@link Class} object for this class, if it is loadable.
+ * Return the {@link Class} object for this class, if it is loadable.
*/
public Class getType() {
return Strings.toClass(getName(), getClassLoader());
}
/**
- * Return the component type name of this class, or null if not an array.
- * The name will be in a form suitable for a {@link Class#forName} call.
+ * Return the component type name of this class, or null if not an array.
+ * The name will be in a form suitable for a {@link Class#forName} call.
*/
public String getComponentName() {
return _state.getComponentName();
}
/**
- * Return the component type of this class, or null if not an array.
+ * Return the component type of this class, or null if not an array.
*/
public Class getComponentType() {
String componentName = getComponentName();
-
- if (componentName == null) {
+ if (componentName == null)
return null;
- }
-
return Strings.toClass(componentName, getClassLoader());
}
/**
- * Return the component type of this class, or null if not an array.
+ * Return the component type of this class, or null if not an array.
*/
public BCClass getComponentBC() {
String componentName = getComponentName();
-
- if (componentName == null) {
+ if (componentName == null)
return null;
- }
-
return getProject().loadClass(componentName, getClassLoader());
}
@@ -604,93 +540,82 @@
/////////////////////////
/**
- * Return the {@link ConstantPool} index of the
- * {@link ClassEntry} for the superclass of this class. Returns -1 if
- * the class does not have a constant pool (such as a primitive or array).
+ * Return the {@link ConstantPool} index of the
+ * {@link ClassEntry} for the superclass of this class. Returns -1 if
+ * the class does not have a constant pool(such as a primitive or array).
*/
public int getSuperclassIndex() {
return _state.getSuperclassIndex();
}
/**
- * Set the {@link ConstantPool} index of the
- * {@link ClassEntry} for the superclass of this class.
+ * Set the {@link ConstantPool} index of the
+ * {@link ClassEntry} for the superclass of this class.
*/
public void setSuperclassIndex(int index) {
_state.setSuperclassIndex(index);
}
/**
- * Return the name of the superclass for this class, including package
- * name. The name will be in a form suitable for a
- * {@link Class#forName} call, or null for types without superclasses.
+ * Return the name of the superclass for this class, including package
+ * name. The name will be in a form suitable for a
+ * {@link Class#forName} call, or null for types without superclasses.
*/
public String getSuperclassName() {
return _state.getSuperclassName();
}
/**
- * Return the {@link Class} object for the superclass of this class, if it
- * is loadable. Returns null for types without superclasses.
+ * Return the {@link Class} object for the superclass of this class, if it
+ * is loadable. Returns null for types without superclasses.
*/
public Class getSuperclassType() {
String name = getSuperclassName();
-
- if (name == null) {
+ if (name == null)
return null;
- }
-
return Strings.toClass(name, getClassLoader());
}
/**
- * Return the bytecode of the superclass of this class, or
- * null for types without superclasses.
+ * Return the bytecode of the superclass of this class, or
+ * null for types without superclasses.
*/
public BCClass getSuperclassBC() {
String name = getSuperclassName();
-
- if (name == null) {
+ if (name == null)
return null;
- }
-
return getProject().loadClass(name, getClassLoader());
}
/**
- * Set the superclass of this class.
+ * Set the superclass of this class.
*/
public void setSuperclass(String name) {
- if (name == null) {
+ if (name == null)
setSuperclassIndex(0);
- } else {
- setSuperclassIndex(getPool()
- .findClassEntry(_project.getNameCache()
- .getInternalForm(name,
- false), true));
- }
+ else
+ setSuperclassIndex(getPool().findClassEntry(_project.
+ getNameCache().getInternalForm(name, false), true));
}
/**
- * Set the superclass of this class.
+ * Set the superclass of this class.
*/
public void setSuperclass(Class type) {
- if (type == null) {
+ if (type == null)
setSuperclass((String) null);
- } else {
+ else
setSuperclass(type.getName());
- }
}
/**
- * Set the superclass of this class.
+ * Set the superclass of this class.
*/
public void setSuperclass(BCClass type) {
- if (type == null) {
+ if (type == null)
setSuperclass((String) null);
- } else {
+ else
setSuperclass(type.getName());
- }
}
////////////////////////
@@ -698,61 +623,55 @@
////////////////////////
/**
- * Return the list of {@link ConstantPool} indexes of the
- * {@link ClassEntry}s describing all the interfaces this class declares
- * that it implements/extends.
- *
- * @return the implmented interfaces, or an empty array if none
+ * Return the list of {@link ConstantPool} indexes of the
+ * {@link ClassEntry}s describing all the interfaces this class declares
+ * that it implements/extends.
+ *
+ * @return the implmented interfaces, or an empty array if none
*/
public int[] getDeclaredInterfaceIndexes() {
Collection interfaces = _state.getInterfacesHolder();
int[] indexes = new int[interfaces.size()];
Iterator itr = interfaces.iterator();
-
for (int i = 0, max = interfaces.size(); i < max; i++)
indexes[i] = ((Number) itr.next()).intValue();
-
return indexes;
}
/**
- * Set the list of {@link ConstantPool} indexes of the
- * {@link ClassEntry}s describing all the interfaces this class declares
- * it implements/extends; set to null or an empty array if none.
+ * Set the list of {@link ConstantPool} indexes of the
+ * {@link ClassEntry}s describing all the interfaces this class declares
+ * it implements/extends; set to null or an empty array if none.
*/
public void setDeclaredInterfaceIndexes(int[] interfaceIndexes) {
Collection stateIndexes = _state.getInterfacesHolder();
stateIndexes.clear();
-
for (int i = 0; i < interfaceIndexes.length; i++)
stateIndexes.add(Numbers.valueOf(interfaceIndexes[i]));
}
/**
- * Return the names of the interfaces declared for this class, including
- * package names, or an empty array if none. The names will be in a form
- * suitable for a {@link Class#forName} call.
+ * Return the names of the interfaces declared for this class, including
+ * package names, or an empty array if none. The names will be in a form
+ * suitable for a {@link Class#forName} call.
*/
public String[] getDeclaredInterfaceNames() {
int[] indexes = getDeclaredInterfaceIndexes();
String[] names = new String[indexes.length];
ClassEntry entry;
-
for (int i = 0; i < indexes.length; i++) {
entry = (ClassEntry) getPool().getEntry(indexes[i]);
- names[i] = _project.getNameCache()
- .getExternalForm(entry.getNameEntry().getValue(),
- false);
+ names[i] = _project.getNameCache().getExternalForm
+ (entry.getNameEntry().getValue(), false);
}
-
return names;
}
/**
- * Return the {@link Class} objects for the declared interfaces of this
- * class, or an empty array if none.
+ * Return the {@link Class} objects for the declared interfaces of this
+ * class, or an empty array if none.
*/
public Class[] getDeclaredInterfaceTypes() {
String[] names = getDeclaredInterfaceNames();
@@ -760,13 +679,12 @@
for (int i = 0; i < names.length; i++)
types[i] = Strings.toClass(names[i], getClassLoader());
-
return types;
}
/**
- * Return the bytecode for the declared interfaces of this class, or an
- * empty array if none.
+ * Return the bytecode for the declared interfaces of this class, or an
+ * empty array if none.
*/
public BCClass[] getDeclaredInterfaceBCs() {
String[] names = getDeclaredInterfaceNames();
@@ -774,245 +692,203 @@
for (int i = 0; i < names.length; i++)
types[i] = getProject().loadClass(names[i], getClassLoader());
-
return types;
}
/**
- * Set the interfaces declared implemented/extended by this class; set to
- * null or an empty array if none.
+ * Set the interfaces declared implemented/extended by this class; set to
+ * null or an empty array if none.
*/
public void setDeclaredInterfaces(String[] interfaces) {
clearDeclaredInterfaces();
-
- if (interfaces != null) {
+ if (interfaces != null)
for (int i = 0; i < interfaces.length; i++)
declareInterface(interfaces[i]);
- }
}
/**
- * Set the interfaces declared implemented/extended by this class; set to
- * null or an empty array if none.
+ * Set the interfaces declared implemented/extended by this class; set to
+ * null or an empty array if none.
*/
public void setDeclaredInterfaces(Class[] interfaces) {
String[] names = null;
-
if (interfaces != null) {
names = new String[interfaces.length];
-
for (int i = 0; i < interfaces.length; i++)
names[i] = interfaces[i].getName();
}
-
setDeclaredInterfaces(names);
}
/**
- * Set the interfaces declared implemented/extended by this class; set to
- * null or an empty array if none.
+ * Set the interfaces declared implemented/extended by this class; set to
+ * null or an empty array if none.
*/
public void setDeclaredInterfaces(BCClass[] interfaces) {
String[] names = null;
-
if (interfaces != null) {
names = new String[interfaces.length];
-
for (int i = 0; i < interfaces.length; i++)
names[i] = interfaces[i].getName();
}
-
setDeclaredInterfaces(names);
}
/**
- * Return the names of all unique interfaces implemented by this class,
- * including those of all superclasses. The names will be returned in a
- * form suitable for a {@link Class#forName} call.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return the names of all unique interfaces implemented by this class,
+ * including those of all superclasses. The names will be returned in a
+ * form suitable for a {@link Class#forName} call.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public String[] getInterfaceNames() {
Collection allNames = new LinkedList();
String[] names;
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC()) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC()) {
names = type.getDeclaredInterfaceNames();
-
for (int i = 0; i < names.length; i++)
allNames.add(names[i]);
}
-
- return (String[]) allNames.toArray(new String[allNames.size()]);
+ return(String[]) allNames.toArray(new String[allNames.size()]);
}
/**
- * Return the {@link Class} objects of all unique interfaces implemented
- * by this class, including those of all superclasses.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return the {@link Class} objects of all unique interfaces implemented
+ * by this class, including those of all superclasses.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public Class[] getInterfaceTypes() {
Collection allTypes = new LinkedList();
Class[] types;
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC()) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC()) {
types = type.getDeclaredInterfaceTypes();
-
for (int i = 0; i < types.length; i++)
allTypes.add(types[i]);
}
-
- return (Class[]) allTypes.toArray(new Class[allTypes.size()]);
+ return(Class[]) allTypes.toArray(new Class[allTypes.size()]);
}
/**
- * Return the bytecode of all unique interfaces implemented by this class,
- * including those of all superclasses.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return the bytecode of all unique interfaces implemented by this class,
+ * including those of all superclasses.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public BCClass[] getInterfaceBCs() {
Collection allTypes = new LinkedList();
BCClass[] types;
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC()) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC()) {
types = type.getDeclaredInterfaceBCs();
-
for (int i = 0; i < types.length; i++)
allTypes.add(types[i]);
}
-
- return (BCClass[]) allTypes.toArray(new BCClass[allTypes.size()]);
+ return(BCClass[]) allTypes.toArray(new BCClass[allTypes.size()]);
}
/**
- * Clear this class of all interface declarations.
+ * Clear this class of all interface declarations.
*/
public void clearDeclaredInterfaces() {
_state.getInterfacesHolder().clear();
}
/**
- * Remove an interface declared by this class.
- *
- * @return true if the class had the interface, false otherwise
+ * Remove an interface declared by this class.
+ *
+ * @return true if the class had the interface, false otherwise
*/
public boolean removeDeclaredInterface(String name) {
String[] names = getDeclaredInterfaceNames();
Iterator itr = _state.getInterfacesHolder().iterator();
-
for (int i = 0; i < names.length; i++) {
itr.next();
-
if (names[i].equals(name)) {
itr.remove();
-
return true;
}
}
-
return false;
}
/**
- * Remove an interface declared by this class.
- *
- * @return true if the class had the interface, false otherwise
+ * Remove an interface declared by this class.
+ *
+ * @return true if the class had the interface, false otherwise
*/
public boolean removeDeclaredInterface(Class type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return removeDeclaredInterface(type.getName());
}
/**
- * Remove an interface declared by this class.
- *
- * @return true if the class had the interface, false otherwise
+ * Remove an interface declared by this class.
+ *
+ * @return true if the class had the interface, false otherwise
*/
public boolean removeDeclaredInterface(BCClass type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return removeDeclaredInterface(type.getName());
}
/**
- * Add an interface to those declared by this class.
+ * Add an interface to those declared by this class.
*/
public void declareInterface(String name) {
- int index = getPool()
- .findClassEntry(_project.getNameCache()
- .getInternalForm(name, false),
- true);
+ int index = getPool().findClassEntry(_project.getNameCache().
+ getInternalForm(name, false), true);
_state.getInterfacesHolder().add(Numbers.valueOf(index));
}
/**
- * Add an interface to those declared by this class.
+ * Add an interface to those declared by this class.
*/
public void declareInterface(Class type) {
declareInterface(type.getName());
}
/**
- * Add an interface to those declared by this class.
+ * Add an interface to those declared by this class.
*/
public void declareInterface(BCClass type) {
declareInterface(type.getName());
}
/**
- * Return true if this class or any of its superclasses implement/extend
- * the given interface/class.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return true if this class or any of its superclasses implement/extend
+ * the given interface/class.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public boolean isInstanceOf(String name) {
name = _project.getNameCache().getExternalForm(name, false);
-
String[] interfaces = getInterfaceNames();
-
for (int i = 0; i < interfaces.length; i++)
- if (interfaces[i].equals(name)) {
+ if (interfaces[i].equals(name))
return true;
- }
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC())
- if (type.getName().equals(name)) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC())
+ if (type.getName().equals(name))
return true;
- }
-
return false;
}
/**
- * Return true if this class or any of its superclasses implement/extend
- * the given interface/class.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return true if this class or any of its superclasses implement/extend
+ * the given interface/class.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public boolean isInstanceOf(Class type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return isInstanceOf(type.getName());
}
/**
- * Return true if this class or any of its superclasses implement/extend
- * the given interface/class.
- * This method does not recurse into interfaces-of-interfaces.
+ * Return true if this class or any of its superclasses implement/extend
+ * the given interface/class.
+ * This method does not recurse into interfaces-of-interfaces.
*/
public boolean isInstanceOf(BCClass type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return isInstanceOf(type.getName());
}
@@ -1021,132 +897,114 @@
//////////////////////
/**
- * Return all the declared fields of this class, or an empty array if none.
+ * Return all the declared fields of this class, or an empty array if none.
*/
public BCField[] getDeclaredFields() {
Collection fields = _state.getFieldsHolder();
-
- return (BCField[]) fields.toArray(new BCField[fields.size()]);
+ return(BCField[]) fields.toArray(new BCField[fields.size()]);
}
/**
- * Return the declared field with the given name, or null if none.
+ * Return the declared field with the given name, or null if none.
*/
public BCField getDeclaredField(String name) {
BCField[] fields = getDeclaredFields();
-
for (int i = 0; i < fields.length; i++)
- if (fields[i].getName().equals(name)) {
+ if (fields[i].getName().equals(name))
return fields[i];
- }
-
return null;
}
/**
- * Return all the fields of this class, including those of all
- * superclasses, or an empty array if none.
+ * Return all the fields of this class, including those of all
+ * superclasses, or an empty array if none.
*/
public BCField[] getFields() {
Collection allFields = new LinkedList();
BCField[] fields;
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC()) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC()) {
fields = type.getDeclaredFields();
-
for (int i = 0; i < fields.length; i++)
allFields.add(fields[i]);
}
-
- return (BCField[]) allFields.toArray(new BCField[allFields.size()]);
+ return(BCField[]) allFields.toArray(new BCField[allFields.size()]);
}
/**
- * Return all fields with the given name, including those of all
- * superclasses, or an empty array if none.
+ * Return all fields with the given name, including those of all
+ * superclasses, or an empty array if none.
*/
public BCField[] getFields(String name) {
List matches = new LinkedList();
BCField[] fields = getFields();
-
for (int i = 0; i < fields.length; i++)
- if (fields[i].getName().equals(name)) {
+ if (fields[i].getName().equals(name))
matches.add(fields[i]);
- }
-
- return (BCField[]) matches.toArray(new BCField[matches.size()]);
+ return(BCField[]) matches.toArray(new BCField[matches.size()]);
}
/**
- * Set the fields for this class; this method is useful for importing all
- * fields from another class. Set to null or empty array if none.
+ * Set the fields for this class; this method is useful for importing all
+ * fields from another class. Set to null or empty array if none.
*/
public void setDeclaredFields(BCField[] fields) {
clearDeclaredFields();
-
- if (fields != null) {
+ if (fields != null)
for (int i = 0; i < fields.length; i++)
declareField(fields[i]);
- }
}
/**
- * Import the information from given field as a new field in this class.
- *
- * @return the added field
+ * Import the information from given field as a new field in this class.
+ *
+ * @return the added field
*/
public BCField declareField(BCField field) {
BCField newField = declareField(field.getName(), field.getTypeName());
newField.setAccessFlags(field.getAccessFlags());
newField.setAttributes(field.getAttributes());
-
return newField;
}
/**
- * Add a field to this class.
- *
- * @return the added field
+ * Add a field to this class.
+ *
+ * @return the added field
*/
public BCField declareField(String name, String type) {
BCField field = new BCField(this);
_state.getFieldsHolder().add(field);
- field.initialize(name,
- _project.getNameCache().getInternalForm(type, true));
-
+ field.initialize(name, _project.getNameCache().
+ getInternalForm(type, true));
return field;
}
/**
- * Add a field to this class.
- *
- * @return the added field
+ * Add a field to this class.
+ *
+ * @return the added field
*/
public BCField declareField(String name, Class type) {
String typeName = (type == null) ? null : type.getName();
-
return declareField(name, typeName);
}
/**
- * Add a field to this class.
- *
- * @return the added field
+ * Add a field to this class.
+ *
+ * @return the added field
*/
public BCField declareField(String name, BCClass type) {
String typeName = (type == null) ? null : type.getName();
-
return declareField(name, typeName);
}
/**
- * Clear all fields from this class.
+ * Clear all fields from this class.
*/
public void clearDeclaredFields() {
Collection fields = _state.getFieldsHolder();
BCField field;
-
for (Iterator itr = fields.iterator(); itr.hasNext();) {
field = (BCField) itr.next();
itr.remove();
@@ -1155,40 +1013,34 @@
}
/**
- * Remove a field from this class. After this method, the removed field
- * will be invalid, and the result of any operations on it is undefined.
- *
- * @return true if this class contained the field, false otherwise
+ * Remove a field from this class. After this method, the removed field
+ * will be invalid, and the result of any operations on it is undefined.
+ *
+ * @return true if this class contained the field, false otherwise
*/
public boolean removeDeclaredField(String name) {
Collection fields = _state.getFieldsHolder();
BCField field;
-
for (Iterator itr = fields.iterator(); itr.hasNext();) {
field = (BCField) itr.next();
-
if (field.getName().equals(name)) {
itr.remove();
field.invalidate();
-
return true;
}
}
-
return false;
}
/**
- * Remove a field from this class. After this method, the removed field
- * will be invalid, and the result of any operations on it is undefined.
- *
- * @return true if this class contained the field, false otherwise
+ * Remove a field from this class. After this method, the removed field
+ * will be invalid, and the result of any operations on it is undefined.
+ *
+ * @return true if this class contained the field, false otherwise
*/
public boolean removeDeclaredField(BCField field) {
- if (field == null) {
+ if (field == null)
return false;
- }
-
return removeDeclaredField(field.getName());
}
@@ -1197,355 +1049,297 @@
//////////////////////
/**
- * Return all methods declared by this class. Constructors and static
- * initializers are included.
+ * Return all methods declared by this class. Constructors and static
+ * initializers are included.
*/
public BCMethod[] getDeclaredMethods() {
Collection methods = _state.getMethodsHolder();
-
- return (BCMethod[]) methods.toArray(new BCMethod[methods.size()]);
+ return(BCMethod[]) methods.toArray(new BCMethod[methods.size()]);
}
/**
- * Return the declared method with the given name, or null if none.
- * If multiple methods are declared with the given name, which is returned
- * is undefined.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the declared method with the given name, or null if none.
+ * If multiple methods are declared with the given name, which is returned
+ * is undefined.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod getDeclaredMethod(String name) {
BCMethod[] methods = getDeclaredMethods();
-
for (int i = 0; i < methods.length; i++)
- if (methods[i].getName().equals(name)) {
+ if (methods[i].getName().equals(name))
return methods[i];
- }
-
return null;
}
/**
- * Return all the declared methods with the given name, or an empty array
- * if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return all the declared methods with the given name, or an empty array
+ * if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod[] getDeclaredMethods(String name) {
Collection matches = new LinkedList();
BCMethod[] methods = getDeclaredMethods();
-
for (int i = 0; i < methods.length; i++)
- if (methods[i].getName().equals(name)) {
+ if (methods[i].getName().equals(name))
matches.add(methods[i]);
- }
-
- return (BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
+ return(BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
}
/**
- * Return the declared method with the given name and parameter types,
- * or null if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the declared method with the given name and parameter types,
+ * or null if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod getDeclaredMethod(String name, String[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
paramTypes = new String[0];
- }
String[] curParams;
boolean match;
BCMethod[] methods = getDeclaredMethods();
-
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
curParams = methods[i].getParamNames();
-
- if (curParams.length != paramTypes.length) {
+ if (curParams.length != paramTypes.length)
continue;
- }
match = true;
-
for (int j = 0; j < paramTypes.length; j++) {
- if (!curParams[j].equals(_project.getNameCache()
- .getExternalForm(paramTypes[j],
- false))) {
+ if (!curParams[j].equals(_project.getNameCache().
+ getExternalForm(paramTypes[j], false))) {
match = false;
-
break;
}
}
- if (match) {
+ if (match)
return methods[i];
- }
}
}
-
return null;
}
/**
- * Return the declared method with the given name and parameter types,
- * or null if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the declared method with the given name and parameter types,
+ * or null if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod getDeclaredMethod(String name, Class[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return getDeclaredMethod(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return getDeclaredMethod(name, paramNames);
}
/**
- * Return the declared method with the given name and parameter types,
- * or null if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the declared method with the given name and parameter types,
+ * or null if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod getDeclaredMethod(String name, BCClass[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return getDeclaredMethod(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return getDeclaredMethod(name, paramNames);
}
/**
- * Return the methods of this class, including those of all superclasses,
- * or an empty array if none.
- * The base version of methods that are overridden will be included, as
- * will all constructors and static initializers.
- * The methods will be ordered from those in the most-specific type up to
- * those in {@link Object}.
+ * Return the methods of this class, including those of all superclasses,
+ * or an empty array if none.
+ * The base version of methods that are overridden will be included, as
+ * will all constructors and static initializers.
+ * The methods will be ordered from those in the most-specific type up to
+ * those in {@link Object}.
*/
public BCMethod[] getMethods() {
Collection allMethods = new LinkedList();
BCMethod[] methods;
-
- for (BCClass type = this; type != null;
- type = type.getSuperclassBC()) {
+ for (BCClass type = this; type != null; type = type.getSuperclassBC()) {
methods = type.getDeclaredMethods();
-
for (int i = 0; i < methods.length; i++)
allMethods.add(methods[i]);
}
-
- return (BCMethod[]) allMethods.toArray(new BCMethod[allMethods.size()]);
+ return(BCMethod[]) allMethods.toArray (new BCMethod[allMethods.size()]);
}
/**
- * Return the methods with the given name, including those of all
- * superclasses, or an empty array if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the methods with the given name, including those of all
+ * superclasses, or an empty array if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod[] getMethods(String name) {
Collection matches = new LinkedList();
BCMethod[] methods = getMethods();
-
for (int i = 0; i < methods.length; i++)
- if (methods[i].getName().equals(name)) {
+ if (methods[i].getName().equals(name))
matches.add(methods[i]);
- }
-
- return (BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
+ return(BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
}
/**
- * Return the methods with the given name and parameter types, including
- * those of all superclasses, or an empty array if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the methods with the given name and parameter types, including
+ * those of all superclasses, or an empty array if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod[] getMethods(String name, String[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
paramTypes = new String[0];
- }
String[] curParams;
boolean match;
BCMethod[] methods = getMethods();
Collection matches = new LinkedList();
-
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
curParams = methods[i].getParamNames();
-
- if (curParams.length != paramTypes.length) {
+ if (curParams.length != paramTypes.length)
continue;
- }
match = true;
-
for (int j = 0; j < paramTypes.length; j++) {
- if (!curParams[j].equals(_project.getNameCache()
- .getExternalForm(paramTypes[j],
- false))) {
+ if (!curParams[j].equals(_project.getNameCache().
+ getExternalForm(paramTypes[j], false))) {
match = false;
-
break;
}
}
- if (match) {
+ if (match)
matches.add(methods[i]);
- }
}
}
-
- return (BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
+ return(BCMethod[]) matches.toArray(new BCMethod[matches.size()]);
}
/**
- * Return the methods with the given name and parameter types, including
- * those of all superclasses, or an empty array if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the methods with the given name and parameter types, including
+ * those of all superclasses, or an empty array if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod[] getMethods(String name, Class[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return getMethods(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return getMethods(name, paramNames);
}
/**
- * Return the methods with the given name and parameter types, including
- * those of all superclasses, or an empty array if none.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
+ * Return the methods with the given name and parameter types, including
+ * those of all superclasses, or an empty array if none.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
*/
public BCMethod[] getMethods(String name, BCClass[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return getMethods(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return getMethods(name, paramNames);
}
/**
- * Set the methods for this class; this method is useful for importing all
- * methods from another class. Set to null or empty array if none.
+ * Set the methods for this class; this method is useful for importing all
+ * methods from another class. Set to null or empty array if none.
*/
public void setDeclaredMethods(BCMethod[] methods) {
clearDeclaredMethods();
-
- if (methods != null) {
+ if (methods != null)
for (int i = 0; i < methods.length; i++)
declareMethod(methods[i]);
- }
}
/**
- * Import the information in the given method as a new method of this
- * class.
- *
- * @return the added method
+ * Import the information in the given method as a new method of this class.
+ *
+ * @return the added method
*/
public BCMethod declareMethod(BCMethod method) {
BCMethod newMethod = declareMethod(method.getName(),
- method.getReturnName(), method.getParamNames());
+ method.getReturnName(), method.getParamNames());
newMethod.setAccessFlags(method.getAccessFlags());
newMethod.setAttributes(method.getAttributes());
-
return newMethod;
}
/**
- * Add a method to this class.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return the added method
+ * Add a method to this class.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return the added method
*/
public BCMethod declareMethod(String name, String returnType,
String[] paramTypes) {
BCMethod method = new BCMethod(this);
_state.getMethodsHolder().add(method);
- method.initialize(name,
- _project.getNameCache().getDescriptor(returnType, paramTypes));
-
+ method.initialize(name, _project.getNameCache().getDescriptor
+ (returnType, paramTypes));
return method;
}
/**
- * Add a method to this class.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return the added method
+ * Add a method to this class.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return the added method
*/
public BCMethod declareMethod(String name, Class returnType,
Class[] paramTypes) {
String[] paramNames = null;
-
if (paramTypes != null) {
paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
}
-
String returnName = (returnType == null) ? null : returnType.getName();
-
return declareMethod(name, returnName, paramNames);
}
/**
- * Add a method to this class.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return the added method
+ * Add a method to this class.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return the added method
*/
public BCMethod declareMethod(String name, BCClass returnType,
BCClass[] paramTypes) {
String[] paramNames = null;
-
if (paramTypes != null) {
paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
}
-
String returnName = (returnType == null) ? null : returnType.getName();
-
return declareMethod(name, returnName, paramNames);
}
/**
- * Clear all declared methods from this class.
+ * Clear all declared methods from this class.
*/
public void clearDeclaredMethods() {
Collection methods = _state.getMethodsHolder();
BCMethod method;
-
for (Iterator itr = methods.iterator(); itr.hasNext();) {
method = (BCMethod) itr.next();
itr.remove();
@@ -1554,82 +1348,68 @@
}
/**
- * Remove a method from this class. After this method, the removed method
- * will be invalid, and the result of any operations on it is undefined.
- * If multiple methods match the given name, which is removed is undefined.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return true if this class contained the method, false otherwise
+ * Remove a method from this class. After this method, the removed method
+ * will be invalid, and the result of any operations on it is undefined.
+ * If multiple methods match the given name, which is removed is undefined.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return true if this class contained the method, false otherwise
*/
public boolean removeDeclaredMethod(String name) {
Collection methods = _state.getMethodsHolder();
BCMethod method;
-
for (Iterator itr = methods.iterator(); itr.hasNext();) {
method = (BCMethod) itr.next();
-
if (method.getName().equals(name)) {
itr.remove();
method.invalidate();
-
return true;
}
}
-
return false;
}
/**
- * Removes a method from this class. After this method, the removed method
- * will be invalid, and the result of any operations on it is undefined.
- *
- * @return true if this class contained the method, false otherwise
+ * Removes a method from this class. After this method, the removed method
+ * will be invalid, and the result of any operations on it is undefined.
+ *
+ * @return true if this class contained the method, false otherwise
*/
public boolean removeDeclaredMethod(BCMethod method) {
- if (method == null) {
+ if (method == null)
return false;
- }
-
return removeDeclaredMethod(method.getName(), method.getParamNames());
}
/**
- * Removes a method from this class. After this method, the removed method
- * will be invalid, and the result of any operations on it is undefined.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return true if this class contained the method, false otherwise
+ * Removes a method from this class. After this method, the removed method
+ * will be invalid, and the result of any operations on it is undefined.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return true if this class contained the method, false otherwise
*/
public boolean removeDeclaredMethod(String name, String[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
paramTypes = new String[0];
- }
String[] curParams;
boolean match;
Collection methods = _state.getMethodsHolder();
BCMethod method;
-
for (Iterator itr = methods.iterator(); itr.hasNext();) {
method = (BCMethod) itr.next();
-
if (method.getName().equals(name)) {
curParams = method.getParamNames();
-
- if (curParams.length != paramTypes.length) {
+ if (curParams.length != paramTypes.length)
continue;
- }
match = true;
-
for (int j = 0; j < paramTypes.length; j++) {
- if (!curParams[j].equals(_project.getNameCache()
- .getExternalForm(paramTypes[j],
- false))) {
+ if (!curParams[j].equals(_project.getNameCache().
+ getExternalForm(paramTypes[j], false))) {
match = false;
-
break;
}
}
@@ -1637,54 +1417,46 @@
if (match) {
itr.remove();
method.invalidate();
-
return true;
}
}
}
-
return false;
}
/**
- * Removes a method from this class. After this method, the removed method
- * will be invalid, and the result of any operations on it is undefined.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return true if this class contained the method, false otherwise
+ * Removes a method from this class. After this method, the removed method
+ * will be invalid, and the result of any operations on it is undefined.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return true if this class contained the method, false otherwise
*/
public boolean removeDeclaredMethod(String name, Class[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return removeDeclaredMethod(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return removeDeclaredMethod(name, paramNames);
}
/**
- * Removes a method from this class. After this method, the removed method
- * will be invalid, and the result of any operations on it is undefined.
- * Note that in bytecode, constructors are named <code><init></code>
- * and static initializers are named <code><clinit></code>.
- *
- * @return true if this class contained the method, false otherwise
+ * Removes a method from this class. After this method, the removed method
+ * will be invalid, and the result of any operations on it is undefined.
+ * Note that in bytecode, constructors are named <code><init></code>
+ * and static initializers are named <code><clinit></code>.
+ *
+ * @return true if this class contained the method, false otherwise
*/
public boolean removeDeclaredMethod(String name, BCClass[] paramTypes) {
- if (paramTypes == null) {
+ if (paramTypes == null)
return removeDeclaredMethod(name, (String[]) null);
- }
String[] paramNames = new String[paramTypes.length];
-
for (int i = 0; i < paramTypes.length; i++)
paramNames[i] = paramTypes[i].getName();
-
return removeDeclaredMethod(name, paramNames);
}
@@ -1693,132 +1465,118 @@
///////////////////////
/**
- * Convenience method to add a default constructor to this class.
- * If a default constructor already exists, this method will return it
- * without modification.
- * This method can only be called if the superclass has been set.
- *
- * @return the default constructor
+ * Convenience method to add a default constructor to this class.
+ * If a default constructor already exists, this method will return it
+ * without modification.
+ * This method can only be called if the superclass has been set.
+ *
+ * @return the default constructor
*/
public BCMethod addDefaultConstructor() {
BCMethod method = getDeclaredMethod("<init>", (String[]) null);
-
- if (method != null) {
+ if (method != null)
return method;
- }
method = declareMethod("<init>", void.class, null);
-
Code code = method.getCode(true);
code.setMaxStack(1);
code.setMaxLocals(1);
code.xload().setThis();
- code.invokespecial()
- .setMethod(getSuperclassName(), "<init>", "void", null);
+ code.invokespecial().setMethod(getSuperclassName(), "<init>",
+ "void", null);
code.vreturn();
-
return method;
}
/**
- * Return source file information for the class.
- * Acts internally through the {@link Attributes} interface.
- *
- * @param add if true, a new source file attribute will be added
- * if not already present
- * @return the source file information, or null if none and the
- * <code>add</code> param is set to false
+ * Return source file information for the class.
+ * Acts internally through the {@link Attributes} interface.
+ *
+ * @param add if true, a new source file attribute will be added
+ * if not already present
+ * @return the source file information, or null if none and the
+ * <code>add</code> param is set to false
*/
public SourceFile getSourceFile(boolean add) {
SourceFile source = (SourceFile) getAttribute(Constants.ATTR_SOURCE);
-
- if (!add || (source != null)) {
+ if (!add || source != null)
return source;
- }
-
- return (SourceFile) addAttribute(Constants.ATTR_SOURCE);
+ return(SourceFile) addAttribute(Constants.ATTR_SOURCE);
}
/**
- * Remove the source file attribute for the class.
- * Acts internally through the {@link Attributes} interface.
- *
- * @return true if there was a file to remove
+ * Remove the source file attribute for the class.
+ * Acts internally through the {@link Attributes} interface.
+ *
+ * @return true if there was a file to remove
*/
public boolean removeSourceFile() {
return removeAttribute(Constants.ATTR_SOURCE);
}
/**
- * Return inner classes information for the class.
- * Acts internally through the {@link Attributes} interface.
- *
- * @param add if true, a new inner classes attribute will be added
- * if not already present
- * @return the inner classes information, or null if none and the
- * <code>add</code> param is set to false
+ * Return inner classes information for the class.
+ * Acts internally through the {@link Attributes} interface.
+ *
+ * @param add if true, a new inner classes attribute will be added
+ * if not already present
+ * @return the inner classes information, or null if none and the
+ * <code>add</code> param is set to false
*/
public InnerClasses getInnerClasses(boolean add) {
- InnerClasses inner = (InnerClasses) getAttribute(Constants.ATTR_INNERCLASS);
-
- if (!add || (inner != null)) {
+ InnerClasses inner = (InnerClasses) getAttribute
+ (Constants.ATTR_INNERCLASS);
+ if (!add || inner != null)
return inner;
- }
-
- return (InnerClasses) addAttribute(Constants.ATTR_INNERCLASS);
+ return(InnerClasses) addAttribute(Constants.ATTR_INNERCLASS);
}
/**
- * Remove the inner classes attribute for the class.
- * Acts internally through the {@link Attributes} interface.
- *
- * @return true if there was an attribute to remove
+ * Remove the inner classes attribute for the class.
+ * Acts internally through the {@link Attributes} interface.
+ *
+ * @return true if there was an attribute to remove
*/
public boolean removeInnerClasses() {
return removeAttribute(Constants.ATTR_INNERCLASS);
}
/**
- * Convenience method to return deprecation information for the class.
- * Acts internally through the {@link Attributes} interface.
+ * Convenience method to return deprecation information for the class.
+ * Acts internally through the {@link Attributes} interface.
*/
public boolean isDeprecated() {
return getAttribute(Constants.ATTR_DEPRECATED) != null;
}
/**
- * Convenience method to set whether this class should be considered
- * deprecated.
- * Acts internally through the {@link Attributes} interface.
+ * Convenience method to set whether this class should be considered
+ * deprecated. Acts internally through the {@link Attributes} interface.
*/
public void setDeprecated(boolean on) {
- if (!on) {
+ if (!on)
removeAttribute(Constants.ATTR_DEPRECATED);
- } else if (!isDeprecated()) {
+ else if (!isDeprecated())
addAttribute(Constants.ATTR_DEPRECATED);
- }
}
///////////////////////////////////
// Implementation of VisitAcceptor
///////////////////////////////////
+
public void acceptVisit(BCVisitor visit) {
visit.enterBCClass(this);
ConstantPool pool = null;
-
try {
pool = _state.getPool();
} catch (UnsupportedOperationException uoe) {
}
-
- if (pool != null) {
+ if (pool != null)
pool.acceptVisit(visit);
- }
BCField[] fields = getDeclaredFields();
-
for (int i = 0; i < fields.length; i++) {
visit.enterBCMember(fields[i]);
fields[i].acceptVisit(visit);
@@ -1826,7 +1584,6 @@
}
BCMethod[] methods = getDeclaredMethods();
-
for (int i = 0; i < methods.length; i++) {
visit.enterBCMember(methods[i]);
methods[i].acceptVisit(visit);
@@ -1840,6 +1597,7 @@
////////////////////////////////
// Implementation of Attributes
////////////////////////////////
+
public Project getProject() {
return _project;
}
@@ -1849,9 +1607,8 @@
}
public ClassLoader getClassLoader() {
- if (_loader != null) {
+ if (_loader != null)
return _loader;
- }
return Thread.currentThread().getContextClassLoader();
}
@@ -1865,14 +1622,13 @@
}
/**
- * Attempts to change the class name with the owning project. The project
- * can reject the change if a class with the given new name already
- * exists; therefore this method should be called before the change is
- * recorded in the class.
+ * Attempts to change the class name with the owning project. The project
+ * can reject the change if a class with the given new name already
+ * exists; therefore this method should be called before the change is
+ * recorded in the class.
*/
private void beforeRename(String oldName, String newName) {
- if ((_project != null) && (oldName != null)) {
+ if (_project != null && oldName != null)
_project.renameClass(oldName, newName, this);
- }
}
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClassLoader.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClassLoader.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCClassLoader.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,27 +12,26 @@
*/
package serp.bytecode;
-
/**
- * <p>Class loader that will attempt to find requested classes in a given
- * {@link Project}.</p>
- *
- * @author Abe White
+ * Class loader that will attempt to find requested classes in a given
+ * {@link Project}.
+ *
+ * @author Abe White
*/
public class BCClassLoader extends ClassLoader {
private Project _project = null;
/**
- * Constructor. Supply the project to use when looking for classes.
+ * Constructor. Supply the project to use when looking for classes.
*/
public BCClassLoader(Project project) {
_project = project;
}
/**
- * Constructor. Supply the project to use when looking for classes.
- *
- * @param parent the parent classoader
+ * Constructor. Supply the project to use when looking for classes.
+ *
+ * @param parent the parent classoader
*/
public BCClassLoader(Project project, ClassLoader loader) {
super(loader);
@@ -43,7 +39,7 @@
}
/**
- * Return this class loader's project.
+ * Return this class loader's project.
*/
public Project getProject() {
return _project;
@@ -51,31 +47,25 @@
protected Class findClass(String name) throws ClassNotFoundException {
byte[] bytes;
-
try {
BCClass type;
-
- if (!_project.containsClass(name)) {
+ if (!_project.containsClass(name))
type = createClass(name);
- } else {
+ else
type = _project.loadClass(name);
- }
-
- if (type == null) {
+ if (type == null)
throw new ClassNotFoundException(name);
- }
bytes = type.toByteArray();
} catch (RuntimeException re) {
throw new ClassNotFoundException(re.toString());
}
-
return defineClass(name, bytes, 0, bytes.length);
}
/**
- * Override this method if unfound classes should be created on-the-fly.
- * Returns null by default.
+ * Override this method if unfound classes should be created on-the-fly.
+ * Returns null by default.
*/
protected BCClass createClass(String name) {
return null;
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCEntity.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCEntity.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/BCEntity.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -17,33 +14,31 @@
import serp.bytecode.lowlevel.*;
-
/**
- * <p>Interface implemented by all bytecode entities. Entities must be able
- * to access the project, constant pool, and class loader of the current
- * class.</p>
- *
- * @author Abe White
+ * Interface implemented by all bytecode entities. Entities must be able
+ * to access the project, constant pool, and class loader of the current class.
+ *
+ * @author Abe White
*/
public interface BCEntity {
/**
- * Return the project of the current class.
+ * Return the project of the current class.
*/
public Project getProject();
/**
- * Return the constant pool of the current class.
+ * Return the constant pool of the current class.
*/
public ConstantPool getPool();
/**
- * Return the class loader to use when loading related classes.
+ * Return the class loader to use when loading related classes.
*/
public ClassLoader getClassLoader();
/**
- * Return false if this entity has been removed from its parent; in this
- * case the results of any operations on the entity are undefined.
+ * Return false if this entity has been removed from its parent; in this
+ * case the results of any operations on the entity are undefined.
*/
public boolean isValid();
}