Search in sources :

Example 61 with PsiMethod

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

the class GradleDocumentationProvider method findDoc.

@Nullable
private static String findDoc(@Nullable PsiElement element, Object argValue) {
    String result = null;
    if (element instanceof GrLiteral) {
        GrLiteral grLiteral = (GrLiteral) element;
        PsiElement stmt = PsiTreeUtil.findFirstParent(grLiteral, psiElement -> psiElement instanceof GrCall);
        if (stmt instanceof GrCall) {
            GrCall grCall = (GrCall) stmt;
            PsiMethod psiMethod = grCall.resolveMethod();
            if (psiMethod != null && psiMethod.getContainingClass() != null) {
                //noinspection ConstantConditions
                String qualifiedName = psiMethod.getContainingClass().getQualifiedName();
                if (grLiteral.getParent() instanceof GrNamedArgument) {
                    GrNamedArgument namedArgument = (GrNamedArgument) grLiteral.getParent();
                    String key = StringUtil.join(new String[] { "gradle.documentation", qualifiedName, psiMethod.getName(), namedArgument.getLabelName(), String.valueOf(argValue) }, ".");
                    result = GradleDocumentationBundle.messageOrDefault(key, "");
                }
            }
        }
    }
    return result;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) PsiMethod(com.intellij.psi.PsiMethod) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 62 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 63 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 64 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 65 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)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)232 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 PsiAnnotation (com.intellij.psi.PsiAnnotation)7 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