Package org.aspectj.weaver

Examples of org.aspectj.weaver.Member$Kind


    for (int i = 0, len = declaredParams.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(paramTypes[i], frameIndex));
      frameIndex += paramTypes[i].getSize();
    }
    // do call to pre
    Member preMethod = AjcMemberMaker.preIntroducedConstructor(aspectType, onType, declaredParams);
    body.append(Utility.createInvoke(fact, null, preMethod));

    // create a local, and store return pre stuff into it.
    int arraySlot = mg.allocateLocal(1);
    body.append(InstructionFactory.createStore(Type.OBJECT, arraySlot));

    // put this on the stack
    body.append(InstructionConstants.ALOAD_0);

    // unpack pre args onto stack
    UnresolvedType[] superParamTypes = explicitConstructor.getParameterTypes();

    for (int i = 0, len = superParamTypes.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
      body.append(Utility.createConstant(fact, i));
      body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
      body.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(superParamTypes[i])));
    }

    // call super/this

    body.append(Utility.createInvoke(fact, null, explicitConstructor));

    // put this back on the stack

    body.append(InstructionConstants.ALOAD_0);

    // unpack params onto stack
    Member postMethod = AjcMemberMaker.postIntroducedConstructor(aspectType, onType, declaredParams);
    UnresolvedType[] postParamTypes = postMethod.getParameterTypes();

    for (int i = 1, len = postParamTypes.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
      body.append(Utility.createConstant(fact, superParamTypes.length + i - 1));
      body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
View Full Code Here


  @Override
  public ShadowMunger parameterizeWith(ResolvedType declaringType, Map<String, UnresolvedType> typeVariableMap) {
    Pointcut pc = getPointcut().parameterizeWith(typeVariableMap, declaringType.getWorld());

    BcelAdvice ret = null;
    Member adviceSignature = signature;
    // allows for around advice where the return value is a type variable (see pr115250)
    if (signature instanceof ResolvedMember && signature.getDeclaringType().isGenericType()) {
      adviceSignature = ((ResolvedMember) signature).parameterizedWith(declaringType.getTypeParameters(), declaringType,
          declaringType.isParameterizedType());
    }
View Full Code Here

    // remove any unnecessary exceptions if the compiler option is set to
    // error or warning and if this piece of advice throws exceptions
    // (bug 129282). This may be expanded to include other compiler warnings
    // at the moment it only deals with 'declared exception is not thrown'
    if (!shadow.getWorld().isIgnoringUnusedDeclaredThrownException() && !getThrownExceptions().isEmpty()) {
      Member member = shadow.getSignature();
      if (member instanceof BcelMethod) {
        removeUnnecessaryProblems((BcelMethod) member, ((BcelMethod) member).getDeclarationLineNumber());
      } else {
        // we're in a call shadow therefore need the line number of the
        // declared method (which may be in a different type). However,
        // we want to remove the problems from the CompilationResult
        // held within the current type's EclipseSourceContext so need
        // the enclosing shadow too
        ResolvedMember resolvedMember = shadow.getSignature().resolve(shadow.getWorld());
        if (resolvedMember instanceof BcelMethod && shadow.getEnclosingShadow() instanceof BcelShadow) {
          Member enclosingMember = shadow.getEnclosingShadow().getSignature();
          if (enclosingMember instanceof BcelMethod) {
            removeUnnecessaryProblems((BcelMethod) enclosingMember,
                ((BcelMethod) resolvedMember).getDeclarationLineNumber());
          }
        }
      }
    }

    if (shadow.getIWorld().isJoinpointSynchronizationEnabled() && shadow.getKind() == Shadow.MethodExecution
        && (s.getSignature().getModifiers() & Modifier.SYNCHRONIZED) != 0) {
      shadow.getIWorld().getLint().advisingSynchronizedMethods.signal(new String[] { shadow.toString() },
          shadow.getSourceLocation(), new ISourceLocation[] { getSourceLocation() });
    }

    // FIXME AV - see #75442, this logic is not enough so for now comment it out until we fix the bug
    // // callback for perObject AJC MightHaveAspect postMunge (#75442)
    // if (getConcreteAspect() != null
    // && getConcreteAspect().getPerClause() != null
    // && PerClause.PEROBJECT.equals(getConcreteAspect().getPerClause().getKind())) {
    // final PerObject clause;
    // if (getConcreteAspect().getPerClause() instanceof PerFromSuper) {
    // clause = (PerObject)((PerFromSuper) getConcreteAspect().getPerClause()).lookupConcretePerClause(getConcreteAspect());
    // } else {
    // clause = (PerObject) getConcreteAspect().getPerClause();
    // }
    // if (clause.isThis()) {
    // PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getThisVar().getType(), getConcreteAspect());
    // } else {
    // PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getTargetVar().getType(), getConcreteAspect());
    // }
    // }
    if (runtimeTest == Literal.FALSE) { // not usually allowed, except in one case (260384)
      Member sig = shadow.getSignature();
      if (sig.getArity() == 0 && shadow.getKind() == Shadow.MethodCall && sig.getName().charAt(0) == 'c'
          && sig.getReturnType().equals(ResolvedType.OBJECT) && sig.getName().equals("clone")) {
        return false;
      }
    }

    if (getKind() == AdviceKind.Before) {
View Full Code Here

    return new InstructionList(Utility.createInvoke(shadow.getFactory(), shadow.getWorld(), getOriginalSignature()));
  }

  @Override
  public Member getOriginalSignature() {
    Member sig = getSignature();
    if (sig instanceof ResolvedMember) {
      ResolvedMember rsig = (ResolvedMember) sig;
      if (rsig.hasBackingGenericMember()) {
        return rsig.getBackingGenericMember();
      }
View Full Code Here

  private boolean hasField(ResolvedType type) {
    // TODO what about ITDs
    World world = type.getWorld();
    for (Iterator iter = type.getFields(); iter.hasNext();) {
      Member field = (Member) iter.next();
      if (field.getName().startsWith(declareAtPrefix)) {
        continue;
      }
      if (signaturePattern.matches(field, type.getWorld(), false)) {
        if (field.getDeclaringType().resolve(world) != type) {
          if (Modifier.isPrivate(field.getModifiers())) {
            continue;
          }
        }
        return true;
      }
View Full Code Here

  protected boolean hasMethod(ResolvedType type) {
    // TODO what about ITDs
    World world = type.getWorld();
    for (Iterator<ResolvedMember> iter = type.getMethods(true, true); iter.hasNext();) {
      Member method = (Member) iter.next();
      if (method.getName().startsWith(declareAtPrefix)) {
        continue;
      }
      if (signaturePattern.matches(method, type.getWorld(), false)) {
        if (method.getDeclaringType().resolve(world) != type) {
          if (Modifier.isPrivate(method.getModifiers())) {
            continue;
          }
        }
        return true;
      }
    }
    // try itds before we give up (this doesnt find annotations - the signature returned may not include them)
    List<ConcreteTypeMunger> mungers = type.getInterTypeMungersIncludingSupers();
    for (Iterator<ConcreteTypeMunger> iter = mungers.iterator(); iter.hasNext();) {
      ConcreteTypeMunger munger = iter.next();
      Member member = munger.getSignature();
      if (signaturePattern.matches(member, type.getWorld(), false)) {
        if (!Modifier.isPublic(member.getModifiers())) {
          continue;
        }
        return true;
      }
    }
View Full Code Here

   *
   * @see org.aspectj.weaver.patterns.Pointcut#match(org.aspectj.weaver.Shadow)
   */
  protected FuzzyBoolean matchInternal(Shadow shadow) {
    AnnotatedElement toMatchAgainst = null;
    Member member = shadow.getSignature();
    ResolvedMember rMember = member.resolve(shadow.getIWorld());

    if (rMember == null) {
      if (member.getName().startsWith(NameMangler.PREFIX)) {
        return FuzzyBoolean.NO;
      }
      shadow.getIWorld().getLint().unresolvableMember.signal(member.toString(), getSourceLocation());
      return FuzzyBoolean.NO;
    }

    Shadow.Kind kind = shadow.getKind();
    if (kind == Shadow.StaticInitialization) {
View Full Code Here

      }
    }
  }

  protected static IProgramElement getNode(AsmManager model, Shadow shadow) {
    Member enclosingMember = shadow.getEnclosingCodeSignature();
    // This variant will not be tricked by ITDs that would report they are
    // in the target type already.
    // This enables us to discover the ITD declaration (in the aspect) and
    // advise it appropriately.

    // Have to be smart here, for a code node within an ITD we want to
    // lookup the declaration of the
    // ITD in the aspect in order to add the code node at the right place -
    // and not lookup the
    // ITD as it applies in some target type. Due to the use of
    // effectiveSignature we will find
    // that shadow.getEnclosingCodeSignature() will return a member
    // representing the ITD as it will
    // appear in the target type. So here, we do an extra bit of analysis to
    // make sure we
    // do the right thing in the ITD case.
    IProgramElement enclosingNode = null;
    if (shadow instanceof BcelShadow) {
      Member actualEnclosingMember = ((BcelShadow) shadow).getRealEnclosingCodeSignature();

      if (actualEnclosingMember == null) {
        enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), enclosingMember);
      } else {
        UnresolvedType type = enclosingMember.getDeclaringType();
        UnresolvedType actualType = actualEnclosingMember.getDeclaringType();

        // if these are not the same, it is an ITD and we need to use
        // the latter to lookup
        if (type.equals(actualType)) {
          enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), enclosingMember);
        } else {
          enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), actualEnclosingMember);
        }
      }
    } else {
      enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), enclosingMember);
    }

    if (enclosingNode == null) {
      Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
      if (err.isEnabled()) {
        err.signal(shadow.toString(), shadow.getSourceLocation());
      }
      return null;
    }

    Member shadowSig = shadow.getSignature();
    // pr235204
    if (shadow.getKind() == Shadow.MethodCall || shadow.getKind() == Shadow.ConstructorCall
        || !shadowSig.equals(enclosingMember)) {
      IProgramElement bodyNode = findOrCreateCodeNode(model, enclosingNode, shadowSig, shadow);
      return bodyNode;
    } else {
      return enclosingNode;
    }
