Package org.aspectj.weaver.patterns

Examples of org.aspectj.weaver.patterns.Pointcut


    UnresolvedType[] argumentTypes = new UnresolvedType[struct.method.getArgumentTypes().length];
    for (int i = 0; i < argumentTypes.length; i++) {
      argumentTypes[i] = UnresolvedType.forSignature(struct.method.getArgumentTypes()[i].getSignature());
    }

    Pointcut pc = null;
    if (struct.method.isAbstract()) {
      if ((pointcutExpr != null && isNullOrEmpty(pointcutExpr.getValue().stringifyValue())) || pointcutExpr == null) {
        // abstract pointcut
        // leave pc = null
      } else {
        reportError("Found defined @Pointcut on an abstract method", struct);
        return false;// stop
      }
    } else {
      if (pointcutExpr == null || isNullOrEmpty(pointcutExpr.getValue().stringifyValue())) {
        // the matches nothing pointcut (125475/125480) - perhaps not as
        // cleanly supported as it could be.
      } else {
        // if (pointcutExpr != null) {
        // use a LazyResolvedPointcutDefinition so that the pointcut is
        // resolved lazily
        // since for it to be resolved, we will need other pointcuts to
        // be registered as well
        pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct, true);
        if (pc == null) {
          return false;// parse error
        }
        pc.setLocation(struct.context, -1, -1);// FIXME AVASM !! bMethod
        // is null here..
        // } else {
        // reportError("Found undefined @Pointcut on a non-abstract method",
        // struct);
        // return false;
View Full Code Here


      if (declareError != null) {
        if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
          reportError("@DeclareError used on a non String constant field", struct);
          return false;
        }
        Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct, false);
        if (pc == null) {
          hasError = false;// cannot parse pointcut
        } else {
          DeclareErrorOrWarning deow = new DeclareErrorOrWarning(true, pc, struct.field.getConstantValue().toString());
          setDeclareErrorOrWarningLocation(model, deow, struct);
          struct.ajAttributes.add(new AjAttribute.DeclareAttribute(deow));
          hasError = true;
        }
      }
    }
    AnnotationGen warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
    boolean hasWarning = false;
    if (warning != null) {
      NameValuePair declareWarning = getAnnotationElement(warning, VALUE);
      if (declareWarning != null) {
        if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
          reportError("@DeclareWarning used on a non String constant field", struct);
          return false;
        }
        Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct, false);
        if (pc == null) {
          hasWarning = false;// cannot parse pointcut
        } else {
          DeclareErrorOrWarning deow = new DeclareErrorOrWarning(false, pc, struct.field.getConstantValue().toString());
          setDeclareErrorOrWarningLocation(model, deow, struct);
View Full Code Here

   * @return pointcut, unresolved
   */
  private static Pointcut parsePointcut(String pointcutString, AjAttributeStruct struct, boolean allowIf) {
    try {
      PatternParser parser = new PatternParser(pointcutString, struct.context);
      Pointcut pointcut = parser.parsePointcut();
      parser.checkEof();
      pointcut.check(null, struct.enclosingType.getWorld());
      if (!allowIf && pointcutString.indexOf("if()") >= 0 && hasIf(pointcut)) {
        reportError("if() pointcut is not allowed at this pointcut location '" + pointcutString + "'", struct);
        return null;
      }
      pointcut.setLocation(struct.context, -1, -1);// FIXME -1,-1 is not
      // good enough
      return pointcut;
    } catch (ParserException e) {
      reportError("Invalid pointcut '" + pointcutString + "': " + e.toString()
          + (e.getLocation() == null ? "" : " at position " + e.getLocation().getStart()), struct);
View Full Code Here

   * even when one single pointcut has one common element (which can be a side-effect of DNF rewriting).
   */
  private void rewritePointcuts(List<ShadowMunger> shadowMungers) {
    PointcutRewriter rewriter = new PointcutRewriter();
    for (ShadowMunger munger : shadowMungers) {
      Pointcut p = munger.getPointcut();
      Pointcut newP = rewriter.rewrite(p);
      // validateBindings now whilst we still have around the pointcut
      // that resembles what the user actually wrote in their program
      // text.
      if (munger instanceof Advice) {
        Advice advice = (Advice) munger;
        if (advice.getSignature() != null) {
          final int numFormals;
          final String names[];
          // If the advice is being concretized in a @AJ aspect *and*
          // the advice was declared in
          // an @AJ aspect (it could have been inherited from a code
          // style aspect) then
          // evaluate the alternative set of formals. pr125699
          if ((advice.getConcreteAspect().isAnnotationStyleAspect() && advice.getDeclaringAspect() != null && advice
              .getDeclaringAspect().resolve(world).isAnnotationStyleAspect())
              || advice.isAnnotationStyle()) {
            numFormals = advice.getBaseParameterCount();
            int numArgs = advice.getSignature().getParameterTypes().length;
            if (numFormals > 0) {
              names = advice.getSignature().getParameterNames(world);
              validateBindings(newP, p, numArgs, names);
            }
          } else {
            numFormals = advice.getBaseParameterCount();
            if (numFormals > 0) {
              names = advice.getBaseParameterNames(world);
              validateBindings(newP, p, numFormals, names);
            }
          }
        }
      }
      newP.m_ignoreUnboundBindingForNames = p.m_ignoreUnboundBindingForNames;
      munger.setPointcut(newP);
    }
    // now that we have optimized individual pointcuts, optimize
    // across the set of pointcuts....
    // Use a map from key based on pc equality, to value based on
    // pc identity.
    Map/* <Pointcut,Pointcut> */<Pointcut, Pointcut> pcMap = new HashMap<Pointcut, Pointcut>();
    for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
      ShadowMunger munger = (ShadowMunger) iter.next();
      Pointcut p = munger.getPointcut();
      Pointcut newP = shareEntriesFromMap(p, pcMap);
      newP.m_ignoreUnboundBindingForNames = p.m_ignoreUnboundBindingForNames;
      munger.setPointcut(newP);
    }
  }
View Full Code Here

    if (p instanceof ConcreteCflowPointcut) {
      return p;
    }
    if (p instanceof AndPointcut) {
      AndPointcut apc = (AndPointcut) p;
      Pointcut left = shareEntriesFromMap(apc.getLeft(), pcMap);
      Pointcut right = shareEntriesFromMap(apc.getRight(), pcMap);
      return new AndPointcut(left, right);
    } else if (p instanceof OrPointcut) {
      OrPointcut opc = (OrPointcut) p;
      Pointcut left = shareEntriesFromMap(opc.getLeft(), pcMap);
      Pointcut right = shareEntriesFromMap(opc.getRight(), pcMap);
      return new OrPointcut(left, right);
    } else if (p instanceof NotPointcut) {
      NotPointcut npc = (NotPointcut) p;
      Pointcut not = shareEntriesFromMap(npc.getNegatedPointcut(), pcMap);
      return new NotPointcut(not);
    } else {
      // primitive pcd
      if (pcMap.containsKey(p)) { // based on equality
        return pcMap.get(p); // same instance (identity)
View Full Code Here

    }
  }

  private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] leftBindings,
      Pointcut[] rightBindings) {
    Pointcut left = pc.getLeft();
    Pointcut right = pc.getRight();
    if (left instanceof OrPointcut) {
      Pointcut[] newRightBindings = new Pointcut[numFormals];
      validateOrBranch((OrPointcut) left, userPointcut, numFormals, names, leftBindings, newRightBindings);
    } else {
      if (left.couldMatchKinds() != Shadow.NO_SHADOW_KINDS_BITS) {
        validateSingleBranch(left, userPointcut, numFormals, names, leftBindings);
      }
    }
    if (right instanceof OrPointcut) {
      Pointcut[] newLeftBindings = new Pointcut[numFormals];
      validateOrBranch((OrPointcut) right, userPointcut, numFormals, names, newLeftBindings, rightBindings);
    } else {
      if (right.couldMatchKinds() != Shadow.NO_SHADOW_KINDS_BITS) {
        validateSingleBranch(right, userPointcut, numFormals, names, rightBindings);
      }
    }
    int kindsInCommon = left.couldMatchKinds() & right.couldMatchKinds();
    if (kindsInCommon != Shadow.NO_SHADOW_KINDS_BITS && couldEverMatchSameJoinPoints(left, right)) {
      // we know that every branch binds every formal, so there is no
      // ambiguity
      // if each branch binds it in exactly the same way...
      List<String> ambiguousNames = new ArrayList<String>();
View Full Code Here

    if (toLookFor.isInstance(toSearch)) {
      return toSearch;
    }
    if (toSearch instanceof AndPointcut) {
      AndPointcut apc = (AndPointcut) toSearch;
      Pointcut left = findFirstPointcutIn(apc.getLeft(), toLookFor);
      if (left != null) {
        return left;
      }
      return findFirstPointcutIn(apc.getRight(), toLookFor);
    }
View Full Code Here

          ResolvedType declaringAspect = munger.getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        long starttime = System.nanoTime();
        FuzzyBoolean fb = pointcut.fastMatch(info);
        long endtime = System.nanoTime();
        world.recordFastMatch(pointcut, endtime - starttime);
        if (fb.maybeTrue()) {
          result.add(munger);
        }
      }
    } else {
      for (ShadowMunger munger : list) {
        if (typeWeaverState != null) { // will only be null if overweaving is ON and there is weaverstate
          ResolvedType declaringAspect = munger.getConcreteAspect();// getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        FuzzyBoolean fb = pointcut.fastMatch(info);
        if (fb.maybeTrue()) {
          result.add(munger);
        }
      }
    }
View Full Code Here

      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,
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

TOP

Related Classes of org.aspectj.weaver.patterns.Pointcut

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.