本文整理汇总了Java中org.apache.bcel.classfile.ConstantValue类的典型用法代码示例。如果您正苦于以下问题:Java ConstantValue类的具体用法?Java ConstantValue怎么用?Java ConstantValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantValue类属于org.apache.bcel.classfile包,在下文中一共展示了ConstantValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNativeValue
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Returns a string representation of a given object native value.
*
* @param type - a Class object that wraps a data type.
* @param value - an object that wraps a value of a primitive data type.
* @return a string that represents a native data type.
*/
public static String getNativeValue(Type type, ConstantValue value) {
StringBuffer result = new StringBuffer();
if (type == Type.INT) {
result.append(value.toString()).append('L');
} else if (type == Type.BYTE) {
result.append(value.toString()).append('L');
} else if (type == Type.LONG) {
result.append(value.toString()).append("LL");
} else if (type == Type.FLOAT) {
result.append(value.toString()).append('f');
} else if (type == Type.DOUBLE) {
result.append(value.toString());
} else if (type == Type.SHORT) {
result.append(value.toString()).append('L');
} else if (type == Type.CHAR) {
result.append(value.toString()).append('L');
} else if (type == Type.BOOLEAN) {
result.append(value.toString()).append('L');
}
return result.toString();
}
示例2: visit
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visit(ConstantValue s) {
if (!visitingField())
return;
int i = s.getConstantValueIndex();
Constant c = getConstantPool().getConstant(i);
if (c instanceof ConstantString) {
String value = ((ConstantString) c).getBytes(getConstantPool());
if (value.length() < SIZE_OF_HUGE_CONSTANT)
return;
String key = getStringKey(value);
definition.put(key, XFactory.createXField(this));
stringSize.put(key, value.length());
}
}
示例3: writeField
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Print field of class.
*
* @param field field to print
* @exception java.io.IOException
*/
private void writeField( Field field ) throws IOException {
String type = Utility.signatureToString(field.getSignature());
String name = field.getName();
String access = Utility.accessToString(field.getAccessFlags());
Attribute[] attributes;
access = Utility.replace(access, " ", " ");
file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>"
+ Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + name
+ "</A></TD>");
attributes = field.getAttributes();
// Write them to the Attributes.html file with anchor "<name>[<i>]"
for (int i = 0; i < attributes.length; i++) {
attribute_html.writeAttribute(attributes[i], name + "@" + i);
}
for (int i = 0; i < attributes.length; i++) {
if (attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
String str = ((ConstantValue) attributes[i]).toString();
// Reference attribute in _attributes.html
file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + name + "@" + i
+ "\" TARGET=\"Attributes\">" + str + "</TD>\n");
break;
}
}
file.println("</TR>");
}
示例4: getConstants
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Get the constants declared in a file as name=value
*
* @param bytes the class as a array of bytes
* @return a StringBuffer contains the name=value pairs
* @exception IOException if an error occurs
*/
public static StringBuffer getConstants(final byte[] bytes)
throws IOException {
final StringBuffer sb = new StringBuffer();
final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
final ClassParser parser = new ClassParser(bis, "");
final JavaClass javaClass = parser.parse();
final Field[] fields = javaClass.getFields();
for (int i = 0; i < fields.length; i++) {
final Field field = fields[i];
if (field != null) {
final ConstantValue cv = field.getConstantValue();
if (cv != null) {
String cvs = cv.toString();
//Remove start and end quotes if field is a String
if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
cvs = cvs.substring(1, cvs.length() - 1);
}
sb.append(field.getName());
sb.append('=');
sb.append(cvs);
sb.append(LS);
}
}
}
return sb;
}
示例5: visitField
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visitField(Field field) {
Element f = new Element("field", nsXMLVM);
xmlClass.addContent(f);
addAccessModifiers(f, field.getAccessFlags());
f.setAttribute("name", field.getName());
Type t = field.getType();
f.setAttribute("type", t.toString());
ConstantValue val = field.getConstantValue();
if (val != null) {
f.setAttribute("value", val.toString());
}
addAnnotations(f, field.getAnnotationEntries());
}
示例6: visit
import org.apache.bcel.classfile.ConstantValue; //导入依赖的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));
}
}
示例7: visit
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visit(ConstantValue obj) {
// ConstantValue is an attribute of a field, so the instance variables
// set during visitation of the Field are still valid here
XField f = XFactory.createXField(this);
data.constantFields.add(f);
}
示例8: FieldGen
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Instantiate from existing field.
*
* @param field Field object
* @param cp constant pool (must contain the same entries as the field's constant pool)
*/
public FieldGen(Field field, ConstantPoolGen cp) {
this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
Attribute[] attrs = field.getAttributes();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof ConstantValue) {
setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
} else {
addAttribute(attrs[i]);
}
}
}
示例9: getField
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Get field object after having set up all necessary values.
*/
public Field getField() {
String signature = getSignature();
int name_index = cp.addUtf8(name);
int signature_index = cp.addUtf8(signature);
if (value != null) {
checkType(type);
int index = addConstant();
addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp
.getConstantPool()));
}
return new Field(access_flags, name_index, signature_index, getAttributes(), cp
.getConstantPool());
}
示例10: visitField
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitField( Field field ) {
_out.println();
_out.println(" field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", "
+ printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);");
ConstantValue cv = field.getConstantValue();
if (cv != null) {
String value = cv.toString();
_out.println(" field.setInitValue(" + value + ")");
}
_out.println(" _cg.addField(field.getField());");
}
示例11: visitConstantValue
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue cv) {
out.println(" = " + cv);
}
示例12: printFields
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
* Returns some information about the class fields.
*
* @param indent - an indentation.
* @return an indented string with some information about the class fields.
*/
private String printFields(int indent) {
StringBuffer result = new StringBuffer();
Field fields[] = wrappedClass.getFields();
if (fields.length > 0) {
// Create the indentation string.
String indentStr = indentString(indent);
boolean found = false;
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
// Skip a field, if we should not print an information about it.
if (!isPrintable(f)) {
continue;
}
found = true;
result.append(n);
result.append(indentStr);
// Append an access string.
String access = Utility.accessToString(f.getAccessFlags());
if (access.length() > 0) {
result.append(access);
result.append(' ');
}
// Append a field signature and name.
result.append(Utility.signatureToString(f.getSignature()));
result.append(' ');
result.append(f.getName());
result.append(';');
result.append(n);
// Append a type signature.
if (printTypeSignatures) {
result.append(indentString(indent * 2, "Signature: "));
result.append(f.getSignature());
result.append(n);
}
if (verbose) {
// Append a field constant value, if any.
ConstantValue cv = f.getConstantValue();
if (cv != null) {
result.append(indentString(indent * 2,
"Constant value: "));
result.append(cv);
result.append(n);
}
Attribute attrs[] = f.getAttributes();
for (int j = 0; j < attrs.length; j++) {
if (attrs[j].getTag() == Constants.ATTR_SYNTHETIC) {
result.append(indentString(indent * 2,
"Synthetic: true"));
result.append(n);
break;
}
}
}
}
if (found) {
result.append(n);
}
}
return result.toString();
}
示例13: visitConstantValue
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visitConstantValue(ConstantValue cv) {
// System.out.println("**************** = " + cv);
}
示例14: visit
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visit(ConstantValue obj) {
visit((Attribute) obj);
}
示例15: visitConstantValue
import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue obj) {
visit(obj);
}