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

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


    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

        } else {
          /*
           * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
           */
          if (variableBinding instanceof ProblemFieldBinding) {
            ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding;
            switch(problemFieldBinding.problemId()) {
              case ProblemReasons.NotVisible :
              case ProblemReasons.NonStaticReferenceInStaticContext :
              case ProblemReasons.NonStaticReferenceInConstructorInvocation :
                ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
 
View Full Code Here

      } else {
        /*
         * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
         */
        if (variableBinding instanceof ProblemFieldBinding) {
          ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding;
          switch(problemFieldBinding.problemId()) {
            case ProblemReasons.NotVisible :
            case ProblemReasons.NonStaticReferenceInStaticContext :
            case ProblemReasons.NonStaticReferenceInConstructorInvocation :
              ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
              FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
 
View Full Code Here

          Binding binding = qualifiedNameReference.binding;
          if (binding != null) {
            if (binding.isValidBinding()) {
              return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
            } else  if (binding instanceof ProblemFieldBinding) {
              ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
              switch(problemFieldBinding.problemId()) {
                case ProblemReasons.NotVisible :
                case ProblemReasons.NonStaticReferenceInStaticContext :
                  ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                  if (declaringClass != null) {
                    FieldBinding exactBinding = declaringClass.getField(tokens[tokens.length - 1], true /*resolve*/);
                    if (exactBinding != null) {
                      if (exactBinding.type != null) {
                        IVariableBinding variableBinding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                        if (variableBinding != null) {
                          return variableBinding;
                        }
                        variableBinding = new VariableBinding(this, exactBinding);
                        this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding);
                        return variableBinding;
                      }
                    }
                  }
                  break;
              }
            }
          }
        }
      } else {
        /* This is the case for a name which is part of a qualified name that
         * cannot be resolved. See PR 13063.
         */
        if (qualifiedNameReference.otherBindings == null || (index - indexOfFirstFieldBinding - 1) < 0) {
          return null;
        } else {
          return this.getVariableBinding(qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]);
        }
      }
    } else if (node instanceof QualifiedTypeReference) {
      QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node;
      if (qualifiedTypeReference.resolvedType == null) {
        return null;
      }
      if (index == qualifiedTypeReference.tokens.length) {
        if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) {
          JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node;
          if (typeRef.packageBinding != null) {
            return getPackageBinding(typeRef.packageBinding);
          }
        }
        return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType());
      } else {
        if (index >= 0) {
          BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
          Binding binding = null;
          try {
            if (internalScope == null) {
              if (this.scope == null) return null;
              binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
            } else {
              binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
            }
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
          if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
            return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
            // it is a type
            return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
          } else {
            return null;
          }
        }
      }
    } else if (node instanceof ImportReference) {
      ImportReference importReference = (ImportReference) node;
      int importReferenceLength = importReference.tokens.length;
      if (index >= 0) {
        Binding binding = null;
        if (this.scope == null) return null;
        if (importReferenceLength == index) {
          try {
            binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic());
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
        } else {
          try {
            binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
        }
        if (binding != null) {
          if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
            return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
            // it is a type
            return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
            // it is a type
            return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
            // it is a type
            return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding);
          } else {
            return null;
          }
        }
      }
    } else if (node instanceof CompilationUnitDeclaration) {
      CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node;
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
      if (types == null || types.length == 0) {
        return null;
      }
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0];
      if (type != null) {
        ITypeBinding typeBinding = this.getTypeBinding(type.binding);
        if (typeBinding != null) {
          return typeBinding.getPackage();
        }
      }
    } else if (node instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
      IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding);
      if (methodBinding != null) {
        return methodBinding;
      }
    } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
      ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
      if (typeBinding != null) {
        return typeBinding;
      }
    } if (node instanceof SingleNameReference) {
      SingleNameReference singleNameReference = (SingleNameReference) node;
      if (singleNameReference.isTypeReference()) {
        return this.getTypeBinding(singleNameReference.resolvedType);
      } else {
        // this is a variable or a field
        Binding binding = singleNameReference.binding;
        if (binding != null) {
          if (binding.isValidBinding()) {
            return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
          } else {
            /*
             * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
             */
            if (binding instanceof ProblemFieldBinding) {
              ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
              switch(problemFieldBinding.problemId()) {
                case ProblemReasons.NotVisible :
                case ProblemReasons.NonStaticReferenceInStaticContext :
                case ProblemReasons.NonStaticReferenceInConstructorInvocation :
                  ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                  FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
 
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)) {
            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

        } else {
          /*
           * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
           */
          if (variableBinding instanceof ProblemFieldBinding) {
            ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding;
            switch(problemFieldBinding.problemId()) {
              case ProblemReasons.NotVisible :
              case ProblemReasons.NonStaticReferenceInStaticContext :
              case ProblemReasons.NonStaticReferenceInConstructorInvocation :
                ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
 
View Full Code Here

      } else {
        /*
         * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
         */
        if (variableBinding instanceof ProblemFieldBinding) {
          ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding;
          switch(problemFieldBinding.problemId()) {
            case ProblemReasons.NotVisible :
            case ProblemReasons.NonStaticReferenceInStaticContext :
            case ProblemReasons.NonStaticReferenceInConstructorInvocation :
              ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
              FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
 
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.