@@ -227,40 +227,16 @@ public <T, A extends T> void visitCtAssignment(CtAssignment<T, A> assignement) {
227227 checkAssignment (name , varDecl .getType (), ex , assignement .getAssignment (), assignement , varDecl );
228228
229229 } else if (ex instanceof CtFieldWrite ) {
230+ System .out .println ("Got field write: " + assignement );
230231 CtFieldWrite <?> fw = ((CtFieldWrite <?>) ex );
231232 CtFieldReference <?> cr = fw .getVariable ();
232233 CtField <?> f = fw .getVariable ().getDeclaration ();
233234 String updatedVarName = String .format (thisFormat , cr .getSimpleName ());
234235 checkAssignment (updatedVarName , cr .getType (), ex , assignement .getAssignment (), assignement , f );
235- // corresponding ghost function update
236- CtMethod <?> transitionMethod = factory .createMethod ();
237- transitionMethod .setType (factory .createCtTypeReference (void .class ));
238- transitionMethod .setBody (factory .createCtBlock (factory .createCodeSnippetStatement ()));
239- transitionMethod .setSimpleName ("_" );
240-
241- transitionMethod .setParent (f .getDeclaringType ());
242- CtAnnotation <?> ann = factory .createAnnotation (factory .createCtTypeReference (StateRefinement .class ));
243-
244- String stateChangeRefinementTo = f .getSimpleName () + "(this) == " + updatedVarName ;
245- String stateChangeRefinementFrom = "true" ;
246- ann .addValue ("to" , stateChangeRefinementTo );
247- ann .addValue ("from" , stateChangeRefinementFrom );
248-
249- transitionMethod .addAnnotation (ann );
250-
251- System .out .println ("Target for invocation: " + fw .getTarget ());
252- CtInvocation <?> inv = factory .createInvocation (fw .getTarget (), transitionMethod .getReference (),
253- Collections .emptyList ());
254-
255- RefinedFunction rf = new RefinedFunction ();
256- rf .setName (transitionMethod .getSimpleName ());
257- rf .setType (transitionMethod .getType ());
258- rf .setRefReturn (new Predicate ());
259- rf .setClass (transitionMethod .getDeclaringType ().getQualifiedName ());
260236
237+ // corresponding ghost function update
261238 try {
262- AuxStateHandler .handleMethodState (transitionMethod , rf , this );
263- AuxStateHandler .checkTargetChanges (this , rf , inv .getTarget (), Collections .emptyMap (), inv );
239+ updateGhostField (fw );
264240 } catch (ParsingException e ) {
265241 ErrorHandler .printCostumeError (assignement , "ParsingException in `" + assignement + "` in class `"
266242 + f .getDeclaringType () + "` : " + e .getMessage (), errorEmitter );
@@ -628,4 +604,42 @@ private <T> void getPutVariableMetadada(CtElement elem, String name) {
628604 elem .putMetadata (REFINE_KEY , cref );
629605 }
630606
607+ private void updateGhostField (CtFieldWrite <?> fw ) throws ParsingException {
608+ CtField <?> f = fw .getVariable ().getDeclaration ();
609+ String updatedVarName = String .format (thisFormat , fw .getVariable ().getSimpleName ());
610+
611+ // transition method construction
612+ CtMethod <?> transitionMethod = factory .createMethod ();
613+ transitionMethod .setType (factory .createCtTypeReference (void .class ));
614+ transitionMethod .setBody (factory .createCtBlock (factory .createCodeSnippetStatement ()));
615+ transitionMethod .setSimpleName ("_" );
616+
617+ transitionMethod .setParent (f .getDeclaringType ());
618+ CtAnnotation <?> ann = factory .createAnnotation (factory .createCtTypeReference (StateRefinement .class ));
619+
620+ // state transition annatation construction
621+ String stateChangeRefinementTo = f .getSimpleName () + "(this) == " + updatedVarName ;
622+ String stateChangeRefinementFrom = "true" ;
623+ ann .addValue ("to" , stateChangeRefinementTo );
624+ ann .addValue ("from" , stateChangeRefinementFrom );
625+
626+ transitionMethod .addAnnotation (ann );
627+
628+ // extracting target from assignment
629+ System .out .println ("Target for invocation: " + fw .getTarget ());
630+ CtInvocation <?> inv = factory .createInvocation (fw .getTarget (), transitionMethod .getReference (),
631+ Collections .emptyList ());
632+
633+ // Refined function construction for invocation facilities reuse
634+ RefinedFunction rf = new RefinedFunction ();
635+ rf .setName (transitionMethod .getSimpleName ());
636+ rf .setType (transitionMethod .getType ());
637+ rf .setRefReturn (new Predicate ());
638+ rf .setClass (transitionMethod .getDeclaringType ().getQualifiedName ());
639+
640+ // applying transition:
641+ AuxStateHandler .handleMethodState (transitionMethod , rf , this );
642+ AuxStateHandler .checkTargetChanges (this , rf , inv .getTarget (), Collections .emptyMap (), inv );
643+ }
644+
631645}
0 commit comments