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

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


  If no visible field is discovered, an error binding is answered.
*/

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


  if (this instanceof NameReference) {
    final Binding receiverBinding = ((NameReference) this).binding;
    if (receiverBinding.isParameter() && (((LocalVariableBinding) receiverBinding).tagBits & TagBits.ForcedToBeRawType) != 0) {
      return true// parameter is forced to be raw since super method uses raw types.
    } else if (receiverBinding instanceof FieldBinding) {
      FieldBinding field = (FieldBinding) receiverBinding;
      if (field.type.isRawType()) {
        if (referenceContext instanceof AbstractMethodDeclaration) {
          AbstractMethodDeclaration methodDecl = (AbstractMethodDeclaration) referenceContext;
          if (field.declaringClass != methodDecl.binding.declaringClass) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
            return true;
          }
        } else if (referenceContext instanceof TypeDeclaration) {
          TypeDeclaration type = (TypeDeclaration) referenceContext;
          if (field.declaringClass != type.binding) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
            return true;
          }
        }
      }
    }
  } else if (this instanceof MessageSend) {
    if (!CharOperation.equals(((MessageSend) this).binding.declaringClass.getFileName(),
        referenceContext.compilationResult().getFileName())) {  // problem is rooted elsewhere
      return true;
    }
  } else if (this instanceof FieldReference) {
    FieldBinding field = ((FieldReference) this).binding;
    if (!CharOperation.equals(field.declaringClass.getFileName(),
        referenceContext.compilationResult().getFileName())) { // problem is rooted elsewhere
      return true;
    }
    if (field.type.isRawType()) {
View Full Code Here

            switch(problemFieldBinding.problemId()) {
              case ProblemReasons.NotVisible :
              case ProblemReasons.NonStaticReferenceInStaticContext :
              case ProblemReasons.NonStaticReferenceInConstructorInvocation :
                ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
                if (exactBinding != null) {
                  IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                  if (variableBinding2 != null) {
                    return variableBinding2;
                  }
View Full Code Here

          switch(problemFieldBinding.problemId()) {
            case ProblemReasons.NotVisible :
            case ProblemReasons.NonStaticReferenceInStaticContext :
            case ProblemReasons.NonStaticReferenceInConstructorInvocation :
              ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
              FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
              if (exactBinding != null) {
                IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                if (variableBinding2 != null) {
                  return variableBinding2;
                }
View Full Code Here

        } else {
          // in this case we want to get the next field declaring's class
          if (qualifiedNameReference.otherBindings == null) {
            return null;
          }
          FieldBinding fieldBinding = qualifiedNameReference.otherBindings[0];
          if (fieldBinding == null) return null;
          org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass;
          if (type == null) { // array length scenario
            // use type from first binding (no capture needed for array type)
            switch (qualifiedNameReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.RestrictiveFlagMASK) {
              case Binding.FIELD:
                type = ((FieldBinding) qualifiedNameReference.binding).type;
                break;
              case Binding.LOCAL:
                type = ((LocalVariableBinding) qualifiedNameReference.binding).type;
                break;
            }
          }
          return this.getTypeBinding(type);
        }
      } 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) return null;
        final int otherBindingsLength = qualifiedNameReference.otherBindings.length;
        if (otherBindingsLength == (index - indexOfFirstFieldBinding)) {
          return this.getTypeBinding(qualifiedNameReference.resolvedType);
        }
        FieldBinding fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding];
        if (fieldBinding == null) return null;
        org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass;
        if (type == null) { // array length scenario
          // use type from previous binding (no capture needed for array type)
          fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1];
View Full Code Here

                  if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) {
                    this.visibleFields.remove(fieldDeclaration.binding);
                  }
                  int count = 0;
                  while (count < this.visibleFields.size) {
                    FieldBinding visibleField = (FieldBinding)this.visibleFields.elementAt(count);
                    if (visibleField.id > fieldDeclaration.binding.id) {
                      this.visibleFields.remove(visibleField);
                      continue;
                    }
                    count++;
View Full Code Here

              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*/);
                  if (exactBinding != null) {
                    if (exactBinding.type != null) {
                      IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                      if (variableBinding2 != null) {
                        return variableBinding2;
View Full Code Here

    }
    size = this.visibleFields.size();
    if (size > 0) {
      next : for (int i = 0; i < size; i++) {
        try {
          FieldBinding binding = (FieldBinding) this.visibleFields.elementAt(i);
          if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
          if (this.assistScope.isDefinedInSameUnit(binding.declaringClass)) {
            JavaElement field = getJavaElementOfCompilationUnit(binding);
            if (field != null) result[elementCount++] = field;
          } else {
View Full Code Here

    ObjectVector newFieldsFound = new ObjectVector();
    // Inherited fields which are hidden by subclasses are filtered out
    // No visibility checks can be performed without the scope & invocationSite

    next : for (int f = fields.length; --f >= 0;) {
      FieldBinding field = fields[f];

      if (field.isSynthetic()) continue next;

      if (onlyStaticFields && !field.isStatic()) continue next;

      if (!field.canBeSeenBy(receiverType, invocationSite, scope)) continue next;

      for (int i = fieldsFound.size; --i >= 0;) {
        FieldBinding otherField = (FieldBinding) fieldsFound.elementAt(i);
        if (CharOperation.equals(field.name, otherField.name, true)) {
          continue next;
        }
      }
View Full Code Here

      if (defaultValueBinding.isEnum()) {
        if (this.contentsOffset + 5 >= this.contents.length) {
          resizeContents(5);
        }
        this.contents[this.contentsOffset++] = (byte) 'e';
        FieldBinding fieldBinding = null;
        if (defaultValue instanceof QualifiedNameReference) {
          QualifiedNameReference nameReference = (QualifiedNameReference) defaultValue;
          fieldBinding = (FieldBinding) nameReference.binding;
        } else if (defaultValue instanceof SingleNameReference) {
          SingleNameReference nameReference = (SingleNameReference) defaultValue;
View Full Code Here

TOP

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

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.