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