From 9665337e6bce882aeb25d2a9922d8dab913cd3dc Mon Sep 17 00:00:00 2001 From: Evgeny Pasynkov Date: Wed, 9 Jul 2014 17:09:37 +0200 Subject: [PATCH] javascript-psi-impl shouldn't depend on lang-impl --- .../roots/impl/JavaLanguageLevelPusher.java | 4 +-- ...a => PushedFilePropertiesUpdaterImpl.java} | 33 +++++++++--------- .../src/componentSets/Lang.xml | 1 + .../lang/LanguagePerFileMappings.java | 0 .../roots/impl/FilePropertyPusher.java | 2 +- .../impl/PushedFilePropertiesUpdater.java | 34 +++++++++++++++++++ .../psi/impl/PythonLanguageLevelPusher.java | 6 ++-- 7 files changed, 58 insertions(+), 22 deletions(-) rename platform/lang-impl/src/com/intellij/openapi/roots/impl/{PushedFilePropertiesUpdater.java => PushedFilePropertiesUpdaterImpl.java} (92%) rename platform/{lang-impl => projectModel-impl}/src/com/intellij/lang/LanguagePerFileMappings.java (100%) create mode 100644 platform/projectModel-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java b/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java index d933576fc697..a4e7b64241f3 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java @@ -86,7 +86,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher myTasks = new ConcurrentLinkedQueue(); private final MessageBusConnection myConnection; - @NotNull - public static PushedFilePropertiesUpdater getInstance(Project project) { - return project.getComponent(PushedFilePropertiesUpdater.class); - } - - public PushedFilePropertiesUpdater(final Project project) { + public PushedFilePropertiesUpdaterImpl(final Project project) { myProject = project; myPushers = Extensions.getExtensions(FilePropertyPusher.EP_NAME); myFilePushers = ContainerUtil.findAllAsArray(myPushers, new Condition() { @@ -122,22 +117,24 @@ public class PushedFilePropertiesUpdater { }); } + @Override public void initializeProperties() { for (final FilePropertyPusher pusher : myPushers) { pusher.initExtra(myProject, myProject.getMessageBus(), new FilePropertyPusher.Engine() { @Override public void pushAll() { - PushedFilePropertiesUpdater.this.pushAll(pusher); + PushedFilePropertiesUpdaterImpl.this.pushAll(pusher); } @Override public void pushRecursively(VirtualFile file, Project project) { - PushedFilePropertiesUpdater.this.schedulePushRecursively(file, pusher); + PushedFilePropertiesUpdaterImpl.this.schedulePushRecursively(file, pusher); } }); } } + @Override public void pushAllPropertiesNow() { performPushTasks(); doPushAll(myPushers); @@ -222,6 +219,7 @@ public class PushedFilePropertiesUpdater { return projectValue != null ? projectValue : pusher.getDefaultValue(); } + @Override public void pushAll(final FilePropertyPusher... pushers) { queueTask(new Runnable() { @Override @@ -289,7 +287,7 @@ public class PushedFilePropertiesUpdater { pusher = pushers[i]; if (!isDir && (pusher.pushDirectoriesOnly() || !pusher.acceptsFile(fileOrDir))) continue; else if (isDir && !pusher.acceptsDirectory(fileOrDir, myProject)) continue; - findAndUpdateValue(myProject, fileOrDir, pusher, moduleValues != null ? moduleValues[i]:null); + findAndUpdateValue(fileOrDir, pusher, moduleValues != null ? moduleValues[i]:null); } } catch (AbstractMethodError ame) { // acceptsDirectory is missed @@ -298,17 +296,18 @@ public class PushedFilePropertiesUpdater { } } - public static void findAndUpdateValue(final Project project, final VirtualFile fileOrDir, final FilePropertyPusher pusher, final T moduleValue) { - final T value = findPusherValuesUpwards(project, fileOrDir, pusher, moduleValue); - updateValue(fileOrDir, value, pusher); + @Override + public void findAndUpdateValue(final VirtualFile fileOrDir, final FilePropertyPusher pusher, final T moduleValue) { + final T value = findPusherValuesUpwards(myProject, fileOrDir, pusher, moduleValue); + updateValue(myProject, fileOrDir, value, pusher); } - private static void updateValue(final VirtualFile fileOrDir, final T value, final FilePropertyPusher pusher) { + private static void updateValue(final Project project, final VirtualFile fileOrDir, final T value, final FilePropertyPusher pusher) { final T oldValue = fileOrDir.getUserData(pusher.getFileDataKey()); if (value != oldValue) { fileOrDir.putUserData(pusher.getFileDataKey(), value); try { - pusher.persistAttribute(fileOrDir, value); + pusher.persistAttribute(project, fileOrDir, value); } catch (IOException e) { LOG.error(e); @@ -316,7 +315,8 @@ public class PushedFilePropertiesUpdater { } } - public static void filePropertiesChanged(@NotNull final VirtualFile file) { + @Override + public void filePropertiesChanged(@NotNull final VirtualFile file) { ApplicationManager.getApplication().assertReadAccessAllowed(); FileBasedIndex.getInstance().requestReindex(file); for (final Project project : ProjectManager.getInstance().getOpenProjects()) { @@ -344,6 +344,7 @@ public class PushedFilePropertiesUpdater { } } + @Override public void processPendingEvents() { myConnection.deliverImmediately(); } diff --git a/platform/platform-resources/src/componentSets/Lang.xml b/platform/platform-resources/src/componentSets/Lang.xml index c79750e31dd8..9772a94c4e62 100644 --- a/platform/platform-resources/src/componentSets/Lang.xml +++ b/platform/platform-resources/src/componentSets/Lang.xml @@ -208,6 +208,7 @@ com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater + com.intellij.openapi.roots.impl.PushedFilePropertiesUpdaterImpl diff --git a/platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java b/platform/projectModel-impl/src/com/intellij/lang/LanguagePerFileMappings.java similarity index 100% rename from platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java rename to platform/projectModel-impl/src/com/intellij/lang/LanguagePerFileMappings.java diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java index 7a22aefbf833..b8af3172bef9 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java @@ -50,7 +50,7 @@ public interface FilePropertyPusher { boolean acceptsFile(@NotNull VirtualFile file); boolean acceptsDirectory(@NotNull VirtualFile file, @NotNull Project project); - void persistAttribute(@NotNull VirtualFile fileOrDir, @NotNull T value) throws IOException; + void persistAttribute(@NotNull Project project, @NotNull VirtualFile fileOrDir, @NotNull T value) throws IOException; interface Engine { void pushAll(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java new file mode 100644 index 000000000000..63fcc111df5d --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java @@ -0,0 +1,34 @@ +/* + * 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. + */ +package com.intellij.openapi.roots.impl; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +public abstract class PushedFilePropertiesUpdater { + @NotNull + public static PushedFilePropertiesUpdater getInstance(Project project) { + return project.getComponent(PushedFilePropertiesUpdater.class); + } + + public abstract void initializeProperties(); + public abstract void pushAll(final FilePropertyPusher... pushers); + public abstract void filePropertiesChanged(@NotNull final VirtualFile file); + public abstract void processPendingEvents(); + public abstract void pushAllPropertiesNow(); + public abstract void findAndUpdateValue(final VirtualFile fileOrDir, final FilePropertyPusher pusher, final T moduleValue); +} diff --git a/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java b/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java index 136a7073bb8b..7e15cab6ffda 100644 --- a/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java +++ b/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java @@ -146,7 +146,7 @@ public class PythonLanguageLevelPusher implements FilePropertyPusher