Search in sources :

Example 1 with HQLCompletionProcessor

use of org.hibernate.eclipse.hqleditor.HQLCompletionProcessor in project jbosstools-hibernate by jbosstools.

the class HQLEditorTest method testHQLEditorCodeCompletionWithTabs.

@Test
public void testHQLEditorCodeCompletionWithTabs() throws CoreException, NoSuchFieldException, IllegalAccessException {
    cleanUpProject();
    project = new SimpleTestProjectWithMapping(PROJ_NAME);
    IPackageFragmentRoot sourceFolder = project.createSourceFolder();
    IPackageFragment pf = sourceFolder.createPackageFragment(SimpleTestProject.PACKAGE_NAME, false, null);
    ConsoleConfigUtils.customizeCfgXmlForPack(pf);
    List<IPath> libs = new ArrayList<IPath>();
    project.generateClassPath(libs, sourceFolder);
    project.fullBuild();
    // setup console configuration
    IPath cfgFilePath = new Path(project.getIProject().getName() + File.separator + TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
    ConsoleConfigUtils.createConsoleConfig(PROJ_NAME, cfgFilePath, CONSOLE_NAME);
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(CONSOLE_NAME);
    // $NON-NLS-1$
    Assert.assertNotNull("Console Configuration not found", cc);
    cc.build();
    // $NON-NLS-1$
    final String codeCompletionPlaceMarker = " from ";
    final String query = // $NON-NLS-1$
    "select\t \tt1." + codeCompletionPlaceMarker + project.getFullyQualifiedTestClassName() + // $NON-NLS-1$
    " t1";
    IEditorPart editorPart = HibernateConsolePlugin.getDefault().openScratchHQLEditor(CONSOLE_NAME, query);
    // $NON-NLS-1$
    Assert.assertTrue("Opened editor is not HQLEditor", editorPart instanceof HQLEditor);
    HQLEditor editor = (HQLEditor) editorPart;
    Assert.assertEquals(editor.getEditorText(), query);
    QueryInputModel model = editor.getQueryInputModel();
    Assert.assertTrue(model.getParameterCount() == 0);
    editor.setConsoleConfigurationName(CONSOLE_NAME);
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    HQLCompletionProcessor processor = new HQLCompletionProcessor(editor);
    int position = query.indexOf(codeCompletionPlaceMarker);
    ICompletionProposal[] proposals = processor.computeCompletionProposals(doc, position);
    Assert.assertTrue(proposals.length > 0);
    cc.reset();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) QueryInputModel(org.hibernate.console.QueryInputModel) SimpleTestProjectWithMapping(org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProjectWithMapping) HQLCompletionProcessor(org.hibernate.eclipse.hqleditor.HQLCompletionProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) HQLEditor(org.hibernate.eclipse.hqleditor.HQLEditor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 IDocument (org.eclipse.jface.text.IDocument)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IEditorPart (org.eclipse.ui.IEditorPart)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 QueryInputModel (org.hibernate.console.QueryInputModel)1 HQLCompletionProcessor (org.hibernate.eclipse.hqleditor.HQLCompletionProcessor)1 HQLEditor (org.hibernate.eclipse.hqleditor.HQLEditor)1 SimpleTestProjectWithMapping (org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProjectWithMapping)1 Test (org.junit.Test)1