Skip to content

Commit

Permalink
Replace direct use of external fields with getter/setter
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/bcel/trunk@1697699 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
sebbASF committed Aug 25, 2015
1 parent b623232 commit adf9fc1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected ArithmeticInstruction(short opcode) {
*/
@Override
public Type getType( ConstantPoolGen cp ) {
switch (opcode) {
final short _opcode = super.getOpcode();
switch (_opcode) {
case Constants.DADD:
case Constants.DDIV:
case Constants.DMUL:
Expand Down Expand Up @@ -89,7 +90,7 @@ public Type getType( ConstantPoolGen cp ) {
case Constants.LXOR:
return Type.LONG;
default: // Never reached
throw new ClassGenException("Unknown type " + opcode);
throw new ClassGenException("Unknown type " + _opcode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public Class<?>[] getExceptions() {
*/
@Override
public Type getType( ConstantPoolGen cp ) {
switch (opcode) {
final short _opcode = super.getOpcode();
switch (_opcode) {
case org.apache.commons.bcel6.Constants.IALOAD:
case org.apache.commons.bcel6.Constants.IASTORE:
return Type.INT;
Expand All @@ -79,7 +80,7 @@ public Type getType( ConstantPoolGen cp ) {
case org.apache.commons.bcel6.Constants.AASTORE:
return Type.OBJECT;
default:
throw new ClassGenException("Oops: unknown case in switch" + opcode);
throw new ClassGenException("Oops: unknown case in switch" + _opcode);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/bcel6/generic/BIPUSH.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String toString( boolean verbose ) {
*/
@Override
protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
length = 2;
super.setLength(2);
b = bytes.readByte();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static BranchHandle getBranchHandle( BranchInstruction i ) {
return new BranchHandle(i);
}
BranchHandle bh = bh_list;
bh_list = (BranchHandle) bh.next;
bh_list = (BranchHandle) bh.getNext();
bh.setInstruction(i);
return bh;
}
Expand All @@ -54,7 +54,7 @@ static BranchHandle getBranchHandle( BranchInstruction i ) {
*/
@Override
protected void addHandle() {
next = bh_list;
super.setNext(bh_list);
bh_list = this;
}

Expand All @@ -78,14 +78,14 @@ public int getPosition() {
void setPosition( int pos ) {
// Original code: i_position = bi.position = pos;
getBI().setPosition(pos);
i_position = pos;
super.setPosition(pos);
}


@Override
protected int updatePosition( int offset, int max_offset ) {
int x = getBI().updatePosition(offset, max_offset);
i_position = getBI().getPosition();
super.setPosition(getBI().getPosition());
return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected ConversionInstruction(short opcode) {
*/
@Override
public Type getType( ConstantPoolGen cp ) {
switch (opcode) {
final short _opcode = super.getOpcode();
switch (_opcode) {
case Constants.D2I:
case Constants.F2I:
case Constants.L2I:
Expand All @@ -71,7 +72,7 @@ public Type getType( ConstantPoolGen cp ) {
case Constants.I2S:
return Type.SHORT;
default: // Never reached
throw new ClassGenException("Unknown type " + opcode);
throw new ClassGenException("Unknown type " + _opcode);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/bcel6/generic/DCONST.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class DCONST extends Instruction implements ConstantPushInstruction {
public DCONST(double f) {
super(org.apache.commons.bcel6.Constants.DCONST_0, (short) 1);
if (f == 0.0) {
opcode = org.apache.commons.bcel6.Constants.DCONST_0;
super.setOpcode(org.apache.commons.bcel6.Constants.DCONST_0);
} else if (f == 1.0) {
opcode = org.apache.commons.bcel6.Constants.DCONST_1;
super.setOpcode(org.apache.commons.bcel6.Constants.DCONST_1);
} else {
throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/commons/bcel6/generic/FCONST.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class FCONST extends Instruction implements ConstantPushInstruction {
public FCONST(float f) {
super(org.apache.commons.bcel6.Constants.FCONST_0, (short) 1);
if (f == 0.0) {
opcode = org.apache.commons.bcel6.Constants.FCONST_0;
super.setOpcode(org.apache.commons.bcel6.Constants.FCONST_0);
} else if (f == 1.0) {
opcode = org.apache.commons.bcel6.Constants.FCONST_1;
super.setOpcode(org.apache.commons.bcel6.Constants.FCONST_1);
} else if (f == 2.0) {
opcode = org.apache.commons.bcel6.Constants.FCONST_2;
super.setOpcode(org.apache.commons.bcel6.Constants.FCONST_2);
} else {
throw new ClassGenException("FCONST can be used only for 0.0, 1.0 and 2.0: " + f);
}
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/org/apache/commons/bcel6/generic/FieldGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public FieldGen(Field field, ConstantPoolGen cp) {


private void setValue( int index ) {
ConstantPool cp = this.cp.getConstantPool();
ConstantPool cp = super.getConstantPool().getConstantPool();
Constant c = cp.getConstant(index);
value = ((ConstantObject) c).getConstantValue(cp);
}
Expand Down Expand Up @@ -196,14 +196,15 @@ public void cancelInitValue() {


private void checkType( Type atype ) {
if (type == null) {
final Type superType = super.getType();
if (superType == null) {
throw new ClassGenException("You haven't defined the type of the field yet");
}
if (!isFinal()) {
throw new ClassGenException("Only final fields may have an initial value!");
}
if (!type.equals(atype)) {
throw new ClassGenException("Types are not compatible: " + type + " vs. " + atype);
if (!superType.equals(atype)) {
throw new ClassGenException("Types are not compatible: " + superType + " vs. " + atype);
}
}

Expand All @@ -213,17 +214,17 @@ private void checkType( Type atype ) {
*/
public Field getField() {
String signature = getSignature();
int name_index = cp.addUtf8(name);
int signature_index = cp.addUtf8(signature);
int name_index = super.getConstantPool().addUtf8(super.getName());
int signature_index = super.getConstantPool().addUtf8(signature);
if (value != null) {
checkType(type);
checkType(super.getType());
int index = addConstant();
addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp
.getConstantPool()));
addAttribute(new ConstantValue(super.getConstantPool().addUtf8("ConstantValue"), 2, index,
super.getConstantPool().getConstantPool())); // sic
}
addAnnotationsAsAttribute(cp);
return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(), cp
.getConstantPool());
addAnnotationsAsAttribute(super.getConstantPool());
return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(),
super.getConstantPool().getConstantPool()); // sic
}

private void addAnnotationsAsAttribute(ConstantPoolGen cp) {
Expand All @@ -235,30 +236,30 @@ private void addAnnotationsAsAttribute(ConstantPoolGen cp) {


private int addConstant() {
switch (type.getType()) {
switch (super.getType().getType()) { // sic
case Constants.T_INT:
case Constants.T_CHAR:
case Constants.T_BYTE:
case Constants.T_BOOLEAN:
case Constants.T_SHORT:
return cp.addInteger(((Integer) value).intValue());
return super.getConstantPool().addInteger(((Integer) value).intValue());
case Constants.T_FLOAT:
return cp.addFloat(((Float) value).floatValue());
return super.getConstantPool().addFloat(((Float) value).floatValue());
case Constants.T_DOUBLE:
return cp.addDouble(((Double) value).doubleValue());
return super.getConstantPool().addDouble(((Double) value).doubleValue());
case Constants.T_LONG:
return cp.addLong(((Long) value).longValue());
return super.getConstantPool().addLong(((Long) value).longValue());
case Constants.T_REFERENCE:
return cp.addString((String) value);
return super.getConstantPool().addString((String) value);
default:
throw new RuntimeException("Oops: Unhandled : " + type.getType());
throw new RuntimeException("Oops: Unhandled : " + super.getType().getType()); // sic
}
}


@Override
public String getSignature() {
return type.getSignature();
return super.getType().getSignature();
}

private List<FieldObserver> observers;
Expand Down Expand Up @@ -317,7 +318,7 @@ public final String toString() {
String access; // Short cuts to constant pool
access = Utility.accessToString(super.getAccessFlags());
access = access.equals("") ? "" : (access + " ");
signature = type.toString();
signature = super.getType().toString();
name = getName();
StringBuilder buf = new StringBuilder(32); // CHECKSTYLE IGNORE MagicNumber
buf.append(access).append(signature).append(" ").append(name);
Expand Down

0 comments on commit adf9fc1

Please sign in to comment.