Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@
/**
* A very simple {@link JavaFileObject} that points to a path on some {@link FileSystem} somewhere.
*
* <p>This object will always use UTF-8 encoding when obtaining readers or writers.
*
* <p>No access level or nesting kind information is provided by this implementation.
*
* @author Ashley Scopes
* @since 0.0.1
*/
@API(since = "0.0.1", status = Status.EXPERIMENTAL)
public class PathFileObject implements JavaFileObject {

private static final Logger LOGGER = LoggerFactory.getLogger(PathFileObject.class);
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static final long NOT_MODIFIED = 0L;

private final Location location;
Expand Down Expand Up @@ -93,11 +97,9 @@ public PathFileObject(Location location, Path rootPath, Path relativePath) {
this.location = location;
this.rootPath = rootPath;

if (relativePath.isAbsolute()) {
this.relativePath = rootPath.relativize(relativePath);
} else {
this.relativePath = relativePath;
}
this.relativePath = relativePath.isAbsolute()
? rootPath.relativize(relativePath)
: relativePath;

fullPath = rootPath.resolve(relativePath);
name = relativePath.toString();
Expand Down Expand Up @@ -141,8 +143,7 @@ public boolean equals(@Nullable Object other) {
@Nullable
@Override
public Modifier getAccessLevel() {
// Null implies that the access level is unknown.
return null;
return unknown();
}

/**
Expand Down Expand Up @@ -183,7 +184,7 @@ public long getLastModified() {
try {
return Files.getLastModifiedTime(fullPath).toMillis();
} catch (IOException ex) {
LOGGER.debug("Ignoring error reading last modified time for {}", uri, ex);
LOGGER.warn("Ignoring error reading last modified time for {}", uri, ex);
return NOT_MODIFIED;
}
}
Expand Down Expand Up @@ -224,8 +225,7 @@ public String getName() {
@Nullable
@Override
public NestingKind getNestingKind() {
// Null implies that the nesting kind is unknown.
return null;
return unknown();
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ public int hashCode() {
*/
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
// TODO(ascopes): does this need to be case insensitive on Windows?
// Note that this behaves case-sensitively, even on Windows.
var fileName = simpleName + kind.extension;

return relativePath.getFileName().toString().equals(fileName);
Expand Down Expand Up @@ -378,16 +378,21 @@ private CharsetDecoder decoder(boolean ignoreEncodingErrors) {
? CodingErrorAction.IGNORE
: CodingErrorAction.REPORT;

return DEFAULT_CHARSET
return CHARSET
.newDecoder()
.onUnmappableCharacter(action)
.onMalformedInput(action);
}

private CharsetEncoder encoder() {
return DEFAULT_CHARSET
return CHARSET
.newEncoder()
.onUnmappableCharacter(CodingErrorAction.REPORT)
.onMalformedInput(CodingErrorAction.REPORT);
}

@Nullable
private <T> T unknown() {
return null;
}
}