use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method deleteFileOnDiskWithoutNotification.
/**
* Same as {@link #deleteFileOnDiskWithoutNotification(FileURI)}, accepting a module name.
*/
protected void deleteFileOnDiskWithoutNotification(String moduleName) {
FileURI fileURI = getFileURIFromModuleName(moduleName);
deleteFileOnDiskWithoutNotification(fileURI);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method assertIssuesInFiles.
/**
* Asserts issues in the files denoted by the given map's keys. Files for which the given map does not contain any
* IDs are *not* checked to be free of issues! If this is desired use method {@link #assertIssues(Map, boolean)}
* instead.
*
* @param fileURIToExpectedIssues
* a map from module IDs to the list of expected issues in each case.
* @param withIgnoredIssues
* iff <code>true</code>, even issues with an issue code that is among those returned by method
* {@link #getIgnoredIssueCodes()} will be taken into consideration.
*/
protected void assertIssuesInFiles(Map<FileURI, List<String>> fileURIToExpectedIssues, boolean withIgnoredIssues) {
class Error implements Comparable<Error> {
final String expected;
final String actual;
final String relFilePath;
Error(String expected, String actual, String relFilePath) {
this.expected = expected;
this.actual = actual;
this.relFilePath = relFilePath;
}
@Override
public String toString() {
return "issues in file " + relFilePath + " do not meet expectation\n" + "EXPECTED:\n" + expected + "\n" + "ACTUAL:\n" + actual;
}
@Override
public int compareTo(Error err) {
if (err == null) {
return 0;
}
return toString().compareTo(err.toString());
}
}
List<Error> failureMessages = new ArrayList<>();
for (Entry<FileURI, List<String>> pair : fileURIToExpectedIssues.entrySet()) {
FileURI fileURI = pair.getKey();
List<String> expectedIssues = pair.getValue();
List<String> actualIssues = getIssueStringsInFile(fileURI, withIgnoredIssues);
Set<String> actualIssuesAsSet = IterableExtensions.toSet(Iterables.transform(actualIssues, String::trim));
Set<String> expectedIssuesAsSet = IterableExtensions.toSet(Iterables.transform(expectedIssues, String::trim));
if (!Objects.equals(expectedIssuesAsSet, actualIssuesAsSet)) {
String indent = " ";
String expected = issuesToSortedString(expectedIssuesAsSet, indent);
String actual = issuesToSortedString(actualIssuesAsSet, indent);
String fileRelPath = getRelativePathFromFileUri(fileURI);
failureMessages.add(new Error(expected, actual, fileRelPath));
}
}
if (failureMessages.size() == 1) {
// make use of built-in compare view of JUnit
Error err = failureMessages.get(0);
Assert.assertEquals("issues in file " + err.relFilePath + " do not meet expectation\n", err.expected, err.actual);
} else if (failureMessages.size() > 1) {
Collections.sort(failureMessages);
Assert.fail("issues in several files do not meet the expectation:\n" + Joiner.on("\n").join(failureMessages));
}
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method saveOpenedFile.
/**
* Same as {@link #saveOpenedFile(FileURI)}, accepting a module name instead of a file URI.
*/
protected void saveOpenedFile(String moduleName) {
FileURI fileURI = getFileURIFromModuleName(moduleName);
saveOpenedFile(fileURI);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method issuesToString.
/**
* Joins the given issues into a single string.
* <p>
* In case only a map with diagnostics is available, use
* {@link Multimaps#transformValues(Multimap, com.google.common.base.Function) transformValues()} as follows:
*
* <pre>
* Multimaps.transformValues(uriToDiagnostic, languageClient::getIssueString)
* </pre>
*/
protected String issuesToString(Multimap<FileURI, String> issuesPerFile) {
if (issuesPerFile.isEmpty()) {
return "<none>";
}
StringBuilder sb = new StringBuilder();
List<FileURI> sortedFileURIs = IterableExtensions.sortWith(issuesPerFile.keySet(), Comparator.comparing(FileURI::toString));
for (FileURI currFileURI : sortedFileURIs) {
if (sb.length() > 0) {
sb.append('\n');
}
sb.append(getRelativePathFromFileUri(currFileURI));
sb.append(":\n ");
Collection<String> currFileIssues = issuesPerFile.get(currFileURI);
sb.append(issuesToSortedString(currFileIssues, " "));
}
return sb.toString();
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method sendDidChangeWatchedFiles.
/**
* Send a 'didChangeWatchedFiles' notification to the server. The file change type will be {@code changeType} for
* all given URIs.
*/
protected void sendDidChangeWatchedFiles(FileChangeType changeType, FileURI... changedFileURIs) {
if (changedFileURIs == null || changedFileURIs.length == 0) {
Assert.fail("no URIs of changed files given");
}
List<FileEvent> fileEvents = Stream.of(changedFileURIs).map(fileURI -> new FileEvent(fileURI.toString(), changeType)).collect(Collectors.toList());
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(fileEvents);
languageServer.didChangeWatchedFiles(params);
}
Aggregations