-
Notifications
You must be signed in to change notification settings - Fork 479
Provide unique IDs for all node info objects #1696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,19 +20,37 @@ | |
|
|
||
| import java.lang.annotation.Annotation; | ||
| import java.lang.reflect.AnnotatedElement; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Base class for runtime information about an element in a Spock specification. | ||
| * | ||
| * @author Peter Niederwieser | ||
| */ | ||
| public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> { | ||
| private String uniqueId = UUID.randomUUID().toString(); | ||
|
Comment on lines
+23
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, locate and examine NodeInfo.java
find . -type f -name "NodeInfo.java" | head -20Repository: spockframework/spock Length of output: 137 🏁 Script executed: # Check the full content of NodeInfo.java
if [ -f "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java" ]; then
cat -n "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java"
else
# Search for the file
find . -name "NodeInfo.java" -type f
fiRepository: spockframework/spock Length of output: 3665 🏁 Script executed: # Also check SpecInfoBuilder.java to see if it assigns semantic IDs
find . -type f -name "SpecInfoBuilder.java" | head -5Repository: spockframework/spock Length of output: 138 🏁 Script executed: # Check IterationInfo.java
find . -type f -name "IterationInfo.java" | head -5Repository: spockframework/spock Length of output: 142 🏁 Script executed: # Examine SpecInfoBuilder.java to find semantic ID assignments
cat -n "spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java"Repository: spockframework/spock Length of output: 10958 🏁 Script executed: # Examine IterationInfo.java
cat -n "spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java"Repository: spockframework/spock Length of output: 5336 🏁 Script executed: # Search for setUniqueId calls to verify overwriting of uniqueId
rg "setUniqueId" -n --context 3Repository: spockframework/spock Length of output: 3267 Avoid eagerly generating a UUID in the base type.
Additionally, the public 💡 One possible simplification-import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
- private String uniqueId = UUID.randomUUID().toString();
+ private static final AtomicLong NEXT_ID = new AtomicLong();
+ private String uniqueId = "node-" + NEXT_ID.incrementAndGet();🤖 Prompt for AI Agents |
||
| private String name; | ||
| private int line = -1; | ||
| private P parent; | ||
| private R reflection; | ||
| private Object metadata; | ||
|
|
||
| /** | ||
| * A unique ID for this node during the current execution. Although some subclasses might | ||
| * provide semantic IDs, and the default implementation uses UUIDs, no semantic or format | ||
| * or maximum length is guaranteed. The only thing that should be assumed is, that the ID | ||
| * is unique across all nodes during the same invocation. | ||
| * | ||
| * @return the unique ID for this node | ||
| */ | ||
| public String getUniqueId() { | ||
| return uniqueId; | ||
| } | ||
|
|
||
| public void setUniqueId(String uniqueId) { | ||
| this.uniqueId = uniqueId; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.