use of java.util.Scanner in project malmo by Microsoft.
the class SchemaHelper method testSchemaVersionNumbers.
public static boolean testSchemaVersionNumbers(String modVersion) {
// modVersion will be in three parts - eg 0.19.1
// We only care about the major and minor release numbers.
String[] parts = modVersion.split("\\.");
if (parts.length != 3) {
System.out.println("Malformed mod version number: " + modVersion + " - should be of form x.y.z. Has CMake been run?");
return false;
}
String requiredVersion = parts[0] + "." + parts[1];
System.out.println("Testing schemas against internal version number: " + requiredVersion);
InputStream stream = MalmoMod.class.getClassLoader().getResourceAsStream("schemas.index");
if (stream == null) {
System.out.println("Cannot find index of schema files in resources - try rebuilding.");
// Failed to find index in resources - check that gradle build has happened!
return false;
}
Scanner scanner = new Scanner(stream);
while (scanner.hasNextLine()) {
String xsdFile = scanner.nextLine();
String version = getVersionNumber(xsdFile);
if (version == null || !version.equals(requiredVersion)) {
scanner.close();
System.out.println("Version error: schema file " + xsdFile + " has the wrong version number - should be " + requiredVersion + ", actually " + version);
return false;
}
}
scanner.close();
return true;
}
use of java.util.Scanner in project visualee by Thomas-S-B.
the class Examiner method getClassBody.
protected static String getClassBody(String sourceCode) {
StringBuilder classBody = new StringBuilder();
boolean isInBodyNow = false;
try (Scanner scanner = new Scanner(sourceCode)) {
scanner.useDelimiter("[\n]+");
while (scanner.hasNext()) {
String token = scanner.next();
if (!isInBodyNow) {
if (token.contains("class ")) {
isInBodyNow = true;
}
} else {
classBody.append(token).append("\n");
}
}
}
return classBody.toString();
}
use of java.util.Scanner in project visualee by Thomas-S-B.
the class ExaminerTest method testScanAfterClosedParenthesisInsufficientTokens.
@Test(expected = IllegalArgumentException.class)
public void testScanAfterClosedParenthesisInsufficientTokens() {
JavaSource javaSource;
String sourceCode;
Scanner scanner;
String currentToken;
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "@NotNull(groups";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
// now @NotNull((groups
currentToken = scanner.next();
ExaminerImpl.scanAfterClosedParenthesis(currentToken, scanner);
}
use of java.util.Scanner in project visualee by Thomas-S-B.
the class ExaminerTest method testJumpOverTokenInsufficientTokens.
@Test(expected = IllegalArgumentException.class)
public void testJumpOverTokenInsufficientTokens() {
JavaSource javaSource;
String sourceCode;
Scanner scanner;
String currentToken;
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "public";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
// now public
currentToken = scanner.next();
ExaminerImpl.jumpOverJavaToken(currentToken, scanner);
}
use of java.util.Scanner in project visualee by Thomas-S-B.
the class ExaminerTest method testScanAfterQuote.
@Test
public void testScanAfterQuote() {
JavaSource javaSource;
String sourceCode;
String actual;
String expected;
Scanner scanner;
String currentToken;
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "out.println(\"<h1>UserTransaction obtained using @Inject</h1>\");\n" + "mytoken";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
// now out.println(\"<h1>UserTransaction
currentToken = scanner.next();
ExaminerImpl.scanAfterQuote(currentToken, scanner);
expected = "mytoken";
actual = scanner.next();
assertEquals(expected, actual);
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "out.println(\"<title>UserTransaction obtained using @Inject</title>\");\n" + "out.println(\"<h1>UserTransaction obtained using @Inject</h1>);\n" + "mytoken";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
// now out.println(\"<h1>UserTransaction\"
currentToken = scanner.next();
ExaminerImpl.scanAfterQuote(currentToken, scanner);
expected = "out.println(\"<h1>UserTransaction";
actual = scanner.next();
assertEquals(expected, actual);
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "@NotNull((groups = PersistenceConstraint.class) saddas)\n" + "private Album2 album;\n";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
// now @NotNull((groups
currentToken = scanner.next();
ExaminerImpl.scanAfterQuote(currentToken, scanner);
expected = "=";
actual = scanner.next();
assertEquals(expected, actual);
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
sourceCode = "LOG.log(Level.FINE, \"Added {0} to watch channel {1}\", new Object[]{browserWindow.hashCode(), browserWindow.getChannel()});";
javaSource.setSourceCode(sourceCode);
scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
//LOG.log(Level.FINE,
scanner.next();
//"Added...
currentToken = scanner.next();
ExaminerImpl.scanAfterQuote(currentToken, scanner);
expected = "new";
actual = scanner.next();
assertEquals(expected, actual);
}
Aggregations