Search in sources :

Example 96 with PsiMethod

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

the class GradleUrlProvider method getLocation.

@NotNull
@Override
public List<Location> getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
    if (!PROTOCOL_ID.equals(protocol))
        return Collections.emptyList();
    final String className = extractFullClassName(path);
    if (className == null)
        return Collections.emptyList();
    final PsiClass testClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
    if (testClass == null)
        return Collections.emptyList();
    final String methodName = extractMethodName(path);
    if (methodName == null) {
        return Collections.<Location>singletonList(new PsiLocation<>(project, testClass));
    }
    final PsiMethod[] methods = testClass.findMethodsByName(methodName, true);
    final List<Location> list = new ArrayList<>(methods.length);
    for (PsiMethod method : methods) {
        list.add(new PsiLocation<>(project, method));
    }
    return list;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with PsiMethod

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

the class TestMethodGradleConfigurationProducer method doSetupConfigurationFromContext.

@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    PsiMethod psiMethod = getPsiMethodForLocation(contextLocation);
    if (psiMethod == null)
        return false;
    sourceElement.set(psiMethod);
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null)
        return false;
    if (context.getModule() == null)
        return false;
    if (!applyTestMethodConfiguration(configuration, context, psiMethod, containingClass))
        return false;
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    return true;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) Location(com.intellij.execution.Location)

Example 98 with PsiMethod

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

the class RecursionUtils method methodCallExpressionDefinitelyRecurses.

private static boolean methodCallExpressionDefinitelyRecurses(GrMethodCallExpression exp, GrMethod method) {
    final GrExpression invoked = exp.getInvokedExpression();
    if (invoked instanceof GrReferenceExpression) {
        final GrReferenceExpression methodExpression = (GrReferenceExpression) invoked;
        final PsiMethod referencedMethod = exp.resolveMethod();
        if (referencedMethod == null) {
            return false;
        }
        final GrExpression qualifier = methodExpression.getQualifierExpression();
        if (referencedMethod.equals(method)) {
            if (method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) {
                return true;
            }
            if (qualifier == null || qualifier instanceof GrReferenceExpression && PsiUtil.isThisReference(qualifier)) {
                return true;
            }
        }
        if (expressionDefinitelyRecurses(qualifier, method)) {
            return true;
        }
    }
    return callExpressionDefinitelyRecurses(exp, method);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod)

Example 99 with PsiMethod

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

the class GroovyConditionalCanBeElvisInspection method checkForStringIsEmpty.

/**
   * checks for the case string.isEmpty() ? something_else : string
   */
private static boolean checkForStringIsEmpty(GrExpression condition, GrExpression elseBranch) {
    if (condition instanceof GrMethodCall)
        condition = ((GrMethodCall) condition).getInvokedExpression();
    if (!(condition instanceof GrReferenceExpression))
        return false;
    final GrExpression qualifier = ((GrReferenceExpression) condition).getQualifier();
    if (qualifier == null)
        return false;
    if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch))
        return false;
    final PsiType type = qualifier.getType();
    if (type == null)
        return false;
    if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING))
        return false;
    final PsiElement resolved = ((GrReferenceExpression) condition).resolve();
    return resolved instanceof PsiMethod && "isEmpty".equals(((PsiMethod) resolved).getName()) && ((PsiMethod) resolved).getParameterList().getParametersCount() == 0;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 100 with PsiMethod

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

the class NamedArgumentReference method handleElementRename.

@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
    final PsiElement resolved = resolve();
    if (resolved instanceof PsiMethod) {
        final PsiMethod method = (PsiMethod) resolved;
        final String oldName = getElement().getName();
        if (!method.getName().equals(oldName)) {
            //was property reference to accessor
            if (PropertyUtil.isSimplePropertySetter(method)) {
                final String newPropertyName = PropertyUtil.getPropertyName(newElementName);
                if (newPropertyName != null) {
                    newElementName = newPropertyName;
                }
            }
        }
    }
    return super.handleElementRename(newElementName);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)229 PsiClass (com.intellij.psi.PsiClass)97 PsiElement (com.intellij.psi.PsiElement)71 ArrayList (java.util.ArrayList)24 NotNull (org.jetbrains.annotations.NotNull)22 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)16 PsiField (com.intellij.psi.PsiField)13 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)12 Location (com.intellij.execution.Location)11 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)9 PsiReference (com.intellij.psi.PsiReference)9 PsiFile (com.intellij.psi.PsiFile)8 List (java.util.List)7 Nullable (com.android.annotations.Nullable)6 Module (com.intellij.openapi.module.Module)6 PsiType (com.intellij.psi.PsiType)6 SearchScope (com.intellij.psi.search.SearchScope)6 PsiParameter (com.intellij.psi.PsiParameter)5 UExpression (org.jetbrains.uast.UExpression)5