Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. One of these regexes is used to scan for an @WebService(... ) annotation.

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). So the ones in

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

are ok; whereas the ones in

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

are not.

Does the latter ever occur?

like image 820
Kristof Avatar asked Nov 10 '22 08:11

Kristof


1 Answers

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 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()"); 
like image 94
kapex Avatar answered Nov 15 '22 07:11

kapex