Package org.aspectj.org.eclipse.jdt.internal.compiler.lookup

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding


      // much nicer, its a real SourceTypeBinding so we can stay in
      // eclipse land
      // if (decA.getAnnotationMethod() != null) {
      char[] declareSelector = decA.getAnnotationMethod().toCharArray();

      ReferenceBinding rb = stb;
      String declaringAspectName = decA.getDeclaringType().getRawName();
      while (rb != null && !new String(CharOperation.concatWith(rb.compoundName, '.')).equals(declaringAspectName)) {
        rb = rb.superclass();
      }
      MethodBinding[] mbs = rb.getMethods(declareSelector);

      ReferenceBinding declaringBinding = mbs[0].declaringClass;
      if (declaringBinding instanceof ParameterizedTypeBinding) {
        // Unwrap - this means we don't allow the type of the annotation to be parameterized, may need to revisit that
        declaringBinding = ((ParameterizedTypeBinding) declaringBinding).type;
      }
      if (declaringBinding instanceof BinaryTypeBinding) {
View Full Code Here


    }
    return path.substring(takefrom + 1);
  }

  private void addParent(SourceTypeBinding sourceType, ResolvedType parent) {
    ReferenceBinding parentBinding = (ReferenceBinding) factory.makeTypeBinding(parent);
    if (parentBinding == null) {
      return; // The parent is missing, it will be reported elsewhere.
    }
    sourceType.rememberTypeHierarchy();
    if (parentBinding.isClass()) {
      sourceType.superclass = parentBinding;

      // this used to be true, but I think I've fixed it now, decp is done
      // at weave time!
      // TAG: WeavingMessage DECLARE PARENTS: EXTENDS
View Full Code Here

      }
      if (needValue) {
        if (lastFieldBinding.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) {
          if (!lastFieldBinding.isStatic()) {
            if ((this.bits & DepthMASK) != 0) {
              ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & DepthMASK) >> DepthSHIFT);
              Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
              codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
            } else {
              generateReceiver(codeStream);
            }
View Full Code Here

    if (this.enclosingInstance != null) {
      flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
    }
   
    // check captured variables are initialized in current context (26134)
    ReferenceBinding allocatedType = this.superTypeBinding == null ? this.binding.declaringClass : this.superTypeBinding;
    checkCapturedLocalInitializationIfNecessary(
      (ReferenceBinding) allocatedType.erasure(),
      currentScope,
      flowInfo);
   
    // process arguments
    if (this.arguments != null) {
View Full Code Here

    BlockScope currentScope,
    CodeStream codeStream,
    boolean valueRequired) {

    int pc = codeStream.position;
    ReferenceBinding allocatedType = this.codegenBinding.declaringClass;
    codeStream.new_(allocatedType);
    boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
    if (valueRequired || isUnboxing) {
      codeStream.dup();
    }
    // better highlight for allocation: display the type individually
    if (this.type != null) { // null for enum constant body
      codeStream.recordPositionsFrom(pc, this.type.sourceStart);
    } else {
      // push enum constant name and ordinal
      codeStream.ldc(String.valueOf(this.enumConstant.name));
      codeStream.generateInlinedValue(this.enumConstant.binding.id);
    }
    // handling innerclass instance allocation - enclosing instance arguments
    if (allocatedType.isNestedType()) {
      codeStream.generateSyntheticEnclosingInstanceValues(
        currentScope,
        allocatedType,
        enclosingInstance(),
        this);
    }
    // generate the arguments for constructor
    generateArguments(this.binding, this.arguments, currentScope, codeStream);
    // handling innerclass instance allocation - outer local arguments
    if (allocatedType.isNestedType()) {
      codeStream.generateSyntheticOuterArgumentValues(
        currentScope,
        allocatedType,
        this);
    }
View Full Code Here

   * exact need.
   */
  public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {

    if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)  {
    ReferenceBinding allocatedTypeErasure = (ReferenceBinding) this.binding.declaringClass.erasure();

    // perform some extra emulation work in case there is some and we are inside a local type only
    if (allocatedTypeErasure.isNestedType()
      && currentScope.enclosingSourceType().isLocalType()) {

      if (allocatedTypeErasure.isLocalType()) {
        ((LocalTypeBinding) allocatedTypeErasure).addInnerEmulationDependent(currentScope, this.enclosingInstance != null);
      } else {
        // locally propagate, since we already now the desired shape for sure
        currentScope.propagateInnerEmulation(allocatedTypeErasure, this.enclosingInstance != null);
      }
View Full Code Here

      } else {
        receiverType = this.type.resolveType(scope, true /* check bounds*/);
        checkParameterizedAllocation: {
          if (receiverType == null) break checkParameterizedAllocation;
          if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
            ReferenceBinding currentType = (ReferenceBinding)receiverType;
            do {
              // isStatic() is answering true for toplevel types
              if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
              if (currentType.isRawType()) break checkParameterizedAllocation;
            } while ((currentType = currentType.enclosingType())!= null);
            ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
            for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
              if (qRef.typeArguments[i] != null) {
                scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
                break;
              }
            }
          }
        }       
      }     
    }
    if (receiverType == null) {
      hasError = true;
    } else if (((ReferenceBinding) receiverType).isFinal()) {
      if (this.anonymousType != null) {
        if (!receiverType.isEnum()) {
          scope.problemReporter().anonymousClassCannotExtendFinalClass(this.type, receiverType);
          hasError = true;
        }
      } else if (!receiverType.canBeInstantiated()) {
        scope.problemReporter().cannotInstantiate(this.type, receiverType);
        return this.resolvedType = receiverType;
      }
    }
    // resolve type arguments (for generic constructor call)
    if (this.typeArguments != null) {
      int length = this.typeArguments.length;
      this.genericTypeArguments = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        TypeReference typeReference = this.typeArguments[i];       
        TypeBinding argType = typeReference.resolveType(scope, true /* check bounds*/);
        if (argType == null) {
          if (typeReference instanceof Wildcard) {
            scope.problemReporter().illegalUsageOfWildcard(typeReference);
          }
          return null; // error already reported
        }
        this.genericTypeArguments[i] = argType;
      }
    }
   
    // will check for null after args are resolved
    TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
    if (this.arguments != null) {
      int length = this.arguments.length;
      argumentTypes = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        Expression argument = this.arguments[i];
        if (argument instanceof CastExpression) {
          argument.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
          argsContainCast = true;
        }
        if ((argumentTypes[i] = argument.resolveType(scope)) == null){
          hasError = true;
        }
      }
    }
    // limit of fault-tolerance
    if (hasError) {
      if (receiverType instanceof ReferenceBinding) {
        // record a best guess, for clients who need hint about possible contructor match
        int length = this.arguments  == null ? 0 : this.arguments.length;
        TypeBinding[] pseudoArgs = new TypeBinding[length];
        for (int i = length; --i >= 0;) {
          pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
        }
        this.binding = scope.findMethod((ReferenceBinding) receiverType, TypeConstants.INIT, pseudoArgs, this);
        if (this.binding != null && !this.binding.isValidBinding()) {
          MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
          // record the closest match, for clients who may still need hint about possible method match
          if (closestMatch != null) {
            if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
              // shouldn't return generic method outside its context, rather convert it to raw method (175409)
              closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding)null);
            }
            this.binding = closestMatch;
            MethodBinding closestMatchOriginal = closestMatch.original();
            if ((closestMatchOriginal.isPrivate() || closestMatchOriginal.declaringClass.isLocalType()) && !scope.isDefinedInMethod(closestMatchOriginal)) {
              // ignore cases where method is used from within inside itself (e.g. direct recursions)
              closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
            }
          }
        }
       
      }
      return this.resolvedType = receiverType;
    }
    if (this.anonymousType == null) {
      // qualified allocation with no anonymous type
      if (!receiverType.canBeInstantiated()) {
        scope.problemReporter().cannotInstantiate(this.type, receiverType);
        return this.resolvedType = receiverType;
      }
      ReferenceBinding allocationType = (ReferenceBinding) receiverType;
      if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
        if (isMethodUseDeprecated(this.binding, scope, true)) {
          scope.problemReporter().deprecatedMethod(this.binding, this);
        }
        checkInvocationArguments(scope, null, allocationType, this.binding, this.arguments, argumentTypes, argsContainCast, this);
      } else {
        if (this.binding.declaringClass == null) {
          this.binding.declaringClass = allocationType;
        }
        scope.problemReporter().invalidConstructor(this, this.binding);
        return this.resolvedType = receiverType;
      }

      // The enclosing instance must be compatible with the innermost enclosing type
      ReferenceBinding expectedType = this.binding.declaringClass.enclosingType();
      if (expectedType != enclosingInstanceType) // must call before computeConversion() and typeMismatchError()
        scope.compilationUnitScope().recordTypeConversion(expectedType, enclosingInstanceType);
      if (enclosingInstanceType.isCompatibleWith(expectedType) || scope.isBoxingCompatibleWith(enclosingInstanceType, expectedType)) {
        this.enclosingInstance.computeConversion(scope, expectedType, enclosingInstanceType);
        return this.resolvedType = receiverType;
      }
      scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance);
      return this.resolvedType = receiverType;
    }

    if (receiverType.isTypeVariable()) {
      receiverType = new ProblemReferenceBinding(receiverType.sourceName(), (ReferenceBinding)receiverType, ProblemReasons.IllegalSuperTypeVariable);
      scope.problemReporter().invalidType(this, receiverType);
      return null;
    } else if (this.type != null && receiverType.isEnum()) { // tolerate enum constant body
      scope.problemReporter().cannotInstantiate(this.type, receiverType);
      return this.resolvedType = receiverType;
    }
    // anonymous type scenario
    // an anonymous class inherits from java.lang.Object when declared "after" an interface
    this.superTypeBinding = receiverType.isInterface() ? scope.getJavaLangObject() : (ReferenceBinding) receiverType;
    // insert anonymous type in scope
    scope.addAnonymousType(this.anonymousType, (ReferenceBinding) receiverType);
    this.anonymousType.resolve(scope);   
    if (this.superTypeBinding.erasure().id == TypeIds.T_JavaLangEnum) {
      scope.problemReporter().cannotExtendEnum(this.anonymousType.binding, this.type, this.superTypeBinding);
    }
   
    if ((receiverType.tagBits & TagBits.HasDirectWildcard) != 0) {
      scope.problemReporter().superTypeCannotUseWildcard(this.anonymousType.binding, this.type, receiverType);
    }   
    // find anonymous super constructor
    MethodBinding inheritedBinding = scope.getConstructor(this.superTypeBinding, argumentTypes, this);
    if (!inheritedBinding.isValidBinding()) {
      if (inheritedBinding.declaringClass == null) {
        inheritedBinding.declaringClass = this.superTypeBinding;
      }
      scope.problemReporter().invalidConstructor(this, inheritedBinding);
      return this.resolvedType = this.anonymousType.binding;
    }
    if (this.enclosingInstance != null) {
      ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
      if (targetEnclosing == null) {
        scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.enclosingInstance, (ReferenceBinding)receiverType);
        return this.resolvedType = this.anonymousType.binding;
      } else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
        scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, this.enclosingInstance);
View Full Code Here

      }
      return lookupEnvironment.createArrayType(makeTypeBinding(typeX), dim);
    } else if (typeX.isParameterizedType()) {
      // Converting back to a binding from a UnresolvedType
      UnresolvedType[] typeParameters = typeX.getTypeParameters();
      ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName());
      TypeBinding[] argumentBindings = new TypeBinding[typeParameters.length];
      baseTypeForParameterizedType = baseTypeBinding;
      for (int i = 0; i < argumentBindings.length; i++) {
        indexOfTypeParameterBeingConverted = i;
        argumentBindings[i] = makeTypeBinding(typeParameters[i]);
      }
      indexOfTypeParameterBeingConverted = 0;
      baseTypeForParameterizedType = null;
      ParameterizedTypeBinding ptb = lookupEnvironment.createParameterizedType(baseTypeBinding, argumentBindings,
          baseTypeBinding.enclosingType());
      return ptb;
    } else if (typeX.isTypeVariableReference()) {
      // return makeTypeVariableBinding((TypeVariableReference)typeX);
      return makeTypeVariableBindingFromAJTypeVariable(((TypeVariableReference) typeX).getTypeVariable());
    } else if (typeX.isRawType()) {
      ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName());
      RawTypeBinding rtb = lookupEnvironment.createRawType(baseTypeBinding, baseTypeBinding.enclosingType());
      return rtb;
    } else if (typeX.isGenericWildcard()) {
      if (typeX instanceof WildcardedUnresolvedType) {
        WildcardedUnresolvedType wut = (WildcardedUnresolvedType) typeX;
        int boundkind = Wildcard.UNBOUND;
View Full Code Here

    }
  }

  private ReferenceBinding lookupBinding(String sname) {
    char[][] name = CharOperation.splitOn('.', sname.toCharArray());
    ReferenceBinding rb = lookupEnvironment.getType(name);
    if (rb == null && !sname.equals(UnresolvedType.MISSING_NAME)) {
      return new ProblemReferenceBinding(name, null, ProblemReasons.NotFound);
    }
    return rb;
  }
View Full Code Here

   * appropriate in the returned fieldbinding.
   */
  public FieldBinding internalMakeFieldBinding(ResolvedMember member, List aliases) {
    typeVariableToTypeBinding.clear();

    ReferenceBinding declaringType = (ReferenceBinding) makeTypeBinding(member.getDeclaringType());

    // If there are aliases, place them in the map
    if (aliases != null && aliases.size() > 0 && declaringType.typeVariables() != null
        && declaringType.typeVariables().length != 0) {
      int i = 0;
      for (Iterator iter = aliases.iterator(); iter.hasNext();) {
        String element = (String) iter.next();
        typeVariableToTypeBinding.put(element, declaringType.typeVariables()[i++]);
      }
    }

    currentType = declaringType;

View Full Code Here

TOP

Related Classes of org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding

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.