@@ -66,24 +66,25 @@ 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 value = getStringFromAnnotation (ann .getValue ("value" ));
70- ref = Optional .of (value );
69+ String st = getStringFromAnnotation (ann .getValue ("value" ));
70+ ref = Optional .of (st );
7171
7272 } else if (an .contentEquals ("liquidjava.specification.RefinementPredicate" )) {
73- String value = getStringFromAnnotation (ann .getValue ("value" ));
74- getGhostFunction (value , element , ann . getPosition () );
73+ String st = getStringFromAnnotation (ann .getValue ("value" ));
74+ getGhostFunction (st , element );
7575
7676 } else if (an .contentEquals ("liquidjava.specification.RefinementAlias" )) {
77- String value = getStringFromAnnotation (ann .getValue ("value" ));
78- handleAlias (value , element , ann . getPosition () );
77+ String st = getStringFromAnnotation (ann .getValue ("value" ));
78+ handleAlias (st , element );
7979 }
8080 }
8181 if (ref .isPresent ()) {
8282 Predicate p = new Predicate (ref .get (), element );
83+
84+ // check if refinement is valid
8385 if (!p .getExpression ().isBooleanExpression ()) {
84- SourcePosition position = Utils .getAnnotationPosition (element , ref .get ());
85- throw new InvalidRefinementError (position , "Refinement predicate must be a boolean expression" ,
86- ref .get ());
86+ throw new InvalidRefinementError (element .getPosition (),
87+ "Refinement predicate must be a boolean expression" , ref .get ());
8788 }
8889 constr = Optional .of (p );
8990 }
@@ -116,7 +117,7 @@ public void handleStateSetsFromAnnotation(CtElement element) throws LJError {
116117 }
117118 if (an .contentEquals ("liquidjava.specification.Ghost" )) {
118119 CtLiteral <String > s = (CtLiteral <String >) ann .getAllValues ().get ("value" );
119- createStateGhost (s .getValue (), element , ann . getPosition () );
120+ createStateGhost (s .getValue (), ann , element );
120121 }
121122 }
122123 }
@@ -162,22 +163,24 @@ private void createStateSet(CtNewArray<String> e, int set, CtElement element) th
162163 }
163164 }
164165
165- protected GhostDTO getGhostDeclaration (String value , SourcePosition position ) throws LJError {
166+ protected GhostDTO getGhostDeclaration (String value , CtElement element ) throws LJError {
166167 try {
167168 return RefinementsParser .getGhostDeclaration (value );
168169 } catch (LJError e ) {
169170 // add location info to error
170- e .setPosition (position );
171+ SourcePosition annPosition = Utils .getAnnotationPosition (element , value );
172+ e .setPosition (annPosition );
171173 throw e ;
172174 }
173175 }
174176
175- private void createStateGhost (String string , CtElement element , SourcePosition position ) throws LJError {
176- GhostDTO gd = getGhostDeclaration (string , position );
177+ private void createStateGhost (String string , CtAnnotation <? extends Annotation > ann , CtElement element )
178+ throws LJError {
179+ GhostDTO gd = getGhostDeclaration (string , ann );
177180 if (!gd .paramTypes ().isEmpty ()) {
178181 throw new CustomError (
179182 "Ghost States have the class as parameter " + "by default, no other parameters are allowed" ,
180- position );
183+ ann . getPosition () );
181184 }
182185 // Set class as parameter of Ghost
183186 String qn = getQualifiedClassName (element );
@@ -228,15 +231,15 @@ protected Optional<GhostFunction> createStateGhost(int order, CtElement element)
228231 return Optional .empty ();
229232 }
230233
231- protected void getGhostFunction (String value , CtElement element , SourcePosition position ) throws LJError {
232- GhostDTO f = getGhostDeclaration (value , position );
234+ protected void getGhostFunction (String value , CtElement element ) throws LJError {
235+ GhostDTO f = getGhostDeclaration (value , element );
233236 if (element .getParent ()instanceof CtClass <?> klass ) {
234237 GhostFunction gh = new GhostFunction (f , factory , klass .getQualifiedName ());
235238 context .addGhostFunction (gh );
236239 }
237240 }
238241
239- protected void handleAlias (String ref , CtElement element , SourcePosition position ) throws LJError {
242+ protected void handleAlias (String ref , CtElement element ) throws LJError {
240243 try {
241244 AliasDTO a = RefinementsParser .getAliasDeclaration (ref );
242245 String klass = null ;
@@ -250,16 +253,18 @@ protected void handleAlias(String ref, CtElement element, SourcePosition positio
250253 }
251254 if (klass != null && path != null ) {
252255 a .parse (path );
256+ // refinement alias must return a boolean expression
253257 if (a .getExpression () != null && !a .getExpression ().isBooleanExpression ()) {
254- throw new InvalidRefinementError (position , "Refinement alias must return a boolean expression" ,
255- ref );
258+ throw new InvalidRefinementError (element . getPosition () ,
259+ "Refinement alias must return a boolean expression" , ref );
256260 }
257261 AliasWrapper aw = new AliasWrapper (a , factory , klass , path );
258262 context .addAlias (aw );
259263 }
260264 } catch (LJError e ) {
261265 // add location info to error
262- e .setPosition (position );
266+ SourcePosition pos = Utils .getAnnotationPosition (element , ref );
267+ e .setPosition (pos );
263268 throw e ;
264269 }
265270 }
0 commit comments