下面列出了怎么用org.eclipse.jface.text.source.AnnotationModel的API类实例代码及写法,或者点击链接到github查看源代码。
protected void setModel(XtextDocument document, String prefix, String editablePart, String suffix) {
if (this.insertLineBreaks) {
String delimiter = document.getDefaultLineDelimiter();
prefix = prefix + delimiter;
suffix = delimiter + suffix;
}
String model = prefix + editablePart + suffix;
document.set(model);
XtextResource resource = createResource(model);
document.setInput(resource);
AnnotationModel annotationModel = new AnnotationModel();
if (document instanceof ISynchronizable) {
Object lock = ((ISynchronizable) document).getLockObject();
if (lock == null) {
lock = new Object();
((ISynchronizable) document).setLockObject(lock);
}
((ISynchronizable) annotationModel).setLockObject(lock);
}
this.viewer.setDocument(document, annotationModel, prefix.length(), editablePart.length());
}
@Override
public void connect(Object element) throws CoreException {
super.connect(element);
if (getFileInfo(element) != null)
return;
CompilationUnitInfo info= fFakeCUMapForMissingInfo.get(element);
if (info == null) {
ICompilationUnit cu= createFakeCompiltationUnit(element, true);
if (cu == null)
return;
info= new CompilationUnitInfo();
info.fCopy= cu;
info.fElement= element;
info.fModel= new AnnotationModel();
fFakeCUMapForMissingInfo.put(element, info);
}
info.fCount++;
}
@Test
public void testAddEntryWithMultipleModels() {
final AnnotationModel testModel2 = new AnnotationModel();
Pair<IAnnotationModel, List<ContributionAnnotation>> annotationsToRemove =
history.addNewEntry(createDummyAnnotation(testModel2));
assertNull(annotationsToRemove);
for (int i = 1; i < MAX_HISTORY_LENGTH; i++) {
annotationsToRemove = history.addNewEntry(createDummyAnnotation(testModel));
assertNull(annotationsToRemove);
}
annotationsToRemove = history.addNewEntry(createDummyAnnotation(testModel));
assertSame(testModel2, annotationsToRemove.getLeft());
annotationsToRemove = history.addNewEntry(createDummyAnnotation(testModel));
assertSame(testModel, annotationsToRemove.getLeft());
}
@Override
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
if (element instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) element;
return new XtextResourceMarkerAnnotationModel(input.getFile(), issueResolutionProvider, issueUtil);
} else if (element instanceof IURIEditorInput) {
return new AnnotationModel();
}
return super.createAnnotationModel(element);
}
protected XtextSourceViewer createXtextSourceViewer() {
final XtextSourceViewer result = new XtextSourceViewerEx(getStyledText(),
getPreferenceStoreAccess().getPreferenceStore());
result.configure(getXtextSourceViewerConfiguration());
result.setDocument(getXtextDocument(), new AnnotationModel());
return result;
}
public IAnnotationModel createAnnotationModel(IPath path)
{
IResource file = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (file instanceof IFile)
{
return new CommonAnnotationModel(file);
}
return new AnnotationModel();
}
/**
* Creates a new line number ruler column that is appropriately initialized.
*
* @return the created line number column
*/
private CompositeRuler createCompositeRuler( )
{
CompositeRuler ruler = new CompositeRuler( );
ruler.setModel( new AnnotationModel( ) );
return ruler;
}
/**
* Creates a new line number ruler column that is appropriately initialized.
*
* @return the created line number column
*/
private CompositeRuler createCompositeRuler( )
{
CompositeRuler ruler = new CompositeRuler( );
ruler.setModel( new AnnotationModel( ) );
return ruler;
}
@Before
public void setUp() {
store = new PreferenceStore();
store.setValue(EclipsePreferenceConstants.SHOW_CONTRIBUTION_ANNOTATIONS, true);
createListenerMocks();
manager = new ContributionAnnotationManager(sessionMock, store);
model = new AnnotationModel();
}
protected AnnotationModel createAnnotationModel() {
return new AnnotationModel();
}
@Override
protected AnnotationModel createAnnotationModel() {
IFile file = getSelectedFile();
return file != null ? new ResourceMarkerAnnotationModel(file) : super.createAnnotationModel();
}
public SourceViewerConfig(AnnotationModel annotationModel,
Document document) {
strategy = new CommentSpellingReconcileStrategy(annotationModel);
strategy.setDocument(document);
}
public CommentSpellingReconcileStrategy(AnnotationModel annotationModel) {
this.fAnnotationModel = annotationModel;
fSpellingContext = new SpellingContext();
fSpellingContext.setContentType(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT));
}
public IAnnotationModel createAnnotationModel(IPath path) {
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (file instanceof IFile)
return new CompilationUnitAnnotationModel(file);
return new AnnotationModel();
}
@Before
public void setUp() {
history = new ContributionAnnotationHistory(MAX_HISTORY_LENGTH);
testModel = new AnnotationModel();
}
private List<ContributionAnnotation> createDummyAnnotation(final AnnotationModel model) {
final User dummyUser = new User(new JID("[email protected]"), false, false, null);
final ContributionAnnotation dummyAnnotation = new ContributionAnnotation(dummyUser, model);
return Arrays.asList(dummyAnnotation);
}
@Test
public void testHistoryRemovalWithMultipleModels() {
final AnnotationModel model2 = new AnnotationModel();
final AnnotationModel model3 = new AnnotationModel();
final int numberOfInsertions = 5;
// Fill history
for (int i = 0; i < numberOfInsertions; i++) {
manager.insertAnnotation(model2, i, 1, ALICE_TEST_USER);
}
for (int i = 0; i < numberOfInsertions; i++) {
manager.insertAnnotation(model3, i, 1, ALICE_TEST_USER);
}
int offset = 0;
final int remainingInsertions = MAX_HISTORY_LENGTH - 2 * numberOfInsertions;
for (int i = 0; i < remainingInsertions; i++, offset++) {
manager.insertAnnotation(model, offset, 1, ALICE_TEST_USER);
}
assertEquals(remainingInsertions, getAnnotationCount(model));
assertEquals(numberOfInsertions, getAnnotationCount(model2));
assertEquals(numberOfInsertions, getAnnotationCount(model3));
for (int i = 0; i < numberOfInsertions; i++, offset++) {
manager.insertAnnotation(model, offset, 1, ALICE_TEST_USER);
}
assertEquals(remainingInsertions + numberOfInsertions, getAnnotationCount(model));
assertEquals(
"Insertions in another model should lead to removing all annotations in the model",
0,
getAnnotationCount(model2));
assertEquals(numberOfInsertions, getAnnotationCount(model3));
for (int i = 0; i < numberOfInsertions; i++, offset++) {
manager.insertAnnotation(model, offset, 1, ALICE_TEST_USER);
}
assertEquals(remainingInsertions + 2 * numberOfInsertions, getAnnotationCount(model));
assertEquals(0, getAnnotationCount(model2));
assertEquals(
"Insertions in another model should lead to removing all annotations in the model",
0,
getAnnotationCount(model3));
}