Package org.aspectj.bridge

Examples of org.aspectj.bridge.Message


    message(kind, location1, message);
    message(kind, location2, message);
  }

  public void message(IMessage.Kind kind, IHasPosition location, String message) {
    getMessageHandler().handleMessage(new Message(message, kind, null, makeSourceLocation(location)));
  }
View Full Code Here


    IMessage msg = null;
    if (isLintMessage) {
      msg = new LintMessage(problem.getMessage(), extraDetails, world.getLint().fromKey(lintkey), kind, sourceLocation, null,
          seeAlsoLocations, declared, problem.getID(), problem.getSourceStart(), problem.getSourceEnd());
    } else {
      msg = new Message(problem.getMessage(), extraDetails, kind, sourceLocation, null, seeAlsoLocations, declared, problem
          .getID(), problem.getSourceStart(), problem.getSourceEnd());
    }
    return msg;
  }
View Full Code Here

    return msg;
  }

  public static IMessage makeErrorMessage(ICompilationUnit unit, String text, Exception ex) {
    ISourceLocation loc = new SourceLocation(new File(new String(unit.getFileName())), 0, 0, 0, "");
    IMessage msg = new Message(text, IMessage.ERROR, ex, loc);
    return msg;
  }
View Full Code Here

    return msg;
  }

  public static IMessage makeErrorMessage(String srcFile, String text, Exception ex) {
    ISourceLocation loc = new SourceLocation(new File(srcFile), 0, 0, 0, "");
    IMessage msg = new Message(text, IMessage.ERROR, ex, loc);
    return msg;
  }
View Full Code Here

  protected boolean warn(String message) {
    return MessageUtil.warn(messageHandler, message);
  }

  protected boolean warn(String message, Throwable th) {
    return messageHandler.handleMessage(new Message(message, IMessage.WARNING, th, null));
  }
View Full Code Here

  protected boolean error(String message) {
    return MessageUtil.error(messageHandler, message);
  }

  protected boolean error(String message, Throwable th) {
    return messageHandler.handleMessage(new Message(message, IMessage.ERROR, th, null));
  }
View Full Code Here

      if (((supertype.isRawType() && newParent.isParameterizedType()) || (supertype.isParameterizedType() && newParent
          .isRawType()))
          && newParentGenericType.equals(supertype.getGenericType())) {
        // new parent is a parameterized type, but this is a raw type
        world.getMessageHandler().handleMessage(
            new Message(WeaverMessages.format(WeaverMessages.CANT_DECP_MULTIPLE_PARAMETERIZATIONS, newParent.getName(),
                typeToVerify.getName(), supertype.getName()), getSourceLocation(), true,
                new ISourceLocation[] { typeToVerify.getSourceLocation() }));
        return false;
      }
      if (supertype.isParameterizedType()) {
        ResolvedType generictype = supertype.getGenericType();

        // If the generic types are compatible but the parameterizations aren't then we have a problem
        if (generictype.isAssignableFrom(newParentGenericType) && !supertype.isAssignableFrom(newParent)) {
          world.getMessageHandler().handleMessage(
              new Message(WeaverMessages.format(WeaverMessages.CANT_DECP_MULTIPLE_PARAMETERIZATIONS, newParent
                  .getName(), typeToVerify.getName(), supertype.getName()), getSourceLocation(), true,
                  new ISourceLocation[] { typeToVerify.getSourceLocation() }));
          return false;
        }
      }
View Full Code Here

          }
        }
        if (!itdMatch) {
          IMessage message = null;
          if (isDeclareAtField) {
            message = new Message("The field '" + declA.getSignaturePattern().toString() + "' does not exist",
                declA.getSourceLocation(), true);
          } else {
            message = new Message("The method '" + declA.getSignaturePattern().toString() + "' does not exist",
                declA.getSourceLocation(), true);
          }
          world.getMessageHandler().handleMessage(message);
        }
      }
