我想配置我的 Eclipse 首选项以允许我输入:
printf<CTRL+SPACE> (or ALT+/, or anything I use as a "Content Assist" sequence)
并得到这个:
System.out.printf("<BANANA>%n", <argument1>);
能够在 <BANANA>
之间进行 TAB 跳转和<argument1>
.
最后一部分很重要,TAB 跳转/替换。请注意,所选文本不包含保留的 %n 常量。
我想要知道这一点,我需要知道如何指定片段,如何使用内置变量并将其转换为 .epf
中的条目文件。
此外,Eclipse 似乎很聪明,可以从周围的上下文中找出我可能想要在某个位置使用哪个变量。可能是因为类型、线路接近程度等等。在定义片段时我自己可以控制吗?示例:
System.out.printf("<BANANA>%n", <argument1>);
// Make BANANA equal to the second public static final String from the top + " split"
// Make argument1 the closest Float in the current block or any other Double, anywhere
最佳答案
我需要在 .epf 文件中添加“类似”的内容:
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="java" deleted\="false" description\="System.out.printf" enabled\="true" name\="pf">System.out.printf("${Message}%n", ${argument1\:var}${cursor});</template></templates>
将光标放在第一个参数之后可以轻松添加最终参数2,...
缺少的是一种指定集合中选择的方法,例如“选择 %s、%d、%f、... 之一”
关于java - Eclipse `sysout` 片段/扩展为 System.out.printf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12188845/