コード例 #1
0
 public CompilationUnitImpl getCompUnit(Class<?> base, String relPath)
     throws CoreException, IOException, DartModelException {
   DartLibraryImpl lib = getDartApp();
   String expected = TestFileUtil.readResource(base, relPath);
   String fileName = relPath.substring(relPath.lastIndexOf('/') + 1);
   IFile file = getOrCreateFile(fileName, expected);
   DefaultWorkingCopyOwner wcopy = DefaultWorkingCopyOwner.getInstance();
   CompilationUnitImpl unit = new CompilationUnitImpl(lib, file, wcopy);
   String actual = unit.getSource();
   assertEquals(expected, actual);
   return unit;
 }
コード例 #2
0
 private IFile getOrCreateFile(String fileName, String expected) throws CoreException {
   final IFile file = getContainer().getFile(new Path(fileName));
   if (file.exists()) {
     return file;
   }
   final InputStream stream = new ByteArrayInputStream(expected.getBytes());
   TestFileUtil.run(
       new IWorkspaceRunnable() {
         @Override
         public void run(IProgressMonitor monitor) throws CoreException {
           file.create(stream, 0, new NullProgressMonitor());
         }
       });
   return file;
 }
コード例 #3
0
 private IProject getProject() throws CoreException {
   if (project == null) {
     project = TestFileUtil.getOrCreateDartProject(getClass().getSimpleName());
   }
   return project;
 }
コード例 #4
0
 private IFile getOrCreateFile(String fileName) throws CoreException, IOException {
   return getOrCreateFile(
       fileName, TestFileUtil.readResource(getClass(), "testsource/" + fileName));
 }
コード例 #5
0
 private IContainer getContainer() throws CoreException {
   if (container == null) {
     container = TestFileUtil.getOrCreateFolder(getProject(), "src");
   }
   return container;
 }