如果我使用前/后模板使用
获取以下值将生成以下代码(Eclipse 4.2)
01 public static String[] c = new String[]{"hi"};
02 public static void test() {
03 String[] a = new String[]{"hi"};
04 int[] b = new int[]{2};
05 for (String string : a) {
06 // 1. fine
07 }
08 for (int i : b) {
09 // 2. fine too
10 }
11 for (iterable_type iterable_element : c) {
12 // 3. not resolved?
13 }
14 }
现在的问题是:
c
无法解析它的数组类型和名称?答案 0 :(得分:1)
在while的模板中,
while (${condition:var(boolean)}) {
${line_selection}${cursor}
}
${condition:var(boolean)}
确实匹配成员和静态成员。
请注意,var的content-assist说:
$ {ID:VAR(式[,类型] *)} 评估字段,局部变量或参数 在当前作用域中可见,它是任何子类型 给定类型。如果没有指定类型,则任何非类型 原始变量匹配。
在foreach的模板中,模板变量是不同的:
for (${iterable_type} ${iterable_element} : ${iterable}) {
${cursor}
}
${iterable}
变量的文档说明:
可迭代的提议(数组或 java.lang.Iterable)
没有具体说明是否应该提出(静态)成员。
$ {iterable}评估当前范围内可见的可迭代或数组的提议。
所以根据文档,这可能实际上是一个错误。实际上已经报告了here。