Package org.aspectj.weaver

Examples of org.aspectj.weaver.ResolvedPointcutDefinition


  private static void addPointcuts(AsmManager model, String sourcefilename, ResolvedType aspect,
      IProgramElement containingAspect, ResolvedMember[] pointcuts) {
    for (int i = 0; i < pointcuts.length; i++) {
      ResolvedMember pointcut = pointcuts[i];
      if (pointcut instanceof ResolvedPointcutDefinition) {
        ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition) pointcut;
        Pointcut p = rpcd.getPointcut();
        ISourceLocation sLoc = (p == null ? null : p.getSourceLocation());
        if (sLoc == null) {
          sLoc = rpcd.getSourceLocation();
        }
        ISourceLocation pointcutLocation = (sLoc == null ? null : createSourceLocation(sourcefilename, aspect, sLoc));
        ProgramElement pointcutElement = new ProgramElement(model, pointcut.getName(), IProgramElement.Kind.POINTCUT,
            pointcutLocation, pointcut.getModifiers(), NO_COMMENT, Collections.EMPTY_LIST);
        containingAspect.addChild(pointcutElement);
View Full Code Here


  private static void addChildNodes(AsmManager asm, ResolvedType aspect, IProgramElement parent, ResolvedMember[] children) {
    for (int i = 0; i < children.length; i++) {
      ResolvedMember pcd = children[i];
      if (pcd instanceof ResolvedPointcutDefinition) {
        ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition) pcd;
        Pointcut p = rpcd.getPointcut();
        ISourceLocation sLoc = (p == null ? null : p.getSourceLocation());
        if (sLoc == null) {
          sLoc = rpcd.getSourceLocation();
        }
        parent.addChild(new ProgramElement(asm, pcd.getName(), IProgramElement.Kind.POINTCUT, getBinarySourceLocation(
            aspect, sLoc), pcd.getModifiers(), null, Collections.EMPTY_LIST));
      }
    }
View Full Code Here

        org.aspectj.weaver.patterns.Pointcut pc = pEx.getUnderlyingPointcut();
        UnresolvedType[] weaverPTypes = new UnresolvedType[ptypes.length];
        for (int j = 0; j < weaverPTypes.length; j++) {
          weaverPTypes[j] = UnresolvedType.forName(ptypes[j].getName());
        }
        pointcuts[i] = new ResolvedPointcutDefinition(getResolvedTypeX(),pcs[i].getModifiers(),pcs[i].getName(),weaverPTypes,pc);
      }
    }
    return pointcuts;
  }
View Full Code Here

        //  before(String s):  somePointcut(*,s)
        // where the first argument in somePointcut is of type Number
        // for free variable 0 we want to ask the pointcut for the type of its first argument, if we only
        // ask the advice for the type of its first argument then we'll get the wrong type (pr86903)
       
        ResolvedPointcutDefinition enclosingDef = bindings.peekEnclosingDefinition();
        ResolvedType formalType = null;
       
        // Is there a useful enclosing pointcut?
        if (enclosingDef!=null && enclosingDef.getParameterTypes().length>0) {
          formalType = enclosingDef.getParameterTypes()[freeVar].resolve(world);
        } else {
          formalType = bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world);
        }
       
        ConcreteCflowPointcut.Slot slot =
View Full Code Here

    public Object visit(ReferencePointcut node, Object data) {
        // && pc_ref()
        // we know there is no support for binding in perClause: perthis(pc_ref(java.lang.String))
        // TODO AV - may need some work for generics..

        ResolvedPointcutDefinition pointcutDec;
        ResolvedType searchStart = m_fromAspectType;
        if (node.onType != null) {
            searchStart = node.onType.resolve(m_fromAspectType.getWorld());
            if (searchStart.isMissing()) {
                return MAYBE;// this should not happen since concretize will fails but just in case..
            }
        }
        pointcutDec = searchStart.findPointcut(node.name);

        return getPerTypePointcut(pointcutDec.getPointcut());
    }
