Search in sources :

Example 1 with VisitorIOException

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

the class ReferencedMachines method determineRootDirectory.

private void determineRootDirectory(final TPragmaIdOrString packageTerminal, final Node node) {
    final String text = packageTerminal.getText();
    if ((text.startsWith("\"") && text.endsWith("\""))) {
        this.packageName = text.replaceAll("\"", "");
    } else {
        this.packageName = text;
    }
    final String[] packageNameArray = determinePackage(packageTerminal, node);
    File dir;
    try {
        dir = mainFile.getCanonicalFile();
    } catch (IOException e) {
        throw new VisitorIOException(e);
    }
    for (int i = packageNameArray.length - 1; i >= 0; i--) {
        final String name1 = packageNameArray[i];
        dir = dir.getParentFile();
        final String name2 = dir.getName();
        if (!name1.equals(name2)) {
            throw new VisitorException(new CheckException(String.format("Package declaration '%s' does not match the folder structure: %s vs %s", this.packageName, name1, name2), node));
        }
    }
    rootDirectory = dir.getParentFile();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) IOException(java.io.IOException) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorIOException(de.be4.classicalb.core.parser.exceptions.VisitorIOException) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) File(java.io.File)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 VisitorIOException (de.be4.classicalb.core.parser.exceptions.VisitorIOException)1 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)1 File (java.io.File)1 IOException (java.io.IOException)1