Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1402 from Yakindu/issue_1381
Browse files Browse the repository at this point in the history
Add check & warning for sgen that does not contain any entries
  • Loading branch information
BeckmaR authored May 31, 2017
2 parents 3482899 + e079a69 commit bb05c8e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class SGenJavaValidator extends AbstractSGenJavaValidator {
public static final String INCOMPATIBLE_TYPE_STRING_EXPECTED = "Incompatible type, String expected";
public static final String UNKNOWN_CONTENT_TYPE = "Unknown content type '";
public static final String DEPRECATED = "Element is depricated";
public static final String EMPTY_SGEN = ".sgen file does not contain any entries";
// Failure codes
public static final String CODE_REQUIRED_FEATURE = "code_req_feature";

Expand Down Expand Up @@ -148,6 +149,14 @@ public void checkGeneratorExists(GeneratorModel model) {
SGenPackage.Literals.GENERATOR_MODEL__GENERATOR_ID);
}
}

@Check
public void checkEntriesExist(GeneratorModel model) {
if(model.getEntries() == null || model.getEntries().isEmpty()) {
warning(EMPTY_SGEN, null);
}
}


@Check
public void checkDuplicateGeneratorEntryFeature(final FeatureConfiguration config) {
Expand Down Expand Up @@ -226,7 +235,7 @@ public void checkRequiredParameters(FeatureConfiguration configuration) {
transform(
filter(concat(transform(transform(libraryDescriptors, getFeatureTypeLibrary()),
getFeatureTypes())), hasName(configuration.getType().getName())),
getParmeter())),
getParameter())),
isRequiredParamter()),
getName());

Expand All @@ -245,7 +254,7 @@ public void checkRequiredParameters(FeatureConfiguration configuration) {
@Check
public void checkDeprecatedParameters(GeneratorEntry entry) {
Iterable<FeatureParameter> deprecatedParameters = filter(
concat(transform(transform(entry.getFeatures(), getFeatureType()), getParmeter())), isDeprecated());
concat(transform(transform(entry.getFeatures(), getFeatureType()), getParameter())), isDeprecated());
for (FeatureParameter parameter : deprecatedParameters) {
warning(String.format(DEPRECATED + " %s : %s", parameter.getName(), parameter.getComment()),
SGenPackage.Literals.GENERATOR_ENTRY__ELEMENT_REF, parameter.getName());
Expand Down Expand Up @@ -278,7 +287,7 @@ public boolean apply(DeprecatableElement input) {
};
}

private Function<FeatureType, Iterable<FeatureParameter>> getParmeter() {
private Function<FeatureType, Iterable<FeatureParameter>> getParameter() {
return new Function<FeatureType, Iterable<FeatureParameter>>() {

public Iterable<FeatureParameter> apply(FeatureType from) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.yakindu.sct.generator.genmodel.validation.SGenJavaValidator.MISSING_REQUIRED_PARAMETER;
import static org.yakindu.sct.generator.genmodel.validation.SGenJavaValidator.UNKNOWN_CONTENT_TYPE;
import static org.yakindu.sct.generator.genmodel.validation.SGenJavaValidator.UNKOWN_GENERATOR;
import static org.yakindu.sct.generator.genmodel.validation.SGenJavaValidator.EMPTY_SGEN;

import java.lang.reflect.Method;

Expand Down Expand Up @@ -201,6 +202,23 @@ public void checkDeprecatedParameters() {
result.assertAny(new MsgPredicate(DEPRECATED));
}
}

/**
* @see SGenJavaValidator#checkDeprecatedParameters(GeneratorEntry)
*/
@Test
public void checkEntriesExist() {
EObject model = parseExpression(
"GeneratorModel for yakindu::java {}",
GeneratorModel.class.getSimpleName());
if (!(model instanceof GeneratorModel)) {
fail("Model is of the wrong type");
} else {
GeneratorModel genModel = (GeneratorModel) model;
AssertableDiagnostics result = tester.validate(genModel);
result.assertAny(new MsgPredicate(EMPTY_SGEN));
}
}

/**
* checks that each @Check method of {@link STextJavaValidator} has a @Test
Expand Down

0 comments on commit bb05c8e

Please sign in to comment.