Bug 252949 - Make the "variableFromPreviousAssignment " code templates hints work for Java
Make the "variableFromPreviousAssignment " code templates hints work for Java
Status: NEW
Product: editor
Classification: Unclassified
Component: Completion & Templates
8.0.2
PC Windows 7
: P3 with 12 votes (vote)
: TBD
Assigned To: Dusan Balek
issues@editor
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-06-12 10:45 UTC by taringamberini
Modified: 2017-02-11 17:11 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description taringamberini 2015-06-12 10:45:05 UTC
REQUEST

1.
Rename the code template hints from the current name:

    variableFromPreviousAssignment 

to the new name:

    variableFromPreviousAssignmentName

2.
Make the "variableFromPreviousAssignmentName" hints:

    ${param_name variableFromPreviousAssignmentName} 	The parameter value is the closest previously assigned variable. Usually used with instanceof and default.

work for Java.



DESCRIPTION

As documented at http://wiki.netbeans.org/Java_EditorUsersGuide#How_to_use_Code_Templates
the "variableFrom..." hints:

    ${param_name variableFromPreviousAssignment } 	The parameter value is the closest previously assigned variable. Usually used with instanceof and default.
    ${param_name variableFromNextAssignmentName } 	The parameter value is the name of the closest variable assigned after the code template. Usually used with default.
    ${param_name variableFromNextAssignmentType } 	The parameter value is the type of the closest variable assigned after the code template. Usually used with default.

don't work for Java.

It seems that the variableFromPreviousAssignment is similar to the variableFromNextAssignmentName so it would be better to rename variableFromPreviousAssignment as described above at point 1 of this request. The renaming might be emphasize the lack of the variableFromPreviousAssignmentType.

The point 2 of this request would be a *very useful* enhancement, if implemented for Java Language (in PHP these hints already works), because there are lots of code templates which may be written based on the name of a previous assigned variable.



EXAMPLE: CHECK FOR NULL code template

1.
Go to Tools -> Options -> Editor -> Code Templates

2.
Select "Java" in the Language drop down menu

3.
Create a new code template with:

* abbreviation: ifn

* description: if (param_name == null) { ${cursor} }

* expanded text:

    if (${param_name variableFromPreviousAssignmentName editable=false} == null) {
      ${cursor}
    } 

4.
Then inside a block of code, which allow inserting an "if", the IDE should look for the name of the variable present on the left side of the first assignment instruction which precedes the cursor position "|": see following cases for details.



CASE 1 (just after assignment)

Given the code:

    {
        ...(some instructions)...
        billingAddress = user.getBillingAddress();
        |
        ...(some instructions)...
    }

typing ifn + [TAB] the IDE should generate:

    {
        ...(some instructions)...
        billingAddress = user.getBillingAddress();
        if (billingAddress == null) {
            |
        }
        ...(some instructions)...
    }



CASE 2 (just after assignment with variable declaration)

Given the code:

    {
        ...(some instructions)...
        Address billingAddress = user.getBillingAddress();
        |
        ...(some instructions)...
    }

typing ifn + [TAB] the IDE should generate (again):

    {
        ...(some instructions)...
        Address billingAddress = user.getBillingAddress();
        if (billingAddress == null) {
            |
        }
        ...(some instructions)...
    }



CASE 3 (far from assignment)

Given the code:

    {
        ...(some instructions)...
        billingAddress = user.getBillingAddress();
        ...(some instructions not any of which is an assignment)...
        |
        ...(some instructions)...
    }

typing ifn + [TAB] the IDE should generate:

    {
        ...(some instructions)...
        billingAddress = user.getBillingAddress();
        ...(some instructions not any of which is an assignment)...
        if (billingAddress == null) {
            |
        }
        ...(some instructions)...
    }



CASE 4 (far from assignment with variable declaration)

Given the code:

    {
        ...(some instructions)...
        Address billingAddress = user.getBillingAddress();
        ...(some instructions not any of which is an assignment)...
        |
        ...(some instructions)...
    }

typing ifn + [TAB] the IDE should generate:

    {
        ...(some instructions)...
        Address billingAddress = user.getBillingAddress();
        ...(some instructions not any of which is an assignment)...
        if (billingAddress == null) {
            |
        }
        ...(some instructions)...
    }

Thanks,
Tarin


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo