Search in sources :

Example 1 with GrDocMethodParams

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams in project intellij-community by JetBrains.

the class GroovyDocParamsSelectioner method select.

@Override
public List<TextRange> select(PsiElement element, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = super.select(element, editorText, cursorOffset, editor);
    if (element instanceof GrDocMethodParams) {
        GrDocMethodParams params = ((GrDocMethodParams) element);
        TextRange range = params.getTextRange();
        if (range.contains(cursorOffset)) {
            PsiElement leftParen = params.getLeftParen();
            PsiElement rightParen = params.getRightParen();
            int leftOffset = leftParen.getTextOffset();
            if (rightParen != null) {
                if (leftOffset + 1 < rightParen.getTextOffset()) {
                    int rightOffset = rightParen.getTextRange().getEndOffset();
                    range = new TextRange(leftParen.getTextRange().getStartOffset() + 1, rightOffset - 1);
                    result.add(range);
                }
            } else {
                range = new TextRange(leftParen.getTextRange().getStartOffset() + 1, element.getTextRange().getEndOffset());
                result.add(range);
            }
        }
    }
    return result;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) GrDocMethodParams(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GrDocMethodParams

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams 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

GrDocMethodParams (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams)2 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 GrDocMethodParameter (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParameter)1 GrDocMethodReference (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference)1