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

Add check & warning for sgen that does not contain any entries #1402

Merged
merged 2 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.getEntries is never null, EMF one to many references always return empty lists so the == null check is obsolete

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