use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference 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 org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference in project intellij-community by JetBrains.
the class GroovyDocCheckInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitDocMethodReference(@NotNull GrDocMethodReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitDocFieldReference(@NotNull GrDocFieldReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement refElement) {
GroovyResolveResult resolveResult = refElement.advancedResolve();
if (refElement.getReferenceName() == null)
return;
if (PsiTreeUtil.getParentOfType(refElement, GroovyDocPsiElement.class, true, GrMember.class, GrCodeBlock.class) == null)
return;
final PsiElement resolved = resolveResult.getElement();
if (resolved != null)
return;
final PsiElement toHighlight = refElement.getReferenceNameElement();
registerError(toHighlight, GroovyBundle.message("cannot.resolve", refElement.getReferenceName()));
}
private void checkGrDocMemberReference(final GrDocMemberReference reference) {
if (reference.resolve() != null)
return;
registerError(reference.getReferenceNameElement(), GroovyBundle.message("cannot.resolve", reference.getReferenceName()));
}
};
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference in project intellij-community by JetBrains.
the class GroovyDocMethodHandler method shortenParamterReferences.
private static int shortenParamterReferences(InsertionContext context, int startOffset, PsiMethod method, StringBuffer buffer) {
Document document = context.getEditor().getDocument();
int offset = startOffset + method.getName().length();
String paramText = buffer.toString();
document.insertString(offset, paramText);
int endOffset = offset + paramText.length();
final Project project = context.getProject();
PsiDocumentManager.getInstance(project).commitDocument(document);
PsiReference ref = context.getFile().findReferenceAt(startOffset);
if (ref instanceof GrDocMethodReference) {
GrDocMethodReference methodReference = (GrDocMethodReference) ref;
GrDocMethodParams list = methodReference.getParameterList();
for (GrDocMethodParameter parameter : list.getParameters()) {
JavaCodeStyleManager.getInstance(project).shortenClassReferences(parameter);
}
endOffset = methodReference.getTextRange().getEndOffset() + 1;
}
return endOffset;
}
Aggregations