Examples of CtConstructor


Examples of javassist.CtConstructor

    {
        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

Examples of javassist.CtConstructor

        shell = context.mock(Shell.class);

        ClassPool pool = ClassPool.getDefault();
        pool.appendClassPath(new ClassClassPath(MockedAnimatedCanvas.class));
        CtClass ctControl = pool.makeClass("MockedAnimatedCanvas");
        ctControl.addConstructor(new CtConstructor());

        context.checking(new Expectations() {{
            oneOf(display).isDisposed(); will(returnValue(false));
            oneOf(shell).isDisposed(); will(returnValue(false));
            oneOf(shell).checkWidget(); will(returnValue(false));
View Full Code Here

Examples of javassist.CtConstructor

    sourceCode.append(constructor.computeJava14Signature(ClassUtils.getShortClassName(proxyClass.getName())));
    sourceCode.append(constructor.getCode());
   
  //  Add method body
  //
    CtConstructor ctConstructor = CtNewConstructor.make(sourceCode.toString(), proxyClass);
    proxyClass.addConstructor(ctConstructor);
  }
View Full Code Here

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

Examples of javassist.CtConstructor

    {
        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

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

Examples of javassist.CtConstructor

        // constructors
        List constructorList = new ArrayList();
        CtConstructor[] constructors = javaClass.getConstructors();
        for (int i = 0; i < constructors.length; i++) {
            CtConstructor constructor = constructors[i];
            constructorList.add(createConstructorMetaData(constructor));
        }
        classMetaData.setConstructors(constructorList);

        // methods
View Full Code Here

Examples of javassist.CtConstructor

        field.setModifiers(syntheticModifier);

        javassistClass.addField(field);

        CtConstructor ctor = new CtConstructor(new CtClass[]{CtClass.intType}, javassistClass);

        ctor.setModifiers(syntheticModifier);

        ctor.setBody("{super();}");

        javassistClass.addConstructor(ctor);


View Full Code Here

Examples of javassist.CtConstructor

            if (classFilter(definition, new ExpressionContext(PointcutType.EXECUTION, classInfo, classInfo), ctClass)) {
                continue;
            }
            final CtConstructor[] constructors = ctClass.getConstructors();
            for (int i = 0; i < constructors.length; i++) {
                CtConstructor constructor = constructors[i];
                ConstructorInfo constructorInfo = JavassistConstructorInfo.getConstructorInfo(constructor, context
                        .getLoader());
                ExpressionContext ctx = new ExpressionContext(PointcutType.EXECUTION, constructorInfo, constructorInfo);
                if (constructorFilter(definition, ctx)) {
                    continue;
View Full Code Here

Examples of javassist.CtConstructor

            newParameterTypes[i] = parameterTypes[i];
        }
        newParameterTypes[parameterTypes.length] = ctClass.getClassPool().get(
            TransformationUtil.JOIN_POINT_MANAGER_CLASS);
        if (!JavassistHelper.hasConstructor(ctClass, newParameterTypes)) {
            CtConstructor newConstructor = CtNewConstructor.make(
                newParameterTypes,
                constructor.getExceptionTypes(),
                CtNewConstructor.PASS_NONE,
                null,
                CtMethod.ConstParameter.string(constructor.getSignature()),
                ctClass);
            newConstructor.setBody(constructor, null);
            newConstructor.setModifiers(accessFlags);
            CodeAttribute codeAttribute = newConstructor.getMethodInfo().getCodeAttribute();
            codeAttribute.setMaxLocals(codeAttribute.getMaxLocals() + 1);
            ctClass.addConstructor(newConstructor);
            return true;
        } else {
            return false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.