use of org.eclipse.jface.text.IDocumentPartitioner in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class DocumentSetupParticipant method setup.
@Override
public void setup(final IDocument document) {
if (document instanceof IDocumentExtension3) {
final IDocumentExtension3 extension3 = (IDocumentExtension3) document;
final IDocumentPartitioner partitioner = new FastPartitioner(Activator.getDefault().getTestFilePartitionScanner(), TestFile.PARTITION_TYPES);
extension3.setDocumentPartitioner("__rts_partitioning", partitioner);
partitioner.connect(document);
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestReload.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private void doTestReload(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredModel model = modelManager.getNewModelForEdit(file, true);
try {
assertNotNull(model);
IStructuredDocument document = model.getStructuredDocument();
assertNotNull(document);
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
InputStream inStream = null;
try {
inStream = file.getContents();
model.reload(inStream);
assertNotNull(model);
IStructuredDocument documentReloaded = model.getStructuredDocument();
// note: NOT same instance of document
// FIXME: this test has to be changed back, once the reload
// API is
// fixed to work with different document.
// assertFalse(document == documentReloaded);
assertTrue(document == documentReloaded);
} finally {
if (inStream != null) {
inStream.close();
}
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestCreateModelWithNonExistIFile.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private String doTestCreateModelWithNonExistIFile(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
// file will be null if the resource does not exist
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredModel model = modelManager.getNewModelForEdit(file, false);
try {
assertNotNull(model);
IStructuredDocument document = model.getStructuredDocument();
assertNotNull(document);
contents = document.get();
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
} finally {
if (model != null)
model.releaseFromEdit();
}
return contents;
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method testGetDefaultPartitionType.
public void testGetDefaultPartitionType() {
IStructuredModel model = null;
try {
model = getModelForEdit("testfiles/html/example01.xml");
if (model != null) {
IStructuredDocument sDoc = model.getStructuredDocument();
assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
String defaultPartitionType = stp.getDefaultPartitionType();
assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
} else {
assertTrue("could not retrieve structured model", false);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class AbstractDocumentLoader method createNewStructuredDocument.
/**
* This method must return a new instance of IEncodedDocument, that has
* been initialized with appropriate parser. For many loaders, the
* (default) parser used is known for any input. For others, the correct
* parser (and its initialization) is normally dependent on the content of
* the file. This no-argument method should assume "empty input" and would
* therefore return the default parser for the default contentType.
*/
public IEncodedDocument createNewStructuredDocument() {
IEncodedDocument structuredDocument = newEncodedDocument();
// Make sure every structuredDocument has an Encoding Memento,
// which is the default one for "empty" structuredDocuments
String charset = ContentTypeEncodingPreferences.useDefaultNameRules(getDocumentEncodingDetector());
String specDefaultCharset = getDocumentEncodingDetector().getSpecDefaultEncoding();
structuredDocument.setEncodingMemento(CodedIO.createEncodingMemento(charset, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT, specDefaultCharset));
String lineDelimiter = getPreferredNewLineDelimiter(null);
if (lineDelimiter != null)
structuredDocument.setPreferredLineDelimiter(lineDelimiter);
IDocumentPartitioner defaultPartitioner = getDefaultDocumentPartitioner();
if (structuredDocument instanceof IDocumentExtension3) {
((IDocumentExtension3) structuredDocument).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, defaultPartitioner);
} else {
structuredDocument.setDocumentPartitioner(defaultPartitioner);
}
defaultPartitioner.connect(structuredDocument);
return structuredDocument;
}
Aggregations