@Test public void test() { String filename = "test1.sol"; SensorContextTester context = SensorContextTester.create(new File("src/test/resources").getAbsoluteFile()); InputFile file = createInputFile(filename); context.fileSystem().add(file); try { SolidityCpd.addTokensCpd(context.newCpdTokens().onFile(file), file.contents()); List<TokensLine> tokensLines = context.cpdTokens("module:" + filename); assertThat(tokensLines).hasSize(26); assertThat(tokensLines.get(0).getValue()).isEqualTo("contractTwoD{"); assertThat(tokensLines.get(4).getValue()).isEqualTo("stringconstant_string=\"cryptopus.co Medium\";"); assertThat(tokensLines.get(10).getValue()).isEqualTo("while(y<arraylength)"); } catch (IOException e) { e.printStackTrace(); } }
public static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); for (Token token : tokenStream.getTokens()) { if (token.getType() != -1) { TokenLocation tokenLocation = new TokenLocation(token.getLine(), token.getCharPositionInLine(), token.getText()); cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), token.getText()); } } cpdTokens.save(); }
SolidityCpd { public static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); for (Token token : tokenStream.getTokens()) { if (token.getType() != -1) { TokenLocation tokenLocation = new TokenLocation(token.getLine(), token.getCharPositionInLine(), token.getText()); cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), token.getText()); } } cpdTokens.save(); } }
SolidityCpd { public static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); for (Token token : tokenStream.getTokens()) { if (token.getType() != -1) { TokenLocation tokenLocation = new TokenLocation(token.getLine(), token.getCharPositionInLine(), token.getText()); cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), token.getText()); } } cpdTokens.save(); } private  SolidityCpd(); }
SolidityCpd { public static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); for (Token token : tokenStream.getTokens()) { if (token.getType() != -1) { TokenLocation tokenLocation = new TokenLocation(token.getLine(), token.getCharPositionInLine(), token.getText()); cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), token.getText()); } } cpdTokens.save(); } private  SolidityCpd(); static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents); }
SolidityCpd { public static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); for (Token token : tokenStream.getTokens()) { if (token.getType() != -1) { TokenLocation tokenLocation = new TokenLocation(token.getLine(), token.getCharPositionInLine(), token.getText()); cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startLineOffset(), tokenLocation.endLine(), tokenLocation.endLineOffset(), token.getText()); } } cpdTokens.save(); } private  SolidityCpd(); static void addTokensCpd(NewCpdTokens cpdTokens, String fileContents);  }