Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337930 - [feature] Validation and content assist for Named Queries in Java source
Summary: [feature] Validation and content assist for Named Queries in Java source
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: General (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Pascal Filion CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks:
 
Reported: 2011-02-22 22:40 EST by Neil Hauge CLA
Modified: 2011-04-12 18:16 EDT (History)
2 users (show)

See Also:
neil.hauge: pmc_approved? (david_williams)
neil.hauge: pmc_approved? (raghunathan.srinivasan)
naci.dai: pmc_approved+
neil.hauge: pmc_approved? (deboer)
neil.hauge: pmc_approved? (neil.hauge)
neil.hauge: pmc_approved? (kaloyan)


Attachments
JPQL Content assist support (136.09 KB, text/plain)
2011-02-23 10:55 EST, Pascal Filion CLA
no flags Details
The 3 icons needed for JPQL content assist (1.42 KB, application/x-zip-compressed)
2011-02-23 10:58 EST, Pascal Filion CLA
neil.hauge: iplog+
Details
Updated code (135.13 KB, patch)
2011-02-23 15:04 EST, Pascal Filion CLA
no flags Details | Diff
Unit-Tests (72.02 KB, patch)
2011-02-23 15:04 EST, Pascal Filion CLA
no flags Details | Diff
JPQL content assist support (212.73 KB, patch)
2011-03-03 17:41 EST, Pascal Filion CLA
no flags Details | Diff
Hermes parser integration tests (72.06 KB, patch)
2011-03-03 17:43 EST, Pascal Filion CLA
no flags Details | Diff
Full JPQL query support (267.31 KB, patch)
2011-03-14 22:01 EDT, Pascal Filion CLA
no flags Details | Diff
Updated tests (67.01 KB, patch)
2011-03-14 22:01 EDT, Pascal Filion CLA
no flags Details | Diff
Latest changes (359.75 KB, patch)
2011-03-17 15:14 EDT, Pascal Filion CLA
no flags Details | Diff
Latest code (293.45 KB, patch)
2011-03-24 09:59 EDT, Pascal Filion CLA
no flags Details | Diff
Latest code (300.35 KB, patch)
2011-03-31 13:05 EDT, Pascal Filion CLA
no flags Details | Diff
JPQL content assist support (304.46 KB, patch)
2011-04-04 08:55 EDT, Pascal Filion CLA
no flags Details | Diff
JPQL content assist support (348.41 KB, patch)
2011-04-12 13:27 EDT, Pascal Filion CLA
neil.hauge: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Neil Hauge CLA 2011-02-22 22:40:06 EST
Dali should provide validation and content assist for NamedQueries.

Validation and content assist should first focus on the Java source.  This bug will track work focused on this area, while future bugs will address validation in XML source, and then content assist and validation in the JPA Details view.
Comment 1 Pascal Filion CLA 2011-02-23 10:55:27 EST
Created attachment 189609 [details]
JPQL Content assist support

This patch contains
- Hermes parser SPI implementation
- Content assist extension point to add content assist support to the query element of the @NamedQuery annotation
- Validation support for JPQL queries
Comment 2 Pascal Filion CLA 2011-02-23 10:58:55 EST
Created attachment 189610 [details]
The 3 icons needed for JPQL content assist

The icons will go under
org.eclipse.jpt.jpa.ui/icons/full/obj16
Comment 3 Pascal Filion CLA 2011-02-23 15:04:08 EST
Created attachment 189632 [details]
Updated code

The code was updated to move 2 methods with the exact code into a common place and opened up the API since the unit-tests are in a different package.
Comment 4 Pascal Filion CLA 2011-02-23 15:04:48 EST
Created attachment 189633 [details]
Unit-Tests

This patch includes the unit-tests.
Comment 5 Neil Hauge CLA 2011-03-02 11:28:35 EST
The underlying dependencies in EclipseLink that are required for this functionality are currently undergoing some necessary restructuring for the Indigo release.  In addition, all of our recent build cycles have been spent integrating the JPA Diagram Editor and associated tests.  As a result we were not able to add this code to Dali for M6.  The new plan will be to introduce this functionality early in M7 as an exception.
Comment 6 Pascal Filion CLA 2011-03-03 17:41:54 EST
Created attachment 190326 [details]
JPQL content assist support

Latest update on the JPQL content assist, which was updated to use the new package structure used by Hermes parser, see bug 338138.
Comment 7 Pascal Filion CLA 2011-03-03 17:43:21 EST
Created attachment 190327 [details]
Hermes parser integration tests

Same comment as attachment 190326 [details].
Comment 8 Pascal Filion CLA 2011-03-14 22:01:01 EDT
Created attachment 191181 [details]
Full JPQL query support

This patch contains the full support for JPQL queries:
- Content assist support in orm.xml xml tags, in the Java source (@NamedQuery) and in the query editor of the JPA details view.
- Validation of JPQL queries in ORM, Java source and in the Query editor.
- Syntax highlighting in orm.xml, Java source and in the Query editor.
Comment 9 Pascal Filion CLA 2011-03-14 22:01:34 EDT
Created attachment 191182 [details]
Updated tests

Updated unit-tests as well.
Comment 10 Pascal Filion CLA 2011-03-17 15:14:48 EDT
Created attachment 191457 [details]
Latest changes

This patch contains:
- Clean up and refactoring of the computers
- Use SourceViewer for the query editor to add content assist support
- Added context menu to the editor
Comment 11 Neil Hauge CLA 2011-03-18 16:55:34 EDT
Feature exception for M7.
Comment 12 Pascal Filion CLA 2011-03-24 09:59:02 EDT
Created attachment 191822 [details]
Latest code

This patch requires the patch for bug 340854 because some classes were renamed.

Also, it contains a minor fix to the undo action. It will not delete the entire query after the pane is connected to the model.
Comment 13 Pascal Filion CLA 2011-03-31 13:05:10 EDT
Created attachment 192304 [details]
Latest code

This patch includes the latest code and also depends on the latest Hermes API, see bug 341523. The Hermes validation and content assist got optimized and the public API changed as a result.
Comment 14 Pascal Filion CLA 2011-04-04 08:55:31 EDT
Created attachment 192454 [details]
JPQL content assist support

This patch still depends on the latest Hermes API, see bug 341523. The changes made to this patch compared to the previous are:

Problems: It seems when applying a content assist proposal, StyledText widget does not trigger a ModifyListener event because the change is applied to a IDocument and not to the StyledText directly. This results in an out of sync situation between the source (Java or XML document) and the text editor.
Solution: Removed the code that binds a StyledText to a WritablePropertyValueModel and do it internally. The entire support for multi-line StyledText was removed since it's not longer used.

Also:
- Fixed couple issues with orm.xml in regards to \r and \n and positioning the problems.
- The code that validates the JPQL query from within the model was moved to JpaJpqlQueryHelper instead of duplicating the code in 4 different places.
- Added popup for additional info (it was not added to the query editor).
Comment 15 Neil Hauge CLA 2011-04-08 16:11:14 EDT
I'm having trouble validating any query with a WHERE clause with the latest patch used against the latest jpql parser code.  Not sure if this is an incompatibility between the Dali code and EL code.  I get the following exception with the below test query.

@NamedQuery(name="foo", query="SELECT o FROM Owner o WHERE o.address = 'foo'")  


	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1116)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:801)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaType.buildCompilationUnit(JpaType.java:156)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaType.compilationUnit(JpaType.java:261)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaType.buildTypeBinding(JpaType.java:199)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaType.getTypeBinding(JpaType.java:338)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaType.isAssignableTo(JpaType.java:397)
	at org.eclipse.persistence.jpa.jpql.TypeHelper.isEnumType(TypeHelper.java:284)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator$EnumTypeValidator.isRightType(SemanticValidator.java:2274)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator$AbstractTypeValidator.visit(SemanticValidator.java:2046)
	at org.eclipse.persistence.jpa.internal.jpql.parser.StateFieldPathExpression.accept(StateFieldPathExpression.java:62)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator.isEnumType(SemanticValidator.java:228)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator.access$1300(SemanticValidator.java:147)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator$ReferencedIdentificationVariableVisitor.visitAbstractPathExpression(SemanticValidator.java:2594)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator$ReferencedIdentificationVariableVisitor.visit(SemanticValidator.java:2585)
	at org.eclipse.persistence.jpa.internal.jpql.parser.StateFieldPathExpression.accept(StateFieldPathExpression.java:62)
	at org.eclipse.persistence.jpa.internal.jpql.parser.CompoundExpression.acceptChildren(CompoundExpression.java:60)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractTraverseChildrenVisitor.visit(AbstractTraverseChildrenVisitor.java:32)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:142)
	at org.eclipse.persistence.jpa.internal.jpql.parser.ComparisonExpression.accept(ComparisonExpression.java:73)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractConditionalClause.acceptChildren(AbstractConditionalClause.java:64)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractTraverseChildrenVisitor.visit(AbstractTraverseChildrenVisitor.java:32)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:626)
	at org.eclipse.persistence.jpa.internal.jpql.parser.WhereClause.accept(WhereClause.java:42)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractSelectStatement.acceptChildren(AbstractSelectStatement.java:92)
	at org.eclipse.persistence.jpa.internal.jpql.parser.SelectStatement.acceptChildren(SelectStatement.java:65)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractTraverseChildrenVisitor.visit(AbstractTraverseChildrenVisitor.java:32)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:472)
	at org.eclipse.persistence.jpa.internal.jpql.parser.SelectStatement.accept(SelectStatement.java:57)
	at org.eclipse.persistence.jpa.internal.jpql.parser.JPQLExpression.acceptChildren(JPQLExpression.java:154)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AbstractTraverseChildrenVisitor.visit(AbstractTraverseChildrenVisitor.java:32)
	at org.eclipse.persistence.jpa.internal.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:311)
	at org.eclipse.persistence.jpa.internal.jpql.parser.JPQLExpression.accept(JPQLExpression.java:147)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator.visitIdentificationVariable(SemanticValidator.java:1921)
	at org.eclipse.persistence.jpa.internal.jpql.SemanticValidator.visit(SemanticValidator.java:1227)
	at org.eclipse.persistence.jpa.internal.jpql.parser.JPQLExpression.accept(JPQLExpression.java:147)
	at org.eclipse.persistence.jpa.internal.jpql.AbstractJPQLQueryHelper.validateSemantic(AbstractJPQLQueryHelper.java:390)
	at org.eclipse.persistence.jpa.internal.jpql.AbstractJPQLQueryHelper.validate(AbstractJPQLQueryHelper.java:334)
	at org.eclipse.persistence.jpa.internal.jpql.AbstractJPQLQueryHelper.validate(AbstractJPQLQueryHelper.java:321)
	at org.eclipse.persistence.jpa.jpql.JPQLQueryHelper.validate(JPQLQueryHelper.java:146)
	at org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper.validate(JpaJpqlQueryHelper.java:230)
	at org.eclipse.jpt.jpa.core.internal.jpa2.context.java.GenericJavaNamedQuery2_0.validate(GenericJavaNamedQuery2_0.java:106)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaQueryContainer.validateQueries(GenericJavaQueryContainer.java:358)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaQueryContainer.validate(GenericJavaQueryContainer.java:311)
	at org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaEntity.validate(AbstractJavaEntity.java:1327)
	at org.eclipse.jpt.jpa.eclipselink.core.internal.context.java.JavaEclipseLinkEntityImpl.validate(JavaEclipseLinkEntityImpl.java:175)
	at org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaPersistentType.validateMapping(AbstractJavaPersistentType.java:649)
	at org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaPersistentType.validate(AbstractJavaPersistentType.java:643)
	at org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaPersistentType.validate(AbstractJavaPersistentType.java:636)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericClassRef.validateJavaPersistentType(GenericClassRef.java:369)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericClassRef.validate(GenericClassRef.java:363)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit.validateClassRefs(AbstractPersistenceUnit.java:1662)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit.validate(AbstractPersistenceUnit.java:1607)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistence.validatePersistenceUnit(GenericPersistence.java:299)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistence.validate(GenericPersistence.java:251)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistenceXml.validate(GenericPersistenceXml.java:244)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericRootContextNode.validate(GenericRootContextNode.java:213)
	at org.eclipse.jpt.jpa.core.internal.AbstractJpaProject.validate(AbstractJpaProject.java:1408)
	at org.eclipse.jpt.jpa.core.internal.AbstractJpaProject.getValidationMessages(AbstractJpaProject.java:1398)
	at org.eclipse.jpt.jpa.core.internal.validation.JpaValidator.getValidationMessages(JpaValidator.java:102)
	at org.eclipse.jpt.jpa.core.internal.validation.JpaValidator.validate(JpaValidator.java:87)
	at org.eclipse.jpt.jpa.core.internal.validation.JpaValidator.validate(JpaValidator.java:64)
Comment 16 Pascal Filion CLA 2011-04-12 13:27:11 EDT
Created attachment 193077 [details]
JPQL content assist support

The exception seen is due to the missing source attachment on rt.jar. The updated patch support all 3 cases (Java source files, Java Compiled classes with and without source attachment).

A new IDE preference was also added: "Match Case of First Character", which override the default behavior if a character precede the cursor when invoking the content assist, the case is determined by that character.
Comment 17 Neil Hauge CLA 2011-04-12 18:16:00 EDT
Patch tested, reviewed and committed!  Thanks Pascal!  This is a fantastic feature add for the Dali project.