jkeresman01 commented on PR #8509:
URL: https://github.com/apache/netbeans/pull/8509#issuecomment-2899589538

   Thanks again for the feedback
   
   The resource expression often varies — it might involve a different 
constructed type than the declared one, chained method calls, or multiple 
resources. 
   
   For example:
   
   ```java
   try (InputStream in = new FileInputStream("file.txt")) { ... }
   ```
   
   ```java
   try (Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(...)) { ... }
   ```
   
    ```java
   try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, 
UTF_8))) { ... }
   ```
   
   Not sure how to support these diverse cases,
   
   I’ve defined the template like this:
   
   ```xml
   <codetemplate abbreviation="tryr" 
contexts="BLOCK,CASE,LABELED_STATEMENT,DO_WHILE_LOOP,ENHANCED_FOR_LOOP,FOR_LOOP,IF,WHILE_LOOP,LAMBDA_EXPRESSION"
 descriptionId="CT_tryr">
       <code><![CDATA[try (${Type default="AutoCloseable"} ${var newVarName 
default="res"} = ${rhs default="new SomeResource()"}) {
       ${selection}${cursor}
   }]]></code>
   </codetemplate>
   ```
   That said, I’m happy to revisit the defaults or structure if there’s a more 
useful or consistent pattern — open to further suggestions!
   
   
   Also if we were to reduce the snippet to its minimal form:
   
   ```java
   try (|) {
       
   }
   ```
   
   More complex resource declarations could still be composed by combining 
multiple abbreviations (e.g. tryr + newo), depending on user preferences.
   
    ```java
   try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, 
UTF_8))) { ... }
   ```
   
   Anyhow let me know you thoughts.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to