Search in sources :

Example 1 with Module

use of org.eclipse.n4js.tests.codegen.Module in project n4js by eclipse.

the class TestWorkspaceManager method createAndAddModule.

private void createAndAddModule(String contents, String moduleName, Folder nmSourceFolder) {
    NameAndExtension nae = getN4JSNameAndExtension(moduleName);
    Module module = nae.extension == null ? new Module(moduleName) : new Module(nae.name, nae.extension);
    module.setContents(contents);
    nmSourceFolder.addModule(module);
}
Also used : Module(org.eclipse.n4js.tests.codegen.Module)

Example 2 with Module

use of org.eclipse.n4js.tests.codegen.Module in project n4js by eclipse.

the class ScenarioGenerator method createSupplierModule.

/**
 * Creates the supplier module with the given supplier classifier, factory, and implementer classes. While the
 * supplier classifier must not be <code>null</code>, the factory and / or the implementer may be <code>null</code>.
 * The newly created module will contain the supplier classifier and the given factory and / or implementer if they
 * are not <code>null</code>.
 *
 * @param supplier
 *            the supplier classifier
 * @param factory
 *            the factory class
 * @param implementer
 *            the implementer class
 * @return the newly created module
 */
private Module createSupplierModule(Classifier<?> supplier, Class factory, Class implementer) {
    Module supplierModule = new Module("SupplierModule");
    supplierModule.addClassifier(supplier);
    if (implementer != null)
        supplierModule.addClassifier(implementer);
    if (factory != null)
        supplierModule.addClassifier(factory);
    return supplierModule;
}
Also used : Module(org.eclipse.n4js.tests.codegen.Module)

Example 3 with Module

use of org.eclipse.n4js.tests.codegen.Module in project n4js by eclipse.

the class XtFileDataParser method createDefaultWorkspace.

static XtWorkspace createDefaultWorkspace(String fileName, String xtFileContent, XtSetupParseResult setupParseResult) {
    String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
    String moduleName = fileName.substring(0, fileName.length() - 1 - extension.length());
    Module xtFileModule = new Module(moduleName, extension);
    xtFileModule.setContents(xtFileContent);
    Folder srcFolder = new Folder(DEFAULT_SOURCE_FOLDER);
    srcFolder.addModule(xtFileModule);
    Project project = new Project(DEFAULT_PROJECT_NAME, VENDOR, VENDOR_NAME);
    project.addSourceFolder(srcFolder);
    project.setGenerateDts(setupParseResult.generateDts);
    for (String otherSrcFileName : setupParseResult.files.keySet()) {
        String otherExt = URIUtils.fileExtension(URIUtils.toFileUri(otherSrcFileName));
        String otherContent = setupParseResult.files.get(otherSrcFileName);
        String otherModuleName = otherSrcFileName.substring(0, otherSrcFileName.length() - otherExt.length() - 1);
        Module otherModule = new Module(otherModuleName, otherExt);
        otherModule.setContents(otherContent);
        srcFolder.addModule(otherModule);
    }
    XtWorkspace workspace = new XtWorkspace();
    workspace.addProject(project);
    workspace.moduleNameOfXtFile = fileName;
    return workspace;
}
Also used : Project(org.eclipse.n4js.tests.codegen.Project) XtWorkspace(org.eclipse.n4js.ide.tests.helper.server.xt.XtSetupParser.XtWorkspace) Module(org.eclipse.n4js.tests.codegen.Module) Folder(org.eclipse.n4js.tests.codegen.Folder)

Example 4 with Module

use of org.eclipse.n4js.tests.codegen.Module 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;
}
Also used : Project(org.eclipse.n4js.tests.codegen.Project) Class(org.eclipse.n4js.tests.codegen.Class) Module(org.eclipse.n4js.tests.codegen.Module) File(java.io.File) LinkedList(java.util.LinkedList)

Example 5 with Module

use of org.eclipse.n4js.tests.codegen.Module in project n4js by eclipse.

the class ScenarioGenerator method createClientModule.

/**
 * Creates the client module with the given client classifier. If the given factory is not <code>null</code>, the
 * newly created module will import the given supplier classifier from the given supplier module. Otherwise, it will
 * import the given factory from the given supplier module, but not the given supplier itself.
 *
 * @param client
 *            the client classifier
 * @param supplier
 *            the supplier classifier
 * @param supplierFactory
 *            the supplier factory
 * @param supplierModule
 *            the supplier module containing the supplier classifier and factory
 *
 * @return the newly created module
 */
private Module createClientModule(Classifier<?> client, Classifier<?> supplier, Class supplierFactory, Module supplierModule) {
    Module clientModule = new Module("ClientModule");
    if (supplierFactory != null)
        clientModule.addImport(supplierFactory, supplierModule);
    else
        clientModule.addImport(supplier, supplierModule);
    clientModule.addClassifier(client);
    return clientModule;
}
Also used : Module(org.eclipse.n4js.tests.codegen.Module)

Aggregations

Module (org.eclipse.n4js.tests.codegen.Module)5 Project (org.eclipse.n4js.tests.codegen.Project)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 XtWorkspace (org.eclipse.n4js.ide.tests.helper.server.xt.XtSetupParser.XtWorkspace)1 Class (org.eclipse.n4js.tests.codegen.Class)1 Folder (org.eclipse.n4js.tests.codegen.Folder)1