Search in sources :

Example 16 with CtClass

use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.

the class MultiType method getAllMultiInterfaces.

private Map getAllMultiInterfaces(MultiType type) {
    Map map = new HashMap();
    Iterator iter = type.interfaces.values().iterator();
    while (iter.hasNext()) {
        CtClass intf = (CtClass) iter.next();
        map.put(intf.getName(), intf);
        getAllInterfaces(intf, map);
    }
    return map;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with CtClass

use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.

the class Type method getDeclaredInterfaces.

Map getDeclaredInterfaces(CtClass clazz, Map map) {
    if (map == null)
        map = new HashMap();
    if (clazz.isInterface())
        map.put(clazz.getName(), clazz);
    CtClass[] interfaces;
    try {
        interfaces = clazz.getInterfaces();
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }
    for (int i = 0; i < interfaces.length; i++) {
        CtClass intf = interfaces[i];
        map.put(intf.getName(), intf);
        getDeclaredInterfaces(intf, map);
    }
    return map;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 18 with CtClass

use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.

the class Type method getAllInterfaces.

Map getAllInterfaces(CtClass clazz, Map map) {
    if (map == null)
        map = new HashMap();
    if (clazz.isInterface())
        map.put(clazz.getName(), clazz);
    do {
        try {
            CtClass[] interfaces = clazz.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                CtClass intf = interfaces[i];
                map.put(intf.getName(), intf);
                getAllInterfaces(intf, map);
            }
            clazz = clazz.getSuperclass();
        } catch (NotFoundException e) {
            throw new RuntimeException(e);
        }
    } while (clazz != null);
    return map;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 19 with CtClass

use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.

the class Type method findCommonInterfaces.

Map findCommonInterfaces(Map typeMap, Map alterMap) {
    Iterator i = alterMap.keySet().iterator();
    while (i.hasNext()) {
        if (!typeMap.containsKey(i.next()))
            i.remove();
    }
    // Reduce to subinterfaces
    // This does not need to be recursive since we make a copy,
    // and that copy contains all super types for the whole hierarchy
    i = new ArrayList(alterMap.values()).iterator();
    while (i.hasNext()) {
        CtClass intf = (CtClass) i.next();
        CtClass[] interfaces;
        try {
            interfaces = intf.getInterfaces();
        } catch (NotFoundException e) {
            throw new RuntimeException(e);
        }
        for (int c = 0; c < interfaces.length; c++) alterMap.remove(interfaces[c].getName());
    }
    return alterMap;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 20 with CtClass

use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.

the class Annotation method createMemberValue.

/**
 * Makes an instance of <code>MemberValue</code>.
 *
 * @param cp            the constant pool table.
 * @param type          the type of the member.
 * @return the member value
 * @throws NotFoundException when the type is not found
 */
public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException {
    if (type == CtClass.booleanType)
        return new BooleanMemberValue(cp);
    else if (type == CtClass.byteType)
        return new ByteMemberValue(cp);
    else if (type == CtClass.charType)
        return new CharMemberValue(cp);
    else if (type == CtClass.shortType)
        return new ShortMemberValue(cp);
    else if (type == CtClass.intType)
        return new IntegerMemberValue(cp);
    else if (type == CtClass.longType)
        return new LongMemberValue(cp);
    else if (type == CtClass.floatType)
        return new FloatMemberValue(cp);
    else if (type == CtClass.doubleType)
        return new DoubleMemberValue(cp);
    else if (type.getName().equals("java.lang.Class"))
        return new ClassMemberValue(cp);
    else if (type.getName().equals("java.lang.String"))
        return new StringMemberValue(cp);
    else if (type.isArray()) {
        CtClass arrayType = type.getComponentType();
        MemberValue member = createMemberValue(cp, arrayType);
        return new ArrayMemberValue(member, cp);
    } else if (type.isInterface()) {
        Annotation info = new Annotation(cp, type);
        return new AnnotationMemberValue(info, cp);
    } else {
        // treat as enum.  I know this is not typed,
        // but JBoss has an Annotation Compiler for JDK 1.4
        // and I want it to work with that. - Bill Burke
        EnumMemberValue emv = new EnumMemberValue(cp);
        emv.setType(type.getName());
        return emv;
    }
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass)

Aggregations

CtClass (org.hotswap.agent.javassist.CtClass)69 NotFoundException (org.hotswap.agent.javassist.NotFoundException)20 CtMethod (org.hotswap.agent.javassist.CtMethod)18 ClassPool (org.hotswap.agent.javassist.ClassPool)14 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)13 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)8 CtConstructor (org.hotswap.agent.javassist.CtConstructor)8 CtField (org.hotswap.agent.javassist.CtField)8 HashMap (java.util.HashMap)6 LoaderClassPath (org.hotswap.agent.javassist.LoaderClassPath)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Test (org.junit.Test)5 Iterator (java.util.Iterator)4 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)4 Method (java.lang.reflect.Method)3 IdentityHashMap (java.util.IdentityHashMap)3 BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2