use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.
the class ModelHandlerRegistryTest method testGetHandler.
public void testGetHandler() throws Exception {
IProject project = setUp(getName());
IFile file = project.getFile(FILE);
IModelHandler handler;
try {
handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
assertNotNull("Model handler default should not be null.", handler);
assertEquals("Proper default model handler was not returned.", handler.getId(), "org.eclipse.wst.xml.core.modelhandler");
} catch (CoreException e) {
fail("Caught exception: " + e);
}
tearDown(getName());
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.
the class ExclusivePositionUpdaterTest method createDocument.
private IDocument createDocument(String contents) {
IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.jst.jsp.jspsource");
BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
document.set(contents);
return document;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.
the class StructuredFileTaskScanner method findTasks.
private void findTasks(IFile file, final TaskTag[] taskTags, final IProgressMonitor monitor) {
try {
IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
// records if the optimized streamish parse was possible
boolean didStreamParse = false;
final IEncodedDocument defaultDocument = handler.getDocumentLoader().createNewStructuredDocument();
if (defaultDocument instanceof IStructuredDocument) {
RegionParser parser = ((IStructuredDocument) defaultDocument).getParser();
if (parser instanceof StructuredDocumentRegionParser) {
didStreamParse = true;
String charset = detectCharset(file);
StructuredDocumentRegionParser documentParser = (StructuredDocumentRegionParser) parser;
final IDocument textDocument = new Document();
setDocumentContent(textDocument, file.getContents(true), charset);
monitor.beginTask("", textDocument.getLength());
documentParser.reset(new DocumentReader(textDocument));
documentParser.addStructuredDocumentRegionHandler(new StructuredDocumentRegionHandler() {
public void nodeParsed(IStructuredDocumentRegion documentRegion) {
ITextRegionList regions = documentRegion.getRegions();
for (int j = 0; j < regions.size(); j++) {
ITextRegion comment = regions.get(j);
findTasks(textDocument, taskTags, documentRegion, comment);
}
// disconnect the document regions
if (documentRegion.getPrevious() != null) {
documentRegion.getPrevious().setPrevious(null);
documentRegion.getPrevious().setNext(null);
}
if (monitor.isCanceled()) {
// $NON-NLS-1$
textDocument.set("");
}
monitor.worked(documentRegion.getLength());
}
public void resetNodes() {
}
});
documentParser.getDocumentRegions();
}
}
if (!didStreamParse) {
// Use a StructuredDocument
IEncodedDocument document = handler.getDocumentLoader().createNewStructuredDocument(file);
monitor.beginTask("", document.getLength());
if (document instanceof IStructuredDocument) {
IStructuredDocumentRegion documentRegion = ((IStructuredDocument) document).getFirstStructuredDocumentRegion();
while (documentRegion != null) {
ITextRegionList regions = documentRegion.getRegions();
for (int j = 0; j < regions.size(); j++) {
ITextRegion comment = regions.get(j);
findTasks(document, taskTags, documentRegion, comment);
}
monitor.worked(documentRegion.getLength());
documentRegion = documentRegion.getNext();
}
}
}
} catch (CoreException e) {
// $NON-NLS-1$
Logger.logException("Exception with " + file.getFullPath().toString(), e);
} catch (CharacterCodingException e) {
// $NON-NLS-1$
Logger.log(Logger.INFO, "StructuredFileTaskScanner encountered CharacterCodingException reading " + file.getFullPath());
} catch (Exception e) {
// $NON-NLS-1$
Logger.logException("Exception with " + file.getFullPath().toString(), e);
}
monitor.done();
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.
the class BasicStructuredDocumentFactory method createDocument.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.filebuffers.IDocumentFactory#createDocument()
*/
public IDocument createDocument() {
IDocument document = null;
IContentType contentType = Platform.getContentTypeManager().getContentType(getContentTypeIdentifier());
IModelHandler handler = null;
while (handler == null && !IContentTypeManager.CT_TEXT.equals(contentType.getId())) {
handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId(contentType.getId());
contentType = contentType.getBaseType();
}
if (handler != null) {
document = handler.getDocumentLoader().createNewStructuredDocument();
} else {
document = new JobSafeStructuredDocument();
}
return document;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.
the class AbstractUndoManagerTest method createDocument.
private IDocument createDocument(String contents) {
IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.core.runtime.xml");
BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
document.set(contents);
// return new Document(contents);
return document;
}
Aggregations