Search in sources :

Example 16 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 17 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)

Example 18 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)

Example 19 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineForbiddenCodeInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    final Project project = manager.getProject();
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    final AppEngineStandardFacet appEngineStandardFacet = AppEngineStandardFacet.getAppEngineFacetByModule(module);
    if (appEngineStandardFacet == null) {
        return null;
    }
    if (appEngineStandardFacet.getRuntimeJavaVersion().atLeast(JavaVersion.JAVA_1_8)) {
        return null;
    }
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
    file.accept(new JavaRecursiveElementWalkingVisitor() {

        CloudSdkInternals sdkInternals = CloudSdkInternals.getInstance();

        @Override
        public void visitDocComment(PsiDocComment comment) {
        }

        @Override
        public void visitMethod(PsiMethod method) {
            final PsiModifierList modifierList = method.getModifierList();
            if (modifierList.hasModifierProperty(PsiModifier.NATIVE)) {
                if (!isNativeMethodAllowed(method)) {
                    problems.add(manager.createProblemDescriptor(modifierList, "Native methods aren't allowed in App Engine application", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                }
            }
            super.visitMethod(method);
        }

        @Override
        public void visitNewExpression(PsiNewExpression expression) {
            final PsiJavaCodeReferenceElement classReference = expression.getClassReference();
            if (classReference != null) {
                final PsiElement resolved = classReference.resolve();
                if (resolved instanceof PsiClass) {
                    final String qualifiedName = ((PsiClass) resolved).getQualifiedName();
                    if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, "new")) {
                        final String message = "App Engine application should not create new instances of '" + qualifiedName + "' class";
                        problems.add(manager.createProblemDescriptor(classReference, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitNewExpression(expression);
        }

        @Override
        public void visitMethodCallExpression(PsiMethodCallExpression expression) {
            final PsiReferenceExpression methodExpression = expression.getMethodExpression();
            final PsiElement element = methodExpression.resolve();
            if (element instanceof PsiMethod) {
                final PsiMethod method = (PsiMethod) element;
                final PsiClass psiClass = method.getContainingClass();
                if (psiClass != null) {
                    final String qualifiedName = psiClass.getQualifiedName();
                    final String methodName = method.getName();
                    if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, methodName)) {
                        final String message = "AppEngine application should not call '" + StringUtil.getShortName(qualifiedName) + "" + methodName + "' method";
                        problems.add(manager.createProblemDescriptor(methodExpression, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitMethodCallExpression(expression);
        }

        @Override
        public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
            final PsiElement resolved = reference.resolve();
            if (resolved instanceof PsiClass) {
                final PsiFile psiFile = resolved.getContainingFile();
                if (psiFile != null) {
                    final VirtualFile virtualFile = psiFile.getVirtualFile();
                    if (virtualFile != null && !fileIndex.isInSource(virtualFile)) {
                        final List<OrderEntry> list = fileIndex.getOrderEntriesForFile(virtualFile);
                        for (OrderEntry entry : list) {
                            if (entry instanceof JdkOrderEntry) {
                                final String className = ClassUtil.getJVMClassName((PsiClass) resolved);
                                if (className != null && !sdkInternals.isClassInWhiteList(className)) {
                                    problems.add(manager.createProblemDescriptor(reference, "Class '" + className + "' is not included in App Engine JRE White List", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                                }
                            }
                        }
                    }
                }
            }
            super.visitReferenceElement(reference);
        }
    });
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiMethod(com.intellij.psi.PsiMethod) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) ArrayList(java.util.ArrayList) CloudSdkInternals(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkInternals) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) PsiFile(com.intellij.psi.PsiFile) ArrayList(java.util.ArrayList) PsiModifierList(com.intellij.psi.PsiModifierList) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) JavaRecursiveElementWalkingVisitor(com.intellij.psi.JavaRecursiveElementWalkingVisitor) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) PsiClass(com.intellij.psi.PsiClass) PsiNewExpression(com.intellij.psi.PsiNewExpression) PsiModifierList(com.intellij.psi.PsiModifierList) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) AppEngineStandardFacet(com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet) Module(com.intellij.openapi.module.Module)

Example 20 with PsiMethodCallExpression

use of com.intellij.psi.PsiMethodCallExpression in project oxy-template-support-plugin by mutant-industries.

the class JavaMacroParamSuggestionProvider method getParamsPulledFromParamHelper.

private MacroParamSuggestionSet getParamsPulledFromParamHelper(PsiLocalVariable paramHelper) {
    MacroParamSuggestionSet params = new MacroParamSuggestionSet();
    PsiReferenceExpression methodReference;
    for (PsiReference reference : ReferencesSearch.search(paramHelper).findAll()) {
        if ((methodReference = PsiTreeUtil.getParentOfType(reference.getElement(), PsiReferenceExpression.class)) != null) {
            String parameterName = null;
            boolean required = false;
            boolean notNull = true;
            String type = JSCommonTypeNames.ANY_TYPE_NAME;
            String defaultValue = null;
            while (methodReference != null) {
                if (!(methodReference.getParent() instanceof PsiMethodCallExpression) || methodReference.getReferenceName() == null) {
                    break;
                }
                PsiMethodCallExpression callExpression = (PsiMethodCallExpression) methodReference.getParent();
                PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
                if (expressions.length == 0) {
                    break;
                }
                switch(methodReference.getReferenceName()) {
                    case PARAMETER_METHOD:
                    case PULL_PARAMETER_METHOD:
                        parameterName = getExpressionValue(expressions[0]);
                        if (expressions.length == 2 && expressions[1].getFirstChild() instanceof PsiTypeElement) {
                            type = InnerJsJavaTypeConverter.modifyCollectionType(((PsiTypeElement) expressions[1].getFirstChild()).getType(), paramHelper.getProject());
                        }
                        break;
                    case PULL_INTEGER_VALUE_METHOD:
                        parameterName = getExpressionValue(expressions[0]);
                        notNull = expressions.length < 2;
                        required = expressions.length < 2;
                        type = JSCommonTypeNames.NUMBER_TYPE_NAME;
                        if (expressions.length == 2) {
                            defaultValue = getExpressionValue(expressions[1]);
                        }
                        break;
                    case PULL_BOOLEAN_VALUE_METHOD:
                        parameterName = getExpressionValue(expressions[0]);
                        notNull = false;
                        required = false;
                        type = JSCommonTypeNames.BOOLEAN_TYPE_NAME;
                        if (expressions.length == 2) {
                            defaultValue = getExpressionValue(expressions[1]);
                        }
                        break;
                    case SET_NON_NULL_METHOD:
                        notNull = Boolean.parseBoolean(expressions[0].getText());
                        break;
                    case SET_REQUIRED_METHOD:
                        required = Boolean.parseBoolean(expressions[0].getText());
                        break;
                }
                methodReference = PsiTreeUtil.getParentOfType(methodReference, PsiReferenceExpression.class);
            }
            if (parameterName != null) {
                params.add(new JavaMacroParamDescriptor(parameterName, macro, notNull, required, type, defaultValue));
            }
        }
    // TODO the case when object is passed to another method
    }
    return params;
}
Also used : MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiTypeElement(com.intellij.psi.PsiTypeElement) PsiReference(com.intellij.psi.PsiReference) JavaMacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.JavaMacroParamDescriptor) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Aggregations

PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)21 PsiExpression (com.intellij.psi.PsiExpression)11 PsiElement (com.intellij.psi.PsiElement)10 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)9 PsiMethod (com.intellij.psi.PsiMethod)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)4 PsiReference (com.intellij.psi.PsiReference)4 Nullable (com.android.annotations.Nullable)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)2 PsiClass (com.intellij.psi.PsiClass)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 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)2 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)2 PsiParenthesizedExpression (com.intellij.psi.PsiParenthesizedExpression)2 PsiStatement (com.intellij.psi.PsiStatement)2 NonNls (org.jetbrains.annotations.NonNls)2