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

Camelcade / Perl5-IDEA / #525521639

21 Jul 2025 03:09PM UTC coverage: 82.304% (-0.04%) from 82.347%
#525521639

push

github

hurricup
#2842 Moved MasonFoldingBuilder to the common

68 of 98 new or added lines in 14 files covered. (69.39%)

67 existing lines in 12 files now uncovered.

30962 of 37619 relevant lines covered (82.3%)

0.82 hits per line

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

0.0
/mason/mason2/backend/src/main/java/com/perl5/lang/mason2/idea/vfs/MasonVirtualFileListener.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.mason2.idea.vfs;
18

19
import com.intellij.openapi.project.Project;
20
import com.intellij.openapi.util.Key;
21
import com.intellij.openapi.vfs.*;
22
import com.intellij.util.indexing.FileBasedIndex;
23
import com.perl5.lang.htmlmason.idea.configuration.AbstractMasonSettings;
24
import com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType;
25
import com.perl5.lang.mason2.idea.configuration.MasonSettings;
26
import com.perl5.lang.perl.idea.project.PerlProjectManager;
27
import org.jetbrains.annotations.NotNull;
28

29
import java.util.HashSet;
30
import java.util.List;
31
import java.util.Set;
32

33

34
public final class MasonVirtualFileListener implements VirtualFileListener {
35
  public static final Key<Boolean> FORCE_REINDEX = new Key<>("Force re-indexing");
×
36

37
  private final @NotNull Project myProject;
38

39
  public MasonVirtualFileListener(@NotNull Project project) {
×
40
    myProject = project;
×
41
  }
×
42

43
  /**
44
   * Fired when a virtual file is renamed from within IDEA, or its writable status is changed.
45
   * For files renamed externally, {@link #fileCreated} and {@link #fileDeleted} events will be fired.
46
   *
47
   * @param event the event object containing information about the change.
48
   */
49
  @Override
50
  public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
51
    if (!event.getPropertyName().equals(VirtualFile.PROP_NAME)) {
×
52
      return;
×
53
    }
54

55
    processFileChange(event.getFile());
×
56
  }
×
57

58
  private void processFileChange(@NotNull VirtualFile changedFile) {
59
    List<VirtualFile> componentsRoots = getComponentsRoots();
×
60
    if (componentsRoots.isEmpty()) {
×
61
      return;
×
62
    }
63

64

65
    Set<VirtualFile> rootsSet = new HashSet<>(componentsRoots);
×
66
    if (changedFile.isDirectory()) {
×
67
      if (changedFile.getUserData(FORCE_REINDEX) != null ||
×
68
          VfsUtilCore.isUnder(changedFile, rootsSet) ||        // moved to component root
×
69
          containsAtLeastOneFile(changedFile, componentsRoots)
×
70
      ) {
71
        FileBasedIndex.getInstance().requestReindex(changedFile);
×
72
      }
73
    }
74
    else if (changedFile.getFileType() instanceof MasonPurePerlComponentFileType)    // Mason file has been moved
×
75
    {
76
      if (changedFile.getUserData(FORCE_REINDEX) != null ||
×
77
          VfsUtilCore.isUnder(changedFile, rootsSet)
×
78
      ) {
79
        FileBasedIndex.getInstance().requestReindex(changedFile);
×
80
      }
81
    }
82
  }
×
83

84
  private @NotNull MasonSettings getSettings() {
85
    return MasonSettings.getInstance(getProject());
×
86
  }
87

88
  /**
89
   * Fired when a virtual file is moved from within IDEA.
90
   *
91
   * @param event the event object containing information about the change.
92
   */
93
  @Override
94
  public void fileMoved(@NotNull VirtualFileMoveEvent event) {
95
    processFileChange(event.getFile());
×
96
  }
×
97

98
  /**
99
   * Fired before the change of a name or writable status of a file is processed.
100
   *
101
   * @param event the event object containing information about the change.
102
   */
103
  @Override
104
  public void beforePropertyChange(@NotNull VirtualFilePropertyEvent event) {
105
    if (!event.getPropertyName().equals(VirtualFile.PROP_NAME)) {
×
106
      return;
×
107
    }
108

109
    List<VirtualFile> componentsRoots = getComponentsRoots();
×
110
    if (componentsRoots.isEmpty()) {
×
111
      return;
×
112
    }
113

114
    VirtualFile renamedFile = event.getFile();
×
115

116
    if (renamedFile.isDirectory()) {
×
117
      if (containsAtLeastOneFile(renamedFile, componentsRoots)) // contains component root
×
118
      {
119
        renamedFile.putUserData(FORCE_REINDEX, true);
×
120
      }
121
    }
122
  }
×
123

124
  private @NotNull List<VirtualFile> getComponentsRoots() {
NEW
125
    AbstractMasonSettings settings = getSettings();
×
NEW
126
    return PerlProjectManager.getInstance(settings.getProject()).getModulesRootsOfType(settings.getSourceRootType());
×
127
  }
128

129
  /**
130
   * Fired before the movement of a file is processed.
131
   *
132
   * @param event the event object containing information about the change.
133
   */
134
  @Override
135
  public void beforeFileMovement(@NotNull VirtualFileMoveEvent event) {
136
    List<VirtualFile> componentsRoots = getComponentsRoots();
×
137
    if (componentsRoots.isEmpty()) {
×
138
      return;
×
139
    }
140

141
    VirtualFile movedFile = event.getFile();
×
142

143
    Set<VirtualFile> rootsSet = new HashSet<>(componentsRoots);
×
144
    if (movedFile.isDirectory()) {
×
145
      if (VfsUtilCore.isUnder(movedFile, rootsSet) ||    // moved from component root
×
146
          containsAtLeastOneFile(movedFile, componentsRoots) // contains component root
×
147
      ) {
148
        movedFile.putUserData(FORCE_REINDEX, true);
×
149
      }
150
    }
151
    else if (movedFile.getFileType() instanceof MasonPurePerlComponentFileType)    // Mason file has been moved
×
152
    {
153
      if (VfsUtilCore.isUnder(movedFile, rootsSet)) {
×
154
        movedFile.putUserData(FORCE_REINDEX, true);
×
155
      }
156
    }
157
  }
×
158

159
  private @NotNull Project getProject() {
160
    return myProject;
×
161
  }
162

163
  private static boolean containsAtLeastOneFile(VirtualFile root, List<? extends VirtualFile> files) {
164
    for (VirtualFile file : files) {
×
165
      if (VfsUtilCore.isAncestor(root, file, false)) {
×
166
        return true;
×
167
      }
168
    }
×
169
    return false;
×
170
  }
171
}
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