-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Update the documentation to include
BreakStmt
, LabeledStmt
, …
…`YieldStmt` and etc (#185) * added yield stmt 🍺 * added continue stmt * 🍺 added break statement * 🍺 added label statement
- Loading branch information
1 parent
a736e05
commit aae792c
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Break Statement | ||
description: "BreakStmt Statement Entity - Code PathFinder API Index" | ||
--- | ||
import PostHogLayout from '../../../../layouts/PostHogLayout.astro'; | ||
import { Badge } from '@astrojs/starlight/components'; | ||
|
||
<PostHogLayout> | ||
</PostHogLayout> | ||
|
||
### BreakStmt <Badge text="Entity" variant="tip" size="small" /> | ||
|
||
In Java, the break statement is used within loops (for, while, do-while) and switch statements to immediately terminate the execution of the current loop or switch block and transfer control to the statement following the terminated block. | ||
When encountered, it stops the current iteration and continues with the next one, bypassing any code that comes after the continue statement within the loop body. | ||
This is particularly useful when you want to skip specific iterations based on certain conditions while allowing the loop to continue its normal execution for other cases. | ||
|
||
#### Example | ||
```java | ||
for (int i = 0; i < 10; i++) { | ||
if (i == 5) { | ||
break; // BreakStmt | ||
} | ||
// Code to be executed for all iterations except when i is 5 | ||
} | ||
``` | ||
|
||
### Attributes | ||
|
||
| Method | Description | | ||
|-----------------------------|-------------------------------------------------------------------| | ||
| GetAPrimaryQlClass() string | Returns the primary CodeQL class name for this entity | | ||
| GetHalsteadID() int | Returns the Halstead ID for this break statement | | ||
| GetLabel() string | Returns the label associated with this break statement | | ||
| hasLabel() bool | Checks if the break statement has a label | | ||
| GetPP() string | Returns the pretty-printed representation of the break statement | | ||
| ToString() string | Returns the string representation of the break statement | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Continue Statement | ||
description: "ContinueStmt Statement Entity - Code PathFinder API Index" | ||
--- | ||
import PostHogLayout from '../../../../layouts/PostHogLayout.astro'; | ||
import { Badge } from '@astrojs/starlight/components'; | ||
|
||
<PostHogLayout> | ||
</PostHogLayout> | ||
|
||
### ContinueStmt <Badge text="Entity" variant="tip" size="small" /> | ||
|
||
In Java, the continue statement is used within loops (for, while, do-while) to skip the rest of the current iteration and immediately jump to the next iteration of the loop. | ||
When encountered, it stops the current iteration and continues with the next one, bypassing any code that comes after the continue statement within the loop body. | ||
This is particularly useful when you want to skip specific iterations based on certain conditions while allowing the loop to continue its normal execution for other cases. | ||
|
||
#### Example | ||
```java | ||
for (int i = 0; i < 10; i++) { | ||
if (i == 5) { | ||
continue; // ContinueStmt | ||
} | ||
// Code to be executed for all iterations except when i is 5 | ||
} | ||
``` | ||
|
||
### Attributes | ||
|
||
| Method | Description | | ||
|-----------------------------|-------------------------------------------------------------------| | ||
| GetAPrimaryQlClass() string | Returns the primary CodeQL class name for this entity | | ||
| GetHalsteadID() int | Returns the Halstead ID metric for this continue statement | | ||
| GetLabel() string | Gets the label associated with this continue statement if any | | ||
| hasLabel() bool | Checks if this continue statement has a label attached to it | | ||
| GetPP() string | Returns the pretty-printed representation of this statement | | ||
| ToString() string | Returns a string representation of the continue statement | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: Labeled Statement | ||
description: "LabeledStmt Statement Entity - Code PathFinder API Index" | ||
--- | ||
import PostHogLayout from '../../../../layouts/PostHogLayout.astro'; | ||
import { Badge } from '@astrojs/starlight/components'; | ||
|
||
<PostHogLayout> | ||
</PostHogLayout> | ||
|
||
### LabeledStmt <Badge text="Entity" variant="tip" size="small" /> | ||
|
||
In Java, a labeled statement allows you to assign an identifier (label) to a specific block of code or statement. Labels are most commonly used with break and | ||
continue statements to control the flow of nested loops or blocks. | ||
When using a labeled statement, you place the label name followed by a colon (:) before the statement or block you want to label. | ||
This is particularly useful when you need to break out of or continue a specific outer loop from within a nested loop structure. | ||
|
||
#### Example | ||
```java | ||
outer: // Label for the outer loop | ||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
if (i == 1 && j == 1) { | ||
break outer; // Breaks out of the outer loop | ||
} | ||
System.out.println("i = " + i + ", j = " + j); | ||
} | ||
} | ||
|
||
// Example with continue and label | ||
search: | ||
for (int i = 0; i < array.length; i++) { | ||
for (int j = 0; j < array[i].length; j++) { | ||
if (array[i][j] == -1) { | ||
continue search; // Skips to the next iteration of outer loop | ||
} | ||
// Process array[i][j] | ||
} | ||
} | ||
``` | ||
|
||
### Attributes | ||
|
||
| Method | Description | | ||
|--------|-------------| | ||
| GetAPrimaryQlClass() string | Returns the primary CodeQL class name for this entity | | ||
| GetHalsteadID() int | Returns the Halstead complexity metric identifier for the labeled statement | | ||
| GetLabel() *LabeledStmt | Returns a pointer to the labeled statement itself | | ||
| GetPP() string | Returns the pretty-printed representation of the labeled statement | | ||
| ToString() string | Returns a string representation of the labeled statement | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: YieldStmt Statement | ||
description: "YieldStmt Statement Entity - Code PathFinder API Index" | ||
--- | ||
import PostHogLayout from '../../../../layouts/PostHogLayout.astro'; | ||
import { Badge } from '@astrojs/starlight/components'; | ||
|
||
<PostHogLayout> | ||
</PostHogLayout> | ||
|
||
### YieldStmt <Badge text="Entity" variant="tip" size="small" /> | ||
|
||
In Java, the `yield` keyword is used within switch expressions to return a value from a case label. It was introduced in Java 13 as part of switch expressions to provide a way to return values from individual cases. Unlike the traditional break statement, yield allows you to produce a value that becomes the result of the entire switch expression. This is particularly useful when you need to | ||
compute and return different values based on different cases in a more concise and expressive way than traditional switch statements. | ||
|
||
#### Example | ||
```java | ||
String message = switch (number) { | ||
case ONE -> { | ||
yield "Got a 1"; | ||
} | ||
case TWO -> { | ||
yield "Got a 2"; | ||
} | ||
default -> { | ||
yield "More than 2"; | ||
} | ||
}; | ||
``` | ||
|
||
### Attributes | ||
|
||
| Method | Description | | ||
|-----------------------------|------------------------------------------------------------------| | ||
| GetAPrimaryQlClass() string | Returns the primary CodeQL class name for this entity | | ||
| GetHalsteadID() int | Returns the Halstead ID metric for this statement | | ||
| GetPP() string | Returns the pretty-printed representation of this statement | | ||
| ToString() string | Returns a string representation of this statement | | ||
| GetValue() *Exp | Returns the expression being yielded in this statement | |