]> source.dussan.org Git - javassist.git/commitdiff
updates javadoc
authorchibash <chiba@javassist.org>
Thu, 9 Jun 2016 10:19:20 +0000 (19:19 +0900)
committerchibash <chiba@javassist.org>
Thu, 9 Jun 2016 10:19:20 +0000 (19:19 +0900)
src/main/javassist/bytecode/ConstPool.java
src/test/Test.java

index 789351604509b4a0e4c8451d1709703e18032bd3..06df132797b01c07c9dcfc8fda40cfd52e0317c2 100644 (file)
@@ -222,6 +222,9 @@ public final class ConstPool {
     /**
      * Returns the <code>tag</code> field of the constant pool table
      * entry at the given index.
+     *
+     * @return either <code>CONST_Class</code>, <code>CONST_Fieldref</code>,
+     *         <code>CONST_Methodref</code>, or ...  
      */
     public int getTag(int index) {
         return getItem(index).getTag();
index 441879dbbf87d8ae84fe7d49ba6a0c18646315aa..3eb9a6014fff0f6894b56f3bd309a2ff38b5f783 100644 (file)
@@ -1,50 +1,31 @@
 import javassist.*;
+import javassist.bytecode.*;
+import javassist.bytecode.annotation.*;
 
-public class Test {
-    public static void main(String[] args) {
-        CtClass badClass = ClassPool.getDefault().makeClass("badClass");
-        String src = String.join(System.getProperty("line.separator"),
-                "public void eval () {",
-                "    if (true) {",
-                "        double t=0;",
-                "    } else {",
-                "        double t=0;",
-                "    }",
-                "    for (int i=0; i < 2; i++) {",
-                "        int a=0;",
-                "        int b=0;",
-                "        int c=0;",
-                "        int d=0;",
-                "        if (true) {",
-                "            int e = 0;",
-                "        }",
-                "    }",
-                "}");
-        System.out.println(src);
-        try {
-            badClass.addMethod(CtMethod.make(src, badClass));
-            badClass.debugWriteFile("./bin");
-            Class clazzz = badClass.toClass();
-            Object obj = clazzz.newInstance(); // <-- falls here
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
+@interface Entity {}
 
-    public void eval () {
-        if (true) {
-            double t=0;
-        } else {
-            double t=0;
-        }
-        for (int i=0; i < 2; i++) {
-            int a=0;
-            int b=0;
-           int c=0;
-            int d=0;
-            if (true) {
-                int e = 0;
-            }
-        }
+@interface Table {}
+
+public class Test {
+    public static void main(String[] args) throws Exception {
+        ClassPool classPool = ClassPool.getDefault();
+        ClassFile cf = classPool.makeClass("TestSub").getClassFile();
+        ConstPool constPool = cf.getConstPool();
+        Annotation[] annotations = new Annotation[2];
+        AnnotationsAttribute attrib =
+                new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
+        Annotation annotation = new Annotation(constPool, classPool.get("Entity"));
+        annotations[0] = annotation;
+        // Add @Table(name="",schema="") to class
+        annotation = new Annotation(constPool, classPool.get("Table"));
+        annotation.addMemberValue("name", new StringMemberValue("name", constPool));
+        annotation.addMemberValue("schema", new StringMemberValue("schema", constPool));
+        ArrayMemberValue blankMemberValueArray = new ArrayMemberValue(new AnnotationMemberValue(constPool), constPool);
+        blankMemberValueArray.setValue(new MemberValue[0]);
+        annotation.addMemberValue("uniqueConstraints", blankMemberValueArray);
+        annotation.addMemberValue("indexes", blankMemberValueArray);
+        annotations[1] = annotation;
+        attrib.setAnnotations(annotations);
+        cf.addAttribute(attrib);
     }
 }