• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Camelcade / Perl5-IDEA / #525521648

24 Jul 2025 06:24AM UTC coverage: 82.289% (+0.01%) from 82.279%
#525521648

push

github

hurricup
#2842 IJPL-197971 fixed RT access issue for path to package map

11 of 16 new or added lines in 8 files covered. (68.75%)

12 existing lines in 7 files now uncovered.

30991 of 37661 relevant lines covered (82.29%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugin/backend/src/main/java/com/perl5/lang/perl/idea/refactoring/move/PerlMoveFileHandler.java
1
/*
2
 * Copyright 2015-2025 Alexandr Evstigneev
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.perl5.lang.perl.idea.refactoring.move;
18

19
import com.intellij.openapi.application.ApplicationManager;
20
import com.intellij.openapi.project.Project;
21
import com.intellij.openapi.util.Key;
22
import com.intellij.openapi.vfs.VfsUtilCore;
23
import com.intellij.openapi.vfs.VirtualFile;
24
import com.intellij.psi.PsiDirectory;
25
import com.intellij.psi.PsiElement;
26
import com.intellij.psi.PsiFile;
27
import com.intellij.psi.PsiReference;
28
import com.intellij.psi.search.searches.ReferencesSearch;
29
import com.intellij.psi.util.PsiTreeUtil;
30
import com.intellij.refactoring.RefactoringFactory;
31
import com.intellij.refactoring.RenameRefactoring;
32
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFileHandler;
33
import com.intellij.usageView.UsageInfo;
34
import com.intellij.util.IncorrectOperationException;
35
import com.perl5.lang.perl.fileTypes.PerlFileTypePackage;
36
import com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement;
37
import com.perl5.lang.perl.psi.impl.PerlFileImpl;
38
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
39
import com.perl5.lang.perl.util.PerlPackageUtil;
40
import com.perl5.lang.perl.util.PerlPackageUtilCore;
41
import org.jetbrains.annotations.NotNull;
42
import org.jetbrains.annotations.Nullable;
43
import org.jetbrains.annotations.Unmodifiable;
44

45
import java.util.List;
46
import java.util.Map;
47

48
public class PerlMoveFileHandler extends MoveFileHandler {
×
49
  private static final Key<String> ORIGINAL_PACKAGE_NAME = Key.create("PERL_ORIGINAL_PACKAGE_NAME");
×
50

51
  @Override
52
  public boolean canProcessElement(PsiFile element) {
53
    return element instanceof PerlFileImpl && element.getVirtualFile().getFileType() == PerlFileTypePackage.INSTANCE;
×
54
  }
55

56
  @Override
57
  public void prepareMovedFile(PsiFile file, PsiDirectory moveDestination, Map<PsiElement, PsiElement> oldToNewMap) {
58
    file.putUserData(ORIGINAL_PACKAGE_NAME, ((PerlFileImpl)file).getFilePackageName());
×
59

60
    String newFilePath = moveDestination.getVirtualFile().getPath() + '/' + file.getName();
×
61
    VirtualFile newClassRoot = PerlPackageUtil.getClosestIncRoot(moveDestination.getProject(), newFilePath);
×
62

63
    if (newClassRoot != null) {
×
64
      String newRelativePath = newFilePath.substring(newClassRoot.getPath().length());
×
NEW
65
      String newPackageName = PerlPackageUtilCore.getPackageNameByPath(newRelativePath);
×
66

67
      if (newPackageName != null) {
×
68
        for (PsiReference reference : ReferencesSearch.search(file, file.getUseScope()).findAll()) {
×
69
          PerlPsiUtil.renameElement(reference.getElement(), newPackageName);
×
70
        }
×
71
      }
72
    }
73
  }
×
74

75
  @Override
76
  public void updateMovedFile(PsiFile file) throws IncorrectOperationException {
77
    String originalPackageName = file.getUserData(ORIGINAL_PACKAGE_NAME);
×
78
    Project project = file.getProject();
×
79
    VirtualFile virtualFile = file.getVirtualFile();
×
80
    VirtualFile newInnermostRoot = PerlPackageUtil.getClosestIncRoot(project, virtualFile);
×
81

82
    if (newInnermostRoot != null && originalPackageName != null) {
×
83
      String newRelativePath = VfsUtilCore.getRelativePath(virtualFile, newInnermostRoot);
×
NEW
84
      String newPackageName = PerlPackageUtilCore.getPackageNameByPath(newRelativePath);
×
85

86
      final RenameRefactoring[] refactoring = {null};
×
87

88
      for (PerlNamespaceDefinitionElement namespaceDefinition : PsiTreeUtil
×
89
        .findChildrenOfType(file, PerlNamespaceDefinitionElement.class)) {
×
90
        if (originalPackageName.equals(namespaceDefinition.getNamespaceName())) {
×
91
          if (refactoring[0] == null) {
×
92
            refactoring[0] = RefactoringFactory.getInstance(file.getProject()).createRename(namespaceDefinition, newPackageName);
×
93
          }
94
          else {
95
            refactoring[0].addElement(namespaceDefinition, newPackageName);
×
96
          }
97
        }
98
      }
×
99

100
      if (refactoring[0] != null) {
×
101
        ApplicationManager.getApplication().invokeLater(refactoring[0]::run);
×
102
      }
103
    }
104
  }
×
105

106
  @Override
107
  public @Nullable List<UsageInfo> findUsages(@NotNull PsiFile psiFile,
108
                                              @NotNull PsiDirectory newParent,
109
                                              boolean searchInComments,
110
                                              boolean searchInNonJavaFiles) {
111
    return null;
×
112
  }
113

114
  @Override
115
  public void retargetUsages(@Unmodifiable @NotNull List<? extends UsageInfo> usageInfos,
116
                             @NotNull Map<PsiElement, PsiElement> oldToNewMap) {
117

118
  }
×
119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc