Fixed bug on deannotating: when annotation tag removed, parent is also removed if the latter has no children. Added test.

This commit is contained in:
Evgeny Gerashchenko
2012-09-06 20:46:00 +04:00
parent 9c20a65d0e
commit 37ceccb1eb
4 changed files with 14 additions and 2 deletions
@@ -367,11 +367,11 @@ public class ExternalAnnotationsManagerImpl extends BaseExternalAnnotationsManag
return processExistingExternalAnnotations(listOwner, annotationFQN, new Processor<XmlTag>() {
@Override
public boolean process(XmlTag annotationTag) {
annotationTag.delete();
PsiElement parent = annotationTag.getParent();
annotationTag.delete();
if (parent instanceof XmlTag) {
if (((XmlTag)parent).getSubTags().length == 0) {
annotationTag.delete();
parent.delete();
}
}
return true;
@@ -0,0 +1,5 @@
<root>
<item name='p.TestDeannotation java.lang.String get()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -0,0 +1,5 @@
<root>
<item name='p.TestDeannotation1 java.lang.String get(java.lang.String) 0'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -137,12 +137,14 @@ public class AddAnnotationFixTest extends UsefulTestCase {
addLibrary();
myFixture.configureByFiles("lib/p/TestPrimitive.java", "content/anno/p/annotations.xml");
doDeannotate("lib/p/TestDeannotation.java", "Annotate method 'get' as @NotNull", "Annotate method 'get' as @Nullable");
myFixture.checkResultByFile("content/anno/p/annotations.xml", "content/anno/p/annotationsDeannotation_after.xml", false);
}
public void testDeannotation1() throws Throwable {
addLibrary();
myFixture.configureByFiles("lib/p/TestPrimitive.java", "content/anno/p/annotations.xml");
doDeannotate("lib/p/TestDeannotation1.java", "Annotate parameter 'ss' as @NotNull", "Annotate parameter 'ss' as @Nullable");
myFixture.checkResultByFile("content/anno/p/annotations.xml", "content/anno/p/annotationsDeannotation1_after.xml", false);
}
private void doDeannotate(@NonNls final String testPath, String hint1, String hint2) throws Throwable {