Skip to content

Commit 4096711

Browse files
Zopsssnrmancuso
authored andcommitted
Issue #14765: fix OverloadMethodsDeclarationOrderCheck
1 parent 5b05fff commit 4096711

File tree

16 files changed

+66
-15
lines changed

16 files changed

+66
-15
lines changed

src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/OverloadMethodsDeclarationOrderCheck.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ private void checkOverloadMethodsGrouping(DetailAST objectBlock) {
110110
final String methodName =
111111
currentToken.findFirstToken(TokenTypes.IDENT).getText();
112112
final Integer previousIndex = methodIndexMap.get(methodName);
113-
if (previousIndex != null && currentIndex - previousIndex > allowedDistance) {
113+
final DetailAST previousSibling = currentToken.getPreviousSibling();
114+
final boolean isMethod = previousSibling.getType() == TokenTypes.METHOD_DEF;
115+
116+
if (previousIndex != null
117+
&& (!isMethod || currentIndex - previousIndex > allowedDistance)) {
114118
final int previousLineWithOverloadMethod =
115119
methodLineNumberMap.get(methodName);
116120
log(currentToken, MSG_KEY,

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=Nested if-else depth is {0,number,integer} (max allowed is {1,nu
4444
nested.try.depth=Nested try depth is {0,number,integer} (max allowed is {1,number,integer}).
4545
no.array.trailing.comma=Array should not contain trailing comma.
4646
no.enum.trailing.comma=Enum should not contain trailing comma.
47-
overload.methods.declaration=All overloaded methods should be placed next to each other. Placing non-overloaded methods in between overloaded methods with the same type is a violation. Previous overloaded method located at line ''{0}''.
47+
overload.methods.declaration=All overloaded methods should be placed next to each other. Previous overloaded method located at line ''{0}''.
4848
parameter.assignment=Assignment of parameter ''{0}'' is not allowed.
4949
require.this.method=Method call to ''{0}'' needs \"{1}this.\".
5050
require.this.variable=Reference to instance variable ''{0}'' needs \"{1}this.\".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_es.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=La profundidad de if-else anidados es {0,number,integer} (máxim
4444
nested.try.depth=La profundidad de try anidados es {0,number,integer} (máximo permitido es {1,number,integer}).
4545
no.array.trailing.comma=La matriz no debe contener una coma final.
4646
no.enum.trailing.comma=Enum no debe contener una coma final.
47-
overload.methods.declaration=Todos los métodos sobrecargados deben colocarse uno al lado del otro. Colocar métodos no sobrecargados entre métodos sobrecargados con el mismo tipo es una violación. Método sobrecargado anterior ubicado en la línea ''{0} ''.
47+
overload.methods.declaration=Todos los métodos sobrecargados deben colocarse uno al lado del otro. Método sobrecargado anterior ubicado en la línea ''{0}''.
4848
parameter.assignment=No esta permitida la asignación del parámetro ''{0}''.
4949
require.this.method=La llamada al método ''{0}'' necesita "{1}this.".
5050
require.this.variable=La referencia a la variable de instancia ''{0}'' necesita "{1}this.".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_fi.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=Sisäkkäisten if-else -lausekkeiden syvyys on {0,number,integer
4444
nested.try.depth=Sisäkkäisten try -lausekkeiden syvyys on {0,number,integer} (suurin sallittu on {1,number,integer}).
4545
no.array.trailing.comma=Matriisissa ei tulisi olla takaosan pilkkua.
4646
no.enum.trailing.comma=Enum ei saisi sisältää takaosan pilkkua.
47-
overload.methods.declaration=Kaikki ylikuormitetut menetelmät tulisi asettaa vierekkäin. Ei-ylikuormitettujen menetelmien sijoittaminen samantyyppisiin ylikuormitettuihin menetelmiin on rikkomus. Aikaisempi ylikuormitettu menetelmä sijaitsee rivillä '' {0} ''.
47+
overload.methods.declaration=Kaikki ylikuormitetut menetelmät tulee sijoittaa vierekkäin. Edellinen ylikuormitettu menetelmä sijaitsee rivillä ''{0}''.
4848
parameter.assignment=Tehtävä parametrin ''{0}'' ei ole sallittu.
4949
require.this.method=Menetelmä kehotus ''{0}'' tarvitsee "{1}this.".
5050
require.this.variable=Viittaus Esimerkiksi muuttuja ''{0}'' tarvitsee "{1}this.".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_fr.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=Le nombre de ''if'' imbriqués est de {0,number,integer}, alors
4444
nested.try.depth=Le nombre de ''try'' imbriqués est de {0,number,integer}, alors que le maximum autorisé est de {1,number,integer}.
4545
no.array.trailing.comma=Le tableau ne doit pas contenir de virgule.
4646
no.enum.trailing.comma=Enum ne doit pas contenir de virgule.
47-
overload.methods.declaration=Toutes les méthodes surchargées doivent être placées côte à côte. Placer des méthodes non surchargées entre des méthodes surchargées avec le même type est une violation. La méthode surchargée précédente se trouve à la ligne '' {0} ''.
47+
overload.methods.declaration=Toutes les méthodes surchargées doivent être placées les unes à côté des autres. Méthode surchargée précédente située à la ligne ''{0}''.
4848
parameter.assignment=Il est interdit d''affecter une valeur au paramètre ''{0}''.
4949
require.this.method=L''appel à la méthode ''{0}'' nécessite l''utilisation de "{1}this.".
5050
require.this.variable=La référence à la variable d''instance ''{0}'' doit utiliser "{1}this.".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_ja.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=ネストした if-else の深さが {0,number,integer} (最
4444
nested.try.depth=ネストした try の深さが {0,number,integer} (最大 {1,number,integer} まで)です。
4545
no.array.trailing.comma=配列には末尾のコンマを含めないでください。
4646
no.enum.trailing.comma=列挙には末尾のコンマを含めないでください。
47-
overload.methods.declaration=すべてのオーバーロードされたメソッドは、互いに隣接して配置する必要があります。 同じタイプのオーバーロードされたメソッドの間に非オーバーロードされたメソッドを配置することは違反です。 最後のオーバーロードされたメソッドは、行 '' {0} ''にあります。
47+
overload.methods.declaration=すべてのオーバーロードされたメソッドは隣り合って配置する必要があります。以前のオーバーロードされたメソッドは行 ''{0}'' にあります。
4848
parameter.assignment=パラメータ ''{0}'' への代入は許可されていません。
4949
require.this.method=メソッド ''{0}'' への呼び出しは、 "{1}this." が必要です。
5050
require.this.variable=インスタンス変数 ''{0}'' への参照には "{1}this." が必要です。

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_pt.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=A profundidade de aninhamento do "if-else" é {0,number,integer}
4444
nested.try.depth=A profundidade de aninhamento do "try" é {0,number,integer} (o máximo permitido é {1,number,integer}).
4545
no.array.trailing.comma=A matriz não deve conter vírgula à direita.
4646
no.enum.trailing.comma=O enum não deve conter vírgula à direita.
47-
overload.methods.declaration=Todos os métodos sobrecarregados devem ser colocados juntos. A colocação de métodos não sobrecarregados entre métodos sobrecarregados com o mesmo tipo é uma violação. O método sobrecarregado anterior foi encontrado na linha '' {0} ''.
47+
overload.methods.declaration=Todos os métodos sobrecarregados devem ser colocados um ao lado do outro. Método sobrecarregado anterior localizado na linha ''{0}''.
4848
parameter.assignment=A atribuição ao parâmetro ''{0}'' não é permitida.
4949
require.this.method=A chamada de método no ''{0}'' precisa de "{1}this.".
5050
require.this.variable=A referência à variável de instância ''{0}'' precisa de "{1}this.".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_ru.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=Глубина if-else {0,number,integer} (максимум {1,n
4444
nested.try.depth=Глубина try {0,number,integer} (максимум {1,number,integer}).
4545
no.array.trailing.comma=У последнего элемента массива не должно быть запятой.
4646
no.enum.trailing.comma=У последней константы перечисления не должно быть запятой.
47-
overload.methods.declaration=Все перегруженные методы должны быть размещены рядом друг с другом. Размещение не перегруженных методов между перегруженными методами одного и того же типа является нарушением. Предыдущий перегруженный метод расположен в строке ''{0}''.
47+
overload.methods.declaration=Все перегруженные методы следует размещать рядом друг с другом. Предыдущий перегруженный метод расположен в строке ''{0}''.
4848
parameter.assignment=Параметр метода ''{0}'' не должен менять значение.
4949
require.this.method=При вызове метода ''{0}'' нужно использовать \"{1}this.\".
5050
require.this.variable=При использовании переменной класса ''{0}'' нужно использовать \"{1}this.\".

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_tr.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=İç içe kullanılan ''if-else'' sayısı {0,number,integer} (m
4444
nested.try.depth=İç içe kullanılan ''try'' sayısı {0,number,integer} (maksimum izin verilen değer {1,number,integer}).
4545
no.array.trailing.comma=Dizi sonda virgül içermemelidir.
4646
no.enum.trailing.comma=Enum, sonda virgül içermemelidir.
47-
overload.methods.declaration=Aşırı yüklenmiş tüm yöntemler yan yana yerleştirilmelidir. Aşırı yüklenmemiş yöntemleri aynı tip aşırı yüklenmiş yöntemler arasına yerleştirmek bir ihlaldir. '' {0} '' satırında önceki aşırı yüklenmiş yöntem.
47+
overload.methods.declaration=Tüm aşırı yüklenmiş yöntemler yan yana yerleştirilmelidir. ''{0}'' satırında bulunan önceki aşırı yüklenmiş yöntem.
4848
parameter.assignment=''{0}'' parametresine atama yapılamaz.
4949
require.this.method=''{0}'' metoduna erişim "{1}this." kullanılarak yapılmalıdır.
5050
require.this.variable=''{0}'' değişkenine erişim "{1}this." kullanılarak yapılmalıdır.

src/main/resources/com/puppycrawl/tools/checkstyle/checks/coding/messages_zh.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nested.if.depth=至多{1,number,integer}层 if,目前{0,number,integer}层。
4444
nested.try.depth=至多{1,number,integer}层 try,目前{0,number,integer}层。
4545
no.array.trailing.comma=數組不應包含結尾逗號。
4646
no.enum.trailing.comma=枚举不应包含结尾逗号。
47-
overload.methods.declaration=所有重载的方法都应该相邻放置。在相同类型的重载方法之间放置非重载方法是违反的。最后一个重载方法在行 ''{0}''
47+
overload.methods.declaration=所有重载方法应彼此相邻放置。上一个重载方法位于 ''{0}''
4848
parameter.assignment=不应对方法参数''{0}''赋值。
4949
require.this.method=对方法 ''{0}'' 的调用需要 "{1}this."
5050
require.this.variable=对实例属性 ''{0}'' 的引用需要 "{1}this."

0 commit comments

Comments
 (0)