From 9dbec9bae81ccec2bfbe2518ca6059fea6d04722 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 28 Mar 2019 08:40:29 +0100 Subject: [PATCH] get rid of constructor injection - part 7 --- java/java-impl/src/META-INF/JavaPlugin.xml | 6 +-- .../xml/impl/JavaDomApplicationComponent.java | 30 +++++-------- .../groovy/GrConcatenationAwareInjector.java | 44 ++++++++----------- .../src/org/zmlx/hg4idea/HgTaskHandler.java | 24 +++------- .../hg4idea/branch/HgBranchStateProvider.kt | 12 ++--- 5 files changed, 42 insertions(+), 74 deletions(-) diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml index 1bf833aa76e5..8b2ba28ab783 100644 --- a/java/java-impl/src/META-INF/JavaPlugin.xml +++ b/java/java-impl/src/META-INF/JavaPlugin.xml @@ -48,15 +48,11 @@ - com.intellij.openapi.vfs.jrt.JrtFileSystem com.intellij.openapi.vfs.impl.jrt.JrtFileSystemImpl - - com.intellij.util.xml.impl.JavaDomApplicationComponent - com.intellij.openapi.projectRoots.JavaSdk com.intellij.openapi.projectRoots.impl.JavaSdkImpl @@ -1929,6 +1925,8 @@ + + diff --git a/java/java-impl/src/com/intellij/util/xml/impl/JavaDomApplicationComponent.java b/java/java-impl/src/com/intellij/util/xml/impl/JavaDomApplicationComponent.java index 54c9c416adda..bea9bfaa8433 100644 --- a/java/java-impl/src/com/intellij/util/xml/impl/JavaDomApplicationComponent.java +++ b/java/java-impl/src/com/intellij/util/xml/impl/JavaDomApplicationComponent.java @@ -1,20 +1,8 @@ -/* - * 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-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.util.xml.impl; +import com.intellij.ide.ApplicationInitializedListener; +import com.intellij.openapi.components.ServiceManager; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiType; import com.intellij.util.Consumer; @@ -29,10 +17,14 @@ import com.intellij.util.xml.ui.PsiTypeControl; /** * @author peter */ -public class JavaDomApplicationComponent implements Consumer { - public JavaDomApplicationComponent(ConverterManager converterManager) { - converterManager.addConverter(PsiClass.class, new PsiClassConverter()); - converterManager.addConverter(PsiType.class, new CanonicalPsiTypeConverterImpl()); +final class JavaDomApplicationComponent implements Consumer { + private static final class Initializer implements ApplicationInitializedListener { + @Override + public void componentsInitialized() { + ConverterManager converterManager = ServiceManager.getService(ConverterManager.class); + converterManager.addConverter(PsiClass.class, new PsiClassConverter()); + converterManager.addConverter(PsiType.class, new CanonicalPsiTypeConverterImpl()); + } } @Override diff --git a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GrConcatenationAwareInjector.java b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GrConcatenationAwareInjector.java index c5247b828445..79bbeb27ccf2 100644 --- a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GrConcatenationAwareInjector.java +++ b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GrConcatenationAwareInjector.java @@ -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 org.intellij.plugins.intelliLang.inject.groovy; import com.intellij.lang.Language; @@ -20,7 +20,6 @@ import org.intellij.plugins.intelliLang.Configuration; import org.intellij.plugins.intelliLang.inject.InjectedLanguage; import org.intellij.plugins.intelliLang.inject.InjectorUtils; import org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport; -import org.intellij.plugins.intelliLang.inject.TemporaryPlacesRegistry; import org.intellij.plugins.intelliLang.inject.config.BaseInjection; import org.intellij.plugins.intelliLang.inject.java.InjectionCache; import org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport; @@ -44,17 +43,7 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; -public class GrConcatenationAwareInjector implements ConcatenationAwareInjector { - private final LanguageInjectionSupport mySupport; - private final Configuration myConfiguration; - private final Project myProject; - - public GrConcatenationAwareInjector(Configuration configuration, Project project, TemporaryPlacesRegistry temporaryPlacesRegistry) { - myConfiguration = configuration; - myProject = project; - mySupport = InjectorUtils.findNotNullInjectionSupport(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID); - } - +public final class GrConcatenationAwareInjector implements ConcatenationAwareInjector { @Override public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement... operands) { if (operands.length == 0) return; @@ -63,24 +52,26 @@ public class GrConcatenationAwareInjector implements ConcatenationAwareInjector if (!(file instanceof GroovyFileBase)) return; - new InjectionProcessor(myConfiguration, mySupport, operands) { + LanguageInjectionSupport support = InjectorUtils.findNotNullInjectionSupport(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID); + Project project = file.getProject(); + new InjectionProcessor(Configuration.getProjectInstance(project), support, operands) { @Override protected void processInjection(Language language, List> list, boolean settingsAvailable, boolean unparsable) { InjectorUtils.registerInjection(language, list, file, registrar); - InjectorUtils.registerSupport(mySupport, settingsAvailable, list.get(0).getFirst(), language); + InjectorUtils.registerSupport(support, settingsAvailable, list.get(0).getFirst(), language); InjectorUtils.putInjectedFileUserData(list.get(0).getFirst(), language, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable); } @Override protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) { if (methodName == null) return false; - if (getAnnotatedElementsValue().contains(methodName)) { + if (getAnnotatedElementsValue(project).contains(methodName)) { return true; } - if (!annoOnly && getXmlAnnotatedElementsValue().contains(methodName)) { + if (!annoOnly && getXmlAnnotatedElementsValue(project).contains(methodName)) { return true; } return false; @@ -329,27 +320,28 @@ public class GrConcatenationAwareInjector implements ConcatenationAwareInjector boolean unparsable = false; - String prefix = ""; + StringBuilder prefix = new StringBuilder(); //String suffix = ""; for (int i = 0; i < myOperands.length; i++) { PsiElement operand = myOperands[i]; final ElementManipulator manipulator = ElementManipulators.getManipulator(operand); if (manipulator == null) { unparsable = true; - prefix += getStringPresentation(operand); + prefix.append(getStringPresentation(operand)); if (i == myOperands.length - 1) { Trinity last = ContainerUtil.getLastItem(list); assert last != null; InjectedLanguage injected = last.second; - list.set(list.size() - 1, Trinity.create(last.first, InjectedLanguage.create(injected.getID(), injected.getPrefix(), prefix, false), last.third)); + list.set(list.size() - 1, Trinity.create(last.first, InjectedLanguage.create(injected.getID(), injected.getPrefix(), + prefix.toString(), false), last.third)); } } else { - InjectedLanguage injectedLanguage = InjectedLanguage.create(languageID, prefix, "", false); + InjectedLanguage injectedLanguage = InjectedLanguage.create(languageID, prefix.toString(), "", false); TextRange range = manipulator.getRangeInElement(operand); PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)operand; list.add(Trinity.create(host, injectedLanguage, range)); - prefix = ""; + prefix.setLength(0); } } @@ -364,12 +356,12 @@ public class GrConcatenationAwareInjector implements ConcatenationAwareInjector } } - public Collection getAnnotatedElementsValue() { + private static Collection getAnnotatedElementsValue(@NotNull Project project) { // note: external annotations not supported - return InjectionCache.getInstance(myProject).getAnnoIndex(); + return InjectionCache.getInstance(project).getAnnoIndex(); } - private Collection getXmlAnnotatedElementsValue() { - return InjectionCache.getInstance(myProject).getXmlIndex(); + private static Collection getXmlAnnotatedElementsValue(@NotNull Project project) { + return InjectionCache.getInstance(project).getXmlIndex(); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgTaskHandler.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgTaskHandler.java index 8c010fdba5dd..35e128cb1d31 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgTaskHandler.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgTaskHandler.java @@ -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 org.zmlx.hg4idea; import com.intellij.dvcs.branch.DvcsTaskHandler; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; @@ -41,12 +28,11 @@ import java.util.Collections; import java.util.List; public class HgTaskHandler extends DvcsTaskHandler { - private final HgReferenceValidator myNameValidator; - public HgTaskHandler(@NotNull HgRepositoryManager repositoryManager, - @NotNull Project project) { - super(repositoryManager, project, "bookmark"); + public HgTaskHandler(@NotNull Project project) { + super(ServiceManager.getService(project, HgRepositoryManager.class), project, "bookmark"); + myNameValidator = HgReferenceValidator.getInstance(); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchStateProvider.kt b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchStateProvider.kt index 90a363f05812..5e431532b76a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchStateProvider.kt +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchStateProvider.kt @@ -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 org.zmlx.hg4idea.branch import com.intellij.dvcs.repo.VcsRepositoryManager @@ -12,13 +12,13 @@ import com.intellij.vcs.branch.BranchStateProvider import org.zmlx.hg4idea.HgVcs import org.zmlx.hg4idea.repo.HgRepository -class HgBranchStateProvider(val project: Project, - val vcsManager: ProjectLevelVcsManager, - val repositoryManager: VcsRepositoryManager) : BranchStateProvider { +internal class HgBranchStateProvider(val project: Project) : BranchStateProvider { override fun getCurrentBranch(path: FilePath): BranchData? { - if (!vcsManager.checkVcsIsActive(HgVcs.VCS_NAME)) return null + if (!ProjectLevelVcsManager.getInstance(project).checkVcsIsActive(HgVcs.VCS_NAME)) { + return null + } - val repository = findValidParentAccurately(path)?.let { repositoryManager.getRepositoryForFile(it, true) } as? HgRepository + val repository = findValidParentAccurately(path)?.let { VcsRepositoryManager.getInstance(project).getRepositoryForFile(it, true) } as? HgRepository return repository?.let { BranchDataImpl(it.root.presentableName, it.currentBranchName) } } } \ No newline at end of file