mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
to remove the dependency on PsiCommentImpl, register the default ASTFactory implementation as a service
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.lang;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.impl.source.CharTableImpl;
|
||||
import com.intellij.psi.impl.source.CodeFragmentElement;
|
||||
@@ -30,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author max
|
||||
*/
|
||||
public abstract class ASTFactory {
|
||||
public static final DefaultFactory DEFAULT = new DefaultFactory();
|
||||
public static final ASTFactory DEFAULT = (ASTFactory) ServiceManager.getService(DefaultASTFactory.class);
|
||||
|
||||
private static final CharTable WHITESPACES = new CharTableImpl();
|
||||
|
||||
@@ -103,42 +104,4 @@ public abstract class ASTFactory {
|
||||
CodeEditUtil.setNodeGenerated(w, true);
|
||||
return w;
|
||||
}
|
||||
|
||||
// default implementation
|
||||
|
||||
private static class DefaultFactory extends ASTFactory {
|
||||
@Override
|
||||
@NotNull
|
||||
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
|
||||
if (type instanceof IFileElementType) {
|
||||
return new FileElement(type, text);
|
||||
}
|
||||
|
||||
return new LazyParseableElement(type, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CompositeElement createComposite(final IElementType type) {
|
||||
if (type instanceof IFileElementType) {
|
||||
return new FileElement(type, null);
|
||||
}
|
||||
|
||||
return new CompositeElement(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LeafElement createLeaf(final IElementType type, final CharSequence text) {
|
||||
final Language lang = type.getLanguage();
|
||||
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
|
||||
if (parserDefinition != null) {
|
||||
if (parserDefinition.getCommentTokens().contains(type)) {
|
||||
return new PsiCommentImpl(type, text);
|
||||
}
|
||||
}
|
||||
|
||||
return new LeafPsiElement(type, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
*/
|
||||
package com.intellij.lang;
|
||||
|
||||
/**
|
||||
* Marker interface for retrieving the service which provides a default implementation of ASTFactory.
|
||||
*
|
||||
* @author yole
|
||||
*/
|
||||
public interface DefaultASTFactory {
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
*/
|
||||
package com.intellij.lang;
|
||||
|
||||
import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.ILazyParseableElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DefaultASTFactoryImpl extends ASTFactory implements DefaultASTFactory {
|
||||
@Override
|
||||
@NotNull
|
||||
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
|
||||
if (type instanceof IFileElementType) {
|
||||
return new FileElement(type, text);
|
||||
}
|
||||
|
||||
return new LazyParseableElement(type, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CompositeElement createComposite(final IElementType type) {
|
||||
if (type instanceof IFileElementType) {
|
||||
return new FileElement(type, null);
|
||||
}
|
||||
|
||||
return new CompositeElement(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LeafElement createLeaf(final IElementType type, final CharSequence text) {
|
||||
final Language lang = type.getLanguage();
|
||||
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
|
||||
if (parserDefinition != null) {
|
||||
if (parserDefinition.getCommentTokens().contains(type)) {
|
||||
return new PsiCommentImpl(type, text);
|
||||
}
|
||||
}
|
||||
|
||||
return new LeafPsiElement(type, text);
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,9 @@
|
||||
<applicationService serviceInterface="com.intellij.psi.impl.source.codeStyle.IndentHelper"
|
||||
serviceImplementation="com.intellij.psi.impl.source.codeStyle.IndentHelperImpl"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.lang.DefaultASTFactory"
|
||||
serviceImplementation="com.intellij.lang.DefaultASTFactoryImpl"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.conversion.ConversionService"
|
||||
serviceImplementation="com.intellij.conversion.impl.ConversionServiceImpl"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user