8224157: BCEL: update to version 6.3.1

Reviewed-by: dfuchs, lancea
This commit is contained in:
Joe Wang 2019-06-26 05:49:59 +00:00
parent 3d4d89b2ae
commit 622cdc7189
291 changed files with 5776 additions and 5721 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,59 +25,59 @@ import com.sun.org.apache.bcel.internal.util.SyntheticRepository;
/**
* 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.
* 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 SyntheticRepository
*
* @version $Id: Repository.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class Repository {
private static com.sun.org.apache.bcel.internal.util.Repository repository
= SyntheticRepository.getInstance();
/**
* @return currently used repository instance
/** @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
/** Set repository instance to be used for class loading
*/
public static void setRepository(final com.sun.org.apache.bcel.internal.util.Repository rep) {
public static void setRepository( final com.sun.org.apache.bcel.internal.util.Repository rep ) {
repository = rep;
}
/**
* Lookup class somewhere found on your CLASSPATH, or whereever the
/** Lookup class somewhere found on your CLASSPATH, or whereever the
* repository instance looks for it.
*
* @return class object for given fully qualified class name
* @throws ClassNotFoundException if the class could not be found or parsed
* correctly
* @throws ClassNotFoundException if the class could not be found or
* parsed correctly
*/
public static JavaClass lookupClass(final String class_name)
throws ClassNotFoundException {
public static JavaClass lookupClass( final String class_name ) throws ClassNotFoundException {
return repository.loadClass(class_name);
}
/**
* Try to find class source using the internal repository instance.
*
* @see Class
* @return JavaClass object for given runtime class
* @throws ClassNotFoundException if the class could not be found or parsed
* correctly
* @throws ClassNotFoundException if the class could not be found or
* parsed correctly
*/
public static JavaClass lookupClass(final Class<?> clazz)
throws ClassNotFoundException {
public static JavaClass lookupClass( final Class<?> clazz ) throws ClassNotFoundException {
return repository.loadClass(clazz);
}
/**
* Clear the repository.
*/
@ -85,149 +85,162 @@ public abstract class Repository {
repository.clear();
}
/**
* Add clazz to repository if there isn't an equally named class already in
* there.
* Add clazz to repository if there isn't an equally named class already in there.
*
* @return old entry in repository
*/
public static JavaClass addClass(final JavaClass clazz) {
public static JavaClass addClass( final JavaClass clazz ) {
final JavaClass old = repository.findClass(clazz.getClassName());
repository.storeClass(clazz);
return old;
}
/**
* Remove class with given (fully qualified) name from repository.
*/
public static void removeClass(final String clazz) {
public static void removeClass( final String clazz ) {
repository.removeClass(repository.findClass(clazz));
}
/**
* Remove given class from repository.
*/
public static void removeClass(final JavaClass clazz) {
public static void removeClass( final JavaClass clazz ) {
repository.removeClass(clazz);
}
/**
* @return list of super classes of clazz in ascending order, i.e., Object
* is always the last element
* @return list of super classes of clazz in ascending order, i.e.,
* Object is always the last element
* @throws ClassNotFoundException if any of the superclasses can't be found
*/
public static JavaClass[] getSuperClasses(final JavaClass clazz) throws ClassNotFoundException {
public static JavaClass[] getSuperClasses( final JavaClass clazz ) throws ClassNotFoundException {
return clazz.getSuperClasses();
}
/**
* @return list of super classes of clazz in ascending order, i.e., Object
* is always the last element.
* @return list of super classes of clazz in ascending order, i.e.,
* Object is always the last element.
* @throws ClassNotFoundException if the named class or any of its
* superclasses can't be found
* superclasses can't be found
*/
public static JavaClass[] getSuperClasses(final String class_name) throws ClassNotFoundException {
public static JavaClass[] getSuperClasses( final String class_name ) throws ClassNotFoundException {
final JavaClass jc = lookupClass(class_name);
return 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).
* @throws ClassNotFoundException if any of the class's superclasses or
* superinterfaces can't be found
* @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).
* @throws ClassNotFoundException if any of the class's
* superclasses or superinterfaces can't be found
*/
public static JavaClass[] getInterfaces(final JavaClass clazz) throws ClassNotFoundException {
public static JavaClass[] getInterfaces( final JavaClass clazz ) throws ClassNotFoundException {
return clazz.getAllInterfaces();
}
/**
* @return all interfaces implemented by class and its super classes and the
* interfaces that extend those interfaces, and so on
* @throws ClassNotFoundException if the named class can't be found, or if
* any of its superclasses or superinterfaces can't be found
* @return all interfaces implemented by class and its super
* classes and the interfaces that extend those interfaces, and so on
* @throws ClassNotFoundException if the named class can't be found,
* or if any of its superclasses or superinterfaces can't be found
*/
public static JavaClass[] getInterfaces(final String class_name) throws ClassNotFoundException {
public static JavaClass[] getInterfaces( final String class_name ) throws ClassNotFoundException {
return getInterfaces(lookupClass(class_name));
}
/**
* Equivalent to runtime "instanceof" operator.
*
* @return true, if clazz is an instance of super_class
* @throws ClassNotFoundException if any superclasses or superinterfaces of
* clazz can't be found
* @throws ClassNotFoundException if any superclasses or superinterfaces
* of clazz can't be found
*/
public static boolean instanceOf(final JavaClass clazz, final JavaClass super_class)
public static boolean instanceOf( final JavaClass clazz, final JavaClass super_class )
throws ClassNotFoundException {
return clazz.instanceOf(super_class);
}
/**
* @return true, if clazz is an instance of super_class
* @throws ClassNotFoundException if either clazz or super_class can't be
* found
* @throws ClassNotFoundException if either clazz or super_class
* can't be found
*/
public static boolean instanceOf(final String clazz, final String super_class)
public static boolean instanceOf( final String clazz, final String super_class )
throws ClassNotFoundException {
return instanceOf(lookupClass(clazz), lookupClass(super_class));
}
/**
* @return true, if clazz is an instance of super_class
* @throws ClassNotFoundException if super_class can't be found
*/
public static boolean instanceOf(final JavaClass clazz, final String super_class)
public static boolean instanceOf( final JavaClass clazz, final String super_class )
throws ClassNotFoundException {
return instanceOf(clazz, lookupClass(super_class));
}
/**
* @return true, if clazz is an instance of super_class
* @throws ClassNotFoundException if clazz can't be found
*/
public static boolean instanceOf(final String clazz, final JavaClass super_class)
public static boolean instanceOf( final String clazz, final JavaClass super_class )
throws ClassNotFoundException {
return instanceOf(lookupClass(clazz), super_class);
}
/**
* @return true, if clazz is an implementation of interface inter
* @throws ClassNotFoundException if any superclasses or superinterfaces of
* clazz can't be found
* @throws ClassNotFoundException if any superclasses or superinterfaces
* of clazz can't be found
*/
public static boolean implementationOf(final JavaClass clazz, final JavaClass inter)
public static boolean implementationOf( final JavaClass clazz, final JavaClass inter )
throws ClassNotFoundException {
return clazz.implementationOf(inter);
}
/**
* @return true, if clazz is an implementation of interface inter
* @throws ClassNotFoundException if clazz, inter, or any superclasses or
* superinterfaces of clazz can't be found
* @throws ClassNotFoundException if clazz, inter, or any superclasses
* or superinterfaces of clazz can't be found
*/
public static boolean implementationOf(final String clazz, final String inter)
public static boolean implementationOf( final String clazz, final String inter )
throws ClassNotFoundException {
return implementationOf(lookupClass(clazz), lookupClass(inter));
}
/**
* @return true, if clazz is an implementation of interface inter
* @throws ClassNotFoundException if inter or any superclasses or
* superinterfaces of clazz can't be found
* @throws ClassNotFoundException if inter or any superclasses
* or superinterfaces of clazz can't be found
*/
public static boolean implementationOf(final JavaClass clazz, final String inter)
public static boolean implementationOf( final JavaClass clazz, final String inter )
throws ClassNotFoundException {
return implementationOf(clazz, lookupClass(inter));
}
/**
* @return true, if clazz is an implementation of interface inter
* @throws ClassNotFoundException if clazz or any superclasses or
* superinterfaces of clazz can't be found
* superinterfaces of clazz can't be found
*/
public static boolean implementationOf(final String clazz, final JavaClass inter)
public static boolean implementationOf( final String clazz, final JavaClass inter )
throws ClassNotFoundException {
return implementationOf(lookupClass(clazz), inter);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,7 +25,8 @@ import com.sun.org.apache.bcel.internal.Const;
* Super class for all objects that have modifiers like private, final, ... I.e.
* classes, fields, and methods.
*
* @version $Id: AccessFlags.java 1748636 2016-06-15 20:45:17Z dbrosius $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class AccessFlags {
@ -35,7 +36,8 @@ public abstract class AccessFlags {
}
/**
* @param a inital access flags
* @param a
* inital access flags
*/
public AccessFlags(final int a) {
access_flags = a;
@ -58,7 +60,8 @@ public abstract class AccessFlags {
/**
* Set access flags aka "modifiers".
*
* @param access_flags Access flags of the object.
* @param access_flags
* Access flags of the object.
*/
public final void setAccessFlags(final int access_flags) {
this.access_flags = access_flags;
@ -67,7 +70,8 @@ public abstract class AccessFlags {
/**
* Set access flags aka "modifiers".
*
* @param access_flags Access flags of the object.
* @param access_flags
* Access flags of the object.
*/
public final void setModifiers(final int access_flags) {
setAccessFlags(access_flags);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -36,7 +36,7 @@ import com.sun.org.apache.bcel.internal.Const;
* <em>Synthetic</em> attributes are supported. The <em>Unknown</em>
* attribute stands for non-standard-attributes.
*
* @version $Id: Attribute.java 1750029 2016-06-23 22:14:38Z sebb $
* @version $Id$
* @see ConstantValue
* @see SourceFile
* @see Code
@ -48,6 +48,7 @@ import com.sun.org.apache.bcel.internal.Const;
* @see Synthetic
* @see Deprecated
* @see Signature
* @LastModified: Jun 2019
*/
public abstract class Attribute implements Cloneable, Node {
@ -79,7 +80,8 @@ public abstract class Attribute implements Cloneable, Node {
* @param file Output file stream
* @throws IOException
*/
public void dump(final DataOutputStream file) throws IOException {
public void dump(final DataOutputStream file) throws IOException
{
file.writeShort(name_index);
file.writeInt(length);
}
@ -92,9 +94,10 @@ public abstract class Attribute implements Cloneable, Node {
* 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
* @param r the reader object
*/
public static void addAttributeReader(final String name, final UnknownAttributeReader r) {
public static void addAttributeReader(final String name, final UnknownAttributeReader r)
{
readers.put(name, r);
}
@ -103,7 +106,8 @@ public abstract class Attribute implements Cloneable, Node {
*
* @param name the name of the attribute as stored in the class file
*/
public static void removeAttributeReader(final String name) {
public static void removeAttributeReader(final String name)
{
readers.remove(name);
}
@ -122,7 +126,8 @@ public abstract class Attribute implements Cloneable, Node {
* @throws ClassFormatException
*/
public static Attribute readAttribute(final DataInputStream file, final ConstantPool constant_pool)
throws IOException, ClassFormatException {
throws IOException, ClassFormatException
{
return readAttribute((DataInput) file, constant_pool);
}
@ -142,7 +147,8 @@ public abstract class Attribute implements Cloneable, Node {
* @since 6.0
*/
public static Attribute readAttribute(final DataInput file, final ConstantPool constant_pool)
throws IOException, ClassFormatException {
throws IOException, ClassFormatException
{
byte tag = Const.ATTR_UNKNOWN; // Unknown attribute
// Get class name from constant pool via `name_index' indirection
final int name_index = file.readUnsignedShort();
@ -153,18 +159,22 @@ public abstract class Attribute implements Cloneable, Node {
final int length = file.readInt();
// Compare strings to find known attribute
for (byte i = 0; i < Const.KNOWN_ATTRIBUTES; i++) {
if (name.equals(Const.getAttributeName(i))) {
for (byte i = 0; i < Const.KNOWN_ATTRIBUTES; i++)
{
if (name.equals(Const.getAttributeName(i)))
{
tag = i; // found!
break;
}
}
// Call proper constructor, depending on `tag'
switch (tag) {
switch (tag)
{
case Const.ATTR_UNKNOWN:
final Object r = readers.get(name);
if (r instanceof UnknownAttributeReader) {
if (r instanceof UnknownAttributeReader)
{
return ((UnknownAttributeReader) r).createAttribute(name_index, length, file, constant_pool);
}
return new Unknown(name_index, length, file, constant_pool);
@ -191,7 +201,10 @@ public abstract class Attribute implements Cloneable, Node {
case Const.ATTR_SIGNATURE:
return new Signature(name_index, length, file, constant_pool);
case Const.ATTR_STACK_MAP:
return new StackMap(name_index, length, file, constant_pool);
// old style stack map: unneeded for JDK5 and below;
// illegal(?) for JDK6 and above. So just delete with a warning.
System.err.println("Warning: Obsolete StackMap attribute ignored.");
return new Unknown(name_index, length, file, constant_pool);
case Const.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
return new RuntimeVisibleAnnotations(name_index, length, file, constant_pool);
case Const.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
@ -207,6 +220,8 @@ public abstract class Attribute implements Cloneable, Node {
case Const.ATTR_ENCLOSING_METHOD:
return new EnclosingMethod(name_index, length, file, constant_pool);
case Const.ATTR_STACK_MAP_TABLE:
// read new style stack map: StackMapTable. The rest of the code
// calls this a StackMap for historical reasons.
return new StackMap(name_index, length, file, constant_pool);
case Const.ATTR_BOOTSTRAP_METHODS:
return new BootstrapMethods(name_index, length, file, constant_pool);
@ -222,7 +237,8 @@ public abstract class Attribute implements Cloneable, Node {
* @return Name of attribute
* @since 6.0
*/
public String getName() {
public String getName()
{
final ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8);
return c.getBytes();
}
@ -230,36 +246,40 @@ public abstract class Attribute implements Cloneable, Node {
/**
* @return Length of attribute field in bytes.
*/
public final int getLength() {
public final int getLength()
{
return length;
}
/**
* @param length length in bytes.
*/
public final void setLength(final int length) {
public final void setLength(final int length)
{
this.length = length;
}
/**
* @param name_index of attribute.
*/
public final void setNameIndex(final int name_index) {
public final void setNameIndex(final int name_index)
{
this.name_index = name_index;
}
/**
* @return Name index in constant pool of attribute name.
*/
public final int getNameIndex() {
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.
* @return Tag of attribute, i.e., its type. Value may not be altered, thus there is no setTag() method.
*/
public final byte getTag() {
public final byte getTag()
{
return tag;
}
@ -267,7 +287,8 @@ public abstract class Attribute implements Cloneable, Node {
* @return Constant pool used by this object.
* @see ConstantPool
*/
public final ConstantPool getConstantPool() {
public final ConstantPool getConstantPool()
{
return constant_pool;
}
@ -275,7 +296,8 @@ public abstract class Attribute implements Cloneable, Node {
* @param constant_pool Constant pool to be used for this object.
* @see ConstantPool
*/
public final void setConstantPool(final ConstantPool constant_pool) {
public final void setConstantPool(final ConstantPool constant_pool)
{
this.constant_pool = constant_pool;
}
@ -286,11 +308,15 @@ public abstract class Attribute implements Cloneable, Node {
* @return shallow copy of this attribute
*/
@Override
public Object clone() {
public Object clone()
{
Attribute attr = null;
try {
try
{
attr = (Attribute) super.clone();
} catch (final CloneNotSupportedException e) {
}
catch (final CloneNotSupportedException e)
{
throw new Error("Clone Not Supported"); // never happens
}
return attr;
@ -305,7 +331,8 @@ public abstract class Attribute implements Cloneable, Node {
* @return attribute name.
*/
@Override
public String toString() {
public String toString()
{
return Const.getAttributeName(tag);
}
}

View File

@ -27,7 +27,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* method. These factory objects should implement this interface.
* @see Attribute
* @version $Id: AttributeReader.java 1748467 2016-06-14 21:05:14Z ggregory $
* @version $Id$
*
* @deprecated Use UnknownAttributeReader instead
*/

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* that the file is malformed or otherwise cannot be interpreted as a
* class file.
*
* @version $Id: ClassFormatException.java 1748973 2016-06-18 12:14:42Z sebb $
* @version $Id$
*/
public class ClassFormatException extends RuntimeException {

View File

@ -43,7 +43,7 @@ import com.sun.org.apache.bcel.internal.Const;
* JVM specification 1.0</a>. See this paper for
* further details about the structure of a bytecode file.
*
* @version $Id: ClassParser.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public final class ClassParser {

View File

@ -39,7 +39,7 @@ import com.sun.org.apache.bcel.internal.Const;
* is used for debugging purposes and <em>LocalVariableTable</em> which
* contains information about the local variables.
*
* @version $Id: Code.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
* @see CodeException
* @see LineNumberTable

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -31,8 +31,9 @@ import com.sun.org.apache.bcel.internal.Const;
* attribute and is used only there. It contains a range in which a
* particular exception handler is active.
*
* @version $Id: CodeException.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Code
* @LastModified: Jun 2019
*/
public final class CodeException implements Cloneable, Node {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -22,30 +22,33 @@ package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
/**
* 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.
* 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.
*
* @version $Id: Constant.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class Constant implements Cloneable, Node {
private static BCELComparator bcelComparator = new BCELComparator() {
@Override
public boolean equals(final Object o1, final Object o2) {
public boolean equals( final Object o1, final Object o2 ) {
final Constant THIS = (Constant) o1;
final Constant THAT = (Constant) o2;
return THIS.toString().equals(THAT.toString());
return Objects.equals(THIS.toString(), THAT.toString());
}
@Override
public int hashCode(final Object o) {
public int hashCode( final Object o ) {
final Constant THIS = (Constant) o;
return THIS.toString().hashCode();
}
@ -61,10 +64,12 @@ public abstract class Constant implements Cloneable, Node {
*/
private byte tag;
Constant(final 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,
@ -73,9 +78,11 @@ public abstract class Constant implements Cloneable, Node {
* @param v Visitor object
*/
@Override
public abstract void accept(Visitor v);
public abstract void accept( Visitor v );
public abstract void dump( DataOutputStream file ) throws IOException;
public abstract void dump(DataOutputStream file) throws IOException;
/**
* @return Tag of constant, i.e., its type. No setTag() method to avoid
@ -85,6 +92,7 @@ public abstract class Constant implements Cloneable, Node {
return tag;
}
/**
* @return String representation.
*/
@ -93,6 +101,7 @@ public abstract class Constant implements Cloneable, Node {
return Const.getConstantName(tag) + "[" + tag + "]";
}
/**
* @return deep copy of this constant
*/
@ -105,6 +114,7 @@ public abstract class Constant implements Cloneable, Node {
return null;
}
@Override
public Object clone() {
try {
@ -114,47 +124,55 @@ public abstract class Constant implements Cloneable, Node {
}
}
/**
* Read one constant from the given input, the type depends on a tag byte.
*
* @param input Input stream
* @param dataInput Input stream
* @return Constant object
* @throws IOException if an I/O error occurs reading from the given {@code dataInput}.
* @throws ClassFormatException if the next byte is not recognized
* @since 6.0 made public
*/
public static Constant readConstant(final DataInput input) throws IOException,
ClassFormatException {
final byte b = input.readByte(); // Read tag byte
public static Constant readConstant(final DataInput dataInput) throws IOException, ClassFormatException {
final byte b = dataInput.readByte(); // Read tag byte
switch (b) {
case Const.CONSTANT_Class:
return new ConstantClass(input);
case Const.CONSTANT_Fieldref:
return new ConstantFieldref(input);
case Const.CONSTANT_Methodref:
return new ConstantMethodref(input);
case Const.CONSTANT_InterfaceMethodref:
return new ConstantInterfaceMethodref(input);
case Const.CONSTANT_String:
return new ConstantString(input);
case Const.CONSTANT_Integer:
return new ConstantInteger(input);
case Const.CONSTANT_Float:
return new ConstantFloat(input);
case Const.CONSTANT_Long:
return new ConstantLong(input);
case Const.CONSTANT_Double:
return new ConstantDouble(input);
case Const.CONSTANT_NameAndType:
return new ConstantNameAndType(input);
case Const.CONSTANT_Utf8:
return ConstantUtf8.getInstance(input);
case Const.CONSTANT_MethodHandle:
return new ConstantMethodHandle(input);
case Const.CONSTANT_MethodType:
return new ConstantMethodType(input);
case Const.CONSTANT_InvokeDynamic:
return new ConstantInvokeDynamic(input);
default:
throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
case Const.CONSTANT_Class:
return new ConstantClass(dataInput);
case Const.CONSTANT_Fieldref:
return new ConstantFieldref(dataInput);
case Const.CONSTANT_Methodref:
return new ConstantMethodref(dataInput);
case Const.CONSTANT_InterfaceMethodref:
return new ConstantInterfaceMethodref(dataInput);
case Const.CONSTANT_String:
return new ConstantString(dataInput);
case Const.CONSTANT_Integer:
return new ConstantInteger(dataInput);
case Const.CONSTANT_Float:
return new ConstantFloat(dataInput);
case Const.CONSTANT_Long:
return new ConstantLong(dataInput);
case Const.CONSTANT_Double:
return new ConstantDouble(dataInput);
case Const.CONSTANT_NameAndType:
return new ConstantNameAndType(dataInput);
case Const.CONSTANT_Utf8:
return ConstantUtf8.getInstance(dataInput);
case Const.CONSTANT_MethodHandle:
return new ConstantMethodHandle(dataInput);
case Const.CONSTANT_MethodType:
return new ConstantMethodType(dataInput);
case Const.CONSTANT_Dynamic:
return new ConstantDynamic(dataInput);
case Const.CONSTANT_InvokeDynamic:
return new ConstantInvokeDynamic(dataInput);
case Const.CONSTANT_Module:
return new ConstantModule(dataInput);
case Const.CONSTANT_Package:
return new ConstantPackage(dataInput);
default:
throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
}
}
@ -165,28 +183,31 @@ public abstract class Constant implements Cloneable, Node {
return bcelComparator;
}
/**
* @param comparator Comparison strategy object
*/
public static void setComparator(final BCELComparator comparator) {
public static void setComparator( final BCELComparator comparator ) {
bcelComparator = comparator;
}
/**
* Return value as defined by given BCELComparator strategy. By default two
* Constant objects are said to be equal when the result of toString() is
* equal.
* Return value as defined by given BCELComparator strategy.
* By default two Constant objects are said to be equal when
* the result of toString() is equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {
public boolean equals( final Object obj ) {
return bcelComparator.equals(this, obj);
}
/**
* Return value as defined by given BCELComparator strategy. By default
* return the hashcode of the result of toString().
* Return value as defined by given BCELComparator strategy.
* By default return the hashcode of the result of toString().
*
* @see java.lang.Object#hashCode()
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -27,13 +27,14 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Abstract super class for Fieldref, Methodref, InterfaceMethodref and
* InvokeDynamic constants.
* InvokeDynamic constants.
*
* @version $Id: ConstantCP.java 1747278 2016-06-07 17:28:43Z britter $
* @see ConstantFieldref
* @see ConstantMethodref
* @see ConstantInterfaceMethodref
* @see ConstantInvokeDynamic
* @version $Id$
* @see ConstantFieldref
* @see ConstantMethodref
* @see ConstantInterfaceMethodref
* @see ConstantInvokeDynamic
* @LastModified: Jun 2019
*/
public abstract class ConstantCP extends Constant {
@ -53,10 +54,11 @@ public abstract class ConstantCP extends Constant {
this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param tag Constant type tag
* @param tag Constant type tag
* @param file Input stream
* @throws IOException
*/
@ -64,6 +66,7 @@ public abstract class ConstantCP extends Constant {
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
@ -74,6 +77,7 @@ public abstract class ConstantCP extends Constant {
this.name_and_type_index = name_and_type_index;
}
/**
* Dump constant field reference to file stream in binary format.
*
@ -81,12 +85,13 @@ public abstract class ConstantCP extends Constant {
* @throws IOException
*/
@Override
public final void dump(final DataOutputStream file) throws IOException {
public final void dump( final DataOutputStream file ) throws IOException {
file.writeByte(super.getTag());
file.writeShort(class_index);
file.writeShort(name_and_type_index);
}
/**
* @return Reference (index) to class this constant refers to.
*/
@ -94,13 +99,15 @@ public abstract class ConstantCP extends Constant {
return class_index;
}
/**
* @param class_index points to Constant_class
*/
public final void setClassIndex(final int class_index) {
public final void setClassIndex( final int class_index ) {
this.class_index = class_index;
}
/**
* @return Reference (index) to signature of the field.
*/
@ -108,20 +115,23 @@ public abstract class ConstantCP extends Constant {
return name_and_type_index;
}
/**
* @param name_and_type_index points to Constant_NameAndType
*/
public final void setNameAndTypeIndex(final int name_and_type_index) {
public final void setNameAndTypeIndex( final int name_and_type_index ) {
this.name_and_type_index = name_and_type_index;
}
/**
* @return Class this field belongs to.
*/
public String getClass(final ConstantPool cp) {
public String getClass( final ConstantPool cp ) {
return cp.constantToString(class_index, Const.CONSTANT_Class);
}
/**
* @return String representation.
*

View File

@ -31,7 +31,6 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a (external) class.
*
* @version $Id: ConstantClass.java 1749603 2016-06-21 20:50:19Z ggregory $
* @see Constant
*/
public final class ConstantClass extends Constant implements ConstantObject {
@ -48,13 +47,13 @@ public final class ConstantClass extends Constant implements ConstantObject {
/**
* Initialize instance from file data.
* Constructs an instance from file data.
*
* @param file Input stream
* @throws IOException
* @param dataInput Input stream
* @throws IOException if an I/O error occurs reading from the given {@code dataInput}.
*/
ConstantClass(final DataInput file) throws IOException {
this(file.readUnsignedShort());
ConstantClass(final DataInput dataInput) throws IOException {
this(dataInput.readUnsignedShort());
}
@ -82,10 +81,10 @@ public final class ConstantClass extends Constant implements ConstantObject {
/**
* Dump constant class to file stream in binary format.
* Dumps constant class to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
* @throws IOException if an I/O error occurs writing to the DataOutputStream.
*/
@Override
public final void dump( final DataOutputStream file ) throws IOException {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -30,9 +30,9 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a Double object.
*
* @version $Id: ConstantDouble.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
* @LastModified: Nov 2017
* @LastModified: Jun 2019
*/
public final class ConstantDouble extends Constant implements ConstantObject {

View File

@ -0,0 +1,94 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.Const;
/**
* This class is derived from the abstract {@link Constant}
* and represents a reference to a dynamically computed constant.
*
* @see Constant
* @see <a href="https://bugs.openjdk.java.net/secure/attachment/74618/constant-dynamic.html">
* Change request for JEP 309</a>
* @since 6.3
*/
public final class ConstantDynamic extends ConstantCP {
/**
* Initialize from another object.
*/
public ConstantDynamic(final ConstantDynamic c) {
this(c.getBootstrapMethodAttrIndex(), c.getNameAndTypeIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantDynamic(final DataInput file) throws IOException {
this(file.readShort(), file.readShort());
}
public ConstantDynamic(final int bootstrap_method_attr_index, final int name_and_type_index) {
super(Const.CONSTANT_Dynamic, bootstrap_method_attr_index, name_and_type_index);
}
/**
* Called by objects that are traversing the nodes of the tree implicitly
* 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
*/
@Override
public void accept( final Visitor v ) {
v.visitConstantDynamic(this);
}
/**
* @return Reference (index) to bootstrap method this constant refers to.
*
* Note that this method is a functional duplicate of getClassIndex
* for use by ConstantInvokeDynamic.
* @since 6.0
*/
public final int getBootstrapMethodAttrIndex() {
return super.getClassIndex(); // AKA bootstrap_method_attr_index
}
/**
* @return String representation
*/
@Override
public final String toString() {
return super.toString().replace("class_index", "bootstrap_method_attr_index");
}
}

View File

@ -29,7 +29,7 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* This class represents a constant pool reference to a field.
*
* @version $Id: ConstantFieldref.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public final class ConstantFieldref extends ConstantCP {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -30,9 +30,9 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a float object.
*
* @version $Id: ConstantFloat.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
* @LastModified: Nov 2017
* @LastModified: Jun 2019
*/
public final class ConstantFloat extends Constant implements ConstantObject {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -30,8 +30,9 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to an int object.
*
* @version $Id: ConstantInteger.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
* @LastModified: Jun 2019
*/
public final class ConstantInteger extends Constant implements ConstantObject {

View File

@ -29,7 +29,7 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* This class represents a constant pool reference to an interface method.
*
* @version $Id: ConstantInterfaceMethodref.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public final class ConstantInterfaceMethodref extends ConstantCP {

View File

@ -30,7 +30,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a long object.
*
* @version $Id: ConstantLong.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
*/
public final class ConstantLong extends Constant implements ConstantObject {

View File

@ -29,7 +29,7 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* This class represents a constant pool reference to a method.
*
* @version $Id: ConstantMethodref.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public final class ConstantMethodref extends ConstantCP {

View File

@ -0,0 +1,138 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.Const;
/**
* This class is derived from the abstract {@link Constant}
* and represents a reference to a module.
*
* <p>Note: Early access Java 9 support- currently subject to change</p>
*
* @see Constant
* @since 6.1
*/
public final class ConstantModule extends Constant implements ConstantObject {
private int name_index;
/**
* Initialize from another object.
*/
public ConstantModule(final ConstantModule c) {
this(c.getNameIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantModule(final DataInput file) throws IOException {
this(file.readUnsignedShort());
}
/**
* @param name_index Name index in constant pool. Should refer to a
* ConstantUtf8.
*/
public ConstantModule(final int name_index) {
super(Const.CONSTANT_Module);
this.name_index = name_index;
}
/**
* Called by objects that are traversing the nodes of the tree implicitly
* 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
*/
@Override
public void accept( final Visitor v ) {
v.visitConstantModule(this);
}
/**
* Dump constant module to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
@Override
public final void dump( final DataOutputStream file ) throws IOException {
file.writeByte(super.getTag());
file.writeShort(name_index);
}
/**
* @return Name index in constant pool of module name.
*/
public final int getNameIndex() {
return name_index;
}
/**
* @param name_index the name index in the constant pool of this Constant Module
*/
public final void setNameIndex( final int name_index ) {
this.name_index = name_index;
}
/** @return String object
*/
@Override
public Object getConstantValue( final ConstantPool cp ) {
final Constant c = cp.getConstant(name_index, Const.CONSTANT_Utf8);
return ((ConstantUtf8) c).getBytes();
}
/** @return dereferenced string
*/
public String getBytes( final ConstantPool cp ) {
return (String) getConstantValue(cp);
}
/**
* @return String representation.
*/
@Override
public final String toString() {
return super.toString() + "(name_index = " + name_index + ")";
}
}

View File

@ -32,7 +32,7 @@ import com.sun.org.apache.bcel.internal.Const;
* and represents a reference to the name and signature
* of a field or method.
*
* @version $Id: ConstantNameAndType.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
*/
public final class ConstantNameAndType extends Constant {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* This interface denotes those constants that have a "natural" value,
* such as ConstantLong, ConstantString, etc..
*
* @version $Id: ConstantObject.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see Constant
*/
public interface ConstantObject {

View File

@ -0,0 +1,138 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.Const;
/**
* This class is derived from the abstract {@link Constant}
* and represents a reference to a package.
*
* <p>Note: Early access Java 9 support- currently subject to change</p>
*
* @see Constant
* @since 6.1
*/
public final class ConstantPackage extends Constant implements ConstantObject {
private int name_index;
/**
* Initialize from another object.
*/
public ConstantPackage(final ConstantPackage c) {
this(c.getNameIndex());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantPackage(final DataInput file) throws IOException {
this(file.readUnsignedShort());
}
/**
* @param name_index Name index in constant pool. Should refer to a
* ConstantUtf8.
*/
public ConstantPackage(final int name_index) {
super(Const.CONSTANT_Package);
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
*/
@Override
public void accept( final Visitor v ) {
v.visitConstantPackage(this);
}
/**
* Dump constant package to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
@Override
public final void dump( final DataOutputStream file ) throws IOException {
file.writeByte(super.getTag());
file.writeShort(name_index);
}
/**
* @return Name index in constant pool of package name.
*/
public final int getNameIndex() {
return name_index;
}
/**
* @param name_index the name index in the constant pool of this Constant Package
*/
public final void setNameIndex( final int name_index ) {
this.name_index = name_index;
}
/** @return String object
*/
@Override
public Object getConstantValue( final ConstantPool cp ) {
final Constant c = cp.getConstant(name_index, Const.CONSTANT_Utf8);
return ((ConstantUtf8) c).getBytes();
}
/** @return dereferenced string
*/
public String getBytes( final ConstantPool cp ) {
return (String) getConstantValue(cp);
}
/**
* @return String representation.
*/
@Override
public final String toString() {
return super.toString() + "(name_index = " + name_index + ")";
}
}

View File

@ -35,7 +35,7 @@ import com.sun.org.apache.bcel.internal.Const;
* programatically should see <a href="../generic/ConstantPoolGen.html">
* ConstantPoolGen</a>.
* @version $Id: ConstantPool.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
*/
@ -135,7 +135,7 @@ public class ConstantPool implements Cloneable, Node {
case Const.CONSTANT_NameAndType:
str = constantToString(((ConstantNameAndType) c).getNameIndex(),
Const.CONSTANT_Utf8)
+ ":" + constantToString(((ConstantNameAndType) c).getSignatureIndex(),
+ " " + constantToString(((ConstantNameAndType) c).getSignatureIndex(),
Const.CONSTANT_Utf8);
break;
case Const.CONSTANT_InterfaceMethodref:

View File

@ -31,7 +31,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a String object.
*
* @version $Id: ConstantString.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Constant
*/
public final class ConstantString extends Constant implements ConstantObject {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -32,8 +32,9 @@ import java.util.Map;
* This class is derived from the abstract {@link Constant}
* and represents a reference to a Utf8 encoded string.
*
* @version $Id: ConstantUtf8.java 1750029 2016-06-23 22:14:38Z sebb $
* @version $Id$
* @see Constant
* @LastModified: Jun 2019
*/
public final class ConstantUtf8 extends Constant {

View File

@ -32,7 +32,7 @@ import com.sun.org.apache.bcel.internal.Const;
* value, i.e., a default value for initializing a class field.
* This class is instantiated by the <em>Attribute.readAttribute()</em> method.
*
* @version $Id: ConstantValue.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class ConstantValue extends Attribute {

View File

@ -28,16 +28,17 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* 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.
* deprecated method.
* It is instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @version $Id: Deprecated.java 1749603 2016-06-21 20:50:19Z ggregory $
* @see Attribute
* @version $Id$
* @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.
@ -46,6 +47,7 @@ public final class Deprecated extends Attribute {
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
@ -57,6 +59,7 @@ public final class Deprecated extends Attribute {
this.bytes = bytes;
}
/**
* Construct object from input stream.
*
@ -76,6 +79,7 @@ public final class Deprecated extends Attribute {
}
}
/**
* 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,
@ -84,10 +88,11 @@ public final class Deprecated extends Attribute {
* @param v Visitor object
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitDeprecated(this);
}
/**
* Dump source file attribute to file stream in binary format.
*
@ -95,13 +100,14 @@ public final class Deprecated extends Attribute {
* @throws IOException
*/
@Override
public final void dump(final DataOutputStream file) throws IOException {
public final void dump( final DataOutputStream file ) throws IOException {
super.dump(file);
if (super.getLength() > 0) {
file.write(bytes, 0, super.getLength());
}
}
/**
* @return data bytes.
*/
@ -109,13 +115,15 @@ public final class Deprecated extends Attribute {
return bytes;
}
/**
* @param bytes the raw bytes that represents this byte array
*/
public final void setBytes(final byte[] bytes) {
public final void setBytes( final byte[] bytes ) {
this.bytes = bytes;
}
/**
* @return attribute name
*/
@ -124,11 +132,12 @@ public final class Deprecated extends Attribute {
return Const.getAttributeName(Const.ATTR_DEPRECATED);
}
/**
* @return deep copy of this attribute
*/
@Override
public Attribute copy(final ConstantPool _constant_pool) {
public Attribute copy( final ConstantPool _constant_pool ) {
final Deprecated c = (Deprecated) clone();
if (bytes != null) {
c.bytes = new byte[bytes.length];

View File

@ -26,10 +26,10 @@ import java.util.Stack;
* applied to all components of a JavaClass object. I.e. this class supplies the
* traversal strategy, other classes can make use of it.
*
* @version $Id: DescendingVisitor.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public class DescendingVisitor implements Visitor {
public class DescendingVisitor implements Visitor
{
private final JavaClass clazz;
private final Visitor visitor;
@ -39,17 +39,21 @@ public class DescendingVisitor implements Visitor {
/**
* @return container of current entitity, i.e., predecessor during traversal
*/
public Object predecessor() {
public Object predecessor()
{
return predecessor(0);
}
/**
* @param level nesting level, i.e., 0 returns the direct predecessor
* @param level
* nesting level, i.e., 0 returns the direct predecessor
* @return container of current entitity, i.e., predecessor during traversal
*/
public Object predecessor(final int level) {
public Object predecessor(final int level)
{
final int size = stack.size();
if ((size < 2) || (level < 0)) {
if ((size < 2) || (level < 0))
{
return null;
}
return stack.elementAt(size - (level + 2)); // size - 1 == current
@ -58,15 +62,19 @@ public class DescendingVisitor implements Visitor {
/**
* @return current object
*/
public Object current() {
public Object current()
{
return stack.peek();
}
/**
* @param clazz Class to traverse
* @param visitor visitor object to apply to all components
* @param clazz
* Class to traverse
* @param visitor
* visitor object to apply to all components
*/
public DescendingVisitor(final JavaClass clazz, final Visitor visitor) {
public DescendingVisitor(final JavaClass clazz, final Visitor visitor)
{
this.clazz = clazz;
this.visitor = visitor;
}
@ -74,12 +82,14 @@ public class DescendingVisitor implements Visitor {
/**
* Start traversal.
*/
public void visit() {
public void visit()
{
clazz.accept(this);
}
@Override
public void visitJavaClass(final JavaClass _clazz) {
public void visitJavaClass(final JavaClass _clazz)
{
stack.push(_clazz);
_clazz.accept(visitor);
final Field[] fields = _clazz.getFields();
@ -102,7 +112,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitAnnotation(final Annotations annotation) {
public void visitAnnotation(final Annotations annotation)
{
stack.push(annotation);
annotation.accept(visitor);
final AnnotationEntry[] entries = annotation.getAnnotationEntries();
@ -116,14 +127,16 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitAnnotationEntry(final AnnotationEntry annotationEntry) {
public void visitAnnotationEntry(final AnnotationEntry annotationEntry)
{
stack.push(annotationEntry);
annotationEntry.accept(visitor);
stack.pop();
}
@Override
public void visitField(final Field field) {
public void visitField(final Field field)
{
stack.push(field);
field.accept(visitor);
final Attribute[] attributes = field.getAttributes();
@ -134,14 +147,16 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitConstantValue(final ConstantValue cv) {
public void visitConstantValue(final ConstantValue cv)
{
stack.push(cv);
cv.accept(visitor);
stack.pop();
}
@Override
public void visitMethod(final Method method) {
public void visitMethod(final Method method)
{
stack.push(method);
method.accept(visitor);
final Attribute[] attributes = method.getAttributes();
@ -152,14 +167,16 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitExceptionTable(final ExceptionTable table) {
public void visitExceptionTable(final ExceptionTable table)
{
stack.push(table);
table.accept(visitor);
stack.pop();
}
@Override
public void visitCode(final Code code) {
public void visitCode(final Code code)
{
stack.push(code);
code.accept(visitor);
final CodeException[] table = code.getExceptionTable();
@ -174,14 +191,16 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitCodeException(final CodeException ce) {
public void visitCodeException(final CodeException ce)
{
stack.push(ce);
ce.accept(visitor);
stack.pop();
}
@Override
public void visitLineNumberTable(final LineNumberTable table) {
public void visitLineNumberTable(final LineNumberTable table)
{
stack.push(table);
table.accept(visitor);
final LineNumber[] numbers = table.getLineNumberTable();
@ -192,14 +211,16 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitLineNumber(final LineNumber number) {
public void visitLineNumber(final LineNumber number)
{
stack.push(number);
number.accept(visitor);
stack.pop();
}
@Override
public void visitLocalVariableTable(final LocalVariableTable table) {
public void visitLocalVariableTable(final LocalVariableTable table)
{
stack.push(table);
table.accept(visitor);
final LocalVariable[] vars = table.getLocalVariableTable();
@ -210,7 +231,8 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitStackMap(final StackMap table) {
public void visitStackMap(final StackMap table)
{
stack.push(table);
table.accept(visitor);
final StackMapEntry[] vars = table.getStackMap();
@ -221,26 +243,31 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitStackMapEntry(final StackMapEntry var) {
public void visitStackMapEntry(final StackMapEntry var)
{
stack.push(var);
var.accept(visitor);
stack.pop();
}
@Override
public void visitLocalVariable(final LocalVariable var) {
public void visitLocalVariable(final LocalVariable var)
{
stack.push(var);
var.accept(visitor);
stack.pop();
}
@Override
public void visitConstantPool(final ConstantPool cp) {
public void visitConstantPool(final ConstantPool cp)
{
stack.push(cp);
cp.accept(visitor);
final Constant[] constants = cp.getConstantPool();
for (int i = 1; i < constants.length; i++) {
if (constants[i] != null) {
for (int i = 1; i < constants.length; i++)
{
if (constants[i] != null)
{
constants[i].accept(this);
}
}
@ -248,35 +275,40 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitConstantClass(final ConstantClass constant) {
public void visitConstantClass(final ConstantClass constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantDouble(final ConstantDouble constant) {
public void visitConstantDouble(final ConstantDouble constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantFieldref(final ConstantFieldref constant) {
public void visitConstantFieldref(final ConstantFieldref constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantFloat(final ConstantFloat constant) {
public void visitConstantFloat(final ConstantFloat constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantInteger(final ConstantInteger constant) {
public void visitConstantInteger(final ConstantInteger constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
@ -284,7 +316,8 @@ public class DescendingVisitor implements Visitor {
@Override
public void visitConstantInterfaceMethodref(
final ConstantInterfaceMethodref constant) {
final ConstantInterfaceMethodref constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
@ -295,49 +328,56 @@ public class DescendingVisitor implements Visitor {
*/
@Override
public void visitConstantInvokeDynamic(
final ConstantInvokeDynamic constant) {
final ConstantInvokeDynamic constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantLong(final ConstantLong constant) {
public void visitConstantLong(final ConstantLong constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantMethodref(final ConstantMethodref constant) {
public void visitConstantMethodref(final ConstantMethodref constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantNameAndType(final ConstantNameAndType constant) {
public void visitConstantNameAndType(final ConstantNameAndType constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantString(final ConstantString constant) {
public void visitConstantString(final ConstantString constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitConstantUtf8(final ConstantUtf8 constant) {
public void visitConstantUtf8(final ConstantUtf8 constant)
{
stack.push(constant);
constant.accept(visitor);
stack.pop();
}
@Override
public void visitInnerClasses(final InnerClasses ic) {
public void visitInnerClasses(final InnerClasses ic)
{
stack.push(ic);
ic.accept(visitor);
final InnerClass[] ics = ic.getInnerClasses();
@ -348,7 +388,8 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitInnerClass(final InnerClass inner) {
public void visitInnerClass(final InnerClass inner)
{
stack.push(inner);
inner.accept(visitor);
stack.pop();
@ -358,7 +399,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitBootstrapMethods(final BootstrapMethods bm) {
public void visitBootstrapMethods(final BootstrapMethods bm)
{
stack.push(bm);
bm.accept(visitor);
// BootstrapMethod[] bms = bm.getBootstrapMethods();
@ -370,35 +412,40 @@ public class DescendingVisitor implements Visitor {
}
@Override
public void visitDeprecated(final Deprecated attribute) {
public void visitDeprecated(final Deprecated attribute)
{
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
@Override
public void visitSignature(final Signature attribute) {
public void visitSignature(final Signature attribute)
{
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
@Override
public void visitSourceFile(final SourceFile attribute) {
public void visitSourceFile(final SourceFile attribute)
{
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
@Override
public void visitSynthetic(final Synthetic attribute) {
public void visitSynthetic(final Synthetic attribute)
{
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
}
@Override
public void visitUnknown(final Unknown attribute) {
public void visitUnknown(final Unknown attribute)
{
stack.push(attribute);
attribute.accept(visitor);
stack.pop();
@ -408,7 +455,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitAnnotationDefault(final AnnotationDefault obj) {
public void visitAnnotationDefault(final AnnotationDefault obj)
{
stack.push(obj);
obj.accept(visitor);
stack.pop();
@ -418,7 +466,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitEnclosingMethod(final EnclosingMethod obj) {
public void visitEnclosingMethod(final EnclosingMethod obj)
{
stack.push(obj);
obj.accept(visitor);
stack.pop();
@ -428,21 +477,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitLocalVariableTypeTable(final LocalVariableTypeTable obj) {
stack.push(obj);
obj.accept(visitor);
LocalVariable[] vars = obj.getLocalVariableTypeTable();
for (LocalVariable var : vars) {
var.accept(this);
}
stack.pop();
}
/**
* @since 6.0
*/
@Override
public void visitParameterAnnotation(final ParameterAnnotations obj) {
public void visitLocalVariableTypeTable(final LocalVariableTypeTable obj)
{
stack.push(obj);
obj.accept(visitor);
stack.pop();
@ -452,7 +488,8 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitMethodParameters(final MethodParameters obj) {
public void visitParameterAnnotation(final ParameterAnnotations obj)
{
stack.push(obj);
obj.accept(visitor);
stack.pop();
@ -462,15 +499,22 @@ public class DescendingVisitor implements Visitor {
* @since 6.0
*/
@Override
public void visitMethodParameters(final MethodParameters obj)
{
stack.push(obj);
obj.accept(visitor);
stack.pop();
}
/** @since 6.0 */
@Override
public void visitConstantMethodType(final ConstantMethodType obj) {
stack.push(obj);
obj.accept(visitor);
stack.pop();
}
/**
* @since 6.0
*/
/** @since 6.0 */
@Override
public void visitConstantMethodHandle(final ConstantMethodHandle obj) {
stack.push(obj);
@ -478,9 +522,7 @@ public class DescendingVisitor implements Visitor {
stack.pop();
}
/**
* @since 6.0
*/
/** @since 6.0 */
@Override
public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
stack.push(obj);
@ -488,4 +530,27 @@ public class DescendingVisitor implements Visitor {
stack.pop();
}
/** @since 6.1 */
@Override
public void visitConstantPackage(final ConstantPackage obj) {
stack.push(obj);
obj.accept(visitor);
stack.pop();
}
/** @since 6.1 */
@Override
public void visitConstantModule(final ConstantModule obj) {
stack.push(obj);
obj.accept(visitor);
stack.pop();
}
/** @since 6.3 */
@Override
public void visitConstantDynamic(final ConstantDynamic obj) {
stack.push(obj);
obj.accept(visitor);
stack.pop();
}
}

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -28,6 +27,7 @@ import java.io.IOException;
/**
* @version $Id: ElementValue
* @since 6.0
* @LastModified: Jun 2019
*/
public abstract class ElementValue
{

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* with the DescendingVisitor class, e.g. By courtesy of David Spencer.
*
* @see DescendingVisitor
* @version $Id: EmptyVisitor.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class EmptyVisitor implements Visitor
{
@ -300,4 +300,26 @@ public class EmptyVisitor implements Visitor
@Override
public void visitParameterAnnotationEntry(final ParameterAnnotationEntry parameterAnnotationEntry) {
}
/**
* @since 6.1
*/
@Override
public void visitConstantPackage(final ConstantPackage constantPackage) {
}
/**
* @since 6.1
*/
@Override
public void visitConstantModule(final ConstantModule constantModule) {
}
/**
* @since 6.3
*/
@Override
public void visitConstantDynamic(final ConstantDynamic obj) {
}
}

View File

@ -35,7 +35,7 @@ import com.sun.org.apache.bcel.internal.Const;
* attribute using the name <em>Exceptions</em> (which is inconsistent
* with the other classes).
*
* @version $Id: ExceptionTable.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Code
*/
public final class ExceptionTable extends Attribute {

View File

@ -23,6 +23,7 @@ package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.IOException;
import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.generic.Type;
@ -32,7 +33,7 @@ import com.sun.org.apache.bcel.internal.util.BCELComparator;
* This class represents the field info structure, i.e., the representation
* for a variable in the class. See JVM specification for details.
*
* @version $Id: Field.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public final class Field extends FieldOrMethod {
@ -42,8 +43,8 @@ public final class Field extends FieldOrMethod {
public boolean equals( final Object o1, final Object o2 ) {
final Field THIS = (Field) o1;
final Field THAT = (Field) o2;
return THIS.getName().equals(THAT.getName())
&& THIS.getSignature().equals(THAT.getSignature());
return Objects.equals(THIS.getName(), THAT.getName())
&& Objects.equals(THIS.getSignature(), THAT.getSignature());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -29,7 +29,8 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Abstract super class for fields and methods.
*
* @version $Id: FieldOrMethod.java 1750029 2016-06-23 22:14:38Z sebb $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
private int name_index; // Points to field name in constant pool
@ -48,6 +49,7 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
FieldOrMethod() {
}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
@ -57,25 +59,23 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
c.getAttributes(), c.getConstantPool());
}
/**
* Construct object from file stream.
*
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
* @deprecated (6.0) Use
* {@link #FieldOrMethod(java.io.DataInput, ConstantPool)} instead.
* @deprecated (6.0) Use {@link #FieldOrMethod(java.io.DataInput, ConstantPool)} instead.
*/
@java.lang.Deprecated
protected FieldOrMethod(final DataInputStream file,
final ConstantPool constant_pool) throws IOException,
protected FieldOrMethod(final DataInputStream file, final ConstantPool constant_pool) throws IOException,
ClassFormatException {
this((DataInput) file, constant_pool);
}
/**
* Construct object from file stream.
*
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
@ -84,13 +84,15 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
final ConstantPool constant_pool) throws IOException, ClassFormatException {
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
constant_pool);
attributes_count = file.readUnsignedShort();
final int attributes_count = file.readUnsignedShort();
attributes = new Attribute[attributes_count];
for (int i = 0; i < attributes_count; i++) {
attributes[i] = Attribute.readAttribute(file, constant_pool);
}
this.attributes_count = attributes_count; // init deprecated field
}
/**
* @param access_flags Access rights of method
* @param name_index Points to field name in constant pool
@ -107,6 +109,7 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
setAttributes(attributes);
}
/**
* Dump object to file stream on binary format.
*
@ -118,12 +121,14 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
file.writeShort(name_index);
file.writeShort(signature_index);
file.writeShort(attributes_count);
for(int i=0; i < attributes_count; i++) {
attributes[i].dump(file);
if (attributes != null) {
for (final Attribute attribute : attributes) {
attribute.dump(file);
}
}
}
/**
* @return Collection of object attributes.
*/
@ -131,14 +136,16 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return attributes;
}
/**
* @param attributes Collection of object attributes.
*/
public final void setAttributes(final Attribute[] attributes) {
public final void setAttributes( final Attribute[] attributes ) {
this.attributes = attributes;
this.attributes_count = attributes != null ? attributes.length : 0;
this.attributes_count = attributes != null ? attributes.length : 0; // init deprecated field
}
/**
* @return Constant pool used by this object.
*/
@ -146,13 +153,15 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return constant_pool;
}
/**
* @param constant_pool Constant pool to be used for this object.
*/
public final void setConstantPool(final ConstantPool constant_pool) {
public final void setConstantPool( final ConstantPool constant_pool ) {
this.constant_pool = constant_pool;
}
/**
* @return Index in constant pool of object's name.
*/
@ -160,13 +169,15 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return name_index;
}
/**
* @param name_index Index in constant pool of object's name.
*/
public final void setNameIndex(final int name_index) {
public final void setNameIndex( final int name_index ) {
this.name_index = name_index;
}
/**
* @return Index in constant pool of field signature.
*/
@ -174,13 +185,15 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return signature_index;
}
/**
* @param signature_index Index in constant pool of field signature.
*/
public final void setSignatureIndex(final int signature_index) {
public final void setSignatureIndex( final int signature_index ) {
this.signature_index = signature_index;
}
/**
* @return Name of object, i.e., method name or field name
*/
@ -190,6 +203,7 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return c.getBytes();
}
/**
* @return String representation of object's type signature (java style)
*/
@ -199,23 +213,24 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
return c.getBytes();
}
/**
* @return deep copy of this field
*/
protected FieldOrMethod copy_(final ConstantPool _constant_pool) {
protected FieldOrMethod copy_( final ConstantPool _constant_pool ) {
FieldOrMethod c = null;
try {
c = (FieldOrMethod) clone();
} catch (final CloneNotSupportedException e) {
c = (FieldOrMethod)clone();
} catch(final CloneNotSupportedException e) {
// ignored, but will cause NPE ...
}
c.constant_pool = constant_pool;
c.attributes = new Attribute[attributes_count];
c.attributes_count = attributes_count;
c.constant_pool = constant_pool;
c.attributes = new Attribute[attributes.length];
c.attributes_count = attributes_count; // init deprecated field
for (int i = 0; i < attributes_count; i++) {
for (int i = 0; i < attributes.length; i++) {
c.attributes[i] = attributes[i].copy(constant_pool);
}
@ -244,11 +259,15 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No
*
* @since 6.0
*/
public final String getGenericSignature() {
if (!searchedForSignatureAttribute) {
public final String getGenericSignature()
{
if (!searchedForSignatureAttribute)
{
boolean found = false;
for (int i = 0; !found && i < attributes.length; i++) {
if (attributes[i] instanceof Signature) {
for (int i = 0; !found && i < attributes.length; i++)
{
if (attributes[i] instanceof Signature)
{
signatureAttributeString = ((Signature) attributes[i])
.getSignature();
found = true;

View File

@ -32,7 +32,7 @@ import com.sun.org.apache.bcel.internal.Const;
* indices of the inner and outer classes, the name and the attributes
* of the inner class.
*
* @version $Id: InnerClass.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see InnerClasses
*/
public final class InnerClass implements Cloneable, Node {

View File

@ -33,7 +33,7 @@ import com.sun.org.apache.bcel.internal.Const;
* to the source file of this class.
* It is instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @version $Id: InnerClasses.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class InnerClasses extends Attribute {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,9 +26,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import com.sun.org.apache.bcel.internal.Const;
@ -36,7 +37,6 @@ import com.sun.org.apache.bcel.internal.generic.Type;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
import com.sun.org.apache.bcel.internal.util.ClassQueue;
import com.sun.org.apache.bcel.internal.util.SyntheticRepository;
import jdk.xml.internal.SecuritySupport;
/**
* Represents a Java class, i.e., the data structures, constant pool, fields,
@ -45,9 +45,10 @@ import jdk.xml.internal.SecuritySupport;
* details. The intent of this class is to represent a parsed or otherwise
* existing class file. Those interested in programatically generating classes
* should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
*
* @version $Id: JavaClass.java 1750227 2016-06-25 21:47:10Z ggregory $
* @version $Id$
* @see com.sun.org.apache.bcel.internal.generic.ClassGen
* @LastModified: Jun 2019
*/
public class JavaClass extends AccessFlags implements Cloneable, Node, Comparable<JavaClass> {
@ -78,25 +79,28 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
private static BCELComparator bcelComparator = new BCELComparator() {
@Override
public boolean equals(final Object o1, final Object o2) {
public boolean equals( final Object o1, final Object o2 ) {
final JavaClass THIS = (JavaClass) o1;
final JavaClass THAT = (JavaClass) o2;
return THIS.getClassName().equals(THAT.getClassName());
return Objects.equals(THIS.getClassName(), THAT.getClassName());
}
@Override
public int hashCode(final Object o) {
public int hashCode( final Object o ) {
final JavaClass THIS = (JavaClass) o;
return THIS.getClassName().hashCode();
}
};
/**
* In cases where we go ahead and create something, use the default
* SyntheticRepository, because we don't know any better.
* 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.
*
@ -177,6 +181,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
}
}
/**
* Constructor gets all contents as arguments.
*
@ -200,15 +205,16 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
constant_pool, interfaces, fields, methods, attributes, HEAP);
}
/**
* Called by objects that are traversing the nodes of the tree implicitly
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitJavaClass(this);
}
@ -223,7 +229,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
if (parent != null) {
final File dir = new File(parent);
if (!dir.mkdirs()) { // either was not created or already existed
if (!SecuritySupport.isDirectory(dir)) {
if (!dir.isDirectory()) {
throw new IOException("Could not create the directory " + dir);
}
}
@ -233,16 +239,18 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
}
}
/**
* Dump class to a file named file_name.
*
* @param _file_name Output file name
* @throws IOException
*/
public void dump(final String _file_name) throws IOException {
public void dump( final String _file_name ) throws IOException {
dump(new File(_file_name));
}
/**
* @return class in binary format
*/
@ -263,15 +271,6 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return s.toByteArray();
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @throws IOException
*/
public void dump(final OutputStream file) throws IOException {
dump(new DataOutputStream(file));
}
/**
* Dump Java class to output stream in binary format.
@ -279,7 +278,18 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
* @param file Output stream
* @throws IOException
*/
private void dump(final DataOutputStream file) throws IOException {
public void dump( final OutputStream file ) throws IOException {
dump(new DataOutputStream(file));
}
/**
* Dump Java class to output stream in binary format.
*
* @param file Output stream
* @throws IOException
*/
public void dump( final DataOutputStream file ) throws IOException {
file.writeInt(Const.JVM_CLASSFILE_MAGIC);
file.writeShort(minor);
file.writeShort(major);
@ -310,6 +320,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
file.flush();
}
/**
* @return Attributes of the class.
*/
@ -336,6 +347,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return class_name;
}
/**
* @return Package name.
*/
@ -343,6 +355,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return package_name;
}
/**
* @return Class name index.
*/
@ -350,6 +363,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return class_name_index;
}
/**
* @return Constant pool.
*/
@ -357,15 +371,17 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return constant_pool;
}
/**
* @return Fields, i.e., variables of the class. Like the JVM spec mandates
* for the classfile format, these fields are those specific to this class,
* and not those of the superclass or superinterfaces.
* @return 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
*/
@ -373,6 +389,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return file_name;
}
/**
* @return Names of implemented interfaces.
*/
@ -380,6 +397,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return interface_names;
}
/**
* @return Indices in constant pool of implemented interfaces.
*/
@ -387,6 +405,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return interfaces;
}
/**
* @return Major number of class file version.
*/
@ -394,6 +413,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return major;
}
/**
* @return Methods of the class.
*/
@ -401,10 +421,12 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return methods;
}
/**
* @return A {@link Method} corresponding to java.lang.reflect.Method if any
* @return A {@link Method} corresponding to
* java.lang.reflect.Method if any
*/
public Method getMethod(final java.lang.reflect.Method m) {
public Method getMethod( final java.lang.reflect.Method m ) {
for (final Method method : methods) {
if (m.getName().equals(method.getName()) && (m.getModifiers() == method.getModifiers())
&& Type.getSignature(m).equals(method.getSignature())) {
@ -414,6 +436,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return null;
}
/**
* @return Minor number of class file version.
*/
@ -421,6 +444,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return minor;
}
/**
* @return sbsolute path to file where this class was read from
*/
@ -428,11 +452,11 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return source_file_name;
}
/**
* returns the super class name of this class. In the case that this class
* is java.lang.Object, it will return itself (java.lang.Object). This is
* probably incorrect but isn't fixed at this time to not break existing
* clients.
* returns the super class name of this class. In the case that this class is
* java.lang.Object, it will return itself (java.lang.Object). This is probably incorrect
* but isn't fixed at this time to not break existing clients.
*
* @return Superclass name.
*/
@ -440,6 +464,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return superclass_name;
}
/**
* @return Class name index.
*/
@ -450,101 +475,115 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
/**
* @param attributes .
*/
public void setAttributes(final Attribute[] attributes) {
public void setAttributes( final Attribute[] attributes ) {
this.attributes = attributes;
}
/**
* @param class_name .
*/
public void setClassName(final String class_name) {
public void setClassName( final String class_name ) {
this.class_name = class_name;
}
/**
* @param class_name_index .
*/
public void setClassNameIndex(final int class_name_index) {
public void setClassNameIndex( final int class_name_index ) {
this.class_name_index = class_name_index;
}
/**
* @param constant_pool .
*/
public void setConstantPool(final ConstantPool constant_pool) {
public void setConstantPool( final ConstantPool constant_pool ) {
this.constant_pool = constant_pool;
}
/**
* @param fields .
*/
public void setFields(final Field[] fields) {
public void setFields( final Field[] fields ) {
this.fields = fields;
}
/**
* Set File name of class, aka SourceFile attribute value
*/
public void setFileName(final String file_name) {
public void setFileName( final String file_name ) {
this.file_name = file_name;
}
/**
* @param interface_names .
*/
public void setInterfaceNames(final String[] interface_names) {
public void setInterfaceNames( final String[] interface_names ) {
this.interface_names = interface_names;
}
/**
* @param interfaces .
*/
public void setInterfaces(final int[] interfaces) {
public void setInterfaces( final int[] interfaces ) {
this.interfaces = interfaces;
}
/**
* @param major .
*/
public void setMajor(final int major) {
public void setMajor( final int major ) {
this.major = major;
}
/**
* @param methods .
*/
public void setMethods(final Method[] methods) {
public void setMethods( final Method[] methods ) {
this.methods = methods;
}
/**
* @param minor .
*/
public void setMinor(final int minor) {
public void setMinor( final int minor ) {
this.minor = minor;
}
/**
* Set absolute path to file this class was read from.
*/
public void setSourceFileName(final String source_file_name) {
public void setSourceFileName( final String source_file_name ) {
this.source_file_name = source_file_name;
}
/**
* @param superclass_name .
*/
public void setSuperclassName(final String superclass_name) {
public void setSuperclassName( final String superclass_name ) {
this.superclass_name = superclass_name;
}
/**
* @param superclass_name_index .
*/
public void setSuperclassNameIndex(final int superclass_name_index) {
public void setSuperclassNameIndex( final int superclass_name_index ) {
this.superclass_name_index = superclass_name_index;
}
/**
* @return String representing class contents.
*/
@ -555,7 +594,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
final StringBuilder buf = new StringBuilder(128);
buf.append(access).append(Utility.classOrInterface(super.getAccessFlags())).append(" ").append(
class_name).append(" extends ").append(
Utility.compactClassName(superclass_name, false)).append('\n');
Utility.compactClassName(superclass_name, false)).append('\n');
final int size = interfaces.length;
if (size > 0) {
buf.append("implements\t\t");
@ -580,7 +619,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
}
}
final AnnotationEntry[] annotations = getAnnotationEntries();
if (annotations != null && annotations.length > 0) {
if (annotations!=null && annotations.length>0) {
buf.append("\nAnnotation(s):\n");
for (final AnnotationEntry annotation : annotations) {
buf.append(indent(annotation));
@ -601,7 +640,8 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return buf.toString();
}
private static String indent(final Object obj) {
private static String indent( final Object obj ) {
final StringTokenizer tok = new StringTokenizer(obj.toString(), "\n");
final StringBuilder buf = new StringBuilder();
while (tok.hasMoreTokens()) {
@ -610,6 +650,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return buf.toString();
}
/**
* @return deep copy of this class
*/
@ -638,10 +679,12 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return c;
}
public final boolean isSuper() {
return (super.getAccessFlags() & Const.ACC_SUPER) != 0;
}
public final boolean isClass() {
return (super.getAccessFlags() & Const.ACC_INTERFACE) == 0;
}
@ -667,62 +710,62 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return;
}
for (final Attribute attribute : this.attributes) {
if (attribute instanceof InnerClasses) {
final InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses();
for (final InnerClass innerClasse : innerClasses) {
boolean innerClassAttributeRefersToMe = false;
String inner_class_name = constant_pool.getConstantString(innerClasse.getInnerClassIndex(),
Const.CONSTANT_Class);
inner_class_name = Utility.compactClassName(inner_class_name);
if (inner_class_name.equals(getClassName())) {
innerClassAttributeRefersToMe = true;
}
if (innerClassAttributeRefersToMe) {
this.isNested = true;
if (innerClasse.getInnerNameIndex() == 0) {
this.isAnonymous = true;
}
}
}
}
if (attribute instanceof InnerClasses) {
final InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses();
for (final InnerClass innerClasse : innerClasses) {
boolean innerClassAttributeRefersToMe = false;
String inner_class_name = constant_pool.getConstantString(innerClasse.getInnerClassIndex(),
Const.CONSTANT_Class);
inner_class_name = Utility.compactClassName(inner_class_name);
if (inner_class_name.equals(getClassName())) {
innerClassAttributeRefersToMe = true;
}
if (innerClassAttributeRefersToMe) {
this.isNested = true;
if (innerClasse.getInnerNameIndex() == 0) {
this.isAnonymous = true;
}
}
}
}
}
this.computedNestedTypeStatus = true;
}
/**
* @return returns either HEAP (generated), FILE, or ZIP
/** @return returns either HEAP (generated), FILE, or ZIP
*/
public final byte getSource() {
return source;
}
/********************* New repository functionality *********************/
/**
* ******************* New repository functionality ********************
*/
/**
* Gets the ClassRepository which holds its definition. By default this is
* the same as SyntheticRepository.getInstance();
* 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.
* Sets the ClassRepository which loaded the JavaClass.
* Should be called immediately after parsing is done.
*/
public void setRepository(final com.sun.org.apache.bcel.internal.util.Repository repository) {
this.repository = repository;
}
/**
* Equivalent to runtime "instanceof" operator.
/** Equivalent to runtime "instanceof" operator.
*
* @return true if this JavaClass is derived from the super class
* @throws ClassNotFoundException if superclasses or superinterfaces of this
* object can't be found
* @throws ClassNotFoundException if superclasses or superinterfaces
* of this object can't be found
*/
public final boolean instanceOf(final JavaClass super_class) throws ClassNotFoundException {
public final boolean instanceOf( final JavaClass super_class ) throws ClassNotFoundException {
if (this.equals(super_class)) {
return true;
}
@ -738,12 +781,13 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return false;
}
/**
* @return true, if this class is an implementation of interface inter
* @throws ClassNotFoundException if superclasses or superinterfaces of this
* class can't be found
* @throws ClassNotFoundException if superclasses or superinterfaces
* of this class can't be found
*/
public boolean implementationOf(final JavaClass inter) throws ClassNotFoundException {
public boolean implementationOf( final JavaClass inter ) throws ClassNotFoundException {
if (!inter.isInterface()) {
throw new IllegalArgumentException(inter.getClassName() + " is no interface");
}
@ -759,9 +803,10 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return false;
}
/**
* @return the superclass for this JavaClass object, or null if this is
* java.lang.Object
* @return the superclass for this JavaClass object, or null if this
* is java.lang.Object
* @throws ClassNotFoundException if the superclass can't be found
*/
public JavaClass getSuperClass() throws ClassNotFoundException {
@ -771,6 +816,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return repository.loadClass(getSuperclassName());
}
/**
* @return list of super classes of this class in ascending order, i.e.,
* java.lang.Object is always the last element
@ -785,6 +831,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return allSuperClasses.toArray(new JavaClass[allSuperClasses.size()]);
}
/**
* Get interfaces directly implemented by this JavaClass.
*/
@ -797,6 +844,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return classes;
}
/**
* Get all interfaces implemented by this JavaClass (transitively).
*/
@ -822,6 +870,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return allInterfaces.toArray(new JavaClass[allInterfaces.size()]);
}
/**
* @return Comparison strategy object
*/
@ -829,38 +878,42 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
return bcelComparator;
}
/**
* @param comparator Comparison strategy object
*/
public static void setComparator(final BCELComparator comparator) {
public static void setComparator( final BCELComparator comparator ) {
bcelComparator = comparator;
}
/**
* Return value as defined by given BCELComparator strategy. By default two
* JavaClass objects are said to be equal when their class names are equal.
* Return value as defined by given BCELComparator strategy.
* By default two JavaClass objects are said to be equal when
* their class names are equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {
public boolean equals( final Object obj ) {
return bcelComparator.equals(this, obj);
}
/**
* Return the natural ordering of two JavaClasses. This ordering is based on
* the class name
*
* Return the natural ordering of two JavaClasses.
* This ordering is based on the class name
* @since 6.0
*/
@Override
public int compareTo(final JavaClass obj) {
public int compareTo( final JavaClass obj ) {
return getClassName().compareTo(obj.getClassName());
}
/**
* Return value as defined by given BCELComparator strategy. By default
* return the hashcode of the class name.
* Return value as defined by given BCELComparator strategy.
* By default return the hashcode of the class name.
*
* @see java.lang.Object#hashCode()
*/

View File

@ -30,7 +30,7 @@ import java.io.IOException;
* the source that corresponds to a relative address in the byte code. This
* is used for debugging purposes.
*
* @version $Id: LineNumber.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see LineNumberTable
*/
public final class LineNumber implements Cloneable, Node {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,13 +26,14 @@ import java.io.IOException;
import jdk.xml.internal.SecuritySupport;
/**
* 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.
* 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.
*
* @version $Id: LineNumberTable.java 1749603 2016-06-21 20:50:19Z ggregory $
* @see Code
* @version $Id$
* @see Code
* @see LineNumber
* @LastModified: Jun 2019
*/
public final class LineNumberTable extends Attribute {
@ -63,7 +64,6 @@ public final class LineNumberTable extends Attribute {
/**
* Construct object from input stream.
*
* @param name_index Index of name
* @param length Content length in bytes
* @param input Input stream
@ -88,7 +88,7 @@ public final class LineNumberTable extends Attribute {
* @param v Visitor object
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitLineNumberTable(this);
}
@ -99,7 +99,7 @@ public final class LineNumberTable extends Attribute {
* @throws IOEXception if an I/O Exception occurs in writeShort
*/
@Override
public final void dump(final DataOutputStream file) throws IOException {
public final void dump( final DataOutputStream file ) throws IOException {
super.dump(file);
file.writeShort(line_number_table.length);
for (final LineNumber lineNumber : line_number_table) {
@ -117,7 +117,7 @@ public final class LineNumberTable extends Attribute {
/**
* @param line_number_table the line number entries for this table
*/
public final void setLineNumberTable(final LineNumber[] line_number_table) {
public final void setLineNumberTable( final LineNumber[] line_number_table ) {
this.line_number_table = line_number_table;
}
@ -150,7 +150,7 @@ public final class LineNumberTable extends Attribute {
* @param pos byte code offset
* @return corresponding line in source code
*/
public int getSourceLine(final int pos) {
public int getSourceLine( final int pos ) {
int l = 0;
int r = line_number_table.length - 1;
if (r < 0) {
@ -192,7 +192,7 @@ public final class LineNumberTable extends Attribute {
* @return deep copy of this attribute
*/
@Override
public Attribute copy(final ConstantPool _constant_pool) {
public Attribute copy( final ConstantPool _constant_pool ) {
// TODO could use the lower level constructor and thereby allow
// line_number_table to be made final
final LineNumberTable c = (LineNumberTable) clone();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -30,8 +30,9 @@ import com.sun.org.apache.bcel.internal.Const;
* This class represents a local variable within a method. It contains its
* scope, name, signature and index on the method's frame.
*
* @version $Id: LocalVariable.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see LocalVariableTable
* @LastModified: Jun 2019
*/
public final class LocalVariable implements Cloneable, Node {
@ -43,6 +44,7 @@ public final class LocalVariable implements Cloneable, Node {
* this method's frame.
*/
private ConstantPool constant_pool;
private int orig_index; // never changes; used to match up with LocalVariableTypeTable entries
/**
@ -52,6 +54,7 @@ public final class LocalVariable implements Cloneable, Node {
public LocalVariable(final LocalVariable c) {
this(c.getStartPC(), c.getLength(), c.getNameIndex(), c.getSignatureIndex(), c.getIndex(),
c.getConstantPool());
this.orig_index = c.getOrigIndex();
}
@ -82,6 +85,28 @@ public final class LocalVariable implements Cloneable, Node {
this.signature_index = signature_index;
this.index = index;
this.constant_pool = constant_pool;
this.orig_index = index;
}
/**
* @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
* @param orig_index Variable is `index'th local variable on the method's frame prior to any changes
*/
public LocalVariable(final int start_pc, final int length, final int name_index, final int signature_index, final int index,
final ConstantPool constant_pool, final int orig_index) {
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;
this.orig_index = orig_index;
}
@ -173,6 +198,14 @@ public final class LocalVariable implements Cloneable, Node {
}
/**
* @return index of register where variable was originally stored
*/
public final int getOrigIndex() {
return orig_index;
}
/**
* @return Start of range where he variable is valid
*/

View File

@ -31,7 +31,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class represents colection of local variables in a
* method. This attribute is contained in the <em>Code</em> attribute.
*
* @version $Id: LocalVariableTable.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Code
* @see LocalVariable
*/

View File

@ -23,9 +23,11 @@ package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.Const;
// The new table is used when generic types are about...
//LocalVariableTable_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
@ -37,6 +39,7 @@ import com.sun.org.apache.bcel.internal.Const;
// u2 index;
// } local_variable_table[local_variable_table_length];
// }
//LocalVariableTypeTable_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
@ -50,6 +53,7 @@ import com.sun.org.apache.bcel.internal.Const;
// } local_variable_type_table[local_variable_type_table_length];
// }
// J5TODO: Needs some testing !
/**
* @since 6.0
*/
@ -61,14 +65,12 @@ public class LocalVariableTypeTable extends Attribute {
this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), c.getConstantPool());
}
public LocalVariableTypeTable(final int name_index, final int length,
final LocalVariable[] local_variable_table, final ConstantPool constant_pool) {
public LocalVariableTypeTable(final int name_index, final int length, final LocalVariable[] local_variable_table, final ConstantPool constant_pool) {
super(Const.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
this.local_variable_type_table = local_variable_table;
}
LocalVariableTypeTable(final int nameIdx, final int len, final DataInput input,
final ConstantPool cpool) throws IOException {
LocalVariableTypeTable(final int nameIdx, final int len, final DataInput input, final ConstantPool cpool) throws IOException {
this(nameIdx, len, (LocalVariable[]) null, cpool);
final int local_variable_type_table_length = input.readUnsignedShort();

View File

@ -22,32 +22,34 @@ package com.sun.org.apache.bcel.internal.classfile;
import java.io.DataInput;
import java.io.IOException;
import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.generic.Type;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
/**
* 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.
* 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.
*
* @version $Id: Method.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public final class Method extends FieldOrMethod {
private static BCELComparator bcelComparator = new BCELComparator() {
@Override
public boolean equals(final Object o1, final Object o2) {
public boolean equals( final Object o1, final Object o2 ) {
final Method THIS = (Method) o1;
final Method THAT = (Method) o2;
return THIS.getName().equals(THAT.getName())
&& THIS.getSignature().equals(THAT.getSignature());
return Objects.equals(THIS.getName(), THAT.getName())
&& Objects.equals(THIS.getSignature(), THAT.getSignature());
}
@Override
public int hashCode(final Object o) {
public int hashCode( final Object o ) {
final Method THIS = (Method) o;
return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
}
@ -63,6 +65,7 @@ public final class Method extends FieldOrMethod {
public Method() {
}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
@ -71,9 +74,9 @@ public final class Method extends FieldOrMethod {
super(c);
}
/**
* Construct object from file stream.
*
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
@ -83,6 +86,7 @@ public final class Method extends FieldOrMethod {
super(file, constant_pool);
}
/**
* @param access_flags Access rights of method
* @param name_index Points to field name in constant pool
@ -95,6 +99,7 @@ public final class Method extends FieldOrMethod {
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,
@ -103,10 +108,11 @@ public final class Method extends FieldOrMethod {
* @param v Visitor object
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitMethod(this);
}
/**
* @return Code attribute of method, if any
*/
@ -119,6 +125,7 @@ public final class Method extends FieldOrMethod {
return null;
}
/**
* @return ExceptionTable attribute of method, if any, i.e., list all
* exceptions the method may throw not exception handlers!
@ -132,9 +139,9 @@ public final class Method extends FieldOrMethod {
return null;
}
/**
* @return LocalVariableTable of code attribute if any, i.e. the call is
* forwarded to the Code atribute.
/** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded
* to the Code atribute.
*/
public final LocalVariableTable getLocalVariableTable() {
final Code code = getCode();
@ -144,9 +151,9 @@ public final class Method extends FieldOrMethod {
return code.getLocalVariableTable();
}
/**
* @return LineNumberTable of code attribute if any, i.e. the call is
* forwarded to the Code atribute.
/** @return LineNumberTable of code attribute if any, i.e. the call is forwarded
* to the Code atribute.
*/
public final LineNumberTable getLineNumberTable() {
final Code code = getCode();
@ -156,9 +163,10 @@ public final class Method extends FieldOrMethod {
return code.getLineNumberTable();
}
/**
* Return string representation close to declaration format, e.g.
* 'public static void main(String[] args) throws IOException'
* Return string representation close to declaration format,
* `public static void main(String[] args) throws IOException', e.g.
*
* @return String representation of the method.
*/
@ -188,13 +196,15 @@ public final class Method extends FieldOrMethod {
return buf.toString();
}
/**
* @return deep copy of this method
*/
public final Method copy(final ConstantPool _constant_pool) {
public final Method copy( final ConstantPool _constant_pool ) {
return (Method) copy_(_constant_pool);
}
/**
* @return return type of method
*/
@ -202,6 +212,7 @@ public final class Method extends FieldOrMethod {
return Type.getReturnType(getSignature());
}
/**
* @return array of method argument types
*/
@ -209,6 +220,7 @@ public final class Method extends FieldOrMethod {
return Type.getArgumentTypes(getSignature());
}
/**
* @return Comparison strategy object
*/
@ -216,28 +228,31 @@ public final class Method extends FieldOrMethod {
return bcelComparator;
}
/**
* @param comparator Comparison strategy object
*/
public static void setComparator(final BCELComparator comparator) {
public static void setComparator( final BCELComparator comparator ) {
bcelComparator = comparator;
}
/**
* Return value as defined by given BCELComparator strategy. By default two
* method objects are said to be equal when their names and signatures are
* equal.
* Return value as defined by given BCELComparator strategy.
* By default two method objects are said to be equal when
* their names and signatures are equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {
public boolean equals( final Object obj ) {
return bcelComparator.equals(this, obj);
}
/**
* Return value as defined by given BCELComparator strategy. By default
* return the hashcode of the method's name XOR signature.
* Return value as defined by given BCELComparator strategy.
* By default return the hashcode of the method's name XOR signature.
*
* @see java.lang.Object#hashCode()
*/

View File

@ -24,7 +24,7 @@ package com.sun.org.apache.bcel.internal.classfile;
/**
* Denote class to have an accept method();
*
* @version $Id: Node.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public interface Node {

View File

@ -31,7 +31,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from <em>Attribute</em> and represents a reference
* to a PMG attribute.
*
* @version $Id: PMGClass.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class PMGClass extends Attribute {

View File

@ -32,7 +32,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class is derived from <em>Attribute</em> and represents a reference
* to a GJ attribute.
*
* @version $Id: Signature.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class Signature extends Attribute {

View File

@ -33,7 +33,7 @@ import com.sun.org.apache.bcel.internal.Const;
* should appear per classfile. The intention of this class is that it is
* instantiated from the <em>Attribute.readAttribute()</em> method.
*
* @version $Id: SourceFile.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class SourceFile extends Attribute {

View File

@ -36,7 +36,7 @@ import com.sun.org.apache.bcel.internal.Const;
* within the Code attribute of a method. See CLDC specification
* 5.3.1.2
*
* @version $Id: StackMap.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Code
* @see StackMapEntry
* @see StackMapType
@ -78,7 +78,7 @@ public final class StackMap extends Attribute {
/**
* Dump line number table attribute to file stream in binary format.
* Dump stack map table attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException

View File

@ -31,7 +31,7 @@ import com.sun.org.apache.bcel.internal.Const;
* local variables and the the of stack items at a given byte code offset.
* See CLDC specification 5.3.1.2
*
* @version $Id: StackMapEntry.java 1750029 2016-06-23 22:14:38Z sebb $
* @version $Id$
* @see StackMap
* @see StackMapType
*/
@ -51,8 +51,8 @@ public final class StackMapEntry implements Node, Cloneable
* @param input Input stream
* @throws IOException
*/
StackMapEntry(final DataInput input, final ConstantPool constant_pool) throws IOException {
this(input.readByte() & 0xFF, -1, null, null, constant_pool);
StackMapEntry(final DataInput input, final ConstantPool constantPool) throws IOException {
this(input.readByte() & 0xFF, -1, null, null, constantPool);
if (frame_type >= Const.SAME_FRAME && frame_type <= Const.SAME_FRAME_MAX) {
byte_code_offset = frame_type - Const.SAME_FRAME;
@ -60,11 +60,11 @@ public final class StackMapEntry implements Node, Cloneable
frame_type <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
byte_code_offset = frame_type - Const.SAME_LOCALS_1_STACK_ITEM_FRAME;
types_of_stack_items = new StackMapType[1];
types_of_stack_items[0] = new StackMapType(input, constant_pool);
types_of_stack_items[0] = new StackMapType(input, constantPool);
} else if (frame_type == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
byte_code_offset = input.readShort();
types_of_stack_items = new StackMapType[1];
types_of_stack_items[0] = new StackMapType(input, constant_pool);
types_of_stack_items[0] = new StackMapType(input, constantPool);
} else if (frame_type >= Const.CHOP_FRAME && frame_type <= Const.CHOP_FRAME_MAX) {
byte_code_offset = input.readShort();
} else if (frame_type == Const.SAME_FRAME_EXTENDED) {
@ -74,19 +74,19 @@ public final class StackMapEntry implements Node, Cloneable
final int number_of_locals = frame_type - 251;
types_of_locals = new StackMapType[number_of_locals];
for (int i = 0; i < number_of_locals; i++) {
types_of_locals[i] = new StackMapType(input, constant_pool);
types_of_locals[i] = new StackMapType(input, constantPool);
}
} else if (frame_type == Const.FULL_FRAME) {
byte_code_offset = input.readShort();
final int number_of_locals = input.readShort();
types_of_locals = new StackMapType[number_of_locals];
for (int i = 0; i < number_of_locals; i++) {
types_of_locals[i] = new StackMapType(input, constant_pool);
types_of_locals[i] = new StackMapType(input, constantPool);
}
final int number_of_stack_items = input.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(input, constant_pool);
types_of_stack_items[i] = new StackMapType(input, constantPool);
}
} else {
/* Can't happen */
@ -97,42 +97,42 @@ public final class StackMapEntry implements Node, Cloneable
/**
* DO NOT USE
*
* @param byte_code_offset
* @param number_of_locals NOT USED
* @param types_of_locals array of {@link StackMapType}s of locals
* @param number_of_stack_items NOT USED
* @param types_of_stack_items array ot {@link StackMapType}s of stack items
* @param constant_pool the constant pool
* @param byteCodeOffset
* @param numberOfLocals NOT USED
* @param typesOfLocals array of {@link StackMapType}s of locals
* @param numberOfStackItems NOT USED
* @param typesOfStackItems array ot {@link StackMapType}s of stack items
* @param constantPool the constant pool
* @deprecated Since 6.0, use {@link #StackMapEntry(int, int, StackMapType[], StackMapType[], ConstantPool)}
* instead
*/
@java.lang.Deprecated
public StackMapEntry(final int byte_code_offset, final int number_of_locals,
final StackMapType[] types_of_locals, final int number_of_stack_items,
final StackMapType[] types_of_stack_items, final ConstantPool constant_pool) {
this.byte_code_offset = byte_code_offset;
this.types_of_locals = types_of_locals != null ? types_of_locals : new StackMapType[0];
this.types_of_stack_items = types_of_stack_items != null ? types_of_stack_items : new StackMapType[0];
this.constant_pool = constant_pool;
public StackMapEntry(final int byteCodeOffset, final int numberOfLocals,
final StackMapType[] typesOfLocals, final int numberOfStackItems,
final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
this.byte_code_offset = byteCodeOffset;
this.types_of_locals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
this.types_of_stack_items = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
this.constant_pool = constantPool;
}
/**
* Create an instance
*
* @param tag the frame_type to use
* @param byte_code_offset
* @param types_of_locals array of {@link StackMapType}s of locals
* @param types_of_stack_items array ot {@link StackMapType}s of stack items
* @param constant_pool the constant pool
* @param byteCodeOffset
* @param typesOfLocals array of {@link StackMapType}s of locals
* @param typesOfStackItems array ot {@link StackMapType}s of stack items
* @param constantPool the constant pool
*/
public StackMapEntry(final int tag, final int byte_code_offset,
final StackMapType[] types_of_locals,
final StackMapType[] types_of_stack_items, final ConstantPool constant_pool) {
public StackMapEntry(final int tag, final int byteCodeOffset,
final StackMapType[] typesOfLocals,
final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
this.frame_type = tag;
this.byte_code_offset = byte_code_offset;
this.types_of_locals = types_of_locals != null ? types_of_locals : new StackMapType[0];
this.types_of_stack_items = types_of_stack_items != null ? types_of_stack_items : new StackMapType[0];
this.constant_pool = constant_pool;
this.byte_code_offset = byteCodeOffset;
this.types_of_locals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
this.types_of_stack_items = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
this.constant_pool = constantPool;
}

View File

@ -31,7 +31,7 @@ import com.sun.org.apache.bcel.internal.Const;
* This class represents the type of a local variable or item on stack
* used in the StackMap entries.
*
* @version $Id: StackMapType.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see StackMapEntry
* @see StackMap
* @see Const

View File

@ -36,7 +36,7 @@ import com.sun.org.apache.bcel.internal.Const;
* is intended to be instantiated from the
* <em>Attribute.readAttribute()</em> method.
*
* @version $Id: Synthetic.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
*/
public final class Synthetic extends Attribute {

View File

@ -38,7 +38,7 @@ import com.sun.org.apache.bcel.internal.Const;
* {@link Attribute#addAttributeReader(String, UnknownAttributeReader)}.
*
* @version $Id: Unknown.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Attribute
* @see UnknownAttributeReader
*/

View File

@ -27,7 +27,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* method. These factory objects should implement this interface.
*
* @see Attribute
* @version $Id: UnknownAttributeReader.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @since 6.0
*/
public interface UnknownAttributeReader {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -42,32 +42,32 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Utility functions that do not really belong to any class in particular.
*
* @version $Id: Utility.java 1751107 2016-07-03 02:41:18Z dbrosius $
* @LastModified: Oct 2017
* @version $Id$
* @LastModified: Jun 2019
*/
// @since 6.0 methods are no longer final
public abstract class Utility {
private static int unwrap(final ThreadLocal<Integer> tl) {
return tl.get().intValue();
private static int unwrap( final ThreadLocal<Integer> tl ) {
return tl.get();
}
private static void wrap(final ThreadLocal<Integer> tl, final int value) {
tl.set(Integer.valueOf(value));
private static void wrap( final ThreadLocal<Integer> tl, final int value ) {
tl.set(value);
}
private static ThreadLocal<Integer> consumed_chars = new ThreadLocal<Integer>() {
@Override
protected Integer initialValue() {
return Integer.valueOf(0);
return 0;
}
};/* How many chars have been consumed
* during parsing in signatureToString().
* Read by methodSignatureToString().
* Set by side effect,but only internally.
*/
private static boolean wide = false; /* The `WIDE' instruction is used in the
* byte code to allow 16-bit wide indices
* for local variables. This opcode
@ -82,25 +82,27 @@ public abstract class Utility {
/**
* Convert bit field of flags into string such as `static final'.
*
* @param access_flags Access flags
* @param access_flags Access flags
* @return String representation of flags
*/
public static String accessToString(final int access_flags) {
public static String accessToString( final int access_flags ) {
return accessToString(access_flags, false);
}
/**
* Convert bit field of flags into string such as `static final'.
*
* Special case: Classes compiled with new compilers and with the
* `ACC_SUPER' flag would be said to be "synchronized". This is because SUN
* used the same value for the flags `ACC_SUPER' and `ACC_SYNCHRONIZED'.
* `ACC_SUPER' flag would be said to be "synchronized". This is
* because SUN used the same value for the flags `ACC_SUPER' and
* `ACC_SYNCHRONIZED'.
*
* @param access_flags Access flags
* @param for_class access flags are for class qualifiers ?
* @param access_flags Access flags
* @param for_class access flags are for class qualifiers ?
* @return String representation of flags
*/
public static String accessToString(final int access_flags, final boolean for_class) {
public static String accessToString( final int access_flags, final boolean for_class ) {
final StringBuilder buf = new StringBuilder();
int p = 0;
for (int i = 0; p < Const.MAX_ACC_FLAG; i++) { // Loop through known flags
@ -120,33 +122,34 @@ public abstract class Utility {
return buf.toString().trim();
}
/**
* @param access_flags the class flags
*
* @return "class" or "interface", depending on the ACC_INTERFACE flag
*/
public static String classOrInterface(final int access_flags) {
public static String classOrInterface( final int access_flags ) {
return ((access_flags & Const.ACC_INTERFACE) != 0) ? "interface" : "class";
}
/**
* Disassemble a byte array of JVM byte codes starting from code line
* `index' and return the disassembled string representation. Decode only
* `num' opcodes (including their operands), use -1 if you want to decompile
* everything.
* `num' opcodes (including their operands), use -1 if you want to
* decompile everything.
*
* @param code byte code array
* @param constant_pool Array of constants
* @param index offset in `code' array
* @param code byte code array
* @param constant_pool Array of constants
* @param index offset in `code' array
* <EM>(number of opcodes, not bytes!)</EM>
* @param length number of opcodes to decompile, -1 for all
* @param verbose be verbose, e.g. print constant pool index
* @param length number of opcodes to decompile, -1 for all
* @param verbose be verbose, e.g. print constant pool index
* @return String representation of byte codes
*/
public static String codeToString(final byte[] code, final ConstantPool constant_pool,
final int index, final int length, final boolean verbose) {
// Should be sufficient // CHECKSTYLE IGNORE MagicNumber
final StringBuilder buf = new StringBuilder(code.length * 20);
public static String codeToString( final byte[] code, final ConstantPool constant_pool, final int index,
final int length, final boolean verbose ) {
final StringBuilder buf = new StringBuilder(code.length * 20); // Should be sufficient // CHECKSTYLE IGNORE MagicNumber
try (ByteSequence stream = new ByteSequence(code)) {
for (int i = 0; i < index; i++) {
codeToString(stream, constant_pool, verbose);
@ -154,9 +157,7 @@ public abstract class Utility {
for (int i = 0; stream.available() > 0; i++) {
if ((length < 0) || (i < length)) {
final String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
buf.append(indices)
.append(codeToString(stream, constant_pool, verbose))
.append('\n');
buf.append(indices).append(codeToString(stream, constant_pool, verbose)).append('\n');
}
}
} catch (final IOException e) {
@ -165,21 +166,22 @@ public abstract class Utility {
return buf.toString();
}
public static String codeToString(final byte[] code, final ConstantPool constant_pool,
final int index, final int length) {
public static String codeToString( final byte[] code, final ConstantPool constant_pool, final int index, final int length ) {
return codeToString(code, constant_pool, index, length, true);
}
/**
* Disassemble a stream of byte codes and return the string representation.
* Disassemble a stream of byte codes and return the
* string representation.
*
* @param bytes stream of bytes
* @param constant_pool Array of constants
* @param verbose be verbose, e.g. print constant pool index
* @param bytes stream of bytes
* @param constant_pool Array of constants
* @param verbose be verbose, e.g. print constant pool index
* @return String representation of byte code
*
* @throws IOException if a failure from reading from the bytes argument
* occurs
* @throws IOException if a failure from reading from the bytes argument occurs
*/
@SuppressWarnings("fallthrough") // by design for case Const.INSTANCEOF
public static String codeToString(final ByteSequence bytes, final ConstantPool constant_pool,
@ -253,7 +255,7 @@ public abstract class Utility {
}
buf.append(")");
}
break;
break;
/* Two address bytes + offset from start of byte stream form the
* jump target
*/
@ -327,14 +329,14 @@ public abstract class Utility {
index = bytes.readUnsignedShort();
buf.append("\t\t").append(
constant_pool.constantToString(index, Const.CONSTANT_Fieldref)).append(
verbose ? " (" + index + ")" : "");
verbose ? " (" + index + ")" : "");
break;
/* Operands are references to classes in constant pool
*/
case Const.NEW:
case Const.CHECKCAST:
buf.append("\t");
//$FALL-THROUGH$
//$FALL-THROUGH$
case Const.INSTANCEOF:
index = bytes.readUnsignedShort();
buf.append("\t<").append(
@ -364,7 +366,7 @@ public abstract class Utility {
final int nargs = bytes.readUnsignedByte(); // historical, redundant
buf.append("\t").append(
constant_pool
.constantToString(index, Const.CONSTANT_InterfaceMethodref))
.constantToString(index, Const.CONSTANT_InterfaceMethodref))
.append(verbose ? " (" + index + ")\t" : "").append(nargs).append("\t")
.append(bytes.readUnsignedByte()); // Last byte is a reserved space
break;
@ -372,9 +374,9 @@ public abstract class Utility {
index = bytes.readUnsignedShort();
buf.append("\t").append(
constant_pool
.constantToString(index, Const.CONSTANT_InvokeDynamic))
.constantToString(index, Const.CONSTANT_InvokeDynamic))
.append(verbose ? " (" + index + ")\t" : "")
.append(bytes.readUnsignedByte()) // Thrid byte is a reserved space
.append(bytes.readUnsignedByte()) // Thrid byte is a reserved space
.append(bytes.readUnsignedByte()); // Last byte is a reserved space
break;
/* Operands are references to items in constant pool
@ -398,8 +400,8 @@ public abstract class Utility {
index = bytes.readUnsignedShort();
buf.append("\t\t<").append(
compactClassName(constant_pool.getConstantString(index,
Const.CONSTANT_Class), false)).append(">").append(
verbose ? " (" + index + ")" : "");
Const.CONSTANT_Class), false)).append(">").append(
verbose ? " (" + index + ")" : "");
break;
/* Multidimensional array of references.
*/
@ -408,10 +410,10 @@ public abstract class Utility {
final int dimensions = bytes.readUnsignedByte();
buf.append("\t<").append(
compactClassName(constant_pool.getConstantString(index,
Const.CONSTANT_Class), false)).append(">\t").append(dimensions)
Const.CONSTANT_Class), false)).append(">\t").append(dimensions)
.append(verbose ? " (" + index + ")" : "");
}
break;
break;
/* Increment local variable.
*/
case Const.IINC:
@ -448,11 +450,13 @@ public abstract class Utility {
return buf.toString();
}
public static String codeToString(final ByteSequence bytes, final ConstantPool constant_pool)
public static String codeToString( final ByteSequence bytes, final ConstantPool constant_pool )
throws IOException {
return codeToString(bytes, constant_pool, true);
}
/**
* Shorten long class names, <em>java/lang/String</em> becomes
* <em>String</em>.
@ -460,21 +464,23 @@ public abstract class Utility {
* @param str The long class name
* @return Compacted class name
*/
public static String compactClassName(final String str) {
public static String compactClassName( final String str ) {
return compactClassName(str, true);
}
/**
* Shorten long class name <em>str</em>, i.e., chop off the <em>prefix</em>,
* if the class name starts with this string and the flag <em>chopit</em> is
* true. Slashes <em>/</em> are converted to dots <em>.</em>.
* if the
* class name starts with this string and the flag <em>chopit</em> is true.
* Slashes <em>/</em> are converted to dots <em>.</em>.
*
* @param str The long class name
* @param prefix The prefix the get rid off
* @param chopit Flag that determines whether chopping is executed or not
* @return Compacted class name
*/
public static String compactClassName(String str, final String prefix, final boolean chopit) {
public static String compactClassName( String str, final String prefix, final boolean chopit ) {
final int len = prefix.length();
str = str.replace('/', '.'); // Is `/' on all systems, even DOS
if (chopit) {
@ -486,53 +492,58 @@ public abstract class Utility {
return str;
}
/**
* Shorten long class names, <em>java/lang/String</em> becomes
* <em>java.lang.String</em>, e.g.. If <em>chopit</em> is <em>true</em> the
* prefix <em>java.lang</em>
* <em>java.lang.String</em>,
* e.g.. If <em>chopit</em> is <em>true</em> the prefix <em>java.lang</em>
* is also removed.
*
* @param str The long class name
* @param chopit Flag that determines whether chopping is executed or not
* @return Compacted class name
*/
public static String compactClassName(final String str, final boolean chopit) {
public static String compactClassName( final String str, final boolean chopit ) {
return compactClassName(str, "java.lang.", chopit);
}
/**
* @return `flag' with bit `i' set to 1
*/
public static int setBit(final int flag, final int i) {
public static int setBit( final int flag, final int i ) {
return flag | pow2(i);
}
/**
* @return `flag' with bit `i' set to 0
*/
public static int clearBit(final int flag, final int i) {
public static int clearBit( final int flag, final int i ) {
final int bit = pow2(i);
return (flag & bit) == 0 ? flag : flag ^ bit;
}
/**
* @return true, if bit `i' in `flag' is set
*/
public static boolean isSet(final int flag, final int i) {
public static boolean isSet( final int flag, final int i ) {
return (flag & pow2(i)) != 0;
}
/**
* Converts string containing the method return and argument types to a byte
* code method signature.
* Converts string containing the method return and argument types
* to a byte code method signature.
*
* @param ret Return type of method
* @param argv Types of method arguments
* @param ret Return type of method
* @param argv Types of method arguments
* @return Byte code representation of method signature
*
* @throws ClassFormatException if the signature is for Void
*/
public static String methodTypeToSignature(final String ret, final String[] argv)
public static String methodTypeToSignature( final String ret, final String[] argv )
throws ClassFormatException {
final StringBuilder buf = new StringBuilder("(");
String str;
@ -550,23 +561,25 @@ public abstract class Utility {
return buf.toString();
}
/**
* @param signature Method signature
* @param signature Method signature
* @return Array of argument types
* @throws ClassFormatException
* @throws ClassFormatException
*/
public static String[] methodSignatureArgumentTypes(final String signature)
public static String[] methodSignatureArgumentTypes( final String signature )
throws ClassFormatException {
return methodSignatureArgumentTypes(signature, true);
}
/**
* @param signature Method signature
* @param signature Method signature
* @param chopit Shorten class names ?
* @return Array of argument types
* @throws ClassFormatException
* @throws ClassFormatException
*/
public static String[] methodSignatureArgumentTypes(final String signature, final boolean chopit)
public static String[] methodSignatureArgumentTypes( final String signature, final boolean chopit )
throws ClassFormatException {
final List<String> vec = new ArrayList<>();
int index;
@ -586,24 +599,24 @@ public abstract class Utility {
return vec.toArray(new String[vec.size()]);
}
/**
* @param signature Method signature
* @param signature Method signature
* @return return type of method
* @throws ClassFormatException
* @throws ClassFormatException
*/
public static String methodSignatureReturnType(final String signature)
throws ClassFormatException {
public static String methodSignatureReturnType( final String signature ) throws ClassFormatException {
return methodSignatureReturnType(signature, true);
}
/**
* @param signature Method signature
* @param signature Method signature
* @param chopit Shorten class names ?
* @return return type of method
* @throws ClassFormatException
* @throws ClassFormatException
*/
public static String methodSignatureReturnType(final String signature,
final boolean chopit) throws ClassFormatException {
public static String methodSignatureReturnType( final String signature, final boolean chopit ) throws ClassFormatException {
int index;
String type;
try {
@ -616,6 +629,7 @@ public abstract class Utility {
return type;
}
/**
* Converts method signature to string with all class names compacted.
*
@ -624,27 +638,27 @@ public abstract class Utility {
* @param access flags of method
* @return Human readable signature
*/
public static String methodSignatureToString(final String signature,
final String name, final String access) {
public static String methodSignatureToString( final String signature, final String name, final String access ) {
return methodSignatureToString(signature, name, access, true);
}
public static String methodSignatureToString(final String signature,
final String name, final String access, final boolean chopit) {
public static String methodSignatureToString( final String signature, final String name, final String access, final boolean chopit ) {
return methodSignatureToString(signature, name, access, chopit, null);
}
/**
* A returntype signature represents the return value from a method. It is a
* series of bytes in the following grammar:
* A returntype signature represents the return value from a method.
* It is a series of bytes in the following grammar:
*
* <pre>
* &lt;return_signature&gt; ::= &lt;field_type&gt; | V
* </pre>
*
* The character V indicates that the method returns no value. Otherwise,
* the signature indicates the type of the return value. An argument
* signature represents an argument passed to a method:
* The character V indicates that the method returns no value. Otherwise, the
* signature indicates the type of the return value.
* An argument signature represents an argument passed to a method:
*
* <pre>
* &lt;argument_signature&gt; ::= &lt;field_type&gt;
@ -661,17 +675,16 @@ public abstract class Utility {
* `void main(String[])' and throws a `ClassFormatException' when the parsed
* type is invalid.
*
* @param signature Method signature
* @param name Method name
* @param access Method access rights
* @param signature Method signature
* @param name Method name
* @param access Method access rights
* @param chopit
* @param vars
* @return Java type declaration
* @throws ClassFormatException
* @throws ClassFormatException
*/
public static String methodSignatureToString(final String signature, final String name,
final String access, final boolean chopit, final LocalVariableTable vars)
throws ClassFormatException {
public static String methodSignatureToString( final String signature, final String name,
final String access, final boolean chopit, final LocalVariableTable vars ) throws ClassFormatException {
final StringBuilder buf = new StringBuilder("(");
String type;
int index;
@ -715,21 +728,22 @@ public abstract class Utility {
type + " " + name + buf.toString();
}
// Guess what this does
private static int pow2(final int n) {
private static int pow2( final int n ) {
return 1 << n;
}
/**
* Replace all occurrences of <em>old</em> in <em>str</em> with
* <em>new</em>.
* Replace all occurrences of <em>old</em> in <em>str</em> with <em>new</em>.
*
* @param str String to permute
* @param old String to be replaced
* @param new_ Replacement string
* @return new String object
*/
public static String replace(String str, final String old, final String new_) {
public static String replace( String str, final String old, final String new_ ) {
int index;
int old_index;
try {
@ -751,16 +765,18 @@ public abstract class Utility {
return str;
}
/**
* Converts signature to string with all class names compacted.
*
* @param signature to convert
* @return Human readable signature
*/
public static String signatureToString(final String signature) {
public static String signatureToString( final String signature ) {
return signatureToString(signature, true);
}
/**
* The field signature represents the value of an argument to a function or
* the value of a variable. It is a series of bytes generated by the
@ -790,12 +806,12 @@ public abstract class Utility {
* `String[]' and throws a `ClassFormatException' when the parsed type is
* invalid.
*
* @param signature Class signature
* @param signature Class signature
* @param chopit Flag that determines whether chopping is executed or not
* @return Java type declaration
* @throws ClassFormatException
*/
public static String signatureToString(final String signature, final boolean chopit) {
public static String signatureToString( final String signature, final boolean chopit ) {
//corrected concurrent private static field acess
wrap(consumed_chars, 1); // This is the default, read just one char like `B'
try {
@ -837,6 +853,7 @@ public abstract class Utility {
if (index < 0) {
throw new ClassFormatException("Invalid signature: " + signature);
}
// check to see if there are any TypeArguments
final int bracketIndex = signature.substring(0, index).indexOf('<');
if (bracketIndex < 0) {
@ -844,12 +861,20 @@ public abstract class Utility {
wrap(consumed_chars, index + 1); // "Lblabla;" `L' and `;' are removed
return compactClassName(signature.substring(1, index), chopit);
}
// but make sure we are not looking past the end of the current item
fromIndex = signature.indexOf(';');
if (fromIndex < 0) {
throw new ClassFormatException("Invalid signature: " + signature);
}
if (fromIndex < bracketIndex) {
// just a class identifier
wrap(consumed_chars, fromIndex + 1); // "Lblabla;" `L' and `;' are removed
return compactClassName(signature.substring(1, fromIndex), chopit);
}
// we have TypeArguments; build up partial result
// as we recurse for each TypeArgument
final StringBuilder type = new StringBuilder(
compactClassName(signature.substring(1, bracketIndex), chopit))
.append("<");
final StringBuilder type = new StringBuilder(compactClassName(signature.substring(1, bracketIndex), chopit)).append("<");
int consumed_chars = bracketIndex + 1; // Shadows global var
// check for wildcards
@ -859,37 +884,63 @@ public abstract class Utility {
} else if (signature.charAt(consumed_chars) == '-') {
type.append("? super ");
consumed_chars++;
} else if (signature.charAt(consumed_chars) == '*') {
// must be at end of signature
if (signature.charAt(consumed_chars + 1) != '>') {
throw new ClassFormatException("Invalid signature: " + signature);
}
if (signature.charAt(consumed_chars + 2) != ';') {
throw new ClassFormatException("Invalid signature: " + signature);
}
wrap(Utility.consumed_chars, consumed_chars + 3); // remove final "*>;"
return type + "?>...";
}
// get the first TypeArgument
type.append(signatureToString(signature.substring(consumed_chars), chopit));
// update our consumed count by the number of characters the for type argument
consumed_chars = unwrap(Utility.consumed_chars) + consumed_chars;
wrap(Utility.consumed_chars, consumed_chars);
// are there more TypeArguments?
while (signature.charAt(consumed_chars) != '>') {
type.append(", ").append(signatureToString(signature.substring(consumed_chars), chopit));
if (signature.charAt(consumed_chars) == '*') {
type.append("?");
consumed_chars++;
} else {
type.append(signatureToString(signature.substring(consumed_chars), chopit));
// update our consumed count by the number of characters the for type argument
consumed_chars = unwrap(Utility.consumed_chars) + consumed_chars;
wrap(Utility.consumed_chars, consumed_chars);
}
if (signature.charAt(consumed_chars + 1) != ';') {
// are there more TypeArguments?
while (signature.charAt(consumed_chars) != '>') {
type.append(", ");
// check for wildcards
if (signature.charAt(consumed_chars) == '+') {
type.append("? extends ");
consumed_chars++;
} else if (signature.charAt(consumed_chars) == '-') {
type.append("? super ");
consumed_chars++;
}
if (signature.charAt(consumed_chars) == '*') {
type.append("?");
consumed_chars++;
} else {
type.append(signatureToString(signature.substring(consumed_chars), chopit));
// update our consumed count by the number of characters the for type argument
consumed_chars = unwrap(Utility.consumed_chars) + consumed_chars;
wrap(Utility.consumed_chars, consumed_chars);
}
}
// process the closing ">"
consumed_chars++;
type.append(">");
if (signature.charAt(consumed_chars) == '.') {
// we have a ClassTypeSignatureSuffix
type.append(".");
// convert SimpleClassTypeSignature to fake ClassTypeSignature
// and then recurse to parse it
type.append(signatureToString("L" + signature.substring(consumed_chars+1), chopit));
// update our consumed count by the number of characters the for type argument
// note that this count includes the "L" we added, but that is ok
// as it accounts for the "." we didn't consume
consumed_chars = unwrap(Utility.consumed_chars) + consumed_chars;
wrap(Utility.consumed_chars, consumed_chars);
return type.toString();
}
if (signature.charAt(consumed_chars) != ';') {
throw new ClassFormatException("Invalid signature: " + signature);
}
wrap(Utility.consumed_chars, consumed_chars + 2); // remove final ">;"
return type.append(">").toString();
wrap(Utility.consumed_chars, consumed_chars + 1); // remove final ";"
return type.toString();
}
case 'S':
return "short";
@ -924,22 +975,20 @@ public abstract class Utility {
}
}
/**
* Parse Java type such as "char", or "java.lang.String[]" and return the
* signature in byte code format, e.g. "C" or "[Ljava/lang/String;"
* respectively.
/** Parse Java type such as "char", or "java.lang.String[]" and return the
* signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
*
* @param type Java type
* @param type Java type
* @return byte code signature
*/
public static String getSignature(String type) {
public static String getSignature( String type ) {
final StringBuilder buf = new StringBuilder();
final char[] chars = type.toCharArray();
boolean char_found = false;
boolean delim = false;
int index = -1;
loop:
for (int i = 0; i < chars.length; i++) {
loop: for (int i = 0; i < chars.length; i++) {
switch (chars[i]) {
case ' ':
case '\t':
@ -985,7 +1034,8 @@ public abstract class Utility {
return buf.toString();
}
private static int countBrackets(final String brackets) {
private static int countBrackets( final String brackets ) {
final char[] chars = brackets.toCharArray();
int count = 0;
boolean open = false;
@ -1015,17 +1065,17 @@ public abstract class Utility {
return count;
}
/**
* Return type of method signature as a byte value as defined in
* <em>Constants</em>
* Return type of method signature as a byte value as defined in <em>Constants</em>
*
* @param signature in format described above
* @param signature in format described above
* @return type of method signature
* @see Const
* @see Const
*
* @throws ClassFormatException if signature is not a method signature
*/
public static byte typeOfMethodSignature(final String signature) throws ClassFormatException {
public static byte typeOfMethodSignature( final String signature ) throws ClassFormatException {
int index;
try {
if (signature.charAt(0) != '(') {
@ -1038,16 +1088,17 @@ public abstract class Utility {
}
}
/**
* Return type of signature as a byte value as defined in <em>Constants</em>
*
* @param signature in format described above
* @param signature in format described above
* @return type of signature
* @see Const
* @see Const
*
* @throws ClassFormatException if signature isn't a known type
*/
public static byte typeOfSignature(final String signature) throws ClassFormatException {
public static byte typeOfSignature( final String signature ) throws ClassFormatException {
try {
switch (signature.charAt(0)) {
case 'B':
@ -1085,11 +1136,10 @@ public abstract class Utility {
}
}
/**
* Map opcode names to opcode numbers. E.g., return Constants.ALOAD for
* "aload"
/** Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload"
*/
public static short searchOpcode(String name) {
public static short searchOpcode( String name ) {
name = name.toLowerCase(Locale.ENGLISH);
for (short i = 0; i < Const.OPCODE_NAMES_LENGTH; i++) {
if (Const.getOpcodeName(i).equals(name)) {
@ -1099,22 +1149,23 @@ public abstract class Utility {
return -1;
}
/**
* Convert (signed) byte to (unsigned) short value, i.e., all negative
* values become positive.
*/
private static short byteToShort(final byte b) {
private static short byteToShort( final byte b ) {
return (b < 0) ? (short) (256 + b) : (short) b;
}
/**
* Convert bytes into hexadecimal string
/** Convert bytes into hexadecimal string
*
* @param bytes an array of bytes to convert to hexadecimal
*
* @return bytes as hexadecimal string, e.g. 00 fa 12 ...
*/
public static String toHexString(final byte[] bytes) {
public static String toHexString( final byte[] bytes ) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
final short b = byteToShort(bytes[i]);
@ -1130,6 +1181,7 @@ public abstract class Utility {
return buf.toString();
}
/**
* Return a string for an integer justified left or right and filled up with
* `fill' characters if necessary.
@ -1140,14 +1192,13 @@ public abstract class Utility {
* @param fill fill character
* @return formatted int
*/
public static String format(final int i, final int length,
final boolean left_justify, final char fill) {
public static String format( final int i, final int length, final boolean left_justify, final char fill ) {
return fillup(Integer.toString(i), length, left_justify, fill);
}
/**
* Fillup char with up to length characters with char `fill' and justify it
* left or right.
* Fillup char with up to length characters with char `fill' and justify it left or right.
*
* @param str string to format
* @param length length of desired string
@ -1155,8 +1206,7 @@ public abstract class Utility {
* @param fill fill character
* @return formatted string
*/
public static String fillup(final String str, final int length,
final boolean left_justify, final char fill) {
public static String fillup( final String str, final int length, final boolean left_justify, final char fill ) {
final int len = length - str.length();
final char[] buf = new char[(len < 0) ? 0 : len];
for (int j = 0; j < buf.length; j++) {
@ -1168,7 +1218,8 @@ public abstract class Utility {
return new String(buf) + str;
}
static boolean equals(final byte[] a, final byte[] b) {
static boolean equals( final byte[] a, final byte[] b ) {
int size;
if ((size = a.length) != b.length) {
return false;
@ -1181,23 +1232,28 @@ public abstract class Utility {
return true;
}
public static void printArray(final PrintStream out, final Object[] obj) {
public static void printArray( final PrintStream out, final Object[] obj ) {
out.println(printArray(obj, true));
}
public static void printArray(final PrintWriter out, final Object[] obj) {
public static void printArray( final PrintWriter out, final Object[] obj ) {
out.println(printArray(obj, true));
}
public static String printArray(final Object[] obj) {
public static String printArray( final Object[] obj ) {
return printArray(obj, true);
}
public static String printArray(final Object[] obj, final boolean braces) {
public static String printArray( final Object[] obj, final boolean braces ) {
return printArray(obj, braces, false);
}
public static String printArray(final Object[] obj, final boolean braces, final boolean quote) {
public static String printArray( final Object[] obj, final boolean braces, final boolean quote ) {
if (obj == null) {
return null;
}
@ -1221,32 +1277,32 @@ public abstract class Utility {
return buf.toString();
}
/**
* @param ch the character to test if it's part of an identifier
*
* @return true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _)
*/
public static boolean isJavaIdentifierPart(final char ch) {
public static boolean isJavaIdentifierPart( final char ch ) {
return ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))
|| ((ch >= '0') && (ch <= '9')) || (ch == '_');
}
/**
* Encode byte array it into Java identifier string, i.e., a string that
* only contains the following characters: (a, ... z, A, ... Z, 0, ... 9, _,
* $). The encoding algorithm itself is not too clever: if the current
* byte's ASCII value already is a valid Java identifier part, leave it as
* it is. Otherwise it writes the escape character($) followed by:
* Encode byte array it into Java identifier string, i.e., a string
* that only contains the following characters: (a, ... z, A, ... Z,
* 0, ... 9, _, $). The encoding algorithm itself is not too
* clever: if the current byte's ASCII value already is a valid Java
* identifier part, leave it as it is. Otherwise it writes the
* escape character($) followed by:
*
* <ul>
* <li> the ASCII value as a hexadecimal string, if the value is not in the
* range 200..247</li>
* <li>a Java identifier char not used in a lowercase hexadecimal string, if
* the value is in the range 200..247</li>
* <li> the ASCII value as a hexadecimal string, if the value is not in the range 200..247</li>
* <li>a Java identifier char not used in a lowercase hexadecimal string, if the value is in the range 200..247</li>
* </ul>
*
* <p>
* This operation inflates the original byte array by roughly 40-50%</p>
* <p>This operation inflates the original byte array by roughly 40-50%</p>
*
* @param bytes the byte array to convert
* @param compress use gzip to minimize string
@ -1271,6 +1327,7 @@ public abstract class Utility {
return caw.toString();
}
/**
* Decode a string back to a byte array.
*
@ -1308,7 +1365,6 @@ public abstract class Utility {
private static int[] CHAR_MAP = new int[FREE_CHARS];
private static int[] MAP_CHAR = new int[256]; // Reverse map
private static final char ESCAPE_CHAR = '$';
static {
int j = 0;
for (int i = 'A'; i <= 'Z'; i++) {
@ -1329,8 +1385,8 @@ public abstract class Utility {
}
/**
* Decode characters into bytes. Used by <a
* href="Utility.html#decode(java.lang.String, boolean)">decode()</a>
* Decode characters into bytes.
* Used by <a href="Utility.html#decode(java.lang.String, boolean)">decode()</a>
*/
private static class JavaReader extends FilterReader {
@ -1338,6 +1394,7 @@ public abstract class Utility {
super(in);
}
@Override
public int read() throws IOException {
final int b = in.read();
@ -1354,7 +1411,7 @@ public abstract class Utility {
return -1;
}
final char[] tmp = {
(char) i, (char) j
(char) i, (char) j
};
final int s = Integer.parseInt(new String(tmp), 16);
return s;
@ -1362,8 +1419,9 @@ public abstract class Utility {
return MAP_CHAR[i];
}
@Override
public int read(final char[] cbuf, final int off, final int len) throws IOException {
public int read( final char[] cbuf, final int off, final int len ) throws IOException {
for (int i = 0; i < len; i++) {
cbuf[off + i] = (char) read();
}
@ -1372,8 +1430,8 @@ public abstract class Utility {
}
/**
* Encode bytes into valid java identifier characters. Used by <a
* href="Utility.html#encode(byte[], boolean)">encode()</a>
* Encode bytes into valid java identifier characters.
* Used by <a href="Utility.html#encode(byte[], boolean)">encode()</a>
*/
private static class JavaWriter extends FilterWriter {
@ -1381,8 +1439,9 @@ public abstract class Utility {
super(out);
}
@Override
public void write(final int b) throws IOException {
public void write( final int b ) throws IOException {
if (isJavaIdentifierPart((char) b) && (b != ESCAPE_CHAR)) {
out.write(b);
} else {
@ -1403,23 +1462,26 @@ public abstract class Utility {
}
}
@Override
public void write(final char[] cbuf, final int off, final int len) throws IOException {
public void write( final char[] cbuf, final int off, final int len ) throws IOException {
for (int i = 0; i < len; i++) {
write(cbuf[off + i]);
}
}
@Override
public void write(final String str, final int off, final int len) throws IOException {
public void write( final String str, final int off, final int len ) throws IOException {
write(str.toCharArray(), off, len);
}
}
/**
* Escape all occurences of newline chars '\n', quotes \", etc.
*/
public static String convertString(final String label) {
public static String convertString( final String label ) {
final char[] ch = label.toCharArray();
final StringBuilder buf = new StringBuilder();
for (final char element : ch) {
@ -1446,4 +1508,5 @@ public abstract class Utility {
}
return buf.toString();
}
}

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.bcel.internal.classfile;
* that implements this interface can traverse the contents of a Java class just
* by calling the `accept' method which all classes have.
*
* @version $Id: Visitor.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public interface Visitor
{
@ -150,4 +150,21 @@ public interface Visitor
* @since 6.0
*/
void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
/**
* @since 6.1
*/
void visitConstantPackage(ConstantPackage constantPackage);
/**
* @since 6.1
*/
void visitConstantModule(ConstantModule constantModule);
/**
* @since 6.3
*/
default void visitConstantDynamic(ConstantDynamic constantDynamic) {
// empty
}
}

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* AALOAD - Load reference from array
* <PRE>Stack: ..., arrayref, index -&gt; value</PRE>
*
* @version $Id: AALOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class AALOAD extends ArrayInstruction implements StackProducer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* AASTORE - Store into reference array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @version $Id: AASTORE.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class AASTORE extends ArrayInstruction implements StackConsumer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* ACONST_NULL - Push null reference
* <PRE>Stack: ... -&gt; ..., null</PRE>
*
* @version $Id: ACONST_NULL.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class ACONST_NULL extends Instruction implements PushInstruction, TypedInstruction {

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -27,18 +26,20 @@ import com.sun.org.apache.bcel.internal.Const;
* ALOAD - Load reference from local variable
* <PRE>Stack: ... -&gt; ..., objectref</PRE>
*
* @version $Id: ALOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @LastModified: Jun 2019
*/
public class ALOAD extends LoadInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ALOAD() {
super(Const.ALOAD, Const.ALOAD_0);
}
/** Load reference from local variable
* @param n index of local variable
*/
@ -46,6 +47,7 @@ public class ALOAD extends LoadInstruction {
super(Const.ALOAD, Const.ALOAD_0, n);
}
/**
* Call corresponding visitor method(s). The order is:
* Call visitor methods of implemented interfaces first, then

View File

@ -27,14 +27,14 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
* ANEWARRAY - Create new array of references
* <PRE>Stack: ..., count -&gt; ..., arrayref</PRE>
*
* @version $Id: ANEWARRAY.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class ANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction,
ExceptionThrower, StackConsumer, StackProducer {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ANEWARRAY() {
}

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* ARETURN - Return reference from method
* <PRE>Stack: ..., objectref -&gt; &lt;empty&gt;</PRE>
*
* @version $Id: ARETURN.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class ARETURN extends ReturnInstruction {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,8 +26,8 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
* ARRAYLENGTH - Get length of array
* <PRE>Stack: ..., arrayref -&gt; ..., length</PRE>
*
* @version $Id: ARRAYLENGTH.java 1747278 2016-06-07 17:28:43Z britter $
* @LastModified: Oct 2017
* @version $Id$
* @LastModified: Jun 2019
*/
public class ARRAYLENGTH extends Instruction
implements ExceptionThrower, StackProducer, StackConsumer /* since 6.0 */ {

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,37 +25,38 @@ import com.sun.org.apache.bcel.internal.Const;
* ASTORE - Store reference into local variable
* <PRE>Stack ..., objectref -&gt; ... </PRE>
*
* @version $Id: ASTORE.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @LastModified: Jun 2019
*/
public class ASTORE extends StoreInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ASTORE() {
super(Const.ASTORE, Const.ASTORE_0);
}
/**
* Store reference into local variable
*
/** Store reference into local variable
* @param n index of local variable
*/
public ASTORE(final int n) {
super(Const.ASTORE, Const.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.
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
super.accept(v);
v.visitASTORE(this);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,8 +26,8 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
* ATHROW - Throw exception
* <PRE>Stack: ..., objectref -&gt; objectref</PRE>
*
* @version $Id: ATHROW.java 1747278 2016-06-07 17:28:43Z britter $
* @LastModified: Oct 2017
* @version $Id$
* @LastModified: Jun 2019
*/
public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower {

View File

@ -24,7 +24,7 @@ package com.sun.org.apache.bcel.internal.generic;
/**
* Denote family of instructions that allocates space in the heap.
*
* @version $Id: AllocationInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public interface AllocationInstruction {
}

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -41,6 +40,7 @@ import com.sun.org.apache.bcel.internal.classfile.RuntimeVisibleParameterAnnotat
/**
* @since 6.0
* @LastModified: Jun 2019
*/
public class AnnotationEntryGen {
private int typeIndex;
@ -263,8 +263,8 @@ public class AnnotationEntryGen {
return newAttributes.toArray(new Attribute[newAttributes.size()]);
} catch (final IOException e) {
System.err.println("IOException whilst processing annotations. " +
e.getMessage());
System.err.println("IOException whilst processing annotations");
e.printStackTrace();
}
return null;
}

View File

@ -26,14 +26,14 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Super class for the family of arithmetic instructions.
*
* @version $Id: ArithmeticInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
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.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ArithmeticInstruction() {
}

View File

@ -26,14 +26,14 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
/**
* Super class for instructions dealing with array access such as IALOAD.
*
* @version $Id: ArrayInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
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.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ArrayInstruction() {
}

View File

@ -25,13 +25,14 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Denotes array type, such as int[][]
*
* @version $Id: ArrayType.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public final class ArrayType extends ReferenceType {
private int dimensions;
private Type basic_type;
/**
* Convenience constructor for array type, e.g. int[]
*
@ -41,6 +42,7 @@ public final class ArrayType extends ReferenceType {
this(BasicType.getType(type), dimensions);
}
/**
* Convenience constructor for reference array type, e.g. Object[]
*
@ -50,6 +52,7 @@ public final class ArrayType extends ReferenceType {
this(ObjectType.getInstance(class_name), dimensions);
}
/**
* Constructor for array of given type
*
@ -81,6 +84,7 @@ public final class ArrayType extends ReferenceType {
super.setSignature(buf.toString());
}
/**
* @return basic type of array, i.e., for int[][][] the basic type is int
*/
@ -88,9 +92,9 @@ public final class ArrayType extends ReferenceType {
return basic_type;
}
/**
* @return element type of array, i.e., for int[][][] the element type is
* int[][]
* @return element type of array, i.e., for int[][][] the element type is int[][]
*/
public Type getElementType() {
if (dimensions == 1) {
@ -99,26 +103,26 @@ public final class ArrayType extends ReferenceType {
return new ArrayType(basic_type, dimensions - 1);
}
/**
* @return number of dimensions of array
/** @return number of dimensions of array
*/
public int getDimensions() {
return dimensions;
}
/**
* @return a hash code value for the object.
/** @return a hash code value for the object.
*/
@Override
public int hashCode() {
return basic_type.hashCode() ^ dimensions;
}
/**
* @return true if both type objects refer to the same array type.
/** @return true if both type objects refer to the same array type.
*/
@Override
public boolean equals(final Object _type) {
public boolean equals( final Object _type ) {
if (_type instanceof ArrayType) {
final ArrayType array = (ArrayType) _type;
return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);

View File

@ -24,27 +24,27 @@ package com.sun.org.apache.bcel.internal.generic;
* BALOAD - Load byte or boolean from array
* <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
*
* @version $Id: BALOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class BALOAD extends ArrayInstruction implements StackProducer {
/**
* Load byte or boolean from array
/** Load byte or boolean from array
*/
public BALOAD() {
super(com.sun.org.apache.bcel.internal.Const.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.
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitStackProducer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);

View File

@ -21,30 +21,30 @@
package com.sun.org.apache.bcel.internal.generic;
/**
* BASTORE - Store into byte or boolean array
* BASTORE - Store into byte or boolean array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @version $Id: BASTORE.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class BASTORE extends ArrayInstruction implements StackConsumer {
/**
* Store byte or boolean into array
/** Store byte or boolean into array
*/
public BASTORE() {
super(com.sun.org.apache.bcel.internal.Const.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.
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitStackConsumer(this);
v.visitExceptionThrower(this);
v.visitTypedInstruction(this);

View File

@ -29,76 +29,82 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
*
* <PRE>Stack: ... -&gt; ..., value</PRE>
*
* @version $Id: BIPUSH.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
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.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
BIPUSH() {
}
/**
* Push byte on stack
/** Push byte on stack
*/
public BIPUSH(final byte b) {
super(com.sun.org.apache.bcel.internal.Const.BIPUSH, (short) 2);
this.b = b;
}
/**
* Dump instruction as byte code to stream out.
*/
@Override
public void dump(final DataOutputStream out) throws IOException {
public void dump( final DataOutputStream out ) throws IOException {
super.dump(out);
out.writeByte(b);
}
/**
* @return mnemonic for instruction
*/
@Override
public String toString(final boolean verbose) {
public String toString( final boolean verbose ) {
return super.toString(verbose) + " " + b;
}
/**
* Read needed data (e.g. index) from file.
*/
@Override
protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
super.setLength(2);
b = bytes.readByte();
}
@Override
public Number getValue() {
return Integer.valueOf(b);
}
/**
* @return Type.BYTE
/** @return Type.BYTE
*/
@Override
public Type getType(final ConstantPoolGen cp) {
public Type getType( final 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.
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitPushInstruction(this);
v.visitStackProducer(this);
v.visitTypedInstruction(this);

View File

@ -23,7 +23,7 @@ package com.sun.org.apache.bcel.internal.generic;
/**
* BREAKPOINT, JVM dependent, ignored by default
*
* @version $Id: BREAKPOINT.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class BREAKPOINT extends Instruction {
@ -31,16 +31,17 @@ public class BREAKPOINT extends Instruction {
super(com.sun.org.apache.bcel.internal.Const.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.
* 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
*/
@Override
public void accept(final Visitor v) {
public void accept( final Visitor v ) {
v.visitBREAKPOINT(this);
}
}

View File

@ -25,7 +25,7 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Denotes basic type such as int.
*
* @version $Id: BasicType.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public final class BasicType extends Type {
@ -42,8 +42,9 @@ public final class BasicType extends Type {
}
}
// @since 6.0 no longer final
public static BasicType getType(final byte type) {
public static BasicType getType( final byte type ) {
switch (type) {
case Const.T_VOID:
return VOID;
@ -68,19 +69,19 @@ public final class BasicType extends Type {
}
}
/**
* @return a hash code value for the object.
/** @return a hash code value for the object.
*/
@Override
public int hashCode() {
return super.getType();
}
/**
* @return true if both type objects refer to the same type
/** @return true if both type objects refer to the same type
*/
@Override
public boolean equals(final Object _type) {
public boolean equals( final Object _type ) {
return (_type instanceof BasicType) ? ((BasicType) _type).getType() == this.getType() : false;
}
}

View File

@ -23,13 +23,13 @@ package com.sun.org.apache.bcel.internal.generic;
/**
* 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().
* instruction is not known at time of creation and must be set later
* via setTarget().
*
* @see InstructionHandle
* @see Instruction
* @see InstructionList
* @version $Id: BranchHandle.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
*/
public final class BranchHandle extends InstructionHandle {
@ -37,33 +37,16 @@ public final class BranchHandle extends InstructionHandle {
// See BCEL-273
private BranchInstruction bi; // An alias in fact, but saves lots of casts
private BranchHandle(final BranchInstruction i) {
super(i);
bi = i;
}
/**
* Factory methods.
/** Factory method.
*/
private static BranchHandle bh_list = null; // List of reusable handles
static BranchHandle getBranchHandle(final BranchInstruction i) {
if (bh_list == null) {
return new BranchHandle(i);
}
final BranchHandle bh = bh_list;
bh_list = (BranchHandle) bh.getNext();
bh.setInstruction(i);
return bh;
}
/**
* Handle adds itself to the list of resuable handles.
*/
@Override
protected void addHandle() {
super.setNext(bh_list);
bh_list = this;
static BranchHandle getBranchHandle( final BranchInstruction i ) {
return new BranchHandle(i);
}
@ -76,34 +59,39 @@ public final class BranchHandle extends InstructionHandle {
return bi.getPosition();
}
@Override
void setPosition(final int pos) {
void setPosition( final int pos ) {
// Original code: i_position = bi.position = pos;
bi.setPosition(pos);
super.setPosition(pos);
}
@Override
protected int updatePosition(final int offset, final int max_offset) {
protected int updatePosition( final int offset, final int max_offset ) {
final int x = bi.updatePosition(offset, max_offset);
super.setPosition(bi.getPosition());
return x;
}
/**
* Pass new target to instruction.
*/
public void setTarget(final InstructionHandle ih) {
public void setTarget( final InstructionHandle ih ) {
bi.setTarget(ih);
}
/**
* Update target of instruction.
*/
public void updateTarget(final InstructionHandle old_ih, final InstructionHandle new_ih) {
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) {
bi.updateTarget(old_ih, new_ih);
}
/**
* @return target of instruction.
*/
@ -111,12 +99,12 @@ public final class BranchHandle extends InstructionHandle {
return bi.getTarget();
}
/**
* Set new contents. Old instruction is disposed and may not be used
* anymore.
* Set new contents. Old instruction is disposed and may not be used anymore.
*/
@Override // This is only done in order to apply the additional type check; could be merged with super impl.
public void setInstruction(final Instruction i) { // TODO could be package-protected?
public void setInstruction( final Instruction i ) { // TODO could be package-protected?
super.setInstruction(i);
if (!(i instanceof BranchInstruction)) {
throw new ClassGenException("Assigning " + i

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -26,12 +25,13 @@ import java.io.IOException;
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.
* 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
* @version $Id: BranchInstruction.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class BranchInstruction extends Instruction implements InstructionTargeter {
@ -46,9 +46,8 @@ public abstract class BranchInstruction extends Instruction implements Instructi
BranchInstruction() {
}
/**
* Common super constructor
*
/** Common super constructor
* @param opcode Instruction opcode
* @param target instruction to branch to
*/
@ -57,13 +56,13 @@ public abstract class BranchInstruction extends Instruction implements Instructi
setTarget(target);
}
/**
* Dump instruction as byte code to stream out.
*
* @param out Output stream
*/
@Override
public void dump(final DataOutputStream out) throws IOException {
public void dump( final DataOutputStream out ) throws IOException {
out.writeByte(super.getOpcode());
index = getTargetOffset();
if (!isValidShort(index)) {
@ -72,11 +71,12 @@ public abstract class BranchInstruction extends Instruction implements Instructi
out.writeShort(index); // May be negative, i.e., point backwards
}
/**
* @param _target branch target
* @return the offset to `target' relative to this instruction
* @return the offset to `target' relative to this instruction
*/
protected int getTargetOffset(final InstructionHandle _target) {
protected int getTargetOffset( final InstructionHandle _target ) {
if (_target == null) {
throw new ClassGenException("Target of " + super.toString(true)
+ " is invalid null handle");
@ -89,6 +89,7 @@ public abstract class BranchInstruction extends Instruction implements Instructi
return t - position;
}
/**
* @return the offset to this instruction's target
*/
@ -96,37 +97,36 @@ public abstract class BranchInstruction extends Instruction implements Instructi
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.
* 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
* @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(final int offset, final int max_offset) {
protected int updatePosition( final int offset, final 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;
* &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
*/
@Override
public String toString(final boolean verbose) {
public String toString( final boolean verbose ) {
final String s = super.toString(verbose);
String t = "null";
if (verbose) {
@ -153,20 +153,22 @@ public abstract class BranchInstruction extends Instruction implements Instructi
return s + " -> " + t;
}
/**
* Read needed data (e.g. index) from file. Conversion to a
* InstructionHandle is done in InstructionList(byte[]).
* 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
*/
@Override
protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
super.setLength(3);
index = bytes.readShort();
}
/**
* @return target offset in byte code
*/
@ -174,6 +176,7 @@ public abstract class BranchInstruction extends Instruction implements Instructi
return index;
}
/**
* @return target of branch instruction
*/
@ -181,22 +184,22 @@ public abstract class BranchInstruction extends Instruction implements Instructi
return target;
}
/**
* Set branch target
*
* @param target branch target
*/
public void setTarget(final InstructionHandle target) {
public void setTarget( final InstructionHandle target ) {
notifyTarget(this.target, target, this);
this.target = target;
}
/**
* Used by BranchInstruction, LocalVariableGen, CodeExceptionGen,
* LineNumberGen
* Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGen
*/
static void notifyTarget(final InstructionHandle old_ih, final InstructionHandle new_ih,
final InstructionTargeter t) {
static void notifyTarget( final InstructionHandle old_ih, final InstructionHandle new_ih,
final InstructionTargeter t ) {
if (old_ih != null) {
old_ih.removeTargeter(t);
}
@ -205,12 +208,13 @@ public abstract class BranchInstruction extends Instruction implements Instructi
}
}
/**
* @param old_ih old target
* @param new_ih new target
*/
@Override
public void updateTarget(final InstructionHandle old_ih, final InstructionHandle new_ih) {
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) {
if (target == old_ih) {
setTarget(new_ih);
} else {
@ -218,14 +222,16 @@ public abstract class BranchInstruction extends Instruction implements Instructi
}
}
/**
* @return true, if ih is target of this instruction
*/
@Override
public boolean containsTarget(final InstructionHandle ih) {
public boolean containsTarget( final InstructionHandle ih ) {
return target == ih;
}
/**
* Inform target that it's not targeted anymore.
*/
@ -236,6 +242,7 @@ public abstract class BranchInstruction extends Instruction implements Instructi
position = -1;
}
/**
* @return the position
* @since 6.0
@ -244,6 +251,7 @@ public abstract class BranchInstruction extends Instruction implements Instructi
return position;
}
/**
* @param position the position to set
* @since 6.0
@ -252,6 +260,7 @@ public abstract class BranchInstruction extends Instruction implements Instructi
this.position = position;
}
/**
* @param index the index to set
* @since 6.0

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* CALOAD - Load char from array
* <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
*
* @version $Id: CALOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class CALOAD extends ArrayInstruction implements StackProducer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* CASTORE - Store into char array
* <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
*
* @version $Id: CASTORE.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class CASTORE extends ArrayInstruction implements StackConsumer {

View File

@ -27,14 +27,14 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
* CHECKCAST - Check whether object is of given type
* <PRE>Stack: ..., objectref -&gt; ..., objectref</PRE>
*
* @version $Id: CHECKCAST.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
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.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
CHECKCAST() {
}

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -29,27 +28,30 @@ import com.sun.org.apache.bcel.internal.classfile.ConstantPool;
import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Abstract super class for instructions that use an index into the constant
* pool such as LDC, INVOKEVIRTUAL, etc.
* Abstract super class for instructions that use an index into the
* constant pool such as LDC, INVOKEVIRTUAL, etc.
*
* @see ConstantPoolGen
* @see LDC
* @see INVOKEVIRTUAL
*
* @version $Id: CPInstruction.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @LastModified: Jun 2019
*/
public abstract class CPInstruction extends Instruction implements TypedInstruction,
IndexedInstruction {
private int index; // index to constant pool
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
CPInstruction() {
}
/**
* @param index to constant pool
*/
@ -58,36 +60,38 @@ public abstract class CPInstruction extends Instruction implements TypedInstruct
setIndex(index);
}
/**
* Dump instruction as byte code to stream out.
*
* @param out Output stream
*/
@Override
public void dump(final DataOutputStream out) throws IOException {
public void dump( final DataOutputStream out ) throws IOException {
out.writeByte(super.getOpcode());
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;"
* &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
*/
@Override
public String toString(final boolean verbose) {
public String toString( final boolean verbose ) {
return super.toString(verbose) + " " + index;
}
/**
* @return mnemonic for instruction with symbolic references resolved
*/
@Override
public String toString(final ConstantPool cp) {
public String toString( final ConstantPool cp ) {
final Constant c = cp.getConstant(index);
String str = cp.constantToString(c);
if (c instanceof ConstantClass) {
@ -96,18 +100,19 @@ public abstract class CPInstruction extends Instruction implements TypedInstruct
return com.sun.org.apache.bcel.internal.Const.getOpcodeName(super.getOpcode()) + " " + str;
}
/**
* Read needed data (i.e., index) from file.
*
* @param bytes input stream
* @param wide wide prefix?
*/
@Override
protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
setIndex(bytes.readUnsignedShort());
super.setLength(3);
}
/**
* @return index in constant pool referred by this instruction.
*/
@ -116,24 +121,24 @@ public abstract class CPInstruction extends Instruction implements TypedInstruct
return index;
}
/**
* Set the index to constant pool.
*
* @param index in constant pool.
* @param index in constant pool.
*/
@Override
public void setIndex(final int index) { // TODO could be package-protected?
public void setIndex( final int index ) { // TODO could be package-protected?
if (index < 0) {
throw new ClassGenException("Negative index value: " + index);
}
this.index = index;
}
/**
* @return type related with this instruction.
/** @return type related with this instruction.
*/
@Override
public Type getType(final ConstantPoolGen cpg) {
public Type getType( final ConstantPoolGen cpg ) {
final ConstantPool cp = cpg.getConstantPool();
String name = cp.getConstantString(index, com.sun.org.apache.bcel.internal.Const.CONSTANT_Class);
if (!name.startsWith("[")) {

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -22,6 +21,7 @@ package com.sun.org.apache.bcel.internal.generic;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.classfile.AccessFlags;
@ -42,7 +42,8 @@ import com.sun.org.apache.bcel.internal.util.BCELComparator;
* existing java class (file).
*
* @see JavaClass
* @version $Id: ClassGen.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @LastModified: Jun 2019
*/
public class ClassGen extends AccessFlags implements Cloneable {
@ -66,21 +67,22 @@ public class ClassGen extends AccessFlags implements Cloneable {
private static BCELComparator _cmp = new BCELComparator() {
@Override
public boolean equals(final Object o1, final Object o2) {
public boolean equals( final Object o1, final Object o2 ) {
final ClassGen THIS = (ClassGen) o1;
final ClassGen THAT = (ClassGen) o2;
return THIS.getClassName().equals(THAT.getClassName());
return Objects.equals(THIS.getClassName(), THAT.getClassName());
}
@Override
public int hashCode(final Object o) {
public int hashCode( final Object o ) {
final ClassGen THIS = (ClassGen) o;
return THIS.getClassName().hashCode();
}
};
/**
* Convenience constructor to set up some important values initially.
/** Convenience constructor to set up some important values initially.
*
* @param class_name fully qualified class name
* @param super_class_name fully qualified superclass name
@ -110,8 +112,8 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
}
/**
* Convenience constructor to set up some important values initially.
/** Convenience constructor to set up some important values initially.
*
* @param class_name fully qualified class name
* @param super_class_name fully qualified superclass name
@ -125,9 +127,9 @@ public class ClassGen extends AccessFlags implements Cloneable {
new ConstantPoolGen());
}
/**
* Initialize with existing class.
*
* @param clazz JavaClass object (e.g. read from file)
*/
public ClassGen(final JavaClass clazz) {
@ -168,28 +170,34 @@ public class ClassGen extends AccessFlags implements Cloneable {
/**
* Look for attributes representing annotations and unpack them.
*/
private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs) {
private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs)
{
final List<AnnotationEntryGen> annotationGenObjs = new ArrayList<>();
for (final Attribute attr : attrs) {
if (attr instanceof RuntimeVisibleAnnotations) {
if (attr instanceof RuntimeVisibleAnnotations)
{
final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
final AnnotationEntry[] annos = rva.getAnnotationEntries();
for (final AnnotationEntry a : annos) {
annotationGenObjs.add(new AnnotationEntryGen(a,
getConstantPool(), false));
}
} else if (attr instanceof RuntimeInvisibleAnnotations) {
final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
final AnnotationEntry[] annos = ria.getAnnotationEntries();
for (final AnnotationEntry a : annos) {
annotationGenObjs.add(new AnnotationEntryGen(a,
getConstantPool(), false));
}
}
else
if (attr instanceof RuntimeInvisibleAnnotations)
{
final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
final AnnotationEntry[] annos = ria.getAnnotationEntries();
for (final AnnotationEntry a : annos) {
annotationGenObjs.add(new AnnotationEntryGen(a,
getConstantPool(), false));
}
}
}
return annotationGenObjs.toArray(new AnnotationEntryGen[annotationGenObjs.size()]);
}
/**
* @return the (finally) built up Java class object.
*/
@ -197,15 +205,15 @@ public class ClassGen extends AccessFlags implements Cloneable {
final int[] interfaces = getInterfaces();
final Field[] fields = getFields();
final Method[] methods = getMethods();
Attribute[] attributes;
Attribute[] attributes = null;
if (annotation_vec.isEmpty()) {
attributes = getAttributes();
} else {
// TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
final Attribute[] annAttributes = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries());
attributes = new Attribute[attribute_vec.size() + annAttributes.length];
final Attribute[] annAttributes = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries());
attributes = new Attribute[attribute_vec.size()+annAttributes.length];
attribute_vec.toArray(attributes);
System.arraycopy(annAttributes, 0, attributes, attribute_vec.size(), annAttributes.length);
System.arraycopy(annAttributes,0,attributes,attribute_vec.size(),annAttributes.length);
}
// Must be last since the above calls may still add something to it
final ConstantPool _cp = this.cp.getFinalConstantPool();
@ -213,24 +221,25 @@ public class ClassGen extends AccessFlags implements Cloneable {
super.getAccessFlags(), _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 final void addInterface(final String name) {
public void addInterface( final String name ) {
interface_vec.add(name);
}
/**
* Remove an interface from this class.
*
* @param name interface to remove (fully qualified name)
*/
public void removeInterface(final String name) {
public void removeInterface( final String name ) {
interface_vec.remove(name);
}
/**
* @return major version number of class file
*/
@ -238,21 +247,19 @@ public class ClassGen extends AccessFlags implements Cloneable {
return major;
}
/**
* Set major version number of class file, default value is 45 (JDK 1.1)
*
/** Set major version number of class file, default value is 45 (JDK 1.1)
* @param major major version number
*/
public void setMajor(final int major) { // TODO could be package-protected - only called by test code
public void setMajor( final int major ) { // TODO could be package-protected - only called by test code
this.major = major;
}
/**
* Set minor version number of class file, default value is 3 (JDK 1.1)
*
/** Set minor version number of class file, default value is 3 (JDK 1.1)
* @param minor minor version number
*/
public void setMinor(final int minor) { // TODO could be package-protected - only called by test code
public void setMinor( final int minor ) { // TODO could be package-protected - only called by test code
this.minor = minor;
}
@ -263,37 +270,36 @@ public class ClassGen extends AccessFlags implements Cloneable {
return minor;
}
/**
* Add an attribute to this class.
*
* @param a attribute to add
*/
public final void addAttribute(final Attribute a) {
public void addAttribute( final Attribute a ) {
attribute_vec.add(a);
}
public final void addAnnotationEntry(final AnnotationEntryGen a) {
public void addAnnotationEntry(final AnnotationEntryGen a) {
annotation_vec.add(a);
}
/**
* Add a method to this class.
*
* @param m method to add
*/
public final void addMethod(final Method m) {
public void addMethod( final Method m ) {
method_vec.add(m);
}
/**
* Convenience method.
*
* Add an empty constructor to this class that does nothing but calling
* super().
*
* Add an empty constructor to this class that does nothing but calling super().
* @param access_flags rights for constructor
*/
public void addEmptyConstructor(final int access_flags) {
public void addEmptyConstructor( final int access_flags ) {
final InstructionList il = new InstructionList();
il.append(InstructionConst.THIS); // Push `this'
il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name, "<init>", "()V")));
@ -304,23 +310,24 @@ public class ClassGen extends AccessFlags implements Cloneable {
addMethod(mg.getMethod());
}
/**
* Add a field to this class.
*
* @param f field to add
*/
public final void addField(final Field f) {
public void addField( final Field f ) {
field_vec.add(f);
}
public boolean containsField(final Field f) {
public boolean containsField( final Field f ) {
return field_vec.contains(f);
}
/**
* @return field object with given name, or null
/** @return field object with given name, or null
*/
public Field containsField(final String name) {
public Field containsField( final String name ) {
for (final Field f : field_vec) {
if (f.getName().equals(name)) {
return f;
@ -329,10 +336,10 @@ public class ClassGen extends AccessFlags implements Cloneable {
return null;
}
/**
* @return method object with given name and signature, or null
/** @return method object with given name and signature, or null
*/
public Method containsMethod(final String name, final String signature) {
public Method containsMethod( final String name, final String signature ) {
for (final Method m : method_vec) {
if (m.getName().equals(name) && m.getSignature().equals(signature)) {
return m;
@ -341,29 +348,29 @@ public class ClassGen extends AccessFlags implements Cloneable {
return null;
}
/**
* Remove an attribute from this class.
*
* @param a attribute to remove
*/
public void removeAttribute(final Attribute a) {
public void removeAttribute( final Attribute a ) {
attribute_vec.remove(a);
}
/**
* Remove a method from this class.
*
* @param m method to remove
*/
public void removeMethod(final Method m) {
public void removeMethod( final 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.
/** Replace given method with new one. If the old one does not exist
* add the new_ method to the class anyway.
*/
public void replaceMethod(final Method old, final Method new_) {
public void replaceMethod( final Method old, final Method new_ ) {
if (new_ == null) {
throw new ClassGenException("Replacement method must not be null");
}
@ -375,11 +382,11 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
}
/**
* Replace given field with new one. If the old one does not exist add the
* new_ field to the class anyway.
/** Replace given field with new one. If the old one does not exist
* add the new_ field to the class anyway.
*/
public void replaceField(final Field old, final Field new_) {
public void replaceField( final Field old, final Field new_ ) {
if (new_ == null) {
throw new ClassGenException("Replacement method must not be null");
}
@ -391,56 +398,66 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
}
/**
* Remove a field to this class.
*
* @param f field to remove
*/
public void removeField(final Field f) {
public void removeField( final 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(final String name) {
public void setClassName( final String name ) {
class_name = name.replace('/', '.');
class_name_index = cp.addClass(name);
}
public void setSuperclassName(final String name) {
public void setSuperclassName( final String name ) {
super_class_name = name.replace('/', '.');
superclass_name_index = cp.addClass(name);
}
public Method[] getMethods() {
return method_vec.toArray(new Method[method_vec.size()]);
}
public void setMethods(final Method[] methods) {
public void setMethods( final Method[] methods ) {
method_vec.clear();
for (final Method method : methods) {
addMethod(method);
}
}
public void setMethodAt(final Method method, final int pos) {
public void setMethodAt( final Method method, final int pos ) {
method_vec.set(pos, method);
}
public Method getMethodAt(final int pos) {
public Method getMethodAt( final int pos ) {
return method_vec.get(pos);
}
public String[] getInterfaceNames() {
final int size = interface_vec.size();
final String[] interfaces = new String[size];
@ -448,6 +465,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
return interfaces;
}
public int[] getInterfaces() {
final int size = interface_vec.size();
final int[] interfaces = new int[size];
@ -457,10 +475,12 @@ public class ClassGen extends AccessFlags implements Cloneable {
return interfaces;
}
public Field[] getFields() {
return field_vec.toArray(new Field[field_vec.size()]);
}
public Attribute[] getAttributes() {
return attribute_vec.toArray(new Attribute[attribute_vec.size()]);
}
@ -470,59 +490,65 @@ public class ClassGen extends AccessFlags implements Cloneable {
return annotation_vec.toArray(new AnnotationEntryGen[annotation_vec.size()]);
}
public ConstantPoolGen getConstantPool() {
return cp;
}
public void setConstantPool(final ConstantPoolGen constant_pool) {
public void setConstantPool( final ConstantPoolGen constant_pool ) {
cp = constant_pool;
}
public void setClassNameIndex(final int class_name_index) {
public void setClassNameIndex( final int class_name_index ) {
this.class_name_index = class_name_index;
class_name = cp.getConstantPool().getConstantString(class_name_index,
Const.CONSTANT_Class).replace('/', '.');
}
public void setSuperclassNameIndex(final int superclass_name_index) {
public void setSuperclassNameIndex( final int superclass_name_index ) {
this.superclass_name_index = superclass_name_index;
super_class_name = cp.getConstantPool().getConstantString(superclass_name_index,
Const.CONSTANT_Class).replace('/', '.');
}
public int getSuperclassNameIndex() {
return superclass_name_index;
}
public int getClassNameIndex() {
return class_name_index;
}
private List<ClassObserver> observers;
/**
* Add observer for this object.
/** Add observer for this object.
*/
public void addObserver(final ClassObserver o) {
public void addObserver( final ClassObserver o ) {
if (observers == null) {
observers = new ArrayList<>();
}
observers.add(o);
}
/**
* Remove observer for this object.
/** Remove observer for this object.
*/
public void removeObserver(final ClassObserver o) {
public void removeObserver( final 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.
/** 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) {
@ -532,6 +558,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
}
@Override
public Object clone() {
try {
@ -541,6 +568,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
}
/**
* @return Comparison strategy object
*/
@ -548,27 +576,31 @@ public class ClassGen extends AccessFlags implements Cloneable {
return _cmp;
}
/**
* @param comparator Comparison strategy object
*/
public static void setComparator(final BCELComparator comparator) {
public static void setComparator( final BCELComparator comparator ) {
_cmp = comparator;
}
/**
* Return value as defined by given BCELComparator strategy. By default two
* ClassGen objects are said to be equal when their class names are equal.
* Return value as defined by given BCELComparator strategy.
* By default two ClassGen objects are said to be equal when
* their class names are equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {
public boolean equals( final Object obj ) {
return _cmp.equals(this, obj);
}
/**
* Return value as defined by given BCELComparator strategy. By default
* return the hashcode of the class name.
* Return value as defined by given BCELComparator strategy.
* By default return the hashcode of the class name.
*
* @see java.lang.Object#hashCode()
*/

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* Thrown on internal errors. Extends RuntimeException so it hasn't to be declared
* in the throws clause every time.
*
* @version $Id: ClassGenException.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class ClassGenException extends RuntimeException {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* Implement this interface if you're interested in changes to a ClassGen object
* and register yourself with addObserver().
*
* @version $Id: ClassObserver.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public interface ClassObserver {

View File

@ -23,7 +23,7 @@ package com.sun.org.apache.bcel.internal.generic;
import com.sun.org.apache.bcel.internal.classfile.CodeException;
/**
* This class represents an exception handler, i.e., specifies the region where
* 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
@ -31,10 +31,10 @@ import com.sun.org.apache.bcel.internal.classfile.CodeException;
* The end of the region is automatically mapped to be exclusive when calling
* getCodeException(), i.e., there is no difference semantically.
*
* @version $Id: CodeExceptionGen.java 1749603 2016-06-21 20:50:19Z ggregory $
* @see MethodGen
* @see CodeException
* @see InstructionHandle
* @version $Id$
* @see MethodGen
* @see CodeException
* @see InstructionHandle
*/
public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
@ -43,9 +43,10 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
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.
* 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)
@ -60,16 +61,17 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
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.
* 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(final ConstantPoolGen cp) {
public CodeException getCodeException( final 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));
@ -79,7 +81,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
/* Set start of handler
* @param start_pc Start of handled region (inclusive)
*/
public void setStartPC(final InstructionHandle start_pc) { // TODO could be package-protected?
public void setStartPC( final InstructionHandle start_pc ) { // TODO could be package-protected?
BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
this.start_pc = start_pc;
}
@ -88,7 +90,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
/* Set end of handler
* @param end_pc End of handled region (inclusive)
*/
public void setEndPC(final InstructionHandle end_pc) { // TODO could be package-protected?
public void setEndPC( final InstructionHandle end_pc ) { // TODO could be package-protected?
BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
this.end_pc = end_pc;
}
@ -97,17 +99,18 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
/* Set handler code
* @param handler_pc Start of handler
*/
public void setHandlerPC(final InstructionHandle handler_pc) { // TODO could be package-protected?
public void setHandlerPC( final InstructionHandle handler_pc ) { // TODO could be package-protected?
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
*/
@Override
public void updateTarget(final InstructionHandle old_ih, final InstructionHandle new_ih) {
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) {
boolean targeted = false;
if (start_pc == old_ih) {
targeted = true;
@ -127,54 +130,55 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
}
}
/**
* @return true, if ih is target of this handler
*/
@Override
public boolean containsTarget(final InstructionHandle ih) {
public boolean containsTarget( final 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(final ObjectType catch_type) {
/** Sets the type of the Exception to catch. Set 'null' for ANY. */
public void setCatchType( final ObjectType catch_type ) {
this.catch_type = catch_type;
}
/**
* Gets the type of the Exception to catch, 'null' for ANY.
*/
/** Gets the type of the Exception to catch, 'null' for ANY. */
public ObjectType getCatchType() {
return catch_type;
}
/**
* @return start of handled region (inclusive)
/** @return start of handled region (inclusive)
*/
public InstructionHandle getStartPC() {
return start_pc;
}
/**
* @return end of handled region (inclusive)
/** @return end of handled region (inclusive)
*/
public InstructionHandle getEndPC() {
return end_pc;
}
/**
* @return start of handler
/** @return start of handler
*/
public InstructionHandle getHandlerPC() {
return handler_pc;
}
@Override
public String toString() {
return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")";
}
@Override
public Object clone() {
try {

View File

@ -32,7 +32,7 @@ package com.sun.org.apache.bcel.internal.generic;
* The interface provides the possibilty for the user to write
* `templates' or `macros' for such reuseable code patterns.
*
* @version $Id: CompoundInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see PUSH
* @see SWITCH
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -40,16 +40,18 @@ import com.sun.org.apache.bcel.internal.classfile.ConstantString;
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8;
/**
* 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
* 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.
* Constants.MAX_SHORT entries. Note that the first (0) is used by the
* JVM and that Double and Long constants need two slots.
*
* @version $Id: ConstantPoolGen.java 1749603 2016-06-21 20:50:19Z ggregory $
* @version $Id$
* @see Constant
* @LastModified: Jun 2019
*/
public class ConstantPoolGen {
@ -67,11 +69,13 @@ public class ConstantPoolGen {
final int index;
Index(final int i) {
index = i;
}
}
/**
* Initialize with given array of constants.
*
@ -88,6 +92,7 @@ public class ConstantPoolGen {
index = cs.length;
}
for (int i = 1; i < index; i++) {
final Constant c = constants[i];
if (c instanceof ConstantString) {
@ -134,7 +139,7 @@ public class ConstantPoolGen {
// since name can't begin with digit, can use
// METHODREF_DELIM with out fear of duplicates.
} else {
final ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
final ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
class_name = u8.getBytes().replace('/', '.');
}
@ -183,6 +188,7 @@ public class ConstantPoolGen {
}
}
/**
* Initialize with given constant pool.
*/
@ -190,6 +196,7 @@ public class ConstantPoolGen {
this(cp.getConstantPool());
}
/**
* Create empty constant pool.
*/
@ -198,8 +205,8 @@ public class ConstantPoolGen {
constants = new Constant[size];
}
/**
* Resize internal array of constants.
/** Resize internal array of constants.
*/
protected void adjustSize() {
if (index + 3 >= size) {
@ -212,25 +219,26 @@ public class ConstantPoolGen {
private final Map<String, Index> 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(final String str) {
public int lookupString( final String str ) {
final 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.
* 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(final String str) {
public int addString( final String str ) {
int ret;
if ((ret = lookupString(str)) != -1) {
return ret; // Already in CP
@ -248,18 +256,20 @@ public class ConstantPoolGen {
private final Map<String, Index> 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(final String str) {
public int lookupClass( final String str ) {
final Index index = class_table.get(str.replace('.', '/'));
return (index != null) ? index.index : -1;
}
private int addClass_(final String clazz) {
private int addClass_( final String clazz ) {
int ret;
if ((ret = lookupClass(clazz)) != -1) {
return ret; // Already in CP
@ -274,45 +284,48 @@ public class ConstantPoolGen {
return ret;
}
/**
* Add a new Class reference to the ConstantPool, if it is not already in
* there.
* 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(final String str) {
public int addClass( final String str ) {
return addClass_(str.replace('.', '/'));
}
/**
* Add a new Class reference to the ConstantPool for a given type.
*
* @param type Class to add
* @return index of entry
*/
public int addClass(final ObjectType type) {
public int addClass( final 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.
* 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(final ArrayType type) {
public int addArrayClass( final 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(final int n) {
public int lookupInteger( final int n ) {
for (int i = 1; i < index; i++) {
if (constants[i] instanceof ConstantInteger) {
final ConstantInteger c = (ConstantInteger) constants[i];
@ -324,14 +337,14 @@ public class ConstantPoolGen {
return -1;
}
/**
* Add a new Integer constant to the ConstantPool, if it is not already in
* there.
* 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(final int n) {
public int addInteger( final int n ) {
int ret;
if ((ret = lookupInteger(n)) != -1) {
return ret; // Already in CP
@ -342,13 +355,14 @@ public class ConstantPoolGen {
return ret;
}
/**
* Look for ConstantFloat in ConstantPool.
*
* @param n Float number to look for
* @return index on success, -1 otherwise
*/
public int lookupFloat(final float n) {
public int lookupFloat( final float n ) {
final int bits = Float.floatToIntBits(n);
for (int i = 1; i < index; i++) {
if (constants[i] instanceof ConstantFloat) {
@ -361,14 +375,14 @@ public class ConstantPoolGen {
return -1;
}
/**
* Add a new Float constant to the ConstantPool, if it is not already in
* there.
* 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(final float n) {
public int addFloat( final float n ) {
int ret;
if ((ret = lookupFloat(n)) != -1) {
return ret; // Already in CP
@ -381,25 +395,26 @@ public class ConstantPoolGen {
private final Map<String, Index> 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(final String n) {
public int lookupUtf8( final String n ) {
final 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.
* 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(final String n) {
public int addUtf8( final String n ) {
int ret;
if ((ret = lookupUtf8(n)) != -1) {
return ret; // Already in CP
@ -413,13 +428,14 @@ public class ConstantPoolGen {
return ret;
}
/**
* Look for ConstantLong in ConstantPool.
*
* @param n Long number to look for
* @return index on success, -1 otherwise
*/
public int lookupLong(final long n) {
public int lookupLong( final long n ) {
for (int i = 1; i < index; i++) {
if (constants[i] instanceof ConstantLong) {
final ConstantLong c = (ConstantLong) constants[i];
@ -431,14 +447,14 @@ public class ConstantPoolGen {
return -1;
}
/**
* Add a new long constant to the ConstantPool, if it is not already in
* there.
* 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(final long n) {
public int addLong( final long n ) {
int ret;
if ((ret = lookupLong(n)) != -1) {
return ret; // Already in CP
@ -450,13 +466,14 @@ public class ConstantPoolGen {
return ret;
}
/**
* Look for ConstantDouble in ConstantPool.
*
* @param n Double number to look for
* @return index on success, -1 otherwise
*/
public int lookupDouble(final double n) {
public int lookupDouble( final double n ) {
final long bits = Double.doubleToLongBits(n);
for (int i = 1; i < index; i++) {
if (constants[i] instanceof ConstantDouble) {
@ -469,14 +486,14 @@ public class ConstantPoolGen {
return -1;
}
/**
* Add a new double constant to the ConstantPool, if it is not already in
* there.
* 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(final double n) {
public int addDouble( final double n ) {
int ret;
if ((ret = lookupDouble(n)) != -1) {
return ret; // Already in CP
@ -490,6 +507,7 @@ public class ConstantPoolGen {
private final Map<String, Index> n_a_t_table = new HashMap<>();
/**
* Look for ConstantNameAndType in ConstantPool.
*
@ -497,11 +515,12 @@ public class ConstantPoolGen {
* @param signature of variable/method
* @return index on success, -1 otherwise
*/
public int lookupNameAndType(final String name, final String signature) {
public int lookupNameAndType( final String name, final String signature ) {
final 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.
@ -510,7 +529,7 @@ public class ConstantPoolGen {
* @param signature signature string to add
* @return index of entry
*/
public int addNameAndType(final String name, final String signature) {
public int addNameAndType( final String name, final String signature ) {
int ret;
int name_index;
int signature_index;
@ -531,6 +550,7 @@ public class ConstantPoolGen {
private final Map<String, Index> cp_table = new HashMap<>();
/**
* Look for ConstantMethodref in ConstantPool.
*
@ -539,26 +559,28 @@ public class ConstantPoolGen {
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupMethodref(final String class_name, final String method_name, final String signature) {
public int lookupMethodref( final String class_name, final String method_name, final String signature ) {
final Index index = cp_table.get(class_name + METHODREF_DELIM + method_name
+ METHODREF_DELIM + signature);
return (index != null) ? index.index : -1;
}
public int lookupMethodref(final MethodGen method) {
public int lookupMethodref( final 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.
* Add a new Methodref constant to the ConstantPool, if it is not already
* in there.
*
* @param class_name class name string to add
* @param method_name method name string to add
* @param signature method signature string to add
* @return index of entry
*/
public int addMethodref(final String class_name, final String method_name, final String signature) {
public int addMethodref( final String class_name, final String method_name, final String signature ) {
int ret;
int class_index;
int name_and_type_index;
@ -577,10 +599,12 @@ public class ConstantPoolGen {
return ret;
}
public int addMethodref(final MethodGen method) {
public int addMethodref( final MethodGen method ) {
return addMethodref(method.getClassName(), method.getName(), method.getSignature());
}
/**
* Look for ConstantInterfaceMethodref in ConstantPool.
*
@ -589,27 +613,29 @@ public class ConstantPoolGen {
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupInterfaceMethodref(final String class_name, final String method_name, final String signature) {
public int lookupInterfaceMethodref( final String class_name, final String method_name, final String signature ) {
final Index index = cp_table.get(class_name + IMETHODREF_DELIM + method_name
+ IMETHODREF_DELIM + signature);
return (index != null) ? index.index : -1;
}
public int lookupInterfaceMethodref(final MethodGen method) {
public int lookupInterfaceMethodref( final 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.
* Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
* in there.
*
* @param class_name class name string to add
* @param method_name method name string to add
* @param signature signature string to add
* @return index of entry
*/
public int addInterfaceMethodref(final String class_name, final String method_name, final String signature) {
public int addInterfaceMethodref( final String class_name, final String method_name, final String signature ) {
int ret;
int class_index;
int name_and_type_index;
@ -628,10 +654,12 @@ public class ConstantPoolGen {
return ret;
}
public int addInterfaceMethodref(final MethodGen method) {
public int addInterfaceMethodref( final MethodGen method ) {
return addInterfaceMethodref(method.getClassName(), method.getName(), method.getSignature());
}
/**
* Look for ConstantFieldref in ConstantPool.
*
@ -640,22 +668,23 @@ public class ConstantPoolGen {
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
public int lookupFieldref(final String class_name, final String field_name, final String signature) {
public int lookupFieldref( final String class_name, final String field_name, final String signature ) {
final 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.
* Add a new Fieldref constant to the ConstantPool, if it is not already
* in there.
*
* @param class_name class name string to add
* @param field_name field name string to add
* @param signature signature string to add
* @return index of entry
*/
public int addFieldref(final String class_name, final String field_name, final String signature) {
public int addFieldref( final String class_name, final String field_name, final String signature ) {
int ret;
int class_index;
int name_and_type_index;
@ -674,24 +703,27 @@ public class ConstantPoolGen {
return ret;
}
/**
* @param i index in constant pool
* @return constant pool entry at index i
*/
public Constant getConstant(final int i) {
public Constant getConstant( final 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(final int i, final Constant c) {
public void setConstant( final int i, final Constant c ) {
constants[i] = c;
}
/**
* @return intermediate constant pool
*/
@ -699,6 +731,7 @@ public class ConstantPoolGen {
return new ConstantPool(constants);
}
/**
* @return current size of constant pool
*/
@ -706,6 +739,7 @@ public class ConstantPoolGen {
return index;
}
/**
* @return constant pool with proper length
*/
@ -715,6 +749,7 @@ public class ConstantPoolGen {
return new ConstantPool(cs);
}
/**
* @return String representation.
*/
@ -727,10 +762,10 @@ public class ConstantPoolGen {
return buf.toString();
}
/**
* Import constant from another ConstantPool and return new index.
/** Import constant from another ConstantPool and return new index.
*/
public int addConstant(final Constant c, final ConstantPoolGen cp) {
public int addConstant( final Constant c, final ConstantPoolGen cp ) {
final Constant[] constants = cp.getConstantPool().getConstantPool();
switch (c.getTag()) {
case Const.CONSTANT_String: {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* Denotes a push instruction that produces a literal on the stack
* such as SIPUSH, BIPUSH, ICONST, etc.
*
* @version $Id: ConstantPushInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
* @see ICONST
* @see SIPUSH

View File

@ -26,14 +26,14 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Super class for the x2y family of instructions.
*
* @version $Id: ConversionInstruction.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public abstract class ConversionInstruction extends Instruction implements TypedInstruction,
StackProducer, StackConsumer {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
ConversionInstruction() {
}

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* D2F - Convert double to float
* <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
*
* @version $Id: D2F.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class D2F extends ConversionInstruction {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* D2I - Convert double to int
* <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
*
* @version $Id: D2I.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class D2I extends ConversionInstruction {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* D2L - Convert double to long
* <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result.word1, result.word2</PRE>
*
* @version $Id: D2L.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class D2L extends ConversionInstruction {

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.bcel.internal.generic;
* <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
* ..., result.word1, result1.word2
*
* @version $Id: DADD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DADD extends ArithmeticInstruction {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* DALOAD - Load double from array
* <PRE>Stack: ..., arrayref, index -&gt; ..., result.word1, result.word2</PRE>
*
* @version $Id: DALOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DALOAD extends ArrayInstruction implements StackProducer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* DASTORE - Store into double array
* <PRE>Stack: ..., arrayref, index, value.word1, value.word2 -&gt; ...</PRE>
*
* @version $Id: DASTORE.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DASTORE extends ArrayInstruction implements StackConsumer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* DCMPG - Compare doubles: value1 &gt; value2
* <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt; ..., result</PRE>
*
* @version $Id: DCMPG.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DCMPG extends Instruction implements TypedInstruction, StackProducer, StackConsumer {

View File

@ -25,7 +25,7 @@ package com.sun.org.apache.bcel.internal.generic;
* DCMPL - Compare doubles: value1 &lt; value2
* <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt; ..., result</PRE>
*
* @version $Id: DCMPL.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DCMPL extends Instruction implements TypedInstruction, StackProducer, StackConsumer {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,8 +25,8 @@ package com.sun.org.apache.bcel.internal.generic;
*
* <PRE>Stack: ... -&gt; ..., </PRE>
*
* @version $Id: DCONST.java 1747278 2016-06-07 17:28:43Z britter $
* @LastModified: Nov 2017
* @version $Id$
* @LastModified: Jun 2019
*/
public class DCONST extends Instruction implements ConstantPushInstruction {
@ -34,8 +34,8 @@ public class DCONST extends Instruction implements ConstantPushInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
DCONST() {
}

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.bcel.internal.generic;
* <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
* ..., result.word1, result.word2
*
* @version $Id: DDIV.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DDIV extends ArithmeticInstruction {

View File

@ -25,13 +25,13 @@ package com.sun.org.apache.bcel.internal.generic;
* DLOAD - Load double from local variable
* <PRE>Stack ... -&gt; ..., result.word1, result.word2</PRE>
*
* @version $Id: DLOAD.java 1747278 2016-06-07 17:28:43Z britter $
* @version $Id$
*/
public class DLOAD extends LoadInstruction {
/**
* Empty constructor needed for the Class.newInstance() statement in
* Instruction.readInstruction(). Not to be used otherwise.
* Empty constructor needed for Instruction.readInstruction.
* Not to be used otherwise.
*/
DLOAD() {
super(com.sun.org.apache.bcel.internal.Const.DLOAD, com.sun.org.apache.bcel.internal.Const.DLOAD_0);

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