From 4637378014f6d457039f4f06ae90da13b7517093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Mon, 18 Nov 2024 20:17:35 +0200 Subject: [PATCH] Use IFile.create method taking byte array for content --- .../wildwebdeveloper/tests/TestHTML.java | 10 ++++----- .../wildwebdeveloper/tests/TestJsTs.java | 3 +-- .../tests/TestLanguageServers.java | 21 +++++++++---------- .../tests/TestSyntaxHighlighting.java | 3 +-- .../wildwebdeveloper/tests/TestXML.java | 13 ++++++------ .../wildwebdeveloper/tests/TestYaml.java | 5 ++--- .../debug/node/VSCodeJSDebugDelegate.java | 7 +++---- 7 files changed, 27 insertions(+), 35 deletions(-) diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java index 638af28e7f..2523c14d04 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019-2023 Red Hat Inc. and others. + * Copyright (c) 2019, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -14,8 +14,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.ByteArrayInputStream; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -42,7 +40,7 @@ public void testHTMLFile() throws Exception { project.create(null); project.open(null); final IFile file = project.getFile("blah.html"); - file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); + file.create("FAIL".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<"); @@ -62,7 +60,7 @@ public void testFormat() throws Exception { project.create(null); project.open(null); final IFile file = project.getFile("blah.html"); - file.create(new ByteArrayInputStream("".getBytes()), true, null); + file.create("".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.setFocus(); @@ -102,7 +100,7 @@ public void autoCloseTags() throws Exception { project.create(null); project.open(null); final IFile file = project.getFile("autoCloseTags.html"); - file.create(new ByteArrayInputStream("<"); @@ -95,7 +94,7 @@ public void testHTMLFile() throws Exception { @Test public void testYAMLFile() throws Exception { final IFile file = project.getFile("blah.yaml"); - file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); + file.create("FAIL".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("hello: '"); @@ -111,7 +110,7 @@ public void testYAMLFile() throws Exception { @Test public void testJSONFile() throws Exception { final IFile file = project.getFile("blah.json"); - file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); + file.create("FAIL".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("ERROR"); @@ -127,7 +126,7 @@ public void testJSONFile() throws Exception { @Test public void testJSFile() throws Exception { final IFile file = project.getFile("blah.js"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); DisplayHelper.sleep(2000); // Give time for LS to initialize enough before making edit and sending a @@ -145,7 +144,7 @@ public void testJSFile() throws Exception { @Test public void testTSFile() throws Exception { final IFile file = project.getFile("blah.ts"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); @@ -161,7 +160,7 @@ public void testTSFile() throws Exception { @Test public void testJSXFile() throws Exception { final IFile file = project.getFile("blah.jsx"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<"); @@ -177,7 +176,7 @@ public void testJSXFile() throws Exception { @Test public void testTSXFile() throws Exception { final IFile file = project.getFile("blah.tsx"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); @@ -272,7 +271,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Test public void testSCSSFile() throws Exception { final IFile file = project.getFile("blah.scss"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); @@ -288,7 +287,7 @@ public void testSCSSFile() throws Exception { @Test public void testLESSFile() throws Exception { final IFile file = project.getFile("blah.less"); - file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); + file.create("ERROR".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestSyntaxHighlighting.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestSyntaxHighlighting.java index 4138f738c3..e9944e3cab 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestSyntaxHighlighting.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestSyntaxHighlighting.java @@ -14,7 +14,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.ByteArrayInputStream; import java.util.Arrays; import org.eclipse.core.resources.IFile; @@ -47,7 +46,7 @@ public void initializeHostProject() throws CoreException { @Test public void testJSXHighlighting() throws CoreException { IFile file = project.getFile("test.jsx"); - file.create(new ByteArrayInputStream("var n = 4;\n".getBytes()), true, null); + file.create("var n = 4;\n".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); StyledText widget = (StyledText) editor.getAdapter(Control.class); diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestXML.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestXML.java index fabd93550e..5e5c3d2cfb 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestXML.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestXML.java @@ -17,7 +17,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; @@ -75,7 +74,7 @@ public void setUpProject() throws CoreException { @Test public void testXMLFile() throws Exception { final IFile file = project.getFile("blah.xml"); - file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); + file.create("FAIL".getBytes(), true, false, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set(""); @@ -144,7 +143,7 @@ public void testComplexXML() throws Exception { + " xmlns:layout=\"sap.ui.layout\">\n" + " |\n" + ""; int offset = content.indexOf('|'); content = content.replace("|", ""); - file.create(new ByteArrayInputStream(content.getBytes()), true, null); + file.create(content.getBytes(), true, false, null); AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, "org.eclipse.ui.genericeditor.GenericEditor"); @@ -158,7 +157,7 @@ public void testComplexXML() throws Exception { @Test public void autoCloseTags() throws Exception { final IFile file = project.getFile("autoCloseTags.xml"); - file.create(new ByteArrayInputStream(" { result[0] = null; - try (ByteArrayInputStream is = new ByteArrayInputStream(new byte[0])) { + try { createContainers(file); - file.create(is, true, null); + file.create(new byte[0], true, false, null); file.refreshLocal(IResource.DEPTH_ZERO, null); result[0] = file; - } catch (CoreException | IOException e) { + } catch (CoreException e) { ILog.get().error(e.getMessage(), e); } }, null);