use of org.eclipse.n4js.tests.codegen.Class in project n4js by eclipse.
the class ScenarioGenerator method generateScenario.
/**
* Generates a test scenario according to the parameters specified in the test specification.
*
* @param destination
* the path to generate the scenario in
* @return a list files representing the root directories of the created projects
*/
public List<File> generateScenario(Path destination) {
List<File> result = new LinkedList<>();
// Create the required classifiers for the scenario.
ScenarioResult scenario = createScenario();
Classifier<?> supplier = scenario.supplier;
Classifier<?> client = scenario.client;
Class factory = scenario.factory;
Class implementer = scenario.implementer;
// Create a member for the supplier according the specified visibility and "abstract-ness".
switch(specification.getSupplierType()) {
case CLASS:
case DEFAULT_INTERFACE:
supplier.addMember(createMember("member", specification.getMemberVisibility()));
break;
case ABSTRACT_CLASS:
case INTERFACE:
supplier.addMember(createMember("member", specification.getMemberVisibility()).makeAbstract());
break;
}
// or it may attempt to access it by reading or writing it or calling it if it is a method.
switch(specification.getScenario()) {
case EXTENDS:
case IMPLEMENTS:
{
switch(specification.getUsageType()) {
case ACCESS:
switch(specification.getMemberStatic()) {
case YES:
client.addMember(createAccess("member", "S"));
break;
case NO:
client.addMember(createAccess("member", "this"));
break;
}
if (specification.getSupplierType() != ClassifierType.INTERFACE && specification.getSupplierType() != ClassifierType.ABSTRACT_CLASS)
break;
if (// Fields cannot be abstract
memberType == MemberType.FIELD)
break;
// $FALL-THROUGH$
case OVERRIDE:
client.addMember(createMember("member", specification.getMemberVisibility()).makeOverride());
break;
default:
throw new IllegalArgumentException("Unexpected usage type: " + specification.getUsageType());
}
break;
}
case REFERENCES:
{
if (specification.getUsageType() == UsageType.OVERRIDE)
throw new IllegalArgumentException("Cannot override in reference scenario");
switch(specification.getSupplierType()) {
case CLASS:
case DEFAULT_INTERFACE:
break;
case ABSTRACT_CLASS:
case INTERFACE:
implementer.addMember(createMember("member", specification.getMemberVisibility()).makeOverride());
break;
}
// Create a method that accesses the supplier's member via an instance created by the factory.
client.addMember(createAccess("member", "new GetS().getS()"));
break;
}
}
// created, according to the client location in the test specification.
switch(specification.getClientLocation()) {
case SAME_TYPE:
case SAME_MODULE:
{
Module module = new Module("SameModule");
module.addClassifier(supplier);
if (implementer != null)
module.addClassifier(implementer);
if (factory != null)
module.addClassifier(factory);
module.addClassifier(client);
Project project = new Project("SameModule", "sameVendor", "SameVendor", PROJECT_TYPE);
project.createSourceFolder("src").addModule(module);
result.add(project.create(destination));
break;
}
case SAME_PROJECT:
{
Module supplierModule = createSupplierModule(supplier, factory, implementer);
Module clientModule = createClientModule(client, supplier, factory, supplierModule);
Project project = new Project("SameProject", "sameVendor", "SameVendor", PROJECT_TYPE);
project.createSourceFolder("src").addModule(supplierModule).addModule(clientModule);
result.add(project.create(destination));
break;
}
case SAME_VENDOR:
{
Module supplierModule = createSupplierModule(supplier, factory, implementer);
Module clientModule = createClientModule(client, supplier, factory, supplierModule);
Project supplierProject = createSupplierProject(supplierModule, "sameVendor");
Project clientProject = createClientProject(clientModule, "sameVendor", supplierProject);
result.add(supplierProject.create(destination));
result.add(clientProject.create(destination));
break;
}
case OTHER:
{
Module supplierModule = createSupplierModule(supplier, factory, implementer);
Module clientModule = createClientModule(client, supplier, factory, supplierModule);
Project supplierProject = createSupplierProject(supplierModule, "vendorA");
Project clientProject = createClientProject(clientModule, "vendorB", supplierProject);
result.add(supplierProject.create(destination));
result.add(clientProject.create(destination));
break;
}
default:
break;
}
return result;
}
Aggregations