2222import com .siyeh .ig .BaseInspectionVisitor ;
2323import com .siyeh .localize .InspectionGadgetsLocalize ;
2424import consulo .annotation .component .ExtensionImpl ;
25+ import consulo .localize .LocalizeValue ;
2526import jakarta .annotation .Nonnull ;
27+ import org .intellij .lang .annotations .Pattern ;
2628
2729@ ExtensionImpl
2830public class NumericToStringInspection extends BaseInspection {
31+ @ Nonnull
32+ @ Override
33+ @ Pattern (VALID_ID_PATTERN )
34+ public String getID () {
35+ return "CallToNumericToString" ;
36+ }
2937
30- @ Nonnull
31- public String getID () {
32- return "CallToNumericToString" ;
33- }
34-
35- @ Nonnull
36- public String getDisplayName () {
37- return InspectionGadgetsLocalize .callToNumericTostringDisplayName ().get ();
38- }
39-
40- @ Nonnull
41- public String buildErrorString (Object ... infos ) {
42- return InspectionGadgetsLocalize .callToNumericTostringProblemDescriptor ().get ();
43- }
38+ @ Nonnull
39+ @ Override
40+ public LocalizeValue getDisplayName () {
41+ return InspectionGadgetsLocalize .callToNumericTostringDisplayName ();
42+ }
4443
45- public BaseInspectionVisitor buildVisitor () {
46- return new NumericToStringVisitor ();
47- }
44+ @ Nonnull
45+ public String buildErrorString (Object ... infos ) {
46+ return InspectionGadgetsLocalize .callToNumericTostringProblemDescriptor ().get ();
47+ }
4848
49- private static class NumericToStringVisitor extends BaseInspectionVisitor {
49+ public BaseInspectionVisitor buildVisitor () {
50+ return new NumericToStringVisitor ();
51+ }
5052
51- @ Override
52- public void visitMethodCallExpression (
53- @ Nonnull PsiMethodCallExpression expression ) {
54- super .visitMethodCallExpression (expression );
55- final PsiReferenceExpression methodExpression =
56- expression . getMethodExpression ();
57- final String methodName = methodExpression . getReferenceName ();
58- if (! HardcodedMethodConstants . TO_STRING . equals ( methodName )) {
59- return ;
60- }
61- final PsiMethod method = expression . resolveMethod ();
62- if ( method == null ) {
63- return ;
64- }
65- final PsiParameterList parameterList = method . getParameterList ();
66- if ( parameterList . getParametersCount () != 0 ) {
67- return ;
68- }
69- final PsiClass aClass = method . getContainingClass ();
70- if ( aClass == null ) {
71- return ;
72- }
73- final String className = aClass . getQualifiedName ();
74- if (! TypeConversionUtil . isPrimitiveWrapper ( className )) {
75- return ;
76- }
77- if ( NonNlsUtils . isNonNlsAnnotatedUse ( expression )) {
78- return ;
79- }
80- registerMethodCallError ( expression );
53+ private static class NumericToStringVisitor extends BaseInspectionVisitor {
54+ @ Override
55+ public void visitMethodCallExpression ( @ Nonnull PsiMethodCallExpression expression ) {
56+ super .visitMethodCallExpression (expression );
57+ final PsiReferenceExpression methodExpression = expression . getMethodExpression ();
58+ final String methodName = methodExpression . getReferenceName ();
59+ if (! HardcodedMethodConstants . TO_STRING . equals ( methodName )) {
60+ return ;
61+ }
62+ final PsiMethod method = expression . resolveMethod ();
63+ if ( method == null ) {
64+ return ;
65+ }
66+ final PsiParameterList parameterList = method . getParameterList ();
67+ if ( parameterList . getParametersCount () != 0 ) {
68+ return ;
69+ }
70+ final PsiClass aClass = method . getContainingClass ();
71+ if ( aClass == null ) {
72+ return ;
73+ }
74+ final String className = aClass . getQualifiedName ();
75+ if (! TypeConversionUtil . isPrimitiveWrapper ( className )) {
76+ return ;
77+ }
78+ if ( NonNlsUtils . isNonNlsAnnotatedUse ( expression )) {
79+ return ;
80+ }
81+ registerMethodCallError ( expression );
82+ }
8183 }
82- }
8384}
0 commit comments