1 package org.robolectric.annotation.internal; 2 3 import org.robolectric.annotation.Config; 4 5 public class ConfigUtils { 6 private ConfigUtils() { 7 } 8 9 public static String[] parseStringArrayProperty(String property) { 10 if (property.isEmpty()) return new String[0]; 11 return property.split("[, ]+"); 12 } 13 14 public static int[] parseSdkArrayProperty(String property) { 15 String[] parts = parseStringArrayProperty(property); 16 int[] result = new int[parts.length]; 17 for (int i = 0; i < parts.length; i++) { 18 result[i] = parseSdkInt(parts[i]); 19 } 20 21 return result; 22 } 23 24 public static int parseSdkInt(String part) { 25 String spec = part.trim(); 26 switch (spec) { 27 case "ALL_SDKS": 28 return Config.ALL_SDKS; 29 case "TARGET_SDK": 30 return Config.TARGET_SDK; 31 case "OLDEST_SDK": 32 return Config.OLDEST_SDK; 33 case "NEWEST_SDK": 34 return Config.NEWEST_SDK; 35 default: 36 try { 37 return Integer.parseInt(spec); 38 } catch (NumberFormatException e) { 39 try { 40 return (int) android.os.Build.VERSION_CODES.class.getField(part).get(null); 41 } catch (Exception e2) { 42 throw new IllegalArgumentException("unknown SDK \"" + part + "\""); 43 } 44 } 45 } 46 } 47 } 48