Package javassist.bytecode

Examples of javassist.bytecode.SignatureAttribute$ObjectType


   public static Object getGenericType(Field f)
   {
      CtField fld = JavassistUtil.getCtField(f);
      FieldInfo info = fld.getFieldInfo2();
      SignatureAttribute sig = (SignatureAttribute)info.getAttribute(SignatureAttribute.tag);
      if (sig != null)
      {
         try
         {
            SignatureAttribute.ObjectType type = SignatureAttribute.toFieldSignature(sig.getSignature());
            return createType(f.getType(), type);
         }
         catch (BadBytecode e)
         {
            throw new RuntimeException(e);
View Full Code Here


   private static SignatureAttribute.ClassSignature getClassSignature(Class clazz)
   {
      CtClass ctclazz = JavassistUtil.getCtClass(clazz);
      ClassFile cf = ctclazz.getClassFile2();
      SignatureAttribute sig = (SignatureAttribute)cf.getAttribute(SignatureAttribute.tag);
      if (sig != null)
      {
         try
         {
            SignatureAttribute.ClassSignature type = SignatureAttribute.toClassSignature(sig.getSignature());
            return type;
         }
         catch (BadBytecode e)
         {
            throw new RuntimeException(e);
View Full Code Here

      return getMethodSignature(info);
   }
  
   private static SignatureAttribute.MethodSignature getMethodSignature(MethodInfo info)
   {
      SignatureAttribute sig = (SignatureAttribute)info.getAttribute(SignatureAttribute.tag);
      if (sig != null)
      {
         try
         {
            SignatureAttribute.MethodSignature type = SignatureAttribute.toMethodSignature(sig.getSignature());
            return type;
         }
         catch (BadBytecode e)
         {
            throw new RuntimeException(e);
View Full Code Here

      final String superClassName = seiClass.getSuperclass().getName().replace('.', '/') ;
      final String interfaceName = Provider.class.getName().replace('.', '/') ;
      final String typeName = SOAPMessage.class.getName().replace('.', '/') ;
      final String signature = 'L' + superClassName + ';' + 'L' + interfaceName + "<L" + typeName + ";>;" ;
      final SignatureAttribute signatureAttribute = new SignatureAttribute(constantPool, signature) ;
      seiClass.getClassFile().addAttribute(signatureAttribute) ;

      AnnotationsAttribute attribute = new AnnotationsAttribute(
          constantPool, AnnotationsAttribute.visibleTag);
      Annotation annotation = new Annotation(
View Full Code Here

            //add our @Simplified annotation to the new class
            newAnnotations = addSimplifiedClassAnnotation(originalClass.getName(), newAnnotations, constPool);
            newClassFile.addAttribute(newAnnotations);

            //copy the generic signature of the class
            SignatureAttribute signature = (SignatureAttribute) originalClassFile.getAttribute(SignatureAttribute.tag);
            if (signature != null) {
                newClassFile.addAttribute(new SignatureAttribute(constPool, signature.getSignature()));
            }

            //now copy over the methods
            CtMethod[] methods = originalClass.getMethods();

            for (CtMethod originalMethod : methods) {

                //we are only simplifying interfaces here, but the CtClass.getMethods() also returns concrete methods
                //inherited from Object. Let's just skip those - we don't need to worry about them...
                if (!Modifier.isAbstract(originalMethod.getModifiers())) {
                    continue;
                }

                CtClass[] params = originalMethod.getParameterTypes();

                //capture all the runtime visible method annotations on the original method
                annotations = (AnnotationsAttribute) originalMethod.getMethodInfo().getAttribute(
                    AnnotationsAttribute.visibleTag);

                //capture all the runtime visible parameter annotations on the original method
                ParameterAnnotationsAttribute parameterAnnotations = (ParameterAnnotationsAttribute) originalMethod
                    .getMethodInfo().getAttribute(ParameterAnnotationsAttribute.visibleTag);

                //capture the generic signature of the original method.
                signature = (SignatureAttribute) originalMethod.getMethodInfo().getAttribute(
                    SignatureAttribute.tag);

                boolean simplify = params.length > 0 && params[0].getName().equals(Subject.class.getName());

                if (simplify) {
                    //generate new params, leaving out the first parameter (the subject)
                    CtClass[] simpleParams = new CtClass[params.length - 1];

                    System.arraycopy(params, 1, simpleParams, 0, params.length - 1);
                    params = simpleParams;
                }

                //generate the new method with possibly modified parameters
                CtMethod newMethod = CtNewMethod.abstractMethod(originalMethod.getReturnType(),
                    originalMethod.getName(), params, originalMethod.getExceptionTypes(), newClass);

                //copy over the method annotations
                annotations = copyAnnotations(annotations, constPool);

                if (simplify) {
                    //add the @SimplifiedMethod to the method annotations
                    annotations = addSimplifiedMethodAnnotation(annotations, constPool);

                    if (signature != null) {
                        //fun, we need to modify the signature, too, because we have left out the parameter
                        MethodSignature sig = MethodSignature.parse(signature.getSignature());

                        sig.paramTypes.remove(0);

                        signature = new SignatureAttribute(constPool, sig.toString());
                    }

                    //next, we need to copy the parameter annotations
                    parameterAnnotations = copyParameterAnnotations(parameterAnnotations, constPool, 1);
                } else {
                    //just copy the sig and parameter annotations verbatim
                    if (signature != null) {
                        signature = new SignatureAttribute(constPool, signature.getSignature());
                    }

                    parameterAnnotations = copyParameterAnnotations(parameterAnnotations, constPool, 0);
                }
View Full Code Here

        nameReplaced();
        classPool.classNameChanged(oldname, this);
    }

    public String getGenericSignature() {
        SignatureAttribute sa
            = (SignatureAttribute)getClassFile2().getAttribute(SignatureAttribute.tag);
        return sa == null ? null : sa.getSignature();
    }
View Full Code Here

        return sa == null ? null : sa.getSignature();
    }

    public void setGenericSignature(String sig) {
        ClassFile cf = getClassFile();
        SignatureAttribute sa = new SignatureAttribute(cf.getConstPool(), sig);
        cf.addAttribute(sa);
    }
View Full Code Here

        String rep = "<T extends java.lang.Exception> extends Poi.Foo<java.lang.String> implements Bar, Bar2";
        SignatureAttribute.ClassSignature cs = SignatureAttribute.toClassSignature(sig);
        assertEquals(rep, cs.toString());
        CtClass c = loader.get("test3.SigAttribute");
        CtField f = c.getDeclaredField("value");
        SignatureAttribute a = (SignatureAttribute)f.getFieldInfo2().getAttribute(SignatureAttribute.tag);
        assertNotNull(a);
        f.getFieldInfo().prune(new ConstPool("test3.SigAttribute"));
        a = (SignatureAttribute)f.getFieldInfo2().getAttribute(SignatureAttribute.tag);
        assertNotNull(a);
    }
View Full Code Here

   public static void addSignature(CtField field, String signature)
   {
      FieldInfo fieldInfo = field.getFieldInfo();
      ConstPool constPool = fieldInfo.getConstPool();
      SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature);
      fieldInfo.addAttribute(signatureAttribute);
   }
View Full Code Here

   public static void addSignature(CtMethod method, String signature)
   {
      MethodInfo methodInfo = method.getMethodInfo();
      ConstPool constPool = methodInfo.getConstPool();
      SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature);
      methodInfo.addAttribute(signatureAttribute);
   }
View Full Code Here

TOP

Related Classes of javassist.bytecode.SignatureAttribute$ObjectType

Copyright © 2018 www.massapicom. 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.