JAVA: better handling of java code
This commit is contained in:
parent
4ff52b5883
commit
6a66d32871
|
@ -1981,6 +1981,13 @@ void CheckClass::checkConst()
|
|||
if (!_settings->_checkCodingStyle || _settings->ifcfg)
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
createSymbolDatabase();
|
||||
|
||||
std::multimap<std::string, SpaceInfo *>::iterator it;
|
||||
|
|
|
@ -36,6 +36,11 @@ void CheckObsoleteFunctions::obsoleteFunctions()
|
|||
if (!_settings->_checkCodingStyle)
|
||||
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)
|
||||
return;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
{
|
||||
std::list< std::pair<const std::string, const std::string> >::const_iterator it(_obsoleteFunctions.begin()), itend(_obsoleteFunctions.end());
|
||||
|
|
|
@ -1744,6 +1744,22 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
}
|
||||
|
||||
// Simplify JAVA code
|
||||
if (_files[0].find(".java") != std::string::npos)
|
||||
{
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, ") throws %var% {"))
|
||||
Token::eraseTokens(tok, tok->tokAt(3));
|
||||
else if (tok->str() == "private")
|
||||
tok->str("private:");
|
||||
else if (tok->str() == "protected")
|
||||
tok->str("protected:");
|
||||
else if (tok->str() == "public")
|
||||
tok->str("public:");
|
||||
}
|
||||
}
|
||||
|
||||
// remove inline SQL (Oracle PRO*C). Ticket: #1959
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
|
@ -6612,6 +6628,10 @@ 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)
|
||||
return;
|
||||
|
||||
std::string className;
|
||||
int classLevel = 0;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
|
|
|
@ -268,6 +268,9 @@ private:
|
|||
|
||||
// Tokenize C#
|
||||
TEST_CASE(cs);
|
||||
|
||||
// Tokenize JAVA
|
||||
TEST_CASE(java);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4578,6 +4581,30 @@ private:
|
|||
{
|
||||
ASSERT_EQUALS("; int * i ;", tokenizeAndStringify("; int [] i;"));
|
||||
}
|
||||
|
||||
std::string javatest(const char javacode[])
|
||||
{
|
||||
// tokenize..
|
||||
Tokenizer tokenizer(0, this);
|
||||
std::istringstream istr(javacode);
|
||||
tokenizer.tokenize(istr, "test.java");
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
{
|
||||
ostr << tok->str();
|
||||
if (tok->next())
|
||||
ostr << " ";
|
||||
}
|
||||
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
void java()
|
||||
{
|
||||
ASSERT_EQUALS("void f ( ) { }", javatest("void f() throws Exception { }"));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue