Package com.tngtech.archunit.lang
Interface ConditionEvent
- All Known Implementing Classes:
SimpleConditionEvent
An event that occurred while checking an
ArchCondition
. This can either be a violation
or be allowed. An event that is allowed will turn into a violation if it is inverted
(e.g. for negation of the rule).-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Handles the data of aConditionEvent
that is the corresponding objects and the description (comparehandleWith(Handler)
).
As an example, this could be a single element of typeJavaMethodCall
together with a description, like -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends HasDescription & HasSourceCodeLocation>
StringcreateMessage
(T object, String message) Convenience method to create a standard ArchUnitConditionEvent
message.void
handleWith
(ConditionEvent.Handler handler) Supplies the corresponding objects and description to the supplied handler.invert()
boolean
-
Method Details
-
isViolation
boolean isViolation()- Returns:
true
if this event represents a violation of an evaluated rule,false
otherwise
-
invert
ConditionEvent invert()- Returns:
- the 'opposite' of the event.
Assume e.g. The event is a violation, if some conditions A and B are both true
=> The 'inverted' event is a violation if either A or B (or both) are not true
In the most simple case, this is just an equivalent event evaluatingisViolation()
inverted.
-
getDescriptionLines
- Returns:
- A textual description of this event as a list of lines
-
handleWith
Supplies the corresponding objects and description to the supplied handler.
The term "corresponding objects" refers to the objects involved in the evaluation of this rule. E.g. the rule checks for illegal field accesses, then this object might be a single field access checked by the rule.
May also be a collection of objects, if the evaluation of the rule depends on sets of objects. E.g. the rule checks that some access to another class happened? The rule can only be violated, by a whole set (all accesses from a class) of objects, but not by a single one (if there is more than one).- Parameters:
handler
- The handler to supply the data of this event to.
-
createMessage
@PublicAPI(usage=ACCESS) static <T extends HasDescription & HasSourceCodeLocation> String createMessage(T object, String message) Convenience method to create a standard ArchUnitConditionEvent
message. It will prepend the description of the object that caused the event (e.g. aJavaClass
) and append the source code location of the respective object.- Type Parameters:
T
- The object described by the event.- Parameters:
object
- The object to describe, e.g. theJavaClass
com.example.SomeClass
message
- The message that should be filled into the template, e.g. "does not have simple name 'Correct'"- Returns:
- The formatted message, e.g.
Class <com.example.SomeClass> does not have simple name 'Correct' in (SomeClass.java:0)
-