There were a few different versions. This is the way it
should be done:
// get a file from the project
IFile file = getProject().getFile(fileName);
// get the equivalent model – for read or
edit
final IStructuredModel
modelForEdit = StructuredModelManager.getModelManager().getModelForEdit(file);
try {
// get the document
final IStructuredDocument document = modelForEdit.getStructuredDocument();
// do the test here
// ...
// ...
} finally {
// release the model from read or edit
if (modelForEdit != null) {
modelForEdit.releaseFromEdit();
}
}
|