33 * SPDX-License-Identifier: GPL-2.0-only */
44package de .uka .ilkd .key .java .transformations .pipeline ;
55
6- import java .util .*;
7- import java .util .stream .Collectors ;
8-
9- import de .uka .ilkd .key .java .loader .JavaParserFactory ;
10- import de .uka .ilkd .key .java .transformations .ConstantExpressionEvaluator ;
11- import de .uka .ilkd .key .java .transformations .EvaluationException ;
12- import de .uka .ilkd .key .speclang .PositionedString ;
13- import de .uka .ilkd .key .speclang .jml .pretranslation .TextualJMLConstruct ;
14- import de .uka .ilkd .key .speclang .jml .pretranslation .TextualJMLLoopSpec ;
15- import de .uka .ilkd .key .speclang .njml .PreParser ;
16-
17- import org .key_project .util .collection .ImmutableList ;
18-
196import com .github .javaparser .JavaParser ;
207import com .github .javaparser .ast .CompilationUnit ;
218import com .github .javaparser .ast .Modifier ;
3118import com .github .javaparser .resolution .model .SymbolReference ;
3219import com .github .javaparser .resolution .types .ResolvedReferenceType ;
3320import com .github .javaparser .resolution .types .ResolvedType ;
21+ import de .uka .ilkd .key .java .Position ;
22+ import de .uka .ilkd .key .java .loader .JavaParserFactory ;
23+ import de .uka .ilkd .key .java .transformations .ConstantExpressionEvaluator ;
24+ import de .uka .ilkd .key .java .transformations .EvaluationException ;
25+ import de .uka .ilkd .key .speclang .PositionedString ;
26+ import de .uka .ilkd .key .speclang .jml .pretranslation .TextualJMLAssertStatement ;
27+ import de .uka .ilkd .key .speclang .jml .pretranslation .TextualJMLConstruct ;
28+ import de .uka .ilkd .key .speclang .jml .pretranslation .TextualJMLLoopSpec ;
29+ import de .uka .ilkd .key .speclang .njml .PreParser ;
3430import org .jspecify .annotations .NonNull ;
3531import org .jspecify .annotations .NullMarked ;
3632import org .jspecify .annotations .Nullable ;
33+ import org .key_project .util .collection .ImmutableList ;
3734import org .slf4j .Logger ;
3835import org .slf4j .LoggerFactory ;
3936
37+ import java .util .*;
38+ import java .util .stream .Collectors ;
39+
40+ import static de .uka .ilkd .key .java .transformations .MarkerStatementHelper .KEY_EXPR ;
41+
4042/**
4143 * @author Alexander Weigl
4244 * @version 1 (11/2/21)
4345 */
4446@ NullMarked
4547public class TransformationPipelineServices {
4648 private static final Logger LOGGER =
47- LoggerFactory .getLogger (TransformationPipelineServices .class );
49+ LoggerFactory .getLogger (TransformationPipelineServices .class );
4850
4951 private final TransformerCache cache ;
5052
@@ -53,7 +55,7 @@ public class TransformationPipelineServices {
5355 private List <PositionedString > warnings = new ArrayList <>(8 );
5456
5557 public TransformationPipelineServices (JavaParserFactory javaParserFactory ,
56- TransformerCache cache ) {
58+ TransformerCache cache ) {
5759 this .cache = cache ;
5860 this .javaParserFactory = javaParserFactory ;
5961 }
@@ -139,7 +141,7 @@ public String getId(TypeDeclaration<?> td) {
139141 * according to JLS Sect. 4.5.5
140142 *
141143 * @return the default value of the given type
142- * according to JLS Sect. 4.5.5
144+ * according to JLS Sect. 4.5.5
143145 */
144146 public Expression getDefaultValue (Type type ) {
145147 if (type instanceof ReferenceType ) {
@@ -270,7 +272,7 @@ public NodeList<Statement> getInitializers(ClassOrInterfaceDeclaration cd) {
270272 if (member instanceof InitializerDeclaration init &&
271273 !init .isStatic ()) {
272274 String name =
273- PipelineConstants .OBJECT_INITIALIZER_IDENTIFIER + objectInitializerCount ;
275+ PipelineConstants .OBJECT_INITIALIZER_IDENTIFIER + objectInitializerCount ;
274276 var initializerMethod = cd .addMethod (name , Modifier .DefaultKeyword .PRIVATE );
275277 initializerMethod .setBody (init .getBody ().clone ());
276278 initializerMethod .setParentNode (cd );
@@ -282,9 +284,9 @@ public NodeList<Statement> getInitializers(ClassOrInterfaceDeclaration cd) {
282284 if (variable .getInitializer ().isPresent ()) {
283285 Expression fieldInit = variable .getInitializer ().get ();
284286 final var access = new FieldAccessExpr (
285- new ThisExpr (), new NodeList <>(), variable .getName ());
287+ new ThisExpr (), new NodeList <>(), variable .getName ());
286288 var fieldCopy =
287- new AssignExpr (access , fieldInit .clone (), AssignExpr .Operator .ASSIGN );
289+ new AssignExpr (access , fieldInit .clone (), AssignExpr .Operator .ASSIGN );
288290 result .add (new ExpressionStmt (fieldCopy ));
289291 }
290292 }
@@ -317,8 +319,7 @@ public Expression getDefaultValue(ResolvedType type) {
317319 case "int" , "byte" , "short" -> new IntegerLiteralExpr ("0" );
318320 case "char" -> new CharLiteralExpr ("0" );
319321 case "float" , "double" -> new DoubleLiteralExpr ("0.0" );
320- default ->
321- throw new IllegalStateException ("Unexpected value: " + name .toLowerCase ());
322+ default -> throw new IllegalStateException ("Unexpected value: " + name .toLowerCase ());
322323 };
323324 }
324325
@@ -360,6 +361,16 @@ public void attachSpec(Node node, @Nullable String spec) {
360361 LOGGER .info ("Generated specification {} for {}" , spec , node );
361362 }
362363
364+ public void attachExpr (Node node , @ Nullable String spec ) {
365+ if (spec == null )
366+ return ;
367+ PreParser pp = getPreParser ();
368+ ImmutableList <TextualJMLConstruct > specification = pp .parseMethodLevel (spec , null , Position .UNDEFINED );
369+ TextualJMLAssertStatement expr = (TextualJMLAssertStatement ) specification .get (0 );
370+ node .setData (KEY_EXPR , expr .getContext ());
371+ LOGGER .info ("Generated specification {} for {}" , spec , node );
372+ }
373+
363374
364375 /**
365376 * Cache of important data. This is done mainly for performance reasons.
0 commit comments