Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WidgetOfType |
|
| 1.0;1 |
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=126 | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.swtbot.swt.finder.matchers; | |
13 | ||
14 | import org.eclipse.swt.widgets.Widget; | |
15 | import org.hamcrest.Description; | |
16 | import org.hamcrest.Factory; | |
17 | import org.hamcrest.Matcher; | |
18 | ||
19 | /** | |
20 | * Tells if a particular widget is of a specified type. | |
21 | * | |
22 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
23 | * @version $Id$ | |
24 | * @since 2.0 | |
25 | */ | |
26 | public class WidgetOfType<T extends Widget> extends AbstractMatcher<T> { | |
27 | ||
28 | /** | |
29 | * The type of widget to match. | |
30 | */ | |
31 | private Class<? extends Widget> type; | |
32 | ||
33 | /** | |
34 | * Matches a widget that has the specified type | |
35 | * | |
36 | * @param type the type of the widget. | |
37 | */ | |
38 | 1307 | WidgetOfType(Class<? extends Widget> type) { |
39 | 1307 | this.type = type; |
40 | 1307 | } |
41 | ||
42 | protected boolean doMatch(Object obj) { | |
43 | 98694 | return type.isInstance(obj); |
44 | } | |
45 | ||
46 | public void describeTo(Description description) { | |
47 | 6214 | description.appendText("of type '").appendText(type.getSimpleName()).appendText("'"); //$NON-NLS-1$ //$NON-NLS-2$ |
48 | 6214 | } |
49 | ||
50 | /** | |
51 | * Matches a widget that has the specified type | |
52 | * | |
53 | * @param type the type of the widget. | |
54 | * @return a matcher. | |
55 | * @since 2.0 | |
56 | */ | |
57 | @Factory | |
58 | public static <T extends Widget> Matcher<T> widgetOfType(Class<T> type) { | |
59 | 1307 | return new WidgetOfType<T>(type); |
60 | } | |
61 | ||
62 | } |