mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
58 lines
2.2 KiB
Java
58 lines
2.2 KiB
Java
package com.intellij.psi;
|
|
|
|
import com.intellij.JavaTestUtil;
|
|
import com.intellij.openapi.application.ApplicationManager;
|
|
import com.intellij.openapi.command.CommandProcessor;
|
|
import com.intellij.openapi.projectRoots.Sdk;
|
|
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
|
import com.intellij.openapi.vfs.VirtualFileFilter;
|
|
import com.intellij.psi.search.GlobalSearchScope;
|
|
import com.intellij.testFramework.PsiTestCase;
|
|
import com.intellij.testFramework.PsiTestUtil;
|
|
import com.intellij.util.IncorrectOperationException;
|
|
|
|
/**
|
|
* @author ven
|
|
*/
|
|
public class ModifyAnnotationsTest extends PsiTestCase {
|
|
@Override
|
|
protected void setUp() throws Exception {
|
|
super.setUp();
|
|
|
|
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/modifyAnnotations";
|
|
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5"));
|
|
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
|
}
|
|
|
|
public void testReplaceAnnotation() throws Exception {
|
|
//be sure not to load tree
|
|
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL);
|
|
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(myProject));
|
|
assertNotNull(aClass);
|
|
final PsiAnnotation[] annotations = aClass.getModifierList().getAnnotations();
|
|
assertEquals(1, annotations.length);
|
|
assertEquals("A", annotations[0].getNameReferenceElement().getReferenceName());
|
|
final PsiAnnotation newAnnotation = myJavaFacade.getElementFactory().createAnnotationFromText("@B", null);
|
|
//here the tree is going to be loaded
|
|
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
|
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
annotations[0].replace(newAnnotation);
|
|
}
|
|
catch (IncorrectOperationException e) {
|
|
LOG.error(e);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}, null, null);
|
|
|
|
assertEquals("@B", aClass.getModifierList().getText());
|
|
}
|
|
}
|