Initial load

This commit is contained in:
J. Duke 2007-12-01 00:00:00 +00:00
parent 686d76f772
commit 74f4779697
1972 changed files with 585739 additions and 0 deletions

3
jaxp/.hgignore Normal file
View file

@ -0,0 +1,3 @@
^build/
^dist/
^nbproject/private/

27
jaxp/ASSEMBLY_EXCEPTION Normal file
View file

@ -0,0 +1,27 @@
OPENJDK ASSEMBLY EXCEPTION
The OpenJDK source code made available by Sun at openjdk.java.net and
openjdk.dev.java.net ("OpenJDK Code") is distributed under the terms of the
GNU General Public License <http://www.gnu.org/copyleft/gpl.html> version 2
only ("GPL2"), with the following clarification and special exception.
Linking this OpenJDK Code statically or dynamically with other code
is making a combined work based on this library. Thus, the terms
and conditions of GPL2 cover the whole combination.
As a special exception, Sun gives you permission to link this
OpenJDK Code with certain code licensed by Sun as indicated at
http://openjdk.java.net/legal/exception-modules-2007-05-08.html
("Designated Exception Modules") to produce an executable,
regardless of the license terms of the Designated Exception Modules,
and to copy and distribute the resulting executable under GPL2,
provided that the Designated Exception Modules continue to be
governed by the licenses under which they were offered by Sun.
As such, it allows licensees and sublicensees of Sun's GPL2 OpenJDK Code to
build an executable that includes those portions of necessary code that Sun
could not provide under GPL2 (or that Sun has provided under GPL2 with the
Classpath exception). If you modify or add to the OpenJDK code, that new
GPL2 code may still be combined with Designated Exception Modules if the
new code is made subject to this exception by its copyright holder.

347
jaxp/LICENSE Normal file
View file

@ -0,0 +1,347 @@
The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share
and change it. By contrast, the GNU General Public License is intended to
guarantee your freedom to share and change free software--to make sure the
software is free for all its users. This General Public License applies to
most of the Free Software Foundation's software and to any other program whose
authors commit to using it. (Some other Free Software Foundation software is
covered by the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for this service if you wish),
that you receive source code or can get it if you want it, that you can change
the software or use pieces of it in new free programs; and that you know you
can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny
you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must
make sure that they, too, receive or can get the source code. And you must
show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients to
know that what they have is not the original, so that any problems introduced
by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will
individually obtain patent licenses, in effect making the program proprietary.
To prevent this, we have made it clear that any patent must be licensed for
everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms of
this General Public License. The "Program", below, refers to any such program
or work, and a "work based on the Program" means either the Program or any
derivative work under copyright law: that is to say, a work containing the
Program or a portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is included
without limitation in the term "modification".) Each licensee is addressed as
"you".
Activities other than copying, distribution and modification are not covered by
this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made by
running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as
you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may
at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus
forming a work based on the Program, and copy and distribute such modifications
or work under the terms of Section 1 above, provided that you also meet all of
these conditions:
a) You must cause the modified files to carry prominent notices stating
that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or
in part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of
this License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the
most ordinary way, to print or display an announcement including an
appropriate copyright notice and a notice that there is no warranty (or
else, saying that you provide a warranty) and that users may redistribute
the program under these conditions, and telling the user how to view a copy
of this License. (Exception: if the Program itself is interactive but does
not normally print such an announcement, your work based on the Program is
not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be reasonably
considered independent and separate works in themselves, then this License, and
its terms, do not apply to those sections when you distribute them as separate
works. But when you distribute the same sections as part of a whole which is a
work based on the Program, the distribution of the whole must be on the terms
of this License, whose permissions for other licensees extend to the entire
whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your
rights to work written entirely by you; rather, the intent is to exercise the
right to control the distribution of derivative or collective works based on
the Program.
In addition, mere aggregation of another work not based on the Program with the
Program (or with a work based on the Program) on a volume of a storage or
distribution medium does not bring the other work under the scope of this
License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1 and
2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to
give any third party, for a charge no more than your cost of physically
performing source distribution, a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of Sections 1
and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to
distribute corresponding source code. (This alternative is allowed only
for noncommercial distribution and only if you received the program in
object code or executable form with such an offer, in accord with
Subsection b above.)
The source code for a work means the preferred form of the work for making
modifications to it. For an executable work, complete source code means all
the source code for all modules it contains, plus any associated interface
definition files, plus the scripts used to control compilation and installation
of the executable. However, as a special exception, the source code
distributed need not include anything that is normally distributed (in either
source or binary form) with the major components (compiler, kernel, and so on)
of the operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the source
code from the same place counts as distribution of the source code, even though
third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy, modify,
sublicense or distribute the Program is void, and will automatically terminate
your rights under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses terminated so
long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the Program
or its derivative works. These actions are prohibited by law if you do not
accept this License. Therefore, by modifying or distributing the Program (or
any work based on the Program), you indicate your acceptance of this License to
do so, and all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program),
the recipient automatically receives a license from the original licensor to
copy, distribute or modify the Program subject to these terms and conditions.
You may not impose any further restrictions on the recipients' exercise of the
rights granted herein. You are not responsible for enforcing compliance by
third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose that
choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original
copyright holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In
such case, this License incorporates the limitation as if written in the body
of this License.
9. The Free Software Foundation may publish revised and/or new versions of the
General Public License from time to time. Such new versions will be similar in
spirit to the present version, but may differ in detail to address new problems
or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any later
version", you have the option of following the terms and conditions either of
that version or of any later version published by the Free Software Foundation.
If the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software Foundation,
write to the Free Software Foundation; we sometimes make exceptions for this.
Our decision will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing and reuse of
software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible
use to the public, the best way to achieve this is to make it free software
which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach
them to the start of each source file to most effectively convey the exclusion
of warranty; and each file should have at least the "copyright" line and a
pointer to where the full notice is found.
One line to give the program's name and a brief idea of what it does.
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program 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 for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it
starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
software, and you are welcome to redistribute it under certain conditions;
type 'show c' for details.
The hypothetical commands 'show w' and 'show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may be
called something other than 'show w' and 'show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school,
if any, to sign a "copyright disclaimer" for the program, if necessary. Here
is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
'Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General Public
License instead of this License.
"CLASSPATH" EXCEPTION TO THE GPL
Certain source files distributed by Sun Microsystems, Inc. are subject to
the following clarification and special exception to the GPL, but only where
Sun has expressly included in the particular source file's header the words
"Sun designates this particular file as subject to the "Classpath" exception
as provided by Sun in the LICENSE file that accompanied this code."
Linking this library statically or dynamically with other modules is making
a combined work based on this library. Thus, the terms and conditions of
the GNU General Public License cover the whole combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent module,
the terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library. If
you modify this library, you may extend this exception to your version of
the library, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.

14
jaxp/README Normal file
View file

@ -0,0 +1,14 @@
README:
This file should be located at the top of the jaxp Mercurial repository.
See http://openjdk.java.net/ for more information about the OpenJDK.
See ../README-builds.html for complete details on build machine requirements.
Simple Build Instructions:
cd make && gnumake
The files that will be imported into the jdk build will be in the "dist"
directory.

1616
jaxp/THIRD_PARTY_README Normal file

File diff suppressed because it is too large Load diff

134
jaxp/make/Makefile Normal file
View file

@ -0,0 +1,134 @@
#
# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# Makefile for jaxp: wrapper around Ant build.xml file
#
# On Solaris, the 'make' utility from Sun will not work with these makefiles.
# This little rule is only understood by Sun's make, and is harmless
# when seen by the GNU make tool. If using Sun's make, this causes the
# make command to fail.
#
SUN_MAKE_TEST:sh = @echo "ERROR: PLEASE USE GNU VERSION OF MAKE"; exit 33
ifdef QUIET
ANT_OPTIONS += -quiet
endif
ifdef VERBOSE
ANT_OPTIONS += -verbose
endif
ifdef JDK_VERSION
ANT_OPTIONS += -Djdk.version=$(JDK_VERSION)
endif
ifdef FULL_VERSION
ANT_OPTIONS += -Dfull.version='$(FULL_VERSION)' # will contain spaces
endif
ifdef MILESTONE
ANT_OPTIONS += -Dmilestone=$(MILESTONE)
endif
ifdef BUILD_NUMBER
ANT_OPTIONS += -Dbuild.number=$(BUILD_NUMBER)
else
ifdef JDK_BUILD_NUMBER
ANT_OPTIONS += -Dbuild.number=$(JDK_BUILD_NUMBER)
endif
endif
ifeq ($(VARIANT), DBG)
ANT_OPTIONS += -Djavac.debug=true
else
ifeq ($(VARIANT), OPT)
ANT_OPTIONS += -Djavac.debug=false
endif
endif
# Note: jdk/make/common/Defs.gmk uses LANGUAGE_VERSION (-source NN)
# and the somewhat misnamed CLASS_VERSION (-target NN)
ifdef TARGET_CLASS_VERSION
ANT_OPTIONS += -Djavac.target=$(TARGET_CLASS_VERSION)
else
ifdef JAVAC_TARGET_ARG
ANT_OPTIONS += -Djavac.target=$(JAVAC_TARGET_ARG)
endif
endif
ifdef ALT_BOOTDIR
ANT_JAVA_HOME = JAVA_HOME=$(ALT_BOOTDIR)
endif
ifdef ALT_OUTPUTDIR
OUTPUTDIR = $(ALT_OUTPUTDIR)
ANT_OPTIONS += -Dbuild.dir=$(ALT_OUTPUTDIR)/build
ANT_OPTIONS += -Ddist.dir=$(ALT_OUTPUTDIR)/dist
else
OUTPUTDIR = ..
endif
ABS_OUTPUTDIR = $(call FullPath,$(OUTPUTDIR))
ifdef ALT_LANGTOOLS_DIST
ANT_OPTIONS += -Dbootstrap.dir=$(ALT_LANGTOOLS_DIST)/bootstrap
endif
ifdef FINDBUGS_HOME
ANT_OPTIONS += -Dfindbugs.home=$(FINDBUGS_HOME)
endif
ifdef ANT_HOME
ANT = $(ANT_HOME)/bin/ant
ifneq ($(shell test -x $(ANT); echo $$?), 0)
$(error "$(ANT) not found; please update ANT_HOME")
endif
else
ANT = ant
ifneq ($(shell which $(ANT) > /dev/null; echo $$?), 0)
$(error "\"ant\" not found; please set ANT_HOME or put \"ant\" on your PATH")
endif
endif
# Default target and expected 'do everything' target
all: build
# Standard make clobber target
clobber: clean
# All ant targets of interest
ANT_TARGETS = build clean sanity # for now
# Create a make target for each
$(ANT_TARGETS):
$(ANT_JAVA_HOME) $(ANT) -version
$(ANT_JAVA_HOME) $(ANT) $(ANT_OPTIONS) $@
# Targets for Sun's internal JPRT build system
jprt_build_product jprt_build_debug jprt_build_fastdebug: all
# Declare these phony (not filenames)
.PHONY: $(ANT_TARGETS) all clobber \
jprt_build_product jprt_build_debug jprt_build_fastdebug

14
jaxp/make/README Normal file
View file

@ -0,0 +1,14 @@
README:
This file should be located at the top of the jaxp Mercurial repository.
See http://openjdk.java.net/ for more information about the OpenJDK.
See ../README-builds.html for complete details on build machine requirements.
Simple Build Instructions:
cd make && gnumake
The files that will be imported into the jdk build will be in the "dist"
directory.

View file

@ -0,0 +1,46 @@
#
# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# This is the JDK used to build and run the bootstrap version of javac.
# The bootstrap javac is used to compile both boostrap versions of the
# other tools, and product versions of all the tools.
# Override this path as needed, either on the command line or in
# one of the standard user build.properties files (see build.xml)
# options for the <javac> tasks used to compile the tools
javac.target = 5
javac.debug = true
javac.debuglevel = source,lines
javac.no.jdk.warnings = -XDignore.symbol.file=true
# set the following to -version to verify the versions of javac being used
javac.version.opt =
# in time, there should be no exceptions to -Xlint:all
javac.lint.opts = -Xlint:all,-unchecked,-deprecation,-fallthrough,-cast,-serial -Werror
# JVM memory size
javac.memoryInitialSize = 128m
javac.memoryMaximumSize = 256m
#------------------------------------------------------------

105
jaxp/make/build.xml Normal file
View file

@ -0,0 +1,105 @@
<?xml version="1.0"?>
<!--
Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Sun designates this
particular file as subject to the "Classpath" exception as provided
by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
CA 95054 USA or visit www.sun.com if you need additional information or
have any questions.
-->
<!--
This is the main build file for the complete jaxp workspace.
-->
<project name="jaxp" default="all" basedir=".">
<!-- Convenient shorthands for standard locations within the workspace. -->
<property file="build.properties"/>
<property name="topdir" value=".."/>
<property name="build.dir" location="${topdir}/build"/>
<property name="build.classes.dir" location="${build.dir}/classes"/>
<property name="build.gensrc.dir" location="${build.dir}/gensrc"/>
<property name="build.toolclasses.dir" location="${build.dir}/toolclasses"/>
<property name="dist.dir" location="${topdir}/dist"/>
<property name="dist.lib.dir" location="${dist.dir}/lib"/>
<property name="make.dir" location="${topdir}/make"/>
<property name="make.tools.dir" location="${make.dir}/tools"/>
<property name="src.dir" location="${topdir}/src"/>
<property name="src.classes.dir" location="${src.dir}/share/classes"/>
<property environment="env"/>
<target name="build" depends="banner, build-classes, build-tools">
<mkdir dir="${dist.lib.dir}"/>
<jar file="${dist.lib.dir}/classes.jar" basedir="${build.classes.dir}"/>
<zip file="${dist.lib.dir}/src.zip" basedir="${src.classes.dir}"/>
</target>
<!-- Debug information -->
<target name="sanity"
description="display settings of configuration values">
<echo level="info">ant.home = ${ant.home}</echo>
<echo level="info">java.home = ${env.JAVA_HOME}</echo>
<echo level="info">bootstrap.dir = ${bootstrap.dir}</echo>
</target>
<target name="build-tools" depends="-defs-pstrip">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<pstrip srcdir="${src.classes.dir}"
destdir="${build.classes.dir}"
includes="**/*.properties"/>
</target>
<target name="-defs-pstrip">
<mkdir dir="${build.toolclasses.dir}"/>
<javac srcdir="${make.tools.dir}/StripProperties"
destdir="${build.toolclasses.dir}/"
classpath="${ant.home}/lib/ant.jar"/>
<taskdef name="pstrip"
classname="StripPropertiesTask"
classpath="${build.toolclasses.dir}/"/>
</target>
<target name="build-classes" depends="sanity">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<javac fork="true"
srcdir="${src.classes.dir}"
destdir="${build.classes.dir}"
memoryInitialSize="${javac.memoryInitialSize}"
memoryMaximumSize="${javac.memoryMaximumSize}"
target="${javac.target}">
<compilerarg value="-J-Xbootclasspath/p:${bootstrap.dir}/lib/javac.jar"/>
<compilerarg line="${javac.version.opt}"/>
</javac>
</target>
<target name="clean" description="Delete all generated files">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="banner">
<echo>+---------------------------------------+</echo>
<echo>+ Building JAXP Component +</echo>
<echo>+---------------------------------------+</echo>
</target>
</project>

241
jaxp/make/jprt.config Normal file
View file

@ -0,0 +1,241 @@
#!echo "This is not a shell script"
#############################################################################
#
# Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#############################################################################
#
# JPRT shell configuration for building.
#
# Input environment variables:
# ALT_BOOTDIR
# ALT_SLASH_JAVA
# ALT_JDK_IMPORT_PATH
# Windows Only:
# PATH
# PROCESSOR_IDENTIFIER
# ROOTDIR
#
# Output variable settings:
# make Full path to GNU make
#
# Output environment variables:
# PATH
# Windows Only:
# ALT_DEVTOOLS_PATH (To avoid the C:/UTILS default)
#
# After JDK6, most settings will be found via ALT_SLASH_JAVA or
# by way of other system environment variables. If this was JDK5
# or an older JDK, you might need to export more ALT_* variables.
#
#############################################################################
#############################################################################
# Error
error() # message
{
echo "ERROR: $1"
exit 6
}
# Directory must exist
dirMustExist() # dir name
{
if [ ! -d "$1" ] ; then
error "Directory for $2 does not exist: $1"
fi
}
# File must exist
fileMustExist() # dir name
{
if [ ! -f "$1" ] ; then
error "File for $2 does not exist: $1"
fi
}
#############################################################################
# Should be set by JPRT as the 3 basic inputs
bootdir="${ALT_BOOTDIR}"
slashjava="${ALT_SLASH_JAVA}"
jdk_import="${ALT_JDK_IMPORT_PATH}"
# Check input
dirMustExist "${bootdir}" ALT_BOOTDIR
dirMustExist "${slashjava}" ALT_SLASH_JAVA
dirMustExist "${jdk_import}" ALT_JDK_IMPORT_PATH
# Uses 'uname -s', but only expect SunOS or Linux, assume Windows otherwise.
osname=`uname -s`
if [ "${osname}" = SunOS ] ; then
# SOLARIS: Sparc or X86
osarch=`uname -p`
if [ "${osarch}" = sparc ] ; then
solaris_arch=sparc
else
solaris_arch=i386
fi
# Add basic solaris system paths
path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin
# Get the previous JDK to be used to bootstrap the build
path4sdk=${bootdir}/bin:${path4sdk}
# Ant
ANT_HOME=${slashjava}/devtools/share/ant/1.7.0
export ANT_HOME
antbindir=${ANT_HOME}/bin
fileMustExist "${antbindir}/ant" ant
path4sdk=${antbindir}:${path4sdk}
# Find GNU make
make=/usr/sfw/bin/gmake
if [ ! -f ${make} ] ; then
make=/opt/sfw/bin/gmake
if [ ! -f ${make} ] ; then
make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
fi
fi
fileMustExist "${make}" make
# File creation mask
umask 002
elif [ "${osname}" = Linux ] ; then
# LINUX: X86, AMD64
osarch=`uname -m`
if [ "${osarch}" = i686 ] ; then
linux_arch=i586
elif [ "${osarch}" = x86_64 ] ; then
linux_arch=amd64
fi
# Add basic paths
path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
# Get the previous JDK to be used to bootstrap the build
path4sdk=${bootdir}/bin:${path4sdk}
# Ant
ANT_HOME=${slashjava}/devtools/share/ant/1.7.0
export ANT_HOME
antbindir=${ANT_HOME}/bin
fileMustExist "${antbindir}/ant" ant
path4sdk=${antbindir}:${path4sdk}
# Find GNU make
make=/usr/bin/make
fileMustExist "${make}" make
umask 002
else
# Windows: Differs on CYGWIN vs. MKS.
# Also, blanks in pathnames gives GNU make headaches, so anything placed
# in any ALT_* variable should be the short windows dosname.
# WINDOWS: Install and use MKS or CYGWIN (should have already been done)
# Assumption here is that you are in a shell window via MKS or cygwin.
# MKS install should have defined the environment variable ROOTDIR.
# We also need to figure out which one we have: X86, AMD64
if [ "`echo ${PROCESSOR_IDENTIFIER} | fgrep AMD64`" != "" ] ; then
windows_arch=amd64
else
windows_arch=i586
fi
# We need to determine if we are running a CYGWIN shell or an MKS shell
# (if uname isn't available, then it will be unix_toolset=unknown)
unix_toolset=unknown
if [ "`uname -a | fgrep Cygwin`" = "" -a -d "${ROOTDIR}" ] ; then
# We kind of assume ROOTDIR is where MKS is and it's ok
unix_toolset=MKS
mkshome=`dosname -s "${ROOTDIR}"`
# Utility to convert to short pathnames without spaces
dosname="${mkshome}/mksnt/dosname -s"
# Most unix utilities are in the mksnt directory of ROOTDIR
unixcommand_path="${mkshome}/mksnt"
path4sdk="${unixcommand_path}"
dirMustExist "${unixcommand_path}" ALT_UNIXCOMMAND_PATH
devtools_path="${slashjava}/devtools/win32/bin"
path4sdk="${devtools_path};${path4sdk}"
# Normally this need not be set, but on Windows it's default is C:/UTILS
ALT_DEVTOOLS_PATH="${devtools_path}"
export ALT_DEVTOOLS_PATH
dirMustExist "${devtools_path}" ALT_DEVTOOLS_PATH
# Find GNU make
make="${devtools_path}/gnumake.exe"
fileMustExist "${make}" make
elif [ "`uname -a | fgrep Cygwin`" != "" -a -f /bin/cygpath ] ; then
# For CYGWIN, uname will have "Cygwin" in it, and /bin/cygpath should exist
unix_toolset=CYGWIN
# Utility to convert to short pathnames without spaces
dosname="/usr/bin/cygpath -a -m -s"
# Most unix utilities are in the /usr/bin
unixcommand_path="/usr/bin"
path4sdk="${unixcommand_path}"
dirMustExist "${unixcommand_path}" ALT_UNIXCOMMAND_PATH
# Find GNU make
make="${unixcommand_path}/make.exe"
fileMustExist "${make}" make
else
echo "WARNING: Cannot figure out if this is MKS or CYGWIN"
fi
# WINDOWS: Get the previous JDK to be used to bootstrap the build
path4sdk="${bootdir}/bin;${path4sdk}"
# Ant
ANT_HOME=${slashjava}/devtools/share/ant/1.7.0
export ANT_HOME
antbindir=${ANT_HOME}/bin
fileMustExist "${antbindir}/ant" ant
path4sdk="${antbindir};${path4sdk}"
# Turn all \\ into /, remove duplicates and trailing /
slash_path="`echo ${path4sdk} | sed -e 's@\\\\@/@g' -e 's@//@/@g' -e 's@/$@@' -e 's@/;@;@g'`"
# For windows, it's hard to know where the system is, so we just add this
# to PATH.
path4sdk="${slash_path};${PATH}"
# Convert path4sdk to cygwin style
if [ "${unix_toolset}" = CYGWIN ] ; then
path4sdk="`/usr/bin/cygpath -p ${path4sdk}`"
fi
fi
# Export PATH setting
PATH="${path4sdk}"
export PATH
# Things we need to unset
unset LD_LIBRARY_PATH
unset LD_LIBRARY_PATH_32
unset LD_LIBRARY_PATH_64
unset JAVA_HOME

55
jaxp/make/jprt.properties Normal file
View file

@ -0,0 +1,55 @@
#
# Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# Properties for jprt
jprt.tools.default.release=jdk1.7.0
# Specific platform list
jprt.build.platforms=\
solaris_sparc_5.10,\
solaris_sparcv9_5.10,\
solaris_i586_5.10,\
solaris_x64_5.10,\
linux_i586,\
linux_x64,\
windows_i586,\
windows_x64
# The different build flavors we want
jprt.build.flavors=product
# Explicitly designate what the 32bit match is for the 64bit build
jprt.solaris_sparcv9.build.platform.match32=solaris_sparc_5.10
jprt.solaris_sparcv9_5.10.build.platform.match32=solaris_sparc_5.10
jprt.solaris_x64.build.platform.match32=solaris_i586_5.10
jprt.solaris_x64_5.10.build.platform.match32=solaris_i586_5.10
# Standard list of jprt test targets for this workspace
jprt.test.targets=
# Directories needed to build
jprt.bundle.src.dirs=make src
jprt.bundle.exclude.src.dirs=build dist

View file

@ -0,0 +1,329 @@
/*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
/**
* Reads a properties file from standard input and writes an equivalent
* properties file without comments to standard output.
*/
public class StripProperties {
public static void main(String[] args) {
StripProperties sp = new StripProperties();
boolean ok = sp.run(args);
if ( !ok ) {
System.exit(1);
}
}
static interface Log {
void info(String msg);
void verbose(String msg);
void error(String msg, Exception e);
}
private String propfiles[];
private String outfiles[] ;
private int stripCount = 0;
private boolean quiet = false;
private Log log;
public void setLog(Log log) {
this.log = log;
}
private boolean parseOptions(String args[]) {
boolean ok = true;
if ( stripCount > 0 ) {
String new_propfiles[] = new String[stripCount + args.length];
String new_outfiles[] = new String[stripCount + args.length];
System.arraycopy(propfiles, 0, new_propfiles, 0, stripCount);
System.arraycopy(outfiles, 0, new_outfiles, 0, stripCount);
propfiles = new_propfiles;
outfiles = new_outfiles;
} else {
propfiles = new String[args.length];
outfiles = new String[args.length];
}
for ( int i = 0; i < args.length ; i++ ) {
if ( "-strip".equals(args[i]) && i+2 < args.length ) {
propfiles[stripCount] = args[++i];
outfiles[stripCount] = args[++i];
stripCount++;
} else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
String filename = args[++i];
FileInputStream finput = null;
byte contents[] = null;
try {
finput = new FileInputStream(filename);
int byteCount = finput.available();
if ( byteCount <= 0 ) {
log.error("The -optionsfile file is empty", null);
ok = false;
} else {
contents = new byte[byteCount];
int bytesRead = finput.read(contents);
if ( byteCount != bytesRead ) {
log.error("Cannot read all of -optionsfile file", null);
ok = false;
}
}
} catch ( IOException e ) {
log.error("cannot open " + filename, e);
ok = false;
}
if ( finput != null ) {
try {
finput.close();
} catch ( IOException e ) {
ok = false;
log.error("cannot close " + filename, e);
}
}
if ( ok = true && contents != null ) {
String tokens[] = (new String(contents)).split("\\s+");
if ( tokens.length > 0 ) {
ok = parseOptions(tokens);
}
}
if ( !ok ) {
break;
}
} else if ( "-quiet".equals(args[i]) ) {
quiet = true;
} else {
log.error("argument error", null);
ok = false;
}
}
return ok;
}
private boolean stripFiles(String propertiesPath, String outputPath) {
boolean ok = true;
Properties prop = new Properties();
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(propertiesPath));
prop.load(in);
} catch ( FileNotFoundException e ) {
log.error("Cannot access file " + propertiesPath, e);
ok = false;
} catch ( IOException e ) {
log.error("IO exception processing file " + propertiesPath, e);
ok = false;
}
if ( in != null ) {
try {
in.close();
} catch ( IOException e ) {
log.error("IO exception closing file " + propertiesPath, e);
ok = false;
}
}
OutputStream out = null;
try {
out = new FileOutputStream(outputPath);
storeProperties(prop, out);
out.flush();
} catch ( IOException e ) {
log.error("IO exception processing file " + outputPath, e);
e.printStackTrace();
ok = false;
}
if ( out != null ) {
try {
out.close();
} catch ( IOException e ) {
log.error("IO exception closing file " + outputPath, e);
ok = false;
}
}
return ok;
}
/**
* Strip the properties filenames supplied, replacing their contents.
* @param args Names of properties files to process and replace contents
*/
public boolean run(String args[]) {
if (log == null) {
log = new Log() {
public void error(String msg, Exception e) {
System.err.println("ERROR: StripProperties: " + msg);
if ( e != null ) {
System.err.println("EXCEPTION: " + e.toString());
e.printStackTrace();
}
}
public void info(String msg) {
System.out.println(msg);
}
public void verbose(String msg) {
if (!quiet)
System.out.println(msg);
}
};
}
boolean ok = true;
ok = parseOptions(args);
if ( ok && stripCount == 0 ) {
log.error("options parsed but no files to compile", null);
ok = false;
}
/* Need at least one file. */
if ( !ok ) {
//usage(log);
} else {
/* Process files */
for ( int i = 0; i < stripCount && ok ; i++ ) {
ok = stripFiles(propfiles[i], outfiles[i]);
}
}
return ok;
}
// --- code below here is adapted from java.util.Properties ---
private static final String specialSaveChars = "=: \t\r\n\f#!";
/*
* Converts unicodes to encoded &#92;uxxxx
* and writes out any of the characters in specialSaveChars
* with a preceding slash
*/
private static String saveConvert(String theString, boolean escapeSpace) {
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len*2);
for(int x=0; x<len; x++) {
char aChar = theString.charAt(x);
switch(aChar) {
case ' ':
if (x == 0 || escapeSpace) {
outBuffer.append('\\');
}
outBuffer.append(' ');
break;
case '\\':
outBuffer.append('\\');
outBuffer.append('\\');
break;
case '\t':
outBuffer.append('\\');
outBuffer.append('t');
break;
case '\n':
outBuffer.append('\\');
outBuffer.append('n');
break;
case '\r':
outBuffer.append('\\');
outBuffer.append('r');
break;
case '\f':
outBuffer.append('\\');
outBuffer.append('f');
break;
default:
if ((aChar < 0x0020) || (aChar == 0x007e) || (aChar > 0x00ff)) {
outBuffer.append('\\');
outBuffer.append('u');
outBuffer.append(toHex((aChar >> 12) & 0xF));
outBuffer.append(toHex((aChar >> 8) & 0xF));
outBuffer.append(toHex((aChar >> 4) & 0xF));
outBuffer.append(toHex( aChar & 0xF));
} else {
if (specialSaveChars.indexOf(aChar) != -1) {
outBuffer.append('\\');
}
outBuffer.append(aChar);
}
}
}
return outBuffer.toString();
}
/**
* Writes the content of <code>properties</code> to <code>out</code>.
* The format is that of Properties.store with the following modifications:
* <ul>
* <li>No header or date is written
* <li>Latin-1 characters are written as single bytes, not escape sequences
* <li>Line breaks are indicated by a single \n independent of platform
* <ul>
*/
private static void storeProperties(Properties properties, OutputStream out)
throws IOException {
BufferedWriter awriter;
awriter = new BufferedWriter(new OutputStreamWriter(out, "8859_1"));
for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String key = (String)e.nextElement();
String val = (String)properties.get(key);
key = saveConvert(key, true);
/* No need to escape embedded and trailing spaces for value, hence
* pass false to flag.
*/
val = saveConvert(val, false);
writeln(awriter, key + "=" + val);
}
awriter.flush();
}
private static void writeln(BufferedWriter bw, String s) throws IOException {
bw.write(s);
bw.write("\n");
}
/**
* Convert a nibble to a hex character
* @param nibble the nibble to convert.
*/
private static char toHex(int nibble) {
return hexDigit[(nibble & 0xF)];
}
/** A table of hex digits */
private static final char[] hexDigit = {
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
}

View file

@ -0,0 +1,87 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
public class StripPropertiesTask extends MatchingTask {
public void setSrcDir(File srcDir) {
this.srcDir = srcDir;
}
public void setDestDir(File destDir) {
this.destDir = destDir;
}
public void execute() {
StripProperties.Log log = new StripProperties.Log() {
public void error(String msg, Exception e) {
log(msg, Project.MSG_ERR);
}
public void info(String msg) {
log(msg, Project.MSG_INFO);
}
public void verbose(String msg) {
log(msg, Project.MSG_VERBOSE);
}
};
List<String> mainOpts = new ArrayList<String>();
int count = 0;
DirectoryScanner s = getDirectoryScanner(srcDir);
for (String path: s.getIncludedFiles()) {
if (path.endsWith(".properties")) {
File srcFile = new File(srcDir, path);
File destFile = new File(destDir, path);
// Arguably, the comparison in the next line should be ">", not ">="
// but that assumes the resolution of the last modified time is fine
// grained enough; in practice, it is better to use ">=".
if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
continue;
destFile.getParentFile().mkdirs();
mainOpts.add("-strip");
mainOpts.add(srcFile.getPath());
mainOpts.add(destFile.getPath());
count++;
}
}
if (mainOpts.size() > 0) {
log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
StripProperties sp = new StripProperties();
sp.setLog(log);
boolean ok = sp.run((String[])mainOpts.toArray(new String[mainOpts.size()]));
if (!ok)
throw new BuildException("StripProperties failed.");
}
}
private File srcDir;
private File destDir;
}

View file

@ -0,0 +1,45 @@
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java_cup.internal.runtime;
/**
* Defines the Scanner interface, which CUP uses in the default
* implementation of <code>lr_parser.scan()</code>. Integration
* of scanners implementing <code>Scanner</code> is facilitated.
*
* @author David MacMahon <davidm@smartsc.com>
*/
/* *************************************************
Interface Scanner
Declares the next_token() method that should be
implemented by scanners. This method is typically
called by lr_parser.scan().
***************************************************/
public interface Scanner {
public Symbol next_token() throws java.lang.Exception;
}

View file

