Package javassist

Examples of javassist.CtBehavior


                                }
                                catch (NullPointerException e) {
                                    return;
                                }

                                CtBehavior where = null;
                                try {
                                    where = handlerExpr.where();
                                }
                                catch (RuntimeException e) {
                                    // <clinit> access leads to a bug in Javassist
                                    where = ctClass.getClassInitializer();
                                }

                                MethodMetaData methodMetaData = null; //JavassistMetaDataMaker.createMethodMetaData(...);

                                ClassMetaData exceptionClassMetaData = JavassistMetaDataMaker.createClassMetaData(
                                        exceptionClass
                                );


                                // TODO: NO filtering on class and method is done (only exception class), needs to be implemented
                                if (!definition.hasHandlerPointcut(
                                        classMetaData, methodMetaData, exceptionClassMetaData
                                )) {
                                    return;
                                }

                                // call the wrapper method instead of the callee method
                                StringBuffer body = new StringBuffer();
                                body.append(TransformationUtil.JOIN_POINT_MANAGER_FIELD);
                                body.append('.');
                                body.append(TransformationUtil.PROCEED_WITH_HANDLER_JOIN_POINT_METHOD);
                                body.append('(');

                                // TODO: unique hash is needed, based on: executing class, executing method, catch clause (and sequence number?)
                                body.append(TransformationUtil.calculateHash(exceptionClass));
                                body.append(',');
                                body.append(m_joinPointIndex);
                                if (Modifier.isStatic(where.getModifiers())) {
                                    body.append(", $1, (Object)null, \"");
                                }
                                else {
                                    body.append(", $1, this, \"");
                                }
