1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2010 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2025 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials are made available under the
5
5
* terms of the Eclipse Public License 2.0 which is available at
15
15
import java .util .HashMap ;
16
16
import java .util .Map ;
17
17
18
- import org .eclipse .core .runtime .Assert ;
19
18
import org .eclipse .jface .resource .ImageDescriptor ;
20
19
21
20
import org .eclipse .gef .Tool ;
@@ -29,7 +28,7 @@ public abstract class ToolEntry extends PaletteEntry {
29
28
public static final Object PALETTE_TYPE_TOOL = "$Palette Tool" ;//$NON-NLS-1$
30
29
31
30
private Map <Object , Object > map ;
32
- private Class toolClass ;
31
+ private Class <? extends Tool > toolClass ;
33
32
34
33
/**
35
34
* Creates a new ToolEntry. Any parameter can be <code>null</code>.
@@ -55,7 +54,7 @@ public ToolEntry(String label, String shortDesc, ImageDescriptor iconSmall, Imag
55
54
* @since 3.1
56
55
*/
57
56
public ToolEntry (String label , String description , ImageDescriptor iconSmall , ImageDescriptor iconLarge ,
58
- Class tool ) {
57
+ Class <? extends Tool > tool ) {
59
58
super (label , description , iconSmall , iconLarge , PALETTE_TYPE_TOOL );
60
59
setToolClass (tool );
61
60
}
@@ -74,10 +73,8 @@ public Tool createTool() {
74
73
}
75
74
Tool tool ;
76
75
try {
77
- tool = (Tool ) toolClass .newInstance ();
78
- } catch (IllegalAccessException iae ) {
79
- return null ;
80
- } catch (InstantiationException ie ) {
76
+ tool = toolClass .getDeclaredConstructor ().newInstance ();
77
+ } catch (ReflectiveOperationException e ) {
81
78
return null ;
82
79
}
83
80
tool .setProperties (getToolProperties ());
@@ -115,10 +112,7 @@ public Object getToolProperty(Object key) {
115
112
* @param toolClass the type of tool to be created by this entry
116
113
* @since 3.1
117
114
*/
118
- public void setToolClass (Class toolClass ) {
119
- if (toolClass != null ) {
120
- Assert .isTrue (Tool .class .isAssignableFrom (toolClass ));
121
- }
115
+ public void setToolClass (Class <? extends Tool > toolClass ) {
122
116
this .toolClass = toolClass ;
123
117
}
124
118
0 commit comments