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

📄 rewritervisitor.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			handleCommentAfter(lastNode);

		printer.printNewlineAndIndentation();

		visit(node, node.body);

		return null;
	}

	public Object visitGeneratorExp(GeneratorExp node) throws Exception {
		printer.openParentheses(node);
		visit(node.elt);
		visit(node, node.generators, false, false);
		return null;
	}

	public Object visitGlobal(Global node) throws Exception {
		printer.printStatementGlobal();
		visitWithSeparator(node, node.names);
		return null;
	}

	public Object visitIf(If node) throws Exception {

		printer.printStatementIf(node, false, true);

		printer.openParentheses(node);
		super.visit(node.test);
		printer.closeParentheses(node);
		printer.printFunctionMarker();
		printer.indent();
		handleCommentAfter(node.test);

		printer.printNewlineAndIndentation();
		if (isFilledList(node.body))
			handleCommentBeforeBody(node, node.body[0]);

		if (isFilledList(node.body))
			handleCommentAfterBody(node, visit(node, node.body));

		handleIfElse(node);
		
		return null;
	}

	public Object visitIfExp(IfExp node) throws Exception {
		super.visit(node.body);

		printer.printStatementIf(node, true, true);
		printer.openParentheses(node.test);
		super.visit(node.test);
		printer.closeParentheses(node.test);

		if (node.orelse != null) {
			printer.printStatementElseWithSpace();
			super.visit(node.orelse);
		}

		return null;

	}

	public Object visitImport(Import node) throws Exception {
		printer.printStatementImport();
		visitWithSeparator(node, node.names);
		return null;
	}

	public Object visitImportFrom(ImportFrom node) throws Exception {

		handleCommentBefore(node.module);
		printer.printStatementFrom();
		super.visit(node.module);
		printer.printStatementFromImport();

		if (isFilledList(node.names))
			visitWithSeparator(node, node.names);
		else
			printer.printBinOp(BinOp.Mult, false, false);

		return null;
	}

	public Object visitIndex(Index node) throws Exception {
		visit(node.value);
		return null;
	}

	public Object visitInteractive(Interactive node) throws Exception {
		handleRootNode(node, node.body);
		return null;
	}

	public exprType visitKeyValue(SimpleNode parent, exprType[] keys, exprType[] values) throws Exception {
		return handleKeyValueArgs(parent, keys, values);
	}

	@Override
	public Object visitKeywordType(keywordType node) throws Exception {
		SimpleNode lastNode = visit(node.arg);
		printer.printAssignmentOperator(false, false);
		if (node.value != null)
			lastNode = visit(node.value);
		return lastNode;
	}

	public Object visitLambda(Lambda node) throws Exception {
		printer.printstatementLambda();
		setPreviousNode(node);
		visit(node.args);
		setPreviousNode(node);
		printer.printFunctionMarkerWithSpace();
		visit(node.body);
		return null;

	}

	public Object visitList(List node) throws Exception {
		if (isFilledList(node.elts)) {
			handleCommentBefore(node.elts[0]);
		}
		printer.openBracket(node);
		printer.setIgnoreComments(true);
		SimpleNode lastNode = visitWithSeparator(node, node.elts);
		printer.setIgnoreComments(false);
		printer.closeBracket(node);

		handleCommentAfter(lastNode);
		return null;
	}

	public Object visitListComp(ListComp node) throws Exception {
		if (!inCall())
			printer.openParentheses(node);
		printer.openBracket(node);
		visit(node.elt);
		visit(node, node.generators, false, false);
		printer.closeBracket(node);
		if (!inCall())
			printer.closeParentheses(node);
		return null;
	}

	public Object visitListCompType(listcompType node) throws Exception {
		SimpleNode lastNode = visit(node.target);
		if (node.iter != null)
			lastNode = visit(node.iter);
		if (isFilledList(node.ifs)) {
			lastNode = visit(node, node.ifs, false, false);
		}
		return lastNode;
	}

	public Object visitModule(Module node) throws Exception {
		handleRootNode(node, node.body);
		return null;
	}

	public Object visitName(Name node) throws Exception {
		printer.print(node.id);
		return null;
	}

	public Object visitNameTok(NameTok node) throws Exception {
		printer.print(node.id);
		return null;
	}

	public Object visitNum(Num node) throws Exception {
		printer.printNum(node);
		return null;
	}

	public Object visitPass(Pass node) throws Exception {
		printer.printStatementPass();
		return null;
	}

	public Object visitPrint(Print node) throws Exception {
		printer.printStatementPrint();
		if (node.dest != null) {
			printer.printDestinationOperator(false, true);
			visit(node.dest);
			if (isFilledList(node.values)) {
				printer.printListSeparator();
			}
		}
		visitWithSeparator(node, node.values);

		return null;
	}

	public Object visitRaise(Raise node) throws Exception {
		printer.printStatementRaise(node.type != null);
		visit(node.type);
		if (node.inst != null) {
			printer.printListSeparator();
			visit(node.inst);
		}
		if (node.tback != null) {
			printer.printListSeparator();
			visit(node.tback);
		}

		return null;
	}

	public Object visitRepr(Repr node) throws Exception {
		handleCommentBefore(node);
		printer.printReprQuote();
		super.visit(node.value);
		printer.printReprQuote();
		handleCommentAfter(node);
		return null;
	}

	public Object visitReturn(Return node) throws Exception {
		printer.printStatementReturn();
		visit(node.value);
		return null;
	}

	public Object visitSlice(Slice node) throws Exception {
		visit(node.lower);
		printer.printFunctionMarker();
		visit(node.upper);
		if (node.step != null) {
			printer.printFunctionMarker();
			visit(node.step);
		}
		return null;

	}

	public Object visitStr(Str node) throws Exception {
		printer.printStr(node);
		return null;
	}

	public Object visitStrJoin(StrJoin node) throws Exception {
		visitWithSeparator(node, node.strs);
		return null;
	}

	public Object visitSubscript(Subscript node) throws Exception {
		visit(node.value);
		printer.openBracket(node);
		visit(node.slice);
		printer.closeBracket(node);
		return null;
	}

	public Object visitSuite(Suite node) throws Exception {
		handleRootNode(node, node.body);
		return null;
	}

	public Object visitSuiteType(suiteType node) throws Exception {
		if (node != null) {
			if (!(printer.getNodeHelper().isTryFinallyStatement(getPreviousNode()))) {
				printer.printNewlineAndIndentation();
				printer.printStatementElse();

				printer.printFunctionMarker();

			}
			if (isFilledList(node.body))
				handleCommentBeforeBody(node, node.body[0]);

			printer.indent();
			printer.printNewlineAndIndentation();
			SimpleNode lastNode = visit(node, node.body);
			if (isFilledList(node.body))
				handleCommentAfterBody(node, lastNode);
		}
		return null;
	}

	public Object visitTryExcept(TryExcept node) throws Exception {
		handleTryBody(node, node.body);

		visitExceptionHandlers(node);

		visitSuiteType(node.orelse);

		return null;
	}

	public Object visitTryFinally(TryFinally node) throws Exception {
		handleTryBody(node, node.body);

		if (node.finalbody != null) {
			printer.printNewlineAndIndentation();
			handleCommentBefore(node.finalbody);

			printer.printStatementFinally();
			printer.printFunctionMarker();

			setPreviousNode(node);
			visitSuiteType(node.finalbody);
		}

		return null;
	}

	public Object visitTuple(Tuple node) throws Exception {
		if (isFilledList(node.elts)) {
			handleCommentBefore(node.elts[0]);
		}
		printer.openParentheses(node);
		printer.setIgnoreComments(true);
		SimpleNode lastNode = visitWithSeparator(node, node.elts);
		printer.setIgnoreComments(false);
		printer.closeParentheses(node);

		handleCommentAfter(lastNode);
		return null;
	}

	public Object visitUnaryOp(UnaryOp node) throws Exception {
		if (node.operand != null) {
			printer.printUnaryOp(node.op);
			visit(node.operand);
		}
		return null;

	}

	public Object visitWhile(While node) throws Exception {
		printer.printStatementWhile();
		printer.openParentheses(node);
		super.visit(node.test);
		printer.closeParentheses(node);
		printer.printFunctionMarker();
		if (isFilledList(node.body))
			handleCommentBeforeBody(node.test, node.body[0]);

		printer.indent();
		printer.printNewlineAndIndentation();
		visit(node, node.body);

		visitSuiteType(node.orelse);

		return null;
	}

	public Object visitWith(With node) throws Exception {
		SimpleNode lastNode = node.context_expr;

		printer.printStatementWith();
		printer.openParentheses(node.context_expr);
		super.visit(node.context_expr);
		printer.closeParentheses(node.context_expr);

		if (node.optional_vars != null) {
			printer.printStatementAs();
			super.visit(node.optional_vars);
			lastNode = node.optional_vars;
		}
		printer.printFunctionMarker();
		printer.indent();
		handleCommentAfter(lastNode);

		printer.printNewlineAndIndentation();

		visit(node, node.body.body);

		return null;
	}

	private SimpleNode visitWithSeparator(SimpleNode parent, SimpleNode[] body) throws Exception {
		return visit(parent, body, false, true);
	}

	public Object visitYield(Yield node) throws Exception {
		handleCommentBefore(node.value);
		printer.printStatementYield();
		super.visit(node.value);
		handleCommentAfter(node.value);
		return null;
	}





}

⌨️ 快捷键说明

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