mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline: do not warn about non existing write usages
This commit is contained in:
@@ -32,6 +32,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.controlFlow.DefUseUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
@@ -247,8 +248,8 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if (parent instanceof PsiAssignmentExpression && element == ((PsiAssignmentExpression)parent).getLExpression() ||
|
||||
parent instanceof PsiPrefixExpression || parent instanceof PsiPostfixExpression ) {
|
||||
if (parent instanceof PsiAssignmentExpression && element == ((PsiAssignmentExpression)parent).getLExpression()
|
||||
|| isUnaryWriteExpression(parent)) {
|
||||
|
||||
EditorColorsManager manager = EditorColorsManager.getInstance();
|
||||
final TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
|
||||
@@ -262,6 +263,17 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isUnaryWriteExpression(PsiElement parent) {
|
||||
IElementType tokenType = null;
|
||||
if (parent instanceof PsiPrefixExpression) {
|
||||
tokenType = ((PsiPrefixExpression)parent).getOperationTokenType();
|
||||
}
|
||||
if (parent instanceof PsiPostfixExpression) {
|
||||
tokenType = ((PsiPostfixExpression)parent).getOperationTokenType();
|
||||
}
|
||||
return tokenType == JavaTokenType.PLUSPLUS || tokenType == JavaTokenType.MINUSMINUS;
|
||||
}
|
||||
|
||||
private static boolean isSameDefinition(final PsiElement def, final PsiExpression defToInline) {
|
||||
if (def instanceof PsiLocalVariable) return defToInline.equals(((PsiLocalVariable)def).getInitializer());
|
||||
final PsiElement parent = def.getParent();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test {
|
||||
|
||||
void get(){
|
||||
boolean toInline = false;
|
||||
if (!to<caret>Inline) return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
|
||||
void get(){
|
||||
if (!false) return;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testNonWriteUnaryExpression() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testNewExpression() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user