Package org.aspectj.weaver.patterns

Examples of org.aspectj.weaver.patterns.TypePattern


    // needs further analysis
    ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(aspectClassName), true);
    // exclude are "AND"ed
    for (Iterator iterator = m_aspectExcludeTypePattern.iterator(); iterator.hasNext();) {
      TypePattern typePattern = (TypePattern) iterator.next();
      if (typePattern.matchesStatically(classInfo)) {
        // exclude match - skip
        return false;
      }
    }
    // include are "OR"ed
    boolean accept = true;// defaults to true if no include
    for (Iterator iterator = m_aspectIncludeTypePattern.iterator(); iterator.hasNext();) {
      TypePattern typePattern = (TypePattern) iterator.next();
      accept = typePattern.matchesStatically(classInfo);
      if (accept) {
        break;
      }
      // goes on if this include did not match ("OR"ed)
    }
View Full Code Here


    // TODO AV - optimize for className.startWith only
    ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(className), true);
    // dump
    for (Iterator iterator = m_dumpTypePattern.iterator(); iterator.hasNext();) {
      TypePattern typePattern = (TypePattern) iterator.next();
      if (typePattern.matchesStatically(classInfo)) {
        // dump match
        return true;
      }
    }
    return false;
View Full Code Here

   * @return a PerClause instance
   */
  private static PerClause parsePerClausePointcut(String perClauseString, AjAttributeStruct struct) {
    final String pointcutString;
    Pointcut pointcut = null;
    TypePattern typePattern = null;
    final PerClause perClause;
    if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERCFLOW.getName())) {
      pointcutString = PerClause.KindAnnotationPrefix.PERCFLOW.extractPointcut(perClauseString);
      pointcut = parsePointcut(pointcutString, struct, false);
      perClause = new PerCflow(pointcut, false);
View Full Code Here

    AnnotationGen decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
    if (decp != null) {
      NameValuePair decpPatternNVP = getAnnotationElement(decp, VALUE);
      String decpPattern = decpPatternNVP.getValue().stringifyValue();
      if (decpPattern != null) {
        TypePattern typePattern = parseTypePattern(decpPattern, struct);
        ResolvedType fieldType = UnresolvedType.forSignature(struct.field.getSignature()).resolve(
            struct.enclosingType.getWorld());
        if (fieldType.isInterface()) {
          TypePattern parent = parseTypePattern(fieldType.getName(), struct);
          FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
          IScope binding = new BindingScope(struct.enclosingType, struct.context, bindings);
          // first add the declare implements like
          List<TypePattern> parents = new ArrayList<TypePattern>(1);
          parents.add(parent);
View Full Code Here

    World world = struct.enclosingType.getWorld();
    NameValuePair declareMixinPatternNameValuePair = getAnnotationElement(declareMixinAnnotation, VALUE);

    // declareMixinPattern could be of the form "Bar*" or "A || B" or "Foo+"
    String declareMixinPattern = declareMixinPatternNameValuePair.getValue().stringifyValue();
    TypePattern targetTypePattern = parseTypePattern(declareMixinPattern, struct);

    // Return value of the annotated method is the interface or class that the mixin delegate should have
    ResolvedType methodReturnType = UnresolvedType.forSignature(annotatedMethod.getReturnType().getSignature()).resolve(world);

    if (methodReturnType.isPrimitiveType()) {
      reportError(getMethodForMessage(struct) + ":  factory methods for a mixin cannot return void or a primitive type",
          struct);
      return false;
    }

    if (annotatedMethod.getArgumentTypes().length > 1) {
      reportError(getMethodForMessage(struct) + ": factory methods for a mixin can take a maximum of one parameter", struct);
      return false;
    }

    // The set of interfaces to be mixed in is either:
    // supplied as a list in the 'Class[] interfaces' value in the annotation value
    // supplied as just the interface return value of the annotated method
    // supplied as just the class return value of the annotated method
    NameValuePair interfaceListSpecified = getAnnotationElement(declareMixinAnnotation, "interfaces");

    List<TypePattern> newParents = new ArrayList<TypePattern>(1);
    List<ResolvedType> newInterfaceTypes = new ArrayList<ResolvedType>(1);
    if (interfaceListSpecified != null) {
      ArrayElementValue arrayOfInterfaceTypes = (ArrayElementValue) interfaceListSpecified.getValue();
      int numberOfTypes = arrayOfInterfaceTypes.getElementValuesArraySize();
      ElementValue[] theTypes = arrayOfInterfaceTypes.getElementValuesArray();
      for (int i = 0; i < numberOfTypes; i++) {
        ClassElementValue interfaceType = (ClassElementValue) theTypes[i];
        // Check: needs to be resolvable
        // TODO crappy replace required
        ResolvedType ajInterfaceType = UnresolvedType.forSignature(interfaceType.getClassString().replace("/", "."))
            .resolve(world);
        if (ajInterfaceType.isMissing() || !ajInterfaceType.isInterface()) {
          reportError(
              "Types listed in the 'interfaces' DeclareMixin annotation value must be valid interfaces. This is invalid: "
                  + ajInterfaceType.getName(), struct); // TODO better error location, use the method position
          return false;
        }
        if (!ajInterfaceType.isAssignableFrom(methodReturnType)) {
          reportError(getMethodForMessage(struct) + ": factory method does not return something that implements '"
              + ajInterfaceType.getName() + "'", struct);
          return false;
        }
        newInterfaceTypes.add(ajInterfaceType);
        // Checking that it is a superinterface of the methods return value is done at weave time
        TypePattern newParent = parseTypePattern(ajInterfaceType.getName(), struct);
        newParents.add(newParent);
      }
    } else {
      if (methodReturnType.isClass()) {
        reportError(
            getMethodForMessage(struct)
                + ": factory methods for a mixin must either return an interface type or specify interfaces in the annotation and return a class",
            struct);
        return false;
      }
      // Use the method return type: this might be a class or an interface
      TypePattern newParent = parseTypePattern(methodReturnType.getName(), struct);
      newInterfaceTypes.add(methodReturnType);
      newParents.add(newParent);
    }
    if (newParents.size() == 0) {
      // Warning: did they foolishly put @DeclareMixin(value="Bar+",interfaces={})
View Full Code Here

   * @param location
   * @return type pattern
   */
  private static TypePattern parseTypePattern(String patternString, AjAttributeStruct location) {
    try {
      TypePattern typePattern = new PatternParser(patternString).parseTypePattern();
      typePattern.setLocation(location.context, -1, -1);// FIXME -1,-1 is
      // not good
      // enough
      return typePattern;
    } catch (ParserException e) {
      reportError("Invalid type pattern'" + patternString + "' : " + e.getLocation(), location);
View Full Code Here

    public void addScopedAspect(String aspectName, String scope) {
      ensureInitialized();
      resolvedIncludedAspects.add(aspectName);
      try {
        TypePattern scopePattern = new PatternParser(scope).parseTypePattern();
        scopePattern.resolve(world);
        scopes.put(aspectName, scopePattern);
        if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
          world.getMessageHandler().handleMessage(
              MessageUtil.info("Aspect '" + aspectName + "' is scoped to apply against types matching pattern '"
                  + scopePattern.toString() + "'"));
        }
      } catch (Exception e) {
        world.getMessageHandler().handleMessage(
            MessageUtil.error("Unable to parse scope as type pattern.  Scope was '" + scope + "': " + e.getMessage()));
      }
View Full Code Here

              // }
              String scope = definition.getScopeForAspect(name);
              if (scope != null) {
                // Resolve the type pattern
                try {
                  TypePattern scopePattern = new PatternParser(scope).parseTypePattern();
                  scopePattern.resolve(world);
                  scopes.put(name, scopePattern);
                  if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
                    world.getMessageHandler().handleMessage(
                        MessageUtil.info("Aspect '" + name
                            + "' is scoped to apply against types matching pattern '"
                            + scopePattern.toString() + "'"));
                  }
                } catch (Exception e) {
                  // TODO definitions should remember which file they came from, for inclusion in this message
                  world.getMessageHandler().handleMessage(
                      MessageUtil.error("Unable to parse scope as type pattern.  Scope was '" + scope + "': "
                          + e.getMessage()));
                }
              }
            }
            try {
              List<String> includePatterns = definition.getIncludePatterns();
              if (includePatterns.size() > 0) {
                includedPatterns = new ArrayList<TypePattern>();
                includedFastMatchPatterns = new ArrayList<String>();
              }
              for (String includePattern : includePatterns) {
                if (includePattern.endsWith("..*")) {
                  // from 'blah.blah.blah..*' leave the 'blah.blah.blah.'
                  includedFastMatchPatterns.add(includePattern.substring(0, includePattern.length() - 2));
                } else {
                  TypePattern includedPattern = new PatternParser(includePattern).parseTypePattern();
                  includedPatterns.add(includedPattern);
                }
              }
              List<String> excludePatterns = definition.getExcludePatterns();
              if (excludePatterns.size() > 0) {
                excludedPatterns = new ArrayList<TypePattern>();
                excludedFastMatchPatterns = new ArrayList<String>();
              }
              for (String excludePattern : excludePatterns) {
                if (excludePattern.endsWith("..*")) {
                  // from 'blah.blah.blah..*' leave the 'blah.blah.blah.'
                  excludedFastMatchPatterns.add(excludePattern.substring(0, excludePattern.length() - 2));
                } else {
                  TypePattern excludedPattern = new PatternParser(excludePattern).parseTypePattern();
                  excludedPatterns.add(excludedPattern);
                }
              }
            } catch (ParserException pe) {
              // TODO definitions should remember which file they came from, for inclusion in this message
View Full Code Here

     * be successfully parsed.
     */
    public TypePatternMatcher parseTypePattern(String typePattern)
    throws IllegalArgumentException {
        try {
          TypePattern tp = new PatternParser(typePattern).parseTypePattern();
          tp.resolve(world);
          return new TypePatternMatcherImpl(tp,world);
        } catch (ParserException pEx) {
            throw new IllegalArgumentException(buildUserMessageFromParserException(typePattern,pEx));
        } catch (ReflectionWorld.ReflectionWorldException rwEx) {
            throw new IllegalArgumentException(rwEx.getMessage());
View Full Code Here

       
        String kindOfDP = null;
        StringBuffer details = new StringBuffer("");
        TypePattern[] newParents = dp.getParents().getTypePatterns();
        for (int i = 0; i < newParents.length; i++) {
          TypePattern tp = newParents[i];
          UnresolvedType tx = tp.getExactType();
          if (kindOfDP == null) {
            kindOfDP = "implements ";
            try {
              ResolvedType rtx = tx.resolve(((AjLookupEnvironment)declare.scope.environment()).factory.getWorld());
            if (!rtx.isInterface()) kindOfDP = "extends ";
            } catch (Throwable t) {
              // What can go wrong???? who knows!
            }
           
          }
          String typename= tp.toString();
          if (typename.lastIndexOf(".")!=-1) {
            typename=typename.substring(typename.lastIndexOf(".")+1);
          }
          details.append(typename);
          if ((i+1)<newParents.length) details.append(",");
View Full Code Here

TOP

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

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.