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
0e12b5fc
Commit
0e12b5fc
authored
6 years ago
by
Tagir Valeev
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-204773 Enable non-null parameter inference for non-stable source methods
parent
294d7d89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/inference/InferenceFromSourceUtil.java
+3
-2
...nspection/dataFlow/inference/InferenceFromSourceUtil.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/inference/JavaSourceInference.java
+5
-5
...odeInspection/dataFlow/inference/JavaSourceInference.java
java/java-tests/testData/inspection/dataFlow/fixture/InferenceForNonStableParameters.java
+9
-0
...ion/dataFlow/fixture/InferenceForNonStableParameters.java
java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java
+1
-0
.../intellij/java/codeInspection/DataFlowInspectionTest.java
with
18 additions
and
7 deletions
+18
-7
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/inference/InferenceFromSourceUtil.java
+
3
-
2
View file @
0e12b5fc
...
...
@@ -16,7 +16,8 @@ import org.jetbrains.annotations.NotNull;
* @author peter
*/
public
class
InferenceFromSourceUtil
{
static
boolean
shouldInferFromSource
(
@NotNull
PsiMethodImpl
method
)
{
static
boolean
shouldInferFromSource
(
@NotNull
PsiMethodImpl
method
,
boolean
allowOverridden
)
{
if
(!
allowOverridden
&&
PsiUtil
.
canBeOverridden
(
method
))
return
false
;
return
CachedValuesManager
.
getCachedValue
(
method
,
()
->
CachedValueProvider
.
Result
.
create
(
calcShouldInferFromSource
(
method
),
method
,
PsiModificationTracker
.
JAVA_STRUCTURE_MODIFICATION_COUNT
));
}
...
...
@@ -24,7 +25,7 @@ public class InferenceFromSourceUtil {
private
static
boolean
calcShouldInferFromSource
(
@NotNull
PsiMethod
method
)
{
if
(
isLibraryCode
(
method
)
||
method
.
hasModifierProperty
(
PsiModifier
.
ABSTRACT
)
||
PsiUtil
.
canBeOverridden
(
method
))
{
method
.
hasModifierProperty
(
PsiModifier
.
NATIVE
))
{
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/inference/JavaSourceInference.java
+
5
-
5
View file @
0e12b5fc
...
...
@@ -41,7 +41,7 @@ public class JavaSourceInference {
*/
@NotNull
public
static
Nullability
inferNullability
(
PsiMethodImpl
method
)
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
))
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
,
false
))
{
return
Nullability
.
UNKNOWN
;
}
...
...
@@ -71,7 +71,7 @@ public class JavaSourceInference {
PsiParameterList
parent
=
ObjectUtils
.
tryCast
(
parameter
.
getParent
(),
PsiParameterList
.
class
);
if
(
parent
==
null
)
return
Nullability
.
UNKNOWN
;
PsiMethodImpl
method
=
ObjectUtils
.
tryCast
(
parent
.
getParent
(),
PsiMethodImpl
.
class
);
if
(
method
==
null
||
!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
))
return
Nullability
.
UNKNOWN
;
if
(
method
==
null
||
!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
,
true
))
return
Nullability
.
UNKNOWN
;
return
CachedValuesManager
.
getCachedValue
(
parameter
,
()
->
{
Nullability
nullability
=
Nullability
.
UNKNOWN
;
...
...
@@ -97,7 +97,7 @@ public class JavaSourceInference {
*/
@NotNull
public
static
Mutability
inferMutability
(
PsiMethodImpl
method
)
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
))
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
,
false
))
{
return
Mutability
.
UNKNOWN
;
}
...
...
@@ -124,7 +124,7 @@ public class JavaSourceInference {
*/
@NotNull
public
static
List
<
StandardMethodContract
>
inferContracts
(
@NotNull
PsiMethodImpl
method
)
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
))
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
,
false
))
{
return
Collections
.
emptyList
();
}
...
...
@@ -144,7 +144,7 @@ public class JavaSourceInference {
* @return true if method was inferred to be pure; false if method is not pure or cannot be analyzed
*/
public
static
boolean
inferPurity
(
@NotNull
PsiMethodImpl
method
)
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
)
||
PsiType
.
VOID
.
equals
(
method
.
getReturnType
()))
{
if
(!
InferenceFromSourceUtil
.
shouldInferFromSource
(
method
,
false
)
||
PsiType
.
VOID
.
equals
(
method
.
getReturnType
()))
{
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
java/java-tests/testData/inspection/dataFlow/fixture/InferenceForNonStableParameters.java
0 → 100644
+
9
-
0
View file @
0e12b5fc
class
X
{
public
void
test
(
String
s
)
{
System
.
out
.
println
(
s
.
trim
());
}
void
use
()
{
test
(<
warning
descr
=
"Passing 'null' argument to parameter annotated as @NotNull"
>
null
</
warning
>);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java
+
1
-
0
View file @
0e12b5fc
...
...
@@ -673,4 +673,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public
void
testRewriteFinal
()
{
doTest
();
}
public
void
testFinalGettersForFinalFields
()
{
doTest
();
}
public
void
testInlineSimpleMethods
()
{
doTest
();
}
public
void
testInferenceForNonStableParameters
()
{
doTest
();
}
}
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