Class SourceMatchesFileName

java.lang.Object
org.ek9lang.compiler.common.SourceMatchesFileName
All Implemented Interfaces:
BiPredicate<CompilableSource, String>

public class SourceMatchesFileName extends Object implements BiPredicate<CompilableSource, String>
Determines whether a CompilableSource corresponds to a given source file name.

The candidate name can legitimately arrive in several forms depending on how the compiler was invoked and which component is doing the lookup:

  • the file:// URI "general identifier" - matches CompilableSource.getGeneralIdentifier(). This is the form a parser/lexer token carries as its getSourceName() (and what the LSP/IDE uses), e.g. file:///proj/pkg/File.ek9. It is CWD-resolved and invocation-independent, so it is the primary, exact match;
  • the full/absolute path - matches CompilableSource.getFileName() (e.g. /home/dev/proj/pkg/File.ek9);
  • the base-directory-relative form - matches CompilableSource.getRelativeFileName() (e.g. ./pkg/File.ek9, as produced when ek9 -c is given a relative path - the normal CLI form);
  • a plain file://-prefixed path - the scheme prefix is stripped before the full/relative comparison.

Several call sites previously stripped file:// from a token's getSourceName() and compared the remainder against source.getFileName(). That comparison silently failed whenever the compiler was invoked with a relative path: the token's source name is the CWD-resolved file:///abs/path URI, but with a relative invocation getFileName() stays ./File.ek9, so the stripped absolute path never matched. (With an absolute invocation it happened to match, which is why tests - always using consistent absolute names - never exposed it.) For checks that emit diagnostics via a per-source ErrorListener resolved by this lookup, the miss meant the diagnostic was dropped with no error - a silent false negative. Centralising the comparison here, with getGeneralIdentifier() as the primary key, keeps every name-to-source lookup consistent and robust to invocation style.

The match is a strict superset of the historical comparison: it preserves the file://-stripped full-path branch and additionally accepts the general-identifier URI and relative forms, so it can only add matches, never remove a previously-working one.

  • Constructor Details

    • SourceMatchesFileName

      public SourceMatchesFileName()
  • Method Details

    • test

      public boolean test(CompilableSource source, String candidateFileName)
      Specified by:
      test in interface BiPredicate<CompilableSource, String>
      Parameters:
      source - the source to test (must be non-null to match).
      candidateFileName - the file name to compare against, in full, relative or file:// URI form (must be non-null to match).
      Returns:
      true if the source represents the candidate file name.