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

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


      return call;
    }

    JExpression processExpression(QualifiedNameReference x) {
      SourceInfo info = makeSourceInfo(x);
      Binding binding = x.binding;
      JNode node = typeMap.get(binding);
      if (!(node instanceof JVariable)) {
        return null;
      }
      JVariable variable = (JVariable) node;
View Full Code Here


      return processQualifiedThisOrSuperRef(x, qualType);
    }

    JExpression processExpression(SingleNameReference x) {
      SourceInfo info = makeSourceInfo(x);
      Binding binding = x.binding;
      Object target = typeMap.get(binding);
      if (!(target instanceof JVariable)) {
        return null;
      }
      JVariable variable = (JVariable) target;
View Full Code Here

      return call;
    }

    JExpression processExpression(QualifiedNameReference x) {
      SourceInfo info = makeSourceInfo(x);
      Binding binding = x.binding;
      JNode node = typeMap.get(binding);
      if (!(node instanceof JVariable)) {
        return null;
      }
      JVariable variable = (JVariable) node;
View Full Code Here

      return processQualifiedThisOrSuperRef(x, qualType);
    }

    JExpression processExpression(SingleNameReference x) {
      SourceInfo info = makeSourceInfo(x);
      Binding binding = x.binding;
      Object target = typeMap.get(binding);
      if (!(target instanceof JVariable)) {
        return null;
      }
      JVariable variable = (JVariable) target;
View Full Code Here

  IMPORTANT NOTE: This method is written under the assumption that compoundName is longer than length 1.
*/

public Binding getBinding(char[][] compoundName, int mask, InvocationSite invocationSite, ReferenceBinding receiverType) {
  Binding binding = getBinding(compoundName[0], mask | Binding.TYPE | Binding.PACKAGE, invocationSite, true /*resolve*/);
  invocationSite.setFieldIndex(1);
  if (!binding.isValidBinding() || binding instanceof VariableBinding)
    return binding;

  int length = compoundName.length;
  int currentIndex = 1;
  foundType: if (binding instanceof PackageBinding) {
    PackageBinding packageBinding = (PackageBinding) binding;

    while (currentIndex < length) {
      binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]);
      invocationSite.setFieldIndex(currentIndex);
       if (binding == null) {
         if (currentIndex == length) // must be a type if its the last name, otherwise we have no idea if its a package or type
          return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null, ProblemReasons.NotFound);
        else
          return new ProblemBinding(CharOperation.subarray(compoundName, 0, currentIndex), ProblemReasons.NotFound);
       }
       if (binding instanceof ReferenceBinding) {
         if (!binding.isValidBinding())
          return new ProblemReferenceBinding(
                  CharOperation.subarray(compoundName, 0, currentIndex),
                  (ReferenceBinding)((ReferenceBinding)binding).closestMatch(),
                  binding.problemId());
         if (!this.canBeSeenByForCodeSnippet((ReferenceBinding) binding, receiverType))
          return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), (ReferenceBinding) binding, ProblemReasons.NotVisible);
         break foundType;
       }
       packageBinding = (PackageBinding) binding;
    }

    // It is illegal to request a PACKAGE from this method.
    return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null, ProblemReasons.NotFound);
  }

  // know binding is now a ReferenceBinding
  while (currentIndex < length) {
    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()) {
View Full Code Here

* by a super type or because it *is* raw and the current type has no control over it (i.e the rawness
* originates from some other file.)
*/
public boolean forcedToBeRaw(ReferenceContext referenceContext) {
  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) {
View Full Code Here

      org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(importDeclaration);
      if (node instanceof ImportReference) {
        ImportReference importReference = (ImportReference) node;
        final boolean isStatic = importReference.isStatic();
        if ((importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0) {
          Binding binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length), true, isStatic);
          if (binding != null) {
            if (isStatic) {
              if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
                ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
                return typeBinding == null ? null : typeBinding;
              }
            } else {
              if ((binding.kind() & Binding.PACKAGE) != 0) {
                IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
                if (packageBinding == null) {
                  return null;
                }
                return packageBinding;
              } else {
                // if it is not a package, it has to be a type
                ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
                if (typeBinding == null) {
                  return null;
                }
                return typeBinding;
              }
            }
          }
        } else {
          Binding binding = this.scope.getImport(importReference.tokens, false, isStatic);
          if (binding != null) {
            if (isStatic) {
              if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
                ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
                return typeBinding == null ? null : typeBinding;
View Full Code Here

      }
      int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based
      if (index < indexOfFirstFieldBinding) {
        // an extra lookup is required
        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(tokens, 0, index));
          } else {
            binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
          }
        } catch (AbortCompilation e) {
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
        }
        if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
          return null;
        } 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 (index == indexOfFirstFieldBinding) {
        if (qualifiedNameReference.isTypeReference()) {
          return this.getTypeBinding(qualifiedNameReference.resolvedType);
        } 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];
          if (fieldBinding == null) return null;
          type = fieldBinding.type;
        }
        return this.getTypeBinding(type);
      }
    } 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 null;
          }
        }
        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 null;
          } 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.TypeBinding) {
            // it is a type
            return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
          }
          return null;
        }
      }
    } else if (node instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
      IMethodBinding method = getMethodBinding(methodDeclaration.binding);
      if (method == null) return null;
      return method.getReturnType();
    } 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 JavadocSingleNameReference) {
      JavadocSingleNameReference singleNameReference = (JavadocSingleNameReference) node;
      LocalVariableBinding localVariable = (LocalVariableBinding)singleNameReference.binding;
      if (localVariable != null) {
        return this.getTypeBinding(localVariable.type);
      }
    } if (node instanceof SingleNameReference) {
      SingleNameReference singleNameReference = (SingleNameReference) node;
      return this.getTypeBinding(singleNameReference.resolvedType);
    } else if (node instanceof QualifiedSuperReference) {
      QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node;
      return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType);
    } else if (node instanceof LocalDeclaration) {
      IVariableBinding variable = this.getVariableBinding(((LocalDeclaration)node).binding);
      if (variable == null) return null;
      return variable.getType();
    } else if (node instanceof JavadocFieldReference) {
      JavadocFieldReference fieldRef = (JavadocFieldReference) node;
      if (fieldRef.methodBinding != null) {
        return getMethodBinding(fieldRef.methodBinding).getReturnType();
      }
      return getTypeBinding(fieldRef.resolvedType);
    } else if (node instanceof FieldReference) {
      return getTypeBinding(((FieldReference) node).resolvedType);
    } else if (node instanceof SingleTypeReference) {
      SingleTypeReference singleTypeReference = (SingleTypeReference) node;
      org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType;
      if (binding != null) {
        return this.getTypeBinding(binding.leafComponentType());
      }
    } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
      org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
      IVariableBinding field = this.getVariableBinding(fieldDeclaration.binding);
      if (field == null) return null;
