33 * SPDX-License-Identifier: GPL-2.0-only */
44package de .uka .ilkd .key .gui ;
55
6- import java .io .BufferedReader ;
7- import java .io .File ;
8- import java .io .FileReader ;
6+ import org .slf4j .Logger ;
7+ import org .slf4j .LoggerFactory ;
8+
9+ import javax .swing .tree .DefaultMutableTreeNode ;
10+ import javax .swing .tree .DefaultTreeModel ;
911import java .io .IOException ;
1012import java .nio .charset .StandardCharsets ;
13+ import java .nio .file .Files ;
14+ import java .nio .file .Path ;
1115import java .util .ArrayList ;
1216import java .util .Enumeration ;
1317import java .util .List ;
1418import java .util .Properties ;
15- import javax .swing .tree .DefaultMutableTreeNode ;
16- import javax .swing .tree .DefaultTreeModel ;
17-
18- import org .slf4j .Logger ;
19- import org .slf4j .LoggerFactory ;
2019
2120/**
2221 * This class wraps a {@link java.io.File} and has a special {@link #toString()} method only using
@@ -74,59 +73,59 @@ public class Example {
7473 */
7574 public static final String EXPORT_FILE_PREFIX = "example.exportFile." ;
7675
77- public final File exampleFile ;
78- public final File directory ;
76+ public final Path exampleFile ;
77+ public final Path directory ;
7978 public final String description ;
8079 public final Properties properties ;
8180
82- public Example (File file ) throws IOException {
81+ public Example (Path file ) throws IOException {
8382 this .exampleFile = file ;
84- this .directory = file .getParentFile ();
83+ this .directory = file .getParent ();
8584 this .properties = new Properties ();
8685 StringBuilder sb = new StringBuilder ();
8786 extractDescription (file , sb , properties );
8887 this .description = sb .toString ();
8988 }
9089
91- public File getDirectory () {
90+ public Path getDirectory () {
9291 return directory ;
9392 }
9493
95- public File getProofFile () {
96- return new File ( directory , properties .getProperty (KEY_PROOF_FILE , PROOF_FILE_NAME ));
94+ public Path getProofFile () {
95+ return directory . resolve ( properties .getProperty (KEY_PROOF_FILE , PROOF_FILE_NAME ));
9796 }
9897
99- public File getObligationFile () {
100- return new File ( directory , properties .getProperty (KEY_FILE , KEY_FILE_NAME ));
98+ public Path getObligationFile () {
99+ return directory . resolve ( properties .getProperty (KEY_FILE , KEY_FILE_NAME ));
101100 }
102101
103102 public String getName () {
104- return properties .getProperty (KEY_NAME , directory .getName ());
103+ return properties .getProperty (KEY_NAME , directory .getFileName (). toString ());
105104 }
106105
107106 public String getDescription () {
108107 return description ;
109108 }
110109
111- public File getExampleFile () {
110+ public Path getExampleFile () {
112111 return exampleFile ;
113112 }
114113
115- public List <File > getAdditionalFiles () {
116- var result = new ArrayList <File >();
114+ public List <Path > getAdditionalFiles () {
115+ var result = new ArrayList <Path >();
117116 int i = 1 ;
118117 while (properties .containsKey (ADDITIONAL_FILE_PREFIX + i )) {
119- result .add (new File ( directory , properties .getProperty (ADDITIONAL_FILE_PREFIX + i )));
118+ result .add (directory . resolve ( properties .getProperty (ADDITIONAL_FILE_PREFIX + i )));
120119 i ++;
121120 }
122121 return result ;
123122 }
124123
125- public List <File > getExportFiles () {
126- ArrayList < File > result = new ArrayList <>();
124+ public List <Path > getExportFiles () {
125+ var result = new ArrayList <Path >();
127126 int i = 1 ;
128127 while (properties .containsKey (EXPORT_FILE_PREFIX + i )) {
129- result .add (new File ( directory , properties .getProperty (EXPORT_FILE_PREFIX + i )));
128+ result .add (directory . resolve ( properties .getProperty (EXPORT_FILE_PREFIX + i )));
130129 i ++;
131130 }
132131 return result ;
@@ -143,12 +142,12 @@ public String toString() {
143142
144143 public void addToTreeModel (DefaultTreeModel model ) {
145144 DefaultMutableTreeNode node =
146- findChild ((DefaultMutableTreeNode ) model .getRoot (), getPath (), 0 );
145+ findChild ((DefaultMutableTreeNode ) model .getRoot (), getPath (), 0 );
147146 node .add (new DefaultMutableTreeNode (this ));
148147 }
149148
150149 private DefaultMutableTreeNode findChild (DefaultMutableTreeNode root , String [] path ,
151- int from ) {
150+ int from ) {
152151 if (from == path .length ) {
153152 return root ;
154153 }
@@ -169,24 +168,23 @@ public boolean hasProof() {
169168 return properties .containsKey (KEY_PROOF_FILE );
170169 }
171170
172- private static StringBuilder extractDescription (File file , StringBuilder sb ,
173- Properties properties ) {
174- try (BufferedReader r = new BufferedReader (new FileReader (file , StandardCharsets .UTF_8 ))) {
175- String line ;
171+ private static StringBuilder extractDescription (Path file , StringBuilder sb ,
172+ Properties properties ) {
173+ try {
176174 boolean emptyLineSeen = false ;
177- while (( line = r . readLine ()) != null ) {
175+ for ( var line : Files . readAllLines ( file , StandardCharsets . UTF_8 ) ) {
178176 if (emptyLineSeen ) {
179177 sb .append (line ).append ("\n " );
180178 } else {
181179 String trimmed = line .trim ();
182- if (trimmed .length () == 0 ) {
180+ if (trimmed .isEmpty () ) {
183181 emptyLineSeen = true ;
184- } else if (trimmed .startsWith ("#" )) {
185- // ignore
186182 } else {
187- String [] entry = trimmed .split (" *[:=] *" , 2 );
188- if (entry .length > 1 ) {
189- properties .put (entry [0 ], entry [1 ]);
183+ if (!trimmed .startsWith ("#" )) {
184+ String [] entry = trimmed .split (" *[:=] *" , 2 );
185+ if (entry .length > 1 ) {
186+ properties .put (entry [0 ], entry [1 ]);
187+ }
190188 }
191189 }
192190 }
0 commit comments