matthiasblaesing commented on code in PR #9285:
URL: https://github.com/apache/netbeans/pull/9285#discussion_r3312802636
##########
java/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/LineBreakpoint.java:
##########
@@ -182,6 +189,29 @@ public void setLineNumber (int ln) {
Integer.valueOf(ln)
);
}
+
+ public int[] getLambdaIndex() {
Review Comment:
Would it make sense to use correct plural form? I.e. `getLambdaIndexes`?
##########
java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/BreakpointsReader.java:
##########
@@ -370,6 +372,10 @@ public void write (Object object, Properties properties) {
LineBreakpoint.PROP_LINE_NUMBER,
lb.getLineNumber ()
);
+ properties.setArray(
+ LineBreakpoint.PROP_LAMBDA_INDEX,
+ Arrays.stream(lb.getLambdaIndex()).mapToObj(v -> v).toArray()
Review Comment:
I assume this is done to get the raw ints boxed?
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle.properties:
##########
@@ -229,6 +229,11 @@
ACSD_TF_Line_Breakpoint_Line_Number=Line number
TTT_TF_Line_Breakpoint_Line_Number=Line number to stop at
+ L_Line_Breakpoint_Lambda_Index=Lambda &Index\:
+ ACSD_L_Line_Breakpoint_Lambda_Index=Lambda Index
+ ACSD_TF_Line_Breakpoint_Lambda_Index=Lambda Index
+ TTT_TF_Line_Breakpoint_Lambda_Index=Lambda Index to stop at
Review Comment:
I suggest to add a minimal explanation/usage instruction:
```suggestion
L_Line_Breakpoint_Lambda_Index=Lambda &Indexes\:
ACSD_L_Line_Breakpoint_Lambda_Index=Lambda Indexes
ACSD_TF_Line_Breakpoint_Lambda_Index=Lambda Indexes
TTT_TF_Line_Breakpoint_Lambda_Index=Comma seperated lambda indexes to
stop at\nempty: all locations\n-1: stop outside of lambda\n0-based index: break
in that lambda expression
```
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/breakpoints/LineBreakpointPanel.java:
##########
@@ -248,6 +254,29 @@ private void initComponents() {
tfLineNumber.getAccessibleContext().setAccessibleName("Line number");
tfLineNumber.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Line_Breakpoint_Line_Number"));
// NOI18N
+ jLabel4.setLabelFor(tfLambdaIndex);
+ org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
bundle.getString("L_Line_Breakpoint_Lambda_Index")); // NOI18N
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 4;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+ gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
+ pSettings.add(jLabel4, gridBagConstraints);
+
jLabel4.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Line_Breakpoint_Lambda_Index"));
// NOI18N
+
+
tfLambdaIndex.setToolTipText(bundle.getString("TTT_TF_Line_Breakpoint_Lambda_Index"));
// NOI18N
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 1;
+ gridBagConstraints.gridy = 4;
+ gridBagConstraints.gridwidth = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
+ pSettings.add(tfLambdaIndex, gridBagConstraints);
+ tfLambdaIndex.getAccessibleContext().setAccessibleName("Lambda index");
Review Comment:
Should this be localized?
##########
java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java:
##########
@@ -697,6 +709,39 @@ private static String normalize(String path) {
return path;
}
+ private List<Location> filterLocationsByLambdaIndex(List<Location>
locations, int[] lambdaIndex) {
+ if (lambdaIndex.length == 0) {
+ return locations;
+ } else {
+ Map<String, List<Location>> lambda2Locations = new
LinkedHashMap<>();
+ List<Location> outsideOfLambda = new ArrayList<>();
+
+ for (Location l : locations) {
+ if (l.method().name().startsWith("lambda$")) {
Review Comment:
Should here be a comment, that this relies on the lambda naming convention
and might break? I only suspect, that this detail is not described in the JLS?
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/breakpoints/LineBreakpointPanel.java:
##########
@@ -319,6 +350,12 @@ public boolean ok () {
logger.fine(" => URL = '"+url+"'");
breakpoint.setURL((url != null) ? url.toString() : path);
breakpoint.setLineNumber(Integer.parseInt(tfLineNumber.getText().trim()));
+ String lambdaIndexText = tfLambdaIndex.getText().trim();
+ if (lambdaIndexText.isEmpty()) {
+ breakpoint.setLambdaIndex(new int[0]);
+ } else {
+
breakpoint.setLambdaIndex(Arrays.stream(lambdaIndexText.split(",
*")).mapToInt(v -> Integer.parseInt(v)).toArray());
Review Comment:
I think we should be prepared for bogus values, so I would suggest this:
```suggestion
int[] indexes = Arrays.stream(lambdaIndexText.split(", *"))
.map(indexString -> {
try {
return Integer.parseInt(indexString);
} catch (NumberFormatException ex) {
// Ignore invalid values
return null;
}
})
.filter(value -> value != null)
.mapToInt(i -> i)
.toArray();
breakpoint.setLambdaIndex(indexes);
```
--
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