use of com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo in project intellij-community by JetBrains.
the class JavaSafeDeleteDelegateForGroovy method createUsageInfoForParameter.
@Override
public void createUsageInfoForParameter(PsiReference reference, List<UsageInfo> usages, final PsiParameter parameter, final PsiMethod method) {
int index = method.getParameterList().getParameterIndex(parameter);
final PsiElement element = reference.getElement();
GrCall call = null;
if (element instanceof GrCall) {
call = (GrCall) element;
} else if (element.getParent() instanceof GrCall) {
call = (GrCall) element.getParent();
}
if (call != null) {
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(call);
//todo ???
if (signature == null)
return;
GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, call);
//todo???
if (argInfos == null)
return;
for (PsiElement arg : argInfos[index].args) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(arg, parameter, true));
}
} else if (element instanceof GrDocMethodReference) {
@NonNls final StringBuilder newText = new StringBuilder();
newText.append("/** @see ");
GrDocReferenceElement holder = ((GrDocMethodReference) element).getReferenceHolder();
if (holder != null) {
newText.append(holder.getText());
}
newText.append('#');
newText.append(method.getName());
newText.append('(');
final List<PsiParameter> parameters = new ArrayList<>(Arrays.asList(method.getParameterList().getParameters()));
parameters.remove(parameter);
newText.append(StringUtil.join(parameters, psiParameter -> parameter.getType().getCanonicalText(), ","));
newText.append(")*/");
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
@Override
public void deleteElement() throws IncorrectOperationException {
((GrDocMethodReference) element).bindToText(method.getProject(), newText.toString());
}
});
}
}
use of com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo in project intellij-community by JetBrains.
the class JavaSafeDeleteDelegateImpl method createUsageInfoForParameter.
@Override
public void createUsageInfoForParameter(final PsiReference reference, final List<UsageInfo> usages, final PsiParameter parameter, final PsiMethod method) {
int index = method.getParameterList().getParameterIndex(parameter);
final PsiElement element = reference.getElement();
PsiCall call = null;
if (element instanceof PsiCall) {
call = (PsiCall) element;
} else {
final PsiElement parent = element.getParent();
if (parent instanceof PsiCall) {
call = (PsiCall) parent;
} else if (parent instanceof PsiAnonymousClass) {
call = (PsiNewExpression) parent.getParent();
}
}
if (call != null) {
final PsiExpressionList argList = call.getArgumentList();
if (argList != null) {
final PsiExpression[] args = argList.getExpressions();
if (index < args.length) {
if (!parameter.isVarArgs()) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(args[index], parameter));
} else {
for (int i = index; i < args.length; i++) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(args[i], parameter));
}
}
}
}
} else if (element instanceof PsiDocMethodOrFieldRef) {
if (((PsiDocMethodOrFieldRef) element).getSignature() != null) {
@NonNls final StringBuffer newText = new StringBuffer();
newText.append("/** @see #").append(method.getName()).append('(');
final List<PsiParameter> parameters = new ArrayList<>(Arrays.asList(method.getParameterList().getParameters()));
parameters.remove(parameter);
newText.append(StringUtil.join(parameters, psiParameter -> psiParameter.getType().getCanonicalText(), ","));
newText.append(")*/");
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
public void deleteElement() throws IncorrectOperationException {
final PsiDocMethodOrFieldRef.MyReference javadocMethodReference = (PsiDocMethodOrFieldRef.MyReference) element.getReference();
if (javadocMethodReference != null) {
javadocMethodReference.bindToText(method.getContainingClass(), newText);
}
}
});
}
} else if (element instanceof PsiMethodReferenceExpression) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
public void deleteElement() throws IncorrectOperationException {
final PsiExpression callExpression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression) element);
if (callExpression instanceof PsiCallExpression) {
final PsiExpressionList expressionList = ((PsiCallExpression) callExpression).getArgumentList();
if (expressionList != null) {
final PsiExpression[] args = expressionList.getExpressions();
if (index < args.length) {
args[index].delete();
}
}
}
}
});
}
}
Aggregations