Examples of TypePattern


Examples of org.aspectj.weaver.patterns.TypePattern

    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

Examples of org.aspectj.weaver.patterns.TypePattern

   * @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

Examples of org.aspectj.weaver.patterns.TypePattern

    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

Examples of org.aspectj.weaver.patterns.TypePattern

              // }
              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

Examples of org.aspectj.weaver.patterns.TypePattern

  /**
   * All overriding methods should call super
   */
  public boolean match(Shadow shadow, World world) {
    if (world.isXmlConfigured() && world.isAspectIncluded(declaringType)) {
      TypePattern scoped = world.getAspectScope(declaringType);
      if (scoped != null) {
        // Check the 'cached' exclusion map
        Set<ResolvedType> excludedTypes = world.getExclusionMap().get(declaringType);
        ResolvedType type = shadow.getEnclosingType().resolve(world);
        if (excludedTypes != null && excludedTypes.contains(type)) {
          return false;
        }
        boolean b = scoped.matches(type, TypePattern.STATIC).alwaysTrue();
        if (!b) {
          if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
            world.getMessageHandler().handleMessage(
                MessageUtil.info("Type '" + type.getName() + "' not woven by aspect '" + declaringType.getName()
                    + "' due to scope exclusion in XML definition"));
View Full Code Here

Examples of org.aspectj.weaver.patterns.TypePattern

   * @return a type pattern matcher that matches using the given pattern
   * @throws IllegalArgumentException if the type pattern cannot 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

Examples of org.aspectj.weaver.patterns.TypePattern

   * @return a type pattern matcher that matches using the given pattern
   * @throws IllegalArgumentException if the type pattern cannot 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

Examples of org.aspectj.weaver.patterns.TypePattern

  public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context, boolean isEnhanced)
      throws IOException {
    ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context);
    UnresolvedType aspect = UnresolvedType.read(s);
    String implClassName = s.readUTF();
    TypePattern tp = TypePattern.read(s, context);
    MethodDelegateTypeMunger typeMunger = new MethodDelegateTypeMunger(signature, aspect, implClassName, tp);
    UnresolvedType fieldType = null;
    if (isEnhanced) {
      fieldType = UnresolvedType.read(s);
    } else {
View Full Code Here

Examples of org.aspectj.weaver.patterns.TypePattern

    }

    public static ResolvedTypeMunger readFieldHost(VersionedDataInputStream s, ISourceContext context) throws IOException {
      ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context);
      UnresolvedType aspect = UnresolvedType.read(s);
      TypePattern tp = TypePattern.read(s, context);
      return new FieldHostTypeMunger(signature, aspect, tp);
    }
View Full Code Here

Examples of org.aspectj.weaver.patterns.TypePattern

  private void registerAspectExclude(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
    String fastMatchInfo = null;
    for (Definition definition : definitions) {
      for (String exclude : definition.getAspectExcludePatterns()) {
        TypePattern excludePattern = new PatternParser(exclude).parseTypePattern();
        m_aspectExcludeTypePattern.add(excludePattern);
        fastMatchInfo = looksLikeStartsWith(exclude);
        if (fastMatchInfo != null) {
          m_aspectExcludeStartsWith.add(fastMatchInfo);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.