Search in sources :

Example 21 with Scanner

use of java.util.Scanner in project sonarqube by SonarSource.

the class ScannerReportViewerApp method updateSource.

private void updateSource(Component component) {
    File sourceFile = reader.getFileStructure().fileFor(Domain.SOURCE, component.getRef());
    sourceEditor.setText("");
    if (sourceFile.exists()) {
        try (Scanner s = new Scanner(sourceFile, StandardCharsets.UTF_8.name()).useDelimiter("\\Z")) {
            if (s.hasNext()) {
                sourceEditor.setText(s.next());
            }
        } catch (IOException ex) {
            StringWriter errors = new StringWriter();
            ex.printStackTrace(new PrintWriter(errors));
            sourceEditor.setText(errors.toString());
        }
    }
}
Also used : Scanner(java.util.Scanner) StringWriter(java.io.StringWriter) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 22 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 23 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 24 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 25 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)567 File (java.io.File)97 IOException (java.io.IOException)63 NoSuchElementException (java.util.NoSuchElementException)59 ArrayList (java.util.ArrayList)56 Test (org.junit.Test)53 InputStream (java.io.InputStream)51 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 InputMismatchException (java.util.InputMismatchException)47 FileNotFoundException (java.io.FileNotFoundException)42 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 FileInputStream (java.io.FileInputStream)27 HashMap (java.util.HashMap)26 Locale (java.util.Locale)23 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)18 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)18