【我的Android进阶之旅】Android 源代码中的Java代码中//$NON-NLS-1$ 注释是什么意思?...

1、背景

最近在负责公司基础业务和移动基础设施的开发工作,正在负责Lint代码静态检查工作。因此编写了自定义的Lint规则,在编写自定义的Lint规则前,当然是需要去把Google的关于Lint检测的源代码看一遍学习学习如何编写自定义规则。

google官方的lint源代码链接为:
https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks?spm=5176.100239.blogcont6918.10.MXIr5J

我的github上备份了该源代码:
https://github.com/ouyangpeng/android-lint-checks

在看源代码的过程中,我发现一些奇怪的注释//$NON-NLS-1$,这个注释到底是什么意思呢?

 /** Using a view inflater unconditionally in an AdapterView */
    public static final Issue ISSUE = Issue.create(
            "ViewHolder", //$NON-NLS-1$
            "View Holder Candidates",

            "When implementing a view Adapter, you should avoid unconditionally inflating a " +
            "new layout; if an available item is passed in for reuse, you should try to " +
            "use that one instead. This helps make for example ListView scrolling much " +
            "smoother.",

            Category.PERFORMANCE,
            5,
            Severity.WARNING,
            IMPLEMENTATION)
            .addMoreInfo(
            "http://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder");

    private static final String GET_VIEW = "getView";  //$NON-NLS-1$
    static final String INFLATE = "inflate";           //$NON-NLS-1$

这里写图片描述

除了上面的//$NON-NLS-1$注释之外,还有类似于 //$NON-NLS-2$//$NON-NLS-3$的注释,如下所示:

    /* (non-Javadoc)
     * @see javax.lang.model.util.Types#contains(javax.lang.model.type.TypeMirror, javax.lang.model.type.TypeMirror)
     */
    @Override
    public boolean contains(TypeMirror t1, TypeMirror t2) {
        switch(t1.getKind()) {
            case EXECUTABLE :
            case PACKAGE :
                throw new IllegalArgumentException("Executable and package are illegal argument for Types.contains(..)"); //$NON-NLS-1$
            default:
                break;
        }
        switch(t2.getKind()) {
            case EXECUTABLE :
            case PACKAGE :
                throw new IllegalArgumentException("Executable and package are illegal argument for Types.contains(..)"); //$NON-NLS-1$
            default:
                break;
        }
        throw new UnsupportedOperationException("NYI: TypesImpl.contains(" + t1 + ", " + t2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

这里写图片描述

这里写图片描述

反正看了下代码,基本上所有的使用字符串的地方,后面都会接上这么一个注释,//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$。那么 这个 //$NON-NLS-1$ 到底是什么意思呢?

2、//$NON-NLS-1$的意义

参考了网上的资料,
查看了stackoverflow上的一个提问,下面是链接:

https://stackoverflow.com/questions/654037/what-does-non-nls-1-mean

这里写图片描述

原文解释如下:

They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).

The idea is that UI messages should not be embedded as string literals, but rather sourced from a resource file (so that they can be translated, proofed, etc). Consequently, Eclipse can be configured to detect string literals, so that you don’t accidentally have leave unexternalized UI strings in the code; however, there are strings which should not be externalized (such as regexps) and so, //NONNLS1 gives you a way to communicate that fact to the compiler.

使用Google翻译内容如下:

当它遇到字符串文字(并已被配置为抱怨)时,它们会使Eclipse发出警告。

这个想法是,UI消息不应该嵌入字符串文字,而是从资源文件中获取(以便可以翻译,校对等)。因此,Eclipse可以配置为检测字符串文字,这样您就不会意外地在代码中留下无用的UI字符串;但是,有些字符串不应该被外部化(如regexps),所以// $ NON-NLS-1 $给你一个方法来将该事实传递给编译器。

查看链接:
http://www.eeworm.com/read/185704/8990379/3/

里面有一段注释对// $ NON-NLS-1 $进行了描述,如下所示:

这里写图片描述

描述内容为:

The string $NON-NLS-1$ is a hint for both the compiler =
and the=20
Externalization wizard that the first character string on this line is a =
tag or=20
keyword of some sort and should not be localized.

大概含义就是:

$NON-NLS-1$表明本行的第一个string型变量是一个标签或者关键字,不需要被本地化。

参考链接:
http://www.eclipse.org/articles/Article-Internationalization/how2I18n.html

里面举了一个例子,如下所示:
这里写图片描述

总结一下:使用了//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$的含义就是告诉Eclipse等IDE软件,该字符串不需要被本地化操作。

3、参考链接


这里写图片描述

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/77941890

如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作!

这里写图片描述

转载于:https://www.cnblogs.com/ouyangpeng/p/8537628.html

### LoongArch GNU 工具链配置详情及 GCC 版本信息 #### 配置细节 LoongArch GNU 工具链的目标架构为 `loongarch64-linux-gnu`,其对应的 GCC 编译器版本为 8.3.0。此工具链支持龙芯自主指令集体系结构(LoongArch),并针对该架构进行了优化[^1]。 在构建过程中,GCC 的配置选项通常会指定目标平台以及所需的特性支持。对于 LoongArch 架构而言,常见的配置命令可能如下所示: ```bash ./configure --target=loongarch64-linux-gnu \ --prefix=/opt/loongson/toolchain \ --enable-languages=c,c++ \ --disable-multilib \ --with-system-zlib \ --with-gmp=/usr/local/gmp \ --with-mpfr=/usr/local/mpfr \ --with-mpc=/usr/local/mpc \ --with-isl=/usr/local/isl ``` 上述配置说明了以下几点: - 使用 `--target=loongarch64-linux-gnu` 来定义目标平台。 - 设置安装路径为 `/opt/loongson/toolchain`。 - 启用了 C 和 C++ 支持。 - 关闭多库模式以减少复杂度。 - 指定了依赖项的位置,例如 GMP、MPFR、MPC 和 ISL 库。 #### GCC 版本信息 所使用的 GCC 版本为 8.3.0,这是由官方预先编译好的二进制文件提供[^4]。通过解压预编译的工具链包即可获得完整的开发环境。例如,在 Linux 下可以通过以下命令完成解压操作: ```bash tar -xvf loongson-gnu-toolchain-8.3-src-loongarch64-linux-gnu-rc1.2.tar ``` 这一步骤将提取出所有必要的组件,包括编译器、汇编器和链接器等工具。 此外,动态链接库的信息也表明系统中存在兼容的 libc 实现。例如,标准 C 库的共享对象文件位于 `/lib/x86_64-linux-gnu/libc.so.6` 中[^3]。尽管此处提到的是 x86_64 平台上的实现,但在 LoongArch 上也会有类似的对应版本。 --- ### 总结 综上所述,LoongArch GNU 工具链基于 GCC 8.3.0 开发,并专门适配于 `loongarch64-linux-gnu` 目标平台。它不仅提供了高效的编译能力,还包含了经过验证的标准库支持。用户可以按照既定流程下载并部署这一工具链至本地环境中,从而开展面向 LoongArch 架构的应用程序开发工作。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值