bad plugin must not break StubUpdatingIndex

GitOrigin-RevId: 4cdf8a7ab4fc849603831549e6359e1efb050b62
This commit is contained in:
Vladimir Krivosheev
2020-10-30 16:15:18 +01:00
committed by intellij-monorepo-bot
parent 8ef8f2b1aa
commit fdabc4617b
5 changed files with 39 additions and 46 deletions

View File

@@ -34,7 +34,7 @@ public abstract class BaseKeyedLazyInstance<T> extends LazyExtensionInstance<T>
@Override
protected abstract @Nullable String getImplementationClassName();
public final @NotNull T getInstance() {
public @NotNull T getInstance() {
return getInstance(ApplicationManager.getApplication(), pluginDescriptor);
}

View File

@@ -0,0 +1,25 @@
// 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.util;
import com.intellij.serviceContainer.BaseKeyedLazyInstance;
import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.Nullable;
public class KeyedLazyInstanceEP<T> extends BaseKeyedLazyInstance<T> implements KeyedLazyInstance<T> {
// these must be public for scrambling compatibility
@Attribute("key")
public String key;
@Attribute("implementationClass")
public String implementationClass;
@Override
public String getKey() {
return key;
}
@Override
protected @Nullable String getImplementationClassName() {
return implementationClass;
}
}

View File

@@ -35,7 +35,7 @@ public final class ExtensionProcessingHelper {
catch (ProcessCanceledException e) {
throw e;
}
catch (Exception e) {
catch (Throwable e) {
ExtensionPointImpl.LOG.error(e);
}
}

View File

@@ -1,37 +0,0 @@
// 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.util;
import com.intellij.openapi.extensions.AbstractExtensionPointBean;
import com.intellij.openapi.util.LazyInstance;
import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class KeyedLazyInstanceEP<T> extends AbstractExtensionPointBean implements KeyedLazyInstance<T> {
// these must be public for scrambling compatibility
@Attribute("key")
public String key;
@Attribute("implementationClass")
public String implementationClass;
private final LazyInstance<T> myHandler = new LazyInstance<T>() {
@Override
protected Class<T> getInstanceClass() {
return findExtensionClass(implementationClass);
}
};
@Override
public @NotNull T getInstance() {
return myHandler.getValue();
}
@Override
public String getKey() {
return key;
}
}

View File

@@ -8,7 +8,8 @@ import com.intellij.lang.ParserDefinition;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.impl.ExtensionPointImpl;
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.fileTypes.LanguageFileType;
@@ -49,7 +50,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.function.Consumer;
public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<SerializedStubTree>
implements CustomImplementationFileBasedIndexExtension<Integer, SerializedStubTree> {
@@ -571,12 +572,16 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
private static void instantiateElementTypesFromFields() {
// load stub serializers before usage
FileTypeRegistry.getInstance().getRegisteredFileTypes();
getExtensions(BinaryFileStubBuilders.INSTANCE).forEach(builder -> {});
getExtensions(LanguageParserDefinitions.INSTANCE).forEach(ParserDefinition::getFileNodeType);
getExtensions(BinaryFileStubBuilders.INSTANCE, builder -> {});
getExtensions(LanguageParserDefinitions.INSTANCE, ParserDefinition::getFileNodeType);
}
private static @NotNull <T> Stream<T> getExtensions(@NotNull KeyedExtensionCollector<T, ?> collector) {
ExtensionPoint<KeyedLazyInstance<T>> point = collector.getPoint();
return point == null ? Stream.empty() : point.extensions().map(KeyedLazyInstance::getInstance);
private static <T> void getExtensions(@NotNull KeyedExtensionCollector<T, ?> collector, @NotNull Consumer<T> consumer) {
ExtensionPointImpl<KeyedLazyInstance<T>> point = (ExtensionPointImpl<KeyedLazyInstance<T>>)collector.getPoint();
if (point != null) {
ExtensionProcessingHelper.forEachExtensionSafe(point, instance -> {
consumer.accept(instance.getInstance());
});
}
}
}