下面列出了怎么用org.objectweb.asm.Attribute的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Prints a disassembled view of the given attribute.
*
* @param attribute an attribute.
*/
public void visitAttribute(final Attribute attribute) {
stringBuilder.setLength(0);
stringBuilder.append(tab).append("ATTRIBUTE ");
appendDescriptor(-1, attribute.type);
if (attribute instanceof TextifierSupport) {
if (labelNames == null) {
labelNames = new HashMap<>();
}
((TextifierSupport) attribute).textify(stringBuilder, labelNames);
} else {
stringBuilder.append(" : unknown\n");
}
text.add(stringBuilder.toString());
}
@Override
public void visitAttribute(final Attribute attribute) {
if (attrs == null) {
attrs = new ArrayList<>(1);
}
attrs.add(attribute);
}
@Override
public void visitAttribute(final Attribute attribute) {
if (attrs == null) {
attrs = new ArrayList<>(1);
}
attrs.add(attribute);
}
@Override
public void visitAttribute(final Attribute attribute) {
if (attrs == null) {
attrs = new ArrayList<>(1);
}
attrs.add(attribute);
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeOffset,
final Label[] labels) {
return new ModuleResolutionAttribute(classReader.readUnsignedShort(offset));
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeOffset,
final Label[] labels) {
return new ModuleTargetAttribute(classReader.readUTF8(offset, charBuffer));
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeAttributeOffset,
final Label[] labels) {
int currentOffset = offset;
String hashAlgorithm = classReader.readUTF8(currentOffset, charBuffer);
currentOffset += 2;
int numModules = classReader.readUnsignedShort(currentOffset);
currentOffset += 2;
ArrayList<String> moduleList = new ArrayList<>(numModules);
ArrayList<byte[]> hashList = new ArrayList<>(numModules);
for (int i = 0; i < numModules; ++i) {
String module = classReader.readModule(currentOffset, charBuffer);
currentOffset += 2;
moduleList.add(module);
int hashLength = classReader.readUnsignedShort(currentOffset);
currentOffset += 2;
byte[] hash = new byte[hashLength];
for (int j = 0; j < hashLength; ++j) {
hash[j] = (byte) (classReader.readByte(currentOffset) & 0xFF);
currentOffset += 1;
}
hashList.add(hash);
}
return new ModuleHashesAttribute(hashAlgorithm, moduleList, hashList);
}
@Override
public void visitAttribute(final Attribute attribute) {
if (attribute instanceof ModuleHashesAttribute) {
ModuleHashesAttribute moduleHashesAttribute = (ModuleHashesAttribute) attribute;
List<String> modules = moduleHashesAttribute.modules;
for (int i = 0; i < modules.size(); ++i) {
modules.set(i, remapper.mapModuleName(modules.get(i)));
}
}
super.visitAttribute(attribute);
}
@Override
public void visitAttribute(final Attribute attribute) {
checkVisitEndNotCalled();
if (attribute == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attribute);
}
/**
* Visit a class, field or method attribute.
*
* @param attribute an attribute.
*/
public void visitAttribute(final Attribute attribute) {
stringBuilder.setLength(0);
stringBuilder.append("// ATTRIBUTE ").append(attribute.type).append('\n');
if (attribute instanceof ASMifierSupport) {
if (labelNames == null) {
labelNames = new HashMap<>();
}
stringBuilder.append("{\n");
((ASMifierSupport) attribute).asmify(stringBuilder, "attribute", labelNames);
stringBuilder.append(name).append(".visitAttribute(attribute);\n");
stringBuilder.append("}\n");
}
text.add(stringBuilder.toString());
}
@Override
public void visitAttribute(final Attribute attribute) {
checkState();
if (attribute == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attribute);
}
@Override
public void visitAttribute(final Attribute attribute) {
checkVisitEndNotCalled();
if (attribute == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attribute);
}
public void emitNodeAttributes(List<Attribute> attrs) {
for (int i = 0; i < attrs.size(); i++) {
Attribute attr = attrs.get(i);
if (i < (attrs.size() - 1)) {
Attribute next = attrs.get(i + 1);
}
}
this.emitDirective("attrs", attrs);
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeOffset,
final Label[] labels) {
return new ModuleResolutionAttribute(classReader.readUnsignedShort(offset));
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeOffset,
final Label[] labels) {
return new ModuleTargetAttribute(classReader.readUTF8(offset, charBuffer));
}
@Override
protected Attribute read(
final ClassReader classReader,
final int offset,
final int length,
final char[] charBuffer,
final int codeAttributeOffset,
final Label[] labels) {
int currentOffset = offset;
String hashAlgorithm = classReader.readUTF8(currentOffset, charBuffer);
currentOffset += 2;
int numModules = classReader.readUnsignedShort(currentOffset);
currentOffset += 2;
ArrayList<String> moduleList = new ArrayList<String>(numModules);
ArrayList<byte[]> hashList = new ArrayList<byte[]>(numModules);
for (int i = 0; i < numModules; ++i) {
String module = classReader.readModule(currentOffset, charBuffer);
currentOffset += 2;
moduleList.add(module);
int hashLength = classReader.readUnsignedShort(currentOffset);
currentOffset += 2;
byte[] hash = new byte[hashLength];
for (int j = 0; j < hashLength; ++j) {
hash[j] = (byte) (classReader.readByte(currentOffset) & 0xFF);
currentOffset += 1;
}
hashList.add(hash);
}
return new ModuleHashesAttribute(hashAlgorithm, moduleList, hashList);
}
@Override
public void visitAttribute(final Attribute attribute) {
if (attribute instanceof ModuleHashesAttribute) {
ModuleHashesAttribute moduleHashesAttribute = (ModuleHashesAttribute) attribute;
List<String> modules = moduleHashesAttribute.modules;
for (int i = 0; i < modules.size(); ++i) {
modules.set(i, remapper.mapModuleName(modules.get(i)));
}
}
super.visitAttribute(attribute);
}
@Override
public void visitAttribute(final Attribute attr) {
if (attrs == null) {
attrs = new ArrayList<Attribute>(1);
}
attrs.add(attr);
}
@Override
public void visitAttribute(final Attribute attr) {
if (attrs == null) {
attrs = new ArrayList<Attribute>(1);
}
attrs.add(attr);
}
@Override
public void visitAttribute(final Attribute attr) {
if (attrs == null) {
attrs = new ArrayList<Attribute>(1);
}
attrs.add(attr);
}
@Override
public void visitAttribute(final Attribute attr) {
checkEnd();
if (attr == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
public void visitAttribute(final Attribute attr) {
buf.setLength(0);
buf.append("// ATTRIBUTE ").append(attr.type).append('\n');
if (attr instanceof ASMifiable) {
if (labelNames == null) {
labelNames = new HashMap<Label, String>();
}
buf.append("{\n");
((ASMifiable) attr).asmify(buf, "attr", labelNames);
buf.append(name).append(".visitAttribute(attr);\n");
buf.append("}\n");
}
text.add(buf.toString());
}
@Override
public void visitAttribute(final Attribute attr) {
checkState();
if (attr == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@Override
public void visitMethodAttribute(final Attribute attr) {
buf.setLength(0);
buf.append(tab).append("ATTRIBUTE ");
appendDescriptor(-1, attr.type);
if (attr instanceof Textifiable) {
((Textifiable) attr).textify(buf, labelNames);
} else {
buf.append(" : unknown\n");
}
text.add(buf.toString());
}
/**
* Prints a disassembled view of the given attribute.
*
* @param attr
* an attribute.
*/
public void visitAttribute(final Attribute attr) {
buf.setLength(0);
buf.append(tab).append("ATTRIBUTE ");
appendDescriptor(-1, attr.type);
if (attr instanceof Textifiable) {
((Textifiable) attr).textify(buf, null);
} else {
buf.append(" : unknown\n");
}
text.add(buf.toString());
}
@Override
public void visitAttribute(final Attribute attr) {
checkEndMethod();
if (attr == null) {
throw new IllegalArgumentException("Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@Override
public void visitAttribute(Attribute attribute) {
for (IHandler handler : handlers) {
handler.visitAttribute(attribute);
}
super.visitAttribute(attribute);
}
@Override
public void visitAttribute(final Attribute attr) {
fsmCursor.transition("visitAttribute");
super.visitAttribute(attr);
}
@Override
public void visitAttribute(final Attribute attr) {
fsmCursor.transition("visitAttribute");
super.visitAttribute(attr);
}
public void visitAttribute( final Attribute attr ) {
}