use of org.eclipse.jface.text.contentassist.CompletionProposal in project webtools.sourceediting by eclipse.
the class CustomCompletionProposal method apply.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#apply(org.eclipse.jface.text.IDocument,
* char, int)
*/
public void apply(IDocument document, char trigger, int offset) {
CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(), getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(), getContextInformation(), getAdditionalProposalInfo());
// we currently don't do anything special for which character
// selected the proposal, and where the cursor offset is
// but we might in the future...
proposal.apply(document);
// we want to ContextInformationPresenter.updatePresentation() here
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project webtools.sourceediting by eclipse.
the class QuickFixProcessorXML method getProposals.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.ui.correction.IQuickFixProcessor#getProposals(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)
*/
public ICompletionProposal[] getProposals(Annotation annotation) throws CoreException {
ArrayList proposals = new ArrayList();
if (annotation instanceof TemporaryAnnotation) {
TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) annotation;
int problemID = tempAnnotation.getProblemID();
switch(problemID) {
case ProblemIDsXML.EmptyTag:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_0, null, ""));
break;
case ProblemIDsXML.MissingEndTag:
String tagName = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0];
String tagClose = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1];
int tagCloseOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[2]).intValue();
int startTagEndOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[3]).intValue();
int firstChildStartOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[4]).intValue();
int endOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[5]).intValue();
// $NON-NLS-1$
proposals.add(new CompletionProposal(tagClose, tagCloseOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_1, null, ""));
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), startTagEndOffset - tempAnnotation.getPosition().getOffset(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_2, null, ""));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
proposals.add(new CompletionProposal("</" + tagName + ">", firstChildStartOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_3, null, ""));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
proposals.add(new CompletionProposal("</" + tagName + ">", endOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_4, null, ""));
break;
case ProblemIDsXML.AttrsInEndTag:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_5, null, ""));
break;
case ProblemIDsXML.MissingAttrValue:
String defaultAttrValue = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0];
int insertOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1]).intValue();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
proposals.add(new CompletionProposal("\"" + defaultAttrValue + "\"", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength() + insertOffset, 0, defaultAttrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, ""));
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
break;
case ProblemIDsXML.NoAttrValue:
defaultAttrValue = (String) tempAnnotation.getAdditionalFixInfo();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
proposals.add(new CompletionProposal("=\"" + defaultAttrValue + "\"", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, defaultAttrValue.length() + 3, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, ""));
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
break;
case ProblemIDsXML.SpacesBeforeTagName:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_8, null, ""));
break;
case ProblemIDsXML.SpacesBeforePI:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_9, null, ""));
break;
case ProblemIDsXML.NamespaceInPI:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_10, null, ""));
break;
case ProblemIDsXML.UnknownElement:
proposals.add(new RemoveUnknownElementQuickFixProposal(tempAnnotation.getAdditionalFixInfo(), getImage(), XMLUIMessages.QuickFixProcessorXML_11));
proposals.add(new RenameInFileQuickAssistProposal());
break;
case ProblemIDsXML.UnknownAttr:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
proposals.add(new RenameInFileQuickAssistProposal());
break;
case ProblemIDsXML.InvalidAttrValue:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_12, null, ""));
break;
case ProblemIDsXML.MissingRequiredAttr:
String requiredAttr = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0];
insertOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1]).intValue();
// $NON-NLS-1$
proposals.add(new CompletionProposal(requiredAttr, tempAnnotation.getPosition().getOffset() + insertOffset, 0, requiredAttr.length(), getImage(), XMLUIMessages.QuickFixProcessorXML_13, null, ""));
break;
case ProblemIDsXML.AttrValueNotQuoted:
String attrValue = (String) tempAnnotation.getAdditionalFixInfo();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
proposals.add(new CompletionProposal("\"" + attrValue + "\"", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), attrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_14, null, ""));
break;
case ProblemIDsXML.MissingClosingBracket:
// $NON-NLS-1$ //$NON-NLS-2$
proposals.add(new CompletionProposal(">", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, 1, getImage(), XMLUIMessages.QuickFixProcessorXML_15, null, ""));
break;
}
}
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project bndtools by bndtools.
the class BundleVersionErrorHandler method getProposals.
@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
int start = marker.getAttribute(IMarker.CHAR_START, 0);
int end = marker.getAttribute(IMarker.CHAR_END, 0);
CompletionProposal proposal = new CompletionProposal(Constants.BUNDLE_VERSION + ": " + suggestedVersion, start, end - start, end, null, "Change bundle version to " + suggestedVersion, null, null);
result.add(proposal);
return result;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project bndtools by bndtools.
the class BndCompletionProcessor method proposals.
private static ICompletionProposal[] proposals(String prefix, int offset) {
ArrayList<ICompletionProposal> results = new ArrayList<ICompletionProposal>(Syntax.HELP.size());
for (Syntax s : Syntax.HELP.values()) {
if (prefix == null || s.getHeader().startsWith(prefix)) {
IContextInformation info = new ContextInformation(s.getHeader(), s.getHeader());
String text = prefix == null ? s.getHeader() : s.getHeader().substring(prefix.length());
// $NON-NLS-1$
results.add(new CompletionProposal(text + ": ", offset, 0, text.length() + 2, null, s.getHeader(), info, s.getLead()));
}
}
Collections.sort(results, new Comparator<ICompletionProposal>() {
@Override
public int compare(ICompletionProposal p1, ICompletionProposal p2) {
return p1.getDisplayString().compareTo(p2.getDisplayString());
}
});
return results.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project bndtools by bndtools.
the class BaselineErrorHandler method getProposals.
@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
int start = marker.getAttribute(IMarker.CHAR_START, 0);
int end = marker.getAttribute(IMarker.CHAR_END, 0);
CompletionProposal proposal = new CompletionProposal("version " + suggestedVersion, start, end - start, end, null, "Change package version to " + suggestedVersion, null, null);
proposals.add(proposal);
return proposals;
}
Aggregations