fix a bug found with inner definitions.

This commit is contained in:
Oliver Burn 2008-07-16 08:23:02 +00:00
parent 756e47a05a
commit a6471e8a26
5 changed files with 37 additions and 2 deletions

View File

@ -204,6 +204,7 @@
<exclude name="**/InputSimple.java" />
<exclude name="**/InputValidMethodIndent.java" />
<exclude name="**/Post13KeywordsAsIdentifiersOK.java" />
<exclude name="**/InputMethodNameExtra.java"/>
</javac>
</target>

View File

@ -98,7 +98,15 @@ public class MethodNameCheck extends AbstractNameCheck
final DetailAST classDefOrNew = aAst.getParent().getParent();
final DetailAST classIdent =
classDefOrNew.findFirstToken(TokenTypes.IDENT);
if (method.getText().equals(classIdent.getText())) {
// Following logic is to handle when a classIdent can not be
// found. This is when you have a Literal_New keyword followed
// a DOT, which is when you have:
// new Outclass.InnerInterface(x) { ... }
// Such a rare case, will not have the logic to handle parsing
// down the tree looking for the first ident.
if ((null != classIdent)
&& method.getText().equals(classIdent.getText()))
{
log(method.getLineNo(), method.getColumnNo(),
"method.name.equals.class.name", method.getText());
}

View File

@ -0,0 +1,14 @@
public class InputMethodNameExtra
{
public void doit()
{
createNameHistoryDetails(historyDetails, previousNameService, entityId,
new More.ViewChangeHistoryBaseAction.ChangeHistoryDisplayName(agencyName)
{
String getDisplayName()
{
return getPreviousName(TypeOfName.AGENCY_NAME);
}
});
}
}

View File

@ -60,4 +60,16 @@ public class MethodNameCheckTest
verify(checkConfig, getPath("InputMethNameEqualClsName.java"), expected);
}
@Test
public void testForNpe() throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(MethodNameCheck.class);
final String[] expected = {
};
verify(checkConfig, getPath("naming/InputMethodNameExtra.java"), expected);
}
}

View File

@ -9,7 +9,7 @@
</properties>
<body>
<section name="Release 5.0">
<section name="Release 5.0 Beta 1">
<p>
The 5.x release is developed using Java 5 and requires a Java 5
platform to run. If you need run a Java 1.4 or earlier, then use