Search in sources :

Example 66 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)

Example 67 with PsiMethod

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);
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) PsiMethod(com.intellij.psi.PsiMethod) SearchScope(com.intellij.psi.search.SearchScope) PsiElement(com.intellij.psi.PsiElement)

Example 68 with PsiMethod

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));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) SearchScope(com.intellij.psi.search.SearchScope) MethodTextOccurrenceProcessor(com.intellij.psi.impl.search.MethodTextOccurrenceProcessor)

Example 69 with PsiMethod

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());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod)

Example 70 with PsiMethod

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;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) PsiManager(com.intellij.psi.PsiManager) PsiElement(com.intellij.psi.PsiElement)

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