Search in sources :

Example 11 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression 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 12 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression 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 13 with PsiMethodCallExpression

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

the class AssertEqualsBetweenInconvertibleTypesTestNGInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {

        @Override
        public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
            super.visitMethodCallExpression(expression);
            final String errorMessage = AssertHint.areExpectedActualTypesCompatible(expression, true);
            if (errorMessage != null) {
                final PsiElement referenceNameElement = expression.getMethodExpression().getReferenceNameElement();
                if (referenceNameElement == null) {
                    return;
                }
                holder.registerProblem(referenceNameElement, errorMessage);
            }
        }
    };
}
Also used : JavaElementVisitor(com.intellij.psi.JavaElementVisitor) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project android by JetBrains.

the class InlinedResource method getResolvedString.

@Nullable
public String getResolvedString() {
    if (myResourceRepository != null) {
        if (myResourceRepository.hasResourceItem(myType, myKey)) {
            FolderConfiguration referenceConfig = new FolderConfiguration();
            // Nonexistent language qualifier: trick it to fall back to the default locale
            referenceConfig.setLocaleQualifier(new LocaleQualifier("xx"));
            ResourceValue value = myResourceRepository.getConfiguredValue(myType, myKey, referenceConfig);
            if (value != null) {
                String text = value.getValue();
                if (text != null) {
                    if (myElement instanceof PsiMethodCallExpression) {
                        text = insertArguments((PsiMethodCallExpression) myElement, text);
                    }
                    if (myType == ResourceType.PLURALS && text.startsWith(STRING_PREFIX)) {
                        value = myResourceRepository.getConfiguredValue(ResourceType.STRING, text.substring(STRING_PREFIX.length()), referenceConfig);
                        if (value != null && value.getValue() != null) {
                            text = value.getValue();
                            return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
                        }
                    }
                    if (myType == ResourceType.STRING || myElement instanceof XmlAttributeValue) {
                        return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
                    } else if (text.length() <= 1) {
                        // This is similar to how IntelliJ 14 handles call parameters
                        return myKey + ": " + text;
                    } else {
                        return StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH, 0);
                    }
                }
            }
        }
    }
    return null;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project Main by SpartanRefactoring.

the class LispLastElementTest method testCreateReplacement2.

public void testCreateReplacement2() {
    PsiMethodCallExpression methodCallExpression = createTestMethodCallExpression("x.get", "x.size()-1");
    assert new LispLastElement().canTip(methodCallExpression);
    assertEquals("last(x)", new LispLastElement().createReplacement(methodCallExpression).getText());
}
Also used : 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