我有一个xml,其中包含我想用velocity生成的类的描述,格式如下:
<Class name="name">
<Attribute name="name" type="typeName"/>
...
<Method name="name" type="typeName"/>
</Class>
模板的代码是:
public class $class.Name implements NodeIface {
#foreach($att in $class.Attributes)
private $att.Type $att.name;
public $att.Type get$utility.firstToUpperCase($att.Name)() {
return this.$att.Name;
}
public void set$utility.firstToUpperCase($att.Name)($att.Type $att.Name) {
this.$att.Name = $att.Name;
}
#end
#foreach($mtd in $class.Methods)
if($class.Name == "name") {
public $mtd.Name() {
this.$att.Name = new $att.Type(Constants.SERVER_PORT, classNameHandler.class); //here lies the error
}
@Override
public $mtd.Type $mtd.Name() throws TException {
TSocket $att.Name = new TSocket("localhost", Constants.SERVER_PORT);
TBinaryProtocol $att.Name = new TBinaryProtocol($att.Name);
managementClient = new ManagementService.Client($att.Name);
this.setDispatcher(new OperationDispatcher($att.Name));
arithmeticServerTransport.open();
$att.Name.start();
$att.Name = new $att.Type($att.Name);
PortNegotiator negotiator = new PortNegotiator($att.Name);
negotiator.negotiate($att.Type, $att.Name);
}
@Override
public $mtd.Type $mtd.Name() {
$att.Name.stop();
}
}
else if ($class.Name == "GreetingsNode") {
public $mtd.Name();
this.$att.Name = new $att.Type((Constants.SERVER_PORT, GreetingsServiceHandler.class));
}
#Override
public $mtd.Type $mtd.Name() throws TException {
TSocket $att.Name = new TSocekt("localhost", Constants.SERVER_PORT);
TBinaryProtocol $att.Name = new TBinaryProtocol($att.Name);
$att.Name = new ManagementService.Client($att.Name);
this.SetUser(new User($att.Name);
this.setMessenger(new MessageDispatcher($att.Name));
$att.Name.open()
$att.Name = new $att.Type($att.Name);
PortNegotiator negotiator = new PortNegotiator($att.Name);
negotiator.negotiate($att.Type, $att.Name);
}
@Override
public $mtd.Type $mtd.Name() {
$att.Name.stop();
}
#End
Eclipse的速度文本编辑器告诉我这条消息有错误:&#34;遇到&#34;); \ r \ n \ t \ t} \ r \ n \ t \ t \ r \ n \ t \ t @ Override \ r \ n \ t \ tpublic&#34;在Class.vm [第23行,第86栏] 期待以下之一: &#34; [&#34; ... &#34;&#34; ... &#34;)&#34; ... ...&#34;
这是什么意思?
答案 0 :(得分:1)
这是您需要使用formal reference notation:
的情况 this.$att.Name = new ${att.Type}(Constants.SERVER_PORT, classNameHandler.class);
否则Velocity解析器会认为您正试图在$att.Type
对象上调用方法。