Ejemplo n.º 1
0
  @Test
  public void testIgnore() throws Throwable {
    JavaTokenizer tokenizer = new JavaTokenizer();
    tokenizer.setIgnoreLiterals(true);
    tokenizer.setIgnoreIdentifiers(true);
    SourceCode sourceCode =
        new SourceCode(new SourceCode.StringCodeLoader(getSampleCode(), "Foo.java"));
    Tokens tokens = new Tokens();
    TokenEntry.clearImages();
    tokenizer.tokenize(sourceCode, tokens);
    Map<String, SourceCode> codeMap = new HashMap<String, SourceCode>();
    codeMap.put("Foo.java", sourceCode);

    MatchAlgorithm matchAlgorithm = new MatchAlgorithm(codeMap, tokens, 5);
    matchAlgorithm.findMatches();
    Iterator matches = matchAlgorithm.matches();
    Match match = (Match) matches.next();
    assertFalse(matches.hasNext());

    Iterator marks = match.iterator();
    marks.next();
    marks.next();
    marks.next();
    assertFalse(marks.hasNext());
  }
Ejemplo n.º 2
0
  @Test
  public void testSimple() throws Throwable {
    JavaTokenizer tokenizer = new JavaTokenizer();
    SourceCode sourceCode =
        new SourceCode(new SourceCode.StringCodeLoader(getSampleCode(), "Foo.java"));
    Tokens tokens = new Tokens();
    TokenEntry.clearImages();
    tokenizer.tokenize(sourceCode, tokens);
    assertEquals(41, tokens.size());
    Map<String, SourceCode> codeMap = new HashMap<String, SourceCode>();
    codeMap.put("Foo.java", sourceCode);

    MatchAlgorithm matchAlgorithm = new MatchAlgorithm(codeMap, tokens, 5);
    matchAlgorithm.findMatches();
    Iterator matches = matchAlgorithm.matches();
    Match match = (Match) matches.next();
    assertFalse(matches.hasNext());

    Iterator marks = match.iterator();
    TokenEntry mark1 = (TokenEntry) marks.next();
    TokenEntry mark2 = (TokenEntry) marks.next();
    assertFalse(marks.hasNext());

    assertEquals(3, mark1.getBeginLine());
    assertEquals(4, mark2.getBeginLine());
    assertTrue("Foo.java" == mark1.getTokenSrcID() && "Foo.java" == mark2.getTokenSrcID());
    assertEquals(LINE_3, match.getSourceCodeSlice());
  }