| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IllegalClassReferenceRule |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Copyright 2011 the original author or authors. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.codenarc.rule.generic | |
| 17 | ||
| 18 | import org.codenarc.rule.AbstractAstVisitorRule | |
| 19 | import org.codenarc.rule.AstVisitor | |
| 20 | import org.codenarc.rule.ClassReferenceAstVisitor | |
| 21 | ||
| 22 | /** | |
| 23 | * Checks for reference to any of the named classes. | |
| 24 | * <p/> | |
| 25 | * The <code>classNames</code> property specifies the comma-separated list of (fully-qualified) class names to check for. | |
| 26 | * The class name(s) may optionally include wildcard characters ('*' or '?'). Note that the '*' wildcard | |
| 27 | * matches any sequence of zero or more characters in the class/package name, e.g. 'a.*.MyClass' matches | |
| 28 | * 'a.b.MyClass' as well as 'a.b.c.d.MyClass'. If <code>classNames</code> is null or empty, do nothing. | |
| 29 | * | |
| 30 | * Known limitation: Does not catch references as Anonymous Inner class: def x = new org.bad.Handler() { .. } | |
| 31 | * | |
| 32 | * @author Chris Mair | |
| 33 | */ | |
| 34 | 53 | class IllegalClassReferenceRule extends AbstractAstVisitorRule { |
| 35 | String name = 'IllegalClassReference' | |
| 36 | int priority = 2 | |
| 37 | String classNames = null | |
| 38 | ||
| 39 | @Override | |
| 40 | AstVisitor getAstVisitor() { | |
| 41 | 42 | new ClassReferenceAstVisitor(classNames) |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | boolean isReady() { | |
| 46 | 81 | classNames |
| 47 | } | |
| 48 | } |