View Full Code Here

 

  public ResolvedPointcutDefinition makeResolvedPointcutDefinition(EclipseFactory inWorld) {
        if (resolvedPointcutDeclaration != null) return resolvedPointcutDeclaration;
    //System.out.println("pc: " + getPointcut() + ", " + getPointcut().state);
    resolvedPointcutDeclaration = new ResolvedPointcutDefinition(
            inWorld.fromBinding(this.binding.declaringClass),
            declaredModifiers,
            declaredName,
      inWorld.fromBindings(this.binding.parameters),
      getPointcut()); //??? might want to use null
View Full Code Here

      pc.resolve(new EclipseScope(bindings,methodDeclaration.scope));
      EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(methodDeclaration.scope);
      // now create a ResolvedPointcutDefinition,make an attribute out of it, and add it to the method
      UnresolvedType[] paramTypes = new UnresolvedType[bindings.length];
      for (int i = 0; i < paramTypes.length; i++) paramTypes[i] = bindings[i].getType();
      ResolvedPointcutDefinition resPcutDef =
        new ResolvedPointcutDefinition(
            factory.fromBinding(((TypeDeclaration)typeStack.peek()).binding),
            methodDeclaration.modifiers,
            "anonymous",
            paramTypes,
            pc
View Full Code Here

    arguments.resolveBindings(scope, bindings, true, true);
    //XXX ensure that arguments has no ..'s in it
   
    // check that I refer to a real pointcut declaration and that I match
   
    ResolvedPointcutDefinition pointcutDef = searchType.findPointcut(name);
    // if we're not a static reference, then do a lookup of outers
    if (pointcutDef == null && onType == null) {
      while (true) {
        UnresolvedType declaringType = searchType.getDeclaringType();
        if (declaringType == null) break;
        searchType = declaringType.resolve(scope.getWorld());
        pointcutDef = searchType.findPointcut(name);
        if (pointcutDef != null) {
          // make this a static reference
          onType = searchType;
          break;
        }
      }
    }
   
    if (pointcutDef == null) {
      scope.message(IMessage.ERROR, this, "can't find referenced pointcut " + name);
      return;
    }
   
    // check visibility
    if (!pointcutDef.isVisible(scope.getEnclosingType())) {
      scope.message(IMessage.ERROR, this, "pointcut declaration " + pointcutDef + " is not accessible");
      return;
    }
   
    if (Modifier.isAbstract(pointcutDef.getModifiers())) {
      if (onType != null) {
        scope.message(IMessage.ERROR, this,
                "can't make static reference to abstract pointcut");
        return;
      } else if (!searchType.isAbstract()) {
        scope.message(IMessage.ERROR, this,
                "can't use abstract pointcut in concrete context");
        return;
      }
    }
   
   
    ResolvedType[] parameterTypes =
      scope.getWorld().resolve(pointcutDef.getParameterTypes());
   
    if (parameterTypes.length != arguments.size()) {
      scope.message(IMessage.ERROR, this, "incompatible number of arguments to pointcut, expected " +
            parameterTypes.length + " found " + arguments.size());
      return;
View Full Code Here

    }
   
    try {
      concretizing = true;
   
      ResolvedPointcutDefinition pointcutDec;
      if (onType != null) {
        searchStart = onType.resolve(searchStart.getWorld());
        if (searchStart.isMissing()) {
          return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
        }
      }
     
      if (declaringType == null) declaringType = searchStart;
      pointcutDec = declaringType.findPointcut(name);
      boolean foundMatchingPointcut = (pointcutDec != null && pointcutDec.isPrivate());
      if (!foundMatchingPointcut) {       
        pointcutDec = searchStart.findPointcut(name);
        if (pointcutDec == null) {
          searchStart.getWorld().getMessageHandler().handleMessage(
            MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_FIND_POINTCUT,name,searchStart.getName()),
                    getSourceLocation())
          );
          return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
        }
      }
     
      if (pointcutDec.isAbstract()) {
        //Thread.currentThread().dumpStack();
        ShadowMunger enclosingAdvice = bindings.getEnclosingAdvice();
        searchStart.getWorld().showMessage(IMessage.ERROR,
            WeaverMessages.format(WeaverMessages.ABSTRACT_POINTCUT,pointcutDec),
            getSourceLocation(),
            (null == enclosingAdvice) ? null : enclosingAdvice.getSourceLocation());
        return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
      }
         
      //System.err.println("start: " + searchStart);
      ResolvedType[] parameterTypes = searchStart.getWorld().resolve(pointcutDec.getParameterTypes());
     
      TypePatternList arguments = this.arguments.resolveReferences(bindings);
     
      IntMap newBindings = new IntMap();
      for (int i=0,len=arguments.size(); i < len; i++) {
        TypePattern p = arguments.get(i);
        if (p == TypePattern.NO) continue;
        // we are allowed to bind to pointcuts which use subtypes as this is type safe
        // this will be checked in ReferencePointcut.resolveBindings().  Can't check it here
        // as we don't know about any new parents added via decp.
          if (p instanceof BindingTypePattern) {
            newBindings.put(i, ((BindingTypePattern)p).getFormalIndex());
          }
      }

      if (searchStart.isParameterizedType()) {
        // build a type map mapping type variable names in the generic type to
        // the type parameters presented
        typeVariableMap = new HashMap();
        ResolvedType underlyingGenericType = searchStart.getGenericType();
        TypeVariable[] tVars = underlyingGenericType.getTypeVariables();
        ResolvedType[] typeParams = searchStart.getResolvedTypeParameters();
        for (int i = 0; i < tVars.length; i++) {
          typeVariableMap.put(tVars[i].getName(),typeParams[i]);
        }
      }
     
      newBindings.copyContext(bindings);
      newBindings.pushEnclosingDefinition(pointcutDec);
      try {
        Pointcut ret = pointcutDec.getPointcut();
        if (typeVariableMap != null && !hasBeenParameterized) {         
          ret = ret.parameterizeWith(typeVariableMap);
          ret.hasBeenParameterized=true;
        }
        return ret.concretize(searchStart, declaringType, newBindings);
View Full Code Here

    }

        final IfPointcut ret;
        if (extraParameterFlags < 0 && testMethod == null) {
            // @AJ style, we need to find the testMethod in the aspect defining the "if()" enclosing pointcut
            ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition();
            if (def != null) {
                ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType());
                for (Iterator memberIter = aspect.getMethods(); memberIter.hasNext();) {
                    ResolvedMember method = (ResolvedMember) memberIter.next();
                    if (def.getName().equals(method.getName())
                        && def.getParameterTypes().length == method.getParameterTypes().length) {
                        boolean sameSig = true;
                        for (int j = 0; j < method.getParameterTypes().length; j++) {
                            UnresolvedType argJ = method.getParameterTypes()[j];
                            if (!argJ.equals(def.getParameterTypes()[j])) {
                                sameSig = false;
                                break;
                            }
                        }
                        if (sameSig) {
                            testMethod = method;
                            break;
                        }
                    }
                }
                if (testMethod == null) {
                    inAspect.getWorld().showMessage(
                            IMessage.ERROR,
                            "Cannot find if() body from '" + def.toString() + "' for '" + enclosingPointcutHint + "'",
                            this.getSourceLocation(),
                            null
                    );
                    return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
                }
            } else {
                testMethod = inAspect.getWorld().resolve(bindings.getAdviceSignature());
            }
            ret = new IfPointcut(enclosingPointcutHint);
            ret.testMethod = testMethod;
        } else {
            ret = new IfPointcut(testMethod, extraParameterFlags);
        }
        ret.copyLocationFrom(this);
        partiallyConcretized = ret;

    // It is possible to directly code your pointcut expression in a per clause
    // rather than defining a pointcut declaration and referencing it in your
    // per clause.  If you do this, we have problems (bug #62458).  For now,
    // let's police that you are trying to code a pointcut in a per clause and
    // put out a compiler error.
    if (bindings.directlyInAdvice() && bindings.getEnclosingAdvice()==null) {
      // Assumption: if() is in a per clause if we say we are directly in advice
      // but we have no enclosing advice.
      inAspect.getWorld().showMessage(IMessage.ERROR,
          WeaverMessages.format(WeaverMessages.IF_IN_PERCLAUSE),
          this.getSourceLocation(),null);
      return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
    }
   
    if (bindings.directlyInAdvice()) {
      ShadowMunger advice = bindings.getEnclosingAdvice();
      if (advice instanceof Advice) {
        ret.baseArgsCount = ((Advice)advice).getBaseParameterCount();
      } else {
        ret.baseArgsCount = 0;
      }
      ret.residueSource = advice.getPointcut().concretize(inAspect, inAspect, ret.baseArgsCount, advice);
    } else {
      ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition();
      if (def == CflowPointcut.CFLOW_MARKER) {
        inAspect.getWorld().showMessage(IMessage.ERROR,
            WeaverMessages.format(WeaverMessages.IF_LEXICALLY_IN_CFLOW),
            getSourceLocation(), null);
        return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
      }
      ret.baseArgsCount = def.getParameterTypes().length;

            // for @style, we have implicit binding for JoinPoint.* things
            //FIXME AV - will lead to failure for "args(jp)" test(jp, thejp) / see args() implementation
            if (ret.extraParameterFlags < 0) {
                ret.baseArgsCount = 0;
                for (int i = 0; i < testMethod.getParameterTypes().length; i++) {
                    String argSignature = testMethod.getParameterTypes()[i].getSignature();
                    if (AjcMemberMaker.TYPEX_JOINPOINT.getSignature().equals(argSignature)
                        || AjcMemberMaker.TYPEX_PROCEEDINGJOINPOINT.getSignature().equals(argSignature)
                        || AjcMemberMaker.TYPEX_STATICJOINPOINT.getSignature().equals(argSignature)
                        || AjcMemberMaker.TYPEX_ENCLOSINGSTATICJOINPOINT.getSignature().equals(argSignature)) {
                        ;
                    } else {
                        ret.baseArgsCount++;
                    }
                }
            }

      IntMap newBindings = IntMap.idMap(ret.baseArgsCount);
      newBindings.copyContext(bindings);
      ret.residueSource = def.getPointcut().concretize(inAspect, declaringType, newBindings);
    }
   
    return ret;
  }
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.ResolvedPointcutDefinition

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.