mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
introduce over non-valid expression (IDEA-26836)
This commit is contained in:
@@ -194,12 +194,20 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
return tempExpr;
|
||||
}
|
||||
|
||||
public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, final int startOffset, final int endOffset) {
|
||||
public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, int startOffset, int endOffset) {
|
||||
|
||||
final PsiElement elementAtStart = file.findElementAt(startOffset);
|
||||
if (elementAtStart == null) return null;
|
||||
final PsiElement elementAtEnd = file.findElementAt(endOffset - 1);
|
||||
if (elementAtEnd == null) return null;
|
||||
PsiElement elementAtStart = file.findElementAt(startOffset);
|
||||
if (elementAtStart == null || elementAtStart instanceof PsiWhiteSpace || elementAtStart instanceof PsiComment) {
|
||||
elementAtStart = PsiTreeUtil.skipSiblingsForward(elementAtStart, PsiWhiteSpace.class, PsiComment.class);
|
||||
if (elementAtStart == null) return null;
|
||||
startOffset = elementAtStart.getTextOffset();
|
||||
}
|
||||
PsiElement elementAtEnd = file.findElementAt(endOffset - 1);
|
||||
if (elementAtEnd == null || elementAtEnd instanceof PsiWhiteSpace || elementAtEnd instanceof PsiComment) {
|
||||
elementAtEnd = PsiTreeUtil.skipSiblingsBackward(elementAtEnd, PsiWhiteSpace.class, PsiComment.class);
|
||||
if (elementAtEnd == null) return null;
|
||||
endOffset = elementAtEnd.getTextRange().getEndOffset();
|
||||
}
|
||||
|
||||
PsiExpression tempExpr;
|
||||
PsiElement elementAt = PsiTreeUtil.findCommonParent(elementAtStart, elementAtEnd);
|
||||
@@ -295,7 +303,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
tempExpr.putUserData(ElementToWorkOn.PARENT, parent);
|
||||
}
|
||||
else {
|
||||
PsiErrorElement errorElement = PsiTreeUtil.getNextSiblingOfType(elementAtStart, PsiErrorElement.class);
|
||||
PsiErrorElement errorElement = elementAtStart instanceof PsiErrorElement
|
||||
? (PsiErrorElement)elementAtStart
|
||||
: PsiTreeUtil.getNextSiblingOfType(elementAtStart, PsiErrorElement.class);
|
||||
if (errorElement == null) {
|
||||
errorElement = PsiTreeUtil.getParentOfType(elementAtStart, PsiErrorElement.class);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
public void test(boolean a, boolean b) {
|
||||
final boolean ab = a &&
|
||||
b;
|
||||
if (true && ab
|
||||
//some comment
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
public void test(boolean a, boolean b) {
|
||||
if (true && <selection>a &&
|
||||
b
|
||||
//some comment
|
||||
</selection>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -198,6 +198,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
public void testAndAndSubexpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean"));
|
||||
}
|
||||
|
||||
public void testSubexpressionWithSpacesInSelection() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean"));
|
||||
}
|
||||
|
||||
public void testDuplicatesAnonymousClassCreationWithSimilarParameters () throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("foo1", true, true, false, "Foo"));
|
||||
|
||||
Reference in New Issue
Block a user