@@ -21,6 +21,8 @@ import scala.collection.JavaConversions._
21
21
22
22
object GenFactories {
23
23
24
+ val generatorSource = new File (" GenFactories.scala" )
25
+
24
26
val topPart = """
25
27
package org.scalatest.matchers
26
28
@@ -3061,70 +3063,71 @@ private[scalatest] class MatcherFactory$arity$Macro[-SC, $typeConstructors$] {
3061
3063
}
3062
3064
3063
3065
val targetFile = new File (targetDir, " MatcherFactory" + arity + " .scala" )
3064
- val bw = new BufferedWriter (new FileWriter (targetFile))
3065
-
3066
- try {
3067
-
3068
- val topSt = new org.antlr.stringtemplate.StringTemplate (topPart)
3069
- setCommonOnes(arity, topSt)
3070
- val nTypeclassInstances =
3071
- if (arity == 1 ) " one typeclass instance"
3072
- else {
3073
- val numStr =
3074
- arity match {
3075
- case 2 => " two"
3076
- case 3 => " three"
3077
- case 4 => " four"
3078
- case 5 => " five"
3079
- case 6 => " six"
3080
- case 7 => " seven"
3081
- case 8 => " eight"
3082
- case 9 => " nine"
3083
- }
3084
- numStr + " typeclass instances"
3066
+ if (! targetFile.exists || generatorSource.lastModified > targetFile.lastModified) {
3067
+ val bw = new BufferedWriter (new FileWriter (targetFile))
3068
+
3069
+ try {
3070
+
3071
+ val topSt = new org.antlr.stringtemplate.StringTemplate (topPart)
3072
+ setCommonOnes(arity, topSt)
3073
+ val nTypeclassInstances =
3074
+ if (arity == 1 ) " one typeclass instance"
3075
+ else {
3076
+ val numStr =
3077
+ arity match {
3078
+ case 2 => " two"
3079
+ case 3 => " three"
3080
+ case 4 => " four"
3081
+ case 5 => " five"
3082
+ case 6 => " six"
3083
+ case 7 => " seven"
3084
+ case 8 => " eight"
3085
+ case 9 => " nine"
3086
+ }
3087
+ numStr + " typeclass instances"
3088
+ }
3089
+ topSt.setAttribute(" nTypeclassInstances" , nTypeclassInstances)
3090
+ bw.write(transform(topSt.toString))
3091
+
3092
+ // Now do the and/or methods that take matcher factories of various arities
3093
+ for (passedArity <- 1 to MaxArity - arity) {
3094
+ val resultArity = arity + passedArity
3095
+ val middleSt = new org.antlr.stringtemplate.StringTemplate (middlePart)
3096
+ setCommonOnes(arity, middleSt)
3097
+ middleSt.setAttribute(" passedArity" , passedArity);
3098
+ middleSt.setAttribute(" resultArity" , resultArity);
3099
+ val resultColonSeparatedTCNs = (1 to resultArity).map(" TC" + _).mkString(" : " )
3100
+ middleSt.setAttribute(" resultColonSeparatedTCNs" , resultColonSeparatedTCNs);
3101
+ val resultCommaSeparatedTCNs = (1 to resultArity).map(" TC" + _).mkString(" , " )
3102
+ middleSt.setAttribute(" resultCommaSeparatedTCNs" , resultCommaSeparatedTCNs);
3103
+ val passedTypeConstructors = (arity + 1 to resultArity).map(" TC" + _ + " [_]" ).mkString(" , " )
3104
+ middleSt.setAttribute(" passedTypeConstructors" , passedTypeConstructors);
3105
+ val passedCommaSeparatedTCNs = (arity + 1 to resultArity).map(" TC" + _).mkString(" , " )
3106
+ middleSt.setAttribute(" passedCommaSeparatedTCNs" , passedCommaSeparatedTCNs);
3107
+ bw.write(transform(middleSt.toString))
3085
3108
}
3086
- topSt.setAttribute(" nTypeclassInstances" , nTypeclassInstances)
3087
- bw.write(transform(topSt.toString))
3088
-
3089
- // Now do the and/or methods that take matcher factories of various arities
3090
- for (passedArity <- 1 to MaxArity - arity) {
3091
- val resultArity = arity + passedArity
3092
- val middleSt = new org.antlr.stringtemplate.StringTemplate (middlePart)
3093
- setCommonOnes(arity, middleSt)
3094
- middleSt.setAttribute(" passedArity" , passedArity);
3095
- middleSt.setAttribute(" resultArity" , resultArity);
3096
- val resultColonSeparatedTCNs = (1 to resultArity).map(" TC" + _).mkString(" : " )
3097
- middleSt.setAttribute(" resultColonSeparatedTCNs" , resultColonSeparatedTCNs);
3098
- val resultCommaSeparatedTCNs = (1 to resultArity).map(" TC" + _).mkString(" , " )
3099
- middleSt.setAttribute(" resultCommaSeparatedTCNs" , resultCommaSeparatedTCNs);
3100
- val passedTypeConstructors = (arity + 1 to resultArity).map(" TC" + _ + " [_]" ).mkString(" , " )
3101
- middleSt.setAttribute(" passedTypeConstructors" , passedTypeConstructors);
3102
- val passedCommaSeparatedTCNs = (arity + 1 to resultArity).map(" TC" + _).mkString(" , " )
3103
- middleSt.setAttribute(" passedCommaSeparatedTCNs" , passedCommaSeparatedTCNs);
3104
- bw.write(transform(middleSt.toString))
3105
- }
3106
3109
3107
- // Just don't put the and/or DSL under MatcherFactory<MaxArity>, even though the ones that could
3108
- // return another MatcherFactory<MaxArity> could be implemented. That would mean only *some* of the
3109
- // DSL is implemented under MatcherFactory<MaxArity>. I'd rather just say none of it is.
3110
- if (arity < MaxArity ) {
3111
- def doABottomHalf (bottomSt : org.antlr.stringtemplate.StringTemplate ) {
3112
- setCommonOnes(arity, bottomSt)
3113
- bottomSt.setAttribute(" arityPlusOne" , arity + 1 );
3114
- bw.write(transform(bottomSt.toString))
3110
+ // Just don't put the and/or DSL under MatcherFactory<MaxArity>, even though the ones that could
3111
+ // return another MatcherFactory<MaxArity> could be implemented. That would mean only *some* of the
3112
+ // DSL is implemented under MatcherFactory<MaxArity>. I'd rather just say none of it is.
3113
+ if (arity < MaxArity ) {
3114
+ def doABottomHalf (bottomSt : org.antlr.stringtemplate.StringTemplate ) {
3115
+ setCommonOnes(arity, bottomSt)
3116
+ bottomSt.setAttribute(" arityPlusOne" , arity + 1 );
3117
+ bw.write(transform(bottomSt.toString))
3118
+ }
3119
+ doABottomHalf(new org.antlr.stringtemplate.StringTemplate (bottomPart1)) // Do in two halves, because hitting class file max string size limit
3120
+ doABottomHalf(new org.antlr.stringtemplate.StringTemplate (bottomPart2))
3121
+ }
3122
+ else {
3123
+ bw.write(" }\n " )
3115
3124
}
3116
- doABottomHalf(new org.antlr.stringtemplate.StringTemplate (bottomPart1)) // Do in two halves, because hitting class file max string size limit
3117
- doABottomHalf(new org.antlr.stringtemplate.StringTemplate (bottomPart2))
3118
3125
}
3119
- else {
3120
- bw.write( " } \n " )
3126
+ finally {
3127
+ bw.close( )
3121
3128
}
3122
-
3123
- targetFile
3124
- }
3125
- finally {
3126
- bw.close()
3127
3129
}
3130
+ targetFile
3128
3131
}
3129
3132
}
3130
3133
0 commit comments