java - Eclipse `sysout` 片段/扩展为 System.out.printf?

标签 java eclipse

我想配置我的 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/

相关文章:

java - 在数组中递归移动

java - 使用 itext jar 创建的 pdf 在打开时给出错误(不支持或损坏),我使用 itext 版本 5.3.0

java - 有没有办法让空包在 Eclipse 中可见?

java - Akka EventBus for Java 示例

java - 将整数转换为 "/\"字符串

java - 将唯一点映射到唯一整数索引

c++ - 面向 C++ 新手的 GUI

eclipse - 我使用 Tomcat 和 Eclipse 编写的第一个 JSF 程序出错

c++ - Eclipse/Code::Block 不运行应用程序

java - 有什么方法可以在 Eclipse 中获得类似 IntelliJ 的自动完成功能?