Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pdt-dev] Getting the structured model in unit tests

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();

            }

      }

 

 


Back to the top