mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-12 19:06:35 +07:00
IDEA-80590 (hint to ignore unused for-each parameters and resource variables)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,6 +75,7 @@ import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureGestureDetector;
|
||||
import com.intellij.util.Processor;
|
||||
@@ -322,16 +323,18 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processLocalVariable(PsiLocalVariable variable, ProgressIndicator progress) {
|
||||
PsiIdentifier identifier = variable.getNameIdentifier();
|
||||
if (identifier == null) return null;
|
||||
if (variable instanceof PsiResourceVariable && PsiUtil.isIgnoredName(variable.getName())) return null;
|
||||
if (isImplicitUsage(variable, progress)) return null;
|
||||
|
||||
if (!myRefCountHolder.isReferenced(variable)) {
|
||||
String message = JavaErrorMessages.message("local.variable.is.never.used", identifier.getText());
|
||||
HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new RemoveUnusedVariableFix(variable), myUnusedSymbolKey);
|
||||
IntentionAction fix = variable instanceof PsiResourceVariable ? new RenameToIgnoredFix(variable) : new RemoveUnusedVariableFix(variable);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, fix, myUnusedSymbolKey);
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
@@ -356,7 +359,6 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isImplicitUsage(final PsiModifierListOwner element, ProgressIndicator progress) {
|
||||
if (UnusedSymbolLocalInspection.isInjected(element)) return true;
|
||||
for (ImplicitUsageProvider provider : ourImplicitUsageProviders) {
|
||||
@@ -506,10 +508,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (declarationScope instanceof PsiForeachStatement && !Comparing.strEqual(parameter.getName(), "ignore")) {
|
||||
else if (declarationScope instanceof PsiForeachStatement && !PsiUtil.isIgnoredName(parameter.getName())) {
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, progress);
|
||||
if (highlightInfo != null) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new EmptyIntentionAction(UnusedSymbolLocalInspection.DISPLAY_NAME), myUnusedSymbolKey);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new RenameToIgnoredFix(parameter), myUnusedSymbolKey);
|
||||
return highlightInfo;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -799,7 +799,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
if (aClass != null) {
|
||||
String className = aClass instanceof PsiAnonymousClass ? null : aClass.getName();
|
||||
if (!Comparing.strEqual(methodName, className)) {
|
||||
if (className != null && !Comparing.strEqual(methodName, className)) {
|
||||
errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, method.getNameIdentifier(),
|
||||
JavaErrorMessages.message("missing.return.type"));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new RenameElementFix(method, className));
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RenameToIgnoredFix extends RenameElementFix {
|
||||
public RenameToIgnoredFix(@NotNull PsiNamedElement element) {
|
||||
super(element, "ignored");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user