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

Examples of org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding


                 declaringClass.superclass() instanceof MissingTypeBinding;
    if (!avoidSecondary) {
      scope.problemReporter().invalidField(this, this.actualReceiverType);
    }
    if (fieldBinding instanceof ProblemFieldBinding) {
      ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) fieldBinding;
      FieldBinding closestMatch = problemFieldBinding.closestMatch;
      switch(problemFieldBinding.problemId()) {
        case ProblemReasons.InheritedNameHidesEnclosingName :
        case ProblemReasons.NotVisible :
        case ProblemReasons.NonStaticReferenceInConstructorInvocation :
        case ProblemReasons.NonStaticReferenceInStaticContext :
          if (closestMatch != null) {
View Full Code Here


            return null;
          }
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
        if (this.binding instanceof FieldBinding) {
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.FIELD;
          FieldBinding fieldBinding = (FieldBinding) this.binding;
          MethodScope methodScope = scope.methodScope();
          ReferenceBinding declaringClass = fieldBinding.original().declaringClass;
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          // check for forward references
          if ((this.indexOfFirstFieldBinding == 1 || (fieldBinding.modifiers & ClassFileConstants.AccEnum) != 0 || (!fieldBinding.isFinal() && declaringClass.isEnum())) // enum constants are checked even when qualified
              && TypeBinding.equalsEquals(sourceType, declaringClass)
              && methodScope.lastVisibleFieldID >= 0
              && fieldBinding.id >= methodScope.lastVisibleFieldID
              && (!fieldBinding.isStatic() || methodScope.isStatic)) {
            if (methodScope.insideTypeAnnotation && fieldBinding.id == methodScope.lastVisibleFieldID) {
              // false alarm, location is NOT a field initializer but the value in a memberValuePair
            } else {
              scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
            }
          }
          if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) {
            scope.problemReporter().deprecatedField(fieldBinding, this)
          }
          if (fieldBinding.isStatic()) {
            // only last field is actually a write access if any
            // check if accessing enum static field in initializer
            if (declaringClass.isEnum()) {
              if ((TypeBinding.equalsEquals(sourceType, declaringClass) || TypeBinding.equalsEquals(sourceType.superclass, declaringClass)) // enum constant body
                  && fieldBinding.constant() == Constant.NotAConstant
                  && !methodScope.isStatic
                  && methodScope.isInsideInitializerOrConstructor()) {
                scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
              }
            }
            if (this.indexOfFirstFieldBinding > 1
                && TypeBinding.notEquals(fieldBinding.declaringClass, this.actualReceiverType)
                && fieldBinding.declaringClass.canBeSeenBy(scope)) {
              scope.problemReporter().indirectAccessToStaticField(this, fieldBinding);
            }           
          } else {
            boolean inStaticContext = scope.methodScope().isStatic;
            if (this.indexOfFirstFieldBinding == 1) {
              if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) {
                scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
              }
              if (!inStaticContext) {
                scope.tagAsAccessingEnclosingInstanceStateOf(fieldBinding.declaringClass, false /* type variable access */);
              }
            }
            //must check for the static status....
            if (this.indexOfFirstFieldBinding > //accessing to a field using a type as "receiver" is allowed only with static field
                 || inStaticContext) {   // the field is the first token of the qualified reference....
              scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
              return null;
             }
          }
         
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null
              && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.indexOfFirstFieldBinding == this.tokens.length ? (FieldBinding)this.binding : this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
        // thus it was a type
View Full Code Here

    return null;
  if (receiverType.isArrayType()) {
    TypeBinding leafType = receiverType.leafComponentType();
    if (leafType instanceof ReferenceBinding)
    if (!((ReferenceBinding)leafType).canBeSeenBy(this)) {
      return new ProblemFieldBinding((ReferenceBinding)leafType, fieldName, ProblemReasons.ReceiverTypeNotVisible);
    }
    if (CharOperation.equals(fieldName, TypeConstants.LENGTH))
      return ArrayBinding.ArrayLength;
    return null;
  }

  ReferenceBinding currentType = (ReferenceBinding) receiverType;
  if (!currentType.canBeSeenBy(this))
    return new ProblemFieldBinding(currentType, fieldName, ProblemReasons.ReceiverTypeNotVisible);

  FieldBinding field = currentType.getField(fieldName, true /*resolve*/);
  if (field != null) {
    if (canBeSeenByForCodeSnippet(field, currentType, invocationSite, this))
      return field;
    else
      return new ProblemFieldBinding(field /* closest match*/, field.declaringClass, fieldName, ProblemReasons.NotVisible);
  }

  // collect all superinterfaces of receiverType until the field is found in a supertype
  ReferenceBinding[][] interfacesToVisit = null;
  int lastPosition = -1;
  FieldBinding visibleField = null;
  boolean keepLooking = true;
  boolean notVisible = false; // we could hold onto the not visible field for extra error reporting
  while (keepLooking) {
    ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
    if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
      if (interfacesToVisit == null)
        interfacesToVisit = new ReferenceBinding[5][];
      if (++lastPosition == interfacesToVisit.length)
        System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[lastPosition * 2][], 0, lastPosition);
      interfacesToVisit[lastPosition] = itsInterfaces;
    }
    if ((currentType = currentType.superclass()) == null)
      break;

    if ((field = currentType.getField(fieldName, true /*resolve*/)) != null) {
      keepLooking = false;
      if (canBeSeenByForCodeSnippet(field, receiverType, invocationSite, this)) {
        if (visibleField == null)
          visibleField = field;
        else
          return new ProblemFieldBinding(visibleField, visibleField.declaringClass, fieldName, ProblemReasons.Ambiguous);
      } else {
        notVisible = true;
      }
    }
  }

  // walk all visible interfaces to find ambiguous references
  if (interfacesToVisit != null) {
    ProblemFieldBinding ambiguous = null;
    org.eclipse.jdt.internal.compiler.util.SimpleSet interfacesSeen = new org.eclipse.jdt.internal.compiler.util.SimpleSet(lastPosition * 2);
    done : for (int i = 0; i <= lastPosition; i++) {
      ReferenceBinding[] interfaces = interfacesToVisit[i];
      for (int j = 0, length = interfaces.length; j < length; j++) {
        ReferenceBinding anInterface = interfaces[j];
        if (interfacesSeen.addIfNotIncluded(anInterface) == anInterface) {
          // if interface as not already been visited
          if ((field = anInterface.getField(fieldName, true /*resolve*/)) != null) {
            if (visibleField == null) {
              visibleField = field;
            } else {
              ambiguous = new ProblemFieldBinding(visibleField, visibleField.declaringClass, fieldName, ProblemReasons.Ambiguous);
              break done;
            }
          } else {
            ReferenceBinding[] itsInterfaces = anInterface.superInterfaces();
            if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
              if (++lastPosition == interfacesToVisit.length)
                System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[lastPosition * 2][], 0, lastPosition);
              interfacesToVisit[lastPosition] = itsInterfaces;
            }
          }
        }
      }
    }
    if (ambiguous != null) return ambiguous;
  }

  if (visibleField != null)
    return visibleField;
  if (notVisible)
    return new ProblemFieldBinding(currentType, fieldName, ProblemReasons.NotVisible);
  return null;
}
View Full Code Here

    ReferenceBinding typeBinding = (ReferenceBinding) binding;
    char[] nextName = compoundName[currentIndex++];
    invocationSite.setFieldIndex(currentIndex);
    if ((binding = findFieldForCodeSnippet(typeBinding, nextName, invocationSite)) != null) {
      if (!binding.isValidBinding()) {
        return new ProblemFieldBinding(
            (FieldBinding)binding,
            ((FieldBinding)binding).declaringClass,
            CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
            binding.problemId());
      }
      break; // binding is now a field
    }
    if ((binding = findMemberType(nextName, typeBinding)) == null)
      return new ProblemBinding(CharOperation.subarray(compoundName, 0, currentIndex), typeBinding, ProblemReasons.NotFound);
     if (!binding.isValidBinding())
      return new ProblemReferenceBinding(
                CharOperation.subarray(compoundName, 0, currentIndex),
                (ReferenceBinding)((ReferenceBinding)binding).closestMatch(),
                binding.problemId());
  }

  if ((mask & Binding.FIELD) != 0 && (binding instanceof FieldBinding)) { // was looking for a field and found a field
    FieldBinding field = (FieldBinding) binding;
    if (!field.isStatic()) {
      return new ProblemFieldBinding(
          field,
          field.declaringClass,
          CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
          ProblemReasons.NonStaticReferenceInStaticContext);
    }
View Full Code Here

*/

public FieldBinding getFieldForCodeSnippet(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite) {
  FieldBinding field = findFieldForCodeSnippet(receiverType, fieldName, invocationSite);
  if (field == null)
    return new ProblemFieldBinding(receiverType instanceof ReferenceBinding ? (ReferenceBinding) receiverType : null, fieldName, ProblemReasons.NotFound);
  else
    return field;
}
View Full Code Here

            return null;
          }
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
        if (this.binding instanceof FieldBinding) {
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.FIELD;
          FieldBinding fieldBinding = (FieldBinding) this.binding;
          MethodScope methodScope = scope.methodScope();
          ReferenceBinding declaringClass = fieldBinding.original().declaringClass;
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          // check for forward references
          if ((this.indexOfFirstFieldBinding == 1 || (fieldBinding.modifiers & ClassFileConstants.AccEnum) != 0 || (!fieldBinding.isFinal() && declaringClass.isEnum())) // enum constants are checked even when qualified
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && fieldBinding.id >= methodScope.lastVisibleFieldID
              && (!fieldBinding.isStatic() || methodScope.isStatic)) {
            if (methodScope.insideTypeAnnotation && fieldBinding.id == methodScope.lastVisibleFieldID) {
              // false alarm, location is NOT a field initializer but the value in a memberValuePair
            } else {
              scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
            }
          }
          if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) {
            scope.problemReporter().deprecatedField(fieldBinding, this)
          }
          if (fieldBinding.isStatic()) {
            // only last field is actually a write access if any
            // check if accessing enum static field in initializer
            if (declaringClass.isEnum()) {
              if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
                  && fieldBinding.constant() == Constant.NotAConstant
                  && !methodScope.isStatic
                  && methodScope.isInsideInitializerOrConstructor()) {
                scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
              }
            }
            if (this.indexOfFirstFieldBinding > 1
                && fieldBinding.declaringClass != this.actualReceiverType
                && fieldBinding.declaringClass.canBeSeenBy(scope)) {
              scope.problemReporter().indirectAccessToStaticField(this, fieldBinding);
            }           
          } else {
            if (this.indexOfFirstFieldBinding == 1 && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) {
              scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
            }
            //must check for the static status....
            if (this.indexOfFirstFieldBinding > //accessing to a field using a type as "receiver" is allowed only with static field
                 || scope.methodScope().isStatic) {   // the field is the first token of the qualified reference....
              scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
              return null;
             }
          }
         
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null
              && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.indexOfFirstFieldBinding == this.tokens.length ? (FieldBinding)this.binding : this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
        // thus it was a type
View Full Code Here

                 declaringClass.superclass() instanceof MissingTypeBinding;
    if (!avoidSecondary) {
      scope.problemReporter().invalidField(this, this.actualReceiverType);
    }
    if (fieldBinding instanceof ProblemFieldBinding) {
      ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) fieldBinding;
      FieldBinding closestMatch = problemFieldBinding.closestMatch;
      switch(problemFieldBinding.problemId()) {
        case ProblemReasons.InheritedNameHidesEnclosingName :
        case ProblemReasons.NotVisible :
        case ProblemReasons.NonStaticReferenceInConstructorInvocation :
        case ProblemReasons.NonStaticReferenceInStaticContext :
          if (closestMatch != null) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding

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.