public void visitReferenceExpression(PsiReferenceExpression expression) { super.visitReferenceExpression(expression); final PsiElement referent = expression.resolve(); if (!(referent instanceof PsiParameter)) { return; } final PsiParameter parameter = (PsiParameter) referent; if (paramsToMerge.contains(parameter)) { parameterUsages.add(expression); } }
private void findUsagesForMethod( PsiMethod overridingMethod, List<FixableUsageInfo> usages, boolean changeSignature) { final PsiCodeBlock body = overridingMethod.getBody(); final String baseParameterName = StringUtil.decapitalize(className); final String fixedParamName = body != null ? JavaCodeStyleManager.getInstance(myProject) .suggestUniqueVariableName(baseParameterName, body.getLBrace(), true) : JavaCodeStyleManager.getInstance(myProject) .propertyNameToVariableName(baseParameterName, VariableKind.PARAMETER); usages.add( new MergeMethodArguments( overridingMethod, className, packageName, fixedParamName, paramsToMerge, typeParams, keepMethodAsDelegate, myCreateInnerClass ? method.getContainingClass() : null, changeSignature)); final ParamUsageVisitor visitor = new ParamUsageVisitor(overridingMethod, paramsToMerge); overridingMethod.accept(visitor); final Set<PsiReferenceExpression> values = visitor.getParameterUsages(); for (PsiReferenceExpression paramUsage : values) { final PsiParameter parameter = (PsiParameter) paramUsage.resolve(); assert parameter != null; final PsiMethod containingMethod = (PsiMethod) parameter.getDeclarationScope(); final int index = containingMethod.getParameterList().getParameterIndex(parameter); final PsiParameter replacedParameter = method.getParameterList().getParameters()[index]; final ParameterChunk parameterChunk = ParameterChunk.getChunkByParameter(parameter, parameters); @NonNls String getter = parameterChunk != null ? parameterChunk.getter : null; final String paramName = parameterChunk != null ? parameterChunk.parameter.name : replacedParameter.getName(); final PsiType paramType = parameterChunk != null ? parameterChunk.parameter.type : replacedParameter.getType(); if (getter == null) { getter = GenerateMembersUtil.suggestGetterName(paramName, paramType, myProject); paramsNeedingGetters.add(replacedParameter); } @NonNls String setter = parameterChunk != null ? parameterChunk.setter : null; if (setter == null) { setter = GenerateMembersUtil.suggestSetterName(paramName, paramType, myProject); } if (RefactoringUtil.isPlusPlusOrMinusMinus(paramUsage.getParent())) { usages.add( new ReplaceParameterIncrementDecrement(paramUsage, fixedParamName, setter, getter)); if (parameterChunk == null || parameterChunk.setter == null) { paramsNeedingSetters.add(replacedParameter); } } else if (RefactoringUtil.isAssignmentLHS(paramUsage)) { usages.add( new ReplaceParameterAssignmentWithCall(paramUsage, fixedParamName, setter, getter)); if (parameterChunk == null || parameterChunk.setter == null) { paramsNeedingSetters.add(replacedParameter); } } else { usages.add(new ReplaceParameterReferenceWithCall(paramUsage, fixedParamName, getter)); } } }