use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class TestReconcilerXML method testIllFormedNoCloseBracket.
/**
* Tests reconciler by verifying error/warning found with ill-formed xml.
* (missing close bracket)
*/
public void testIllFormedNoCloseBracket() {
IDocument doc = fEditor.getAdapter(IDocument.class);
doc.set("<html><body><h1>Title</h1></body></html>");
ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
// verify ill-formed xml
try {
doc.replace(6, 6, "<body ");
Thread.sleep(5000);
boolean errorFound = false;
Iterator iter = annoModel.getAnnotationIterator();
StringBuffer buffer = new StringBuffer();
while (iter.hasNext()) {
Annotation anno = (Annotation) iter.next();
String annoType = anno.getType();
buffer.append("\n");
buffer.append(anno.getText());
if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
errorFound = true;
}
}
assertTrue("testReconciler: Did not find expected errors in: " + doc.get() + buffer.toString(), errorFound);
} catch (BadLocationException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class GoToMatchingTagAction method updateFor.
void updateFor(ISelection selection) {
ITextEditor textEditor = getTextEditor();
if (textEditor == null) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("no editor");
}
return;
}
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
if (documentProvider == null) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("no document provider");
}
return;
}
IAnnotationModel annotationModel = documentProvider.getAnnotationModel(textEditor.getEditorInput());
if (annotationModel == null || !(annotationModel instanceof IAnnotationModelExtension)) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("no annotation model");
}
return;
}
List oldAnnotations = new ArrayList(2);
Iterator annotationIterator = annotationModel.getAnnotationIterator();
while (annotationIterator.hasNext()) {
Annotation annotation = (Annotation) annotationIterator.next();
if (ANNOTATION_TYPE.equals(annotation.getType())) {
annotation.markDeleted(true);
if (DEBUG) {
// $NON-NLS-1$
System.out.println("removing " + annotation);
}
oldAnnotations.add(annotation);
}
}
Map newAnnotations = new HashMap();
if (!selection.isEmpty() && selection instanceof IStructuredSelection && selection instanceof ITextSelection) {
Object o = ((IStructuredSelection) selection).getFirstElement();
if (o instanceof IDOMNode) {
int offset = ((ITextSelection) selection).getOffset();
IStructuredDocumentRegion matchRegion = null;
if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) {
o = ((Attr) o).getOwnerElement();
}
Position pStart = null;
Position pEnd = null;
// $NON-NLS-1$
String tag = "";
if (o instanceof IDOMNode) {
IDOMNode node = (IDOMNode) o;
IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) {
if (startStructuredDocumentRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = startStructuredDocumentRegion.getRegions().get(1);
pStart = new Position(startStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
tag = startStructuredDocumentRegion.getText(nameRegion);
}
matchRegion = ((IDOMNode) o).getEndStructuredDocumentRegion();
if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = matchRegion.getRegions().get(1);
pEnd = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
}
} else {
IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.containsOffset(offset)) {
if (endStructuredDocumentRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = endStructuredDocumentRegion.getRegions().get(1);
pEnd = new Position(endStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
tag = endStructuredDocumentRegion.getText(nameRegion);
}
matchRegion = ((IDOMNode) o).getStartStructuredDocumentRegion();
if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = matchRegion.getRegions().get(1);
pStart = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
}
}
}
}
if (pStart != null && pEnd != null) {
Annotation annotation = new Annotation(ANNOTATION_TYPE, false, NLS.bind(XMLUIMessages.gotoMatchingTag_start, tag));
newAnnotations.put(annotation, pStart);
if (DEBUG) {
// $NON-NLS-1$
System.out.println("adding " + annotation);
}
annotation = new Annotation(ANNOTATION_TYPE, false, NLS.bind(XMLUIMessages.gotoMatchingTag_end, tag));
newAnnotations.put(annotation, pEnd);
if (DEBUG) {
// $NON-NLS-1$
System.out.println("adding " + annotation);
}
}
}
}
((IAnnotationModelExtension) annotationModel).replaceAnnotations((Annotation[]) oldAnnotations.toArray(new Annotation[oldAnnotations.size()]), newAnnotations);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project bndtools by bndtools.
the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
ISourceViewer viewer = context.getSourceViewer();
@SuppressWarnings("unused") IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
@SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = (Annotation) iter.next();
if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
Position position = model.getPosition(annotation);
if (isAtPosition(context.getOffset(), position)) {
IMarker marker = ((MarkerAnnotation) annotation).getMarker();
String errorType = marker.getAttribute("$bndType", null);
if (errorType != null) {
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
if (handler != null) {
proposals.addAll(handler.getProposals(marker));
}
}
}
}
}
if (proposals.isEmpty()) {
proposals.add(new NoCompletionsProposal());
}
return proposals.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project dbeaver by serge-rider.
the class FileRefDocumentProvider method createElementInfo.
@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
if (element instanceof IEditorInput) {
IEditorInput input = (IEditorInput) element;
IStorage storage = EditorUtils.getStorageFromInput(input);
if (storage instanceof IFile) {
IFile file = (IFile) storage;
try {
refreshFile(file);
} catch (CoreException x) {
log.warn("Can't refresh file", x);
}
IDocument d;
IStatus s = null;
try {
d = createDocument(element);
} catch (CoreException x) {
log.warn("Can't create document", x);
s = x.getStatus();
d = createEmptyDocument();
}
// Set the initial line delimiter
String initialLineDelimiter = GeneralUtils.getDefaultLineSeparator();
if (initialLineDelimiter != null) {
((IDocumentExtension4) d).setInitialLineDelimiter(initialLineDelimiter);
}
IAnnotationModel m = createAnnotationModel(element);
FileSynchronizer f = new FileSynchronizer(input);
f.install();
FileInfo info = new FileInfo(d, m, f);
info.modificationStamp = computeModificationStamp(file);
info.fStatus = s;
return info;
}
}
return super.createElementInfo(element);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonQuickAssistProcessor method getMarkersFor.
protected List<IMarker> getMarkersFor(ISourceViewer sourceViewer, int lineOffset, int lineLength) {
List<IMarker> result = Lists.newArrayList();
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
Iterator annotationIter = annotationModel.getAnnotationIterator();
while (annotationIter.hasNext()) {
Object annotation = annotationIter.next();
if (annotation instanceof MarkerAnnotation) {
MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
IMarker marker = markerAnnotation.getMarker();
Position markerPosition = annotationModel.getPosition(markerAnnotation);
if (markerPosition != null && markerPosition.overlapsWith(lineOffset, lineLength)) {
result.add(marker);
}
}
}
return result;
}
Aggregations