/** * Returns a document representing the file. Note that * this document will not be synchronized with changes to * the file. It will simply be a snapshot of the file. * * Returns null if unsuccessful. * * @param module * @return */ public static IDocument getDocFromFile(IFile file) { /* * We need a file document provider to create * the document. After the document is created * the file document provider must be disconnected * to avoid a memory leak. */ FileDocumentProvider fdp = new FileDocumentProvider(); FileEditorInput input = new FileEditorInput(file); try { fdp.connect(input); return fdp.getDocument(input); } catch (CoreException e) { Activator.getDefault().logError("Error getting document for module " + file, e); } finally { fdp.disconnect(input); } return null; }
IDocument moduleNameToIDocument(String moduleName) { IDocument result = this.moduleNameToDoc.get(moduleName) ; if (result == null ) { IFile moduleIFile = (IFile) ResourceHelper .getResourceByModuleName(moduleName); FileEditorInput fileEditorInput = new FileEditorInput(moduleIFile); FileDocumentProvider moduleFileDocProvider = new FileDocumentProvider(); try { moduleFileDocProvider.connect(fileEditorInput); } catch (CoreException e1) { // I don't know what to do here MessageDialog.openError(UIHelper.getShellProvider().getShell(), "Decompose Proof Command", "An error that should not happen has occurred in " + "line 2737 of NewDecomposeProofHandler."); } result = moduleFileDocProvider.getDocument(fileEditorInput); } return result ; }
public SourceEditor() { setSourceViewerConfiguration(new TextUMLSourceViewerConfiguration(this)); // set the document provider to create the partitioner setDocumentProvider(new FileDocumentProvider() { protected IDocument createDocument(Object element) throws CoreException { IDocument document = super.createDocument(element); if (document != null) { // this will create partitions IDocumentPartitioner partitioner = new FastPartitioner(new PartitionScanner(), ContentTypes.CONFIGURED_CONTENT_TYPES); partitioner.connect(document); document.setDocumentPartitioner(partitioner); } return document; } }); }