CustomLoadingExtensionPointBean — do not use pico container to instantiate classes

This commit is contained in:
Vladimir Krivosheev
2019-01-30 14:07:00 +01:00
parent 1bb82a7f5c
commit d8c8de01b0
9 changed files with 49 additions and 91 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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-2019 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.codeInsight.daemon.impl;
import com.intellij.codeHighlighting.Pass;
@@ -57,8 +43,6 @@ import java.awt.event.MouseEvent;
import java.util.*;
public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
protected final DaemonCodeAnalyzerSettings myDaemonSettings;
protected final EditorColorsManager myColorsManager;
private final Option myLambdaOption = new Option("java.lambda", "Lambda", AllIcons.Gutter.ImplementingFunctionalInterface);
private final Option myOverriddenOption = new Option("java.overridden", "Overridden method", AllIcons.Gutter.OverridenMethod);
private final Option myImplementedOption = new Option("java.implemented", "Implemented method", AllIcons.Gutter.ImplementedMethod);
@@ -69,9 +53,12 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
private static final CallMatcher SERVICE_LOADER_LOAD = CallMatcher.staticCall("java.util.ServiceLoader", "load", "loadInstalled");
public JavaLineMarkerProvider() {
}
@SuppressWarnings("unused")
@Deprecated
public JavaLineMarkerProvider(DaemonCodeAnalyzerSettings daemonSettings, EditorColorsManager colorsManager) {
myDaemonSettings = daemonSettings;
myColorsManager = colorsManager;
}
@Override
@@ -112,7 +99,7 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
}
}
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
if (DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
@@ -139,7 +126,7 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
}
if (drawSeparator) {
return LineMarkersPass.createMethodSeparatorLineMarker(element, myColorsManager);
return LineMarkersPass.createMethodSeparatorLineMarker(element, EditorColorsManager.getInstance());
}
}
}
@@ -41,8 +41,8 @@ import org.jetbrains.lang.manifest.psi.ManifestTokenType;
* @author <a href="mailto:janthomae@janthomae.de">Jan Thom&auml;</a>
* @author Robert F. Beeger (robert@beeger.net)
*/
public class ManifestCompletionContributor extends CompletionContributor {
public ManifestCompletionContributor(@NotNull final HeaderParserRepository repository) {
final class ManifestCompletionContributor extends CompletionContributor {
ManifestCompletionContributor() {
extend(CompletionType.BASIC,
PlatformPatterns.psiElement(ManifestTokenType.HEADER_NAME).withLanguage(ManifestLanguage.INSTANCE),
new CompletionProvider<CompletionParameters>() {
@@ -50,7 +50,7 @@ public class ManifestCompletionContributor extends CompletionContributor {
public void addCompletions(@NotNull CompletionParameters parameters,
@NotNull ProcessingContext context,
@NotNull CompletionResultSet resultSet) {
for (String header : repository.getAllHeaderNames()) {
for (String header : HeaderParserRepository.getInstance().getAllHeaderNames()) {
resultSet.addElement(LookupElementBuilder.create(header).withInsertHandler(HEADER_INSERT_HANDLER));
}
}
@@ -37,13 +37,7 @@ import org.jetbrains.lang.manifest.psi.Header;
/**
* @author Robert F. Beeger (robert@beeger.net)
*/
public class HeaderAnnotator implements Annotator {
private final HeaderParserRepository myRepository;
public HeaderAnnotator(@NotNull HeaderParserRepository repository) {
myRepository = repository;
}
final class HeaderAnnotator implements Annotator {
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
if (psiElement instanceof Header) {
@@ -53,7 +47,7 @@ public class HeaderAnnotator implements Annotator {
holder.createAnnotation(HighlightSeverity.ERROR, header.getNameElement().getTextRange(), ManifestBundle.message("header.name.invalid"));
}
else {
HeaderParser headerParser = myRepository.getHeaderParser(name);
HeaderParser headerParser = HeaderParserRepository.getInstance().getHeaderParser(name);
if (headerParser != null) {
headerParser.annotate(header, holder);
}
@@ -1,21 +1,9 @@
/*
* Copyright 2000-2015 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-2019 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.codeInsight.daemon.impl;
import com.intellij.lang.annotation.Annotator;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.pico.CachingConstructorInjectionComponentAdapter;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
@@ -52,7 +40,14 @@ abstract class ThreadLocalAnnotatorMap<K, V> {
PicoContainer container = ApplicationManager.getApplication().getPicoContainer();
for (V template : templates) {
Class<? extends V> aClass = (Class<? extends V>)template.getClass();
V clone = (V)new CachingConstructorInjectionComponentAdapter(aClass.getName(), aClass).getComponentInstance(container);
V clone;
// todo in general CachingConstructorInjectionComponentAdapter should be not used at all, but for now disable it only for known cases
if (Annotator.class.isAssignableFrom(aClass)) {
clone = ReflectionUtil.newInstance(aClass);
}
else {
clone = (V)new CachingConstructorInjectionComponentAdapter(aClass.getName(), aClass, null, true).getComponentInstance(container);
}
result.add(clone);
}
return result;
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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.
// Copyright 2000-2019 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.extensions;
import com.intellij.openapi.diagnostic.Logger;
@@ -12,7 +12,8 @@ import org.picocontainer.PicoContainer;
* @author peter
*/
public abstract class AbstractExtensionPointBean implements PluginAware {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.extensions.AbstractExtensionPointBean");
protected static final Logger LOG = Logger.getInstance("#com.intellij.openapi.extensions.AbstractExtensionPointBean");
protected PluginDescriptor myPluginDescriptor;
@Transient
@@ -1,21 +1,8 @@
/*
* 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.
*/
// Copyright 2000-2019 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.extensions;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.NotNull;
import org.picocontainer.PicoContainer;
@@ -43,7 +30,19 @@ public class CustomLoadingExtensionPointBean extends AbstractExtensionPointBean
(myPluginDescriptor == null ? "<not available>" : myPluginDescriptor.getPluginId()) + ". " +
"Check if 'implementationClass' attribute is specified");
}
return instantiate(findClass(implementationClass), picoContainer, true);
Class<Object> clazz = findClass(implementationClass);
try {
return ReflectionUtil.newInstance(clazz);
}
catch (RuntimeException e) {
if (e.getCause() instanceof NoSuchMethodException) {
LOG.error("Bean extension class constructor must not have parameters: " + implementationClass);
return instantiate(clazz, picoContainer, true);
}
else {
throw e;
}
}
}
}
}
@@ -113,4 +113,5 @@ PerforceIC 0.10.0 0.9.6 0.9.5 0.9.4 0.9.3 0.9.2 0.9.1 0.9.0 0.8.7
com.compilerexplorer.compilerexplorer 1.13 1.12 1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0
Bazel 2018.12.03.0.2 2018.11.12.0.4
ru.makkarpov.ucl 0.1 0.1.1 0.1.2
com.undo_software.clion.reverse 2.0.0
com.undo_software.clion.reverse 2.0.0
"Randori Compiler" 0.2.0 0.2.1 0.2.3 0.2.4 0.3.0
@@ -422,7 +422,7 @@ public class ReflectionUtil {
return t;
}
ExceptionUtil.rethrow(e);
ExceptionUtilRt.rethrow(e);
}
// error will be thrown
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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-2019 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 org.jetbrains.plugins.groovy.codeInsight;
import com.intellij.codeHighlighting.Pass;
@@ -62,12 +48,7 @@ import java.util.*;
* @author ilyas
* Same logic as for Java LMP
*/
public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
public GroovyLineMarkerProvider(DaemonCodeAnalyzerSettings daemonSettings, EditorColorsManager colorsManager) {
super(daemonSettings, colorsManager);
}
final class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
final PsiElement parent = element.getParent();
@@ -97,7 +78,7 @@ public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
}
}
//need to draw method separator above docComment
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
if (DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
@@ -132,7 +113,7 @@ public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null,
Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null,
GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;