Skip to content

Commit 4637378

Browse files
committed
Use IFile.create method taking byte array for content
1 parent 449fc7c commit 4637378

File tree

7 files changed

+27
-35
lines changed

7 files changed

+27
-35
lines changed

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2023 Red Hat Inc. and others.
2+
* Copyright (c) 2019, 2024 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -14,8 +14,6 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

17-
import java.io.ByteArrayInputStream;
18-
1917
import org.eclipse.core.resources.IFile;
2018
import org.eclipse.core.resources.IProject;
2119
import org.eclipse.core.resources.IResource;
@@ -42,7 +40,7 @@ public void testHTMLFile() throws Exception {
4240
project.create(null);
4341
project.open(null);
4442
final IFile file = project.getFile("blah.html");
45-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
43+
file.create("FAIL".getBytes(), true, false, null);
4644
ITextEditor editor = (ITextEditor) IDE
4745
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
4846
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
@@ -62,7 +60,7 @@ public void testFormat() throws Exception {
6260
project.create(null);
6361
project.open(null);
6462
final IFile file = project.getFile("blah.html");
65-
file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
63+
file.create("<html><body><a></a></body></html>".getBytes(), true, false, null);
6664
ITextEditor editor = (ITextEditor) IDE
6765
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
6866
editor.setFocus();
@@ -102,7 +100,7 @@ public void autoCloseTags() throws Exception {
102100
project.create(null);
103101
project.open(null);
104102
final IFile file = project.getFile("autoCloseTags.html");
105-
file.create(new ByteArrayInputStream("<foo".getBytes()), true, null);
103+
file.create("<foo".getBytes(), true, false, null);
106104
ITextEditor editor = (ITextEditor) IDE
107105
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
108106
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestJsTs.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

17-
import java.io.ByteArrayInputStream;
1817
import java.lang.reflect.Method;
1918
import java.util.HashSet;
2019
import java.util.Set;
@@ -101,7 +100,7 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
101100
String newContent = content.replaceAll(oldName, newName);
102101

103102
int offset = content.indexOf(oldName);
104-
file.create(new ByteArrayInputStream(content.getBytes()), true, null);
103+
file.create(content.getBytes(), true, false, null);
105104
AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor(
106105
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file,
107106
"org.eclipse.ui.genericeditor.GenericEditor");

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestLanguageServers.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.junit.jupiter.api.Assertions.assertTrue;
1717

18-
import java.io.ByteArrayInputStream;
1918
import java.io.File;
2019
import java.io.IOException;
2120
import java.nio.file.FileVisitResult;
@@ -63,7 +62,7 @@ public void setUpProject() throws Exception {
6362
@Test
6463
public void testCSSFile() throws Exception {
6564
final IFile file = project.getFile("blah.css");
66-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
65+
file.create("ERROR".getBytes(), true, false, null);
6766
ITextEditor editor = (ITextEditor) IDE
6867
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
6968
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
@@ -79,7 +78,7 @@ public void testCSSFile() throws Exception {
7978
@Test
8079
public void testHTMLFile() throws Exception {
8180
final IFile file = project.getFile("blah.html");
82-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
81+
file.create("FAIL".getBytes(), true, false, null);
8382
ITextEditor editor = (ITextEditor) IDE
8483
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
8584
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
@@ -95,7 +94,7 @@ public void testHTMLFile() throws Exception {
9594
@Test
9695
public void testYAMLFile() throws Exception {
9796
final IFile file = project.getFile("blah.yaml");
98-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
97+
file.create("FAIL".getBytes(), true, false, null);
9998
ITextEditor editor = (ITextEditor) IDE
10099
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
101100
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("hello: '");
@@ -111,7 +110,7 @@ public void testYAMLFile() throws Exception {
111110
@Test
112111
public void testJSONFile() throws Exception {
113112
final IFile file = project.getFile("blah.json");
114-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
113+
file.create("FAIL".getBytes(), true, false, null);
115114
ITextEditor editor = (ITextEditor) IDE
116115
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
117116
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("ERROR");
@@ -127,7 +126,7 @@ public void testJSONFile() throws Exception {
127126
@Test
128127
public void testJSFile() throws Exception {
129128
final IFile file = project.getFile("blah.js");
130-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
129+
file.create("ERROR".getBytes(), true, false, null);
131130
ITextEditor editor = (ITextEditor) IDE
132131
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
133132
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 {
145144
@Test
146145
public void testTSFile() throws Exception {
147146
final IFile file = project.getFile("blah.ts");
148-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
147+
file.create("ERROR".getBytes(), true, false, null);
149148
ITextEditor editor = (ITextEditor) IDE
150149
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
151150
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
@@ -161,7 +160,7 @@ public void testTSFile() throws Exception {
161160
@Test
162161
public void testJSXFile() throws Exception {
163162
final IFile file = project.getFile("blah.jsx");
164-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
163+
file.create("ERROR".getBytes(), true, false, null);
165164
ITextEditor editor = (ITextEditor) IDE
166165
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
167166
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
@@ -177,7 +176,7 @@ public void testJSXFile() throws Exception {
177176
@Test
178177
public void testTSXFile() throws Exception {
179178
final IFile file = project.getFile("blah.tsx");
180-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
179+
file.create("ERROR".getBytes(), true, false, null);
181180
ITextEditor editor = (ITextEditor) IDE
182181
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
183182
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
@@ -272,7 +271,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
272271
@Test
273272
public void testSCSSFile() throws Exception {
274273
final IFile file = project.getFile("blah.scss");
275-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
274+
file.create("ERROR".getBytes(), true, false, null);
276275
ITextEditor editor = (ITextEditor) IDE
277276
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
278277
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
@@ -288,7 +287,7 @@ public void testSCSSFile() throws Exception {
288287
@Test
289288
public void testLESSFile() throws Exception {
290289
final IFile file = project.getFile("blah.less");
291-
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
290+
file.create("ERROR".getBytes(), true, false, null);
292291
ITextEditor editor = (ITextEditor) IDE
293292
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
294293
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestSyntaxHighlighting.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

17-
import java.io.ByteArrayInputStream;
1817
import java.util.Arrays;
1918

2019
import org.eclipse.core.resources.IFile;
@@ -47,7 +46,7 @@ public void initializeHostProject() throws CoreException {
4746
@Test
4847
public void testJSXHighlighting() throws CoreException {
4948
IFile file = project.getFile("test.jsx");
50-
file.create(new ByteArrayInputStream("var n = 4;\n".getBytes()), true, null);
49+
file.create("var n = 4;\n".getBytes(), true, false, null);
5150
ITextEditor editor = (ITextEditor) IDE
5251
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
5352
StyledText widget = (StyledText) editor.getAdapter(Control.class);

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestXML.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.junit.jupiter.api.Assertions.assertNotNull;
1818
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

20-
import java.io.ByteArrayInputStream;
2120
import java.io.File;
2221
import java.io.FileOutputStream;
2322
import java.io.PrintWriter;
@@ -75,7 +74,7 @@ public void setUpProject() throws CoreException {
7574
@Test
7675
public void testXMLFile() throws Exception {
7776
final IFile file = project.getFile("blah.xml");
78-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
77+
file.create("FAIL".getBytes(), true, false, null);
7978
ITextEditor editor = (ITextEditor) IDE
8079
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
8180
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<plugin></");
@@ -91,7 +90,7 @@ public void testXMLFile() throws Exception {
9190
@Test
9291
public void testXSLFile() throws Exception {
9392
final IFile file = project.getFile("blah.xsl");
94-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
93+
file.create("FAIL".getBytes(), true, false, null);
9594
ITextEditor editor = (ITextEditor) IDE
9695
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
9796
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
@@ -107,7 +106,7 @@ public void testXSLFile() throws Exception {
107106
@Test
108107
public void testXSDFile() throws Exception {
109108
final IFile file = project.getFile("blah.xsd");
110-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
109+
file.create("FAIL".getBytes(), true, false, null);
111110
ITextEditor editor = (ITextEditor) IDE
112111
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
113112
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
@@ -123,7 +122,7 @@ public void testXSDFile() throws Exception {
123122
@Test
124123
public void testDTDFile() throws Exception {
125124
final IFile file = project.getFile("blah.dtd");
126-
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
125+
file.create("FAIL".getBytes(), true, false, null);
127126
ITextEditor editor = (ITextEditor) IDE
128127
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
129128
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<!--<!-- -->");
@@ -144,7 +143,7 @@ public void testComplexXML() throws Exception {
144143
+ " xmlns:layout=\"sap.ui.layout\">\n" + " |\n" + "</layout:BlockLayoutCell>";
145144
int offset = content.indexOf('|');
146145
content = content.replace("|", "");
147-
file.create(new ByteArrayInputStream(content.getBytes()), true, null);
146+
file.create(content.getBytes(), true, false, null);
148147
AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor(
149148
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file,
150149
"org.eclipse.ui.genericeditor.GenericEditor");
@@ -158,7 +157,7 @@ public void testComplexXML() throws Exception {
158157
@Test
159158
public void autoCloseTags() throws Exception {
160159
final IFile file = project.getFile("autoCloseTags.xml");
161-
file.create(new ByteArrayInputStream("<foo".getBytes()), true, null);
160+
file.create("<foo".getBytes(), true, false, null);
162161
ITextEditor editor = (ITextEditor) IDE
163162
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
164163
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestYaml.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static org.junit.jupiter.api.Assertions.assertFalse;
1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

17-
import java.io.ByteArrayInputStream;
1817
import java.util.Arrays;
1918
import java.util.stream.Collectors;
2019

@@ -43,7 +42,7 @@ public void testFalseDetectionAsKubernetes() throws Exception {
4342
p.create(new NullProgressMonitor());
4443
p.open(new NullProgressMonitor());
4544
IFile file = p.getFile("blah.yaml");
46-
file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
45+
file.create(new byte[0], true, false, new NullProgressMonitor());
4746
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
4847
ITextEditor editor = (ITextEditor) IDE.openEditor(activePage, file, true);
4948
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
@@ -65,7 +64,7 @@ private void testErrorFile(String name) throws Exception {
6564
p.create(new NullProgressMonitor());
6665
p.open(new NullProgressMonitor());
6766
IFile file = p.getFile(name);
68-
file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
67+
file.create(new byte[0], true, false, new NullProgressMonitor());
6968
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
7069
ITextEditor editor = (ITextEditor) IDE.openEditor(activePage, file, true);
7170
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/VSCodeJSDebugDelegate.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.eclipse.wildwebdeveloper.debug.node;
1515

1616
import java.io.BufferedReader;
17-
import java.io.ByteArrayInputStream;
1817
import java.io.File;
1918
import java.io.FileReader;
2019
import java.io.IOException;
@@ -349,12 +348,12 @@ private IFile createNewEmptyFile(File fsFile) {
349348
try {
350349
ws.run((IWorkspaceRunnable) monitor -> {
351350
result[0] = null;
352-
try (ByteArrayInputStream is = new ByteArrayInputStream(new byte[0])) {
351+
try {
353352
createContainers(file);
354-
file.create(is, true, null);
353+
file.create(new byte[0], true, false, null);
355354
file.refreshLocal(IResource.DEPTH_ZERO, null);
356355
result[0] = file;
357-
} catch (CoreException | IOException e) {
356+
} catch (CoreException e) {
358357
ILog.get().error(e.getMessage(), e);
359358
}
360359
}, null);

0 commit comments

Comments
 (0)