fixed null ptr in debugging output on virtual/floating elements

This commit is contained in:
overflowerror 2021-12-02 17:24:48 +01:00
parent 5f136cf262
commit 3f665c0d39
2 changed files with 13 additions and 1 deletions

View file

@ -240,8 +240,10 @@ public class HoistingProcessor {
// TODO: make private
public HoistingGuard findGuardForRule(AbstractRule rule) {
log.info("finding guard for rule: " + rule.getName());
HoistingGuard guard = ruleCache.get(rule.getName());
if (guard == null) {
log.info("not in cache");
guard = findGuardForElement(rule.getAlternatives(), rule);
ruleCache.put(rule.getName(), guard);
}
@ -306,6 +308,7 @@ public class HoistingProcessor {
public HoistingGuard findHoistingGuard(AbstractElement element) {
log.info("hoisting guard of: \n" + abstractElementToString(element));
// should only be called for valid AST elements, so element can never be floating
return findGuardForElement(element, containingParserRule(element));
}

View file

@ -108,7 +108,7 @@ public class DebugUtils {
public static String abstractElementToString(AbstractElement element) {
StringBuilder builder = new StringBuilder();
abstractElementToString(element, builder, 0, Arrays.asList(GrammarUtil.containingRule(element).getName()));
abstractElementToString(element, builder, 0, Arrays.asList(containingRuleSafe(element)));
return builder.toString();
}
@ -185,4 +185,13 @@ public class DebugUtils {
abstractElementToShortString(element, builder);
return builder.toString();
}
public static String containingRuleSafe(AbstractElement element) {
AbstractRule rule = GrammarUtil.containingRule(element);
if (rule == null) {
return "{floating}";
} else {
return rule.getName();
}
}
}