mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (dead code; better diagnostic; formatting)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -113,7 +113,6 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
|
||||
@Override
|
||||
public void checkSetName(String name) throws IncorrectOperationException {
|
||||
//CheckUtil.checkIsIdentifier(name);
|
||||
CheckUtil.checkWritable(this);
|
||||
VirtualFile parentFile = myFile.getParent();
|
||||
if (parentFile == null) {
|
||||
@@ -153,7 +152,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiFile[] getFiles() {
|
||||
LOG.assertTrue(myFile.isValid());
|
||||
if (!myFile.isValid()) throw new InvalidVirtualFileAccessException(myFile);
|
||||
VirtualFile[] files = myFile.getChildren();
|
||||
ArrayList<PsiFile> psiFiles = new ArrayList<PsiFile>();
|
||||
for (VirtualFile file : files) {
|
||||
@@ -264,13 +263,13 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return ""; // TODO throw new InsupportedOperationException()
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public char[] textToCharArray() {
|
||||
return ArrayUtil.EMPTY_CHAR_ARRAY; // TODO throw new InsupportedOperationException()
|
||||
return ArrayUtil.EMPTY_CHAR_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,16 +292,11 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
return !(myFile.getFileSystem() instanceof NonPhysicalFileSystem) && !myFile.getFileSystem().getProtocol().equals("temp");
|
||||
}
|
||||
|
||||
/**
|
||||
* @not_implemented
|
||||
*/
|
||||
@Override
|
||||
public PsiElement copy() {
|
||||
LOG.error("not implemented");
|
||||
return null;
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiDirectory createSubdirectory(@NotNull String name) throws IncorrectOperationException {
|
||||
@@ -321,8 +315,6 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
|
||||
@Override
|
||||
public void checkCreateSubdirectory(@NotNull String name) throws IncorrectOperationException {
|
||||
// TODO : another check?
|
||||
//CheckUtil.checkIsIdentifier(name);
|
||||
VirtualFile existingFile = getVirtualFile().findChild(name);
|
||||
if (existingFile != null) {
|
||||
throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl()));
|
||||
@@ -337,7 +329,9 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
|
||||
try {
|
||||
VirtualFile vFile = getVirtualFile().createChildData(myManager, name);
|
||||
return myManager.findFile(vFile);
|
||||
PsiFile psiFile = myManager.findFile(vFile);
|
||||
assert psiFile != null : vFile.getPath();
|
||||
return psiFile;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IncorrectOperationException(e.toString());
|
||||
@@ -357,7 +351,8 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
final VirtualFile parent = getVirtualFile();
|
||||
try {
|
||||
final VirtualFile vFile = originalFile.getVirtualFile();
|
||||
if (vFile == null) throw new IncorrectOperationException("Cannot copy nonphysical file");
|
||||
if (vFile == null) throw new IncorrectOperationException("Cannot copy non-physical file: " + originalFile);
|
||||
|
||||
VirtualFile copyVFile;
|
||||
if (parent.getFileSystem() == vFile.getFileSystem()) {
|
||||
copyVFile = vFile.copy(this, parent, newName);
|
||||
@@ -369,11 +364,10 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
else {
|
||||
copyVFile = VfsUtilCore.copyFile(this, vFile, parent, newName);
|
||||
}
|
||||
LOG.assertTrue(copyVFile != null, "File was not copied: " + vFile);
|
||||
if (copyVFile == null) throw new IncorrectOperationException("File was not copied: " + vFile);
|
||||
|
||||
final PsiFile copyPsi = myManager.findFile(copyVFile);
|
||||
if (copyPsi == null) {
|
||||
LOG.error("Could not find file '" + copyVFile + "' after copying '" + vFile + "'");
|
||||
}
|
||||
if (copyPsi == null) throw new IncorrectOperationException("Could not find file " + copyVFile + " after copying " + vFile);
|
||||
updateAddedFile(copyPsi);
|
||||
return copyPsi;
|
||||
}
|
||||
@@ -405,15 +399,11 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
CheckUtil.checkWritable(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
checkAdd(element);
|
||||
if (element instanceof PsiDirectory) {
|
||||
LOG.error("not implemented");
|
||||
return null;
|
||||
}
|
||||
else if (element instanceof PsiFile) {
|
||||
|
||||
if (element instanceof PsiFile) {
|
||||
PsiFile originalFile = (PsiFile)element;
|
||||
|
||||
try {
|
||||
@@ -451,18 +441,16 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
psiDocumentManager.commitAllDocuments();
|
||||
|
||||
PsiFile newFile = myManager.findFile(newVFile);
|
||||
if (newFile == null) throw new IncorrectOperationException("Could not find file " + newVFile);
|
||||
updateAddedFile(newFile);
|
||||
|
||||
return newFile;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IncorrectOperationException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG.assertTrue(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new IncorrectOperationException(element + " (" + element.getClass() + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -503,30 +491,12 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
@Override
|
||||
public void delete() throws IncorrectOperationException {
|
||||
checkDelete();
|
||||
//PsiDirectory parent = getParentDirectory();
|
||||
|
||||
/*
|
||||
PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(myManager);
|
||||
event.setParent(parent);
|
||||
event.setChild(this);
|
||||
myManager.beforeChildRemoval(event);
|
||||
*/
|
||||
|
||||
try {
|
||||
myFile.delete(myManager);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IncorrectOperationException(e);
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO : allow undo
|
||||
PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
|
||||
treeEvent.setParent(parent);
|
||||
treeEvent.setChild(this);
|
||||
treeEvent.setUndoableAction(null);
|
||||
myManager.childRemoved(treeEvent);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -534,13 +504,9 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
CheckUtil.checkDelete(myFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @not_implemented
|
||||
*/
|
||||
@Override
|
||||
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
|
||||
LOG.error("not implemented");
|
||||
return null;
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -581,4 +547,4 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
|
||||
public void putInfo(@NotNull Map<String, String> info) {
|
||||
info.put("fileName", getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -63,6 +63,17 @@ public class FileWatcher {
|
||||
public boolean isEmpty() {
|
||||
return dirtyPaths.isEmpty() && dirtyPathsRecursive.isEmpty() && dirtyDirectories.isEmpty();
|
||||
}
|
||||
|
||||
private void addDirtyPath(String path) {
|
||||
if (!dirtyPathsRecursive.contains(path)) {
|
||||
dirtyPaths.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void addDirtyPathRecursive(String path) {
|
||||
dirtyPaths.remove(path);
|
||||
dirtyPathsRecursive.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
private final MyFileWatcherNotificationSink myNotificationSink;
|
||||
@@ -119,7 +130,7 @@ public class FileWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
return result != null ? result : Collections.<String>emptyList();
|
||||
return result != null ? result : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,34 +211,23 @@ public class FileWatcher {
|
||||
if (!paths.isEmpty()) {
|
||||
synchronized (myLock) {
|
||||
for (String eachPath : paths) {
|
||||
doAddDirtyPath(eachPath);
|
||||
myDirtyPaths.addDirtyPath(eachPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyOnAnyEvent();
|
||||
}
|
||||
|
||||
private void doAddDirtyPath(String path) {
|
||||
if (!myDirtyPaths.dirtyPathsRecursive.contains(path)) {
|
||||
myDirtyPaths.dirtyPaths.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void doAddDirtyPathRecursive(String path) {
|
||||
myDirtyPaths.dirtyPaths.remove(path);
|
||||
myDirtyPaths.dirtyPathsRecursive.add(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyPathCreatedOrDeleted(@NotNull String path) {
|
||||
Collection<String> paths = myPathMap.getWatchedPaths(path, true, false);
|
||||
if (!paths.isEmpty()) {
|
||||
synchronized (myLock) {
|
||||
for (String p : paths) {
|
||||
doAddDirtyPathRecursive(p);
|
||||
myDirtyPaths.addDirtyPathRecursive(p);
|
||||
String parentPath = new File(p).getParent();
|
||||
if (parentPath != null) {
|
||||
doAddDirtyPath(parentPath);
|
||||
myDirtyPaths.addDirtyPath(parentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public class FileWatcher {
|
||||
if (!paths.isEmpty()) {
|
||||
synchronized (myLock) {
|
||||
for (String each : paths) {
|
||||
doAddDirtyPathRecursive(each);
|
||||
myDirtyPaths.addDirtyPathRecursive(each);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -33,7 +33,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -54,11 +53,9 @@ public class VfsImplUtil {
|
||||
private VfsImplUtil() { }
|
||||
|
||||
@Nullable
|
||||
public static NewVirtualFile findFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) {
|
||||
public static NewVirtualFile findFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull String path) {
|
||||
Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
if (data == null) return null;
|
||||
|
||||
NewVirtualFile file = data.first;
|
||||
for (String pathElement : data.second) {
|
||||
@@ -83,11 +80,9 @@ public class VfsImplUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NewVirtualFile findFileByPathIfCached(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) {
|
||||
public static NewVirtualFile findFileByPathIfCached(@NotNull NewVirtualFileSystem vfs, @NotNull String path) {
|
||||
Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
if (data == null) return null;
|
||||
|
||||
NewVirtualFile file = data.first;
|
||||
for (String pathElement : data.second) {
|
||||
@@ -113,11 +108,9 @@ public class VfsImplUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NewVirtualFile refreshAndFindFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) {
|
||||
public static NewVirtualFile refreshAndFindFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull String path) {
|
||||
Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
if (data == null) return null;
|
||||
|
||||
NewVirtualFile file = data.first;
|
||||
for (String pathElement : data.second) {
|
||||
@@ -324,4 +317,4 @@ public class VfsImplUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -53,7 +53,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindFileByUrl() throws Exception {
|
||||
public void testFindFileByUrl() throws IOException {
|
||||
File file1 = new File(PathManagerEx.getTestDataPath());
|
||||
file1 = new File(file1, "vfs");
|
||||
file1 = new File(file1, "findFileByUrl");
|
||||
@@ -78,6 +78,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase {
|
||||
|
||||
File file3 = new File(file1, "1.txt");
|
||||
file0 = VfsUtil.findFileByURL(file3.toURI().toURL());
|
||||
assertNotNull(file0);
|
||||
String content = VfsUtilCore.loadText(file0);
|
||||
assertNotNull(file0);
|
||||
assertFalse(file0.isDirectory());
|
||||
@@ -85,7 +86,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindRelativeFile() throws Exception {
|
||||
public void testFindRelativeFile() throws IOException {
|
||||
File ioTestDataDir = new File(PathManagerEx.getTestDataPath());
|
||||
VirtualFile testDataDir = LocalFileSystem.getInstance().findFileByIoFile(ioTestDataDir);
|
||||
assertNotNull(testDataDir);
|
||||
@@ -100,7 +101,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelativePath() throws Exception {
|
||||
public void testRelativePath() {
|
||||
File root = new File(PathManagerEx.getTestDataPath());
|
||||
File testRoot = new File(new File(root, "vfs"), "relativePath");
|
||||
VirtualFile vTestRoot = LocalFileSystem.getInstance().findFileByIoFile(testRoot);
|
||||
|
||||
Reference in New Issue
Block a user