Skip to content

Commit

Permalink
add null checks for constructor body
Browse files Browse the repository at this point in the history
  • Loading branch information
nnym committed Feb 12, 2022
1 parent e866b9e commit 6c60c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion idea/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("org.jetbrains.intellij").version("latest.integration")
}

version("0.2.0")
version("0.2.1")
javaVersion(11)

sourceSets {
Expand Down
17 changes: 8 additions & 9 deletions idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,16 @@ private static boolean matches(HighlightInfo info, String key, String... argumen
}

private static boolean initialized(PsiMethod constructor, PsiField field) {
return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, constructor.getBody()) || Stream.of(constructor.getBody().getChildren()).anyMatch(child -> {
if (child instanceof PsiExpressionStatement) {
var expression = ((PsiExpressionStatement) child).getExpression();

if (expression instanceof PsiMethodCallExpression) {
return initialized(((PsiMethodCallExpression) expression).resolveMethod(), field);
}
}
var body = constructor.getBody();

if (body == null) {
return false;
});
}

return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, body)
|| Stream.of(body.getChildren())
.filter(PsiExpressionStatement.class::isInstance)
.map(statement -> ((PsiExpressionStatement) statement).getExpression())
.anyMatch(expression -> expression instanceof PsiMethodCallExpression && initialized(((PsiMethodCallExpression) expression).resolveMethod(), field));
}
}

0 comments on commit 6c60c75

Please sign in to comment.