Skip to content

Commit

Permalink
Do not instantiate Labels
Browse files Browse the repository at this point in the history
until required. In the worst case if the regex is wrong is parses out
something that our Label implementation rejects it will appear in the
error list.

This change is to make it easier to understand why and what kind of
labels is instantiated during build operations.

Bug: n/a
Test: n/a
Change-Id: I53a6371be1ec2fc38dcd74acb7b2038e2612a064

AOSP: 3e7c8ecfb0ccdc4fbe9e1bdfa862f2b267e87b0a
  • Loading branch information
Googler authored and LeFrosch committed Nov 15, 2024
1 parent 82e728d commit c999e03
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.idea.blaze.base.settings.Blaze;
import com.intellij.execution.filters.ConsoleFilterProvider;
import com.intellij.execution.filters.Filter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -63,13 +64,13 @@ public Result applyFilter(String line, int entireLength) {
int prefixLength = Optional.ofNullable(matcher.group(1)).map(String::length).orElse(0);

String labelString = matcher.group().substring(prefixLength);
Label label = LabelUtils.createLabelFromString(/* blazePackage= */ null, labelString);
if (label == null) {
continue;
}
// for performance reasons, don't resolve until the user clicks the link
NonProblemHyperlinkInfo link =
project -> {
Label label = LabelUtils.createLabelFromString(/* blazePackage= */ null, labelString);
if (label == null) {
Logger.getInstance(this.getClass()).error(new IllegalStateException("Parsing returned illegal label: " + labelString));
}
PsiElement psi = BuildReferenceManager.getInstance(project).resolveLabel(label);
if (psi instanceof NavigatablePsiElement) {
((NavigatablePsiElement) psi).navigate(true);
Expand Down

0 comments on commit c999e03

Please sign in to comment.