Search in sources :

Example 36 with CompletionProposal

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

the class ProposalFactory method addClassProposals.

/**
 * add the classes in the current module
 * @param node the node under the cursor
 */
private void addClassProposals(ASTNode<?> node) {
    ProposalComparator comp = new ProposalComparator();
    ArrayList<ICompletionProposal> tempNonqual = new ArrayList<ICompletionProposal>();
    ArrayList<ICompletionProposal> tempQual = new ArrayList<ICompletionProposal>();
    ModuleDecl moddecl = node.getModuleDecl();
    // Only crash when debugging:
    assert moddecl != null : "Node is not in a Module!";
    if (moddecl == null)
        return;
    Map<KindedName, ResolvedName> visibleNames = moddecl.getVisibleNames();
    for (Entry<KindedName, ResolvedName> kentry : visibleNames.entrySet()) {
        KindedName kname = kentry.getKey();
        if (qualifierIsPrefixOf(kname.getName()) && kname.getKind() == Kind.CLASS) {
            CompletionProposal proposal = makeVisibleNameProposal(kentry.getValue(), kname);
            if (kname.isQualified()) {
                tempQual.add(proposal);
            } else {
                tempNonqual.add(proposal);
            }
        }
    }
    Collections.sort(tempNonqual, comp);
    proposals.addAll(0, tempNonqual);
    Collections.sort(tempQual, comp);
    proposals.addAll(0, tempQual);
}
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) ResolvedName(abs.frontend.typechecker.ResolvedName) KindedName(abs.frontend.typechecker.KindedName)

Example 37 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project eclipse-cs by checkstyle.

the class PropertiesContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
    List<CompletionProposal> proposals = new ArrayList<>();
    // $NON-NLS-1$
    String basedir = "${basedir}";
    // $NON-NLS-1$
    String projectLoc = "${project_loc}";
    // $NON-NLS-1$
    String workspaceLoc = "${workspace_loc}";
    // $NON-NLS-1$
    String configLoc = "${config_loc}";
    // $NON-NLS-1$
    String samedir = "${samedir}";
    // TODO translate the descriptions
    proposals.add(new CompletionProposal(basedir, documentOffset, 0, basedir.length(), null, basedir, null, Messages.PropertiesContentAssistProcessor_basedir));
    proposals.add(new CompletionProposal(projectLoc, documentOffset, 0, projectLoc.length(), null, projectLoc, null, Messages.PropertiesContentAssistProcessor_projectLoc));
    proposals.add(new CompletionProposal(workspaceLoc, documentOffset, 0, workspaceLoc.length(), null, workspaceLoc, null, Messages.PropertiesContentAssistProcessor_workspaceLoc));
    proposals.add(new CompletionProposal(configLoc, documentOffset, 0, configLoc.length(), null, configLoc, null, Messages.PropertiesContentAssistProcessor_configLoc));
    proposals.add(new CompletionProposal(samedir, documentOffset, 0, samedir.length(), null, samedir, null, Messages.PropertiesContentAssistProcessor_samedir));
    return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ArrayList(java.util.ArrayList)

Example 38 with CompletionProposal

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

the class BundleClassCompletionProposalComputer method computeCompletionProposals.

@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        return Collections.emptyList();
    }
    try {
        int offset = context.getInvocationOffset();
        CharSequence prefix = context.computeIdentifierPrefix();
        result.add(new CompletionProposal("foobar", offset - prefix.length(), prefix.length(), offset - prefix.length() + 6));
        result.add(new CompletionProposal("fizzbuzz", offset - prefix.length(), prefix.length(), offset - prefix.length() + 8));
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 39 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.

the class CFGXMLContentAssistProcessor method getAttributeValueProposals.

protected List getAttributeValueProposals(String attributeName, String matchString, int offset, ContentAssistRequest contentAssistRequest) {
    String nodeName = contentAssistRequest.getNode().getNodeName();
    if ("property".equals(nodeName) && "name".equals(attributeName)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        List types = this.extractor.findMatchingPropertyTypes(matchString);
        List proposals = new ArrayList(types.size());
        for (Iterator iter = types.iterator(); iter.hasNext(); ) {
            String element = (String) iter.next();
            proposals.add(new CompletionProposal(element, offset, matchString.length(), element.length(), null, null, null, null));
        }
        return proposals;
    }
    if ("property".equals(nodeName) && "value".equals(attributeName)) {
        // $NON-NLS-1$//$NON-NLS-2$
        List types = this.extractor.findMatchingPropertyValues(matchString, contentAssistRequest.getNode());
        List proposals = new ArrayList(types.size());
        for (Iterator iter = types.iterator(); iter.hasNext(); ) {
            String element = (String) iter.next();
            proposals.add(new CompletionProposal(element, offset, matchString.length(), element.length(), null, null, null, null));
        }
        return proposals;
    }
    if ("mapping".equals(nodeName) && "resource".equals(attributeName)) {
    // $NON-NLS-1$ //$NON-NLS-2$
    }
    return Collections.EMPTY_LIST;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 40 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.

the class PropertyAccessHandler method attributeCompletionProposals.

public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node node, String attributeName, String start, int offset) {
    List types = this.extractor.findMatchingAccessMethods(start);
    List proposals = new ArrayList(types.size());
    for (Iterator iter = types.iterator(); iter.hasNext(); ) {
        HibernateTypeDescriptor element = (HibernateTypeDescriptor) iter.next();
        String extendedinfo = MapperMessages.PropertyAccessHandler_access_method + element.getName();
        if (element.getReturnClass() != null) {
            extendedinfo += MapperMessages.PropertyAccessHandler_description + element.getReturnClass();
        }
        proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, extendedinfo));
    }
    try {
        // $NON-NLS-1$
        IType typeInterface = project.findType("org.hibernate.property.PropertyAccessor");
        Set alreadyFound = new HashSet();
        if (typeInterface != null) {
            ITypeHierarchy hier = typeInterface.newTypeHierarchy(project, new NullProgressMonitor());
            // TODO: cache these results ?
            IType[] classes = hier.getAllSubtypes(typeInterface);
            // $NON-NLS-1$
            this.extractor.generateTypeProposals(start, offset, proposals, alreadyFound, classes, "org.hibernate.property");
        }
    } catch (CoreException e) {
        // TODO: log as error!
        throw new RuntimeException(e);
    }
    ICompletionProposal[] result = (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) HashSet(java.util.HashSet) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) CoreException(org.eclipse.core.runtime.CoreException) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

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