use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.
the class DebugJavaCompletionProposalComputer method computeCompletionProposals.
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
// $NON-NLS-1$
proposals.add(new CompletionProposal("hibernate tools", context.getInvocationOffset(), 7, context.getInvocationOffset()));
CharSequence computeIdentifierPrefix = null;
try {
computeIdentifierPrefix = context.computeIdentifierPrefix();
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// $NON-NLS-1$//$NON-NLS-2$
proposals.add(new CompletionProposal("ctxid: [" + computeIdentifierPrefix + "]", context.getInvocationOffset(), 7, context.getInvocationOffset()));
// $NON-NLS-1$
proposals.add(new CompletionProposal("Class: " + context.getClass(), context.getInvocationOffset(), 7, context.getInvocationOffset()));
if (context instanceof JavaContentAssistInvocationContext) {
JavaContentAssistInvocationContext jcaic = (JavaContentAssistInvocationContext) context;
// $NON-NLS-1$
proposals.add(new CompletionProposal("Cu: " + jcaic.getCompilationUnit(), context.getInvocationOffset(), 7, context.getInvocationOffset()));
// $NON-NLS-1$
proposals.add(new CompletionProposal("Corectx: " + jcaic.getCoreContext(), context.getInvocationOffset(), 7, context.getInvocationOffset()));
// $NON-NLS-1$
proposals.add(new CompletionProposal("type: " + jcaic.getExpectedType(), context.getInvocationOffset(), 7, context.getInvocationOffset()));
}
proposals.add(new MyCompletionProposal());
return proposals;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project n4js by eclipse.
the class JSDocCompletionProposalComputer method exec.
@SuppressWarnings("unchecked")
@Override
public ICompletionProposal[] exec(XtextResource xtextResource) throws Exception {
ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, offset, xtextResource);
if (contexts.length > 0) {
ArrayList<ICompletionProposal> proposals = new ArrayList<>();
ContentAssistContext contentAssistContext = contexts[contexts.length - 1];
INode currentNode = contentAssistContext.getCurrentNode();
String content = currentNode.getText();
int offsetInNode = contentAssistContext.getOffset() - currentNode.getOffset() - contentAssistContext.getPrefix().length();
// String textInFront = content.substring(0, offsetInNode);
// System.out.println(textInFront);
N4JSDocletParser docletParser = processor.getDocletParser();
Doclet doclet = docletParser.parse(content);
Optional<String> lineTagPrefix = getLineTagTitlePrefix(content, offsetInNode);
if (lineTagPrefix.isPresent()) {
createLineTagProposal(lineTagPrefix.get(), docletParser, proposals);
}
Tag tag = JSDocletUtils.getTagAtOffset(doclet, offsetInNode);
if (tag != null) {
ITagDefinition tagDef = tag.getTagDefinition();
JSDocCharScanner scanner = new JSDocCharScanner(content);
ScannerState state = scanner.saveState();
scanner.setNextOffset(offsetInNode);
JSDocCompletionHint completionHint = tagDef.completionHint(scanner);
scanner.restoreState(state);
if (completionHint.kind != NOCOMPLETION) {
int replacementOffset = offset - completionHint.prefix.length();
if (completionHint.isTypeModelRef()) {
// get reference as far as it can be parsed:
FullMemberReference ref = completionHint.nodeAsFullMemberReference();
IContentAssistScopeProvider scopeProvider = (IContentAssistScopeProvider) processor.getScopeProvider();
IScope moduleSpecScope = scopeProvider.getScopeForContentAssist(// context for finding modules
xtextResource.getContents().get(0), N4JSPackage.Literals.IMPORT_DECLARATION__MODULE);
// complete module or type
if (!completionHint.isModuleNameCompleted()) {
for (IEObjectDescription moduleDescr : moduleSpecScope.getAllElements()) {
String moduleSpec = moduleDescr.getName().toString("/");
String moduleSimpleName = moduleDescr.getName().getLastSegment();
if (!moduleSpec.startsWith("#")) {
if (moduleSpec.startsWith(completionHint.prefix) || moduleSimpleName.startsWith(completionHint.prefix)) {
if (moduleSpec.length() == completionHint.prefix.length()) {
int replacementLength = 0;
int cursorPosition = 1;
ICompletionProposal proposal = new CompletionProposal(".", replacementOffset + completionHint.prefix.length(), replacementLength, cursorPosition);
proposals.add(proposal);
} else {
int replacementLength = completionHint.prefix.length();
int cursorPosition = moduleSpec.length();
ICompletionProposal proposal = new CompletionProposal(moduleSpec, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
}
}
} else {
QualifiedName moduleQN = QualifiedName.create(ref.getModuleName().split("/"));
IEObjectDescription descr = moduleSpecScope.getSingleElement(moduleQN);
if (descr != null && descr.getEObjectOrProxy() instanceof TModule) {
TModule module = (TModule) descr.getEObjectOrProxy();
if (module.eIsProxy())
module = (TModule) EcoreUtil.resolve(module, xtextResource);
if (!completionHint.isTypeNameCompleted(false) && completionHint.kind != MODULESPEC) {
String typePrefix = ref.getTypeName();
for (Type t : module.getTopLevelTypes()) {
String typeName = t.getName();
if (typeName.startsWith(typePrefix)) {
String completion = module.getModuleSpecifier() + "." + typeName;
int replacementLength = completionHint.prefix.length();
int cursorPosition = completion.length();
ICompletionProposal proposal = new CompletionProposal(completion, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
} else {
// completionHint.kind == MEMBER
Optional<Type> optType = module.getTopLevelTypes().stream().filter(t -> t.getName().equals(ref.getTypeName())).findAny();
if (optType.isPresent()) {
Type t = optType.get();
if (t instanceof ContainerType) {
String memberPrefix = ref.getMemberName();
for (TMember m : ((ContainerType<? extends TMember>) t).getOwnedMembers()) {
String memberName = m.getName();
if (memberName.startsWith(memberPrefix)) {
String completion = LineTagWithFullElementReference.createReferenceFromType(m).toString();
int replacementLength = completionHint.prefix.length();
int cursorPosition = completion.length();
ICompletionProposal proposal = new CompletionProposal(completion, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
}
}
}
}
}
}
}
}
ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
proposals.toArray(result);
return result;
}
return null;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project syncope by apache.
the class HTMLCompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int documentOffset) {
String text = viewer.getDocument().get().substring(0, documentOffset);
String[] dim = getLastWord(text);
String word = dim[0].toLowerCase();
String prev = dim[1].toLowerCase();
String last = dim[2];
this.offset = documentOffset;
List<ICompletionProposal> list = new ArrayList<ICompletionProposal>();
List<TagInfo> tagList = getTagList();
// attribute value
if (word.startsWith("<") && !word.equals("</")) {
TagInfo parent = getTagInfo(last);
// tagList = new ArrayList < TagInfo>();
if (parent != null) {
String[] childNames = parent.getChildTagNames();
for (int i = 0; i < childNames.length; i++) {
tagList.add(getTagInfo(childNames[i]));
}
}
for (int i = 0; i < tagList.size(); i++) {
TagInfo tagInfo = (TagInfo) tagList.get(i);
if (tagInfo instanceof TextInfo) {
TextInfo textInfo = (TextInfo) tagInfo;
if ((textInfo.getText().toLowerCase()).indexOf(word) == 0) {
list.add(new CompletionProposal(textInfo.getText(), documentOffset - word.length(), word.length(), textInfo.getPosition()));
}
continue;
}
String tagName = tagInfo.getTagName();
if (("<" + tagInfo.getTagName().toLowerCase()).indexOf(word) == 0) {
String assistKeyword = tagName;
int position = 0;
// required attributes
AttributeInfo[] requierAttrs = tagInfo.getRequiredAttributeInfo();
for (int j = 0; j < requierAttrs.length; j++) {
assistKeyword = assistKeyword + " " + requierAttrs[j].getAttributeName();
if (requierAttrs[j].hasValue()) {
assistKeyword = assistKeyword + "=\"\"";
if (j == 0) {
position = tagName.length() + requierAttrs[j].getAttributeName().length() + 3;
}
}
}
if (tagInfo.hasBody()) {
assistKeyword = assistKeyword + ">";
if (true) {
if (position == 0) {
position = assistKeyword.length();
}
assistKeyword = assistKeyword + "</" + tagName + ">";
}
} else {
if (tagInfo.isEmptyTag() && !xhtmlMode) {
assistKeyword += ">";
} else {
assistKeyword += "/>";
}
}
if (position == 0) {
position = assistKeyword.length();
}
try {
list.add(new CompletionProposal(assistKeyword, documentOffset - word.length() + 1, word.length() - 1, position));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
// attribute
} else if (!prev.equals("")) {
String tagName = prev;
TagInfo tagInfo = getTagInfo(tagName);
if (tagInfo != null) {
AttributeInfo[] attrList = tagInfo.getAttributeInfo();
for (int j = 0; j < attrList.length; j++) {
if (attrList[j].getAttributeName().toLowerCase().indexOf(word) == 0) {
String assistKeyword = null;
int position = 0;
if (attrList[j].hasValue()) {
assistKeyword = attrList[j].getAttributeName() + "=\"\"";
position = 2;
} else {
assistKeyword = attrList[j].getAttributeName();
position = 0;
}
list.add(new CompletionProposal(assistKeyword, documentOffset - word.length(), word.length(), attrList[j].getAttributeName().length() + position));
}
}
}
// close tag
} else if (!last.equals("")) {
TagInfo info = getTagInfo(last);
if (info == null || xhtmlMode || info.hasBody() || !info.isEmptyTag()) {
String assistKeyword = "</" + last + ">";
int length = 0;
if (word.equals("</")) {
length = 2;
}
String contentBefore = viewer.getDocument().get().substring(0, documentOffset - length);
if (contentBefore.endsWith("\t")) {
list.add(new CompletionProposal(assistKeyword, documentOffset - (length + 1), length + 1, assistKeyword.length()));
} else {
list.add(new CompletionProposal(assistKeyword, documentOffset - length, length, assistKeyword.length()));
}
}
}
sortCompilationProposal(list);
ICompletionProposal[] templates = super.computeCompletionProposals(viewer, documentOffset);
for (int i = 0; i < templates.length; i++) {
list.add(templates[i]);
}
ICompletionProposal[] prop = list.toArray(new ICompletionProposal[list.size()]);
return prop;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project egit by eclipse.
the class CommitProposalProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
String prefix;
try {
prefix = getPrefix(viewer, offset);
} catch (BadLocationException e) {
return NO_PROPOSALS;
}
Collection<String> messages = computeMessageProposals();
Set<CommitFile> files = computeFileProposals();
List<ICompletionProposal> proposals = new ArrayList<>();
if (prefix != null && prefix.length() > 0) {
int replacementLength = prefix.length();
int replacementOffset = offset - replacementLength;
prefix = prefix.toLowerCase(Locale.US);
for (CommitFile file : files) if (file.matches(prefix))
proposals.add(file.createProposal(replacementOffset, replacementLength));
for (String message : messages) if (message.startsWith(prefix))
proposals.add(new CompletionProposal(message, replacementOffset, replacementLength, message.length(), (Image) resourceManager.get(UIIcons.ELCL16_COMMENTS), escapeWhitespace(message), null, null));
} else {
for (String message : messages) proposals.add(new CompletionProposal(message, offset, 0, message.length(), (Image) resourceManager.get(UIIcons.ELCL16_COMMENTS), escapeWhitespace(message), null, null));
for (CommitFile file : files) proposals.add(file.createProposal(offset, 0));
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project webtools.sourceediting by eclipse.
the class CustomCompletionProposal method apply.
public void apply(IDocument document) {
CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(), getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(), getContextInformation(), getAdditionalProposalInfo());
proposal.apply(document);
}
Aggregations