Skip to content

Commit 44d9140

Browse files
committed
more exception details
1 parent 831bace commit 44d9140

File tree

1 file changed

+116
-107
lines changed

1 file changed

+116
-107
lines changed

src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java

Lines changed: 116 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ else if (browserVersion.isFirefox()) {
156156
new ClassConfiguration(klass, domClasses.toArray(new Class<?>[0]), isJsObject,
157157
className, extendedClassName);
158158

159-
process(classConfiguration, hostClassName, expectedBrowser);
159+
process(classConfiguration, expectedBrowser);
160160
return classConfiguration;
161161
}
162162

@@ -190,139 +190,148 @@ else if (browserVersion.isFirefox()) {
190190
className,
191191
extendedClassName);
192192

193-
process(classConfiguration, hostClassName, expectedBrowser);
193+
process(classConfiguration, expectedBrowser);
194194
return classConfiguration;
195195
}
196196
}
197197
return null;
198198
}
199199

200-
private static void process(final ClassConfiguration classConfiguration,
201-
final String hostClassName, final SupportedBrowser expectedBrowser) {
200+
private static void process(final ClassConfiguration classConfiguration, final SupportedBrowser expectedBrowser) {
202201
final Map<String, Method> allGetters = new ConcurrentHashMap<>();
203202
final Map<String, Method> allSetters = new ConcurrentHashMap<>();
204-
for (final Constructor<?> constructor : classConfiguration.getHostClass().getDeclaredConstructors()) {
205-
for (final Annotation annotation : constructor.getAnnotations()) {
206-
if (annotation instanceof JsxConstructor && isSupported(((JsxConstructor) annotation).value(),
207-
expectedBrowser)) {
208-
classConfiguration.setJSConstructor(constructor);
203+
204+
try {
205+
for (final Constructor<?> constructor : classConfiguration.getHostClass().getDeclaredConstructors()) {
206+
for (final Annotation annotation : constructor.getAnnotations()) {
207+
if (annotation instanceof JsxConstructor && isSupported(((JsxConstructor) annotation).value(),
208+
expectedBrowser)) {
209+
classConfiguration.setJSConstructor(constructor);
210+
}
209211
}
210212
}
211-
}
212-
for (final Method method : classConfiguration.getHostClass().getDeclaredMethods()) {
213-
for (final Annotation annotation : method.getAnnotations()) {
214-
if (annotation instanceof JsxGetter) {
215-
final JsxGetter jsxGetter = (JsxGetter) annotation;
216-
if (isSupported(jsxGetter.value(), expectedBrowser)) {
217-
String property;
218-
if (jsxGetter.propertyName().isEmpty()) {
219-
final int prefix = method.getName().startsWith("is") ? 2 : 3;
220-
property = method.getName().substring(prefix);
221-
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
222-
}
223-
else {
224-
property = jsxGetter.propertyName();
213+
for (final Method method : classConfiguration.getHostClass().getDeclaredMethods()) {
214+
for (final Annotation annotation : method.getAnnotations()) {
215+
if (annotation instanceof JsxGetter) {
216+
final JsxGetter jsxGetter = (JsxGetter) annotation;
217+
if (isSupported(jsxGetter.value(), expectedBrowser)) {
218+
String property;
219+
if (jsxGetter.propertyName().isEmpty()) {
220+
final int prefix = method.getName().startsWith("is") ? 2 : 3;
221+
property = method.getName().substring(prefix);
222+
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
223+
}
224+
else {
225+
property = jsxGetter.propertyName();
226+
}
227+
allGetters.put(property, method);
225228
}
226-
allGetters.put(property, method);
227229
}
228-
}
229-
else if (annotation instanceof JsxSetter) {
230-
final JsxSetter jsxSetter = (JsxSetter) annotation;
231-
if (isSupported(jsxSetter.value(), expectedBrowser)) {
232-
String property;
233-
if (jsxSetter.propertyName().isEmpty()) {
234-
property = method.getName().substring(3);
235-
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
230+
else if (annotation instanceof JsxSetter) {
231+
final JsxSetter jsxSetter = (JsxSetter) annotation;
232+
if (isSupported(jsxSetter.value(), expectedBrowser)) {
233+
String property;
234+
if (jsxSetter.propertyName().isEmpty()) {
235+
property = method.getName().substring(3);
236+
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
237+
}
238+
else {
239+
property = jsxSetter.propertyName();
240+
}
241+
allSetters.put(property, method);
236242
}
237-
else {
238-
property = jsxSetter.propertyName();
239-
}
240-
allSetters.put(property, method);
241243
}
242-
}
243-
if (annotation instanceof JsxSymbol) {
244-
final JsxSymbol jsxSymbol = (JsxSymbol) annotation;
245-
if (isSupported(jsxSymbol.value(), expectedBrowser)) {
246-
final String symbolKeyName;
247-
if (jsxSymbol.symbolName().isEmpty()) {
248-
symbolKeyName = method.getName();
249-
}
250-
else {
251-
symbolKeyName = jsxSymbol.symbolName();
252-
}
253-
254-
final SymbolKey symbolKey;
255-
if ("iterator".equalsIgnoreCase(symbolKeyName)) {
256-
symbolKey = SymbolKey.ITERATOR;
257-
}
258-
else {
259-
throw new RuntimeException("Invalid JsxSymbol annotation; unsupported '"
260-
+ symbolKeyName + "' symbol name.");
244+
if (annotation instanceof JsxSymbol) {
245+
final JsxSymbol jsxSymbol = (JsxSymbol) annotation;
246+
if (isSupported(jsxSymbol.value(), expectedBrowser)) {
247+
final String symbolKeyName;
248+
if (jsxSymbol.symbolName().isEmpty()) {
249+
symbolKeyName = method.getName();
250+
}
251+
else {
252+
symbolKeyName = jsxSymbol.symbolName();
253+
}
254+
255+
final SymbolKey symbolKey;
256+
if ("iterator".equalsIgnoreCase(symbolKeyName)) {
257+
symbolKey = SymbolKey.ITERATOR;
258+
}
259+
else {
260+
throw new RuntimeException("Invalid JsxSymbol annotation; unsupported '"
261+
+ symbolKeyName + "' symbol name.");
262+
}
263+
classConfiguration.addSymbol(symbolKey, method);
261264
}
262-
classConfiguration.addSymbol(symbolKey, method);
263265
}
264-
}
265-
else if (annotation instanceof JsxFunction) {
266-
final JsxFunction jsxFunction = (JsxFunction) annotation;
267-
if (isSupported(jsxFunction.value(), expectedBrowser)) {
268-
final String name;
269-
if (jsxFunction.functionName().isEmpty()) {
270-
name = method.getName();
271-
}
272-
else {
273-
name = jsxFunction.functionName();
266+
else if (annotation instanceof JsxFunction) {
267+
final JsxFunction jsxFunction = (JsxFunction) annotation;
268+
if (isSupported(jsxFunction.value(), expectedBrowser)) {
269+
final String name;
270+
if (jsxFunction.functionName().isEmpty()) {
271+
name = method.getName();
272+
}
273+
else {
274+
name = jsxFunction.functionName();
275+
}
276+
classConfiguration.addFunction(name, method);
274277
}
275-
classConfiguration.addFunction(name, method);
276278
}
277-
}
278-
else if (annotation instanceof JsxStaticGetter) {
279-
final JsxStaticGetter jsxStaticGetter = (JsxStaticGetter) annotation;
280-
if (isSupported(jsxStaticGetter.value(), expectedBrowser)) {
281-
final int prefix = method.getName().startsWith("is") ? 2 : 3;
282-
String property = method.getName().substring(prefix);
283-
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
284-
classConfiguration.addStaticProperty(property, method, null);
285-
}
286-
}
287-
else if (annotation instanceof JsxStaticFunction) {
288-
final JsxStaticFunction jsxStaticFunction = (JsxStaticFunction) annotation;
289-
if (isSupported(jsxStaticFunction.value(), expectedBrowser)) {
290-
final String name;
291-
if (jsxStaticFunction.functionName().isEmpty()) {
292-
name = method.getName();
279+
else if (annotation instanceof JsxStaticGetter) {
280+
final JsxStaticGetter jsxStaticGetter = (JsxStaticGetter) annotation;
281+
if (isSupported(jsxStaticGetter.value(), expectedBrowser)) {
282+
final int prefix = method.getName().startsWith("is") ? 2 : 3;
283+
String property = method.getName().substring(prefix);
284+
property = Character.toLowerCase(property.charAt(0)) + property.substring(1);
285+
classConfiguration.addStaticProperty(property, method, null);
293286
}
294-
else {
295-
name = jsxStaticFunction.functionName();
287+
}
288+
else if (annotation instanceof JsxStaticFunction) {
289+
final JsxStaticFunction jsxStaticFunction = (JsxStaticFunction) annotation;
290+
if (isSupported(jsxStaticFunction.value(), expectedBrowser)) {
291+
final String name;
292+
if (jsxStaticFunction.functionName().isEmpty()) {
293+
name = method.getName();
294+
}
295+
else {
296+
name = jsxStaticFunction.functionName();
297+
}
298+
classConfiguration.addStaticFunction(name, method);
296299
}
297-
classConfiguration.addStaticFunction(name, method);
298300
}
299-
}
300-
else if (annotation instanceof JsxConstructor && isSupported(((JsxConstructor) annotation).value(),
301-
expectedBrowser)) {
302-
classConfiguration.setJSConstructor(method);
301+
else if (annotation instanceof JsxConstructor && isSupported(((JsxConstructor) annotation).value(),
302+
expectedBrowser)) {
303+
classConfiguration.setJSConstructor(method);
304+
}
303305
}
304306
}
305-
}
306-
for (final Entry<String, Method> getterEntry : allGetters.entrySet()) {
307-
final String property = getterEntry.getKey();
308-
classConfiguration.addProperty(property, getterEntry.getValue(), allSetters.get(property));
309-
}
310307

311-
// JsxConstant
312-
for (final Field field : classConfiguration.getHostClass().getDeclaredFields()) {
313-
final JsxConstant jsxConstant = field.getAnnotation(JsxConstant.class);
314-
if (jsxConstant != null && isSupported(jsxConstant.value(), expectedBrowser)) {
315-
try {
316-
classConfiguration.addConstant(field.getName(), field.get(null));
317-
}
318-
catch (final IllegalAccessException e) {
319-
throw Context.reportRuntimeError(
320-
"Cannot get field '" + field.getName()
321-
+ "' for type: " + classConfiguration.getHostClass().getName()
322-
+ "reason: " + e.getMessage());
308+
for (final Entry<String, Method> getterEntry : allGetters.entrySet()) {
309+
final String property = getterEntry.getKey();
310+
classConfiguration.addProperty(property, getterEntry.getValue(), allSetters.get(property));
311+
}
312+
313+
// JsxConstant
314+
for (final Field field : classConfiguration.getHostClass().getDeclaredFields()) {
315+
final JsxConstant jsxConstant = field.getAnnotation(JsxConstant.class);
316+
if (jsxConstant != null && isSupported(jsxConstant.value(), expectedBrowser)) {
317+
try {
318+
classConfiguration.addConstant(field.getName(), field.get(null));
319+
}
320+
catch (final IllegalAccessException e) {
321+
throw Context.reportRuntimeError(
322+
"Cannot get field '" + field.getName()
323+
+ "' for type: " + classConfiguration.getHostClass().getName()
324+
+ "reason: " + e.getMessage());
325+
}
323326
}
324327
}
325328
}
329+
catch (final Throwable e) {
330+
throw new RuntimeException(
331+
"Processing classConfiguration for class "
332+
+ classConfiguration.getHostClassSimpleName() + "failed."
333+
+ " Reason: " + e, e);
334+
}
326335
}
327336

328337
private static boolean isSupported(final SupportedBrowser[] browsers, final SupportedBrowser expectedBrowser) {

0 commit comments

Comments
 (0)