[java] Pattern variable can be used mass cleanup

GitOrigin-RevId: 46452d7711435b63fca78af3a6f634bcec862139
This commit is contained in:
Mikhail Pyltsin
2024-04-17 17:50:53 +02:00
committed by intellij-monorepo-bot
parent 31737a3bf3
commit 74e210570e
15 changed files with 18 additions and 17 deletions

View File

@@ -1317,7 +1317,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
PsiElement parent = expression.getParent();
if (parent instanceof PsiMethodCallExpression methodCallExpression &&
((PsiMethodCallExpression)parent).getMethodExpression() == expression &&
methodCallExpression.getMethodExpression() == expression &&
(!result.isAccessible() || !result.isStaticsScopeCorrect())) {
PsiExpressionList list = methodCallExpression.getArgumentList();
PsiResolveHelper resolveHelper = getResolveHelper(getProject());

View File

@@ -509,7 +509,7 @@ public final class TrackingRunner extends StandardDataFlowRunner {
if (other instanceof RangeDfaProblemType rangeProblem &&
myTemplate.equals(rangeProblem.myTemplate) &&
Objects.equals(myType, rangeProblem.myType)) {
return new RangeDfaProblemType(myTemplate, myRangeSet.join(((RangeDfaProblemType)other).myRangeSet), myType);
return new RangeDfaProblemType(myTemplate, myRangeSet.join(rangeProblem.myRangeSet), myType);
}
return super.tryMerge(other);
}

View File

@@ -553,7 +553,7 @@ public final class StringConcatenationInLoopsInspection extends BaseInspection {
String builderName = Objects.requireNonNull(builderVariable.getName());
if(assignment.getOperationTokenType().equals(JavaTokenType.EQ)) {
if (rValue instanceof PsiPolyadicExpression concat &&
((PsiPolyadicExpression)rValue).getOperationTokenType().equals(JavaTokenType.PLUS)) {
concat.getOperationTokenType().equals(JavaTokenType.PLUS)) {
PsiExpression[] operands = concat.getOperands();
if (operands.length > 1) {
// s = s + ...;

View File

@@ -38,7 +38,7 @@ public final class InstanceOfUtils {
if (!(castType instanceof PsiClassType classType)) {
return null;
}
if (((PsiClassType)castType).resolve() instanceof PsiTypeParameter) {
if (classType.resolve() instanceof PsiTypeParameter) {
return null;
}
final PsiClassType rawType = classType.rawType();

View File

@@ -121,7 +121,7 @@ public final class NonAtomicOperationOnVolatileFieldInspection extends BaseInspe
if (SynchronizationUtil.isInSynchronizedContext(reference)) {
return null;
}
return (PsiReferenceExpression)expression;
return reference;
}
}
}

View File

@@ -82,8 +82,8 @@ final class EqualsChecker {
}
}
if (operand instanceof PsiBinaryExpression binOp && binOp.getOperationTokenType().equals(JavaTokenType.EQEQ)) {
PsiExpression lOperand = ((PsiBinaryExpression)operand).getLOperand();
PsiExpression rOperand = ((PsiBinaryExpression)operand).getROperand();
PsiExpression lOperand = binOp.getLOperand();
PsiExpression rOperand = binOp.getROperand();
PsiField field = getField(lOperand, rOperand, that);
if (field != null) {
PsiType type = field.getType();

View File

@@ -563,7 +563,7 @@ public final class ConstantValueInspection extends AbstractBaseJavaLocalInspecti
final SimplifyBooleanExpressionFix fix = new SimplifyBooleanExpressionFix(expression, value);
// simplify intention already active
if (!fix.isAvailable(expression) ||
(SimplifyBooleanExpressionFix.canBeSimplified((PsiExpression)element) && expression instanceof PsiLiteralExpression)) {
(SimplifyBooleanExpressionFix.canBeSimplified(expression) && expression instanceof PsiLiteralExpression)) {
return null;
}
return fix;

View File

@@ -34,7 +34,7 @@ public class ExtractSuperClassProcessor extends ExtractSuperBaseProcessor {
@Override
protected boolean isInSuper(PsiElement member) {
if (member instanceof PsiField field) {
final PsiClass containingClass = ((PsiField)member).getContainingClass();
final PsiClass containingClass = field.getContainingClass();
if (myClass.isInheritor(containingClass, true)) return true;
return doMemberInfosContain(field);
}

View File

@@ -247,7 +247,7 @@ public final class PullUpConflictsUtil {
PsiClass aClass = method.getContainingClass();
if (aClass == null) continue;
PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, PsiSubstitutor.EMPTY);
MethodSignature signature = ((PsiMethod) member).getSignature(superSubstitutor);
MethodSignature signature = method.getSignature(superSubstitutor);
final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(superClass, signature, false);
if (superClassMethod != null && !superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
superMember = superClassMethod;

View File

@@ -39,7 +39,7 @@ public final class MoveMembersImpl {
for (PsiElement element : elements) {
if (element instanceof PsiMember member) {
preselectMembers.add(member);
if (!sourceClass.equals(((PsiMember)element).getContainingClass())) {
if (!sourceClass.equals(member.getContainingClass())) {
String message = RefactoringBundle.getCannotRefactorMessage(
RefactoringBundle.message("members.to.be.moved.should.belong.to.the.same.class"));
CommonRefactoringUtil.showErrorMessage(getRefactoringName(), message, HelpID.MOVE_MEMBERS, project);

View File

@@ -141,10 +141,10 @@ public class JavaSafeDeleteProcessor extends SafeDeleteProcessorDelegateBase {
psiMethods.add((PsiMethod)element);
return psiMethods;
}
if (element instanceof PsiParameter param && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod method) {
if (element instanceof PsiParameter param && param.getDeclarationScope() instanceof PsiMethod method) {
Set<PsiElement> parametersToDelete = new HashSet<>();
parametersToDelete.add(element);
int parameterIndex = method.getParameterList().getParameterIndex((PsiParameter) element);
int parameterIndex = method.getParameterList().getParameterIndex(param);
List<PsiMethod> superMethods = new ArrayList<>(Arrays.asList(method.findDeepestSuperMethods()));
if (superMethods.isEmpty()) {
superMethods.add(method);

View File

@@ -84,7 +84,7 @@ final class SliceForwardUtil {
if (from instanceof PsiParameter parameter) {
PsiElement scope = parameter.getDeclarationScope();
Collection<PsiParameter> parametersToAnalyze = new HashSet<>();
if (scope instanceof PsiMethod method && ((PsiMethod)scope).hasModifierProperty(PsiModifier.ABSTRACT)) {
if (scope instanceof PsiMethod method && method.hasModifierProperty(PsiModifier.ABSTRACT)) {
int index = method.getParameterList().getParameterIndex(parameter);
final Set<PsiMethod> implementors = new HashSet<>();

View File

@@ -385,7 +385,8 @@ final class SliceUtil {
}
}
}
if (parentExpr instanceof PsiUnaryExpression unaryExpression && ((PsiUnaryExpression)parentExpr).getOperand() == referenceExpression && (((PsiUnaryExpression)parentExpr).getOperationTokenType() == JavaTokenType.PLUSPLUS || ((PsiUnaryExpression)parentExpr).getOperationTokenType() == JavaTokenType.MINUSMINUS)) {
if (parentExpr instanceof PsiUnaryExpression unaryExpression && unaryExpression.getOperand() == referenceExpression && (
unaryExpression.getOperationTokenType() == JavaTokenType.PLUSPLUS || unaryExpression.getOperationTokenType() == JavaTokenType.MINUSMINUS)) {
return builder.process(unaryExpression, processor);
}
}

View File

@@ -105,7 +105,7 @@ public class RenameFix extends RefactoringInspectionGadgetsFix {
String message = RefactoringBundle.message("rename.0.and.its.usages.preview.text", what);
return new IntentionPreviewInfo.Html(HtmlChunk.text(message));
}
((PsiNamedElement)element).setName(m_targetName);
namedElement.setName(m_targetName);
return IntentionPreviewInfo.DIFF;
}
return IntentionPreviewInfo.EMPTY;

View File

@@ -96,7 +96,7 @@ public final class MakeCallChainIntoCallSequenceIntention extends MCIntention {
introduceVariable = false;
}
else if (parent instanceof PsiAssignmentExpression assignment && parent.getParent() instanceof PsiExpressionStatement &&
((PsiAssignmentExpression)parent).getOperationTokenType().equals(JavaTokenType.EQ)) {
assignment.getOperationTokenType().equals(JavaTokenType.EQ)) {
final PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(assignment.getLExpression());
if (lhs instanceof PsiReferenceExpression expression) {
final PsiElement target = expression.resolve();