Package org.faktorips.runtime.model.type
Class Type
- java.lang.Object
-
- org.faktorips.runtime.model.type.ModelElement
-
- org.faktorips.runtime.model.type.Type
-
- Direct Known Subclasses:
PolicyCmptType,ProductCmptType
public abstract class Type extends ModelElement
ATyperepresents a design time type of Faktor-IPS. It provides all meta data for the type as well as for properties like attributes or associations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceType.AnnotatedElementMatcher<T extends java.lang.annotation.Annotation>Matcher for methods or fields based on annotation properties.
-
Constructor Summary
Constructors Constructor Description Type(java.lang.String name, AnnotatedDeclaration annotatedDeclaration)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends java.lang.annotation.Annotation>
java.util.Optional<java.lang.reflect.Field>findDeclaredField(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a field with the given annotation that matches the condition defined by amatcher.<T extends java.lang.annotation.Annotation>
java.util.Optional<java.lang.reflect.Method>findDeclaredMethod(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a method with the given annotation that matches the condition defined by amatcher.java.util.Optional<java.lang.Class<?>>findJavaInterface()Returns the published interface for this type.java.util.Optional<? extends Type>findSuperType()Returns this type's super type ifpresent, otherwise anempty Optional.protected AnnotatedDeclarationgetAnnotatedDeclaration()Returns theAnnotatedDeclarationobject for this model type that should be used to read all annotations.AssociationgetAssociation(java.lang.String name)Returns the association with the givennamedeclared in this type or one of it's super types.abstract java.util.List<? extends Association>getAssociations()Returns the type's associations including those defined in it's super types.AttributegetAttribute(java.lang.String name)Returns the attribute with the givennamedeclared in this type or one of it's super types.abstract java.util.List<? extends Attribute>getAttributes()Returns a list containing the type's attributes including those defined in the type's super types.java.lang.Class<?>getDeclarationClass()AssociationgetDeclaredAssociation(int index)Returns the association at the givenindex.abstract AssociationgetDeclaredAssociation(java.lang.String name)Returns the association with the givennamedeclared in this type.abstract java.util.List<? extends Association>getDeclaredAssociations()Returns a list containing all associations declared in this type.AttributegetDeclaredAttribute(int index)Returns the declared attribute at the givenindex.abstract AttributegetDeclaredAttribute(java.lang.String name)Returns the attribute with the givennamedeclared in this type.abstract java.util.List<? extends Attribute>getDeclaredAttributes()Returns a list containing all attributes declared in this model type.protected java.util.List<java.lang.reflect.Field>getDeclaredFields()protected java.util.List<java.lang.reflect.Method>getDeclaredMethods()java.lang.Class<?>getJavaClass()Returns the Java class for this type.java.lang.Class<?>getJavaInterface()Returns the published interface for this type.protected abstract java.lang.StringgetKindName()protected MessagesHelpergetMessageHelper()protected java.lang.StringgetMessageKey(DocumentationKind messageType)abstract TypegetSuperType()Returns this type's super type ornullif it has none.abstract booleanisAssociationDeclared(java.lang.String name)Returns whether the association with the givennameis declared in this type.booleanisAssociationPresent(java.lang.String name)Returns whether the association with the givennameis declared in this type or in any supertype.abstract booleanisAttributeDeclared(java.lang.String name)Returns whether the attribute with the givennameis declared in this type.booleanisAttributePresent(java.lang.String name)Returns whether the attribute with the givennameis declared in this type or in any supertype.booleanisSuperTypePresent()Returns whether this type has a super type.<T extends java.lang.annotation.Annotation>
java.lang.reflect.MethodsearchDeclaredMethod(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a method with the given annotation that matches the condition defined by amatcher.java.lang.StringtoString()-
Methods inherited from class org.faktorips.runtime.model.type.ModelElement
createMessageHelper, getDeprecation, getDescription, getDocumentation, getExtensionPropertyIds, getExtensionPropertyValue, getLabel, getName, getRelevantProductObject, invokeField, invokeMethod, isDeprecated
-
-
-
-
Constructor Detail
-
Type
public Type(java.lang.String name, AnnotatedDeclaration annotatedDeclaration)
-
-
Method Detail
-
getKindName
protected abstract java.lang.String getKindName()
-
getMessageKey
protected java.lang.String getMessageKey(DocumentationKind messageType)
- Specified by:
getMessageKeyin classModelElement
-
getMessageHelper
protected MessagesHelper getMessageHelper()
- Specified by:
getMessageHelperin classModelElement
-
getDeclaredAssociation
public Association getDeclaredAssociation(int index)
Returns the association at the givenindex. Associations defined in the type's super types are not returned.- Throws:
java.lang.IndexOutOfBoundsException- if no association exists for the givenindex.
-
getDeclaredAttribute
public Attribute getDeclaredAttribute(int index)
Returns the declared attribute at the givenindex.- Throws:
java.lang.IndexOutOfBoundsException- if no attribute exists for the givenindex.
-
getAssociation
public Association getAssociation(java.lang.String name)
Returns the association with the givennamedeclared in this type or one of it's super types. The name could either be the singular or the plural name.- Throws:
java.lang.IllegalArgumentException- if no association with the givennameexists.
-
getAttribute
public Attribute getAttribute(java.lang.String name)
Returns the attribute with the givennamedeclared in this type or one of it's super types.- Throws:
java.lang.IllegalArgumentException- if no attribute with the givennameexists.
-
getAnnotatedDeclaration
protected AnnotatedDeclaration getAnnotatedDeclaration()
Returns theAnnotatedDeclarationobject for this model type that should be used to read all annotations.
-
getJavaClass
public java.lang.Class<?> getJavaClass()
Returns the Java class for this type.
-
getJavaInterface
public java.lang.Class<?> getJavaInterface()
Returns the published interface for this type. Returnsnullif published interfaces are not generated.
-
findJavaInterface
public java.util.Optional<java.lang.Class<?>> findJavaInterface()
Returns the published interface for this type. if published interfaces are generated, otherwise anempty Optional.
-
getDeclarationClass
public java.lang.Class<?> getDeclarationClass()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classModelElement
-
searchDeclaredMethod
public <T extends java.lang.annotation.Annotation> java.lang.reflect.Method searchDeclaredMethod(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a method with the given annotation that matches the condition defined by amatcher. Only methods in this type's declaration class are considered, thus no methods from super classes are found.- Parameters:
annotationClass- the class of the annotation the method must be annotated withmatcher- matcher to determine if the annotation has the correct properties- Returns:
- the first method that is both annotated with the given annotation and has the correct
annotated properties.
nullif no such method can be found. - See Also:
findDeclaredMethod for null-safe processing
-
findDeclaredMethod
public <T extends java.lang.annotation.Annotation> java.util.Optional<java.lang.reflect.Method> findDeclaredMethod(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a method with the given annotation that matches the condition defined by amatcher. Only methods in this type's declaration class are considered, thus no methods from super classes are found.- Parameters:
annotationClass- the class of the annotation the method must be annotated withmatcher- matcher to determine if the annotation has the correct properties- Returns:
- the first method that is both annotated with the given annotation and has the correct
annotated properties.
Optional.empty()if no such method can be found.
-
getDeclaredMethods
protected java.util.List<java.lang.reflect.Method> getDeclaredMethods()
-
findDeclaredField
public <T extends java.lang.annotation.Annotation> java.util.Optional<java.lang.reflect.Field> findDeclaredField(java.lang.Class<T> annotationClass, Type.AnnotatedElementMatcher<T> matcher)Searches for a field with the given annotation that matches the condition defined by amatcher. Only fields in this type's declaration class are considered, thus no fields from super classes are found.- Parameters:
annotationClass- the class of the annotation the field must be annotated withmatcher- matcher to determine if the annotation has the correct properties- Returns:
- the first field that is both annotated with the given annotation and has the correct
annotated properties.
Optional.empty()if no such field can be found.
-
getDeclaredFields
protected java.util.List<java.lang.reflect.Field> getDeclaredFields()
-
getDeclaredAssociations
public abstract java.util.List<? extends Association> getDeclaredAssociations()
Returns a list containing all associations declared in this type. Associations defined in the type's super types are not returned.- Returns:
- the list of associations declared in this type
-
getAssociations
public abstract java.util.List<? extends Association> getAssociations()
Returns the type's associations including those defined in it's super types.- Returns:
- the list of all associations declared in this type or in any super type
-
getDeclaredAssociation
public abstract Association getDeclaredAssociation(java.lang.String name)
Returns the association with the givennamedeclared in this type. Associations defined in the type's super types are not considered. The name could either be the singular or the plural name.- Parameters:
name- the name of the association- Returns:
- the association if it was found in this type
- Throws:
java.lang.IllegalArgumentException- if no association with the givennameexists- See Also:
isAssociationDeclared(String)
-
isAssociationDeclared
public abstract boolean isAssociationDeclared(java.lang.String name)
Returns whether the association with the givennameis declared in this type. Associations defined in the type's super types are not considered.- Parameters:
name- the name of the association- Returns:
trueif the association is declared in this type,falseif not- See Also:
isAssociationPresent(String)
-
isAssociationPresent
public boolean isAssociationPresent(java.lang.String name)
Returns whether the association with the givennameis declared in this type or in any supertype.- Parameters:
name- the name of the association- Returns:
trueif the association is declared in this type or in any supertype,falseif not- See Also:
isAssociationDeclared(String)
-
getDeclaredAttributes
public abstract java.util.List<? extends Attribute> getDeclaredAttributes()
Returns a list containing all attributes declared in this model type. Attributes defined in the type's super types are not returned.- Returns:
- the list of attributes declared in this type
-
isAttributeDeclared
public abstract boolean isAttributeDeclared(java.lang.String name)
Returns whether the attribute with the givennameis declared in this type. Attributes defined in the type's super types are not considered.- Parameters:
name- the name of the attribute- Returns:
trueif the attribute is declared in this type,falseif not
-
isAttributePresent
public boolean isAttributePresent(java.lang.String name)
Returns whether the attribute with the givennameis declared in this type or in any supertype.- Parameters:
name- the name of the attribute- Returns:
trueif the attribute is declared in this type or in any supertype,falseif not
-
getAttributes
public abstract java.util.List<? extends Attribute> getAttributes()
Returns a list containing the type's attributes including those defined in the type's super types.- Returns:
- the list of all attributes declared in this type or in any supertype
-
getDeclaredAttribute
public abstract Attribute getDeclaredAttribute(java.lang.String name)
Returns the attribute with the givennamedeclared in this type. Attributes defined in the type's super types are not returned.- Parameters:
name- the name of the attribute- Returns:
- the attribute if it was found in this type
- Throws:
java.lang.IllegalArgumentException- if no attribute with the givennameexists- See Also:
isAttributeDeclared(String)
-
isSuperTypePresent
public boolean isSuperTypePresent()
Returns whether this type has a super type.- Returns:
trueif this type has a supertype,falseif not
-
getSuperType
public abstract Type getSuperType()
Returns this type's super type ornullif it has none.- See Also:
findSuperType for null-safe processing
-
-