Tokenizer: Added function for checking if code is Java/C#

This commit is contained in:
Daniel Marjamäki 2010-10-28 18:51:55 +02:00
parent fee20bafa0
commit 9435fde551
5 changed files with 18 additions and 9 deletions

View File

@ -1984,8 +1984,7 @@ void CheckClass::checkConst()
return;
// Don't check C# and JAVA classes
if (_tokenizer->getFiles()->at(0).find(".java") != std::string::npos ||
_tokenizer->getFiles()->at(0).find(".cs") != std::string::npos)
if (_tokenizer->isJavaOrCSharp())
{
return;
}

View File

@ -37,8 +37,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
return;
// Don't check C# and Java code
if (_tokenizer->getFiles()->at(0).find(".java") != std::string::npos ||
_tokenizer->getFiles()->at(0).find(".cs") != std::string::npos)
if (_tokenizer->isJavaOrCSharp())
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

View File

@ -2212,8 +2212,7 @@ void CheckOther::checkIncompleteStatement()
void CheckOther::strPlusChar()
{
// Don't use this check for Java and C# programs..
if (_tokenizer->getFiles()->at(0).find(".java") != std::string::npos ||
_tokenizer->getFiles()->at(0).find(".cs") != std::string::npos)
if (_tokenizer->isJavaOrCSharp())
{
return;
}

View File

@ -1744,8 +1744,8 @@ bool Tokenizer::tokenize(std::istream &code,
}
}
// Simplify JAVA code
if (_files[0].find(".java") != std::string::npos)
// Simplify JAVA/C# code
if (isJavaOrCSharp() && _files[0].find(".java") != std::string::npos)
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
@ -6649,7 +6649,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
void Tokenizer::simplifyEnum()
{
// Don't simplify enums in java files
if (_files[0].find(".java") != std::string::npos)
if (isJavaOrCSharp())
return;
std::string className;

View File

@ -45,6 +45,18 @@ public:
Tokenizer(const Settings * settings, ErrorLogger *errorLogger);
virtual ~Tokenizer();
/** Is the code JAVA/C#. Used for bailouts */
bool isJavaOrCSharp() const
{
if (_files.size() != 1)
return false;
const std::string::size_type pos = _files[0].rfind(".");
if (pos != std::string::npos)
return (_files[0].substr(pos) == ".java" ||
_files[0].substr(pos) == ".cs");
return false;
}
/**
* Tokenize code
* @param code input stream for code, e.g.