Examples of EclipseFactory


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

      PatternParser pp = new PatternParser(pointcutExpression, context);
      Pointcut pc = pp.parsePointcut();
      pp.checkEof();
      FormalBinding[] bindings = buildFormalAdviceBindingsFrom(methodDeclaration);
      pc.resolve(new EclipseScope(bindings, methodDeclaration.scope));
      EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(methodDeclaration.scope);
      // now create a ResolvedPointcutDefinition,make an attribute out of
      // it, and add it to the method
      UnresolvedType[] paramTypes = new UnresolvedType[bindings.length];
      for (int i = 0; i < paramTypes.length; i++)
        paramTypes[i] = bindings[i].getType();
      ResolvedPointcutDefinition resPcutDef = new ResolvedPointcutDefinition(factory.fromBinding(((TypeDeclaration) typeStack
          .peek()).binding), methodDeclaration.modifiers, "anonymous", paramTypes, pc);
      AjAttribute attr = new AjAttribute.PointcutDeclarationAttribute(resPcutDef);
      ((AjMethodDeclaration) methodDeclaration).addAttribute(new EclipseAttributeAdapter(attr));
    } catch (ParserException pEx) {
      methodDeclaration.scope.problemReporter().parseError(pcLocation[0] + pEx.getLocation().getStart(),
View Full Code Here

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

  private FormalBinding[] buildFormalAdviceBindingsFrom(MethodDeclaration mDecl) {
    if (mDecl.arguments == null)
      return new FormalBinding[0];
    if (mDecl.binding == null)
      return new FormalBinding[0];
    EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(mDecl.scope);
    String extraArgName = maybeGetExtraArgName();
    if (extraArgName == null)
      extraArgName = "";
    FormalBinding[] ret = new FormalBinding[mDecl.arguments.length];
    for (int i = 0; i < mDecl.arguments.length; i++) {
      Argument arg = mDecl.arguments[i];
      String name = new String(arg.name);
      TypeBinding argTypeBinding = mDecl.binding.parameters[i];
      UnresolvedType type = factory.fromBinding(argTypeBinding);
      if (CharOperation.equals(joinPoint, argTypeBinding.signature())
          || CharOperation.equals(joinPointStaticPart, argTypeBinding.signature())
          || CharOperation.equals(joinPointEnclosingStaticPart, argTypeBinding.signature())
          || CharOperation.equals(proceedingJoinPoint, argTypeBinding.signature()) || name.equals(extraArgName)) {
        ret[i] = new FormalBinding.ImplicitFormalBinding(type, name, i);
View Full Code Here

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

   * initializers in the target class will not be executed leading to unexpected behaviour.
   */
  private void raiseNoFieldInitializersWarning() {
    if (suppressingNoExplicitConstructorCall())
      return;
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);
    ISourceLocation location = new EclipseSourceLocation(scope.problemReporter().referenceContext.compilationResult(),
        sourceStart(), sourceEnd());
    world.getWorld().getLint().noExplicitConstructorCall.signal(null, location);
  }
View Full Code Here

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

    }
    return false;
  }

  private MethodDeclaration makePreMethod(ClassScope scope, ExplicitConstructorCall explicitConstructorCall) {
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);

    UnresolvedType aspectTypeX = world.fromBinding(binding.declaringClass);
    UnresolvedType targetTypeX = world.fromBinding(onTypeBinding);

    ArrayBinding objectArrayBinding = scope.createArrayType(scope.getJavaLangObject(), 1);

    MethodDeclaration pre = new MethodDeclaration(compilationResult);
    pre.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
    pre.returnType = AstUtil.makeTypeReference(objectArrayBinding);
    pre.selector = NameMangler.postIntroducedConstructor(aspectTypeX, targetTypeX).toCharArray();

    pre.arguments = AstUtil.copyArguments(this.arguments);

    // XXX should do exceptions

    pre.scope = new MethodScope(scope, pre, true);
    // ??? do we need to do anything with scope???

    // Use the factory to build a semi-correct resolvedmember - then patch it up with
    // reset calls. This is SAFE
    ResolvedMemberImpl preIntroducedConstructorRM = world.makeResolvedMember(binding);
    preIntroducedConstructorRM.resetName(NameMangler.preIntroducedConstructor(aspectTypeX, targetTypeX));
    preIntroducedConstructorRM.resetModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
    preIntroducedConstructorRM.resetReturnTypeToObjectArray();

    pre.binding = world.makeMethodBinding(preIntroducedConstructorRM);

    pre.bindArguments();
    pre.bindThrownExceptions();

    if (explicitConstructorCall == null) {
      pre.statements = new Statement[] {};
    } else {
      pre.statements = new Statement[] { explicitConstructorCall };
    }

    InterTypeScope newParent = new InterTypeScope(scope, onTypeBinding);
    pre.scope.parent = newParent;

    pre.resolveStatements(); // newParent);

    int nParams = pre.arguments.length;
    MethodBinding explicitConstructor = null;
    if (explicitConstructorCall != null) {
      explicitConstructor = explicitConstructorCall.binding;
      // If it is null then we are going to report something else is wrong with this code!
      if (explicitConstructor != null && explicitConstructor.alwaysNeedsAccessMethod()) {
        explicitConstructor = explicitConstructor.getAccessMethod(true);
      }
    }

    int nExprs;
    if (explicitConstructor == null)
      nExprs = 0;
    else
      nExprs = explicitConstructor.parameters.length;

    ArrayInitializer init = new ArrayInitializer();
    init.expressions = new Expression[nExprs + nParams];
    int index = 0;
    for (int i = 0; i < nExprs; i++) {
      if (i >= (explicitConstructorCall.arguments == null ? 0 : explicitConstructorCall.arguments.length)) {
        init.expressions[index++] = new NullLiteral(0, 0);
        continue;
      }

      Expression arg = explicitConstructorCall.arguments[i];
      ResolvedMember conversionMethod = AjcMemberMaker.toObjectConversionMethod(world
          .fromBinding(explicitConstructorCall.binding.parameters[i]));
      if (conversionMethod != null) {
        arg = new KnownMessageSend(world.makeMethodBindingForCall(conversionMethod), new CastExpression(new NullLiteral(0,
            0), AstUtil.makeTypeReference(world.makeTypeBinding(AjcMemberMaker.CONVERSIONS_TYPE))),
            new Expression[] { arg });
      }
      init.expressions[index++] = arg;
    }

    for (int i = 0; i < nParams; i++) {
      LocalVariableBinding binding = pre.arguments[i].binding;
      Expression arg = AstUtil.makeResolvedLocalVariableReference(binding);
      ResolvedMember conversionMethod = AjcMemberMaker.toObjectConversionMethod(world.fromBinding(binding.type));
      if (conversionMethod != null) {
        arg = new KnownMessageSend(world.makeMethodBindingForCall(conversionMethod), new CastExpression(new NullLiteral(0,
            0), AstUtil.makeTypeReference(world.makeTypeBinding(AjcMemberMaker.CONVERSIONS_TYPE))),
            new Expression[] { arg });
      }
      init.expressions[index++] = arg;
    }
View Full Code Here

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

    pre.statements = new Statement[] { new ReturnStatement(newArray, 0, 0), };
    return pre;
  }

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

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

    binding = classScope.referenceContext.binding.resolveTypesFor(binding);

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

    if (onTypeBinding.isInterface()) {
      classScope.problemReporter().signalError(sourceStart, sourceEnd, "can't define constructors on interfaces");
      ignoreFurtherInvestigation = true;
      return null;
    }

    if (onTypeBinding.isNestedType()) {
      classScope.problemReporter().signalError(sourceStart, sourceEnd,
          "can't define constructors on nested types (compiler limitation)");
      ignoreFurtherInvestigation = true;
      return null;
    }

    ResolvedType declaringTypeX = world.fromEclipse(onTypeBinding);
    ResolvedType aspectType = world.fromEclipse(classScope.referenceContext.binding);

    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'
    ResolvedMemberImpl signature = world.makeResolvedMemberForITD(binding, onTypeBinding, interTypeScope.getRecoveryAliases());
    signature.resetKind(Member.CONSTRUCTOR);
    signature.resetName("<init>");
    int resetModifiers = declaredModifiers;
    if (binding.isVarargs())
      resetModifiers = resetModifiers | Constants.ACC_VARARGS;
    signature.resetModifiers(resetModifiers);

    ResolvedMember syntheticInterMember = AjcMemberMaker.interConstructor(declaringTypeX, signature, aspectType);

    NewConstructorTypeMunger myMunger = new NewConstructorTypeMunger(signature, syntheticInterMember, null, null,
        typeVariableAliases);
    setMunger(myMunger);
    myMunger.check(world.getWorld());

    this.selector = binding.selector = NameMangler.postIntroducedConstructor(world.fromBinding(binding.declaringClass),
        declaringTypeX).toCharArray();

    return new EclipseTypeMunger(world, myMunger, aspectType, this);
  }
