Author: dgeraskov
Date: 2012-03-19 06:18:25 -0400 (Mon, 19 Mar 2012)
New Revision: 39607
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JavaHBMQueryTest.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF
Log:
https://issues.jboss.org/browse/JBIDE-11342
Use code completion string start in java editor to do not brake it.
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -25,7 +25,7 @@
*/
public interface ConsoleExtension {
- public CompletionProposalsResult hqlCodeComplete(String query, int position);
+ public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int
position);
public void setHibernateException(HibernateExtension hibernateExtension);
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -119,7 +119,7 @@
if(consoleConfiguration != null) {
ConsoleExtension consoleExtension =
ConsoleExtensionManager.getConsoleExtension(consoleConfiguration.getHibernateExtension());
if (consoleExtension != null){
- CompletionProposalsResult codeCompletions =
consoleExtension.hqlCodeComplete(doc.get(), currentOffset);
+ CompletionProposalsResult codeCompletions =
consoleExtension.hqlCodeComplete(doc.get(), startOffset, currentOffset);
proposalList.addAll(codeCompletions.getCompletionProposals());
errorMessage =
codeCompletions.getErrorMessage();//eclipseHQLCompletionCollector.getLastErrorMessage();
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -91,7 +91,7 @@
query = ctx.getDocument().get(stringStart, stringEnd-stringStart );
ConsoleExtension consoleExtension =
ConsoleExtensionManager.getConsoleExtension(consoleConfiguration.getHibernateExtension());
if (consoleExtension != null){
- CompletionProposalsResult codeCompletions =
consoleExtension.hqlCodeComplete(query, ctx.getInvocationOffset()-stringStart);
+ CompletionProposalsResult codeCompletions =
consoleExtension.hqlCodeComplete(query, stringStart, ctx.getInvocationOffset() -
stringStart);
errorMessage = codeCompletions.getErrorMessage();
proposals = codeCompletions.getCompletionProposals();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -72,8 +72,8 @@
}
@Override
- public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
- EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int
currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new
EclipseHQLCompletionRequestor(startPosition);
if (!hibernateExtension.hasConfiguration()){
try {
hibernateExtension.build();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -71,8 +71,8 @@
}
@Override
- public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
- EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ public CompletionProposalsResult hqlCodeComplete(String query, int startPosition , int
currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new
EclipseHQLCompletionRequestor(startPosition);
if (!hibernateExtension.hasConfiguration()){
try {
hibernateExtension.build();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -71,8 +71,8 @@
}
@Override
- public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
- EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int
currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new
EclipseHQLCompletionRequestor(startPosition);
if (!hibernateExtension.hasConfiguration()){
try {
hibernateExtension.build();
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -14,9 +14,15 @@
import java.io.IOException;
import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jdt.core.JavaModelException;
+import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
public class SimpleTestProjectWithMapping extends SimpleTestProject {
@@ -48,5 +54,18 @@
getIProject().findMember(path);
getIProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
}
+
+ public void addHibernateNature() throws CoreException{
+ ProjectUtils.addProjectNature(getIProject(),
HibernatePropertiesConstants.HIBERNATE_NATURE, new NullProgressMonitor() );
+ }
+ public void setDefaultConsoleConfiguration(String ccName) throws BackingStoreException,
CoreException{
+ IScopeContext scope = new ProjectScope(getIProject() );
+ Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
+
+ node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, true );
+ node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, ccName ); //$NON-NLS-1$
+ node.flush();
+ addHibernateNature();
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF 2012-03-19
08:19:21 UTC (rev 39606)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF 2012-03-19
10:18:25 UTC (rev 39607)
@@ -13,7 +13,12 @@
org.eclipse.core.resources,
org.eclipse.jdt.core,
org.hibernate.eclipse.jdt.ui,
- org.eclipse.jdt.launching
+ org.eclipse.jdt.launching,
+ org.eclipse.jdt;bundle-version="3.7.0",
+ org.eclipse.jdt.ui;bundle-version="3.7.0",
+ org.eclipse.ui.editors;bundle-version="3.7.0",
+ org.eclipse.text;bundle-version="3.5.100",
+ org.eclipse.jface.text;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.hibernate.eclipse.jdt.ui.test
Bundle-Activator: org.hibernate.eclipse.jdt.ui.test.HibernateJDTuiTestPlugin
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JavaHBMQueryTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JavaHBMQueryTest.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JavaHBMQueryTest.java 2012-03-19
10:18:25 UTC (rev 39607)
@@ -0,0 +1,124 @@
+package org.hibernate.eclipse.jdt.ui.test;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
+import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.console.test.project.SimpleTestProject;
+import org.hibernate.eclipse.console.test.project.SimpleTestProjectWithMapping;
+import org.hibernate.eclipse.console.test.project.TestProject;
+import org.hibernate.eclipse.console.test.utils.ConsoleConfigUtils;
+import org.hibernate.eclipse.jdt.ui.internal.HQLJavaCompletionProposalComputer;
+
+/**
+ *
+ * @author Dmitry Geraskov (geraskov(a)gmail.com)
+ *
+ */
+public class JavaHBMQueryTest extends TestCase {
+
+ private static final String PROJ_NAME = "JavaHBMQueryTest"; //$NON-NLS-1$
+ private static final String CONSOLE_NAME = PROJ_NAME;
+
+ private SimpleTestProjectWithMapping project = null;
+ private ConsoleConfiguration cc;
+
+ protected void setUp() throws Exception {
+ 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.setDefaultConsoleConfiguration(CONSOLE_NAME);
+ 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);
+ assertNotNull("Console Configuration not found", cc); //$NON-NLS-1$
+ cc.build();
+ }
+
+ protected void tearDown() throws Exception {
+ cleanUpProject();
+ }
+
+ protected void cleanUpProject() {
+ if (project != null) {
+ project.deleteIProject();
+ project = null;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public void testJavaHQLQueryCodeCompletion() throws JavaModelException,
+ CoreException, NoSuchFieldException, IllegalAccessException {
+ IPackageFragment pack = project.getTestClassType().getPackageFragment();
+
+ String testCP = "TestCompletionProposals.java";
+ ICompilationUnit cu = pack
+ .createCompilationUnit(testCP, "", true, null); //$NON-NLS-1$
+
+ cu.createPackageDeclaration(pack.getElementName(), null);
+ IType type = cu.createType(
+ "public class " + testCP + " {}", null, false, null);
//$NON-NLS-1$//$NON-NLS-2$
+ type.createMethod(
+ "public static void main(String[] args){String query = \"from
\";}", null, false, null); //$NON-NLS-1$
+
+ IWorkbenchPage p = JavaPlugin.getActivePage();
+ IEditorPart part = EditorUtility.openInEditor(type, true);
+ if (part instanceof CompilationUnitEditor) {
+ CompilationUnitEditor editor = (CompilationUnitEditor) part;
+ IDocument doc = editor.getDocumentProvider().getDocument(
+ editor.getEditorInput());
+
+ HQLJavaCompletionProposalComputer proposalComputer = new
HQLJavaCompletionProposalComputer();
+ ContentAssistInvocationContext context = new
JavaContentAssistInvocationContext(editor.getViewer(), 125, editor);
+ List<ICompletionProposal> computeCompletionProposals =
proposalComputer.computeCompletionProposals(context, null);
+ for (ICompletionProposal iCompletionProposal : computeCompletionProposals) {
+ Class<? extends ICompletionProposal> class1 = iCompletionProposal.getClass();
+ if (class1.getPackage().getName().indexOf("org.jboss.tools.hibernate") ==
0){
+ //this is our completion proposal
+ Field declaredField = class1.getDeclaredField("documentOffset");
+ declaredField.setAccessible(true);
+ Integer offset = (Integer) declaredField.get(iCompletionProposal);
+ Assert.assertTrue(offset > 0);
+ }
+ }
+ } else {
+ fail("Can't open CompilationUnitEditor");
+ }
+ }
+
+}