Search in sources :

Example 1 with PerlClassAccessorMethod

use of com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod in project Perl5-IDEA by Camelcade.

the class ClassAccessorReferencesSearcher method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    PsiElement element = queryParameters.getElementToSearch();
    if (element instanceof PerlClassAccessorMethod) {
        queryParameters.getOptimizer().searchWord(((PerlClassAccessorMethod) element).getSubName(), queryParameters.getEffectiveSearchScope(), true, element);
        PerlClassAccessorMethod pairedMethod = ((PerlClassAccessorMethod) element).getPairedMethod();
        if (pairedMethod != null) {
            queryParameters.getOptimizer().searchWord(pairedMethod.getSubName(), queryParameters.getEffectiveSearchScope(), true, pairedMethod);
        }
    }
}
Also used : PerlClassAccessorMethod(com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PerlClassAccessorMethod

use of com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod in project Perl5-IDEA by Camelcade.

the class PerlRenamePolyReferencedElementProcessor method prepareRenaming.

@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames, SearchScope scope) {
    final String currentBaseName = ((PsiNameIdentifierOwner) element).getName();
    if (currentBaseName != null && StringUtil.isNotEmpty(newName)) {
        boolean globScanned = element instanceof PerlGlobVariable;
        for (PsiReference reference : ReferencesSearch.search(element, element.getUseScope()).findAll()) {
            if (reference instanceof PsiPolyVariantReference) {
                for (ResolveResult resolveResult : ((PsiPolyVariantReference) reference).multiResolve(false)) {
                    PsiElement resolveResultElement = resolveResult.getElement();
                    if (!allRenames.containsKey(resolveResultElement)) {
                        allRenames.put(resolveResultElement, newName);
                        if (!globScanned && resolveResultElement instanceof PerlGlobVariable) {
                            globScanned = true;
                            prepareRenaming(resolveResultElement, newName, allRenames, scope);
                        }
                    }
                }
            }
            processDocReference(currentBaseName, newName, reference, allRenames);
        }
        if (element instanceof PerlSubElement && ((PerlSubElement) element).isMethod()) {
            for (PerlSubElement overridingSub : PerlSubUtil.collectOverridingSubs((PerlSubElement) element)) {
                allRenames.put(overridingSub, newName);
            }
        }
        // following is the hack until #1730 is fixed
        Set<PsiElement> allElements = new THashSet<>(allRenames.keySet());
        allElements.stream().filter(e -> e instanceof PerlClassAccessorMethod).forEach(e -> {
            PerlClassAccessorMethod pairedMethod = ((PerlClassAccessorMethod) e).getPairedMethod();
            if (pairedMethod != null && allRenames.containsKey(e)) {
                allRenames.remove(pairedMethod);
            }
        });
    }
}
Also used : ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) PerlGlobVariable(com.perl5.lang.perl.psi.PerlGlobVariable) PerlSubUtil(com.perl5.lang.perl.util.PerlSubUtil) RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) THashSet(gnu.trove.THashSet) SearchScope(com.intellij.psi.search.SearchScope) PerlClassAccessorMethod(com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler) PerlIcons(com.perl5.PerlIcons) Map(java.util.Map) Messages(com.intellij.openapi.ui.Messages) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) PodLanguage(com.perl5.lang.pod.PodLanguage) PerlClassAccessorMethod(com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod) THashSet(gnu.trove.THashSet) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) PerlGlobVariable(com.perl5.lang.perl.psi.PerlGlobVariable)

Example 3 with PerlClassAccessorMethod

use of com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod in project Perl5-IDEA by Camelcade.

the class PerlClassAccessorWrapper method calcLightElementsFromPsi.

@NotNull
@Override
public List<PerlDelegatingLightNamedElement> calcLightElementsFromPsi() {
    String packageName = PerlPackageUtil.getContextPackageName(this);
    if (StringUtil.isEmpty(packageName)) {
        return Collections.emptyList();
    }
    List<PsiElement> listElements = getCallArgumentsList();
    if (listElements.isEmpty()) {
        return Collections.emptyList();
    }
    List<PerlDelegatingLightNamedElement> result = new ArrayList<>();
    for (PsiElement listElement : listElements) {
        if (!isAcceptableIdentifierElement(listElement)) {
            continue;
        }
        String baseName = ElementManipulators.getValueText(listElement);
        PerlSubAnnotations subAnnotations = computeSubAnnotations(this, listElement);
        for (Function<String, String> computation : getNamesComputations()) {
            result.add(new PerlClassAccessorMethod(this, baseName, computation, CLASS_ACCESSOR_METHOD, listElement, packageName, subAnnotations));
        }
    }
    return result;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 PerlClassAccessorMethod (com.perl5.lang.perl.parser.Class.Accessor.psi.impl.PerlClassAccessorMethod)2 NotNull (org.jetbrains.annotations.NotNull)2 Editor (com.intellij.openapi.editor.Editor)1 Messages (com.intellij.openapi.ui.Messages)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 com.intellij.psi (com.intellij.psi)1 SearchScope (com.intellij.psi.search.SearchScope)1 ReferencesSearch (com.intellij.psi.search.searches.ReferencesSearch)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PsiElementRenameHandler (com.intellij.refactoring.rename.PsiElementRenameHandler)1 RenamePsiElementProcessor (com.intellij.refactoring.rename.RenamePsiElementProcessor)1 PerlIcons (com.perl5.PerlIcons)1 PerlGlobVariable (com.perl5.lang.perl.psi.PerlGlobVariable)1 PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)1 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)1 PerlSubAnnotations (com.perl5.lang.perl.psi.utils.PerlSubAnnotations)1 PerlSubUtil (com.perl5.lang.perl.util.PerlSubUtil)1 PodLanguage (com.perl5.lang.pod.PodLanguage)1 THashSet (gnu.trove.THashSet)1