fix for bug #626875, array instantiation incorrectly flagged
This commit is contained in:
parent
acc3f40015
commit
c2b22a74a2
|
|
@ -28,6 +28,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FullIdent;
|
||||
import antlr.collections.AST;
|
||||
|
||||
// TODO: Clean up potential duplicate code here and in UnusedImportsCheck
|
||||
/**
|
||||
|
|
@ -47,8 +48,10 @@ import com.puppycrawl.tools.checkstyle.api.FullIdent;
|
|||
* Some extremely performance sensitive projects may require the use of factory
|
||||
* methods for other classes as well, to enforce the usage of number caches or
|
||||
* object pools.
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* Limitations: It is currently not possible to specify array classes.
|
||||
*
|
||||
* @author Lars Kühne
|
||||
*/
|
||||
public class IllegalInstantiationCheck
|
||||
|
|
@ -129,6 +132,15 @@ public class IllegalInstantiationCheck
|
|||
private void processLiteralNew(DetailAST aAST)
|
||||
{
|
||||
DetailAST typeNameAST = (DetailAST) aAST.getFirstChild();
|
||||
|
||||
AST nameSibling = typeNameAST.getNextSibling();
|
||||
if (nameSibling != null
|
||||
&& nameSibling.getType() == TokenTypes.ARRAY_DECLARATOR)
|
||||
{
|
||||
// aAST == "new Boolean[]"
|
||||
return;
|
||||
}
|
||||
|
||||
FullIdent typeIdent = FullIdent.createFullIdent(typeNameAST);
|
||||
final String typeName = typeIdent.getText();
|
||||
final int lineNo = aAST.getLineNo();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class InputSemantic
|
|||
/* Boolean instantiation in a non-static initializer */
|
||||
{
|
||||
Boolean x = new Boolean(true);
|
||||
Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE};
|
||||
}
|
||||
|
||||
/** fully qualified Boolean instantiation in a method. **/
|
||||
|
|
|
|||
|
|
@ -546,15 +546,15 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputSemantic.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":51:65: Must have at least one statement.",
|
||||
filepath + ":53:41: Must have at least one statement.",
|
||||
filepath + ":70:38: Must have at least one statement.",
|
||||
filepath + ":71:52: Must have at least one statement.",
|
||||
filepath + ":72:45: Must have at least one statement.",
|
||||
filepath + ":74:13: Must have at least one statement.",
|
||||
filepath + ":76:17: Must have at least one statement.",
|
||||
filepath + ":78:13: Must have at least one statement.",
|
||||
filepath + ":81:17: Must have at least one statement.",
|
||||
filepath + ":52:65: Must have at least one statement.",
|
||||
filepath + ":54:41: Must have at least one statement.",
|
||||
filepath + ":71:38: Must have at least one statement.",
|
||||
filepath + ":72:52: Must have at least one statement.",
|
||||
filepath + ":73:45: Must have at least one statement.",
|
||||
filepath + ":75:13: Must have at least one statement.",
|
||||
filepath + ":77:17: Must have at least one statement.",
|
||||
filepath + ":79:13: Must have at least one statement.",
|
||||
filepath + ":82:17: Must have at least one statement.",
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
|
@ -571,11 +571,11 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputSemantic.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":51:65: Empty catch block.",
|
||||
filepath + ":71:52: Empty catch block.",
|
||||
filepath + ":72:45: Empty catch block.",
|
||||
filepath + ":74:13: Empty try block.",
|
||||
filepath + ":76:17: Empty finally block.",
|
||||
filepath + ":52:65: Empty catch block.",
|
||||
filepath + ":72:52: Empty catch block.",
|
||||
filepath + ":73:45: Empty catch block.",
|
||||
filepath + ":75:13: Empty try block.",
|
||||
filepath + ":77:17: Empty finally block.",
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public class EqualsHashCodeCheckTest
|
|||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputSemantic.java");
|
||||
final String[] expected = {
|
||||
"125:9: Definition of 'equals()' without corresponding defnition of 'hashCode()'.",
|
||||
"162:13: Definition of 'equals()' without corresponding defnition of 'hashCode()'.",
|
||||
"126:9: Definition of 'equals()' without corresponding defnition of 'hashCode()'.",
|
||||
"163:13: Definition of 'equals()' without corresponding defnition of 'hashCode()'.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class GenericIllegalRegexpCheckTest
|
|||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputSemantic.java");
|
||||
final String[] expected = {
|
||||
"68: Line matches the illegal pattern '" + illegal + "'."
|
||||
"69: Line matches the illegal pattern '" + illegal + "'."
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ public class IllegalInstantiationCheckTest
|
|||
final String[] expected = {
|
||||
"19:21: Avoid instantiation of java.lang.Boolean.",
|
||||
"24:21: Avoid instantiation of java.lang.Boolean.",
|
||||
"30:16: Avoid instantiation of java.lang.Boolean.",
|
||||
"37:21: Avoid instantiation of " +
|
||||
"31:16: Avoid instantiation of java.lang.Boolean.",
|
||||
"38:21: Avoid instantiation of " +
|
||||
"com.puppycrawl.tools.checkstyle.InputModifier.",
|
||||
"40:18: Avoid instantiation of java.io.File.",
|
||||
"43:21: Avoid instantiation of java.awt.Color."
|
||||
"41:18: Avoid instantiation of java.io.File.",
|
||||
"44:21: Avoid instantiation of java.awt.Color."
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ public class InnerAssignmentCheckTest
|
|||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputSemantic.java");
|
||||
final String[] expected = {
|
||||
"101:15: Avoid inner assignments.",
|
||||
"101:19: Avoid inner assignments.",
|
||||
"103:39: Avoid inner assignments.",
|
||||
"105:35: Avoid inner assignments.",
|
||||
"102:15: Avoid inner assignments.",
|
||||
"102:19: Avoid inner assignments.",
|
||||
"104:39: Avoid inner assignments.",
|
||||
"106:35: Avoid inner assignments.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ extends BaseCheckTestCase
|
|||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputSemantic.java");
|
||||
final String[] expected = {
|
||||
"93:43: Should use uppercase 'L'.",
|
||||
"94:43: Should use uppercase 'L'.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue