Search in sources :

Example 1 with GrDocMethodReference

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());
            }
        });
    }
}
Also used : SafeDeleteReferenceJavaDeleteUsageInfo(com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrDocReferenceElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) ArrayList(java.util.ArrayList) List(java.util.List) GrDocMethodReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference)

Example 2 with GrDocMethodReference

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()));
        }
    };
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) BaseInspectionVisitor(org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrDocFieldReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocFieldReference) GrDocMemberReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) GrDocMethodReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference) GrCodeBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GrDocMethodReference

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;
}
Also used : Project(com.intellij.openapi.project.Project) GrDocMethodParams(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams) Document(com.intellij.openapi.editor.Document) GrDocMethodParameter(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParameter) GrDocMethodReference(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference)

Aggregations

GrDocMethodReference (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference)3 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 SafeDeleteReferenceJavaDeleteUsageInfo (com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 BaseInspectionVisitor (org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor)1 GrDocFieldReference (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocFieldReference)1 GrDocMemberReference (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference)1 GrDocMethodParameter (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParameter)1 GrDocMethodParams (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams)1 GrDocReferenceElement (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement)1 GroovyDocPsiElement (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)1 GrCodeBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock)1 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)1 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)1