@@ -66,22 +66,20 @@ 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 ()) {
8684 throw new InvalidRefinementError (element .getPosition (),
8785 "Refinement predicate must be a boolean expression" , ref .get ());
@@ -117,7 +115,7 @@ public void handleStateSetsFromAnnotation(CtElement element) throws LJError {
117115 }
118116 if (an .contentEquals ("liquidjava.specification.Ghost" )) {
119117 CtLiteral <String > s = (CtLiteral <String >) ann .getAllValues ().get ("value" );
120- createStateGhost (s .getValue (), ann , element );
118+ createStateGhost (s .getValue (), element , ann . getPosition () );
121119 }
122120 }
123121 }
@@ -163,24 +161,22 @@ private void createStateSet(CtNewArray<String> e, int set, CtElement element) th
163161 }
164162 }
165163
166- protected GhostDTO getGhostDeclaration (String value , CtElement element ) throws LJError {
164+ protected GhostDTO getGhostDeclaration (String value , SourcePosition position ) throws LJError {
167165 try {
168166 return RefinementsParser .getGhostDeclaration (value );
169167 } catch (LJError e ) {
170168 // add location info to error
171- SourcePosition annPosition = Utils .getAnnotationPosition (element , value );
172- e .setPosition (annPosition );
169+ e .setPosition (position );
173170 throw e ;
174171 }
175172 }
176173
177- private void createStateGhost (String string , CtAnnotation <? extends Annotation > ann , CtElement element )
178- throws LJError {
179- GhostDTO gd = getGhostDeclaration (string , ann );
174+ private void createStateGhost (String string , CtElement element , SourcePosition position ) throws LJError {
175+ GhostDTO gd = getGhostDeclaration (string , position );
180176 if (!gd .paramTypes ().isEmpty ()) {
181177 throw new CustomError (
182178 "Ghost States have the class as parameter " + "by default, no other parameters are allowed" ,
183- ann . getPosition () );
179+ position );
184180 }
185181 // Set class as parameter of Ghost
186182 String qn = getQualifiedClassName (element );
@@ -231,15 +227,15 @@ protected Optional<GhostFunction> createStateGhost(int order, CtElement element)
231227 return Optional .empty ();
232228 }
233229
234- protected void getGhostFunction (String value , CtElement element ) throws LJError {
235- GhostDTO f = getGhostDeclaration (value , element );
230+ protected void getGhostFunction (String value , CtElement element , SourcePosition position ) throws LJError {
231+ GhostDTO f = getGhostDeclaration (value , position );
236232 if (element .getParent ()instanceof CtClass <?> klass ) {
237233 GhostFunction gh = new GhostFunction (f , factory , klass .getQualifiedName ());
238234 context .addGhostFunction (gh );
239235 }
240236 }
241237
242- protected void handleAlias (String ref , CtElement element ) throws LJError {
238+ protected void handleAlias (String ref , CtElement element , SourcePosition position ) throws LJError {
243239 try {
244240 AliasDTO a = RefinementsParser .getAliasDeclaration (ref );
245241 String klass = null ;
@@ -253,7 +249,6 @@ protected void handleAlias(String ref, CtElement element) throws LJError {
253249 }
254250 if (klass != null && path != null ) {
255251 a .parse (path );
256- // refinement alias must return a boolean expression
257252 if (a .getExpression () != null && !a .getExpression ().isBooleanExpression ()) {
258253 throw new InvalidRefinementError (element .getPosition (),
259254 "Refinement alias must return a boolean expression" , ref );
@@ -263,8 +258,7 @@ protected void handleAlias(String ref, CtElement element) throws LJError {
263258 }
264259 } catch (LJError e ) {
265260 // add location info to error
266- SourcePosition pos = Utils .getAnnotationPosition (element , ref );
267- e .setPosition (pos );
261+ e .setPosition (position );
268262 throw e ;
269263 }
270264 }
0 commit comments