Package javassist.bytecode

Examples of javassist.bytecode.ClassFile


   }

   protected void deployElement(InputStream stream, Ejb3HandlerFactory factory, InitialContext ctx) throws Exception
   {
      DataInputStream dstream = new DataInputStream(new BufferedInputStream(stream));
      ClassFile cf = null;
      try
      {
         cf = new ClassFile(dstream);
      }
      finally
      {
         dstream.close();
         stream.close();
View Full Code Here


      }
   }
  
   private void copySignature(CtClass src, CtClass dest)
   {
      ClassFile srcFile = src.getClassFile2();
      ClassFile destFile = dest.getClassFile2();
     
      SignatureAttribute sig = (SignatureAttribute)srcFile.getAttribute(SignatureAttribute.tag);
      if (sig != null)
      {
         destFile.addAttribute(sig.copy(destFile.getConstPool(), EMPTY_HASHMAP));
      }
   }
View Full Code Here

      }
   }

   private void copyAnnotations(CtClass src, CtClass dest) throws NotFoundException
   {
      ClassFile srcFile = src.getClassFile2();
      ClassFile destFile = dest.getClassFile2();
      copyAnnotations(srcFile, destFile, AnnotationsAttribute.invisibleTag);
      copyAnnotations(srcFile, destFile, AnnotationsAttribute.visibleTag);
   }
View Full Code Here

         {
            file.delete();
            return;
         }
      }
      ClassFile cf = createClassFile(file);
      String className = cf.getName();
      String superClassName = cf.getSuperclass();
      CompilerClassInfo info = new CompilerClassInfo(file, className, superClassName);
      classesToCompile.put(className, info);
   }
View Full Code Here

      classesToCompile.put(className, info);
   }
  
   private ClassFile createClassFile(final File file) throws Exception{
      DataInputStream is = new DataInputStream(new FileInputStream(file));
      ClassFile cf = new ClassFile(is);
      is.close();
      return cf;
   }
View Full Code Here

    * @return {@code true} is {@code file} contains an advised class.
    */
   public boolean loadFile(File file) throws Exception
   {
      DataInputStream is = new DataInputStream(new FileInputStream(file));
      ClassFile cf = new ClassFile(is);
      is.close();
      Class<?> clazz = loader.loadClass(cf.getName());
      if (org.jboss.aop.Advised.class.isAssignableFrom(clazz))
      {
         Field f = clazz.getDeclaredField("aop$classAdvisor$aop");
         f.setAccessible(true);
         f.get(null);
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());
View Full Code Here

   }

   public boolean doWeave(ClassLoader cl, ClassFileInfo info) throws BadBytecode, CannotCompileException
   {
      CtClass clazz = info.getClazz();
      ClassFile file = clazz.getClassFile();
      log.fine("weaving: " + info.getClassName());
     
      // Already done
      if (file.getMajorVersion() <= 48)
         return false;

      // Set the major version
      file.setMajorVersion(48);

      // Rename known classes
      file.renameClass(getClassRenames());

      ConstPool constPool = file.getConstPool();

      // Rename classes with + to have $
      HashMap<String, String> mapClasses = new HashMap<String, String>();
     
      for (String name : (Set<String>) constPool.getClassNames())
      {
         if (name.indexOf('+') != -1) {
            mapClasses.put(name, name.replace('+', '$'));
         }
      }
      if (mapClasses.size() != 0) {
         constPool.renameClass(mapClasses);
      }

      // Replace LDC/LDC_W
      for (MethodInfo method : (List<MethodInfo>) file.getMethods()) {
         rewriteLDC(constPool, method);
      }

      if (clazz.isAnnotation())
      {
         rewriteSystemAnnotations(file);
      }

      // Run the converters
      for (CodeConverter converter : this.getCodeConverters())
      {
         clazz.instrument(converter);
      }

      // Run the editors
      for (ExprEditor editor : this.getExprEditors())
      {
         clazz.instrument(editor);
      }

      if (log.isLoggable(Level.FINEST))
      {
         PrintWriter out = new PrintWriter(System.out, true);
         out.println("*** constant pool ***");
         file.getConstPool().print(out);
         out.println();
         out.println("*** members ***");
         ClassFileWriter.print(file, out);
      }
     
View Full Code Here

         addDirectory(directory, pool);
   }

   private void addFile(File file, ClassPool pool) throws Exception
   {
      ClassFile cf = createClassFile(file);
      CtClass clazz = pool.get(cf.getName());
      String className = cf.getName();
      String srcRoot = file.getCanonicalPath();
      srcRoot = srcRoot.substring(0, srcRoot.length() - className.length() - 6);
      CheckClassInfo info = new CheckClassInfo(file, srcRoot, clazz);
      classesToCheck.put(className, info);
   }
View Full Code Here

   }

   private ClassFile createClassFile(final File file) throws Exception
   {
      DataInputStream is = new DataInputStream(new FileInputStream(file));
      ClassFile cf = new ClassFile(is);
      is.close();
      return cf;
   }
View Full Code Here

TOP

Related Classes of javassist.bytecode.ClassFile

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.