use of org.eclipse.jface.text.source.IAnnotationModelExtension2 in project eclipse.platform.text by eclipse.
the class InlinedAnnotationSupport method getInlinedAnnotationAtOffset.
/**
* Returns the {@link AbstractInlinedAnnotation} from the given offset and null otherwise.
*
* @param viewer the source viewer
* @param offset the start position of the region, must be >= 0
* @param length the length of the region, must be >= 0
* @return the {@link AbstractInlinedAnnotation} from the given offset and null otherwise.
*/
private static AbstractInlinedAnnotation getInlinedAnnotationAtOffset(ISourceViewer viewer, int offset, int length) {
if (viewer == null) {
return null;
}
IAnnotationModel annotationModel = viewer.getAnnotationModel();
if (annotationModel == null) {
return null;
}
Iterator<Annotation> iter = (annotationModel instanceof IAnnotationModelExtension2) ? ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(offset, length, true, true) : annotationModel.getAnnotationIterator();
while (iter.hasNext()) {
Annotation ann = iter.next();
if (ann instanceof AbstractInlinedAnnotation) {
Position p = annotationModel.getPosition(ann);
if (p != null) {
if (p.overlapsWith(offset, length)) {
return (AbstractInlinedAnnotation) ann;
}
}
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension2 in project xtext-eclipse by eclipse.
the class XtextEditor method getAnnotation.
@SuppressWarnings("rawtypes")
private Annotation getAnnotation(final int offset, final int length) {
final IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
if (model == null || length < 0)
return null;
Iterator iterator;
if (model instanceof IAnnotationModelExtension2) {
iterator = ((IAnnotationModelExtension2) model).getAnnotationIterator(offset, length, true, true);
} else {
iterator = model.getAnnotationIterator();
}
while (iterator.hasNext()) {
final Annotation a = (Annotation) iterator.next();
final Position p = model.getPosition(a);
if (p != null && p.overlapsWith(offset, length))
return a;
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension2 in project webtools.sourceediting by eclipse.
the class HTMLSyntaxValidationQuickFixProcessor 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_ELEMENT_NAMES, HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES_DEFAULT, fLookupOrder);
String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ELEMENT_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 = getElementName(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())) {
IgnoreElementNameCompletionProposal p = new IgnoreElementNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateElement, name), HTMLUIMessages.DoNotValidateElementAddInfo, 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;
IgnoreElementNameCompletionProposal p = new IgnoreElementNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllElements, namePattern.toString()), HTMLUIMessages.DoNotValidateAllElementsAddInfo, 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()]);
}
Aggregations