1230 * used.
1231 * @param file a relative file name
1232 * @return a relative URI
1233 * @throws IllegalArgumentException if the file name is not
1234 * relative according to the definition given in {@link
1235 * javax.tools.JavaFileManager#getFileForInput}
1236 */
1237 public static String getRelativeName(File file) {
1238 if (!file.isAbsolute()) {
1239 String result = file.getPath().replace(File.separatorChar, '/');
1240 if (isRelativeUri(result))
1241 return result;
1242 }
1243 throw new IllegalArgumentException("Invalid relative path: " + file);
1244 }
1245
1246 /**
1247 * Get a detail message from an IOException.
1248 * Most, but not all, instances of IOException provide a non-null result
1249 * for getLocalizedMessage(). But some instances return null: in these
1250 * cases, fallover to getMessage(), and if even that is null, return the
1251 * name of the exception itself.
1252 * @param e an IOException
1253 * @return a string to include in a compiler diagnostic
1254 */
1255 public static String getMessage(IOException e) {
1256 String s = e.getLocalizedMessage();
1257 if (s != null)
1258 return s;
1259 s = e.getMessage();
1260 if (s != null)
1261 return s;
1262 return e.toString();
1263 }
1264
1265 private void checkOutputLocation(Location location) {
1266 Objects.requireNonNull(location);
1267 if (!location.isOutputLocation())
1268 throw new IllegalArgumentException("location is not an output location: " + location.getName());
1269 }
1270
|
1230 * used.
1231 * @param file a relative file name
1232 * @return a relative URI
1233 * @throws IllegalArgumentException if the file name is not
1234 * relative according to the definition given in {@link
1235 * javax.tools.JavaFileManager#getFileForInput}
1236 */
1237 public static String getRelativeName(File file) {
1238 if (!file.isAbsolute()) {
1239 String result = file.getPath().replace(File.separatorChar, '/');
1240 if (isRelativeUri(result))
1241 return result;
1242 }
1243 throw new IllegalArgumentException("Invalid relative path: " + file);
1244 }
1245
1246 /**
1247 * Get a detail message from an IOException.
1248 * Most, but not all, instances of IOException provide a non-null result
1249 * for getLocalizedMessage(). But some instances return null: in these
1250 * cases, fall back to getMessage(), and if even that is null, return the
1251 * name of the exception itself.
1252 * @param e an IOException
1253 * @return a string to include in a compiler diagnostic
1254 */
1255 public static String getMessage(IOException e) {
1256 String s = e.getLocalizedMessage();
1257 if (s != null)
1258 return s;
1259 s = e.getMessage();
1260 if (s != null)
1261 return s;
1262 return e.toString();
1263 }
1264
1265 private void checkOutputLocation(Location location) {
1266 Objects.requireNonNull(location);
1267 if (!location.isOutputLocation())
1268 throw new IllegalArgumentException("location is not an output location: " + location.getName());
1269 }
1270
|