Class FieldTemplate.setterDefensiveCopy

java.lang.Object
de.japkit.test.members.field.FieldTemplate.setterDefensiveCopy
Enclosing class:
FieldTemplate

@Switch
class FieldTemplate.setterDefensiveCopy
extends java.lang.Object
Generates a code to create a defensive copy if a mutable type is used.

Here, only List is supported, but more cases could be added (Set, Map, Date, ...).

In a Switch the first case that evaluates to true is applied. A case can either be annotated by a boolean function (like FieldTemplate.isList below) or by Case.

Since the Switch shall provide a code fragment here, each case needs to be annotated with CodeFragment.

Since setterDefensiveCopy is used as a fragment that surrounds other code, there is some special EL variable "surrounded" available here that contains the code to be surrounded.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    (package private) java.lang.String copyList
    The code fragment for creating a defensive copy of a List.
    (package private) java.lang.String deflt
    The code fragment for the default case, without defensive copy.
  • Constructor Summary

    Constructors 
    Constructor Description
    setterDefensiveCopy()  
  • Method Summary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • copyList

      @isList @CodeFragment(imports=java.util.ArrayList.class, code="new ArrayList<>(#{surrounded})") java.lang.String copyList
      The code fragment for creating a defensive copy of a List.
    • deflt

      @DefaultCase @CodeFragment(code="#{surrounded}") java.lang.String deflt
      The code fragment for the default case, without defensive copy.
  • Constructor Details