本文整理汇总了Java中org.apache.bcel.classfile.Field.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Field.getAttributes方法的具体用法?Java Field.getAttributes怎么用?Java Field.getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Field
的用法示例。
在下文中一共展示了Field.getAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeField
import org.apache.bcel.classfile.Field; //导入方法依赖的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>");
}
示例2: FieldGen
import org.apache.bcel.classfile.Field; //导入方法依赖的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]);
}
}
}
示例3: getSignature
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
private Signature getSignature(final Field field) {
for (final Attribute attribute : field.getAttributes()) {
if (attribute instanceof Signature) {
return (Signature) attribute;
}
}
return null;
}
示例4: visitField
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visitField(Field field) {
out.print(".field " + Utility.accessToString(field.getAccessFlags()) +
" " + field.getName() + " " + field.getSignature());
if(field.getAttributes().length == 0)
out.print("\n");
}
示例5: 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();
}
示例6: visitField
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visitField(Field obj){
if (jc.isClass()){
int maxone=0;
if (obj.isPrivate()) {
maxone++;
}
if (obj.isProtected()) {
maxone++;
}
if (obj.isPublic()) {
maxone++;
}
if (maxone > 1){
throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
}
if (obj.isFinal() && obj.isVolatile()){
throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
}
}
else{ // isInterface!
if (!obj.isPublic()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
}
if (!obj.isStatic()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
}
if (!obj.isFinal()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
}
}
if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
}
checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
String name = obj.getName();
if (! validFieldName(name)){
throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
}
// A descriptor is often named signature in BCEL
checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
try{
Type.getType(sig); /* Don't need the return value */
}
catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
String nameanddesc = (name+sig);
if (field_names_and_desc.contains(nameanddesc)){
throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
}
if (field_names.contains(name)){
addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
}
field_names_and_desc.add(nameanddesc);
field_names.add(name);
Attribute[] atts = obj.getAttributes();
for (int i=0; i<atts.length; i++){
if ((! (atts[i] instanceof ConstantValue)) &&
(! (atts[i] instanceof Synthetic)) &&
(! (atts[i] instanceof Deprecated))){
addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is unknown and will therefore be ignored.");
}
if (! (atts[i] instanceof ConstantValue)){
addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is not a ConstantValue and is therefore only of use for debuggers and such.");
}
}
}