use of org.eclipse.jface.text.source.IAnnotationModel in project liferay-ide by liferay.
the class JSPQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
ICompletionProposal[] retval = null;
List<ICompletionProposal> proposals = new ArrayList<>();
ISourceViewer sourceViewer = context.getSourceViewer();
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
Iterator<Annotation> annotations = annotationModel.getAnnotationIterator();
while (annotations.hasNext()) {
Annotation annotation = annotations.next();
Position position = annotationModel.getPosition(annotation);
try {
IMarker marker = _createTempMarker(annotation);
int lineNum = sourceViewer.getDocument().getLineOfOffset(position.getOffset()) + 1;
int currentLineNum = sourceViewer.getDocument().getLineOfOffset(context.getOffset()) + 1;
if ((marker != null) && (currentLineNum == lineNum)) {
if (marker.getAttribute(LiferayBaseValidator.MARKER_QUERY_ID, null) != null) {
ICompletionProposal[] resolutions = _createFromMarkerResolutions(marker);
if (ListUtil.isNotEmpty(resolutions)) {
Collections.addAll(proposals, resolutions);
if (annotation instanceof IQuickFixableAnnotation) {
IQuickFixableAnnotation quick = (IQuickFixableAnnotation) annotation;
quick.setQuickFixable(true);
}
}
}
}
} catch (BadLocationException ble) {
LiferayXMLSearchUI.logError("Error finding quick assists", ble);
}
}
if (ListUtil.isNotEmpty(proposals)) {
retval = proposals.toArray(new ICompletionProposal[0]);
}
return retval;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project liferay-ide by liferay.
the class AbstractQuickAssistProcessorFromMarkerResolution method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
ICompletionProposal[] retval = null;
List<ICompletionProposal> proposals = new ArrayList<>();
ISourceViewer sourceViewer = context.getSourceViewer();
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
Iterator<Annotation> annotations = annotationModel.getAnnotationIterator();
while (annotations.hasNext()) {
Annotation annotation = annotations.next();
Position position = annotationModel.getPosition(annotation);
try {
IMarker marker = getMarkerFromAnnotation(annotation);
int lineNum = sourceViewer.getDocument().getLineOfOffset(position.getOffset()) + 1;
int currentLineNum = sourceViewer.getDocument().getLineOfOffset(context.getOffset()) + 1;
if ((marker != null) && (currentLineNum == lineNum)) {
ICompletionProposal[] resolutions = createFromMarkerResolutions(marker);
if (ListUtil.isNotEmpty(resolutions)) {
Collections.addAll(proposals, resolutions);
if (annotation instanceof IQuickFixableAnnotation) {
IQuickFixableAnnotation quick = (IQuickFixableAnnotation) annotation;
quick.setQuickFixable(true);
}
}
}
} catch (BadLocationException ble) {
LiferayXMLSearchUI.logError("Error finding quick assists", ble);
}
}
if (ListUtil.isNotEmpty(proposals)) {
retval = proposals.toArray(new ICompletionProposal[0]);
}
return retval;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project mylyn.docs by eclipse.
the class TextHover method getHoverRegion.
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
if (annotationModel != null) {
int start = Integer.MAX_VALUE;
int end = -1;
Iterator<?> iterator = annotationModel.getAnnotationIterator();
while (iterator.hasNext()) {
Annotation next = (Annotation) iterator.next();
Position position = annotationModel.getPosition(next);
if (position.getOffset() <= offset && (position.getLength() + position.getOffset()) >= offset) {
start = Math.min(start, position.getOffset());
end = Math.max(end, position.getOffset() + position.getLength());
}
}
if (start <= end && end > -1) {
return new Region(start, end - start);
}
}
return super.getHoverRegion(textViewer, offset);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project mylyn.docs by eclipse.
the class TextHover method getHoverInfo.
@SuppressWarnings({ "deprecation" })
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
IAnnotationModel model = getAnnotationModel(sourceViewer);
if (model == null) {
return null;
}
Iterator<?> e = model.getAnnotationIterator();
while (e.hasNext()) {
Annotation a = (Annotation) e.next();
if (isIncluded(a)) {
Position p = model.getPosition(a);
if (p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
String msg = a.getText();
if (msg != null && msg.trim().length() > 0) {
if (a.getType().equals(AnchorHrefAnnotation.TYPE)) {
if (msg.startsWith("#")) {
// links
return null;
} else {
return NLS.bind(Messages.TextHover_hyperlinkHover, msg);
}
}
return msg;
}
}
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse-cs by checkstyle.
the class AbstractASTResolution method run.
/**
* {@inheritDoc}
*/
@Override
public void run(IMarker marker) {
IResource resource = marker.getResource();
if (!(resource instanceof IFile)) {
return;
}
ICompilationUnit compilationUnit = getCompilationUnit(marker);
if (compilationUnit == null) {
return;
}
ITextFileBufferManager bufferManager = null;
IPath path = compilationUnit.getPath();
try {
final IProgressMonitor monitor = new NullProgressMonitor();
// open the file the editor
JavaUI.openInEditor(compilationUnit);
// reimplemented according to this article
// http://www.eclipse.org/articles/Article-JavaCodeManipulation_AST/index.html
bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(path, null);
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
IDocument document = textFileBuffer.getDocument();
IAnnotationModel annotationModel = textFileBuffer.getAnnotationModel();
MarkerAnnotation annotation = getMarkerAnnotation(annotationModel, marker);
// by a previous quickfix
if (annotation == null) {
return;
}
Position pos = annotationModel.getPosition(annotation);
final IRegion lineInfo = document.getLineInformationOfOffset(pos.getOffset());
final int markerStart = pos.getOffset();
ASTParser astParser = ASTParser.newParser(AST.JLS3);
astParser.setKind(ASTParser.K_COMPILATION_UNIT);
astParser.setSource(compilationUnit);
CompilationUnit ast = (CompilationUnit) astParser.createAST(monitor);
ast.recordModifications();
ast.accept(handleGetCorrectingASTVisitor(lineInfo, markerStart));
// rewrite all recorded changes to the document
TextEdit edit = ast.rewrite(document, compilationUnit.getJavaProject().getOptions(true));
edit.apply(document);
// commit changes to underlying file
if (mAutoCommit) {
textFileBuffer.commit(monitor, false);
}
} catch (CoreException e) {
CheckstyleLog.log(e, Messages.AbstractASTResolution_msgErrorQuickfix);
} catch (MalformedTreeException e) {
CheckstyleLog.log(e, Messages.AbstractASTResolution_msgErrorQuickfix);
} catch (BadLocationException e) {
CheckstyleLog.log(e, Messages.AbstractASTResolution_msgErrorQuickfix);
} finally {
if (bufferManager != null) {
try {
bufferManager.disconnect(path, null);
} catch (CoreException e) {
// $NON-NLS-1$
CheckstyleLog.log(e, "Error processing quickfix");
}
}
}
}
Aggregations