|
Groovy example source code file (QDoxCategory.groovy)
The Groovy QDoxCategory.groovy source code
/*
* Copyright 2003-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.tools.stubgenerator
import com.thoughtworks.qdox.model.JavaClass
import com.thoughtworks.qdox.model.JavaMethod
/**
* Category methods for the QDox library to simplify the writing assertions to check the generated stubs.
*
* @author Guillaume Laforge
*/
class QDoxCategory {
/**
* Given <code>JavaClass[] array,
* like provided by the <code>getClasses() method (or
*
* @param self an array of <code>JavaClass[]
* @param className the name of the class to find
* @return a <code>JavaClass
*/
static JavaClass getAt(JavaClass[] self, String className) {
def clazz = self.find { JavaClass jc -> jc.fullyQualifiedName == className }
assert clazz, "No stub class found for name $className, among ${self.collect { it.fullyQualifiedName }}"
return clazz
}
/**
* Find one or several methods from a <code>JavaMethod[] array.
*
* Usage:
*
* <pre>
* classes['com.bar.Rectangle'].methods['area']
* </code>
*
* @param self an array of <code>JavaMethod
* @param methodName the name of the method(s) to find
* @return a single <code>JavaMethod if only one of that name exists, or a JavaMethod[] array
*/
static getAt(JavaMethod[] self, String methodName) {
def methods = self.findAll { JavaMethod jc -> jc.name == methodName }
if (methods.size() == 1)
return methods[0]
else
return methods
}
/**
* Get a normalized string of the signature of a method, including its modifiers.
* <br>* Usage: * * <pre>
* // an area() method
* assert classes['Rectangle'].methods['area'].signature == "public double area()"
* // a constructor
* assert classes['Rectangle'].methods['Rectangle'].signature == "public Rectangle(double x, double y)"
* </code>
*
* @param self a method
* @return a normalized strings representing the signature
*/
static String getSignature(JavaMethod self) {
self.getDeclarationSignature(true)
}
/**
* Lists the interfaces implemented by a class.
* <br> |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.