Package javassist

Examples of javassist.CtBehavior


            )
            {
               return;
            }

            CtBehavior behavior = call.where();

            boolean hasPointcut = false;

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


                  break;
               }
            }
            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

        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

            )
            {
               return;
            }

            CtBehavior behavior = call.where();

            boolean hasPointcut = false;

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

                  break;
               }
            }
            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

         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

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

                                // filter caller context
                                if (methodFilter(where)) {
                                    return;
                                }

                                // get field accessed information
                                final String fieldName = fieldAccess.getFieldName();
                                final String fieldSignature = fieldAccess.getField().getType().getName() + ' ' +
                                                              fieldName;
                                FieldMetaData fieldMetaData = JavassistMetaDataMaker.createFieldMetaData(
                                        fieldAccess.getField()
                                );

                                // handle GET
                                if (fieldAccess.isReader() &&
                                    !getFieldFilter(definition, classMetaData, fieldMetaData)) {
                                    // check the declaring class for the field 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 declaringClassFieldName = TransformationUtil.STATIC_CLASS_FIELD;
                                    CtClass declaringClass = fieldAccess.getField().getDeclaringClass();
                                    if (!declaringClass.getName().equals(where.getDeclaringClass().getName())) {
                                        declaringClassFieldName =
                                        addFieldAccessDeclaringClassField(declaringClass, fieldAccess.getField());
                                    }

                                    //TODO ALEX might need to review since SET is not handled gracefully that way
                                    StringBuffer body = new StringBuffer();
                                    StringBuffer callBody = new StringBuffer();
                                    callBody.append(TransformationUtil.JOIN_POINT_MANAGER_FIELD);
                                    callBody.append('.');
                                    callBody.append(TransformationUtil.PROCEED_WITH_GET_JOIN_POINT_METHOD);
                                    callBody.append('(');
                                    callBody.append(TransformationUtil.calculateHash(fieldAccess.getField()));
                                    callBody.append(',');
                                    callBody.append(m_joinPointIndex);
                                    if (Modifier.isStatic(fieldAccess.getField().getModifiers())) {
                                        callBody.append(", (Object)null, ");
                                    }
                                    else {
                                        callBody.append(", $0, ");
                                    }
                                    callBody.append(declaringClassFieldName);
                                    callBody.append(",\"");
                                    callBody.append(fieldSignature);
                                    callBody.append("\");");

                                    // handles advice returns null and fiel is primitive type
                                    if (!fieldAccess.getField().getType().isPrimitive()) {
                                        body.append("$_ = ($r)");
                                        body.append(callBody.toString());
                                    }
                                    else {
                                        String localResult = TransformationUtil.ASPECTWERKZ_PREFIX + "res";
                                        body.append("{ Object ").append(localResult).append(" = ");
                                        body.append(callBody.toString());
                                        body.append("if (").append(localResult).append(" != null)");
                                        body.append("$_ = ($r) ").append(localResult).append("; else ");
                                        body.append("$_ = ");
                                        body.append(
                                                JavassistHelper.getDefaultPrimitiveValue(
                                                        fieldAccess.getField().getType()
                                                )
                                        );
                                        body.append("; }");
                                    }

                                    fieldAccess.replace(body.toString());
                                    context.markAsAdvised();

                                    m_joinPointIndex++;
                                }

                                // handle SET
                                if (fieldAccess.isWriter() &&
                                    !setFieldFilter(definition, classMetaData, fieldMetaData)) {
                                    // check the declaring class for the field 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 declaringClassFieldName = TransformationUtil.STATIC_CLASS_FIELD;
                                    CtClass declaringClass = fieldAccess.getField().getDeclaringClass();
                                    if (!declaringClass.getName().equals(where.getDeclaringClass().getName())) {
                                        declaringClassFieldName =
                                        addFieldAccessDeclaringClassField(declaringClass, fieldAccess.getField());
                                    }

                                    //TODO ALEX think about null advice
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().equals(where.getDeclaringClass().getName())) {
                                        declaringClassMethodName = addCalleeMethodDeclaringClassField(ctClass, method);
                                    }

                                    // call the wrapper method instead of the callee method
                                    StringBuffer body = new StringBuffer();
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.