Merge branch 'db/javac-ast'
[idea/community.git] / platform / core-api / src / com / intellij / openapi / vfs / DeprecatedVirtualFileSystem.java
1 /*
2  * Copyright 2000-2016 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * @author max
19  */
20 package com.intellij.openapi.vfs;
21
22 import com.intellij.openapi.application.Application;
23 import com.intellij.openapi.application.ApplicationManager;
24 import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter;
25 import com.intellij.util.EventDispatcher;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28
29 import java.io.IOException;
30
31 public abstract class DeprecatedVirtualFileSystem extends VirtualFileSystem {
32   private final EventDispatcher<VirtualFileListener> myEventDispatcher = EventDispatcher.create(VirtualFileListener.class);
33
34   protected void startEventPropagation() {
35     Application app = ApplicationManager.getApplication();
36     if (app != null) {
37       app.getMessageBus().connect().subscribe(
38         VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(myEventDispatcher.getMulticaster(), this));
39     }
40   }
41
42   @Override
43   public void addVirtualFileListener(@NotNull VirtualFileListener listener) {
44     myEventDispatcher.addListener(listener);
45   }
46
47   @Override
48   public void removeVirtualFileListener(@NotNull VirtualFileListener listener) {
49     myEventDispatcher.removeListener(listener);
50   }
51
52   @SuppressWarnings("unused")
53   protected void firePropertyChanged(Object requestor,
54                                      @NotNull VirtualFile file,
55                                      @NotNull String propertyName,
56                                      Object oldValue,
57                                      Object newValue) {
58     assertWriteAccessAllowed();
59     VirtualFilePropertyEvent event = new VirtualFilePropertyEvent(requestor, file, propertyName, oldValue, newValue);
60     myEventDispatcher.getMulticaster().propertyChanged(event);
61   }
62
63   @SuppressWarnings("unused")
64   protected void fireContentsChanged(Object requestor, @NotNull VirtualFile file, long oldModificationStamp) {
65     assertWriteAccessAllowed();
66     VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getParent(), oldModificationStamp, file.getModificationStamp());
67     myEventDispatcher.getMulticaster().contentsChanged(event);
68   }
69
70   @SuppressWarnings("unused")
71   protected void fireFileCreated(@Nullable Object requestor, @NotNull VirtualFile file) {
72     assertWriteAccessAllowed();
73     VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
74     myEventDispatcher.getMulticaster().fileCreated(event);
75   }
76
77   @SuppressWarnings("unused")
78   protected void fireFileDeleted(Object requestor, @NotNull VirtualFile file, @NotNull String fileName, VirtualFile parent) {
79     assertWriteAccessAllowed();
80     VirtualFileEvent event = new VirtualFileEvent(requestor, file, fileName, parent);
81     myEventDispatcher.getMulticaster().fileDeleted(event);
82   }
83
84   @SuppressWarnings("unused")
85   protected void fireFileMoved(Object requestor, @NotNull VirtualFile file, VirtualFile oldParent) {
86     assertWriteAccessAllowed();
87     VirtualFileMoveEvent event = new VirtualFileMoveEvent(requestor, file, oldParent, file.getParent());
88     myEventDispatcher.getMulticaster().fileMoved(event);
89   }
90
91   @SuppressWarnings("unused")
92   protected void fireFileCopied(@Nullable Object requestor, @NotNull VirtualFile originalFile, @NotNull VirtualFile createdFile) {
93     assertWriteAccessAllowed();
94     VirtualFileCopyEvent event = new VirtualFileCopyEvent(requestor, originalFile, createdFile);
95     myEventDispatcher.getMulticaster().fileCopied(event);
96   }
97
98   @SuppressWarnings("unused")
99   protected void fireBeforePropertyChange(Object requestor,
100                                           @NotNull VirtualFile file,
101                                           @NotNull String propertyName,
102                                           Object oldValue,
103                                           Object newValue) {
104     assertWriteAccessAllowed();
105     VirtualFilePropertyEvent event = new VirtualFilePropertyEvent(requestor, file, propertyName, oldValue, newValue);
106     myEventDispatcher.getMulticaster().beforePropertyChange(event);
107   }
108
109   @SuppressWarnings("unused")
110   protected void fireBeforeContentsChange(Object requestor, @NotNull VirtualFile file) {
111     assertWriteAccessAllowed();
112     VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
113     myEventDispatcher.getMulticaster().beforeContentsChange(event);
114   }
115
116   @SuppressWarnings("unused")
117   protected void fireBeforeFileDeletion(Object requestor, @NotNull VirtualFile file) {
118     assertWriteAccessAllowed();
119     VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
120     myEventDispatcher.getMulticaster().beforeFileDeletion(event);
121   }
122
123   @SuppressWarnings("unused")
124   protected void fireBeforeFileMovement(Object requestor, @NotNull VirtualFile file, VirtualFile newParent) {
125     assertWriteAccessAllowed();
126     VirtualFileMoveEvent event = new VirtualFileMoveEvent(requestor, file, file.getParent(), newParent);
127     myEventDispatcher.getMulticaster().beforeFileMovement(event);
128   }
129
130   protected void assertWriteAccessAllowed() {
131     ApplicationManager.getApplication().assertWriteAccessAllowed();
132   }
133
134   @Override
135   public boolean isReadOnly() {
136     return true;
137   }
138
139   @Override
140   protected void deleteFile(Object requestor, @NotNull VirtualFile vFile) throws IOException {
141     throw unsupported("deleteFile", vFile);
142   }
143
144   @Override
145   protected void moveFile(Object requestor, @NotNull VirtualFile vFile, @NotNull VirtualFile newParent) throws IOException {
146     throw unsupported("move", vFile);
147   }
148
149   @Override
150   protected void renameFile(Object requestor, @NotNull VirtualFile vFile, @NotNull String newName) throws IOException {
151     throw unsupported("renameFile", vFile);
152   }
153
154   @NotNull
155   @Override
156   public VirtualFile createChildFile(Object requestor, @NotNull VirtualFile vDir, @NotNull String fileName) throws IOException {
157     throw unsupported("createChildFile", vDir);
158   }
159
160   @NotNull
161   @Override
162   public VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile vDir, @NotNull String dirName) throws IOException {
163     throw unsupported("createChildDirectory", vDir);
164   }
165
166   @NotNull
167   @Override
168   public VirtualFile copyFile(Object requestor, @NotNull VirtualFile vFile, @NotNull VirtualFile newParent, @NotNull String copyName) throws IOException {
169     throw unsupported("copyFile() not supported", vFile);
170   }
171
172   private UnsupportedOperationException unsupported(String op, VirtualFile vFile) {
173     return new UnsupportedOperationException(op + '(' + vFile + ") not supported by " + getClass().getName());
174   }
175 }