下面列出了怎么用org.eclipse.jface.text.contentassist.ContextInformation的API类实例代码及写法,或者点击链接到github查看源代码。
public IContextInformation[] computeContextInformation( ITextViewer viewer, int documentOffset){
// viewer.getSelectedRange();
// if (selectedRange.y > 0) Text is selected. Create a context information array.
// ContextInformation[] contextInfos = new
// ContextInformation[STYLELABELS.length];
// // Create one context information item for each style
// for (int i = 0; i < STYLELABELS.length; i++)
// contextInfos[i] = new ContextInformation("<" + STYLETAGS[i] + ">",
// STYLELABELS[i] + " Style");
// return contextInfos;
// }
return new ContextInformation[0];
}
/**
* Returns the style context.
*
* @return Array of style contexts
*/
public IContextInformation[] getStyleContext() {
ContextInformation[] contextInfos = new ContextInformation[STYLELABELS.length];
// Create one context information item for each style
for (int i = 0; i < STYLELABELS.length; i++) {
contextInfos[i] = new ContextInformation(null, STYLELABELS[i]+" Style");
}
return contextInfos;
}
public IContextInformation[] computeContextInformation(ITextViewer viewer,
int offset) {
// FIXME -- for testing
// Retrieve selected range
Point selectedRange = viewer.getSelectedRange();
if (selectedRange.y > 0) {
if (styleManager == null) {
styleManager = TexStyleCompletionManager.getInstance();
}
return styleManager.getStyleContext();
}
return new ContextInformation[0];
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
// Retrieve selected range
final Point selectedRange = viewer.getSelectedRange();
if (selectedRange.y > 0) {
// Text is selected. Create a context information array.
final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];
// Create one context information item for each style
for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
}
return contextInfos;
}
return new ContextInformation[0];
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
// Retrieve selected range
final Point selectedRange = viewer.getSelectedRange();
if (selectedRange.y > 0) {
// Text is selected. Create a context information array.
final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];
// Create one context information item for each style
for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
}
return contextInfos;
}
return new ContextInformation[0];
}
private IContextInformation createContextInformation() {
try {
String information = null;
List<CompletionEntryDetails> entryDetails = super.getEntryDetails();
if (entryDetails == null || entryDetails.size() < 1) {
return null;
}
if (isFunction()) {
information = TypeScriptHelper.extractFunctionParameters(entryDetails.get(0).getDisplayParts());
}
return information != null ? new ContextInformation("", information) : null;
} catch (TypeScriptException e) {
}
return null;
}
@Override
public IContextInformation getContextInformation() {
if (markerResolution instanceof IMarkerResolution2) {
IMarkerResolution2 mr2 = (IMarkerResolution2) markerResolution;
String displayString = mr2.getDescription() == null ? mr2.getLabel() : mr2.getDescription();
return new ContextInformation(mr2.getImage(), mr2.getLabel(), displayString);
}
return null;
}
/**
* Returns the style completion proposals
*
* @param selectedText The selected text
* @param selectedRange The selected range
* @return An array of completion proposals
*/
public ICompletionProposal[] getStyleCompletions(String selectedText, Point selectedRange) {
/*
ICompletionProposal[] result = new ICompletionProposal[keyValue.size()];
int i=0;
for (Iterator iter = keyValue.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
String value = (String) keyValue.get(key);
String replacement = "{" + key + " " + selectedText + "}";
int cursor = key.length() + 2;
IContextInformation contextInfo = new ContextInformation(null, value+" Style");
result[i] = new CompletionProposal(replacement,
selectedRange.x, selectedRange.y,
cursor, null, value,
contextInfo, replacement);
i++;
}
*/
ICompletionProposal[] result = new ICompletionProposal[STYLELABELS.length];
// Loop through all styles
for (int i = 0; i < STYLETAGS.length; i++) {
String tag = STYLETAGS[i];
// Compute replacement text
String replacement = tag + selectedText + "}";
// Derive cursor position
int cursor = tag.length() + selectedText.length() + 1;
// Compute a suitable context information
IContextInformation contextInfo =
new ContextInformation(null, STYLELABELS[i]+" Style");
// Construct proposal
result[i] = new CompletionProposal(replacement,
selectedRange.x, selectedRange.y,
cursor, null, STYLELABELS[i],
contextInfo, replacement);
}
return result;
}