use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class AbstractCodeActionTest method performTest.
@Override
protected void performTest(Project project, String moduleName, N4JSTestCodeActionConfiguration tcac) throws InterruptedException, ExecutionException {
CodeActionParams codeActionParams = new CodeActionParams();
Range range = new Range();
Position posStart = new Position(tcac.getLine(), tcac.getColumn());
Position posEnd = tcac.getEndLine() >= 0 && tcac.getEndColumn() >= 0 ? new Position(tcac.getEndLine(), tcac.getEndColumn()) : posStart;
range.setStart(posStart);
range.setEnd(posEnd);
codeActionParams.setRange(range);
CodeActionContext context = new CodeActionContext();
FileURI uri = getFileURIFromModuleName(moduleName);
context.setDiagnostics(Lists.newArrayList(getIssuesInFile(uri)));
codeActionParams.setContext(context);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(uri.toString());
codeActionParams.setTextDocument(textDocument);
CompletableFuture<List<Either<Command, CodeAction>>> future = languageServer.codeAction(codeActionParams);
List<Either<Command, CodeAction>> result = future.get();
if (tcac.getAssertCodeActions() != null) {
tcac.getAssertCodeActions().apply(result);
} else {
String resultStr = result.stream().map(cmdOrAction -> getStringLSP4J().toString3(cmdOrAction)).collect(Collectors.joining("\n-----\n"));
assertEquals(tcac.getExpectedCodeActions().trim(), resultStr.trim());
}
}
use of org.eclipse.n4js.tests.codegen.Project 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;
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class TestWorkspaceManager method getProjectRootContaining.
/**
* For this method, it is sufficient if the given file is located somewhere inside a project; strict
* {@link SourceFolderSnapshot#contains(URI) containment in a source folder} is *not* required.
*
* @return the root folder of the project containing the given file or <code>null</code>.
*/
public File getProjectRootContaining(File file) {
List<Project> allProjects = new ArrayList<>();
if (createdProject instanceof YarnWorkspaceProject) {
allProjects.addAll(((YarnWorkspaceProject) createdProject).getMemberProjects());
} else {
allProjects.add(createdProject);
}
Path filePath = file.toPath();
Path resultPath = null;
for (Project project : allProjects) {
File projectRoot = getProjectRoot(project.getName());
if (projectRoot != null) {
Path projectRootPath = projectRoot.toPath();
if (filePath.startsWith(projectRootPath)) {
if (resultPath == null || projectRootPath.getNameCount() > resultPath.getNameCount()) {
resultPath = projectRootPath;
}
}
}
}
return resultPath != null ? resultPath.toFile() : null;
}
use of org.eclipse.n4js.tests.codegen.Project in project n4js by eclipse.
the class TestWorkspaceManager method setDependencies.
private void setDependencies(YarnWorkspaceProject yarnProject, Multimap<String, String> dependencies) {
for (String projectName : dependencies.keySet()) {
Collection<String> projectDependencies = dependencies.get(projectName);
Project project = yarnProject.getMemberProject(projectName);
if (project == null) {
project = yarnProject.getNodeModuleProject(projectName);
if (project == null) {
throw new IllegalStateException("unknown project: " + projectName);
}
}
for (String projectDependency : projectDependencies) {
Project dependency = yarnProject.getMemberProject(projectDependency);
if (dependency == null) {
dependency = yarnProject.getNodeModuleProject(projectDependency);
if (dependency == null) {
// -> this might be a valid test case, so ignore this problem
continue;
}
}
project.addProjectDependency(dependency.getName());
}
}
}
use of org.eclipse.n4js.tests.codegen.Project 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