Package javassist

Examples of javassist.CtConstructor


        try
        {
            // And have a public constructor.

            CtConstructor ctor = ctClass.getConstructor("()V");

            if (!Modifier.isPublic(ctor.getModifiers()))
                return;
        }
        catch (NotFoundException ex)
        {
            return;
View Full Code Here


    {
        String initializer = _idAllocator.allocateId("initializer");

        try
        {
            CtConstructor defaultConstructor = _ctClass.getConstructor("()V");

            CtMethod initializerMethod = defaultConstructor.toMethod(initializer, _ctClass);

            _ctClass.addMethod(initializerMethod);
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }

        _formatter.format("convert default constructor: %s();\n\n", initializer);

        int count = _constructorArgs.size();

        CtClass[] types = new CtClass[count];

        for (int i = 0; i < count; i++)
        {
            ConstructorArg arg = _constructorArgs.get(i);

            types[i] = arg.getType();
        }

        // Add a call to the initializer; the method converted fromt the classes default
        // constructor.

        _constructor.append("  ");
        _constructor.append(initializer);

        // This finally matches the "{" added inside the constructor

        _constructor.append("();\n\n}");

        String constructorBody = _constructor.toString();

        try
        {
            CtConstructor cons = CtNewConstructor.make(types, null, constructorBody, _ctClass);
            _ctClass.addConstructor(cons);
        }
        catch (CannotCompileException ex)
        {
            throw new RuntimeException(ex);
View Full Code Here

                try
                {
                    // And have a public constructor.

                    CtConstructor ctor = ctClass.getConstructor("()V");

                    if (!Modifier.isPublic(ctor.getModifiers()))
                        return;
                }
                catch (NotFoundException ex)
                {
                    return;
View Full Code Here

            builder.addln("%s = $%d;", name, 3 + i);
        }

        builder.end();

        CtConstructor constructor = new CtConstructor(parameterTypes, invocationCtClass);
        constructor.setBody(builder.toString());

        invocationCtClass.addConstructor(constructor);
    }
View Full Code Here

        CtClass ctClass = pool.makeClass(CLASS);

        ctClass.setModifiers(Modifier.ABSTRACT | Modifier.PUBLIC);
        ctClass.addInterface(pool.get(ReloadableService.class.getName()));

        CtConstructor constructor = new CtConstructor(new CtClass[0], ctClass);

        constructor.setBody("return $0;");

        constructor.setModifiers(Modifier.PROTECTED);

        ctClass.addConstructor(constructor);

        ctClass.writeFile(classesDir.getAbsolutePath());
    }
View Full Code Here

        try
        {
            // And have a public constructor.

            CtConstructor ctor = ctClass.getConstructor("()V");

            if (!Modifier.isPublic(ctor.getModifiers())) return;
        }
        catch (NotFoundException ex)
        {
            return;
        }
View Full Code Here

        int lineNumber = 0;

        try
        {
            CtConstructor ctConstructor = ctClass.getConstructor(descripton.toString());

            lineNumber = ctConstructor.getMethodInfo().getLineNumber(0);

            String sourceFile = ctConstructor.getDeclaringClass().getClassFile2().getSourceFile();

            builder.append(String.format(" (at %s:%d)", sourceFile, lineNumber));
        }
        catch (Exception ex)
        {
View Full Code Here

        try
        {
            // And have a public constructor.

            CtConstructor ctor = ctClass.getConstructor("()V");

            if (!Modifier.isPublic(ctor.getModifiers())) return;
        }
        catch (NotFoundException ex)
        {
            return;
        }
View Full Code Here

        CtBehavior[] cb = thisClass.getDeclaredBehaviors();
        for (int i = cb.length - 1; i >= 0; --i)
            if (cb[i].getMethodInfo2() == mi)
                return cb[i];

        CtConstructor init = thisClass.getClassInitializer();
        if (init != null && init.getMethodInfo2() == mi)
            return init;

        /* getDeclaredBehaviors() returns a list of methods/constructors.
         * Although the list is cached in a CtClass object, it might be
         * recreated for some reason.  Thus, the member name and the signature
View Full Code Here

                    keyGenerator = keyGeneratorClass.newInstance();
                }
            }
           
            ResourceBundle resBundle = ResourceBundle.getBundle(ifaceName, locale);
            CtConstructor ctorMethod = new CtConstructor(new CtClass[] {localeClass}, impl);
            impl.addConstructor(ctorMethod);
            ctorMethod.setModifiers(Modifier.PUBLIC);
            ctorMethod.setBody("super();");
            CtField localeField = new CtField(localeClass, "_locale", impl);
            impl.addField(localeField, CtField.Initializer.byParameter(0));
            TreeMap<String,String> keys = new TreeMap<String,String>();
            for(CtMethod method : iface.getMethods()) {
                // Only abstract methods
View Full Code Here

TOP

Related Classes of javassist.CtConstructor

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.