Package org.codenarc.rule
Class AbstractAstVisitorRule
- java.lang.Object
-
- org.codenarc.rule.AbstractRule
-
- org.codenarc.rule.AbstractAstVisitorRule
-
- All Implemented Interfaces:
Rule
- Direct Known Subclasses:
AbcMetricRule,AbstractClassNameRule,AbstractClassWithoutAbstractMethodRule,AbstractClassWithPublicConstructorRule,AbstractEnhanceableAstVisitorRule,AbstractJavadocEmptyTagRule,AbstractJavadocMissingDescriptionRule,AbstractSharedAstVisitorRule,AddEmptyStringRule,AssertWithinFinallyBlockRule,AssignCollectionSortRule,AssignCollectionUniqueRule,AssignmentInConditionalRule,AssignmentToStaticFieldFromInstanceMethodRule,BigDecimalInstantiationRule,BitwiseOperatorInConditionalRule,BlockEndsWithBlankLineRule,BlockStartsWithBlankLineRule,BooleanGetBooleanRule,BooleanMethodReturnsNullRule,BracesForForLoopRule,BracesForIfElseRule,BracesForMethodRule,BracesForTryCatchFinallyRule,BrokenNullCheckRule,BrokenOddnessCheckRule,BuilderMethodWithSideEffectsRule,BusyWaitRule,CatchArrayIndexOutOfBoundsExceptionRule,CatchErrorRule,CatchExceptionRule,CatchIllegalMonitorStateExceptionRule,CatchIndexOutOfBoundsExceptionRule,CatchNullPointerExceptionRule,CatchRuntimeExceptionRule,CatchThrowableRule,ChainedTestRule,ClassEndsWithBlankLineRule,ClassForNameRule,ClassNameRule,ClassNameSameAsSuperclassRule,ClassSizeRule,ClassStartsWithBlankLineRule,CloneableWithoutCloneRule,CloneWithoutCloneableRule,ClosureAsLastMethodParameterRule,ClosureStatementOnOpeningLineOfMultipleLineClosureRule,CollectAllIsDeprecatedRule,ComparisonOfTwoConstantsRule,ComparisonWithSelfRule,CompileStaticRule,ConfusingClassNamedExceptionRule,ConfusingMethodNameRule,ConfusingMultipleReturnsRule,ConfusingTernaryRule,ConsecutiveLiteralAppendsRule,ConsecutiveStringConcatenationRule,ConstantAssertExpressionRule,ConstantIfExpressionRule,ConstantsOnlyInterfaceRule,ConstantTernaryExpressionRule,CouldBeElvisRule,CouldBeSwitchStatementRule,CoupledTestCaseRule,CrapMetricRule,CyclomaticComplexityRule,DeadCodeRule,DirectConnectionManagementRule,DoubleCheckedLockingRule,DoubleNegativeRule,DuplicateCaseStatementRule,DuplicateListLiteralRule,DuplicateMapKeyRule,DuplicateMapLiteralRule,DuplicateNumberLiteralRule,DuplicateSetValueRule,DuplicateStringLiteralRule,ElseBlockBracesRule,EmptyCatchBlockRule,EmptyClassRule,EmptyElseBlockRule,EmptyFinallyBlockRule,EmptyForStatementRule,EmptyIfStatementRule,EmptyInstanceInitializerRule,EmptyMethodInAbstractClassRule,EmptyMethodRule,EmptyStaticInitializerRule,EmptySwitchStatementRule,EmptySynchronizedStatementRule,EmptyTryBlockRule,EmptyWhileStatementRule,EnumCustomSerializationIgnoredRule,EqualsAndHashCodeRule,EqualsOverloadedRule,ExceptionExtendsErrorRule,ExceptionExtendsThrowableRule,ExceptionNotThrownRule,ExplicitArrayListInstantiationRule,ExplicitCallToAndMethodRule,ExplicitCallToCompareToMethodRule,ExplicitCallToDivMethodRule,ExplicitCallToEqualsMethodRule,ExplicitCallToGetAtMethodRule,ExplicitCallToLeftShiftMethodRule,ExplicitCallToMinusMethodRule,ExplicitCallToModMethodRule,ExplicitCallToMultiplyMethodRule,ExplicitCallToOrMethodRule,ExplicitCallToPlusMethodRule,ExplicitCallToPowerMethodRule,ExplicitCallToPutAtMethodRule,ExplicitCallToRightShiftMethodRule,ExplicitCallToXorMethodRule,ExplicitGarbageCollectionRule,ExplicitHashMapInstantiationRule,ExplicitHashSetInstantiationRule,ExplicitLinkedHashMapInstantiationRule,ExplicitLinkedListInstantiationRule,ExplicitStackInstantiationRule,ExplicitTreeSetInstantiationRule,FactoryMethodNameRule,FieldNameRule,FieldTypeRequiredRule,FileCreateTempFileRule,FinalClassWithProtectedMemberRule,ForLoopShouldBeWhileLoopRule,ForStatementBracesRule,GetterMethodCouldBePropertyRule,GrailsDomainHasEqualsRule,GrailsDomainHasToStringRule,GrailsDomainReservedSqlKeywordNameRule,GrailsDomainStringPropertyMaxSizeRule,GrailsDomainWithServiceReferenceRule,GrailsDuplicateConstraintRule,GrailsDuplicateMappingRule,GrailsMassAssignmentRule,GrailsPublicControllerMethodRule,GrailsServletContextReferenceRule,GroovyLangImmutableRule,GStringAsMapKeyRule,GStringExpressionWithinStringRule,HardCodedWindowsFileSeparatorRule,HardCodedWindowsRootDirectoryRule,HashtableIsObsoleteRule,IfStatementBracesRule,IfStatementCouldBeTernaryRule,IllegalClassMemberRule,IllegalClassReferenceRule,IllegalPackageReferenceRule,IllegalSubclassRule,ImplementationAsTypeRule,ImportFromSunPackagesRule,InconsistentPropertyLockingRule,InconsistentPropertySynchronizationRule,IndentationRule,InsecureRandomRule,InstanceofRule,IntegerGetIntegerRule,InterfaceNameRule,InterfaceNameSameAsSuperInterfaceRule,InvertedConditionRule,InvertedIfElseRule,JavadocConsecutiveEmptyLinesRule,JavadocEmptyLastLineRule,JavaIoPackageAccessRule,JdbcConnectionReferenceRule,JdbcResultSetReferenceRule,JdbcStatementReferenceRule,JUnitAssertAlwaysFailsRule,JUnitAssertAlwaysSucceedsRule,JUnitAssertEqualsConstantActualValueRule,JUnitFailWithoutMessageRule,JUnitLostTestRule,JUnitPublicFieldRule,JUnitPublicNonTestMethodRule,JUnitPublicPropertyRule,JUnitSetUpCallsSuperRule,JUnitStyleAssertionsRule,JUnitTearDownCallsSuperRule,JUnitTestMethodWithoutAssertRule,JUnitUnnecessarySetUpRule,JUnitUnnecessaryTearDownRule,JUnitUnnecessaryThrowsExceptionRule,LineLengthRule,LocaleSetDefaultRule,LoggerForDifferentClassRule,LoggerWithWrongModifiersRule,LoggingSwallowsStacktraceRule,LongLiteralWithLowerCaseLRule,MethodCountRule,MethodNameRule,MethodParameterTypeRequired,MethodReturnTypeRequiredRule,MethodSizeRule,MissingNewInThrowStatementRule,MissingOverrideAnnotationRule,MultipleLoggersRule,MultipleUnaryOperatorsRule,NestedBlockDepthRule,NestedForLoopRule,NestedSynchronizationRule,NoDefRule,NoJavaUtilDateRule,NonFinalPublicFieldRule,NonFinalSubclassOfSensitiveInterfaceRule,ObjectFinalizeRule,ObjectOverrideMisspelledMethodNameRule,PackageNameRule,ParameterCountRule,ParameterNameRule,ParameterReassignmentRule,PrintlnRule,PrintStackTraceRule,PropertyNameRule,PublicFinalizeMethodRule,PublicInstanceFieldRule,PublicMethodsBeforeNonPublicMethodsRule,RandomDoubleCoercedToZeroRule,RemoveAllOnSelfRule,ReturnFromFinallyBlockRule,ReturnNullFromCatchBlockRule,ReturnsNullInsteadOfEmptyArrayRule,ReturnsNullInsteadOfEmptyCollectionRule,SerializableClassMustDefineSerialVersionUIDRule,SerialPersistentFieldsRule,SerialVersionUIDRule,SimpleDateFormatMissingLocaleRule,SpaceAfterCatchRule,SpaceAfterClosingBraceRule,SpaceAfterCommaRule,SpaceAfterForRule,SpaceAfterIfRule,SpaceAfterOpeningBraceRule,SpaceAfterSemicolonRule,SpaceAfterSwitchRule,SpaceAfterWhileRule,SpaceAroundClosureArrowRule,SpaceAroundMapEntryColonRule,SpaceAroundOperatorRule,SpaceBeforeClosingBraceRule,SpaceBeforeOpeningBraceRule,SpockIgnoreRestUsedRule,StatelessClassRule,StatelessSingletonRule,StaticCalendarFieldRule,StaticConnectionRule,StaticDateFormatFieldRule,StaticFieldsBeforeInstanceFieldsRule,StaticMatcherFieldRule,StaticMethodsBeforeInstanceMethodsRule,StaticSimpleDateFormatFieldRule,SwallowThreadDeathRule,SynchronizedMethodRule,SynchronizedOnBoxedPrimitiveRule,SynchronizedOnGetClassRule,SynchronizedOnReentrantLockRule,SynchronizedOnStringRule,SynchronizedOnThisRule,SynchronizedReadObjectMethodRule,SystemErrPrintRule,SystemExitRule,SystemOutPrintRule,SystemRunFinalizersOnExitRule,TernaryCouldBeElvisRule,ThisReferenceEscapesConstructorRule,ThreadGroupRule,ThreadLocalNotStaticFinalRule,ThreadYieldRule,ThrowErrorRule,ThrowExceptionFromFinallyBlockRule,ThrowExceptionRule,ThrowNullPointerExceptionRule,ThrowRuntimeExceptionRule,ThrowThrowableRule,ToStringReturnsNullRule,TrailingCommaRule,UnnecessaryBigDecimalInstantiationRule,UnnecessaryBigIntegerInstantiationRule,UnnecessaryBooleanExpressionRule,UnnecessaryBooleanInstantiationRule,UnnecessaryCallForLastElementRule,UnnecessaryCallToSubstringRule,UnnecessaryCastRule,UnnecessaryCatchBlockRule,UnnecessaryCollectCallRule,UnnecessaryCollectionCallRule,UnnecessaryConstructorRule,UnnecessaryDefInFieldDeclarationRule,UnnecessaryDefInMethodDeclarationRule,UnnecessaryDefInVariableDeclarationRule,UnnecessaryDotClassRule,UnnecessaryDoubleInstantiationRule,UnnecessaryElseStatementRule,UnnecessaryFailRule,UnnecessaryFinalOnPrivateMethodRule,UnnecessaryFloatInstantiationRule,UnnecessaryGetterRule,UnnecessaryGStringRule,UnnecessaryIfStatementRule,UnnecessaryInstanceOfCheckRule,UnnecessaryInstantiationToGetClassRule,UnnecessaryIntegerInstantiationRule,UnnecessaryLongInstantiationRule,UnnecessaryModOneRule,UnnecessaryNullCheckBeforeInstanceOfRule,UnnecessaryNullCheckRule,UnnecessaryObjectReferencesRule,UnnecessaryOverridingMethodRule,UnnecessaryPackageReferenceRule,UnnecessaryParenthesesForMethodCallWithClosureRule,UnnecessaryPublicModifierRule,UnnecessaryReturnKeywordRule,UnnecessarySafeNavigationOperatorRule,UnnecessarySelfAssignmentRule,UnnecessarySemicolonRule,UnnecessarySetterRule,UnnecessaryStringInstantiationRule,UnnecessarySubstringRule,UnnecessaryTernaryExpressionRule,UnnecessaryToStringRule,UnnecessaryTransientModifierRule,UnsafeArrayDeclarationRule,UnsafeImplementationAsMapRule,UnusedArrayRule,UnusedMethodParameterRule,UnusedObjectRule,UnusedPrivateMethodParameterRule,UnusedVariableRule,UseAssertEqualsInsteadOfAssertTrueRule,UseAssertFalseInsteadOfNegationRule,UseAssertNullInsteadOfAssertEqualsRule,UseAssertSameInsteadOfAssertTrueRule,UseAssertTrueInsteadOfAssertEqualsRule,UseAssertTrueInsteadOfNegationRule,UseCollectManyRule,UseCollectNestedRule,UseOfNotifyMethodRule,VariableNameRule,VariableTypeRequiredRule,VectorIsObsoleteRule,VolatileArrayFieldRule,VolatileLongOrDoubleFieldRule,WaitOutsideOfWhileLoopRule,WhileStatementBracesRule
public abstract class AbstractAstVisitorRule extends AbstractRule
Abstract superclass for Rules that use a Groovy AST Visitor. Each subclass must set theastVisitorClassproperty or else define a new property with the same name, specifying the Class of theAstVisitorto applied to the specified source code.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringapplyToClassNamesThis rule is only applied to classes with names matching this value.static java.lang.StringCLOSURE_TEXTprotected static java.lang.StringDEFAULT_CONST_NAMEprotected static java.lang.StringDEFAULT_FIELD_NAMEprotected static java.lang.StringDEFAULT_TEST_CLASS_NAMESprotected static java.lang.StringDEFAULT_TEST_FILESprotected static java.lang.StringDEFAULT_VAR_NAMEprivate java.lang.StringdoNotApplyToClassNamesThis rule is NOT applied to classes with names matching this value.
-
Constructor Summary
Constructors Constructor Description AbstractAstVisitorRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyTo(SourceCode sourceCode, java.util.List<Violation> violations)Apply this rule to the specified source and return a list of violations (or an empty List)java.lang.StringgetApplyToClassNames()AstVisitorgetAstVisitor()protected java.lang.ClassgetAstVisitorClass()Each concrete subclass must either set this property or define its own property with the same namejava.lang.StringgetDoNotApplyToClassNames()voidsetApplyToClassNames(java.lang.String applyToClassNames)voidsetDoNotApplyToClassNames(java.lang.String doNotApplyToClassNames)protected booleanshouldApplyThisRuleTo(org.codehaus.groovy.ast.ClassNode classNode)Return true if this rule should be applied for the specified ClassNode, based on the configuration of this rule.-
Methods inherited from class org.codenarc.rule.AbstractRule
applyTo, createViolation, createViolation, createViolationForImport, createViolationForImport, getApplyToFileNames, getApplyToFilesMatching, getCompilerPhase, getDescription, getDoNotApplyToFileNames, getDoNotApplyToFilesMatching, getName, getPriority, getViolationMessage, isEnabled, isReady, setApplyToFileNames, setApplyToFilesMatching, setDescription, setDoNotApplyToFileNames, setDoNotApplyToFilesMatching, setEnabled, setName, setPriority, setViolationMessage, toString, validate
-
-
-
-
Field Detail
-
DEFAULT_CONST_NAME
protected static final java.lang.String DEFAULT_CONST_NAME
- See Also:
- Constant Field Values
-
DEFAULT_FIELD_NAME
protected static final java.lang.String DEFAULT_FIELD_NAME
- See Also:
- Constant Field Values
-
DEFAULT_VAR_NAME
protected static final java.lang.String DEFAULT_VAR_NAME
- See Also:
- Constant Field Values
-
DEFAULT_TEST_FILES
protected static final java.lang.String DEFAULT_TEST_FILES
- See Also:
- Constant Field Values
-
DEFAULT_TEST_CLASS_NAMES
protected static final java.lang.String DEFAULT_TEST_CLASS_NAMES
- See Also:
- Constant Field Values
-
CLOSURE_TEXT
public static final java.lang.String CLOSURE_TEXT
- See Also:
- Constant Field Values
-
applyToClassNames
private java.lang.String applyToClassNames
This rule is only applied to classes with names matching this value. The value may optionally be a comma-separated list of names, in which case one of the names must match. If a name includes a period ('.'), then it is assumed to specify a full package name, so the name (pattern) is matched against each fully-qualified class name. Otherwise it is matched only against the class name without a package. The name(s) may optionally include wildcard characters ('*' or '?').
-
doNotApplyToClassNames
private java.lang.String doNotApplyToClassNames
This rule is NOT applied to classes with names matching this value. The value may optionally be a comma-separated list of names, in which case any one of the names can match. If a name includes a period ('.'), then it is assumed to specify a full package name, so the name (pattern) is matched against each fully-qualified class name. Otherwise it is matched only against the class name without a package. The name(s) may optionally include wildcard characters ('*' or '?').
-
-
Method Detail
-
getAstVisitorClass
protected java.lang.Class getAstVisitorClass()
Each concrete subclass must either set this property or define its own property with the same name
-
getAstVisitor
public AstVisitor getAstVisitor()
-
applyTo
public void applyTo(SourceCode sourceCode, java.util.List<Violation> violations)
Description copied from class:AbstractRuleApply this rule to the specified source and return a list of violations (or an empty List)- Specified by:
applyToin classAbstractRule- Parameters:
sourceCode- - the source to apply this rule toviolations- - the List of violations to which new violations from this rule are to be added
-
shouldApplyThisRuleTo
protected boolean shouldApplyThisRuleTo(org.codehaus.groovy.ast.ClassNode classNode)
Return true if this rule should be applied for the specified ClassNode, based on the configuration of this rule.- Parameters:
classNode- - the ClassNode- Returns:
- true if this rule should be applied for the specified ClassNode
-
getApplyToClassNames
public java.lang.String getApplyToClassNames()
-
setApplyToClassNames
public void setApplyToClassNames(java.lang.String applyToClassNames)
-
getDoNotApplyToClassNames
public java.lang.String getDoNotApplyToClassNames()
-
setDoNotApplyToClassNames
public void setDoNotApplyToClassNames(java.lang.String doNotApplyToClassNames)
-
-