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

Camelcade / Perl5-IDEA / #525521539

20 May 2025 06:24PM UTC coverage: 82.29% (+0.1%) from 82.163%
#525521539

push

github

hurricup
Removed deprecated `ActionPlaces` check

1 of 1 new or added line in 1 file covered. (100.0%)

61 existing lines in 7 files now uncovered.

30894 of 37543 relevant lines covered (82.29%)

0.82 hits per line

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

92.06
/plugin/core/src/main/java/com/perl5/lang/perl/psi/impl/PerlFileImpl.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.psi.impl;
18

19
import com.intellij.codeInsight.controlflow.Instruction;
20
import com.intellij.extapi.psi.PsiFileBase;
21
import com.intellij.lang.Language;
22
import com.intellij.navigation.ItemPresentation;
23
import com.intellij.openapi.fileTypes.FileType;
24
import com.intellij.openapi.roots.ProjectFileIndex;
25
import com.intellij.openapi.util.ClearableLazyValue;
26
import com.intellij.openapi.vfs.VfsUtilCore;
27
import com.intellij.openapi.vfs.VirtualFile;
28
import com.intellij.psi.FileViewProvider;
29
import com.intellij.psi.PsiElement;
30
import com.intellij.psi.ResolveState;
31
import com.intellij.psi.impl.source.PsiFileImpl;
32
import com.intellij.psi.scope.PsiScopeProcessor;
33
import com.intellij.psi.util.PsiUtilCore;
34
import com.perl5.lang.perl.PerlLanguage;
35
import com.perl5.lang.perl.extensions.PerlCodeGenerator;
36
import com.perl5.lang.perl.extensions.generation.PerlCodeGeneratorImpl;
37
import com.perl5.lang.perl.fileTypes.PerlFileTypePackage;
38
import com.perl5.lang.perl.fileTypes.PerlFileTypeScript;
39
import com.perl5.lang.perl.idea.codeInsight.controlFlow.PerlControlFlowBuilder;
40
import com.perl5.lang.perl.psi.PerlFile;
41
import com.perl5.lang.perl.psi.mro.PerlMroType;
42
import com.perl5.lang.perl.psi.references.PerlFileContextSubstitutor;
43
import com.perl5.lang.perl.psi.stubs.PerlFileStub;
44
import com.perl5.lang.perl.psi.utils.PerlNamespaceAnnotations;
45
import com.perl5.lang.perl.psi.utils.PerlResolveUtil;
46
import com.perl5.lang.perl.util.PerlPackageUtil;
47
import org.jetbrains.annotations.NotNull;
48
import org.jetbrains.annotations.Nullable;
49

50
import javax.swing.*;
51
import java.util.Collections;
52
import java.util.List;
53
import java.util.Map;
54

55

56
public class PerlFileImpl extends PsiFileBase implements PerlFile {
57
  protected PsiElement fileContext;
58

59
  private final ClearableLazyValue<List<String>> myParentNamespaces = ClearableLazyValue.create(
1✔
60
    () -> PerlPackageUtil.collectParentNamespaceNamesFromPsi(this));
1✔
61
  private final ClearableLazyValue<Instruction[]> myControlFlow = PerlControlFlowBuilder.createLazy(this);
1✔
62

63
  public PerlFileImpl(@NotNull FileViewProvider viewProvider, Language language) {
64
    super(viewProvider, language);
1✔
65
  }
1✔
66

67
  public PerlFileImpl(@NotNull FileViewProvider viewProvider) {
68
    super(viewProvider, PerlLanguage.INSTANCE);
1✔
69
  }
1✔
70

71
  @Override
72
  public @NotNull FileType getFileType() {
73
    VirtualFile virtualFile = getVirtualFile();
1✔
74

75
    if (virtualFile != null) {
1✔
76
      return getVirtualFile().getFileType();
1✔
77
    }
78
    return getDefaultFileType();
1✔
79
  }
80

81
  protected FileType getDefaultFileType() {
82
    // fixme getViewProvider().getVirtualFile() should be here, but incompatible with IDEA14
83
    return PerlFileTypeScript.INSTANCE;
1✔
84
  }
85

86
  /**
87
   * Returns package name for this psi file. Name built from filename and innermost root.
88
   *
89
   * @return canonical package name or null if it's not pm file or it's not in source root
90
   */
91
  public @Nullable String getFilePackageName() {
92
    VirtualFile containingFile = getVirtualFile();
1✔
93

94
    if (containingFile != null && containingFile.getFileType() == PerlFileTypePackage.INSTANCE) {
1✔
95
      VirtualFile innermostSourceRoot = PerlPackageUtil.getClosestIncRoot(getProject(), containingFile);
1✔
96
      if (innermostSourceRoot != null) {
1✔
97
        String relativePath = VfsUtilCore.getRelativePath(containingFile, innermostSourceRoot);
1✔
98
        return PerlPackageUtil.getPackageNameByPath(relativePath);
1✔
99
      }
100
    }
101
    return null;
1✔
102
  }
103

104
  @Override
105
  public void subtreeChanged() {
106
    super.subtreeChanged();
1✔
107
    myParentNamespaces.drop();
1✔
108
    myControlFlow.drop();
1✔
109
  }
1✔
110

111
  @Override
112
  public @NotNull String getNamespaceName() {
113
    return PerlPackageUtil.MAIN_NAMESPACE_NAME;
1✔
114
  }
115

116
  @Override
117
  public @NotNull PerlMroType getMroType() {
118
    return PerlMroType.DFS;
1✔
119
  }
120

121
  @Override
122
  public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
123
                                     @NotNull ResolveState state,
124
                                     PsiElement lastParent,
125
                                     @NotNull PsiElement place) {
126
    return PerlResolveUtil.processChildren(this, processor, state, lastParent, place) && processor.execute(this, state);
1✔
127
  }
