Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-481

Introduce AnnotatedParameter.getJavaParameter()

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Major Major
    • 2.0 .Final
    • None
    • Portable Extensions
    • None

      Make it possible to obtain the Java Reflection object representing the parameter. This is in line with

      AnnotatedField.getJavaMember()
      AnnotatedMethod.getJavaMember()
      AnnotatedConstructor.getJavaMember()

      Can be implemented as a default method such as:

      default Parameter getJavaParameter() {
              Member member = getDeclaringCallable().getJavaMember();
              if (!(member instanceof Executable)) {
                  throw new IllegalStateException("Parameter does not belong to an executable " + member);
              }
              Executable executable = (Executable) member;
              return executable.getParameters()[getPosition()];
          }
      

            [CDI-481] Introduce AnnotatedParameter.getJavaParameter()

            Jozef Hartinger added a comment - Prototype of the new method: https://github.com/weld/api/blob/3.0.Alpha1/weld/src/main/java/org/jboss/weld/experimental/ExperimentalAnnotatedParameter.java

            Yep. If you think to an extension allowing kind of dynamic calls it can use then names instead of index or type (which are not enough). For instance:

            @PreSecurity("authenticator.login(username, password)
            public Data getSensitiveData() {
              // ...
            }
            
            // ...
            
            @Named
            public class Authenticator {
                public boolean login(@Parameter("username") String user, @Parameter("password")  String pwd) {
                    return true; 
                }
            }
            

            Romain Manni-Bucau (Inactive) added a comment - - edited Yep. If you think to an extension allowing kind of dynamic calls it can use then names instead of index or type (which are not enough). For instance: @PreSecurity("authenticator.login(username, password) public Data getSensitiveData() { // ... } // ... @Named public class Authenticator { public boolean login(@Parameter( "username" ) String user, @Parameter( "password" ) String pwd) { return true ; } }

            Oh, I see.

            The named would be available here as AnnotatedParameter.getJavaParameter().getName()

            Jozef Hartinger added a comment - Oh, I see. The named would be available here as AnnotatedParameter.getJavaParameter().getName()

            http://javadox.com/javax/javaee-api/7.0/javax/validation/ParameterNameProvider.html

            this way extensions can use parameters name which can be useful for extension configuration and match it with something better/more expressive than index.

            Romain Manni-Bucau (Inactive) added a comment - http://javadox.com/javax/javaee-api/7.0/javax/validation/ParameterNameProvider.html this way extensions can use parameters name which can be useful for extension configuration and match it with something better/more expressive than index.

            Can be interesting to align it on BVal with parameter naming, no?

            Sorry, I don't follow. Please elaborate.

            Jozef Hartinger added a comment - Can be interesting to align it on BVal with parameter naming, no? Sorry, I don't follow. Please elaborate.

            Can be interesting to align it on BVal with parameter naming, no?

            Romain Manni-Bucau (Inactive) added a comment - Can be interesting to align it on BVal with parameter naming, no?

              mkouba@redhat.com Martin Kouba
              rhn-engineering-jharting Jozef Hartinger
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: