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

Camelcade / Perl5-IDEA / #525521824

24 Apr 2026 06:38PM UTC coverage: 76.187% (+0.2%) from 75.952%
#525521824

push

github

hurricup
Pass a disposable to Registry.get to revert it in the end

14757 of 22542 branches covered (65.46%)

Branch coverage included in aggregate %.

31096 of 37643 relevant lines covered (82.61%)

0.83 hits per line

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

44.57
/plugin/backend/src/main/java/com/perl5/lang/perl/idea/sdk/host/PerlFileDescriptor.java
1
/*
2
 * Copyright 2015-2026 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.sdk.host;
18

19
import com.intellij.openapi.diagnostic.Logger;
20
import com.intellij.openapi.util.io.FileUtil;
21
import org.jetbrains.annotations.Contract;
22
import org.jetbrains.annotations.NotNull;
23
import org.jetbrains.annotations.Nullable;
24

25
import java.io.File;
26

27
/**
28
 * Descriptor for the remote file
29
 */
30
public class PerlFileDescriptor {
31
  public static final PerlFileDescriptor ROOT_DESCRIPTOR = new PerlFileDescriptor("/", "", Type.DIRECTORY, 0);
1✔
32
  private static final Logger LOG = Logger.getInstance(PerlFileDescriptor.class);
1✔
33
  private final @NotNull String myPath;
34
  private final @NotNull String myName;
35
  private final @NotNull Type myType;
36
  // in kilobytes
37
  private final int mySize;
38

39
  private PerlFileDescriptor(@NotNull String path, @NotNull String name, @NotNull Type type, int size) {
1✔
40
    myPath = path.endsWith("/") ? path : path + '/';
1✔
41
    myName = name;
1✔
42
    myType = type;
1✔
43
    mySize = size;
1✔
44
  }
1✔
45

46
  public @Nullable PerlFileDescriptor getParentDescriptor() {
47
    if (this == ROOT_DESCRIPTOR) {
×
48
      return null;
×
49
    }
50
    if (myPath.equals("/")) {
×
51
      return ROOT_DESCRIPTOR;
×
52
    }
53
    File parentFile = new File(myPath);
×
54
    return new PerlFileDescriptor(FileUtil.toSystemIndependentName(parentFile.getParent()), parentFile.getName(), Type.DIRECTORY, 0);
×
55
  }
56

57
  public @NotNull String getPath() {
58
    return myPath + myName;
1!
59
  }
60

61
  public @NotNull String getName() {
62
    return myName;
1!
63
  }
64

65
  @SuppressWarnings("unused")
66
  public @NotNull Type getType() {
67
    return myType;
×
68
  }
69

70
  public int getSize() {
71
    return mySize;
×
72
  }
73

74
  public boolean isDirectory() {
75
    return myType.myIsDirectory;
1✔
76
  }
77

78
  @Override
79
  public boolean equals(Object o) {
80
    if (this == o) {
×
81
      return true;
×
82
    }
83
    if (!(o instanceof PerlFileDescriptor that)) {
×
84
      return false;
×
85
    }
86

87
    if (!myPath.equals(that.myPath)) {
×
88
      return false;
×
89
    }
90
    return myName.equals(that.myName);
×
91
  }
92

93
  @Override
94
  public int hashCode() {
95
    int result = myPath.hashCode();
×
96
    result = 31 * result + myName.hashCode();
×
97
    return result;
×
98
  }
99

100
  /**
101
   * @param input input in format {@code size name[suffix]}
102
   * @return new descriptor or null if failed to parse input
103
   * @implNote Prefixes are:
104
   */
105
  @Contract("_, null->null")
106
  public static @Nullable PerlFileDescriptor create(@NotNull String basePath, @Nullable String input) {
107
    if (input == null) {
1!
108
      return null;
×
109
    }
110
    String[] parts = input.trim().split("\\s+");
1✔
111
    if (parts.length != 2) {
1!
112
      LOG.warn("Unable to parse: " + input);
×
113
      return null;
×
114
    }
115

116
    if (parts[0].equals("total")) {
1✔
117
      return null;
1✔
118
    }
119

120
    int size;
121
    try {
122
      size = Integer.parseInt(parts[0]);
1✔
123
    }
124
    catch (NumberFormatException e) {
×
125
      LOG.error("Failed to parse size for: " + input, e);
×
126
      return null;
×
127
    }
1✔
128
    char lastChar = parts[1].charAt(parts[1].length() - 1);
1✔
129
    Type type = switch (lastChar) {
1!
130
      case '/' -> Type.DIRECTORY;
1✔
131
      case '|' -> Type.PIPE;
×
132
      case '@' -> Type.SYMLINK;
×
133
      case '*' -> Type.EXECUTABLE;
1✔
134
      case '=' -> Type.SOCKET;
×
135
      case '>' -> Type.DOOR;
×
136
      default -> Type.FILE;
×
137
    };
1✔
138
    String name = type == Type.FILE ? parts[1] : parts[1].substring(0, parts[1].length() - 1);
1!
139
    return new PerlFileDescriptor(basePath, name, type, size);
1✔
140
  }
141

142
  public enum Type {
1✔
143
    FILE(false), DIRECTORY(true), PIPE(false), SYMLINK(false), EXECUTABLE(false), SOCKET(false), DOOR(false);
1✔
144
    private final boolean myIsDirectory;
145

146
    Type(boolean isDirectory) {
1✔
147
      myIsDirectory = isDirectory;
1✔
148
    }
1✔
149
  }
150
}
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