/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/**
* Represents a Java class, i.e., the data structures, constant pool,
* fields, methods and commands contained in a Java .class file.
* See <a href="ftp://java.sun.com/docs/specs/">JVM
* specification</a> for details.
* The intent of this class is to represent a parsed or otherwise existing
* class file. Those interested in programatically generating classes
* should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
* @version $Id: JavaClass.java,v 1.4 2007-07-19 04:34:42 ofung Exp $
* @see com.sun.org.apache.bcel.internal.generic.ClassGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
private int class_name_index;
private int superclass_name_index;
/**
* In cases where we go ahead and create something,
* use the default SyntheticRepository, because we
* don't know any better.
*/
/**
* Constructor gets all contents as arguments.
*
* @param class_name_index Index into constant pool referencing a
* ConstantClass that represents this class.
* @param superclass_name_index Index into constant pool referencing a
* ConstantClass that represents this class's superclass.
* @param file_name File name
* @param major Major compiler version
* @param minor Minor compiler version
* @param access_flags Access rights defined by bit flags
* @param constant_pool Array of constants
* @param interfaces Implemented interfaces
* @param fields Class fields
* @param methods Class methods
* @param attributes Class attributes
* @param source Read from file or generated in memory?
*/
int major,
int minor,
int access_flags,
int[] interfaces,
byte source)
{
interfaces = new int[0];
if(attributes == null)
this.class_name_index = class_name_index;
this.access_flags = access_flags;
this.constant_pool = constant_pool;
this.interfaces = interfaces;
this.attributes = attributes;
// Get source file name if available
if(attributes[i] instanceof SourceFile) {
break;
}
}
/* According to the specification the following entries must be of type
* `ConstantClass' but we check that anyway via the
* `ConstPool.getConstant' method.
*/
if(index < 0)
package_name = "";
else
}
else
superclass_name = "java.lang.Object";
}
}
/**
* Constructor gets all contents as arguments.
*
* @param class_name_index Class name
* @param superclass_name_index Superclass name
* @param file_name File name
* @param major Major compiler version
* @param minor Minor compiler version
* @param access_flags Access rights defined by bit flags
* @param constant_pool Array of constants
* @param interfaces Implemented interfaces
* @param fields Class fields
* @param methods Class methods
* @param attributes Class attributes
*/
int major,
int minor,
int access_flags,
int[] interfaces,
Attribute[] attributes) {
}
/**
* Called by objects that are traversing the nodes of the tree implicitely
* defined by the contents of a Java class. I.e., the hierarchy of methods,
* fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
v.visitJavaClass(this);
}
/* Print debug information depending on `JavaClass.debug'
*/
if(debug)
}
/**
* Dump class to a file.
*
* @param file Output file
* @throws IOException
*/
{
}
}
/**
* Dump class to a file named file_name.
*
* @param file_name Output file name
* @exception IOException
*/
{
}
/**
* @return class in binary format
*/
public byte[] getBytes() {
ByteArrayOutputStream s = new ByteArrayOutputStream();
try {
} catch(IOException e) {
e.printStackTrace();
} finally {
}
return s.toByteArray();
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @exception IOException
*/
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @exception IOException
*/
{
if(attributes != null) {
}
else
}
/**
* @return Attributes of the class.
*/
/**
* @return Class name.
*/
/**
* @return Package name.
*/
/**
* @return Class name index.
*/
/**
* @return Constant pool.
*/
/**
* @return Fields, i.e., variables of the class. Like the JVM spec
* mandates for the classfile format, these fields are those specific to
* this class, and not those of the superclass or superinterfaces.
*/
/**
* @return File name of class, aka SourceFile attribute value
*/
/**
* @return Names of implemented interfaces.
*/
/**
* @return Indices in constant pool of implemented interfaces.
*/
/**
* @return Major number of class file version.
*/
/**
* @return Methods of the class.
*/
/**
* @return A com.sun.org.apache.bcel.internal.classfile.Method corresponding to
* java.lang.reflect.Method if any
*/
return method;
}
}
return null;
}
/**
* @return Minor number of class file version.
*/
/**
* @return sbsolute path to file where this class was read from
*/
/**
* @return Superclass name.
*/
/**
* @return Class name index.
*/
static {
try {
// Get path separator either / or \ usually
}
catch (SecurityException e) {
// falls through
}
try {
} catch(StringIndexOutOfBoundsException e) {} // Never reached
}
/**
* @param attributes .
*/
this.attributes = attributes;
}
/**
* @param class_name .
*/
this.class_name = class_name;
}
/**
* @param class_name_index .
*/
this.class_name_index = class_name_index;
}
/**
* @param constant_pool .
*/
this.constant_pool = constant_pool;
}
/**
* @param fields .
*/
}
/**
* Set File name of class, aka SourceFile attribute value
*/
}
/**
* @param interface_names .
*/
this.interface_names = interface_names;
}
/**
* @param interfaces .
*/
this.interfaces = interfaces;
}
/**
* @param major .
*/
}
/**
* @param methods .
*/
}
/**
* @param minor .
*/
}
/**
* Set absolute path to file this class was read from.
*/
this.source_file_name = source_file_name;
}
/**
* @param superclass_name .
*/
this.superclass_name = superclass_name;
}
/**
* @param superclass_name_index .
*/
}
/**
* @return String representing class contents.
*/
" " +
class_name + " extends " +
false) + '\n');
if(size > 0) {
for(int i=0; i < size; i++) {
if(i < size - 1)
}
}
}
}
}
}
while(tok.hasMoreTokens())
}
/**
* @return deep copy of this class
*/
try {
} catch(CloneNotSupportedException e) {}
return c;
}
public final boolean isSuper() {
}
public final boolean isClass() {
}
/** @return returns either HEAP (generated), FILE, or ZIP
*/
public final byte getSource() {
return source;
}
/********************* New repository functionality *********************/
/**
* Gets the ClassRepository which holds its definition. By default
* this is the same as SyntheticRepository.getInstance();
*/
return repository;
}
/**
* Sets the ClassRepository which loaded the JavaClass.
* Should be called immediately after parsing is done.
*/
this.repository = repository;
}
/** Equivalent to runtime "instanceof" operator.
*
* @return true if this JavaClass is derived from teh super class
*/
if(this.equals(super_class))
return true;
return true;
}
}
if(super_class.isInterface()) {
return implementationOf(super_class);
}
return false;
}
/**
* @return true, if clazz is an implementation of interface inter
*/
if(!inter.isInterface()) {
}
return true;
}
return true;
}
}
return false;
}
/**
* @return the superclass for this JavaClass object, or null if this
* is java.lang.Object
*/
return null;
}
try {
} catch(ClassNotFoundException e) {
return null;
}
}
/**
* @return list of super classes of this class in ascending order, i.e.,
* java.lang.Object is always the last element
*/
{
}
}
/**
* Get interfaces directly implemented by this JavaClass.
*/
try {
}
} catch(ClassNotFoundException e) {
return null;
}
return classes;
}
/**
* Get all interfaces implemented by this JavaClass (transitively).
*/
if(clazz.isInterface()) {
} else {
}
}
}
}
}
}