`
javatar
  • 浏览: 1680393 次
  • 性别: Icon_minigender_1
  • 来自: 杭州699号
社区版块
存档分类
最新评论

CommonTemplate完成DEBUG单步调试

    博客分类:
  • HTTL
阅读更多
CommonTemplate(http://www.commontemplate.org)的
Debug单步跟踪初始版完成, 可下载每日构建版本试用. (http://commontemplate.googlecode.com/svn/trunk/commontemplate/dist/)
将在后期TemplateEditor的eclipse插件中集成此Debug功能, 并做成策略接口,
当在eclipse环境中时自动适用插件集成,
在非图形系统中(纯文本模式,AWT未加载时)自动适用命令行,
否则使用swing图形界面. (现完成版为swing图形界面)
测试代码:
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.commontemplate.core.Context;
import org.commontemplate.core.Factory;
import org.commontemplate.engine.Engine;
import org.commontemplate.standard.ConfigurationSettings;
import org.commontemplate.tools.PropertiesConfigurationLoader;

public class OutTester {

	public static void main(String[] args) {
		// 定义数据
		Map model = new HashMap();
		model.put("allow", Boolean.valueOf(false));
		List users = new ArrayList();
		model.put("users", users);
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		try {
			users.add(new User(12, "liangfei", "liangfei0201@163.com", 10000, df.parse("2007-08-09")));
			users.add(new User(15, "zhangyong", "zhangyong@aaa.com", 25000, df.parse("2007-08-10")));
			users.add(new User(17, "bobo", "bobo@bbb.com", 95010, df.parse("2007-08-11")));
			users.add(new User(17, "lixudong", null, 25000, df.parse("2007-09-11")));
		} catch (ParseException e) {
			e.printStackTrace();
		}

		// 配置
		ConfigurationSettings config = PropertiesConfigurationLoader.loadConfiguration("commontemplate.properties");
		Factory factory = new Engine(config);
		// 执行模板
		Writer output = null;
		try {
			output = new OutputStreamWriter(System.out);
			Context context = factory.createContext(output);
			context.pushLocalContext(model);
			factory.getTemplate("out.ctl").render(context);
			context.clear();
			output.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (output != null) {
				try {
					output.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}

测试配置: commontemplate.properties
@extends=org/commontemplate/tools/commontemplate.properties
debug=true

测试模板: out.ctl
ttttt
${allow}
$breakpoint
$if{users != null && users.size > 0}
<table>
	$for{user: users}
	<tr>
		<td>${user.name}</td>
	</tr>
	$end
</table>
$end
$for{num: 1..3}
	${num}
$end

引擎遇到$breakpoint指令时, 弹出附件所示界面.
高亮显示当前运行的指令, 上下文中的变量.
点击"Step"单步运行,
点击"Step Over"单步越过块指令的内部指令运行(非块指令此按钮不可用),
点击"Resume"恢复正常运行(直到下一$breakpoint),
点击"Terminate"终止运行.

注: 当commontemplate.properties配置: debug=true 时才启用调试, 否则忽略$breakpoint指令以及其它debug指令.

尚未美化界面, 暂先保证功能实现.

JFrame未重用(每一步都创建窗口), 所以调试时会出现窗口闪动, 待完善.
  • 描述: 指令跟踪
  • 大小: 65.3 KB
分享到:
评论
4 楼 javatar 2008-04-24  
完成修改:
通过ThreadLocal将Debug窗口锁定, 一次调试过程复用同一个窗口, 不再出现闪烁.

已更新到每日构建jar包中:
http://commontemplate.googlecode.com/svn/trunk/commontemplate/dist/

或者用SVN下载开发目录:
svn checkout http://commontemplate.googlecode.com/svn/trunk/ commontemplate-read-only
直接导入项目到Eclipse中, 然后运行src/test/java/integration.OutTester进行测试.
3 楼 javatar 2008-04-22  
1. 加入Step Return, 使Step功能齐全(Into, Over, Return).
2. 加入变量类型框
3. 将UI风格设成与当前系统相同风格.
4. 按钮改成图片.
5. 显示时, 保持模块源的缩进格式.
6. 改为采用反显背景色提示当前运行指令所在位置, 使可以看到空白符.
2 楼 javatar 2008-04-21  
有朋友建议, 在调试过程中, 动态修改变量栈的值. (现在只能查看), 下一版本将考虑这个建议.
1 楼 jasongreen 2008-04-21  
so cool!

相关推荐

Global site tag (gtag.js) - Google Analytics