/
LombokHighlightErrorFilter.java
36 lines (29 loc) · 1.32 KB
/
LombokHighlightErrorFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package de.plushnikov.intellij.plugin.extension;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import de.plushnikov.intellij.plugin.handler.LazyGetterHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LombokHighlightErrorFilter implements HighlightInfoFilter {
private static final Pattern UNINITIALIZED_MESSAGE = Pattern.compile("Variable '.+' might not have been initialized");
@Override
public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile file) {
if (null != file && HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) {
final String description = StringUtil.notNullize(highlightInfo.getDescription());
// Handling LazyGetter
if (uninitializedField(description) && LazyGetterHandler.isLazyGetterHandled(highlightInfo, file)) {
return false;
}
}
return true;
}
private boolean uninitializedField(String description) {
Matcher matcher = UNINITIALIZED_MESSAGE.matcher(description);
return matcher.matches();
}
}