Search in sources :

Example 76 with Scanner

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;
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) MalmoMod(com.microsoft.Malmo.MalmoMod)

Example 77 with Scanner

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();
}
Also used : Scanner(java.util.Scanner)

Example 78 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Example 79 with 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);
}
Also used : Scanner(java.util.Scanner) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Example 80 with 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);
}
Also used : Scanner(java.util.Scanner) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Aggregations

Scanner (java.util.Scanner)862 File (java.io.File)135 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)72 Test (org.junit.Test)70 NoSuchElementException (java.util.NoSuchElementException)59 InputStream (java.io.InputStream)54 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 FileNotFoundException (java.io.FileNotFoundException)47 InputMismatchException (java.util.InputMismatchException)47 HashMap (java.util.HashMap)35 FileInputStream (java.io.FileInputStream)33 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 Locale (java.util.Locale)24 BigInteger (java.math.BigInteger)23 List (java.util.List)22 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18