View Full Code Here

          String handlerClass = arg.substring(OPTIONVALUED_messageHandler.length()).trim();
          try {
            Class handler = Class.forName(handlerClass, false, laoder);
            weaverOption.messageHandler = ((IMessageHandler) handler.newInstance());
          } catch (Throwable t) {
            weaverOption.messageHandler.handleMessage(new Message("Cannot instantiate message handler " + handlerClass,
                IMessage.ERROR, t, null));
          }
        }
      }
    }

    // configure the other options
    for (Iterator iterator = flags.iterator(); iterator.hasNext();) {
      String arg = (String) iterator.next();
      if (arg.equals(OPTION_15)) {
        weaverOption.java5 = true;
      } else if (arg.equalsIgnoreCase(OPTION_lazyTjp)) {
        weaverOption.lazyTjp = true;
      } else if (arg.equalsIgnoreCase(OPTION_noinline)) {
        weaverOption.noInline = true;
      } else if (arg.equalsIgnoreCase(OPTION_addSerialVersionUID)) {
        weaverOption.addSerialVersionUID = true;
      } else if (arg.equalsIgnoreCase(OPTION_noWarn) || arg.equalsIgnoreCase(OPTION_noWarnNone)) {
        weaverOption.noWarn = true;
      } else if (arg.equalsIgnoreCase(OPTION_proceedOnError)) {
        weaverOption.proceedOnError = true;
      } else if (arg.equalsIgnoreCase(OPTION_reweavable)) {
        weaverOption.notReWeavable = false;
      } else if (arg.equalsIgnoreCase(OPTION_showWeaveInfo)) {
        weaverOption.showWeaveInfo = true;
      } else if (arg.equalsIgnoreCase(OPTION_hasMember)) {
        weaverOption.hasMember = true;
      } else if (arg.startsWith(OPTIONVALUED_joinpoints)) {
        if (arg.length() > OPTIONVALUED_joinpoints.length()) {
          weaverOption.optionalJoinpoints = arg.substring(OPTIONVALUED_joinpoints.length()).trim();
        }
      } else if (arg.equalsIgnoreCase(OPTION_verbose)) {
        weaverOption.verbose = true;
      } else if (arg.equalsIgnoreCase(OPTION_debug)) {
        weaverOption.debug = true;
      } else if (arg.equalsIgnoreCase(OPTION_pinpoint)) {
        weaverOption.pinpoint = true;
      } else if (arg.startsWith(OPTIONVALUED_messageHandler)) {
        // handled in first round
      } else if (arg.startsWith(OPTIONVALUED_Xlintfile)) {
        if (arg.length() > OPTIONVALUED_Xlintfile.length()) {
          weaverOption.lintFile = arg.substring(OPTIONVALUED_Xlintfile.length()).trim();
        }
      } else if (arg.startsWith(OPTIONVALUED_Xlint)) {
        if (arg.length() > OPTIONVALUED_Xlint.length()) {
          weaverOption.lint = arg.substring(OPTIONVALUED_Xlint.length()).trim();
        }
      } else if (arg.startsWith(OPTIONVALUED_Xset)) {
        if (arg.length() > OPTIONVALUED_Xlint.length()) {
          weaverOption.xSet = arg.substring(OPTIONVALUED_Xset.length()).trim();
        }
      } else if (arg.equalsIgnoreCase(OPTION_timers)) {
        weaverOption.timers = true;
      } else {
        weaverOption.messageHandler.handleMessage(new Message("Cannot configure weaver with option '" + arg
            + "': unknown option", IMessage.WARNING, null, null));
      }
    }

    // refine message handler configuration
