platform: remove code duplication, introduce the new API methods

GitOrigin-RevId: 8dfb38653e3828edb3f091e3dfec59cd322e4a8f
This commit is contained in:
anstarovoyt
2019-12-19 14:08:32 +00:00
committed by intellij-monorepo-bot
parent 6e98bba244
commit a4d7f60198
6 changed files with 25 additions and 43 deletions
@@ -121,6 +121,8 @@ public interface ExtensionPoint<T> {
void addExtensionPointListener(@NotNull ExtensionPointListener<T> listener);
void addExtensionPointListener(@NotNull ExtensionPointListener<T> listener, boolean invokeForLoadedExtensions, @Nullable Disposable parentDisposable);
void addExtensionPointListener(@NotNull ExtensionPointChangeListener<T> listener, boolean invokeForLoadedExtensions, @Nullable Disposable parentDisposable);
void removeExtensionPointListener(@NotNull ExtensionPointListener<T> extensionPointListener);
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
/**
* @author yole
* @see ExtensionPointChangeListener
*/
public abstract class ExtensionPointAdapter<T> implements ExtensionPointAndAreaListener<T> {
@Override
@@ -719,6 +719,21 @@ public abstract class ExtensionPointImpl<T> implements ExtensionPoint<T>, Iterab
}
}
@Override
public void addExtensionPointListener(@NotNull ExtensionPointChangeListener<T> listener, boolean invokeForLoadedExtensions, @Nullable Disposable parentDisposable) {
addExtensionPointListener(new ExtensionPointListener<T>() {
@Override
public void extensionAdded(@NotNull T extension, @NotNull PluginDescriptor pluginDescriptor) {
listener.extensionChanged(extension, pluginDescriptor);
}
@Override
public void extensionRemoved(@NotNull T extension, @NotNull PluginDescriptor pluginDescriptor) {
listener.extensionChanged(extension, pluginDescriptor);
}
}, invokeForLoadedExtensions, parentDisposable);
}
@Override
public synchronized void removeExtensionPointListener(@NotNull ExtensionPointListener<T> listener) {
removeListener(listener);
@@ -73,26 +73,12 @@ public final class PsiVFSListener implements BulkFileListener {
ExtensionPoint<KeyedLazyInstance<LanguageSubstitutor>> point = LanguageSubstitutors.getInstance().getPoint();
if (point != null) {
point.addExtensionPointListener(
new ExtensionPointListener<KeyedLazyInstance<LanguageSubstitutor>>() {
point.addExtensionPointListener((e, pd) -> {
if (project.isDisposed()) return;
@Override
public void extensionRemoved(@NotNull KeyedLazyInstance<LanguageSubstitutor> extension,
@NotNull PluginDescriptor pluginDescriptor) {
if (project.isDisposed()) return;
PsiManagerImpl psiManager = (PsiManagerImpl)PsiManager.getInstance(project);
((FileManagerImpl)(psiManager.getFileManager())).processFileTypesChanged(true);
}
@Override
public void extensionAdded(@NotNull KeyedLazyInstance<LanguageSubstitutor> extension,
@NotNull PluginDescriptor pluginDescriptor) {
if (project.isDisposed()) return;
PsiManagerImpl psiManager = (PsiManagerImpl)PsiManager.getInstance(project);
((FileManagerImpl)(psiManager.getFileManager())).processFileTypesChanged(true);
}
}, false, project);
PsiManagerImpl psiManager = (PsiManagerImpl)PsiManager.getInstance(project);
((FileManagerImpl)(psiManager.getFileManager())).processFileTypesChanged(true);
}, false, project);
}
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener(project));
@@ -56,17 +56,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
myDumbService = DumbService.getInstance(myProject);
myDocManager = PsiDocumentManager.getInstance(project);
MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME.getPoint(project).addExtensionPointListener(new ExtensionPointListener<MultiHostInjector>() {
@Override
public void extensionAdded(@NotNull MultiHostInjector injector, @NotNull PluginDescriptor pluginDescriptor) {
clearInjectorCache();
}
@Override
public void extensionRemoved(@NotNull MultiHostInjector injector, @NotNull PluginDescriptor pluginDescriptor) {
clearInjectorCache();
}
}, false, this);
MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME.getPoint(project).addExtensionPointListener((e, pd) -> clearInjectorCache(), false, this);
LanguageInjector.EXTENSION_POINT_NAME.addExtensionPointListener(new ExtensionPointListener<LanguageInjector>() {
@Override
@@ -39,19 +39,7 @@ public class FileTypeUtil {
types = null;
}
});
Objects.requireNonNull(CopyrightUpdaters.INSTANCE.getPoint())
.addExtensionPointListener(
new ExtensionPointListener<KeyedLazyInstance<UpdateCopyrightsProvider >> () {
@Override
public void extensionAdded(@NotNull KeyedLazyInstance<UpdateCopyrightsProvider> extension, @NotNull PluginDescriptor pluginDescriptor) {
types = null;
}
@Override
public void extensionRemoved(@NotNull KeyedLazyInstance<UpdateCopyrightsProvider> extension, @NotNull PluginDescriptor pluginDescriptor) {
types = null;
}
}, false, application);
Objects.requireNonNull(CopyrightUpdaters.INSTANCE.getPoint()).addExtensionPointListener((e, pd) -> types = null, false, application);
}
public static String buildComment(FileType type, String template, LanguageOptions options) {