diff --git a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java index 6e34b85fa4ae..6851be0554e0 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2019 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileTypes; import com.intellij.lang.Language; @@ -22,7 +8,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * @author max * @see SingleLazyInstanceSyntaxHighlighterFactory */ public abstract class SyntaxHighlighterFactory { @@ -50,8 +35,7 @@ public abstract class SyntaxHighlighterFactory { * @param file might be necessary to collect file specific settings * @return {@code SyntaxHighlighter} interface implementation for the given file type */ - @Nullable - public static SyntaxHighlighter getSyntaxHighlighter(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { + public static @Nullable SyntaxHighlighter getSyntaxHighlighter(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { return SyntaxHighlighter.PROVIDER.create(fileType, project, file); } @@ -66,6 +50,5 @@ public abstract class SyntaxHighlighterFactory { * @param virtualFile might be necessary to collect file specific settings * @return {@code SyntaxHighlighter} interface implementation for this particular language. */ - @NotNull - public abstract SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile); + public abstract @NotNull SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile); } \ No newline at end of file diff --git a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java index f904cd3c3d65..f5794207e48e 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /* * @author max @@ -30,51 +16,52 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; -public class SyntaxHighlighterLanguageFactory extends LanguageExtension { - public static final ExtensionPointName> EP_NAME = ExtensionPointName.create("com.intellij.lang.syntaxHighlighterFactory"); +public final class SyntaxHighlighterLanguageFactory extends LanguageExtension { + public static final ExtensionPointName> EP_NAME = new ExtensionPointName<>("com.intellij.lang.syntaxHighlighterFactory"); - private boolean myEPListenerAdded = false; + private boolean myEpListenerAdded = false; SyntaxHighlighterLanguageFactory() { super(EP_NAME, new PlainSyntaxHighlighterFactory()); } - @NotNull @Override - protected List buildExtensions(@NotNull String stringKey, @NotNull Language key) { - List fromEP = super.buildExtensions(stringKey, key); - if (fromEP.isEmpty()) { - SyntaxHighlighter highlighter = LanguageSyntaxHighlighters.INSTANCE.forLanguage(key); - if (highlighter != null) { - checkAddEPListener(); - SyntaxHighlighterFactory defaultFactory = new SingleLazyInstanceSyntaxHighlighterFactory() { - @NotNull - @Override - protected SyntaxHighlighter createHighlighter() { - return highlighter; - } - }; - return Collections.singletonList(defaultFactory); - } + protected @NotNull List buildExtensions(@NotNull String stringKey, @NotNull Language key) { + List fromEp = super.buildExtensions(stringKey, key); + if (!fromEp.isEmpty()) { + return fromEp; } - return fromEP; + + SyntaxHighlighter highlighter = LanguageSyntaxHighlighters.INSTANCE.forLanguage(key); + if (highlighter != null) { + checkAddEPListener(); + return Collections.singletonList(new SingleLazyInstanceSyntaxHighlighterFactory() { + @Override + protected @NotNull SyntaxHighlighter createHighlighter() { + return highlighter; + } + }); + } + return fromEp; } private synchronized void checkAddEPListener() { - if (!myEPListenerAdded) { - myEPListenerAdded = true; - - LanguageSyntaxHighlighters.EP_NAME.addExtensionPointListener(new ExtensionPointListener>() { - @Override - public void extensionAdded(@NotNull KeyedLazyInstance extension, @NotNull PluginDescriptor pluginDescriptor) { - invalidateCacheForExtension(extension.getKey()); - } - - @Override - public void extensionRemoved(@NotNull KeyedLazyInstance extension, @NotNull PluginDescriptor pluginDescriptor) { - invalidateCacheForExtension(extension.getKey()); - } - }, null); + if (myEpListenerAdded) { + return; } + + myEpListenerAdded = true; + + LanguageSyntaxHighlighters.EP_NAME.addExtensionPointListener(new ExtensionPointListener>() { + @Override + public void extensionAdded(@NotNull KeyedLazyInstance extension, @NotNull PluginDescriptor pluginDescriptor) { + invalidateCacheForExtension(extension.getKey()); + } + + @Override + public void extensionRemoved(@NotNull KeyedLazyInstance extension, @NotNull PluginDescriptor pluginDescriptor) { + invalidateCacheForExtension(extension.getKey()); + } + }, null); } } diff --git a/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java b/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java index 49804162b9ff..22e97cf3ede3 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java @@ -11,6 +11,7 @@ import org.picocontainer.PicoContainer; /** * @deprecated Use {@link com.intellij.serviceContainer.LazyExtensionInstance}. */ +@Deprecated public abstract class AbstractExtensionPointBean implements PluginAware { private static final Logger LOG = Logger.getInstance(AbstractExtensionPointBean.class);