/*
 * Copyright 2018 The Closure Compiler Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.javascript.jscomp.ijs;

import com.google.javascript.jscomp.AbstractCompiler;
import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.FileAwareWarningsGuard;
import com.google.javascript.jscomp.JSError;
import com.google.javascript.jscomp.NodeUtil;
import com.google.javascript.rhino.Node;

/**
 * A warnings guard that sets the errors found in type summary files to be warnings, leaving only
 * the errors found in the original source.
 */
public class CheckTypeSummaryWarningsGuard extends FileAwareWarningsGuard {

  public CheckTypeSummaryWarningsGuard(AbstractCompiler compiler) {
    super(compiler);
  }

  @Override
  public CheckLevel level(JSError error) {
    if (inTypeSummary(error)) {
      return CheckLevel.WARNING;
    }
    return null;
  }

  /** Return whether the given error was produced inside a type summary file */
  private boolean inTypeSummary(JSError error) {
    Node scriptNode = getScriptNodeForError(error);
    return scriptNode != null && NodeUtil.isFromTypeSummary(scriptNode);
  }
}

@@ -1413,16 +1413,188 @@
 l;%0A  %7D%0A%0A
+  @Override%0A  protected int getPriority() %7B%0A    // Treat warnings in .i.js files as though they are whitelisted.%0A    return Priority.SUPPRESS_BY_WHITELIST.getValue();%0A  %7D%0A%0A
   /** Re

Raise the priority of the .i.js warnings guard above that of jscomp_error