xref: /aosp_15_r20/external/cldr/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckAlt.java (revision 912701f9769bb47905792267661f0baf2b85bed5)
1 package org.unicode.cldr.test;
2 
3 import java.util.HashSet;
4 import java.util.List;
5 import java.util.Set;
6 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
7 import org.unicode.cldr.util.CLDRFile;
8 
9 public class CheckAlt extends CheckCLDR {
10 
11     Set<String> seenSoFar = new HashSet<>();
12 
13     // determine if we have an alt=...proposed
14     // if we have one, and there is not a non-proposed version -- in this same file, unaliased,
15     // there's a problem.
16     @Override
handleCheck( String path, String fullPath, String value, Options options, List<CheckStatus> result)17     public CheckCLDR handleCheck(
18             String path, String fullPath, String value, Options options, List<CheckStatus> result) {
19         if (fullPath == null) return this; // skip paths that we don't have
20 
21         // quick checks
22         if (path.indexOf("[@alt=") <= 0) {
23             return this;
24         }
25         if (path.indexOf("proposed") <= 0) {
26             return this;
27         }
28 
29         if (!accept(result)) return this;
30 
31         String strippedPath = CLDRFile.getNondraftNonaltXPath(path);
32         if (strippedPath.equals(path)) {
33             return this; // paths equal, skip
34         }
35 
36         String otherValue = getCldrFileToCheck().getStringValue(strippedPath);
37         if (otherValue != null) {
38             return this;
39         }
40         result.add(
41                 new CheckStatus()
42                         .setCause(this)
43                         .setMainType(CheckStatus.warningType)
44                         .setSubtype(Subtype.noUnproposedVariant)
45                         .setCheckOnSubmit(false)
46                         .setMessage("Proposed item but no unproposed variant", new Object[] {}));
47         seenSoFar.add(strippedPath);
48 
49         return this;
50     }
51 
52     @Override
handleSetCldrFileToCheck( CLDRFile cldrFileToCheck, Options options, List<CheckStatus> possibleErrors)53     public CheckCLDR handleSetCldrFileToCheck(
54             CLDRFile cldrFileToCheck, Options options, List<CheckStatus> possibleErrors) {
55         if (cldrFileToCheck == null) return this;
56         // Skip if the phase is not final testing
57         if (Phase.FINAL_TESTING == getPhase() || Phase.BUILD == getPhase()) {
58             setSkipTest(false); // ok
59         } else {
60             setSkipTest(true);
61             return this;
62         }
63 
64         super.handleSetCldrFileToCheck(cldrFileToCheck, options, possibleErrors);
65         seenSoFar.clear();
66         return this;
67     }
68 }
69