android studio插件相关(逐步完成系列)

插件相关内容:只是日常看点英文,并且为有需要的人提供一点帮助,如果有意见,那代表你并不是本文适合的服务对象,请点击退出键退出,如果有建议,我们可以详细探讨。

 

Whitespaces and Imports

When working with PSI modification functions, you should never create individual whitespace nodes (spaces or line breaks) from text. Instead, all whitespace modifications are performed by the formatter, which follows the code style settings selected by the user. Formatting is automatically performed at the end of every command, and if you need, you can also perform it manually using the reformat(PsiElement) method in the CodeStyleManager class.

Also, when working with Java code (or with code in other languages with a similar import mechanism such as Groovy or Python), you should never create imports manually. Instead, you should insert fully-qualified names into the code you’re generating, and then call the shortenClassReferences() method in the JavaCodeStyleManager (or the equivalent API for the language you’re working with). This ensures that the imports are created according to the user’s code style settings and inserted into the correct place of the file.

译:

空白代码片段(此处指空行,和空格)和导包操作

当使用PSI修改功能时,你绝不该以text文字的方式新建独立的空白代码片段。而应该使用格式整理器来进行代码的整理工作,代码整理器的整理效果是按照用户设定的代码格式而定的。代码整理在每一条指令之后都会自动执行,但是如果你有迫切的需要的话,你也可以手动通过调用CodeStyleManager类中的reformat(PsiElement)方法来执行它。

另外,运作的目标语言为Java(或者其他相似导包操作的的语言例如Groovy或者Python时),你绝不应该尝试手动创建导包代码。而应该在你生成的代码中插入该类的全路径名,然后调用JavaCodeStyleManager的shortenClassReferences()方法(或者你当前正在使用的相应的API)来达成相应的目的。这确保了导包的代码是符合用户的代码风格并且能正确地插入到文件中的合适位置。

上一篇:eclipse配置SVN禁止提交的文件


下一篇:resource handler working logic for Fiori BSP application - how is javascript file loaded from BSP re