Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 private IProject getProject() throws CoreException {
   if (project == null) {
     project = TestFileUtil.getOrCreateDartProject(getClass().getSimpleName());
   }
   return project;
 }
Ejemplo n.º 4
0
 private IFile getOrCreateFile(String fileName) throws CoreException, IOException {
   return getOrCreateFile(
       fileName, TestFileUtil.readResource(getClass(), "testsource/" + fileName));
 }
Ejemplo n.º 5
0
 private IContainer getContainer() throws CoreException {
   if (container == null) {
     container = TestFileUtil.getOrCreateFolder(getProject(), "src");
   }
   return container;
 }