Skip to content

Use IFile.create method taking byte array for content #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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("<style\n<html><");
Expand All @@ -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("<html><body><a></a></body></html>".getBytes()), true, null);
file.create("<html><body><a></a></body></html>".getBytes(), true, false, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.setFocus();
Expand Down Expand Up @@ -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("<foo".getBytes()), true, null);
file.create("<foo".getBytes(), true, false, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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

import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -101,7 +100,7 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
String newContent = content.replaceAll(oldName, newName);

int offset = content.indexOf(oldName);
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void setUpProject() throws Exception {
@Test
public void testCSSFile() throws Exception {
final IFile file = project.getFile("blah.css");
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");
Expand All @@ -79,7 +78,7 @@ public void testCSSFile() throws Exception {
@Test
public void testHTMLFile() throws Exception {
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("<style\n<html><");
Expand All @@ -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: '");
Expand All @@ -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");
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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<");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("<plugin></");
Expand All @@ -91,7 +90,7 @@ public void testXMLFile() throws Exception {
@Test
public void testXSLFile() throws Exception {
final IFile file = project.getFile("blah.xsl");
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("FAIL");
Expand All @@ -107,7 +106,7 @@ public void testXSLFile() throws Exception {
@Test
public void testXSDFile() throws Exception {
final IFile file = project.getFile("blah.xsd");
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("a<");
Expand All @@ -123,7 +122,7 @@ public void testXSDFile() throws Exception {
@Test
public void testDTDFile() throws Exception {
final IFile file = project.getFile("blah.dtd");
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("<!--<!-- -->");
Expand All @@ -144,7 +143,7 @@ public void testComplexXML() throws Exception {
+ " xmlns:layout=\"sap.ui.layout\">\n" + " |\n" + "</layout:BlockLayoutCell>";
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");
Expand All @@ -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("<foo".getBytes()), true, null);
file.create("<foo".getBytes(), true, false, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -43,7 +42,7 @@ public void testFalseDetectionAsKubernetes() throws Exception {
p.create(new NullProgressMonitor());
p.open(new NullProgressMonitor());
IFile file = p.getFile("blah.yaml");
file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
file.create(new byte[0], true, false, new NullProgressMonitor());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor) IDE.openEditor(activePage, file, true);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Expand All @@ -65,7 +64,7 @@ private void testErrorFile(String name) throws Exception {
p.create(new NullProgressMonitor());
p.open(new NullProgressMonitor());
IFile file = p.getFile(name);
file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
file.create(new byte[0], true, false, new NullProgressMonitor());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor) IDE.openEditor(activePage, file, true);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.wildwebdeveloper.debug.node;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
Expand Down Expand Up @@ -349,12 +348,12 @@ private IFile createNewEmptyFile(File fsFile) {
try {
ws.run((IWorkspaceRunnable) monitor -> {
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);
Expand Down
Loading