Package org.sonar.cxx

Examples of org.sonar.cxx.CxxConfiguration


  public CxxTokenizer(Charset charset) {
    this.charset = charset;
  }

  public final void tokenize(SourceCode source, Tokens cpdTokens) {
    Lexer lexer = CxxLexer.create(new CxxConfiguration(charset));
    String fileName = source.getFileName();
    List<Token> tokens = lexer.lex(new File(fileName));
    for (Token token : tokens) {
      TokenEntry cpdToken = new TokenEntry(getTokenImage(token), fileName, token.getLine());
      cpdTokens.add(cpdToken);
View Full Code Here


    Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
    save(squidSourceFiles);
  }

  private CxxConfiguration createConfiguration(Project project, Settings conf) {
    CxxConfiguration cxxConf = new CxxConfiguration(fs.sourceCharset());
    cxxConf.setBaseDir(fs.baseDir().getAbsolutePath());
    String[] lines = conf.getStringLines(CxxPlugin.DEFINES_KEY);
    if(lines.length > 0){
      cxxConf.setDefines(Arrays.asList(lines));
    }
    cxxConf.setIncludeDirectories(conf.getStringArray(CxxPlugin.INCLUDE_DIRECTORIES_KEY));
    cxxConf.setErrorRecoveryEnabled(conf.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY));
    cxxConf.setForceIncludeFiles(conf.getStringArray(CxxPlugin.FORCE_INCLUDE_FILES_KEY));
    return cxxConf;
  }
View Full Code Here

  }

  void buildLookupTables(Project project) {
    List<File> files = fs.files(CxxLanguage.testQuery);

    CxxConfiguration cxxConf = new CxxConfiguration(fs.sourceCharset());
    cxxConf.setBaseDir(fs.baseDir().getAbsolutePath());
    String[] lines = conf.getStringLines(CxxPlugin.DEFINES_KEY);
    if(lines.length > 0){
      cxxConf.setDefines(Arrays.asList(lines));
    }
    cxxConf.setIncludeDirectories(conf.getStringArray(CxxPlugin.INCLUDE_DIRECTORIES_KEY));

    for (File file : files) {
      @SuppressWarnings("unchecked")
      SourceFile source = CxxAstScanner.scanSingleFileConfig(file, cxxConf);
      if(source.hasChildren()) {
View Full Code Here

public class ParsingErrorCheckTest {

  @Test
  public void test_syntax_error_recognition() {
    CxxConfiguration config = new CxxConfiguration();
    config.setErrorRecoveryEnabled(false);
    SourceFile file = CxxAstScanner.scanSingleFileConfig(new File("src/test/resources/checks/parsingError1.cc"), config, new ParsingErrorCheck());
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(4).withMessageThat(containsString("Parse error"))
      .noMore();
  }
View Full Code Here

      .noMore();
  }

  @Test
  public void test_syntax_error_pperror() {
    CxxConfiguration config = new CxxConfiguration()
    config.setErrorRecoveryEnabled(false);
    SourceFile file = CxxAstScanner.scanSingleFileConfig(new File("src/test/resources/checks/parsingError2.cc"), config, new ParsingErrorCheck());
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(2).withMessageThat(containsString("Parse error"))
      .noMore();
  }
View Full Code Here

public class ParsingErrorRecoveryCheckTest {
   
  @Test
  public void test_syntax_error_recovery() {
    CxxConfiguration config = new CxxConfiguration();
    config.setErrorRecoveryEnabled(true);
    SourceFile file = CxxAstScanner.scanSingleFileConfig(new File("src/test/resources/checks/parsingError3.cc"), config, new ParsingErrorRecoveryCheck());
   
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(2).withMessage("C++ Parser can't read code. Declaration is skipped.")
      .noMore();
View Full Code Here

  protected CxxConfiguration conf = null;
  protected Parser<Grammar> p = null;
  protected Grammar g = null;

  public ParserBaseTest(){
    conf = new CxxConfiguration();
    conf.setErrorRecoveryEnabled(false);
    p = CxxParser.create(mock(SquidAstVisitorContext.class), conf);
    g = p.getGrammar();
  }
View Full Code Here

    assertThat(lexer.lex("#define M\n" + "M"), not(hasToken("M", GenericTokenType.IDENTIFIER)));
  }

  @Test
  public void external_define() {
    CxxConfiguration conf = new CxxConfiguration();
    conf.setDefines(Arrays.asList("M body"));
    CxxPreprocessor cxxpp = new CxxPreprocessor(mock(SquidAstVisitorContext.class), conf);
    lexer = CxxLexer.create(conf, cxxpp, new JoinStringsPreprocessor());

    List<Token> tokens = lexer.lex("M");
    assertThat(tokens).hasSize(2);
View Full Code Here

    assertThat(tokens, hasToken("body", GenericTokenType.IDENTIFIER));
  }

  @Test
  public void external_defines_with_params() {
    CxxConfiguration conf = new CxxConfiguration();
    conf.setDefines(Arrays.asList("minus(a, b) a - b"));
    CxxPreprocessor cxxpp = new CxxPreprocessor(mock(SquidAstVisitorContext.class), conf);
    lexer = CxxLexer.create(conf, cxxpp, new JoinStringsPreprocessor());

    List<Token> tokens = lexer.lex("minus(1, 2)");
    assertThat(tokens).hasSize(4);
View Full Code Here

    when(scp.getSourceCode(any(File.class))).thenReturn("#define A B\n");

    SquidAstVisitorContext<Grammar> ctx = mock(SquidAstVisitorContext.class);
    when(ctx.getFile()).thenReturn(new File("/home/joe/file.cc"));

    CxxPreprocessor pp = new CxxPreprocessor(ctx, new CxxConfiguration(), scp);
    lexer = CxxLexer.create(pp, new JoinStringsPreprocessor());

    List<Token> tokens = lexer.lex("#include <file>\n"
      + "A");
    assertThat(tokens).hasSize(2); // B + EOF
View Full Code Here

TOP

Related Classes of org.sonar.cxx.CxxConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.