You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [25/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/...
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/CodeEntry.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/CodeEntry.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/CodeEntry.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/CodeEntry.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,11 +12,10 @@
*/
package serp.bytecode;
-
/**
- * <p>An entry in a code block.</p>
- *
- * @author Abe White
+ * An entry in a code block.
+ *
+ * @author Abe White
*/
class CodeEntry {
CodeEntry next = null;
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,23 +12,19 @@
*/
package serp.bytecode;
+import java.io.*;
import serp.bytecode.lowlevel.*;
-
import serp.bytecode.visitor.*;
-
import serp.util.*;
-import java.io.*;
-
-
/**
- * <p>An instruction that that loads a constant onto the stack.
- * The opcode represented by this instruction may change depending on the
- * type and value of the constant set. For example, if the constant value
- * is initially set to 5, the opcode will be <code>iconst5</code>; if later
- * incremented to 6, the opcode will be changed to <code>bipush(6)</code>.</p>
- *
- * @author Abe White
+ * An instruction that that loads a constant onto the stack.
+ * The opcode represented by this instruction may change depending on the
+ * type and value of the constant set. For example, if the constant value
+ * is initially set to 5, the opcode will be <code>iconst5</code>; if later
+ * incremented to 6, the opcode will be changed to <code>bipush(6)</code>.
+ *
+ * @author Abe White
*/
public class ConstantInstruction extends TypedInstruction {
private int _arg = -1;
@@ -49,12 +42,10 @@
case Constants.BIPUSH:
case Constants.LDC:
return super.getLength() + 1;
-
case Constants.SIPUSH:
case Constants.LDCW:
case Constants.LDC2W:
return super.getLength() + 2;
-
default:
return super.getLength();
}
@@ -62,12 +53,9 @@
public int getStackChange() {
String type = getTypeName();
-
- if (double.class.getName().equals(type) ||
- long.class.getName().equals(type)) {
+ if (double.class.getName().equals(type)
+ || long.class.getName().equals(type))
return 2;
- }
-
return 1;
}
@@ -77,14 +65,11 @@
public String getTypeName() {
int opcode = getOpcode();
-
switch (opcode) {
case Constants.NOP:
return null;
-
case Constants.ACONSTNULL:
return Object.class.getName();
-
case Constants.ICONSTM1:
case Constants.ICONST0:
case Constants.ICONST1:
@@ -95,43 +80,33 @@
case Constants.BIPUSH:
case Constants.SIPUSH:
return int.class.getName();
-
case Constants.LCONST0:
case Constants.LCONST1:
return long.class.getName();
-
case Constants.FCONST0:
case Constants.FCONST1:
case Constants.FCONST2:
return float.class.getName();
-
case Constants.DCONST0:
case Constants.DCONST1:
return double.class.getName();
}
Entry entry = getPool().getEntry(_arg);
-
switch (entry.getType()) {
case Entry.UTF8:
case Entry.STRING:
return String.class.getName();
-
case Entry.INT:
return int.class.getName();
-
case Entry.FLOAT:
return float.class.getName();
-
case Entry.LONG:
return long.class.getName();
-
case Entry.DOUBLE:
return double.class.getName();
-
case Entry.CLASS:
return Class.class.getName();
-
default:
return null;
}
@@ -142,17 +117,15 @@
}
/**
- * Return the value of the constant as its wrapper type, or null if
- * not set. Returns class values as the class name.
+ * Return the value of the constant as its wrapper type, or null if
+ * not set. Returns class values as the class name.
*/
public Object getValue() {
int opcode = getOpcode();
-
switch (opcode) {
case Constants.NOP:
case Constants.ACONSTNULL:
return null;
-
case Constants.ICONSTM1:
case Constants.ICONST0:
case Constants.ICONST1:
@@ -161,252 +134,224 @@
case Constants.ICONST4:
case Constants.ICONST5:
return Numbers.valueOf(opcode - Constants.ICONST0);
-
case Constants.LCONST0:
case Constants.LCONST1:
return Numbers.valueOf((long) (opcode - Constants.LCONST0));
-
case Constants.FCONST0:
case Constants.FCONST1:
case Constants.FCONST2:
return new Float(opcode - Constants.FCONST0);
-
case Constants.DCONST0:
case Constants.DCONST1:
return new Double(opcode - Constants.DCONST0);
-
case Constants.BIPUSH:
case Constants.SIPUSH:
return Numbers.valueOf(_arg);
-
default:
-
Entry entry = getPool().getEntry(_arg);
Object val = ((ConstantEntry) entry).getConstant();
-
- if (entry.getType() == Entry.CLASS) {
- return getProject().getNameCache()
- .getExternalForm((String) val, false);
- }
-
+ if (entry.getType() == Entry.CLASS)
+ return getProject().getNameCache().getExternalForm
+ ((String) val, false);
return val;
}
}
/**
- * Set the constant to the given value. The value should be
- * an instance of String, Integer, Long, Double, Float, Class, BCClass, or
- * null depending on the constant type. If the given value is not
- * supported directly, it will be converted accordingly.
- *
- * @return this instruction, for method chaining
+ * Set the constant to the given value. The value should be
+ * an instance of String, Integer, Long, Double, Float, Class, BCClass, or
+ * null depending on the constant type. If the given value is not
+ * supported directly, it will be converted accordingly.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(Object value) {
- if (value instanceof Boolean) {
- value = Numbers.valueOf((((Boolean) value).booleanValue()) ? 1 : 0);
- } else if (value instanceof Character) {
+ if (value instanceof Boolean)
+ value = Numbers.valueOf((((Boolean) value).booleanValue())
+ ? 1 : 0);
+ else if (value instanceof Character)
value = Numbers.valueOf((int) ((Character) value).charValue());
- } else if (value instanceof Byte) {
+ else if (value instanceof Byte)
value = Numbers.valueOf(((Byte) value).intValue());
- } else if (value instanceof Short) {
+ else if (value instanceof Short)
value = Numbers.valueOf(((Short) value).intValue());
- } else if ((value != null) && !(value instanceof Number) &&
- !(value instanceof String) && !(value instanceof Class) &&
- !(value instanceof BCClass)) {
+ else if (value != null && !(value instanceof Number)
+ && !(value instanceof String)
+ && !(value instanceof Class)
+ && !(value instanceof BCClass))
throw new IllegalArgumentException("value = " + value);
- }
calculateOpcode(value, false);
-
return this;
}
/**
- * Return the string value of this constant, or null if not set.
+ * Return the string value of this constant, or null if not set.
*/
public String getStringValue() {
- return (String) getValue();
+ return(String) getValue();
}
/**
- * Return the int value of this constant, or 0 if not set.
+ * Return the int value of this constant, or 0 if not set.
*/
public int getIntValue() {
Object value = getValue();
-
- return (value == null) ? 0 : ((Number) value).intValue();
+ return(value == null) ? 0 : ((Number) value).intValue();
}
/**
- * Return the long value of this constant, or 0 if not set.
+ * Return the long value of this constant, or 0 if not set.
*/
public long getLongValue() {
Object value = getValue();
-
- return (value == null) ? 0L : ((Number) value).longValue();
+ return(value == null) ? 0L : ((Number) value).longValue();
}
/**
- * Return the float value of this constant, or 0 if not set.
+ * Return the float value of this constant, or 0 if not set.
*/
public float getFloatValue() {
Object value = getValue();
-
- return (value == null) ? 0F : ((Number) value).floatValue();
+ return(value == null) ? 0F : ((Number) value).floatValue();
}
/**
- * Return the double value of this constant, or 0 if not set.
+ * Return the double value of this constant, or 0 if not set.
*/
public double getDoubleValue() {
Object value = getValue();
-
- return (value == null) ? 0D : ((Number) value).doubleValue();
+ return(value == null) ? 0D : ((Number) value).doubleValue();
}
/**
- * Return the class value of this constant, or null if not set.
+ * Return the class value of this constant, or null if not set.
*/
public String getClassNameValue() {
- return (String) getValue();
+ return(String) getValue();
}
/**
- * Set this constant to null.
- *
- * @return this instruction, for method chaining
+ * Set this constant to null.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setNull() {
calculateOpcode(null, false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(String value) {
calculateOpcode(value, false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(Class value) {
calculateOpcode(value, false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(BCClass value) {
calculateOpcode(value, false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(int value) {
calculateOpcode(Numbers.valueOf(value), false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(long value) {
calculateOpcode(Numbers.valueOf(value), false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(float value) {
calculateOpcode(new Float(value), false);
-
return this;
}
/**
- * Set the value of this constant.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(double value) {
calculateOpcode(new Double(value), false);
-
return this;
}
/**
- * Set the value of this constant; note that this type is converted
- * to int.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant; note that this type is converted to int.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(boolean value) {
return setValue((value) ? 1 : 0);
}
/**
- * Set the value of this constant; note that this type is converted
- * to int.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant; note that this type is converted to int.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(short value) {
return setValue((int) value);
}
/**
- * Set the value of this constant; note that this type is converted
- * to int.
- *
- * @return this instruction, for method chaining
+ * Set the value of this constant; note that this type is converted to int.
+ *
+ * @return this instruction, for method chaining
*/
public ConstantInstruction setValue(char value) {
return setValue((int) value);
}
/**
- * ConstantInstructions are equal if the const they reference is the same,
- * or if the const of either is unset.
+ * ConstantInstructions are equal if the const they reference is the same,
+ * or if the const of either is unset.
*/
public boolean equalsInstruction(Instruction other) {
- if (this == other) {
+ if (this == other)
return true;
- }
-
- if (!(other instanceof ConstantInstruction)) {
+ if (!(other instanceof ConstantInstruction))
return false;
- }
Object value = getValue();
Object otherValue = ((ConstantInstruction) other).getValue();
- return (value == null) || (otherValue == null) ||
- value.equals(otherValue);
+ return value == null || otherValue == null || value.equals(otherValue);
}
public void acceptVisit(BCVisitor visit) {
@@ -416,7 +361,6 @@
void read(Instruction orig) {
super.read(orig);
-
ConstantInstruction ci = (ConstantInstruction) orig;
calculateOpcode(ci.getValue(), ci.getOpcode() == Constants.LDCW);
}
@@ -428,9 +372,7 @@
case Constants.BIPUSH:
case Constants.LDC:
_arg = in.readUnsignedByte();
-
break;
-
case Constants.SIPUSH:
case Constants.LDCW:
case Constants.LDC2W:
@@ -445,14 +387,11 @@
case Constants.BIPUSH:
case Constants.LDC:
out.writeByte(_arg);
-
break;
-
case Constants.SIPUSH:
case Constants.LDCW:
case Constants.LDC2W:
out.writeShort(_arg);
-
break;
}
}
@@ -460,72 +399,67 @@
private void calculateOpcode(Object value, boolean wide) {
_arg = -1;
- if (value == null) {
+ if (value == null)
setOpcode(Constants.ACONSTNULL);
- } else if (value instanceof Float) {
+ else if (value instanceof Float) {
float floatVal = ((Float) value).floatValue();
-
- if ((floatVal == 0) || (floatVal == 1) || (floatVal == 2)) {
+ if (floatVal == 0 || floatVal == 1 || floatVal == 2)
setOpcode(Constants.FCONST0 + (int) floatVal);
- } else {
+ else {
_arg = getPool().findFloatEntry((float) floatVal, true);
- setOpcode(((_arg > 255) || wide) ? Constants.LDCW : Constants.LDC);
+ setOpcode((_arg > 255 || wide) ? Constants.LDCW
+ : Constants.LDC);
}
} else if (value instanceof Long) {
long longVal = ((Long) value).longValue();
-
- if ((longVal == 0) || (longVal == 1)) {
+ if (longVal == 0 || longVal == 1)
setOpcode(Constants.LCONST0 + (int) longVal);
- } else {
+ else {
_arg = getPool().findLongEntry(longVal, true);
setOpcode(Constants.LDC2W);
}
} else if (value instanceof Double) {
double doubleVal = ((Double) value).doubleValue();
-
- if ((doubleVal == 0) || (doubleVal == 1)) {
+ if (doubleVal == 0 || doubleVal == 1)
setOpcode(Constants.DCONST0 + (int) doubleVal);
- } else {
+ else {
_arg = getPool().findDoubleEntry(doubleVal, true);
setOpcode(Constants.LDC2W);
}
} else if (value instanceof Integer) {
int intVal = ((Integer) value).intValue();
-
- if ((intVal >= -1) && (intVal <= 5)) {
+ if (intVal >= -1 && intVal <= 5)
setOpcode(Constants.ICONST0 + intVal);
- } else if ((intVal >= -(2 << 6)) && (intVal < (2 << 6))) {
+ else if (intVal >= -(2 << 6) && intVal < (2 << 6)) {
setOpcode(Constants.BIPUSH);
_arg = intVal;
- } else if ((intVal >= -(2 << 14)) && (intVal < (2 << 14))) {
+ } else if (intVal >= -(2 << 14) && intVal < (2 << 14)) {
setOpcode(Constants.SIPUSH);
_arg = intVal;
} else {
_arg = getPool().findIntEntry(intVal, true);
- setOpcode(((_arg > 255) || wide) ? Constants.LDCW : Constants.LDC);
+ setOpcode((_arg > 255 || wide) ? Constants.LDCW
+ : Constants.LDC);
}
} else if (value instanceof String) {
_arg = getPool().findStringEntry((String) value, true);
- setOpcode(((_arg > 255) || wide) ? Constants.LDCW : Constants.LDC);
+ setOpcode((_arg > 255 || wide) ? Constants.LDCW : Constants.LDC);
} else if (value instanceof Class) {
- String name = getProject().getNameCache()
- .getInternalForm(((Class) value).getName(), false);
+ String name = getProject().getNameCache().getInternalForm
+ (((Class) value).getName(), false);
_arg = getPool().findClassEntry(name, true);
setOpcode(Constants.LDCW);
} else if (value instanceof BCClass) {
BCClass bc = (BCClass) value;
- ClassEntry entry = (ClassEntry) bc.getPool().getEntry(bc.getIndex());
-
- if (bc.getPool() == getPool()) {
+ ClassEntry entry = (ClassEntry) bc.getPool().
+ getEntry(bc.getIndex());
+ if (bc.getPool() == getPool())
_arg = getPool().indexOf(entry);
- } else {
- _arg = getPool()
- .findClassEntry((String) entry.getConstant(), true);
- }
-
+ else
+ _arg = getPool().findClassEntry((String) entry.getConstant(),
+ true);
setOpcode(Constants.LDCW);
- } else {
+ } else
throw new IllegalArgumentException(String.valueOf(value));
- }
}
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantValue.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantValue.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConstantValue.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,17 +12,14 @@
*/
package serp.bytecode;
+import java.io.*;
import serp.bytecode.lowlevel.*;
-
import serp.bytecode.visitor.*;
-import java.io.*;
-
-
/**
- * <p>A constant value for a member field.</p>
- *
- * @author Abe White
+ * A constant value for a member field.
+ *
+ * @author Abe White
*/
public class ConstantValue extends Attribute {
int _valueIndex = 0;
@@ -39,206 +33,178 @@
}
/**
- * Return the owning field.
- */
+ * Return the owning field.
+ */
public BCField getField() {
- return (BCField) getOwner();
+ return(BCField) getOwner();
}
/**
- * Return the {@link ConstantPool} index of the {@link ConstantEntry}
- * holding the value of this constant. Defaults to 0.
+ * Return the {@link ConstantPool} index of the {@link ConstantEntry}
+ * holding the value of this constant. Defaults to 0.
*/
public int getValueIndex() {
return _valueIndex;
}
/**
- * Set the {@link ConstantPool} of the {@link ConstantEntry}
- * holding the value of this constant.
+ * Set the {@link ConstantPool} of the {@link ConstantEntry}
+ * holding the value of this constant.
*/
public void setValueIndex(int valueIndex) {
_valueIndex = valueIndex;
}
/**
- * Return the type of constant this attribute represents, or null if
- * not set.
+ * Return the type of constant this attribute represents, or null if
+ * not set.
*/
public String getTypeName() {
Class type = getType();
-
- if (type == null) {
+ if (type == null)
return null;
- }
-
return type.getName();
}
/**
- * Return the type of constant this attribute represents (String.class,
- * int.class, etc), or null if not set.
+ * Return the type of constant this attribute represents(String.class,
+ * int.class, etc), or null if not set.
*/
public Class getType() {
Object value = getValue();
-
- if (value == null) {
+ if (value == null)
return null;
- }
Class type = value.getClass();
-
- if (type == Integer.class) {
+ if (type == Integer.class)
return int.class;
- }
-
- if (type == Float.class) {
+ if (type == Float.class)
return float.class;
- }
-
- if (type == Double.class) {
+ if (type == Double.class)
return double.class;
- }
-
- if (type == Long.class) {
+ if (type == Long.class)
return long.class;
- }
-
return String.class;
}
/**
- * Return the bytecode for the type of constant this attribute
- * represents.
+ * Return the bytecode for the type of constant this attribute represents.
*/
public BCClass getTypeBC() {
return getProject().loadClass(getType());
}
/**
- * Return the value of this constant as an Object of the appropriate
- * type (String, Integer, Double, etc), or null if not set.
+ * Return the value of this constant as an Object of the appropriate
+ * type(String, Integer, Double, etc), or null if not set.
*/
public Object getValue() {
- if (_valueIndex <= 0) {
+ if (_valueIndex <= 0)
return null;
- }
-
- return ((ConstantEntry) getPool().getEntry(_valueIndex)).getConstant();
+ return((ConstantEntry) getPool().getEntry(_valueIndex)). getConstant();
}
/**
- * Set the value of this constant using the appropriate wrapper Object
- * type (String, Integer, Double, etc). Types that are not directly
- * supported will be converted accordingly if possible.
+ * Set the value of this constant using the appropriate wrapper Object
+ * type(String, Integer, Double, etc). Types that are not directly
+ * supported will be converted accordingly if possible.
*/
public void setValue(Object value) {
Class type = value.getClass();
- if (type == Boolean.class) {
+ if (type == Boolean.class)
setIntValue((((Boolean) value).booleanValue()) ? 1 : 0);
- } else if (type == Character.class) {
+ else if (type == Character.class)
setIntValue((int) ((Character) value).charValue());
- } else if ((type == Byte.class) || (type == Integer.class) ||
- (type == Short.class)) {
+ else if (type == Byte.class || type == Integer.class
+ || type == Short.class)
setIntValue(((Number) value).intValue());
- } else if (type == Float.class) {
+ else if (type == Float.class)
setFloatValue(((Number) value).floatValue());
- } else if (type == Double.class) {
+ else if (type == Double.class)
setDoubleValue(((Number) value).doubleValue());
- } else if (type == Long.class) {
+ else if (type == Long.class)
setLongValue(((Number) value).longValue());
- } else {
+ else
setStringValue(value.toString());
- }
}
/**
- * Get the value of this int constant, or 0 if not set.
+ * Get the value of this int constant, or 0 if not set.
*/
public int getIntValue() {
- if (getValueIndex() <= 0) {
+ if (getValueIndex() <= 0)
return 0;
- }
-
- return ((IntEntry) getPool().getEntry(getValueIndex())).getValue();
+ return((IntEntry) getPool().getEntry(getValueIndex())).getValue();
}
/**
- * Set the value of this int constant.
+ * Set the value of this int constant.
*/
public void setIntValue(int value) {
setValueIndex(getPool().findIntEntry(value, true));
}
/**
- * Get the value of this float constant.
+ * Get the value of this float constant.
*/
public float getFloatValue() {
- if (getValueIndex() <= 0) {
+ if (getValueIndex() <= 0)
return 0F;
- }
-
- return ((FloatEntry) getPool().getEntry(getValueIndex())).getValue();
+ return((FloatEntry) getPool().getEntry(getValueIndex())).getValue();
}
/**
- * Set the value of this float constant.
+ * Set the value of this float constant.
*/
public void setFloatValue(float value) {
setValueIndex(getPool().findFloatEntry(value, true));
}
/**
- * Get the value of this double constant.
+ * Get the value of this double constant.
*/
public double getDoubleValue() {
- if (getValueIndex() <= 0) {
+ if (getValueIndex() <= 0)
return 0D;
- }
-
- return ((DoubleEntry) getPool().getEntry(getValueIndex())).getValue();
+ return((DoubleEntry) getPool().getEntry(getValueIndex())). getValue();
}
/**
- * Set the value of this double constant.
+ * Set the value of this double constant.
*/
public void setDoubleValue(double value) {
setValueIndex(getPool().findDoubleEntry(value, true));
}
/**
- * Get the value of this long constant.
+ * Get the value of this long constant.
*/
public long getLongValue() {
- if (getValueIndex() <= 0) {
+ if (getValueIndex() <= 0)
return 0L;
- }
-
- return ((LongEntry) getPool().getEntry(getValueIndex())).getValue();
+ return((LongEntry) getPool().getEntry(getValueIndex())).getValue();
}
/**
- * Set the value of this long constant.
+ * Set the value of this long constant.
*/
public void setLongValue(long value) {
setValueIndex(getPool().findLongEntry(value, true));
}
/**
- * Get the value of this string constant.
+ * Get the value of this string constant.
*/
public String getStringValue() {
- if (getValueIndex() <= 0) {
+ if (getValueIndex() <= 0)
return null;
- }
-
- return ((StringEntry) getPool().getEntry(getValueIndex())).getStringEntry()
- .getValue();
+ return((StringEntry) getPool().getEntry(getValueIndex())).
+ getStringEntry().getValue();
}
/**
- * Set the value of this string constant.
+ * Set the value of this string constant.
*/
public void setStringValue(String value) {
setValueIndex(getPool().findStringEntry(value, true));
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Constants.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Constants.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Constants.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Constants.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,14 +12,13 @@
*/
package serp.bytecode;
-
/**
- * <p>Interface to track constants used in bytecode. Entities can access these
- * constants using the static <code>Constants.</code> field prefix,
- * or implement this interface themselves to conveniently import the
- * constants into their own namespace.</p>
- *
- * @author Abe White
+ * Interface to track constants used in bytecode. Entities can access these
+ * constants using the static <code>Constants.</code> field prefix,
+ * or implement this interface themselves to conveniently import the
+ * constants into their own namespace.
+ *
+ * @author Abe White
*/
public interface Constants {
// class magic number
@@ -289,36 +285,33 @@
// human-readable opcode names
public static final String[] OPCODE_NAMES = new String[] {
- "nop", "aconstnull", "iconstm1", "iconst0", "iconst1", "iconst2",
- "iconst3", "iconst4", "iconst5", "lconst0", "lconst1", "fconst0",
- "fconst1", "fconst2", "dconst0", "dconst1", "bipush", "sipush",
- "ldc", "ldcw", "ldc2w", "iload", "lload", "fload", "dload", "aload",
- "iload0", "iload1", "iload2", "iload3", "lload0", "lload1", "lload2",
- "lload3", "fload0", "fload1", "fload2", "fload3", "dload0", "dload1",
- "dload2", "dload3", "aload0", "aload1", "aload2", "aload3", "iaload",
- "laload", "faload", "daload", "aaload", "baload", "caload", "saload",
- "istore", "lstore", "fstore", "dstore", "astore", "istore0",
- "istore1", "istore2", "istore3", "lstore0", "lstore1", "lstore2",
- "lstore3", "fstore0", "fstore1", "fstore2", "fstore3", "dstore0",
- "dstore1", "dstore2", "dstore3", "astore0", "astore1", "astore2",
- "astore3", "iastore", "lastore", "fastore", "dastore", "aastore",
- "bastore", "castore", "sastore", "pop", "pop2", "dup", "dupx1",
- "dupx2", "dup2", "dup2x1", "dup2x2", "swap", "iadd", "ladd", "fadd",
- "dadd", "isub", "lsub", "fsub", "dsub", "imul", "lmul", "fmul",
- "dmul", "idiv", "ldiv", "fdiv", "ddiv", "irem", "lrem", "frem",
- "drem", "ineg", "lneg", "fneg", "dneg", "ishl", "lshl", "ishr",
- "lshr", "iushr", "lushr", "iand", "land", "ior", "lor", "ixor",
- "lxor", "iinc", "i2l", "i2f", "i2d", "l2i", "l2f", "l2d", "f2i",
- "f2l", "f2d", "d2i", "d2l", "d2f", "i2b", "i2c", "i2s", "lcmp",
- "fcmpl", "fcmpg", "dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge",
- "ifgt", "ifle", "ificmpeq", "ificmpne", "ificmplt", "ificmpge",
- "ificmpgt", "ificmple", "ifacmpeq", "ifacmpne", "goto", "jsr", "ret",
- "tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn",
- "dreturn", "areturn", "return", "getstatic", "putstatic", "getfield",
- "putfield", "invokevirtual", "invokespecial", "invokestatic",
- "invokeinterface", "??", "new", "newarray", "anewarray",
- "arraylength", "athrow", "checkcast", "instanceof", "monitorenter",
- "monitorexit", "wide", "multianewarray", "ifnull", "ifnonnull",
- "gotow", "jsrw",
- };
+ "nop", "aconstnull", "iconstm1", "iconst0", "iconst1", "iconst2",
+ "iconst3", "iconst4", "iconst5", "lconst0", "lconst1", "fconst0",
+ "fconst1", "fconst2", "dconst0", "dconst1", "bipush", "sipush", "ldc",
+ "ldcw", "ldc2w", "iload", "lload", "fload", "dload", "aload", "iload0",
+ "iload1", "iload2", "iload3", "lload0", "lload1", "lload2", "lload3",
+ "fload0", "fload1", "fload2", "fload3", "dload0", "dload1", "dload2",
+ "dload3", "aload0", "aload1", "aload2", "aload3", "iaload", "laload",
+ "faload", "daload", "aaload", "baload", "caload", "saload", "istore",
+ "lstore", "fstore", "dstore", "astore", "istore0", "istore1", "istore2",
+ "istore3", "lstore0", "lstore1", "lstore2", "lstore3", "fstore0",
+ "fstore1", "fstore2", "fstore3", "dstore0", "dstore1", "dstore2",
+ "dstore3", "astore0", "astore1", "astore2", "astore3", "iastore",
+ "lastore", "fastore", "dastore", "aastore", "bastore", "castore",
+ "sastore", "pop", "pop2", "dup", "dupx1", "dupx2", "dup2", "dup2x1",
+ "dup2x2", "swap", "iadd", "ladd", "fadd", "dadd", "isub", "lsub",
+ "fsub", "dsub", "imul", "lmul", "fmul", "dmul", "idiv", "ldiv", "fdiv",
+ "ddiv", "irem", "lrem", "frem", "drem", "ineg", "lneg", "fneg", "dneg",
+ "ishl", "lshl", "ishr", "lshr", "iushr", "lushr", "iand", "land", "ior",
+ "lor", "ixor", "lxor", "iinc", "i2l", "i2f", "i2d", "l2i", "l2f", "l2d",
+ "f2i", "f2l", "f2d", "d2i", "d2l", "d2f", "i2b", "i2c", "i2s", "lcmp",
+ "fcmpl", "fcmpg", "dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge",
+ "ifgt", "ifle", "ificmpeq", "ificmpne", "ificmplt", "ificmpge",
+ "ificmpgt", "ificmple", "ifacmpeq", "ifacmpne", "goto", "jsr", "ret",
+ "tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn",
+ "dreturn", "areturn", "return", "getstatic", "putstatic", "getfield",
+ "putfield", "invokevirtual", "invokespecial", "invokestatic",
+ "invokeinterface", "??", "new", "newarray", "anewarray", "arraylength",
+ "athrow", "checkcast", "instanceof", "monitorenter", "monitorexit",
+ "wide", "multianewarray", "ifnull", "ifnonnull", "gotow", "jsrw", };
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConvertInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConvertInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConvertInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ConvertInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,35 +12,27 @@
*/
package serp.bytecode;
+import java.util.*;
import serp.bytecode.visitor.*;
-
import serp.util.*;
-import java.util.*;
-
-
/**
- * <p>A conversion opcode such as <code>i2l, f2i</code>, etc.
- * Changing the types of the instruction will automatically
- * update the underlying opcode. Converting from one type to the same
- * type will result in a <code>nop</code>.</p>
- *
- * @author Abe White
+ * A conversion opcode such as <code>i2l, f2i</code>, etc.
+ * Changing the types of the instruction will automatically
+ * update the underlying opcode. Converting from one type to the same
+ * type will result in a <code>nop</code>.
+ *
+ * @author Abe White
*/
public class ConvertInstruction extends TypedInstruction {
private static final Class[][] _mappings = new Class[][] {
- { boolean.class, int.class },
- { void.class, int.class },
- { Object.class, int.class },
- };
+ { boolean.class, int.class }, { void.class, int.class },
+ { Object.class, int.class }, };
private static final Class[][] _fromMappings = new Class[][] {
- { boolean.class, int.class },
- { void.class, int.class },
- { Object.class, int.class },
- { byte.class, int.class },
- { char.class, int.class },
- { short.class, int.class },
- };
+ { boolean.class, int.class }, { void.class, int.class },
+ { Object.class, int.class }, { byte.class, int.class },
+ { char.class, int.class }, { short.class, int.class }, };
+
String _toType = null;
String _fromType = null;
@@ -66,13 +55,11 @@
case Constants.F2L:
case Constants.F2D:
return 1;
-
case Constants.L2I:
case Constants.L2F:
case Constants.D2I:
case Constants.D2F:
return -1;
-
default:
return 0;
}
@@ -84,31 +71,24 @@
case Constants.F2I:
case Constants.D2I:
return int.class.getName();
-
case Constants.I2L:
case Constants.F2L:
case Constants.D2L:
return long.class.getName();
-
case Constants.I2F:
case Constants.L2F:
case Constants.D2F:
return float.class.getName();
-
case Constants.I2D:
case Constants.L2D:
case Constants.F2D:
return double.class.getName();
-
case Constants.I2B:
return byte.class.getName();
-
case Constants.I2C:
return char.class.getName();
-
case Constants.I2S:
return short.class.getName();
-
default:
return _toType;
}
@@ -120,11 +100,10 @@
// if no valid opcode, remember current types in case they reset one
// to create a valid opcode
- if ((toType == null) || (fromType == null) || toType.equals(fromType)) {
+ if (toType == null || fromType == null || toType.equals(fromType)) {
_toType = toType;
_fromType = fromType;
-
- return (TypedInstruction) setOpcode(Constants.NOP);
+ return(TypedInstruction) setOpcode(Constants.NOP);
}
// ok, valid conversion possible, forget saved types
@@ -136,83 +115,58 @@
switch (to) {
case 'i':
-
switch (from) {
case 'l':
- return (TypedInstruction) setOpcode(Constants.L2I);
-
+ return(TypedInstruction) setOpcode(Constants.L2I);
case 'f':
- return (TypedInstruction) setOpcode(Constants.F2I);
-
+ return(TypedInstruction) setOpcode(Constants.F2I);
case 'd':
- return (TypedInstruction) setOpcode(Constants.D2I);
+ return(TypedInstruction) setOpcode(Constants.D2I);
}
-
case 'l':
-
switch (from) {
case 'i':
- return (TypedInstruction) setOpcode(Constants.I2L);
-
+ return(TypedInstruction) setOpcode(Constants.I2L);
case 'f':
- return (TypedInstruction) setOpcode(Constants.F2L);
-
+ return(TypedInstruction) setOpcode(Constants.F2L);
case 'd':
- return (TypedInstruction) setOpcode(Constants.D2L);
+ return(TypedInstruction) setOpcode(Constants.D2L);
}
-
case 'f':
-
switch (from) {
case 'i':
- return (TypedInstruction) setOpcode(Constants.I2F);
-
+ return(TypedInstruction) setOpcode(Constants.I2F);
case 'l':
- return (TypedInstruction) setOpcode(Constants.L2F);
-
+ return(TypedInstruction) setOpcode(Constants.L2F);
case 'd':
- return (TypedInstruction) setOpcode(Constants.D2F);
+ return(TypedInstruction) setOpcode(Constants.D2F);
}
-
case 'd':
-
switch (from) {
case 'i':
- return (TypedInstruction) setOpcode(Constants.I2D);
-
+ return(TypedInstruction) setOpcode(Constants.I2D);
case 'l':
- return (TypedInstruction) setOpcode(Constants.L2D);
-
+ return(TypedInstruction) setOpcode(Constants.L2D);
case 'f':
- return (TypedInstruction) setOpcode(Constants.F2D);
+ return(TypedInstruction) setOpcode(Constants.F2D);
}
-
case 'b':
-
- if (from == 'i') {
- return (TypedInstruction) setOpcode(Constants.I2B);
- }
-
+ if (from == 'i')
+ return(TypedInstruction) setOpcode(Constants.I2B);
case 'C':
-
- if (from == 'i') {
- return (TypedInstruction) setOpcode(Constants.I2C);
- }
-
+ if (from == 'i')
+ return(TypedInstruction) setOpcode(Constants.I2C);
case 'S':
-
- if (from == 'i') {
- return (TypedInstruction) setOpcode(Constants.I2S);
- }
-
+ if (from == 'i')
+ return(TypedInstruction) setOpcode(Constants.I2S);
default:
throw new IllegalStateException();
}
}
/**
- * Return the name of the type being converted from.
- * If neither type has been set, this method will return null.
+ * Return the name of the type being converted from.
+ * If neither type has been set, this method will return null.
*/
public String getFromTypeName() {
switch (getOpcode()) {
@@ -223,60 +177,50 @@
case Constants.I2S:
case Constants.I2C:
return int.class.getName();
-
case Constants.L2I:
case Constants.L2F:
case Constants.L2D:
return long.class.getName();
-
case Constants.F2I:
case Constants.F2L:
case Constants.F2D:
return float.class.getName();
-
case Constants.D2I:
case Constants.D2L:
case Constants.D2F:
return double.class.getName();
-
default:
return _fromType;
}
}
/**
- * Return the {@link Class} of the type being converted from.
- * If neither type has been set, this method will return null.
+ * Return the {@link Class} of the type being converted from.
+ * If neither type has been set, this method will return null.
*/
public Class getFromType() {
String type = getFromTypeName();
-
- if (type == null) {
+ if (type == null)
return null;
- }
-
return Strings.toClass(type, getClassLoader());
}
/**
- * Return the bytecode of the type being converted from.
- * If neither type has been set, this method will return null.
+ * Return the bytecode of the type being converted from.
+ * If neither type has been set, this method will return null.
*/
public BCClass getFromTypeBC() {
String type = getFromTypeName();
-
- if (type == null) {
+ if (type == null)
return null;
- }
-
return getProject().loadClass(type, getClassLoader());
}
/**
- * Set the type being converted from. Types that have no direct
- * support will be converted accordingly.
- *
- * @return this instruction, for method chaining
+ * Set the type being converted from. Types that have no direct
+ * support will be converted accordingly.
+ *
+ * @return this instruction, for method chaining
*/
public ConvertInstruction setFromType(String type) {
String fromType = mapType(type, _fromMappings, true);
@@ -284,11 +228,10 @@
// if no valid opcode, remember current types in case they reset one
// to create a valid opcode
- if ((toType == null) || (fromType == null) || toType.equals(fromType)) {
+ if (toType == null || fromType == null || toType.equals(fromType)) {
_toType = toType;
_fromType = fromType;
-
- return (ConvertInstruction) setOpcode(Constants.NOP);
+ return(ConvertInstruction) setOpcode(Constants.NOP);
}
// ok, valid conversion possible, forget saved types
@@ -300,129 +243,98 @@
switch (from) {
case 'i':
-
switch (to) {
case 'l':
- return (ConvertInstruction) setOpcode(Constants.I2L);
-
+ return(ConvertInstruction) setOpcode(Constants.I2L);
case 'f':
- return (ConvertInstruction) setOpcode(Constants.I2F);
-
+ return(ConvertInstruction) setOpcode(Constants.I2F);
case 'd':
- return (ConvertInstruction) setOpcode(Constants.I2D);
-
+ return(ConvertInstruction) setOpcode(Constants.I2D);
case 'b':
- return (ConvertInstruction) setOpcode(Constants.I2B);
-
+ return(ConvertInstruction) setOpcode(Constants.I2B);
case 'c':
- return (ConvertInstruction) setOpcode(Constants.I2C);
-
+ return(ConvertInstruction) setOpcode(Constants.I2C);
case 's':
- return (ConvertInstruction) setOpcode(Constants.I2S);
+ return(ConvertInstruction) setOpcode(Constants.I2S);
}
-
case 'l':
-
switch (to) {
case 'i':
- return (ConvertInstruction) setOpcode(Constants.L2I);
-
+ return(ConvertInstruction) setOpcode(Constants.L2I);
case 'f':
- return (ConvertInstruction) setOpcode(Constants.L2F);
-
+ return(ConvertInstruction) setOpcode(Constants.L2F);
case 'd':
- return (ConvertInstruction) setOpcode(Constants.L2D);
+ return(ConvertInstruction) setOpcode(Constants.L2D);
}
-
case 'f':
-
switch (to) {
case 'i':
- return (ConvertInstruction) setOpcode(Constants.F2I);
-
+ return(ConvertInstruction) setOpcode(Constants.F2I);
case 'l':
- return (ConvertInstruction) setOpcode(Constants.F2L);
-
+ return(ConvertInstruction) setOpcode(Constants.F2L);
case 'd':
- return (ConvertInstruction) setOpcode(Constants.F2D);
+ return(ConvertInstruction) setOpcode(Constants.F2D);
}
-
case 'd':
-
switch (to) {
case 'i':
- return (ConvertInstruction) setOpcode(Constants.D2I);
-
+ return(ConvertInstruction) setOpcode(Constants.D2I);
case 'l':
- return (ConvertInstruction) setOpcode(Constants.D2L);
-
+ return(ConvertInstruction) setOpcode(Constants.D2L);
case 'f':
- return (ConvertInstruction) setOpcode(Constants.D2F);
+ return(ConvertInstruction) setOpcode(Constants.D2F);
}
-
default:
throw new IllegalStateException();
}
}
/**
- * Set the type being converted from. Types that have no direct
- * support will be converted accordingly.
- *
- * @return this instruction, for method chaining
+ * Set the type being converted from. Types that have no direct
+ * support will be converted accordingly.
+ *
+ * @return this instruction, for method chaining
*/
public ConvertInstruction setFromType(Class type) {
- if (type == null) {
+ if (type == null)
return setFromType((String) null);
- }
-
return setFromType(type.getName());
}
/**
- * Set the type being converted from. Types that have no direct
- * support will be converted accordingly.
- *
- * @return this instruction, for method chaining
+ * Set the type being converted from. Types that have no direct
+ * support will be converted accordingly.
+ *
+ * @return this instruction, for method chaining
*/
public ConvertInstruction setFromType(BCClass type) {
- if (type == null) {
+ if (type == null)
return setFromType((String) null);
- }
-
return setFromType(type.getName());
}
/**
- * ConvertInstructions are equal if the types they convert between are
- * either equal or unset.
+ * ConvertInstructions are equal if the types they convert between are
+ * either equal or unset.
*/
public boolean equalsInstruction(Instruction other) {
- if (other == this) {
+ if (other == this)
return true;
- }
-
- if (!(other instanceof ConvertInstruction)) {
+ if (!(other instanceof ConvertInstruction))
return false;
- }
ConvertInstruction ins = (ConvertInstruction) other;
-
- if ((getOpcode() != Constants.NOP) && (getOpcode() == ins.getOpcode())) {
+ if (getOpcode() != Constants.NOP && getOpcode() == ins.getOpcode())
return true;
- }
String type = getTypeName();
String otherType = ins.getTypeName();
-
- if (!((type == null) || (otherType == null) || type.equals(otherType))) {
+ if (!(type == null || otherType == null || type.equals(otherType)))
return false;
- }
type = getFromTypeName();
otherType = ins.getFromTypeName();
-
- return (type == null) || (otherType == null) || type.equals(otherType);
+ return type == null || otherType == null || type.equals(otherType);
}
public void acceptVisit(BCVisitor visit) {
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Deprecated.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Deprecated.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Deprecated.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Deprecated.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -17,11 +14,10 @@
import serp.bytecode.visitor.*;
-
/**
- * <p>Attribute signifying that a method or class is deprecated.</p>
- *
- * @author Abe White
+ * Attribute signifying that a method or class is deprecated.
+ *
+ * @author Abe White
*/
public class Deprecated extends Attribute {
Deprecated(int nameIndex, Attributes owner) {
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ExceptionHandler.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ExceptionHandler.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/ExceptionHandler.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,36 +12,32 @@
*/
package serp.bytecode;
+import java.io.*;
+import java.util.*;
import serp.bytecode.lowlevel.*;
-
import serp.bytecode.visitor.*;
-
import serp.util.*;
-import java.io.*;
-
-import java.util.*;
-
-
/**
- * <p>Represents a <code>try {} catch() {}</code> statement in bytecode.</p>
- *
- * @author Abe White
+ * Represents a <code>try {} catch() {}</code> statement in bytecode.
+ *
+ * @author Abe White
*/
-public class ExceptionHandler implements InstructionPtr, BCEntity,
- VisitAcceptor {
+public class ExceptionHandler implements InstructionPtr, BCEntity, VisitAcceptor {
private int _catchIndex = 0;
private Code _owner = null;
+
private InstructionPtrStrategy _tryStart = new InstructionPtrStrategy(this);
private InstructionPtrStrategy _tryEnd = new InstructionPtrStrategy(this);
- private InstructionPtrStrategy _tryHandler = new InstructionPtrStrategy(this);
+ private InstructionPtrStrategy _tryHandler =
+ new InstructionPtrStrategy(this);
ExceptionHandler(Code owner) {
_owner = owner;
}
/**
- * Return the owning code block.
+ * Return the owning code block.
*/
public Code getCode() {
return _owner;
@@ -55,30 +48,30 @@
///////////////////
/**
- * Return the instruction marking the beginning of the try {} block.
+ * Return the instruction marking the beginning of the try {} block.
*/
public Instruction getTryStart() {
return _tryStart.getTargetInstruction();
}
/**
- * Set the {@link Instruction} marking the beginning of the try block.
- * The instruction must already be a part of the method.
+ * Set the {@link Instruction} marking the beginning of the try block.
+ * The instruction must already be a part of the method.
*/
public void setTryStart(Instruction instruction) {
_tryStart.setTargetInstruction(instruction);
}
/**
- * Return the instruction at the end of the try {} block.
+ * Return the instruction at the end of the try {} block.
*/
public Instruction getTryEnd() {
return _tryEnd.getTargetInstruction();
}
/**
- * Set the Instruction at the end of the try block. The
- * Instruction must already be a part of the method.
+ * Set the Instruction at the end of the try block. The
+ * Instruction must already be a part of the method.
*/
public void setTryEnd(Instruction instruction) {
_tryEnd.setTargetInstruction(instruction);
@@ -89,16 +82,16 @@
//////////////////////
/**
- * Return the instruction marking the beginning of the catch {} block.
+ * Return the instruction marking the beginning of the catch {} block.
*/
public Instruction getHandlerStart() {
return _tryHandler.getTargetInstruction();
}
/**
- * Set the {@link Instruction} marking the beginning of the catch block.
- * The instruction must already be a part of the method.
- * WARNING: if this instruction is deleted, the results are undefined.
+ * Set the {@link Instruction} marking the beginning of the catch block.
+ * The instruction must already be a part of the method.
+ * WARNING: if this instruction is deleted, the results are undefined.
*/
public void setHandlerStart(Instruction instruction) {
_tryHandler.setTargetInstruction(instruction);
@@ -109,107 +102,95 @@
////////////////////
/**
- * Return the index into the class {@link ConstantPool} of the
- * {@link ClassEntry} describing the exception type this handler catches.
+ * Return the index into the class {@link ConstantPool} of the
+ * {@link ClassEntry} describing the exception type this handler catches.
*/
public int getCatchIndex() {
return _catchIndex;
}
/**
- * Set the index into the class {@link ConstantPool} of the
- * {@link ClassEntry} describing the exception type this handler catches.
+ * Set the index into the class {@link ConstantPool} of the
+ * {@link ClassEntry} describing the exception type this handler catches.
*/
public void setCatchIndex(int catchTypeIndex) {
_catchIndex = catchTypeIndex;
}
/**
- * Return the name of the exception type; returns null for catch-all
- * clauses used to implement finally blocks. The name will be returned
- * in a forum suitable for a {@link Class#forName} call.
+ * Return the name of the exception type; returns null for catch-all
+ * clauses used to implement finally blocks. The name will be returned
+ * in a forum suitable for a {@link Class#forName} call.
*/
public String getCatchName() {
- if (_catchIndex == 0) {
+ if (_catchIndex == 0)
return null;
- }
ClassEntry entry = (ClassEntry) getPool().getEntry(_catchIndex);
-
- return getProject().getNameCache()
- .getExternalForm(entry.getNameEntry().getValue(), false);
+ return getProject().getNameCache().getExternalForm
+ (entry.getNameEntry().getValue(), false);
}
/**
- * Return the {@link Class} of the exception type; returns null for
- * catch-all clauses used to implement finally blocks.
+ * Return the {@link Class} of the exception type; returns null for
+ * catch-all clauses used to implement finally blocks.
*/
public Class getCatchType() {
String name = getCatchName();
-
- if (name == null) {
+ if (name == null)
return null;
- }
-
return Strings.toClass(name, getClassLoader());
}
/**
- * Return the bytecode of the exception type; returns null for
- * catch-all clauses used to implement finally blocks.
+ * Return the bytecode of the exception type; returns null for
+ * catch-all clauses used to implement finally blocks.
*/
public BCClass getCatchBC() {
String name = getCatchName();
-
- if (name == null) {
+ if (name == null)
return null;
- }
-
return getProject().loadClass(name, getClassLoader());
}
/**
- * Set the class of the exception type, or null for catch-all clauses used
- * with finally blocks.
+ * Set the class of the exception type, or null for catch-all clauses used
+ * with finally blocks.
*/
public void setCatch(String name) {
- if (name == null) {
+ if (name == null)
_catchIndex = 0;
- } else {
- _catchIndex = getPool()
- .findClassEntry(getProject().getNameCache()
- .getInternalForm(name, false),
- true);
- }
+ else
+ _catchIndex = getPool().findClassEntry(getProject().
+ getNameCache().getInternalForm(name, false), true);
}
/**
- * Set the class of the exception type, or null for catch-all clauses used
- * for finally blocks.
+ * Set the class of the exception type, or null for catch-all clauses used
+ * for finally blocks.
*/
public void setCatch(Class type) {
- if (type == null) {
+ if (type == null)
setCatch((String) null);
- } else {
+ else
setCatch(type.getName());
- }
}
/**
- * Set the class of the exception type, or null for catch-all clauses used
- * for finally blocks.
+ * Set the class of the exception type, or null for catch-all clauses used
+ * for finally blocks.
*/
public void setCatch(BCClass type) {
- if (type == null) {
+ if (type == null)
setCatch((String) null);
- } else {
+ else
setCatch(type.getName());
- }
}
/////////////////////////////////
// InstructionPtr implementation
/////////////////////////////////
+
public void updateTargets() {
_tryStart.updateTargets();
_tryEnd.updateTargets();
@@ -225,6 +206,7 @@
///////////////////////////
// BCEntity implementation
///////////////////////////
+
public Project getProject() {
return _owner.getProject();
}
@@ -244,6 +226,7 @@
////////////////////////////////
// VisitAcceptor implementation
////////////////////////////////
+
public void acceptVisit(BCVisitor visit) {
visit.enterExceptionHandler(this);
visit.exitExceptionHandler(this);
@@ -252,6 +235,7 @@
//////////////////
// I/O operations
//////////////////
+
void read(ExceptionHandler orig) {
_tryStart.setByteIndex(orig._tryStart.getByteIndex());
_tryEnd.setByteIndex(orig._tryEnd.getByteIndex());
@@ -289,8 +273,8 @@
}
/**
- * Return the program counter end position for this exception handler.
- * This represents an index into the code byte array.
+ * Return the program counter end position for this exception handler.
+ * This represents an index into the code byte array.
*/
public int getTryEndPc() {
return _tryEnd.getByteIndex() + getTryEnd().getLength();
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Exceptions.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Exceptions.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Exceptions.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Exceptions.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,21 +12,16 @@
*/
package serp.bytecode;
+import java.io.*;
+import java.util.*;
import serp.bytecode.lowlevel.*;
-
import serp.bytecode.visitor.*;
-
import serp.util.*;
-import java.io.*;
-
-import java.util.*;
-
-
/**
- * <p>Attribute declaring the checked exceptions a method can throw.</p>
- *
- * @author Abe White
+ * Attribute declaring the checked exceptions a method can throw.
+ *
+ * @author Abe White
*/
public class Exceptions extends Attribute {
private List _indexes = new LinkedList();
@@ -39,267 +31,231 @@
}
int getLength() {
- return 2 + (2 * _indexes.size());
+ return 2 + 2 * _indexes.size();
}
/**
- * Return the owning method.
+ * Return the owning method.
*/
public BCMethod getMethod() {
- return (BCMethod) getOwner();
+ return(BCMethod) getOwner();
}
/**
- * Return the indexes in the class {@link ConstantPool} of the
- * {@link ClassEntry}s for the exception types thrown by this method, or
- * an empty array if none.
+ * Return the indexes in the class {@link ConstantPool} of the
+ * {@link ClassEntry}s for the exception types thrown by this method, or
+ * an empty array if none.
*/
public int[] getExceptionIndexes() {
int[] indexes = new int[_indexes.size()];
Iterator itr = _indexes.iterator();
-
for (int i = 0; i < indexes.length; i++)
indexes[i] = ((Integer) itr.next()).intValue();
-
return indexes;
}
/**
- * Set the indexes in the class {@link ConstantPool} of the
- * {@link ClassEntry}s for the exception types thrown by this method. Use
- * null or an empty array for none.
+ * Set the indexes in the class {@link ConstantPool} of the
+ * {@link ClassEntry}s for the exception types thrown by this method. Use
+ * null or an empty array for none.
*/
public void setExceptionIndexes(int[] exceptionIndexes) {
_indexes.clear();
-
- if (exceptionIndexes != null) {
+ if (exceptionIndexes != null)
for (int i = 0; i < exceptionIndexes.length; i++)
_indexes.add(Numbers.valueOf(exceptionIndexes[i]));
- }
}
/**
- * Return the names of the exception types for this method, or an empty
- * array if none. The names will be in a form suitable for a
- * {@link Class#forName} call.
+ * Return the names of the exception types for this method, or an empty
+ * array if none. The names will be in a form suitable for a
+ * {@link Class#forName} call.
*/
public String[] getExceptionNames() {
String[] names = new String[_indexes.size()];
Iterator itr = _indexes.iterator();
int index;
ClassEntry entry;
-
for (int i = 0; i < names.length; i++) {
index = ((Number) itr.next()).intValue();
entry = (ClassEntry) getPool().getEntry(index);
- names[i] = getProject().getNameCache()
- .getExternalForm(entry.getNameEntry().getValue(),
- false);
+ names[i] = getProject().getNameCache().getExternalForm
+ (entry.getNameEntry().getValue(), false);
}
-
return names;
}
/**
- * Return the {@link Class} objects for the exception types for this
- * method, or an empty array if none.
+ * Return the {@link Class} objects for the exception types for this
+ * method, or an empty array if none.
*/
public Class[] getExceptionTypes() {
String[] names = getExceptionNames();
Class[] types = new Class[names.length];
-
for (int i = 0; i < names.length; i++)
types[i] = Strings.toClass(names[i], getClassLoader());
-
return types;
}
/**
- * Return bytecode for the exception types of this
- * method, or an empty array if none.
+ * Return bytecode for the exception types of this
+ * method, or an empty array if none.
*/
public BCClass[] getExceptionBCs() {
String[] names = getExceptionNames();
BCClass[] types = new BCClass[names.length];
-
for (int i = 0; i < names.length; i++)
types[i] = getProject().loadClass(names[i], getClassLoader());
-
return types;
}
/**
- * Set the checked exceptions thrown by this method. Use null or an
- * empty array for none.
+ * Set the checked exceptions thrown by this method. Use null or an
+ * empty array for none.
*/
public void setExceptions(String[] exceptions) {
- if (exceptions != null) {
+ if (exceptions != null)
for (int i = 0; i < exceptions.length; i++)
- if (exceptions[i] == null) {
- throw new NullPointerException("exceptions[" + i +
- "] = null");
- }
- }
+ if (exceptions[i] == null)
+ throw new NullPointerException("exceptions[" + i
+ + "] = null");
clear();
-
- if (exceptions != null) {
+ if (exceptions != null)
for (int i = 0; i < exceptions.length; i++)
addException(exceptions[i]);
- }
}
/**
- * Set the checked exceptions thrown by this method. Use null or an
- * empty array for none.
+ * Set the checked exceptions thrown by this method. Use null or an
+ * empty array for none.
*/
public void setExceptions(Class[] exceptions) {
String[] names = null;
-
if (exceptions != null) {
names = new String[exceptions.length];
-
for (int i = 0; i < exceptions.length; i++)
names[i] = exceptions[i].getName();
}
-
setExceptions(names);
}
/**
- * Set the checked exceptions thrown by this method. Use null or an
- * empty array for none.
+ * Set the checked exceptions thrown by this method. Use null or an
+ * empty array for none.
*/
public void setExceptions(BCClass[] exceptions) {
String[] names = null;
-
if (exceptions != null) {
names = new String[exceptions.length];
-
for (int i = 0; i < exceptions.length; i++)
names[i] = exceptions[i].getName();
}
-
setExceptions(names);
}
/**
- * Clear this method of all exception declarations.
+ * Clear this method of all exception declarations.
*/
public void clear() {
_indexes.clear();
}
/**
- * Remove an exception type thrown by this method.
- *
- * @return true if the method had the exception type, false otherwise
+ * Remove an exception type thrown by this method.
+ *
+ * @return true if the method had the exception type, false otherwise
*/
public boolean removeException(String type) {
- String internalForm = getProject().getNameCache()
- .getInternalForm(type, false);
+ String internalForm = getProject().getNameCache().
+ getInternalForm(type, false);
ClassEntry entry;
-
for (Iterator itr = _indexes.iterator(); itr.hasNext();) {
- entry = (ClassEntry) getPool()
- .getEntry(((Integer) itr.next()).intValue());
+ entry = (ClassEntry) getPool().getEntry
+ (((Integer) itr.next()).intValue());
if (entry.getNameEntry().getValue().equals(internalForm)) {
itr.remove();
-
return true;
}
}
-
return false;
}
/**
- * Remove an exception thrown by this method.
- *
- * @return true if the method had the exception type, false otherwise
+ * Remove an exception thrown by this method.
+ *
+ * @return true if the method had the exception type, false otherwise
*/
public boolean removeException(Class type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return removeException(type.getName());
}
/**
- * Remove an exception thrown by this method.
- *
- * @return true if the method had the exception type, false otherwise
+ * Remove an exception thrown by this method.
+ *
+ * @return true if the method had the exception type, false otherwise
*/
public boolean removeException(BCClass type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return removeException(type.getName());
}
/**
- * Add an exception type to those thrown by this method.
+ * Add an exception type to those thrown by this method.
*/
public void addException(String type) {
- int index = getPool()
- .findClassEntry(getProject().getNameCache()
- .getInternalForm(type, false), true);
+ int index = getPool().findClassEntry(getProject().getNameCache().
+ getInternalForm(type, false), true);
_indexes.add(Numbers.valueOf(index));
}
/**
- * Add an exception to those thrown by this method.
+ * Add an exception to those thrown by this method.
*/
public void addException(Class type) {
addException(type.getName());
}
/**
- * Add an exception to those thrown by this method.
+ * Add an exception to those thrown by this method.
*/
public void addException(BCClass type) {
addException(type.getName());
}
/**
- * Return true if the method declares that it throws the given
- * exception type.
+ * Return true if the method declares that it throws the given
+ * exception type.
*/
public boolean throwsException(String type) {
String[] exceptions = getExceptionNames();
-
for (int i = 0; i < exceptions.length; i++)
- if (exceptions[i].equals(type)) {
+ if (exceptions[i].equals(type))
return true;
- }
-
return false;
}
/**
- * Return true if the method declares that it throws the given
- * exception type.
+ * Return true if the method declares that it throws the given
+ * exception type.
*/
public boolean throwsException(Class type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return throwsException(type.getName());
}
/**
- * Return true if the method declares that it throws the given
- * exception type.
+ * Return true if the method declares that it throws the given
+ * exception type.
*/
public boolean throwsException(BCClass type) {
- if (type == null) {
+ if (type == null)
return false;
- }
-
return throwsException(type.getName());
}
@@ -314,16 +270,13 @@
void read(DataInput in, int length) throws IOException {
_indexes.clear();
-
int exceptionCount = in.readUnsignedShort();
-
for (int i = 0; i < exceptionCount; i++)
_indexes.add(Numbers.valueOf((int) in.readUnsignedShort()));
}
void write(DataOutput out, int length) throws IOException {
out.writeShort(_indexes.size());
-
for (Iterator itr = _indexes.iterator(); itr.hasNext();)
out.writeShort(((Number) itr.next()).shortValue());
}