retrieve type from binary comparisons to detect applicable constants (IDEA-165557)

This commit is contained in:
Anna.Kozlova
2016-12-16 13:44:34 +01:00
parent 12e86f8f1d
commit d7f10b93e1
3 changed files with 43 additions and 0 deletions

View File

@@ -78,6 +78,17 @@ abstract class StaticMembersProcessor<T extends PsiMember & PsiDocCommentOwner>
return ((PsiAssignmentExpression)parent).getLExpression().getType();
}
}
else if (parent instanceof PsiBinaryExpression && JavaTokenType.EQEQ.equals(((PsiBinaryExpression)parent).getOperationTokenType())) {
if (myPlace.equals(PsiUtil.skipParenthesizedExprDown(((PsiBinaryExpression)parent).getROperand()))) {
return ((PsiBinaryExpression)parent).getLOperand().getType();
}
if (myPlace.equals(PsiUtil.skipParenthesizedExprDown(((PsiBinaryExpression)parent).getLOperand()))) {
PsiExpression rOperand = ((PsiBinaryExpression)parent).getROperand();
if (rOperand != null) {
return rOperand.getType();
}
}
}
else if (parent instanceof PsiReturnStatement) {
return PsiTypesUtil.getMethodReturnType(parent);
}

View File

@@ -0,0 +1,17 @@
// "Import static constant 'foo.B.aaaaaaa'" "true"
package foo;
import static foo.B.aaaaaaa;
public class X {
{
if (1 == aaaaaaa);
}
}
class B {
public static Integer aaaaaaa = 1;
}
class B1 {
public static String aaaaaaa = "";
}

View File

@@ -0,0 +1,15 @@
// "Import static constant 'foo.B.aaaaaaa'" "true"
package foo;
public class X {
{
if (1 == <caret>aaaaaaa);
}
}
class B {
public static Integer aaaaaaa = 1;
}
class B1 {
public static String aaaaaaa = "";
}