use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class AbstractStructuredIdeTest method test.
/**
* Single entry method to perform tests.
* <p>
* Note: At this point, neither projects nor modules have a '*' appended.
*
* @param projectsModulesContents
* map that maps directories to module names which map to their contents.
* @param projectPath
* project that contains the module with the name 'moduleName'
* @param moduleName
* one moduleName of the {@code moduleNameToContents}. Will be opened during the test.
* @param t
* will be passed to {@link #performTest(Project, String, Object)}.
*/
protected Project test(Map<String, Map<String, String>> projectsModulesContents, String projectPath, String moduleName, T t) {
Project project = testWorkspaceManager.createTestOnDisk(projectsModulesContents);
startAndWaitForLspServer();
openFile(moduleName);
try {
performTest(project, moduleName, t);
} catch (AssertionError ae) {
throw ae;
} catch (Throwable th) {
throw new AssertionError("exception/error in #performTest() method", th);
}
return project;
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class AbstractOrganizeImportsTest method performTest.
@Override
protected void performTest(Project project, String moduleName, TestOrganizeImportsConfiguration config) throws Exception {
FileURI uri = getFileURIFromModuleName(moduleName);
if (config.expectedIssues.isEmpty()) {
assertNoIssues();
} else {
assertIssues(Collections.singletonMap(uri, config.expectedIssues));
}
TextDocumentIdentifier id = new TextDocumentIdentifier(uri.toString());
Range range = new Range(new Position(0, 0), new Position(0, 0));
CodeActionContext context = new CodeActionContext();
CodeActionParams params = new CodeActionParams(id, range, context);
CompletableFuture<List<Either<Command, CodeAction>>> codeActionFuture = languageServer.codeAction(params);
List<Either<Command, CodeAction>> result = codeActionFuture.join();
Command organizeImportsCommand = result.stream().map(e -> e.isLeft() ? e.getLeft() : e.getRight().getCommand()).filter(cmd -> cmd != null && Objects.equals(cmd.getCommand(), N4JSCommandService.N4JS_ORGANIZE_IMPORTS)).findFirst().orElse(null);
Assert.assertNotNull("code action for organize imports not found", organizeImportsCommand);
ExecuteCommandParams execParams = new ExecuteCommandParams(organizeImportsCommand.getCommand(), organizeImportsCommand.getArguments());
CompletableFuture<Object> execFuture = languageServer.executeCommand(execParams);
execFuture.join();
joinServerRequests();
assertContentOfFileOnDisk(uri, config.expectedCode);
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class TestWorkspaceManager method createYarnProject.
private Project createYarnProject(Map<String, ? extends Map<String, ? extends CharSequence>> projectsModulesContents) {
YarnWorkspaceProject yarnProject = new YarnWorkspaceProject(YARN_TEST_PROJECT, VENDOR, VENDOR_NAME);
Multimap<String, String> dependencies = HashMultimap.create();
for (String projectNameWithSelector : projectsModulesContents.keySet()) {
Map<String, ? extends CharSequence> moduleContents = projectsModulesContents.get(projectNameWithSelector);
String prjName = projectNameWithSelector;
if (prjName.startsWith(CFG_NODE_MODULES)) {
prjName = prjName.substring(CFG_NODE_MODULES.length());
Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.NodeModule);
yarnProject.addNodeModuleProject(project);
} else if (prjName.startsWith(CFG_WORKSPACES_FOLDER)) {
int idxCFG = CFG_WORKSPACES_FOLDER.length();
int idxSlash = prjName.indexOf("/");
String wsFolder = prjName.substring(idxCFG, idxSlash);
prjName = prjName.substring(idxSlash + 1);
Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.Member);
yarnProject.addMemberProject(wsFolder, project);
} else if (prjName.equals(CFG_YARN_PROJECT)) {
if (moduleContents.containsKey(N4JSGlobals.PACKAGE_JSON)) {
yarnProject.setProjectDescriptionContent(moduleContents.get(N4JSGlobals.PACKAGE_JSON).toString());
}
} else {
Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.Member);
yarnProject.addMemberProject(project);
}
}
setDependencies(yarnProject, dependencies);
// apply default values
boolean haveMemberRequiringN4jsRuntime = IterableExtensions.exists(yarnProject.getMemberProjects(), p -> N4JSGlobals.PROJECT_TYPES_REQUIRING_N4JS_RUNTIME.contains(p.getType()));
if (haveMemberRequiringN4jsRuntime) {
if (yarnProject.getNodeModuleProject(N4JS_RUNTIME) == null) {
yarnProject.addNodeModuleProject(N4JS_RUNTIME_FAKE);
}
}
return yarnProject;
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class TestWorkspaceManager method createTestOnDisk.
private Project createTestOnDisk(Path destination, Map<String, ? extends Map<String, ? extends CharSequence>> projectsModulesContents, boolean forceYarnWorkspace) {
final Project project;
if (!forceYarnWorkspace && projectsModulesContents.size() == 1) {
Entry<String, ? extends Map<String, ? extends CharSequence>> singleProject = projectsModulesContents.entrySet().iterator().next();
String projectName = singleProject.getKey();
Map<String, ? extends CharSequence> modulesContents = singleProject.getValue();
project = createSimpleProject(projectName, modulesContents, HashMultimap.create(), ProjectKind.TopLevel);
} else {
project = createYarnProject(projectsModulesContents);
}
Workspace workspace = new Workspace();
workspace.addProject(project);
createTestOnDisk(destination, workspace);
return project;
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class TestWorkspaceManager method getProjectRootFailSafe.
private File getProjectRootFailSafe(String projectName) {
if (!isCreated()) {
return null;
}
Path projectNamePath = projectNameToRelativePath(projectName);
Path createdProjectNamePath = projectNameToRelativePath(createdProject.getName());
Path createdProjectPath = getRoot().toPath().resolve(createdProjectNamePath);
if (projectName.equals(createdProject.getName())) {
return createdProjectPath.toFile();
}
if (createdProject instanceof YarnWorkspaceProject) {
Project containedProject = ((YarnWorkspaceProject) createdProject).getMemberProject(projectName);
if (containedProject != null) {
return createdProjectPath.resolve(YarnWorkspaceProject.PACKAGES).resolve(projectNamePath).toFile();
}
}
Project nodeModuleProject = createdProject.getNodeModuleProject(projectName);
if (nodeModuleProject != null) {
return createdProjectPath.resolve(N4JSGlobals.NODE_MODULES).resolve(projectNamePath).toFile();
}
if (createdProject instanceof YarnWorkspaceProject) {
for (Project containedProject : ((YarnWorkspaceProject) createdProject).getMemberProjects()) {
Project containedNodeModuleProject = createdProject.getNodeModuleProject(projectName);
if (containedNodeModuleProject != null) {
Path containedProjectNamePath = projectNameToRelativePath(containedProject.getName());
return createdProjectPath.resolve(YarnWorkspaceProject.PACKAGES).resolve(containedProjectNamePath).resolve(N4JSGlobals.NODE_MODULES).resolve(projectNamePath).toFile();
}
}
}
return null;
}
Aggregations