/** * Constructs a CloseableReference. * * <p>Returns null if the parameter is null. */ public static <T extends Closeable> CloseableReference<T> of(@PropagatesNullable T t) { if (t == null) { return null; } else { return new CloseableReference<T>(t, (ResourceReleaser<T>) DEFAULT_CLOSEABLE_RELEASER); } }
/** * Constructs a CloseableReference (wrapping a SharedReference) of T with provided * ResourceReleaser<T>. If t is null, this will just return null. */ public static <T> CloseableReference<T> of( @PropagatesNullable T t, ResourceReleaser<T> resourceReleaser) { if (t == null) { return null; } else { return new CloseableReference<T>(t, resourceReleaser); } }
/** * Clones a collection of references and returns a list. Returns null if the list is null. If the * list is non-null, clones each reference. If a reference cannot be cloned due to already being * closed, the list will contain a null value in its place. * * @param refs the references to clone * @return the list of cloned references or null */ public static <T> List<CloseableReference<T>> cloneOrNull( @PropagatesNullable Collection<CloseableReference<T>> refs) { if (refs == null) { return null; } List<CloseableReference<T>> ret = new ArrayList<>(refs.size()); for (CloseableReference<T> ref : refs) { ret.add(CloseableReference.cloneOrNull(ref)); } return ret; }
private String fixupSignature(@PropagatesNullable String signature) { if (signature == null || compatibilityMode.usesDependencies()) { return signature; } SignatureReader reader = new SignatureReader(signature); SignatureWriter writer = new SignatureWriter(); reader.accept(new SourceAbiCompatibleSignatureVisitor(writer)); return writer.toString(); }
/** @return a {@link SourcePath} identified by a {@link Path}. */ public PathSourcePath getPathSourcePath(@PropagatesNullable Path path) { if (path == null) { return null; } if (path.isAbsolute()) { return PathSourcePath.of(projectFilesystem, path); } return PathSourcePath.of( projectFilesystem, checkPathExists( path.toString(), String.format( "Failed to transform Path %s to Source Path because path was not found.", path))); }
public static String convertLanguageLevelToIjFormat(@PropagatesNullable String languageLevel) { if (languageLevel == null) { return null; } return "JDK_" + normalizeSourceLevel(languageLevel).replace('.', '_'); }
public Path resolvePathThatMayBeOutsideTheProjectFilesystem(@PropagatesNullable Path path) { if (path == null) { return path; } return resolveNonNullPathOutsideTheProjectFilesystem(path); }