get rid of constructor injection - part 7

This commit is contained in:
Vladimir Krivosheev
2019-03-28 09:51:00 +01:00
parent bbbcd74f2b
commit 9dbec9bae8
5 changed files with 42 additions and 74 deletions
+2 -4
View File
@@ -48,15 +48,11 @@
<xi:fallback/>
</xi:include>
<application-components>
<component>
<interface-class>com.intellij.openapi.vfs.jrt.JrtFileSystem</interface-class>
<implementation-class>com.intellij.openapi.vfs.impl.jrt.JrtFileSystemImpl</implementation-class>
</component>
<component>
<implementation-class>com.intellij.util.xml.impl.JavaDomApplicationComponent</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.projectRoots.JavaSdk</interface-class>
<implementation-class>com.intellij.openapi.projectRoots.impl.JavaSdkImpl</implementation-class>
@@ -1929,6 +1925,8 @@
<fileTypeDetector implementation="com.intellij.openapi.fileTypes.impl.JavaFileTypeDetector"/>
<searchEverywhereResultsEqualityProvider implementation="com.intellij.ide.JavaClassAndFileEqualityProvider"/>
<applicationInitializedListener implementation="com.intellij.util.xml.impl.JavaDomApplicationComponent$Initializer"/>
</extensions>
<extensions defaultExtensionNs="org.jetbrains">
@@ -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<DomUIFactory> {
public JavaDomApplicationComponent(ConverterManager converterManager) {
converterManager.addConverter(PsiClass.class, new PsiClassConverter());
converterManager.addConverter(PsiType.class, new CanonicalPsiTypeConverterImpl());
final class JavaDomApplicationComponent implements Consumer<DomUIFactory> {
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
@@ -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<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> 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<PsiElement> manipulator = ElementManipulators.getManipulator(operand);
if (manipulator == null) {
unparsable = true;
prefix += getStringPresentation(operand);
prefix.append(getStringPresentation(operand));
if (i == myOperands.length - 1) {
Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange> 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<String> getAnnotatedElementsValue() {
private static Collection<String> getAnnotatedElementsValue(@NotNull Project project) {
// note: external annotations not supported
return InjectionCache.getInstance(myProject).getAnnoIndex();
return InjectionCache.getInstance(project).getAnnoIndex();
}
private Collection<String> getXmlAnnotatedElementsValue() {
return InjectionCache.getInstance(myProject).getXmlIndex();
private static Collection<String> getXmlAnnotatedElementsValue(@NotNull Project project) {
return InjectionCache.getInstance(project).getXmlIndex();
}
}
@@ -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<HgRepository> {
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();
}
@@ -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) }
}
}