Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java63
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java6
3 files changed, 70 insertions, 48 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
index 7f6301b8e9..c7c4d5c3fb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
@@ -417,8 +417,10 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
}
private void disposeQueryHelper() {
- queryHelper.dispose();
- queryHelper.disposeProvider();
+ if (queryHelper != null) {
+ queryHelper.dispose();
+ queryHelper.disposeProvider();
+ }
}
private KeyStroke findContentAssistTrigger() {
@@ -550,11 +552,14 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
private void subjectChanged(PropertyChangeEvent e) {
- // Disposes of the internal data since the subject changed
disposeQueryHelper();
// Prevent undoing the actual query that was set
if (e.getNewValue() != null) {
+
+ namedQuery = (NamedQuery) e.getNewValue();
+ queryHelper = namedQuery.getJpaProject().getJpaPlatform().getJpqlQueryHelper();
+
sourceViewer.getUndoManager().reset();
validate();
}
@@ -568,29 +573,35 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
*/
private void validate() {
- NamedQuery query = query();
+ // First clear any existing problems
annotationModel.removeAllAnnotations();
- if ((query != null) && !styledText.isDisposed()) {
- try {
- String jpqlQuery = styledText.getText();
- queryHelper.setQuery(query, jpqlQuery);
- String parsedJpqlQuery = queryHelper.getParsedJPQLQuery();
+ // Nothing to validate
+ if ((query() == null) ||
+ styledText.isDisposed() ||
+ StringTools.stringIsEmpty(styledText.getText())) {
- for (JPQLQueryProblem problem : sortProblems(queryHelper.validate())) {
+ return;
+ }
- // Create the range
- int[] positions = queryHelper.buildPositions(problem, parsedJpqlQuery, jpqlQuery);
+ try {
+ String jpqlQuery = styledText.getText();
+ queryHelper.setQuery(query(), jpqlQuery);
+ String parsedJpqlQuery = queryHelper.getParsedJPQLQuery();
- // Add the problem to the tool tip
- Annotation annotation = new Annotation(ERROR_TYPE, true, buildMessage(problem));
- annotationModel.addAnnotation(annotation, new Position(positions[0], positions[1] - positions[0]));
- }
- }
- finally {
- queryHelper.dispose();
+ for (JPQLQueryProblem problem : sortProblems(queryHelper.validate())) {
+
+ // Create the range
+ int[] positions = queryHelper.buildPositions(problem, parsedJpqlQuery, jpqlQuery);
+
+ // Add the problem to the tool tip
+ Annotation annotation = new Annotation(ERROR_TYPE, true, buildMessage(problem));
+ annotationModel.addAnnotation(annotation, new Position(positions[0], positions[1] - positions[0]));
}
}
+ finally {
+ queryHelper.dispose();
+ }
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java
index a6afab7c0c..bea30857c3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlCompletionProposalComputer.java
@@ -13,6 +13,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.jpql;
+import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
+
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@@ -21,29 +23,27 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.jpa.core.context.NamedQuery;
-import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.persistence.jpa.internal.jpql.WordParser;
-import org.eclipse.persistence.jpa.internal.jpql.parser.Expression;
-import org.eclipse.persistence.jpa.internal.jpql.parser.IdentifierRole;
-import org.eclipse.persistence.jpa.internal.jpql.parser.JPQLExpression;
import org.eclipse.persistence.jpa.jpql.ContentAssistProposals;
+import org.eclipse.persistence.jpa.jpql.WordParser;
+import org.eclipse.persistence.jpa.jpql.parser.Expression;
+import org.eclipse.persistence.jpa.jpql.parser.IdentifierRole;
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
-import static org.eclipse.jpt.common.utility.internal.CollectionTools.*;
+import static org.eclipse.persistence.jpa.jpql.spi.IMappingType.*;
/**
* The abstract definition of JPQL content assist support.
*
- * @version 3.0
+ * @version 3.1
* @since 3.0
* @author Pascal Filion
*/
-@SuppressWarnings({"nls", "restriction"})
+@SuppressWarnings("nls")
abstract class JpqlCompletionProposalComputer<T> {
/**
@@ -91,14 +91,13 @@ abstract class JpqlCompletionProposalComputer<T> {
* This helper is responsible to retrieve the possible proposals to complete or to add more
* information to a JPQL based on the position of the cursor.
*/
- final JpaJpqlQueryHelper queryHelper;
+ JpaJpqlQueryHelper queryHelper;
/**
* Creates a new <code>JpqlCompletionProposalComputer</code>.
*/
public JpqlCompletionProposalComputer() {
super();
- queryHelper = new JpaJpqlQueryHelper();
}
/**
@@ -188,7 +187,7 @@ abstract class JpqlCompletionProposalComputer<T> {
private T buildIdentifierProposal(String proposal) {
String additionalInfo = additionalInfo(proposal);
- IdentifierRole role = JPQLExpression.identifierRole(proposal);
+ IdentifierRole role = queryHelper.getQueryContext().getExpressionRegistry().getIdentifierRole(proposal);
boolean realFunction = (role == IdentifierRole.FUNCTION) && isRealFunction(proposal);
int cursorOffset = 0;
@@ -265,6 +264,7 @@ abstract class JpqlCompletionProposalComputer<T> {
this.offset = offset;
this.actualQuery = actualQuery;
this.namedQuery = namedQuery;
+ this.queryHelper = namedQuery.getJpaProject().getJpaPlatform().getJpqlQueryHelper();
// It's possible the string has literal representation of the escape characters, if required,
// convert them into actual escape characters and adjust the position accordingly
@@ -273,17 +273,21 @@ abstract class JpqlCompletionProposalComputer<T> {
this.position = positions[0];
this.partialWord = partialWord();
- // Gather the possible proposals
- this.queryHelper.setQuery(namedQuery, jpqlQuery);
- this.contentAssistProposals = queryHelper.buildContentAssistProposals(positions[0]);
- this.queryHelper.dispose();
-
- // Create the proposals for those proposals
List<T> proposals = new ArrayList<T>();
- addAbstractSchemaNames (proposals);
- addIdentificationVariables(proposals);
- addIdentifiers (proposals);
- addMappings (proposals);
+
+ try {
+ this.queryHelper.setQuery(namedQuery, jpqlQuery);
+ this.contentAssistProposals = queryHelper.buildContentAssistProposals(positions[0]);
+
+ // Create the proposals for those proposals
+ addAbstractSchemaNames (proposals);
+ addIdentificationVariables(proposals);
+ addIdentifiers (proposals);
+ addMappings (proposals);
+ }
+ finally {
+ this.queryHelper.dispose();
+ }
return proposals;
}
@@ -367,8 +371,8 @@ abstract class JpqlCompletionProposalComputer<T> {
private Image mappingImage(IMapping mapping) {
switch (mapping.getMappingType()) {
case BASIC: return getImage(JptUiIcons.BASIC);
- case BASIC_COLLECTION: return getImage(JptUiIcons.ELEMENT_COLLECTION);
- case BASIC_MAP: return getImage(JptUiIcons.ELEMENT_COLLECTION);
+// case BASIC_COLLECTION: return getImage(JptUiIcons.ELEMENT_COLLECTION);
+// case BASIC_MAP: return getImage(JptUiIcons.ELEMENT_COLLECTION);
case ELEMENT_COLLECTION: return getImage(JptUiIcons.ELEMENT_COLLECTION);
case EMBEDDED: return getImage(JptUiIcons.EMBEDDED);
case EMBEDDED_ID: return getImage(JptUiIcons.EMBEDDED_ID);
@@ -377,8 +381,8 @@ abstract class JpqlCompletionProposalComputer<T> {
case MANY_TO_ONE: return getImage(JptUiIcons.MANY_TO_ONE);
case ONE_TO_MANY: return getImage(JptUiIcons.ONE_TO_MANY);
case ONE_TO_ONE: return getImage(JptUiIcons.ONE_TO_ONE);
- case TRANSFORMATION: return getImage(JptUiIcons.BASIC); // TODO
- case VARIABLE_ONE_TO_ONE: return getImage(JptUiIcons.ONE_TO_ONE); // TODO
+// case TRANSFORMATION: return getImage(JptUiIcons.BASIC); // TODO
+// case VARIABLE_ONE_TO_ONE: return getImage(JptUiIcons.ONE_TO_ONE); // TODO
case VERSION: return getImage(JptUiIcons.VERSION);
default: return getImage(JptUiIcons.TRANSIENT);
}
@@ -407,7 +411,10 @@ abstract class JpqlCompletionProposalComputer<T> {
*/
public void sessionEnded() {
- queryHelper.disposeProvider();
+ if (queryHelper != null) {
+ queryHelper.disposeProvider();
+ }
+
clearInformation();
if (imageRegistry != null) {
@@ -431,6 +438,10 @@ abstract class JpqlCompletionProposalComputer<T> {
return JptJpaUiPlugin.JPQL_IDENTIFIER_LOWERCASE_PREF_VALUE.equals(value);
}
+ private <I extends Comparable<? super I>> Iterable<I> sort(Iterable<I> iterator) {
+ return CollectionTools.sort(iterator);
+ }
+
private Iterable<IEntity> sortByNames(Iterable<IEntity> abstractSchemaTypes) {
return CollectionTools.sort(abstractSchemaTypes, buildEntityNameComparator());
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java
index e3739def27..a8e66038c3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpqlIdentifierMessages.java
@@ -17,16 +17,16 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.persistence.jpa.internal.jpql.parser.Expression;
+import org.eclipse.persistence.jpa.jpql.parser.Expression;
/**
* The localized messages describing the JPQL identifiers.
*
- * @version 3.0
+ * @version 3.1
* @since 3.0
* @author Pascal Filion
*/
-@SuppressWarnings({"nls", "restriction"})
+@SuppressWarnings("nls")
final class JpqlIdentifierMessages extends NLS {
// JPA 1.0 identifiers

Back to the top