mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
CommentTracker: do not add a comment as a first child of PsiElement
Fixes IDEA-187526 "Add static import" with an intervening comment leads to exception
This commit is contained in:
@@ -14,7 +14,7 @@ class Foo {
|
||||
|
||||
void test3(String[] foos, String[] bars) {
|
||||
System.out.println(//line comment
|
||||
asList(foos)+":"+//line comment
|
||||
asList(bars));
|
||||
asList(foos)+":"+//line comment
|
||||
asList(bars));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class X {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("took " + (System//simple end comment
|
||||
.currentTi<caret>meMillis() - 1) + "ms");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
|
||||
class X {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("took " + (//simple end comment
|
||||
currentTimeMillis() - 1) + "ms");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -135,6 +135,10 @@ public class AddSingleStaticImportActionTest extends JavaCodeInsightFixtureTestC
|
||||
doTest("Add static import for 'java.util.Arrays.asList'");
|
||||
}
|
||||
|
||||
public void testLineComment() {
|
||||
doTest("Add static import for 'java.lang.System.currentTimeMillis'");
|
||||
}
|
||||
|
||||
private void doTest(String intentionName) {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
IntentionAction intention = myFixture.findSingleIntention(intentionName);
|
||||
|
||||
@@ -111,15 +111,8 @@ public class CommentTracker {
|
||||
public void deleteAndRestoreComments(@NotNull PsiElement element) {
|
||||
grabCommentsOnDelete(element);
|
||||
PsiElement anchor = element;
|
||||
if (element instanceof PsiVariable) {
|
||||
anchor = element.getParent();
|
||||
}
|
||||
else if ((element.getParent() instanceof PsiJavaCodeReferenceElement &&
|
||||
((PsiJavaCodeReferenceElement)element.getParent()).getQualifier() == element)) {
|
||||
anchor = element.getParent();
|
||||
if (anchor.getParent() instanceof PsiMethodCallExpression) {
|
||||
anchor = anchor.getParent();
|
||||
}
|
||||
while (anchor.getParent() != null && anchor.getParent().getFirstChild() == anchor) {
|
||||
anchor = anchor.getParent();
|
||||
}
|
||||
insertCommentsBefore(anchor);
|
||||
element.delete();
|
||||
|
||||
Reference in New Issue
Block a user