This commit is contained in:
Mikhail Senkov
2012-07-24 15:51:39 +04:00
parent e9ee0ef6c8
commit f05916c5f2
3 changed files with 25 additions and 11 deletions
@@ -32,6 +32,6 @@ public class ForeignLeafType extends TokenWrapper implements ILeafElementType {
@Override
@NotNull
public ASTNode createLeafNode(CharSequence leafText) {
return new ForeignLeafPsiElement(getDelegate(), getValue());
return new ForeignLeafPsiElement(this, getValue());
}
}
@@ -1367,15 +1367,13 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder, AS
return ourAnyLanguageWhitespaceTokens.contains(n2.getTokenType()) ||
n2 instanceof Token && ((Token)n2).myBuilder.myWhitespaces.contains(n2.getTokenType());
}
IElementType n1t;
if (n1 instanceof ForeignLeafPsiElement)
n1t = ((ForeignLeafPsiElement)n1).getForeignType();
else
n1t = n1.getElementType();
return dereferenceToken(n1.getElementType()) == dereferenceToken(n2.getTokenType());
}
public static IElementType dereferenceToken(IElementType probablyWrapper) {
if (probablyWrapper instanceof TokenWrapper) {
return dereferenceToken(((TokenWrapper)probablyWrapper).getDelegate());
}
return probablyWrapper;
return Comparing.equal(n1t, n2.getTokenType());
}
@Override
@@ -19,13 +19,25 @@
*/
package com.intellij.psi.impl.source.tree;
import com.intellij.lang.ForeignLeafType;
import com.intellij.lang.TokenWrapper;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class ForeignLeafPsiElement extends LeafPsiElement {
public ForeignLeafPsiElement(IElementType type, CharSequence text) {
super(type, text);
private ForeignLeafType myForeignType;
public ForeignLeafPsiElement(ForeignLeafType type, CharSequence text) {
super(dereferenceElementType(type.getDelegate()), text);
myForeignType = type;
}
private static IElementType dereferenceElementType(IElementType type) {
while ( type instanceof TokenWrapper)
type = (( TokenWrapper ) type ).getDelegate();
return type;
}
@Override
@@ -63,6 +75,10 @@ public class ForeignLeafPsiElement extends LeafPsiElement {
return 0;
}
public ForeignLeafType getForeignType() {
return myForeignType;
}
@Override
public String toString() {
return "ForeignLeaf(" + getElementType() + ": " + getText() + ")";