[Pydev-cvs] org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/rewriter RewriterVis
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2007-06-11 00:24:14
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/rewriter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2121/src/org/python/pydev/refactoring/ast/rewriter Modified Files: RewriterVisitor.java Log Message: Some failing tests added and checking if the contributed PrettyPrinter may be able to work around those... Index: RewriterVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/rewriter/RewriterVisitor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RewriterVisitor.java 27 Feb 2007 12:24:55 -0000 1.2 --- RewriterVisitor.java 11 Jun 2007 00:24:13 -0000 1.3 *************** *** 1,4 **** --- 1,6 ---- package org.python.pydev.refactoring.ast.rewriter; + import java.io.StringWriter; + import java.io.Writer; import java.util.Arrays; import java.util.Collections; *************** *** 69,73 **** --- 71,79 ---- import org.python.pydev.parser.jython.ast.stmtType; import org.python.pydev.parser.jython.ast.suiteType; + import org.python.pydev.parser.prettyprinter.PrettyPrinter; + import org.python.pydev.parser.prettyprinter.PrettyPrinterPrefs; + import org.python.pydev.parser.prettyprinter.WriterEraser; import org.python.pydev.refactoring.ast.printer.SourcePrinter; + import org.python.pydev.refactoring.ast.visitors.VisitorFactory; /** *************** *** 79,84 **** */ public class RewriterVisitor extends AbstractRewriterVisitor { ! public RewriterVisitor(SourcePrinter printer) { super(printer); } --- 85,168 ---- */ public class RewriterVisitor extends AbstractRewriterVisitor { + + //------------------------------------------------------------------------------------------------- public interface ! //REWRITER INTERFACE FOR CURRENT VERSION --------------------------------------------------------------------------- ! public static String reparsed(String source, String string) { ! StringWriter out = new StringWriter(); ! createRewriterVisitor(out, source, "\n"); ! return out.getBuffer().toString(); ! } ! ! public static String createSourceFromAST(SimpleNode root, boolean ignoreComments, String newLineDelim) { ! RewriterVisitor visitor = null; ! StringWriter writer = new StringWriter(); ! try { ! visitor = new RewriterVisitor(VisitorFactory.createPrinter(writer, newLineDelim)); ! visitor.setIgnoreComments(ignoreComments); ! visitor.visit(root); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! visitor.flush(); ! return writer.getBuffer().toString(); ! } ! ! public static String createSourceFromAST(SimpleNode root, String newLineDelim) { ! return createSourceFromAST(root, false, newLineDelim); ! } ! ! private static RewriterVisitor createRewriterVisitor(Writer out, String source, String newLineDelim) { ! RewriterVisitor visitor = null; ! try { ! SimpleNode root = VisitorFactory.getRootNodeFromString(source); ! visitor = new RewriterVisitor(VisitorFactory.createPrinter(out, newLineDelim)); ! root.accept(visitor); ! } catch (Throwable e) { ! throw new RuntimeException(e); ! } ! visitor.flush(); ! return visitor; ! } ! ! //END REWRITER INTERFACE FOR CURRENT VERSION ----------------------------------------------------------------------- ! ! ! // public static String reparsed(String source, String delimiter) { ! // try { ! // SimpleNode root = VisitorFactory.getRootNodeFromString(source); ! // return createSourceFromAST(root, delimiter); ! // } catch (Throwable e) { ! // throw new RuntimeException(e); ! // } ! // ! // } ! // ! // public static String createSourceFromAST(SimpleNode root, String newLineDelim) { ! // return createSourceFromAST(root, false, newLineDelim); ! // } ! // ! // ! // public static String createSourceFromAST(SimpleNode root, boolean ignoreComments, String newLineDelim) { ! // final WriterEraser stringWriter = new WriterEraser(); ! // PrettyPrinterPrefs prettyPrinterPrefs = new PrettyPrinterPrefs(newLineDelim); ! // prettyPrinterPrefs.setSpacesAfterComma(1); ! // prettyPrinterPrefs.setSpacesBeforeComment(1); ! // PrettyPrinter printer = new PrettyPrinter(prettyPrinterPrefs, stringWriter); ! // try { ! // root.accept(printer); ! // return stringWriter.getBuffer().toString(); ! // } catch (Exception e) { ! // throw new RuntimeException(e); ! // } ! // ! // } ! ! ! ! //--------------------------------------------------------------------------------------------- end public interface ! ! ! private RewriterVisitor(SourcePrinter printer) { super(printer); } *************** *** 716,719 **** --- 800,804 ---- public Object visitIf(If node) throws Exception { + printer.printStatementIf(false, true); *************** *** 733,737 **** handleIfElse(node); ! return null; } --- 818,822 ---- handleIfElse(node); ! return null; } *************** *** 1074,1076 **** --- 1159,1165 ---- } + + + + } |