git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@157 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -120,7 +120,7 @@ public abstract class CtMember { | |||
public abstract String getName(); | |||
/** | |||
* Obtains an attribute with the given name. | |||
* Obtains a user-defined attribute with the given name. | |||
* If that attribute is not found in the class file, this | |||
* method returns null. | |||
* | |||
@@ -129,7 +129,7 @@ public abstract class CtMember { | |||
public abstract byte[] getAttribute(String name); | |||
/** | |||
* Adds an attribute. The attribute is saved in the class file. | |||
* Adds a user-defined attribute. The attribute is saved in the class file. | |||
* | |||
* @param name attribute name | |||
* @param data attribute value |
@@ -35,6 +35,22 @@ import javassist.bytecode.annotation.*; | |||
* <code>AnnotationAttribute.visibleTag</code>, then the obtained | |||
* attribute is a runtime visible one. | |||
* | |||
* <p>For example, | |||
* | |||
* <ul><pre> | |||
* CtMethod m = ... ; | |||
* MethodInfo minfo = m.getMethodInfo(); | |||
* AnnotationsAttribute attr = (AnnotationsAttribute) | |||
* minfo.getAttribute(AnnotationsAttribute.invisibleTag); | |||
* Annotation an = attr.getAnnotation("Author"); | |||
* String s = ((StringMemberValue)a.getMemberValue("name")).getValue(); | |||
* System.out.println("@Author(name=" + s + ")"); | |||
* </pre></ul> | |||
* | |||
* <p>This code snippet retrieves an annotation of the type <code>Author</code> | |||
* from the <code>MethodInfo</code> object specified by <code>minfo</code>. | |||
* Then, it prints the value of <code>name</code> in <code>Author</code>. | |||
* | |||
* <p>If you want to record a new AnnotationAttribute object, execute the | |||
* following snippet: | |||
* | |||
@@ -48,6 +64,8 @@ import javassist.bytecode.annotation.*; | |||
* attr.setAnnotation(a); | |||
* cf.addAttribute(attr); | |||
* </pre></ul> | |||
* | |||
* @see javassist.bytecode.annotation.Annotation | |||
*/ | |||
public class AnnotationsAttribute extends AttributeInfo { | |||
/** | |||
@@ -125,6 +143,7 @@ public class AnnotationsAttribute extends AttributeInfo { | |||
* <code>getAnnotations()</code> as to the returned data structure. | |||
* | |||
* @param type the annotation type. | |||
* @return null if the specified annotation type is not included. | |||
* @see #getAnnotations() | |||
*/ | |||
public Annotation getAnnotation(String type) { |
@@ -20,8 +20,7 @@ package javassist.bytecode.annotation; | |||
* | |||
* @author <a href="mailto:bill@jboss.org">Bill Burke</a> | |||
*/ | |||
public interface MemberValueVisitor | |||
{ | |||
public interface MemberValueVisitor { | |||
public void visitAnnotationMemberValue(AnnotationMemberValue node); | |||
public void visitArrayMemberValue(ArrayMemberValue node); | |||
public void visitBooleanMemberValue(BooleanMemberValue node); |
@@ -1368,6 +1368,13 @@ CtField f = CtField.make("public int z = 0;", point); | |||
point.addField(f); | |||
</pre></ul> | |||
<h4>Removing a member</h4> | |||
<p>To remove a field or a method, call <code>removeField()</code> | |||
or <code>removeMethod()</code> in <code>CtClass</code>. A | |||
<code>CtConstructor</code> can be removed by <code>removeConstructor()</code> | |||
in <code>CtClass</code>. | |||
<p><br> | |||
@@ -84,7 +84,7 @@ In other words, a <code>FieldInfo</code> (or <code>MethodInfo</code> etc.) objec | |||
must not be shared among different <code>ClassFile</code> objects. | |||
<p> | |||
To remove a field or a method, | |||
To remove a field or a method from a <code>ClassFile</code> object, | |||
you must first obtain a <code>java.util.List</code> | |||
object containing all the fields of the class. <code>getFields()</code> | |||
and <code>getMethods()</code> return the lists. A field or a method can |