Search in sources :

Example 1 with CompletionProposalsResult

use of org.hibernate.eclipse.console.common.CompletionProposalsResult in project jbosstools-hibernate by jbosstools.

the class HQLCompletionProcessor method computeProposals.

ICompletionProposal[] computeProposals(IDocument doc, int lineStart, final int currentOffset, final ConsoleConfiguration consoleConfiguration) {
    ICompletionProposal[] result = null;
    errorMessage = null;
    if (doc != null && currentOffset >= 0) {
        List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
        String startWord = null;
        int startOffset = findNearestWhiteSpace(doc, currentOffset, lineStart);
        int wordLength = currentOffset - startOffset;
        startWord = getWord(doc, startOffset, wordLength);
        if (startWord != null) {
            try {
                doc.get(0, doc.getLength()).toCharArray();
            } catch (BadLocationException e) {
                errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_could_not_get_document_contents;
                return result;
            }
            if (consoleConfiguration != null) {
                ConsoleExtension consoleExtension = consoleConfiguration.getHibernateExtension().getConsoleExtension();
                if (consoleExtension != null) {
                    CompletionProposalsResult codeCompletions = consoleExtension.hqlCodeComplete(doc.get(), 0, currentOffset);
                    proposalList.addAll(codeCompletions.getCompletionProposals());
                    // eclipseHQLCompletionCollector.getLastErrorMessage();
                    errorMessage = codeCompletions.getErrorMessage();
                    result = proposalList.toArray(new ICompletionProposal[proposalList.size()]);
                    if (result.length == 0 && errorMessage == null) {
                        errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_no_hql_completions_available;
                    }
                } else {
                    errorMessage = // $NON-NLS-1$
                    "There is no completion proposal implementation for this hibernate version \'" + consoleConfiguration.getHibernateExtension().getHibernateVersion() + // $NON-NLS-1$
                    "\'";
                }
            }
        } else {
            errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_no_start_word_found;
        }
    }
    return result;
}
Also used : CompletionProposalsResult(org.hibernate.eclipse.console.common.CompletionProposalsResult) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with CompletionProposalsResult

use of org.hibernate.eclipse.console.common.CompletionProposalsResult in project jbosstools-hibernate by jbosstools.

the class HQLJavaCompletionProposalComputer method computeCompletionProposals.

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    errorMessage = null;
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        return proposals;
    }
    JavaContentAssistInvocationContext ctx = (JavaContentAssistInvocationContext) context;
    try {
        ConsoleConfiguration consoleConfiguration = getConfiguration(ctx.getProject());
        if (consoleConfiguration != null) {
            // $NON-NLS-1$
            String query = "";
            int stringStart = getStringStart(ctx.getDocument(), ctx.getInvocationOffset());
            int stringEnd = getStringEnd(ctx.getDocument(), ctx.getInvocationOffset());
            query = ctx.getDocument().get(stringStart, stringEnd - stringStart);
            ConsoleExtension consoleExtension = consoleConfiguration.getHibernateExtension().getConsoleExtension();
            if (consoleExtension != null) {
                CompletionProposalsResult codeCompletions = consoleExtension.hqlCodeComplete(query, stringStart, ctx.getInvocationOffset() - stringStart);
                errorMessage = codeCompletions.getErrorMessage();
                proposals = codeCompletions.getCompletionProposals();
            } else {
                errorMessage = // $NON-NLS-1$
                "There is no completion proposal implementation for this hibernate version \'" + consoleConfiguration.getHibernateExtension().getHibernateVersion() + // $NON-NLS-1$
                "\'";
            }
        }
    } catch (RuntimeException re) {
        HibernateConsolePlugin.getDefault().logErrorMessage(JdtUiMessages.HQLJavaCompletionProposalComputer_errormessage, re);
    } catch (BadLocationException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage(JdtUiMessages.HQLJavaCompletionProposalComputer_errormessage, e);
    }
    return proposals;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) CompletionProposalsResult(org.hibernate.eclipse.console.common.CompletionProposalsResult) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ArrayList (java.util.ArrayList)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 CompletionProposalsResult (org.hibernate.eclipse.console.common.CompletionProposalsResult)2 ConsoleExtension (org.hibernate.eclipse.console.common.ConsoleExtension)2 JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1