use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class TemplateEngine method reset.
/**
* Empties the collector.
*/
public void reset() {
fProposals.clear();
for (Iterator<Entry<IDocument, Position>> it = fPositions.entrySet().iterator(); it.hasNext(); ) {
Entry<IDocument, Position> entry = it.next();
IDocument doc = entry.getKey();
Position position = entry.getValue();
doc.removePosition(position);
}
fPositions.clear();
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class ContentAssistInvocationContext method computeIdentifierPrefix.
/**
* Computes the identifier (as specified by {@link Character#isJavaIdentifierPart(char)}) that
* immediately precedes the invocation offset.
*
* @return the prefix preceding the content assist invocation offset, <code>null</code> if
* there is no document
* @throws org.eclipse.jface.text.BadLocationException if accessing the document fails
*/
public CharSequence computeIdentifierPrefix() throws BadLocationException {
if (fPrefix == null) {
IDocument document = getDocument();
if (document == null)
return null;
int end = getInvocationOffset();
int start = end;
while (--start >= 0) {
if (!Character.isJavaIdentifierPart(document.getChar(start)))
break;
}
start++;
fPrefix = document.get(start, end - start);
}
return fPrefix;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class CUCorrectionProposal method getAdditionalProposalInfo.
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
StringBuffer buf = new StringBuffer();
try {
TextChange change = getTextChange();
change.setKeepPreviewEdits(true);
IDocument previewDocument = change.getPreviewDocument(monitor);
TextEdit rootEdit = change.getPreviewEdit(change.getEdit());
EditAnnotator ea = new EditAnnotator(buf, previewDocument);
rootEdit.accept(ea);
// Final pre-existing region
ea.unchangedUntil(previewDocument.getLength());
} catch (CoreException e) {
JavaPlugin.log(e);
}
return buf.toString();
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class TemplateProposal method computeRelevance.
/**
* Computes the relevance to match the relevance values generated by the
* core content assistant.
*
* @return a sensible relevance value.
*/
private int computeRelevance() {
// see org.eclipse.jdt.internal.codeassist.RelevanceConstants
final int R_DEFAULT = 0;
final int R_INTERESTING = 5;
final int R_CASE = 10;
final int R_NON_RESTRICTED = 3;
final int R_EXACT_NAME = 4;
final int R_INLINE_TAG = 31;
int base = R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED;
try {
if (fContext instanceof DocumentTemplateContext) {
DocumentTemplateContext templateContext = (DocumentTemplateContext) fContext;
IDocument document = templateContext.getDocument();
String content = document.get(fRegion.getOffset(), fRegion.getLength());
if (content.length() > 0 && fTemplate.getName().startsWith(content))
base += R_CASE;
if (fTemplate.getName().equalsIgnoreCase(content))
base += R_EXACT_NAME;
if (fContext instanceof JavaDocContext)
base += R_INLINE_TAG;
}
} catch (BadLocationException e) {
// ignore - not a case sensitive match then
}
// see CompletionProposalCollector.computeRelevance
// just under keywords, but better than packages
final int TEMPLATE_RELEVANCE = 1;
return base * 16 + TEMPLATE_RELEVANCE;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class TemplateProposal method getAdditionalProposalInfo.
/*
* @see ICompletionProposal#getAdditionalProposalInfo()
*/
public String getAdditionalProposalInfo() {
try {
fContext.setReadOnly(true);
TemplateBuffer templateBuffer;
try {
templateBuffer = fContext.evaluate(fTemplate);
} catch (TemplateException e) {
return null;
}
IDocument document = new Document(templateBuffer.getString());
IndentUtil.indentLines(document, new LineRange(0, document.getNumberOfLines()), null, null);
StringBuffer buffer = new StringBuffer();
HTMLPrinter.insertPageProlog(buffer, 0, JavadocFinder.getStyleSheet());
HTMLPrinter.addParagraph(buffer, document.get());
HTMLPrinter.addPageEpilog(buffer);
return buffer.toString();
} catch (BadLocationException e) {
// handleException(
// JavaPlugin.getActiveWorkbenchShell(), new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "", e))); //$NON-NLS-1$
JavaPlugin.log(e);
return null;
}
}
Aggregations