View Full Code Here

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

  }

  public void generateCode(ClassScope classScope, ClassFile classFile) {
    if (ignoreFurtherInvestigation)
      return;
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
    classFile.extraAttributes.add(new EclipseAttributeAdapter(makeAttribute(world)));
    super.generateCode(classScope, classFile);
    // classFile.codeStream.generateAttributes &= ~ClassFileConstants.ATTR_VARS;
    preMethod.generateCode(classScope, classFile);
  }
View Full Code Here

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

    }
    if (ignoreFurtherInvestigation) {
      return;
    }

    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(upperScope);
    ResolvedMember sig = munger.getSignature();
    UnresolvedType aspectType = world.fromBinding(upperScope.referenceContext.binding);

    if (sig.getReturnType() == ResolvedType.VOID
        || (sig.getReturnType().isArray() && (sig.getReturnType().getComponentType() == ResolvedType.VOID))) {
      upperScope.problemReporter().signalError(sourceStart, sourceEnd, "field type can not be void");
    }

    //
    // System.err.println("sig: " + sig);
    // System.err.println("field: " + world.makeFieldBinding(
    // AjcMemberMaker.interFieldClassField(sig, aspectType)));

    if (initialization != null && initialization instanceof ArrayInitializer) {
      // System.err.println("got initializer: " + initialization);
      ArrayAllocationExpression aae = new ArrayAllocationExpression();
      aae.initializer = (ArrayInitializer) initialization;
      ArrayBinding arrayType = (ArrayBinding) world.makeTypeBinding(sig.getReturnType());
      aae.type = AstUtil.makeTypeReference(arrayType.leafComponentType());
      aae.sourceStart = initialization.sourceStart;
      aae.sourceEnd = initialization.sourceEnd;
      aae.dimensions = new Expression[arrayType.dimensions];
      initialization = aae;
    } /*
     * else if (initialization!=null) { MethodScope initializationScope = this.scope; TypeBinding fieldType = realFieldType;
     * TypeBinding initializationType; this.initialization.setExpectedType(fieldType); // needed in case of generic method
     * invocation if (this.initialization instanceof ArrayInitializer) {
     *
     * if ((initializationType = this.initialization.resolveTypeExpecting(initializationScope, fieldType)) != null) {
     * ((ArrayInitializer) this.initialization).binding = (ArrayBinding) initializationType;
     * this.initialization.computeConversion(initializationScope, fieldType, initializationType); } } //
     * System.err.println("i=>"+initialization); // System.err.println("sasuages=>"+initialization.resolvedType); //
     * //initializationType = initialization.resolveType(initializationScope); //
     * System.err.println("scope=>"+initializationScope);
     *
     * else if ((initializationType = this.initialization.resolveType(initializationScope)) != null) {
     *
     * if (fieldType != initializationType) // must call before computeConversion() and typeMismatchError()
     * initializationScope.compilationUnitScope().recordTypeConversion(fieldType, initializationType); if
     * (this.initialization.isConstantValueOfTypeAssignableToType(initializationType, fieldType) || (fieldType.isBaseType() &&
     * BaseTypeBinding.isWidening(fieldType.id, initializationType.id)) || initializationType.isCompatibleWith(fieldType)) {
     * initialization.computeConversion(initializationScope, fieldType, initializationType); if
     * (initializationType.needsUncheckedConversion(fieldType)) {
     * initializationScope.problemReporter().unsafeTypeConversion(this.initialization, initializationType, fieldType); } } else
     * if (initializationScope.isBoxingCompatibleWith(initializationType, fieldType) || (initializationType.isBaseType() //
     * narrowing then boxing ? && initializationScope.compilerOptions().sourceLevel >= JDK1_5 // autoboxing &&
     * !fieldType.isBaseType() && initialization.isConstantValueOfTypeAssignableToType(initializationType,
     * initializationScope.environment().computeBoxingType(fieldType)))) {
     * this.initialization.computeConversion(initializationScope, fieldType, initializationType); } else {
     * initializationScope.problemReporter().typeMismatchError(initializationType, fieldType, this); } // if
     * (this.binding.isFinal()){ // cast from constant actual type to variable type //
     * this.binding.setConstant(this.initialization.constant.castTo((this.binding.returnType.id << 4) +
     * this.initialization.constant.typeID())); // } // } else { // this.binding.setConstant(NotAConstant); } // }
     */

    // ////////////////////

    if (initialization == null) {
      this.statements = new Statement[] { new ReturnStatement(null, 0, 0), };
    } else if (!onTypeBinding.isInterface()) {
      MethodBinding writeMethod = world.makeMethodBinding(AjcMemberMaker.interFieldSetDispatcher(sig, aspectType), munger
          .getTypeVariableAliases());
      // For the body of an intertype field initalizer, generate a call to the inter field set dispatcher
      // method as that casts the shadow of a field set join point.
      if (Modifier.isStatic(declaredModifiers)) {
        this.statements = new Statement[] { new KnownMessageSend(writeMethod, AstUtil
            .makeNameReference(writeMethod.declaringClass), new Expression[] { initialization }), };
      } else {
        this.statements = new Statement[] { new KnownMessageSend(writeMethod, AstUtil
            .makeNameReference(writeMethod.declaringClass), new Expression[] {
            AstUtil.makeLocalVariableReference(arguments[0].binding), initialization }), };
      }
    } else {
      // XXX something is broken about this logic. Can we write to static interface fields?
      MethodBinding writeMethod = world.makeMethodBinding(AjcMemberMaker.interFieldInterfaceSetter(sig, sig
          .getDeclaringType().resolve(world.getWorld()), aspectType), munger.getTypeVariableAliases());
      if (Modifier.isStatic(declaredModifiers)) {
        this.statements = new Statement[] { new KnownMessageSend(writeMethod, AstUtil
            .makeNameReference(writeMethod.declaringClass), new Expression[] { initialization }), };
      } else {
        this.statements = new Statement[] { new KnownMessageSend(writeMethod, AstUtil
View Full Code Here

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

   * this.initialization.constant.typeID())); // // } // // } else { // // this.binding.setConstant(NotAConstant); // }}
   *
   * }
   */
  public EclipseTypeMunger build(ClassScope classScope) {
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
    resolveOnType(classScope);

    if (ignoreFurtherInvestigation) {
      return null;
    }

    binding = classScope.referenceContext.binding.resolveTypesFor(binding);
    if (ignoreFurtherInvestigation) {
      return null;
    }

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

    if (!Modifier.isStatic(declaredModifiers)) {
      super.binding.parameters = new TypeBinding[] { onTypeBinding, };
      this.arguments = new Argument[] { AstUtil.makeFinalArgument("ajc$this_".toCharArray(), onTypeBinding), };
    }

    // System.err.println("type: " + binding.returnType + ", " + returnType);
    ResolvedType declaringType = world.fromBinding(onTypeBinding).resolve(world.getWorld());
    if (declaringType.isRawType() || declaringType.isParameterizedType()) {
      declaringType = declaringType.getGenericType();
    }

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

    // Build a half correct resolvedmember (makeResolvedMember understands tvars) then build a fully correct sig from it
    ResolvedMember sigtemp = world.makeResolvedMemberForITD(binding, onTypeBinding, interTypeScope.getRecoveryAliases());
    UnresolvedType returnType = sigtemp.getReturnType();
    // if (returnType.isParameterizedType() || returnType.isGenericType()) returnType = returnType.getRawType();
    ResolvedMember sig = new ResolvedMemberImpl(Member.FIELD, declaringType, declaredModifiers, returnType, new String(
        declaredSelector), UnresolvedType.NONE);
    sig.setTypeVariables(sigtemp.getTypeVariables());

    NewFieldTypeMunger myMunger = new NewFieldTypeMunger(sig, null, typeVariableAliases);
    setMunger(myMunger);
    ResolvedType aspectType = world.fromEclipse(classScope.referenceContext.binding);
    ResolvedMember me = myMunger.getInitMethod(aspectType);
    this.selector = binding.selector = me.getName().toCharArray();
    this.realFieldType = this.binding.returnType;
    this.binding.returnType = TypeBinding.VOID;
    // ??? all other pieces should already match
View Full Code Here

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

    // interBinding.reader.generateMethod(this, classScope, classFile);
    // interBinding.writer.generateMethod(this, classScope, classFile);
  }

  private void generateDispatchMethods(ClassScope classScope, ClassFile classFile) {
    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
    ResolvedMember sig = munger.getSignature();
    UnresolvedType aspectType = world.fromBinding(classScope.referenceContext.binding);
    generateDispatchMethod(world, sig, aspectType, classScope, classFile, true);
    generateDispatchMethod(world, sig, aspectType, classScope, classFile, false);
  }
View Full Code Here

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

        ignoreFurtherInvestigation = true;
        return;
      }
    }

    EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);
    ResolvedType myType = typeX;
    // if (myType == null) System.err.println("bad myType for: " + this);
    ResolvedType superType = myType.getSuperclass();

    // can't be Serializable/Cloneable unless -XserializableAspects
    if (!world.isXSerializableAspects()) {
      if (world.getWorld().getCoreType(UnresolvedType.SERIALIZABLE).isAssignableFrom(myType)) {
        scope.problemReporter().signalError(sourceStart, sourceEnd, "aspects may not implement Serializable");
        ignoreFurtherInvestigation = true;
        return;
      }
      if (world.getWorld().getCoreType(UnresolvedType.CLONEABLE).isAssignableFrom(myType)) {
        scope.problemReporter().signalError(sourceStart, sourceEnd, "aspects may not implement Cloneable");
        ignoreFurtherInvestigation = true;
        return;
      }
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.