Skip to content

Commit

Permalink
Cache step definition finding results per JBehaveStep in JBehaveSteps…
Browse files Browse the repository at this point in the history
…Index
  • Loading branch information
picimako committed Jul 4, 2024
1 parent 9c31207 commit 580ef58
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,34 @@ public static JBehaveStepsIndex getInstance(Project project) {

@NotNull
public Collection<JavaStepDefinition> findStepDefinitions(@NotNull JBehaveStep step) {
Module module = ModuleUtilCore.findModuleForPsiElement(step);

if (module == null) {
return emptyList();
}
return CachedValuesManager.getCachedValue(step, (CachedValueProvider<? extends Collection<JavaStepDefinition>>) () -> {
Module module = ModuleUtilCore.findModuleForPsiElement(step);

if (module == null) {
return new CachedValueProvider.Result<>(
emptyList(),
JBehaveStepDefClassesModificationTracker.getInstance(step.getProject()),
ProjectRootModificationTracker.getInstance(step.getProject()));
}

var definitionsByClass = new HashMap<Class, JavaStepDefinition>(2);
String stepText = step.getStepText();
var definitionsByClass = new HashMap<Class, JavaStepDefinition>(2);
String stepText = step.getStepText();

for (var javaStepDefinition : loadStepsFor(module)) {
if (javaStepDefinition.supportsStepAndMatches(step, stepText)) {
Integer currentHighestPriority = getPriorityByDefinition(definitionsByClass.get(javaStepDefinition.getClass()));
Integer newPriority = getPriorityByDefinition(javaStepDefinition);
for (var javaStepDefinition : loadStepsFor(module)) {
if (javaStepDefinition.supportsStepAndMatches(step, stepText)) {
Integer currentHighestPriority = getPriorityByDefinition(definitionsByClass.get(javaStepDefinition.getClass()));
Integer newPriority = getPriorityByDefinition(javaStepDefinition);

if (newPriority > currentHighestPriority) {
definitionsByClass.put(javaStepDefinition.getClass(), javaStepDefinition);
if (newPriority > currentHighestPriority) {
definitionsByClass.put(javaStepDefinition.getClass(), javaStepDefinition);
}
}
}
}

return definitionsByClass.values();
return new CachedValueProvider.Result<>(definitionsByClass.values(),
JBehaveStepDefClassesModificationTracker.getInstance(step.getProject()),
ProjectRootModificationTracker.getInstance(step.getProject()));
});
}

@NotNull
Expand Down

0 comments on commit 580ef58

Please sign in to comment.