use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method createAnnotations.
protected IReconcileResult[] createAnnotations(AnnotationInfo[] infos) {
List annotations = new ArrayList();
for (int i = 0; i < infos.length; i++) {
AnnotationInfo info = infos[i];
IMessage validationMessage = info.getMessage();
int offset = validationMessage.getOffset();
if (offset < 0)
continue;
String messageText = null;
try {
messageText = validationMessage.getText(validationMessage.getClass().getClassLoader());
} catch (Exception t) {
// $NON-NLS-1$
Logger.logException("exception reporting message from validator", t);
continue;
}
String type = getSeverity(validationMessage);
// this position seems like it would be possibly be the wrong
// length
int length = validationMessage.getLength();
if (length >= 0) {
Position p = new Position(offset, length);
ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope());
// create an annotation w/ problem ID and fix info
TemporaryAnnotation annotation = new TemporaryAnnotation(p, type, messageText, key);
Object extraInfo = info.getAdditionalFixInfo();
// add quick fix information
if (extraInfo == null) {
extraInfo = validationMessage.getAttribute(QUICKASSISTPROCESSOR);
}
annotation.setAdditionalFixInfo(extraInfo);
annotation.setAttributes(validationMessage.getAttributes());
annotations.add(annotation);
}
}
return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]);
}
use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.
the class SourceValidationQuickAssistProcessor method computeQuickAssistProposals.
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) {
ISourceViewer viewer = quickAssistContext.getSourceViewer();
int documentOffset = quickAssistContext.getOffset();
int length = viewer != null ? viewer.getSelectedRange().y : 0;
IAnnotationModel model = viewer.getAnnotationModel();
if (model == null)
return null;
List allProposals = new ArrayList();
if (model instanceof IAnnotationModelExtension2) {
Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
while (iter.hasNext()) {
List processors = new ArrayList();
Annotation anno = (Annotation) iter.next();
if (canFix(anno)) {
// fix processor attached to it
if (anno instanceof TemporaryAnnotation) {
Object o = ((TemporaryAnnotation) anno).getAdditionalFixInfo();
if (o instanceof IQuickAssistProcessor) {
processors.add(o);
}
}
// get all relevant quick fixes for this annotation
QuickFixRegistry registry = QuickFixRegistry.getInstance();
processors.addAll(Arrays.asList(registry.getQuickFixProcessors(anno)));
// set up context
Map attributes = null;
if (anno instanceof TemporaryAnnotation) {
attributes = ((TemporaryAnnotation) anno).getAttributes();
}
Position pos = model.getPosition(anno);
StructuredTextInvocationContext sseContext = new StructuredTextInvocationContext(viewer, pos.getOffset(), pos.getLength(), attributes);
// call each processor
for (int i = 0; i < processors.size(); ++i) {
List proposals = new ArrayList();
collectProposals((IQuickAssistProcessor) processors.get(i), anno, sseContext, proposals);
if (proposals.size() > 0) {
allProposals.addAll(proposals);
}
}
}
}
}
if (allProposals.isEmpty())
return null;
return (ICompletionProposal[]) allProposals.toArray(new ICompletionProposal[allProposals.size()]);
}
use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.
the class AnnotationQuery method performQuery.
/**
* Performs a query against the given annotation.
* <p>
* Returns a <code>AnnotationQueryResult</code> if the marker is
* appropriate for this query (correct type and has all of the query
* attributes), otherwise <code>null</code> is returned.
*
* @param annotation
* the annotation to perform the query against
* @return a annotation query result or <code>null</code>
*/
public AnnotationQueryResult performQuery(Annotation anno) {
if (!(anno instanceof TemporaryAnnotation))
return null;
Map annoAttributes = ((TemporaryAnnotation) anno).getAttributes();
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=243660
*
* May be null if the original validation IMessage contained no
* attributes or this annotation was not based on a validation
* IMessage
*/
if (annoAttributes == null) {
return null;
}
// Check type
if (type != null) {
// $NON-NLS-1$;
String problemType = (String) annoAttributes.get("problemType");
if (!type.equals(problemType))
return null;
}
String[] values = new String[attributes.length];
for (int i = 0; i < attributes.length; i++) {
Object value = annoAttributes.get(attributes[i]);
if (value == null) {
return null;
}
values[i] = value.toString();
}
// Create and return the result
return new AnnotationQueryResult(values);
}
use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.
the class HTMLAttributeValidationQuickFixProcessor method computeQuickAssistProposals.
/*
* @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#computeQuickAssistProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
*/
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
ISourceViewer viewer = invocationContext.getSourceViewer();
int documentOffset = invocationContext.getOffset();
int length = viewer != null ? viewer.getSelectedRange().y : 0;
IAnnotationModel model = viewer.getAnnotationModel();
if (model == null)
return null;
List proposals = new ArrayList();
if (model instanceof IAnnotationModelExtension2) {
Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
while (iter.hasNext()) {
Annotation anno = (Annotation) iter.next();
if (canFix(anno)) {
int offset = -1;
if (anno instanceof TemporaryAnnotation) {
offset = ((TemporaryAnnotation) anno).getPosition().getOffset();
} else if (anno instanceof MarkerAnnotation) {
offset = ((MarkerAnnotation) anno).getMarker().getAttribute(IMarker.CHAR_START, -1);
}
if (offset == -1)
continue;
IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
if (!(node instanceof Element))
continue;
Object adapter = (node instanceof IAdaptable ? ((IAdaptable) node).getAdapter(IResource.class) : null);
IProject project = (adapter instanceof IResource ? ((IResource) adapter).getProject() : null);
IScopeContext[] fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
if (project != null) {
ProjectScope projectScope = new ProjectScope(project);
if (projectScope.getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false))
fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
boolean ignore = fPreferenceService.getBoolean(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT, fLookupOrder);
String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
Set result = new HashSet();
if (ignoreList.trim().length() > 0) {
// $NON-NLS-1$
String[] names = ignoreList.split(",");
for (int i = 0; names != null && i < names.length; i++) {
String name = names[i] == null ? null : names[i].trim();
if (name != null && name.length() > 0)
result.add(name.toLowerCase());
}
}
String name = getAttributeName(node, offset);
if (name == null)
continue;
// If ignore == false. then show a quick fix anyway (due to allow to turn 'ignore' option on)
if (!ignore || shouldShowQuickFix(result, name.toLowerCase())) {
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAttribute, name), HTMLUIMessages.DoNotValidateAttributeAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
}
int dashIndex = name.indexOf('-');
while (dashIndex != -1) {
StringBuffer namePattern = new StringBuffer(name.substring(0, dashIndex + 1)).append('*');
// a more common pattern is already created
if (ignore && result.contains(namePattern.toString().toLowerCase()))
break;
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllAttributes, namePattern.toString()), HTMLUIMessages.DoNotValidateAllAttributesAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
dashIndex = name.indexOf('-', dashIndex + 1);
}
}
}
}
if (proposals.isEmpty())
return null;
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.
the class SpellcheckStrategy method getSpellingAnnotationsToRemove.
private TemporaryAnnotation[] getSpellingAnnotationsToRemove(IRegion region) {
List toRemove = new ArrayList();
IAnnotationModel annotationModel = getAnnotationModel();
// can be null when closing the editor
if (annotationModel != null) {
Iterator i = null;
boolean annotationOverlaps = false;
if (annotationModel instanceof IAnnotationModelExtension2) {
i = ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(region.getOffset(), region.getLength(), true, true);
annotationOverlaps = true;
} else {
i = annotationModel.getAnnotationIterator();
}
while (i.hasNext()) {
Object obj = i.next();
if (!(obj instanceof TemporaryAnnotation))
continue;
TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
// partition type
if (key != null && key.equals(fReconcileAnnotationKey)) {
if (key.getScope() == ReconcileAnnotationKey.PARTIAL && (annotationOverlaps || annotation.getPosition().overlapsWith(region.getOffset(), region.getLength()))) {
toRemove.add(annotation);
} else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
toRemove.add(annotation);
}
}
}
}
return (TemporaryAnnotation[]) toRemove.toArray(new TemporaryAnnotation[toRemove.size()]);
}
Aggregations