Class SourceMatchesFileName
- All Implemented Interfaces:
BiPredicate<CompilableSource, String>
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" - matchesCompilableSource.getGeneralIdentifier(). This is the form a parser/lexer token carries as itsgetSourceName()(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 whenek9 -cis 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleantest(CompilableSource source, String candidateFileName) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiPredicate
and, negate, or
-
Constructor Details
-
SourceMatchesFileName
public SourceMatchesFileName()
-
-
Method Details
-
test
- Specified by:
testin interfaceBiPredicate<CompilableSource, String>- Parameters:
source- the source to test (must be non-null to match).candidateFileName- the file name to compare against, in full, relative orfile://URI form (must be non-null to match).- Returns:
- true if the source represents the candidate file name.
-