View Full Code Here

  // all the arguments in temps.
  public static BcelShadow makeConstructorCall(BcelWorld world, LazyMethodGen enclosingMethod, InstructionHandle callHandle,
      BcelShadow enclosingShadow) {
    final InstructionList body = enclosingMethod.getBody();

    Member sig = world.makeJoinPointSignatureForMethodInvocation(enclosingMethod.getEnclosingClass(),
        (InvokeInstruction) callHandle.getInstruction());

    BcelShadow s = new BcelShadow(world, ConstructorCall, sig, enclosingMethod, enclosingShadow);
    ShadowRange r = new ShadowRange(body);
    r.associateWithShadow(s);
View Full Code Here

  }

  public static BcelShadow makeArrayConstructorCall(BcelWorld world, LazyMethodGen enclosingMethod,
      InstructionHandle arrayInstruction, BcelShadow enclosingShadow) {
    final InstructionList body = enclosingMethod.getBody();
    Member sig = world.makeJoinPointSignatureForArrayConstruction(enclosingMethod.getEnclosingClass(), arrayInstruction);
    BcelShadow s = new BcelShadow(world, ConstructorCall, sig, enclosingMethod, enclosingShadow);
    ShadowRange r = new ShadowRange(body);
    r.associateWithShadow(s);
    r.associateWithTargets(Range.genStart(body, arrayInstruction), Range.genEnd(body, arrayInstruction));
    retargetAllBranches(arrayInstruction, r.getStart());
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.Member$Kind

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.