Package de.gebit.integrity.utils
Class IntegrityDSLUtil
- java.lang.Object
-
- de.gebit.integrity.utils.IntegrityDSLUtil
-
public final class IntegrityDSLUtil extends 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 StringcleanMultiLineComment(VisibleMultiLineComment aComment)Removes prefix and suffix from visible single-line comment text, as well as any newlines in between.static StringcleanSingleLineComment(VisibleSingleLineComment aComment)Removes the prefix as well as any trailing newlines from visible single-line comment text.static voidensureResolved(org.eclipse.emf.ecore.EObject anObject)Ensures that a given EObject that is possibly a proxy is resolved, resolving it if necessary.static VariableOrConstantEntityextractVariableOrConstantEntity(ValueOrEnumValueOrOperation anInput)Attempts to extract aVariableOrConstantEntityfrom the providedValueOrEnumValueOrOperation.static <T extends org.eclipse.emf.ecore.EObject>
TfindUpstreamContainer(Class<T> aContainerClass, org.eclipse.emf.ecore.EObject aSource)Finds an upstream container matching a provided container class.static 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 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 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 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 List<ResultFieldTuple>getAllResultNamesFromFixtureMethod(MethodReference aMethod)Returns a list of named results defined by a given fixture method.static Collection<ValueOrEnumValueOrOperation>getAllValuesFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection)Aggregates allValueOrEnumValueOrOperations from the givenValueOrEnumValueOrOperationCollection.
Integrity has (historically; could be done more elegant with todays' Xtext) splittedValueOrEnumValueOrOperationCollections' internal values into two properties: a single value comes fromValueOrEnumValueOrOperationCollection.getValue()and everything else goes intoValueOrEnumValueOrOperationCollection.getMoreValues().static StringgetExpectedResultNameStringFromTestResultName(ResultName aName)Returns the name of a specific test result value.static StringgetIdentifierFromArbitraryParameterOrResultName(ArbitraryParameterOrResultName aName)ArbitraryParameterOrResultNames can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes).static StringgetIdentifierFromKeyValuePair(KeyValuePair aPair)KeyValuePairs can be identified either by a free-form String (enclosed in quotes) or by a more restricted ID (without quotes).static ValueOrEnumValueOrOperationCollectiongetInitialValueForConstant(ConstantDefinition aConstant, VariantDefinition aVariant)Determines the initial value for the given constant.static ValueOrEnumValueOrOperationCollectiongetInitialValueForVariableOrConstantEntity(VariableOrConstantEntity anEntity, VariantDefinition aVariant)Determines the initial value to use for the givenVariableOrConstantEntity.static MethodReferencegetMethodReferenceForAction(org.eclipse.emf.ecore.EObject anAction)static PackageDefinitiongetPackageContaining(org.eclipse.emf.ecore.EObject anObject)Finds thePackageDefinitionthat contains the givenEObject.static booleangetParamMandatoryFlagFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)Returns whether the mandatory flag is set defined by a given annotation reference.static StringgetParamNameFromAnnotation(org.eclipse.xtext.common.types.JvmAnnotationReference anAnnotation)Returns the name of a single parameter defined by a given annotation reference.static StringgetParamNameStringFromParameterName(ParameterName aParameterName)Returns the name of a single given parameter defined by aParameterNameinstance.static StringgetQualifiedCallName(CallDefinition aCall)Returns the fully qualified name of a givenCallDefinition.static StringgetQualifiedForkName(ForkDefinition aFork)Returns the fully qualified name of a givenForkDefinition.static StringgetQualifiedNameOfFixtureMethod(MethodReference aReference)Returns the fully qualified name of the fixture method referenced by the given method reference.static StringgetQualifiedSuiteName(SuiteDefinition aSuite)Returns the fully qualified name of a givenSuiteDefinition.static StringgetQualifiedTestName(TestDefinition aTest)Returns the fully qualified name of a givenTestDefinition.static StringgetQualifiedVariableEntityName(VariableOrConstantEntity aVariable, boolean aQualifyLocalVariables)Returns the fully qualified name of the givenVariableOrConstantEntity.static StringgetQualifiedVariantName(VariantDefinition aVariant)Returns the fully qualified name of a givenVariantDefinition.static ValueOrEnumValueOrOperationgetSpecificValueFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection, int anIndex)Gets a specific index position out of aValueOrEnumValueOrOperationCollection.static SuiteDefinitiongetSuiteContaining(org.eclipse.emf.ecore.EObject anObject)Finds theSuiteDefinitionthat contains the givenEObject.static StringgetSuiteTitle(SuiteDefinition aSuite)Gets the suites' title from a given suite.static org.eclipse.emf.ecore.EObjectgetTableHeaderForTableCell(ParameterTableValue aTableCell)Finds the corresponding table header element to a given table cell element.static Map<ParameterTableHeader,List<ParameterTableValue>>getTableParameterValuesPerParameter(TableTest aTableTest)Returns a map of allParameterTableHeaders in a givenTableTestwith their associatedParameterTableValues.static booleanisGlobalVariableOrConstant(VariableOrConstantEntity anEntity)Checks whether the given variable/constant entity is defined in a global (package) context.static booleanisPrivate(org.eclipse.emf.ecore.EObject anObject)Checks whether the givenEObjectis of private visibility.static booleanisPrivateInsideSuite(org.eclipse.emf.ecore.EObject anObject)Checks whether the givenEObjectis located inside a suite and is thus of private visibility by default.static BooleanisResult(org.eclipse.emf.ecore.EObject anObject)Determines whether a givenEObjectis part of a result of a test/call/tabletest.
-
-
-
Method Detail
-
getAllParamNamesFromFixtureMethod
public static 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 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 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 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 String getParamNameStringFromParameterName(ParameterName aParameterName)
Returns the name of a single given parameter defined by aParameterNameinstance.- Parameters:
aParameterName- the parameter name instance- Returns:
- the parameter name string
-
getAllEnumLiteralsFromFixtureMethodParam
public static 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 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 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 String getQualifiedSuiteName(SuiteDefinition aSuite)
Returns the fully qualified name of a givenSuiteDefinition.- Parameters:
aSuite- the suite- Returns:
- the fully qualified name
-
getQualifiedVariantName
public static String getQualifiedVariantName(VariantDefinition aVariant)
Returns the fully qualified name of a givenVariantDefinition.- Parameters:
aVariant- the variant- Returns:
- the fully qualified name
-
getQualifiedForkName
public static String getQualifiedForkName(ForkDefinition aFork)
Returns the fully qualified name of a givenForkDefinition.- Parameters:
aFork- the fork- Returns:
- the fully qualified name
-
getQualifiedCallName
public static 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 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 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 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 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 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 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 Boolean isResult(org.eclipse.emf.ecore.EObject anObject)
Determines whether a givenEObjectis 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 Map<ParameterTableHeader,List<ParameterTableValue>> getTableParameterValuesPerParameter(TableTest aTableTest)
Returns a map of allParameterTableHeaders in a givenTableTestwith their associatedParameterTableValues.- 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 Collection<ValueOrEnumValueOrOperation> getAllValuesFromCollection(ValueOrEnumValueOrOperationCollection aValueCollection)
Aggregates allValueOrEnumValueOrOperations from the givenValueOrEnumValueOrOperationCollection.
Integrity has (historically; could be done more elegant with todays' Xtext) splittedValueOrEnumValueOrOperationCollections' 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(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 thePackageDefinitionthat 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 theSuiteDefinitionthat 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 String getIdentifierFromKeyValuePair(KeyValuePair aPair)
KeyValuePairs 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 String getIdentifierFromArbitraryParameterOrResultName(ArbitraryParameterOrResultName aName)
ArbitraryParameterOrResultNames 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 givenEObjectis 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 givenEObjectis 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 aVariableOrConstantEntityfrom 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-
-
-