コード例 #1
0
  public boolean isDeclaredInScope(IBinding declaration, SimpleName selector, int flags) {
    try {
      // special case for switch on enum
      if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
        ITypeBinding binding =
            ((SwitchStatement) selector.getParent().getParent())
                .getExpression()
                .resolveTypeBinding();
        if (binding != null && binding.isEnum()) {
          return hasEnumContants(declaration, binding.getTypeDeclaration());
        }
      }

      ITypeBinding parentTypeBinding = Bindings.getBindingOfParentTypeContext(selector);
      if (parentTypeBinding != null) {
        ITypeBinding binding = getQualifier(selector);
        SearchRequestor requestor = new SearchRequestor(declaration, parentTypeBinding, flags);
        if (binding == null) {
          addLocalDeclarations(selector, flags, requestor);
          if (requestor.found()) return requestor.isVisible();
          addTypeDeclarations(parentTypeBinding, flags, requestor);
          if (requestor.found()) return requestor.isVisible();
        } else {
          addInherited(binding, flags, requestor);
          if (requestor.found()) return requestor.isVisible();
        }
      }
      return false;
    } finally {
      clearLists();
    }
  }
コード例 #2
0
  public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) {
    try {
      // special case for switch on enum
      if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
        ITypeBinding binding =
            ((SwitchStatement) selector.getParent().getParent())
                .getExpression()
                .resolveTypeBinding();
        if (binding != null && binding.isEnum()) {
          return getEnumContants(binding);
        }
      }

      ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector);
      if (parentTypeBinding != null) {
        ITypeBinding binding = getQualifier(selector);
        DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags);
        if (binding == null) {
          addLocalDeclarations(selector, flags, requestor);
          addTypeDeclarations(parentTypeBinding, flags, requestor);
        } else {
          addInherited(binding, flags, requestor);
        }

        List<IBinding> result = requestor.getResult();
        return result.toArray(new IBinding[result.size()]);
      }
      return NO_BINDING;
    } finally {
      clearLists();
    }
  }
コード例 #3
0
 @Override
 public boolean visit(SwitchCase node) {
   // switch on enum allows to use enum constants without qualification
   if (hasFlag(VARIABLES, fFlags) && !node.isDefault() && isInside(node.getExpression())) {
     SwitchStatement switchStatement = (SwitchStatement) node.getParent();
     ITypeBinding binding = switchStatement.getExpression().resolveTypeBinding();
     if (binding != null && binding.isEnum()) {
       IVariableBinding[] declaredFields = binding.getDeclaredFields();
       for (int i = 0; i < declaredFields.length; i++) {
         IVariableBinding curr = declaredFields[i];
         if (curr.isEnumConstant()) {
           fBreak = fRequestor.acceptBinding(curr);
           if (fBreak) return false;
         }
       }
     }
   }
   return false;
 }