1、背景
最近在负责公司基础业务和移动基础设施的开发工作,正在负责Lint代码静态检查工作。因此编写了自定义的Lint规则,在编写自定义的Lint规则前,当然是需要去把Google的关于Lint检测的源代码看一遍学习学习如何编写自定义规则。
在看源代码的过程中,我发现一些奇怪的注释//$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上的一个提问,下面是链接:
原文解释如下:
使用Google翻译内容如下:
查看链接:
http://www.eeworm.com/read/185704/8990379/3/
里面有一段注释对// $ NON-NLS-1 $
进行了描述,如下所示:
描述内容为:
大概含义就是:
参考链接:
http://www.eclipse.org/articles/Article-Internationalization/how2I18n.html
里面举了一个例子,如下所示:
总结一下:使用了//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
的含义就是告诉Eclipse等IDE软件,该字符串不需要被本地化操作。
3、参考链接
https://stackoverflow.com/questions/654037/what-does-non-nls-1-mean
http://www.eclipse.org/articles/Article-Internationalization/how2I18n.html