// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

public class DeprecatedMethodException extends RuntimeException {
  private static final Set<String> BEAT_DEAD_HORSE = ContainerUtil.newConcurrentSet();
  private static final Logger LOG = Logger.getInstance(DeprecatedMethodException.class);
  private DeprecatedMethodException(@NotNull String message) {
    super(message);
  }

  public static void report(@NotNull String message) {
    String text = "This method in '" + ReflectionUtil.findCallerClass(2) +
                      "' is deprecated and going to be removed soon. " + message;
    if (BEAT_DEAD_HORSE.add(text)) {
      LOG.warn(new DeprecatedMethodException(text));
    }
  }

  public static void reportDefaultImplementation(@NotNull Class<?> thisClass, @NotNull String methodName, @NotNull String message) {
    Class<?> superClass = ReflectionUtil.findCallerClass(2);
    String text = "The default implementation of method '" +superClass.getName()+"."+methodName+"' is deprecated, you need to override it in '" +
                  thisClass + "'. " + message;
    if (BEAT_DEAD_HORSE.add(text)) {
      LOG.warn(new DeprecatedMethodException(text));
    }
  }
}

@@ -17,10 +17,10 @@
 0-20
-18
+20
  Jet
@@ -662,133 +662,397 @@
 %0A%0A  
-public static void report(@NotNull String message) %7B%0A    String text = %22This method in '%22 + ReflectionUtil.findCallerClass(2)
+/**%0A   * This method reports the error only once for every same %7B@param message%7D%0A   */%0A  public static void report(@NotNull String message) %7B%0A    if (!BEAT_DEAD_HORSE.add(message)) return;%0A    Class%3C?%3E superClass = ReflectionUtil.findCallerClass(2);%0A    String superClassName = superClass != null ? superClass.getName() : %22%3Cno class%3E%22;%0A    String text = %22This method in '%22 + superClassName
  +%0A 
@@ -1136,47 +1136,8 @@
 ge;%0A
-    if (BEAT_DEAD_HORSE.add(text)) %7B%0A  
     
@@ -1185,24 +1185,96 @@
 xt));%0A  
-  %7D%0A  %7D%0A
+%7D%0A%0A  /**%0A   * This method reports the error only for every same parameters%0A   */
 %0A  publi
@@ -1407,63 +1407,237 @@
     
-Class%3C?%3E superClass = ReflectionUtil.findCallerClass(2)
+if (!BEAT_DEAD_HORSE.add(methodName + %22###%22 + message + %22###%22 + thisClass)) return;%0A    Class%3C?%3E superClass = ReflectionUtil.findCallerClass(2);%0A    String superClassName = superClass != null ? superClass.getName() : %22%3Cno class%3E%22
 ;%0A  
@@ -1694,16 +1694,17 @@
 hod '%22 +
+ 
 superCla
@@ -1709,23 +1709,21 @@
 lass
-.getName()+%22.%22+
+Name + %22.%22 + 
 meth
@@ -1728,17 +1728,19 @@
 thodName
-+
+ + 
 %22' is de
@@ -1832,47 +1832,8 @@
 ge;%0A
-    if (BEAT_DEAD_HORSE.add(text)) %7B%0A  
     
@@ -1883,14 +1883,8 @@
 ));%0A
-    %7D%0A
   %7D%0A

fix warning, unify code, avoid calling ReflectionUtil.findCallerClass too often