Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Xtend/Xpand查找和替换(规则)_Java_Loops_Xtext_Xtend_Xpand - Fatal编程技术网

Java Xtend/Xpand查找和替换(规则)

Java Xtend/Xpand查找和替换(规则),java,loops,xtext,xtend,xpand,Java,Loops,Xtext,Xtend,Xpand,是否可以设置一个规则,允许Xpand方法根据输入输出指定的文本字符串。例如: «FOR a:e.attributes» Type = «a.eClass.name» Value = «a.name.toFirstUpper» «ENDFOR» 上述代码可以输出: Type = StringAttribute Value = String1 Type = IntegerAttribute Value = 123 如何生成此输出: Type = String Value = String

是否可以设置一个规则,允许Xpand方法根据输入输出指定的文本字符串。例如:

«FOR a:e.attributes»
 Type = «a.eClass.name»
 Value = «a.name.toFirstUpper»

«ENDFOR»
上述代码可以输出:

Type = StringAttribute
Value = String1

Type = IntegerAttribute
Value = 123
如何生成此输出:

Type = String
Value = String1

Type = int
Value = 123

我知道这可以用if语句来完成,但我希望它或多或少是自动的。每次我需要在同一个文件中输出这些细节时,都必须指定这样的规则,这将是一种浪费。有人能告诉我什么样的代码可以实现这一点吗?谢谢。

我建议您创建一个可重用的助手

然后从Xpand模板调用它,如下所示:

«FOR a:e.attributes»
 Type = «a.eClass.name.toSimpleName()»
 Value = «a.name.toFirstUpper»

«ENDFOR»

非常感谢你。没有我想象的那么难。虽然我不得不稍微更改代码,使其在Xtend中有效:
def-toJavaType(String-inp){switch(inp){case“NumberAttribute”:“String”case“StringAttribute”:“int”default:}
«FOR a:e.attributes»
 Type = «a.eClass.name.toSimpleName()»
 Value = «a.name.toFirstUpper»

«ENDFOR»