Package org.hotswap.agent.javassist

Examples of org.hotswap.agent.javassist.CtClass


            case DRETURN:
                verifyAssignable(org.hotswap.agent.javassist.bytecode.analysis.Type.DOUBLE, simplePop(frame));
                break;
            case ARETURN:
                try {
                    CtClass returnType = Descriptor.getReturnType(method.getDescriptor(), classPool);
                    verifyAssignable(org.hotswap.agent.javassist.bytecode.analysis.Type.get(returnType), simplePop(frame));
                } catch (NotFoundException e) {
                    throw new RuntimeException(e);
                }
                break;
View Full Code Here


            throw new BadBytecode("Could not find class [pos = " + lastPos + "]: " + name);
        }
    }

    private org.hotswap.agent.javassist.bytecode.analysis.Type[] paramTypesFromDesc(String desc) throws BadBytecode {
        CtClass classes[] = null;
        try {
            classes = Descriptor.getParameterTypes(desc, classPool);
        } catch (NotFoundException e) {
            throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
        }
View Full Code Here

        return types;
    }

    private org.hotswap.agent.javassist.bytecode.analysis.Type returnTypeFromDesc(String desc) throws BadBytecode {
        CtClass clazz = null;
        try {
            clazz = Descriptor.getReturnType(desc, classPool);
        } catch (NotFoundException e) {
            throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
        }
View Full Code Here

        if (type.getSize() == 2)
            frame.setLocal(index + 1, org.hotswap.agent.javassist.bytecode.analysis.Type.TOP);
    }

    private org.hotswap.agent.javassist.bytecode.analysis.Type resolveClassInfo(String info) throws BadBytecode {
        CtClass clazz = null;
        try {
            if (info.charAt(0) == '[') {
                clazz = Descriptor.toCtClass(info, classPool);
            } else {
                clazz = classPool.get(info);
View Full Code Here

        return org.hotswap.agent.javassist.bytecode.analysis.Type.get(clazz);
    }

    private org.hotswap.agent.javassist.bytecode.analysis.Type typeFromDesc(String desc) throws BadBytecode {
        CtClass clazz = null;
        try {
            clazz = Descriptor.toCtClass(desc, classPool);
        } catch (NotFoundException e) {
            throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
        }
View Full Code Here

    }

    @Test
    public void testHasAnnotationJavassist() throws Exception {
        ClassPool ctPool = ClassPool.getDefault();
        CtClass ctClass = ctPool.getCtClass(AnonymousClassPatchPlugin.class.getName());

        assertTrue(AnnotationHelper.hasAnnotation(ctClass, "org.hotswap.agent.annotation.Plugin"));
        assertFalse(AnnotationHelper.hasAnnotation(ctClass, "xxxx"));
    }
View Full Code Here

                "Boolean.TRUE", "java.lang.Boolean");

        ClassPool classPool = ClassPool.getDefault();
        classPool.appendSystemPath();

        CtClass clazz = classPool.makeClass("Test");
        clazz.addMethod(CtNewMethod.make("public void test() {" + s + "}", clazz));
        Class<?> testClass = clazz.toClass();


        Method testMethod = testClass.getDeclaredMethod("test");
        testMethod.invoke(testClass.newInstance());
View Full Code Here

        lastModifiedTimestamp = lastModified(classPool, className);

        // search for declared classes in new state to skip obsolete anonymous inner classes on filesystem
        List<CtClass> declaredClasses;
        try {
            CtClass ctClass = classPool.get(className);
            declaredClasses = Arrays.asList(ctClass.getNestedClasses());
        } catch (NotFoundException e) {
            throw new IllegalArgumentException("Class " + className + " not found.");
        }


        int i = 1;
        while (true) {
            try {
                CtClass anonymous = classPool.get(className + "$" + i);
                if (!declaredClasses.contains(anonymous))
                    break; // skip obsolete classes
                anonymousClassInfoList.add(i - 1, new AnonymousClassInfo(anonymous));
                i++;
            } catch (NotFoundException e) {
View Full Code Here

    private String getTopType(int pos) throws BadBytecode {
        Frame frame = getFrame(pos);
        if (frame == null)
            return null;

        CtClass clazz = frame.peek().getCtClass();
        return clazz != null ? Descriptor.toJvmName(clazz) : null;
    }
View Full Code Here

                return;
            }
        }

        //we may need to crate CtClass on behalf of the client and close it after invocation.
        CtClass ctClass = null;

        // class file regexp
        if (watchEventDTO.isClassFileEvent()) {
            try {
                // TODO creating class only to check name may slow down if lot of handlers is in use.
                ctClass = createCtClass(event.getURI(), classLoader);
            } catch (Exception e) {
                LOGGER.error("Unable create CtClass for URI '{}'.", e, event.getURI());
                return;
            }

            // unable to create CtClass or it's name does not match
            if (ctClass == null || !ctClass.getName().matches(watchEventDTO.getClassNameRegexp()))
                return;
        }

        LOGGER.debug("Executing resource changed method {} on class {} for event {}",
                pluginAnnotation.getMethod().getName(), plugin.getClass().getName(), event);


        List<Object> args = new ArrayList<Object>();
        for (Class<?> type : pluginAnnotation.getMethod().getParameterTypes()) {
            if (type.isAssignableFrom(ClassLoader.class)) {
                args.add(classLoader);
            } else if (type.isAssignableFrom(URI.class)) {
                args.add(event.getURI());
            } else if (type.isAssignableFrom(URL.class)) {
                try {
                    args.add(event.getURI().toURL());
                } catch (MalformedURLException e) {
                    LOGGER.error("Unable to convert URI '{}' to URL.", e, event.getURI());
                    return;
                }
            } else if (type.isAssignableFrom(ClassPool.class)) {
                args.add(ClassPool.getDefault());
            } else if (type.isAssignableFrom(FileEvent.class)) {
                args.add(event.getEventType());
            } else if (watchEventDTO.isClassFileEvent() && type.isAssignableFrom(CtClass.class)) {
                args.add(ctClass);
            } else if (watchEventDTO.isClassFileEvent() && type.isAssignableFrom(String.class)) {
                args.add(ctClass.getName());
            } else {
                LOGGER.error("Unable to call method {} on plugin {}. Method parameter type {} is not recognized.",
                        pluginAnnotation.getMethod().getName(), plugin.getClass().getName(), type);
                return;
            }
        }
        try {
            pluginAnnotation.getMethod().invoke(plugin, args.toArray());

            // close CtClass if created from here
            if (ctClass != null) {
                ctClass.detach();
            }
        } catch (IllegalAccessException e) {
            LOGGER.error("IllegalAccessException in method {} on plugin {}", e,
                    pluginAnnotation.getMethod().getName(), plugin.getClass().getName());
        } catch (InvocationTargetException e) {
View Full Code Here

TOP

Related Classes of org.hotswap.agent.javassist.CtClass

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.