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