package checking
Helper classes and functionality related to specifying architectural concerns.
- Source
- package.scala
- Alphabetic
- By Inheritance
- checking
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- case class AccessFlags(accessFlags: AccessFlagsMatcher) extends SourceElementPredicate[ConcreteSourceElement] with Product with Serializable
- case class AnnotatedWith(annotationType: FieldType, elementValuePairs: Seq[ElementValuePair]) extends AnnotationPredicate with Product with Serializable
Tests if an annotation of a class, field, method or method parameter is as specified.
Tests if an annotation of a class, field, method or method parameter is as specified. The test takes the element values into consideration; if you don't want to take them into consideration use a HasAnnotation predicate.
scala> import org.opalj.br._ scala> import org.opalj.av.checking._ scala> val foo = ObjectType("java/lang/Foo") scala> val am = AnnotationPredicate("java.lang.Foo",Map("clazz" -> StringValue(""))) am: org.opalj.av.checking.AnnotationPredicate = @java.lang.Foo(clazz="") scala> am(Annotation(foo,IndexedSeq(ElementValuePair("clazz",StringValue(""))))) res: Boolean = true scala> am(Annotation(foo,IndexedSeq(ElementValuePair("clazz",StringValue("-+-"))))) res: Boolean = false scala> val am = DefaultAnnotationPredicate("java.lang.Foo",IndexedSeq.empty) am: org.opalj.av.checking.DefaultAnnotationPredicate = @java.lang.Foo() scala> am(Annotation(ObjectType("java/lang/Foo"),IndexedSeq(ElementValuePair("clazz",StringValue(" "))))) res: Boolean = false
- trait AnnotationPredicate extends SourceElementPredicate[ConcreteSourceElement]
Matches an annotation of a class, field, method or method parameter.
- trait AnnotationsPredicate extends (Iterable[Annotation]) => Boolean
- sealed trait ArchitectureChecker extends AnyRef
An architecture checker validates if the implemented architecture complies with the expected/specified one.
- case class Attributes(attributes: br.Attributes) extends SourceElementPredicate[ConcreteSourceElement] with Product with Serializable
- final class BinaryString extends AnyRef
Helper class to mark those places where a string using binary notation (i.e., where packages are separated using "/" instead of ".") is expected.
Helper class to mark those places where a string using binary notation (i.e., where packages are separated using "/" instead of ".") is expected.
A related implicit conversion is defined in the package object.
- trait ClassLevelMatcher extends SourceElementsMatcher
A class level matcher matches classes and all methods and fields defined by the respective classes.
- trait ClassMatcher extends ClassLevelMatcher
A class matcher matches classes defined by the respective classes.
- case class DefaultClassMatcher(accessFlagsMatcher: AccessFlagsMatcher = AccessFlagsMatcher.ANY, namePredicate: NamePredicate = RegexNamePredicate(""".*""".r), annotationsPredicate: AnnotationsPredicate = AnyAnnotations, matchSubclasses: Boolean = false, matchImplementingclasses: Boolean = false, matchMethods: Boolean = true, matchFields: Boolean = true) extends ClassMatcher with Product with Serializable
Default class matcher matches classes defined by the respective classes.
- trait DependencyChecker extends ArchitectureChecker
A dependency checker validates if the dependencies between the elements of two ensembles comply with the expected/specified dependencies.
- case class DependencyViolation(project: SomeProject, dependencyChecker: DependencyChecker, source: VirtualSourceElement, target: VirtualSourceElement, dependencyType: DependencyType, description: String) extends SpecificationViolation with Product with Serializable
Used to report deviations between the specified/expected and the implemented dependencies.
- case class Equals(name: BinaryString) extends NamePredicate with Product with Serializable
- case class FieldMatcher(declaringClass: ClassLevelMatcher, annotations: AnnotationsPredicate, theType: Option[FieldType], theName: Option[NamePredicate]) extends SourceElementsMatcher with Product with Serializable
Matches fields based on their name, type, annotations and declaring class.
- case class HasAnnotation(annotationType: FieldType) extends AnnotationPredicate with Product with Serializable
Matches an annotation of a class, field, method or method parameter that has the specified type.
Matches an annotation of a class, field, method or method parameter that has the specified type. The annotation is matched independent of the annotation's values.
Example
scala> import org.opalj.br._ scala> val foo = ObjectType("java/lang/Foo") scala> val aw = org.opalj.av.checking.AnnotatedWith(foo) aw: org.opalj.av.checking.AnnotatedWith = @java.lang.Foo scala> aw(Annotation(foo,IndexedSeq(ElementValuePair("clazz",StringValue(" "))))) res: Boolean = true
- case class HasAtLeastOneAnnotation(annotationPredicates: Set[_ <: AnnotationPredicate]) extends AnnotationsPredicate with Product with Serializable
- case class HasAtLeastTheAnnotations(annotationPredicates: Set[_ <: AnnotationPredicate]) extends AnnotationsPredicate with Product with Serializable
- case class HasTheAnnotations(annotationPredicates: Set[_ <: AnnotationPredicate]) extends AnnotationsPredicate with Product with Serializable
- case class MethodMatcher(classLevelMatcher: ClassLevelMatcher = AllClasses, annotationsPredicate: AnnotationsPredicate = AnyAnnotations, methodPredicate: SourceElementPredicate[Method] = AnyMethod) extends SourceElementsMatcher with Product with Serializable
Matches methods based on their attributes, annotations and class.
- case class MethodWithName(name: String) extends SourceElementPredicate[Method] with Product with Serializable
- case class MethodWithSignature(name: String, descriptor: MethodDescriptor) extends SourceElementPredicate[Method] with Product with Serializable
- trait NamePredicate extends (String) => Boolean
Matches a (binary) name of a file, method or class.
- case class PackageMatcher(namePredicate: NamePredicate, classMatcher: ClassMatcher) extends ClassLevelMatcher with Product with Serializable
Matches all classes in the specified package.
- trait PropertyChecker extends ArchitectureChecker
A property checker validates if the elements of an ensemble have the expected/specified properties.
- case class PropertyViolation(project: SomeProject, propertyChecker: PropertyChecker, source: VirtualSourceElement, propertyType: String, description: String) extends SpecificationViolation with Product with Serializable
Used to report source elements that have properties that deviate from the expected ones.
- case class RegexNamePredicate(matcher: Regex) extends NamePredicate with Product with Serializable
Matches name of class, fields and methods based on their name.
Matches name of class, fields and methods based on their name.
The name is matched against the binary notation.
- trait SourceElementPredicate[-S <: ConcreteSourceElement] extends (S) => Boolean
A predicate related to a specific source element.
- trait SourceElementsMatcher extends (SomeProject) => Set[VirtualSourceElement]
A source element matcher determines a set of source elements that matches a given query.
- class Specification extends AnyRef
A specification of a project's architectural constraints.
A specification of a project's architectural constraints.
Usage
First define the ensembles, then the rules and at last specify the class files that should be analyzed. The rules will then automatically be evaluated.
The intended way to create a specification is to create a new anonymous Specification class that contains the specification of the architecture. Afterwards the specification object can be used to get the list of architectural violations.
new Specification(project) { ensemble('Number) { "mathematics.Number*" } ensemble('Rational) { "mathematics.Rational*" } ensemble('Mathematics) { "mathematics.Mathematics*" } ensemble('Example) { "mathematics.Example*" } 'Example is_only_allowed_to (USE, 'Mathematics) }
Note
One ensemble is predefined:
Specification.empty
it represents an ensemble that contains no source elements and which can, e.g., be used to specify that no "real" ensemble is allowed to depend on a specific ensemble. - case class SpecificationError(description: String) extends Exception with Product with Serializable
Used to report errors in the specification itself.
- sealed trait SpecificationViolation extends AnyRef
Used to report deviations between the specified and the implemented architecture.
- case class StartsWith(name: BinaryString) extends NamePredicate with Product with Serializable
Value Members
- implicit def StringToBinaryString(string: String): BinaryString
- case object AllClasses extends ClassMatcher with Product with Serializable
Matches all project and library classes including inner elements like methods and fields defined by the respective classes.
- object AnnotatedWith extends Serializable
Defines several additional factory methods to facilitate the creation of AnnotationPredicates.
- case object AnyAnnotation extends AnnotationPredicate with Product with Serializable
An annotation matcher that always returns
true
; it matches any annotation. - case object AnyAnnotations extends AnnotationsPredicate with Product with Serializable
- case object AnyMethod extends SourceElementPredicate[Method] with Product with Serializable
- object BinaryString
- object ClassMatcher
Defines several additional factory methods to facilitate the creation of ClassMatchers.
- object FieldMatcher extends Serializable
Defines several additional factory methods to facilitate the creation of FieldMatchers.
- object HasAnnotation extends Serializable
Factory methods to create AnnotatedWith predicates.
- object HasAtLeastTheAnnotations extends Serializable
- object HasTheAnnotations extends Serializable
- object MethodMatcher extends Serializable
Defines several additional factory methods to facilitate the creation of MethodMatchers.
- case object NoAnnotations extends AnnotationsPredicate with Product with Serializable
- case object NoSourceElementsMatcher extends SourceElementsMatcher with Product with Serializable
A source element matcher that matches no elements.
- object PackageMatcher extends Serializable
Defines several additional factory methods to facilitate the creation of PackageMatchers.
- object Specification