@@ -66,25 +66,24 @@ public Optional<Predicate> getRefinementFromAnnotation(CtElement element) throws
6666 for (CtAnnotation <? extends Annotation > ann : element .getAnnotations ()) {
6767 String an = ann .getActualAnnotation ().annotationType ().getCanonicalName ();
6868 if (an .contentEquals ("liquidjava.specification.Refinement" )) {
69- String st = getStringFromAnnotation (ann .getValue ("value" ));
70- ref = Optional .of (st );
69+ String value = getStringFromAnnotation (ann .getValue ("value" ));
70+ ref = Optional .of (value );
7171
7272 } else if (an .contentEquals ("liquidjava.specification.RefinementPredicate" )) {
73- String st = getStringFromAnnotation (ann .getValue ("value" ));
74- getGhostFunction (st , element );
73+ String value = getStringFromAnnotation (ann .getValue ("value" ));
74+ getGhostFunction (value , element , ann . getPosition () );
7575
7676 } else if (an .contentEquals ("liquidjava.specification.RefinementAlias" )) {
77- String st = getStringFromAnnotation (ann .getValue ("value" ));
78- handleAlias (st , element );
77+ String value = getStringFromAnnotation (ann .getValue ("value" ));
78+ handleAlias (value , element , ann . getPosition () );
7979 }
8080 }
8181 if (ref .isPresent ()) {
8282 Predicate p = new Predicate (ref .get (), element );
83-
84- // check if refinement is valid
8583 if (!p .getExpression ().isBooleanExpression ()) {
86- throw new InvalidRefinementError (element .getPosition (),
87- "Refinement predicate must be a boolean expression" , ref .get ());
84+ SourcePosition position = Utils .getAnnotationPosition (element , ref .get ());
85+ throw new InvalidRefinementError (position , "Refinement predicate must be a boolean expression" ,
86+ ref .get ());
8887 }
8988 constr = Optional .of (p );
9089 }
@@ -117,7 +116,7 @@ public void handleStateSetsFromAnnotation(CtElement element) throws LJError {
117116 }
118117 if (an .contentEquals ("liquidjava.specification.Ghost" )) {
119118 CtLiteral <String > s = (CtLiteral <String >) ann .getAllValues ().get ("value" );
120- createStateGhost (s .getValue (), ann , element );
119+ createStateGhost (s .getValue (), element , ann . getPosition () );
121120 }
122121 }
123122 }
@@ -163,13 +162,22 @@ private void createStateSet(CtNewArray<String> e, int set, CtElement element) th
163162 }
164163 }
165164
166- private void createStateGhost (String string , CtAnnotation <? extends Annotation > ann , CtElement element )
167- throws LJError {
168- GhostDTO gd = RefinementsParser .getGhostDeclaration (string );
165+ protected GhostDTO getGhostDeclaration (String value , SourcePosition position ) throws LJError {
166+ try {
167+ return RefinementsParser .getGhostDeclaration (value );
168+ } catch (LJError e ) {
169+ // add location info to error
170+ e .setPosition (position );
171+ throw e ;
172+ }
173+ }
174+
175+ private void createStateGhost (String string , CtElement element , SourcePosition position ) throws LJError {
176+ GhostDTO gd = getGhostDeclaration (string , position );
169177 if (!gd .paramTypes ().isEmpty ()) {
170178 throw new CustomError (
171179 "Ghost States have the class as parameter " + "by default, no other parameters are allowed" ,
172- ann . getPosition () );
180+ position );
173181 }
174182 // Set class as parameter of Ghost
175183 String qn = getQualifiedClassName (element );
@@ -220,15 +228,15 @@ protected Optional<GhostFunction> createStateGhost(int order, CtElement element)
220228 return Optional .empty ();
221229 }
222230
223- protected void getGhostFunction (String value , CtElement element ) throws LJError {
224- GhostDTO f = RefinementsParser . getGhostDeclaration (value );
231+ protected void getGhostFunction (String value , CtElement element , SourcePosition position ) throws LJError {
232+ GhostDTO f = getGhostDeclaration (value , position );
225233 if (element .getParent ()instanceof CtClass <?> klass ) {
226234 GhostFunction gh = new GhostFunction (f , factory , klass .getQualifiedName ());
227235 context .addGhostFunction (gh );
228236 }
229237 }
230238
231- protected void handleAlias (String ref , CtElement element ) throws LJError {
239+ protected void handleAlias (String ref , CtElement element , SourcePosition position ) throws LJError {
232240 try {
233241 AliasDTO a = RefinementsParser .getAliasDeclaration (ref );
234242 String klass = null ;
@@ -242,18 +250,16 @@ protected void handleAlias(String ref, CtElement element) throws LJError {
242250 }
243251 if (klass != null && path != null ) {
244252 a .parse (path );
245- // refinement alias must return a boolean expression
246253 if (a .getExpression () != null && !a .getExpression ().isBooleanExpression ()) {
247- throw new InvalidRefinementError (element . getPosition () ,
248- "Refinement alias must return a boolean expression" , ref );
254+ throw new InvalidRefinementError (position , "Refinement alias must return a boolean expression" ,
255+ ref );
249256 }
250257 AliasWrapper aw = new AliasWrapper (a , factory , klass , path );
251258 context .addAlias (aw );
252259 }
253260 } catch (LJError e ) {
254261 // add location info to error
255- SourcePosition pos = Utils .getAnnotationPosition (element , ref );
256- e .setPosition (pos );
262+ e .setPosition (position );
257263 throw e ;
258264 }
259265 }
0 commit comments