Package org.aspectj.bridge

Examples of org.aspectj.bridge.Message


        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


          hasAtAspectJAnnotation = hasAtAspectJAnnotation || handleAroundAnnotation(rvs, struct, preResolvedPointcut);
          // there can only be one RuntimeVisible bytecode attribute
          break;
        }
      } catch (ReturningFormalNotDeclaredInAdviceSignatureException e) {
        msgHandler.handleMessage(new Message(WeaverMessages.format(WeaverMessages.RETURNING_FORMAL_NOT_DECLARED_IN_ADVICE,
            e.getFormalName()), IMessage.ERROR, null, bMethod.getSourceLocation()));
      } catch (ThrownFormalNotDeclaredInAdviceSignatureException e) {
        msgHandler.handleMessage(new Message(WeaverMessages.format(WeaverMessages.THROWN_FORMAL_NOT_DECLARED_IN_ADVICE,
            e.getFormalName()), IMessage.ERROR, null, bMethod.getSourceLocation()));
      }
    }
    hasAtAspectJAnnotation = hasAtAspectJAnnotation || hasAtAspectJAnnotationMustReturnVoid;

    // semantic check - must be in an @Aspect [remove if previous block
    // bypassed in advance]
    if (hasAtAspectJAnnotation && !type.isAspect()) { // isAnnotationStyleAspect())
      // {
      msgHandler.handleMessage(new Message("Found @AspectJ annotations in a non @Aspect type '" + type.getName() + "'",
          IMessage.WARNING, null, type.getSourceLocation()));
      // go ahead
    }
    // semantic check - advice must be public
    if (hasAtAspectJAnnotation && !struct.method.isPublic()) {
      msgHandler.handleMessage(new Message("Found @AspectJ annotation on a non public advice '"
          + methodToString(struct.method) + "'", IMessage.ERROR, null, type.getSourceLocation()));
      // go ahead
    }

    // semantic check - advice must not be static
    if (hasAtAspectJAnnotation && struct.method.isStatic()) {
      msgHandler.handleMessage(MessageUtil.error("Advice cannot be declared static '" + methodToString(struct.method) + "'",
          type.getSourceLocation()));
      // new Message(
      // "Advice cannot be declared static '" +
      // methodToString(struct.method) + "'",
      // IMessage.ERROR,
      // null,
      // type.getSourceLocation()
      // )
      // );
      // go ahead
    }

    // semantic check for non around advice must return void
    if (hasAtAspectJAnnotationMustReturnVoid && !Type.VOID.equals(struct.method.getReturnType())) {
      msgHandler.handleMessage(new Message("Found @AspectJ annotation on a non around advice not returning void '"
          + methodToString(struct.method) + "'", IMessage.ERROR, null, type.getSourceLocation()));
      // go ahead
    }

    return struct.ajAttributes;
View Full Code Here

        try {
            path = getPropertiesFilePath();
            in = new FileInputStream(file);
            properties.load(in);
        } catch (IOException ioe) {
          Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null);
          Ajde.getDefault().getMessageHandler().handleMessage(msg);
        } finally {
            if (null != in) {
                try {
                    in.close();
View Full Code Here

   * @param message
   * @param location
   */
  private static void reportError(String message, AjAttributeStruct location) {
    if (!location.handler.isIgnoring(IMessage.ERROR)) {
      location.handler.handleMessage(new Message(message, location.enclosingType.getSourceLocation(), true));
    }
  }
View Full Code Here

        try {
            path = getPropertiesFilePath();
            out = new FileOutputStream(path);
            properties.store(out, "AJDE Settings");
        } catch (IOException ioe) {
          Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null);
          Ajde.getDefault().getMessageHandler().handleMessage(msg);
        } finally {
            if (null != out) {
                try {
                    out.close();
View Full Code Here

   * @param message
   * @param location
   */
  private static void reportWarning(String message, AjAttributeStruct location) {
    if (!location.handler.isIgnoring(IMessage.WARNING)) {
      location.handler.handleMessage(new Message(message, location.enclosingType.getSourceLocation(), false));
    }
  }
View Full Code Here

    public void showError(String message) {
      ISourceLocation location = null;
      if (buildConfig.getConfigFile() != null) {
        location = new SourceLocation(buildConfig.getConfigFile(), 0);
      }
      IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.ERROR, null, location);
      handler.handleMessage(errorMessage);
      // MessageUtil.error(handler, CONFIG_MSG + message);
    }
View Full Code Here

    protected void showWarning(String message) {
      ISourceLocation location = null;
      if (buildConfig.getConfigFile() != null) {
        location = new SourceLocation(buildConfig.getConfigFile(), 0);
      }
      IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.WARNING, null, location);
      handler.handleMessage(errorMessage);
      // MessageUtil.warn(handler, message);
    }
View Full Code Here

      for (Iterator i = slots.iterator(); i.hasNext();) {
        Slot slot = (Slot) i.next();
        ResolvedType rt = slot.formalType;
        if (rt.isMissing()) {
          ISourceLocation[] locs = new ISourceLocation[] { getSourceLocation() };
          Message m = new Message(WeaverMessages.format(WeaverMessages.MISSING_TYPE_PREVENTS_MATCH, rt.getName()), "",
              Message.WARNING, shadow.getSourceLocation(), null, locs);
          rt.getWorld().getMessageHandler().handleMessage(m);
          return FuzzyBoolean.NO;
        }
      }
View Full Code Here

      super();
        try {
          views_splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
            jbInit();
        } catch(Exception e) {
          Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null);
          Ajde.getDefault().getMessageHandler().handleMessage(msg);
        }
  }
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.