本文整理汇总了Java中org.apache.bcel.classfile.Field.getConstantValue方法的典型用法代码示例。如果您正苦于以下问题:Java Field.getConstantValue方法的具体用法?Java Field.getConstantValue怎么用?Java Field.getConstantValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Field
的用法示例。
在下文中一共展示了Field.getConstantValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConstants
import org.apache.bcel.classfile.Field; //导入方法依赖的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;
}
示例2: Attribute
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public Attribute(JavaClass javaClass, Field field, boolean isParseAnnotation) {
this.javaClass = javaClass;
this.javaClassId = javaClass.getId();
this.access_flags = field.getAccessFlags();
this.info = field.toString();
this.name = field.getName();
this.signature = SignatureUtil.getSignature(field);
this.types = new ArrayList<String>();
for (String type : ParseUtil.signatureToTypes(this.signature)) {
this.types.add(type);
}
if (field.isStatic() && field.getConstantValue() != null) {
staticValue = field.getConstantValue().toString();
}
this.annotationRefs = new AnnotationRefs();
// 处理Annotation
if (isParseAnnotation) {
for (AnnotationEntry annotationEntry : field.getAnnotationEntries()) {
if (annotationEntry.getAnnotationType().equals(AnnotationParse.Autowired)) {
this.annotationRefs.setAutowired(AnnotationParse.parseAutowired(annotationEntry));
} else if (annotationEntry.getAnnotationType().equals(AnnotationParse.Qualifier)) {
this.annotationRefs.setQualifier(AnnotationParse.parseQualifier(annotationEntry));
}
}
}
}
示例3: visitField
import org.apache.bcel.classfile.Field; //导入方法依赖的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());
}
示例4: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的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));
}
}
示例5: visitField
import org.apache.bcel.classfile.Field; //导入方法依赖的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());");
}
示例6: printFields
import org.apache.bcel.classfile.Field; //导入方法依赖的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();
}
示例7: hasConstantValue
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
private static boolean hasConstantValue(final Field field) {
return field.getConstantValue() != null;
}