From 540f792196c506a43fc9e62f522b47b159c9c4bd Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 8 Sep 2011 17:44:50 +0200 Subject: [PATCH] fix ASTFactory registration in ParsingTestCase --- .../src/com/intellij/lang/ASTFactory.java | 19 ++++++++++++++----- .../com/intellij/lang/LanguageASTFactory.java | 2 +- .../testFramework/ParsingTestCase.java | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/lang/ASTFactory.java b/platform/lang-impl/src/com/intellij/lang/ASTFactory.java index f22d3612a96e..ad03567f3303 100644 --- a/platform/lang-impl/src/com/intellij/lang/ASTFactory.java +++ b/platform/lang-impl/src/com/intellij/lang/ASTFactory.java @@ -31,8 +31,6 @@ import org.jetbrains.annotations.Nullable; * @author max */ public abstract class ASTFactory { - public static final ASTFactory DEFAULT = (ASTFactory) ServiceManager.getService(DefaultASTFactory.class); - private static final CharTable WHITESPACES = new CharTableImpl(); // interface methods @@ -67,7 +65,7 @@ public abstract class ASTFactory { } final LazyParseableElement customLazy = factory(type).createLazy(type, text); - return customLazy != null ? customLazy : DEFAULT.createLazy(type, text); + return customLazy != null ? customLazy : DefaultFactoryHolder.DEFAULT.createLazy(type, text); } @NotNull @@ -77,7 +75,7 @@ public abstract class ASTFactory { } final CompositeElement customComposite = factory(type).createComposite(type); - return customComposite != null ? customComposite : DEFAULT.createComposite(type); + return customComposite != null ? customComposite : DefaultFactoryHolder.DEFAULT.createComposite(type); } @NotNull @@ -91,7 +89,7 @@ public abstract class ASTFactory { } final LeafElement customLeaf = factory(type).createLeaf(type, text); - return customLeaf != null ? customLeaf : DEFAULT.createLeaf(type, text); + return customLeaf != null ? customLeaf : DefaultFactoryHolder.DEFAULT.createLeaf(type, text); } private static ASTFactory factory(final IElementType type) { @@ -104,4 +102,15 @@ public abstract class ASTFactory { CodeEditUtil.setNodeGenerated(w, true); return w; } + + public static class DefaultFactoryHolder { + public static final ASTFactory DEFAULT = def(); + + private static ASTFactory def() { + return (ASTFactory)ServiceManager.getService(DefaultASTFactory.class); + } + + private DefaultFactoryHolder() { + } + } } diff --git a/platform/lang-impl/src/com/intellij/lang/LanguageASTFactory.java b/platform/lang-impl/src/com/intellij/lang/LanguageASTFactory.java index ed82e8cd8815..4393dbbd9572 100644 --- a/platform/lang-impl/src/com/intellij/lang/LanguageASTFactory.java +++ b/platform/lang-impl/src/com/intellij/lang/LanguageASTFactory.java @@ -23,6 +23,6 @@ public class LanguageASTFactory extends LanguageExtension { public static final LanguageASTFactory INSTANCE = new LanguageASTFactory(); private LanguageASTFactory() { - super("com.intellij.lang.ast.factory", ASTFactory.DEFAULT); + super("com.intellij.lang.ast.factory", ASTFactory.DefaultFactoryHolder.DEFAULT); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java index b41745124b36..df6c8aae8134 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java @@ -97,6 +97,7 @@ public abstract class ParsingTestCase extends PlatformLiteFixture { myLanguage = myLanguage == null && myDefinitions != null && myDefinitions.length > 0? myDefinitions[0].getFileNodeType().getLanguage() : myLanguage; registerComponentInstance(appContainer, FileTypeManager.class, new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt))); registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl()); + registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl()); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); myProject.registerService(PsiManager.class, myPsiManager); myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));