SimpleMethodInliner: support lambdas/method refs/casts/array accesses

This commit is contained in:
Tagir Valeev
2019-01-21 15:16:54 +07:00
parent e66bf9e0ab
commit cd40025bd1
2 changed files with 23 additions and 1 deletions
@@ -48,7 +48,9 @@ public class SimpleMethodInliner implements CallInliner {
boolean allowed = PsiTreeUtil.processElements(value, e -> {
if (!(e instanceof PsiExpression)) return true;
if (e instanceof PsiInstanceOfExpression || e instanceof PsiParenthesizedExpression || e instanceof PsiLiteralExpression ||
e instanceof PsiPolyadicExpression || e instanceof PsiUnaryExpression || e instanceof PsiConditionalExpression) {
e instanceof PsiPolyadicExpression || e instanceof PsiUnaryExpression || e instanceof PsiConditionalExpression ||
e instanceof PsiTypeCastExpression || e instanceof PsiArrayAccessExpression || e instanceof PsiLambdaExpression ||
e instanceof PsiMethodReferenceExpression) {
return true;
}
if (e instanceof PsiReferenceExpression) {
@@ -32,4 +32,24 @@ class Scratch {
private boolean hasData() {
return data != null && data.length > 0;
}
int[] array;
private int readValue() {
return array[0];
}
void testArraySize() {
if(readValue() > 0 && <warning descr="Condition 'array.length > 0' is always 'true' when reached">array.length > 0</warning>) {}
}
Object element;
private String getString() {
return ((String)element);
}
void testGetString() {
if(!getString().isEmpty() && <warning descr="Condition 'element instanceof String' is always 'true' when reached">element instanceof String</warning>) {}
}
}