Commit Graph

5581 Commits

Author SHA1 Message Date
Anna Kozlova
8aafb282f3 java switch expressions: infer Object if one of branches has null type (IDEA-241470)
GitOrigin-RevId: 489d3413091cbd1a85348fae0a428e29b287f7e0
2020-05-25 22:47:41 +03:00
Anna Kozlova
1c2a41050d java: remove redundant cast: ensure operation priority
GitOrigin-RevId: cad7c6e31f088f5b9528ee3d35743fd5b4b8ef66
2020-05-25 22:47:38 +03:00
Tagir Valeev
0c336ffda4 IDEA-240404 Analyze dataflow to here: stack-trace based scope
GitOrigin-RevId: 33b4b1cdf2198e9c15fc2d52e0113ffe97c3dde9
2020-05-25 12:59:28 +03:00
Tagir Valeev
c66e612649 Specific method call test
GitOrigin-RevId: 9d41843321968d4633ced2b838b1d8313ed59bd9
2020-05-25 12:59:18 +03:00
Ilyas Selimov
80ee8725fd IDEA-238099 - moved test cases to an appropriate place, fixed an error which could lead to unexpected element deletion
GitOrigin-RevId: f79de804e604675868d58715b65fd291da8e5483
2020-05-21 15:25:59 +03:00
Tagir Valeev
8ddeb2cd07 Disable lambda2methodref if lambda parameter has annotations; preserve annotations in extract to methodref
Fixes IDEA-200489 Replacing lambda with method reference discards annotation on Java 11 var lambda parameter

GitOrigin-RevId: 78bf5f00389f8e1e8a866fbaa226cea2e31b749c
2020-05-21 14:05:56 +03:00
Tagir Valeev
983a6c1d3a Inherit type annotations for arrays
Fixes IDEA-240571 "implement method" action works bad with arrays notnulled twice

GitOrigin-RevId: 3014f528f6af966153ae4dc8c821240fca3d9d79
2020-05-20 08:50:34 +00:00
Anna Kozlova
0314adac6d java: redundant cast: don't check casts against non-denotable types
GitOrigin-RevId: ba1ac48a92057ae13f2694a6667e576ca1328134
2020-05-20 06:38:50 +00:00
Tagir Valeev
a7f179e554 CommonDataflow: track both assertionEnabled and assertionDisabled modes; use in dataflow to here
GitOrigin-RevId: 31615f1351df48feb8df75ed9611997263f75af0
2020-05-19 07:46:29 +00:00
Tagir Valeev
0191ffb437 Testdata fix after 6f6f693c6a3c
GitOrigin-RevId: 1e8e50c91e78ef61788e922cdbc5c92da7c07b61
2020-05-18 04:10:49 +00:00
Anna Kozlova
4b5272c14a java: redundant cast: check inference problems in cast operand
expected type (available after removing type cast) may add bounds for inference variables which would lead to errors after applying the fix

GitOrigin-RevId: 24a97411b7175cacabd8e81ed5711509195dfd4d
2020-05-15 20:27:18 +00:00
Nikita Eshkeev
ce7dae26b1 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch replaces the excessive extraction of a qualifier via `ExpressionUtils.getEffectiveQualifier` with a simple `call.getMethodExpression().getQualifierExpression`

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 4a4f1c6b218c63691fa2bd4610e9901874d3c712
2020-05-15 12:15:31 +00:00
Tagir Valeev
7d4c5ea4d8 IDEA-240403 Analyze dataflow to here: perform backpropagation through simple expressions
GitOrigin-RevId: 6c7d2e9f30121748c624a20ab14cbcf7dd7c71ec
2020-05-15 11:16:42 +00:00
Anna Kozlova
2bc23faf05 java: redundant cast: preserve exact types for functional expressions
otherwise we may loose serialization or miss compilation errors in lambda body

GitOrigin-RevId: 180e0ee713a19c42abecf1228616bbd6754ea3b8
2020-05-15 08:33:44 +00:00
Tagir Valeev
7b3ce3097a IDEA-240402 Dataflow to here: narrow filters during the dataflow
GitOrigin-RevId: 3fb73062b31ec664aebe8bfe167726d421752cb2
2020-05-15 06:47:18 +00:00
Nikita Eshkeev
0218cec2c9 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch removes the detection of redundant calls to `StringBuilder#toString` from the `RedundantStringOperationInspection` since there is a more general inspection called `UnnecessaryToStringCallInspection` which handles all the redundant `Object#toString` calls. All the related tests were moved to the test data of `UnnecessaryToStringCallInspectionTest`

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 1fe7723fa4369b797120c5bbc6a6b24947c84a94
2020-05-14 22:04:54 +00:00
Nikita Eshkeev
ae75412782 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch fixes the syntax error in testData

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 90aae74914c4143dcb1ebff9e7d0c585f373718b
2020-05-14 15:42:52 +00:00
Tagir Valeev
be0e0336bc Keep filtering on indexNesting increment/decrement
GitOrigin-RevId: e5a874102eadc538a6bc5a79150ddf423f314594
2020-05-14 08:14:59 +00:00
Nikita Eshkeev
06fbc3bdd2 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch simplifies the `RedundantStringOperationInspection#isOperandOfStringType` method by checking if the type of the passed operand is java.lang.String. The check is the same for any passed operand since they are of the `PsiExpression` type and hence poses the `PsiExpression#getType` method.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: bcd489d41d1272877a1bbf6032ef837a228a18e1
2020-05-13 00:55:37 +00:00
Tagir Valeev
7b5c5c2875 IDEA-240285 ConstantConditions: improve detection of pointless 'Math.min' and 'Math.max' operations
+Quick-fix

GitOrigin-RevId: 9f01fac2ecd4faf7ff76101a956cc30582ad421b
2020-05-12 08:00:09 +00:00
Nikita Eshkeev
cb47b00f60 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch alters the `getRedundantStringBuilderToStringProblem` method with more sophisticated algorithm to detect unnecessary freestanding `StringBuilder#toString` calls. If the call is a part of a polyadic expression it checks if there is at least one string operand (either a constant literal or a local variable or a constant variable or a method call) and based on that information it detects redundant `StringBuilder#toString` calls.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: e09ea8b8829ad9e28e8ff1bcfad34cf6b191aa6b
2020-05-12 00:59:21 +00:00
Anna Kozlova
c879ed4e4a java redundant cast: preserve multiple type casts around functional interface when if expected type is the same as cast
isAssignable check may fail otherwise

GitOrigin-RevId: d02c9d50645a2bbb0e957f077a4a66813c94afd6
2020-05-11 20:09:58 +00:00
Anna Kozlova
7f02ca14a9 java redundant cast: check conditional expression as call argument inplace
GitOrigin-RevId: ee7fa6ef4cac4e39e9dad97c7d5ace983bc81044
2020-05-11 08:33:17 +00:00
Anna Kozlova
e3bc888dc7 java redundant cast: cleanup checks for calls
GitOrigin-RevId: 2d999bc7356856ef7d2fea45f793d69f401f7256
2020-05-11 08:33:17 +00:00
Anna Kozlova
1bc4cda08e java redundant cast: cleanup: visitor finally inverted
GitOrigin-RevId: 8b4449e6d9163c24b046aad9065e5ec055d6d62c
2020-05-11 08:33:17 +00:00
Anna Kozlova
78891be4bb java redundant cast: cleanup: extract conditional
GitOrigin-RevId: ca95c0e70c197e27943596e91df8d526bbfbf1bb
2020-05-11 08:33:17 +00:00
Anna Kozlova
efc6106e02 java redundant cast: cleanup: avoid dbl cast registration for expressions with expected type
GitOrigin-RevId: a31b1d892b2e19bfaf556e85724eb244189111b4
2020-05-11 08:33:17 +00:00
Anna Kozlova
fdc80d017c java redundant cast: fixed multiple casts in synchronized stmt
GitOrigin-RevId: 49a7d8dbcd26a3aa905c57db97d386bcbd285464
2020-05-11 08:33:17 +00:00
Anna Kozlova
1c35803b4a java redundant cast: cleanup: extract foreach, instanceof, throws statements
GitOrigin-RevId: ac04ea8db453518f4c15d3e37e33d9a25a22ce35
2020-05-11 08:33:17 +00:00
Nikita Eshkeev
597a92c0b2 [codeInsight] IDEA-240288 Inspection for StringBuilder.toString().substring()
This patch enhances RedundantStringOperationInspection with detecting either unnecessary naked calls StringBuilder.toString or redundant toString in StringBuilder.toString.substring.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 3cd7e964c0acc73fb1ac38061ef31264035f82dc
2020-05-09 05:25:10 +00:00
Nikita Eshkeev
ec420ec3d4 [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
This patch cleans up the code

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: f90c1f9af167102b3b57daf43c144973e9502a6f
2020-05-08 01:22:39 +00:00
Nikita Eshkeev
8db5967f7b [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
This patch adds processing of Java 14's text blocks to RedundantStringFormatCallInspection and fixes the problems from the code review

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 126cfc001e7b201b62060333de7f71480403fb93
2020-05-08 00:38:22 +00:00
Nikita Eshkeev
299e3d31e1 [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
This patch fixes the notes from the code review, it inclues:

- renaming method to methodNameReference for variables that contain the name of a method that is being called, i.e. either `println` or `print` or `format`
- using a different overloaded createProblemDescriptor method that does not accept a `TextRange`
- using `getParent` in quick fixes to get the `PsiMethodExpressionCall`
- proper handling arguments with parenthesis

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: ea1e335372bf7b1ce3e6c87a3816baa0ab54e11e
2020-05-06 13:46:11 +00:00
Anna Kozlova
0a41902bda java redundant cast: normalize parenthesis
GitOrigin-RevId: 8069758686e0e76c3aed4d6851914315d29a493e
2020-05-05 21:49:48 +00:00
Anna Kozlova
c2ec0c2e78 java redundant cast: forbid changing of substitutor if cast is removed (IDEA-184330)
this way neighbour functional expressions can't be broken

GitOrigin-RevId: c13823eca79157030f3dde53fa6a6d496be9c2b7
2020-05-05 21:49:48 +00:00
Anna Kozlova
349c96eaee java redundant cast: allow warnings in poly conditional when target type remains the same
GitOrigin-RevId: f953fc42882a1eaad0b0a8c65d1e94236f0ec99e
2020-05-05 11:29:06 +00:00
Anna Kozlova
2832d5f81c java redundant cast: keep same conditional expression type based on cast type & opposite operand (IDEA-235896)
GitOrigin-RevId: 7e454f0db256ad843c7abb890953c8d264af0257
2020-05-05 11:29:06 +00:00
Anna Kozlova
462856d81c java: ensure that lambda parameters are available inside lambdabody.copy() (IDEA-222542)
GitOrigin-RevId: b31c6c8484d8e77e96dfad104b08ce13631ddeaa
2020-05-05 07:04:28 +00:00
Tagir Valeev
c7cfd81bc2 Positive test added (IDEA-CR-62158)
GitOrigin-RevId: bafc04a87dd7b52f54938dc6dcb3a76cc32ee732
2020-05-05 05:11:19 +00:00
Tagir Valeev
39ca5a8e57 IDEA-227219 Dataflow to here: filter by target value
GitOrigin-RevId: 4509bbb852b61262ac4160bebe31fd93976da286
2020-05-05 04:30:49 +00:00
Anna Kozlova
02d7164d3b java redundant cast: check erased context (IDEA-205885)
GitOrigin-RevId: 1dd464c7b8feba43181c9e60472170b2bbbaa72e
2020-05-04 20:49:32 +00:00
Nikita Eshkeev
fcd7fac054 [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
This patch fixes the notes from the code review, it includes:

- Renaming the testData files so their titles are more informative
- Moving `PsiLiteralUtil#append` to `RedundantStringFormatCallInspection` and renaming it to `joinWithNewlineToken` so it does not have to deal with the escape characters' problems
- `RedundantStringFormatCallInspection` only highlights the "`format`" word in `String.format` in order to reduce the warnings area in code visually

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 07b3b3b2d24e500774928d406e274dd4cb20bd5d
2020-05-04 17:09:45 +00:00
Nikita Eshkeev
d605adb8d1 [codeInsight] IDEA-113640 Provide intention to combine System.out.println(String.format(...)) into System.out.printf
The RedundantStringFormatCallInspection inspection used to be able to
detect excessive String.format calls and get rid of them not changing
the callsite at all. This patch enhances the inspection's capabilities
with changing the callsite if it is either PrintStream#print or
PrintStream#println and converting it to PrintStream#printf adding "%n"
if necessary.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 7edc5b0a84fb6c7b9caf504b1afb8905c5684985
2020-05-01 14:07:13 +00:00
Artemiy Sartakov
349d58606e OptionalToIfInspection: propagate rename to nested flatMap
GitOrigin-RevId: ae65a4a91dbefc73bd160a2b92a36e296fed3c3e
2020-05-01 09:40:21 +00:00
Tagir Valeev
618696f129 IDEA-239649 Increase language level fix is not suggested for records
GitOrigin-RevId: 19843f9e1f610f7536b7e591012ec3eb64af6c43
2020-04-30 06:26:10 +00:00
Artemiy Sartakov
fcd1363aee OptionalToIfInspection: propagate rename to nested operations for flatMap and or
GitOrigin-RevId: 338d1c5e49a05fdd0ab60321275acc7ac51bcb4d
2020-04-30 05:32:53 +00:00
Tagir Valeev
f18b4797d9 AddMissingRequiredAnnotationParametersFix preview-friendly; default values
GitOrigin-RevId: 7e2cd8fca577fce7acc290caa0b9a3c37dcf3e4b
2020-04-30 04:48:14 +00:00
Peter Gromov
33ae0aa674 IDEA-239386 Completion for $Class$.class should be suggested first if Class parameter is expected
GitOrigin-RevId: ba80deade49dc5cabc96cd89eb833fe024f56281
2020-04-29 20:17:20 +00:00
Alexey Kudravtsev
f88eeb5101 Look for string literals with mixed languages and repair some found violations to fix IDEA-239390 Inspection to detect mixed characters in strings (strings containing both ASCII and non-ASCII)
GitOrigin-RevId: 312b7bcfd4e9c8ae438ae3d08aa0a60188fa226a
2020-04-29 11:54:28 +00:00
Tagir Valeev
b3ba7b6783 IDEA-239116 Switch expression without any results is not highlighted as erroneous
GitOrigin-RevId: 66580d3aa4a95e1fdb32b1a3131544560c9c432a
2020-04-29 10:51:14 +00:00