Skip to content

Commit e59c141

Browse files
committed
Updated support for function parameters
1 parent ad07150 commit e59c141

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/main/scala/scoverage/plugin.scala

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,23 @@ class ScoverageComponent(val global: Global)
138138

139139
case EmptyTree => super.transform(tree)
140140

141-
// This AST node corresponds to the following Scala code: fun(args)
142-
case apply: Apply =>
143-
instrument(treeCopy.Apply(apply, apply.fun, transformStatements(apply.args)))
141+
case a: ApplyDynamic =>
142+
println("ApplyDynamic: " + a.toString() + " " + a.symbol)
143+
tree
144+
145+
/** This AST node corresponds to the following Scala code: fun(args)
146+
* With the guard, we are checking for case only applications
147+
* eg Currency.apply("USD")
148+
* todo decide if we should instrument the outer call, or just the param applys
149+
*/
150+
case a: Apply if a.symbol.isCaseApplyOrUnapply =>
151+
treeCopy.Apply(a, a.fun, transformStatements(a.args))
152+
153+
/** This AST node corresponds to the following Scala code: fun(args)
154+
* todo decide if we should instrument the outer call, or just the param applys
155+
*/
156+
case a: Apply =>
157+
treeCopy.Apply(a, a.fun, transformStatements(a.args))
144158

145159
/** pattern match with syntax `Block(stats, expr)`.
146160
* This AST node corresponds to the following Scala code:
@@ -164,21 +178,33 @@ class ScoverageComponent(val global: Global)
164178
updateLocation(c.symbol)
165179
super.transform(tree)
166180

167-
case d: DefDef if tree.symbol.isConstructor && (tree.symbol.isTrait || tree.symbol.isModule) => tree
181+
case d: DefDef if d.symbol.isConstructor && d.symbol.isPrimaryConstructor && d.symbol.isCase =>
182+
println("CASE CONSTRUCTOR 1: " + d.toString() + " " + d.symbol)
183+
tree
184+
185+
case d: DefDef if d.symbol.isConstructor && (d.symbol.isTrait || d.symbol.isModule) =>
186+
println("DefDef isConstructor 1: " + d.toString() + " " + d.symbol)
187+
tree
168188

169189
// todo handle constructors, as a method?
170-
case d: DefDef if tree.symbol.isConstructor => super.transform(tree)
190+
case d: DefDef if tree.symbol.isConstructor =>
191+
println("DefDef isConstructor 2: " + d.toString() + " " + d.symbol)
192+
super.transform(tree)
171193

172194
/**
195+
* Case class accessors for vals
173196
* EG for case class CreditReject(req: MarketOrderRequest, client: ActorRef)
174197
* <stable> <caseaccessor> <accessor> <paramaccessor> def req: com.sksamuel.scoverage.samples.MarketOrderRequest
175198
* <stable> <caseaccessor> <accessor> <paramaccessor> def client: akka.actor.ActorRef
176199
*/
177200
case d: DefDef if d.symbol.isCaseAccessor =>
178201
super.transform(tree)
179202

203+
// Compiler generated case apply and unapply. Ignore these
204+
case d: DefDef if d.symbol.isCaseApplyOrUnapply => tree
205+
180206
case d: DefDef if d.symbol.isCase =>
181-
//println("CASE: " + d.toString() + " " + d.symbol)
207+
println("CASE: " + d.toString() + " " + d.symbol)
182208
super.transform(tree)
183209

184210
// top level vals todo should instrument the rhs
@@ -195,26 +221,24 @@ class ScoverageComponent(val global: Global)
195221
case d: DefDef if d.symbol.isGetter =>
196222
super.transform(tree)
197223

198-
// for field definitions generated for primary constructor
199-
case d: DefDef if d.symbol.isParamAccessor && d.symbol.isAccessor => tree
224+
case d: DefDef if d.symbol.isParamAccessor && d.symbol.isAccessor =>
225+
println("PARAM ACCESSOR: " + d.toString() + " " + d.symbol)
226+
tree
200227

201228
// generated setters todo check the accessor flag is not set on user setters
202-
case d: DefDef if d.symbol.isAccessor && d.symbol.isSetter => tree
229+
case d: DefDef if d.symbol.isAccessor && d.symbol.isSetter =>
230+
println("PARAM isAccessor isSetter: " + d.toString() + " " + d.symbol)
231+
tree
203232

204-
// abstract methods ??
205-
case d: DefDef if tree.symbol.isDeferred => super.transform(tree)
233+
// was `abstract' for members | trait is virtual
234+
case d: DefDef if tree.symbol.isDeferred => tree
206235

207236
/** eg
208237
* override <synthetic> def hashCode(): Int
209238
* <synthetic> def copy$default$1: com.sksamuel.scoverage.samples.MarketOrderRequest
210239
*/
211240
case d: DefDef if d.symbol.isSynthetic => tree
212241

213-
case d: DefDef if d.symbol.isCaseApplyOrUnapply =>
214-
println("isCaseApplyOrUnapply: " + d.toString() + " " + d.symbol)
215-
updateLocation(d.symbol)
216-
super.transform(tree)
217-
218242
/** Match all remaining def definitions
219243
*
220244
* If the return type is not specified explicitly (i.e. is meant to be inferred),

0 commit comments

Comments
 (0)