@ -0,0 +1,129 @@
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java_cup.internal.runtime;
/**
* Defines the Symbol class, which is used to represent all terminals
* and nonterminals while parsing. The lexer should pass CUP Symbols
* and CUP returns a Symbol.
*
* @author Frank Flannery
*/
/* ****************************************************************
Class Symbol
what the parser expects to receive from the lexer.
the token is identified as follows:
sym: the symbol type
parse_state: the parse state.
value: is the lexical value of type Object
left : is the left position in the original input file
right: is the right position in the original input file
******************************************************************/
public class Symbol {
/*******************************
Constructor for l,r values
*******************************/
public Symbol(int id, int l, int r, Object o) {
this(id);
left = l;
right = r;
value = o;
}
/*******************************
Constructor for no l,r values
********************************/
public Symbol(int id, Object o) {
this(id);
left = -1;
right = -1;
value = o;
}
/*****************************
Constructor for no value
***************************/
public Symbol(int sym_num, int l, int r) {
sym = sym_num;
left = l;
right = r;
value = null;
}
/***********************************
Constructor for no value or l,r
***********************************/
public Symbol(int sym_num) {
this(sym_num, -1);
left = -1;
right = -1;
value = null;
}
/***********************************
Constructor to give a start state
***********************************/
public Symbol(int sym_num, int state)
{
sym = sym_num;
parse_state = state;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The symbol number of the terminal or non terminal being represented */
public int sym;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The parse state to be recorded on the parse stack with this symbol.
* This field is for the convenience of the parser and shouldn't be
* modified except by the parser.
*/
public int parse_state;
/** This allows us to catch some errors caused by scanners recycling
* symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
boolean used_by_parser = false;
/*******************************
The data passed to parser
*******************************/
public int left, right;
public Object value;
/*****************************
Printing this token out. (Override for pretty-print).
****************************/
public String toString() { return "#"+sym; }
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,169 @@
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java_cup.internal.runtime;
import java.util.Stack;
/** This class implements a temporary or "virtual" parse stack that
* replaces the top portion of the actual parse stack (the part that
* has been changed by some set of operations) while maintaining its
* original contents. This data structure is used when the parse needs
* to "parse ahead" to determine if a given error recovery attempt will
* allow the parse to continue far enough to consider it successful. Once
* success or failure of parse ahead is determined the system then
* reverts to the original parse stack (which has not actually been
* modified). Since parse ahead does not execute actions, only parse
* state is maintained on the virtual stack, not full Symbol objects.
*
* @see com.sun.java_cup.internal.runtime.lr_parser
* @author Frank Flannery
*/
public class virtual_parse_stack {
/*-----------------------------------------------------------*/
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
/** Constructor to build a virtual stack out of a real stack. */
public virtual_parse_stack(Stack shadowing_stack) throws java.lang.Exception
{
/* sanity check */
if (shadowing_stack == null)
throw new Exception(
"Internal parser error: attempt to create null virtual stack");
/* set up our internals */
real_stack = shadowing_stack;
vstack = new Stack();
real_next = 0;
/* get one element onto the virtual portion of the stack */
get_from_real();
}
/*-----------------------------------------------------------*/
/*--- (Access to) Instance Variables ------------------------*/
/*-----------------------------------------------------------*/
/** The real stack that we shadow. This is accessed when we move off
* the bottom of the virtual portion of the stack, but is always left
* unmodified.
*/
protected Stack real_stack;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Top of stack indicator for where we leave off in the real stack.
* This is measured from top of stack, so 0 would indicate that no
* elements have been "moved" from the real to virtual stack.
*/
protected int real_next;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The virtual top portion of the stack. This stack contains Integer
* objects with state numbers. This stack shadows the top portion
* of the real stack within the area that has been modified (via operations
* on the virtual stack). When this portion of the stack becomes empty we
* transfer elements from the underlying stack onto this stack.
*/
protected Stack vstack;
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/** Transfer an element from the real to the virtual stack. This assumes
* that the virtual stack is currently empty.
*/
protected void get_from_real()
{
Symbol stack_sym;
/* don't transfer if the real stack is empty */
if (real_next >= real_stack.size()) return;
/* get a copy of the first Symbol we have not transfered */
stack_sym = (Symbol)real_stack.elementAt(real_stack.size()-1-real_next);
/* record the transfer */
real_next++;
/* put the state number from the Symbol onto the virtual stack */
vstack.push(new Integer(stack_sym.parse_state));
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Indicate whether the stack is empty. */
public boolean empty()
{
/* if vstack is empty then we were unable to transfer onto it and
the whole thing is empty. */
return vstack.empty();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Return value on the top of the stack (without popping it). */
public int top() throws java.lang.Exception
{
if (vstack.empty())
throw new Exception(
"Internal parser error: top() called on empty virtual stack");
return ((Integer)vstack.peek()).intValue();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Pop the stack. */
public void pop() throws java.lang.Exception
{
if (vstack.empty())
throw new Exception(
"Internal parser error: pop from empty virtual stack");
/* pop it */
vstack.pop();
/* if we are now empty transfer an element (if there is one) */
if (vstack.empty())
get_from_real();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Push a state number onto the stack. */
public void push(int state_num)
{
vstack.push(new Integer(state_num));
}
/*-----------------------------------------------------------*/
}

View file

@ -0,0 +1,788 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Constants for the project, mostly defined in the JVM specification.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface Constants {
/** Major and minor version of the code.
*/
public final static short MAJOR_1_1 = 45;
public final static short MINOR_1_1 = 3;
public final static short MAJOR_1_2 = 46;
public final static short MINOR_1_2 = 0;
public final static short MAJOR_1_3 = 47;
public final static short MINOR_1_3 = 0;
public final static short MAJOR = MAJOR_1_1; // Defaults
public final static short MINOR = MINOR_1_1;
/** Maximum value for an unsigned short.
*/
public final static int MAX_SHORT = 65535; // 2^16 - 1
/** Maximum value for an unsigned byte.
*/
public final static int MAX_BYTE = 255; // 2^8 - 1
/** Access flags for classes, fields and methods.
*/
public final static short ACC_PUBLIC = 0x0001;
public final static short ACC_PRIVATE = 0x0002;
public final static short ACC_PROTECTED = 0x0004;
public final static short ACC_STATIC = 0x0008;
public final static short ACC_FINAL = 0x0010;
public final static short ACC_SYNCHRONIZED = 0x0020;
public final static short ACC_VOLATILE = 0x0040;
public final static short ACC_TRANSIENT = 0x0080;
public final static short ACC_NATIVE = 0x0100;
public final static short ACC_INTERFACE = 0x0200;
public final static short ACC_ABSTRACT = 0x0400;
public final static short ACC_STRICT = 0x0800;
// Applies to classes compiled by new compilers only
public final static short ACC_SUPER = 0x0020;
public final static short MAX_ACC_FLAG = ACC_STRICT;
public final static String[] ACCESS_NAMES = {
"public", "private", "protected", "static", "final", "synchronized",
"volatile", "transient", "native", "interface", "abstract", "strictfp"
};
/** Tags in constant pool to denote type of constant.
*/
public final static byte CONSTANT_Utf8 = 1;
public final static byte CONSTANT_Integer = 3;
public final static byte CONSTANT_Float = 4;
public final static byte CONSTANT_Long = 5;
public final static byte CONSTANT_Double = 6;
public final static byte CONSTANT_Class = 7;
public final static byte CONSTANT_Fieldref = 9;
public final static byte CONSTANT_String = 8;
public final static byte CONSTANT_Methodref = 10;
public final static byte CONSTANT_InterfaceMethodref = 11;
public final static byte CONSTANT_NameAndType = 12;
public final static String[] CONSTANT_NAMES = {
"", "CONSTANT_Utf8", "", "CONSTANT_Integer",
"CONSTANT_Float", "CONSTANT_Long", "CONSTANT_Double",
"CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref",
"CONSTANT_Methodref", "CONSTANT_InterfaceMethodref",
"CONSTANT_NameAndType" };
/** The name of the static initializer, also called &quot;class
* initialization method&quot; or &quot;interface initialization
* method&quot;. This is &quot;&lt;clinit&gt;&quot;.
*/
public final static String STATIC_INITIALIZER_NAME = "<clinit>";
/** The name of every constructor method in a class, also called
* &quot;instance initialization method&quot;. This is &quot;&lt;init&gt;&quot;.
*/
public final static String CONSTRUCTOR_NAME = "<init>";
/** The names of the interfaces implemented by arrays */
public final static String[] INTERFACES_IMPLEMENTED_BY_ARRAYS = {"java.lang.Cloneable", "java.io.Serializable"};
/**
* Limitations of the Java Virtual Machine.
* See The Java Virtual Machine Specification, Second Edition, page 152, chapter 4.10.
*/
public static final int MAX_CP_ENTRIES = 65535;
public static final int MAX_CODE_SIZE = 65536; //bytes
/** Java VM opcodes.
*/
public static final short NOP = 0;
public static final short ACONST_NULL = 1;
public static final short ICONST_M1 = 2;
public static final short ICONST_0 = 3;
public static final short ICONST_1 = 4;
public static final short ICONST_2 = 5;
public static final short ICONST_3 = 6;
public static final short ICONST_4 = 7;
public static final short ICONST_5 = 8;
public static final short LCONST_0 = 9;
public static final short LCONST_1 = 10;
public static final short FCONST_0 = 11;
public static final short FCONST_1 = 12;
public static final short FCONST_2 = 13;
public static final short DCONST_0 = 14;
public static final short DCONST_1 = 15;
public static final short BIPUSH = 16;
public static final short SIPUSH = 17;
public static final short LDC = 18;
public static final short LDC_W = 19;
public static final short LDC2_W = 20;
public static final short ILOAD = 21;
public static final short LLOAD = 22;
public static final short FLOAD = 23;
public static final short DLOAD = 24;
public static final short ALOAD = 25;
public static final short ILOAD_0 = 26;
public static final short ILOAD_1 = 27;
public static final short ILOAD_2 = 28;
public static final short ILOAD_3 = 29;
public static final short LLOAD_0 = 30;
public static final short LLOAD_1 = 31;
public static final short LLOAD_2 = 32;
public static final short LLOAD_3 = 33;
public static final short FLOAD_0 = 34;
public static final short FLOAD_1 = 35;
public static final short FLOAD_2 = 36;
public static final short FLOAD_3 = 37;
public static final short DLOAD_0 = 38;
public static final short DLOAD_1 = 39;
public static final short DLOAD_2 = 40;
public static final short DLOAD_3 = 41;
public static final short ALOAD_0 = 42;
public static final short ALOAD_1 = 43;
public static final short ALOAD_2 = 44;
public static final short ALOAD_3 = 45;
public static final short IALOAD = 46;
public static final short LALOAD = 47;
public static final short FALOAD = 48;
public static final short DALOAD = 49;
public static final short AALOAD = 50;
public static final short BALOAD = 51;
public static final short CALOAD = 52;
public static final short SALOAD = 53;
public static final short ISTORE = 54;
public static final short LSTORE = 55;
public static final short FSTORE = 56;
public static final short DSTORE = 57;
public static final short ASTORE = 58;
public static final short ISTORE_0 = 59;
public static final short ISTORE_1 = 60;
public static final short ISTORE_2 = 61;
public static final short ISTORE_3 = 62;
public static final short LSTORE_0 = 63;
public static final short LSTORE_1 = 64;
public static final short LSTORE_2 = 65;
public static final short LSTORE_3 = 66;
public static final short FSTORE_0 = 67;
public static final short FSTORE_1 = 68;
public static final short FSTORE_2 = 69;
public static final short FSTORE_3 = 70;
public static final short DSTORE_0 = 71;
public static final short DSTORE_1 = 72;
public static final short DSTORE_2 = 73;
public static final short DSTORE_3 = 74;
public static final short ASTORE_0 = 75;
public static final short ASTORE_1 = 76;
public static final short ASTORE_2 = 77;
public static final short ASTORE_3 = 78;
public static final short IASTORE = 79;
public static final short LASTORE = 80;
public static final short FASTORE = 81;
public static final short DASTORE = 82;
public static final short AASTORE = 83;
public static final short BASTORE = 84;
public static final short CASTORE = 85;
public static final short SASTORE = 86;
public static final short POP = 87;
public static final short POP2 = 88;
public static final short DUP = 89;
public static final short DUP_X1 = 90;
public static final short DUP_X2 = 91;
public static final short DUP2 = 92;
public static final short DUP2_X1 = 93;
public static final short DUP2_X2 = 94;
public static final short SWAP = 95;
public static final short IADD = 96;
public static final short LADD = 97;
public static final short FADD = 98;
public static final short DADD = 99;
public static final short ISUB = 100;
public static final short LSUB = 101;
public static final short FSUB = 102;
public static final short DSUB = 103;
public static final short IMUL = 104;
public static final short LMUL = 105;
public static final short FMUL = 106;
public static final short DMUL = 107;
public static final short IDIV = 108;
public static final short LDIV = 109;
public static final short FDIV = 110;
public static final short DDIV = 111;
public static final short IREM = 112;
public static final short LREM = 113;
public static final short FREM = 114;
public static final short DREM = 115;
public static final short INEG = 116;
public static final short LNEG = 117;
public static final short FNEG = 118;
public static final short DNEG = 119;
public static final short ISHL = 120;
public static final short LSHL = 121;
public static final short ISHR = 122;
public static final short LSHR = 123;
public static final short IUSHR = 124;
public static final short LUSHR = 125;
public static final short IAND = 126;
public static final short LAND = 127;
public static final short IOR = 128;
public static final short LOR = 129;
public static final short IXOR = 130;
public static final short LXOR = 131;
public static final short IINC = 132;
public static final short I2L = 133;
public static final short I2F = 134;
public static final short I2D = 135;
public static final short L2I = 136;
public static final short L2F = 137;
public static final short L2D = 138;
public static final short F2I = 139;
public static final short F2L = 140;
public static final short F2D = 141;
public static final short D2I = 142;
public static final short D2L = 143;
public static final short D2F = 144;
public static final short I2B = 145;
public static final short INT2BYTE = 145; // Old notion
public static final short I2C = 146;
public static final short INT2CHAR = 146; // Old notion
public static final short I2S = 147;
public static final short INT2SHORT = 147; // Old notion
public static final short LCMP = 148;
public static final short FCMPL = 149;
public static final short FCMPG = 150;
public static final short DCMPL = 151;
public static final short DCMPG = 152;
public static final short IFEQ = 153;
public static final short IFNE = 154;
public static final short IFLT = 155;
public static final short IFGE = 156;
public static final short IFGT = 157;
public static final short IFLE = 158;
public static final short IF_ICMPEQ = 159;
public static final short IF_ICMPNE = 160;
public static final short IF_ICMPLT = 161;
public static final short IF_ICMPGE = 162;
public static final short IF_ICMPGT = 163;
public static final short IF_ICMPLE = 164;
public static final short IF_ACMPEQ = 165;
public static final short IF_ACMPNE = 166;
public static final short GOTO = 167;
public static final short JSR = 168;
public static final short RET = 169;
public static final short TABLESWITCH = 170;
public static final short LOOKUPSWITCH = 171;
public static final short IRETURN = 172;
public static final short LRETURN = 173;
public static final short FRETURN = 174;
public static final short DRETURN = 175;
public static final short ARETURN = 176;
public static final short RETURN = 177;
public static final short GETSTATIC = 178;
public static final short PUTSTATIC = 179;
public static final short GETFIELD = 180;
public static final short PUTFIELD = 181;
public static final short INVOKEVIRTUAL = 182;
public static final short INVOKESPECIAL = 183;
public static final short INVOKENONVIRTUAL = 183; // Old name in JDK 1.0
public static final short INVOKESTATIC = 184;
public static final short INVOKEINTERFACE = 185;
public static final short NEW = 187;
public static final short NEWARRAY = 188;
public static final short ANEWARRAY = 189;
public static final short ARRAYLENGTH = 190;
public static final short ATHROW = 191;
public static final short CHECKCAST = 192;
public static final short INSTANCEOF = 193;
public static final short MONITORENTER = 194;
public static final short MONITOREXIT = 195;
public static final short WIDE = 196;
public static final short MULTIANEWARRAY = 197;
public static final short IFNULL = 198;
public static final short IFNONNULL = 199;
public static final short GOTO_W = 200;
public static final short JSR_W = 201;
/**
* Non-legal opcodes, may be used by JVM internally.
*/
public static final short BREAKPOINT = 202;
public static final short LDC_QUICK = 203;
public static final short LDC_W_QUICK = 204;
public static final short LDC2_W_QUICK = 205;
public static final short GETFIELD_QUICK = 206;
public static final short PUTFIELD_QUICK = 207;
public static final short GETFIELD2_QUICK = 208;
public static final short PUTFIELD2_QUICK = 209;
public static final short GETSTATIC_QUICK = 210;
public static final short PUTSTATIC_QUICK = 211;
public static final short GETSTATIC2_QUICK = 212;
public static final short PUTSTATIC2_QUICK = 213;
public static final short INVOKEVIRTUAL_QUICK = 214;
public static final short INVOKENONVIRTUAL_QUICK = 215;
public static final short INVOKESUPER_QUICK = 216;
public static final short INVOKESTATIC_QUICK = 217;
public static final short INVOKEINTERFACE_QUICK = 218;
public static final short INVOKEVIRTUALOBJECT_QUICK = 219;
public static final short NEW_QUICK = 221;
public static final short ANEWARRAY_QUICK = 222;
public static final short MULTIANEWARRAY_QUICK = 223;
public static final short CHECKCAST_QUICK = 224;
public static final short INSTANCEOF_QUICK = 225;
public static final short INVOKEVIRTUAL_QUICK_W = 226;
public static final short GETFIELD_QUICK_W = 227;
public static final short PUTFIELD_QUICK_W = 228;
public static final short IMPDEP1 = 254;
public static final short IMPDEP2 = 255;
/**
* For internal purposes only.
*/
public static final short PUSH = 4711;
public static final short SWITCH = 4712;
/**
* Illegal codes
*/
public static final short UNDEFINED = -1;
public static final short UNPREDICTABLE = -2;
public static final short RESERVED = -3;
public static final String ILLEGAL_OPCODE = "<illegal opcode>";
public static final String ILLEGAL_TYPE = "<illegal type>";
public static final byte T_BOOLEAN = 4;
public static final byte T_CHAR = 5;
public static final byte T_FLOAT = 6;
public static final byte T_DOUBLE = 7;
public static final byte T_BYTE = 8;
public static final byte T_SHORT = 9;
public static final byte T_INT = 10;
public static final byte T_LONG = 11;
public static final byte T_VOID = 12; // Non-standard
public static final byte T_ARRAY = 13;
public static final byte T_OBJECT = 14;
public static final byte T_REFERENCE = 14; // Deprecated
public static final byte T_UNKNOWN = 15;
public static final byte T_ADDRESS = 16;
/** The primitive type names corresponding to the T_XX constants,
* e.g., TYPE_NAMES[T_INT] = "int"
*/
public static final String[] TYPE_NAMES = {
ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
"boolean", "char", "float", "double", "byte", "short", "int", "long",
"void", "array", "object", "unknown" // Non-standard
};
/** The primitive class names corresponding to the T_XX constants,
* e.g., CLASS_TYPE_NAMES[T_INT] = "java.lang.Integer"
*/
public static final String[] CLASS_TYPE_NAMES = {
ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
"java.lang.Boolean", "java.lang.Character", "java.lang.Float",
"java.lang.Double", "java.lang.Byte", "java.lang.Short",
"java.lang.Integer", "java.lang.Long", "java.lang.Void",
ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE
};
/** The signature characters corresponding to primitive types,
* e.g., SHORT_TYPE_NAMES[T_INT] = "I"
*/
public static final String[] SHORT_TYPE_NAMES = {
ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
"Z", "C", "F", "D", "B", "S", "I", "J",
"V", ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE
};
/**
* Number of byte code operands, i.e., number of bytes after the tag byte
* itself.
*/
public static final short[] NO_OF_OPERANDS = {
0/*nop*/, 0/*aconst_null*/, 0/*iconst_m1*/, 0/*iconst_0*/,
0/*iconst_1*/, 0/*iconst_2*/, 0/*iconst_3*/, 0/*iconst_4*/,
0/*iconst_5*/, 0/*lconst_0*/, 0/*lconst_1*/, 0/*fconst_0*/,
0/*fconst_1*/, 0/*fconst_2*/, 0/*dconst_0*/, 0/*dconst_1*/,
1/*bipush*/, 2/*sipush*/, 1/*ldc*/, 2/*ldc_w*/, 2/*ldc2_w*/,
1/*iload*/, 1/*lload*/, 1/*fload*/, 1/*dload*/, 1/*aload*/,
0/*iload_0*/, 0/*iload_1*/, 0/*iload_2*/, 0/*iload_3*/,
0/*lload_0*/, 0/*lload_1*/, 0/*lload_2*/, 0/*lload_3*/,
0/*fload_0*/, 0/*fload_1*/, 0/*fload_2*/, 0/*fload_3*/,
0/*dload_0*/, 0/*dload_1*/, 0/*dload_2*/, 0/*dload_3*/,
0/*aload_0*/, 0/*aload_1*/, 0/*aload_2*/, 0/*aload_3*/,
0/*iaload*/, 0/*laload*/, 0/*faload*/, 0/*daload*/,
0/*aaload*/, 0/*baload*/, 0/*caload*/, 0/*saload*/,
1/*istore*/, 1/*lstore*/, 1/*fstore*/, 1/*dstore*/,
1/*astore*/, 0/*istore_0*/, 0/*istore_1*/, 0/*istore_2*/,
0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/, 0/*lstore_2*/,
0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/,
0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/,
0/*dstore_3*/, 0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/,
0/*astore_3*/, 0/*iastore*/, 0/*lastore*/, 0/*fastore*/,
0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/,
0/*sastore*/, 0/*pop*/, 0/*pop2*/, 0/*dup*/, 0/*dup_x1*/,
0/*dup_x2*/, 0/*dup2*/, 0/*dup2_x1*/, 0/*dup2_x2*/, 0/*swap*/,
0/*iadd*/, 0/*ladd*/, 0/*fadd*/, 0/*dadd*/, 0/*isub*/,
0/*lsub*/, 0/*fsub*/, 0/*dsub*/, 0/*imul*/, 0/*lmul*/,
0/*fmul*/, 0/*dmul*/, 0/*idiv*/, 0/*ldiv*/, 0/*fdiv*/,
0/*ddiv*/, 0/*irem*/, 0/*lrem*/, 0/*frem*/, 0/*drem*/,
0/*ineg*/, 0/*lneg*/, 0/*fneg*/, 0/*dneg*/, 0/*ishl*/,
0/*lshl*/, 0/*ishr*/, 0/*lshr*/, 0/*iushr*/, 0/*lushr*/,
0/*iand*/, 0/*land*/, 0/*ior*/, 0/*lor*/, 0/*ixor*/, 0/*lxor*/,
2/*iinc*/, 0/*i2l*/, 0/*i2f*/, 0/*i2d*/, 0/*l2i*/, 0/*l2f*/,
0/*l2d*/, 0/*f2i*/, 0/*f2l*/, 0/*f2d*/, 0/*d2i*/, 0/*d2l*/,
0/*d2f*/, 0/*i2b*/, 0/*i2c*/, 0/*i2s*/, 0/*lcmp*/, 0/*fcmpl*/,
0/*fcmpg*/, 0/*dcmpl*/, 0/*dcmpg*/, 2/*ifeq*/, 2/*ifne*/,
2/*iflt*/, 2/*ifge*/, 2/*ifgt*/, 2/*ifle*/, 2/*if_icmpeq*/,
2/*if_icmpne*/, 2/*if_icmplt*/, 2/*if_icmpge*/, 2/*if_icmpgt*/,
2/*if_icmple*/, 2/*if_acmpeq*/, 2/*if_acmpne*/, 2/*goto*/,
2/*jsr*/, 1/*ret*/, UNPREDICTABLE/*tableswitch*/, UNPREDICTABLE/*lookupswitch*/,
0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/,
0/*dreturn*/, 0/*areturn*/, 0/*return*/,
2/*getstatic*/, 2/*putstatic*/, 2/*getfield*/,
2/*putfield*/, 2/*invokevirtual*/, 2/*invokespecial*/, 2/*invokestatic*/,
4/*invokeinterface*/, UNDEFINED, 2/*new*/,
1/*newarray*/, 2/*anewarray*/,
0/*arraylength*/, 0/*athrow*/, 2/*checkcast*/,
2/*instanceof*/, 0/*monitorenter*/,
0/*monitorexit*/, UNPREDICTABLE/*wide*/, 3/*multianewarray*/,
2/*ifnull*/, 2/*ifnonnull*/, 4/*goto_w*/,
4/*jsr_w*/, 0/*breakpoint*/, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, RESERVED/*impdep1*/, RESERVED/*impdep2*/
};
/**
* How the byte code operands are to be interpreted.
*/
public static final short[][] TYPE_OF_OPERANDS = {
{}/*nop*/, {}/*aconst_null*/, {}/*iconst_m1*/, {}/*iconst_0*/,
{}/*iconst_1*/, {}/*iconst_2*/, {}/*iconst_3*/, {}/*iconst_4*/,
{}/*iconst_5*/, {}/*lconst_0*/, {}/*lconst_1*/, {}/*fconst_0*/,
{}/*fconst_1*/, {}/*fconst_2*/, {}/*dconst_0*/, {}/*dconst_1*/,
{T_BYTE}/*bipush*/, {T_SHORT}/*sipush*/, {T_BYTE}/*ldc*/,
{T_SHORT}/*ldc_w*/, {T_SHORT}/*ldc2_w*/,
{T_BYTE}/*iload*/, {T_BYTE}/*lload*/, {T_BYTE}/*fload*/,
{T_BYTE}/*dload*/, {T_BYTE}/*aload*/, {}/*iload_0*/,
{}/*iload_1*/, {}/*iload_2*/, {}/*iload_3*/, {}/*lload_0*/,
{}/*lload_1*/, {}/*lload_2*/, {}/*lload_3*/, {}/*fload_0*/,
{}/*fload_1*/, {}/*fload_2*/, {}/*fload_3*/, {}/*dload_0*/,
{}/*dload_1*/, {}/*dload_2*/, {}/*dload_3*/, {}/*aload_0*/,
{}/*aload_1*/, {}/*aload_2*/, {}/*aload_3*/, {}/*iaload*/,
{}/*laload*/, {}/*faload*/, {}/*daload*/, {}/*aaload*/,
{}/*baload*/, {}/*caload*/, {}/*saload*/, {T_BYTE}/*istore*/,
{T_BYTE}/*lstore*/, {T_BYTE}/*fstore*/, {T_BYTE}/*dstore*/,
{T_BYTE}/*astore*/, {}/*istore_0*/, {}/*istore_1*/,
{}/*istore_2*/, {}/*istore_3*/, {}/*lstore_0*/, {}/*lstore_1*/,
{}/*lstore_2*/, {}/*lstore_3*/, {}/*fstore_0*/, {}/*fstore_1*/,
{}/*fstore_2*/, {}/*fstore_3*/, {}/*dstore_0*/, {}/*dstore_1*/,
{}/*dstore_2*/, {}/*dstore_3*/, {}/*astore_0*/, {}/*astore_1*/,
{}/*astore_2*/, {}/*astore_3*/, {}/*iastore*/, {}/*lastore*/,
{}/*fastore*/, {}/*dastore*/, {}/*aastore*/, {}/*bastore*/,
{}/*castore*/, {}/*sastore*/, {}/*pop*/, {}/*pop2*/, {}/*dup*/,
{}/*dup_x1*/, {}/*dup_x2*/, {}/*dup2*/, {}/*dup2_x1*/,
{}/*dup2_x2*/, {}/*swap*/, {}/*iadd*/, {}/*ladd*/, {}/*fadd*/,
{}/*dadd*/, {}/*isub*/, {}/*lsub*/, {}/*fsub*/, {}/*dsub*/,
{}/*imul*/, {}/*lmul*/, {}/*fmul*/, {}/*dmul*/, {}/*idiv*/,
{}/*ldiv*/, {}/*fdiv*/, {}/*ddiv*/, {}/*irem*/, {}/*lrem*/,
{}/*frem*/, {}/*drem*/, {}/*ineg*/, {}/*lneg*/, {}/*fneg*/,
{}/*dneg*/, {}/*ishl*/, {}/*lshl*/, {}/*ishr*/, {}/*lshr*/,
{}/*iushr*/, {}/*lushr*/, {}/*iand*/, {}/*land*/, {}/*ior*/,
{}/*lor*/, {}/*ixor*/, {}/*lxor*/, {T_BYTE, T_BYTE}/*iinc*/,
{}/*i2l*/, {}/*i2f*/, {}/*i2d*/, {}/*l2i*/, {}/*l2f*/, {}/*l2d*/,
{}/*f2i*/, {}/*f2l*/, {}/*f2d*/, {}/*d2i*/, {}/*d2l*/, {}/*d2f*/,
{}/*i2b*/, {}/*i2c*/,{}/*i2s*/, {}/*lcmp*/, {}/*fcmpl*/,
{}/*fcmpg*/, {}/*dcmpl*/, {}/*dcmpg*/, {T_SHORT}/*ifeq*/,
{T_SHORT}/*ifne*/, {T_SHORT}/*iflt*/, {T_SHORT}/*ifge*/,
{T_SHORT}/*ifgt*/, {T_SHORT}/*ifle*/, {T_SHORT}/*if_icmpeq*/,
{T_SHORT}/*if_icmpne*/, {T_SHORT}/*if_icmplt*/,
{T_SHORT}/*if_icmpge*/, {T_SHORT}/*if_icmpgt*/,
{T_SHORT}/*if_icmple*/, {T_SHORT}/*if_acmpeq*/,
{T_SHORT}/*if_acmpne*/, {T_SHORT}/*goto*/, {T_SHORT}/*jsr*/,
{T_BYTE}/*ret*/, {}/*tableswitch*/, {}/*lookupswitch*/,
{}/*ireturn*/, {}/*lreturn*/, {}/*freturn*/, {}/*dreturn*/,
{}/*areturn*/, {}/*return*/, {T_SHORT}/*getstatic*/,
{T_SHORT}/*putstatic*/, {T_SHORT}/*getfield*/,
{T_SHORT}/*putfield*/, {T_SHORT}/*invokevirtual*/,
{T_SHORT}/*invokespecial*/, {T_SHORT}/*invokestatic*/,
{T_SHORT, T_BYTE, T_BYTE}/*invokeinterface*/, {},
{T_SHORT}/*new*/, {T_BYTE}/*newarray*/,
{T_SHORT}/*anewarray*/, {}/*arraylength*/, {}/*athrow*/,
{T_SHORT}/*checkcast*/, {T_SHORT}/*instanceof*/,
{}/*monitorenter*/, {}/*monitorexit*/, {T_BYTE}/*wide*/,
{T_SHORT, T_BYTE}/*multianewarray*/, {T_SHORT}/*ifnull*/,
{T_SHORT}/*ifnonnull*/, {T_INT}/*goto_w*/, {T_INT}/*jsr_w*/,
{}/*breakpoint*/, {}, {}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
{}/*impdep1*/, {}/*impdep2*/
};
/**
* Names of opcodes.
*/
public static final String[] OPCODE_NAMES = {
"nop", "aconst_null", "iconst_m1", "iconst_0", "iconst_1",
"iconst_2", "iconst_3", "iconst_4", "iconst_5", "lconst_0",
"lconst_1", "fconst_0", "fconst_1", "fconst_2", "dconst_0",
"dconst_1", "bipush", "sipush", "ldc", "ldc_w", "ldc2_w", "iload",
"lload", "fload", "dload", "aload", "iload_0", "iload_1", "iload_2",
"iload_3", "lload_0", "lload_1", "lload_2", "lload_3", "fload_0",
"fload_1", "fload_2", "fload_3", "dload_0", "dload_1", "dload_2",
"dload_3", "aload_0", "aload_1", "aload_2", "aload_3", "iaload",
"laload", "faload", "daload", "aaload", "baload", "caload", "saload",
"istore", "lstore", "fstore", "dstore", "astore", "istore_0",
"istore_1", "istore_2", "istore_3", "lstore_0", "lstore_1",
"lstore_2", "lstore_3", "fstore_0", "fstore_1", "fstore_2",
"fstore_3", "dstore_0", "dstore_1", "dstore_2", "dstore_3",
"astore_0", "astore_1", "astore_2", "astore_3", "iastore", "lastore",
"fastore", "dastore", "aastore", "bastore", "castore", "sastore",
"pop", "pop2", "dup", "dup_x1", "dup_x2", "dup2", "dup2_x1",
"dup2_x2", "swap", "iadd", "ladd", "fadd", "dadd", "isub", "lsub",
"fsub", "dsub", "imul", "lmul", "fmul", "dmul", "idiv", "ldiv",
"fdiv", "ddiv", "irem", "lrem", "frem", "drem", "ineg", "lneg",
"fneg", "dneg", "ishl", "lshl", "ishr", "lshr", "iushr", "lushr",
"iand", "land", "ior", "lor", "ixor", "lxor", "iinc", "i2l", "i2f",
"i2d", "l2i", "l2f", "l2d", "f2i", "f2l", "f2d", "d2i", "d2l", "d2f",
"i2b", "i2c", "i2s", "lcmp", "fcmpl", "fcmpg",
"dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge", "ifgt", "ifle",
"if_icmpeq", "if_icmpne", "if_icmplt", "if_icmpge", "if_icmpgt",
"if_icmple", "if_acmpeq", "if_acmpne", "goto", "jsr", "ret",
"tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn",
"dreturn", "areturn", "return", "getstatic", "putstatic", "getfield",
"putfield", "invokevirtual", "invokespecial", "invokestatic",
"invokeinterface", ILLEGAL_OPCODE, "new", "newarray", "anewarray",
"arraylength", "athrow", "checkcast", "instanceof", "monitorenter",
"monitorexit", "wide", "multianewarray", "ifnull", "ifnonnull",
"goto_w", "jsr_w", "breakpoint", ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, "impdep1", "impdep2"
};
/**
* Number of words consumed on operand stack by instructions.
*/
public static final int[] CONSUME_STACK = {
0/*nop*/, 0/*aconst_null*/, 0/*iconst_m1*/, 0/*iconst_0*/, 0/*iconst_1*/,
0/*iconst_2*/, 0/*iconst_3*/, 0/*iconst_4*/, 0/*iconst_5*/, 0/*lconst_0*/,
0/*lconst_1*/, 0/*fconst_0*/, 0/*fconst_1*/, 0/*fconst_2*/, 0/*dconst_0*/,
0/*dconst_1*/, 0/*bipush*/, 0/*sipush*/, 0/*ldc*/, 0/*ldc_w*/, 0/*ldc2_w*/, 0/*iload*/,
0/*lload*/, 0/*fload*/, 0/*dload*/, 0/*aload*/, 0/*iload_0*/, 0/*iload_1*/, 0/*iload_2*/,
0/*iload_3*/, 0/*lload_0*/, 0/*lload_1*/, 0/*lload_2*/, 0/*lload_3*/, 0/*fload_0*/,
0/*fload_1*/, 0/*fload_2*/, 0/*fload_3*/, 0/*dload_0*/, 0/*dload_1*/, 0/*dload_2*/,
0/*dload_3*/, 0/*aload_0*/, 0/*aload_1*/, 0/*aload_2*/, 0/*aload_3*/, 2/*iaload*/,
2/*laload*/, 2/*faload*/, 2/*daload*/, 2/*aaload*/, 2/*baload*/, 2/*caload*/, 2/*saload*/,
1/*istore*/, 2/*lstore*/, 1/*fstore*/, 2/*dstore*/, 1/*astore*/, 1/*istore_0*/,
1/*istore_1*/, 1/*istore_2*/, 1/*istore_3*/, 2/*lstore_0*/, 2/*lstore_1*/,
2/*lstore_2*/, 2/*lstore_3*/, 1/*fstore_0*/, 1/*fstore_1*/, 1/*fstore_2*/,
1/*fstore_3*/, 2/*dstore_0*/, 2/*dstore_1*/, 2/*dstore_2*/, 2/*dstore_3*/,
1/*astore_0*/, 1/*astore_1*/, 1/*astore_2*/, 1/*astore_3*/, 3/*iastore*/, 4/*lastore*/,
3/*fastore*/, 4/*dastore*/, 3/*aastore*/, 3/*bastore*/, 3/*castore*/, 3/*sastore*/,
1/*pop*/, 2/*pop2*/, 1/*dup*/, 2/*dup_x1*/, 3/*dup_x2*/, 2/*dup2*/, 3/*dup2_x1*/,
4/*dup2_x2*/, 2/*swap*/, 2/*iadd*/, 4/*ladd*/, 2/*fadd*/, 4/*dadd*/, 2/*isub*/, 4/*lsub*/,
2/*fsub*/, 4/*dsub*/, 2/*imul*/, 4/*lmul*/, 2/*fmul*/, 4/*dmul*/, 2/*idiv*/, 4/*ldiv*/,
2/*fdiv*/, 4/*ddiv*/, 2/*irem*/, 4/*lrem*/, 2/*frem*/, 4/*drem*/, 1/*ineg*/, 2/*lneg*/,
1/*fneg*/, 2/*dneg*/, 2/*ishl*/, 3/*lshl*/, 2/*ishr*/, 3/*lshr*/, 2/*iushr*/, 3/*lushr*/,
2/*iand*/, 4/*land*/, 2/*ior*/, 4/*lor*/, 2/*ixor*/, 4/*lxor*/, 0/*iinc*/,
1/*i2l*/, 1/*i2f*/, 1/*i2d*/, 2/*l2i*/, 2/*l2f*/, 2/*l2d*/, 1/*f2i*/, 1/*f2l*/,
1/*f2d*/, 2/*d2i*/, 2/*d2l*/, 2/*d2f*/, 1/*i2b*/, 1/*i2c*/, 1/*i2s*/,
4/*lcmp*/, 2/*fcmpl*/, 2/*fcmpg*/, 4/*dcmpl*/, 4/*dcmpg*/, 1/*ifeq*/, 1/*ifne*/,
1/*iflt*/, 1/*ifge*/, 1/*ifgt*/, 1/*ifle*/, 2/*if_icmpeq*/, 2/*if_icmpne*/, 2/*if_icmplt*/,
2 /*if_icmpge*/, 2/*if_icmpgt*/, 2/*if_icmple*/, 2/*if_acmpeq*/, 2/*if_acmpne*/,
0/*goto*/, 0/*jsr*/, 0/*ret*/, 1/*tableswitch*/, 1/*lookupswitch*/, 1/*ireturn*/,
2/*lreturn*/, 1/*freturn*/, 2/*dreturn*/, 1/*areturn*/, 0/*return*/, 0/*getstatic*/,
UNPREDICTABLE/*putstatic*/, 1/*getfield*/, UNPREDICTABLE/*putfield*/,
UNPREDICTABLE/*invokevirtual*/, UNPREDICTABLE/*invokespecial*/,
UNPREDICTABLE/*invokestatic*/,
UNPREDICTABLE/*invokeinterface*/, UNDEFINED, 0/*new*/, 1/*newarray*/, 1/*anewarray*/,
1/*arraylength*/, 1/*athrow*/, 1/*checkcast*/, 1/*instanceof*/, 1/*monitorenter*/,
1/*monitorexit*/, 0/*wide*/, UNPREDICTABLE/*multianewarray*/, 1/*ifnull*/, 1/*ifnonnull*/,
0/*goto_w*/, 0/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/
};
/**
* Number of words produced onto operand stack by instructions.
*/
public static final int[] PRODUCE_STACK = {
0/*nop*/, 1/*aconst_null*/, 1/*iconst_m1*/, 1/*iconst_0*/, 1/*iconst_1*/,
1/*iconst_2*/, 1/*iconst_3*/, 1/*iconst_4*/, 1/*iconst_5*/, 2/*lconst_0*/,
2/*lconst_1*/, 1/*fconst_0*/, 1/*fconst_1*/, 1/*fconst_2*/, 2/*dconst_0*/,
2/*dconst_1*/, 1/*bipush*/, 1/*sipush*/, 1/*ldc*/, 1/*ldc_w*/, 2/*ldc2_w*/, 1/*iload*/,
2/*lload*/, 1/*fload*/, 2/*dload*/, 1/*aload*/, 1/*iload_0*/, 1/*iload_1*/, 1/*iload_2*/,
1/*iload_3*/, 2/*lload_0*/, 2/*lload_1*/, 2/*lload_2*/, 2/*lload_3*/, 1/*fload_0*/,
1/*fload_1*/, 1/*fload_2*/, 1/*fload_3*/, 2/*dload_0*/, 2/*dload_1*/, 2/*dload_2*/,
2/*dload_3*/, 1/*aload_0*/, 1/*aload_1*/, 1/*aload_2*/, 1/*aload_3*/, 1/*iaload*/,
2/*laload*/, 1/*faload*/, 2/*daload*/, 1/*aaload*/, 1/*baload*/, 1/*caload*/, 1/*saload*/,
0/*istore*/, 0/*lstore*/, 0/*fstore*/, 0/*dstore*/, 0/*astore*/, 0/*istore_0*/,
0/*istore_1*/, 0/*istore_2*/, 0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/,
0/*lstore_2*/, 0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/,
0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/, 0/*dstore_3*/,
0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/, 0/*astore_3*/, 0/*iastore*/, 0/*lastore*/,
0/*fastore*/, 0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/, 0/*sastore*/,
0/*pop*/, 0/*pop2*/, 2/*dup*/, 3/*dup_x1*/, 4/*dup_x2*/, 4/*dup2*/, 5/*dup2_x1*/,
6/*dup2_x2*/, 2/*swap*/, 1/*iadd*/, 2/*ladd*/, 1/*fadd*/, 2/*dadd*/, 1/*isub*/, 2/*lsub*/,
1/*fsub*/, 2/*dsub*/, 1/*imul*/, 2/*lmul*/, 1/*fmul*/, 2/*dmul*/, 1/*idiv*/, 2/*ldiv*/,
1/*fdiv*/, 2/*ddiv*/, 1/*irem*/, 2/*lrem*/, 1/*frem*/, 2/*drem*/, 1/*ineg*/, 2/*lneg*/,
1/*fneg*/, 2/*dneg*/, 1/*ishl*/, 2/*lshl*/, 1/*ishr*/, 2/*lshr*/, 1/*iushr*/, 2/*lushr*/,
1/*iand*/, 2/*land*/, 1/*ior*/, 2/*lor*/, 1/*ixor*/, 2/*lxor*/,
0/*iinc*/, 2/*i2l*/, 1/*i2f*/, 2/*i2d*/, 1/*l2i*/, 1/*l2f*/, 2/*l2d*/, 1/*f2i*/,
2/*f2l*/, 2/*f2d*/, 1/*d2i*/, 2/*d2l*/, 1/*d2f*/,
1/*i2b*/, 1/*i2c*/, 1/*i2s*/, 1/*lcmp*/, 1/*fcmpl*/, 1/*fcmpg*/,
1/*dcmpl*/, 1/*dcmpg*/, 0/*ifeq*/, 0/*ifne*/, 0/*iflt*/, 0/*ifge*/, 0/*ifgt*/, 0/*ifle*/,
0/*if_icmpeq*/, 0/*if_icmpne*/, 0/*if_icmplt*/, 0/*if_icmpge*/, 0/*if_icmpgt*/,
0/*if_icmple*/, 0/*if_acmpeq*/, 0/*if_acmpne*/, 0/*goto*/, 1/*jsr*/, 0/*ret*/,
0/*tableswitch*/, 0/*lookupswitch*/, 0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/,
0/*dreturn*/, 0/*areturn*/, 0/*return*/, UNPREDICTABLE/*getstatic*/, 0/*putstatic*/,
UNPREDICTABLE/*getfield*/, 0/*putfield*/, UNPREDICTABLE/*invokevirtual*/,
UNPREDICTABLE/*invokespecial*/, UNPREDICTABLE/*invokestatic*/,
UNPREDICTABLE/*invokeinterface*/, UNDEFINED, 1/*new*/, 1/*newarray*/, 1/*anewarray*/,
1/*arraylength*/, 1/*athrow*/, 1/*checkcast*/, 1/*instanceof*/, 0/*monitorenter*/,
0/*monitorexit*/, 0/*wide*/, 1/*multianewarray*/, 0/*ifnull*/, 0/*ifnonnull*/,
0/*goto_w*/, 1/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/
};
/** Attributes and their corresponding names.
*/
public static final byte ATTR_UNKNOWN = -1;
public static final byte ATTR_SOURCE_FILE = 0;
public static final byte ATTR_CONSTANT_VALUE = 1;
public static final byte ATTR_CODE = 2;
public static final byte ATTR_EXCEPTIONS = 3;
public static final byte ATTR_LINE_NUMBER_TABLE = 4;
public static final byte ATTR_LOCAL_VARIABLE_TABLE = 5;
public static final byte ATTR_INNER_CLASSES = 6;
public static final byte ATTR_SYNTHETIC = 7;
public static final byte ATTR_DEPRECATED = 8;
public static final byte ATTR_PMG = 9;
public static final byte ATTR_SIGNATURE = 10;
public static final byte ATTR_STACK_MAP = 11;
public static final short KNOWN_ATTRIBUTES = 12;
public static final String[] ATTRIBUTE_NAMES = {
"SourceFile", "ConstantValue", "Code", "Exceptions",
"LineNumberTable", "LocalVariableTable",
"InnerClasses", "Synthetic", "Deprecated",
"PMGClass", "Signature", "StackMap"
};
/** Constants used in the StackMap attribute.
*/
public static final byte ITEM_Bogus = 0;
public static final byte ITEM_Integer = 1;
public static final byte ITEM_Float = 2;
public static final byte ITEM_Double = 3;
public static final byte ITEM_Long = 4;
public static final byte ITEM_Null = 5;
public static final byte ITEM_InitObject = 6;
public static final byte ITEM_Object = 7;
public static final byte ITEM_NewObject = 8;
public static final String[] ITEM_NAMES = {
"Bogus", "Integer", "Float", "Double", "Long",
"Null", "InitObject", "Object", "NewObject"
};
}

View file

@ -0,0 +1,126 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Exception constants.
*
* @author <A HREF="http://www.inf.fu-berlin.de/~ehaase">E. Haase</A>
*/
public interface ExceptionConstants {
/** The mother of all exceptions
*/
public static final Class THROWABLE = Throwable.class;
/** Super class of any run-time exception
*/
public static final Class RUNTIME_EXCEPTION = RuntimeException.class;
/** Super class of any linking exception (aka Linkage Error)
*/
public static final Class LINKING_EXCEPTION = LinkageError.class;
/** Linking Exceptions
*/
public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class;
public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class;
public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class;
public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class;
public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class;
public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class;
public static final Class INSTANTIATION_ERROR = InstantiationError.class;
public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class;
public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class;
public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class;
public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class;
public static final Class VERIFY_ERROR = VerifyError.class;
/* UnsupportedClassVersionError is new in JDK 1.2 */
//public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class;
/** Run-Time Exceptions
*/
public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class;
public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class;
public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class;
public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class;
public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class;
public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class;
/** Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual
* Machine Specification
*/
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = {
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR,
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR
}; // Chapter 5.1
public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = {
NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR
}; // Chapter 5.2
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below)
public static final Class[] EXCS_STRING_RESOLUTION = new Class[0];
// Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
public static final Class[] EXCS_ARRAY_EXCEPTION = {
NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
};
}

View file

@ -0,0 +1,250 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import com.sun.org.apache.bcel.internal.util.*;
import java.io.*;
/**
* The repository maintains informations about class interdependencies, e.g.,
* whether a class is a sub-class of another. Delegates actual class loading
* to SyntheticRepository with current class path by default.
*
* @see com.sun.org.apache.bcel.internal.util.Repository
* @see com.sun.org.apache.bcel.internal.util.SyntheticRepository
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class Repository {
private static com.sun.org.apache.bcel.internal.util.Repository _repository =
SyntheticRepository.getInstance();
/** @return currently used repository instance
*/
public static com.sun.org.apache.bcel.internal.util.Repository getRepository() {
return _repository;
}
/** Set repository instance to be used for class loading
*/
public static void setRepository(com.sun.org.apache.bcel.internal.util.Repository rep) {
_repository = rep;
}
/** Lookup class somewhere found on your CLASSPATH, or whereever the
* repository instance looks for it.
*
* @return class object for given fully qualified class name, or null
* if the class could not be found or parsed correctly
*/
public static JavaClass lookupClass(String class_name) {
try {
JavaClass clazz = _repository.findClass(class_name);
if(clazz == null) {
return _repository.loadClass(class_name);
} else {
return clazz;
}
} catch(ClassNotFoundException ex) { return null; }
}
/**
* Try to find class source via getResourceAsStream().
* @see Class
* @return JavaClass object for given runtime class
*/
public static JavaClass lookupClass(Class clazz) {
try {
return _repository.loadClass(clazz);
} catch(ClassNotFoundException ex) { return null; }
}
/** @return class file object for given Java class.
*/
public static ClassPath.ClassFile lookupClassFile(String class_name) {
try {
return ClassPath.SYSTEM_CLASS_PATH.getClassFile(class_name);
} catch(IOException e) { return null; }
}
/** Clear the repository.
*/
public static void clearCache() {
_repository.clear();
}
/**
* Add clazz to repository if there isn't an equally named class already in there.
*
* @return old entry in repository
*/
public static JavaClass addClass(JavaClass clazz) {
JavaClass old = _repository.findClass(clazz.getClassName());
_repository.storeClass(clazz);
return old;
}
/**
* Remove class with given (fully qualified) name from repository.
*/
public static void removeClass(String clazz) {
_repository.removeClass(_repository.findClass(clazz));
}
/**
* Remove given class from repository.
*/
public static void removeClass(JavaClass clazz) {
_repository.removeClass(clazz);
}
/**
* @return list of super classes of clazz in ascending order, i.e.,
* Object is always the last element
*/
public static JavaClass[] getSuperClasses(JavaClass clazz) {
return clazz.getSuperClasses();
}
/**
* @return list of super classes of clazz in ascending order, i.e.,
* Object is always the last element. return "null", if class
* cannot be found.
*/
public static JavaClass[] getSuperClasses(String class_name) {
JavaClass jc = lookupClass(class_name);
return (jc == null? null : getSuperClasses(jc));
}
/**
* @return all interfaces implemented by class and its super
* classes and the interfaces that those interfaces extend, and so on.
* (Some people call this a transitive hull).
*/
public static JavaClass[] getInterfaces(JavaClass clazz) {
return clazz.getAllInterfaces();
}
/**
* @return all interfaces implemented by class and its super
* classes and the interfaces that extend those interfaces, and so on
*/
public static JavaClass[] getInterfaces(String class_name) {
return getInterfaces(lookupClass(class_name));
}
/**
* Equivalent to runtime "instanceof" operator.
* @return true, if clazz is an instance of super_class
*/
public static boolean instanceOf(JavaClass clazz, JavaClass super_class) {
return clazz.instanceOf(super_class);
}
/**
* @return true, if clazz is an instance of super_class
*/
public static boolean instanceOf(String clazz, String super_class) {
return instanceOf(lookupClass(clazz), lookupClass(super_class));
}
/**
* @return true, if clazz is an instance of super_class
*/
public static boolean instanceOf(JavaClass clazz, String super_class) {
return instanceOf(clazz, lookupClass(super_class));
}
/**
* @return true, if clazz is an instance of super_class
*/
public static boolean instanceOf(String clazz, JavaClass super_class) {
return instanceOf(lookupClass(clazz), super_class);
}
/**
* @return true, if clazz is an implementation of interface inter
*/
public static boolean implementationOf(JavaClass clazz, JavaClass inter) {
return clazz.implementationOf(inter);
}
/**
* @return true, if clazz is an implementation of interface inter
*/
public static boolean implementationOf(String clazz, String inter) {
return implementationOf(lookupClass(clazz), lookupClass(inter));
}
/**
* @return true, if clazz is an implementation of interface inter
*/
public static boolean implementationOf(JavaClass clazz, String inter) {
return implementationOf(clazz, lookupClass(inter));
}
/**
* @return true, if clazz is an implementation of interface inter
*/
public static boolean implementationOf(String clazz, JavaClass inter) {
return implementationOf(lookupClass(clazz), inter);
}
}

View file

@ -0,0 +1,174 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
/**
* Super class for all objects that have modifiers like private, final, ...
* I.e. classes, fields, and methods.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class AccessFlags implements java.io.Serializable {
protected int access_flags;
public AccessFlags() {}
/**
* @param a inital access flags
*/
public AccessFlags(int a) {
access_flags = a;
}
/**
* @return Access flags of the object aka. "modifiers".
*/
public final int getAccessFlags() { return access_flags; }
/**
* @return Access flags of the object aka. "modifiers".
*/
public final int getModifiers() { return access_flags; }
/** Set access flags aka "modifiers".
* @param access_flags Access flags of the object.
*/
public final void setAccessFlags(int access_flags) {
this.access_flags = access_flags;
}
/** Set access flags aka "modifiers".
* @param access_flags Access flags of the object.
*/
public final void setModifiers(int access_flags) {
setAccessFlags(access_flags);
}
private final void setFlag(int flag, boolean set) {
if((access_flags & flag) != 0) { // Flag is set already
if(!set) // Delete flag ?
access_flags ^= flag;
} else { // Flag not set
if(set) // Set flag ?
access_flags |= flag;
}
}
public final void isPublic(boolean flag) { setFlag(Constants.ACC_PUBLIC, flag); }
public final boolean isPublic() {
return (access_flags & Constants.ACC_PUBLIC) != 0;
}
public final void isPrivate(boolean flag) { setFlag(Constants.ACC_PRIVATE, flag); }
public final boolean isPrivate() {
return (access_flags & Constants.ACC_PRIVATE) != 0;
}
public final void isProtected(boolean flag) { setFlag(Constants.ACC_PROTECTED, flag); }
public final boolean isProtected() {
return (access_flags & Constants.ACC_PROTECTED) != 0;
}
public final void isStatic(boolean flag) { setFlag(Constants.ACC_STATIC, flag); }
public final boolean isStatic() {
return (access_flags & Constants.ACC_STATIC) != 0;
}
public final void isFinal(boolean flag) { setFlag(Constants.ACC_FINAL, flag); }
public final boolean isFinal() {
return (access_flags & Constants.ACC_FINAL) != 0;
}
public final void isSynchronized(boolean flag) { setFlag(Constants.ACC_SYNCHRONIZED, flag); }
public final boolean isSynchronized() {
return (access_flags & Constants.ACC_SYNCHRONIZED) != 0;
}
public final void isVolatile(boolean flag) { setFlag(Constants.ACC_VOLATILE, flag); }
public final boolean isVolatile() {
return (access_flags & Constants.ACC_VOLATILE) != 0;
}
public final void isTransient(boolean flag) { setFlag(Constants.ACC_TRANSIENT, flag); }
public final boolean isTransient() {
return (access_flags & Constants.ACC_TRANSIENT) != 0;
}
public final void isNative(boolean flag) { setFlag(Constants.ACC_NATIVE, flag); }
public final boolean isNative() {
return (access_flags & Constants.ACC_NATIVE) != 0;
}
public final void isInterface(boolean flag) { setFlag(Constants.ACC_INTERFACE, flag); }
public final boolean isInterface() {
return (access_flags & Constants.ACC_INTERFACE) != 0;
}
public final void isAbstract(boolean flag) { setFlag(Constants.ACC_ABSTRACT, flag); }
public final boolean isAbstract() {
return (access_flags & Constants.ACC_ABSTRACT) != 0;
}
public final void isStrictfp(boolean flag) { setFlag(Constants.ACC_STRICT, flag); }
public final boolean isStrictfp() {
return (access_flags & Constants.ACC_STRICT) != 0;
}
}

View file

@ -0,0 +1,305 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
import java.util.HashMap;
/**
* Abstract super class for <em>Attribute</em> objects. Currently the
* <em>ConstantValue</em>, <em>SourceFile</em>, <em>Code</em>,
* <em>Exceptiontable</em>, <em>LineNumberTable</em>,
* <em>LocalVariableTable</em>, <em>InnerClasses</em> and
* <em>Synthetic</em> attributes are supported. The
* <em>Unknown</em> attribute stands for non-standard-attributes.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ConstantValue
* @see SourceFile
* @see Code
* @see Unknown
* @see ExceptionTable
* @see LineNumberTable
* @see LocalVariableTable
* @see InnerClasses
* @see Synthetic
* @see Deprecated
* @see Signature
*/
public abstract class Attribute implements Cloneable, Node, Serializable {
protected int name_index; // Points to attribute name in constant pool
protected int length; // Content length of attribute field
protected byte tag; // Tag to distiguish subclasses
protected ConstantPool constant_pool;
protected Attribute(byte tag, int name_index, int length,
ConstantPool constant_pool) {
this.tag = tag;
this.name_index = name_index;
this.length = length;
this.constant_pool = constant_pool;
}
/**
* 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
*/
public abstract void accept(Visitor v);
/**
* Dump attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public void dump(DataOutputStream file) throws IOException
{
file.writeShort(name_index);
file.writeInt(length);
}
private static HashMap readers = new HashMap();
/** Add an Attribute reader capable of parsing (user-defined) attributes
* named "name". You should not add readers for the standard attributes
* such as "LineNumberTable", because those are handled internally.
*
* @param name the name of the attribute as stored in the class file
* @param r the reader object
*/
public static void addAttributeReader(String name, AttributeReader r) {
readers.put(name, r);
}
/** Remove attribute reader
*
* @param name the name of the attribute as stored in the class file
*/
public static void removeAttributeReader(String name) {
readers.remove(name);
}
/* Class method reads one attribute from the input data stream.
* This method must not be accessible from the outside. It is
* called by the Field and Method constructor methods.
*
* @see Field
* @see Method
* @param file Input stream
* @param constant_pool Array of constants
* @return Attribute
* @throws IOException
* @throws ClassFormatException
*/
public static final Attribute readAttribute(DataInputStream file,
ConstantPool constant_pool)
throws IOException, ClassFormatException
{
ConstantUtf8 c;
String name;
int name_index;
int length;
byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute
// Get class name from constant pool via `name_index' indirection
name_index = (int)file.readUnsignedShort();
c = (ConstantUtf8)constant_pool.getConstant(name_index,
Constants.CONSTANT_Utf8);
name = c.getBytes();
// Length of data in bytes
length = file.readInt();
// Compare strings to find known attribute
for(byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) {
if(name.equals(Constants.ATTRIBUTE_NAMES[i])) {
tag = i; // found!
break;
}
}
// Call proper constructor, depending on `tag'
switch(tag) {
case Constants.ATTR_UNKNOWN:
AttributeReader r = (AttributeReader)readers.get(name);
if(r != null)
return r.createAttribute(name_index, length, file, constant_pool);
else
return new Unknown(name_index, length, file, constant_pool);
case Constants.ATTR_CONSTANT_VALUE:
return new ConstantValue(name_index, length, file, constant_pool);
case Constants.ATTR_SOURCE_FILE:
return new SourceFile(name_index, length, file, constant_pool);
case Constants.ATTR_CODE:
return new Code(name_index, length, file, constant_pool);
case Constants.ATTR_EXCEPTIONS:
return new ExceptionTable(name_index, length, file, constant_pool);
case Constants.ATTR_LINE_NUMBER_TABLE:
return new LineNumberTable(name_index, length, file, constant_pool);
case Constants.ATTR_LOCAL_VARIABLE_TABLE:
return new LocalVariableTable(name_index, length, file, constant_pool);
case Constants.ATTR_INNER_CLASSES:
return new InnerClasses(name_index, length, file, constant_pool);
case Constants.ATTR_SYNTHETIC:
return new Synthetic(name_index, length, file, constant_pool);
case Constants.ATTR_DEPRECATED:
return new Deprecated(name_index, length, file, constant_pool);
case Constants.ATTR_PMG:
return new PMGClass(name_index, length, file, constant_pool);
case Constants.ATTR_SIGNATURE:
return new Signature(name_index, length, file, constant_pool);
case Constants.ATTR_STACK_MAP:
return new StackMap(name_index, length, file, constant_pool);
default: // Never reached
throw new IllegalStateException("Ooops! default case reached.");
}
}
/**
* @return Length of attribute field in bytes.
*/
public final int getLength() { return length; }
/**
* @param Attribute length in bytes.
*/
public final void setLength(int length) {
this.length = length;
}
/**
* @param name_index of attribute.
*/
public final void setNameIndex(int name_index) {
this.name_index = name_index;
}
/**
* @return Name index in constant pool of attribute name.
*/
public final int getNameIndex() { return name_index; }
/**
* @return Tag of attribute, i.e., its type. Value may not be altered, thus
* there is no setTag() method.
*/
public final byte getTag() { return tag; }
/**
* @return Constant pool used by this object.
* @see ConstantPool
*/
public final ConstantPool getConstantPool() { return constant_pool; }
/**
* @param constant_pool Constant pool to be used for this object.
* @see ConstantPool
*/
public final void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
/**
* Use copy() if you want to have a deep copy(), i.e., with all references
* copied correctly.
*
* @return shallow copy of this attribute
*/
public Object clone() {
Object o = null;
try {
o = super.clone();
} catch(CloneNotSupportedException e) {
e.printStackTrace(); // Never occurs
}
return o;
}
/**
* @return deep copy of this attribute
*/
public abstract Attribute copy(ConstantPool constant_pool);
/**
* @return attribute name.
*/
public String toString() {
return Constants.ATTRIBUTE_NAMES[tag];
}
}

View file

@ -0,0 +1,100 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Unknown (non-standard) attributes may be read via user-defined factory
* objects that can be registered with the Attribute.addAttributeReader
* method. These factory objects should implement this interface.
* @see Attribute
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface AttributeReader {
/**
When this attribute reader is added via the static method
Attribute.addAttributeReader, an attribute name is associated with it.
As the class file parser parses attributes, it will call various
AttributeReaders based on the name of the attributes it is
constructing.
@param name_index An index into the constant pool, indexing a
ConstantUtf8 that represents the name of the attribute.
@param length The length of the data contained in the attribute. This
is written into the constant pool and should agree with what the
factory expects the length to be.
@param file This is the data input stream that the factory needs to read
its data from.
@param constant_pool This is the constant pool associated with the
Attribute that we are constructing.
@return The user-defined AttributeReader should take this data and use
it to construct an attribute. In the case of errors, a null can be
returned which will cause the parsing of the class file to fail.
@see Attribute#addAttributeReader( String, AttributeReader )
*/
public Attribute createAttribute(int name_index,
int length,
java.io.DataInputStream file,
ConstantPool constant_pool);
}

View file

@ -0,0 +1,71 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Thrown when the BCEL attempts to read a class file and determines
* that the file is malformed or otherwise cannot be interpreted as a
* class file.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ClassFormatException extends RuntimeException {
public ClassFormatException() { super(); }
public ClassFormatException(String s) { super(s); }
}

View file

@ -0,0 +1,331 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
import java.util.zip.*;
/**
* Wrapper class that parses a given Java .class file. The method <A
* href ="#parse">parse</A> returns a <A href ="JavaClass.html">
* JavaClass</A> object on success. When an I/O error or an
* inconsistency occurs an appropiate exception is propagated back to
* the caller.
*
* The structure and the names comply, except for a few conveniences,
* exactly with the <A href="ftp://java.sun.com/docs/specs/vmspec.ps">
* JVM specification 1.0</a>. See this paper for
* further details about the structure of a bytecode file.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class ClassParser {
private DataInputStream file;
private ZipFile zip;
private String file_name;
private int class_name_index, superclass_name_index;
private int major, minor; // Compiler version
private int access_flags; // Access rights of parsed class
private int[] interfaces; // Names of implemented interfaces
private ConstantPool constant_pool; // collection of constants
private Field[] fields; // class fields, i.e., its variables
private Method[] methods; // methods defined in the class
private Attribute[] attributes; // attributes defined in the class
private boolean is_zip; // Loaded from zip file
private static final int BUFSIZE = 8192;
/**
* Parse class from the given stream.
*
* @param file Input stream
* @param file_name File name
*/
public ClassParser(InputStream file, String file_name) {
this.file_name = file_name;
String clazz = file.getClass().getName(); // Not a very clean solution ...
is_zip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar.");
if(file instanceof DataInputStream) // Is already a data stream
this.file = (DataInputStream)file;
else
this.file = new DataInputStream(new BufferedInputStream(file, BUFSIZE));
}
/** Parse class from given .class file.
*
* @param file_name file name
* @throws IOException
*/
public ClassParser(String file_name) throws IOException
{
is_zip = false;
this.file_name = file_name;
file = new DataInputStream(new BufferedInputStream
(new FileInputStream(file_name), BUFSIZE));
}
/** Parse class from given .class file in a ZIP-archive
*
* @param file_name file name
* @throws IOException
*/
public ClassParser(String zip_file, String file_name) throws IOException
{
is_zip = true;
zip = new ZipFile(zip_file);
ZipEntry entry = zip.getEntry(file_name);
this.file_name = file_name;
file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry),
BUFSIZE));
}
/**
* Parse the given Java class file and return an object that represents
* the contained data, i.e., constants, methods, fields and commands.
* A <em>ClassFormatException</em> is raised, if the file is not a valid
* .class file. (This does not include verification of the byte code as it
* is performed by the java interpreter).
*
* @return Class object representing the parsed class file
* @throws IOException
* @throws ClassFormatException
*/
public JavaClass parse() throws IOException, ClassFormatException
{
/****************** Read headers ********************************/
// Check magic tag of class file
readID();
// Get compiler version
readVersion();
/****************** Read constant pool and related **************/
// Read constant pool entries
readConstantPool();
// Get class information
readClassInfo();
// Get interface information, i.e., implemented interfaces
readInterfaces();
/****************** Read class fields and methods ***************/
// Read class fields, i.e., the variables of the class
readFields();
// Read class methods, i.e., the functions in the class
readMethods();
// Read class attributes
readAttributes();
// Check for unknown variables
//Unknown[] u = Unknown.getUnknownAttributes();
//for(int i=0; i < u.length; i++)
// System.err.println("WARNING: " + u[i]);
// Everything should have been read now
// if(file.available() > 0) {
// int bytes = file.available();
// byte[] buf = new byte[bytes];
// file.read(buf);
// if(!(is_zip && (buf.length == 1))) {
// System.err.println("WARNING: Trailing garbage at end of " + file_name);
// System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf));
// }
// }
// Read everything of interest, so close the file
file.close();
if(zip != null)
zip.close();
// Return the information we have gathered in a new object
return new JavaClass(class_name_index, superclass_name_index,
file_name, major, minor, access_flags,
constant_pool, interfaces, fields,
methods, attributes, is_zip? JavaClass.ZIP : JavaClass.FILE);
}
/**
* Read information about the attributes of the class.
* @throws IOException
* @throws ClassFormatException
*/
private final void readAttributes() throws IOException, ClassFormatException
{
int attributes_count;
attributes_count = file.readUnsignedShort();
attributes = new Attribute[attributes_count];
for(int i=0; i < attributes_count; i++)
attributes[i] = Attribute.readAttribute(file, constant_pool);
}
/**
* Read information about the class and its super class.
* @throws IOException
* @throws ClassFormatException
*/
private final void readClassInfo() throws IOException, ClassFormatException
{
access_flags = file.readUnsignedShort();
/* Interfaces are implicitely abstract, the flag should be set
* according to the JVM specification.
*/
if((access_flags & Constants.ACC_INTERFACE) != 0)
access_flags |= Constants.ACC_ABSTRACT;
if(((access_flags & Constants.ACC_ABSTRACT) != 0) &&
((access_flags & Constants.ACC_FINAL) != 0 ))
throw new ClassFormatException("Class can't be both final and abstract");
class_name_index = file.readUnsignedShort();
superclass_name_index = file.readUnsignedShort();
}
/**
* Read constant pool entries.
* @throws IOException
* @throws ClassFormatException
*/
private final void readConstantPool() throws IOException, ClassFormatException
{
constant_pool = new ConstantPool(file);
}
/**
* Read information about the fields of the class, i.e., its variables.
* @throws IOException
* @throws ClassFormatException
*/
private final void readFields() throws IOException, ClassFormatException
{
int fields_count;
fields_count = file.readUnsignedShort();
fields = new Field[fields_count];
for(int i=0; i < fields_count; i++)
fields[i] = new Field(file, constant_pool);
}
/******************** Private utility methods **********************/
/**
* Check whether the header of the file is ok.
* Of course, this has to be the first action on successive file reads.
* @throws IOException
* @throws ClassFormatException
*/
private final void readID() throws IOException, ClassFormatException
{
int magic = 0xCAFEBABE;
if(file.readInt() != magic)
throw new ClassFormatException(file_name + " is not a Java .class file");
}
/**
* Read information about the interfaces implemented by this class.
* @throws IOException
* @throws ClassFormatException
*/
private final void readInterfaces() throws IOException, ClassFormatException
{
int interfaces_count;
interfaces_count = file.readUnsignedShort();
interfaces = new int[interfaces_count];
for(int i=0; i < interfaces_count; i++)
interfaces[i] = file.readUnsignedShort();
}
/**
* Read information about the methods of the class.
* @throws IOException
* @throws ClassFormatException
*/
private final void readMethods() throws IOException, ClassFormatException
{
int methods_count;
methods_count = file.readUnsignedShort();
methods = new Method[methods_count];
for(int i=0; i < methods_count; i++)
methods[i] = new Method(file, constant_pool);
}
/**
* Read major and minor version of compiler which created the file.
* @throws IOException
* @throws ClassFormatException
*/
private final void readVersion() throws IOException, ClassFormatException
{
minor = file.readUnsignedShort();
major = file.readUnsignedShort();
}
}

