mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (typos; formatting)
This commit is contained in:
+24
-26
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.diagnostic;
|
||||
|
||||
import com.intellij.concurrency.JobScheduler;
|
||||
@@ -16,9 +17,8 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* @author ksafonov
|
||||
*/
|
||||
public class IdeFatalErrorsIcon extends JLabel {
|
||||
|
||||
public enum State {UnreadErrors, ReadErrors, NoErrors}
|
||||
class IdeErrorsIcon extends JLabel {
|
||||
enum State {UnreadErrors, ReadErrors, NoErrors}
|
||||
|
||||
private final LayeredIcon myIcon;
|
||||
private final ActionListener myListener;
|
||||
@@ -27,8 +27,8 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
private Future myBlinker;
|
||||
private State myState;
|
||||
|
||||
public IdeFatalErrorsIcon(ActionListener aListener, boolean enableBlink) {
|
||||
myListener = aListener;
|
||||
IdeErrorsIcon(@NotNull ActionListener listener, boolean enableBlink) {
|
||||
myListener = listener;
|
||||
myEnableBlink = enableBlink;
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1));
|
||||
|
||||
@@ -57,7 +57,7 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
setIcon(myIcon);
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
void setState(State state) {
|
||||
myState = state;
|
||||
switch (state) {
|
||||
case UnreadErrors:
|
||||
@@ -66,7 +66,7 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
myIcon.setLayerEnabled(2, false);
|
||||
startBlinker();
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
setToolTipText(IdeMessagePanel.INTERNAL_ERROR_NOTICE);
|
||||
setToolTipText(DiagnosticBundle.message("error.notification.tooltip"));
|
||||
break;
|
||||
|
||||
case ReadErrors:
|
||||
@@ -75,7 +75,7 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
myIcon.setLayerEnabled(1, true);
|
||||
myIcon.setLayerEnabled(2, false);
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
setToolTipText(IdeMessagePanel.INTERNAL_ERROR_NOTICE);
|
||||
setToolTipText(DiagnosticBundle.message("error.notification.tooltip"));
|
||||
break;
|
||||
|
||||
case NoErrors:
|
||||
@@ -89,28 +89,26 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
break;
|
||||
|
||||
default:
|
||||
assert false;
|
||||
throw new IllegalStateException(state.name());
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
private synchronized void startBlinker() {
|
||||
if (myBlinker != null || !myEnableBlink) {
|
||||
return;
|
||||
private synchronized void startBlinker() {
|
||||
if (myEnableBlink && myBlinker == null) {
|
||||
myBlinker = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
|
||||
boolean enabled = false;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
myIcon.setLayerEnabled(0, enabled);
|
||||
myIcon.setLayerEnabled(1, false);
|
||||
myIcon.setLayerEnabled(2, !enabled);
|
||||
repaint();
|
||||
enabled = !enabled;
|
||||
}
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
myBlinker = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
|
||||
boolean enabled = false;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
myIcon.setLayerEnabled(0, enabled);
|
||||
myIcon.setLayerEnabled(1, false);
|
||||
myIcon.setLayerEnabled(2, !enabled);
|
||||
repaint();
|
||||
enabled = !enabled;
|
||||
}
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private synchronized void stopBlinker() {
|
||||
@@ -119,4 +117,4 @@ public class IdeFatalErrorsIcon extends JLabel {
|
||||
myBlinker = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.diagnostic;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -39,35 +25,26 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class IdeMessagePanel extends JPanel implements MessagePoolListener, IconLikeCustomStatusBarWidget {
|
||||
public static final String FATAL_ERROR = "FatalError";
|
||||
private final IdeFatalErrorsIcon myIdeFatal;
|
||||
private Balloon myBalloon;
|
||||
|
||||
static final String INTERNAL_ERROR_NOTICE = DiagnosticBundle.message("error.notification.tooltip");
|
||||
|
||||
private IdeErrorsDialog myDialog;
|
||||
private boolean myOpeningInProgress;
|
||||
private final IdeErrorsIcon myIdeFatal;
|
||||
private final IdeFrame myFrame;
|
||||
private final MessagePool myMessagePool;
|
||||
private boolean myNotificationPopupAlreadyShown = false;
|
||||
|
||||
private Balloon myBalloon;
|
||||
private IdeErrorsDialog myDialog;
|
||||
private boolean myOpeningInProgress;
|
||||
private boolean myNotificationPopupAlreadyShown;
|
||||
|
||||
public IdeMessagePanel(@Nullable IdeFrame frame, @NotNull MessagePool messagePool) {
|
||||
super(new BorderLayout());
|
||||
myIdeFatal = new IdeFatalErrorsIcon(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
openFatals(null);
|
||||
}
|
||||
}, frame != null);
|
||||
|
||||
myIdeFatal = new IdeErrorsIcon(e -> openErrorsDialog(null), frame != null);
|
||||
myIdeFatal.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
add(myIdeFatal, BorderLayout.CENTER);
|
||||
|
||||
myFrame = frame;
|
||||
@@ -97,42 +74,43 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(@NotNull StatusBar statusBar) {
|
||||
}
|
||||
public void install(@NotNull StatusBar statusBar) { }
|
||||
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void openFatals(@Nullable final LogMessage message) {
|
||||
/** @deprecated use {@link #openErrorsDialog(LogMessage)} (to be removed in IDEA 2019) */
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public void openFatals(@Nullable LogMessage message) {
|
||||
openErrorsDialog(message);
|
||||
}
|
||||
|
||||
public void openErrorsDialog(@Nullable LogMessage message) {
|
||||
if (myDialog != null) return;
|
||||
if (myOpeningInProgress) return;
|
||||
myOpeningInProgress = true;
|
||||
|
||||
final Runnable task = new Runnable() {
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isOtherModalWindowActive()) {
|
||||
if (myDialog == null) {
|
||||
EdtExecutorService.getScheduledExecutorInstance().schedule(this, (long)300, TimeUnit.MILLISECONDS);
|
||||
if (!isOtherModalWindowActive()) {
|
||||
try {
|
||||
doOpenErrorsDialog(message);
|
||||
}
|
||||
finally {
|
||||
myOpeningInProgress = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
_openFatals(message);
|
||||
}
|
||||
finally {
|
||||
myOpeningInProgress = false;
|
||||
else if (myDialog == null) {
|
||||
EdtExecutorService.getScheduledExecutorInstance().schedule(this, 300L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
task.run();
|
||||
}.run();
|
||||
}
|
||||
|
||||
private void _openFatals(@Nullable final LogMessage message) {
|
||||
private void doOpenErrorsDialog(@Nullable LogMessage message) {
|
||||
myDialog = new IdeErrorsDialog(myMessagePool, message) {
|
||||
@Override
|
||||
public void doOKAction() {
|
||||
@@ -166,13 +144,13 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState(final IdeFatalErrorsIcon.State state) {
|
||||
private void updateState(IdeErrorsIcon.State state) {
|
||||
myIdeFatal.setState(state);
|
||||
UIUtil.invokeLaterIfNeeded(() -> setVisible(state != IdeFatalErrorsIcon.State.NoErrors));
|
||||
UIUtil.invokeLaterIfNeeded(() -> setVisible(state != IdeErrorsIcon.State.NoErrors));
|
||||
}
|
||||
|
||||
private void disposeDialog(final IdeErrorsDialog listDialog) {
|
||||
myMessagePool.removeListener(listDialog);
|
||||
private void disposeDialog(IdeErrorsDialog dialog) {
|
||||
myMessagePool.removeListener(dialog);
|
||||
updateFatalErrorsIcon();
|
||||
myDialog = null;
|
||||
}
|
||||
@@ -180,7 +158,6 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
@Override
|
||||
public void newEntryAdded() {
|
||||
updateFatalErrorsIcon();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,52 +171,31 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
}
|
||||
|
||||
private boolean isOtherModalWindowActive() {
|
||||
final Window window = getActiveModalWindow();
|
||||
if (window == null) return false;
|
||||
|
||||
return myDialog == null || myDialog.getWindow() != window;
|
||||
|
||||
Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
|
||||
return activeWindow instanceof JDialog &&
|
||||
((JDialog)activeWindow).isModal() &&
|
||||
(myDialog == null || myDialog.getWindow() != activeWindow);
|
||||
}
|
||||
|
||||
private static Window getActiveModalWindow() {
|
||||
final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
final Window activeWindow = manager.getActiveWindow();
|
||||
if (activeWindow instanceof JDialog) {
|
||||
if (((JDialog) activeWindow).isModal()) {
|
||||
return activeWindow;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
private IdeErrorsIcon.State computeState() {
|
||||
List<AbstractMessage> unsent = myMessagePool.getFatalErrors(true, false);
|
||||
if (unsent.isEmpty()) return IdeErrorsIcon.State.NoErrors;
|
||||
if (unsent.stream().allMatch(AbstractMessage::isRead)) return IdeErrorsIcon.State.ReadErrors;
|
||||
return IdeErrorsIcon.State.UnreadErrors;
|
||||
}
|
||||
|
||||
private IdeFatalErrorsIcon.State computeState() {
|
||||
final List<AbstractMessage> errors = myMessagePool.getFatalErrors(true, false);
|
||||
if (errors.isEmpty()) {
|
||||
return IdeFatalErrorsIcon.State.NoErrors;
|
||||
}
|
||||
else {
|
||||
for (AbstractMessage error : errors) {
|
||||
if (!error.isRead()) {
|
||||
return IdeFatalErrorsIcon.State.UnreadErrors;
|
||||
}
|
||||
}
|
||||
return IdeFatalErrorsIcon.State.ReadErrors;
|
||||
}
|
||||
}
|
||||
|
||||
void updateFatalErrorsIcon() {
|
||||
final IdeFatalErrorsIcon.State state = computeState();
|
||||
private void updateFatalErrorsIcon() {
|
||||
IdeErrorsIcon.State state = computeState();
|
||||
updateState(state);
|
||||
|
||||
if (state == IdeFatalErrorsIcon.State.NoErrors) {
|
||||
if (state == IdeErrorsIcon.State.NoErrors) {
|
||||
myNotificationPopupAlreadyShown = false;
|
||||
}
|
||||
else if (state == IdeFatalErrorsIcon.State.UnreadErrors && !myNotificationPopupAlreadyShown) {
|
||||
else if (state == IdeErrorsIcon.State.UnreadErrors && !myNotificationPopupAlreadyShown) {
|
||||
Project project = myFrame == null ? null : myFrame.getProject();
|
||||
if (project != null) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
String notificationText = tryGetFromMessages(myMessagePool.getFatalErrors(false, false));
|
||||
String notificationText = getNotificationText(myMessagePool.getFatalErrors(false, false));
|
||||
showErrorNotification(notificationText, project);
|
||||
}, project.getDisposed());
|
||||
myNotificationPopupAlreadyShown = true;
|
||||
@@ -251,15 +207,16 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
private static final String ERROR_LINK = DiagnosticBundle.message("error.new.notification.link");
|
||||
|
||||
private void showErrorNotification(@Nullable String notificationText, @NotNull Project project) {
|
||||
Notification notification = new Notification("", AllIcons.Ide.FatalError, notificationText == null ? ERROR_TITLE : "", null,
|
||||
notificationText == null ? "" : notificationText, NotificationType.ERROR, null);
|
||||
String title = notificationText == null ? ERROR_TITLE : "";
|
||||
String content = notificationText == null ? "" : notificationText;
|
||||
Notification notification = new Notification("", AllIcons.Ide.FatalError, title, null, content, NotificationType.ERROR, null);
|
||||
|
||||
if (notificationText == null) {
|
||||
notification.addAction(new NotificationAction(ERROR_LINK) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
|
||||
notification.expire();
|
||||
_openFatals(null);
|
||||
doOpenErrorsDialog(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -278,7 +235,7 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
layout.add(myBalloon);
|
||||
}
|
||||
|
||||
private static String tryGetFromMessages(List<AbstractMessage> messages) {
|
||||
private static String getNotificationText(List<AbstractMessage> messages) {
|
||||
String result = null;
|
||||
for (AbstractMessage message : messages) {
|
||||
String s;
|
||||
@@ -286,20 +243,18 @@ public class IdeMessagePanel extends JPanel implements MessagePoolListener, Icon
|
||||
s = ((LogMessageEx)message).getNotificationText();
|
||||
}
|
||||
else if (message instanceof GroupedLogMessage) {
|
||||
s = tryGetFromMessages(((GroupedLogMessage)message).getMessages());
|
||||
s = getNotificationText(((GroupedLogMessage)message).getMessages());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
result = s;
|
||||
}
|
||||
else if (!result.equals(s)) {
|
||||
// if texts are different, show default
|
||||
return null;
|
||||
return null; // if texts are different, show default
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
-56
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.vfs.impl.local;
|
||||
|
||||
import com.intellij.ide.GeneralSettings;
|
||||
@@ -85,37 +85,37 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(@NotNull final VirtualFile file) {
|
||||
public boolean exists(@NotNull VirtualFile file) {
|
||||
return getAttributes(file) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength(@NotNull final VirtualFile file) {
|
||||
final FileAttributes attributes = getAttributes(file);
|
||||
public long getLength(@NotNull VirtualFile file) {
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
return attributes != null ? attributes.length : DEFAULT_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeStamp(@NotNull final VirtualFile file) {
|
||||
final FileAttributes attributes = getAttributes(file);
|
||||
public long getTimeStamp(@NotNull VirtualFile file) {
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
return attributes != null ? attributes.lastModified : DEFAULT_TIMESTAMP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory(@NotNull final VirtualFile file) {
|
||||
final FileAttributes attributes = getAttributes(file);
|
||||
public boolean isDirectory(@NotNull VirtualFile file) {
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
return attributes != null && attributes.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(@NotNull final VirtualFile file) {
|
||||
final FileAttributes attributes = getAttributes(file);
|
||||
public boolean isWritable(@NotNull VirtualFile file) {
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
return attributes != null && attributes.isWritable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSymLink(@NotNull final VirtualFile file) {
|
||||
final FileAttributes attributes = getAttributes(file);
|
||||
public boolean isSymLink(@NotNull VirtualFile file) {
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
return attributes != null && attributes.isSymLink();
|
||||
}
|
||||
|
||||
@@ -126,18 +126,18 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] list(@NotNull final VirtualFile file) {
|
||||
public String[] list(@NotNull VirtualFile file) {
|
||||
if (file.getParent() == null) {
|
||||
final File[] roots = File.listRoots();
|
||||
File[] roots = File.listRoots();
|
||||
if (roots.length == 1 && roots[0].getName().isEmpty()) {
|
||||
final String[] list = roots[0].list();
|
||||
String[] list = roots[0].list();
|
||||
if (list != null) return list;
|
||||
LOG.warn("Root '" + roots[0] + "' has no children - is it readable?");
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
if (file.getName().isEmpty()) {
|
||||
// return drive letter names for the 'fake' root on windows
|
||||
final String[] names = new String[roots.length];
|
||||
String[] names = new String[roots.length];
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
String name = roots[i].getPath();
|
||||
name = StringUtil.trimTrailing(name, File.separatorChar);
|
||||
@@ -147,7 +147,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
final String[] names = convertToIOFile(file).list();
|
||||
String[] names = convertToIOFile(file).list();
|
||||
return names == null ? ArrayUtil.EMPTY_STRING_ARRAY : names;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@Override
|
||||
public void refreshIoFiles(@NotNull Iterable<File> files, boolean async, boolean recursive, @Nullable Runnable onFinish) {
|
||||
final VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance();
|
||||
VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance();
|
||||
|
||||
Application app = ApplicationManager.getApplication();
|
||||
boolean fireCommonRefreshSession = app.isDispatchThread() || app.isWriteAccessAllowed();
|
||||
@@ -227,7 +227,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
List<VirtualFile> filesToRefresh = new ArrayList<>();
|
||||
|
||||
for (File file : files) {
|
||||
final VirtualFile virtualFile = refreshAndFindFileByIoFile(file);
|
||||
VirtualFile virtualFile = refreshAndFindFileByIoFile(file);
|
||||
if (virtualFile != null) {
|
||||
filesToRefresh.add(virtualFile);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processCachedFilesInSubtree(@NotNull final VirtualFile file, @NotNull Processor<VirtualFile> processor) {
|
||||
public boolean processCachedFilesInSubtree(@NotNull VirtualFile file, @NotNull Processor<VirtualFile> processor) {
|
||||
return file.getFileSystem() != this
|
||||
|| processFile((NewVirtualFile)file, processor);
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
private static boolean processFile(@NotNull NewVirtualFile file, @NotNull Processor<VirtualFile> processor) {
|
||||
if (!processor.process(file)) return false;
|
||||
if (file.isDirectory()) {
|
||||
for (final VirtualFile child : file.getCachedChildren()) {
|
||||
for (VirtualFile child : file.getCachedChildren()) {
|
||||
if (!processFile((NewVirtualFile)child, processor)) return false;
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
private boolean auxCopy(@NotNull VirtualFile file, @NotNull VirtualFile toDir, @NotNull String copyName) throws IOException {
|
||||
for (LocalFileOperationsHandler handler : myHandlers) {
|
||||
final File copy = handler.copy(file, toDir, copyName);
|
||||
File copy = handler.copy(file, toDir, copyName);
|
||||
if (copy != null) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -333,7 +333,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile createChildDirectory(Object requestor, @NotNull final VirtualFile parent, @NotNull final String dir) throws IOException {
|
||||
public VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile parent, @NotNull String dir) throws IOException {
|
||||
if (!isValidName(dir)) {
|
||||
throw new IOException(VfsBundle.message("directory.invalid.name.error", dir));
|
||||
}
|
||||
@@ -364,7 +364,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile createChildFile(Object requestor, @NotNull final VirtualFile parent, @NotNull final String file) throws IOException {
|
||||
public VirtualFile createChildFile(Object requestor, @NotNull VirtualFile parent, @NotNull String file) throws IOException {
|
||||
if (!isValidName(file)) {
|
||||
throw new IOException(VfsBundle.message("file.invalid.name.error", file));
|
||||
}
|
||||
@@ -394,7 +394,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(Object requestor, @NotNull final VirtualFile file) throws IOException {
|
||||
public void deleteFile(Object requestor, @NotNull VirtualFile file) throws IOException {
|
||||
if (file.getParent() == null) {
|
||||
throw new IOException(VfsBundle.message("cannot.delete.root.directory", file.getPath()));
|
||||
}
|
||||
@@ -421,17 +421,17 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InputStream getInputStream(@NotNull final VirtualFile file) throws IOException {
|
||||
public InputStream getInputStream(@NotNull VirtualFile file) throws IOException {
|
||||
return new BufferedInputStream(new FileInputStream(convertToIOFileAndCheck(file)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public byte[] contentsToByteArray(@NotNull final VirtualFile file) throws IOException {
|
||||
public byte[] contentsToByteArray(@NotNull VirtualFile file) throws IOException {
|
||||
try (InputStream stream = new FileInputStream(convertToIOFileAndCheck(file))) {
|
||||
long l = file.getLength();
|
||||
if (l >= FileUtilRt.LARGE_FOR_CONTENT_LOADING) throw new FileTooBigException(file.getPath());
|
||||
final int length = (int)l;
|
||||
int length = (int)l;
|
||||
if (length < 0) throw new IOException("Invalid file length: " + length + ", " + file);
|
||||
// io_util.c#readBytes allocates custom native stack buffer for io operation with malloc if io request > 8K
|
||||
// so let's do buffered requests with buffer size 8192 that will use stack allocated buffer
|
||||
@@ -457,11 +457,10 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OutputStream getOutputStream(@NotNull VirtualFile file, Object requestor, long modStamp, final long timeStamp) throws IOException {
|
||||
final File ioFile = convertToIOFileAndCheck(file);
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
final OutputStream stream = shallUseSafeStream(requestor, file) ?
|
||||
new SafeFileOutputStream(ioFile, SystemInfo.isUnix) : new FileOutputStream(ioFile);
|
||||
public OutputStream getOutputStream(@NotNull VirtualFile file, Object requestor, long modStamp, long timeStamp) throws IOException {
|
||||
File ioFile = convertToIOFileAndCheck(file);
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") OutputStream stream =
|
||||
shallUseSafeStream(requestor, file) ? new SafeFileOutputStream(ioFile, SystemInfo.isUnix) : new FileOutputStream(ioFile);
|
||||
return new BufferedOutputStream(stream) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
@@ -475,12 +474,12 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean shallUseSafeStream(final Object requestor, @NotNull VirtualFile file) {
|
||||
private static boolean shallUseSafeStream(Object requestor, @NotNull VirtualFile file) {
|
||||
return requestor instanceof SafeWriteRequestor && GeneralSettings.getInstance().isUseSafeWrite() && !file.is(VFileProperty.SYMLINK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFile(Object requestor, @NotNull final VirtualFile file, @NotNull final VirtualFile newParent) throws IOException {
|
||||
public void moveFile(Object requestor, @NotNull VirtualFile file, @NotNull VirtualFile newParent) throws IOException {
|
||||
String name = file.getName();
|
||||
|
||||
if (!file.exists()) {
|
||||
@@ -519,7 +518,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameFile(Object requestor, @NotNull final VirtualFile file, @NotNull final String newName) throws IOException {
|
||||
public void renameFile(Object requestor, @NotNull VirtualFile file, @NotNull String newName) throws IOException {
|
||||
if (!isValidName(newName)) {
|
||||
throw new IOException(VfsBundle.message("file.invalid.name.error", newName));
|
||||
}
|
||||
@@ -558,9 +557,9 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile copyFile(Object requestor,
|
||||
@NotNull final VirtualFile file,
|
||||
@NotNull final VirtualFile newParent,
|
||||
@NotNull final String copyName) throws IOException {
|
||||
@NotNull VirtualFile file,
|
||||
@NotNull VirtualFile newParent,
|
||||
@NotNull String copyName) throws IOException {
|
||||
if (!isValidName(copyName)) {
|
||||
throw new IOException(VfsBundle.message("file.invalid.name.error", copyName));
|
||||
}
|
||||
@@ -608,8 +607,8 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeStamp(@NotNull final VirtualFile file, final long timeStamp) {
|
||||
final File ioFile = convertToIOFile(file);
|
||||
public void setTimeStamp(@NotNull VirtualFile file, long timeStamp) {
|
||||
File ioFile = convertToIOFile(file);
|
||||
if (ioFile.exists() && !ioFile.setLastModified(timeStamp)) {
|
||||
LOG.warn("Failed: " + file.getPath() + ", new:" + timeStamp + ", old:" + ioFile.lastModified());
|
||||
}
|
||||
@@ -624,21 +623,16 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<String> ourRootPaths = new ArrayList<>();
|
||||
|
||||
private static final List<String> ourRootPaths;
|
||||
static {
|
||||
List<String> persistentFsRoots = StringUtil.split(System.getProperty("idea.persistentfs.roots", ""), File.pathSeparator);
|
||||
sortRootsLongestFirst(persistentFsRoots);
|
||||
ourRootPaths.addAll(persistentFsRoots);
|
||||
}
|
||||
|
||||
private static void sortRootsLongestFirst(List<String> persistentFsRoots) {
|
||||
Collections.sort(persistentFsRoots, (o1, o2) -> o2.length() - o1.length());
|
||||
//noinspection SpellCheckingInspection
|
||||
ourRootPaths = StringUtil.split(System.getProperty("idea.persistentfs.roots", ""), File.pathSeparator);
|
||||
Collections.sort(ourRootPaths, (o1, o2) -> o2.length() - o1.length()); // longest first
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String extractRootPath(@NotNull final String path) {
|
||||
protected String extractRootPath(@NotNull String path) {
|
||||
if (path.isEmpty()) {
|
||||
try {
|
||||
return extractRootPath(new File("").getCanonicalPath());
|
||||
@@ -648,7 +642,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
for(String customRootPath:ourRootPaths) {
|
||||
for (String customRootPath : ourRootPaths) {
|
||||
if (path.startsWith(customRootPath)) return customRootPath;
|
||||
}
|
||||
|
||||
@@ -665,7 +659,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
int slashCount = 0;
|
||||
int idx;
|
||||
for (idx = 2; idx < path.length() && slashCount < 2; idx++) {
|
||||
final char c = path.charAt(idx);
|
||||
char c = path.charAt(idx);
|
||||
if (c == '\\' || c == '/') {
|
||||
slashCount++;
|
||||
idx--;
|
||||
@@ -753,7 +747,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileAttributes getAttributes(@NotNull final VirtualFile file) {
|
||||
public FileAttributes getAttributes(@NotNull VirtualFile file) {
|
||||
String path = normalize(file.getPath());
|
||||
if (path == null) return null;
|
||||
if (file.getParent() == null && path.startsWith("//")) {
|
||||
@@ -763,7 +757,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(final boolean asynchronous) {
|
||||
public void refresh(boolean asynchronous) {
|
||||
RefreshQueue.getInstance().refresh(asynchronous, true, null, ManagingFS.getInstance().getRoots(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -201,7 +201,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase {
|
||||
|
||||
@Test
|
||||
public void testFindRootWithCrazySlashes() {
|
||||
for (int i=0;i<10;i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
String path = StringUtil.repeat("/", i);
|
||||
VirtualFile root = LocalFileSystem.getInstance().findFileByPathIfCached(path);
|
||||
assertTrue(path, root == null || !root.getPath().contains("//"));
|
||||
|
||||
Reference in New Issue
Block a user