Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
d2fbc49a
Commit
d2fbc49a
authored
6 years ago
by
Anna Kozlova
Browse files
Options
Download
Email Patches
Plain Diff
simplify if: preserve comments (IDEA-197511)
parent
de4e4520
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/TrivialIfInspection.java
+9
-5
...sis/src/com/siyeh/ig/controlflow/TrivialIfInspection.java
plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/trivialIf/NegatedConditional.after.java
+1
-0
...fixes/controlflow/trivialIf/NegatedConditional.after.java
plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/trivialIf/NegatedConditional.java
+1
-1
...yeh/igfixes/controlflow/trivialIf/NegatedConditional.java
with
11 additions
and
6 deletions
+11
-6
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/TrivialIfInspection.java
+
9
-
5
View file @
d2fbc49a
...
...
@@ -243,19 +243,23 @@ public class TrivialIfInspection extends BaseInspection implements CleanupLocalI
if
(
condition
==
null
)
{
return
;
}
final
String
conditionText
=
BoolUtils
.
getNegatedExpressionText
(
condition
);
CommentTracker
commentTracker
=
new
CommentTracker
();
final
String
conditionText
=
BoolUtils
.
getNegatedExpressionText
(
condition
,
commentTracker
);
final
PsiReturnStatement
nextStatement
=
ControlFlowUtils
.
getNextReturnStatement
(
statement
);
if
(
nextStatement
==
null
)
{
return
;
}
final
PsiElement
nextSibling
=
statement
.
getNextSibling
();
PsiElement
nextSibling
=
statement
.
getNextSibling
();
if
(
nextSibling
!=
nextStatement
&&
nextStatement
.
getParent
()
==
statement
.
getParent
())
{
statement
.
getParent
().
deleteChildRange
(
nextSibling
,
nextStatement
.
getPrevSibling
());
while
(
nextSibling
!=
nextStatement
&&
nextSibling
!=
null
)
{
commentTracker
.
delete
(
nextSibling
);
nextSibling
=
nextSibling
.
getNextSibling
();
}
}
@NonNls
final
String
newStatement
=
"return "
+
conditionText
+
';'
;
PsiReplacementUtil
.
replaceStatement
(
statement
,
newStatement
);
PsiReplacementUtil
.
replaceStatement
(
statement
,
newStatement
,
commentTracker
);
if
(!
ControlFlowUtils
.
isReachable
(
nextStatement
))
{
nextStatement
.
delete
(
);
ne
w
CommentTracker
().
deleteAndRestoreComments
(
ne
xtStatement
);
}
}
...
...
This diff is collapsed.
Click to expand it.
plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/trivialIf/NegatedConditional.after.java
+
1
-
0
View file @
d2fbc49a
...
...
@@ -8,6 +8,7 @@ class NegatedConditional {
final
NegatedConditional
that
=
(
NegatedConditional
)
object
;
//comment
return
text
!=
null
?
text
.
equals
(
that
.
text
)
:
that
.
text
==
null
;
}
...
...
This diff is collapsed.
Click to expand it.
plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/trivialIf/NegatedConditional.java
+
1
-
1
View file @
d2fbc49a
...
...
@@ -8,7 +8,7 @@ class NegatedConditional {
final
NegatedConditional
that
=
(
NegatedConditional
)
object
;
<
caret
>
if
(
text
!=
null
?
!
text
.
equals
(
that
.
text
)
:
that
.
text
!=
null
)
return
false
;
<
caret
>
if
(
text
!=
null
?
!
text
.
equals
(
that
.
text
)
:
that
.
text
!=
null
)
return
false
;
//comment
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help