| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ClassUtils |
|
| 3.3333333333333335;3.333 |
| 1 | /******************************************************************************* | |
| 2 | * Copyright (c) 2008 Ketan Padegaonkar and others. | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Ketan Padegaonkar - initial API and implementation | |
| 10 | * Ketan Padegaonkar - http://swtbot.org/bugzilla/show_bug.cgi?id=88 | |
| 11 | *******************************************************************************/ | |
| 12 | package org.eclipse.swtbot.swt.finder.utils; | |
| 13 | ||
| 14 | /** | |
| 15 | * A utility for class based work. | |
| 16 | * | |
| 17 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 18 | * @version $Id$ | |
| 19 | */ | |
| 20 | 0 | public abstract class ClassUtils { |
| 21 | ||
| 22 | /** | |
| 23 | * Gets the simple class name of an object or an empty string if not valid. | |
| 24 | * | |
| 25 | * @param object the object | |
| 26 | * @return the classname of the object or an empty string. | |
| 27 | */ | |
| 28 | public static String simpleClassName(Object object) { | |
| 29 | 583 | return object == null ? "" : ClassUtils.simpleClassName(object.getClass()); //$NON-NLS-1$ |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * Gets the simple class name for the given class. | |
| 34 | * | |
| 35 | * @param clasz the class | |
| 36 | * @return the classname of the clasz | |
| 37 | */ | |
| 38 | public static String simpleClassName(Class<?> clasz) { | |
| 39 | 586 | if (clasz == null) |
| 40 | 1 | return ""; //$NON-NLS-1$ |
| 41 | 585 | if (clasz.isMemberClass()) |
| 42 | 2 | return clasz.getDeclaringClass().getSimpleName() + "$" + clasz.getSimpleName(); //$NON-NLS-1$ |
| 43 | 583 | return clasz.getSimpleName(); |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * Gets the simple class name for the given class. | |
| 48 | * | |
| 49 | * @param claszName the class | |
| 50 | * @return the classname of the clasz | |
| 51 | * @since 2.0 | |
| 52 | */ | |
| 53 | public static String simpleClassName(String claszName) { | |
| 54 | 3 | if (StringUtils.isEmptyOrNull(claszName)) |
| 55 | 1 | return ""; //$NON-NLS-1$ |
| 56 | 2 | return claszName.substring(claszName.lastIndexOf(".") + 1); //$NON-NLS-1$ |
| 57 | } | |
| 58 | } |