Examples of AnnotationsAttribute


Examples of javassist.bytecode.AnnotationsAttribute

        }

        for (Object obj : fields)
        {
            FieldInfo field = (FieldInfo) obj;
            AnnotationsAttribute visible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag);
            AnnotationsAttribute invisible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.invisibleTag);

            if (visible != null)
            {
                populate(visible.getAnnotations(), cf.getName());
            }
            if (invisible != null)
            {
                populate(invisible.getAnnotations(), cf.getName());
            }
        }


    }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

   /**
    * Check if the Javassist {@link ClassFile} has the specfied annotation
    */
   protected boolean hasAnnotation(ClassFile classFile, Class<? extends Annotation> annotationType)
   {
      AnnotationsAttribute visible = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag );
      if ( visible != null )
      {
         return visible.getAnnotation( annotationType.getName() ) != null;
      }
      return false;
   }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

    * Get the value of the annotation on the Javassist {@link ClassFile}, or null
    * if the class doesn't have that annotation
    */
   protected String getAnnotationValue(ClassFile classFile, Class<? extends Annotation> annotationType, String memberName)
   {
      AnnotationsAttribute visible = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag );
      if ( visible != null )
      {
         javassist.bytecode.annotation.Annotation annotation = visible.getAnnotation( annotationType.getName() );
         if (annotation==null)
         {
            return null;
         }
         else
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

    private static void addNewAnnotations(Annotation[] add, CtMethod method, ConstPool constpool, ClassPool classPool, AnnotationsAttribute attr)
        throws IllegalAccessException, NotFoundException, InvocationTargetException
    {
        if (null == attr) {
            attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
            method.getMethodInfo().addAttribute(attr);
        }
        for (Annotation toAdd : add) {
            attr.addAnnotation(toJavassist(toAdd, constpool, classPool));
        }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

        }
    }

    private static AnnotationsAttribute filterExistingAnnotations(Annotation[] remove, CtMethod method)
    {
        AnnotationsAttribute attr = null;
        final List attributes = method.getMethodInfo().getAttributes();
        for (Object attribute : attributes) {
            if (attribute instanceof AnnotationsAttribute) {
                attr = (AnnotationsAttribute) attribute;
                final List<javassist.bytecode.annotation.Annotation> annotations = new ArrayList<javassist.bytecode.annotation.Annotation>();
                for (javassist.bytecode.annotation.Annotation annotation : attr.getAnnotations()) {
                    boolean shouldRemove = false;
                    for (Annotation annotationToRemove : remove) {
                        if (annotationToRemove.annotationType().getCanonicalName().equals(annotation.getTypeName())) {
                            shouldRemove = true;
                        }
                    }
                    if (!shouldRemove) {
                        annotations.add(annotation);
                    }
                }
                attr.setAnnotations(annotations.toArray(new javassist.bytecode.annotation.Annotation[annotations.size()]));
            }
        }
        return attr;
    }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.get(clazz.getCanonicalName());
        for (CtMethod method : cc.getDeclaredMethods()) {
            ClassFile ccFile = cc.getClassFile();
            ConstPool constpool = ccFile.getConstPool();
            AnnotationsAttribute attr;
            attr = filterExistingAnnotations(add, method);
            addNewAnnotations(add, method, constpool, pool, attr);
        }
        cc.setName(cc.getName() + "$ClassModifier$" + COUNTER.increment());
        cc.setSuperclass(pool.get(clazz.getCanonicalName()));
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

  }

  protected void scanClass(ClassFile cf)
  {
    String className = cf.getName();
    AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
    AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);

    if (visible != null)
    {
      populate(visible.getAnnotations(), className);
    }
    if (invisible != null)
    {
      populate(invisible.getAnnotations(), className);
    }
    populateInterfaces(cf);
  }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

    for (Object obj : methods)
    {
      MethodInfo method = (MethodInfo) obj;
      if (scanMethodAnnotations)
      {
        AnnotationsAttribute visible = (AnnotationsAttribute) method.getAttribute(AnnotationsAttribute.visibleTag);
        AnnotationsAttribute invisible = (AnnotationsAttribute) method.getAttribute(AnnotationsAttribute.invisibleTag);

        if (visible != null)
        {
          populate(visible.getAnnotations(), cf.getName());
        }
        if (invisible != null)
        {
          populate(invisible.getAnnotations(), cf.getName());
        }
      }
      if (scanParameterAnnotations)
      {
        ParameterAnnotationsAttribute paramsVisible = (ParameterAnnotationsAttribute) method.getAttribute(ParameterAnnotationsAttribute.visibleTag);
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

      return;
    }
    for (Object obj : fields)
    {
      FieldInfo field = (FieldInfo) obj;
      AnnotationsAttribute visible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag);
      AnnotationsAttribute invisible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.invisibleTag);

      if (visible != null)
      {
        populate(visible.getAnnotations(), cf.getName());
      }
      if (invisible != null)
      {
        populate(invisible.getAnnotations(), cf.getName());
      }
    }
  }
View Full Code Here

Examples of javassist.bytecode.AnnotationsAttribute

                        ctMethod.setModifiers(Modifier.PUBLIC);
                        ctMethod.setBody("runCommand(\"" + name + "\", $1, $2);");
                        ctClass.addMethod(ctMethod);

                        // add GoGo descriptor for this shell command
                        AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
                        Annotation annotation = new Annotation(Descriptor.class.getName(), constPool);
                        annotation.addMemberValue("value", new StringMemberValue(commands.get(name), constPool));
                        annotationsAttribute.addAnnotation(annotation);
                        ctMethod.getMethodInfo().addAttribute(annotationsAttribute);
                    }
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.