Package javassist

Examples of javassist.CtClass


        pool.appendClassPath(new LoaderClassPath(loader));

        ClassFactory cf = new ClassFactoryImpl(loader, pool, logger);

        CtClass ctClass = pool.get(componentClassName);

        replay();

        InternalClassTransformation transformation = new InternalClassTransformationImpl(cf, ctClass, null, model,
                                                                                         null);
View Full Code Here


     */
    private Map _ctClassCache = new HashMap();

    public void addInterface(Class interfaceClass)
    {
        CtClass ctInterfaceClass = _source.getCtClass(interfaceClass);

        _ctClass.addInterface(ctInterfaceClass);
    }
View Full Code Here

        int count = inputClasses.length;
        CtClass[] result = new CtClass[count];

        for (int i = 0; i < count; i++)
        {
            CtClass ctClass = convertClass(inputClasses[i]);

            result[i] = ctClass;
        }

        return result;
View Full Code Here

    /**
     * @since 1.1
     */
    protected CtClass convertClass(Class inputClass)
    {
        CtClass result = (CtClass) _ctClassCache.get(inputClass);

        if (result == null)
        {
            result = _source.getCtClass(inputClass);
            _ctClassCache.put(inputClass, result);
View Full Code Here

        return buffer.toString();
    }

    public void addCatch(Class exceptionClass, String catchBody)
    {
        CtClass ctException = _source.getCtClass(exceptionClass);

        try
        {
            _method.addCatch(catchBody, ctException);
        }
View Full Code Here

        return getCtClass().getName();
    }
   
    public void addField(String name, Class type)
    {
        CtClass ctType = convertClass(type);

        try
        {
            CtField field = new CtField(ctType, name, getCtClass());
            field.setModifiers(Modifier.PRIVATE);
View Full Code Here

    public MethodFab addMethod(int modifiers, MethodSignature ms, String body)
    {
        if (_methods.get(ms) != null)
            throw new ApplicationRuntimeException(ServiceMessages.duplicateMethodInClass(ms, this));

        CtClass ctReturnType = convertClass(ms.getReturnType());

        CtClass[] ctParameters = convertClasses(ms.getParameterTypes());
        CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes());

        CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass());
View Full Code Here

    public ClassFab newClass(String name, Class superClass)
    {
        try
        {
            CtClass ctNewClass = _classSource.newClass(name, superClass);

            return new ClassFabImpl(_classSource, ctNewClass);
        }
        catch (Exception ex)
        {
View Full Code Here

    public InterfaceFab newInterface(String name)
    {
        try
        {
            CtClass ctNewClass = _classSource.newInterface(name);

            return new InterfaceFabImpl(_classSource, ctNewClass);
        }
        catch (Exception ex)
        {
View Full Code Here

  public static BeanInterface createJavassistBean() {
    try {
      ClassPool classPool = new ClassPool();
      classPool.appendClassPath(new LoaderClassPath(BeanInterface.class
          .getClassLoader()));
      CtClass theClass = classPool
          .makeClass(ClassFabUtils.generateClassName( BeanInterface.class ) );

      theClass.addInterface(classPool.get(BeanInterface.class.getName()));
      CtMethod theMethod = new CtMethod(
          classPool.get("java.lang.String"), "interfaceMethod",
          new CtClass[0], theClass);
      theMethod.setBody("return \"Hello, World!\";");
      theClass.addMethod(theMethod);
      Class clazz = theClass.toClass();
      return ( BeanInterface )clazz.newInstance();
    } catch (Exception e) {
      throw new ApplicationRuntimeException("Cannot construct instance.",
          e);
    }
View Full Code Here

TOP

Related Classes of 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.