View Full Code Here

        String constantValue = ((ConstantUtf8) constant).getValue();
        if (constantValue.length() > 28 && constantValue.charAt(1) == 'o') {
          if (constantValue.startsWith("Lorg/aspectj/lang/annotation")) {
            containsAnnotationClassReference = true;
            if ("Lorg/aspectj/lang/annotation/DeclareAnnotation;".equals(constantValue)) {
              msgHandler.handleMessage(new Message(
                  "Found @DeclareAnnotation while current release does not support it (see '" + type.getName()
                      + "')", IMessage.WARNING, null, type.getSourceLocation()));
            }
            if ("Lorg/aspectj/lang/annotation/Pointcut;".equals(constantValue)) {
              containsPointcut = true;
            }
          }

        }
      }
    }
    if (!containsAnnotationClassReference) {
      return NO_ATTRIBUTES;
    }

    AjAttributeStruct struct = new AjAttributeStruct(type, context, msgHandler);
    Attribute[] attributes = javaClass.getAttributes();
    boolean hasAtAspectAnnotation = false;
    boolean hasAtPrecedenceAnnotation = false;

    WeaverVersionInfo wvinfo = null;
    for (int i = 0; i < attributes.length; i++) {
      Attribute attribute = attributes[i];
      if (acceptAttribute(attribute)) {
        RuntimeAnnos rvs = (RuntimeAnnos) attribute;
        // we don't need to look for several attribute occurrences since
        // it cannot happen as per JSR175
        if (!isCodeStyleAspect && !javaClass.isInterface()) {
          hasAtAspectAnnotation = handleAspectAnnotation(rvs, struct);
          // TODO AV - if put outside the if isCodeStyleAspect then we
          // would enable mix style
          hasAtPrecedenceAnnotation = handlePrecedenceAnnotation(rvs, struct);
        }
        // there can only be one RuntimeVisible bytecode attribute
        break;
      }
    }
    for (int i = attributes.length - 1; i >= 0; i--) {
      Attribute attribute = attributes[i];
      if (attribute.getName().equals(WeaverVersionInfo.AttributeName)) {
        try {
          VersionedDataInputStream s = new VersionedDataInputStream(new ByteArrayInputStream(
              ((Unknown) attribute).getBytes()), null);
          wvinfo = WeaverVersionInfo.read(s);
          struct.ajAttributes.add(0, wvinfo);
        } catch (IOException ioe) {
          ioe.printStackTrace();
        }
      }
    }
    if (wvinfo == null) {
      // If we are in here due to a resetState() call (presumably because of reweavable state processing), the
      // original type delegate will have been set with a version but that version will be missing from
      // the new set of attributes (looks like a bug where the version attribute was not included in the
      // data compressed into the attribute). So rather than 'defaulting' to current, we should use one
      // if it set on the delegate for the type.
      ReferenceTypeDelegate delegate = type.getDelegate();
      if (delegate instanceof BcelObjectType) {
        wvinfo = ((BcelObjectType) delegate).getWeaverVersionAttribute();
        if (wvinfo != null) {
          if (wvinfo.getMajorVersion() != WeaverVersionInfo.WEAVER_VERSION_MAJOR_UNKNOWN) {
            // use this one
            struct.ajAttributes.add(0, wvinfo);
          } else {
            wvinfo = null;
          }
        }
      }
      if (wvinfo == null) {
        struct.ajAttributes.add(0, wvinfo = new AjAttribute.WeaverVersionInfo());
      }
    }

    // basic semantic check
    if (hasAtPrecedenceAnnotation && !hasAtAspectAnnotation) {
      msgHandler.handleMessage(new Message("Found @DeclarePrecedence on a non @Aspect type '" + type.getName() + "'",
          IMessage.WARNING, null, type.getSourceLocation()));
      // bypass what we have read
      return NO_ATTRIBUTES;
    }

    // the following block will not detect @Pointcut in non @Aspect types
    // for optimization purpose
    if (!(hasAtAspectAnnotation || isCodeStyleAspect) && !containsPointcut) {
      return NO_ATTRIBUTES;
    }

    // FIXME AV - turn on when ajcMightHaveAspect
    // if (hasAtAspectAnnotation && type.isInterface()) {
    // msgHandler.handleMessage(
    // new Message(
    // "Found @Aspect on an interface type '" + type.getName() + "'",
    // IMessage.WARNING,
    // null,
    // type.getSourceLocation()
    // )
    // );
    // // bypass what we have read
    // return EMPTY_LIST;
    // }

    // semantic check: @Aspect must be public
    // FIXME AV - do we really want to enforce that?
    // if (hasAtAspectAnnotation && !javaClass.isPublic()) {
    // msgHandler.handleMessage(
    // new Message(
    // "Found @Aspect annotation on a non public class '" +
    // javaClass.getClassName() + "'",
    // IMessage.ERROR,
    // null,
    // type.getSourceLocation()
    // )
    // );
    // return EMPTY_LIST;
    // }

    // code style pointcuts are class attributes
    // we need to gather the @AJ pointcut right now and not at method level
    // annotation extraction time
    // in order to be able to resolve the pointcut references later on
    // we don't need to look in super class, the pointcut reference in the
    // grammar will do it

    for (int i = 0; i < javaClass.getMethods().length; i++) {
      Method method = javaClass.getMethods()[i];
      if (method.getName().startsWith(NameMangler.PREFIX)) {
        continue; // already dealt with by ajc...
      }
      // FIXME alex optimize, this method struct will gets recreated for
      // advice extraction
      AjAttributeMethodStruct mstruct = null;
      boolean processedPointcut = false;
      Attribute[] mattributes = method.getAttributes();
      for (int j = 0; j < mattributes.length; j++) {
        Attribute mattribute = mattributes[j];
        if (acceptAttribute(mattribute)) {
          // TODO speed all this nonsense up rather than looking
          // through all the annotations every time
          // same for fields
          mstruct = new AjAttributeMethodStruct(method, null, type, context, msgHandler);
          processedPointcut = handlePointcutAnnotation((RuntimeAnnos) mattribute, mstruct);
          if (!processedPointcut) {
            processedPointcut = handleDeclareMixinAnnotation((RuntimeAnnos) mattribute, mstruct);
          }
          // there can only be one RuntimeVisible bytecode attribute
          break;
        }
      }
      if (processedPointcut) {
        struct.ajAttributes.addAll(mstruct.ajAttributes);
      }
    }

    // code style declare error / warning / implements / parents are field
    // attributes
    Field[] fs = javaClass.getFields();
    for (int i = 0; i < fs.length; i++) {
      Field field = fs[i];
      if (field.getName().startsWith(NameMangler.PREFIX)) {
        continue; // already dealt with by ajc...
      }
      // FIXME alex optimize, this method struct will gets recreated for
      // advice extraction
      AjAttributeFieldStruct fstruct = new AjAttributeFieldStruct(field, null, type, context, msgHandler);
      Attribute[] fattributes = field.getAttributes();

      for (int j = 0; j < fattributes.length; j++) {
        Attribute fattribute = fattributes[j];
        if (acceptAttribute(fattribute)) {
          RuntimeAnnos frvs = (RuntimeAnnos) fattribute;
          if (handleDeclareErrorOrWarningAnnotation(model, frvs, fstruct)
              || handleDeclareParentsAnnotation(frvs, fstruct)) {
            // semantic check - must be in an @Aspect [remove if
            // previous block bypassed in advance]
            if (!type.isAnnotationStyleAspect() && !isCodeStyleAspect) {
              msgHandler.handleMessage(new Message("Found @AspectJ annotations in a non @Aspect type '"
                  + type.getName() + "'", IMessage.WARNING, null, type.getSourceLocation()));
              // go ahead
            }
          }
          // there can only be one RuntimeVisible bytecode attribute
View Full Code Here

TOP

Related Classes of org.aspectj.bridge.Message

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.