prefer List instead of vararg array

This commit is contained in:
Vladimir Krivosheev
2019-01-02 17:53:10 +01:00
parent 7d98f8bd6a
commit 6335fc265e
42 changed files with 140 additions and 272 deletions
@@ -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-2019 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.compiler.actions;
import com.intellij.compiler.CompilerConfiguration;
@@ -266,14 +252,14 @@ public class GenerateAntBuildAction extends CompileActionBase {
}
}
final ReadonlyStatusHandler.OperationStatus status =
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(VfsUtil.toVirtualFileArray(toCheck));
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(toCheck);
if (status.hasReadonlyFiles()) {
throw new IOException(status.getReadonlyFilesMessage());
}
}
public File[] generateMultipleFileBuild(Project project, GenerationOptions genOptions, List<? super File> filesToRefresh) throws IOException {
final File projectBuildFileDestDir = VfsUtil.virtualToIoFile(project.getBaseDir());
final File projectBuildFileDestDir = VfsUtilCore.virtualToIoFile(project.getBaseDir());
projectBuildFileDestDir.mkdirs();
final List<File> generated = new ArrayList<>();
final File projectBuildFile = new File(projectBuildFileDestDir, genOptions.getBuildFileName());
@@ -1,4 +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.
// Copyright 2000-2019 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.codeInsight;
import com.google.common.annotations.VisibleForTesting;
@@ -496,7 +496,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
}
@Override
public void elementRenamedOrMoved(@NotNull PsiModifierListOwner element, @NotNull String oldExternalName) {
public void elementRenamedOrMoved(@NotNull PsiModifierListOwner element, @NotNull String oldExternalName) {
ApplicationManager.getApplication().assertIsDispatchThread();
try {
final List<XmlFile> files = findExternalAnnotationsXmlFiles(element);
@@ -541,7 +541,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
}
}
@Override
public boolean editExternalAnnotation(@NotNull PsiModifierListOwner listOwner,
@NotNull final String annotationFQN,
@@ -569,7 +569,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
continue;
}
if (ReadonlyStatusHandler.getInstance(myPsiManager.getProject())
.ensureFilesWritable(file.getVirtualFile()).hasReadonlyFiles()) {
.ensureFilesWritable(Collections.singletonList(file.getVirtualFile())).hasReadonlyFiles()) {
continue;
}
final XmlDocument document = file.getDocument();
@@ -1,4 +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.
// Copyright 2000-2019 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.ide.hierarchy.method;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
@@ -11,7 +11,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.psi.*;
@@ -50,7 +49,7 @@ abstract class OverrideImplementMethodAction extends AnAction {
}
}
}
final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(VfsUtil.toVirtualFileArray(files));
final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
if (!status.hasReadonlyFiles()) {
for (HierarchyNodeDescriptor selectedDescriptor : selectedDescriptors) {
final PsiElement aClass = ((MethodHierarchyNodeDescriptor)selectedDescriptor).getPsiClass();
@@ -1,19 +1,5 @@
/*
* Copyright 2000-2009 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-2019 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.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtil;
@@ -30,6 +16,8 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.refactoring.util.InlineUtil;
import com.intellij.refactoring.util.RefactoringUtil;
import java.util.Collections;
class InlineMethodHandler extends JavaInlineActionHandler {
private static final String REFACTORING_NAME = RefactoringBundle.message("inline.method.title");
@@ -130,7 +118,7 @@ class InlineMethodHandler extends JavaInlineActionHandler {
final boolean invokedOnReference = reference != null;
if (!invokedOnReference) {
final VirtualFile vFile = method.getContainingFile().getVirtualFile();
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(vFile);
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(vFile));
}
PsiJavaCodeReferenceElement refElement = null;
@@ -1,4 +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.
// Copyright 2000-2019 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.refactoring.typeMigration.ui;
import com.intellij.CommonBundle;
@@ -16,7 +16,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Splitter;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
@@ -191,7 +190,7 @@ public class MigrationPanel extends JPanel implements Disposable {
ApplicationManager.getApplication().invokeLater(() -> {
if (ReadonlyStatusHandler.getInstance(myProject).
ensureFilesWritable(VfsUtilCore.toVirtualFileArray(files)).hasReadonlyFiles()) {
ensureFilesWritable(files).hasReadonlyFiles()) {
return;
}
WriteCommandAction.writeCommandAction(myProject).run(() -> {
@@ -8,12 +8,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class ClsElementWritingAccessProvider extends WritingAccessProvider {
@NotNull
@Override
public Collection<VirtualFile> requestWriting(@NotNull List<VirtualFile> files) {
public Collection<VirtualFile> requestWriting(@NotNull Collection<VirtualFile> files) {
return Collections.emptyList();
}
@@ -1,4 +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.
// Copyright 2000-2019 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.configurationStore
import com.intellij.ide.highlighter.ProjectFileType
@@ -33,6 +33,7 @@ import com.intellij.util.PathUtilRt
import com.intellij.util.SmartList
import com.intellij.util.containers.computeIfAny
import com.intellij.util.containers.isNullOrEmpty
import com.intellij.util.containers.mapSmart
import com.intellij.util.io.*
import com.intellij.util.lang.CompoundRuntimeException
import com.intellij.util.text.nullize
@@ -326,9 +327,9 @@ private open class ProjectStoreImpl(project: Project, private val pathMacroManag
throw IComponentStore.SaveCancelledException()
}
val status = runReadAction { ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(*getFilesList(readonlyFiles)) }
val status = runReadAction { ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(getFilesList(readonlyFiles)) }
if (status.hasReadonlyFiles()) {
dropUnableToSaveProjectNotification(project, status.readonlyFiles)
dropUnableToSaveProjectNotification(project, status.readonlyFiles.toList())
throw IComponentStore.SaveCancelledException()
}
@@ -350,7 +351,7 @@ private open class ProjectStoreImpl(project: Project, private val pathMacroManag
}
}
private fun dropUnableToSaveProjectNotification(project: Project, readOnlyFiles: Array<VirtualFile>) {
private fun dropUnableToSaveProjectNotification(project: Project, readOnlyFiles: List<VirtualFile>) {
val notifications = NotificationsManager.getNotificationsManager().getNotificationsOfType(UnableToSaveProjectNotification::class.java, project)
if (notifications.isEmpty()) {
Notifications.Bus.notify(UnableToSaveProjectNotification(project, readOnlyFiles), project)
@@ -360,7 +361,7 @@ private fun dropUnableToSaveProjectNotification(project: Project, readOnlyFiles:
}
}
private fun getFilesList(readonlyFiles: List<SaveSessionAndFile>) = Array(readonlyFiles.size) { readonlyFiles[it].file }
private fun getFilesList(readonlyFiles: List<SaveSessionAndFile>) = readonlyFiles.mapSmart { it.file }
private class ProjectWithModulesStoreImpl(project: Project, pathMacroManager: PathMacroManager) : ProjectStoreImpl(project, pathMacroManager) {
override fun beforeSave(readonlyFiles: MutableList<SaveSessionAndFile>) {
@@ -20,7 +20,7 @@ public abstract class WritingAccessProvider {
* @return set of files that cannot be accessed
*/
@NotNull
public Collection<VirtualFile> requestWriting(@NotNull List<VirtualFile> files) {
public Collection<VirtualFile> requestWriting(@NotNull Collection<VirtualFile> files) {
//noinspection deprecation
return requestWriting(files.toArray(VirtualFile.EMPTY_ARRAY));
}
@@ -1,4 +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.
// Copyright 2000-2019 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.diff.util;
import com.intellij.application.options.CodeStyle;
@@ -1430,7 +1430,7 @@ public class DiffUtil {
@CalledInAwt
public static boolean makeWritable(@Nullable Project project, @NotNull VirtualFile file) {
if (project == null) project = ProjectManager.getInstance().getDefaultProject();
return !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file).hasReadonlyFiles();
return !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(file)).hasReadonlyFiles();
}
public static void putNonundoableOperation(@Nullable Project project, @NotNull Document document) {
@@ -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-2019 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.refactoring.util;
import com.intellij.codeInsight.hint.HintManager;
@@ -97,7 +83,7 @@ public class CommonRefactoringUtil {
public static boolean checkReadOnlyStatus(@NotNull PsiElement element) {
final VirtualFile file = element.getContainingFile().getVirtualFile();
return file != null && !ReadonlyStatusHandler.getInstance(element.getProject()).ensureFilesWritable(file).hasReadonlyFiles();
return file != null && !ReadonlyStatusHandler.getInstance(element.getProject()).ensureFilesWritable(Collections.singletonList(file)).hasReadonlyFiles();
}
public static boolean checkReadOnlyStatus(@NotNull Project project, @NotNull PsiElement element) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2009 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-2019 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.codeInsight;
@@ -24,7 +10,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -85,8 +70,7 @@ public class CodeInsightUtilBase extends CodeInsightUtilCore {
files.add(virtualFile);
}
if (!files.isEmpty()) {
VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(virtualFiles);
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
return !status.hasReadonlyFiles();
}
return true;
@@ -97,7 +81,7 @@ public class CodeInsightUtilBase extends CodeInsightUtilCore {
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
return !status.hasReadonlyFiles();
}
// returns true on success
@Deprecated
public static boolean prepareEditorForWrite(@NotNull Editor editor) {
@@ -1,4 +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.
// Copyright 2000-2019 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.codeInsight.actions;
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.util.Arrays;
public class OptimizeImportsAction extends AnAction {
private static final @NonNls String HELP_ID = "editing.manageImports";
@@ -58,7 +59,8 @@ public class OptimizeImportsAction extends AnAction {
dir = file.getContainingDirectory();
}
else if (files != null && ReformatCodeAction.containsAtLeastOneFile(files)) {
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(
Arrays.asList(files));
if (!operationStatus.hasReadonlyFiles()) {
new OptimizeImportsProcessor(project, ReformatCodeAction.convertToPsiFiles(files, project), null).run();
}
@@ -217,19 +219,19 @@ public class OptimizeImportsAction extends AnAction {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return myProcessVcsChangedFilesInTests;
}
OptimizeImportsDialog dialog = new OptimizeImportsDialog(project, text, hasChanges);
if (!dialog.showAndGet()) {
return null;
}
return dialog.isProcessOnlyVcsChangedFiles();
}
@TestOnly
protected static void setProcessVcsChangedFilesInTests(boolean value) {
myProcessVcsChangedFilesInTests = value;
}
}
private static class OptimizeImportsDialog extends DialogWrapper {
private final boolean myContextHasChanges;
@@ -1,4 +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.
// Copyright 2000-2019 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.codeInsight.actions;
@@ -24,7 +24,6 @@ import com.intellij.psi.*;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -36,7 +35,6 @@ import java.util.regex.PatternSyntaxException;
public class ReformatCodeAction extends AnAction implements DumbAware {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.actions.ReformatCodeAction");
private static final @NonNls String HELP_ID = "editing.codeReformatting";
protected static ReformatFilesOptions myTestOptions;
public ReformatCodeAction() {
@@ -55,7 +53,7 @@ public class ReformatCodeAction extends AnAction implements DumbAware {
final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
PsiFile file = null;
PsiDirectory dir = null;
PsiDirectory dir;
boolean hasSelection = false;
if (editor != null){
@@ -65,7 +63,7 @@ public class ReformatCodeAction extends AnAction implements DumbAware {
hasSelection = editor.getSelectionModel().hasSelection();
}
else if (containsAtLeastOneFile(files)) {
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Arrays.asList(files));
if (!operationStatus.hasReadonlyFiles()) {
ReformatFilesOptions selectedFlags = getReformatFilesOptions(project, files);
if (selectedFlags == null)
@@ -1,4 +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.
// Copyright 2000-2019 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.codeInsight.template.impl;
import com.intellij.codeInsight.template.TemplateManager;
@@ -15,6 +15,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Set;
/**
@@ -59,7 +60,7 @@ public class InvokeTemplateAction extends AnAction {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(file);
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(Collections.singletonList(file));
}
CommandProcessor.getInstance().executeCommand(myProject, () -> myEditor.getCaretModel().runForEachCaret(__ -> {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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-2019 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.codeInsight.template.impl;
import com.intellij.codeInsight.template.CustomLiveTemplate;
@@ -28,6 +14,7 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Set;
public class WrapWithCustomTemplateAction extends AnAction {
@@ -55,7 +42,7 @@ public class WrapWithCustomTemplateAction extends AnAction {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(Collections.singletonList(file));
}
String selection = myEditor.getSelectionModel().getSelectedText(true);
@@ -1,4 +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.
// Copyright 2000-2019 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.codeInspection.ex;
@@ -30,7 +30,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
@@ -272,8 +271,7 @@ public class QuickFixAction extends AnAction implements CustomComponentAction {
Set<VirtualFile> readOnlyFiles = getReadOnlyFiles(refElements);
if (!readOnlyFiles.isEmpty()) {
final Project project = refElements[0].getRefManager().getProject();
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(
VfsUtilCore.toVirtualFileArray(readOnlyFiles));
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(readOnlyFiles);
if (operationStatus.hasReadonlyFiles()) return false;
}
return true;
@@ -1,4 +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.
// Copyright 2000-2019 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.find.replaceInProject;
@@ -30,7 +30,6 @@ import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.StatusBar;
@@ -303,7 +302,7 @@ public class ReplaceInProjectManager {
putValue(LONG_DESCRIPTION, KeymapUtil.getKeystrokeText(altEnter));
putValue(SHORT_DESCRIPTION, KeymapUtil.getKeystrokeText(altEnter));
}
@Override
public void actionPerformed(ActionEvent e) {
replaceUsagesUnderCommand(replaceContext, replaceContext.getUsageView().getSelectedUsages());
@@ -551,7 +550,7 @@ public class ReplaceInProjectManager {
}
if (readOnlyFiles != null) {
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(readOnlyFiles));
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(readOnlyFiles);
}
if (hasReadOnlyUsages(selectedUsages)) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 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-2019 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.ide.scratch;
import com.intellij.ide.util.PropertiesComponent;
@@ -45,8 +31,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.*;
import java.util.List;
import java.util.*;
/**
* @author gregsh
@@ -281,7 +267,7 @@ public abstract class LRUPopupBuilder<T> {
@NotNull Language t,
@NotNull VirtualFile[] sortedFiles,
@NotNull PerFileMappings<Language> mappings) throws UnexpectedUndoException {
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(sortedFiles);
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Arrays.asList(sortedFiles));
if (status.hasReadonlyFiles()) return;
final Set<VirtualFile> matchedExtensions = ContainerUtil.newLinkedHashSet();
@@ -1,4 +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.
// Copyright 2000-2019 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.history.integration;
import com.intellij.history.core.LocalHistoryFacade;
@@ -22,7 +22,10 @@ import com.intellij.openapi.util.Clock;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingRegistry;
import com.intellij.openapi.vfs.ex.temp.TempFileSystem;
import com.intellij.openapi.vfs.newvfs.ManagingFS;
@@ -59,7 +62,7 @@ public class IdeaGateway {
return false;
}
}
VersionedFilterData versionedFilterData = getVersionedFilterData();
boolean isInContent = false;
@@ -151,7 +154,7 @@ public class IdeaGateway {
public boolean ensureFilesAreWritable(@NotNull Project p, @NotNull List<VirtualFile> ff) {
ReadonlyStatusHandler h = ReadonlyStatusHandler.getInstance(p);
return !h.ensureFilesWritable(VfsUtilCore.toVirtualFileArray(ff)).hasReadonlyFiles();
return !h.ensureFilesWritable(ff).hasReadonlyFiles();
}
@Nullable
@@ -10,11 +10,10 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public abstract class ReadonlyStatusHandler {
public static boolean ensureFilesWritable(@NotNull Project project, @NotNull VirtualFile... files) {
return !getInstance(project).ensureFilesWritable(files).hasReadonlyFiles();
return !getInstance(project).ensureFilesWritable(Arrays.asList(files)).hasReadonlyFiles();
}
public static boolean ensureDocumentWritable(@NotNull Project project, @NotNull Document document) {
@@ -46,18 +45,16 @@ public abstract class ReadonlyStatusHandler {
}
/**
* @deprecated Use {@link #ensureFilesWritable(List)}
* @deprecated Use {@link #ensureFilesWritable(Collection)}
*/
@Deprecated
@NotNull
public OperationStatus ensureFilesWritable(@NotNull VirtualFile... files) {
return ensureFilesWritable(Arrays.asList(files));
}
public abstract OperationStatus ensureFilesWritable(@NotNull List<VirtualFile> files);
public OperationStatus ensureFilesWritable(@NotNull Collection<VirtualFile> files) {
return ensureFilesWritable(VfsUtilCore.toVirtualFileArray(files));
}
@NotNull
public abstract OperationStatus ensureFilesWritable(@NotNull Collection<VirtualFile> files);
public static ReadonlyStatusHandler getInstance(@NotNull Project project) {
return ServiceManager.getService(project, ReadonlyStatusHandler.class);
@@ -1,4 +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.
// Copyright 2000-2019 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.command.impl;
import com.intellij.CommonBundle;
@@ -14,7 +14,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -107,13 +106,11 @@ abstract class UndoRedo {
Collection<VirtualFile> readOnlyFiles = collectReadOnlyAffectedFiles();
if (!readOnlyFiles.isEmpty()) {
final Project project = myManager.getProject();
final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles);
if (project == null) {
return false;
}
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(readOnlyFiles);
if (operationStatus.hasReadonlyFiles()) {
return false;
}
@@ -209,7 +206,7 @@ abstract class UndoRedo {
private boolean restore(EditorAndState pair, boolean onlyIfDiffers) {
// editor can be invalid if underlying file is deleted during undo (e.g. after undoing scratch file creation)
if (pair == null || myEditor == null || !myEditor.isValid() || !pair.canBeAppliedTo(myEditor)) return false;
// If current editor state isn't equals to remembered state then
// we have to try to restore previous state. But sometime it's
// not possible to restore it. For example, it's not possible to
@@ -57,7 +57,7 @@ public class NonProjectFileWritingAccessProvider extends WritingAccessProvider {
@NotNull
@Override
public Collection<VirtualFile> requestWriting(@NotNull List<VirtualFile> files) {
public Collection<VirtualFile> requestWriting(@NotNull Collection<VirtualFile> files) {
if (isAllAccessAllowed()) return Collections.emptyList();
List<VirtualFile> deniedFiles = new ArrayList<>();
@@ -1,4 +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.
// Copyright 2000-2019 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.project.impl;
import com.intellij.configurationStore.StorageUtilKt;
@@ -872,10 +872,10 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
message.append("\n\nRead-only files:\n");
int count = 0;
VirtualFile[] files = notifications[0].myFiles;
List<VirtualFile> files = notifications[0].myFiles;
for (VirtualFile file : files) {
if (count == 10) {
message.append('\n').append("and ").append(files.length - count).append(" more").append('\n');
message.append('\n').append("and ").append(files.size() - count).append(" more").append('\n');
}
else {
message.append(file.getPath()).append('\n');
@@ -887,9 +887,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
public static class UnableToSaveProjectNotification extends Notification {
private Project myProject;
public VirtualFile[] myFiles;
public List<VirtualFile> myFiles;
public UnableToSaveProjectNotification(@NotNull final Project project, @NotNull VirtualFile[] readOnlyFiles) {
public UnableToSaveProjectNotification(@NotNull final Project project, @NotNull List<VirtualFile> readOnlyFiles) {
super("Project Settings", "Could not save project", "Unable to save project files. Please ensure project files are writable and you have permissions to modify them." +
" <a href=\"\">Try to save project again</a>.", NotificationType.ERROR,
(notification, event) -> {
@@ -58,8 +58,9 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
myState = state;
}
@NotNull
@Override
public OperationStatus ensureFilesWritable(@NotNull List<VirtualFile> files) {
public OperationStatus ensureFilesWritable(@NotNull Collection<VirtualFile> files) {
if (files.isEmpty()) {
return new OperationStatusImpl(VirtualFile.EMPTY_ARRAY);
}
@@ -129,7 +130,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
}
}
private static OperationStatus createResultStatus(@NotNull List<VirtualFile> files) {
private static OperationStatus createResultStatus(@NotNull Collection<VirtualFile> files) {
List<VirtualFile> readOnlyFiles = new ArrayList<>();
for (VirtualFile file : files) {
if (file.exists()) {
@@ -143,7 +144,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
}
@NotNull
private List<FileInfo> createFileInfos(@NotNull List<VirtualFile> files) {
private List<FileInfo> createFileInfos(@NotNull Collection<VirtualFile> files) {
List<FileInfo> fileInfos = new ArrayList<>();
for (final VirtualFile file : files) {
if (file != null && !file.isWritable() && file.isInLocalFileSystem()) {
@@ -307,7 +307,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
PlatformTestUtil.registerExtension(Extensions.getArea(getProject()), WritingAccessProvider.EP_NAME, new WritingAccessProvider() {
@NotNull
@Override
public Collection<VirtualFile> requestWriting(@NotNull List<VirtualFile> files) {
public Collection<VirtualFile> requestWriting(@NotNull Collection<VirtualFile> files) {
requested.addAll(files);
HashSet<VirtualFile> denied = new HashSet<>(Arrays.asList(filesToDeny));
denied.retainAll(files);
@@ -1,4 +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.
// Copyright 2000-2019 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.usages.impl;
import com.intellij.concurrency.JobSchedulerImpl;
@@ -24,7 +24,6 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.ui.Splitter;
import com.intellij.openapi.util.*;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
@@ -1584,7 +1583,7 @@ public class UsageViewImpl implements UsageViewEx {
final Set<VirtualFile> readOnlyUsages = getReadOnlyUsagesFiles();
return readOnlyUsages.isEmpty() ||
!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(readOnlyUsages)).hasReadonlyFiles();
!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(readOnlyUsages).hasReadonlyFiles();
}
@NotNull
@@ -10,7 +10,10 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.WritingAccessProvider;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
/**
* @author Dmitry Avdeev
@@ -26,7 +29,7 @@ public class ChangelistConflictAccessProvider extends WritingAccessProvider {
@NotNull
@Override
public Collection<VirtualFile> requestWriting(@NotNull List<VirtualFile> files) {
public Collection<VirtualFile> requestWriting(@NotNull Collection<VirtualFile> files) {
ChangelistConflictTracker.Options options = myManager.getConflictTracker().getOptions();
if (!options.SHOW_DIALOG) {
return Collections.emptyList();
@@ -1,4 +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.
// Copyright 2000-2019 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.vcs.history.actions;
import com.intellij.history.LocalHistory;
@@ -38,6 +38,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Collections;
public class GetVersionAction extends AnAction implements DumbAware {
private static final Logger LOG = Logger.getInstance(GetVersionAction.class);
@@ -184,7 +185,7 @@ public class GetVersionAction extends AnAction implements DumbAware {
ApplicationManager.getApplication().invokeLater(() -> {
try {
if (myFile != null && !myFile.isWritable() &&
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(myFile).hasReadonlyFiles()) {
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(Collections.singletonList(myFile)).hasReadonlyFiles()) {
return;
}
@@ -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-2019 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.maddyhome.idea.copyright.actions;
@@ -44,7 +30,6 @@ import java.util.List;
public abstract class AbstractFileProcessor {
private final Project myProject;
private final Module myModule;
private final PsiDirectory directory = null;
private PsiFile file = null;
private PsiFile[] files = null;
private final String message;
@@ -69,10 +54,7 @@ public abstract class AbstractFileProcessor {
}
public void run() {
if (directory != null) {
process(directory, false);
}
else if (files != null) {
if (files != null) {
process(files);
}
else if (file != null) {
@@ -189,12 +171,6 @@ public abstract class AbstractFileProcessor {
});
}
private void process(final PsiDirectory dir, final boolean subdirs) {
final List<PsiFile> pfiles = new ArrayList<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> findFiles(pfiles, dir, subdirs), title, true, myProject);
handleFiles(pfiles);
}
private void process(final Project project) {
final List<PsiFile> pfiles = new ArrayList<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> findFiles(project, pfiles), title, true, project);
@@ -236,8 +212,11 @@ public abstract class AbstractFileProcessor {
}
private void handleFiles(final List<PsiFile> files) {
final VirtualFile[] vFiles = files.stream().map(PsiFile::getVirtualFile).toArray(VirtualFile[]::new);
if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(vFiles).hasReadonlyFiles()) {
List<VirtualFile> list = new ArrayList<>();
for (PsiFile psiFile : files) {
list.add(psiFile.getVirtualFile());
}
if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(list).hasReadonlyFiles()) {
if (!files.isEmpty()) {
final Runnable[] resultRunnable = new Runnable[1];
execute(() -> resultRunnable[0] = prepareFiles(files), () -> {
@@ -270,9 +249,7 @@ public abstract class AbstractFileProcessor {
ProgressManager.getInstance()
.runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(readAction), title, true,
myProject);
WriteCommandAction.writeCommandAction(myProject).withName(title).run(() -> {
writeAction.run();
});
WriteCommandAction.writeCommandAction(myProject).withName(title).run(() -> writeAction.run());
}
private static final Logger logger = Logger.getInstance(AbstractFileProcessor.class.getName());
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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-2019 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.cvsSupport2.actions.merge;
import com.intellij.cvsSupport2.actions.actionVisibility.CvsActionVisibility;
@@ -63,8 +49,7 @@ public class MergeAction extends AnAction {
final VirtualFile[] files = context.getSelectedFiles();
if (files.length == 0) return;
final Project project = context.getProject();
final ReadonlyStatusHandler.OperationStatus operationStatus =
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Arrays.asList(files));
if (operationStatus.hasReadonlyFiles()) {
return;
}
@@ -1,4 +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.
// Copyright 2000-2019 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 org.jetbrains.idea.devkit.build;
import com.intellij.compiler.server.CompileServerPlugin;
@@ -201,7 +201,7 @@ public class PrepareToDeployAction extends AnAction {
return true;
}
final VirtualFile vfile = VfsUtil.findFileByURL(url);
return vfile == null || !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(vfile).hasReadonlyFiles();
return vfile == null || !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(vfile)).hasReadonlyFiles();
}
private static FileFilter createFilter(final ProgressIndicator progressIndicator, @Nullable final FileTypeManager fileTypeManager) {
@@ -1,4 +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.
// Copyright 2000-2019 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 org.jetbrains.idea.devkit.inspections.quickfix;
import com.intellij.codeInspection.LocalQuickFix;
@@ -7,7 +7,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.SmartPsiElementPointer;
@@ -16,6 +15,8 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
import java.util.Collections;
abstract class BaseFix implements LocalQuickFix {
protected final SmartPsiElementPointer<? extends PsiElement> myPointer;
protected final boolean myOnTheFly;
@@ -36,8 +37,7 @@ abstract class BaseFix implements LocalQuickFix {
if (external) {
PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
VirtualFile[] files = new VirtualFile[]{element.getContainingFile().getVirtualFile()};
ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);
ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(Collections.singletonList(element.getContainingFile().getVirtualFile()));
if (status.hasReadonlyFiles()) {
String className = clazz != null ? clazz.getQualifiedName() : element.getContainingFile().getName();
@@ -1,4 +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.
// Copyright 2000-2019 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 org.jetbrains.idea.devkit.util;
import com.intellij.openapi.application.WriteAction;
@@ -57,7 +57,7 @@ public final class DescriptorUtil {
VirtualFile file = pluginXml.getVirtualFile();
final ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(file);
final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(Collections.singletonList(file));
if (status.hasReadonlyFiles()) {
throw new IncorrectOperationException(DevKitBundle.message("error.plugin.xml.readonly", status.getReadonlyFiles()[0]));
}
@@ -1,4 +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.
// Copyright 2000-2019 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 org.jetbrains.plugins.javaFX.sceneBuilder;
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
@@ -142,7 +142,7 @@ public class SceneBuilderEditor extends UserDataHolderBase implements FileEditor
ApplicationManager.getApplication().invokeLater(() -> {
if (mySceneBuilder != null) {
if (!myDocument.isWritable() && ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(myFile).hasReadonlyFiles()) {
if (!myDocument.isWritable() && ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(Collections.singletonList(myFile)).hasReadonlyFiles()) {
return;
}
@@ -1,4 +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.
// Copyright 2000-2019 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 org.jetbrains.idea.maven.dom.refactorings.introduce;
import com.intellij.find.FindManager;
@@ -18,7 +18,6 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
@@ -160,7 +159,8 @@ public class IntroducePropertyAction extends BaseRefactoringAction {
showFindUsages(project, propertyName, selectedString, replaceWith, selectedProject);
}
private static VirtualFile[] getFiles(PsiFile file, MavenDomProjectModel model) {
@NotNull
private static List<VirtualFile> getFiles(PsiFile file, MavenDomProjectModel model) {
Set<VirtualFile> virtualFiles = new HashSet<>();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
@@ -173,7 +173,7 @@ public class IntroducePropertyAction extends BaseRefactoringAction {
if (vf != null) virtualFiles.add(vf);
}
return VfsUtilCore.toVirtualFileArray(virtualFiles);
return new ArrayList<>(virtualFiles);
}
private static void createMavenProperty(@NotNull MavenDomProjectModel model,
@@ -1,4 +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.
// Copyright 2000-2019 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.lang.properties.editor;
import com.intellij.icons.AllIcons;
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
/**
* @author Dmitry Batkovich
@@ -74,7 +75,8 @@ class NewPropertyAction extends AnAction {
final ResourceBundle bundle = resourceBundleEditor.getResourceBundle();
final VirtualFile file = bundle.getDefaultPropertiesFile().getVirtualFile();
final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file);
final ReadonlyStatusHandler.OperationStatus status =
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(file));
if (status.hasReadonlyFiles()) {
Messages.showErrorDialog(bundle.getProject(),
String.format("Resource bundle '%s' has read-only default properties file", bundle.getBaseName()),
@@ -1,4 +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.
// Copyright 2000-2019 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.lang.properties.editor;
@@ -82,8 +82,8 @@ import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ResourceBundleEditor extends UserDataHolderBase implements DocumentsEditor {
@@ -411,7 +411,8 @@ public class ResourceBundleEditor extends UserDataHolderBase implements Document
@Override
public void keyTyped(KeyEvent e) {
if (editor.isViewer()) {
editor.setViewer( ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(propertiesFile.getVirtualFile()).hasReadonlyFiles());
editor.setViewer(ReadonlyStatusHandler.getInstance(myProject)
.ensureFilesWritable(Collections.singletonList(propertiesFile.getVirtualFile())).hasReadonlyFiles());
}
}
});
@@ -1,4 +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.
// Copyright 2000-2019 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.uiDesigner.binding;
import com.intellij.codeInsight.daemon.QuickFixBundle;
@@ -12,6 +12,8 @@ import com.intellij.psi.util.ClassUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
/**
* @author Eugene Zhuravlev
*/
@@ -58,7 +60,8 @@ public class ChangeFormComponentTypeFix implements IntentionAction {
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
CommandProcessor.getInstance().executeCommand(file.getProject(), () -> {
final ReadonlyStatusHandler readOnlyHandler = ReadonlyStatusHandler.getInstance(myFormFile.getProject());
final ReadonlyStatusHandler.OperationStatus status = readOnlyHandler.ensureFilesWritable(myFormFile.getVirtualFile());
final ReadonlyStatusHandler.OperationStatus status =
readOnlyHandler.ensureFilesWritable(Collections.singletonList(myFormFile.getVirtualFile()));
if (!status.hasReadonlyFiles()) {
FormReferenceProvider.setGUIComponentType(myFormFile, myFieldName, myComponentTypeToSet);
}
@@ -1,4 +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.
// Copyright 2000-2019 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.uiDesigner.designSurface;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
@@ -76,9 +76,7 @@ import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.*;
/**
* {@code GuiEditor} is a panel with border layout. It has palette at the north,
@@ -451,10 +449,10 @@ public final class GuiEditor extends JPanel implements DesignerEditorPanelFacade
final ReadonlyStatusHandler.OperationStatus status;
if (sourceFileToCheckOut != null) {
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(myFile, sourceFileToCheckOut);
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(Arrays.asList(myFile, sourceFileToCheckOut));
}
else {
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(myFile);
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(Collections.singletonList(myFile));
}
return !status.hasReadonlyFiles();
}
@@ -1,4 +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.
// Copyright 2000-2019 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.uiDesigner.propertyInspector.editors.string;
import com.intellij.CommonBundle;
@@ -151,7 +151,7 @@ public final class StringEditorDialog extends DialogWrapper{
}
}
final ReadonlyStatusHandler.OperationStatus operationStatus =
ReadonlyStatusHandler.getInstance(module.getProject()).ensureFilesWritable(propFile.getVirtualFile());
ReadonlyStatusHandler.getInstance(module.getProject()).ensureFilesWritable(Collections.singletonList(propFile.getVirtualFile()));
if (operationStatus.hasReadonlyFiles()) {
return null;
}
@@ -225,7 +225,7 @@ public final class StringEditorDialog extends DialogWrapper{
public static boolean saveCreatedProperty(final PropertiesFile bundle, final String name, final String value,
final PsiFile formFile) {
final ReadonlyStatusHandler.OperationStatus operationStatus =
ReadonlyStatusHandler.getInstance(bundle.getProject()).ensureFilesWritable(bundle.getVirtualFile());
ReadonlyStatusHandler.getInstance(bundle.getProject()).ensureFilesWritable(Collections.singletonList(bundle.getVirtualFile()));
if (operationStatus.hasReadonlyFiles()) {
return false;
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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-2019 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.codeInsight.template.emmet;
import com.intellij.application.options.emmet.EmmetOptions;
@@ -171,7 +157,7 @@ public class EmmetUpdateTagAction extends BaseCodeInsightAction implements DumbA
@NotNull final Map<String, String> attributes) {
return ()->{
if (tag.isValid()) {
if (!ReadonlyStatusHandler.getInstance(file.getProject()).ensureFilesWritable(file.getVirtualFile()).hasReadonlyFiles()) {
if (!ReadonlyStatusHandler.getInstance(file.getProject()).ensureFilesWritable(Collections.singletonList(file.getVirtualFile())).hasReadonlyFiles()) {
tag.setAttribute(HtmlUtil.CLASS_ATTRIBUTE_NAME, StringUtil.join(classes, " ").trim());
for (Map.Entry<String, String> attribute : attributes.entrySet()) {
@@ -38,6 +38,8 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
public abstract class BaseInspection extends XmlSuppressableInspectionTool {
@Override
@Nls
@@ -148,7 +150,7 @@ public abstract class BaseInspection extends XmlSuppressableInspectionTool {
private static void suppress(PsiFile file, @NotNull PsiElement location, String suppressComment, Function<? super String, String> replace) {
final Project project = file.getProject();
final VirtualFile vfile = file.getVirtualFile();
if (vfile == null || ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(vfile).hasReadonlyFiles()) {
if (vfile == null || ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(vfile)).hasReadonlyFiles()) {
return;
}