adfemg
  1. adfemg
  2. ADFEMG-140

Separate Declaration And Assignment to assign null at declaration

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Labels:
      None

      Description

      hi

      JDeveloper (e.g. version 11.1.2.4.0) has a "Separate Declaration And Assignment" feature in a Java code editor.

      It allows to go from this

      String vFirstArgument = pArguments[0];
      

      to this

      String vFirstArgument;
      vFirstArgument = pArguments[0];
      

      Typically this is used to move a declaration outside a code-block to be able to also use it outside/after that code-block.
      Without explicit initialization, this will result in a compiler error "variable ... might not have been initialized".

      see also the screencast at http://screencast.com/t/iNzu46xDO

      So, it would be convenient if "Separate Declaration And Assignment" would result in this

      String vFirstArgument = null;
      vFirstArgument = pArguments[0];
      

      Would it make sense to create an Oracle enhancement request for this?

      many thanks
      Jan Vervecken

        Activity

        Hide
        chriscmuir added a comment -

        Jan, I was having a look at this today. I know where you're coming from, but I think development will just argue that sometimes developers aren't going to move the code outside the code-block, so leave it be, let the developer do what they're paid for.

        My opinion, this is a pretty minor ER and not worth us pursuing.

        CM.

        Show
        chriscmuir added a comment - Jan, I was having a look at this today. I know where you're coming from, but I think development will just argue that sometimes developers aren't going to move the code outside the code-block, so leave it be, let the developer do what they're paid for. My opinion, this is a pretty minor ER and not worth us pursuing. CM.
        Hide
        Jan Vervecken added a comment -

        Thanks for your reply Chris.

        • about "... I think development will just argue that sometimes developers aren't going to move the code outside the code-block ..."
          • If so, which other use-cases can use this "Separate Declaration And Assignment" feature in a Java code editor?
            What would be the result if you apply the 80-20 rule on such use-cases (taking the compiler error about initialization into account)?
            And which of those other use-cases would hurt from an "= null" assignment?
        • about "... let the developer do what they're paid for ..."
          • Which is also, making optimal use of the correct tools (including IDE's) for the job at hand.
        • about "... this is a pretty minor ER ..."
          • In a way, but it has been bothering me for a very long time.

        Would there exist a sample of a JDeveloper extension that does this kind of change in a Java code editor?
        If so, it could help guide the implementation of a slightly modified "Separate Declaration And Assignment" feature.

        But, having this work out-of-the-box would still be preferable.

        regards
        Jan Vervecken

        Show
        Jan Vervecken added a comment - Thanks for your reply Chris. about "... I think development will just argue that sometimes developers aren't going to move the code outside the code-block ..." If so, which other use-cases can use this "Separate Declaration And Assignment" feature in a Java code editor? What would be the result if you apply the 80-20 rule on such use-cases (taking the compiler error about initialization into account)? And which of those other use-cases would hurt from an "= null" assignment? about "... let the developer do what they're paid for ..." Which is also, making optimal use of the correct tools (including IDE's) for the job at hand. about "... this is a pretty minor ER ..." In a way, but it has been bothering me for a very long time. Would there exist a sample of a JDeveloper extension that does this kind of change in a Java code editor? If so, it could help guide the implementation of a slightly modified "Separate Declaration And Assignment" feature. But, having this work out-of-the-box would still be preferable. regards Jan Vervecken
        Hide
        chriscmuir added a comment -

        It's not a case of "would it hurt" but development priorities.

        Regardless lodged ER 17160780. Full text of ER is here:

        @ Lodged as per ADF EMG public customer issue tracker:
        @ https://java.net/jira/browse/ADFEMG-140
        @ .
        @ If you have a code block like the following in JDev:
        @ .
        @ public static void main(String[] args) {
        @ if (args.length > 0)

        { @ String firstArg = args[0]; @ }


        @ .
        @ ...then on the 3rd line of the String declaration/assignment, you select the
        @ Code Assist "Separate Declaration and Assignment" option JDev generates:
        @ .
        @ public static void main(String[] args) {
        @ if (args.length > 0)

        { @ String firstArg; @ firstArg = args[0]; @ }


        @ }
        @ .
        @ If you then move the "String firstArg" before the if statement as:
        @ .
        @ public static void main(String[] args) {
        @ String firstArg;
        @ if (args.length > 0)

        { @ firstArg = args[0]; @ }
        @ System.out.println(firstArg);
        @ }
        @ .
        @ ....which is a common code move for programmers as this is why they would
        @ separate the declaration/assignment in the first place, the programmer will
        @ get a visual compiler warning under the System.out.println statement that
        @ "variable firstArg might not have been initialized". As such the programmer
        @ as an extra step will then change the initial String firstArg declaration to
        @ include a null assignment:
        @ .
        @ public static void main(String[] args) {
        @ String firstArg = null;
        @ if (args.length > 0) { @ firstArg = args[0]; @ }


        @ System.out.println(firstArg);
        @ }
        @ .
        @ As this is a such a common thing for developers to do, if the original Code
        @ Assist "Separate Declaration and Assignment" option can also assign null to
        @ the declaration this would save them an unnecessary manual step.

        Show
        chriscmuir added a comment - It's not a case of "would it hurt" but development priorities. Regardless lodged ER 17160780. Full text of ER is here: @ Lodged as per ADF EMG public customer issue tracker: @ https://java.net/jira/browse/ADFEMG-140 @ . @ If you have a code block like the following in JDev: @ . @ public static void main(String[] args) { @ if (args.length > 0) { @ String firstArg = args[0]; @ } @ . @ ...then on the 3rd line of the String declaration/assignment, you select the @ Code Assist "Separate Declaration and Assignment" option JDev generates: @ . @ public static void main(String[] args) { @ if (args.length > 0) { @ String firstArg; @ firstArg = args[0]; @ } @ } @ . @ If you then move the "String firstArg" before the if statement as: @ . @ public static void main(String[] args) { @ String firstArg; @ if (args.length > 0) { @ firstArg = args[0]; @ } @ System.out.println(firstArg); @ } @ . @ ....which is a common code move for programmers as this is why they would @ separate the declaration/assignment in the first place, the programmer will @ get a visual compiler warning under the System.out.println statement that @ "variable firstArg might not have been initialized". As such the programmer @ as an extra step will then change the initial String firstArg declaration to @ include a null assignment: @ . @ public static void main(String[] args) { @ String firstArg = null; @ if (args.length > 0) { @ firstArg = args[0]; @ } @ System.out.println(firstArg); @ } @ . @ As this is a such a common thing for developers to do, if the original Code @ Assist "Separate Declaration and Assignment" option can also assign null to @ the declaration this would save them an unnecessary manual step.
        Hide
        chriscmuir added a comment -

        Again like other issues on the ADF EMG, I'm going to mark this issue as incomplete, and leave development to schedule a fix for this based on their own priorities. This will allow me to not repetitively track this issue.

        CM.

        Show
        chriscmuir added a comment - Again like other issues on the ADF EMG, I'm going to mark this issue as incomplete , and leave development to schedule a fix for this based on their own priorities. This will allow me to not repetitively track this issue. CM.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jan Vervecken
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: