Package de.gebit.integrity.utils
Class IntegrityDSLUtil
- java.lang.Object
-
- de.gebit.integrity.utils.IntegrityDSLUtil
-
public final class IntegrityDSLUtil extends java.lang.Object
A utility class providing various helper functions.- Author:
- Rene Schneider - initial API and implementation
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
cleanMultiLineComment(VisibleMultiLineComment aComment)
Removes prefix and suffix from visible single-line comment text, as well as any newlines in between.static java.lang.String
cleanSingleLineComment(VisibleSingleLineComment aComment)
Removes the prefix as well as any trailing newlines from visible single-line comment text.static void
ensureResolved(org.eclipse.emf.ecore.EObject anObject)
Ensures that a given EObject that is possibly a proxy is resolved, resolving it if necessary.static VariableOrConstantEntity
extractVariableOrConstantEntity(ValueOrEnumValueOrOperation anInput)
Attempts to extract aVariableOrConstantEntity
from the providedValueOrEnumValueOrOperation
.static <T extends org.eclipse.emf.ecore.EObject>
TfindUpstreamContainer(java.lang.Class<T> aContainerClass, org.eclipse.emf.ecore.EObject aSource)
Finds an upstream container matching a provided container class.static java.util.List<org.eclipse.xtext.common.types.JvmEnumerationLiteral>
getAllEnumLiteralsFromFixtureMethodParam(MethodReference aMethod, org.eclipse.xtext.common.types.JvmAnnotationReference aParamAnnotation)
Returns a list of all valid enumeration literals for a given parameter in a given fixture method.static java.util.List<ParamAnnotationTypeTriplet>
getAllParamNamesFromFixtureMethod(MethodReference aMethod)
Returns a list of all defined parameter names in a given fixture method, each of the results linked to the annotation reference that's connected to the parameter in the method signature.static java.util.List<ParamAnnotationTypeTriplet>
getAllParamNamesFromFork(ForkDefinition aFork)
Returns a list of all defined parameter names in a given fork, each of the results linked to the annotation reference that's connected to the parameter in the constructor signature.static java.util.List<ParamAnnotationTypeTriplet>
getAllParamNamesFromForkerClass(org.eclipse.xtext.common.types.JvmGenericType aForkerType)
Returns a list of all defined parameter names in a given forker class, each of the results linked to the annotation reference that's connected to the parameter in the constructor signature.static java.util.List<ResultFieldTuple>
getAllResultNamesFromFixtureMethod(MethodReference aMethod)
Returns a list of named results defined by a given fixture method.static java.util.Collection<ValueOrEnumValueOrOperation>
getAllValuesFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection)
Aggregates allValueOrEnumValueOrOperation
s from the givenValueOrEnumValueOrOperationCollection
.
Integrity has (historically; could be done more elegant with todays' Xtext) splittedValueOrEnumValueOrOperationCollection
s' internal values into two properties: a single value comes fromValueOrEnumValueOrOperationCollection.getValue()
and everything else goes intoValueOrEnumValueOrOperationCollection.getMoreValues()
.static java.lang.String
getExpectedResultNameStringFromTestResultName(ResultName aName)
Returns the name of a specific test result value.static java.lang.String
getIdentifierFromArbitraryParameterOrResultName(ArbitraryParameterOrResultName aName)
ArbitraryParameterOrResultName
s can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes).static java.lang.String
getIdentifierFromKeyValuePair(KeyValuePair aPair)
KeyValuePair
s can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes).static ValueOrEnumValueOrOperationCollection
getInitialValueForConstant(ConstantDefinition aConstant, VariantDefinition aVariant)
Determines the initial value for the given constant.static ValueOrEnumValueOrOperationCollection
getInitialValueForVariableOrConstantEntity(VariableOrConstantEntity anEntity, VariantDefinition aVariant)
Determines the initial value to use for the givenVariableOrConstantEntity
.static MethodReference
getMethodReferenceForAction(org.eclipse.emf.ecore.EObject anAction)
static PackageDefinition
getPackageContaining(org.eclipse.emf.ecore.EObject anObject)
Finds thePackageDefinition
that contains the givenEObject
.static boolean
getParamMandatoryFlagFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)
Returns whether the mandatory flag is set defined by a given annotation reference.static java.lang.String
getParamNameFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)
Returns the name of a single parameter defined by a given annotation reference.static java.lang.String
getParamNameStringFromParameterName(ParameterName aParameterName)
Returns the name of a single given parameter defined by aParameterName
instance.static java.lang.String
getQualifiedCallName(CallDefinition aCall)
Returns the fully qualified name of a givenCallDefinition
.static java.lang.String
getQualifiedForkName(ForkDefinition aFork)
Returns the fully qualified name of a givenForkDefinition
.static java.lang.String
getQualifiedNameOfFixtureMethod(MethodReference aReference)
Returns the fully qualified name of the fixture method referenced by the given method reference.static java.lang.String
getQualifiedSuiteName(SuiteDefinition aSuite)
Returns the fully qualified name of a givenSuiteDefinition
.static java.lang.String
getQualifiedTestName(TestDefinition aTest)
Returns the fully qualified name of a givenTestDefinition
.static java.lang.String
getQualifiedVariableEntityName(VariableOrConstantEntity aVariable, boolean aQualifyLocalVariables)
Returns the fully qualified name of the givenVariableOrConstantEntity
.static java.lang.String
getQualifiedVariantName(VariantDefinition aVariant)
Returns the fully qualified name of a givenVariantDefinition
.static ValueOrEnumValueOrOperation
getSpecificValueFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection, int anIndex)
Gets a specific index position out of aValueOrEnumValueOrOperationCollection
.static SuiteDefinition
getSuiteContaining(org.eclipse.emf.ecore.EObject anObject)
Finds theSuiteDefinition
that contains the givenEObject
.static java.lang.String
getSuiteTitle(SuiteDefinition aSuite)
Gets the suites' title from a given suite.static org.eclipse.emf.ecore.EObject
getTableHeaderForTableCell(ParameterTableValue aTableCell)
Finds the corresponding table header element to a given table cell element.static java.util.Map<ParameterTableHeader,java.util.List<ParameterTableValue>>
getTableParameterValuesPerParameter(TableTest aTableTest)
Returns a map of allParameterTableHeader
s in a givenTableTest
with their associatedParameterTableValue
s.static boolean
isGlobalVariableOrConstant(VariableOrConstantEntity anEntity)
Checks whether the given variable/constant entity is defined in a global (package) context.static boolean
isPrivate(org.eclipse.emf.ecore.EObject anObject)
Checks whether the givenEObject
is of private visibility.static boolean
isPrivateInsideSuite(org.eclipse.emf.ecore.EObject anObject)
Checks whether the givenEObject
is located inside a suite and is thus of private visibility by default.static java.lang.Boolean
isResult(org.eclipse.emf.ecore.EObject anObject)
Determines whether a givenEObject
is part of a result of a test/call/tabletest.
-
-
-
Method Detail
-
getAllParamNamesFromFixtureMethod
public static java.util.List<ParamAnnotationTypeTriplet> getAllParamNamesFromFixtureMethod(MethodReference aMethod)
Returns a list of all defined parameter names in a given fixture method, each of the results linked to the annotation reference that's connected to the parameter in the method signature.- Parameters:
aMethod
- the method to inspect- Returns:
- a list of parameters and annotation references
-
getParamNameFromAnnotation
public static java.lang.String getParamNameFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)
Returns the name of a single parameter defined by a given annotation reference.- Parameters:
anAnnotation
- the annotation reference- Returns:
- the name
-
getParamMandatoryFlagFromAnnotation
public static boolean getParamMandatoryFlagFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)
Returns whether the mandatory flag is set defined by a given annotation reference.- Parameters:
anAnnotation
- the annotation reference- Returns:
- true if mandatory, false otherwise
-
getAllParamNamesFromFork
public static java.util.List<ParamAnnotationTypeTriplet> getAllParamNamesFromFork(ForkDefinition aFork)
Returns a list of all defined parameter names in a given fork, each of the results linked to the annotation reference that's connected to the parameter in the constructor signature. Only one constructor is supported.- Parameters:
aFork
- the fork to inspect- Returns:
- a list of parameters and annotation references
-
getAllParamNamesFromForkerClass
public static java.util.List<ParamAnnotationTypeTriplet> getAllParamNamesFromForkerClass(org.eclipse.xtext.common.types.JvmGenericType aForkerType)
Returns a list of all defined parameter names in a given forker class, each of the results linked to the annotation reference that's connected to the parameter in the constructor signature. Only one constructor is supported.- Parameters:
aForkerType
- the forker class to inspect- Returns:
- a list of parameters and annotation references
-
getParamNameStringFromParameterName
public static java.lang.String getParamNameStringFromParameterName(ParameterName aParameterName)
Returns the name of a single given parameter defined by aParameterName
instance.- Parameters:
aParameterName
- the parameter name instance- Returns:
- the parameter name string
-
getAllEnumLiteralsFromFixtureMethodParam
public static java.util.List<org.eclipse.xtext.common.types.JvmEnumerationLiteral> getAllEnumLiteralsFromFixtureMethodParam(MethodReference aMethod, org.eclipse.xtext.common.types.JvmAnnotationReference aParamAnnotation)
Returns a list of all valid enumeration literals for a given parameter in a given fixture method.- Parameters:
aMethod
- the fixture method referenceaParamAnnotation
- the parameter annotation reference- Returns:
- a list of enumeration literals, or null if the parameter is not an enum parameter
-
getAllResultNamesFromFixtureMethod
public static java.util.List<ResultFieldTuple> getAllResultNamesFromFixtureMethod(MethodReference aMethod)
Returns a list of named results defined by a given fixture method.- Parameters:
aMethod
- the method- Returns:
- the list of results
-
getQualifiedNameOfFixtureMethod
public static java.lang.String getQualifiedNameOfFixtureMethod(MethodReference aReference)
Returns the fully qualified name of the fixture method referenced by the given method reference.- Parameters:
aReference
- the method reference- Returns:
- the fully qualified name, including the name of the class and the method itself
-
getQualifiedSuiteName
public static java.lang.String getQualifiedSuiteName(SuiteDefinition aSuite)
Returns the fully qualified name of a givenSuiteDefinition
.- Parameters:
aSuite
- the suite- Returns:
- the fully qualified name
-
getQualifiedVariantName
public static java.lang.String getQualifiedVariantName(VariantDefinition aVariant)
Returns the fully qualified name of a givenVariantDefinition
.- Parameters:
aVariant
- the variant- Returns:
- the fully qualified name
-
getQualifiedForkName
public static java.lang.String getQualifiedForkName(ForkDefinition aFork)
Returns the fully qualified name of a givenForkDefinition
.- Parameters:
aFork
- the fork- Returns:
- the fully qualified name
-
getQualifiedCallName
public static java.lang.String getQualifiedCallName(CallDefinition aCall)
Returns the fully qualified name of a givenCallDefinition
.- Parameters:
aCall
- the call definition- Returns:
- the fully qualified name
-
getQualifiedTestName
public static java.lang.String getQualifiedTestName(TestDefinition aTest)
Returns the fully qualified name of a givenTestDefinition
.- Parameters:
aTest
- the test definition- Returns:
- the fully qualified name
-
getQualifiedVariableEntityName
public static java.lang.String getQualifiedVariableEntityName(VariableOrConstantEntity aVariable, boolean aQualifyLocalVariables)
Returns the fully qualified name of the givenVariableOrConstantEntity
.- Parameters:
aVariable
- the variable- Returns:
- the fully qualified name
-
getExpectedResultNameStringFromTestResultName
public static java.lang.String getExpectedResultNameStringFromTestResultName(ResultName aName)
Returns the name of a specific test result value.- Parameters:
aName
- the result name object- Returns:
- the name string
-
cleanSingleLineComment
public static java.lang.String cleanSingleLineComment(VisibleSingleLineComment aComment)
Removes the prefix as well as any trailing newlines from visible single-line comment text.- Parameters:
aComment
- the comment- Returns:
- the cleaned text
-
cleanMultiLineComment
public static java.lang.String cleanMultiLineComment(VisibleMultiLineComment aComment)
Removes prefix and suffix from visible single-line comment text, as well as any newlines in between.- Parameters:
aComment
- the comment- Returns:
- the cleaned text
-
getSuiteTitle
public static java.lang.String getSuiteTitle(SuiteDefinition aSuite)
Gets the suites' title from a given suite.- Parameters:
aSuite
- the suite to search in- Returns:
- the title of the suite or null if it does not have one
-
isResult
public static java.lang.Boolean isResult(org.eclipse.emf.ecore.EObject anObject)
Determines whether a givenEObject
is part of a result of a test/call/tabletest.- Parameters:
anObject
- the object to look at- Returns:
- true if it is a result, false if not. Null if not determinable.
-
getTableHeaderForTableCell
public static org.eclipse.emf.ecore.EObject getTableHeaderForTableCell(ParameterTableValue aTableCell)
Finds the corresponding table header element to a given table cell element.- Parameters:
aTableCell
- the table cell element- Returns:
- the table header element if one exists, the table itself in case of the default result column or null if nothing was found
-
getTableParameterValuesPerParameter
public static java.util.Map<ParameterTableHeader,java.util.List<ParameterTableValue>> getTableParameterValuesPerParameter(TableTest aTableTest)
Returns a map of allParameterTableHeader
s in a givenTableTest
with their associatedParameterTableValue
s.- Parameters:
aTableTest
- the table test to map- Returns:
- all parameter columns with their associated values
-
getMethodReferenceForAction
public static MethodReference getMethodReferenceForAction(org.eclipse.emf.ecore.EObject anAction)
- Parameters:
anAction
- the action to find a method for- Returns:
- the method or null if none was found
-
getInitialValueForVariableOrConstantEntity
public static ValueOrEnumValueOrOperationCollection getInitialValueForVariableOrConstantEntity(VariableOrConstantEntity anEntity, VariantDefinition aVariant)
Determines the initial value to use for the givenVariableOrConstantEntity
.- Parameters:
anEntity
- the entity to exploreaVariant
- the current variant being executed (null if no variant is used)- Returns:
- the initial value, or null if none was given
-
getInitialValueForConstant
public static ValueOrEnumValueOrOperationCollection getInitialValueForConstant(ConstantDefinition aConstant, VariantDefinition aVariant)
Determines the initial value for the given constant.- Parameters:
aConstant
- the constant to exploreaVariant
- the current variant being executed (null if no variant is used)- Returns:
- the initial value, or null if none was given
-
getAllValuesFromCollection
public static java.util.Collection<ValueOrEnumValueOrOperation> getAllValuesFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection)
Aggregates allValueOrEnumValueOrOperation
s from the givenValueOrEnumValueOrOperationCollection
.
Integrity has (historically; could be done more elegant with todays' Xtext) splittedValueOrEnumValueOrOperationCollection
s' internal values into two properties: a single value comes fromValueOrEnumValueOrOperationCollection.getValue()
and everything else goes intoValueOrEnumValueOrOperationCollection.getMoreValues()
. This method helps handling these by merging all the values into a singleCollection
.- Parameters:
aValueCollection
- the value collection to aggregate single values from- Returns:
- all the aggregated values in a single
Collection
.
-
getSpecificValueFromCollection
public static ValueOrEnumValueOrOperation getSpecificValueFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection, int anIndex)
Gets a specific index position out of aValueOrEnumValueOrOperationCollection
.- Parameters:
aValueCollection
- the value collectionanIndex
- the index to get- Returns:
- the value
-
isGlobalVariableOrConstant
public static boolean isGlobalVariableOrConstant(VariableOrConstantEntity anEntity)
Checks whether the given variable/constant entity is defined in a global (package) context.- Parameters:
anEntity
- the entity to check- Returns:
- true if globally defined, false if defined in a suite
-
findUpstreamContainer
public static <T extends org.eclipse.emf.ecore.EObject> T findUpstreamContainer(java.lang.Class<T> aContainerClass, org.eclipse.emf.ecore.EObject aSource)
Finds an upstream container matching a provided container class.- Parameters:
aContainerClass
- the class to findaSource
- the starting point for the search- Returns:
- the upstream container, or null if nothing was found
-
getPackageContaining
public static PackageDefinition getPackageContaining(org.eclipse.emf.ecore.EObject anObject)
Finds thePackageDefinition
that contains the givenEObject
.- Parameters:
anObject
- the entity- Returns:
- the package containing the entity, or null if the entity is not in a package
-
getSuiteContaining
public static SuiteDefinition getSuiteContaining(org.eclipse.emf.ecore.EObject anObject)
Finds theSuiteDefinition
that contains the givenEObject
.- Parameters:
anObject
- the entity- Returns:
- the suite containing the entity, or null if the entity is not in a package
-
getIdentifierFromKeyValuePair
public static java.lang.String getIdentifierFromKeyValuePair(KeyValuePair aPair)
KeyValuePair
s can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes). This method abstracts aways the decision where to get the final identifier from.- Parameters:
aPair
- the key-value pair- Returns:
- the identifier
-
getIdentifierFromArbitraryParameterOrResultName
public static java.lang.String getIdentifierFromArbitraryParameterOrResultName(ArbitraryParameterOrResultName aName)
ArbitraryParameterOrResultName
s can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes). This method abstracts aways the decision where to get the final identifier from.- Parameters:
aName
- the name- Returns:
- the identifier
-
isPrivate
public static boolean isPrivate(org.eclipse.emf.ecore.EObject anObject)
Checks whether the givenEObject
is of private visibility.- Parameters:
anObject
- the object to check- Returns:
- true or false (will return false on objects which don't support a visibility modifier)
-
isPrivateInsideSuite
public static boolean isPrivateInsideSuite(org.eclipse.emf.ecore.EObject anObject)
Checks whether the givenEObject
is located inside a suite and is thus of private visibility by default.- Parameters:
anObject
-- Returns:
-
extractVariableOrConstantEntity
public static VariableOrConstantEntity extractVariableOrConstantEntity(ValueOrEnumValueOrOperation anInput)
Attempts to extract aVariableOrConstantEntity
from the providedValueOrEnumValueOrOperation
.- Parameters:
anInput
- the input value- Returns:
- the entity if one is found, null if the input value was something else
-
ensureResolved
public static void ensureResolved(org.eclipse.emf.ecore.EObject anObject)
Ensures that a given EObject that is possibly a proxy is resolved, resolving it if necessary.- Parameters:
anObject
-
-
-