⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplenodecomparator.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
字号:
/*
 * Created on Apr 3, 2006
 */
package org.python.pydev.parser.visitors.comparator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.VisitorBase;
import org.python.pydev.parser.visitors.NodeUtils;

class FlatVisitor extends VisitorBase{

    List<SimpleNode> visited = new ArrayList<SimpleNode>();
    
    @Override
    protected Object unhandled_node(SimpleNode node) throws Exception {
        visited.add(node);
        //System.out.println("adding:"+node.getClass().getName());
        return null;
    }

    @Override
    public void traverse(SimpleNode node) throws Exception {
        node.traverse(this);
    }
    
}

public class SimpleNodeComparator {

    public void compare(SimpleNode original, SimpleNode newNode) throws Exception, DifferException {
        FlatVisitor flatVisitorOriginal = new FlatVisitor();
        flatVisitorOriginal.traverse(original);

        FlatVisitor flatVisitor = new FlatVisitor();
        flatVisitor.traverse(original);
        
        Iterator<SimpleNode> it = flatVisitorOriginal.visited.iterator();
        Iterator<SimpleNode> it2 = flatVisitor.visited.iterator();
        
        while(it.hasNext() && it2.hasNext()){
            SimpleNode node = it.next();
            SimpleNode node2 = it2.next();
            if(node.getClass() != node2.getClass()){
                throw new DifferException("Nodes differ. "+node.getClass().getName()+" != "+ node2.getClass().getName());
            }
            String s1 = NodeUtils.getFullRepresentationString(node);
            String s2 = NodeUtils.getFullRepresentationString(node2);
            if((s1 == null && s2 != null) || (s1 != null && s2 == null)){
                throw new DifferException("Nodes differ. (s1 == null && s2 != null) || (s1 != null && s2 == null)");
            }
            if(s1 == s2){ //null
                continue;
            }
            if(s1.equals(s2.replaceAll("\r", "")) == false){
                throw new DifferException("Nodes differ. s1 != s2 \n-->"+ s1 +"<--\n!=\n-->"+ s2 +"<--");
            }
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -