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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations