10
10
import { Recipe } from '../runtime/recipe/recipe.js' ;
11
11
import { Type } from '../runtime/type.js' ;
12
12
import { Particle } from '../runtime/recipe/particle.js' ;
13
+ import { Manifest } from '../runtime/manifest.js' ;
13
14
14
15
export class PlanGenerator {
15
- constructor ( private resolutions : Recipe [ ] , private scope : string = 'arcs.core.data' ) {
16
- }
16
+ constructor ( private resolutions : Recipe [ ] , private manifest : Manifest , private scope : string = 'arcs.core.data' ) { }
17
17
18
18
/** Generates a Kotlin file with plan classes derived from resolved recipes. */
19
19
async generate ( ) : Promise < string > {
@@ -35,7 +35,9 @@ export class PlanGenerator {
35
35
const particles = recipe . particles . map ( this . createParticle ) ;
36
36
37
37
const plan = `\
38
- object ${ planName } : Plan(listOf())` ;
38
+ object ${ planName } : Plan(listOf(
39
+ ${ particles . join ( '\n,' ) }
40
+ ))` ;
39
41
40
42
plans . push ( plan ) ;
41
43
}
@@ -44,11 +46,14 @@ object ${planName} : Plan(listOf())`;
44
46
}
45
47
46
48
createParticle ( particle : Particle ) : string {
49
+ const spec = particle . spec ;
50
+ const location = ( spec && ( spec . implBlobUrl || ( spec . implFile && spec . implFile . replace ( '/' , '.' ) ) ) ) || '' ;
51
+
47
52
return `\
48
53
Particle(
49
- ${ particle . name } ,
50
- ${ particle . spec . implFile . replace ( '/' , '.' ) }
51
- mapOf()
54
+ ${ particle . name } ,
55
+ " ${ location } ",
56
+ mapOf()
52
57
)` ;
53
58
}
54
59
@@ -96,22 +101,4 @@ ${this.scope === 'arcs.core.data' ? '' : 'import arcs.core.data.*'}
96
101
fileFooter ( ) : string {
97
102
return `` ;
98
103
}
99
-
100
- private mapOf ( items : Map < string , string > , indent : number ) : string {
101
- if ( items . size === 0 ) return 'mapOf()' ;
102
-
103
- const mapping = [ ...items . entries ( ) ] . map ( ( [ key , val ] ) => `"${ key } " to ${ val } ` ) ;
104
-
105
- return `mapOf(${ this . joinWithinLimit ( mapping , indent ) } )` ;
106
- }
107
-
108
- private joinWithinLimit ( items : string [ ] , indent : number , lineLength : number = 120 ) : string {
109
- for ( const delim of [ ', ' , '\n' + ' ' . repeat ( indent ) ] ) {
110
- const candidate = items . join ( delim ) ;
111
- const maxLength = Math . max ( ...candidate . split ( '\n' ) . map ( line => line . length ) ) ;
112
- if ( indent + maxLength <= lineLength ) return candidate ;
113
- }
114
-
115
- return items . join ( ', ' ) ; // Default: have poor formatting
116
- }
117
104
}
0 commit comments