Search in sources :

Example 36 with GrReferenceExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.

the class GroovyArgListSelectioner 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 GrArgumentList) {
        GrArgumentList args = ((GrArgumentList) element);
        TextRange range = args.getTextRange();
        if (range.contains(cursorOffset)) {
            PsiElement leftParen = args.getLeftParen();
            PsiElement rightParen = args.getRightParen();
            if (leftParen != null) {
                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);
                }
            }
        }
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof GrReferenceExpression) {
        final GrArgumentList argumentList = ((GrCall) parent.getParent()).getArgumentList();
        final PsiElement refName = ((GrReferenceExpression) parent).getReferenceNameElement();
        if (argumentList != null && refName == element) {
            result.add(new TextRange(refName.getTextRange().getStartOffset(), argumentList.getTextRange().getEndOffset()));
        }
    }
    return result;
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 37 with GrReferenceExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.

the class GroovyShellCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiFile file = parameters.getOriginalFile();
    if (!(file instanceof GroovyShellCodeFragment))
        return;
    PsiElement position = parameters.getPosition();
    PsiElement parent = position.getParent();
    if (!(parent instanceof GrReferenceExpression && !((GrReferenceExpression) parent).isQualified()))
        return;
    if (PsiUtil.isExpressionStatement(parent)) {
        addAllCommands(result);
    } else if (parent.getParent() instanceof GrCommandArgumentList) {
        PsiElement ppparent = parent.getParent().getParent();
        if (ppparent instanceof GrMethodCall && isFirstArg((GrMethodCall) ppparent, parent)) {
            GrExpression invokedExpression = ((GrMethodCall) ppparent).getInvokedExpression();
            if (invokedExpression instanceof GrReferenceExpression && !((GrReferenceExpression) invokedExpression).isQualified()) {
                String name = ((GrReferenceExpression) invokedExpression).getReferenceName();
                if ("help".equals(name)) {
                    addAllCommands(result);
                } else if ("show".equals(name)) {
                    add(result, "classes");
                    add(result, "imports");
                    add(result, "preferences");
                    add(result, "all");
                } else if ("purge".equals(name)) {
                    add(result, "variables");
                    add(result, "classes");
                    add(result, "imports");
                    add(result, "preferences");
                    add(result, "all");
                } else if ("record".equals(name)) {
                    add(result, "start");
                    add(result, "stop");
                    add(result, "status");
                } else if ("history".equals(name)) {
                    add(result, "show");
                    add(result, "recall");
                    add(result, "flush");
                    add(result, "clear");
                }
            }
        }
    }
}
Also used : GrCommandArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiFile(com.intellij.psi.PsiFile) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 38 with GrReferenceExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.

the class DynamicTest method testMethod.

public void testMethod() throws Throwable {
    final GrReferenceExpression referenceExpression = doDynamicFix();
    final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false);
    final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes);
    final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes);
    assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)));
}
Also used : GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 39 with GrReferenceExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.

the class GroovyIntroduceParameterObjectDelegate method collectInternalUsages.

@Override
public <M1 extends PsiNamedElement, P1 extends ParameterInfo> ReadWriteAccessDetector.Access collectInternalUsages(Collection<FixableUsageInfo> usages, GrMethod overridingMethod, IntroduceParameterObjectClassDescriptor<M1, P1> classDescriptor, P1 parameterInfo, String mergedParamName) {
    final int oldIndex = parameterInfo.getOldIndex();
    final GrParameter parameter = overridingMethod.getParameterList().getParameters()[oldIndex];
    final ReadWriteAccessDetector.Access[] accessors = new ReadWriteAccessDetector.Access[1];
    final String setter = classDescriptor.getSetterName(parameterInfo, overridingMethod);
    final String getter = classDescriptor.getGetterName(parameterInfo, overridingMethod);
    ReferencesSearch.search(parameter, new LocalSearchScope(overridingMethod)).forEach(reference -> {
        final PsiElement element = reference.getElement();
        if (element instanceof GrReferenceExpression) {
            accessors[0] = ReadWriteAccessDetector.Access.Read;
            usages.add(new GrReplaceParameterReferenceWithCall(element, getter, mergedParamName));
        }
        return true;
    });
    return accessors[0];
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 40 with GrReferenceExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.

the class GrAliasImportIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    GrImportStatement context;
    final PsiMember resolved;
    if (element instanceof GrReferenceExpression) {
        GrReferenceExpression ref = (GrReferenceExpression) element;
        GroovyResolveResult result = ref.advancedResolve();
        context = (GrImportStatement) result.getCurrentFileResolveContext();
        assert context != null;
        resolved = (PsiMember) result.getElement();
    } else if (element instanceof GrImportStatement) {
        context = (GrImportStatement) element;
        resolved = (PsiMember) context.getImportReference().resolve();
    } else {
        return;
    }
    assert resolved != null;
    doRefactoring(project, context, resolved);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)177 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)92 PsiElement (com.intellij.psi.PsiElement)56 Nullable (org.jetbrains.annotations.Nullable)28 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)27 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)26 NotNull (org.jetbrains.annotations.NotNull)25 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)22 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)22 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)21 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)17 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)16 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)15 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)14 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)14 PsiType (com.intellij.psi.PsiType)13 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)12 Project (com.intellij.openapi.project.Project)11 ArrayList (java.util.ArrayList)11 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)11