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; return;
// Don't check C# and JAVA classes // Don't check C# and JAVA classes
if (_tokenizer->getFiles()->at(0).find(".java") != std::string::npos || if (_tokenizer->isJavaOrCSharp())
_tokenizer->getFiles()->at(0).find(".cs") != std::string::npos)
{ {
return; return;
} }

View File

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

View File

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

View File

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

View File

@ -45,6 +45,18 @@ public:
Tokenizer(const Settings * settings, ErrorLogger *errorLogger); Tokenizer(const Settings * settings, ErrorLogger *errorLogger);
virtual ~Tokenizer(); 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 * Tokenize code
* @param code input stream for code, e.g. * @param code input stream for code, e.g.