Commit Graph

638 Commits

Author SHA1 Message Date
Michal Kordas a13ebd482c Use constant for arrays with zero length. #1555
Fixes `ZeroLengthArrayInitialization` inspection violations in test code.

Description:
>Reports on allocations of arrays with known lengths of zero. Since array lengths in Java are non-modifiable, it is almost always possible to share zero-length arrays, rather than repeatedly allocating new zero-length arrays. Such sharing may provide useful optimizations in program runtime or footprint. Note that this inspection does not report zero-length arrays allocated as static final fields, as it is assumed that those arrays are being used to implement array sharing.
2015-08-22 14:38:41 +03:00
Michal Kordas 04182c6064 Remove unused import from test code. #1555
Fixes `UnusedImport` inspection violations.

Description:
>Reports any import statements that are unused.
2015-08-22 14:37:48 +03:00
Michal Kordas 8abfa48f2e Decrease visibility of public constructor in non-public classes. #1555
Fixes `PublicConstructorInNonPublicClass` inspection violations.

Description:
>Reports all constructors in non-public classes that are declared public.
2015-08-22 14:33:46 +03:00
Michal Kordas 19d1fb3602 Use ignored results of calling methods in test code. #1555
Fixes `IgnoreResultOfCall` inspection violations in test code.

Description:
>Reports any calls to specific methods where the result of that call is ignored. Both methods specified in the inspection's settings and methods annotated with org.jetbrains.annotations.Contract(pure=true) are checked. For many methods, ignoring the result is perfectly legitimate, but for some methods it is almost certainly an error. Examples of methods where ignoring the result of a call is likely to be an error include java.io.inputStream.read(), which returns the number of bytes actually read, any method on java.lang.String or java.math.BigInteger, as all of those methods are side-effect free and thus pointless if ignored.
2015-08-22 14:31:32 +03:00
Michal Kordas 555478f967 Create new instance using constructor in test code. #1555
Fixes `ClassNewInstance` inspection violations in test code.

Description:
>Reports any calls to java.lang.Class.newInstance(). The newInstance method propagates any exception thrown by the no-arg constructor, including checked exceptions. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. Replacing such a method call with a call to the java.lang.reflect.Constructor.newInstance() method avoids this problem by wrapping any exception thrown by the constructor in a java.lang.reflect.InvocationTargetException.
2015-08-22 14:29:30 +03:00
Michal Kordas 70ac1c44d9 Do not use Properties as Hashtable. #1555
Fixes `UseOfPropertiesAsHashtable` inspection violations in test code.

Description:
>Reports any calls to the java.util.Hashtable methods put(), putAll() or get() on a java.util.Properties object. For reasons lost to history, Properties inherits from Hashtable, but use of those methods is discouraged to prevent corruption of properties values with non-String data.
2015-08-22 14:28:37 +03:00
Michal Kordas 4cdea36a1e Remove unnecessary this in test code. #1555
Fixes `UnnecessaryThis` inspection violations in test code.

Description:
>Reports on any unnecessary uses of this in the code. Using this to disambiguate a code reference may easily become unnecessary via automatic refactorings, and is discouraged by many coding styles.
2015-08-21 16:14:25 +03:00
Michal Kordas aa950f0697 Remove unnecessarily qualified statically imported elements. #1555
Fixes `UnnecessarilyQualifiedStaticallyImportedElement` inspection violations in test code.

Description:
>Reports any references to static members which are statically imported and also qualified with their containing class name. Because the elements are already statically imported such qualification is unnecessary and can be removed.
2015-08-21 16:13:37 +03:00
Michal Kordas 613ac4bb77 Remove unnecessary constant array creation expressions. #1555
Fixes `UnnecessaryConstantArrayCreationExpression` inspection violations in test code.

Description:
>Reports any constant new array expression which can be replaced with an array initializer. Array initializers omit the type declaration because that is already specified by the declaration of the variable the expression is assigned to.
2015-08-21 16:12:44 +03:00
Michal Kordas 885fca8fe9 Remove call to printStackTrace() in test code. #1555
Fixes `ThrowablePrintStackTrace` inspection violations in test code.

Description:
>Reports any calls to Throwable.printStackTrace() without arguments. Such statements are often used for temporary debugging, and should probably be either removed from production code, or replaced with a more robust logging facility.
2015-08-21 16:11:08 +03:00
Michal Kordas b543f32fd7 Use field that was unused and remove suppression. #1555
Fixes `SuppressionAnnotation` inspection violations in test code.

Description:
>Reports any inspection suppression comments or annotations.
2015-08-21 16:10:34 +03:00
Michal Kordas cea7f4acbe Remove redundant throws. #1555
Fixes `RedundantThrows` inspection violations in test code.

Description:
>This inspection reports exceptions that are declared in a method's signature but never thrown by the method itself or its implementations/derivatives.
2015-08-21 16:09:26 +03:00
Michal Kordas 5e1cf30d49 Add missing locale to String case conversions in test code. #1555
Fixes `StringToUpperWithoutLocale` inspection violations in test code.

Description:
>Reports any call of toUpperCase() or toLowerCase() on String objects which do not specify a java.util.Locale. Such calls are usually incorrect in an internationalized environment.
2015-08-21 16:08:19 +03:00
Michal Kordas 3db243d947 Use String instead of constant in test code. #1555
Fixes `NumericToString` inspection violations in test code.

Description:
>Reports any call of toString() on numeric objects. Such calls are usually incorrect in an internationalized environment.
2015-08-21 16:07:47 +03:00
Michal Kordas d3dcf0474a Use multi-catch in test code. #1555
Fixes `TryWithIdenticalCatches` inspection violations in test code.

Description:
>Reports identical catch sections in try blocks under JDK 7. A quickfix is available to collapse the sections into a multi-catch section.
This inspection only reports if the project or module is configured to use a language level of 7.0 or higher.
2015-08-21 16:07:15 +03:00
Michal Kordas 8d898f7ceb Simplify throws list in test code. #1555
Fixes `MultipleExceptionsDeclaredOnTestMethod` inspection violations.

Description:
>Reports JUnit test methods with more than one exception declared in the throws clause. Such a throws clause can be more concisely declared as `throws Exception`.
2015-08-21 16:06:47 +03:00
Michal Kordas b2384741dc Use constants for empty arrays. #1555
Fixes some `ZeroLengthArrayInitialization` inspection violations.

Description:
>Reports on allocations of arrays with known lengths of zero. Since array lengths in Java are non-modifiable, it is almost always possible to share zero-length arrays, rather than repeatedly allocating new zero-length arrays. Such sharing may provide useful optimizations in program runtime or footprint. Note that this inspection does not report zero-length arrays allocated as static final fields, as it is assumed that those arrays are being used to implement array sharing.
2015-08-21 15:55:21 +03:00
Michal Kordas d4ef19e679 Fix confusing variable names. #1555
Fixes `StandardVariableNames` inspection violations in test code.

Description:
>Reports on any variables with 'standard' names which are of unexpected types. Such names may be confusing. Standard names and types are as follows:
- i, j, k, m, n - int
- f - float
- d - double
- b - byte
- c, ch - char
- l - long
- s, str - String
2015-08-21 15:53:51 +03:00
Michal Kordas 6d2f3ce5fa Remove redundant overriding methods. #1555
Fixes `RedundantMethodOverride` inspection violations in test code.

Description:
>Reports any method that has a body and signature that are identical to its super method. Such a method is redundant and probably a coding error.
2015-08-21 15:14:34 +03:00
Michal Kordas fa5a88bc1e Fix name for constants in test code. #1555
Fixes `ConstantNamingConvention` inspection violations in test code.

Description:
>Reports any constants whose names are either too short, too long, or do not follow the specified regular expression pattern. Constants are fields declared static final.
2015-08-21 14:26:47 +03:00
Michal Kordas 4a56989f8e Fix too broad scope of variables. #1555
Additionally, obsolete assertions were removed.

Fixes `TooBroadScope` inspection violations.

Description:
>Reports any variable declarations of which the scope can be narrowed. Especially useful for "Pascal style" declarations at the start of a method, but variables with too broad a scope are also often left over after refactorings.
2015-08-20 08:10:15 +03:00
Michal Kordas 03f4181580 Rename static methods not following convention in test code. #1555
Fixes `StaticMethodNamingConvention` inspection violations in test code.

Description:
>Reports static methods whose names are either too short, too long, or do not follow the specified regular expression pattern.
2015-08-20 08:03:54 +03:00
Ilja Dubinin 57b908199d String literals should not be duplicated. Issue #46 2015-08-20 06:54:16 +03:00
Michal Kordas 9dd69b267b Remove unchecked exceptions from throws clauses in test code. #1555
Fixes `ThrowsRuntimeException` inspection violations in test code.

Description:
>Reports declarations of unchecked exceptions (RuntimeException and its subclasses) in the throws clause of a method. Declaration of unchecked exceptions are not required and may be removed or moved to a Javadoc @throws tag.
2015-08-20 06:49:52 +03:00
Michal Kordas da6a8d083c Remove unnecessary local variables. #1555
Fixes `UnnecessaryLocalVariable` inspection violation.

Description:
>Reports unnecessary local variables, which add nothing to the comprehensibility of a method. Variables caught include local variables which are immediately returned, local variables that are immediately assigned to another variable and then not used, and local variables which always have the same value as another local variable or parameter.
2015-08-20 06:42:37 +03:00
Michal Kordas 697895a205 Mark fields as final in test code. #1555
Fixes `CanBeFinal` inspection violations in test code.

Description:
>This inspection reports all fields, methods or classes, found in the specified inspection scope, that may have a final modifier added to their declarations.
2015-08-20 06:40:09 +03:00
Michal Kordas 171935dd69 Remove duplicates in throws lists. #1555
Fixes `DuplicateThrows` inspection violations in test code.

Description:
>This inspection reports duplicate exceptions in a method throws list.
2015-08-20 06:39:05 +03:00
Michal Kordas 681e17be40 Remove unnecessarily fully qualified names in test code. #1555
Fixes `UnnecessaryFullyQualifiedName` inspection violations in test code.

Description:
>Reports on fully qualified class names which can be shortened. The quick fix for this inspection will shorten the fully qualified names, adding import statements as necessary.
2015-08-20 06:37:24 +03:00
Michal Kordas 0b52fefcc8 Remove usage of prohibited exceptions in test code. #1555
Fixes `BadExceptionThrown` inspection violations in test code.

Description:
>Reports throw statements which throw inappropriate exceptions. One use of this inspection would be to warn of throw statements which throw overly generic exceptions (e.g. java.lang.Exception or java.io.IOException).
2015-08-20 06:33:45 +03:00
Michal Kordas 77979aa80e Remove test for default implementation of toString(). #1555
Fixes `ObjectToString` inspection violations in test code.

Description:
>Reports any calls to .toString() which use the default implementation from java.lang.Object. The default implementation is rarely desired, but easy to use by accident. Calls to .toString() on objects of type java.lang.Object are ignored by this inspection.
2015-08-20 06:28:59 +03:00
Michal Kordas 3ac5d486ec Remove string concatenation done inside string builders. #1555
Fixes `StringConcatenationInsideStringBufferAppend` inspection violations in test code.

Description:
>Reports String concatenation used as the argument to StringBuffer.append(), StringBuilder.append() or Appendable.append(). Such calls may profitably be turned into chained append calls on the existing StringBuffer/Builder/Appendable, saving the cost of an extra StringBuffer/Builder allocation.
This inspection ignores compile time evaluated String concatenations, which when converted to chained append calls would only worsen performance.
2015-08-20 06:25:20 +03:00
Baratali Izmailov efa16e17bf Issue #1566: First sentence in a comment should start with a capital letter (Multiline comments) 2015-08-20 06:21:51 +03:00
Michal Kordas 2af817968f Remove unused array declarations. #1555
Fixes `MismatchedArrayReadWrite` inspection violations in test code.

Description:
>Reports any array fields or variables whose contents are read but not written, or written but not read. Such mismatched reads and writes are pointless, and probably indicate dead, incomplete or erroneous code.
2015-08-20 06:20:38 +03:00
Michal Kordas 227135b3ac Remove unused assignments. #1555
Fixes `UnusedAssignment` inspection violations in test code.

Description:
>This inspection points out the cases where a variable value is never used after its assignment, i.e.:  
- the variable never gets read after assignment OR  
- the value is always overwritten with another assignment before the next variable read OR  
- the variable initializer is redundant (for one of the above two reasons) OR  
- the variable is never used.
2015-08-20 06:19:44 +03:00
Michal Kordas 3e6b2028e4 Remove unnecessary cast expression. #1555
Fixes `RedundantCast` inspection violations in test code.

Description:
>This inspection reports unnecessary cast expressions.
2015-08-20 06:17:43 +03:00
Michal Kordas 4643c76051 Remove explicit array creation. #1555
Fixes `RedundantArrayCreation` inspection violations in test code introduced after recent commits.

Description:
>This inspection reports unnecessary creation of array expression to be passed as an argument to varargs parameter.
2015-08-20 06:16:18 +03:00
Michal Kordas 5d6ae80b84 Rename variable in anonymous class hiding other variable. #1555
Fixes `AnonymousClassVariableHidesContainingMethodVariable` inspection violations in test code introduced after recent commits.

Description:
>Reports anonymous class variables being named identically to variables of a containing method or lambda expression. Such a variable name may be confusing.
2015-08-20 06:14:55 +03:00
Michal Kordas f6b33ebf17 Mark methods as static. #1555
Fixes `MethodMayBeStatic` inspection violations in test code introduced after recent commits.

Description:
>Reports any methods which may safely be made static. A method may be static if it is not synchronized, it does not reference any of its class' non static methods and non static fields and is not overridden in a sub class.
2015-08-19 06:43:05 +03:00
Michal Kordas 9fbba0b380 Add missing @Override annotations in test code. #1555
Fixes `MissingOverrideAnnotation` inspection violations in test code.

Description:
>Reports any methods which override methods in a superclass but do not have the @java.lang.Override annotation.
This inspection only reports if the project or module is configured to use a language level of 5.0 or higher.
2015-08-19 06:41:58 +03:00
Michal Kordas bbe93aec4f Replace Arrays.asList() with Collections.emptyList(). #1555
Fixes `ArraysAsListWithZeroOrOneArgument` inspection violations in test code.

Description:
>Reports any calls to Arrays.asList() with zero arguments or only one argument. Such calls could be replaced with either a call to Collections.singletonList() or Collections.emptyList() which will save some memory.
2015-08-19 06:37:53 +03:00
Michal Kordas c5c3b7eed3 Decrease visibility of inner classes. #1555
Possibility to instantiate private checks was added.

Fixes `PublicInnerClass` inspection violation.

Description:
>Reports public inner classes.
2015-08-19 06:35:44 +03:00
Michal Kordas bc0bf95dae Fix non-static non-final all upper-case names in test code. #1555
Fixes `UpperCaseFieldNameNotConstant` inspection violations in test code.

Description:
>Reports non-static non-final fields whose names are all upper-case. Such fields may cause confusion by breaking a common naming convention, and are often the result of developer error.
2015-08-19 06:31:31 +03:00
Michal Kordas 0678968078 Fix questionable names in test code. #1555
Fixes `QuestionableName` inspection violations in test code.

Description:
>Reports on any variables, methods, or classes with questionable names. This inspection is best used to report common metasyntactic variables which may be used as names by lazy or confused developers.
2015-08-19 06:30:04 +03:00
Michal Kordas f88f22e0ab Remove redundant suppressions from test code. #1555
Fixes `RedundantSuppression` inspection violations in test code.

Description:
>This inspection reports usages of
@SuppressWarning annotation, or
// noinspection line comment, or
/** noinspection */ JavaDoc comment
which can be safely removed because inspection they affect is no longer applicable in this context.
2015-08-19 06:26:49 +03:00
Michal Kordas 3440ef73c9 Replace assertEquals() with arrayAssertEquals(). #1555
Fixes `AssertEqualsCalledOnArray` inspection violations in test code.

Description:
>Reports any calls to JUnit's assertEquals() method with arguments of type array. Arrays should be checked with one of the assertArrayEquals() methods.
2015-08-19 06:25:06 +03:00
Baratali Izmailov 54ccca1863 Issue #1566: First sentence in a comment should start with a capital letter 2015-08-18 04:25:29 -04:00
Andrei Selkin d71032a054 Provided UTs for valueOf() and values() methods of enums, issue #1173 2015-08-18 09:40:22 +03:00
Andrei Selkin ef58cc5a0d Workaround problem of interoperability between PowerMock and JaCoCo, issue #1173 2015-08-18 09:40:22 +03:00
Michal Kordas aeb68b7da9 Remove unnecessary this in test code. #1555
Fixes `UnnecessaryThis` inspection violations in test code.

Description:
>Reports on any unnecessary uses of this in the code. Using this to disambiguate a code reference may easily become unnecessary via automatic refactorings, and is discouraged by many coding styles.
2015-08-18 08:52:03 +03:00
Michal Kordas b062024229 Mark util class as final in test code. #1555
Fixes `ClassWithOnlyPrivateConstructors` inspection violation in test code.

Description:
>Reports classes with only private constructors that are not extended by any nested class. Such classes can not be extended and should be declared final.
2015-08-18 08:50:00 +03:00