当前位置: 首页>>代码示例>>Java>>正文


Java PsiTestUtil.addSourceRoot方法代码示例

本文整理汇总了Java中com.intellij.testFramework.PsiTestUtil.addSourceRoot方法的典型用法代码示例。如果您正苦于以下问题:Java PsiTestUtil.addSourceRoot方法的具体用法?Java PsiTestUtil.addSourceRoot怎么用?Java PsiTestUtil.addSourceRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.testFramework.PsiTestUtil的用法示例。


在下文中一共展示了PsiTestUtil.addSourceRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupModule

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
private Module setupModule(String moduleName, final String className) throws IOException {
  final VirtualFile root1 = myFixture.getTempDirFixture().findOrCreateDir(moduleName);
  final Module module = PsiTestUtil.addModule(getProject(), JavaModuleType.getModuleType(), moduleName, root1);
  PsiTestUtil.removeAllRoots(module, IdeaTestUtil.getMockJdk18());
  PsiTestUtil.addSourceRoot(module, root1, true);
  myFixture.addFileToProject(moduleName + "/p/" + className + ".java",
                             "package p;\n" +
                             "public class " + className + " extends junit.framework.TestCase {\n" +
                             "  public void testName1(){}" +
                             "}");
  final String pathForClass = PathUtil.getJarPathForClass(TestCase.class);
  PsiTestUtil.addLibrary(module,
                         "junit4",
                         StringUtil.getPackageName(pathForClass, File.separatorChar),
                         StringUtil.getShortName(pathForClass, File.separatorChar));
  return module;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JUnitClasspathTest.java

示例2: setUp

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();
  setupGenericSampleClasses();

  final String testPath = PathManagerEx.getTestDataPath().replace(File.separatorChar, '/') + "/psi/types/" + getTestName(true);
  final VirtualFile[] testRoot = { null };
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      testRoot[0] = LocalFileSystem.getInstance().refreshAndFindFileByPath(testPath);
    }
  });
  if (testRoot[0] != null) {
    PsiTestUtil.addSourceRoot(myModule, testRoot[0]);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:TypesTest.java

示例3: setUp

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();
  String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/searchInLibs";
  VirtualFile rootFile = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);

  final VirtualFile projectRoot = rootFile.findChild("project");
  assertNotNull(projectRoot);

  final VirtualFile innerSourceRoot = projectRoot.findChild("src2");
  assertNotNull(innerSourceRoot);

  VirtualFile libRoot = rootFile.findChild("lib");
  final VirtualFile libClassesRoot = libRoot.findChild("classes");
  final VirtualFile libSrcRoot = libRoot.findChild("src");
  final VirtualFile libSrc2Root = libRoot.findChild("src2");
  assertNotNull(libRoot);

  PsiTestUtil.removeAllRoots(myModule, null);
  PsiTestUtil.addSourceRoot(myModule, projectRoot);
  PsiTestUtil.addSourceRoot(myModule, innerSourceRoot);
  List<String> sourceRoots = Arrays.asList(libSrcRoot.getUrl(), libSrc2Root.getUrl());
  List<String> classesRoots = Collections.singletonList(libClassesRoot.getUrl());
  ModuleRootModificationUtil.addModuleLibrary(myModule, "lib", classesRoots, sourceRoots);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:SearchInLibsTest.java

示例4: testAddSourceRoot

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testAddSourceRoot() throws Exception{
  File dir = createTempDirectory();

  final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));

  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      PsiTestUtil.addContentRoot(myModule, root);

      VirtualFile newFile = root.createChildData(null, "New.java");
      VfsUtil.saveText(newFile, "class A{ Exception e;} //todo");
    }
  }.execute().throwException();

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to initialize caches

  PsiTestUtil.addSourceRoot(myModule, root);

  PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject()));
  assertNotNull(exceptionClass);
  checkUsages(exceptionClass, new String[]{"1.java", "2.java", "New.java"});
  checkTodos(new String[]{"2.java", "New.java"});
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:UpdateCacheTest.java