View file

@ -0,0 +1,376 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a chunk of Java byte code contained in a
* method. It is instantiated by the
* <em>Attribute.readAttribute()</em> method. A <em>Code</em>
* attribute contains informations about operand stack, local
* variables, byte code and the exceptions handled within this
* method.
*
* This attribute has attributes itself, namely <em>LineNumberTable</em> which
* is used for debugging purposes and <em>LocalVariableTable</em> which
* contains information about the local variables.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
* @see CodeException
* @see LineNumberTable
* @see LocalVariableTable
*/
public final class Code extends Attribute {
private int max_stack; // Maximum size of stack used by this method
private int max_locals; // Number of local variables
private int code_length; // Length of code in bytes
private byte[] code; // Actual byte code
private int exception_table_length;
private CodeException[] exception_table; // Table of handled exceptions
private int attributes_count; // Attributes of code: LineNumber
private Attribute[] attributes; // or LocalVariable
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public Code(Code c) {
this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(),
c.getCode(), c.getExceptionTable(), c.getAttributes(),
c.getConstantPool());
}
/**
* @param name_index Index pointing to the name <em>Code</em>
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
*/
Code(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
// Initialize with some default values which will be overwritten later
this(name_index, length,
file.readUnsignedShort(), file.readUnsignedShort(),
(byte[])null, (CodeException[])null, (Attribute[])null,
constant_pool);
code_length = file.readInt();
code = new byte[code_length]; // Read byte code
file.readFully(code);
/* Read exception table that contains all regions where an exception
* handler is active, i.e., a try { ... } catch() block.
*/
exception_table_length = file.readUnsignedShort();
exception_table = new CodeException[exception_table_length];
for(int i=0; i < exception_table_length; i++)
exception_table[i] = new CodeException(file);
/* Read all attributes, currently `LineNumberTable' and
* `LocalVariableTable'
*/
attributes_count = file.readUnsignedShort();
attributes = new Attribute[attributes_count];
for(int i=0; i < attributes_count; i++)
attributes[i] = Attribute.readAttribute(file, constant_pool);
/* Adjust length, because of setAttributes in this(), s.b. length
* is incorrect, because it didn't take the internal attributes
* into account yet! Very subtle bug, fixed in 3.1.1.
*/
this.length = length;
}
/**
* @param name_index Index pointing to the name <em>Code</em>
* @param length Content length in bytes
* @param max_stack Maximum size of stack
* @param max_locals Number of local variables
* @param code Actual byte code
* @param exception_table Table of handled exceptions
* @param attributes Attributes of code: LineNumber or LocalVariable
* @param constant_pool Array of constants
*/
public Code(int name_index, int length,
int max_stack, int max_locals,
byte[] code,
CodeException[] exception_table,
Attribute[] attributes,
ConstantPool constant_pool)
{
super(Constants.ATTR_CODE, name_index, length, constant_pool);
this.max_stack = max_stack;
this.max_locals = max_locals;
setCode(code);
setExceptionTable(exception_table);
setAttributes(attributes); // Overwrites length!
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitCode(this);
}
/**
* Dump code attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(max_stack);
file.writeShort(max_locals);
file.writeInt(code_length);
file.write(code, 0, code_length);
file.writeShort(exception_table_length);
for(int i=0; i < exception_table_length; i++)
exception_table[i].dump(file);
file.writeShort(attributes_count);
for(int i=0; i < attributes_count; i++)
attributes[i].dump(file);
}
/**
* @return Collection of code attributes.
* @see Attribute
*/
public final Attribute[] getAttributes() { return attributes; }
/**
* @return LineNumberTable of Code, if it has one
*/
public LineNumberTable getLineNumberTable() {
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof LineNumberTable)
return (LineNumberTable)attributes[i];
return null;
}
/**
* @return LocalVariableTable of Code, if it has one
*/
public LocalVariableTable getLocalVariableTable() {
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof LocalVariableTable)
return (LocalVariableTable)attributes[i];
return null;
}
/**
* @return Actual byte code of the method.
*/
public final byte[] getCode() { return code; }
/**
* @return Table of handled exceptions.
* @see CodeException
*/
public final CodeException[] getExceptionTable() { return exception_table; }
/**
* @return Number of local variables.
*/
public final int getMaxLocals() { return max_locals; }
/**
* @return Maximum size of stack used by this method.
*/
public final int getMaxStack() { return max_stack; }
/**
* @return the internal length of this code attribute (minus the first 6 bytes)
* and excluding all its attributes
*/
private final int getInternalLength() {
return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/
+ code_length /*byte-code*/
+ 2 /*exception-table length*/
+ 8 * exception_table_length /* exception table */
+ 2 /* attributes count */;
}
/**
* @return the full size of this code attribute, minus its first 6 bytes,
* including the size of all its contained attributes
*/
private final int calculateLength() {
int len = 0;
for(int i=0; i < attributes_count; i++)
len += attributes[i].length + 6 /*attribute header size*/;
return len + getInternalLength();
}
/**
* @param attributes.
*/
public final void setAttributes(Attribute[] attributes) {
this.attributes = attributes;
attributes_count = (attributes == null)? 0 : attributes.length;
length = calculateLength(); // Adjust length
}
/**
* @param code byte code
*/
public final void setCode(byte[] code) {
this.code = code;
code_length = (code == null)? 0 : code.length;
}
/**
* @param exception_table exception table
*/
public final void setExceptionTable(CodeException[] exception_table) {
this.exception_table = exception_table;
exception_table_length = (exception_table == null)? 0 :
exception_table.length;
}
/**
* @param max_locals maximum number of local variables
*/
public final void setMaxLocals(int max_locals) {
this.max_locals = max_locals;
}
/**
* @param max_stack maximum stack size
*/
public final void setMaxStack(int max_stack) {
this.max_stack = max_stack;
}
/**
* @return String representation of code chunk.
*/
public final String toString(boolean verbose) {
StringBuffer buf;
buf = new StringBuffer("Code(max_stack = " + max_stack +
", max_locals = " + max_locals +
", code_length = " + code_length + ")\n" +
Utility.codeToString(code, constant_pool, 0, -1, verbose));
if(exception_table_length > 0) {
buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n");
for(int i=0; i < exception_table_length; i++)
buf.append(exception_table[i].toString(constant_pool, verbose) + "\n");
}
if(attributes_count > 0) {
buf.append("\nAttribute(s) = \n");
for(int i=0; i < attributes_count; i++)
buf.append(attributes[i].toString() + "\n");
}
return buf.toString();
}
/**
* @return String representation of code chunk.
*/
public final String toString() {
return toString(true);
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
Code c = (Code)clone();
c.code = (byte[])code.clone();
c.constant_pool = constant_pool;
c.exception_table = new CodeException[exception_table_length];
for(int i=0; i < exception_table_length; i++)
c.exception_table[i] = exception_table[i].copy();
c.attributes = new Attribute[attributes_count];
for(int i=0; i < attributes_count; i++)
c.attributes[i] = attributes[i].copy(constant_pool);
return c;
}
}

