use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.
the class ProposalFactory method makeVisibleNameProposal.
private CompletionProposal makeVisibleNameProposal(ResolvedName resolvedName, KindedName kname) {
Decl decl = resolvedName.getDecl();
String name = kname.getName();
String visibleName = name;
String replacement = name;
int cursorposition = name.length();
switch(kname.getKind()) {
case DATA_CONSTRUCTOR:
case FUN:
replacement = name + "()";
cursorposition = name.length() + 1;
break;
case TYPE_DECL:
if (decl instanceof ParametricDataTypeDecl) {
ParametricDataTypeDecl parametricDataTypeDecl = (ParametricDataTypeDecl) decl;
if (parametricDataTypeDecl.getTypeParameterList().getNumChild() > 0) {
replacement = name + "<>";
cursorposition = name.length() + 1;
}
}
break;
default:
break;
}
CompletionProposal proposal = new CompletionProposal(replacement, documentOffset, qualifier.length(), cursorposition, getImageForASTNode(decl), visibleName, null, getAdditionalProposalInfo(decl));
return proposal;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.
the class ProposalFactory method addClassFieldProposals.
/**
* add the fields and variables of the class the cursor is in.
* @param node the node under the cursor
*/
private void addClassFieldProposals(ASTNode<?> node) {
ArrayList<ICompletionProposal> temp = new ArrayList<ICompletionProposal>();
MethodImpl methodimpl = node.getContextMethod();
if (methodimpl != null) {
for (VarDecl varDecl : methodimpl.getBlock().getVars()) {
String name = varDecl.getName();
if (qualifierIsPrefixOf(name)) {
CompletionProposal proposal = new CompletionProposal(name, documentOffset, qualifier.length(), name.length(), getImageForASTNode(varDecl), name, null, getAdditionalProposalInfo(varDecl));
temp.add(proposal);
}
}
}
ClassDecl classdecl = (ClassDecl) node.calcContextNode(ClassDecl.class);
if (classdecl != null) {
for (FieldDecl fieldDecl : classdecl.getType().getAllFieldDecls()) {
String name = fieldDecl.getName();
if (qualifierIsPrefixOf(name)) {
CompletionProposal proposal = new CompletionProposal(name, documentOffset, qualifier.length(), name.length(), getImageForASTNode(fieldDecl), name, null, getAdditionalProposalInfo(fieldDecl));
temp.add(proposal);
}
}
}
Collections.sort(temp, new ProposalComparator());
proposals.addAll(0, temp);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.
the class ProposalFactory method addToplevelProposals.
/**
* add proposals for all visible names.
* @param node the node under the cursor
*/
private void addToplevelProposals(ASTNode<?> node) {
ProposalComparator comp = new ProposalComparator();
ArrayList<ICompletionProposal> tempNonqual = new ArrayList<ICompletionProposal>();
ArrayList<ICompletionProposal> tempQual = new ArrayList<ICompletionProposal>();
ModuleDecl moddecl = node.getModuleDecl();
if (moddecl == null) {
return;
}
try {
Map<KindedName, ResolvedName> visibleNames = moddecl.getVisibleNames();
for (Entry<KindedName, ResolvedName> kentry : visibleNames.entrySet()) {
KindedName kname = kentry.getKey();
if (qualifierIsPrefixOf(kname.getName())) {
CompletionProposal proposal = makeVisibleNameProposal(kentry.getValue(), kname);
if (kname.isQualified()) {
tempQual.add(proposal);
} else {
tempNonqual.add(proposal);
}
}
}
Collections.sort(tempNonqual, comp);
proposals.addAll(tempNonqual);
Collections.sort(tempQual, comp);
proposals.addAll(tempQual);
} catch (TypeCheckerException e) {
// ignore all type check exceptions
}
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project tmdm-studio-se by Talend.
the class DataModelContentAssisProcessor method computeCompletionProposals.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text
* .ITextViewer, int)
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
if (keyWordProvider != null) {
IDocument document = viewer.getDocument();
int start = getInputPos(document, offset);
String input = null;
if (start > 0) {
try {
input = document.get(start, offset - start);
} catch (BadLocationException e) {
// Nothing need report
}
}
if (input != null) {
String[] keyWords = keyWordProvider.getCurrentKeyWords();
int len = offset - start;
if (keyWords != null) {
boolean showAll = input.length() == 0;
for (int i = 0; i < keyWords.length; i++) {
String entityName = keyWords[i];
if (showAll || entityName.toLowerCase().startsWith(input)) {
// $NON-NLS-1$ //$NON-NLS-2$
String replacementString = START + entityName + "></" + entityName + ">";
CompletionProposal proposal = new CompletionProposal(replacementString, offset - len - 1, len + 1, entityName.length() + 2);
proposals.add(proposal);
}
}
}
}
}
return proposals.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project liferay-ide by liferay.
the class NameFragment method getMethodCompletionProposals.
public ICompletionProposal[] getMethodCompletionProposals(int subOffset, int offset, Class parentClass, IResource file) {
if (instanceOf(parentClass, String.class) || instanceOf(parentClass, Number.class) || instanceOf(parentClass, Date.class) || instanceOf(parentClass, Collection.class) || instanceOf(parentClass, List.class) || instanceOf(parentClass, Map.class))
return null;
String prefix = getContent().substring(1, subOffset);
List proposals = new ArrayList();
String pUpper = prefix.toUpperCase();
try {
BeanInfo bi = Introspector.getBeanInfo(parentClass);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
String propertyName = pd.getName();
if (!propertyName.equals("class") && propertyName.toUpperCase().startsWith(pUpper)) {
// $NON-NLS-1$
proposals.add(new CompletionProposal(propertyName, offset - subOffset + 1, getContent().length() - 1, propertyName.length(), null, propertyName + " - " + pd.getReadMethod().getReturnType().getName(), null, // $NON-NLS-1$
null));
}
}
for (int i = 0; i < parentClass.getMethods().length; i++) {
Method m = parentClass.getMethods()[i];
String mName = m.getName();
if (m.getParameterTypes().length > 0 && mName.startsWith("get") && mName.toUpperCase().startsWith(pUpper)) {
// $NON-NLS-1$
StringBuffer display = new StringBuffer();
display.append(mName);
// $NON-NLS-1$
display.append("(");
for (int j = 0; j < m.getParameterTypes().length; j++) {
// $NON-NLS-1$
if (j > 0)
display.append(", ");
display.append(m.getParameterTypes()[j].getName());
}
// $NON-NLS-1$
display.append(")");
// $NON-NLS-1$
String actual = mName + "()";
int tLength = actual.length();
if (m.getParameterTypes().length > 0)
tLength--;
proposals.add(new CompletionProposal(actual, offset - subOffset + 1, getContent().length() - 1, tLength, null, display.toString() + " - " + m.getReturnType().getName(), null, // $NON-NLS-1$
null));
}
}
return completionProposals(proposals);
} catch (IntrospectionException e) {
return null;
}
}
Aggregations