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