use of de.be4.classicalb.core.parser.node.TPragmaIdOrString in project probparsers by bendisposto.
the class ReferencedMachines method determinePackage.
private String[] determinePackage(final TPragmaIdOrString packageTerminal, final Node node) {
String text = packageTerminal.getText();
// "foo.bar" or foo.bar
if ((text.startsWith("\"") && text.endsWith("\""))) {
text = text.replaceAll("\"", "");
}
final String[] packageNameArray = text.split("\\.");
final Pattern VALID_IDENTIFIER = Pattern.compile("([\\p{L}][\\p{L}\\p{N}_]*)");
for (int i = 0; i < packageNameArray.length; i++) {
boolean matches = VALID_IDENTIFIER.matcher(packageNameArray[i]).matches();
if (!matches) {
throw new VisitorException(new CheckException("Invalid package pragma: " + text, node));
}
}
return packageNameArray;
}
use of de.be4.classicalb.core.parser.node.TPragmaIdOrString 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();
}
use of de.be4.classicalb.core.parser.node.TPragmaIdOrString in project probparsers by bendisposto.
the class RulesReferencesFinder 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 = null;
try {
dir = mainFile.getCanonicalFile();
} catch (IOException e) {
errorList.add(new CheckException(e.getMessage(), (Node) null, e));
return;
}
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)) {
errorList.add(new CheckException(String.format("Package declaration '%s' does not match the folder structure: '%s' vs '%s'", this.packageName, name1, name2), node));
}
}
rootDirectory = dir.getParentFile();
}
use of de.be4.classicalb.core.parser.node.TPragmaIdOrString in project probparsers by bendisposto.
the class RulesReferencesFinder method determinePackage.
private String[] determinePackage(final TPragmaIdOrString packageTerminal, final Node node) {
String text = packageTerminal.getText();
// "foo.bar" or foo.bar
if ((text.startsWith("\"") && text.endsWith("\""))) {
text = text.replaceAll("\"", "");
}
final String[] packageNameArray = text.split("\\.");
final Pattern VALID_IDENTIFIER = Pattern.compile("([\\p{L}][\\p{L}\\p{N}_]*)");
for (int i = 0; i < packageNameArray.length; i++) {
boolean matches = VALID_IDENTIFIER.matcher(packageNameArray[i]).matches();
if (!matches) {
errorList.add(new CheckException(String.format("Invalid folder name '%s' in package declaration.", text), node));
}
}
return packageNameArray;
}
Aggregations