View file

@ -0,0 +1,232 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents an entry in the exception table of the <em>Code</em>
* attribute and is used only there. It contains a range in which a
* particular exception handler is active.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
*/
public final class CodeException
implements Cloneable, Constants, Node, Serializable
{
private int start_pc; // Range in the code the exception handler is
private int end_pc; // active. start_pc is inclusive, end_pc exclusive
private int handler_pc; /* Starting address of exception handler, i.e.,
* an offset from start of code.
*/
private int catch_type; /* If this is zero the handler catches any
* exception, otherwise it points to the
* exception class which is to be caught.
*/
/**
* Initialize from another object.
*/
public CodeException(CodeException c) {
this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType());
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
CodeException(DataInputStream file) throws IOException
{
this(file.readUnsignedShort(), file.readUnsignedShort(),
file.readUnsignedShort(), file.readUnsignedShort());
}
/**
* @param start_pc Range in the code the exception handler is active,
* start_pc is inclusive while
* @param end_pc is exclusive
* @param handler_pc Starting address of exception handler, i.e.,
* an offset from start of code.
* @param catch_type If zero the handler catches any
* exception, otherwise it points to the exception class which is
* to be caught.
*/
public CodeException(int start_pc, int end_pc, int handler_pc,
int catch_type)
{
this.start_pc = start_pc;
this.end_pc = end_pc;
this.handler_pc = handler_pc;
this.catch_type = catch_type;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitCodeException(this);
}
/**
* Dump code exception to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(start_pc);
file.writeShort(end_pc);
file.writeShort(handler_pc);
file.writeShort(catch_type);
}
/**
* @return 0, if the handler catches any exception, otherwise it points to
* the exception class which is to be caught.
*/
public final int getCatchType() { return catch_type; }
/**
* @return Exclusive end index of the region where the handler is active.
*/
public final int getEndPC() { return end_pc; }
/**
* @return Starting address of exception handler, relative to the code.
*/
public final int getHandlerPC() { return handler_pc; }
/**
* @return Inclusive start index of the region where the handler is active.
*/
public final int getStartPC() { return start_pc; }
/**
* @param catch_type.
*/
public final void setCatchType(int catch_type) {
this.catch_type = catch_type;
}
/**
* @param end_pc end of handled block
*/
public final void setEndPC(int end_pc) {
this.end_pc = end_pc;
}
/**
* @param handler_pc where the actual code is
*/
public final void setHandlerPC(int handler_pc) {
this.handler_pc = handler_pc;
}
/**
* @param start_pc start of handled block
*/
public final void setStartPC(int start_pc) {
this.start_pc = start_pc;
}
/**
* @return String representation.
*/
public final String toString() {
return "CodeException(start_pc = " + start_pc +
", end_pc = " + end_pc +
", handler_pc = " + handler_pc + ", catch_type = " + catch_type + ")";
}
/**
* @return String representation.
*/
public final String toString(ConstantPool cp, boolean verbose) {
String str;
if(catch_type == 0)
str = "<Any exception>(0)";
else
str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class), false) +
(verbose? "(" + catch_type + ")" : "");
return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str;
}
public final String toString(ConstantPool cp) {
return toString(cp, true);
}
/**
* @return deep copy of this object
*/
public CodeException copy() {
try {
return (CodeException)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
}

View file

@ -0,0 +1,151 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* Abstract superclass for classes to represent the different constant types
* in the constant pool of a class file. The classes keep closely to
* the JVM specification.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class Constant implements Cloneable, Node, Serializable {
/* In fact this tag is redundant since we can distinguish different
* `Constant' objects by their type, i.e., via `instanceof'. In some
* places we will use the tag for switch()es anyway.
*
* First, we want match the specification as closely as possible. Second we
* need the tag as an index to select the corresponding class name from the
* `CONSTANT_NAMES' array.
*/
protected byte tag;
Constant(byte tag) { this.tag = tag; }
/**
* 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
*/
public abstract void accept(Visitor v);
public abstract void dump(DataOutputStream file) throws IOException;
/**
* @return Tag of constant, i.e., its type. No setTag() method to avoid
* confusion.
*/
public final byte getTag() { return tag; }
/**
* @return String representation.
*/
public String toString() {
return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]";
}
/**
* @return deep copy of this constant
*/
public Constant copy() {
try {
return (Constant)super.clone();
} catch(CloneNotSupportedException e) {}
return null;
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* Read one constant from the given file, the type depends on a tag byte.
*
* @param file Input stream
* @return Constant object
*/
static final Constant readConstant(DataInputStream file)
throws IOException, ClassFormatException
{
byte b = file.readByte(); // Read tag byte
switch(b) {
case Constants.CONSTANT_Class: return new ConstantClass(file);
case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file);
case Constants.CONSTANT_Methodref: return new ConstantMethodref(file);
case Constants.CONSTANT_InterfaceMethodref: return new
ConstantInterfaceMethodref(file);
case Constants.CONSTANT_String: return new ConstantString(file);
case Constants.CONSTANT_Integer: return new ConstantInteger(file);
case Constants.CONSTANT_Float: return new ConstantFloat(file);
case Constants.CONSTANT_Long: return new ConstantLong(file);
case Constants.CONSTANT_Double: return new ConstantDouble(file);
case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file);
case Constants.CONSTANT_Utf8: return new ConstantUtf8(file);
default:
throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
}
}
}

View file

