Package javassist

Examples of javassist.ClassPool


      {
         for (int i = 0; i < mixins.length; i++)
         {
            HashSet<Long> mixinMethods = new HashSet<Long>();
            Class<?>[] mixinf = mixins[i].getInterfaces();
            ClassPool mixPool = AspectManager.instance().findClassPool(mixins[i].getMixin().getClass());
            CtClass mixClass = mixPool.get(mixins[i].getMixin().getClass().getName());
            for (int j = 0; j < mixinf.length; j++)
            {
               if (addedInterfaces.contains(mixinf[j].getName())) throw new Exception("2 mixins are implementing the same interfaces");
               ClassPool mixIntfPool = AspectManager.instance().findClassPool(mixinf[j]);
               CtClass intfClass = mixIntfPool.get(mixinf[j].getName());
               CtMethod[] methods = intfClass.getMethods();
               for (int m = 0; m < methods.length; m++)
               {
                  if (methods[m].getDeclaringClass().getName().equals("java.lang.Object")) continue;
                  Long hash = Long.valueOf(JavassistMethodHashing.methodHash(methods[m]));
View Full Code Here


      if (cl == null)
      {
         cl = SecurityActions.getClassLoader(clazz);
      }
     
      ClassPool pool = AspectManager.instance().findClassPool(cl);
     
      if (pool == null) throw new NullPointerException("Could not find ClassPool");

      Class<?> proxyClass = null;
      synchronized (maplock)
      {
         WeakHashMap<Class<?>, Map<ContainerProxyCacheKey, WeakReference<Class<?>>>> proxiesForLoader = proxyCache.get(pool.getClassLoader());
         if (proxiesForLoader == null)
         {
            proxiesForLoader = new WeakHashMap<Class<?>, Map<ContainerProxyCacheKey, WeakReference<Class<?>>>>();
            proxyCache.put(pool.getClassLoader(), proxiesForLoader);
         }

         Map<ContainerProxyCacheKey, WeakReference<Class<?>>> map = proxiesForLoader.get(clazz);
         if (map == null)
         {
View Full Code Here

    */
   static CtClass getCtClass(Class clazz)
   {
      try
      {
         ClassPool pool = repository.findClassPool(clazz.getClassLoader());
         return pool.get(clazz.getName());
      }
      catch (NotFoundException e)
      {
         throw new RuntimeException("Unable to load CtClass for " + clazz, e);
      }
View Full Code Here

    */
   public void init() {
      initClassRenames();
     
      // Set up default converters and editors
      ClassPool pool = ClassPool.getDefault();
      try {
         if (this.getClasspath() != null) {
            pool.appendPathList(this.getClasspath());
         }
        
         addCodeConverter(new AutoboxCodeConverter(pool));
      } catch (NotFoundException nfe) {
         log.severe("Unable to construct default code converter");
View Full Code Here

      if( args.length != 2 )
         throw new IllegalArgumentException("Usage: FindExceptionCtorChanges path-to-jdk14/rt.jar path-to-jdk15/rt.jar");

      String jdk14Jar = args[0];
      JarFile jdk14JarFile = new JarFile(jdk14Jar);
      ClassPool jdk14Pool = new ClassPool();
      jdk14Pool.appendClassPath(jdk14Jar);
      CtClass jdk14Throwable = jdk14Pool.get("java.lang.Throwable");
      HashMap<String, CtClass> throwables14 = new HashMap<String, CtClass>();
      scanJar(jdk14JarFile, jdk14Pool, jdk14Throwable, throwables14);
      log.info("jdk14 throwable count: "+throwables14.size());

      String jdk5Jar = args[1];
      JarFile jdk5JarFile = new JarFile(jdk5Jar);
      ClassPool jdk5Pool = new ClassPool();
      jdk5Pool.appendClassPath(jdk5Jar);
      CtClass jdk5Throwable = jdk5Pool.get("java.lang.Throwable");
      HashMap<String, CtClass> throwables5 = new HashMap<String, CtClass>();
      scanJar(jdk5JarFile, jdk5Pool, jdk5Throwable, throwables5);
      log.info("jdk5 throwable count: "+throwables5.size());

      // For each jdk14 excetion, find the exceptions with new ctor signatures
View Full Code Here

      this.tmpClassesDir = tmpClassesDir;
   }
  
   public synchronized ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
   {
      ClassPool parent = getCreateParentClassPools(cl, src, repository);

      if (cl instanceof RepositoryClassLoader)
      {
         ClassPoolDomain domain = getDomain((RepositoryClassLoader)cl)
        
View Full Code Here

      }
     

      try
      {
         ClassPool pool = getCorrectPoolForResource(classname, url);
         if (pool != lastPool.get())
         {
            lastPool.set(pool);
            return pool.get(classname);
         }
      }
      catch (NotFoundException e)
      {
      }
View Full Code Here

         paths.add(f.toURL());
      }
      urls = paths.toArray(new URL[paths.size()]);
      ClassLoader poolLoader = new URLClassLoader(urls, EmptyClassLoader.EMPTY);
     
      ClassPool pool = new ClassPool(false);
      pool.appendClassPath(new CheckerClassPath(poolLoader));
      pool.appendClassPath(new ClassClassPath(Object.class));
     
      //Add all the classes to compile
      for (File f : files)
      {
         if (f.isDirectory())
View Full Code Here

   public int doCheck(ClassLoader cl, CheckClassInfo info)
   {
      CtClass clazz = info.getClazz();
      ClassFile file = clazz.getClassFile();
      ClassPool pool = clazz.getClassPool();
     
      int failed = 0;
     
      // Incorrect major version
      int major = file.getMajorVersion();
      if (major > 48)
      {
         if (failed == 0)
            System.out.println("==== " + info.getFile());
         System.out.println("Wrong major version " + major);
         ++failed;
      }

      // Check the super class exists
      String superClassName = file.getSuperclass();
      try
      {
         pool.get(superClassName);
      }
      catch (NotFoundException e)
      {
         if (failed == 0)
            System.out.println("==== " + info.getFile());
         System.out.println("SuperClass not found " + superClassName);
         ++failed;
      }
     
      // Check the interfaces exist
      String[] intfs = file.getInterfaces();
      for (String intf : intfs)
      {
         try
         {
            pool.get(intf);
         }
         catch (NotFoundException e)
         {
            if (failed == 0)
               System.out.println("==== " + info.getFile());
            System.out.println("Interface not found " + intf);
            ++failed;
         }
      }

      // Check the field types
      List<FieldInfo> fields = (List<FieldInfo>) file.getFields();
      for (FieldInfo field : fields)
      {
         String name = field.getName();
         String typeName = Descriptor.toJavaName(field.getDescriptor());
         try
         {
            CtField ctField = clazz.getField(name);
            ctField.getType();
         }
         catch (NotFoundException e)
         {
            if (failed == 0)
               System.out.println("==== " + info.getFile());
            System.out.println("Class not found " + typeName + " for field " + name);
            ++failed;
         }
      }

      // Check the method types
      List<MethodInfo> methods = (List<MethodInfo>) file.getMethods();
      for (MethodInfo method : methods)
      {
         String name = method.getName();
         String descriptor = method.getDescriptor();
        
         if (CLINIT.equals(name))
            continue;
        
         try
         {
            if (INIT.equals(name) == false)
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getReturnType();
            }
         }
         catch (NotFoundException e)
         {
            if (failed == 0)
               System.out.println("==== " + info.getFile());
            System.out.println("Return type not found for method " + name + "." + descriptor);
            ++failed;
         }
        
         if (INIT.equals(name))
         {
            try
            {
               CtConstructor ctConstructor = clazz.getConstructor(descriptor);
               ctConstructor.getParameterTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find constructor parameter types " + name + "." + descriptor);
               ++failed;
            }
            try
            {
               CtConstructor ctConstructor = clazz.getConstructor(descriptor);
               ctConstructor.getExceptionTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find constructor exception types " + name + "." + descriptor);
               ++failed;
            }
         }
         else
         {
            try
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getParameterTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find method parameter types " + name + "." + descriptor);
               ++failed;
            }
            try
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getExceptionTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find method exception types " + name + "." + descriptor);
               ++failed;
            }
         }
      }

      // Now we've checked the signatures of the class, let's look at the references
      file.compact();
      ConstPool consts = file.getConstPool();
      for (int i = 1; i < consts.getSize(); ++i) // Yes start at 1
      {
         switch (consts.getTag(i))
         {
            case ConstPool.CONST_Fieldref:
            {
               String type = consts.getFieldrefClassName(i);
               String name = consts.getFieldrefName(i);
               try
               {
                  CtClass ctClazz = pool.get(type);
                  ctClazz.getField(name);
               }
               catch (NotFoundException e)
               {
                  if (failed == 0)
                     System.out.println("==== " + info.getFile());
                  System.out.println("Cannot find field " + type + "." + name);
                  ++failed;
               }
               break;
            }
            case ConstPool.CONST_InterfaceMethodref:
            {
               String type = consts.getInterfaceMethodrefClassName(i);
               String name = consts.getInterfaceMethodrefName(i);
               String descriptor = consts.getInterfaceMethodrefType(i);
               try
               {
                  CtClass ctClazz = pool.get(type);
                  ctClazz.getMethod(name, descriptor);
               }
               catch (NotFoundException e)
               {
                  if (failed == 0)
                     System.out.println("==== " + info.getFile());
                  System.out.println("Cannot find interface method " + type + "." + name + descriptor);
                  ++failed;
               }
               break;
            }
            case ConstPool.CONST_Methodref:
            {
               String type = consts.getMethodrefClassName(i);
               String name = consts.getMethodrefName(i);
               String descriptor = consts.getMethodrefType(i);
               if (INIT.equals(name))
               {
                  try
                  {
                     CtClass ctClazz = pool.get(type);
                     ctClazz.getConstructor(descriptor);
                  }
                  catch (NotFoundException e)
                  {
                     if (failed == 0)
                        System.out.println("==== " + info.getFile());
                     System.out.println("Cannot find constructor " + type + descriptor);
                     ++failed;
                  }
               }
               else
               {
                  try
                  {
                     CtClass ctClazz = pool.get(type);
                     ctClazz.getMethod(name, descriptor);
                  }
                  catch (NotFoundException e)
                  {
                     if (failed == 0)
View Full Code Here

      this.tmpClassesDir = tmpClassesDir;

   }
   public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
   {
      ClassPool parent = getCreateParentClassPools(cl, src, repository);
      if (cl instanceof RepositoryClassLoader)
      {
         File tempdir = getTempDirectory(cl);
         URL tmpCP;
         try
View Full Code Here

TOP

Related Classes of javassist.ClassPool

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.