本文整理匯總了Java中org.eclipse.jface.text.source.IAnnotationModel.addAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java IAnnotationModel.addAnnotation方法的具體用法?Java IAnnotationModel.addAnnotation怎麽用?Java IAnnotationModel.addAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.source.IAnnotationModel
的用法示例。
在下文中一共展示了IAnnotationModel.addAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleCompilerExceptions
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
private void handleCompilerExceptions(MplAnnotationType type,
ImmutableListMultimap<File, CompilerException> exceptions) {
for (Entry<File, Collection<CompilerException>> entry : exceptions.asMap().entrySet()) {
File file = entry.getKey();
TextEditor editor = editors.get(file.toPath());
if (editor != null) {
IAnnotationModel annotationModel = editor.getSourceViewer().getAnnotationModel();
for (CompilerException ex : entry.getValue()) {
MplAnnotation annotation = new MplAnnotation(type, ex.getLocalizedMessage());
MplSource source = ex.getSource();
Position position = new Position(source.getStartIndex(), source.getLength());
annotationModel.addAnnotation(annotation, position);
}
}
}
}
示例2: loadTranslation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
@Override
public String loadTranslation(BTSText text, String language,
IAnnotationModel annotationModel) {
if (text.getTextContent() == null || text.getTextContent().getTextItems().isEmpty()) return "";
StringBuilder stringBuilder = new StringBuilder();
for (BTSTextItems tItem : text.getTextContent().getTextItems())
{
if (tItem instanceof BTSSenctence)
{
BTSSenctence sentence = (BTSSenctence) tItem;
BTSModelAnnotation ma = new BTSSentenceAnnotation(BTSSentenceAnnotation.TYPE,sentence);
int start = stringBuilder.length();
stringBuilder.append(createSentenceTranslationLabel(sentence, language));
int len = stringBuilder.length() - start;
Position pos = new Position(start, len);
if (annotationModel != null) annotationModel.addAnnotation(ma, pos);
}
}
return stringBuilder.toString();
}
示例3: appendWordToModel
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
private void appendWordToModel(BTSWord word, IAnnotationModel model, Position position, Map<String, List<Object>> lemmaAnnotationMap)
{
if (model == null) return;
BTSModelAnnotation annotation;
if (word.getLKey() != null && !"".equals(word.getLKey())) {
annotation = new BTSLemmaAnnotation(BTSLemmaAnnotation.TYPE, word);
if (lemmaAnnotationMap != null)
{
add2LemmaAnnotationMap(word.getLKey(), annotation, lemmaAnnotationMap);
}
} else {
annotation = new BTSModelAnnotation(BTSModelAnnotation.TOKEN,
(BTSIdentifiableItem) word);
}
model.addAnnotation(annotation, position);
}
示例4: run
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
@Override
public void run() {
ITextEditor editor = getTextEditor();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
if (!textSelection.isEmpty()) {
IAnnotationModel model = getAnnotationModel(editor);
if (model != null) {
int start = textSelection.getStartLine();
int end = textSelection.getEndLine();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = document.getLineOffset(start);
int endOffset = document.getLineOffset(end + 1);
Position position = new Position(offset, endOffset - offset);
model.addAnnotation(new ProjectionAnnotation(), position);
} catch (BadLocationException x) {
// ignore
}
}
}
}
}
示例5: setLineBackground
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
public void setLineBackground() {
// TODO who deletes stale annotations after editor refresh?
List<PgObjLocation> refs = getParser().getObjsForEditor(getEditorInput());
IAnnotationModel model = getSourceViewer().getAnnotationModel();
for (PgObjLocation loc : refs) {
String annotationMsg = null;
if (loc.getAction() == StatementActions.DROP && loc.getObjType() == DbObjType.TABLE){
annotationMsg = "DROP TABLE statement"; //$NON-NLS-1$
} else if (loc.getAction() == StatementActions.ALTER){
String text = loc.getText();
if (loc.getObjType() == DbObjType.TABLE) {
if (DangerStatement.ALTER_COLUMN.getRegex().matcher(text).matches()) {
annotationMsg = "ALTER COLUMN ... TYPE statement"; //$NON-NLS-1$
} else if (DangerStatement.DROP_COLUMN.getRegex().matcher(text).matches()) {
annotationMsg = "DROP COLUMN statement"; //$NON-NLS-1$
}
} else if (loc.getObjType() == DbObjType.SEQUENCE &&
DangerStatement.RESTART_WITH.getRegex().matcher(text).matches()) {
annotationMsg = "ALTER SEQUENCE ... RESTART WITH statement"; //$NON-NLS-1$
}
}
if (annotationMsg != null) {
model.addAnnotation(new Annotation(MARKER.DANGER_ANNOTATION, false, annotationMsg),
new Position(loc.getOffset(), loc.getObjLength()));
}
}
}
示例6: createNewAnnotation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
/**
* Creates a new annotation
* @param r The IRegion which should be highlighted
* @param annString The name of the annotation (not important)
* @param model The AnnotationModel
*/
private void createNewAnnotation(IRegion r, String annString, IAnnotationModel model) {
Annotation annotation= new Annotation(ANNOTATION_TYPE, false, annString);
Position position= new Position(r.getOffset(), r.getLength());
model.addAnnotation(annotation, position);
fOldAnnotations.add(annotation);
}
示例7: run
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
public void run()
{
ITextEditor editor = getTextEditor();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection)
{
ITextSelection textSelection = (ITextSelection) selection;
if (textSelection.getLength() != 0)
{
IAnnotationModel model = getAnnotationModel(editor);
if (model != null)
{
int start = textSelection.getStartLine();
int end = textSelection.getEndLine();
try
{
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = document.getLineOffset(start);
int endOffset = document.getLineOffset(end + 1);
Position position = new Position(offset, endOffset - offset);
model.addAnnotation(new ProjectionAnnotation(), position);
} catch (BadLocationException x)
{
// ignore
}
}
}
}
}
示例8: appendLemmaCase
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
private void appendLemmaCase(BTSLemmaCase amCase,
BTSAmbivalence ambivalence, StringBuilder stringBuilder,
IAnnotationModel model, Map<String, List<BTSInterTextReference>> relatingObjectsMap,
Map<String, List<Object>> lemmaAnnotationMap) {
Position pos = new Position(stringBuilder.length());
stringBuilder.append(LEMMA_CASE_TERMIAL + WS);
if (amCase.getName() != null) {
stringBuilder.append(amCase.getName());
}
stringBuilder.append(LEMMA_CASE_INTERFIX);
if (amCase.getScenario() != null) {
for (BTSAmbivalenceItem item : amCase.getScenario()) {
appendAmbivalenceItem((BTSIdentifiableItem) item, amCase, ambivalence, stringBuilder,
model, relatingObjectsMap, lemmaAnnotationMap);
stringBuilder.append(WS);
}
}
stringBuilder.replace(stringBuilder.length() - 1,
stringBuilder.length(), "");
pos.setLength(stringBuilder.length() - pos.getOffset());
// append to model
if (model == null) return;
BTSModelAnnotation annotation = new BTSModelAnnotation(BTSModelAnnotation.TOKEN,
(BTSIdentifiableItem) amCase);
model.addAnnotation(annotation, pos);
return;
}
示例9: appendMarkerToModel
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
private void appendMarkerToModel(BTSMarker marker, IAnnotationModel model,
Position pos)
{
if (model == null) return;
BTSModelAnnotation annotation = new BTSModelAnnotation(BTSModelAnnotation.TOKEN,
(BTSIdentifiableItem) marker);
model.addAnnotation(annotation, pos);
}
示例10: addAnnotation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
public static void addAnnotation(IMarker marker, ITextEditor editor,
String annotation, int offset, int length) {
// The DocumentProvider enables to get the document currently loaded in
// the editor
IDocumentProvider idp = editor.getDocumentProvider();
// This is the document we want to connect to. This is taken from the
// current editor input.
IDocument document = idp.getDocument(editor.getEditorInput());
// The IannotationModel enables to add/remove/change annotation to a
// Document loaded in an Editor
IAnnotationModel iamf = idp.getAnnotationModel(editor.getEditorInput());
// Note: The annotation type id specify that you want to create one of
// your annotations
String an = "";
if (annotation.equals("1")) {
an = ANNOTATION_COLOR1;
} else if (annotation.equals("2")) {
an = ANNOTATION_COLOR2;
} else if (annotation.equals("3")) {
an = ANNOTATION_COLOR3;
}
SimpleMarkerAnnotation ma = new SimpleMarkerAnnotation(an, marker);
// Finally add the new annotation to the model
iamf.connect(document);
iamf.addAnnotation(ma, new Position(offset, length));
iamf.disconnect(document);
}
示例11: calculateLightBulb
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) {
boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context);
if (fIsAnnotationShown) {
model.removeAnnotation(fAnnotation);
}
if (needsAnnotation) {
model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength()));
}
fIsAnnotationShown= needsAnnotation;
}
示例12: createLocationAnnotation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
/**
* Create a new source location annotation.
*
* @param marker
* The marker to assign to the annotation.
* @param selection
* The selection to highlight.
* @param editor
* The editor to set the annotations in.
* @param variant
* The variant to decide about the marker presentation.
*/
private void createLocationAnnotation(IMarker marker, ITextSelection selection, ITextEditor editor, Variant variant) {
IDocumentProvider idp = editor.getDocumentProvider();
IEditorInput editorInput = editor.getEditorInput();
IDocument document = idp.getDocument(editorInput);
IAnnotationModel annotationModel = idp.getAnnotationModel(editorInput);
String annotationType = getAnnotationType(variant);
SimpleMarkerAnnotation annotation = new SimpleMarkerAnnotation(annotationType, marker);
annotationModel.connect(document);
annotationModel.addAnnotation(annotation, new Position(selection.getOffset(), selection.getLength()));
annotationModel.disconnect(document);
}
示例13: createAnnotation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
/**
* Creates the corresponding annotation for a given marker according to the given marker type.
*
* @param marker the given marker.
* @param selection the selection to highlight.
* @param editor the underlying editor.
* @param markerType the given marker type.
*/
private void createAnnotation(IMarker marker, ITextSelection selection, ITextEditor editor, MarkerType markerType) {
IDocumentProvider idp = editor.getDocumentProvider();
IDocument document = idp.getDocument(editorInput);
IAnnotationModel annotationModel = idp.getAnnotationModel(editorInput);
String annotationType = UIConstants.ANNOTATION_TO_ID.get(markerType);
SimpleMarkerAnnotation annotation = new SimpleMarkerAnnotation(annotationType, marker);
annotationModel.connect(document);
annotationModel.addAnnotation(annotation, new Position(selection.getOffset(), selection.getLength()));
annotationModel.disconnect(document);
}
示例14: addAnnotation
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
/*******************************************************
* Adds an annotation of the specified type to the specified marker in the
* specified editor.
*
* @param editor
* The text editor in which text will be annotated.
* @param marker
* The marker that will be used for annotation.
* @param annotationType
* The type of the annotation as specified in the Manifest file.
* @param startPos
* The starting position of the text to annotate.
* @param length
* The length of the text to annotate
*******************************************************/
public static void addAnnotation(ITextEditor editor, IMarker marker, String annotationType, int startPos, int length)
{
if (editor == null || marker == null || annotationType == null)
throw new IllegalArgumentException();
if (startPos < 0 || length <= 0)
throw new IllegalArgumentException("Invalid marker positions!");
// The DocumentProvider enables to get the document currently loaded in
// the editor
IDocumentProvider docProvider = editor.getDocumentProvider();
// This is the document we want to connect to. This is taken from
// the current editor input.
IDocument document = docProvider.getDocument(editor.getEditorInput());
// The IannotationModel enables to add/remove/change annotation to a
// Document loaded in an Editor
IAnnotationModel annotationModel = docProvider.getAnnotationModel(editor.getEditorInput());
// Note: The annotation type id specify that you want to create one of
// your annotations
SimpleMarkerAnnotation markerAnnotation = new SimpleMarkerAnnotation(annotationType, marker);
// Finally add the new annotation to the model
annotationModel.connect(document);
annotationModel.addAnnotation(markerAnnotation, new Position(startPos, length));
annotationModel.disconnect(document);
}
示例15: run
import org.eclipse.jface.text.source.IAnnotationModel; //導入方法依賴的package包/類
public IStatus run(IProgressMonitor progressMonitor) {
fProgressMonitor = progressMonitor;
if (isCanceled()) {
if (LinkedModeModel.hasInstalledModel(fDocument)) {
// Template completion applied, remove occurrences
removeOccurrenceAnnotations();
}
return Status.CANCEL_STATUS;
}
ITextViewer textViewer = getViewer();
if (textViewer == null)
return Status.CANCEL_STATUS;
IDocument document = textViewer.getDocument();
if (document == null)
return Status.CANCEL_STATUS;
IAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel == null)
return Status.CANCEL_STATUS;
// Add occurrence annotations
int length = fPositions.length;
Map annotationMap = new HashMap(length);
for (int i = 0; i < length; i++) {
if (isCanceled())
return Status.CANCEL_STATUS;
String message;
Position position = fPositions[i];
// Create & add annotation
try {
message = document.get(position.offset, position.length);
} catch (BadLocationException ex) {
// Skip this match
continue;
}
annotationMap.put(new Annotation("org.eclipse.wst.jsdt.ui.occurrences", false, message), //$NON-NLS-1$
position);
}
if (isCanceled())
return Status.CANCEL_STATUS;
synchronized (getLockObject(annotationModel)) {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations,
annotationMap);
} else {
removeOccurrenceAnnotations();
Iterator iter = annotationMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iter.next();
annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
}
}
fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet()
.toArray(new Annotation[annotationMap.keySet().size()]);
}
return Status.OK_STATUS;
}