当前位置: 首页>>代码示例>>Java>>正文


Java Field.getConstantValue方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:ant,代码行数:34,代码来源:JavaClassHelper.java

示例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));
			}
		}
	}
}
 
开发者ID:jdepend,项目名称:cooper,代码行数:30,代码来源:Attribute.java

示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:ClassToXmlvmProcess.java

示例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));

    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:15,代码来源:DumbMethods.java

示例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());");
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:12,代码来源:BCELifier.java

示例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();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:76,代码来源:Clazz.java

示例7: hasConstantValue

import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
private static boolean hasConstantValue(final Field field) {
	return field.getConstantValue() != null;
}
 
开发者ID:DesignAndDeploy,项目名称:dnd,代码行数:4,代码来源:FunctionBlockClass.java


注:本文中的org.apache.bcel.classfile.Field.getConstantValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。