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);
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class AccessorReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (element instanceof PsiMethod) {
final String propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod) element);
if (propertyName == null)
return;
SearchScope scope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope());
queryParameters.getOptimizer().searchWord(propertyName, scope, UsageSearchContext.IN_CODE, true, element);
} else if (element instanceof GrField) {
for (GrAccessorMethod method : ((GrField) element).getGetters()) {
MethodReferencesSearch.search(method, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
final GrAccessorMethod setter = ((GrField) element).getSetter();
if (setter != null) {
MethodReferencesSearch.search(setter, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class GrLiteralMethodSearcher method processQuery.
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = p.getMethod();
final PsiClass aClass = method.getContainingClass();
if (aClass == null)
return;
final String name = method.getName();
if (StringUtil.isEmpty(name))
return;
final boolean strictSignatureSearch = p.isStrictSignatureSearch();
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[] { method } : aClass.findMethodsByName(name, false);
SearchScope accessScope = GroovyScopeUtil.getEffectiveScope(methods);
final SearchScope restrictedByAccess = GroovyScopeUtil.restrictScopeToGroovyFiles(p.getEffectiveSearchScope(), accessScope);
final String textToSearch = findLongestWord(name);
p.getOptimizer().searchWord(textToSearch, restrictedByAccess, UsageSearchContext.IN_STRINGS, true, method, new MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods));
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class EquivalenceChecker method newExpressionsAreEquivalent.
private static boolean newExpressionsAreEquivalent(@NotNull GrNewExpression newExp1, @NotNull GrNewExpression newExp2) {
final PsiMethod constructor1 = newExp1.resolveMethod();
final PsiMethod constructor2 = newExp2.resolveMethod();
if (constructor1 == null || constructor2 == null || !constructor1.equals(constructor2)) {
return false;
}
return argumentListsAreEquivalent(newExp1.getArgumentList(), newExp2.getArgumentList());
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class JavaStylePropertiesUtil method isGetterInvocation.
private static boolean isGetterInvocation(@NotNull GrMethodCall call) {
GrExpression expr = call.getInvokedExpression();
if (!(expr instanceof GrReferenceExpression))
return false;
PsiMethod method = call.resolveMethod();
if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
return false;
LOG.assertTrue(method != null);
if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameByGetterName(method.getName(), true), ((GrReferenceExpression) expr).getQualifier() != null, call.getProject())) {
return false;
}
GrArgumentList args = call.getArgumentList();
if (args.getAllArguments().length != 0) {
return false;
}
GrExpression ref = genRefForGetter(call, ((GrReferenceExpression) expr).getReferenceName());
if (ref instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) ref).resolve();
PsiManager manager = call.getManager();
if (manager.areElementsEquivalent(resolved, method) || areEquivalentAccessors(method, resolved, manager)) {
return true;
}
}
return false;
}
Aggregations