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
7906dd0d
Commit
7906dd0d
authored
6 years ago
by
Tagir Valeev
Browse files
Options
Download
Email Patches
Plain Diff
RedundantCastUtil: fix isCastRedundant (avoid checking another cast)
parent
4d844c7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java
+7
-21
...-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantConditional/afterTypeConversionOther.java
+9
-0
...uickFix/constantConditional/afterTypeConversionOther.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantConditional/beforeTypeConversionOther.java
+9
-0
...ickFix/constantConditional/beforeTypeConversionOther.java
with
25 additions
and
21 deletions
+25
-21
java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java
+
7
-
21
View file @
7906dd0d
...
...
@@ -41,7 +41,7 @@ public class RedundantCastUtil {
return
new
ArrayList
<>(
visitor
.
myFoundCasts
);
}
public
static
boolean
isCastRedundant
(
PsiTypeCastExpression
typeCast
)
{
public
static
boolean
isCastRedundant
(
PsiTypeCastExpression
typeCast
)
{
PsiElement
parent
=
typeCast
.
getParent
();
PsiExpression
operand
=
typeCast
.
getOperand
();
if
(
operand
!=
null
&&
operand
.
getType
()
!=
null
&&
operand
.
getType
().
equals
(
typeCast
.
getType
()))
return
true
;
...
...
@@ -49,9 +49,9 @@ public class RedundantCastUtil {
if
(
parent
instanceof
PsiExpressionList
)
parent
=
parent
.
getParent
();
if
(
parent
instanceof
PsiReferenceExpression
)
parent
=
parent
.
getParent
();
if
(
parent
instanceof
PsiAnonymousClass
)
parent
=
parent
.
getParent
();
MyIsRedundantVisitor
visitor
=
new
MyIsRedundantVisitor
(
true
);
MyIsRedundantVisitor
visitor
=
new
MyIsRedundantVisitor
();
parent
.
accept
(
visitor
);
return
visitor
.
is
Redundant
;
return
visitor
.
found
Redundant
Cast
==
typeCast
;
}
@Nullable
...
...
@@ -63,10 +63,6 @@ public class RedundantCastUtil {
private
static
class
MyCollectingVisitor
extends
MyIsRedundantVisitor
{
private
final
Set
<
PsiTypeCastExpression
>
myFoundCasts
=
new
HashSet
<>();
private
MyCollectingVisitor
()
{
super
(
true
);
}
@Override
public
void
visitClass
(
PsiClass
aClass
)
{
// avoid multiple visit
...
...
@@ -90,24 +86,14 @@ public class RedundantCastUtil {
}
}
@SuppressWarnings
(
"UnsafeReturnStatementVisitor"
)
private
static
class
MyIsRedundantVisitor
extends
JavaRecursiveElementWalkingVisitor
{
private
boolean
isRedundant
;
private
final
boolean
myRecursive
;
private
MyIsRedundantVisitor
(
final
boolean
recursive
)
{
myRecursive
=
recursive
;
}
@Override
public
void
visitElement
(
final
PsiElement
element
)
{
if
(
myRecursive
)
{
super
.
visitElement
(
element
);
}
}
private
PsiTypeCastExpression
foundRedundantCast
;
protected
void
addToResults
(
@NotNull
PsiTypeCastExpression
typeCast
){
if
(!
isTypeCastSemantic
(
typeCast
))
{
isRedundant
=
true
;
foundRedundantCast
=
typeCast
;
stopWalking
();
}
}
...
...
This diff is collapsed.
Click to expand it.
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantConditional/afterTypeConversionOther.java
0 → 100644
+
9
-
0
View file @
7906dd0d
// "Simplify" "true"
class
Test
{
public
static
void
main
(
String
[]
args
)
{
foo
((
String
)
null
,
(
int
)
0
);
}
static
void
foo
(
String
s
,
int
i
)
{}
static
void
foo
(
Number
n
,
int
i
)
{}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantConditional/beforeTypeConversionOther.java
0 → 100644
+
9
-
0
View file @
7906dd0d
// "Simplify" "true"
class
Test
{
public
static
void
main
(
String
[]
args
)
{
foo
(
false
?
<
caret
>
""
:
null
,
(
int
)
0
);
}
static
void
foo
(
String
s
,
int
i
)
{}
static
void
foo
(
Number
n
,
int
i
)
{}
}
\ No newline at end of file
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