当前位置: 首页>>代码示例>>Java>>正文


Java ClassPool类代码示例

本文整理汇总了Java中scouter.javassist.ClassPool的典型用法代码示例。如果您正苦于以下问题:Java ClassPool类的具体用法?Java ClassPool怎么用?Java ClassPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassPool类属于scouter.javassist包,在下文中一共展示了ClassPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerClassLoader

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Register a classloader.
 * 
 * @param ucl       the classloader.
 * @return the classpool
 */
public ClassPool registerClassLoader(ClassLoader ucl) {
    synchronized (registeredCLs) {
        // FIXME: Probably want to take this method out later
        // so that AOP framework can be independent of JMX
        // This is in here so that we can remove a UCL from the ClassPool as
        // a
        // ClassPool.classpath
        if (registeredCLs.containsKey(ucl)) {
            return (ClassPool)registeredCLs.get(ucl);
        }
        ScopedClassPool pool = createScopedClassPool(ucl, classpool);
        registeredCLs.put(ucl, pool);
        return pool;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:22,代码来源:ScopedClassPoolRepositoryImpl.java

示例2: getParameterTypes

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Returns the <code>CtClass</code> objects representing the parameter
 * types specified by the given descriptor.
 *
 * @param desc descriptor
 * @param cp   the class pool used for obtaining
 *             a <code>CtClass</code> object.
 */
public static CtClass[] getParameterTypes(String desc, ClassPool cp)
    throws NotFoundException
{
    if (desc.charAt(0) != '(')
        return null;
    else {
        int num = numOfParameters(desc);
        CtClass[] args = new CtClass[num];
        int n = 0;
        int i = 1;
        do {
            i = toCtClass(cp, desc, i, args, n++);
        } while (i > 0);
        return args;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:25,代码来源:Descriptor.java

示例3: getValue

import scouter.javassist.ClassPool; //导入依赖的package包/类
Object getValue(ClassLoader cl, ClassPool cp, Method m)
        throws ClassNotFoundException {
    final String classname = getValue();
    if (classname.equals("void"))
        return void.class;
    else if (classname.equals("int"))
        return int.class;
    else if (classname.equals("byte"))
        return byte.class;
    else if (classname.equals("long"))
        return long.class;
    else if (classname.equals("double"))
        return double.class;
    else if (classname.equals("float"))
        return float.class;
    else if (classname.equals("char"))
        return char.class;
    else if (classname.equals("short"))
        return short.class;
    else if (classname.equals("boolean"))
        return boolean.class;
    else
        return loadClass(cl, classname);
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:25,代码来源:ClassMemberValue.java

示例4: getValue

import scouter.javassist.ClassPool; //导入依赖的package包/类
Object getValue(ClassLoader cl, ClassPool cp, Method method)
    throws ClassNotFoundException
{
    if (values == null)
        throw new ClassNotFoundException(
                    "no array elements found: " + method.getName());

    int size = values.length;
    Class clazz;
    if (type == null) {
        clazz = method.getReturnType().getComponentType();
        if (clazz == null || size > 0)
            throw new ClassNotFoundException("broken array type: "
                                             + method.getName());
    }
    else
        clazz = type.getType(cl);

    Object a = Array.newInstance(clazz, size);
    for (int i = 0; i < size; i++)
        Array.set(a, i, values[i].getValue(cl, cp, method));

    return a;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:25,代码来源:ArrayMemberValue.java

示例5: getCtClass

import scouter.javassist.ClassPool; //导入依赖的package包/类
public CtClass getCtClass() {
    CtClass clazz = component.getCtClass();
    if (clazz == null)
        return null;

    ClassPool pool = clazz.getClassPool();
    if (pool == null)
        pool = ClassPool.getDefault();

    String name = arrayName(clazz.getName(), dims);

    try {
        return pool.get(name);
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:18,代码来源:MultiArrayType.java

示例6: buildExceptionInfo

import scouter.javassist.ClassPool; //导入依赖的package包/类
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();

    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }

        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }

    return exceptions;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:Analyzer.java

示例7: fixTypes2

import scouter.javassist.ClassPool; //导入依赖的package包/类
private String fixTypes2(ArrayList scc, HashSet lowersSet, ClassPool cp) throws NotFoundException {
    Iterator it = lowersSet.iterator();
    if (lowersSet.size() == 0)
        return null;      // only NullType
    else if (lowersSet.size() == 1)
        return (String)it.next(); 
    else {
    	CtClass cc = cp.get((String)it.next());
    	while (it.hasNext())
    		cc = commonSuperClassEx(cc, cp.get((String)it.next()));

    	if (cc.getSuperclass() == null || isObjectArray(cc))
    	    cc = fixByUppers(scc, cp, new HashSet(), cc);

    	if (cc.isArray())
    	    return Descriptor.toJvmName(cc);
    	else
    	    return cc.getName();
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:TypeData.java

示例8: fixByUppers

import scouter.javassist.ClassPool; //导入依赖的package包/类
private CtClass fixByUppers(ArrayList users, ClassPool cp, HashSet visited, CtClass type)
    throws NotFoundException
{
    if (users == null)
        return type;

    int size = users.size();
    for (int i = 0; i < size; i++) {
        TypeVar t = (TypeVar)users.get(i);
        if (!visited.add(t))
            return type;

        if (t.uppers != null) {
            int s = t.uppers.size();
            for (int k = 0; k < s; k++) {
                CtClass cc = cp.get((String)t.uppers.get(k));
                if (cc.subtypeOf(type))
                    type = cc;
            }
        }

        type = fixByUppers(t.usedBy, cp, visited, type);
    }

    return type;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:27,代码来源:TypeData.java

示例9: aastore

import scouter.javassist.ClassPool; //导入依赖的package包/类
public static void aastore(TypeData array, TypeData value, ClassPool cp) throws BadBytecode {
    if (array instanceof AbsTypeVar)
        if (!value.isNullType())
            ((AbsTypeVar)array).merge(ArrayType.make(value));

    if (value instanceof AbsTypeVar)
        if (array instanceof AbsTypeVar)
            ArrayElement.make(array);   // should call value.setType() later.
        else if (array instanceof ClassName) {
            if (!array.isNullType()) {
                String type = ArrayElement.typeName(array.getName());
                value.setType(type, cp);
            }
        }
        else
            throw new BadBytecode("bad AASTORE: " + array);
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:18,代码来源:TypeData.java

示例10: ScopedClassPool

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Create a new ScopedClassPool.
 * 
 * @param cl
 *            the classloader
 * @param src
 *            the original class pool
 * @param repository
 *            the repository
 * @param isTemp
 *            Whether this is a temporary pool used to resolve references
 */
protected ScopedClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, boolean isTemp)
{
   super(src);
   this.repository = repository;
   this.classLoader = new WeakReference(cl);
   if (cl != null) {
       classPath = new LoaderClassPath(cl);
       this.insertClassPath(classPath);
   }
   childFirstLookup = true;
   if (!isTemp && cl == null)
   {
      isBootstrapCl = true;
   }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:28,代码来源:ScopedClassPool.java

示例11: fixTypes2

import scouter.javassist.ClassPool; //导入依赖的package包/类
private String fixTypes2(ArrayList scc, HashSet lowersSet, ClassPool cp) throws NotFoundException {
    Iterator it = lowersSet.iterator();
    if (lowersSet.size() == 0)
        return null;      // only NullType
    else if (lowersSet.size() == 1)
        return (String)it.next(); 
    else {
        CtClass cc = cp.get((String)it.next());
        while (it.hasNext())
            cc = commonSuperClassEx(cc, cp.get((String)it.next()));

        if (cc.getSuperclass() == null || isObjectArray(cc))
            cc = fixByUppers(scc, cp, new HashSet(), cc);

        if (cc.isArray())
            return Descriptor.toJvmName(cc);
        else
            return cc.getName();
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:21,代码来源:TypeData.java

示例12: start

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Initializes the object.
 * This is a method declared in Translator.
 *
 * @see Translator#start(ClassPool)
 */
public void start(ClassPool pool) throws NotFoundException {
    classPool = pool;
    CtClass c = pool.get(sampleClass);
    forwardMethod = c.getDeclaredMethod("forward");
    forwardStaticMethod = c.getDeclaredMethod("forwardStatic");

    proxyConstructorParamTypes
        = pool.get(new String[] { "ObjectImporter",
                                     "int" });
    interfacesForProxy
        = pool.get(new String[] { "java.io.Serializable",
                                     "Proxy" });
    exceptionForProxy
        = new CtClass[] { pool.get("RemoteException") };
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:22,代码来源:StubGenerator.java

示例13: ScopedClassPoolRepositoryImpl

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Singleton.
 */
private ScopedClassPoolRepositoryImpl() {
    classpool = ClassPool.getDefault();
    // FIXME This doesn't look correct
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    classpool.insertClassPath(new LoaderClassPath(cl));
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:10,代码来源:ScopedClassPoolRepositoryImpl.java

示例14: getReturnType

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Returns the <code>CtClass</code> object representing the return
 * type specified by the given descriptor.
 *
 * @param desc descriptor
 * @param cp   the class pool used for obtaining
 *             a <code>CtClass</code> object.
 */
public static CtClass getReturnType(String desc, ClassPool cp)
    throws NotFoundException
{
    int i = desc.indexOf(')');
    if (i < 0)
        return null;
    else {
        CtClass[] type = new CtClass[1];
        toCtClass(cp, desc, i + 1, type, 0);
        return type[0];
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:Descriptor.java

示例15: toCtClass

import scouter.javassist.ClassPool; //导入依赖的package包/类
/**
 * Returns a <code>CtClass</code> object representing the type
 * specified by the given descriptor.
 *
 * <p>This method works even if the package-class separator is
 * not <code>/</code> but <code>.</code> (period).  For example,
 * it accepts <code>Ljava.lang.Object;</code>
 * as well as <code>Ljava/lang/Object;</code>.
 *
 * @param desc descriptor.
 * @param cp   the class pool used for obtaining
 *             a <code>CtClass</code> object.
 */
public static CtClass toCtClass(String desc, ClassPool cp)
    throws NotFoundException
{
    CtClass[] clazz = new CtClass[1];
    int res = toCtClass(cp, desc, 0, clazz, 0);
    if (res >= 0)
        return clazz[0];
    else {
        // maybe, you forgot to surround the class name with
        // L and ;.  It violates the protocol, but I'm tolerant...
        return cp.get(desc.replace('/', '.'));
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:27,代码来源:Descriptor.java


注:本文中的scouter.javassist.ClassPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。