本文整理汇总了Java中com.intellij.testFramework.PsiTestUtil类的典型用法代码示例。如果您正苦于以下问题:Java PsiTestUtil类的具体用法?Java PsiTestUtil怎么用?Java PsiTestUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiTestUtil类属于com.intellij.testFramework包,在下文中一共展示了PsiTestUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
private void doTest(String className) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject,
classToInline,
null, false, false, false);
UsageInfo[] usages = processor.findUsages();
MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
assertEquals(0, conflicts.size());
processor.run();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例2: setUpProject
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
@Override
protected void setUpProject() throws Exception {
final String root = PathManagerEx.getTestDataPath() + BASE_PATH;
VirtualFile tempProjectRootDir =
PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);
VirtualFile projectFile = tempProjectRootDir.findChild("orderEntry.ipr");
myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
UIUtil.dispatchAllInvocationEvents(); // startup activities
setUpJdk();
myModule = ModuleManager.getInstance(getProject()).getModules()[0];
}
示例3: testMultipleFiles
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testMultipleFiles() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile first = root.findFileByRelativePath("from/1.txt");
assertNotNull(first);
final VirtualFile second = root.findFileByRelativePath("from/2.txt");
assertNotNull(second);
final PsiFile firstPsi = myPsiManager.findFile(first);
final PsiFile secondPsi = myPsiManager.findFile(second);
assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi, secondPsi}));
final VirtualFile toDir = root.findChild("to");
assertNotNull(toDir);
final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
CopyHandler.doCopy(new PsiElement[]{firstPsi, secondPsi}, targetDirectory);
assertNotNull(root.findFileByRelativePath("to/1.txt"));
assertNotNull(root.findFileByRelativePath("to/2.txt"));
}
示例4: doTest
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
private void doTest(String className, String methodName) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertTrue(aClass != null);
PsiElement element = aClass.findMethodsByName(methodName, false)[0];
assertTrue(element instanceof PsiMethod);
PsiMethod method = (PsiMethod)element;
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
assertFalse("Bad returns found", condition);
InlineOptions options = new MockInlineMethodOptions();
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly());
processor.run();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例5: testModuleUnderIgnoredDir
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testModuleUnderIgnoredDir() throws IOException {
final VirtualFile ignored = createChildDirectory(myRootVFile, "RCS");
assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
assertTrue(myFileIndex.isExcluded(ignored));
assertTrue(myFileIndex.isUnderIgnored(ignored));
final VirtualFile module4 = createChildDirectory(ignored, "module4");
assertFalse(FileTypeManager.getInstance().isFileIgnored(module4));
assertTrue(myFileIndex.isExcluded(module4));
assertTrue(myFileIndex.isUnderIgnored(module4));
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
PsiTestUtil.addContentRoot(module, module4);
assertNotInProject(ignored);
checkInfo(module4, module, false, false, null, null);
}
}.execute().throwException();
}
示例6: testModuleInIgnoredDir
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testModuleInIgnoredDir() throws IOException {
final VirtualFile ignored = createChildDirectory(myRootVFile, "RCS");
assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
ModifiableModuleModel model = moduleManager.getModifiableModel();
model.disposeModule(myModule);
model.disposeModule(myModule2);
model.disposeModule(myModule3);
model.commit();
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
PsiTestUtil.addContentRoot(module, ignored);
checkInfo(ignored, module, false, false, null, null);
}
}.execute().throwException();
}
示例7: doPackageCopy
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
private void doPackageCopy() throws Exception {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile targetVDir = rootDir.findChild("p2");
final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
final PsiDirectory targetP2Dir = myPsiManager.findDirectory(targetVDir);
new CopyClassesHandler().doCopy(new PsiElement[]{sourceP1Dir}, targetP2Dir);
String rootAfter = root + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
示例8: testExcludesShouldBeRecognizedRightOnRefresh
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception {
final VirtualFile dir = createChildDirectory(myModule1Dir, "dir");
final VirtualFile excluded = createChildDirectory(dir, "excluded");
PsiTestUtil.addExcludedRoot(myModule, excluded);
delete(dir);
boolean created = new File(myModule1Dir.getPath(), "dir/excluded/foo").mkdirs();
assertTrue(created);
VirtualFileListener l = new VirtualFileAdapter() {
@Override
public void fileCreated(@NotNull VirtualFileEvent e) {
assertEquals("dir", e.getFileName());
VirtualFile file = e.getFile();
assertInProject(file);
assertExcluded(file.findFileByRelativePath("excluded"), myModule);
assertExcluded(file.findFileByRelativePath("excluded/foo"), myModule);
}
};
VirtualFileManager.getInstance().addVirtualFileListener(l, getTestRootDisposable());
VirtualFileManager.getInstance().syncRefresh();
}
示例9: testFileModuleExcludeRootUnderFileRoot
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testFileModuleExcludeRootUnderFileRoot() throws IOException {
VirtualFile fileRoot = createChildData(myRootVFile, "fileRoot.txt");
PsiTestUtil.addContentRoot(myModule, fileRoot);
checkInfo(fileRoot, myModule, false, false, "", null);
assertTrue(myFileIndex.isInContent(fileRoot));
assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null);
PsiTestUtil.addExcludedRoot(myModule, fileRoot);
assertFalse(myFileIndex.isInContent(fileRoot));
assertExcluded(fileRoot, myModule);
assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot));
// removing file exclude root
PsiTestUtil.removeExcludedRoot(myModule, fileRoot);
checkInfo(fileRoot, myModule, false, false, "", null);
assertTrue(myFileIndex.isInContent(fileRoot));
assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null);
}
示例10: createModule
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
protected void createModule(VirtualFile module1Content, boolean addSource) throws IOException {
Module module = createEmptyModule();
if (addSource) {
PsiTestUtil.addSourceRoot(module, module1Content, true);
}
else {
PsiTestUtil.addContentRoot(module, module1Content);
}
VirtualFile mockJUnit = findFile(MOCK_JUNIT);
ModuleRootModificationUtil.addModuleLibrary(module, mockJUnit.getUrl());
ModuleRootModificationUtil.setModuleSdk(module, ModuleRootManager.getInstance(myModule).getSdk());
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
VirtualFile testCase = mockJUnit.findFileByRelativePath("junit/framework/TestCase.java");
assertNotNull(testCase);
assertTrue(scope.contains(testCase));
Module missingModule = createTempModule();
addDependency(module, missingModule);
ModuleManager.getInstance(myProject).disposeModule(missingModule);
}
示例11: testNoGotoImplementationOutsideSourceRoot
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testNoGotoImplementationOutsideSourceRoot() throws Throwable {
final TempDirTestFixture dirFixture = new TempDirTestFixtureImpl();
dirFixture.setUp();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final VirtualFile outside = dirFixture.getFile("").createChildDirectory(this, "outside");
PsiTestUtil.addContentRoot(myModule, outside);
VirtualFile out = outside.createChildData(this, "Outside.groovy");
VfsUtil.saveText(out, "class Bar {}\n class Goo extends Bar {}");
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
}.execute();
try {
PsiFile inProject = myFixture.addFileToProject("Foo.groovy", "class <caret>Foo {}\n class Bar extends Foo {}");
myFixture.configureFromExistingVirtualFile(inProject.getVirtualFile());
final PsiElement[] impls = new GotoImplementationHandler().getSourceAndTargetElements(myFixture.getEditor(), inProject).targets;
assertEquals(1, impls.length);
}
finally {
dirFixture.tearDown();
}
}
示例12: testJarRefreshOnRenameOrMove
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testJarRefreshOnRenameOrMove() throws IOException {
File jar = IoTestUtil.createTestJar();
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
assertNotNull(vFile);
new WriteCommandAction.Simple(myProject) {
@Override
protected void run() throws Throwable {
PsiTestUtil.addContentRoot(myModule, vFile.getParent());
}
}.execute();
VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR);
final PsiFile file = getPsiManager().findFile(vFile);
final String newName = vFile.getName() + ".jar";
rename(file, newName);
assertFalse(jarRoot.isValid());
checkMove(jar, vFile, file);
}
示例13: addModule
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
protected Module addModule(final String name, final boolean withSource) {
return new WriteCommandAction<Module>(getProject()) {
@Override
protected void run(@NotNull Result<Module> result) throws Throwable {
final VirtualFile depRoot = myFixture.getTempDirFixture().findOrCreateDir(name);
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
String moduleName = moduleModel.newModule(depRoot.getPath() + "/" + name + ".iml", StdModuleTypes.JAVA.getId()).getName();
moduleModel.commit();
final Module dep = ModuleManager.getInstance(getProject()).findModuleByName(moduleName);
ModuleRootModificationUtil.setModuleSdk(dep, ModuleRootManager.getInstance(myModule).getSdk());
if (withSource) {
PsiTestUtil.addSourceRoot(dep, depRoot);
} else {
PsiTestUtil.addContentRoot(dep, depRoot);
}
IdeaTestUtil.setModuleLanguageLevel(dep, LanguageLevelModuleExtensionImpl.getInstance(myModule).getLanguageLevel());
result.setResult(dep);
}
}.execute().getResultObject();
}
示例14: setUp
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationManager.getApplication().runWriteAction(
new Runnable() {
@Override
public void run() {
try{
String rootPath = JavaTestUtil.getJavaTestDataPath() + "/psi/constantValues";
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootPath, myFilesToDelete, true);
ModuleRootModificationUtil.addModuleLibrary(myModule, root.getUrl());
}
catch(Exception e){
LOG.error(e);
}
}
}
);
myClass = myJavaFacade.findClass("ClassWithConstants", GlobalSearchScope.allScope(getProject()));
assertNotNull(myClass);
assertEquals(StdFileTypes.JAVA, myClass.getContainingFile().getVirtualFile().getFileType());
}
示例15: testCreateFile
import com.intellij.testFramework.PsiTestUtil; //导入依赖的package包/类
public void testCreateFile() throws Throwable {
new WriteCommandAction.Simple(myProject) {
@Override
protected void run() throws Throwable {
final VirtualFile dir = getVirtualFile(createTempDirectory());
PsiTestUtil.addSourceContentToRoots(getModule(), dir);
final VirtualFile childData = dir.createChildData(this, "abc.xml");
System.gc();
System.gc();
System.gc();
System.gc();
assertResultsAndClear();
VfsUtil.saveText(childData, "<a/>");
assertEventCount(0);
assertResultsAndClear();
}
}.execute().throwException();
}