简体   繁体   English

是否有理由在Java EE中的@Webservice(...)注释中包含括号?

[英]Is there ever a reason to have parentheses within an @Webservice(…) annotation in Java EE?

I am building some static analysis tools to help manage the architecture of a large project. 我正在构建一些静态分析工具来帮助管理大型项目的体系结构。 For this I am doing a couple of regexes to parse information from Java files. 为此,我正在做几个正则表达式来解析Java文件中的信息。 One of these regexes is used to scan for an @WebService(... ) annotation. 其中一个正则表达式用于扫描@WebService(...)注释。

I was wondering if there is a situation possible where there are parentheses in an @WebService annotation (withhelding the ones at the start and end, and any in String literals or comments). 我想知道是否存在@WebService注释中有括号的情况(包括开头和结尾处的括号,以及字符串文字或注释中的任何一个)。 So the ones in 所以那些人

@WebService(serviceName="bla()" /* bla() */); 

are ok; 好的 whereas the ones in 而那些人

@WebService( ... ( ... ) ...); 

are not. 不是。

Does the latter ever occur? 后者会发生吗?

Yes, there can be parenthesis even outside of string literals. 是的,即使在字符串文字之外也可以有括号。

In general, annotations can have constant expressions as arguments, that evaluate to a primitive, String, Class, Enum, Annotation or Array. 通常,注释可以具有常量表达式作为参数,可以计算为基元,String,Class,Enum,Annotation或Array。 String literals, annotations parameters and expressions can contain parenthesis. 字符串文字,注释参数和表达式可以包含括号。 The following declaration is valid: 以下声明有效:

@WebService(serviceName="bla()" + ("bla") + (2 * 3)); 

The annotation could also contain comments that include parenthesis: 注释还可以包含包含括号的注释:

@WebService(serviceName="bla()" /* ( ) */); 

@WebService( // ( )
   serviceName="bla()"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM