Search in sources :

Example 6 with CompletionProposal

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;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 7 with CompletionProposal

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);
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList)

Example 8 with CompletionProposal

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
    }
}
Also used : TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ResolvedName(abs.frontend.typechecker.ResolvedName) KindedName(abs.frontend.typechecker.KindedName)

Example 9 with CompletionProposal

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]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with CompletionProposal

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;
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)41 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)39 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)8 List (java.util.List)8 BadLocationException (org.eclipse.jface.text.BadLocationException)6 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IType (org.eclipse.jdt.core.IType)3 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)3 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)3 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)3 Image (org.eclipse.swt.graphics.Image)3 Point (org.eclipse.swt.graphics.Point)3 KindedName (abs.frontend.typechecker.KindedName)2 ResolvedName (abs.frontend.typechecker.ResolvedName)2 Map (java.util.Map)2