下面列出了怎么用org.eclipse.jface.text.contentassist.IContextInformation的API类实例代码及写法,或者点击链接到github查看源代码。
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
List<ICompletionProposal> newpropList = new ArrayList<ICompletionProposal>();
List<IContextInformation> propList2 = new ArrayList<IContextInformation>();
ICompletionProposal first;
DataManager datamanger = new DataManager(context,monitor);
Activator.applyoperationlist.add(new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList));
List<String> list = new ArrayList();
CompletionProposal proposal;
propList = datamanger.JavaDefaultProposal();
propList2 = datamanger.ContextInformation();
ApplyOperation ao = new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList);
System.out.println(ao.toString());
return newpropList;
}
/**
* createProposal
*
* @param displayName
* @param name
* @param image
* @param description
* @param userAgents
* @param fileLocation
* @param offset
* @param length
* @return
*/
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
String[] userAgentIds, String fileLocation, int offset, int length)
{
IContextInformation contextInfo = null;
// TEMP:
int replaceLength = 0;
if (this._replaceRange != null)
{
offset = this._replaceRange.getStartingOffset();
replaceLength = this._replaceRange.getLength();
}
Image[] userAgents = UserAgentManager.getInstance().getUserAgentImages(getProject(), userAgentIds);
// build proposal
CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
displayName, contextInfo, description);
proposal.setFileLocation(fileLocation);
proposal.setUserAgentImages(userAgents);
return proposal;
}
/**
* createProposal
*
* @param displayName
* @param name
* @param image
* @param description
* @param userAgents
* @param fileLocation
* @param offset
* @return
*/
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
String[] userAgentIds, String fileLocation, int offset)
{
int length = name.length();
IContextInformation contextInfo = null;
int replaceLength = 0;
if (this._replaceRange != null)
{
offset = this._replaceRange.getStartingOffset();
replaceLength = this._replaceRange.getLength();
}
// build proposal
Image[] userAgents = UserAgentManager.getInstance().getUserAgentImages(getProject(), userAgentIds);
CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
displayName, contextInfo, description);
proposal.setFileLocation(fileLocation);
proposal.setUserAgentImages(userAgents);
proposal.setTriggerCharacters(getProposalTriggerCharacters());
return proposal;
}
/**
* Creates a context frame for the given offset.
*
* @param information
* the context information
* @param offset
* the offset
* @return the created context frame
* @since 3.0
*/
private ContextFrame createContextFrame(IContextInformation information, int offset)
{
IContextInformationValidator validator = fContentAssistSubjectControlAdapter.getContextInformationValidator(
fContentAssistant, offset);
if (validator != null)
{
int beginOffset = (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information)
.getContextInformationPosition() : offset;
if (beginOffset == -1)
{
beginOffset = offset;
}
int visibleOffset = fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x
- (offset - beginOffset);
IContextInformationPresenter presenter = fContentAssistSubjectControlAdapter
.getContextInformationPresenter(fContentAssistant, offset);
return new ContextFrame(information, beginOffset, offset, visibleOffset, validator, presenter);
}
return null;
}
/**
* Creates a new completion proposal. All fields are initialized based on the provided information.
*
* @param replacementString the actual string to be inserted into the document
* @param replacementOffset the offset of the text to be replaced
* @param replacementLength the length of the text to be replaced
* @param cursorPosition the position of the cursor following the insert relative to replacementOffset
* @param image the image to display for this proposal
* @param displayString the string to be displayed for the proposal
* @param contextInformation the context information associated with this proposal
* @param additionalProposalInfo the additional information associated with this proposal
*/
public ModulaContextualCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
int cursorPosition, Image image, StyledString displaySString, IContextInformation contextInformation, String additionalProposalInfo) {
Assert.isNotNull(replacementString);
Assert.isTrue(replacementOffset >= 0);
Assert.isTrue(replacementLength >= 0);
Assert.isTrue(cursorPosition >= 0);
fReplacementString= replacementString;
fReplacementOffset= replacementOffset;
fReplacementLength= replacementLength;
fCursorPosition= cursorPosition;
fImage= image;
fDisplaySString= displaySString;
fContextInformation= contextInformation;
fAdditionalProposalInfo= additionalProposalInfo;
}
/**
* Returns an array of context information objects computed based on the specified document position. The position
* is used to determine the appropriate code assist processor to invoke.
*
* @param viewer
* the viewer for which to compute the context information
* @param offset
* a document offset
* @return an array of context information objects
* @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
*/
IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
{
fLastErrorMessage = null;
IContextInformation[] result = null;
IContentAssistProcessor p = getProcessor(viewer, offset);
if (p != null)
{
result = p.computeContextInformation(viewer, offset);
fLastErrorMessage = p.getErrorMessage();
}
return result;
}
/**
* createProsal
*
* @param displayName
* @param name
* @param image
* @param description
* @param userAgents
* @param fileLocation
* @param offset
* @param length
* @return
*/
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
Image[] userAgents, String fileLocation, int offset, int length)
{
IContextInformation contextInfo = null;
// TEMP:
int replaceLength = 0;
if (this._replaceRange != null)
{
offset = this._replaceRange.getStartingOffset();
replaceLength = this._replaceRange.getLength();
}
// build proposal
CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
displayName, contextInfo, description);
proposal.setFileLocation(fileLocation);
proposal.setUserAgentImages(userAgents);
proposal.setTriggerCharacters(getProposalTriggerCharacters());
return proposal;
}
/**
* Creates a new proposal.
*/
public N4JSCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
int cursorPosition, Image image, StyledString displayString, IContextInformation contextInformation,
String additionalProposalInfo) {
super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString,
contextInformation, additionalProposalInfo);
}
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];
}
@Override
public boolean isContextInformationValid(int offset) {
if (fContextInformation instanceof ISmartContextInformation) {
return ((ISmartContextInformation) fContextInformation).isContextInformationValid(fViewer, offset);
} else {
IContextInformation[] infos= fProcessor.computeContextInformation(fViewer, offset);
if (infos != null && infos.length > 0) {
for (int i= 0; i < infos.length; i++)
if (fContextInformation.equals(infos[i]))
return true;
}
return false;
}
}
@Override
public IContextInformation[] computeContextInformation(final ITextViewer viewer, final int offset) {
if (contextInformationProvider == null)
return null;
IXtextDocument document = xtextDocumentUtil.getXtextDocument(viewer);
return document.priorityReadOnly(createContextInformationComputer(viewer, offset));
}
public ContextInformationComputer(State state, ITextViewer viewer, int offset) {
super();
this.information = new LinkedHashSet<IContextInformation>();
this.state = state;
this.offset = offset;
this.viewer = viewer;
}
@Override
public IContextInformation[] exec(XtextResource resource) throws Exception {
IContextInformationAcceptor acceptor = state.decorateAcceptor(this);
ContentAssistContext[] contexts = state.getContextFactory().create(viewer, offset, resource);
for (ContentAssistContext context: contexts) {
if (acceptor.canAcceptMoreInformation())
state.getContextInformationProvider().getContextInformation(context, acceptor);
}
if (information.isEmpty())
return null;
return information.toArray(new IContextInformation[information.size()]);
}
/**
* 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 void install(IContextInformation info, ITextViewer viewer, int offset)
{
this._contextInformation = info;
this._viewer = viewer;
if (info instanceof IContextInformationExtension)
{
this._startingOffset = ((IContextInformationExtension) info).getContextInformationPosition();
}
else
{
this._startingOffset = offset;
}
}
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 CompletionProposalTemplate(String replacementString, Image image, String dipslayString,
IContextInformation contextInformation, String additionalProposalInfo) {
this.fReplacementString = replacementString;
this.fImage = image;
this.fDisplayString = dipslayString;
this.fContextInformation = contextInformation;
this.fAdditionalProposalInfo = additionalProposalInfo;
}
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];
}
@Override
public IContextInformation getContextInformation() {
if (contextInformationComputed) {
return contextInformation;
}
this.contextInformation = createContextInformation();
contextInformationComputed = true;
return contextInformation;
}
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;
}
/**
* CommonCompletionProposal
*
* @param replacementString
* @param replacementOffset
* @param replacementLength
* @param cursorPosition
* @param image
* @param displayString
* @param contextInformation
* @param additionalProposalInfo
*/
public CommonCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
int cursorPosition, Image image, String displayString, IContextInformation contextInformation,
String additionalProposalInfo)
{
this._replacementString = (replacementString == null) ? StringUtil.EMPTY : replacementString;
this._replacementOffset = replacementOffset;
this._replacementLength = replacementLength;
this._cursorPosition = cursorPosition;
this._image = image;
this._displayString = (displayString == null) ? StringUtil.EMPTY : displayString;
this._contextInformation = contextInformation;
this._additionalProposalInformation = additionalProposalInfo;
}
@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;
}
public ContextFrame(IContextInformation information, int beginOffset, int offset, int visibleOffset,
IContextInformationValidator validator, IContextInformationPresenter presenter)
{
fInformation = information;
fBeginOffset = beginOffset;
fOffset = offset;
fVisibleOffset = visibleOffset;
fValidator = validator;
fPresenter = presenter;
}
/**
* Displays the given context information for the given offset.
*
* @param info
* the context information
* @param offset
* the offset
* @since 2.0
*/
public void showContextInformation(final IContextInformation info, final int offset)
{
Control control = fContentAssistSubjectControlAdapter.getControl();
BusyIndicator.showWhile(control.getDisplay(), new Runnable()
{
public void run()
{
if (info == null)
{
validateContextInformation();
}
else
{
ContextFrame frame = createContextFrame(info, offset);
if (isDuplicate(frame))
{
validateContextInformation();
}
else
{
internalShowContextInfo(frame);
}
hideContextSelector();
}
}
});
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public IContextInformation[] computeContextInformation(
IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
return null;
}
@Override
public IContextInformation[] computeContextInformation(
IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
return null;
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
public List<IContextInformation> getAllProposalResultInformation(){
return computeContextInformation(context, monitor);
}
public List<IContextInformation> ContextInformation(){
return getproposalresult.getAllProposalResultInformation();
}