From 345de40d630dd53b99c0950eaf05bd90cc6a55ec Mon Sep 17 00:00:00 2001 From: Eugene Petrenko Date: Fri, 24 Apr 2020 13:57:54 +0200 Subject: [PATCH] fix warning, unify code, avoid calling ReflectionUtil.findCallerClass too often GitOrigin-RevId: 7a272c5bca3c8269d62156f3ddb321206341afec --- .../util/DeprecatedMethodException.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/platform/util/src/com/intellij/util/DeprecatedMethodException.java b/platform/util/src/com/intellij/util/DeprecatedMethodException.java index f6c12990e5ac..4e67ed61ce25 100644 --- a/platform/util/src/com/intellij/util/DeprecatedMethodException.java +++ b/platform/util/src/com/intellij/util/DeprecatedMethodException.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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; @@ -14,20 +14,27 @@ public class DeprecatedMethodException extends RuntimeException { super(message); } + /** + * This method reports the error only once for every same {@param message} + */ public static void report(@NotNull String message) { - String text = "This method in '" + ReflectionUtil.findCallerClass(2) + + if (!BEAT_DEAD_HORSE.add(message)) return; + Class superClass = ReflectionUtil.findCallerClass(2); + String superClassName = superClass != null ? superClass.getName() : ""; + String text = "This method in '" + superClassName + "' is deprecated and going to be removed soon. " + message; - if (BEAT_DEAD_HORSE.add(text)) { - LOG.warn(new DeprecatedMethodException(text)); - } + LOG.warn(new DeprecatedMethodException(text)); } + /** + * This method reports the error only for every same parameters + */ public static void reportDefaultImplementation(@NotNull Class thisClass, @NotNull String methodName, @NotNull String message) { + if (!BEAT_DEAD_HORSE.add(methodName + "###" + message + "###" + thisClass)) return; Class superClass = ReflectionUtil.findCallerClass(2); - String text = "The default implementation of method '" +superClass.getName()+"."+methodName+"' is deprecated, you need to override it in '" + + String superClassName = superClass != null ? superClass.getName() : ""; + String text = "The default implementation of method '" + superClassName + "." + methodName + "' is deprecated, you need to override it in '" + thisClass + "'. " + message; - if (BEAT_DEAD_HORSE.add(text)) { - LOG.warn(new DeprecatedMethodException(text)); - } + LOG.warn(new DeprecatedMethodException(text)); } }