Search in sources :

Example 16 with PsiReferenceExpression

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

the class JNDIResourceInspection method isResourceCreation.

protected boolean isResourceCreation(PsiExpression expression) {
    if (expression instanceof PsiMethodCallExpression) {
        final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
        final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
        @NonNls final String methodName = methodExpression.getReferenceName();
        if ("list".equals(methodName) || "listBindings".equals(methodName)) {
            final PsiExpression qualifier = methodExpression.getQualifierExpression();
            if (qualifier == null) {
                return false;
            }
            return TypeUtils.expressionHasTypeOrSubtype(qualifier, "javax.naming.Context");
        } else if ("getAll".equals(methodName)) {
            final PsiExpression qualifier = methodExpression.getQualifierExpression();
            if (qualifier == null) {
                return false;
            }
            return TypeUtils.expressionHasTypeOrSubtype(qualifier, "javax.naming.directory.Attribute", "javax.naming.directory.Attributes") != null;
        } else {
            return false;
        }
    } else if (expression instanceof PsiNewExpression) {
        return TypeUtils.expressionHasTypeOrSubtype(expression, "javax.naming.InitialContext");
    }
    return false;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiNewExpression(com.intellij.psi.PsiNewExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 17 with PsiReferenceExpression

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

the class SocketResourceInspection method isResourceCreation.

@Override
protected boolean isResourceCreation(PsiExpression expression) {
    if (expression instanceof PsiMethodCallExpression) {
        final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
        final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
        @NonNls final String methodName = methodExpression.getReferenceName();
        if (!"accept".equals(methodName)) {
            return false;
        }
        final PsiExpression qualifier = methodExpression.getQualifierExpression();
        if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.net.ServerSocket")) {
            return false;
        }
        return TypeUtils.expressionHasTypeOrSubtype(methodCallExpression, "java.net.Socket");
    } else if (expression instanceof PsiNewExpression) {
        return TypeUtils.expressionHasTypeOrSubtype(expression, "java.net.Socket", "java.net.DatagramSocket", "java.net.ServerSocket") != null;
    }
    return false;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiNewExpression(com.intellij.psi.PsiNewExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 18 with PsiReferenceExpression

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

the class GuessContainerElementTypeTest method guessContainerElementTypes.

private PsiType[] guessContainerElementTypes() {
    int offset = getEditor().getCaretModel().getOffset();
    PsiElement element = getFile().findElementAt(offset);
    assertNotNull(element);
    PsiElement parent = element.getParent();
    assertTrue(parent instanceof PsiReferenceExpression);
    PsiExpression expr = (PsiExpression) parent;
    return GuessManager.getInstance(getProject()).guessContainerElementType(expr, null);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiElement(com.intellij.psi.PsiElement)

Example 19 with PsiReferenceExpression

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

the class ReplaceThisCallWithDelegateCall method fixUsage.

public void fixUsage() throws IncorrectOperationException {
    final PsiReferenceExpression methodExpression = call.getMethodExpression();
    final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
    if (qualifierExpression == null) {
        MutationUtils.replaceExpression(delegateFieldName + '.' + call.getText(), call);
    } else {
        MutationUtils.replaceExpression(delegateFieldName, qualifierExpression);
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression)

Example 20 with PsiReferenceExpression

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

the class InlineLocalTest method performDefInline.

public static void performDefInline(Project project, Editor editor) {
    PsiReference reference = TargetElementUtil.findReference(editor);
    assertTrue(reference instanceof PsiReferenceExpression);
    final PsiElement local = reference.resolve();
    assertTrue(local instanceof PsiLocalVariable);
    InlineLocalHandler.invoke(project, editor, (PsiLocalVariable) local, (PsiReferenceExpression) reference);
}
Also used : PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiReference(com.intellij.psi.PsiReference) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)25 PsiElement (com.intellij.psi.PsiElement)15 PsiExpression (com.intellij.psi.PsiExpression)13 PsiField (com.intellij.psi.PsiField)9 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)9 PsiReference (com.intellij.psi.PsiReference)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiClass (com.intellij.psi.PsiClass)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)5 PsiMethod (com.intellij.psi.PsiMethod)5 ResourceType (com.android.resources.ResourceType)4 PsiStatement (com.intellij.psi.PsiStatement)4 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)3 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)3 PsiParenthesizedExpression (com.intellij.psi.PsiParenthesizedExpression)3 NonNls (org.jetbrains.annotations.NonNls)3