View Full Code Here


            ctClass.instrument(
                    new ExprEditor() {
                        public void edit(MethodCall methodCall) throws CannotCompileException {
                            try {
                                CtBehavior where = null;
                                try {
                                    where = methodCall.where();
                                }
                                catch (RuntimeException e) {
                                    // <clinit> access leads to a bug in Javassist
                                    where = ctClass.getClassInitializer();
                                }

                                // filter caller methods
                                if (methodFilterCaller(where)) {
                                    return;
                                }

                                // get the callee method name, signature and class name
                                CtMethod calleeMethod = methodCall.getMethod();
                                String calleeClassName = methodCall.getClassName();

                                if (!(calleeMethod.getName().equals("proceedWithCallJoinPoint")
                                      && calleeClassName.equals("org.codehaus.aspectwerkz.joinpoint.management.JoinPointManager"))) {
                                    return;
                                }

                                System.out.println("found smtg to REMOVE");
                                System.out.println("calleeMethod = " + calleeMethod.getName());
                                System.out.println("calleeClassName = " + calleeClassName);
                                System.out.println("methodCall = " + methodCall.indexOfBytecode());

                                methodCall.replace("{java.lang.System.out.println($args[0]); $_=null;}");

                                try {
                                CodeIterator it = where.getMethodInfo().getCodeAttribute().iterator();
                                it.move(methodCall.indexOfBytecode()-5);
                                System.out.println("it.get() = " + it.get()); it.next();
                                System.out.println("it.get() = " + it.get()); it.next();
                                System.out.println("it.get() = " + it.get()); it.next();
                                System.out.println("it.get() = " + it.get()); it.next();
View Full Code Here

            ctClass.instrument(
                    new ExprEditor() {
                        public void edit(NewExpr newExpr) throws CannotCompileException {
                            try {
                                CtBehavior where = null;
                                try {
                                    where = newExpr.where();
                                }
                                catch (RuntimeException e) {
                                    // <clinit> access leads to a bug in Javassist
                                    where = ctClass.getClassInitializer();
                                }

                                // filter caller methods
                                if (methodFilterCaller(where)) {
                                    return;
                                }

                                CtConstructor ctConstructor = newExpr.getConstructor();
                                String calleeClassName = newExpr.getClassName();

                                // filter callee classes
                                if (!definition.inIncludePackage(calleeClassName)) {
                                    return;
                                }
                                // filter the constructors
                                if (constructorFilter(ctConstructor)) {
                                    return;
                                }

                                // create the class meta-data
                                ClassMetaData calleeSideClassMetaData;
                                try {
                                    calleeSideClassMetaData =
                                    JavassistMetaDataMaker.createClassMetaData(
                                            context.getClassPool().get(calleeClassName)
                                    );
                                }
                                catch (NotFoundException e) {
                                    throw new WrappedRuntimeException(e);
                                }

                                // create the method meta-data
                                ConstructorMetaData constructorMetaData =
                                        JavassistMetaDataMaker.createConstructorMetaData(newExpr.getConstructor());

                                // is this a caller side method pointcut?
                                if (definition.isPickedOutByCallPointcut(calleeSideClassMetaData, constructorMetaData)) {

                                    // check the callee class is not the same as target class, if that is the case
                                    // then we have have class loaded and set in the ___AW_clazz already
                                    String declaringClassMethodName = TransformationUtil.STATIC_CLASS_FIELD;

                                    CtClass declaringClass = ctConstructor.getDeclaringClass();
                                    if (!declaringClass.getName().replace('/', '.').equals(where.getDeclaringClass().getName().replace('/', '.'))) {
                                        declaringClassMethodName =
                                        addCalleeMethodDeclaringClassField(ctClass, ctConstructor);
                                    }

                                    // call the wrapper method instead of the callee method
                                    StringBuffer body = new StringBuffer();
                                    body.append('{');
                                    if (ctConstructor.getParameterTypes().length > 0) {
                                        body.append("Object[] args = $args; ");
                                    }
                                    else {
                                        body.append("Object[] args = null; ");
                                    }
                                    body.append("Class declaringClassMethodName = ");
                                    body.append(declaringClassMethodName);
                                    body.append("; ");
                                    if (Modifier.isStatic(where.getModifiers())) {
                                        body.append("Object nullObject = null;");
                                    }

                                    body.append("$_ = ($r)");
                                    body.append(TransformationUtil.JOIN_POINT_MANAGER_FIELD);
                                    body.append('.');
                                    body.append(TransformationUtil.PROCEED_WITH_CALL_JOIN_POINT_METHOD);
                                    body.append('(');
                                    body.append(TransformationUtil.calculateHash(ctConstructor));
                                    body.append(',');
                                    body.append(m_joinPointIndex);
                                    body.append(", args, ");
                                    if (Modifier.isStatic(where.getModifiers())) {
                                        body.append("nullObject");
                                    }
                                    else {
                                        body.append("this");
                                    }
View Full Code Here

            ctClass.instrument(
                    new ExprEditor() {
                        public void edit(MethodCall methodCall) throws CannotCompileException {
                            try {
                                CtBehavior where = null;
                                try {
                                    where = methodCall.where();
                                }
                                catch (RuntimeException e) {
                                    // <clinit> access leads to a bug in Javassist
                                    where = ctClass.getClassInitializer();
                                }

                                // filter caller methods
                                if (methodFilterCaller(where)) {
                                    return;
                                }

                                // get the callee method name, signature and class name
                                CtMethod calleeMethod = methodCall.getMethod();
                                String calleeClassName = methodCall.getClassName();

                                // filter callee classes
                                if (!definition.inIncludePackage(calleeClassName)) {
                                    return;
                                }
                                // filter callee methods
                                if (methodFilterCallee(calleeMethod)) {
                                    return;
                                }

                                // create the class meta-data
                                ClassMetaData calleeSideClassMetaData;
                                try {
                                    calleeSideClassMetaData =
                                    JavassistMetaDataMaker.createClassMetaData(
                                            context.getClassPool().get(calleeClassName)
                                    );
                                }
                                catch (NotFoundException e) {
                                    throw new WrappedRuntimeException(e);
                                }

                                // create the method meta-data
                                MethodMetaData calleeSideMethodMetaData = JavassistMetaDataMaker.createMethodMetaData(
                                        methodCall.getMethod()
                                );

                                // is this a caller side method pointcut?
                                if (definition.isPickedOutByCallPointcut(
                                        calleeSideClassMetaData, calleeSideMethodMetaData
                                )) {

//                            // TODO: should this caller data be passed to the join point? It is possible.
//                            String callerMethodName = callerBehaviour.getName();
//                            String callerMethodSignature = callerBehaviour.getSignature();
//                            CtClass[] callerMethodParameterTypes = callerBehaviour.getParameterTypes();
//                            int callerMethodModifiers = callerBehaviour.getModifiers();

                                    // check the callee class is not the same as target class, if that is the case
                                    // then we have have class loaded and set in the ___AW_clazz already
                                    String declaringClassMethodName = TransformationUtil.STATIC_CLASS_FIELD;
                                    CtMethod method = methodCall.getMethod();
                                    CtClass declaringClass = method.getDeclaringClass();
                                    if (!declaringClass.getName().replace('/', '.').equals(where.getDeclaringClass().getName().replace('/', '.'))) {
                                        declaringClassMethodName = addCalleeMethodDeclaringClassField(ctClass, method);
                                    }

                                    // call the wrapper method instead of the callee method
                                    StringBuffer body = new StringBuffer();
View Full Code Here

        ASTList mem = p.parseMember1(stable);
        try {
            if (mem instanceof FieldDecl)
                return compileField((FieldDecl)mem);
            else {
                CtBehavior cb = compileMethod(p, (MethodDecl)mem);
                CtClass decl = cb.getDeclaringClass();
                cb.getMethodInfo2()
                  .rebuildStackMapIf6(decl.getClassPool(),
                                      decl.getClassFile2());
                return cb;
            }
        }
View Full Code Here

         if ((newcall != null && declare.matchesCall(advisor, newcall) || (mcall != null && declare.matchesCall(advisor, mcall))))
         {
            if (mcall != null)
            {
               sb.append("method call:");
               CtBehavior caller = mcall.where();
               if (caller instanceof CtConstructor)
               {
                  CtConstructor con = (CtConstructor)caller;
                  addConstructor(sb, con);
                  sb.append(" calls ");
                  addMethod(sb, mcall.getMethod());
               }
               else if (caller instanceof CtMethod)
               {
                  CtMethod met = (CtMethod)caller;
                  addMethod(sb, met);
                  sb.append(" calls ");
                  addMethod(sb, mcall.getMethod());
               }
            }
            else if (newcall != null)
            {
               sb.append("constructor call: ");
               CtBehavior caller = newcall.where();
               if (caller instanceof CtConstructor)
               {
                  CtConstructor con = (CtConstructor)caller;
                  addConstructor(sb, con);
                  sb.append(" calls ");
View Full Code Here

            )
            {
               return;
            }

            CtBehavior behavior = call.where();

            boolean hasPointcut = false;

            DeclareChecker.checkDeclares(manager, call, advisor);
           
View Full Code Here

                  }
               }
            }
            if (hasPointcut)
            {
               CtBehavior behavior = call.where();
               if (behavior instanceof CtMethod)
                  modifyMethod(call, classname);
               else if (behavior instanceof CtConstructor) modifyConstructor(call, classname);
            }
         }
View Full Code Here

            )
            {
               return;
            }

            CtBehavior behavior = call.where();

            boolean hasPointcut = false;

            DeclareChecker.checkDeclares(manager, call, advisor);
           
View Full Code Here

                  }
               }
            }
            if (hasPointcut)
            {
               CtBehavior behavior = call.where();
               if (behavior instanceof CtMethod)
                  modifyMethod(call, classname);
               else if (behavior instanceof CtConstructor) modifyConstructor(call, classname);
            }
         }
View Full Code Here

TOP

Related Classes of javassist.CtBehavior

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.