code: private void checkNameVisibility(Scope scope, Node name) {
      if (!name.isName()) {
        return;
      }
  
      Var var = scope.getVar(name.getString());
      if (var == null) {
        return;
      }
  
      Visibility v = checkPrivateNameConvention(
          AccessControlUtils.getEffectiveNameVisibility(
              name, var, defaultVisibilityForFiles), name);
  
      switch (v) {
        case PACKAGE:
          if (!isPackageAccessAllowed(var, name)) {
            compiler.report(
                JSError.make(
                    name,
                    BAD_PACKAGE_PROPERTY_ACCESS,
                    name.getString(),
                    var.getSourceFile().getName()));
          }
          break;
        case PRIVATE:
          if (!isPrivateAccessAllowed(var, name)) {
            compiler.report(
                JSError.make(
                    name,
                    BAD_PRIVATE_GLOBAL_ACCESS,
                    name.getString(),
                    var.getSourceFile().getName()));
          }
          break;
        default:
          // Nothing to do for PUBLIC and PROTECTED
          // (which is irrelevant for names).
          break;
      }
    }
docs: Reports an error if the given name is not visible in the current context.
  
  @param scope The current scope.
  @param name The name node.