本文整理汇总了Java中org.apache.bcel.classfile.ConstantLong类的典型用法代码示例。如果您正苦于以下问题:Java ConstantLong类的具体用法?Java ConstantLong怎么用?Java ConstantLong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantLong类属于org.apache.bcel.classfile包,在下文中一共展示了ConstantLong类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pushByConstant
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
private void pushByConstant(DismantleBytecode dbc, Constant c) {
if (c instanceof ConstantInteger)
push(new Item("I", new Integer(((ConstantInteger) c).getBytes())));
else if (c instanceof ConstantString) {
int s = ((ConstantString) c).getStringIndex();
push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s)));
}
else if (c instanceof ConstantFloat)
push(new Item("F", new Float(((ConstantInteger) c).getBytes())));
else if (c instanceof ConstantDouble)
push(new Item("D", new Double(((ConstantDouble) c).getBytes())));
else if (c instanceof ConstantLong)
push(new Item("J", new Long(((ConstantLong) c).getBytes())));
else
throw new UnsupportedOperationException("Constant type not expected" );
}
示例2: pushByConstant
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
private void pushByConstant(DismantleBytecode dbc, Constant c) {
if (c instanceof ConstantClass)
push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool())));
else if (c instanceof ConstantInteger)
push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes())));
else if (c instanceof ConstantString) {
int s = ((ConstantString) c).getStringIndex();
push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s)));
} else if (c instanceof ConstantFloat)
push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes())));
else if (c instanceof ConstantDouble)
push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes())));
else if (c instanceof ConstantLong)
push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes())));
else
throw new UnsupportedOperationException("Constant type not expected");
}
示例3: pushByConstant
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
private void pushByConstant(DismantleBytecode dbc, Constant c) {
if (c instanceof ConstantClass)
push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool())));
else if (c instanceof ConstantInteger)
push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes())));
else if (c instanceof ConstantString) {
int s = ((ConstantString) c).getStringIndex();
push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s)));
} else if (c instanceof ConstantFloat)
push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes())));
else if (c instanceof ConstantDouble)
push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes())));
else if (c instanceof ConstantLong)
push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes())));
else
throw new UnsupportedOperationException("StaticConstant type not expected");
}
示例4: visitLDC2_W
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
// LDC2_W
public void visitLDC2_W(LDC2_W o){
indexValid(o, o.getIndex());
Constant c = cpg.getConstant(o.getIndex());
if (! ( (c instanceof ConstantLong) ||
(c instanceof ConstantDouble) ) ){
constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'.");
}
try{
indexValid(o, o.getIndex()+1);
}
catch(StaticCodeInstructionOperandConstraintException e){
throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem.");
}
}
示例5: CPESSC_Visitor
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
private CPESSC_Visitor(JavaClass _jc){
jc = _jc;
cp = _jc.getConstantPool();
cplen = cp.getLength();
CONST_Class = org.apache.bcel.classfile.ConstantClass.class;
/*
CONST_Fieldref = org.apache.bcel.classfile.ConstantFieldref.class;
CONST_Methodref = org.apache.bcel.classfile.ConstantMethodref.class;
CONST_InterfaceMethodref = org.apache.bcel.classfile.ConstantInterfaceMethodref.class;
*/
CONST_String = org.apache.bcel.classfile.ConstantString.class;
CONST_Integer = org.apache.bcel.classfile.ConstantInteger.class;
CONST_Float = org.apache.bcel.classfile.ConstantFloat.class;
CONST_Long = org.apache.bcel.classfile.ConstantLong.class;
CONST_Double = org.apache.bcel.classfile.ConstantDouble.class;
CONST_NameAndType = org.apache.bcel.classfile.ConstantNameAndType.class;
CONST_Utf8 = org.apache.bcel.classfile.ConstantUtf8.class;
carrier = new DescendingVisitor(_jc, this);
carrier.visit();
}
示例6: visitLDC2_W
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
/** Symbolically executes the corresponding Java Virtual Machine instruction. */
public void visitLDC2_W(LDC2_W o){
Constant c = cpg.getConstant(o.getIndex());
if (c instanceof ConstantLong){
stack().push(Type.LONG);
}
if (c instanceof ConstantDouble){
stack().push(Type.DOUBLE);
}
}
示例7: visitLDC2_W
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
/**
* Ensures the specific preconditions of the said instruction.
*/
public void visitLDC2_W(LDC2_W o){
// visitCPInstruction is called first.
Constant c = cpg.getConstant(o.getIndex());
if (! ( ( c instanceof ConstantLong) ||
( c instanceof ConstantDouble ) ) ){
constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
}
}
示例8: getConstantPool
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
public static Set<Object> getConstantPool(InputStream is, String name) throws ClassFormatException, IOException {
HashSet<Object> constants = new HashSet<Object>();
ClassParser parser = new ClassParser(is, name);
ConstantPool pool = parser.parse().getConstantPool();
for (Constant constant : pool.getConstantPool()) {
//Strings used in code are stored using String constant, they are just references to Utf8 constant
//but we can't use Utf8 constants because they are used to store field/method/class names and signatures too
if (constant instanceof ConstantString) {
String string = (String) ((ConstantString) constant).getConstantValue(pool);
//skip empty string
if (string.isEmpty()) {
continue;
}
constants.add(string);
}
if (constant instanceof ConstantInteger || constant instanceof ConstantLong || constant instanceof ConstantFloat || constant instanceof ConstantDouble) {
constants.add(((ConstantObject) constant).getConstantValue(pool));
}
}
return constants;
}
示例9: visit
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
@Override
public void visit(Field field) {
ConstantValue value = field.getConstantValue();
if (value == null) return;
Constant c = getConstantPool().getConstant(value.getConstantValueIndex());
if (c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) {
bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this)
.addString("Did you mean MICROS_PER_DAY")
.addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT)
.describe(IntAnnotation.INT_VALUE));
}
}
示例10: sawOpcode
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
@Override
public void sawOpcode(int seen) {
if (state == SEEN_NOTHING) {
if ((seen == DCONST_0) || (seen == DCONST_1)) {
constValue = seen - DCONST_0;
state = SEEN_DCONST;
} else if ((seen == LDC2_W) || (seen == LDC_W)) {
state = SEEN_DCONST;
Constant c = this.getConstantRefOperand();
if (c instanceof ConstantDouble)
constValue = ((ConstantDouble) c).getBytes();
else if (c instanceof ConstantFloat)
constValue = ((ConstantFloat) c).getBytes();
else if (c instanceof ConstantLong)
constValue = ((ConstantLong) c).getBytes();
else
state = SEEN_NOTHING;
}
} else if (state == SEEN_DCONST) {
if (seen == INVOKESTATIC) {
state = SEEN_NOTHING;
if (getDottedClassConstantOperand().equals("java.lang.Math")) {
String methodName = getNameConstantOperand();
if (((constValue == 0.0) && zeroMethods.contains(methodName))
|| ((constValue == 1.0) && oneMethods.contains(methodName)) || (anyMethods.contains(methodName))) {
bugReporter.reportBug(new BugInstance(this, "UM_UNNECESSARY_MATH", LOW_PRIORITY).addClassAndMethod(this)
.addSourceLine(this));
}
}
}
state = SEEN_NOTHING;
}
}
示例11: lookupLong
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
/**
* Look for ConstantLong in ConstantPool.
*
* @param n Long number to look for
* @return index on success, -1 otherwise
*/
public int lookupLong( long n ) {
for (int i = 1; i < index; i++) {
if (constants[i] instanceof ConstantLong) {
ConstantLong c = (ConstantLong) constants[i];
if (c.getBytes() == n) {
return i;
}
}
}
return -1;
}
示例12: addLong
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
/**
* Add a new long constant to the ConstantPool, if it is not already in there.
*
* @param n Long number to add
* @return index of entry
*/
public int addLong( long n ) {
int ret;
if ((ret = lookupLong(n)) != -1) {
return ret; // Already in CP
}
adjustSize();
ret = index;
constants[index] = new ConstantLong(n);
index += 2; // Wastes one entry according to spec
return ret;
}
示例13: addConstant
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
private void addConstant(Element node, int idx) {
Constant c = cpg.getConstant(idx);
if (c instanceof ConstantString) {
node.setAttribute("type", "java.lang.String");
String valOrig = ((ConstantString) c).getBytes(cpg.getConstantPool());
String val = "";
for (int i = 0; i < valOrig.length(); i++) {
char ch = valOrig.charAt(i);
val += (ch < ' ' || ch > 'z') ? String.format("\\%03o", new Integer(ch))
: ch;
}
node.setAttribute("value", val);
// node.setText(val);
} else if (c instanceof ConstantClass) {
ConstantClass cc = (ConstantClass) c;
String s = (String) cc.getConstantValue(cpg.getConstantPool());
try {
s = Utility.signatureToString(s);
} catch (ClassFormatException ex) {
s = s.replace("/", ".");
}
node.setAttribute("type", s);
} else if (c instanceof ConstantDouble) {
node.setAttribute("type", "double");
node.setAttribute("value",
java.lang.String.valueOf(((ConstantDouble) c).getBytes()));
} else if (c instanceof ConstantLong) {
node.setAttribute("type", "long");
node.setAttribute("value",
java.lang.String.valueOf(((ConstantLong) c).getBytes()));
} else if (c instanceof ConstantFloat) {
node.setAttribute("type", "float");
node.setAttribute("value",
java.lang.String.valueOf(((ConstantFloat) c).getBytes()));
} else if (c instanceof ConstantInteger) {
node.setAttribute("type", "int");
node.setAttribute("value", String.valueOf(((ConstantInteger) c).getBytes()));
} else {
node.setAttribute("type", "unknown");
node.setAttribute("value", c.toString());
}
}
示例14: visit
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
public void visit(ConstantLong obj) {
visit((Constant) obj);
}
示例15: visitConstantLong
import org.apache.bcel.classfile.ConstantLong; //导入依赖的package包/类
public void visitConstantLong(ConstantLong obj) {
visit(obj);
}