mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unnecessary local: don't raise for inherited targets (IDEA-145135)
This commit is contained in:
+15
-1
@@ -169,6 +169,9 @@ public class UnnecessaryLocalVariableInspectionBase extends BaseInspection {
|
||||
!HighlightControlFlowUtil.isEffectivelyFinal(initialization, containingScope, null) &&
|
||||
HighlightControlFlowUtil.isEffectivelyFinal(variable, containingScope, null);
|
||||
|
||||
final PsiType variableType = variable.getType();
|
||||
final PsiType initializationType = initialization.getType();
|
||||
final boolean sameType = Comparing.equal(variableType, initializationType);
|
||||
for (PsiReference ref : ReferencesSearch.search(variable, new LocalSearchScope(containingScope))) {
|
||||
final PsiElement refElement = ref.getElement();
|
||||
if (finalVariableIntroduction) {
|
||||
@@ -181,9 +184,20 @@ public class UnnecessaryLocalVariableInspectionBase extends BaseInspection {
|
||||
if (resolveHelper.resolveReferencedVariable(initializationName, refElement) != initialization) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sameType) {
|
||||
final PsiElement parent = refElement.getParent();
|
||||
if (parent instanceof PsiReferenceExpression) {
|
||||
final PsiElement resolve = ((PsiReferenceExpression)parent).resolve();
|
||||
if (resolve instanceof PsiMember &&
|
||||
((PsiMember)resolve).hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !TypeConversionUtil.boxingConversionApplicable(variable.getType(), initialization.getType());
|
||||
return !TypeConversionUtil.boxingConversionApplicable(variableType, initializationType);
|
||||
}
|
||||
|
||||
private boolean isImmediatelyReturned(PsiVariable variable) {
|
||||
|
||||
+31
@@ -154,4 +154,35 @@ class C {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
abstract class AbstractSchedulingElement<T extends AbstractSchedulingElement<T>> {
|
||||
private String scenarioSettings;
|
||||
public String scenarioSettings1;
|
||||
|
||||
public T copyInto(T target) {
|
||||
AbstractSchedulingElement<T> targetAsAbstractSchedulingElement = target;
|
||||
targetAsAbstractSchedulingElement.scenarioSettings = scenarioSettings;
|
||||
return target;
|
||||
}
|
||||
|
||||
public T copyInto1(T target) {
|
||||
AbstractSchedulingElement<T> <warning descr="Local variable 'targetAsAbstractSchedulingElement' is redundant">targetAsAbstractSchedulingElement</warning> = target;
|
||||
targetAsAbstractSchedulingElement.scenarioSettings1 = scenarioSettings1;
|
||||
return target;
|
||||
}
|
||||
|
||||
public SchedulingElement copyInto2(SchedulingElement target) {
|
||||
AbstractSchedulingElement<SchedulingElement> targetAsAbstractSchedulingElement = target;
|
||||
targetAsAbstractSchedulingElement.scenarioSettings = scenarioSettings;
|
||||
return target;
|
||||
}
|
||||
|
||||
public SchedulingElement copyInto3(SchedulingElement target) {
|
||||
AbstractSchedulingElement<SchedulingElement> <warning descr="Local variable 'targetAsAbstractSchedulingElement' is redundant">targetAsAbstractSchedulingElement</warning> = target;
|
||||
targetAsAbstractSchedulingElement.scenarioSettings1 = scenarioSettings1;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
class SchedulingElement extends AbstractSchedulingElement<SchedulingElement>{}
|
||||
}
|
||||
Reference in New Issue
Block a user