This commit is contained in:
Alexey Kudravtsev
2014-02-28 13:34:43 +04:00
parent ed02fc99d8
commit 0b40c676a5
18 changed files with 113 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -184,6 +184,7 @@ public class LightVirtualFile extends VirtualFile {
return myFileType;
}
@NotNull
@Override
public String getPath() {
return "/" + getName();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
@@ -18,11 +18,13 @@ package com.intellij.openapi.vfs.impl.jar;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
/**
* @author yole
@@ -30,10 +32,10 @@ import java.util.ArrayList;
public class CoreJarVirtualFile extends VirtualFile {
private final CoreJarHandler myHandler;
private final VirtualFile myParent;
private final ArrayList<VirtualFile> myChildren = new ArrayList<VirtualFile>();
private final List<VirtualFile> myChildren = new ArrayList<VirtualFile>();
private final JarHandlerBase.EntryInfo myEntry;
public CoreJarVirtualFile(CoreJarHandler handler, JarHandlerBase.EntryInfo entry, CoreJarVirtualFile parent) {
public CoreJarVirtualFile(@NotNull CoreJarHandler handler, @NotNull JarHandlerBase.EntryInfo entry, @Nullable CoreJarVirtualFile parent) {
myHandler = handler;
myParent = parent;
myEntry = entry;
@@ -56,6 +58,7 @@ public class CoreJarVirtualFile extends VirtualFile {
}
@Override
@NotNull
public String getPath() {
if (myParent == null) return myHandler.myBasePath + "!/";
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -52,6 +52,7 @@ public class JarHandlerBase {
protected static class EntryInfo {
protected final boolean isDirectory;
@NotNull
protected final String shortName;
protected final EntryInfo parent;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
@@ -56,6 +56,7 @@ public class CoreLocalVirtualFile extends VirtualFile {
return myFileSystem;
}
@NotNull
@Override
public String getPath() {
return FileUtil.toSystemIndependentName(myIoFile.getAbsolutePath());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -39,9 +39,9 @@ import java.io.OutputStream;
*/
public class MockVirtualFile extends VirtualFile {
private static VirtualFileSystem ourFileSystem = new MockVirtualFileSystem();
private static final VirtualFileSystem ourFileSystem = new MockVirtualFileSystem();
private String myPath;
private final String myPath;
@NotNull
static VirtualFile fromPath(@NotNull String absolutePath) {
@@ -84,6 +84,7 @@ public class MockVirtualFile extends VirtualFile {
return ourFileSystem;
}
@NotNull
@Override
public String getPath() {
return myPath;
@@ -179,14 +180,12 @@ public class MockVirtualFile extends VirtualFile {
MockVirtualFile file = (MockVirtualFile)o;
if (myPath != null ? !myPath.equals(file.myPath) : file.myPath != null) return false;
return true;
return myPath.equals(file.myPath);
}
@Override
public int hashCode() {
return myPath != null ? myPath.hashCode() : 0;
return myPath.hashCode();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -30,69 +30,85 @@ import java.io.InputStream;
import java.io.OutputStream;
public class StubVirtualFile extends VirtualFile {
@Override
@NotNull
public byte[] contentsToByteArray() throws IOException {
throw new UnsupportedOperationException("contentsToByteArray is not implemented");
}
@Override
public VirtualFile[] getChildren() {
throw new UnsupportedOperationException("getChildren is not implemented");
}
@Override
@NotNull
public VirtualFileSystem getFileSystem() {
throw new UnsupportedOperationException("getFileSystem is not implemented");
}
@Override
public InputStream getInputStream() throws IOException {
throw new UnsupportedOperationException("getInputStream is not implemented");
}
@Override
public long getLength() {
throw new UnsupportedOperationException("getLength is not implemented");
}
@Override
@NotNull
@NonNls
public String getName() {
throw new UnsupportedOperationException("getName is not implemented");
}
@Override
@NotNull
public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, final long newTimeStamp) throws IOException {
throw new UnsupportedOperationException("getOutputStream is not implemented");
}
@Override
@Nullable
public VirtualFile getParent() {
throw new UnsupportedOperationException("getParent is not implemented");
}
@Override
@NotNull
public String getPath() {
throw new UnsupportedOperationException("getPath is not implemented");
}
@Override
public long getTimeStamp() {
throw new UnsupportedOperationException("getTimeStamp is not implemented");
}
@Override
@NotNull
public String getUrl() {
throw new UnsupportedOperationException("getUrl is not implemented");
}
@Override
public boolean isDirectory() {
throw new UnsupportedOperationException("isDirectory is not implemented");
}
@Override
public boolean isValid() {
throw new UnsupportedOperationException("isValid is not implemented");
}
@Override
public boolean isWritable() {
throw new UnsupportedOperationException("isWritable is not implemented");
}
@Override
public void refresh(final boolean asynchronous, final boolean recursive, final Runnable postRunnable) {
throw new UnsupportedOperationException("refresh is not implemented");
}
@@ -1,6 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
@@ -45,6 +44,7 @@ abstract class VirtualFileImpl extends VirtualFile implements VirtualFileWithId
return myFileSystem;
}
@NotNull
@Override
public String getPath() {
if (myParent == null) {
@@ -102,6 +102,7 @@ class VirtualFileImpl extends HttpVirtualFile {
return myFileSystem;
}
@NotNull
@Override
public String getPath() {
return myPath;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -38,6 +38,7 @@ public class FakeVirtualFile extends StubVirtualFile {
return myParent;
}
@NotNull
@Override
public String getPath() {
final String basePath = myParent.getPath();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -33,12 +33,12 @@ import java.util.List;
// todo get rid of!!!!!!!!!!!!!
public class TestVirtualFile extends VirtualFile {
private String myName;
private final String myName;
private String myContent;
private boolean isReadOnly;
private long myTimestamp;
private boolean IsDirectory;
private final boolean IsDirectory;
private VirtualFile myParent;
private final List<TestVirtualFile> myChildren = new ArrayList<TestVirtualFile>();
@@ -76,6 +76,7 @@ public class TestVirtualFile extends VirtualFile {
return IsDirectory;
}
@NotNull
@Override
public String getPath() {
if (myParent == null) return myName;
@@ -453,9 +453,10 @@ public class Mock {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public String getPath() {
return null;
throw new UnsupportedOperationException();
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -90,6 +90,7 @@ public class MockVirtualFile extends VirtualFile {
return ourFileSystem;
}
@NotNull
@Override
public String getPath() {
String prefix = myParent == null ? "MOCK_ROOT:" : myParent.getPath();
@@ -101,6 +102,7 @@ public class MockVirtualFile extends VirtualFile {
return myIsWritable;
}
@Override
public void setWritable(boolean b) {
myIsWritable = b;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -113,9 +113,10 @@ public class MockVirtualFileSystem extends DeprecatedVirtualFileSystem {
@Override
public boolean isDirectory() {
return myChildren.size() != 0;
return !myChildren.isEmpty();
}
@NotNull
@Override
public String getPath() {
final MockVirtualFileSystem.MyVirtualFile parent = getParent();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -44,20 +44,25 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile {
myParent = null;
}
@Override
@NotNull
public VirtualFileSystem getFileSystem() {
return myFileSystem;
}
@Override
@NotNull
public String getPath() {
return myPath;
}
@Override
@NotNull
public String getName() {
return myName;
}
@Override
public String getPresentableName() {
if (myRevision == null)
return myName;
@@ -65,43 +70,53 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile {
return myName + " (" + myRevision + ")";
}
@Override
public boolean isWritable() {
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public VirtualFile getParent() {
return myParent;
}
@Override
public VirtualFile[] getChildren() {
return null;
}
@Override
public InputStream getInputStream() throws IOException {
return VfsUtilCore.byteStreamSkippingBOM(contentsToByteArray(), this);
}
@Override
@NotNull
public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
throw new RuntimeException(VcsFileSystem.COULD_NOT_IMPLEMENT_MESSAGE);
}
@Override
@NotNull
public abstract byte[] contentsToByteArray() throws IOException;
@Override
public long getModificationStamp() {
return myModificationStamp;
}
@Override
public long getTimeStamp() {
return myModificationStamp;
}
@Override
public long getLength() {
try {
return contentsToByteArray().length;
@@ -110,6 +125,7 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile {
}
}
@Override
public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
if (postRunnable != null)
postRunnable.run();
@@ -123,6 +139,7 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile {
myProcessingBeforeContentsChange = true;
try {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
((VcsFileSystem)getFileSystem()).fireBeforeContentsChange(this, AbstractVcsVirtualFile.this);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -43,7 +43,7 @@ public class TestDataGroupVirtualFile extends VirtualFile {
@Override
public String getName() {
final String prefix = StringUtil.commonPrefix(myBeforeFile.getName(), myAfterFile.getName());
if (prefix.length() == 0) {
if (prefix.isEmpty()) {
return StringUtil.commonSuffix(myBeforeFile.getName(), myAfterFile.getName());
}
return prefix + "." + myBeforeFile.getExtension();
@@ -63,6 +63,7 @@ public class TestDataGroupVirtualFile extends VirtualFile {
return LocalFileSystem.getInstance();
}
@NotNull
@Override
public String getPath() {
return myBeforeFile.getPath();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -789,6 +789,7 @@ public class SkeletonBuilderTest extends TestCase {
return new MockVirtualFileSystem();
}
@NotNull
@Override
public String getPath() {
return "mock";
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -52,46 +52,57 @@ public class MavenPropertiesVirtualFile extends VirtualFile {
return builder.toString().getBytes();
}
@Override
@NotNull
public String getName() {
return myPath;
}
@Override
@NotNull
public VirtualFileSystem getFileSystem() {
return myFS;
}
@Override
@NotNull
public String getPath() {
return myPath;
}
@Override
public boolean isWritable() {
return false;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public VirtualFile getParent() {
return null;
}
@Override
public VirtualFile[] getChildren() {
return null;
}
@Override
@NotNull
public byte[] contentsToByteArray() throws IOException {
if (myContent == null) throw new IOException();
return myContent;
}
@Override
public long getTimeStamp() {
return -1;
}
@@ -101,17 +112,21 @@ public class MavenPropertiesVirtualFile extends VirtualFile {
return myContent.hashCode();
}
@Override
public long getLength() {
return myContent.length;
}
@Override
public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
}
@Override
public InputStream getInputStream() throws IOException {
return VfsUtilCore.byteStreamSkippingBOM(myContent,this);
}
@Override
@NotNull
public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
throw new UnsupportedOperationException();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -42,15 +42,19 @@ public class ResourceBundleAsVirtualFile extends VirtualFile {
return myResourceBundle;
}
@Override
@NotNull
public VirtualFileSystem getFileSystem() {
return LocalFileSystem.getInstance();
}
@Override
@NotNull
public String getPath() {
return getName();
}
@Override
@NotNull
public String getName() {
return myResourceBundle.getBaseName();
@@ -71,71 +75,88 @@ public class ResourceBundleAsVirtualFile extends VirtualFile {
return myResourceBundle.hashCode();
}
@Override
public void rename(Object requestor, @NotNull String newName) throws IOException {
}
@Override
public boolean isWritable() {
return true;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public VirtualFile getParent() {
return myResourceBundle.getBaseDirectory();
}
@Override
public VirtualFile[] getChildren() {
return EMPTY_ARRAY;
}
@Override
public VirtualFile createChildDirectory(Object requestor, String name) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public VirtualFile createChildData(Object requestor, @NotNull String name) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void delete(Object requestor) throws IOException {
//todo
}
@Override
public void move(Object requestor, @NotNull VirtualFile newParent) throws IOException {
//todo
}
@Override
public InputStream getInputStream() throws IOException {
throw new UnsupportedOperationException();
}
@Override
@NotNull
public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
throw new UnsupportedOperationException();
}
@Override
@NotNull
public byte[] contentsToByteArray() throws IOException {
throw new UnsupportedOperationException();
}
@Override
public long getModificationStamp() {
return 0;
}
@Override
public long getTimeStamp() {
return 0;
}
@Override
public long getLength() {
return 0;
}
@Override
public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
}