Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readability improvement - comment and renaming #162

Merged
merged 3 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ClassSweepCompilerPluginComponent(options: CodecRegistrationCheckerOptions

override def newPhase(prev: Phase): Phase =
new StdPhase(prev) {
private val up = options.oldTypes.groupBy(_._2)
private val oldTypesFromPreviousCompilation = options.oldTypes.groupBy(_._2)
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved

override def apply(unit: global.CompilationUnit): Unit = {
val body = unit.body
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -35,7 +35,7 @@ class ClassSweepCompilerPluginComponent(options: CodecRegistrationCheckerOptions
.collect {
case x: ClassDef => x.impl.tpe.typeSymbol.fullName
}
.flatMap(up.get)
.flatMap(oldTypesFromPreviousCompilation.get)
.flatten
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class CodecRegistrationCheckerCompilerPlugin(override val global: Global) extend
options.filterNot(_.startsWith("-")).headOption match {
case Some(path) =>
try {
val f = new File(path + File.separator + cacheFileName)
f.getCanonicalPath
pluginOptions.cacheFile = f
val cacheFile = new File(path + File.separator + cacheFileName)
cacheFile.getCanonicalPath
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
pluginOptions.cacheFile = cacheFile
pluginOptions.oldTypes = {
val raf = new RandomAccessFile(f, "rw")
val raf = new RandomAccessFile(cacheFile, "rw")
try {
val channel = raf.getChannel
val lock = channel.lock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@ package org.virtuslab.ash

import java.io.File

/**
* A helper class needed to hold two following variables:
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
*
* @param cacheFile - CSV file where all Fully Qualified Class Names (FQCNs) for:
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
* a) detected classes/traits annotated with the 'serializability trait'
* and
* b) their direct descendants
* are saved as pairs of comma-separated values (two values per row) according to following pattern:
* <PARENT_FQCN>,<DESCENDANT_FQCN>
*
* @param oldTypes - collection that holds String pairs representing the content of the `cacheFile`. Needed to catch
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
* missing codec registrations when using sbt incremental compilation (so - these are FQCNs that were found
* during previous compilation). Without using `oldTypes` we wouldn't be able to detect situations,
* where codec registration for a serializable type has been removed from the code (when `sbt compile` was incremental).
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
* It gets declared on the plugin's init by invoking the CodecRegistrationCheckerCompilerPlugin.parseCacheFile method.
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
*/
case class CodecRegistrationCheckerOptions(var cacheFile: File = null, var oldTypes: Seq[(String, String)] = null)
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SerializerCheckCompilerPluginComponent(
.collect {
case x: ImplDef => (x, x.symbol.annotations)
}
.map(x => (x._1, x._2.filter(_.tpe.toString() == serializerType)))
.map(x => (x._1, x._2.filter(_.tpe.toString == serializerType)))
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
.filter(_._2.nonEmpty)
.foreach { x =>
val (implDef, annotations) = x
Expand All @@ -81,7 +81,7 @@ class SerializerCheckCompilerPluginComponent(
}

private def processSerializerClass(serializerImplDef: ImplDef, serializerAnnotation: AnnotationInfo): Unit = {
val (fqcn, filterRegex) = serializerAnnotation.args match {
val (fullyQualifiedClassName, filterRegex) = serializerAnnotation.args match {
case List(clazzTree, regexTree) =>
val fqcn = extractValueOfLiteralConstantFromTree[Type](clazzTree).flatMap { tpe =>
if (tpe.typeSymbol.annotations.map(_.tpe.toString()).contains(serializabilityTraitType))
Expand Down Expand Up @@ -133,13 +133,15 @@ class SerializerCheckCompilerPluginComponent(
typeArgsBfs(next, acc)
}

val foundInSerializerTypesFqcns = typeArgsBfs(foundTypes.toSet).map(_.typeSymbol.fullName)
val fullyQualifiedClassNamesOfFoundTypes = typeArgsBfs(foundTypes.toSet).map(_.typeSymbol.fullName)
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved

val missingFqcn = typesToCheck(fqcn).map(_._2).filterNot(foundInSerializerTypesFqcns)
if (missingFqcn.nonEmpty) {
val missingFullyQualifiedClassNames =
typesToCheck(fullyQualifiedClassName).map(_._2).filterNot(fullyQualifiedClassNamesOfFoundTypes)
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
if (missingFullyQualifiedClassNames.nonEmpty) {
reporter.error(
serializerImplDef.pos,
s"""No codecs for ${missingFqcn.mkString(", ")} are registered in class annotated with @$serializerType.
s"""No codecs for ${missingFullyQualifiedClassNames
.mkString(", ")} are registered in class annotated with @$serializerType.
|This will lead to a missing codec for Akka serialization in the runtime.
|Current filtering regex: $filterRegex""".stripMargin)
}
Expand Down