View Full Code Here

      final char[][] tokens = qualifiedNameReference.tokens;
      int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based
      if (index < indexOfFirstFieldBinding) {
        // an extra lookup is required
        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(tokens, 0, index));
          } else {
            binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
          }
        } catch (AbortCompilation e) {
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
        }
        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 (index == indexOfFirstFieldBinding) {
        if (qualifiedNameReference.isTypeReference()) {
          return this.getTypeBinding(qualifiedNameReference.resolvedType);
        } else {
          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*/);
                  if (exactBinding != null) {
                    if (exactBinding.type != null) {
                      IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                      if (variableBinding2 != null) {
                        return variableBinding2;
                      }
                      variableBinding2 = new VariableBinding(this, exactBinding);
                      this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2);
                      return variableBinding2;
                    }
                  }
                  break;
              }
            }
          }
        }
      }
    } else if (node instanceof QualifiedSuperReference) {
      QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node;
      return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType);
    } else if (node instanceof LocalDeclaration) {
      return this.getVariableBinding(((LocalDeclaration)node).binding);
    } else if (node instanceof JavadocFieldReference) {
      JavadocFieldReference fieldRef = (JavadocFieldReference) node;
      if (fieldRef.methodBinding != null) {
        return getMethodBinding(fieldRef.methodBinding);
      }
      return getVariableBinding(fieldRef.binding);
    } else if (node instanceof FieldReference) {
      return getVariableBinding(((FieldReference) node).binding);
    } else if (node instanceof SingleTypeReference) {
      if (node instanceof JavadocSingleTypeReference) {
        JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) node;
        if (typeRef.packageBinding != null) {
          return getPackageBinding(typeRef.packageBinding);
        }
      }
      SingleTypeReference singleTypeReference = (SingleTypeReference) node;
      org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType;
      if (binding == null) {
        return null;
      }
      return this.getTypeBinding(binding.leafComponentType());
    } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
      org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
      return this.getVariableBinding(fieldDeclaration.binding);
    } else if (node instanceof MessageSend) {
      MessageSend messageSend = (MessageSend) node;
View Full Code Here

    if (this.scope == null) return null;
    try {
      org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
      if (node instanceof ImportReference) {
        ImportReference importReference = (ImportReference) node;
        Binding binding = this.scope.getTypeOrPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
        if ((binding != null) && (binding.isValidBinding())) {
          if (binding instanceof ReferenceBinding) {
            // this only happens if a type name has the same name as its package
            ReferenceBinding referenceBinding = (ReferenceBinding) binding;
            binding = referenceBinding.fPackage;
          }
View Full Code Here

TOP

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

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.