@ -0,0 +1,157 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import java.io.*;
import com.sun.org.apache.bcel.internal.Constants;
/**
* Abstract super class for Fieldref and Methodref constants.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ConstantFieldref
* @see ConstantMethodref
* @see ConstantInterfaceMethodref
*/
public abstract class ConstantCP extends Constant {
/** References to the constants containing the class and the field signature
*/
protected int class_index, name_and_type_index;
/**
* Initialize from another object.
*/
public ConstantCP(ConstantCP c) {
this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param tag Constant type tag
* @param file Input stream
* @throws IOException
*/
ConstantCP(byte tag, DataInputStream file) throws IOException
{
this(tag, file.readUnsignedShort(), file.readUnsignedShort());
}
/**
* @param class_index Reference to the class containing the field
* @param name_and_type_index and the field signature
*/
protected ConstantCP(byte tag, int class_index,
int name_and_type_index) {
super(tag);
this.class_index = class_index;
this.name_and_type_index = name_and_type_index;
}
/**
* Dump constant field reference to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeShort(class_index);
file.writeShort(name_and_type_index);
}
/**
* @return Reference (index) to class this field or method belongs to.
*/
public final int getClassIndex() { return class_index; }
/**
* @return Reference (index) to signature of the field.
*/
public final int getNameAndTypeIndex() { return name_and_type_index; }
/**
* @param class_index points to Constant_class
*/
public final void setClassIndex(int class_index) {
this.class_index = class_index;
}
/**
* @return Class this field belongs to.
*/
public String getClass(ConstantPool cp) {
return cp.constantToString(class_index, Constants.CONSTANT_Class);
}
/**
* @param name_and_type_index points to Constant_NameAndType
*/
public final void setNameAndTypeIndex(int name_and_type_index) {
this.name_and_type_index = name_and_type_index;
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(class_index = " + class_index +
", name_and_type_index = " + name_and_type_index + ")";
}
}

View file

@ -0,0 +1,157 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a (external) class.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantClass extends Constant implements ConstantObject {
private int name_index; // Identical to ConstantString except for the name
/**
* Initialize from another object.
*/
public ConstantClass(ConstantClass c) {
this(c.getNameIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantClass(DataInputStream file) throws IOException
{
this(file.readUnsignedShort());
}
/**
* @param name_index Name index in constant pool. Should refer to a
* ConstantUtf8.
*/
public ConstantClass(int name_index) {
super(Constants.CONSTANT_Class);
this.name_index = name_index;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantClass(this);
}
/**
* Dump constant class to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeShort(name_index);
}
/**
* @return Name index in constant pool of class name.
*/
public final int getNameIndex() { return name_index; }
/**
* @param name_index.
*/
public final void setNameIndex(int name_index) {
this.name_index = name_index;
}
/** @return String object
*/
public Object getConstantValue(ConstantPool cp) {
Constant c = cp.getConstant(name_index, Constants.CONSTANT_Utf8);
return ((ConstantUtf8)c).getBytes();
}
/** @return dereferenced string
*/
public String getBytes(ConstantPool cp) {
return (String)getConstantValue(cp);
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(name_index = " + name_index + ")";
}
}

View file

@ -0,0 +1,145 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a Double object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantDouble extends Constant implements ConstantObject {
private double bytes;
/**
* @param bytes Data
*/
public ConstantDouble(double bytes) {
super(Constants.CONSTANT_Double);
this.bytes = bytes;
}
/**
* Initialize from another object.
*/
public ConstantDouble(ConstantDouble c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantDouble(DataInputStream file) throws IOException
{
this(file.readDouble());
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantDouble(this);
}
/**
* Dump constant double to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeDouble(bytes);
}
/**
* @return data, i.e., 8 bytes.
*/
public final double getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(double bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString()
{
return super.toString() + "(bytes = " + bytes + ")";
}
/** @return Double object
*/
public Object getConstantValue(ConstantPool cp) {
return new Double(bytes);
}
}

View file

@ -0,0 +1,107 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a constant pool reference to a field.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class ConstantFieldref extends ConstantCP {
/**
* Initialize from another object.
*/
public ConstantFieldref(ConstantFieldref c) {
super(Constants.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param file input stream
* @throws IOException
*/
ConstantFieldref(DataInputStream file) throws IOException
{
super(Constants.CONSTANT_Fieldref, file);
}
/**
* @param class_index Reference to the class containing the Field
* @param name_and_type_index and the Field signature
*/
public ConstantFieldref(int class_index,
int name_and_type_index) {
super(Constants.CONSTANT_Fieldref, class_index, name_and_type_index);
}
/**
* 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 Fields,
* fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitConstantFieldref(this);
}
}

View file

@ -0,0 +1,144 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a float object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantFloat extends Constant implements ConstantObject {
private float bytes;
/**
* @param bytes Data
*/
public ConstantFloat(float bytes)
{
super(Constants.CONSTANT_Float);
this.bytes = bytes;
}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public ConstantFloat(ConstantFloat c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantFloat(DataInputStream file) throws IOException
{
this(file.readFloat());
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantFloat(this);
}
/**
* Dump constant float to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeFloat(bytes);
}
/**
* @return data, i.e., 4 bytes.
*/
public final float getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(float bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(bytes = " + bytes + ")";
}
/** @return Float object
*/
public Object getConstantValue(ConstantPool cp) {
return new Float(bytes);
}
}

View file

@ -0,0 +1,151 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to an int object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantInteger extends Constant implements ConstantObject {
private int bytes;
/**
* @param bytes Data
*/
public ConstantInteger(int bytes)
{
super(Constants.CONSTANT_Integer);
this.bytes = bytes;
}
/**
* Initialize from another object.
*/
public ConstantInteger(ConstantInteger c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantInteger(DataInputStream file) throws IOException
{
this(file.readInt());
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantInteger(this);
}
/**
* Dump constant integer to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeInt(bytes);
}
/**
* @return data, i.e., 4 bytes.
*/
public final int getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(int bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(bytes = " + bytes + ")";
}
/** @return Integer object
*/
public Object getConstantValue(ConstantPool cp) {
return new Integer(bytes);
}
}

View file

@ -0,0 +1,107 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a constant pool reference to an interface method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class ConstantInterfaceMethodref extends ConstantCP {
/**
* Initialize from another object.
*/
public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) {
super(Constants.CONSTANT_InterfaceMethodref, c.getClassIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param file input stream
* @throws IOException
*/
ConstantInterfaceMethodref(DataInputStream file) throws IOException
{
super(Constants.CONSTANT_InterfaceMethodref, file);
}
/**
* @param class_index Reference to the class containing the method
* @param name_and_type_index and the method signature
*/
public ConstantInterfaceMethodref(int class_index,
int name_and_type_index) {
super(Constants.CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantInterfaceMethodref(this);
}
}

View file

@ -0,0 +1,142 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a long object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantLong extends Constant implements ConstantObject {
private long bytes;
/**
* @param bytes Data
*/
public ConstantLong(long bytes)
{
super(Constants.CONSTANT_Long);
this.bytes = bytes;
}
/**
* Initialize from another object.
*/
public ConstantLong(ConstantLong c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantLong(DataInputStream file) throws IOException
{
this(file.readLong());
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantLong(this);
}
/**
* Dump constant long to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeLong(bytes);
}
/**
* @return data, i.e., 8 bytes.
*/
public final long getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(long bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(bytes = " + bytes + ")";
}
/** @return Long object
*/
public Object getConstantValue(ConstantPool cp) {
return new Long(bytes);
}
}

View file

@ -0,0 +1,107 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a constant pool reference to a method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class ConstantMethodref extends ConstantCP {
/**
* Initialize from another object.
*/
public ConstantMethodref(ConstantMethodref c) {
super(Constants.CONSTANT_Methodref, c.getClassIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param file input stream
* @throws IOException
*/
ConstantMethodref(DataInputStream file) throws IOException
{
super(Constants.CONSTANT_Methodref, file);
}
/**
* @param class_index Reference to the class containing the method
* @param name_and_type_index and the method signature
*/
public ConstantMethodref(int class_index,
int name_and_type_index) {
super(Constants.CONSTANT_Methodref, class_index, name_and_type_index);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantMethodref(this);
}
}

View file

@ -0,0 +1,174 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to the name and signature
* of a field or method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantNameAndType extends Constant {
private int name_index; // Name of field/method
private int signature_index; // and its signature.
/**
* Initialize from another object.
*/
public ConstantNameAndType(ConstantNameAndType c) {
this(c.getNameIndex(), c.getSignatureIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantNameAndType(DataInputStream file) throws IOException
{
this((int)file.readUnsignedShort(), (int)file.readUnsignedShort());
}
/**
* @param name_index Name of field/method
* @param signature_index and its signature
*/
public ConstantNameAndType(int name_index,
int signature_index)
{
super(Constants.CONSTANT_NameAndType);
this.name_index = name_index;
this.signature_index = signature_index;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantNameAndType(this);
}
/**
* Dump name and signature index to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeShort(name_index);
file.writeShort(signature_index);
}
/**
* @return Name index in constant pool of field/method name.
*/
public final int getNameIndex() { return name_index; }
/** @return name
*/
public final String getName(ConstantPool cp) {
return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
}
/**
* @return Index in constant pool of field/method signature.
*/
public final int getSignatureIndex() { return signature_index; }
/** @return signature
*/
public final String getSignature(ConstantPool cp) {
return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
}
/**
* @param name_index.
*/
public final void setNameIndex(int name_index) {
this.name_index = name_index;
}
/**
* @param signature_index.
*/
public final void setSignatureIndex(int signature_index) {
this.signature_index = signature_index;
}
/**
* @return String representation
*/
public final String toString() {
return super.toString() + "(name_index = " + name_index +
", signature_index = " + signature_index + ")";
}
}

View file

@ -0,0 +1,72 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* This interface denotes those constants that have a "natural" value,
* such as ConstantLong, ConstantString, etc..
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public interface ConstantObject {
/** @return object representing the constant, e.g., Long for ConstantLong
*/
public abstract Object getConstantValue(ConstantPool cp);
}

View file

@ -0,0 +1,375 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents the constant pool, i.e., a table of constants, of
* a parsed classfile. It may contain null references, due to the JVM
* specification that skips an entry after an 8-byte constant (double,
* long) entry. Those interested in generating constant pools
* programatically should see <a href="../generic/ConstantPoolGen.html">
* ConstantPoolGen</a>.
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ConstantPool implements Cloneable, Node, Serializable {
private int constant_pool_count;
private Constant[] constant_pool;
/**
* @param constant_pool Array of constants
*/
public ConstantPool(Constant[] constant_pool)
{
setConstantPool(constant_pool);
}
/**
* Read constants from given file stream.
*
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
*/
ConstantPool(DataInputStream file) throws IOException, ClassFormatException
{
byte tag;
constant_pool_count = file.readUnsignedShort();
constant_pool = new Constant[constant_pool_count];
/* constant_pool[0] is unused by the compiler and may be used freely
* by the implementation.
*/
for(int i=1; i < constant_pool_count; i++) {
constant_pool[i] = Constant.readConstant(file);
/* Quote from the JVM specification:
* "All eight byte constants take up two spots in the constant pool.
* If this is the n'th byte in the constant pool, then the next item
* will be numbered n+2"
*
* Thus we have to increment the index counter.
*/
tag = constant_pool[i].getTag();
if((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long))
i++;
}
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantPool(this);
}
/**
* Resolve constant to a string representation.
*
* @param constant Constant to be printed
* @return String representation
*/
public String constantToString(Constant c)
throws ClassFormatException
{
String str;
int i;
byte tag = c.getTag();
switch(tag) {
case Constants.CONSTANT_Class:
i = ((ConstantClass)c).getNameIndex();
c = getConstant(i, Constants.CONSTANT_Utf8);
str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
break;
case Constants.CONSTANT_String:
i = ((ConstantString)c).getStringIndex();
c = getConstant(i, Constants.CONSTANT_Utf8);
str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
break;
case Constants.CONSTANT_Utf8: str = ((ConstantUtf8)c).getBytes(); break;
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break;
case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break;
case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break;
case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;
case Constants.CONSTANT_NameAndType:
str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
Constants.CONSTANT_Utf8) + " " +
constantToString(((ConstantNameAndType)c).getSignatureIndex(),
Constants.CONSTANT_Utf8));
break;
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref:
str = (constantToString(((ConstantCP)c).getClassIndex(),
Constants.CONSTANT_Class) + "." +
constantToString(((ConstantCP)c).getNameAndTypeIndex(),
Constants.CONSTANT_NameAndType));
break;
default: // Never reached
throw new RuntimeException("Unknown constant type " + tag);
}
return str;
}
private static final String escape(String str) {
int len = str.length();
StringBuffer buf = new StringBuffer(len + 5);
char[] ch = str.toCharArray();
for(int i=0; i < len; i++) {
switch(ch[i]) {
case '\n' : buf.append("\\n"); break;
case '\r' : buf.append("\\r"); break;
case '\t' : buf.append("\\t"); break;
case '\b' : buf.append("\\b"); break;
case '"' : buf.append("\\\""); break;
default: buf.append(ch[i]);
}
}
return buf.toString();
}
/**
* Retrieve constant at `index' from constant pool and resolve it to
* a string representation.
*
* @param index of constant in constant pool
* @param tag expected type
* @return String representation
*/
public String constantToString(int index, byte tag)
throws ClassFormatException
{
Constant c = getConstant(index, tag);
return constantToString(c);
}
/**
* Dump constant pool to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public void dump(DataOutputStream file) throws IOException
{
file.writeShort(constant_pool_count);
for(int i=1; i < constant_pool_count; i++)
if(constant_pool[i] != null)
constant_pool[i].dump(file);
}
/**
* Get constant from constant pool.
*
* @param index Index in constant pool
* @return Constant value
* @see Constant
*/
public Constant getConstant(int index) {
if (index >= constant_pool.length || index < 0)
throw new ClassFormatException("Invalid constant pool reference: " +
index + ". Constant pool size is: " +
constant_pool.length);
return constant_pool[index];
}
/**
* Get constant from constant pool and check whether it has the
* expected type.
*
* @param index Index in constant pool
* @param tag Tag of expected constant, i.e., its type
* @return Constant value
* @see Constant
* @throws ClassFormatException
*/
public Constant getConstant(int index, byte tag)
throws ClassFormatException
{
Constant c;
c = getConstant(index);
if(c == null)
throw new ClassFormatException("Constant pool at index " + index + " is null.");
if(c.getTag() == tag)
return c;
else
throw new ClassFormatException("Expected class `" + Constants.CONSTANT_NAMES[tag] +
"' at index " + index + " and got " + c);
}
/**
* @return Array of constants.
* @see Constant
*/
public Constant[] getConstantPool() { return constant_pool; }
/**
* Get string from constant pool and bypass the indirection of
* `ConstantClass' and `ConstantString' objects. I.e. these classes have
* an index field that points to another entry of the constant pool of
* type `ConstantUtf8' which contains the real data.
*
* @param index Index in constant pool
* @param tag Tag of expected constant, either ConstantClass or ConstantString
* @return Contents of string reference
* @see ConstantClass
* @see ConstantString
* @throws ClassFormatException
*/
public String getConstantString(int index, byte tag)
throws ClassFormatException
{
Constant c;
int i;
c = getConstant(index, tag);
/* This switch() is not that elegant, since the two classes have the
* same contents, they just differ in the name of the index
* field variable.
* But we want to stick to the JVM naming conventions closely though
* we could have solved these more elegantly by using the same
* variable name or by subclassing.
*/
switch(tag) {
case Constants.CONSTANT_Class: i = ((ConstantClass)c).getNameIndex(); break;
case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
default:
throw new RuntimeException("getConstantString called with illegal tag " + tag);
}
// Finally get the string from the constant pool
c = getConstant(i, Constants.CONSTANT_Utf8);
return ((ConstantUtf8)c).getBytes();
}
/**
* @return Length of constant pool.
*/
public int getLength()
{
return constant_pool_count;
}
/**
* @param constant Constant to set
*/
public void setConstant(int index, Constant constant) {
constant_pool[index] = constant;
}
/**
* @param constant_pool
*/
public void setConstantPool(Constant[] constant_pool) {
this.constant_pool = constant_pool;
constant_pool_count = (constant_pool == null)? 0 : constant_pool.length;
}
/**
* @return String representation.
*/
public String toString() {
StringBuffer buf = new StringBuffer();
for(int i=1; i < constant_pool_count; i++)
buf.append(i + ")" + constant_pool[i] + "\n");
return buf.toString();
}
/**
* @return deep copy of this constant pool
*/
public ConstantPool copy() {
ConstantPool c = null;
try {
c = (ConstantPool)clone();
} catch(CloneNotSupportedException e) {}
c.constant_pool = new Constant[constant_pool_count];
for(int i=1; i < constant_pool_count; i++) {
if(constant_pool[i] != null)
c.constant_pool[i] = constant_pool[i].copy();
}
return c;
}
}

View file

@ -0,0 +1,150 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a String object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantString extends Constant implements ConstantObject {
private int string_index; // Identical to ConstantClass except for this name
/**
* Initialize from another object.
*/
public ConstantString(ConstantString c) {
this(c.getStringIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantString(DataInputStream file) throws IOException
{
this((int)file.readUnsignedShort());
}
/**
* @param string_index Index of Constant_Utf8 in constant pool
*/
public ConstantString(int string_index)
{
super(Constants.CONSTANT_String);
this.string_index = string_index;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantString(this);
}
/**
* Dump constant field reference to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeShort(string_index);
}
/**
* @return Index in constant pool of the string (ConstantUtf8).
*/
public final int getStringIndex() { return string_index; }
/**
* @param string_index.
*/
public final void setStringIndex(int string_index) {
this.string_index = string_index;
}
/**
* @return String representation.
*/
public final String toString()
{
return super.toString() + "(string_index = " + string_index + ")";
}
/** @return String object
*/
public Object getConstantValue(ConstantPool cp) {
Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8);
return ((ConstantUtf8)c).getBytes();
}
/** @return dereferenced string
*/
public String getBytes(ConstantPool cp) {
return (String)getConstantValue(cp);
}
}

View file

@ -0,0 +1,150 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a Utf8 encoded string.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantUtf8 extends Constant {
private String bytes;
/**
* Initialize from another object.
*/
public ConstantUtf8(ConstantUtf8 c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantUtf8(DataInputStream file) throws IOException
{
super(Constants.CONSTANT_Utf8);
bytes = file.readUTF();
}
/**
* @param bytes Data
*/
public ConstantUtf8(String bytes)
{
super(Constants.CONSTANT_Utf8);
if(bytes == null)
throw new IllegalArgumentException("bytes must not be null!");
this.bytes = bytes;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantUtf8(this);
}
/**
* Dump String in Utf8 format to file stream.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeUTF(bytes);
}
/**
* @return Data converted to string.
*/
public final String getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(String bytes) {
this.bytes = bytes;
}
/**
* @return String representation
*/
public final String toString()
{
return super.toString() + "(\"" + Utility.replace(bytes, "\n", "\\n") + "\")";
}
}

View file

@ -0,0 +1,181 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and represents a constant
* value, i.e., a default value for initializing a class field.
* This class is instantiated by the <em>Attribute.readAttribute()</em> method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class ConstantValue extends Attribute {
private int constantvalue_index;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public ConstantValue(ConstantValue c) {
this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(),
c.getConstantPool());
}
/**
* Construct object from file stream.
* @param name_index Name index in constant pool
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throw IOException
*/
ConstantValue(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (int)file.readUnsignedShort(), constant_pool);
}
/**
* @param name_index Name index in constant pool
* @param length Content length in bytes
* @param constantvalue_index Index in constant pool
* @param constant_pool Array of constants
*/
public ConstantValue(int name_index, int length,
int constantvalue_index,
ConstantPool constant_pool)
{
super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool);
this.constantvalue_index = constantvalue_index;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitConstantValue(this);
}
/**
* Dump constant value attribute to file stream on binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(constantvalue_index);
}
/**
* @return Index in constant pool of constant value.
*/
public final int getConstantValueIndex() { return constantvalue_index; }
/**
* @param constantvalue_index.
*/
public final void setConstantValueIndex(int constantvalue_index) {
this.constantvalue_index = constantvalue_index;
}
/**
* @return String representation of constant value.
*/
public final String toString() {
Constant c = constant_pool.getConstant(constantvalue_index);
String buf;
int i;
// Print constant to string depending on its type
switch(c.getTag()) {
case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break;
case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break;
case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break;
case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break;
case Constants.CONSTANT_String:
i = ((ConstantString)c).getStringIndex();
c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8);
buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\"";
break;
default:
throw new IllegalStateException("Type of ConstValue invalid: " + c);
}
return buf;
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
ConstantValue c = (ConstantValue)clone();
c.constant_pool = constant_pool;
return c;
}
}

View file

@ -0,0 +1,172 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and denotes that this is a
* deprecated method.
* It is instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class Deprecated extends Attribute {
private byte[] bytes;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public Deprecated(Deprecated c) {
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param bytes Attribute contents
* @param constant_pool Array of constants
*/
public Deprecated(int name_index, int length, byte[] bytes,
ConstantPool constant_pool)
{
super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool);
this.bytes = bytes;
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
Deprecated(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (byte [])null, constant_pool);
if(length > 0) {
bytes = new byte[length];
file.readFully(bytes);
System.err.println("Deprecated attribute with length > 0");
}
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitDeprecated(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
if(length > 0)
file.write(bytes, 0, length);
}
/**
* @return data bytes.
*/
public final byte[] getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(byte[] bytes) {
this.bytes = bytes;
}
/**
* @return attribute name
*/
public final String toString() {
return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED];
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
Deprecated c = (Deprecated)clone();
if(bytes != null)
c.bytes = (byte[])bytes.clone();
c.constant_pool = constant_pool;
return c;
}
}

View file

@ -0,0 +1,360 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import java.util.Stack;
/**
* Traverses a JavaClass with another Visitor object 'piggy-backed'
* that is applied to all components of a JavaClass object. I.e. this
* class supplies the traversal strategy, other classes can make use
* of it.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class DescendingVisitor implements Visitor {
private JavaClass clazz;
private Visitor visitor;
private Stack stack = new Stack();
/** @return container of current entitity, i.e., predecessor during traversal
*/
public Object predecessor() {
return predecessor(0);
}
/**
* @param level nesting level, i.e., 0 returns the direct predecessor
* @return container of current entitity, i.e., predecessor during traversal
*/
public Object predecessor(int level) {
int size = stack.size();
if((size < 2) || (level < 0))
return null;
else
return stack.elementAt(size - (level + 2)); // size - 1 == current
}
/** @return current object
*/
public Object current() {
return stack.peek();
}
/**
* @param clazz Class to traverse
* @param visitor visitor object to apply to all components
*/
public DescendingVisitor(JavaClass clazz, Visitor visitor) {
this.clazz = clazz;
this.visitor = visitor;
}
/**
* Start traversal.
*/
public void visit() { clazz.accept(this); }
public void visitJavaClass(JavaClass clazz) {
stack.push(clazz);
clazz.accept(visitor);
Field[] fields = clazz.getFields();
for(int i=0; i < fields.length; i++)
fields[i].accept(this);
Method[] methods = clazz.getMethods();
for(int i=0; i < methods.length; i++)
methods[i].accept(this);
Attribute[] attributes = clazz.getAttributes();
for(int i=0; i < attributes.length; i++)
attributes[i].accept(this);
clazz.getConstantPool().accept(this);
stack.pop();
}
public void visitField(Field field) {
stack.push(field);
field.accept(visitor);
Attribute[] attributes = field.getAttributes();
for(int i=0; i < attributes.length; i++)
attributes[i].accept(this);
stack.pop();
}
public void visitConstantValue(ConstantValue cv) {
stack.push(cv);
cv.accept(visitor);
stack.pop();
}
public void visitMethod(Method method) {
stack.push(method);
method.accept(visitor);
Attribute[] attributes = method.getAttributes();
for(int i=0; i < attributes.length; i++)
attributes[i].accept(this);
stack.pop();
}
public void visitExceptionTable(ExceptionTable table) {
stack.push(table);
table.accept(visitor);
stack.pop();
}
public void visitCode(Code code) {
stack.push(code);
code.accept(visitor);
CodeException[] table = code.getExceptionTable();
for(int i=0; i < table.length; i++)
table[i].accept(this);
Attribute[] attributes = code.getAttributes();
for(int i=0; i < attributes.length; i++)
attributes[i].accept(this);
stack.pop();
}
public void visitCodeException(CodeException ce) {
stack.push(ce);
ce.accept(visitor);
stack.pop();
}
public void visitLineNumberTable(LineNumberTable table) {
stack.push(table);
table.accept(visitor);
LineNumber[] numbers = table.getLineNumberTable();
for(int i=0; i < numbers.length; i++)
numbers[i].accept(this);
stack.pop();
}
public void visitLineNumber(LineNumber number) {
stack.push(number);
number.accept(visitor);
stack.pop();
}
public void visitLocalVariableTable(LocalVariableTable table) {
stack.push(table);
table.accept(visitor);
LocalVariable[] vars = table.getLocalVariableTable();
for(int i=0; i < vars.length; i++)
vars[i].accept(this);
stack.pop();
}
public void visitStackMap(StackMap table) {
stack.push(table);
table.accept(visitor);
StackMapEntry[] vars = table.getStackMap();
for(int i=0; i < vars.length; i++)
vars[i].accept(this);
stack.pop();
}
public void visitStackMapEntry(StackMapEntry var) {
stack.push(var);
var.accept(visitor);
stack.pop();
}
public void visitLocalVariable(LocalVariable var) {
stack.push(var);
var.accept(visitor);
stack.pop();
}
public void visitConstantPool(ConstantPool cp) {
stack.push(cp);
cp.accept(visitor);
Constant[] constants = cp.getConstantPool();
for(int i=1; i < constants.length; i++) {
if(constants[i] != null)
constants[i].accept(this);
}
stack.pop();
}
public void visitConstantClass(ConstantClass constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantDouble(ConstantDouble constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantFieldref(ConstantFieldref constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantFloat(ConstantFloat constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantInteger(ConstantInteger constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantLong(ConstantLong constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantMethodref(ConstantMethodref constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantNameAndType(ConstantNameAndType constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantString(ConstantString constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitConstantUtf8(ConstantUtf8 constant) {
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
public void visitInnerClasses(InnerClasses ic) {
stack.push(ic);
ic.accept(visitor);
InnerClass[] ics = ic.getInnerClasses();
for(int i=0; i < ics.length; i++)
ics[i].accept(this);
stack.pop();
}
public void visitInnerClass(InnerClass inner) {
stack.push(inner);
inner.accept(visitor);
stack.pop();
}
public void visitDeprecated(Deprecated attribute) {
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
public void visitSignature(Signature attribute) {
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
public void visitSourceFile(SourceFile attribute) {
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
public void visitSynthetic(Synthetic attribute) {
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
public void visitUnknown(Unknown attribute) {
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
}

View file

@ -0,0 +1,108 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.classfile.*;
import com.sun.org.apache.bcel.internal.*;
/**
* Visitor with empty method bodies, can be extended and used in conjunction with the
* DescendingVisitor class, e.g.
*
* By courtesy of David Spencer.
*
* @see DescendingVisitor
*
*/
public class EmptyVisitor implements Visitor {
protected EmptyVisitor() { }
public void visitCode(Code obj) {}
public void visitCodeException(CodeException obj) {}
public void visitConstantClass(ConstantClass obj) {}
public void visitConstantDouble(ConstantDouble obj) {}
public void visitConstantFieldref(ConstantFieldref obj) {}
public void visitConstantFloat(ConstantFloat obj) {}
public void visitConstantInteger(ConstantInteger obj) {}
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {}
public void visitConstantLong(ConstantLong obj) {}
public void visitConstantMethodref(ConstantMethodref obj) {}
public void visitConstantNameAndType(ConstantNameAndType obj) {}
public void visitConstantPool(ConstantPool obj) {}
public void visitConstantString(ConstantString obj) {}
public void visitConstantUtf8(ConstantUtf8 obj) {}
public void visitConstantValue(ConstantValue obj) {}
public void visitDeprecated(Deprecated obj) {}
public void visitExceptionTable(ExceptionTable obj) {}
public void visitField(Field obj) {}
public void visitInnerClass(InnerClass obj) {}
public void visitInnerClasses(InnerClasses obj) {}
public void visitJavaClass(JavaClass obj) {}
public void visitLineNumber(LineNumber obj) {}
public void visitLineNumberTable(LineNumberTable obj) {}
public void visitLocalVariable(LocalVariable obj) {}
public void visitLocalVariableTable(LocalVariableTable obj) {}
public void visitMethod(Method obj) {}
public void visitSignature(Signature obj) {}
public void visitSourceFile(SourceFile obj) {}
public void visitSynthetic(Synthetic obj) {}
public void visitUnknown(Unknown obj) {}
public void visitStackMap(StackMap obj) {}
public void visitStackMapEntry(StackMapEntry obj) {}
}

View file

@ -0,0 +1,205 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents the table of exceptions that are thrown by a
* method. This attribute may be used once per method. The name of
* this class is <em>ExceptionTable</em> for historical reasons; The
* Java Virtual Machine Specification, Second Edition defines this
* attribute using the name <em>Exceptions</em> (which is inconsistent
* with the other classes).
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
*/
public final class ExceptionTable extends Attribute {
private int number_of_exceptions; // Table of indices into
private int[] exception_index_table; // constant pool
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public ExceptionTable(ExceptionTable c) {
this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(),
c.getConstantPool());
}
/**
* @param name_index Index in constant pool
* @param length Content length in bytes
* @param exception_index_table Table of indices in constant pool
* @param constant_pool Array of constants
*/
public ExceptionTable(int name_index, int length,
int[] exception_index_table,
ConstantPool constant_pool)
{
super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool);
setExceptionIndexTable(exception_index_table);
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
ExceptionTable(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (int[])null, constant_pool);
number_of_exceptions = file.readUnsignedShort();
exception_index_table = new int[number_of_exceptions];
for(int i=0; i < number_of_exceptions; i++)
exception_index_table[i] = file.readUnsignedShort();
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitExceptionTable(this);
}
/**
* Dump exceptions attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(number_of_exceptions);
for(int i=0; i < number_of_exceptions; i++)
file.writeShort(exception_index_table[i]);
}
/**
* @return Array of indices into constant pool of thrown exceptions.
*/
public final int[] getExceptionIndexTable() {return exception_index_table;}
/**
* @return Length of exception table.
*/
public final int getNumberOfExceptions() { return number_of_exceptions; }
/**
* @return class names of thrown exceptions
*/
public final String[] getExceptionNames() {
String[] names = new String[number_of_exceptions];
for(int i=0; i < number_of_exceptions; i++)
names[i] = constant_pool.getConstantString(exception_index_table[i],
Constants.CONSTANT_Class).
replace('/', '.');
return names;
}
/**
* @param exception_index_table.
* Also redefines number_of_exceptions according to table length.
*/
public final void setExceptionIndexTable(int[] exception_index_table) {
this.exception_index_table = exception_index_table;
number_of_exceptions = (exception_index_table == null)? 0 :
exception_index_table.length;
}
/**
* @return String representation, i.e., a list of thrown exceptions.
*/
public final String toString() {
StringBuffer buf = new StringBuffer("");
String str;
for(int i=0; i < number_of_exceptions; i++) {
str = constant_pool.getConstantString(exception_index_table[i],
Constants.CONSTANT_Class);
buf.append(Utility.compactClassName(str, false));
if(i < number_of_exceptions - 1)
buf.append(", ");
}
return buf.toString();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
ExceptionTable c = (ExceptionTable)clone();
c.exception_index_table = (int[])exception_index_table.clone();
c.constant_pool = constant_pool;
return c;
}
}

View file

@ -0,0 +1,168 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.Type;
import java.io.*;
/**
* This class represents the field info structure, i.e., the representation
* for a variable in the class. See JVM specification for details.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class Field extends FieldOrMethod {
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public Field(Field c) {
super(c);
}
/**
* Construct object from file stream.
* @param file Input stream
*/
Field(DataInputStream file, ConstantPool constant_pool)
throws IOException, ClassFormatException
{
super(file, constant_pool);
}
/**
* @param access_flags Access rights of field
* @param name_index Points to field name in constant pool
* @param signature_index Points to encoded signature
* @param attributes Collection of attributes
* @param constant_pool Array of constants
*/
public Field(int access_flags, int name_index, int signature_index,
Attribute[] attributes, ConstantPool constant_pool)
{
super(access_flags, name_index, signature_index, attributes, constant_pool);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitField(this);
}
/**
* @return constant value associated with this field (may be null)
*/
public final ConstantValue getConstantValue() {
for(int i=0; i < attributes_count; i++)
if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE)
return (ConstantValue)attributes[i];
return null;
}
/**
* Return string representation close to declaration format,
* `public static final short MAX = 100', e.g..
*
* @return String representation of field, including the signature.
*/
public final String toString() {
String name, signature, access; // Short cuts to constant pool
// Get names from constant pool
access = Utility.accessToString(access_flags);
access = access.equals("")? "" : (access + " ");
signature = Utility.signatureToString(getSignature());
name = getName();
StringBuffer buf = new StringBuffer(access + signature + " " + name);
ConstantValue cv = getConstantValue();
if(cv != null)
buf.append(" = " + cv);
for(int i=0; i < attributes_count; i++) {
Attribute a = attributes[i];
if(!(a instanceof ConstantValue))
buf.append(" [" + a.toString() + "]");
}
return buf.toString();
}
/**
* @return deep copy of this field
*/
public final Field copy(ConstantPool constant_pool) {
return (Field)copy_(constant_pool);
}
/**
* @return type of field
*/
public Type getType() {
return Type.getReturnType(getSignature());
}
}

View file

@ -0,0 +1,226 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* Abstract super class for fields and methods.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
protected int name_index; // Points to field name in constant pool
protected int signature_index; // Points to encoded signature
protected int attributes_count;// No. of attributes
protected Attribute[] attributes; // Collection of attributes
protected ConstantPool constant_pool;
FieldOrMethod() {}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
protected FieldOrMethod(FieldOrMethod c) {
this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(),
c.getAttributes(), c.getConstantPool());
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
*/
protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool)
throws IOException, ClassFormatException
{
this(file.readUnsignedShort(), file.readUnsignedShort(),
file.readUnsignedShort(), null, constant_pool);
attributes_count = file.readUnsignedShort();
attributes = new Attribute[attributes_count];
for(int i=0; i < attributes_count; i++)
attributes[i] = Attribute.readAttribute(file, constant_pool);
}
/**
* @param access_flags Access rights of method
* @param name_index Points to field name in constant pool
* @param signature_index Points to encoded signature
* @param attributes Collection of attributes
* @param constant_pool Array of constants
*/
protected FieldOrMethod(int access_flags, int name_index, int signature_index,
Attribute[] attributes, ConstantPool constant_pool)
{
this.access_flags = access_flags;
this.name_index = name_index;
this.signature_index = signature_index;
this.constant_pool = constant_pool;
setAttributes(attributes);
}
/**
* Dump object to file stream on binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(access_flags);
file.writeShort(name_index);
file.writeShort(signature_index);
file.writeShort(attributes_count);
for(int i=0; i < attributes_count; i++)
attributes[i].dump(file);
}
/**
* @return Collection of object attributes.
*/
public final Attribute[] getAttributes() { return attributes; }
/**
* @param attributes Collection of object attributes.
*/
public final void setAttributes(Attribute[] attributes) {
this.attributes = attributes;
attributes_count = (attributes == null)? 0 : attributes.length;
}
/**
* @return Constant pool used by this object.
*/
public final ConstantPool getConstantPool() { return constant_pool; }
/**
* @param constant_pool Constant pool to be used for this object.
*/
public final void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
/**
* @return Index in constant pool of object's name.
*/
public final int getNameIndex() { return name_index; }
/**
* @param name_index Index in constant pool of object's name.
*/
public final void setNameIndex(int name_index) {
this.name_index = name_index;
}
/**
* @return Index in constant pool of field signature.
*/
public final int getSignatureIndex() { return signature_index; }
/**
* @param signature_index Index in constant pool of field signature.
*/
public final void setSignatureIndex(int signature_index) {
this.signature_index = signature_index;
}
/**
* @return Name of object, i.e., method name or field name
*/
public final String getName() {
ConstantUtf8 c;
c = (ConstantUtf8)constant_pool.getConstant(name_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return String representation of object's type signature (java style)
*/
public final String getSignature() {
ConstantUtf8 c;
c = (ConstantUtf8)constant_pool.getConstant(signature_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return deep copy of this field
*/
protected FieldOrMethod copy_(ConstantPool constant_pool) {
FieldOrMethod c = null;
try {
c = (FieldOrMethod)clone();
} catch(CloneNotSupportedException e) {}
c.constant_pool = constant_pool;
c.attributes = new Attribute[attributes_count];
for(int i=0; i < attributes_count; i++)
c.attributes[i] = attributes[i].copy(constant_pool);
return c;
}
}

View file

@ -0,0 +1,224 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a inner class attribute, i.e., the class
* indices of the inner and outer classes, the name and the attributes
* of the inner class.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see InnerClasses
*/
public final class InnerClass implements Cloneable, Node {
private int inner_class_index;
private int outer_class_index;
private int inner_name_index;
private int inner_access_flags;
/**
* Initialize from another object.
*/
public InnerClass(InnerClass c) {
this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(),
c.getInnerAccessFlags());
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
InnerClass(DataInputStream file) throws IOException
{
this(file.readUnsignedShort(), file.readUnsignedShort(),
file.readUnsignedShort(), file.readUnsignedShort());
}
/**
* @param inner_class_index Class index in constant pool of inner class
* @param outer_class_index Class index in constant pool of outer class
* @param inner_name_index Name index in constant pool of inner class
* @param inner_access_flags Access flags of inner class
*/
public InnerClass(int inner_class_index, int outer_class_index,
int inner_name_index, int inner_access_flags)
{
this.inner_class_index = inner_class_index;
this.outer_class_index = outer_class_index;
this.inner_name_index = inner_name_index;
this.inner_access_flags = inner_access_flags;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitInnerClass(this);
}
/**
* Dump inner class attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(inner_class_index);
file.writeShort(outer_class_index);
file.writeShort(inner_name_index);
file.writeShort(inner_access_flags);
}
/**
* @return access flags of inner class.
*/
public final int getInnerAccessFlags() { return inner_access_flags; }
/**
* @return class index of inner class.
*/
public final int getInnerClassIndex() { return inner_class_index; }
/**
* @return name index of inner class.
*/
public final int getInnerNameIndex() { return inner_name_index; }
/**
* @return class index of outer class.
*/
public final int getOuterClassIndex() { return outer_class_index; }
/**
* @param inner_access_flags.
*/
public final void setInnerAccessFlags(int inner_access_flags) {
this.inner_access_flags = inner_access_flags;
}
/**
* @param inner_class_index.
*/
public final void setInnerClassIndex(int inner_class_index) {
this.inner_class_index = inner_class_index;
}
/**
* @param inner_name_index.
*/
public final void setInnerNameIndex(int inner_name_index) {
this.inner_name_index = inner_name_index;
}
/**
* @param outer_class_index.
*/
public final void setOuterClassIndex(int outer_class_index) {
this.outer_class_index = outer_class_index;
}
/**
* @return String representation.
*/
public final String toString() {
return "InnerClass(" + inner_class_index + ", " + outer_class_index +
", " + inner_name_index + ", " + inner_access_flags + ")";
}
/**
* @return Resolved string representation
*/
public final String toString(ConstantPool constant_pool) {
String inner_class_name, outer_class_name, inner_name, access;
inner_class_name = constant_pool.getConstantString(inner_class_index,
Constants.CONSTANT_Class);
inner_class_name = Utility.compactClassName(inner_class_name);
if (outer_class_index != 0) {
outer_class_name = constant_pool.getConstantString(outer_class_index,
Constants.CONSTANT_Class);
outer_class_name = Utility.compactClassName(outer_class_name);
}
else
outer_class_name = "<not a member>";
if(inner_name_index != 0)
inner_name = ((ConstantUtf8)constant_pool.
getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes();
else
inner_name = "<anonymous>";
access = Utility.accessToString(inner_access_flags, true);
access = access.equals("")? "" : (access + " ");
return "InnerClass:" + access + inner_class_name +
"(\"" + outer_class_name + "\", \"" + inner_name + "\")";
}
/**
* @return deep copy of this object
*/
public InnerClass copy() {
try {
return (InnerClass)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
}

View file

@ -0,0 +1,184 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and denotes that this class
* is an Inner class of another.
* to the source file of this class.
* It is instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class InnerClasses extends Attribute {
private InnerClass[] inner_classes;
private int number_of_classes;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public InnerClasses(InnerClasses c) {
this(c.getNameIndex(), c.getLength(), c.getInnerClasses(),
c.getConstantPool());
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param inner_classes array of inner classes attributes
* @param constant_pool Array of constants
* @param sourcefile_index Index in constant pool to CONSTANT_Utf8
*/
public InnerClasses(int name_index, int length,
InnerClass[] inner_classes,
ConstantPool constant_pool)
{
super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool);
setInnerClasses(inner_classes);
}
/**
* Construct object from file stream.
*
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
InnerClasses(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (InnerClass[])null, constant_pool);
number_of_classes = file.readUnsignedShort();
inner_classes = new InnerClass[number_of_classes];
for(int i=0; i < number_of_classes; i++)
inner_classes[i] = new InnerClass(file);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitInnerClasses(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(number_of_classes);
for(int i=0; i < number_of_classes; i++)
inner_classes[i].dump(file);
}
/**
* @return array of inner class "records"
*/
public final InnerClass[] getInnerClasses() { return inner_classes; }
/**
* @param inner_classes.
*/
public final void setInnerClasses(InnerClass[] inner_classes) {
this.inner_classes = inner_classes;
number_of_classes = (inner_classes == null)? 0 : inner_classes.length;
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer();
for(int i=0; i < number_of_classes; i++)
buf.append(inner_classes[i].toString(constant_pool) + "\n");
return buf.toString();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
InnerClasses c = (InnerClasses)clone();
c.inner_classes = new InnerClass[number_of_classes];
for(int i=0; i < number_of_classes; i++)
c.inner_classes[i] = inner_classes[i].copy();
c.constant_pool = constant_pool;
return c;
}
}

View file

@ -0,0 +1,824 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.util.SyntheticRepository;
import com.sun.org.apache.bcel.internal.util.ClassVector;
import com.sun.org.apache.bcel.internal.util.ClassQueue;
import com.sun.org.apache.bcel.internal.generic.Type;
import java.io.*;
import java.util.StringTokenizer;
/**
* 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.
* @see com.sun.org.apache.bcel.internal.generic.ClassGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class JavaClass extends AccessFlags implements Cloneable, Node {
private String file_name;
private String package_name;
private String source_file_name = "<Unknown>";
private int class_name_index;
private int superclass_name_index;
private String class_name;
private String superclass_name;
private int major, minor; // Compiler version
private ConstantPool constant_pool; // Constant pool
private int[] interfaces; // implemented interfaces
private String[] interface_names;
private Field[] fields; // Fields, i.e., variables of class
private Method[] methods; // methods defined in the class
private Attribute[] attributes; // attributes defined in the class
private byte source = HEAP; // Generated in memory
public static final byte HEAP = 1;
public static final byte FILE = 2;
public static final byte ZIP = 3;
static boolean debug = false; // Debugging on/off
static char sep = '/'; // directory separator
/**
* In cases where we go ahead and create something,
* use the default SyntheticRepository, because we
* don't know any better.
*/
private transient com.sun.org.apache.bcel.internal.util.Repository repository =
SyntheticRepository.getInstance();
/**
* 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?
*/
public JavaClass(int class_name_index,
int superclass_name_index,
String file_name,
int major,
int minor,
int access_flags,
ConstantPool constant_pool,
int[] interfaces,
Field[] fields,
Method[] methods,
Attribute[] attributes,
byte source)
{
if(interfaces == null) // Allowed for backward compatibility
interfaces = new int[0];
if(attributes == null)
this.attributes = new Attribute[0];
if(fields == null)
fields = new Field[0];
if(methods == null)
methods = new Method[0];
this.class_name_index = class_name_index;
this.superclass_name_index = superclass_name_index;
this.file_name = file_name;
this.major = major;
this.minor = minor;
this.access_flags = access_flags;
this.constant_pool = constant_pool;
this.interfaces = interfaces;
this.fields = fields;
this.methods = methods;
this.attributes = attributes;
this.source = source;
// Get source file name if available
for(int i=0; i < attributes.length; i++) {
if(attributes[i] instanceof SourceFile) {
source_file_name = ((SourceFile)attributes[i]).getSourceFileName();
break;
}
}
/* According to the specification the following entries must be of type
* `ConstantClass' but we check that anyway via the
* `ConstPool.getConstant' method.
*/
class_name = constant_pool.getConstantString(class_name_index,
Constants.CONSTANT_Class);
class_name = Utility.compactClassName(class_name, false);
int index = class_name.lastIndexOf('.');
if(index < 0)
package_name = "";
else
package_name = class_name.substring(0, index);
if(superclass_name_index > 0) { // May be zero -> class is java.lang.Object
superclass_name = constant_pool.getConstantString(superclass_name_index,
Constants.CONSTANT_Class);
superclass_name = Utility.compactClassName(superclass_name, false);
}
else
superclass_name = "java.lang.Object";
interface_names = new String[interfaces.length];
for(int i=0; i < interfaces.length; i++) {
String str = constant_pool.getConstantString(interfaces[i], Constants.CONSTANT_Class);
interface_names[i] = Utility.compactClassName(str, false);
}
}
/**
* 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
*/
public JavaClass(int class_name_index,
int superclass_name_index,
String file_name,
int major,
int minor,
int access_flags,
ConstantPool constant_pool,
int[] interfaces,
Field[] fields,
Method[] methods,
Attribute[] attributes) {
this(class_name_index, superclass_name_index, file_name, major, minor, access_flags,
constant_pool, interfaces, fields, methods, attributes, HEAP);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitJavaClass(this);
}
/* Print debug information depending on `JavaClass.debug'
*/
static final void Debug(String str) {
if(debug)
System.out.println(str);
}
/**
* Dump class to a file.
*
* @param file Output file
* @throws IOException
*/
public void dump(File file) throws IOException
{
String parent = file.getParent();
if(parent != null) {
File dir = new File(parent);
if(dir != null)
dir.mkdirs();
}
dump(new DataOutputStream(new FileOutputStream(file)));
}
/**
* Dump class to a file named file_name.
*
* @param file_name Output file name
* @exception IOException
*/
public void dump(String file_name) throws IOException
{
dump(new File(file_name));
}
/**
* @return class in binary format
*/
public byte[] getBytes() {
ByteArrayOutputStream s = new ByteArrayOutputStream();
DataOutputStream ds = new DataOutputStream(s);
try {
dump(ds);
} catch(IOException e) {
e.printStackTrace();
} finally {
try { ds.close(); } catch(IOException e2) { e2.printStackTrace(); }
}
return s.toByteArray();
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @exception IOException
*/
public void dump(OutputStream file) throws IOException {
dump(new DataOutputStream(file));
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @exception IOException
*/
public void dump(DataOutputStream file) throws IOException
{
file.writeInt(0xcafebabe);
file.writeShort(minor);
file.writeShort(major);
constant_pool.dump(file);
file.writeShort(access_flags);
file.writeShort(class_name_index);
file.writeShort(superclass_name_index);
file.writeShort(interfaces.length);
for(int i=0; i < interfaces.length; i++)
file.writeShort(interfaces[i]);
file.writeShort(fields.length);
for(int i=0; i < fields.length; i++)
fields[i].dump(file);
file.writeShort(methods.length);
for(int i=0; i < methods.length; i++)
methods[i].dump(file);
if(attributes != null) {
file.writeShort(attributes.length);
for(int i=0; i < attributes.length; i++)
attributes[i].dump(file);
}
else
file.writeShort(0);
file.close();
}
/**
* @return Attributes of the class.
*/
public Attribute[] getAttributes() { return attributes; }
/**
* @return Class name.
*/
public String getClassName() { return class_name; }
/**
* @return Package name.
*/
public String getPackageName() { return package_name; }
/**
* @return Class name index.
*/
public int getClassNameIndex() { return class_name_index; }
/**
* @return Constant pool.
*/
public ConstantPool getConstantPool() { 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.
*/
public Field[] getFields() { return fields; }
/**
* @return File name of class, aka SourceFile attribute value
*/
public String getFileName() { return file_name; }
/**
* @return Names of implemented interfaces.
*/
public String[] getInterfaceNames() { return interface_names; }
/**
* @return Indices in constant pool of implemented interfaces.
*/
public int[] getInterfaceIndices() { return interfaces; }
/**
* @return Major number of class file version.
*/
public int getMajor() { return major; }
/**
* @return Methods of the class.
*/
public Method[] getMethods() { return methods; }
/**
* @return A com.sun.org.apache.bcel.internal.classfile.Method corresponding to
* java.lang.reflect.Method if any
*/
public Method getMethod(java.lang.reflect.Method m) {
for(int i = 0; i < methods.length; i++) {
Method method = methods[i];
if(m.getName().equals(method.getName()) &&
(m.getModifiers() == method.getModifiers()) &&
Type.getSignature(m).equals(method.getSignature())) {
return method;
}
}
return null;
}
/**
* @return Minor number of class file version.
*/
public int getMinor() { return minor; }
/**
* @return sbsolute path to file where this class was read from
*/
public String getSourceFileName() { return source_file_name; }
/**
* @return Superclass name.
*/
public String getSuperclassName() { return superclass_name; }
/**
* @return Class name index.
*/
public int getSuperclassNameIndex() { return superclass_name_index; }
static {
// Debugging ... on/off
String debug = null, sep = null;
try {
debug = System.getProperty("JavaClass.debug");
// Get path separator either / or \ usually
sep = System.getProperty("file.separator");
}
catch (SecurityException e) {
// falls through
}
if(debug != null)
JavaClass.debug = new Boolean(debug).booleanValue();
if(sep != null)
try {
JavaClass.sep = sep.charAt(0);
} catch(StringIndexOutOfBoundsException e) {} // Never reached
}
/**
* @param attributes .
*/
public void setAttributes(Attribute[] attributes) {
this.attributes = attributes;
}
/**
* @param class_name .
*/
public void setClassName(String class_name) {
this.class_name = class_name;
}
/**
* @param class_name_index .
*/
public void setClassNameIndex(int class_name_index) {
this.class_name_index = class_name_index;
}
/**
* @param constant_pool .
*/
public void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
/**
* @param fields .
*/
public void setFields(Field[] fields) {
this.fields = fields;
}
/**
* Set File name of class, aka SourceFile attribute value
*/
public void setFileName(String file_name) {
this.file_name = file_name;
}
/**
* @param interface_names .
*/
public void setInterfaceNames(String[] interface_names) {
this.interface_names = interface_names;
}
/**
* @param interfaces .
*/
public void setInterfaces(int[] interfaces) {
this.interfaces = interfaces;
}
/**
* @param major .
*/
public void setMajor(int major) {
this.major = major;
}
/**
* @param methods .
*/
public void setMethods(Method[] methods) {
this.methods = methods;
}
/**
* @param minor .
*/
public void setMinor(int minor) {
this.minor = minor;
}
/**
* Set absolute path to file this class was read from.
*/
public void setSourceFileName(String source_file_name) {
this.source_file_name = source_file_name;
}
/**
* @param superclass_name .
*/
public void setSuperclassName(String superclass_name) {
this.superclass_name = superclass_name;
}
/**
* @param superclass_name_index .
*/
public void setSuperclassNameIndex(int superclass_name_index) {
this.superclass_name_index = superclass_name_index;
}
/**
* @return String representing class contents.
*/
public String toString() {
String access = Utility.accessToString(access_flags, true);
access = access.equals("")? "" : (access + " ");
StringBuffer buf = new StringBuffer(access +
Utility.classOrInterface(access_flags) +
" " +
class_name + " extends " +
Utility.compactClassName(superclass_name,
false) + '\n');
int size = interfaces.length;
if(size > 0) {
buf.append("implements\t\t");
for(int i=0; i < size; i++) {
buf.append(interface_names[i]);
if(i < size - 1)
buf.append(", ");
}
buf.append('\n');
}
buf.append("filename\t\t" + file_name + '\n');
buf.append("compiled from\t\t" + source_file_name + '\n');
buf.append("compiler version\t" + major + "." + minor + '\n');
buf.append("access flags\t\t" + access_flags + '\n');
buf.append("constant pool\t\t" + constant_pool.getLength() + " entries\n");
buf.append("ACC_SUPER flag\t\t" + isSuper() + "\n");
if(attributes.length > 0) {
buf.append("\nAttribute(s):\n");
for(int i=0; i < attributes.length; i++)
buf.append(indent(attributes[i]));
}
if(fields.length > 0) {
buf.append("\n" + fields.length + " fields:\n");
for(int i=0; i < fields.length; i++)
buf.append("\t" + fields[i] + '\n');
}
if(methods.length > 0) {
buf.append("\n" + methods.length + " methods:\n");
for(int i=0; i < methods.length; i++)
buf.append("\t" + methods[i] + '\n');
}
return buf.toString();
}
private static final String indent(Object obj) {
StringTokenizer tok = new StringTokenizer(obj.toString(), "\n");
StringBuffer buf = new StringBuffer();
while(tok.hasMoreTokens())
buf.append("\t" + tok.nextToken() + "\n");
return buf.toString();
}
/**
* @return deep copy of this class
*/
public JavaClass copy() {
JavaClass c = null;
try {
c = (JavaClass)clone();
} catch(CloneNotSupportedException e) {}
c.constant_pool = constant_pool.copy();
c.interfaces = (int[])interfaces.clone();
c.interface_names = (String[])interface_names.clone();
c.fields = new Field[fields.length];
for(int i=0; i < fields.length; i++)
c.fields[i] = fields[i].copy(c.constant_pool);
c.methods = new Method[methods.length];
for(int i=0; i < methods.length; i++)
c.methods[i] = methods[i].copy(c.constant_pool);
c.attributes = new Attribute[attributes.length];
for(int i=0; i < attributes.length; i++)
c.attributes[i] = attributes[i].copy(c.constant_pool);
return c;
}
public final boolean isSuper() {
return (access_flags & Constants.ACC_SUPER) != 0;
}
public final boolean isClass() {
return (access_flags & Constants.ACC_INTERFACE) == 0;
}
/** @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();
*/
public com.sun.org.apache.bcel.internal.util.Repository getRepository() {
return repository;
}
/**
* Sets the ClassRepository which loaded the JavaClass.
* Should be called immediately after parsing is done.
*/
public void setRepository(com.sun.org.apache.bcel.internal.util.Repository repository) {
this.repository = repository;
}
/** Equivalent to runtime "instanceof" operator.
*
* @return true if this JavaClass is derived from teh super class
*/
public final boolean instanceOf(JavaClass super_class) {
if(this.equals(super_class))
return true;
JavaClass[] super_classes = getSuperClasses();
for(int i=0; i < super_classes.length; i++) {
if(super_classes[i].equals(super_class)) {
return true;
}
}
if(super_class.isInterface()) {
return implementationOf(super_class);
}
return false;
}
/**
* @return true, if clazz is an implementation of interface inter
*/
public boolean implementationOf(JavaClass inter) {
if(!inter.isInterface()) {
throw new IllegalArgumentException(inter.getClassName() + " is no interface");
}
if(this.equals(inter)) {
return true;
}
JavaClass[] super_interfaces = getAllInterfaces();
for(int i=0; i < super_interfaces.length; i++) {
if(super_interfaces[i].equals(inter)) {
return true;
}
}
return false;
}
/**
* @return the superclass for this JavaClass object, or null if this
* is java.lang.Object
*/
public JavaClass getSuperClass() {
if("java.lang.Object".equals(getClassName())) {
return null;
}
try {
return repository.loadClass(getSuperclassName());
} catch(ClassNotFoundException e) {
System.err.println(e);
return null;
}
}
/**
* @return list of super classes of this class in ascending order, i.e.,
* java.lang.Object is always the last element
*/
public JavaClass[] getSuperClasses() {
JavaClass clazz = this;
ClassVector vec = new ClassVector();
for(clazz = clazz.getSuperClass(); clazz != null;
clazz = clazz.getSuperClass())
{
vec.addElement(clazz);
}
return vec.toArray();
}
/**
* Get interfaces directly implemented by this JavaClass.
*/
public JavaClass[] getInterfaces() {
String[] interfaces = getInterfaceNames();
JavaClass[] classes = new JavaClass[interfaces.length];
try {
for(int i = 0; i < interfaces.length; i++) {
classes[i] = repository.loadClass(interfaces[i]);
}
} catch(ClassNotFoundException e) {
System.err.println(e);
return null;
}
return classes;
}
/**
* Get all interfaces implemented by this JavaClass (transitively).
*/
public JavaClass[] getAllInterfaces() {
ClassQueue queue = new ClassQueue();
ClassVector vec = new ClassVector();
queue.enqueue(this);
while(!queue.empty()) {
JavaClass clazz = queue.dequeue();
JavaClass souper = clazz.getSuperClass();
JavaClass[] interfaces = clazz.getInterfaces();
if(clazz.isInterface()) {
vec.addElement(clazz);
} else {
if(souper != null) {
queue.enqueue(souper);
}
}
for(int i = 0; i < interfaces.length; i++) {
queue.enqueue(interfaces[i]);
}
}
return vec.toArray();
}
}

View file

@ -0,0 +1,167 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a (PC offset, line number) pair, i.e., a line number in
* the source that corresponds to a relative address in the byte code. This
* is used for debugging purposes.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see LineNumberTable
*/
public final class LineNumber implements Cloneable, Node, Serializable {
private int start_pc; // Program Counter (PC) corresponds to line
private int line_number; // number in source file
/**
* Initialize from another object.
*/
public LineNumber(LineNumber c) {
this(c.getStartPC(), c.getLineNumber());
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
LineNumber(DataInputStream file) throws IOException
{
this(file.readUnsignedShort(), file.readUnsignedShort());
}
/**
* @param start_pc Program Counter (PC) corresponds to
* @param line_number line number in source file
*/
public LineNumber(int start_pc, int line_number)
{
this.start_pc = start_pc;
this.line_number = line_number;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitLineNumber(this);
}
/**
* Dump line number/pc pair to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(start_pc);
file.writeShort(line_number);
}
/**
* @return Corresponding source line
*/
public final int getLineNumber() { return line_number; }
/**
* @return PC in code
*/
public final int getStartPC() { return start_pc; }
/**
* @param line_number.
*/
public final void setLineNumber(int line_number) {
this.line_number = line_number;
}
/**
* @param start_pc.
*/
public final void setStartPC(int start_pc) {
this.start_pc = start_pc;
}
/**
* @return String representation
*/
public final String toString() {
return "LineNumber(" + start_pc + ", " + line_number + ")";
}
/**
* @return deep copy of this object
*/
public LineNumber copy() {
try {
return (LineNumber)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
}

View file

@ -0,0 +1,243 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a table of line numbers for debugging
* purposes. This attribute is used by the <em>Code</em> attribute. It
* contains pairs of PCs and line numbers.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
* @see LineNumber
*/
public final class LineNumberTable extends Attribute {
private int line_number_table_length;
private LineNumber[] line_number_table; // Table of line/numbers pairs
/*
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public LineNumberTable(LineNumberTable c) {
this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(),
c.getConstantPool());
}
/*
* @param name_index Index of name
* @param length Content length in bytes
* @param line_number_table Table of line/numbers pairs
* @param constant_pool Array of constants
*/
public LineNumberTable(int name_index, int length,
LineNumber[] line_number_table,
ConstantPool constant_pool)
{
super(Constants.ATTR_LINE_NUMBER_TABLE, name_index, length, constant_pool);
setLineNumberTable(line_number_table);
}
/**
* Construct object from file stream.
* @param name_index Index of name
* @param length Content length in bytes
* @param file Input stream
* @throws IOException
* @param constant_pool Array of constants
*/
LineNumberTable(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (LineNumber[])null, constant_pool);
line_number_table_length = (file.readUnsignedShort());
line_number_table = new LineNumber[line_number_table_length];
for(int i=0; i < line_number_table_length; i++)
line_number_table[i] = new LineNumber(file);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitLineNumberTable(this);
}
/**
* Dump line number table attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(line_number_table_length);
for(int i=0; i < line_number_table_length; i++)
line_number_table[i].dump(file);
}
/**
* @return Array of (pc offset, line number) pairs.
*/
public final LineNumber[] getLineNumberTable() { return line_number_table; }
/**
* @param line_number_table.
*/
public final void setLineNumberTable(LineNumber[] line_number_table) {
this.line_number_table = line_number_table;
line_number_table_length = (line_number_table == null)? 0 :
line_number_table.length;
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer();
StringBuffer line = new StringBuffer();
for(int i=0; i < line_number_table_length; i++) {
line.append(line_number_table[i].toString());
if(i < line_number_table_length - 1)
line.append(", ");
if(line.length() > 72) {
line.append('\n');
buf.append(line);
line.setLength(0);
}
}
buf.append(line);
return buf.toString();
}
/**
* Map byte code positions to source code lines.
*
* @param pos byte code offset
* @return corresponding line in source code
*/
public int getSourceLine(int pos) {
int l = 0, r = line_number_table_length-1;
if(r < 0) // array is empty
return -1;
int min_index = -1, min=-1;
/* Do a binary search since the array is ordered.
*/
do {
int i = (l + r) / 2;
int j = line_number_table[i].getStartPC();
if(j == pos)
return line_number_table[i].getLineNumber();
else if(pos < j) // else constrain search area
r = i - 1;
else // pos > j
l = i + 1;
/* If exact match can't be found (which is the most common case)
* return the line number that corresponds to the greatest index less
* than pos.
*/
if(j < pos && j > min) {
min = j;
min_index = i;
}
} while(l <= r);
/* It's possible that we did not find any valid entry for the bytecode
* offset we were looking for.
*/
if (min_index < 0)
return -1;
return line_number_table[min_index].getLineNumber();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
LineNumberTable c = (LineNumberTable)clone();
c.line_number_table = new LineNumber[line_number_table_length];
for(int i=0; i < line_number_table_length; i++)
c.line_number_table[i] = line_number_table[i].copy();
c.constant_pool = constant_pool;
return c;
}
public final int getTableLength() { return line_number_table_length; }
}

View file

@ -0,0 +1,262 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a local variable within a method. It contains its
* scope, name, signature and index on the method's frame.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see LocalVariableTable
*/
public final class LocalVariable
implements Constants, Cloneable, Node, Serializable
{
private int start_pc; // Range in which the variable is valid
private int length;
private int name_index; // Index in constant pool of variable name
private int signature_index; // Index of variable signature
private int index; /* Variable is `index'th local variable on
* this method's frame.
*/
private ConstantPool constant_pool;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public LocalVariable(LocalVariable c) {
this(c.getStartPC(), c.getLength(), c.getNameIndex(),
c.getSignatureIndex(), c.getIndex(), c.getConstantPool());
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
LocalVariable(DataInputStream file, ConstantPool constant_pool)
throws IOException
{
this(file.readUnsignedShort(), file.readUnsignedShort(),
file.readUnsignedShort(), file.readUnsignedShort(),
file.readUnsignedShort(), constant_pool);
}
/**
* @param start_pc Range in which the variable
* @param length ... is valid
* @param name_index Index in constant pool of variable name
* @param signature_index Index of variable's signature
* @param index Variable is `index'th local variable on the method's frame
* @param constant_pool Array of constants
*/
public LocalVariable(int start_pc, int length, int name_index,
int signature_index, int index,
ConstantPool constant_pool)
{
this.start_pc = start_pc;
this.length = length;
this.name_index = name_index;
this.signature_index = signature_index;
this.index = index;
this.constant_pool = constant_pool;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitLocalVariable(this);
}
/**
* Dump local variable to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(start_pc);
file.writeShort(length);
file.writeShort(name_index);
file.writeShort(signature_index);
file.writeShort(index);
}
/**
* @return Constant pool used by this object.
*/
public final ConstantPool getConstantPool() { return constant_pool; }
/**
* @return Variable is valid within getStartPC() .. getStartPC()+getLength()
*/
public final int getLength() { return length; }
/**
* @return Variable name.
*/
public final String getName() {
ConstantUtf8 c;
c = (ConstantUtf8)constant_pool.getConstant(name_index, CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return Index in constant pool of variable name.
*/
public final int getNameIndex() { return name_index; }
/**
* @return Signature.
*/
public final String getSignature() {
ConstantUtf8 c;
c = (ConstantUtf8)constant_pool.getConstant(signature_index,
CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return Index in constant pool of variable signature.
*/
public final int getSignatureIndex() { return signature_index; }
/**
* @return index of register where variable is stored
*/
public final int getIndex() { return index; }
/**
* @return Start of range where he variable is valid
*/
public final int getStartPC() { return start_pc; }
/**
* @param constant_pool Constant pool to be used for this object.
*/
public final void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
/**
* @param length.
*/
public final void setLength(int length) {
this.length = length;
}
/**
* @param name_index.
*/
public final void setNameIndex(int name_index) {
this.name_index = name_index;
}
/**
* @param signature_index.
*/
public final void setSignatureIndex(int signature_index) {
this.signature_index = signature_index;
}
/**
* @param index.
*/
public final void setIndex(int index) { this.index = index; }
/**
* @param start_pc Specify range where the local variable is valid.
*/
public final void setStartPC(int start_pc) {
this.start_pc = start_pc;
}
/**
* @return string representation.
*/
public final String toString() {
String name = getName(), signature = Utility.signatureToString(getSignature());
return "LocalVariable(start_pc = " + start_pc + ", length = " + length +
", index = " + index + ":" + signature + " " + name + ")";
}
/**
* @return deep copy of this object
*/
public LocalVariable copy() {
try {
return (LocalVariable)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
}

View file

@ -0,0 +1,199 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents colection of local variables in a
* method. This attribute is contained in the <em>Code</em> attribute.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
* @see LocalVariable
*/
public class LocalVariableTable extends Attribute {
private int local_variable_table_length; // Table of local
private LocalVariable[] local_variable_table; // variables
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public LocalVariableTable(LocalVariableTable c) {
this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(),
c.getConstantPool());
}
/**
* @param name_index Index in constant pool to `LocalVariableTable'
* @param length Content length in bytes
* @param local_variable_table Table of local variables
* @param constant_pool Array of constants
*/
public LocalVariableTable(int name_index, int length,
LocalVariable[] local_variable_table,
ConstantPool constant_pool)
{
super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool);
setLocalVariableTable(local_variable_table);
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
LocalVariableTable(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (LocalVariable[])null, constant_pool);
local_variable_table_length = (file.readUnsignedShort());
local_variable_table = new LocalVariable[local_variable_table_length];
for(int i=0; i < local_variable_table_length; i++)
local_variable_table[i] = new LocalVariable(file, constant_pool);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitLocalVariableTable(this);
}
/**
* Dump local variable table attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(local_variable_table_length);
for(int i=0; i < local_variable_table_length; i++)
local_variable_table[i].dump(file);
}
/**
* @return Array of local variables of method.
*/
public final LocalVariable[] getLocalVariableTable() {
return local_variable_table;
}
/** @return first matching variable using index
*/
public final LocalVariable getLocalVariable(int index) {
for(int i=0; i < local_variable_table_length; i++)
if(local_variable_table[i].getIndex() == index)
return local_variable_table[i];
return null;
}
public final void setLocalVariableTable(LocalVariable[] local_variable_table)
{
this.local_variable_table = local_variable_table;
local_variable_table_length = (local_variable_table == null)? 0 :
local_variable_table.length;
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer("");
for(int i=0; i < local_variable_table_length; i++) {
buf.append(local_variable_table[i].toString());
if(i < local_variable_table_length - 1)
buf.append('\n');
}
return buf.toString();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
LocalVariableTable c = (LocalVariableTable)clone();
c.local_variable_table = new LocalVariable[local_variable_table_length];
for(int i=0; i < local_variable_table_length; i++)
c.local_variable_table[i] = local_variable_table[i].copy();
c.constant_pool = constant_pool;
return c;
}
public final int getTableLength() { return local_variable_table_length; }
}

View file

@ -0,0 +1,231 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.Type;
import java.io.*;
/**
* This class represents the method info structure, i.e., the representation
* for a method in the class. See JVM specification for details.
* A method has access flags, a name, a signature and a number of attributes.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class Method extends FieldOrMethod {
/**
* Empty constructor, all attributes have to be defined via `setXXX'
* methods. Use at your own risk.
*/
public Method() {}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public Method(Method c) {
super(c);
}
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
*/
Method(DataInputStream file, ConstantPool constant_pool)
throws IOException, ClassFormatException
{
super(file, constant_pool);
}
/**
* @param access_flags Access rights of method
* @param name_index Points to field name in constant pool
* @param signature_index Points to encoded signature
* @param attributes Collection of attributes
* @param constant_pool Array of constants
*/
public Method(int access_flags, int name_index, int signature_index,
Attribute[] attributes, ConstantPool constant_pool)
{
super(access_flags, name_index, signature_index, attributes, constant_pool);
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitMethod(this);
}
/**
* @return Code attribute of method, if any
*/
public final Code getCode() {
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof Code)
return (Code)attributes[i];
return null;
}
/**
* @return ExceptionTable attribute of method, if any, i.e., list all
* exceptions the method may throw not exception handlers!
*/
public final ExceptionTable getExceptionTable() {
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof ExceptionTable)
return (ExceptionTable)attributes[i];
return null;
}
/** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded
* to the Code atribute.
*/
public final LocalVariableTable getLocalVariableTable() {
Code code = getCode();
if(code != null)
return code.getLocalVariableTable();
else
return null;
}
/** @return LineNumberTable of code attribute if any, i.e. the call is forwarded
* to the Code atribute.
*/
public final LineNumberTable getLineNumberTable() {
Code code = getCode();
if(code != null)
return code.getLineNumberTable();
else
return null;
}
/**
* Return string representation close to declaration format,
* `public static void _main(String[] args) throws IOException', e.g.
*
* @return String representation of the method.
*/
public final String toString() {
ConstantUtf8 c;
String name, signature, access; // Short cuts to constant pool
StringBuffer buf;
access = Utility.accessToString(access_flags);
// Get name and signature from constant pool
c = (ConstantUtf8)constant_pool.getConstant(signature_index,
Constants.CONSTANT_Utf8);
signature = c.getBytes();
c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
name = c.getBytes();
signature = Utility.methodSignatureToString(signature, name, access, true,
getLocalVariableTable());
buf = new StringBuffer(signature);
for(int i=0; i < attributes_count; i++) {
Attribute a = attributes[i];
if(!((a instanceof Code) || (a instanceof ExceptionTable)))
buf.append(" [" + a.toString() + "]");
}
ExceptionTable e = getExceptionTable();
if(e != null) {
String str = e.toString();
if(!str.equals(""))
buf.append("\n\t\tthrows " + str);
}
return buf.toString();
}
/**
* @return deep copy of this method
*/
public final Method copy(ConstantPool constant_pool) {
return (Method)copy_(constant_pool);
}
/**
* @return return type of method
*/
public Type getReturnType() {
return Type.getReturnType(getSignature());
}
/**
* @return array of method argument types
*/
public Type[] getArgumentTypes() {
return Type.getArgumentTypes(getSignature());
}
}

View file

@ -0,0 +1,68 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Denote class to have an accept method();
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface Node {
public void accept(Visitor obj);
}

View file

@ -0,0 +1,192 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and represents a reference
* to a <a href="http://www.inf.fu-berlin.de/~bokowski/pmgjava/index.html">PMG</a>
* attribute.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class PMGClass extends Attribute {
private int pmg_class_index, pmg_index;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public PMGClass(PMGClass c) {
this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(),
c.getConstantPool());
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
PMGClass(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(),
constant_pool);
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param constant_pool Array of constants
* @param PMGClass_index Index in constant pool to CONSTANT_Utf8
*/
public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index,
ConstantPool constant_pool)
{
super(Constants.ATTR_PMG, name_index, length, constant_pool);
this.pmg_index = pmg_index;
this.pmg_class_index = pmg_class_index;
}
/**
* 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
*/
public void accept(Visitor v) {
System.err.println("Visiting non-standard PMGClass object");
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(pmg_index);
file.writeShort(pmg_class_index);
}
/**
* @return Index in constant pool of source file name.
*/
public final int getPMGClassIndex() { return pmg_class_index; }
/**
* @param PMGClass_index.
*/
public final void setPMGClassIndex(int pmg_class_index) {
this.pmg_class_index = pmg_class_index;
}
/**
* @return Index in constant pool of source file name.
*/
public final int getPMGIndex() { return pmg_index; }
/**
* @param PMGClass_index.
*/
public final void setPMGIndex(int pmg_index) {
this.pmg_index = pmg_index;
}
/**
* @return PMG name.
*/
public final String getPMGName() {
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return PMG class name.
*/
public final String getPMGClassName() {
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_class_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return String representation
*/
public final String toString() {
return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")";
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
return (PMGClass)clone();
}
}

View file

@ -0,0 +1,299 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and represents a reference
* to a <href="http://wwwipd.ira.uka.de/~pizza/gj/">GJ</a> attribute.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class Signature extends Attribute {
private int signature_index;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public Signature(Signature c) {
this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool());
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
Signature(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, file.readUnsignedShort(), constant_pool);
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param constant_pool Array of constants
* @param Signature_index Index in constant pool to CONSTANT_Utf8
*/
public Signature(int name_index, int length, int signature_index,
ConstantPool constant_pool)
{
super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool);
this.signature_index = signature_index;
}
/**
* 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
*/
public void accept(Visitor v) {
System.err.println("Visiting non-standard Signature object");
v.visitSignature(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(signature_index);
}
/**
* @return Index in constant pool of source file name.
*/
public final int getSignatureIndex() { return signature_index; }
/**
* @param Signature_index.
*/
public final void setSignatureIndex(int signature_index) {
this.signature_index = signature_index;
}
/**
* @return GJ signature.
*/
public final String getSignature() {
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(signature_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* Extends ByteArrayInputStream to make 'unreading' chars possible.
*/
private static final class MyByteArrayInputStream extends ByteArrayInputStream {
MyByteArrayInputStream(String data) { super(data.getBytes()); }
final int mark() { return pos; }
final String getData() { return new String(buf); }
final void reset(int p) { pos = p; }
final void unread() { if(pos > 0) pos--; }
}
private static boolean identStart(int ch) {
return ch == 'T' || ch == 'L';
}
private static boolean identPart(int ch) {
return ch == '/' || ch == ';';
}
private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) {
int ch;
if((ch = in.read()) == -1)
throw new RuntimeException("Illegal signature: " + in.getData() +
" no ident, reaching EOF");
//System.out.println("return from ident:" + (char)ch);
if(!identStart(ch)) {
StringBuffer buf2 = new StringBuffer();
int count = 1;
while(Character.isJavaIdentifierPart((char)ch)) {
buf2.append((char)ch);
count++;
ch = in.read();
}
if(ch == ':') { // Ok, formal parameter
in.skip("Ljava/lang/Object".length());
buf.append(buf2);
ch = in.read();
in.unread();
//System.out.println("so far:" + buf2 + ":next:" +(char)ch);
} else {
for(int i=0; i < count; i++)
in.unread();
}
return;
}
StringBuffer buf2 = new StringBuffer();
ch = in.read();
do {
buf2.append((char)ch);
ch = in.read();
//System.out.println("within ident:"+ (char)ch);
} while((ch != -1) && (Character.isJavaIdentifierPart((char)ch) || (ch == '/')));
buf.append(buf2.toString().replace('/', '.'));
//System.out.println("regular return ident:"+ (char)ch + ":" + buf2);
if(ch != -1)
in.unread();
}
private static final void matchGJIdent(MyByteArrayInputStream in,
StringBuffer buf)
{
int ch;
matchIdent(in, buf);
ch = in.read();
if((ch == '<') || ch == '(') { // Parameterized or method
//System.out.println("Enter <");
buf.append((char)ch);
matchGJIdent(in, buf);
while(((ch = in.read()) != '>') && (ch != ')')) { // List of parameters
if(ch == -1)
throw new RuntimeException("Illegal signature: " + in.getData() +
" reaching EOF");
//System.out.println("Still no >");
buf.append(", ");
in.unread();
matchGJIdent(in, buf); // Recursive call
}
//System.out.println("Exit >");
buf.append((char)ch);
} else
in.unread();
ch = in.read();
if(identStart(ch)) {
in.unread();
matchGJIdent(in, buf);
} else if(ch == ')') {
in.unread();
return;
} else if(ch != ';')
throw new RuntimeException("Illegal signature: " + in.getData() + " read " +
(char)ch);
}
public static String translate(String s) {
//System.out.println("Sig:" + s);
StringBuffer buf = new StringBuffer();
matchGJIdent(new MyByteArrayInputStream(s), buf);
return buf.toString();
}
public static final boolean isFormalParameterList(String s) {
return s.startsWith("<") && (s.indexOf(':') > 0);
}
public static final boolean isActualParameterList(String s) {
return s.startsWith("L") && s.endsWith(">;");
}
/**
* @return String representation
*/
public final String toString() {
String s = getSignature();
return "Signature(" + s + ")";
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
return (Signature)clone();
}
}

View file

@ -0,0 +1,176 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and represents a reference
* to the source file of this class. At most one SourceFile attribute
* should appear per classfile. The intention of this class is that it is
* instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class SourceFile extends Attribute {
private int sourcefile_index;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public SourceFile(SourceFile c) {
this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(),
c.getConstantPool());
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
SourceFile(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, file.readUnsignedShort(), constant_pool);
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8, which
* should represent the string "SourceFile".
* @param length Content length in bytes, the value should be 2.
* @param constant_pool The constant pool that this attribute is
* associated with.
* @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This
* string will be interpreted as the name of the file from which this
* class was compiled. It will not be interpreted as indicating the name
* of the directory contqining the file or an absolute path; this
* information has to be supplied the consumer of this attribute - in
* many cases, the JVM.
*/
public SourceFile(int name_index, int length, int sourcefile_index,
ConstantPool constant_pool)
{
super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool);
this.sourcefile_index = sourcefile_index;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitSourceFile(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(sourcefile_index);
}
/**
* @return Index in constant pool of source file name.
*/
public final int getSourceFileIndex() { return sourcefile_index; }
/**
* @param sourcefile_index.
*/
public final void setSourceFileIndex(int sourcefile_index) {
this.sourcefile_index = sourcefile_index;
}
/**
* @return Source file name.
*/
public final String getSourceFileName() {
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index,
Constants.CONSTANT_Utf8);
return c.getBytes();
}
/**
* @return String representation
*/
public final String toString() {
return "SourceFile(" + getSourceFileName() + ")";
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
return (SourceFile)clone();
}
}

View file

@ -0,0 +1,188 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a stack map attribute used for
* preverification of Java classes for the <a
* href="http://java.sun.com/j2me/"> Java 2 Micro Edition</a>
* (J2ME). This attribute is used by the <a
* href="http://java.sun.com/products/cldc/">KVM</a> and contained
* within the Code attribute of a method. See CLDC specification
* 5.3.1.2
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
* @see StackMapEntry
* @see StackMapType
*/
public final class StackMap extends Attribute implements Node {
private int map_length;
private StackMapEntry[] map; // Table of stack map entries
/*
* @param name_index Index of name
* @param length Content length in bytes
* @param map Table of stack map entries
* @param constant_pool Array of constants
*/
public StackMap(int name_index, int length, StackMapEntry[] map,
ConstantPool constant_pool)
{
super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
setStackMap(map);
}
/**
* Construct object from file stream.
* @param name_index Index of name
* @param length Content length in bytes
* @param file Input stream
* @throws IOException
* @param constant_pool Array of constants
*/
StackMap(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (StackMapEntry[])null, constant_pool);
map_length = file.readUnsignedShort();
map = new StackMapEntry[map_length];
for(int i=0; i < map_length; i++)
map[i] = new StackMapEntry(file, constant_pool);
}
/**
* Dump line number table attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
file.writeShort(map_length);
for(int i=0; i < map_length; i++)
map[i].dump(file);
}
/**
* @return Array of stack map entries
*/
public final StackMapEntry[] getStackMap() { return map; }
/**
* @param map Array of stack map entries
*/
public final void setStackMap(StackMapEntry[] map) {
this.map = map;
map_length = (map == null)? 0 : map.length;
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer("StackMap(");
for(int i=0; i < map_length; i++) {
buf.append(map[i].toString());
if(i < map_length - 1)
buf.append(", ");
}
buf.append(')');
return buf.toString();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
StackMap c = (StackMap)clone();
c.map = new StackMapEntry[map_length];
for(int i=0; i < map_length; i++)
c.map[i] = map[i].copy();
c.constant_pool = constant_pool;
return c;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitStackMap(this);
}
public final int getMapLength() { return map_length; }
}

View file

@ -0,0 +1,212 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents a stack map entry recording the types of
* local variables and the the of stack items at a given byte code offset.
* See CLDC specification 5.3.1.2
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see StackMap
* @see StackMapType
*/
public final class StackMapEntry implements Cloneable {
private int byte_code_offset;
private int number_of_locals;
private StackMapType[] types_of_locals;
private int number_of_stack_items;
private StackMapType[] types_of_stack_items;
private ConstantPool constant_pool;
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException
{
this(file.readShort(), file.readShort(), null, -1, null, constant_pool);
types_of_locals = new StackMapType[number_of_locals];
for(int i=0; i < number_of_locals; i++)
types_of_locals[i] = new StackMapType(file, constant_pool);
number_of_stack_items = file.readShort();
types_of_stack_items = new StackMapType[number_of_stack_items];
for(int i=0; i < number_of_stack_items; i++)
types_of_stack_items[i] = new StackMapType(file, constant_pool);
}
public StackMapEntry(int byte_code_offset, int number_of_locals,
StackMapType[] types_of_locals,
int number_of_stack_items,
StackMapType[] types_of_stack_items,
ConstantPool constant_pool) {
this.byte_code_offset = byte_code_offset;
this.number_of_locals = number_of_locals;
this.types_of_locals = types_of_locals;
this.number_of_stack_items = number_of_stack_items;
this.types_of_stack_items = types_of_stack_items;
this.constant_pool = constant_pool;
}
/**
* Dump stack map entry
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeShort(byte_code_offset);
file.writeShort(number_of_locals);
for(int i=0; i < number_of_locals; i++)
types_of_locals[i].dump(file);
file.writeShort(number_of_stack_items);
for(int i=0; i < number_of_stack_items; i++)
types_of_stack_items[i].dump(file);
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer("(offset=" + byte_code_offset);
if(number_of_locals > 0) {
buf.append(", locals={");
for(int i=0; i < number_of_locals; i++) {
buf.append(types_of_locals[i]);
if(i < number_of_locals - 1)
buf.append(", ");
}
buf.append("}");
}
if(number_of_stack_items > 0) {
buf.append(", stack items={");
for(int i=0; i < number_of_stack_items; i++) {
buf.append(types_of_stack_items[i]);
if(i < number_of_stack_items - 1)
buf.append(", ");
}
buf.append("}");
}
buf.append(")");
return buf.toString();
}
public void setByteCodeOffset(int b) { byte_code_offset = b; }
public int getByteCodeOffset() { return byte_code_offset; }
public void setNumberOfLocals(int n) { number_of_locals = n; }
public int getNumberOfLocals() { return number_of_locals; }
public void setTypesOfLocals(StackMapType[] t) { types_of_locals = t; }
public StackMapType[] getTypesOfLocals() { return types_of_locals; }
public void setNumberOfStackItems(int n) { number_of_stack_items = n; }
public int getNumberOfStackItems() { return number_of_stack_items; }
public void setTypesOfStackItems(StackMapType[] t) { types_of_stack_items = t; }
public StackMapType[] getTypesOfStackItems() { return types_of_stack_items; }
/**
* @return deep copy of this object
*/
public StackMapEntry copy() {
try {
return (StackMapEntry)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitStackMapEntry(this);
}
/**
* @return Constant pool used by this object.
*/
public final ConstantPool getConstantPool() { return constant_pool; }
/**
* @param constant_pool Constant pool to be used for this object.
*/
public final void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
}

View file

@ -0,0 +1,175 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class represents the type of a local variable or item on stack
* used in the StackMap entries.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see StackMapEntry
* @see StackMap
* @see Constants
*/
public final class StackMapType implements Cloneable {
private byte type;
private int index = -1; // Index to CONSTANT_Class or offset
private ConstantPool constant_pool;
/**
* Construct object from file stream.
* @param file Input stream
* @throws IOException
*/
StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException
{
this(file.readByte(), -1, constant_pool);
if(hasIndex())
setIndex(file.readShort());
setConstantPool(constant_pool);
}
/**
* @param type type tag as defined in the Constants interface
* @param index index to constant pool, or byte code offset
*/
public StackMapType(byte type, int index, ConstantPool constant_pool) {
setType(type);
setIndex(index);
setConstantPool(constant_pool);
}
public void setType(byte t) {
if((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject))
throw new RuntimeException("Illegal type for StackMapType: " + t);
type = t;
}
public byte getType() { return type; }
public void setIndex(int t) { index = t; }
/** @return index to constant pool if type == ITEM_Object, or offset
* in byte code, if type == ITEM_NewObject, and -1 otherwise
*/
public int getIndex() { return index; }
/**
* Dump type entries to file.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(type);
if(hasIndex())
file.writeShort(getIndex());
}
/** @return true, if type is either ITEM_Object or ITEM_NewObject
*/
public final boolean hasIndex() {
return ((type == Constants.ITEM_Object) ||
(type == Constants.ITEM_NewObject));
}
private String printIndex() {
if(type == Constants.ITEM_Object)
return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class);
else if(type == Constants.ITEM_NewObject)
return ", offset=" + index;
else
return "";
}
/**
* @return String representation
*/
public final String toString() {
return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")";
}
/**
* @return deep copy of this object
*/
public StackMapType copy() {
try {
return (StackMapType)clone();
} catch(CloneNotSupportedException e) {}
return null;
}
/**
* @return Constant pool used by this object.
*/
public final ConstantPool getConstantPool() { return constant_pool; }
/**
* @param constant_pool Constant pool to be used for this object.
*/
public final void setConstantPool(ConstantPool constant_pool) {
this.constant_pool = constant_pool;
}
}

View file

@ -0,0 +1,179 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from <em>Attribute</em> and declares this class as
* `synthetic', i.e., it needs special handling. The JVM specification
* states "A class member that does not appear in the source code must be
* marked using a Synthetic attribute." It may appear in the ClassFile
* attribute table, a field_info table or a method_info table. This class
* is intended to be instantiated from the
* <em>Attribute.readAttribute()</em> method.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
public final class Synthetic extends Attribute {
private byte[] bytes;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
public Synthetic(Synthetic c) {
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
}
/**
* @param name_index Index in constant pool to CONSTANT_Utf8, which
* should represent the string "Synthetic".
* @param length Content length in bytes - should be zero.
* @param bytes Attribute contents
* @param constant_pool The constant pool this attribute is associated
* with.
*/
public Synthetic(int name_index, int length, byte[] bytes,
ConstantPool constant_pool)
{
super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool);
this.bytes = bytes;
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
Synthetic(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException
{
this(name_index, length, (byte [])null, constant_pool);
if(length > 0) {
bytes = new byte[length];
file.readFully(bytes);
System.err.println("Synthetic attribute with length > 0");
}
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitSynthetic(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
if(length > 0)
file.write(bytes, 0, length);
}
/**
* @return data bytes.
*/
public final byte[] getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(byte[] bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
StringBuffer buf = new StringBuffer("Synthetic");
if(length > 0)
buf.append(" " + Utility.toHexString(bytes));
return buf.toString();
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
Synthetic c = (Synthetic)clone();
if(bytes != null)
c.bytes = (byte[])bytes.clone();
c.constant_pool = constant_pool;
return c;
}
}

View file

@ -0,0 +1,216 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
import java.util.*;
/**
* This class represents a reference to an unknown (i.e.,
* application-specific) attribute of a class. It is instantiated from the
* <em>Attribute.readAttribute()</em> method. Applications that need to
* read in application-specific attributes should create an <a
* href="./AttributeReader.html">AttributeReader</a> implementation and
* attach it via <a
* href="./Attribute.html#addAttributeReader(java.lang.String,
* com.sun.org.apache.bcel.internal.classfile.AttributeReader)">Attribute.addAttributeReader</a>.
*
* @see com.sun.org.apache.bcel.internal.classfile.Attribute
* @see com.sun.org.apache.bcel.internal.classfile.AttributeReader
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class Unknown extends Attribute {
private byte[] bytes;
private String name;
private static HashMap unknown_attributes = new HashMap();
/** @return array of unknown attributes, but just one for each kind.
*/
static Unknown[] getUnknownAttributes() {
Unknown[] unknowns = new Unknown[unknown_attributes.size()];
Iterator entries = unknown_attributes.values().iterator();
for(int i=0; entries.hasNext(); i++)
unknowns[i] = (Unknown)entries.next();
unknown_attributes.clear();
return unknowns;
}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public Unknown(Unknown c) {
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
}
/**
* Create a non-standard attribute.
*
* @param name_index Index in constant pool
* @param length Content length in bytes
* @param bytes Attribute contents
* @param constant_pool Array of constants
*/
public Unknown(int name_index, int length, byte[] bytes,
ConstantPool constant_pool)
{
super(Constants.ATTR_UNKNOWN, name_index, length, constant_pool);
this.bytes = bytes;
name = ((ConstantUtf8)constant_pool.getConstant(name_index,
Constants.CONSTANT_Utf8)).getBytes();
unknown_attributes.put(name, this);
}
/**
* Construct object from file stream.
* @param name_index Index in constant pool
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
Unknown(int name_index, int length, DataInputStream file,
ConstantPool constant_pool)
throws IOException
{
this(name_index, length, (byte [])null, constant_pool);
if(length > 0) {
bytes = new byte[length];
file.readFully(bytes);
}
}
/**
* 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
*/
public void accept(Visitor v) {
v.visitUnknown(this);
}
/**
* Dump unknown bytes to file stream.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
super.dump(file);
if(length > 0)
file.write(bytes, 0, length);
}
/**
* @return data bytes.
*/
public final byte[] getBytes() { return bytes; }
/**
* @return name of attribute.
*/
public final String getName() { return name; }
/**
* @param bytes.
*/
public final void setBytes(byte[] bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
if(length == 0 || bytes == null)
return "(Unknown attribute " + name + ")";
String hex;
if(length > 10) {
byte[] tmp = new byte[10];
System.arraycopy(bytes, 0, tmp, 0, 10);
hex = Utility.toHexString(tmp) + "... (truncated)";
}
else
hex = Utility.toHexString(bytes);
return "(Unknown attribute " + name + ": " + hex + ")";
}
/**
* @return deep copy of this attribute
*/
public Attribute copy(ConstantPool constant_pool) {
Unknown c = (Unknown)clone();
if(bytes != null)
c.bytes = (byte[])bytes.clone();
c.constant_pool = constant_pool;
return c;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,104 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.classfile;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Interface to make use of the Visitor pattern programming style.
* I.e. a class that implements this interface can traverse the contents of
* a Java class just by calling the `accept' method which all classes have.
*
* Implemented by wish of
* <A HREF="http://www.inf.fu-berlin.de/~bokowski">Boris Bokowski</A>.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface Visitor {
public void visitCode(Code obj);
public void visitCodeException(CodeException obj);
public void visitConstantClass(ConstantClass obj);
public void visitConstantDouble(ConstantDouble obj);
public void visitConstantFieldref(ConstantFieldref obj);
public void visitConstantFloat(ConstantFloat obj);
public void visitConstantInteger(ConstantInteger obj);
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj);
public void visitConstantLong(ConstantLong obj);
public void visitConstantMethodref(ConstantMethodref obj);
public void visitConstantNameAndType(ConstantNameAndType obj);
public void visitConstantPool(ConstantPool obj);
public void visitConstantString(ConstantString obj);
public void visitConstantUtf8(ConstantUtf8 obj);
public void visitConstantValue(ConstantValue obj);
public void visitDeprecated(Deprecated obj);
public void visitExceptionTable(ExceptionTable obj);
public void visitField(Field obj);
public void visitInnerClass(InnerClass obj);
public void visitInnerClasses(InnerClasses obj);
public void visitJavaClass(JavaClass obj);
public void visitLineNumber(LineNumber obj);
public void visitLineNumberTable(LineNumberTable obj);
public void visitLocalVariable(LocalVariable obj);
public void visitLocalVariableTable(LocalVariableTable obj);
public void visitMethod(Method obj);
public void visitSignature(Signature obj);
public void visitSourceFile(SourceFile obj);
public void visitSynthetic(Synthetic obj);
public void visitUnknown(Unknown obj);
public void visitStackMap(StackMap obj);
public void visitStackMapEntry(StackMapEntry obj);
}

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
$Id: package.html,v 1.1.2.1 2005/07/31 23:46:33 jeffsuttor Exp $
-->
</head>
<body bgcolor="white">
<p>
This package contains the classes that describe the structure of a
Java class file and a class file parser.
</p>
</body>
</html>

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* AALOAD - Load reference from array
* <PRE>Stack: ..., arrayref, index -&gt; value</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class AALOAD extends ArrayInstruction implements StackProducer {
/** Load reference from array
*/
public AALOAD() {
super(com.sun.org.apache.bcel.internal.Constants.AALOAD);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackProducer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitAALOAD(this);
}
}

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* AASTORE - Store into reference array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class AASTORE extends ArrayInstruction implements StackConsumer {
/** Store into reference array
*/
public AASTORE() {
super(com.sun.org.apache.bcel.internal.Constants.AASTORE);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackConsumer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitAASTORE(this);
}
}

View file

@ -0,0 +1,97 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ACONST_NULL - Push null reference
* <PRE>Stack: ... -&gt; ..., null</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ACONST_NULL extends Instruction
implements PushInstruction, TypedInstruction {
/**
* Push null reference
*/
public ACONST_NULL() {
super(com.sun.org.apache.bcel.internal.Constants.ACONST_NULL, (short)1);
}
/** @return Type.NULL
*/
public Type getType(ConstantPoolGen cp) {
return Type.NULL;
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackProducer(this);
v.visitPushInstruction(this);
v.visitTypedInstruction(this);
v.visitACONST_NULL(this);
}
}

View file

@ -0,0 +1,95 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ALOAD - Load reference from local variable
* <PRE>Stack: ... -&gt; ..., objectref</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ALOAD extends LoadInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
ALOAD() {
super(com.sun.org.apache.bcel.internal.Constants.ALOAD, com.sun.org.apache.bcel.internal.Constants.ALOAD_0);
}
/** Load reference from local variable
* @param n index of local variable
*/
public ALOAD(int n) {
super(com.sun.org.apache.bcel.internal.Constants.ALOAD, com.sun.org.apache.bcel.internal.Constants.ALOAD_0, n);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
super.accept(v);
v.visitALOAD(this);
}
}

View file

@ -0,0 +1,117 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.ExceptionConstants;
/**
* ANEWARRAY - Create new array of references
* <PRE>Stack: ..., count -&gt; ..., arrayref</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ANEWARRAY extends CPInstruction
implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
ANEWARRAY() {}
public ANEWARRAY(int index) {
super(com.sun.org.apache.bcel.internal.Constants.ANEWARRAY, index);
}
public Class[] getExceptions(){
Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0,
cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] =
ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
return cs;
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitLoadClass(this);
v.visitAllocationInstruction(this);
v.visitExceptionThrower(this);
v.visitStackProducer(this);
v.visitTypedInstruction(this);
v.visitCPInstruction(this);
v.visitANEWARRAY(this);
}
public ObjectType getLoadClassType(ConstantPoolGen cpg) {
Type t = getType(cpg);
if (t instanceof ArrayType){
t = ((ArrayType) t).getBasicType();
}
return (t instanceof ObjectType)? (ObjectType) t : null;
}
}

View file

@ -0,0 +1,91 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ARETURN - Return reference from method
* <PRE>Stack: ..., objectref -&gt; &lt;empty&gt;</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ARETURN extends ReturnInstruction {
/**
* Return reference from method
*/
public ARETURN() {
super(com.sun.org.apache.bcel.internal.Constants.ARETURN);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitStackConsumer(this);
v.visitReturnInstruction(this);
v.visitARETURN(this);
}
}

View file

@ -0,0 +1,95 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ARRAYLENGTH - Get length of array
* <PRE>Stack: ..., arrayref -&gt; ..., length</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ARRAYLENGTH extends Instruction
implements ExceptionThrower, StackProducer {
/** Get length of array
*/
public ARRAYLENGTH() {
super(com.sun.org.apache.bcel.internal.Constants.ARRAYLENGTH, (short)1);
}
/** @return exceptions this instruction may cause
*/
public Class[] getExceptions() {
return new Class[] { com.sun.org.apache.bcel.internal.ExceptionConstants.NULL_POINTER_EXCEPTION };
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitExceptionThrower(this);
v.visitStackProducer(this);
v.visitARRAYLENGTH(this);
}
}

View file

@ -0,0 +1,95 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ASTORE - Store reference into local variable
* <PRE>Stack ..., objectref -&gt; ... </PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ASTORE extends StoreInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
ASTORE() {
super(com.sun.org.apache.bcel.internal.Constants.ASTORE, com.sun.org.apache.bcel.internal.Constants.ASTORE_0);
}
/** Store reference into local variable
* @param n index of local variable
*/
public ASTORE(int n) {
super(com.sun.org.apache.bcel.internal.Constants.ASTORE, com.sun.org.apache.bcel.internal.Constants.ASTORE_0, n);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
super.accept(v);
v.visitASTORE(this);
}
}

View file

@ -0,0 +1,95 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* ATHROW - Throw exception
* <PRE>Stack: ..., objectref -&gt; objectref</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower {
/**
* Throw exception
*/
public ATHROW() {
super(com.sun.org.apache.bcel.internal.Constants.ATHROW, (short)1);
}
/** @return exceptions this instruction may cause
*/
public Class[] getExceptions() {
return new Class[] { com.sun.org.apache.bcel.internal.ExceptionConstants.THROWABLE };
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitUnconditionalBranch(this);
v.visitExceptionThrower(this);
v.visitATHROW(this);
}
}

View file

@ -0,0 +1,66 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Denote family of instructions that allocates space in the heap.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface AllocationInstruction {}

View file

@ -0,0 +1,109 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
/**
* Super class for the family of arithmetic instructions.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class ArithmeticInstruction extends Instruction
implements TypedInstruction, StackProducer, StackConsumer {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
ArithmeticInstruction() {}
/**
* @param opcode of instruction
*/
protected ArithmeticInstruction(short opcode) {
super(opcode, (short)1);
}
/** @return type associated with the instruction
*/
public Type getType(ConstantPoolGen cp) {
switch(opcode) {
case Constants.DADD: case Constants.DDIV: case Constants.DMUL:
case Constants.DNEG: case Constants.DREM: case Constants.DSUB:
return Type.DOUBLE;
case Constants.FADD: case Constants.FDIV: case Constants.FMUL:
case Constants.FNEG: case Constants.FREM: case Constants.FSUB:
return Type.FLOAT;
case Constants.IADD: case Constants.IAND: case Constants.IDIV:
case Constants.IMUL: case Constants.INEG: case Constants.IOR: case Constants.IREM:
case Constants.ISHL: case Constants.ISHR: case Constants.ISUB:
case Constants.IUSHR: case Constants.IXOR:
return Type.INT;
case Constants.LADD: case Constants.LAND: case Constants.LDIV:
case Constants.LMUL: case Constants.LNEG: case Constants.LOR: case Constants.LREM:
case Constants.LSHL: case Constants.LSHR: case Constants.LSUB:
case Constants.LUSHR: case Constants.LXOR:
return Type.LONG;
default: // Never reached
throw new ClassGenException("Unknown type " + opcode);
}
}
}

View file

@ -0,0 +1,109 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Super class for instructions dealing with array access such as IALOAD.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class ArrayInstruction extends Instruction
implements ExceptionThrower, TypedInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
ArrayInstruction() {}
/**
* @param opcode of instruction
*/
protected ArrayInstruction(short opcode) {
super(opcode, (short)1);
}
public Class[] getExceptions() {
return com.sun.org.apache.bcel.internal.ExceptionConstants.EXCS_ARRAY_EXCEPTION;
}
/** @return type associated with the instruction
*/
public Type getType(ConstantPoolGen cp) {
switch(opcode) {
case com.sun.org.apache.bcel.internal.Constants.IALOAD: case com.sun.org.apache.bcel.internal.Constants.IASTORE:
return Type.INT;
case com.sun.org.apache.bcel.internal.Constants.CALOAD: case com.sun.org.apache.bcel.internal.Constants.CASTORE:
return Type.CHAR;
case com.sun.org.apache.bcel.internal.Constants.BALOAD: case com.sun.org.apache.bcel.internal.Constants.BASTORE:
return Type.BYTE;
case com.sun.org.apache.bcel.internal.Constants.SALOAD: case com.sun.org.apache.bcel.internal.Constants.SASTORE:
return Type.SHORT;
case com.sun.org.apache.bcel.internal.Constants.LALOAD: case com.sun.org.apache.bcel.internal.Constants.LASTORE:
return Type.LONG;
case com.sun.org.apache.bcel.internal.Constants.DALOAD: case com.sun.org.apache.bcel.internal.Constants.DASTORE:
return Type.DOUBLE;
case com.sun.org.apache.bcel.internal.Constants.FALOAD: case com.sun.org.apache.bcel.internal.Constants.FASTORE:
return Type.FLOAT;
case com.sun.org.apache.bcel.internal.Constants.AALOAD: case com.sun.org.apache.bcel.internal.Constants.AASTORE:
return Type.OBJECT;
default: throw new ClassGenException("Oops: unknown case in switch" + opcode);
}
}
}

View file

@ -0,0 +1,159 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
/**
* Denotes array type, such as int[][]
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class ArrayType extends ReferenceType {
private int dimensions;
private Type basic_type;
/**
* Convenience constructor for array type, e.g. int[]
*
* @param type array type, e.g. T_INT
*/
public ArrayType(byte type, int dimensions) {
this(BasicType.getType(type), dimensions);
}
/**
* Convenience constructor for reference array type, e.g. Object[]
*
* @param class_name complete name of class (java.lang.String, e.g.)
*/
public ArrayType(String class_name, int dimensions) {
this(new ObjectType(class_name), dimensions);
}
/**
* Constructor for array of given type
*
* @param type type of array (may be an array itself)
*/
public ArrayType(Type type, int dimensions) {
super(Constants.T_ARRAY, "<dummy>");
if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
throw new ClassGenException("Invalid number of dimensions: " + dimensions);
switch(type.getType()) {
case Constants.T_ARRAY:
ArrayType array = (ArrayType)type;
this.dimensions = dimensions + array.dimensions;
basic_type = array.basic_type;
break;
case Constants.T_VOID:
throw new ClassGenException("Invalid type: void[]");
default: // Basic type or reference
this.dimensions = dimensions;
basic_type = type;
break;
}
StringBuffer buf = new StringBuffer();
for(int i=0; i < this.dimensions; i++)
buf.append('[');
buf.append(basic_type.getSignature());
signature = buf.toString();
}
/**
* @return basic type of array, i.e., for int[][][] the basic type is int
*/
public Type getBasicType() {
return basic_type;
}
/**
* @return element type of array, i.e., for int[][][] the element type is int[][]
*/
public Type getElementType() {
if(dimensions == 1)
return basic_type;
else
return new ArrayType(basic_type, dimensions - 1);
}
/** @return number of dimensions of array
*/
public int getDimensions() { return dimensions; }
/** @return a hash code value for the object.
*/
public int hashcode() { return basic_type.hashCode() ^ dimensions; }
/** @return true if both type objects refer to the same array type.
*/
public boolean equals(Object type) {
if(type instanceof ArrayType) {
ArrayType array = (ArrayType)type;
return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);
} else
return false;
}
}

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* BALOAD - Load byte or boolean from array
* <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class BALOAD extends ArrayInstruction implements StackProducer {
/** Load byte or boolean from array
*/
public BALOAD() {
super(com.sun.org.apache.bcel.internal.Constants.BALOAD);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackProducer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitBALOAD(this);
}
}

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* BASTORE - Store into byte or boolean array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class BASTORE extends ArrayInstruction implements StackConsumer {
/** Store byte or boolean into array
*/
public BASTORE() {
super(com.sun.org.apache.bcel.internal.Constants.BASTORE);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackConsumer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitBASTORE(this);
}
}

View file

@ -0,0 +1,134 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import java.io.*;
import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* BIPUSH - Push byte on stack
*
* <PRE>Stack: ... -&gt; ..., value</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class BIPUSH extends Instruction implements ConstantPushInstruction {
private byte b;
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
BIPUSH() {}
/** Push byte on stack
*/
public BIPUSH(byte b) {
super(com.sun.org.apache.bcel.internal.Constants.BIPUSH, (short)2);
this.b = b;
}
/**
* Dump instruction as byte code to stream out.
*/
public void dump(DataOutputStream out) throws IOException {
super.dump(out);
out.writeByte(b);
}
/**
* @return mnemonic for instruction
*/
public String toString(boolean verbose) {
return super.toString(verbose) + " " + b;
}
/**
* Read needed data (e.g. index) from file.
*/
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
length = 2;
b = bytes.readByte();
}
public Number getValue() { return new Integer(b); }
/** @return Type.BYTE
*/
public Type getType(ConstantPoolGen cp) {
return Type.BYTE;
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitPushInstruction(this);
v.visitStackProducer(this);
v.visitTypedInstruction(this);
v.visitConstantPushInstruction(this);
v.visitBIPUSH(this);
}
}

View file

@ -0,0 +1,82 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* BREAKPOINT, JVM dependent, ignored by default
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class BREAKPOINT extends Instruction {
public BREAKPOINT() {
super(com.sun.org.apache.bcel.internal.Constants.BREAKPOINT, (short)1);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitBREAKPOINT(this);
}
}

View file

@ -0,0 +1,104 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
/**
* Denotes basic type such as int.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class BasicType extends Type {
/**
* Constructor for basic types such as int, long, `void'
*
* @param type one of T_INT, T_BOOLEAN, ..., T_VOID
* @see com.sun.org.apache.bcel.internal.Constants
*/
BasicType(byte type) {
super(type, Constants.SHORT_TYPE_NAMES[type]);
if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID))
throw new ClassGenException("Invalid type: " + type);
}
public static final BasicType getType(byte type) {
switch(type) {
case Constants.T_VOID: return VOID;
case Constants.T_BOOLEAN: return BOOLEAN;
case Constants.T_BYTE: return BYTE;
case Constants.T_SHORT: return SHORT;
case Constants.T_CHAR: return CHAR;
case Constants.T_INT: return INT;
case Constants.T_LONG: return LONG;
case Constants.T_DOUBLE: return DOUBLE;
case Constants.T_FLOAT: return FLOAT;
default:
throw new ClassGenException("Invalid type: " + type);
}
}
/** @return true if both type objects refer to the same type
*/
public boolean equals(Object type) {
return (type instanceof BasicType)?
((BasicType)type).type == this.type : false;
}
}

View file

@ -0,0 +1,153 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* BranchHandle is returned by specialized InstructionList.append() whenever a
* BranchInstruction is appended. This is useful when the target of this
* instruction is not known at time of creation and must be set later
* via setTarget().
*
* @see InstructionHandle
* @see Instruction
* @see InstructionList
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class BranchHandle extends InstructionHandle {
private BranchInstruction bi; // An alias in fact, but saves lots of casts
private BranchHandle(BranchInstruction i) {
super(i);
bi = i;
}
/** Factory methods.
*/
private static BranchHandle bh_list = null; // List of reusable handles
static final BranchHandle getBranchHandle(BranchInstruction i) {
if(bh_list == null)
return new BranchHandle(i);
else {
BranchHandle bh = bh_list;
bh_list = (BranchHandle)bh.next;
bh.setInstruction(i);
return bh;
}
}
/** Handle adds itself to the list of resuable handles.
*/
protected void addHandle() {
next = bh_list;
bh_list = this;
}
/* Override InstructionHandle methods: delegate to branch instruction.
* Through this overriding all access to the private i_position field should
* be prevented.
*/
public int getPosition() { return bi.position; }
void setPosition(int pos) {
i_position = bi.position = pos;
}
protected int updatePosition(int offset, int max_offset) {
int x = bi.updatePosition(offset, max_offset);
i_position = bi.position;
return x;
}
/**
* Pass new target to instruction.
*/
public void setTarget(InstructionHandle ih) {
bi.setTarget(ih);
}
/**
* Update target of instruction.
*/
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
bi.updateTarget(old_ih, new_ih);
}
/**
* @return target of instruction.
*/
public InstructionHandle getTarget() {
return bi.getTarget();
}
/**
* Set new contents. Old instruction is disposed and may not be used anymore.
*/
public void setInstruction(Instruction i) {
super.setInstruction(i);
if(!(i instanceof BranchInstruction))
throw new ClassGenException("Assigning " + i +
" to branch handle which is not a branch instruction");
bi = (BranchInstruction)i;
}
}

View file

@ -0,0 +1,249 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import java.io.*;
import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Abstract super class for branching instructions like GOTO, IFEQ, etc..
* Branch instructions may have a variable length, namely GOTO, JSR,
* LOOKUPSWITCH and TABLESWITCH.
*
* @see InstructionList
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class BranchInstruction extends Instruction implements InstructionTargeter {
protected int index; // Branch target relative to this instruction
protected InstructionHandle target; // Target object in instruction list
protected int position; // Byte code offset
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
BranchInstruction() {}
/** Common super constructor
* @param opcodee Instruction opcode
* @param target instruction to branch to
*/
protected BranchInstruction(short opcode, InstructionHandle target) {
super(opcode, (short)3);
setTarget(target);
}
/**
* Dump instruction as byte code to stream out.
* @param out Output stream
*/
public void dump(DataOutputStream out) throws IOException {
out.writeByte(opcode);
index = getTargetOffset();
if(Math.abs(index) >= 32767) // too large for short
throw new ClassGenException("Branch target offset too large for short");
out.writeShort(index); // May be negative, i.e., point backwards
}
/**
* @param target branch target
* @return the offset to `target' relative to this instruction
*/
protected int getTargetOffset(InstructionHandle target) {
if(target == null)
throw new ClassGenException("Target of " + super.toString(true) +
" is invalid null handle");
int t = target.getPosition();
if(t < 0)
throw new ClassGenException("Invalid branch target position offset for " +
super.toString(true) + ":" + t + ":" + target);
return t - position;
}
/**
* @return the offset to this instruction's target
*/
protected int getTargetOffset() { return getTargetOffset(target); }
/**
* Called by InstructionList.setPositions when setting the position for every
* instruction. In the presence of variable length instructions `setPositions'
* performs multiple passes over the instruction list to calculate the
* correct (byte) positions and offsets by calling this function.
*
* @param offset additional offset caused by preceding (variable length) instructions
* @param max_offset the maximum offset that may be caused by these instructions
* @return additional offset caused by possible change of this instruction's length
*/
protected int updatePosition(int offset, int max_offset) {
position += offset;
return 0;
}
/**
* Long output format:
*
* &lt;position in byte code&gt;
* &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
* "("&lt;length of instruction&gt;")"
* "&lt;"&lt;target instruction&gt;"&gt;" "@"&lt;branch target offset&gt;
*
* @param verbose long/short format switch
* @return mnemonic for instruction
*/
public String toString(boolean verbose) {
String s = super.toString(verbose);
String t = "null";
if(verbose) {
if(target != null) {
if(target.getInstruction() == this)
t = "<points to itself>";
else if(target.getInstruction() == null)
t = "<null instruction!!!?>";
else
t = target.getInstruction().toString(false); // Avoid circles
}
} else {
if(target != null) {
index = getTargetOffset();
t = "" + (index + position);
}
}
return s + " -> " + t;
}
/**
* Read needed data (e.g. index) from file. Conversion to a InstructionHandle
* is done in InstructionList(byte[]).
*
* @param bytes input stream
* @param wide wide prefix?
* @see InstructionList
*/
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
length = 3;
index = bytes.readShort();
}
/**
* @return target offset in byte code
*/
public final int getIndex() { return index; }
/**
* @return target of branch instruction
*/
public InstructionHandle getTarget() { return target; }
/**
* Set branch target
* @param target branch target
*/
public void setTarget(InstructionHandle target) {
notifyTarget(this.target, target, this);
this.target = target;
}
/**
* Used by BranchInstruction, LocalVariableGen, CodeExceptionGen
*/
static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih,
InstructionTargeter t) {
if(old_ih != null)
old_ih.removeTargeter(t);
if(new_ih != null)
new_ih.addTargeter(t);
}
/**
* @param old_ih old target
* @param new_ih new target
*/
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
if(target == old_ih)
setTarget(new_ih);
else
throw new ClassGenException("Not targeting " + old_ih + ", but " + target);
}
/**
* @return true, if ih is target of this instruction
*/
public boolean containsTarget(InstructionHandle ih) {
return (target == ih);
}
/**
* Inform target that it's not targeted anymore.
*/
void dispose() {
setTarget(null);
index=-1;
position=-1;
}
}

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* CALOAD - Load char from array
* <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class CALOAD extends ArrayInstruction implements StackProducer {
/** Load char from array
*/
public CALOAD() {
super(com.sun.org.apache.bcel.internal.Constants.CALOAD);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackProducer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitCALOAD(this);
}
}

View file

@ -0,0 +1,90 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* CASTORE - Store into char array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class CASTORE extends ArrayInstruction implements StackConsumer {
/** Store char into array
*/
public CASTORE() {
super(com.sun.org.apache.bcel.internal.Constants.CASTORE);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitStackConsumer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);
v.visitArrayInstruction(this);
v.visitCASTORE(this);
}
}

View file

@ -0,0 +1,120 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.ExceptionConstants;
/**
* CHECKCAST - Check whether object is of given type
* <PRE>Stack: ..., objectref -&gt; ..., objectref</PRE>
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class CHECKCAST extends CPInstruction
implements LoadClass, ExceptionThrower, StackProducer, StackConsumer {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
CHECKCAST() {}
/** Check whether object is of given type
* @param n index to class in constant pool
*/
public CHECKCAST(int index) {
super(com.sun.org.apache.bcel.internal.Constants.CHECKCAST, index);
}
/** @return exceptions this instruction may cause
*/
public Class[] getExceptions() {
Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0,
cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] =
ExceptionConstants.CLASS_CAST_EXCEPTION;
return cs;
}
public ObjectType getLoadClassType(ConstantPoolGen cpg) {
Type t = getType(cpg);
if(t instanceof ArrayType)
t = ((ArrayType) t).getBasicType();
return (t instanceof ObjectType)? (ObjectType) t : null;
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then
* call methods according to the class hierarchy in descending order,
* i.e., the most specific visitXXX() call comes last.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitLoadClass(this);
v.visitExceptionThrower(this);
v.visitStackProducer(this);
v.visitStackConsumer(this);
v.visitTypedInstruction(this);
v.visitCPInstruction(this);
v.visitCHECKCAST(this);
}
}

View file

@ -0,0 +1,169 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import java.io.*;
import com.sun.org.apache.bcel.internal.util.ByteSequence;
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.classfile.*;
/**
* Abstract super class for instructions that use an index into the
* constant pool such as LDC, INVOKEVIRTUAL, etc.
*
* @see ConstantPoolGen
* @see LDC
* @see INVOKEVIRTUAL
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class CPInstruction extends Instruction
implements TypedInstruction, IndexedInstruction
{
protected int index; // index to constant pool
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
*/
CPInstruction() {}
/**
* @param index to constant pool
*/
protected CPInstruction(short opcode, int index) {
super(opcode, (short)3);
setIndex(index);
}
/**
* Dump instruction as byte code to stream out.
* @param out Output stream
*/
public void dump(DataOutputStream out) throws IOException {
out.writeByte(opcode);
out.writeShort(index);
}
/**
* Long output format:
*
* &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
* "("&lt;length of instruction&gt;")" "&lt;"&lt; constant pool index&gt;"&gt;"
*
* @param verbose long/short format switch
* @return mnemonic for instruction
*/
public String toString(boolean verbose) {
return super.toString(verbose) + " " + index;
}
/**
* @return mnemonic for instruction with symbolic references resolved
*/
public String toString(ConstantPool cp) {
Constant c = cp.getConstant(index);
String str = cp.constantToString(c);
if(c instanceof ConstantClass)
str = str.replace('.', '/');
return com.sun.org.apache.bcel.internal.Constants.OPCODE_NAMES[opcode] + " " + str;
}
/**
* Read needed data (i.e., index) from file.
* @param bytes input stream
* @param wide wide prefix?
*/
protected void initFromFile(ByteSequence bytes, boolean wide)
throws IOException
{
setIndex(bytes.readUnsignedShort());
length = 3;
}
/**
* @return index in constant pool referred by this instruction.
*/
public final int getIndex() { return index; }
/**
* Set the index to constant pool.
* @param index in constant pool.
*/
public void setIndex(int index) {
if(index < 0)
throw new ClassGenException("Negative index value: " + index);
this.index = index;
}
/** @return type related with this instruction.
*/
public Type getType(ConstantPoolGen cpg) {
ConstantPool cp = cpg.getConstantPool();
String name = cp.getConstantString(index, com.sun.org.apache.bcel.internal.Constants.CONSTANT_Class);
if(!name.startsWith("["))
name = "L" + name + ";";
return Type.getType(name);
}
}

View file

@ -0,0 +1,454 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.classfile.*;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Template class for building up a java class. May be initialized with an
* existing java class (file).
*
* @see JavaClass
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ClassGen extends AccessFlags implements Cloneable {
/* Corresponds to the fields found in a JavaClass object.
*/
private String class_name, super_class_name, file_name;
private int class_name_index = -1, superclass_name_index = -1;
private int major = Constants.MAJOR_1_1, minor = Constants.MINOR_1_1;
private ConstantPoolGen cp; // Template for building up constant pool
// ArrayLists instead of arrays to gather fields, methods, etc.
private ArrayList field_vec = new ArrayList();
private ArrayList method_vec = new ArrayList();
private ArrayList attribute_vec = new ArrayList();
private ArrayList interface_vec = new ArrayList();
/** Convenience constructor to set up some important values initially.
*
* @param class_name fully qualified class name
* @param super_class_name fully qualified superclass name
* @param file_name source file name
* @param access_flags access qualifiers
* @param interfaces implemented interfaces
* @param cp constant pool to use
*/
public ClassGen(String class_name, String super_class_name, String file_name,
int access_flags, String[] interfaces, ConstantPoolGen cp) {
this.class_name = class_name;
this.super_class_name = super_class_name;
this.file_name = file_name;
this.access_flags = access_flags;
this.cp = cp;
// Put everything needed by default into the constant pool and the vectors
if(file_name != null)
addAttribute(new SourceFile(cp.addUtf8("SourceFile"), 2,
cp.addUtf8(file_name), cp.getConstantPool()));
class_name_index = cp.addClass(class_name);
superclass_name_index = cp.addClass(super_class_name);
if(interfaces != null)
for(int i=0; i < interfaces.length; i++)
addInterface(interfaces[i]);
}
/** Convenience constructor to set up some important values initially.
*
* @param class_name fully qualified class name
* @param super_class_name fully qualified superclass name
* @param file_name source file name
* @param access_flags access qualifiers
* @param interfaces implemented interfaces
*/
public ClassGen(String class_name, String super_class_name, String file_name,
int access_flags, String[] interfaces) {
this(class_name, super_class_name, file_name, access_flags, interfaces,
new ConstantPoolGen());
}
/**
* Initialize with existing class.
* @param clazz JavaClass object (e.g. read from file)
*/
public ClassGen(JavaClass clazz) {
class_name_index = clazz.getClassNameIndex();
superclass_name_index = clazz.getSuperclassNameIndex();
class_name = clazz.getClassName();
super_class_name = clazz.getSuperclassName();
file_name = clazz.getSourceFileName();
access_flags = clazz.getAccessFlags();
cp = new ConstantPoolGen(clazz.getConstantPool());
major = clazz.getMajor();
minor = clazz.getMinor();
Attribute[] attributes = clazz.getAttributes();
Method[] methods = clazz.getMethods();
Field[] fields = clazz.getFields();
String[] interfaces = clazz.getInterfaceNames();
for(int i=0; i < interfaces.length; i++)
addInterface(interfaces[i]);
for(int i=0; i < attributes.length; i++)
addAttribute(attributes[i]);
for(int i=0; i < methods.length; i++)
addMethod(methods[i]);
for(int i=0; i < fields.length; i++)
addField(fields[i]);
}
/**
* @return the (finally) built up Java class object.
*/
public JavaClass getJavaClass() {
int[] interfaces = getInterfaces();
Field[] fields = getFields();
Method[] methods = getMethods();
Attribute[] attributes = getAttributes();
// Must be last since the above calls may still add something to it
ConstantPool cp = this.cp.getFinalConstantPool();
return new JavaClass(class_name_index, superclass_name_index,
file_name, major, minor, access_flags,
cp, interfaces, fields, methods, attributes);
}
/**
* Add an interface to this class, i.e., this class has to implement it.
* @param name interface to implement (fully qualified class name)
*/
public void addInterface(String name) {
interface_vec.add(name);
}
/**
* Remove an interface from this class.
* @param name interface to remove (fully qualified name)
*/
public void removeInterface(String name) {
interface_vec.remove(name);
}
/**
* @return major version number of class file
*/
public int getMajor() { return major; }
/** Set major version number of class file, default value is 45 (JDK 1.1)
* @param major major version number
*/
public void setMajor(int major) {
this.major = major;
}
/** Set minor version number of class file, default value is 3 (JDK 1.1)
* @param minor minor version number
*/
public void setMinor(int minor) {
this.minor = minor;
}
/**
* @return minor version number of class file
*/
public int getMinor() { return minor; }
/**
* Add an attribute to this class.
* @param a attribute to add
*/
public void addAttribute(Attribute a) { attribute_vec.add(a); }
/**
* Add a method to this class.
* @param m method to add
*/
public void addMethod(Method m) { method_vec.add(m); }
/**
* Convenience method.
*
* Add an empty constructor to this class that does nothing but calling super().
* @param access rights for constructor
*/
public void addEmptyConstructor(int access_flags) {
InstructionList il = new InstructionList();
il.append(InstructionConstants.THIS); // Push `this'
il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name,
"<init>", "()V")));
il.append(InstructionConstants.RETURN);
MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null,
"<init>", class_name, il, cp);
mg.setMaxStack(1);
addMethod(mg.getMethod());
}
/**
* Add a field to this class.
* @param f field to add
*/
public void addField(Field f) { field_vec.add(f); }
public boolean containsField(Field f) { return field_vec.contains(f); }
/** @return field object with given name, or null
*/
public Field containsField(String name) {
for(Iterator e=field_vec.iterator(); e.hasNext(); ) {
Field f = (Field)e.next();
if(f.getName().equals(name))
return f;
}
return null;
}
/** @return method object with given name and signature, or null
*/
public Method containsMethod(String name, String signature) {
for(Iterator e=method_vec.iterator(); e.hasNext();) {
Method m = (Method)e.next();
if(m.getName().equals(name) && m.getSignature().equals(signature))
return m;
}
return null;
}
/**
* Remove an attribute from this class.
* @param a attribute to remove
*/
public void removeAttribute(Attribute a) { attribute_vec.remove(a); }
/**
* Remove a method from this class.
* @param m method to remove
*/
public void removeMethod(Method m) { method_vec.remove(m); }
/** Replace given method with new one. If the old one does not exist
* add the new_ method to the class anyway.
*/
public void replaceMethod(Method old, Method new_) {
if(new_ == null)
throw new ClassGenException("Replacement method must not be null");
int i = method_vec.indexOf(old);
if(i < 0)
method_vec.add(new_);
else
method_vec.set(i, new_);
}
/** Replace given field with new one. If the old one does not exist
* add the new_ field to the class anyway.
*/
public void replaceField(Field old, Field new_) {
if(new_ == null)
throw new ClassGenException("Replacement method must not be null");
int i = field_vec.indexOf(old);
if(i < 0)
field_vec.add(new_);
else
field_vec.set(i, new_);
}
/**
* Remove a field to this class.
* @param f field to remove
*/
public void removeField(Field f) { field_vec.remove(f); }
public String getClassName() { return class_name; }
public String getSuperclassName() { return super_class_name; }
public String getFileName() { return file_name; }
public void setClassName(String name) {
class_name = name.replace('/', '.');
class_name_index = cp.addClass(name);
}
public void setSuperclassName(String name) {
super_class_name = name.replace('/', '.');
superclass_name_index = cp.addClass(name);
}
public Method[] getMethods() {
Method[] methods = new Method[method_vec.size()];
method_vec.toArray(methods);
return methods;
}
public void setMethods(Method[] methods) {
method_vec.clear();
for(int m=0; m<methods.length; m++)
addMethod(methods[m]);
}
public void setMethodAt(Method method, int pos) {
method_vec.set(pos, method);
}
public Method getMethodAt(int pos) {
return (Method)method_vec.get(pos);
}
public String[] getInterfaceNames() {
int size = interface_vec.size();
String[] interfaces = new String[size];
interface_vec.toArray(interfaces);
return interfaces;
}
public int[] getInterfaces() {
int size = interface_vec.size();
int[] interfaces = new int[size];
for(int i=0; i < size; i++)
interfaces[i] = cp.addClass((String)interface_vec.get(i));
return interfaces;
}
public Field[] getFields() {
Field[] fields = new Field[field_vec.size()];
field_vec.toArray(fields);
return fields;
}
public Attribute[] getAttributes() {
Attribute[] attributes = new Attribute[attribute_vec.size()];
attribute_vec.toArray(attributes);
return attributes;
}
public ConstantPoolGen getConstantPool() { return cp; }
public void setConstantPool(ConstantPoolGen constant_pool) {
cp = constant_pool;
}
public void setClassNameIndex(int class_name_index) {
this.class_name_index = class_name_index;
class_name = cp.getConstantPool().
getConstantString(class_name_index, Constants.CONSTANT_Class).replace('/', '.');
}
public void setSuperclassNameIndex(int superclass_name_index) {
this.superclass_name_index = superclass_name_index;
super_class_name = cp.getConstantPool().
getConstantString(superclass_name_index, Constants.CONSTANT_Class).replace('/', '.');
}
public int getSuperclassNameIndex() { return superclass_name_index; }
public int getClassNameIndex() { return class_name_index; }
private ArrayList observers;
/** Add observer for this object.
*/
public void addObserver(ClassObserver o) {
if(observers == null)
observers = new ArrayList();
observers.add(o);
}
/** Remove observer for this object.
*/
public void removeObserver(ClassObserver o) {
if(observers != null)
observers.remove(o);
}
/** Call notify() method on all observers. This method is not called
* automatically whenever the state has changed, but has to be
* called by the user after he has finished editing the object.
*/
public void update() {
if(observers != null)
for(Iterator e = observers.iterator(); e.hasNext(); )
((ClassObserver)e.next()).notify(this);
}
public Object clone() {
try {
return super.clone();
} catch(CloneNotSupportedException e) {
System.err.println(e);
return null;
}
}
}

View file

@ -0,0 +1,70 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Thrown on internal errors. Extends RuntimeException so it hasn't to be declared
* in the throws clause every time.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public class ClassGenException extends RuntimeException {
public ClassGenException() { super(); }
public ClassGenException(String s) { super(s); }
}

View file

@ -0,0 +1,69 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Implement this interface if you're interested in changes to a ClassGen object
* and register yourself with addObserver().
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface ClassObserver {
public void notify(ClassGen clazz);
}

View file

@ -0,0 +1,205 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.classfile.*;
/**
* This class represents an exception handler, i.e., specifies the region where
* a handler is active and an instruction where the actual handling is done.
* pool as parameters. Opposed to the JVM specification the end of the handled
* region is set to be inclusive, i.e. all instructions between start and end
* are protected including the start and end instructions (handles) themselves.
* The end of the region is automatically mapped to be exclusive when calling
* getCodeException(), i.e., there is no difference semantically.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see MethodGen
* @see CodeException
* @see InstructionHandle
*/
public final class CodeExceptionGen
implements InstructionTargeter, Cloneable, java.io.Serializable {
private InstructionHandle start_pc;
private InstructionHandle end_pc;
private InstructionHandle handler_pc;
private ObjectType catch_type;
/**
* Add an exception handler, i.e., specify region where a handler is active and an
* instruction where the actual handling is done.
*
* @param start_pc Start of handled region (inclusive)
* @param end_pc End of handled region (inclusive)
* @param handler_pc Where handling is done
* @param catch_type which exception is handled, null for ANY
*/
public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc,
InstructionHandle handler_pc, ObjectType catch_type) {
setStartPC(start_pc);
setEndPC(end_pc);
setHandlerPC(handler_pc);
this.catch_type = catch_type;
}
/**
* Get CodeException object.<BR>
*
* This relies on that the instruction list has already been dumped
* to byte code or or that the `setPositions' methods has been
* called for the instruction list.
*
* @param cp constant pool
*/
public CodeException getCodeException(ConstantPoolGen cp) {
return new CodeException(start_pc.getPosition(),
end_pc.getPosition() + end_pc.getInstruction().getLength(),
handler_pc.getPosition(),
(catch_type == null)? 0 : cp.addClass(catch_type));
}
/* Set start of handler
* @param start_pc Start of handled region (inclusive)
*/
public void setStartPC(InstructionHandle start_pc) {
BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
this.start_pc = start_pc;
}
/* Set end of handler
* @param end_pc End of handled region (inclusive)
*/
public void setEndPC(InstructionHandle end_pc) {
BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
this.end_pc = end_pc;
}
/* Set handler code
* @param handler_pc Start of handler
*/
public void setHandlerPC(InstructionHandle handler_pc) {
BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this);
this.handler_pc = handler_pc;
}
/**
* @param old_ih old target, either start or end
* @param new_ih new target
*/
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
boolean targeted = false;
if(start_pc == old_ih) {
targeted = true;
setStartPC(new_ih);
}
if(end_pc == old_ih) {
targeted = true;
setEndPC(new_ih);
}
if(handler_pc == old_ih) {
targeted = true;
setHandlerPC(new_ih);
}
if(!targeted)
throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " +
end_pc + ", " + handler_pc + "}");
}
/**
* @return true, if ih is target of this handler
*/
public boolean containsTarget(InstructionHandle ih) {
return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih);
}
/** Sets the type of the Exception to catch. Set 'null' for ANY. */
public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; }
/** Gets the type of the Exception to catch, 'null' for ANY. */
public ObjectType getCatchType() { return catch_type; }
/** @return start of handled region (inclusive)
*/
public InstructionHandle getStartPC() { return start_pc; }
/** @return end of handled region (inclusive)
*/
public InstructionHandle getEndPC() { return end_pc; }
/** @return start of handler
*/
public InstructionHandle getHandlerPC() { return handler_pc; }
public String toString() {
return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")";
}
public Object clone() {
try {
return super.clone();
} catch(CloneNotSupportedException e) {
System.err.println(e);
return null;
}
}
}

View file

@ -0,0 +1,78 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Wrapper class for `compound' operations, virtual instructions that
* don't exist as byte code, but give a useful meaning. For example,
* the (virtual) PUSH instruction takes an arbitray argument and produces the
* appropiate code at dump time (ICONST, LDC, BIPUSH, ...). Also you can use the
* SWITCH instruction as a useful template for either LOOKUPSWITCH or
* TABLESWITCH.
*
* The interface provides the possibilty for the user to write
* `templates' or `macros' for such reuseable code patterns.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see PUSH
* @see SWITCH
*/
public interface CompoundInstruction {
public InstructionList getInstructionList();
}

View file

@ -0,0 +1,789 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.classfile.*;
import java.util.HashMap;
/**
* This class is used to build up a constant pool. The user adds
* constants via `addXXX' methods, `addString', `addClass',
* etc.. These methods return an index into the constant
* pool. Finally, `getFinalConstantPool()' returns the constant pool
* built up. Intermediate versions of the constant pool can be
* obtained with `getConstantPool()'. A constant pool has capacity for
* Constants.MAX_SHORT entries. Note that the first (0) is used by the
* JVM and that Double and Long constants need two slots.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public class ConstantPoolGen implements java.io.Serializable {
protected int size = 1024; // Inital size, sufficient in most cases
protected Constant[] constants = new Constant[size];
protected int index = 1; // First entry (0) used by JVM
private static final String METHODREF_DELIM = ":";
private static final String IMETHODREF_DELIM = "#";
private static final String FIELDREF_DELIM = "&";
private static final String NAT_DELIM = "%";
private static class Index implements java.io.Serializable {
int index;
Index(int i) { index = i; }
}
/**
* Initialize with given array of constants.
*
* @param c array of given constants, new ones will be appended
*/
public ConstantPoolGen(Constant[] cs) {
if(cs.length > size) {
size = cs.length;
constants = new Constant[size];
}
System.arraycopy(cs, 0, constants, 0, cs.length);
if(cs.length > 0)
index = cs.length;
for(int i=1; i < index; i++) {
Constant c = constants[i];
if(c instanceof ConstantString) {
ConstantString s = (ConstantString)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
string_table.put(u8.getBytes(), new Index(i));
} else if(c instanceof ConstantClass) {
ConstantClass s = (ConstantClass)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
class_table.put(u8.getBytes(), new Index(i));
} else if(c instanceof ConstantNameAndType) {
ConstantNameAndType n = (ConstantNameAndType)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
n_a_t_table.put(u8.getBytes() + NAT_DELIM + u8_2.getBytes(), new Index(i));
} else if(c instanceof ConstantUtf8) {
ConstantUtf8 u = (ConstantUtf8)c;
utf8_table.put(u.getBytes(), new Index(i));
} else if(c instanceof ConstantCP) {
ConstantCP m = (ConstantCP)c;
ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
String class_name = u8.getBytes().replace('/', '.');
u8 = (ConstantUtf8)constants[n.getNameIndex()];
String method_name = u8.getBytes();
u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
String signature = u8.getBytes();
String delim = METHODREF_DELIM;
if(c instanceof ConstantInterfaceMethodref)
delim = IMETHODREF_DELIM;
else if(c instanceof ConstantFieldref)
delim = FIELDREF_DELIM;
cp_table.put(class_name + delim + method_name + delim + signature, new Index(i));
}
}
}
/**
* Initialize with given constant pool.
*/
public ConstantPoolGen(ConstantPool cp) {
this(cp.getConstantPool());
}
/**
* Create empty constant pool.
*/
public ConstantPoolGen() {}
/** Resize internal array of constants.
*/
protected void adjustSize() {
if(index + 3 >= size) {
Constant[] cs = constants;
size *= 2;
constants = new Constant[size];
System.arraycopy(cs, 0, constants, 0, index);
}
}
private HashMap string_table = new HashMap();
/**
* Look for ConstantString in ConstantPool containing String `str'.
*
* @param str String to search for
* @return index on success, -1 otherwise
*/
public int lookupString(String str) {
Index index = (Index)string_table.get(str);
return (index != null)? index.index : -1;
}
/**
* Add a new String constant to the ConstantPool, if it is not already in there.
*
* @param str String to add
* @return index of entry
*/
public int addString(String str) {
int ret;
if((ret = lookupString(str)) != -1)
return ret; // Already in CP
int utf8 = addUtf8(str);
adjustSize();
ConstantString s = new ConstantString(utf8);
ret = index;
constants[index++] = s;
string_table.put(str, new Index(ret));
return ret;
}
private HashMap class_table = new HashMap();
/**
* Look for ConstantClass in ConstantPool named `str'.
*
* @param str String to search for
* @return index on success, -1 otherwise
*/
public int lookupClass(String str) {
Index index = (Index)class_table.get(str.replace('.', '/'));
return (index != null)? index.index : -1;
}
private int addClass_(String clazz) {
int ret;
if((ret = lookupClass(clazz)) != -1)
return ret; // Already in CP
adjustSize();
ConstantClass c = new ConstantClass(addUtf8(clazz));
ret = index;
constants[index++] = c;
class_table.put(clazz, new Index(ret));
return ret;
}
/**
* Add a new Class reference to the ConstantPool, if it is not already in there.
*
* @param str Class to add
* @return index of entry
*/
public int addClass(String str) {
return addClass_(str.replace('.', '/'));
}
/**
* Add a new Class reference to the ConstantPool for a given type.
*
* @param str Class to add
* @return index of entry
*/
public int addClass(ObjectType type) {
return addClass(type.getClassName());
}
/**
* Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
* instruction, e.g. to the ConstantPool.
*
* @param type type of array class
* @return index of entry
*/
public int addArrayClass(ArrayType type) {
return addClass_(type.getSignature());
}
/**
* Look for ConstantInteger in ConstantPool.
*
* @param n integer number to look for
* @return index on success, -1 otherwise
*/
public int lookupInteger(int n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantInteger) {
ConstantInteger c = (ConstantInteger)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
}
/**
* Add a new Integer constant to the ConstantPool, if it is not already in there.
*
* @param n integer number to add
* @return index of entry
*/
public int addInteger(int n) {
int ret;
if((ret = lookupInteger(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantInteger(n);
return ret;
}
/**
* Look for ConstantFloat in ConstantPool.
*
* @param n Float number to look for
* @return index on success, -1 otherwise
*/
public int lookupFloat(float n) {
int bits = Float.floatToIntBits(n);
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantFloat) {
ConstantFloat c = (ConstantFloat)constants[i];
if(Float.floatToIntBits(c.getBytes()) == bits)
return i;
}
}
return -1;
}
/**
* Add a new Float constant to the ConstantPool, if it is not already in there.
*
* @param n Float number to add
* @return index of entry
*/
public int addFloat(float n) {
int ret;
if((ret = lookupFloat(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantFloat(n);
return ret;
}
private HashMap utf8_table = new HashMap();
/**
* Look for ConstantUtf8 in ConstantPool.
*
* @param n Utf8 string to look for
* @return index on success, -1 otherwise
*/
public int lookupUtf8(String n) {
Index index = (Index)utf8_table.get(n);
return (index != null)? index.index : -1;
}
/**
* Add a new Utf8 constant to the ConstantPool, if it is not already in there.
*
* @param n Utf8 string to add
* @return index of entry
*/
public int addUtf8(String n) {
int ret;
if((ret = lookupUtf8(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantUtf8(n);
utf8_table.put(n, new Index(ret));
return ret;
}
/**
* Look for ConstantLong in ConstantPool.
*
* @param n Long number to look for
* @return index on success, -1 otherwise
*/
public int lookupLong(long n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantLong) {
ConstantLong c = (ConstantLong)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
}
/**
* Add a new long constant to the ConstantPool, if it is not already in there.
*
* @param n Long number to add
* @return index of entry
*/
public int addLong(long n) {
int ret;
if((ret = lookupLong(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index] = new ConstantLong(n);
index += 2; // Wastes one entry according to spec
return ret;
}
/**
* Look for ConstantDouble in ConstantPool.
*
* @param n Double number to look for
* @return index on success, -1 otherwise
*/
public int lookupDouble(double n) {
long bits = Double.doubleToLongBits(n);
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantDouble) {
ConstantDouble c = (ConstantDouble)constants[i];
if(Double.doubleToLongBits(c.getBytes()) == bits)
return i;
}
}
return -1;
}
/**
* Add a new double constant to the ConstantPool, if it is not already in there.
*
* @param n Double number to add
* @return index of entry
*/
public int addDouble(double n) {
int ret;
if((ret = lookupDouble(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index] = new ConstantDouble(n);
index += 2; // Wastes one entry according to spec
return ret;
}
private HashMap n_a_t_table = new HashMap();
/**
* Look for ConstantNameAndType in ConstantPool.
*
* @param name of variable/method
* @param signature of variable/method
* @return index on success, -1 otherwise
*/
public int lookupNameAndType(String name, String signature) {
Index index = (Index)n_a_t_table.get(name + NAT_DELIM + signature);
return (index != null)? index.index : -1;
}
/**
* Add a new NameAndType constant to the ConstantPool if it is not already
* in there.
*
* @param n NameAndType string to add
* @return index of entry
*/
public int addNameAndType(String name, String signature) {
int ret;
int name_index, signature_index;
if((ret = lookupNameAndType(name, signature)) != -1)
return ret; // Already in CP
adjustSize();
name_index = addUtf8(name);
signature_index = addUtf8(signature);
ret = index;
constants[index++] = new ConstantNameAndType(name_index, signature_index);
n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret));
return ret;
}
private HashMap cp_table = new HashMap();
/**
* Look for ConstantMethodref in ConstantPool.
*
* @param class_name Where to find method
* @param method_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupMethodref(String class_name, String method_name, String signature) {
Index index = (Index)cp_table.get(class_name + METHODREF_DELIM + method_name +
METHODREF_DELIM + signature);
return (index != null)? index.index : -1;
}
public int lookupMethodref(MethodGen method) {
return lookupMethodref(method.getClassName(), method.getName(),
method.getSignature());
}
/**
* Add a new Methodref constant to the ConstantPool, if it is not already
* in there.
*
* @param n Methodref string to add
* @return index of entry
*/
public int addMethodref(String class_name, String method_name, String signature) {
int ret, class_index, name_and_type_index;
if((ret = lookupMethodref(class_name, method_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
name_and_type_index = addNameAndType(method_name, signature);
class_index = addClass(class_name);
ret = index;
constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
cp_table.put(class_name + METHODREF_DELIM + method_name +
METHODREF_DELIM + signature, new Index(ret));
return ret;
}
public int addMethodref(MethodGen method) {
return addMethodref(method.getClassName(), method.getName(),
method.getSignature());
}
/**
* Look for ConstantInterfaceMethodref in ConstantPool.
*
* @param class_name Where to find method
* @param method_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupInterfaceMethodref(String class_name, String method_name, String signature) {
Index index = (Index)cp_table.get(class_name + IMETHODREF_DELIM + method_name +
IMETHODREF_DELIM + signature);
return (index != null)? index.index : -1;
}
public int lookupInterfaceMethodref(MethodGen method) {
return lookupInterfaceMethodref(method.getClassName(), method.getName(),
method.getSignature());
}
/**
* Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
* in there.
*
* @param n InterfaceMethodref string to add
* @return index of entry
*/
public int addInterfaceMethodref(String class_name, String method_name, String signature) {
int ret, class_index, name_and_type_index;
if((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
class_index = addClass(class_name);
name_and_type_index = addNameAndType(method_name, signature);
ret = index;
constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
cp_table.put(class_name + IMETHODREF_DELIM + method_name +
IMETHODREF_DELIM + signature, new Index(ret));
return ret;
}
public int addInterfaceMethodref(MethodGen method) {
return addInterfaceMethodref(method.getClassName(), method.getName(),
method.getSignature());
}
/**
* Look for ConstantFieldref in ConstantPool.
*
* @param class_name Where to find method
* @param field_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupFieldref(String class_name, String field_name, String signature) {
Index index = (Index)cp_table.get(class_name + FIELDREF_DELIM + field_name +
FIELDREF_DELIM + signature);
return (index != null)? index.index : -1;
}
/**
* Add a new Fieldref constant to the ConstantPool, if it is not already
* in there.
*
* @param n Fieldref string to add
* @return index of entry
*/
public int addFieldref(String class_name, String field_name, String signature) {
int ret;
int class_index, name_and_type_index;
if((ret = lookupFieldref(class_name, field_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
class_index = addClass(class_name);
name_and_type_index = addNameAndType(field_name, signature);
ret = index;
constants[index++] = new ConstantFieldref(class_index, name_and_type_index);
cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret));
return ret;
}
/**
* @param i index in constant pool
* @return constant pool entry at index i
*/
public Constant getConstant(int i) { return constants[i]; }
/**
* Use with care!
*
* @param i index in constant pool
* @param c new constant pool entry at index i
*/
public void setConstant(int i, Constant c) { constants[i] = c; }
/**
* @return intermediate constant pool
*/
public ConstantPool getConstantPool() {
return new ConstantPool(constants);
}
/**
* @return current size of constant pool
*/
public int getSize() {
return index;
}
/**
* @return constant pool with proper length
*/
public ConstantPool getFinalConstantPool() {
Constant[] cs = new Constant[index];
System.arraycopy(constants, 0, cs, 0, index);
return new ConstantPool(cs);
}
/**
* @return String representation.
*/
public String toString() {
StringBuffer buf = new StringBuffer();
for(int i=1; i < index; i++)
buf.append(i + ")" + constants[i] + "\n");
return buf.toString();
}
/** Import constant from another ConstantPool and return new index.
*/
public int addConstant(Constant c, ConstantPoolGen cp) {
Constant[] constants = cp.getConstantPool().getConstantPool();
switch(c.getTag()) {
case Constants.CONSTANT_String: {
ConstantString s = (ConstantString)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
return addString(u8.getBytes());
}
case Constants.CONSTANT_Class: {
ConstantClass s = (ConstantClass)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
return addClass(u8.getBytes());
}
case Constants.CONSTANT_NameAndType: {
ConstantNameAndType n = (ConstantNameAndType)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
return addNameAndType(u8.getBytes(), u8_2.getBytes());
}
case Constants.CONSTANT_Utf8:
return addUtf8(((ConstantUtf8)c).getBytes());
case Constants.CONSTANT_Double:
return addDouble(((ConstantDouble)c).getBytes());
case Constants.CONSTANT_Float:
return addFloat(((ConstantFloat)c).getBytes());
case Constants.CONSTANT_Long:
return addLong(((ConstantLong)c).getBytes());
case Constants.CONSTANT_Integer:
return addInteger(((ConstantInteger)c).getBytes());
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref: {
ConstantCP m = (ConstantCP)c;
ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
String class_name = u8.getBytes().replace('/', '.');
u8 = (ConstantUtf8)constants[n.getNameIndex()];
String name = u8.getBytes();
u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
String signature = u8.getBytes();
switch(c.getTag()) {
case Constants.CONSTANT_InterfaceMethodref:
return addInterfaceMethodref(class_name, name, signature);
case Constants.CONSTANT_Methodref:
return addMethodref(class_name, name, signature);
case Constants.CONSTANT_Fieldref:
return addFieldref(class_name, name, signature);
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
}
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
}
}

View file

@ -0,0 +1,72 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.bcel.internal.generic;
/* ====================================================================
* 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
* the documentation and/or other materials provided with the
* 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
* <http://www.apache.org/>.
*/
/**
* Denotes a push instruction that produces a literal on the stack
* such as SIPUSH, BIPUSH, ICONST, etc.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ICONST
* @see SIPUSH
*/
public interface ConstantPushInstruction extends PushInstruction, TypedInstruction {
public Number getValue();
}

Some files were not shown because too many files have changed in this diff Show more