org.mutabilitydetector
Enum MutabilityReason

java.lang.Object
  extended by java.lang.Enum<MutabilityReason>
      extended by org.mutabilitydetector.MutabilityReason
All Implemented Interfaces:
Serializable, Comparable<MutabilityReason>, Reason

public enum MutabilityReason
extends Enum<MutabilityReason>
implements Reason

The various reasons that instances of a class can be considered mutable.

Author:
Graham Allan / Grundlefleck at gmail dot com

Enum Constant Summary
ABSTRACT_COLLECTION_TYPE_TO_FIELD
           
ABSTRACT_TYPE_INHERENTLY_MUTABLE
          Abstract types (interfaces or abstract classes) are considered to be \"Inherently Mutable\" in particular cases.
ABSTRACT_TYPE_TO_FIELD
          For an object to be immutable, its fields must also be immutable.
ARRAY_TYPE_INHERENTLY_MUTABLE
          Since an array can be mutated after construction (by modifying what it contains) they are inherently mutable.
CAN_BE_SUBCLASSED
          The given class can be subclassed.
CANNOT_ANALYSE
          Class could not be analysed.
COLLECTION_FIELD_WITH_MUTABLE_ELEMENT_TYPE
           
ESCAPED_THIS_REFERENCE
          [Experimental] The 'this' reference escaped during construction.
FIELD_CAN_BE_REASSIGNED
          For a class to be immutable, fields cannot be reassigned once an instance is constructed.
MUTABLE_TYPE_TO_FIELD
          A mutable type can be assigned to a field.
NON_FINAL_FIELD
          Field is not declared final.
NULL_REASON
          This is a placeholder reason.
PUBLISHED_NON_FINAL_FIELD
          Class has a published, non-final field.
 
Method Summary
 String code()
           
 IsImmutable createsResult()
           
 String description()
           
 boolean isOneOf(Reason... reasons)
           
static MutabilityReason valueOf(String name)
          Returns the enum constant of this type with the specified name.
static MutabilityReason[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

CANNOT_ANALYSE

public static final MutabilityReason CANNOT_ANALYSE
Class could not be analysed. Possible reasons include not being able to load the class correctly.


ABSTRACT_TYPE_TO_FIELD

public static final MutabilityReason ABSTRACT_TYPE_TO_FIELD
For an object to be immutable, its fields must also be immutable. By assigning an abstract type to a field, it is not known if the concrete fields supplied will be immutable or not.


ABSTRACT_COLLECTION_TYPE_TO_FIELD

public static final MutabilityReason ABSTRACT_COLLECTION_TYPE_TO_FIELD

COLLECTION_FIELD_WITH_MUTABLE_ELEMENT_TYPE

public static final MutabilityReason COLLECTION_FIELD_WITH_MUTABLE_ELEMENT_TYPE

CAN_BE_SUBCLASSED

public static final MutabilityReason CAN_BE_SUBCLASSED
The given class can be subclassed. While this specific class may still be immutable, subclasses may not. It is recommended that the class be declared final, or all of its constructors declared private. This will allow clients to be confident that parameters declared to be this type will indeed be of this type at runtime, not an instance of a mutable subclass. Note that applying the final keyword to a class does not have any effect on the Java Memory Model.


ABSTRACT_TYPE_INHERENTLY_MUTABLE

public static final MutabilityReason ABSTRACT_TYPE_INHERENTLY_MUTABLE
Abstract types (interfaces or abstract classes) are considered to be \"Inherently Mutable\" in particular cases. Because the concrete implementation cannot be known until compile-time, run-time instances of abstract types could be either mutable or immutable.


ARRAY_TYPE_INHERENTLY_MUTABLE

public static final MutabilityReason ARRAY_TYPE_INHERENTLY_MUTABLE
Since an array can be mutated after construction (by modifying what it contains) they are inherently mutable. However, since it is possible that a field which is an array type is never mutated after construction, it is still possible for the containing type to be immutable


MUTABLE_TYPE_TO_FIELD

public static final MutabilityReason MUTABLE_TYPE_TO_FIELD
A mutable type can be assigned to a field. Since references to the mutable field may be kept, the containing type can be mutated after construction. This reason can also indicate a circular reference in the fields of several types. E.g. type A has a field of type B, and type B has a field of type A. Therefore one of these types has to not be completely constructed when passed to the other type.


ESCAPED_THIS_REFERENCE

public static final MutabilityReason ESCAPED_THIS_REFERENCE
[Experimental] The 'this' reference escaped during construction. Whoever receives the reference may observe values of the object mutating.


NON_FINAL_FIELD

public static final MutabilityReason NON_FINAL_FIELD
Field is not declared final. If the object is published across threads the Java Memory Model does not guarantee that it will be fully initialised before it is read. However, if the object is only used in a single thread, reads are guaranteed to see the fully initialised fields.


PUBLISHED_NON_FINAL_FIELD

public static final MutabilityReason PUBLISHED_NON_FINAL_FIELD
Class has a published, non-final field. Fields of an immutable class may not be reassigned after an instance is constructed. If an accessible field is not made final, it can be reassigned.


FIELD_CAN_BE_REASSIGNED

public static final MutabilityReason FIELD_CAN_BE_REASSIGNED
For a class to be immutable, fields cannot be reassigned once an instance is constructed. The most common example of this is JavaBean convention "setter" methods.


NULL_REASON

public static final MutabilityReason NULL_REASON
This is a placeholder reason.

Method Detail

values

public static MutabilityReason[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (MutabilityReason c : MutabilityReason.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static MutabilityReason valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

description

public String description()
Specified by:
description in interface Reason

code

public String code()
Specified by:
code in interface Reason

createsResult

public IsImmutable createsResult()
Specified by:
createsResult in interface Reason

isOneOf

public boolean isOneOf(Reason... reasons)
Specified by:
isOneOf in interface Reason


Copyright © 2013. All Rights Reserved.