示例5: setupRootModel

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
@Override
protected void setupRootModel(String testDir, VirtualFile[] sourceDir, String jdkName) {
  super.setupRootModel(testDir, sourceDir, jdkName);
  VirtualFile projectDir = LocalFileSystem.getInstance().findFileByPath(testDir);
  VirtualFile test = projectDir.findChild("test");
  if (test != null) PsiTestUtil.addSourceRoot(myModule, test, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:TestOnlyInspectionTest.java

示例6: testGeneratedSourceRoot

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testGeneratedSourceRoot() throws Exception {
  VirtualFile genRoot = getVirtualFile(createTempDir("genSrcRoot"));
  VirtualFile srcRoot = getVirtualFile(createTempDir("srcRoot"));
  JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("", true);
  PsiTestUtil.addSourceRoot(myModule, genRoot, JavaSourceRootType.SOURCE, properties);
  PsiTestUtil.addSourceRoot(myModule, srcRoot);
  VirtualFile genClass = VfsTestUtil.createFile(genRoot, "Gen.java", "class Gen{}");
  VirtualFile srcClass = VfsTestUtil.createFile(srcRoot, "Src.java", "class Src{}");
  AnalysisScope scope = new AnalysisScope(myModule);
  assertTrue(scope.contains(srcClass));
  assertFalse(scope.contains(genClass));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:AnalysisScopeTest.java

示例7: createModuleWithSourceRoot

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
protected Module createModuleWithSourceRoot(String newModuleName) {
  PsiDirectory dir = createDirectory(getTempRootDirectory().getVirtualFile(), newModuleName);
  String path = dir.getVirtualFile().getPath() + "/" + newModuleName + ".iml";

  Module module = ModuleManager.getInstance(getProject()).newModule(path, StdModuleTypes.JAVA.getId());
  PsiDirectory src = createDirectory(dir.getVirtualFile(), "src");

  PsiTestUtil.addSourceRoot(module, src.getVirtualFile());
  return module;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:AbstractLayoutCodeProcessorTest.java

示例8: testAnnotated

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testAnnotated() throws Throwable {
  PsiFile psiFile = myFixture.configureByFile("lib/p/TestAnnotated.java");
  PsiTestUtil.addSourceRoot(myModule, psiFile.getVirtualFile().getParent());
  final PsiFile file = myFixture.getFile();
  final Editor editor = myFixture.getEditor();
  assertNotAvailable("Annotate method 'get' as @NotNull");
  assertNotAvailable("Annotate method 'get' as @Nullable");

  final DeannotateIntentionAction deannotateFix = new DeannotateIntentionAction();
  assertFalse(deannotateFix.isAvailable(myProject, editor, file));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:AddAnnotationFixTest.java

示例9: testDirectoriesWithPackagePrefix

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testDirectoriesWithPackagePrefix() {
  PsiTestUtil.addSourceRoot(myModule3, myModule3Dir);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      final ModifiableRootModel model = ModuleRootManager.getInstance(myModule3).getModifiableModel();
      model.getContentEntries()[0].getSourceFolders()[0].setPackagePrefix("pack1");
      model.commit();
    }
  });
  checkPackage("pack1", true, myPack1Dir, myModule3Dir);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:DirectoryIndexTest.java

示例10: testModulesWithSameSourceContentRoot

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testModulesWithSameSourceContentRoot() {
  // now our API allows this (ReformatCodeActionTest), although UI doesn't. Maybe API shouldn't allow it as well?
  PsiTestUtil.addContentRoot(myModule2, myModule1Dir);
  PsiTestUtil.addSourceRoot(myModule2, mySrcDir1);

  checkInfo(myModule1Dir, myModule, false, false, null, null);
  checkInfo(mySrcDir1, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule3, myModule);
  checkInfo(myTestSrc1, myModule, false, false, "", JavaSourceRootType.TEST_SOURCE, myModule3, myModule);
  checkInfo(myResDir, myModule, false, false, "", JavaResourceRootType.RESOURCE, myModule);

  checkInfo(mySrcDir2, myModule2, false, false, "", JavaSourceRootType.SOURCE, myModule2, myModule3);
  assertEquals(myModule2Dir, myIndex.getInfoForFile(mySrcDir2).getContentRoot());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:DirectoryIndexTest.java

示例11: testFileSourceRootsUnderDirContentRoot

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testFileSourceRootsUnderDirContentRoot() throws IOException {
  VirtualFile fileSourceRoot = createChildData(myModule1Dir, "fileSourceRoot.txt");
  assertTrue(myFileIndex.isInContent(fileSourceRoot));
  assertFalse(myFileIndex.isInSource(fileSourceRoot));

  PsiTestUtil.addSourceRoot(myModule, fileSourceRoot);
  assertTrue(myFileIndex.isInContent(fileSourceRoot));
  assertTrue(myFileIndex.isInSource(fileSourceRoot));
  checkInfo(fileSourceRoot, myModule, false, false, "", JavaSourceRootType.SOURCE, myModule);

  // removing file source root
  PsiTestUtil.removeSourceRoot(myModule, fileSourceRoot);
  assertTrue(myFileIndex.isInContent(fileSourceRoot));
  assertFalse(myFileIndex.isInSource(fileSourceRoot));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:DirectoryIndexTest.java

示例12: prepareProject

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
@Override
protected void prepareProject(VirtualFile rootDir) {
  PsiTestUtil.addContentRoot(myModule, rootDir);
  final VirtualFile[] children = rootDir.getChildren();
  for (VirtualFile child : children) {
    if (child.getName().startsWith("src")) {
      PsiTestUtil.addSourceRoot(myModule, child);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:MovePackageAsDirectoryTest.java

示例13: setUp

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();
  VirtualFile root = WriteCommandAction.runWriteCommandAction(null, new Computable<VirtualFile>() {
    @Override
    public VirtualFile compute() {
      return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(
        new File(new File(TEST_ROOT), "prj")
      );
    }
  });
  assertNotNull(root);
  PsiTestUtil.addSourceRoot(myModule, root);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:BindToElementTest.java

示例14: setupGenericSampleClasses

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
protected void setupGenericSampleClasses() {
  final String commonPath = PathManagerEx.getTestDataPath().replace(File.separatorChar, '/') + "/psi/types/src";
  final VirtualFile[] commonRoot = { null };
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      commonRoot[0] = LocalFileSystem.getInstance().refreshAndFindFileByPath(commonPath);
    }
  });

  PsiTestUtil.addSourceRoot(myModule, commonRoot[0]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GenericsTestCase.java

示例15: testPrimitive

import com.intellij.testFramework.PsiTestUtil; //导入方法依赖的package包/类
public void testPrimitive() throws Throwable {
  PsiFile psiFile = myFixture.configureByFile("lib/p/TestPrimitive.java");
  PsiTestUtil.addSourceRoot(myModule, psiFile.getVirtualFile().getParent());

  assertNotAvailable("Annotate method 'get' as @NotNull");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:AddAnnotationFixTest.java


注:本文中的com.intellij.testFramework.PsiTestUtil.addSourceRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。