Search in sources :

Example 1 with FileSearchPathProvider

use of de.be4.classicalb.core.parser.FileSearchPathProvider in project probparsers by bendisposto.

the class RecursiveMachineLoader method lookupFile.

/**
 * Tries to find a file containing the machine with the given file name.
 *
 * @param ancestors
 *
 * @param machineName
 *            Name of the machine to include, never <code>null</code>
 * @param paths
 *
 * @return reference to a file containing the machine, may be non-existent
 *         but never <code>null</code>.
 * @throws CheckException
 *             if the file cannot be found
 */
private File lookupFile(final File parentMachineDirectory, final MachineReference machineRef, List<String> ancestors, List<String> paths) throws CheckException {
    for (final String suffix : SUFFICES) {
        try {
            final String directoryString = machineRef.getDirectoryPath() != null ? machineRef.getDirectoryPath() : parentMachineDirectory.getAbsolutePath();
            return new FileSearchPathProvider(directoryString, machineRef.getName() + suffix, paths).resolve();
        } catch (FileNotFoundException e) {
        // could not resolve the combination of prefix, machineName and
        // suffix, trying next one
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("Machine not found: '");
    sb.append(machineRef.getName());
    sb.append("'");
    String fileNameOfErrorMachine = parsedFiles.get(ancestors.get(ancestors.size() - 1)).getName();
    sb.append(" in '").append(fileNameOfErrorMachine).append("'");
    for (int i = ancestors.size() - 2; i >= 0; i--) {
        String name = ancestors.get(i);
        String fileName = parsedFiles.get(name).getName();
        sb.append(" loaded by ").append("'").append(fileName).append("'");
    }
    throw new CheckException(sb.toString(), machineRef.getNode());
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) FileNotFoundException(java.io.FileNotFoundException) FileSearchPathProvider(de.be4.classicalb.core.parser.FileSearchPathProvider)

Aggregations

FileSearchPathProvider (de.be4.classicalb.core.parser.FileSearchPathProvider)1 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 FileNotFoundException (java.io.FileNotFoundException)1