Search in sources :

Example 6 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project intellij-community by JetBrains.

the class ReturnWrappedValue method fixUsage.

@Override
public void fixUsage() throws IncorrectOperationException {
    PsiMethodCallExpression returnValue = (PsiMethodCallExpression) myStatement.getReturnValue();
    assert returnValue != null;
    PsiExpression qualifier = returnValue.getMethodExpression().getQualifierExpression();
    assert qualifier != null;
    MutationUtils.replaceExpression(qualifier.getText(), returnValue);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 7 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project intellij-community by JetBrains.

the class InlineCallFix method doFix.

@Override
public void doFix(final Project project, ProblemDescriptor descriptor) {
    final PsiElement nameElement = descriptor.getPsiElement();
    final PsiReferenceExpression methodExpression = (PsiReferenceExpression) nameElement.getParent();
    if (methodExpression == null)
        return;
    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) methodExpression.getParent();
    final PsiMethod method = methodCallExpression.resolveMethod();
    if (method == null)
        return;
    inline(project, methodExpression, method);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiElement(com.intellij.psi.PsiElement) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 8 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project intellij-community by JetBrains.

the class HibernateResourceInspection method isResourceCreation.

protected boolean isResourceCreation(PsiExpression expression) {
    if (!(expression instanceof PsiMethodCallExpression)) {
        return false;
    }
    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
    final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    final String methodName = methodExpression.getReferenceName();
    if (!HardcodedMethodConstants.OPEN_SESSION.equals(methodName)) {
        return false;
    }
    final PsiExpression qualifier = methodExpression.getQualifierExpression();
    return qualifier != null && TypeUtils.expressionHasTypeOrSubtype(qualifier, "org.hibernate.SessionFactory");
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 9 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project timber by JakeWharton.

the class WrongTimberUsageDetector method checkExceptionLogging.

private static void checkExceptionLogging(JavaContext context, PsiMethodCallExpression call) {
    PsiExpression[] arguments = call.getArgumentList().getExpressions();
    if (arguments.length > 1) {
        boolean isFirstParameterThrowable = isSubclassOf(context, arguments[0], Throwable.class);
        if (isFirstParameterThrowable) {
            PsiExpression secondArgument = arguments[1];
            String message = findLiteralValue(secondArgument);
            boolean callsGetMessage = false;
            if (secondArgument instanceof PsiMethodCallExpression) {
                PsiMethodCallExpression callExpression = (PsiMethodCallExpression) secondArgument;
                callsGetMessage = callExpression.getMethodExpression().getCanonicalText().endsWith("getMessage");
            }
            if (callsGetMessage) {
                context.report(ISSUE_EXCEPTION_LOGGING, secondArgument, context.getLocation(secondArgument), "Explicitly logging exception message is redundant");
            } else if (message == null || "".equals(message)) {
                context.report(ISSUE_EXCEPTION_LOGGING, secondArgument, context.getLocation(secondArgument), "Use single-argument log method instead of null/empty message");
            }
        }
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 10 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project intellij-community by JetBrains.

the class MethodCallSelectioner method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    PsiMethodCallExpression methodCall = (PsiMethodCallExpression) e;
    PsiElement referenceNameElement = methodCall.getMethodExpression().getReferenceNameElement();
    if (referenceNameElement == null) {
        return null;
    } else {
        return Collections.singletonList(new TextRange(referenceNameElement.getTextRange().getStartOffset(), methodCall.getTextRange().getEndOffset()));
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Aggregations

PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)15 PsiExpression (com.intellij.psi.PsiExpression)8 PsiElement (com.intellij.psi.PsiElement)6 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)6 PsiMethod (com.intellij.psi.PsiMethod)4 Nullable (com.android.annotations.Nullable)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)2 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)2 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)2 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)2 PsiField (com.intellij.psi.PsiField)2 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)2 PsiNewExpression (com.intellij.psi.PsiNewExpression)2 PsiParenthesizedExpression (com.intellij.psi.PsiParenthesizedExpression)2 PsiReference (com.intellij.psi.PsiReference)2 PsiStatement (com.intellij.psi.PsiStatement)2 NonNls (org.jetbrains.annotations.NonNls)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1