3434import java .util .function .UnaryOperator ;
3535import java .util .regex .Pattern ;
3636
37+ import javax .lang .model .SourceVersion ;
38+
3739import org .apiguardian .api .API ;
3840import org .neo4j .cypherdsl .core .Condition ;
3941import org .neo4j .cypherdsl .core .Conditions ;
4042import org .neo4j .cypherdsl .core .Cypher ;
4143import org .neo4j .cypherdsl .core .Expression ;
4244import org .neo4j .cypherdsl .core .FunctionInvocation ;
4345import org .neo4j .cypherdsl .core .Functions ;
46+ import org .neo4j .cypherdsl .core .IdentifiableElement ;
4447import org .neo4j .cypherdsl .core .MapProjection ;
4548import org .neo4j .cypherdsl .core .Node ;
4649import org .neo4j .cypherdsl .core .Parameter ;
5558import org .neo4j .cypherdsl .core .SymbolicName ;
5659import org .neo4j .cypherdsl .core .renderer .Configuration ;
5760import org .neo4j .cypherdsl .core .renderer .Renderer ;
61+ import org .neo4j .cypherdsl .core .utils .Assertions ;
5862import org .springframework .data .domain .Sort ;
5963import org .springframework .data .mapping .MappingException ;
6064import org .springframework .data .mapping .PersistentProperty ;
@@ -111,12 +115,12 @@ public StatementBuilder.OrderableOngoingReadingAndWith prepareMatchOf(NodeDescri
111115
112116 Node rootNode = createRootNode (nodeDescription );
113117
114- List <Expression > expressions = new ArrayList <>();
118+ List <IdentifiableElement > expressions = new ArrayList <>();
115119 expressions .add (rootNode .getRequiredSymbolicName ());
116120 expressions .add (Functions .id (rootNode ).as (Constants .NAME_OF_INTERNAL_ID ));
117121 expressions .add (Functions .elementId (rootNode ).as (Constants .NAME_OF_ELEMENT_ID ));
118122
119- return match (rootNode ).where (conditionOrNoCondition (condition )).with (expressions .toArray (new Expression [] {} ));
123+ return match (rootNode ).where (conditionOrNoCondition (condition )).with (expressions .toArray (IdentifiableElement []:: new ));
120124 }
121125
122126 public StatementBuilder .OngoingReading prepareMatchOf (NodeDescription <?> nodeDescription ,
@@ -126,12 +130,12 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
126130
127131 StatementBuilder .OngoingReadingWithoutWhere match = prepareMatchOfRootNode (rootNode , initialMatchOn );
128132
129- List <Expression > expressions = new ArrayList <>();
133+ List <IdentifiableElement > expressions = new ArrayList <>();
130134 expressions .add (Functions .collect (Functions .id (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
131135
132136 return match
133137 .where (conditionOrNoCondition (condition ))
134- .with (expressions .toArray (new Expression []{} ));
138+ .with (expressions .toArray (IdentifiableElement []:: new ));
135139 }
136140
137141 public StatementBuilder .OngoingReading prepareMatchOf (NodeDescription <?> nodeDescription ,
@@ -163,15 +167,15 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
163167 };
164168
165169 relationship = relationship .named (Constants .NAME_OF_SYNTHESIZED_RELATIONS );
166- List <Expression > expressions = new ArrayList <>();
170+ List <IdentifiableElement > expressions = new ArrayList <>();
167171 expressions .add (Functions .collect (Functions .id (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
168172 expressions .add (Functions .collect (Functions .id (targetNode )).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ));
169173 expressions .add (Functions .collect (Functions .id (relationship )).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ));
170174
171175 return match
172176 .where (conditionOrNoCondition (condition ))
173177 .optionalMatch (relationship )
174- .with (expressions .toArray (new Expression []{} ));
178+ .with (expressions .toArray (IdentifiableElement []:: new ));
175179 }
176180
177181 @ NonNull
@@ -619,6 +623,7 @@ public Collection<Expression> createReturnStatementForMatch(Neo4jPersistentEntit
619623 expression = Cypher .property (property .substring (0 , firstDot ), tail );
620624 } else {
621625 try {
626+ Assertions .isTrue (SourceVersion .isIdentifier (property ), "Name must be a valid identifier." );
622627 expression = Cypher .name (property );
623628 } catch (IllegalArgumentException e ) {
624629 if (e .getMessage ().endsWith ("." )) {
0 commit comments