mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
[java-intentions] IDEA-379168 Suggest renaming underscore variable when it's used.
GitOrigin-RevId: eb0cfd7ddf8d5d730198ea5cd064cca79724348e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
719fe48b48
commit
2bd42bb487
@@ -204,7 +204,10 @@ public final class PsiImplUtil {
|
||||
if (fromBody) {
|
||||
final PsiParameter[] parameters = element.getParameterList().getParameters();
|
||||
for (PsiParameter parameter : parameters) {
|
||||
if (parameter.isUnnamed()) continue;
|
||||
if (parameter.isUnnamed() &&
|
||||
!Boolean.TRUE.equals(processor.getHint(ElementClassHint.PROCESS_UNNAMED_VARIABLES))) {
|
||||
continue;
|
||||
}
|
||||
if (!processor.execute(parameter, state)) return false;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +225,8 @@ public final class PsiImplUtil {
|
||||
for (PsiResourceListElement resource : resourceList) {
|
||||
if (resource == lastParent) break;
|
||||
if (resource instanceof PsiResourceVariable &&
|
||||
!((PsiResourceVariable)resource).isUnnamed() &&
|
||||
!(((PsiResourceVariable)resource).isUnnamed() &&
|
||||
!Boolean.TRUE.equals(processor.getHint(ElementClassHint.PROCESS_UNNAMED_VARIABLES))) &&
|
||||
!processor.execute(resource, state)) return false;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -119,7 +119,8 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
|
||||
|
||||
for (PsiElement element : getDeclaredElements()) {
|
||||
if (element != lastParent) {
|
||||
if (element instanceof PsiVariable && ((PsiVariable)element).isUnnamed()) continue;
|
||||
if (element instanceof PsiVariable && ((PsiVariable)element).isUnnamed() &&
|
||||
!Boolean.TRUE.equals(processor.getHint(ElementClassHint.PROCESS_UNNAMED_VARIABLES))) continue;
|
||||
if (!processor.execute(element, state)) return false;
|
||||
}
|
||||
else {
|
||||
|
||||
+3
-1
@@ -4,6 +4,7 @@ package com.intellij.psi.impl.source.tree.java;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.Constants;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -32,7 +33,8 @@ public class PsiForeachStatementImpl extends PsiForeachStatementBaseImpl impleme
|
||||
return true;
|
||||
|
||||
PsiParameter parameter = getIterationParameter();
|
||||
if (parameter.isUnnamed()) return true;
|
||||
if (parameter.isUnnamed() &&
|
||||
!Boolean.TRUE.equals(processor.getHint(ElementClassHint.PROCESS_UNNAMED_VARIABLES))) return true;
|
||||
return processor.execute(parameter, state);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -4,6 +4,7 @@ package com.intellij.psi.impl.source.tree.java;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.Constants;
|
||||
import com.intellij.psi.impl.source.tree.CompositePsiElement;
|
||||
import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,7 +47,8 @@ public class PsiTypeTestPatternImpl extends CompositePsiElement implements PsiTy
|
||||
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
|
||||
|
||||
PsiPatternVariable variable = getPatternVariable();
|
||||
if (variable != null && variable != lastParent && !variable.isUnnamed()) {
|
||||
if (variable != null && variable != lastParent &&
|
||||
!(variable.isUnnamed() && !Boolean.TRUE.equals(processor.getHint(ElementClassHint.PROCESS_UNNAMED_VARIABLES)))) {
|
||||
return processor.execute(variable, state);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -7,6 +7,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface ElementClassHint {
|
||||
Key<ElementClassHint> KEY = Key.create("ElementClassHint");
|
||||
|
||||
/**
|
||||
* If this hint is set to true, then the unnamed variables will be processed. By default, they are skipped.
|
||||
*/
|
||||
Key<Boolean> PROCESS_UNNAMED_VARIABLES = Key.create("ElementClassHint.PROCESS_UNNAMED_VARIABLES");
|
||||
|
||||
enum DeclarationKind {
|
||||
CLASS,
|
||||
PACKAGE,
|
||||
|
||||
Reference in New Issue
Block a user