Search in sources :

Example 31 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project n4js by eclipse.

the class JSDocCompletionProposalComputer method createLineTagProposal.

private void createLineTagProposal(String prefix, N4JSDocletParser docletParser, ArrayList<ICompletionProposal> proposals) {
    int replacementOffset = offset - prefix.length();
    // create line tag proposals
    for (ITagDefinition td : docletParser.getLineTagDictionary().getTagDefinitions()) {
        String tagString = '@' + td.getTitle() + ' ';
        if (tagString.startsWith(prefix)) {
            int replacementLength = prefix.length();
            int cursorPosition = tagString.length();
            ICompletionProposal proposal = new CompletionProposal(tagString, replacementOffset, replacementLength, cursorPosition);
            proposals.add(proposal);
        }
    }
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JSDocCompletionHint(org.eclipse.n4js.jsdoc.JSDocCompletionHint) ITagDefinition(org.eclipse.n4js.jsdoc.ITagDefinition)

Example 32 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project tdq-studio-se by Talend.

the class SQLCompletionProcessor method computeCompletionProposals.

/**
 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
 *      int)
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (dictionary == null)
        return null;
    String text = viewer.getDocument().get();
    String string = text.substring(0, documentOffset);
    if (// $NON-NLS-1$
    string.equals(""))
        return null;
    int position = string.length() - 1;
    char character;
    while (position > 0) {
        character = string.charAt(position);
        if (!Character.isJavaIdentifierPart(character) && (character != '.'))
            break;
        --position;
    }
    if (position == 0)
        position = -1;
    string = string.substring(position + 1);
    // JFaceDbcPlugin.error("String: "+string,new Exception());
    if (string == null || string.equals(""))
        return null;
    string = string.toLowerCase();
    int length = string.length();
    if (length < 1)
        return null;
    // $NON-NLS-1$
    int dotIndex = string.lastIndexOf(".");
    if (string.charAt(length - 1) == ' ') {
        return null;
    } else if (string.charAt(length - 1) == '.') {
        // Last typed character
        // is '.'
        String name = string.substring(0, length - 1);
        if (name == null)
            return null;
        int otherDot = name.lastIndexOf(".");
        if (otherDot != -1)
            name = name.substring(otherDot + 1);
        if (name == null || name.equals(""))
            return null;
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
        if (st != null) {
            ArrayList list = (ArrayList) dictionary.getByTableName(name);
            if (list == null)
                return null;
            TableNode nd = null;
            if (list.size() == 1)
                nd = (TableNode) list.get(0);
            else
                return null;
            Object[] obj = st.toArray();
            String[] arr = new String[obj.length];
            System.arraycopy(obj, 0, arr, 0, obj.length);
            ICompletionProposal[] result = new ICompletionProposal[arr.length];
            String tableDesc = null;
            if (nd != null)
                tableDesc = nd.getTableDesc();
            for (int i = 0; i < arr.length; i++) {
                result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
            }
            return result;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(name);
        if (node != null) {
            Object[] children = (Object[]) node.getChildNodes();
            ArrayList propList = new ArrayList();
            if (children != null) {
                for (int i = 0; i < children.length; i++) {
                    String childName = children[i].toString().toLowerCase();
                    if (childName.equals("table") || childName.equals("view")) {
                        Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
                        if (tables != null) {
                            for (int j = 0; j < tables.length; j++) {
                                Image tmpImage = null;
                                String tableName = tables[j].toString();
                                if (tables[j] instanceof TableNode) {
                                    if (((TableNode) tables[j]).isTable())
                                        tmpImage = tableImage;
                                    else if (((TableNode) tables[j]).isView())
                                        tmpImage = viewImage;
                                    propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
                                }
                            }
                        }
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            Arrays.sort(res, new ICompletionProposalComparator());
            return res;
        }
    } else if (// The string does not contain "."
    dotIndex == -1) {
        String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
        ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
        for (int i = 0; i < keywordProposal.length; i++) {
            resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
        }
        String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
        ArrayList propList = new ArrayList();
        for (int i = 0; i < proposalsString.length; i++) {
            ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
            for (int j = 0; j < ls.size(); j++) {
                TableNode tbNode = (TableNode) ls.get(j);
                Image tmpImage = null;
                if (tbNode.isView())
                    tmpImage = viewImage;
                else if (tbNode.isTable())
                    tmpImage = tableImage;
                ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                propList.add(cmp);
            }
        }
        String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
        ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
        for (int i = 0; i < proposalsString2.length; i++) {
            resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
        }
        ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
        System.arraycopy(resKey, 0, res, 0, resKey.length);
        System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
        System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
        Arrays.sort(res, new ICompletionProposalComparator());
        return res;
    } else if (dotIndex != -1) {
        String firstPart = string.substring(0, dotIndex);
        int otherDot = firstPart.indexOf(".");
        if (otherDot != -1)
            firstPart = firstPart.substring(otherDot + 1);
        String lastPart = string.substring(dotIndex + 1);
        if (lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals(""))
            return null;
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
        if (st != null) {
            Iterator iter = st.iterator();
            ArrayList propList = new ArrayList();
            while (iter.hasNext()) {
                String colName = (String) iter.next();
                int length2 = lastPart.length();
                if (colName.length() >= length2) {
                    if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
                        CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
                        propList.add(cmp);
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            return res;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
        if (node != null) {
            String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase());
            ArrayList propList = new ArrayList();
            for (int i = 0; i < proposalsString.length; i++) {
                ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
                for (int j = 0; j < ls.size(); j++) {
                    TableNode tbNode = (TableNode) ls.get(j);
                    Image tmpImage = null;
                    TableFolderNode totn = (TableFolderNode) tbNode.getParent();
                    INode catSchema = (INode) totn.getParent();
                    if (catSchema == node) {
                        if (tbNode.isView())
                            tmpImage = viewImage;
                        else if (tbNode.isTable())
                            tmpImage = tableImage;
                        ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                        propList.add(cmp);
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            return res;
        }
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TableFolderNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode) TreeSet(java.util.TreeSet) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) Iterator(java.util.Iterator)

Example 33 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.

the class ProposalFactory method addMainblockProposals.

/**
 * add the variables of the main block
 * @param node the node under the cursor
 */
private void addMainblockProposals(ASTNode<?> node) {
    ProposalComparator comp = new ProposalComparator();
    ArrayList<ICompletionProposal> temp = new ArrayList<ICompletionProposal>();
    MainBlock mainblock = (MainBlock) node.calcContextNode(MainBlock.class);
    if (mainblock != null) {
        for (VarDecl vardecl : mainblock.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);
            }
        }
        Collections.sort(temp, comp);
        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 34 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.

the class ProposalFactory method addKeywordProposals.

/**
 * adds the abs keywords to the list of proposals
 */
private void addKeywordProposals() {
    // Loop through keywords
    for (String s : abs.frontend.parser.Keywords.getKeywords()) {
        if (qualifierIsPrefixOf(s)) {
            CompletionProposal proposal = new CompletionProposal(s, documentOffset, qualifier.length(), s.length(), NO_IMAGE, s, null, "");
            proposals.add(proposal);
        }
    }
    Collections.sort(proposals, new ProposalComparator());
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 35 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project abstools by abstools.

the class ProposalFactory method addMethodProposal.

private void addMethodProposal(Type type) {
    if (type.isFutureType()) {
        proposals.clear();
        String name = "get";
        proposals.add(new CompletionProposal(name, documentOffset, qualifier.length(), name.length(), null, name, null, null));
    }
    ArrayList<ICompletionProposal> temp = new ArrayList<ICompletionProposal>();
    for (MethodSig methodSig : type.getAllMethodSigs()) {
        String name = methodSig.getName();
        if (qualifierIsPrefixOf(name)) {
            CompletionProposal proposal = makeMethodSigProposal(methodSig, name);
            temp.add(proposal);
        }
    }
    Collections.sort(temp, new ProposalComparator());
    proposals.addAll(0, temp);
    temp.clear();
    for (FieldDecl fdecl : type.getAllFieldDecls()) {
        String name = fdecl.getName();
        if (qualifierIsPrefixOf(name)) {
            CompletionProposal proposal = new CompletionProposal(name, documentOffset, qualifier.length(), name.length(), getImageForASTNode(fdecl), name, null, getAdditionalProposalInfo(fdecl));
            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)

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