Esempio n. 1
0
 /*  31:    */
 /*  32:    */ public TransformCall(Transformer next, String oldMethodName, CtMethod substMethod)
       /*  33:    */ {
   /*  34: 44 */ super(next);
   /*  35: 45 */ this.methodname = oldMethodName;
   /*  36: 46 */ this.methodDescriptor = substMethod.getMethodInfo2().getDescriptor();
   /*  37: 47 */ this.classname = (this.newClassname = substMethod.getDeclaringClass().getName());
   /*  38: 48 */ this.newMethodname = substMethod.getName();
   /*  39: 49 */ this.constPool = null;
   /*  40: 50 */ this.newMethodIsPrivate = Modifier.isPrivate(substMethod.getModifiers());
   /*  41:    */ }
Esempio n. 2
0
  /** Prints the bytecode instructions of a given method. */
  public void print(CtMethod method) {
    MethodInfo info = method.getMethodInfo2();
    ConstPool pool = info.getConstPool();
    CodeAttribute code = info.getCodeAttribute();
    if (code == null) return;

    CodeIterator iterator = code.iterator();
    while (iterator.hasNext()) {
      int pos;
      try {
        pos = iterator.next();
      } catch (BadBytecode e) {
        throw new RuntimeException(e);
      }

      stream.println(pos + ": " + instructionString(iterator, pos, pool));
    }
  }
      private URL computeResourceURL(Method method) throws NotFoundException, URISyntaxException {
        List<ResourceFileEntry> filesSimpleNames = new ArrayList<ResourceFileEntry>();
        boolean computeExtensions = false;
        CtMethod m = ctClass.getMethod(method.getName(), getDescriptor(method));
        MethodInfo minfo = m.getMethodInfo2();
        AnnotationsAttribute attr =
            (AnnotationsAttribute) minfo.getAttribute(AnnotationsAttribute.invisibleTag);
        if (attr != null) {
          Annotation an = attr.getAnnotation(Source.class.getName());
          if (an != null) {
            MemberValue[] mvArray = ((ArrayMemberValue) an.getMemberValue("value")).getValue();
            if (mvArray != null) {
              for (MemberValue mv : mvArray) {
                StringMemberValue smv = (StringMemberValue) mv;
                filesSimpleNames.add(new ResourceFileEntry(smv.getValue(), m));
              }
            }
          }
        }

        if (filesSimpleNames.isEmpty()) {
          // no @Source annotation detected
          filesSimpleNames.add(new ResourceFileEntry(method.getName(), m));
          computeExtensions = true;
        }

        List<URL> existingFiles = new ArrayList<URL>();

        for (ResourceFileEntry resourceEntry : filesSimpleNames) {
          String resourceName = resourceEntry.resourceName;
          CtClass declaringClass = resourceEntry.resourceMethod.getDeclaringClass();
          String baseDir = declaringClass.getPackageName().replaceAll("\\.", "/") + "/";
          String fileName =
              (resourceName.startsWith(baseDir)) ? resourceName : baseDir + resourceName;

          if (computeExtensions) {
            String[] extensions = getResourceDefaultExtensions(method);

            for (String extension : extensions) {
              String possibleFile = fileName + extension;
              URL url = GwtPatcher.class.getClassLoader().getResource(possibleFile);
              if (url != null) {
                existingFiles.add(url);
              }
            }
          } else {
            URL url = GwtPatcher.class.getClassLoader().getResource(fileName);
            if (url != null) {
              existingFiles.add(url);
            }
          }
        }

        if (existingFiles.isEmpty()) {
          throw new RuntimeException(
              "No resource file found for method "
                  + ctClass.getSimpleName()
                  + "."
                  + method.getName()
                  + "()");
        } else if (existingFiles.size() > 1) {
          throw new RuntimeException(
              "Too many resource files found for method "
                  + ctClass.getSimpleName()
                  + "."
                  + method.getName()
                  + "()");
        }

        return existingFiles.get(0);
      }