Skip to content

Commit

Permalink
remove experimental API usage; rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
nnym committed Feb 12, 2022
1 parent 9f94b30 commit 154c1f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion idea/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("org.jetbrains.intellij").version("latest.integration")
}

version("0.1.1")
version("0.1.2")
javaVersion(11)

sourceSets {
Expand Down
2 changes: 1 addition & 1 deletion idea/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</description>
<change-notes>
<![CDATA[
Constructors that invoke throwing methods are no longer red.
Removed experimental API usage.
]]>
</change-notes>
<depends>com.intellij.modules.platform</depends>
Expand Down
11 changes: 8 additions & 3 deletions idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.lang.jvm.JvmModifier;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.psi.PsiExpressionStatement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiMethodCallExpression;
import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -35,6 +35,10 @@ public class HighlightFilter implements HighlightInfoFilter {
return false;
}

if (!matches(info, "variable.not.initialized", "[.$\\w]+")) {
return true;
}

var field = file.findElementAt(info.getStartOffset());

while (true) {
Expand All @@ -45,11 +49,12 @@ public class HighlightFilter implements HighlightInfoFilter {
}

var f = (PsiField) field;
return f.hasModifier(JvmModifier.STATIC) || !(matches(info, "variable.not.initialized", "[.$\\w]+") && Stream.of(f.getContainingClass().getConstructors()).allMatch(constructor -> initialized(constructor, f)));
return f.getModifierList().hasModifierProperty(PsiModifier.STATIC) || !Stream.of(f.getContainingClass().getConstructors()).allMatch(constructor -> initialized(constructor, f));
}

private static boolean matches(HighlightInfo info, String key, String... arguments) {
return messages.computeIfAbsent(JavaErrorBundle.getLocale(), l -> new IdentityHashMap<>()).computeIfAbsent(key, k -> Pattern.compile(JavaErrorBundle.message(k, arguments))).matcher(info.getDescription()).matches();
return messages.computeIfAbsent(JavaErrorBundle.getLocale(), l -> new IdentityHashMap<>())
.computeIfAbsent(key, k -> Pattern.compile(JavaErrorBundle.message(k, arguments))).matcher(info.getDescription()).matches();
}

private static boolean initialized(PsiMethod constructor, PsiField field) {
Expand Down

0 comments on commit 154c1f9

Please sign in to comment.