Package javassist.compiler

Examples of javassist.compiler.Javac


        CodeAttribute ca = methodInfo.getCodeAttribute();
        CodeIterator iterator = ca.iterator();
        Bytecode b = new Bytecode(methodInfo.getConstPool(),
                                  ca.getMaxStack(), ca.getMaxLocals());
        b.setStackDepth(ca.getMaxStack());
        Javac jv = new Javac(b, declaringClass);
        try {
            jv.recordParams(getParameterTypes(), false);
            jv.compileStmnt(src);
            ca.setMaxStack(b.getMaxStack());
            ca.setMaxLocals(b.getMaxLocals());
            iterator.skipConstructor();
            int pos = iterator.insertEx(b.get());
            iterator.insert(b.getExceptionTable(), pos);
View Full Code Here


     */
    public static CtMethod make(String src, CtClass declaring,
                                String delegateObj, String delegateMethod)
        throws CannotCompileException
    {
        Javac compiler = new Javac(declaring);
        try {
            if (delegateMethod != null)
                compiler.recordProceed(delegateObj, delegateMethod);

            CtMember obj = compiler.compile(src);
            if (obj instanceof CtMethod)
                return (CtMethod)obj;
        }
        catch (CompileError e) {
            throw new CannotCompileException(e);
View Full Code Here

     * @param declaring    the class to which the created field is added.
     */
    public static CtField make(String src, CtClass declaring)
        throws CannotCompileException
    {
        Javac compiler = new Javac(declaring);
        try {
            CtMember obj = compiler.compile(src);
            if (obj instanceof CtField)
                return (CtField)obj; // an instance of Javac.CtFieldWithInit
        }
        catch (CompileError e) {
            throw new CannotCompileException(e);
View Full Code Here

        ConstPool cp = methodInfo.getConstPool();
        CodeAttribute ca = methodInfo.getCodeAttribute();
        CodeIterator iterator = ca.iterator();
        Bytecode b = new Bytecode(cp, ca.getMaxStack(), ca.getMaxLocals());
        b.setStackDepth(1);
        Javac jv = new Javac(b, declaringClass);
        try {
            jv.recordParams(getParameterTypes(),
                            Modifier.isStatic(getModifiers()));
            int var = jv.recordVariable(exceptionType, exceptionName);
            b.addAstore(var);
            jv.compileStmnt(src);

            int stack = b.getMaxStack();
            int locals = b.getMaxLocals();

            if (stack > ca.getMaxStack())
View Full Code Here

        if (!modify)
            return lineNum;

        declaringClass.checkModify();
        CodeIterator iterator = ca.iterator();
        Javac jv = new Javac(declaringClass);
        try {
            jv.recordLocalVariables(ca, index);
            jv.recordParams(getParameterTypes(),
                            Modifier.isStatic(getModifiers()));
            jv.setMaxLocals(ca.getMaxLocals());
            jv.compileStmnt(src);
            Bytecode b = jv.getBytecode();
            int locals = b.getMaxLocals();
            int stack = b.getMaxStack();
            ca.setMaxLocals(locals);

            /* We assume that there is no values in the operand stack
View Full Code Here

     * @param declaring    the class to which the created constructor is added.
     */
    public static CtConstructor make(String src, CtClass declaring)
        throws CannotCompileException
    {
        Javac compiler = new Javac(declaring);
        try {
            CtMember obj = compiler.compile(src);
            if (obj instanceof CtConstructor)
                return (CtConstructor)obj;
        }
        catch (CompileError e) {
            throw new CannotCompileException(e);
View Full Code Here

                        String delegateObj, String delegateMethod)
        throws CannotCompileException
    {
        declaringClass.checkModify();
        try {
            Javac jv = new Javac(declaringClass);
            if (delegateMethod != null)
                jv.recordProceed(delegateObj, delegateMethod);

            Bytecode b = jv.compileBody(this, src);
            methodInfo.setCodeAttribute(b.toCodeAttribute());
            methodInfo.setAccessFlags(methodInfo.getAccessFlags()
                                      & ~AccessFlag.ABSTRACT);
        }
        catch (CompileError e) {
View Full Code Here

        CodeAttribute ca = methodInfo.getCodeAttribute();
        if (ca == null)
            throw new CannotCompileException("no method body");

        CodeIterator iterator = ca.iterator();
        Javac jv = new Javac(declaringClass);
        try {
            int nvars = jv.recordParams(getParameterTypes(),
                                        Modifier.isStatic(getModifiers()));
            jv.recordParamNames(ca, nvars);
            jv.recordLocalVariables(ca, 0);
            jv.compileStmnt(src);
            Bytecode b = jv.getBytecode();
            int stack = b.getMaxStack();
            int locals = b.getMaxLocals();

            if (stack > ca.getMaxStack())
                ca.setMaxStack(stack);
View Full Code Here

        CodeIterator iterator = ca.iterator();
        int retAddr = ca.getMaxLocals();
        Bytecode b = new Bytecode(pool, 0, retAddr + 1);
        b.setStackDepth(ca.getMaxStack() + 1);
        Javac jv = new Javac(b, declaringClass);
        try {
            int nvars = jv.recordParams(getParameterTypes(),
                                        Modifier.isStatic(getModifiers()));
            jv.recordParamNames(ca, nvars);
            CtClass rtype = getReturnType0();
            int varNo = jv.recordReturnType(rtype, true);
            jv.recordLocalVariables(ca, 0);

            int handlerLen = insertAfterHandler(asFinally, b, rtype, varNo);

            byte[] save = makeSaveCode(pool, rtype, varNo);
            byte[] restore = makeRestoreCode(b, pool, rtype, varNo);

            b.addAstore(retAddr);
            jv.compileStmnt(src);
            b.addRet(retAddr);
            ca.setMaxStack(b.getMaxStack());
            ca.setMaxLocals(b.getMaxLocals());

            int gapPos = iterator.append(b.get());
View Full Code Here

/*     */     }
/*     */     int opcodeSize;
/*     */     String signature;
/*     */     String methodname;
/*     */     String classname;
/* 203 */     Javac jc = new Javac(this.thisClass);
/* 204 */     ClassPool cp = this.thisClass.getClassPool();
/* 205 */     CodeAttribute ca = this.iterator.get();
/*     */     try {
/* 207 */       CtClass[] params = Descriptor.getParameterTypes(signature, cp);
/* 208 */       CtClass retType = Descriptor.getReturnType(signature, cp);
/* 209 */       int paramVar = ca.getMaxLocals();
/* 210 */       jc.recordParams(classname, params, true, paramVar, withinStatic());
/*     */
/* 212 */       int retVar = jc.recordReturnType(retType, true);
/* 213 */       if (c == 184)
/* 214 */         jc.recordStaticProceed(classname, methodname);
/* 215 */       else if (c == 183) {
/* 216 */         jc.recordSpecialProceed("$0", classname, methodname, signature);
/*     */       }
/*     */       else {
/* 219 */         jc.recordProceed("$0", methodname);
/*     */       }
/*     */
/* 223 */       checkResultValue(retType, statement);
/*     */
/* 225 */       Bytecode bytecode = jc.getBytecode();
/* 226 */       storeStack(params, c == 184, paramVar, bytecode);
/* 227 */       jc.recordLocalVariables(ca, pos);
/*     */
/* 229 */       if (retType != CtClass.voidType) {
/* 230 */         bytecode.addConstZero(retType);
/* 231 */         bytecode.addStore(retVar, retType);
/*     */       }
/*     */
/* 234 */       jc.compileStmnt(statement);
/* 235 */       if (retType != CtClass.voidType) {
/* 236 */         bytecode.addLoad(retVar, retType);
/*     */       }
/* 238 */       replace0(pos, bytecode, opcodeSize);
/*     */     } catch (CompileError e) {
View Full Code Here

TOP

Related Classes of javassist.compiler.Javac

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.