33import java .io .IOException ;
44import java .io .Serializable ;
55import java .util .ArrayList ;
6+ import java .util .HashSet ;
67import java .util .List ;
78import java .util .Map ;
9+ import java .util .Map .Entry ;
10+ import java .util .Set ;
811
912import org .spoofax .interpreter .terms .IStrategoTerm ;
1013import org .strategoxt .HybridInterpreter ;
1316import org .sugarj .common .FileCommands ;
1417import org .sugarj .common .errors .SourceCodeException ;
1518import org .sugarj .common .path .Path ;
16- import org .sugarj .util .Pair ;
1719
1820public abstract class AbstractBaseProcessor implements IBaseProcessor , Serializable {
1921
@@ -38,39 +40,42 @@ public String getRelativeNamespaceSep() {
3840
3941 // Returns true is files were generated or if there were no files to generate
4042 // Returns false if generation was skipped due to generateFiles being false
41- public void compile (
43+ public Set < Path > compile (
4244 Path outFile ,
4345 String source ,
4446 Path bin ,
4547 List <Path > path ,
46- Map <Path , Pair <Path , String >> deferredSourceFilesForSourceFile ,
47- Map <Path , Integer > generatedFileHashes
48+ Map <Path , String > deferredSourceFilesForSourceFile
4849 ) throws IOException , ClassNotFoundException , SourceCodeException {
4950
5051
51- List <Path > outFiles = new ArrayList <Path >();
52+ List <Path > outSourceFiles = new ArrayList <>();
53+ Set <Path > generatedFiles = new HashSet <>();
5254
53- for (Pair <Path , String > deferredSource : deferredSourceFilesForSourceFile .values ()) {
54- String code = deferredSource .b ;
55- writeToFile (generatedFileHashes , deferredSource .a , code );
56- outFiles .add (deferredSource .a );
55+ for (Entry <Path , String > deferredSource : deferredSourceFilesForSourceFile .entrySet ()) {
56+ String code = deferredSource .getValue ();
57+
58+ writeToFile (generatedFiles , deferredSource .getKey (), code );
59+ outSourceFiles .add (deferredSource .getKey ());
5760 }
5861
5962 if (!source .isEmpty ()) {
60- writeToFile (generatedFileHashes , outFile , source );
61- outFiles .add (outFile );
63+ writeToFile (generatedFiles , outFile , source );
64+ outSourceFiles .add (outFile );
6265 }
6366
64- if (!outFiles .isEmpty ()) {
65- List <Path > generatedByCompiler = compile (outFiles , bin , path );
67+ if (!outSourceFiles .isEmpty ()) {
68+ List <Path > generatedByCompiler = compile (outSourceFiles , bin , path );
6669 for (Path p : generatedByCompiler )
67- generatedFileHashes . put ( p , FileCommands . fileHash ( p ) );
70+ generatedFiles . add ( p );
6871 }
72+
73+ return generatedFiles ;
6974 }
7075
71- private void writeToFile (Map <Path , Integer > generatedFileHashes , Path file , String content ) throws IOException {
76+ private void writeToFile (Set <Path > generatedFiles , Path file , String content ) throws IOException {
7277 FileCommands .writeToFile (file , content );
73- generatedFileHashes . put (file , FileCommands . fileHash ( file ) );
78+ generatedFiles . add (file );
7479 }
7580
7681 public String getImportLocalName (IStrategoTerm decl ) { return null ; }
0 commit comments