Search in sources :

Example 36 with FileURI

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);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 37 with 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));
    }
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 38 with FileURI

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);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 39 with 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();
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 40 with FileURI

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);
}
Also used : DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) CliTools(org.eclipse.n4js.cli.helper.CliTools) FileTime(java.nio.file.attribute.FileTime) FileUtils(org.eclipse.n4js.utils.io.FileUtils) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) UriExtensions(org.eclipse.xtext.ide.server.UriExtensions) Collections.singletonList(java.util.Collections.singletonList) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) FluentIterable(com.google.common.collect.FluentIterable) N4JSLanguageConstants(org.eclipse.n4js.N4JSLanguageConstants) Optional(com.google.common.base.Optional) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) Map(java.util.Map) Path(java.nio.file.Path) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) AfterClass(org.junit.AfterClass) Set(java.util.Set) NameAndExtension(org.eclipse.n4js.ide.tests.helper.server.TestWorkspaceManager.NameAndExtension) WrappedException(org.eclipse.emf.common.util.WrappedException) LocationLink(org.eclipse.lsp4j.LocationLink) SystemOutRedirecter(org.eclipse.n4js.cli.helper.SystemOutRedirecter) ConcurrentIndex(org.eclipse.n4js.xtext.ide.server.build.ConcurrentIndex) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) Pair(org.eclipse.xtext.xbase.lib.Pair) GlobalRegistries(org.eclipse.xtext.testing.GlobalRegistries) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) URI(org.eclipse.emf.common.util.URI) ApplyWorkspaceEditParams(org.eclipse.lsp4j.ApplyWorkspaceEditParams) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IIdeTestLanguageClientListener(org.eclipse.n4js.ide.tests.helper.client.IdeTestLanguageClient.IIdeTestLanguageClientListener) Diagnostic(org.eclipse.lsp4j.Diagnostic) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) Strings(com.google.common.base.Strings) FileChangeType(org.eclipse.lsp4j.FileChangeType) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) BuilderFrontend(org.eclipse.n4js.xtext.ide.server.build.BuilderFrontend) TextEdit(org.eclipse.lsp4j.TextEdit) Lists(com.google.common.collect.Lists) TextDocumentEdit(org.eclipse.lsp4j.TextDocumentEdit) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) LanguageInfo(org.eclipse.xtext.LanguageInfo) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) Files(java.nio.file.Files) N4JSLanguageUtils(org.eclipse.n4js.utils.N4JSLanguageUtils) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) IOException(java.io.IOException) GlobalStateMemento(org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) SourceFolderSnapshot(org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot) Assert.assertNull(org.junit.Assert.assertNull) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceOperation(org.eclipse.lsp4j.ResourceOperation) Module(com.google.inject.Module) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) BiFunction(java.util.function.BiFunction) Inject(com.google.inject.Inject) MessageType(org.eclipse.lsp4j.MessageType) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FileEvent(org.eclipse.lsp4j.FileEvent) After(org.junit.After) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Assert.fail(org.junit.Assert.fail) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) FileURI(org.eclipse.n4js.workspace.locations.FileURI) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) Objects(java.util.Objects) CompletionItem(org.eclipse.lsp4j.CompletionItem) List(java.util.List) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) N4jsLibsAccess(org.eclipse.n4js.cli.helper.N4jsLibsAccess) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) BuildOrderFactory(org.eclipse.n4js.xtext.workspace.BuildOrderFactory) CompletionParams(org.eclipse.lsp4j.CompletionParams) BeforeClass(org.junit.BeforeClass) XLanguageServerImpl(org.eclipse.n4js.xtext.ide.server.XLanguageServerImpl) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) XDocument(org.eclipse.n4js.xtext.ide.server.XDocument) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) MessageParams(org.eclipse.lsp4j.MessageParams) ResourceChange(org.eclipse.lsp4j.ResourceChange) Position(org.eclipse.lsp4j.Position) CompletionList(org.eclipse.lsp4j.CompletionList) IdeTestLanguageClient(org.eclipse.n4js.ide.tests.helper.client.IdeTestLanguageClient) PrintStream(java.io.PrintStream) Assert.assertNotNull(org.junit.Assert.assertNotNull) SetView(com.google.common.collect.Sets.SetView) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) Comparator(java.util.Comparator) Collections(java.util.Collections) FileEvent(org.eclipse.lsp4j.FileEvent) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Aggregations

FileURI (org.eclipse.n4js.workspace.locations.FileURI)49 List (java.util.List)13 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Position (org.eclipse.lsp4j.Position)9 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)9 IOException (java.io.IOException)7 CompletionList (org.eclipse.lsp4j.CompletionList)7 Collections (java.util.Collections)6 Range (org.eclipse.lsp4j.Range)6 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Files (java.nio.file.Files)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 URI (org.eclipse.emf.common.util.URI)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 Diagnostic (org.eclipse.lsp4j.Diagnostic)5