RuntimeApi

io.github.polentino.redacted.api.internal.RuntimeApi
trait RuntimeApi

RuntimeApi is the main trait to implement in order to provide redaction functionalities for a specific Scala version, such as the type aliases and method utilities to parse Scala's AST for the specific major version of Scala.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type

Members list

Type members

Types

type DefDef <: Tree

The AST type of the method definition that will be patched.

The AST type of the method definition that will be patched.

Attributes

type Literal <: Tree

The AST type for a Literal, such as a character like "(" .

The AST type for a Literal, such as a character like "(" .

Attributes

type Position

The AST type for a position within a source file, useful for logging.

The AST type for a position within a source file, useful for logging.

Attributes

type Symbol

The AST type for a Symbol.

The AST type for a Symbol.

Attributes

type TermName

The AST type for a TermName, such as methods like "toString" or ".$plus(..)" .

The AST type for a TermName, such as methods like "toString" or ".$plus(..)" .

Attributes

type Tree

The AST type of the Tree that will be validated.

The AST type of the Tree that will be validated.

Attributes

Value members

Abstract methods

protected def caseClassOwner(tree: Tree): Option[Symbol]

Given a Tree passed as parameter, tries to retrieve its case class owner.

Given a Tree passed as parameter, tries to retrieve its case class owner.

Value parameters

tree

for which we would like to retrieve its case class owner

Attributes

Returns

an Option containing either the Symbol of its owner, or None

protected def concat(lhs: Tree, stringConcatOperator: TermName, rhs: Tree): Tree

Given two Trees, combine them together using the String.+(..) operator, to concatenate them together

Given two Trees, combine them together using the String.+(..) operator, to concatenate them together

Value parameters

lhs

the left-hand-sde Tree

rhs

the right-hand-sde Tree

stringConcatOperator

the String operator for concatenating two items

Attributes

Returns

the Tree that represents the concatenation of the two items

protected def constantLiteral(name: String): Literal

Build a Literal constant from the given name identifier i.e. "("

Build a Literal constant from the given name identifier i.e. "("

Value parameters

name

the String reference of the constant we would like to build

Attributes

Returns

the Literal reference

protected def constructorFields(owner: Symbol): List[Symbol]

Given a tree, it returns a List[Symbol] containing all the constructor's fields of the owner

Given a tree, it returns a List[Symbol] containing all the constructor's fields of the owner

Value parameters

owner

the Symbol of the related case class

Attributes

Returns

the List[Symbol] of all the fields in the owners' constructor

protected def isToString(tree: Tree): Option[DefDef]

Given a Tree passed as parameter, this method tries to convert it (via pattern-match) into a DefDef if it actually represents a toString method.

Given a Tree passed as parameter, this method tries to convert it (via pattern-match) into a DefDef if it actually represents a toString method.

Value parameters

tree

the tree to be parsed

Attributes

Returns

an Option containing either the DefDef of the toString method, or None

protected def ownerName(tree: Tree): String

Given a tree, it returns the name of its owner (regardless whether it is a case class or something else)

Given a tree, it returns the name of its owner (regardless whether it is a case class or something else)

Value parameters

tree

the Tree for which we would like to know its name

Attributes

Returns

the String representation of the owner's name

protected def patchToString(toStringDef: DefDef, newToStringBody: Tree): Try[DefDef]

Given the DefDef that represents the original toString implementation, and the Tree that represents its new body implementation, patch the new body into the existing definition, and return it.

Given the DefDef that represents the original toString implementation, and the Tree that represents its new body implementation, patch the new body into the existing definition, and return it.

Value parameters

newToStringBody

the Tree that provides redaction for the sensitive fields

toStringDef

the DefDef which represents the original toString AST

Attributes

Returns

the DefDef that will contain the patched body

protected def redactedFields(owner: Symbol): Option[List[Symbol]]

Returns a list with all the Symbol(s) annotated with @redacted from the given owner

Returns a list with all the Symbol(s) annotated with @redacted from the given owner

Value parameters

owner

the Symbol representing a case class reference for which we want all its @redacted fields

Attributes

Returns

a non-empty List[Symbol] with all the fields that are annotated with @redacted

protected def selectField(owner: Symbol, field: Symbol): Tree

Given a Symbol that represents the owner case class, and a Symbol that represents the constructor field inside it, it combines the two symbols in one Tree that is equivalent to selecting the field in the case class.

Given a Symbol that represents the owner case class, and a Symbol that represents the constructor field inside it, it combines the two symbols in one Tree that is equivalent to selecting the field in the case class.

// class example
final case class User(id: Int, name: String, count: Int)

// can build some AST equivalent of
  `User.this.id` or
  `User.this.name` or
  `User.this.count`

Value parameters

field

the Symbol that reference one specific field in the owner's constructor

owner

the Symbol that references the owning case class

Attributes

Returns

the Tree that select the field within the owner

Attributes

Returns

the TermName that is used to concatenate two Strings, i.e. "+" or ".$plus"

protected def treeName(tree: Tree): String

Returns the name of the Tree passed as parameter, for logging purposes

Returns the name of the Tree passed as parameter, for logging purposes

Value parameters

tree

the Tree for which we want to retrieve the name

Attributes

Returns

the name of the Tree

protected def treePos(tree: Tree): Position

Returns the Position of the Tree passed as parameter, for logging purposes

Returns the Position of the Tree passed as parameter, for logging purposes

Value parameters

tree

the Tree for which we want to retrieve the Position

Attributes

Returns

the Position of the Tree

Concrete methods

final def process(tree: Tree): Tree

Entry point of the redaction process: the tree passed as parameter will be analysed and, if valid, it will be patched and returned to the caller; otherwise, it will be returned unchanged.

Entry point of the redaction process: the tree passed as parameter will be analysed and, if valid, it will be patched and returned to the caller; otherwise, it will be returned unchanged.

Value parameters

tree

the tree that might get patched

Attributes

Returns

the patched (or not) tree

Abstract fields

Concrete fields

protected val REDACTED_CLASS: String

the FQDN of @redacted annotation

the FQDN of @redacted annotation

Attributes

protected val TO_STRING_NAME: String

the name of toString method

the name of toString method

Attributes