provide non-injection-aware version of PsiComment in core

This commit is contained in:
Dmitry Jemerov
2011-10-27 19:00:27 +02:00
parent 0bf59359e9
commit cb4f2e7864
6 changed files with 65 additions and 40 deletions

View File

@@ -16,6 +16,8 @@
package com.intellij.psi.impl.source.tree;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.DefaultASTFactory;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl;
import com.intellij.psi.impl.source.javadoc.PsiDocTokenImpl;
@@ -30,6 +32,8 @@ import com.intellij.psi.tree.java.IJavaElementType;
* @author max
*/
public class JavaASTFactory extends ASTFactory implements Constants {
private final DefaultASTFactory myDefaultASTFactory = ServiceManager.getService(DefaultASTFactory.class);
@Override
public CompositeElement createComposite(final IElementType type) {
if (type == DOC_TAG_VALUE_TOKEN) {
@@ -42,7 +46,7 @@ public class JavaASTFactory extends ASTFactory implements Constants {
@Override
public LeafElement createLeaf(final IElementType type, final CharSequence text) {
if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) {
return new PsiCommentImpl(type, text);
return myDefaultASTFactory.createComment(type, text);
}
else if (type == IDENTIFIER) {
return new PsiIdentifierImpl(text);

View File

@@ -15,8 +15,7 @@
*/
package com.intellij.core;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.DefaultASTFactory;
import com.intellij.lang.*;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IFileElementType;
@@ -49,7 +48,19 @@ public class CoreASTFactory extends ASTFactory implements DefaultASTFactory {
@Override
@NotNull
public LeafElement createLeaf(IElementType type, CharSequence text) {
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 createComment(type, text);
}
}
return new LeafPsiElement(type, text);
}
public LeafElement createComment(IElementType type, CharSequence text) {
return new PsiCoreCommentImpl(type, text);
}
}

View File

@@ -15,10 +15,14 @@
*/
package com.intellij.lang;
import com.intellij.psi.impl.source.tree.LeafElement;
import com.intellij.psi.tree.IElementType;
/**
* Marker interface for retrieving the service which provides a default implementation of ASTFactory.
*
* @author yole
*/
public interface DefaultASTFactory {
LeafElement createComment(IElementType type, CharSequence text);
}

View File

@@ -0,0 +1,37 @@
package com.intellij.psi.impl.source.tree;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class PsiCoreCommentImpl extends LeafPsiElement implements PsiComment {
public PsiCoreCommentImpl(IElementType type, CharSequence text) {
super(type, text);
}
@Override
public IElementType getTokenType() {
return getElementType();
}
@Override
public void accept(@NotNull PsiElementVisitor visitor){
visitor.visitComment(this);
}
public String toString(){
return "PsiComment(" + getElementType().toString() + ")";
}
@Override
@NotNull
public PsiReference[] getReferences() {
return ReferenceProvidersRegistry.getReferencesFromProviders(this, PsiComment.class);
}
}

View File

@@ -19,20 +19,9 @@ import com.intellij.core.CoreASTFactory;
import com.intellij.psi.impl.source.tree.LeafElement;
import com.intellij.psi.impl.source.tree.PsiCommentImpl;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class DefaultASTFactoryImpl extends CoreASTFactory implements DefaultASTFactory {
@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 super.createLeaf(type, text);
public LeafElement createComment(IElementType type, CharSequence text) {
return new PsiCommentImpl(type, text);
}
}

View File

@@ -16,31 +16,17 @@
package com.intellij.psi.impl.source.tree;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.LiteralTextEscaper;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.impl.source.tree.injected.CommentLiteralEscaper;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class PsiCommentImpl extends LeafPsiElement implements PsiComment, PsiLanguageInjectionHost {
public class PsiCommentImpl extends PsiCoreCommentImpl implements PsiLanguageInjectionHost {
public PsiCommentImpl(IElementType type, CharSequence text) {
super(type, text);
}
@Override
public IElementType getTokenType() {
return getElementType();
}
@Override
public void accept(@NotNull PsiElementVisitor visitor){
visitor.visitComment(this);
}
public String toString(){
return "PsiComment(" + getElementType().toString() + ")";
}
@Override
public boolean isValidHost() {
return true;
@@ -51,12 +37,6 @@ public class PsiCommentImpl extends LeafPsiElement implements PsiComment, PsiLan
return (PsiCommentImpl)replaceWithText(text);
}
@Override
@NotNull
public PsiReference[] getReferences() {
return ReferenceProvidersRegistry.getReferencesFromProviders(this, PsiComment.class);
}
@Override
@NotNull
public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() {