mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused declaration: report Kotlin unused main function parameters
GitOrigin-RevId: 0c40f76d3db6539c2217e1aa7967f0e90689f083
This commit is contained in:
committed by
intellij-monorepo-bot
parent
59d91440b0
commit
ce8c5cda4a
+8
-4
@@ -25,6 +25,7 @@ import org.jetbrains.uast.UParameter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -45,13 +46,15 @@ class UnusedParametersInspection extends GlobalJavaBatchInspectionTool {
|
||||
if (aClass != null && ((refMethod.isAbstract() || aClass.isInterface()) && refMethod.getDerivedReferences().isEmpty())) {
|
||||
return null;
|
||||
}
|
||||
if (refMethod.isAppMain()) return null;
|
||||
List<RefParameter> unusedParameters = getUnusedParameters(refMethod);
|
||||
if (unusedParameters.isEmpty()) return null;
|
||||
if (refMethod.isEntry()) return null;
|
||||
UDeclaration uMethod = refMethod.getUastElement();
|
||||
if (uMethod == null) return null;
|
||||
PsiElement element = uMethod.getJavaPsi();
|
||||
if (refMethod.isAppMain()) {
|
||||
if (element == null || !element.getLanguage().isKindOf("kotlin")) return null;
|
||||
}
|
||||
else if (refMethod.isEntry()) return null;
|
||||
if (element != null && EntryPointsManager.getInstance(manager.getProject()).isEntryPoint(element)) return null;
|
||||
|
||||
List<ProblemDescriptor> result = new ArrayList<>();
|
||||
@@ -151,10 +154,11 @@ class UnusedParametersInspection extends GlobalJavaBatchInspectionTool {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ArrayList<RefParameter> getUnusedParameters(@NotNull RefMethod refMethod) {
|
||||
private static List<RefParameter> getUnusedParameters(@NotNull RefMethod refMethod) {
|
||||
RefParameter[] methodParameters = refMethod.getParameters();
|
||||
if (methodParameters.length == 0) return Collections.emptyList();
|
||||
boolean checkDeep = !refMethod.isStatic() && !refMethod.isConstructor();
|
||||
ArrayList<RefParameter> res = new ArrayList<>();
|
||||
RefParameter[] methodParameters = refMethod.getParameters();
|
||||
RefParameter[] result = methodParameters.clone();
|
||||
|
||||
clearUsedParameters(refMethod, result, checkDeep);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Main.kt</file>
|
||||
<line>1</line>
|
||||
<problem_class id="unused" severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unused declaration</problem_class>
|
||||
<description>Parameter <code>args</code> is not used</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello world!")
|
||||
}
|
||||
+6
@@ -69,6 +69,12 @@ public class UnusedDeclarationKtTest20 extends AbstractUnusedDeclarationTest {
|
||||
doTest("deadCode/" + getTestName(true), myToolWrapper);
|
||||
}
|
||||
|
||||
public void testMainParameter() {
|
||||
myTool.getSharedLocalInspectionTool().PARAMETER = true;
|
||||
myTool.getSharedLocalInspectionTool().LOCAL_VARIABLE = false;
|
||||
doTest("deadCode/" + getTestName(true), myToolWrapper);
|
||||
}
|
||||
|
||||
public void testStaticMethods() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user