use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredTextReconcilingStrategy method getAnnotationsToRemove.
protected TemporaryAnnotation[] getAnnotationsToRemove(DirtyRegion dr, List stepsRun) {
List remove = new ArrayList();
IAnnotationModel annotationModel = getAnnotationModel();
// can be null when closing the editor
if (getAnnotationModel() != null) {
// clear validator annotations
getMarkerAnnotations().clear();
Iterator i = annotationModel.getAnnotationIterator();
while (i.hasNext()) {
Object obj = i.next();
// if it is save it for comparision later (to "gray" icons)
if (obj instanceof StructuredMarkerAnnotation) {
StructuredMarkerAnnotation sma = (StructuredMarkerAnnotation) obj;
if (sma.getAnnotationType() == TemporaryAnnotation.ANNOT_ERROR || sma.getAnnotationType() == TemporaryAnnotation.ANNOT_WARNING)
fMarkerAnnotations.add(sma);
}
if (!(obj instanceof TemporaryAnnotation))
continue;
TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
// partition type
if (canHandlePartition(key.getPartitionType()) && stepsRun.contains(key.getStep())) {
if (key.getScope() == ReconcileAnnotationKey.PARTIAL && annotation.getPosition().overlapsWith(dr.getOffset(), dr.getLength())) {
remove.add(annotation);
} else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
remove.add(annotation);
}
}
}
}
return (TemporaryAnnotation[]) remove.toArray(new TemporaryAnnotation[remove.size()]);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class ShowTranslationHandler method execute.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
public Object execute(final ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List list = ((IStructuredSelection) selection).toList();
if (!list.isEmpty()) {
if (list.get(0) instanceof IDOMNode) {
final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
Job opener = new UIJob("Opening JSP Java Translation") {
public IStatus runInUIThread(IProgressMonitor monitor) {
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
// create an IEditorInput for the Java editor
final IStorageEditorInput input = new JSPTranslationEditorInput(model);
try {
IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaUI.ID_CU_EDITOR, true);
// Now add the problems we found
if (editor instanceof ITextEditor) {
IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
translation.reconcileCompilationUnit();
List problemsList = translation.getProblems();
IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
AnnotationTypeLookup lookup = new AnnotationTypeLookup();
for (int i = 0; i < problems.length; i++) {
if (problems[i] instanceof IJSPProblem)
continue;
int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
Position position = new Position(problems[i].getSourceStart(), length);
Annotation annotation = null;
String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
if (problems[i].isError()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
} else if (problems[i].isWarning()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
}
annotation = new Annotation(type, false, problems[i].getMessage());
if (annotation != null) {
annotationModel.addAnnotation(annotation, position);
}
}
}
} catch (PartInitException e) {
e.printStackTrace();
Display.getCurrent().beep();
}
return Status.OK_STATUS;
}
};
opener.setSystem(false);
opener.setUser(true);
opener.schedule();
}
}
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class XSLEditor method installOverrideIndicator.
protected void installOverrideIndicator() {
// uninstallOverrideIndicator();
if (getEditorInput() instanceof FileEditorInput) {
IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
IFile file = ((FileEditorInput) getEditorInput()).getFile();
fOverrideIndicatorManager = new OverrideIndicatorManager(model, file);
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class TestReconcilerXML method testWellFormed.
/**
* Tests reconciler by verifying no errors/warnings found with well-formed
* xml.
*/
public void testWellFormed() {
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 well-formed xml
try {
Thread.sleep(5000);
Iterator iter = annoModel.getAnnotationIterator();
// make sure the only problem we find is the lack of a specified grammar
while (iter.hasNext()) {
Annotation anno = (Annotation) iter.next();
String annoType = anno.getType();
if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
assertTrue("testReconciler: Unexpected initial annotations" + anno.getText(), anno.getText().indexOf("No grammar constraints") > -1);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class TestReconcilerXML method testIllFormedNoAttrValue.
/**
* Tests reconciler by verifying error/warning found with ill-formed xml.
* (missing attribute value)
*/
public void testIllFormedNoAttrValue() {
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 hello>");
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, errorFound);
} catch (BadLocationException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations