Examples of EclipseFactory


Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    });
  }

  private void generatePerObjectBindMethod(ClassFile classFile, final TypeBinding interfaceType) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, AjcMemberMaker.perObjectBind(world.fromBinding(binding)), new BodyGenerator() {
      public void generate(CodeStream codeStream) {
        // body starts here
        BranchLabel wrongType = new BranchLabel(codeStream);
        codeStream.aload_0();
        codeStream.instance_of(interfaceType);
        codeStream.ifeq(wrongType); // XXX this case might call for screaming
        codeStream.aload_0();
        codeStream.checkcast(interfaceType);
        codeStream.invokeinterface(world.makeMethodBindingForCall(AjcMemberMaker.perObjectInterfaceGet(typeX)));
        // XXX should do a check for null here and throw a NoAspectBound
        codeStream.ifnonnull(wrongType);

        codeStream.aload_0();
        codeStream.checkcast(interfaceType);
        codeStream.new_(binding);
        codeStream.dup();
        codeStream.invokespecial(new MethodBinding(0, "<init>".toCharArray(), TypeBinding.VOID, new TypeBinding[0],
            new ReferenceBinding[0], binding));
        codeStream.invokeinterface(world.makeMethodBindingForCall(AjcMemberMaker.perObjectInterfaceSet(typeX)));

        wrongType.place();
        codeStream.return_();
        // body ends here
      }
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    });
  }

  private void generatePerTypeWithinGetWithinTypeNameMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    // Code:
    /*
     * Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #14; //Field ajc$withinType:Ljava/lang/String; 4: areturn
     */
    generateMethod(classFile,
        AjcMemberMaker.perTypeWithinGetWithinTypeNameMethod(world.fromBinding(binding), world.getWorld().isInJava5Mode()),
        new BodyGenerator() {
          public void generate(CodeStream codeStream) {
            ExceptionLabel exc = new ExceptionLabel(codeStream, world.makeTypeBinding(UnresolvedType.JL_EXCEPTION));
            exc.placeStart();
            codeStream.aload_0();
            codeStream.getfield(world.makeFieldBinding(AjcMemberMaker.perTypeWithinWithinTypeField(typeX, typeX)));
            codeStream.areturn();
          }
        });
  }
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

        });
  }

  // PTWIMPL Generate getInstance method
  private void generatePerTypeWithinGetInstanceMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, AjcMemberMaker.perTypeWithinGetInstance(world.fromBinding(binding)), new BodyGenerator() {
      public void generate(CodeStream codeStream) {
        ExceptionLabel exc = new ExceptionLabel(codeStream, world.makeTypeBinding(UnresolvedType.JL_EXCEPTION));
        exc.placeStart();
        codeStream.aload_0();
        codeStream.ldc(NameMangler.perTypeWithinLocalAspectOf(typeX));
        codeStream.aconst_null();
        codeStream.invokevirtual(new MethodBinding(0, "getDeclaredMethod".toCharArray(),
            world.makeTypeBinding(UnresolvedType.forSignature("Ljava/lang/reflect/Method;")), // return type
            new TypeBinding[] { world.makeTypeBinding(UnresolvedType.forSignature("Ljava/lang/String;")),
                world.makeTypeBinding(UnresolvedType.forSignature("[Ljava/lang/Class;")) },
            new ReferenceBinding[0], (ReferenceBinding) world.makeTypeBinding(UnresolvedType.JL_CLASS)));
        codeStream.astore_1();
        codeStream.aload_1();
        codeStream.aconst_null();
        codeStream.aconst_null();
        codeStream.invokevirtual(new MethodBinding(0, "invoke".toCharArray(), world.makeTypeBinding(UnresolvedType.OBJECT),
            new TypeBinding[] { world.makeTypeBinding(UnresolvedType.OBJECT),
                world.makeTypeBinding(UnresolvedType.forSignature("[Ljava/lang/Object;")) },
            new ReferenceBinding[0], (ReferenceBinding) world.makeTypeBinding(UnresolvedType.JAVA_LANG_REFLECT_METHOD)));
        codeStream.checkcast(world.makeTypeBinding(typeX));
        codeStream.astore_2();
        codeStream.aload_2();
        exc.placeEnd();
        codeStream.areturn();
        exc.place();
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    });
  }

  private void generatePerTypeWithinCreateAspectInstanceMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, AjcMemberMaker.perTypeWithinCreateAspectInstance(world.fromBinding(binding)),
        new BodyGenerator() {
          public void generate(CodeStream codeStream) {

            codeStream.new_(world.makeTypeBinding(typeX));
            codeStream.dup();
            codeStream.invokespecial(new MethodBinding(0, "<init>".toCharArray(), TypeBinding.VOID, new TypeBinding[0],
                new ReferenceBinding[0], binding));
            codeStream.astore_1();
            codeStream.aload_1();
            codeStream.aload_0();
            codeStream.putfield(world.makeFieldBinding(AjcMemberMaker.perTypeWithinWithinTypeField(typeX, typeX)));
            codeStream.aload_1();
            codeStream.areturn();
          }
        });
  }
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

          }
        });
  }

  private void generatePerSingletonAspectOfMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, aspectOfMethod, new BodyGenerator() {
      public void generate(CodeStream codeStream) {
        // Old style aspectOf() method which confused decompilers
        // // body starts here
        // codeStream.getstatic(world.makeFieldBinding(AjcMemberMaker.perSingletonField(
        // typeX)));
        // Label isNull = new Label(codeStream);
        // codeStream.dup();
        // codeStream.ifnull(isNull);
        // codeStream.areturn();
        // isNull.place();
        //
        // codeStream.incrStackSize(+1); // the dup trick above confuses the stack counter
        // codeStream.new_(world.makeTypeBinding(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION));
        // codeStream.dup();
        // codeStream.ldc(typeX.getNameAsIdentifier());
        // codeStream.getstatic(initFailureField);
        // codeStream.invokespecial(world.makeMethodBindingForCall(
        // AjcMemberMaker.noAspectBoundExceptionInitWithCause()
        // ));
        // codeStream.athrow();
        // // body ends here

        // The stuff below generates code that looks like this:
        /*
         * if (ajc$perSingletonInstance == null) throw new NoAspectBoundException("A", ajc$initFailureCause); else return
         * ajc$perSingletonInstance;
         */
        // body starts here (see end of each line for what it is doing!)
        FieldBinding fb = world.makeFieldBinding(AjcMemberMaker.perSingletonField(typeX));
        codeStream.getstatic(fb); // GETSTATIC
        BranchLabel isNonNull = new BranchLabel(codeStream);
        codeStream.ifnonnull(isNonNull); // IFNONNULL
        codeStream.new_(world.makeTypeBinding(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION)); // NEW
        codeStream.dup(); // DUP
        codeStream.ldc(typeX.getNameAsIdentifier()); // LDC
        codeStream.getstatic(initFailureField); // GETSTATIC
        codeStream.invokespecial(world.makeMethodBindingForCall(AjcMemberMaker.noAspectBoundExceptionInitWithCause())); // INVOKESPECIAL
        codeStream.athrow(); // ATHROW
        isNonNull.place();
        codeStream.getstatic(fb); // GETSTATIC
        codeStream.areturn(); // ARETURN
        // body ends here
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    });
  }

  private void generatePerSingletonHasAspectMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, hasAspectMethod, new BodyGenerator() {
      public void generate(CodeStream codeStream) {
        // body starts here
        codeStream.getstatic(world.makeFieldBinding(AjcMemberMaker.perSingletonField(typeX)));
        BranchLabel isNull = new BranchLabel(codeStream);
        codeStream.ifnull(isNull);
        codeStream.iconst_1();
        codeStream.ireturn();
        isNull.place();
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    });
  }

  private void generatePerSingletonAjcClinitMethod(ClassFile classFile) {
    final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(this.scope);
    generateMethod(classFile, world.makeMethodBinding(AjcMemberMaker.ajcPostClinitMethod(world.fromBinding(binding))),
        new BodyGenerator() {
          public void generate(CodeStream codeStream) {
            // body starts here
            codeStream.new_(binding);
            codeStream.dup();
            codeStream.invokespecial(new MethodBinding(0, "<init>".toCharArray(), TypeBinding.VOID, new TypeBinding[0],
                new ReferenceBinding[0], binding));

            codeStream.putstatic(world.makeFieldBinding(AjcMemberMaker.perSingletonField(typeX)));
            codeStream.return_();
            // body ends here
          }
        });
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      return perClause.getKind();
    }
  }

  private void buildPerClause(ClassScope scope) {
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);

    if (perClause == null) {
      PerClause.Kind kind = lookupPerClauseKind(binding.superclass);
      if (kind == null) {
        perClause = new PerSingleton();
      } else {
        perClause = new PerFromSuper(kind);
      }
    }

    // aspectAttribute = new AjAttribute.Aspect(perClause);

    if (ignoreFurtherInvestigation) {
      return; // ???
    }

    if (!isAbstract()) {
      if (perClause.getKind() == PerClause.SINGLETON) {
        aspectOfMethod = AjcMemberMaker.perSingletonAspectOfMethod(typeX);
        hasAspectMethod = AjcMemberMaker.perSingletonHasAspectMethod(typeX);
      } else if (perClause.getKind() == PerClause.PERCFLOW) {
        aspectOfMethod = AjcMemberMaker.perCflowAspectOfMethod(typeX);
        hasAspectMethod = AjcMemberMaker.perCflowHasAspectMethod(typeX);
      } else if (perClause.getKind() == PerClause.PEROBJECT) {
        aspectOfMethod = AjcMemberMaker.perObjectAspectOfMethod(typeX);
        hasAspectMethod = AjcMemberMaker.perObjectHasAspectMethod(typeX);
      } else if (perClause.getKind() == PerClause.PERTYPEWITHIN) {
        // PTWIMPL Use these variants of aspectOf()/hasAspect()
        aspectOfMethod = AjcMemberMaker.perTypeWithinAspectOfMethod(typeX, world.getWorld().isInJava5Mode());
        hasAspectMethod = AjcMemberMaker.perTypeWithinHasAspectMethod(typeX, world.getWorld().isInJava5Mode());
        ptwGetWithinTypeNameMethod = AjcMemberMaker.perTypeWithinGetWithinTypeNameMethod(typeX, world.getWorld()
            .isInJava5Mode());
        binding.addMethod(world.makeMethodBinding(ptwGetWithinTypeNameMethod));
      } else {
        throw new RuntimeException("bad per clause: " + perClause);
      }

      binding.addMethod(world.makeMethodBinding(aspectOfMethod));
      binding.addMethod(world.makeMethodBinding(hasAspectMethod));
    }
    resolvePerClause(); // XXX might be too soon for some error checking
  }
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

    // XXX AMC we need to do this, but I'm not 100% comfortable as I don't
    // know why the return type is wrong in this case. Also, we don't seem to need
    // to do it for args...
    if (munger.getSignature().getReturnType().isRawType()) {
      if (!binding.returnType.isRawType()) {
        EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);
        binding.returnType = world.makeTypeBinding(munger.getSignature().getReturnType());
      }
    }

    // check @Override annotation - based on MethodDeclaration.resolveStatements() @Override processing
    checkOverride: {
      if (this.binding == null)
        break checkOverride;
      if (this.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5)
        break checkOverride;
      boolean hasOverrideAnnotation = (this.binding.tagBits & TagBits.AnnotationOverride) != 0;

      // Need to verify
      if (hasOverrideAnnotation) {

        // Work out the real method binding that we can use for comparison
        EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);
        MethodBinding realthing = world.makeMethodBinding(munger.getSignature(), munger.getTypeVariableAliases());

        boolean reportError = true;
        // Go up the hierarchy, looking for something we override
        ReferenceBinding supertype = onTypeBinding.superclass();
        while (supertype != null && reportError) {
View Full Code Here

Examples of org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory

      }
    }
  }

  public EclipseTypeMunger build(ClassScope classScope) {
    EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(classScope);

    resolveOnType(classScope);
    if (ignoreFurtherInvestigation)
      return null;

    binding = classScope.referenceContext.binding.resolveTypesFor(binding);
    if (binding == null) {
      // if binding is null, we failed to find a type used in the method params, this error
      // has already been reported.
      this.ignoreFurtherInvestigation = true;
      // return null;
      throw new AbortCompilationUnit(compilationResult, null);
    }

    if (isTargetAnnotation(classScope, "method"))
      return null; // Error message output in isTargetAnnotation
    if (isTargetEnum(classScope, "method"))
      return null; // Error message output in isTargetEnum

    if (interTypeScope == null)
      return null; // We encountered a problem building the scope, don't continue - error already reported

    // This signature represents what we want consumers of the targetted type to 'see'
    // must use the factory method to build it since there may be typevariables from the binding
    // referred to in the parameters/returntype
    ResolvedMemberImpl sig = factory.makeResolvedMemberForITD(binding, onTypeBinding, interTypeScope.getRecoveryAliases());
    sig.resetName(new String(declaredSelector));
    int resetModifiers = declaredModifiers;
    if (binding.isVarargs())
      resetModifiers = resetModifiers | Constants.ACC_VARARGS;
    sig.resetModifiers(resetModifiers);
    NewMethodTypeMunger myMunger = new NewMethodTypeMunger(sig, null, typeVariableAliases);
    setMunger(myMunger);
    ResolvedType aspectType = factory.fromEclipse(classScope.referenceContext.binding);
    ResolvedMember me = myMunger.getInterMethodBody(aspectType);
    this.selector = binding.selector = me.getName().toCharArray();
    return new EclipseTypeMunger(factory, myMunger, aspectType, this);
  }
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.