@@ -207,18 +207,8 @@ public void handleStateSetsFromAnnotation(CtElement element) throws LJError {
207207 if (an .contentEquals ("liquidjava.specification.StateSet" )) {
208208 set ++;
209209 CtExpression <?> nameValue = ann .getValues ().get ("name" );
210- String name = nameValue instanceof CtLiteral <?> literal && literal .getValue ()instanceof String value
211- ? value : null ;
212210 SourcePosition namePosition = nameValue == null ? null : Utils .getAnnotationValuePosition (nameValue );
213- if (nameValue != null && name == null )
214- throw new CustomError ("State set name must be a string literal" , namePosition );
215- if (name != null && name .isEmpty ())
216- name = null ;
217- if (name != null && (!name .matches ("[a-z][a-zA-Z0-9_]*" ) || name .equals (Keys .OLD ) || name .equals ("true" )
218- || name .equals ("false" )))
219- throw new CustomError (String .format (
220- "State set name '%s' must be an identifier that starts with a lowercase letter" , name ),
221- namePosition );
211+ String name = stateSetName (nameValue , namePosition );
222212 GhostFunction g = createStateSet ((CtNewArray <String >) ann .getAllValues ().get ("value" ),
223213 name != null ? name : String .format ("state%d" , set ), element );
224214 if (name != null )
@@ -234,6 +224,20 @@ public void handleStateSetsFromAnnotation(CtElement element) throws LJError {
234224 checkStateSetNameIsFree (named .getKey (), named .getValue ());
235225 }
236226
227+ /** The name given to a state set, or null when it has none */
228+ private static String stateSetName (CtExpression <?> nameValue , SourcePosition position ) throws LJError {
229+ if (nameValue == null )
230+ return null ;
231+ if (!(nameValue instanceof CtLiteral <?> literal && literal .getValue ()instanceof String name ))
232+ throw new CustomError ("State set name must be a string literal" , position );
233+ if (name .isEmpty ())
234+ return null ;
235+ if (!name .matches ("[a-z][a-zA-Z0-9_]*" ) || name .equals (Keys .OLD ) || name .equals ("true" ) || name .equals ("false" ))
236+ throw new CustomError (String .format (
237+ "State set name '%s' must be an identifier that starts with a lowercase letter" , name ), position );
238+ return name ;
239+ }
240+
237241 /** Reports a named state set whose name is also the name of a state, ghost or other state set of its class */
238242 private void checkStateSetNameIsFree (GhostFunction set , SourcePosition position ) throws LJError {
239243 String name = set .getName ();
0 commit comments