128

129
  @Override
130
  public PerlCodeGenerator getCodeGenerator() {
131
    return PerlCodeGeneratorImpl.INSTANCE;
1✔
132
  }
133

134
  @Override
135
  public ItemPresentation getPresentation() {
136
    return this;
1✔
137
  }
138

139
  @Override
140
  public @Nullable String getPresentableText() {
141
    String result = getFilePackageName();
1✔
142
    return result == null ? getName() : result;
1✔
143
  }
144

145
  @Override
146
  public @Nullable String getLocationString() {
147
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(this);
1✔
148
    if (virtualFile == null) {
1✔
UNCOV
149
      return null;
×
150
    }
151
    VirtualFile parentFile = virtualFile.getParent();
1✔
152
    if (parentFile == null) {
1✔
UNCOV
153
      return null;
×
154
    }
155
    var fileIndex = ProjectFileIndex.getInstance(getProject());
1✔
156
    VirtualFile fileRoot = fileIndex.getContentRootForFile(virtualFile);
1✔
157
    if (fileRoot == null) {
1✔
158
      fileRoot = fileIndex.getClassRootForFile(virtualFile);
1✔
159
    }
160
    if (fileRoot == null) {
1✔
161
      fileRoot = fileIndex.getSourceRootForFile(virtualFile);
1✔
162
    }
163

164
    return fileRoot == null ? parentFile.getPresentableUrl() : VfsUtilCore.getRelativePath(parentFile, fileRoot);
1✔
165
  }
166

167
  @Override
168
  public @Nullable Icon getIcon(boolean unused) {
169
    return getFileType().getIcon();
1✔
170
  }
171

172
  @Override
173
  public @Nullable String getPodLink() {
UNCOV
174
    return getFilePackageName();
×
175
  }
176

177
  @Override
178
  public @Nullable String getPodLinkText() {
UNCOV
179
    return getPodLink();
×
180
  }
181

182

183
  @Override
184
  public byte @Nullable [] getPerlContentInBytes() {
185
    return getText().getBytes(getVirtualFile().getCharset());
1✔
186
  }
187

188
  @Override
189
  public PsiElement getContext() {
190
    return PerlFileContextSubstitutor.getContext(fileContext == null ? super.getContext() : fileContext);
1✔
191
  }
192

193
  @Override
194
  public void setFileContext(PsiElement fileContext) {
195
    this.fileContext = fileContext;
1✔
196
  }
1✔
197

198
  // fixme we could use some SmartPsiElementPointer and UserData to hold the context
199
  @Override
200
  protected PsiFileImpl clone() {
201
    PerlFileImpl clone = (PerlFileImpl)super.clone();
1✔
202
    clone.setFileContext(fileContext);
1✔
203
    return clone;
1✔
204
  }
205

206
  @Override
207
  public @NotNull List<String> getParentNamespacesNames() {
208
    return withGreenStubOrAst(stub -> {
1✔
209
      if (stub instanceof PerlFileStub perlFileStub) {
1✔
210
        return perlFileStub.getParentNamespacesNames();
1✔
211
      }
UNCOV
212
      return Collections.emptyList();
×
213
    }, ast -> myParentNamespaces.getValue());
1✔
214
  }
215

216
  @Override
217
  public @Nullable PerlNamespaceAnnotations getAnnotations() {
218
    return null;
1✔
219
  }
220

221
  @Override
222
  public @NotNull List<String> getEXPORT() {
223
    return Collections.emptyList();
1✔
224
  }
225

226
  @Override
227
  public @NotNull List<String> getEXPORT_OK() {
228
    return Collections.emptyList();
1✔
229
  }
230

231
  @Override
232
  public @NotNull Map<String, List<String>> getEXPORT_TAGS() {
233
    return Collections.emptyMap();
1✔
234
  }
235

236
  @Override
237
  public @NotNull Instruction[] getControlFlow() {
238
    return myControlFlow.getValue();
1✔
239
  }
240
}
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