Example usage for org.eclipse.jdt.core ITypeRoot codeComplete

List of usage examples for org.eclipse.jdt.core ITypeRoot codeComplete

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ITypeRoot codeComplete.

Prototype

void codeComplete(int offset, ICodeCompletionRequestor requestor) throws JavaModelException;

Source Link

Document

Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor.

Usage

From source file:com.microsoft.javapkgsrv.JavaParser.java

License:MIT License

private List<AutocompleteResponse.Completion> Autocomplete(ITypeRoot cu, int cursorPosition)
        throws JavaModelException {
    final List<AutocompleteResponse.Completion> proposals = new ArrayList<AutocompleteResponse.Completion>();
    cu.codeComplete(cursorPosition, new CompletionRequestor() {
        @Override//ww w.  jav  a  2 s. c o m
        public void accept(CompletionProposal proposal) {
            try {
                System.out.println(proposal.toString());
                proposals.add(translateToCompletion(proposal));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return proposals;
}

From source file:com.microsoft.javapkgsrv.JavaParser.java

License:MIT License

private List<ParamHelpResponse.Signature> ParamHelp(ITypeRoot cu, int cursorPosition)
        throws JavaModelException {
    final List<ParamHelpResponse.Signature> proposals = new ArrayList<ParamHelpResponse.Signature>();
    cu.codeComplete(cursorPosition, new CompletionRequestor() {
        @Override/*from  ww w .  j  a  va 2s.co m*/
        public void accept(CompletionProposal proposal) {
            try {
                System.out.println(proposal.toString());
                if (proposal.getKind() == CompletionProposal.METHOD_REF) {
                    char[] javaSig = proposal.getSignature();

                    ParamHelpResponse.Signature.Builder sig = ParamHelpResponse.Signature.newBuilder()
                            .setName(new String(proposal.getName())).setReturnValue(
                                    new String(Signature.toCharArray(Signature.getReturnType(javaSig))));

                    char[][] javaParamTypes = Signature.getParameterTypes(javaSig);
                    for (char[] javaParamType : javaParamTypes) {
                        sig.addParameters(ParamHelpResponse.Parameter.newBuilder()
                                .setName(new String(Signature.toCharArray(javaParamType))).build());
                    }
                    proposals.add(sig.build());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return proposals;
}