use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class FileBufferDocumentTester method doTestCreate.
private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
IFile file = (IFile) fTestProject.findMember(filePath);
System.out.println(fTestProject.getLocation().toOSString());
assertNotNull("Test Case in error. Could not find file " + filePath, file);
IPath locationPath = file.getLocation();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(locationPath, null);
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
IDocument document = buffer.getDocument();
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));
bufferManager.disconnect(locationPath, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestNotEmptyDocument.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private void doTestNotEmptyDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredDocument document = modelManager.createStructuredDocumentFor(file);
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));
contents = document.get();
assertNotNull("contents were null", contents);
assertTrue("contents were empty", contents.length() > 0);
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestCreate.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private String doTestCreate(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, true);
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));
testClone(model);
} finally {
if (model != null)
model.releaseFromEdit();
}
return contents;
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestNonExistentDocument.
private void doTestNonExistentDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
boolean expectedExceptionCaught = false;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredDocument document = null;
try {
document = modelManager.createStructuredDocumentFor(file);
} catch (FileNotFoundException e) {
expectedExceptionCaught = true;
}
if (expectedExceptionCaught) {
document = modelManager.createNewStructuredDocumentFor(file);
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));
contents = document.get();
assertNotNull("contents were null", contents);
assertTrue("contents were *not* empty as expected", contents.length() == 0);
} else {
assertTrue("FileNotFound exception was *not* thrown as expected", false);
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class BasicStructuredDocument method getPartition.
public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (offset > getLength()))
throw new BadLocationException();
ITypedRegion result = null;
IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
if (partitioner instanceof IDocumentPartitionerExtension2) {
result = ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions);
} else if (partitioner != null) {
result = partitioner.getPartition(offset);
} else if (IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING.equals(partitioning)) {
result = new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE);
} else
throw new BadPartitioningException();
return result;
}
Aggregations