Search in sources :

Example 1 with AFileMachineReference

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

the class ReferencedMachines method caseAMachineReference.

/**
 * INCLUDES, EXTENDS, IMPORTS
 */
@Override
public void caseAMachineReference(AMachineReference node) {
    String name = getIdentifier(node.getMachineName());
    if (node.parent() instanceof AFileMachineReference) {
        final AFileMachineReference fileNode = (AFileMachineReference) node.parent();
        String file = fileNode.getFile().getText().replaceAll("\"", "");
        MachineReference ref;
        try {
            ref = new MachineReference(name, node, file);
            referncesTable.put(name, ref);
        } catch (CheckException e) {
            throw new VisitorException(e);
        }
    } else {
        MachineReference machineReference = new MachineReference(name, node);
        if (this.filePathTable.containsKey(name)) {
            machineReference.setDirectoryPath(filePathTable.get(name));
        }
        referncesTable.put(name, machineReference);
    }
}
Also used : AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 2 with AFileMachineReference

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

the class RulesReferencesFinder method registerMachineNames.

private void registerMachineNames(final PMachineReference machineReference) {
    if (machineReference instanceof AFileMachineReference) {
        registerMachineByFilePragma((AFileMachineReference) machineReference);
    } else {
        AMachineReference mchRef = (AMachineReference) machineReference;
        registerMachineReference(mchRef);
    }
}
Also used : AFileMachineReference(de.be4.classicalb.core.parser.node.AFileMachineReference) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference)

Example 3 with AFileMachineReference

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

the class RulesReferencesFinder method registerMachineByFilePragma.

private void registerMachineByFilePragma(AFileMachineReference fileNode) {
    final String filePath = fileNode.getFile().getText().replaceAll("\"", "");
    final AMachineReference ref = (AMachineReference) fileNode.getReference();
    final String name = ref.getMachineName().get(0).getText();
    File file = null;
    File tempFile = new File(filePath);
    if (tempFile.exists() && tempFile.isAbsolute() && !tempFile.isDirectory()) {
        file = tempFile;
    } else {
        tempFile = new File(mainFile.getParentFile(), filePath);
        if (tempFile.exists() && !tempFile.isDirectory()) {
            file = tempFile;
        }
    }
    if (tempFile.isDirectory()) {
        errorList.add(new CheckException(String.format("File '%s' is a directory.", filePath), fileNode.getFile()));
        return;
    } else if (file == null) {
        errorList.add(new CheckException(String.format("File '%s' does not exist.", filePath), fileNode.getFile()));
        return;
    } else {
        RulesMachineReference rulesMachineReference = new RulesMachineReference(file, name, fileNode.getReference());
        referncesTable.put(name, rulesMachineReference);
        return;
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AMachineReference(de.be4.classicalb.core.parser.node.AMachineReference) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Aggregations

AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)3 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 AFileMachineReference (de.be4.classicalb.core.parser.node.AFileMachineReference)2 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)2 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 File (java.io.File)1