This commit is contained in:
Roman Shevchenko
2010-09-07 13:54:55 +04:00
parent ceefb5ea61
commit 4bfd9aec32
5 changed files with 15 additions and 14 deletions
@@ -1004,13 +1004,13 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
final PsiErrorElement e1 = (PsiErrorElement)oldNode;
return Comparing.equal(e1.getErrorDescription(), getErrorMessage(newNode)) ? ThreeState.UNSURE : ThreeState.NO;
}
if (newNode instanceof Token) {
if (oldNode instanceof ForeignLeafPsiElement) {
final IElementType type = newNode.getTokenType();
return type instanceof ForeignLeafType && ((ForeignLeafType)type).getValue().equals(oldNode.getText())
? ThreeState.YES
: ThreeState.NO;
? ThreeState.YES
: ThreeState.NO;
}
if (oldNode instanceof LeafElement) {
@@ -1045,7 +1045,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
return probablyWrapper;
}
public boolean hashcodesEqual(final ASTNode n1, final LighterASTNode n2) {
public boolean hashCodesEqual(final ASTNode n1, final LighterASTNode n2) {
if (n1 instanceof LeafElement && n2 instanceof Token) {
if (n1 instanceof ForeignLeafPsiElement && n2.getTokenType() instanceof ForeignLeafType) {
return n1.getText().equals(((ForeignLeafType)n2.getTokenType()).getValue());
@@ -56,7 +56,7 @@ public class ASTShallowComparator implements ShallowNodeComparator<ASTNode, ASTN
return n1.getElementType() == n2.getElementType();
}
public boolean hashcodesEqual(final ASTNode n1, final ASTNode n2) {
public boolean hashCodesEqual(final ASTNode n1, final ASTNode n2) {
if (n1 instanceof LeafElement && n2 instanceof LeafElement) {
return textMatches(n1, n2) == ThreeState.YES;
}
@@ -36,9 +36,9 @@ public class DiffTree<OT, NT> {
private final List<Ref<NT[]>> myNewChildrenLists = new ArrayList<Ref<NT[]>>();
private DiffTree(final FlyweightCapableTreeStructure<OT> oldTree,
final FlyweightCapableTreeStructure<NT> newTree,
final ShallowNodeComparator<OT, NT> comparator,
final DiffTreeChangeBuilder<OT, NT> consumer) {
final FlyweightCapableTreeStructure<NT> newTree,
final ShallowNodeComparator<OT, NT> comparator,
final DiffTreeChangeBuilder<OT, NT> consumer) {
myOldTree = oldTree;
myNewTree = newTree;
@@ -46,7 +46,10 @@ public class DiffTree<OT, NT> {
myConsumer = consumer;
}
public static <OT, NT> void diff(FlyweightCapableTreeStructure<OT> oldTree, FlyweightCapableTreeStructure<NT> newTree, ShallowNodeComparator<OT, NT> comparator, DiffTreeChangeBuilder<OT, NT> consumer) {
public static <OT, NT> void diff(final FlyweightCapableTreeStructure<OT> oldTree,
final FlyweightCapableTreeStructure<NT> newTree,
final ShallowNodeComparator<OT, NT> comparator,
final DiffTreeChangeBuilder<OT, NT> consumer) {
new DiffTree<OT, NT>(oldTree, newTree, comparator, consumer).build(oldTree.getRoot(), newTree.getRoot(), 0);
}
@@ -57,7 +60,6 @@ public class DiffTree<OT, NT> {
NOT_EQUAL, // 100% different
}
// TODO: disposeChildren
private void build(OT oldN, NT newN, int level) {
OT oldNode = myOldTree.prepareForGetChildren(oldN);
NT newNode = myNewTree.prepareForGetChildren(newN);
@@ -87,7 +89,7 @@ public class DiffTree<OT, NT> {
final ShallowNodeComparator<OT, NT> comparator = myComparator;
if (oldSize == 0 && newSize == 0) {
if (!comparator.hashcodesEqual(oldNode, newNode) || !comparator.typesEqual(oldNode, newNode)) {
if (!comparator.hashCodesEqual(oldNode, newNode) || !comparator.typesEqual(oldNode, newNode)) {
myConsumer.nodeReplaced(oldNode, newNode);
}
return;
@@ -22,8 +22,7 @@ import com.intellij.util.ThreeState;
* @author max
*/
public interface ShallowNodeComparator<OT, NT> {
ThreeState deepEqual(OT oldNode, NT newNode);
boolean typesEqual(OT oldNode, NT newNode);
boolean hashcodesEqual(OT oldNode, NT newNode);
boolean hashCodesEqual(OT oldNode, NT newNode);
}
@@ -90,7 +90,7 @@ public class DiffTreeTest extends TestCase {
return node.getId() == node1.getId();
}
public boolean hashcodesEqual(final Node node, final Node node1) {
public boolean hashCodesEqual(final Node node, final Node node1) {
return node.hashCode() == node1.hashCode();
}
}