use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method assertFile.
/**
* Asserts the workspace contains the given file. {@link #getFileURIFromModuleName(String)}
*/
protected void assertFile(String moduleName) {
try {
FileURI file = getFileURIFromModuleName(moduleName);
assertNotNull(file);
} catch (Exception e) {
fail();
}
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method createFileOnDiskWithoutNotification.
/**
* Same as {@link #createFileOnDiskWithoutNotification(FileURI, CharSequence)}, placing the new file next to an
* existing module.
*/
protected void createFileOnDiskWithoutNotification(String existingModuleName, String newFileNameIncludingExtension, CharSequence content) {
FileURI existingFileURI = getFileURIFromModuleName(existingModuleName);
FileURI newFileURI = existingFileURI.getParent().appendSegment(newFileNameIncludingExtension);
createFileOnDiskWithoutNotification(newFileURI, content);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method assertIssues.
/**
* Same as {@link #assertIssuesInFiles(Map, boolean)}, but in addition to checking the files denoted by the given
* map's keys, this method will also assert that the remaining files in the workspace do not contain any issues.
* Flag <code>withIgnoredIssues</code> applies to those issues accordingly.
*/
protected void assertIssues(Map<FileURI, List<String>> fileURIToExpectedIssues, boolean withIgnoredIssues) {
// check given expectations
assertIssuesInFiles(fileURIToExpectedIssues, withIgnoredIssues);
Set<FileURI> checkedModules = fileURIToExpectedIssues.keySet();
// check that there are no other issues in the workspace
Multimap<FileURI, Diagnostic> allIssues = languageClient.getIssues();
Set<FileURI> modulesWithIssues = allIssues.keySet();
Set<FileURI> uncheckedModulesWithIssues = new LinkedHashSet<>(modulesWithIssues);
uncheckedModulesWithIssues.removeAll(checkedModules);
if (!uncheckedModulesWithIssues.isEmpty()) {
Multimap<FileURI, String> issuesPerUncheckedModule = LinkedHashMultimap.create();
for (FileURI currModuleURI : uncheckedModulesWithIssues) {
List<String> currModuleIssuesAsList = getIssueStringsInFile(currModuleURI, withIgnoredIssues);
issuesPerUncheckedModule.putAll(currModuleURI, currModuleIssuesAsList);
}
if (!issuesPerUncheckedModule.isEmpty()) {
// empty if all remaining issues are ignored
String msg = fileURIToExpectedIssues.size() == 0 ? "expected no issues in workspace but found one or more issues:" : "found one or more unexpected issues in workspace:";
Assert.fail(msg + "\n" + issuesToString(issuesPerUncheckedModule));
}
}
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractRenameTest method performTestAtPosition.
private void performTestAtPosition(RenamePosition pos, RenameTestConfiguration config) throws InterruptedException, ExecutionException {
FileURI fileURI = getFileURIFromModuleName(pos.moduleName);
String uriStr = fileURI.toString();
// ensure the file with URI 'fileURI' is open and is the only opened file
if (!getOpenFiles().equals(Collections.singleton(fileURI))) {
closeAllFiles();
joinServerRequests();
openFile(fileURI);
joinServerRequests();
}
String sourceBefore = config.projectsModulesSourcesBefore.get(pos.projectName).get(pos.moduleName);
PrepareRenameParams prepareRenameParams = new PrepareRenameParams();
prepareRenameParams.setTextDocument(new TextDocumentIdentifier(uriStr));
prepareRenameParams.setPosition(new Position(pos.line, pos.column));
Either<Range, PrepareRenameResult> result1 = languageServer.prepareRename(prepareRenameParams).get();
if (result1 == null || (result1.getLeft() == null && result1.getRight() == null)) {
fail("element cannot be renamed", sourceBefore, pos);
}
RenameParams renameParams = new RenameParams();
renameParams.setTextDocument(new TextDocumentIdentifier(uriStr));
renameParams.setPosition(new Position(pos.line, pos.column));
renameParams.setNewName(config.newName);
WorkspaceEdit workspaceEdit = languageServer.rename(renameParams).get();
Map<FileURI, String> fileURI2ActualSourceAfter = applyWorkspaceEdit(config.projectsModulesSourcesBefore, workspaceEdit, pos, config);
Set<FileURI> checkedFileURIs = new LinkedHashSet<>();
for (Map<String, String> moduleName2ExpectedSourceAfter : config.projectsModulesExpectedSourcesAfter.values()) {
for (Entry<String, String> entry : moduleName2ExpectedSourceAfter.entrySet()) {
String moduleName = entry.getKey();
String expectedSourceAfter = entry.getValue();
FileURI changedFileURI = getFileURIFromModuleName(moduleName);
String actualSourceAfter = fileURI2ActualSourceAfter.get(changedFileURI);
if (actualSourceAfter == null) {
fail("expected changes in module '" + moduleName + "' but rename did not lead to any changes in this module", sourceBefore, pos);
} else if (!actualSourceAfter.equals(expectedSourceAfter)) {
fail("rename led to incorrect source code changes in module '" + moduleName + "'", sourceBefore, pos, expectedSourceAfter, actualSourceAfter);
}
checkedFileURIs.add(changedFileURI);
}
}
for (Entry<FileURI, String> entry : fileURI2ActualSourceAfter.entrySet()) {
FileURI changedFileURI = entry.getKey();
String actualSourceAfter = entry.getValue();
if (!checkedFileURIs.contains(changedFileURI)) {
fail("rename led to unexpected changes in file '" + changedFileURI.getName() + "'", sourceBefore, pos, null, actualSourceAfter);
}
}
}
use of org.eclipse.n4js.workspace.locations.FileURI 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);
}
Aggregations