[Buix-commits] r206 - trunk/jaxx/src/main/java/jaxx/tags
Author: tchemit Date: 2008-02-12 14:32:02 +0000 (Tue, 12 Feb 2008) New Revision: 206 Modified: trunk/jaxx/src/main/java/jaxx/tags/DefaultObjectHandler.java Log: formattage code Modified: trunk/jaxx/src/main/java/jaxx/tags/DefaultObjectHandler.java =================================================================== --- trunk/jaxx/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-02-12 13:52:27 UTC (rev 205) +++ trunk/jaxx/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-02-12 14:32:02 UTC (rev 206) @@ -163,8 +163,7 @@ public JAXXBeanInfo getJAXXBeanInfo() { try { init(); - } - catch (IntrospectionException e) { + } catch (IntrospectionException e) { throw new RuntimeException(e); } return jaxxBeanInfo; @@ -197,16 +196,15 @@ public ClassDescriptor getPropertyType(CompiledObject object, String propertyName, JAXXCompiler compiler) { try { init(); - } - catch (IntrospectionException e) { + } catch (IntrospectionException e) { throw new RuntimeException(e); } JAXXPropertyDescriptor property = properties.get(propertyName); - if (property != null) + if (property != null) { return property.getPropertyType(); - else - throw new UnsupportedAttributeException("property '" + propertyName + "' not found in " + object); + } + throw new UnsupportedAttributeException("property '" + propertyName + "' not found in " + object); } @@ -223,34 +221,34 @@ public boolean isMemberBound(String name) throws UnsupportedAttributeException { try { init(); - } - catch (IntrospectionException e) { + } catch (IntrospectionException e) { throw new RuntimeException(e); } - if (eventInfos != null && eventInfos.containsKey(name)) + if (eventInfos != null && eventInfos.containsKey(name)) { return true; + } - if (name.equals("getClass")) + if (name.equals("getClass")) { return false; + } String propertyName = null; - if (name.startsWith("get")) + if (name.startsWith("get")) { propertyName = Introspector.decapitalize(name.substring("get".length())); - else if (name.startsWith("is")) + } else if (name.startsWith("is")) { propertyName = Introspector.decapitalize(name.substring("is".length())); + } JAXXPropertyDescriptor property = propertyName != null ? properties.get(propertyName) : null; if (property != null) { return property.isBound(); - } else { // check to see if it is a field - try { - FieldDescriptor field = getBeanClass().getFieldDescriptor(name); - return Modifier.isFinal(field.getModifiers()); // final fields might as well be considered bound -- they can't be modified anyway - } - catch (NoSuchFieldException e) { - throw new UnsupportedAttributeException("cannot find property '" + name + "' of " + getBeanClass()); - } } + try { + FieldDescriptor field = getBeanClass().getFieldDescriptor(name); + return Modifier.isFinal(field.getModifiers()); // final fields might as well be considered bound -- they can't be modified anyway + } catch (NoSuchFieldException e) { + throw new UnsupportedAttributeException("cannot find property '" + name + "' of " + getBeanClass()); + } } @@ -267,10 +265,7 @@ */ public String[] getMemberDependencies(String memberName) { ProxyEventInfo eventInfo = eventInfos != null ? eventInfos.get(memberName) : null; - if (eventInfo != null) - return new String[]{eventInfo.modelName}; - else - return null; + return eventInfo == null ? null : new String[]{eventInfo.modelName}; } @@ -292,8 +287,9 @@ * @return Java code snippet which causes the listener to be added to the object */ public String getAddMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) { - if (memberName.equals("getClass")) + if ("getClass".equals(memberName)) { return null; + } ProxyEventInfo eventInfo = eventInfos != null ? eventInfos.get(memberName) : null; if (eventInfo != null) { // a "proxied" event is one that doesn't fire PropertyChangeEvent, so we need to convert its native event type into PropertyChangeEvents @@ -308,32 +304,32 @@ } } ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass); - if (!methodExists) + if (!methodExists) { compiler.getJavaFile().addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName, new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null, propertyChangeListenerCode + ".propertyChange(null);")); + } String code = objectCode + (eventInfo.modelName != null ? ".get" + JAXXCompiler.capitalize(eventInfo.modelName) + "()" : ""); result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator()); result.append(code).append('.').append(eventInfo.addMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));\n"); - if (eventInfo.modelName != null) + if (eventInfo.modelName != null) { result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + JAXXCompiler.capitalize(eventInfo.modelName), "jaxx.runtime.Util.getDataBindingUpdateListener(this , \"" + dataBinding + "\")", compiler)); + } return result.toString(); } else { String propertyName = null; if (memberName.startsWith("get")) { propertyName = Introspector.decapitalize(memberName.substring("get".length())); - } - else if (memberName.startsWith("is")) { + } else if (memberName.startsWith("is")) { propertyName = Introspector.decapitalize(memberName.substring("is".length())); } else { try { getBeanClass().getFieldDescriptor(memberName); propertyName = memberName; - } - catch (NoSuchFieldException e) { + } catch (NoSuchFieldException e) { // ignore ? } } @@ -343,20 +339,20 @@ getBeanClass().getMethodDescriptor("addPropertyChangeListener", new ClassDescriptor[]{ClassDescriptorLoader.getClassDescriptor(String.class), ClassDescriptorLoader.getClassDescriptor(PropertyChangeListener.class)}); return objectCode + ".addPropertyChangeListener(\"" + propertyName + "\", " + propertyChangeListenerCode + ");\n"; - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { // no property-specific method, use general one return objectCode + ".addPropertyChangeListener(" + propertyChangeListenerCode + ");\n"; } - } else - return null; + } + return null; } } public String getRemoveMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) { - if (memberName.equals("getClass")) + if ("getClass".equals(memberName)) { return null; + } ProxyEventInfo eventInfo = eventInfos != null ? eventInfos.get(memberName) : null; if (eventInfo != null) { // a "proxied" event is one that doesn't fire PropertyChangeEvent, so we need to convert its native event type into PropertyChangeEvents @@ -371,10 +367,11 @@ } } ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass); - if (!methodExists) + if (!methodExists) { compiler.getJavaFile().addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName, new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null, propertyChangeListenerCode + ".propertyChange(null);")); + } try { String modelMemberName = eventInfo.modelName != null ? "get" + JAXXCompiler.capitalize(eventInfo.modelName) : null; String modelClassName = modelMemberName != null ? getBeanClass().getMethodDescriptor(modelMemberName, new ClassDescriptor[0]).getReturnType().getName() : JAXXCompiler.getCanonicalName(getBeanClass()); @@ -394,16 +391,13 @@ String propertyName = null; if (memberName.startsWith("get")) { propertyName = Introspector.decapitalize(memberName.substring("get".length())); - } - else if (memberName.startsWith("is")) { + } else if (memberName.startsWith("is")) { propertyName = Introspector.decapitalize(memberName.substring("is".length())); - } - else { + } else { try { getBeanClass().getFieldDescriptor(memberName); propertyName = memberName; - } - catch (NoSuchFieldException e) { + } catch (NoSuchFieldException e) { // ignore ? } } @@ -413,13 +407,12 @@ getBeanClass().getMethodDescriptor("removePropertyChangeListener", new ClassDescriptor[]{ClassDescriptorLoader.getClassDescriptor(String.class), ClassDescriptorLoader.getClassDescriptor(PropertyChangeListener.class)}); return objectCode + ".removePropertyChangeListener(\"" + propertyName + "\", " + propertyChangeListenerCode + ");\n"; - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { // no property-specific method, use general one return objectCode + ".removePropertyChangeListener(" + propertyChangeListenerCode + ");\n"; } - } else - return null; + } + return null; } } @@ -485,8 +478,7 @@ String modelName, String addMethod, String removeMethod) { try { addProxyEventInfo(memberName, ClassDescriptorLoader.getClassDescriptor(listenerClass.getName()), modelName, addMethod, removeMethod); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } @@ -543,8 +535,7 @@ public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { try { init(); - } - catch (IntrospectionException e) { + } catch (IntrospectionException e) { throw new RuntimeException(e); } CompiledObject object = objectMap.get(tag); @@ -646,10 +637,8 @@ String value = attribute.getValue(); if (name.equals("constraints") || isEventHandlerName(name)) { compiler.preprocessScript(value); // adds dependencies as a side effect - } - else if (name.equals("constructorParams")) { - String[] params = value.split("\\s*,\\s*"); - for (String param : params) { + } else if (name.equals("constructorParams")) { + for (String param : value.split("\\s*,\\s*")) { compiler.preprocessScript(param); } } else if (value.startsWith("{") && value.endsWith("}")) { @@ -688,8 +677,7 @@ value+=";"; } addEventHandler(object, Introspector.decapitalize(name.substring(2)), value, compiler); - } - else { + } else { setAttribute(object, name, value, true, compiler); } } @@ -722,8 +710,9 @@ * @return the attribute's priority */ protected int getAttributeOrdering(Attr attr) { - if (attr.getName().equals("displayedMnemonicIndex") || attr.getName().equals("displayedMnemonic") || attr.getName().equals("mnemonic")) + if (attr.getName().equals("displayedMnemonicIndex") || attr.getName().equals("displayedMnemonic") || attr.getName().equals("mnemonic")) { return 1; + } return 0; } @@ -733,23 +722,19 @@ String binding = compiler.processDataBindings(stringValue, type); if (binding != null) { return ""; - } else { // no bindings, convert from string - try { - Class typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null; - Object value = convertFromString(propertyName, stringValue, typeClass); - return getSetPropertyCode(object.getJavaCode(), propertyName, TypeManager.getJavaCode(value), compiler); - } - catch (NumberFormatException e) { - compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); - } - catch (IllegalArgumentException e) { - compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); - } - catch (ClassNotFoundException e) { - compiler.reportError("could not find class " + type.getName()); - } - return ""; } + try { + Class typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null; + Object value = convertFromString(propertyName, stringValue, typeClass); + return getSetPropertyCode(object.getJavaCode(), propertyName, TypeManager.getJavaCode(value), compiler); + } catch (NumberFormatException e) { + compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); + } catch (IllegalArgumentException e) { + compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); + } catch (ClassNotFoundException e) { + compiler.reportError("could not find class " + type.getName()); + } + return ""; } @@ -802,19 +787,15 @@ Class typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null; Object value = convertFromString(propertyName, stringValue, typeClass); setProperty(object, propertyName, value, compiler); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName()); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { compiler.reportError("could not find class " + type.getName()); } } - } - catch (UnsupportedAttributeException e) { + } catch (UnsupportedAttributeException e) { compiler.reportError("class " + object.getObjectClass().getName() + " does not support attribute '" + propertyName + "'"); } } @@ -857,16 +838,18 @@ } currentObject.setParent(object); String styleClass = object.getStyleClass(); - if (styleClass == null) + if (styleClass == null) { styleClass = descriptor.getStyleClass(); + } child.setStyleClass(styleClass); Stylesheet mergedStylesheet = overrides; Stylesheet childOverrides = jaxxObjectDescriptor.getStylesheet(); if (childOverrides != null) { - if (mergedStylesheet == null) + if (mergedStylesheet == null) { mergedStylesheet = childOverrides; - else + } else { mergedStylesheet.add(childOverrides.getRules()); + } } TagManager.getTagHandler(objectClass).applyStylesheets(child, compiler, mergedStylesheet, isRoot); object.appendInitializationCode(child.getInitializationCode(compiler)); @@ -899,13 +882,13 @@ break; } } - if (listenerMethod == null) + if (listenerMethod == null) { throw new RuntimeException("expected to find method '" + name + "' in JAXXEventSetDescriptor.getListenerMethods()"); + } try { value = compiler.preprocessScript(value); object.addEventHandler(name, JAXXEventSetDescriptor.getAddListenerMethod(), listenerMethod, value, compiler); - } - catch (CompilerException e) { + } catch (CompilerException e) { compiler.reportError("While parsing event handler for '" + name + "': " + e.getMessage()); } } else @@ -926,19 +909,18 @@ public String getGetPropertyCode(String javaCode, String name, JAXXCompiler compiler) { try { init(); - } - catch (IntrospectionException e) { + } catch (IntrospectionException e) { throw new RuntimeException(e); } JAXXPropertyDescriptor property = properties.get(name); if (property != null) { - if (property.getReadMethodDescriptor() != null) + if (property.getReadMethodDescriptor() != null) { return javaCode + '.' + property.getReadMethodDescriptor().getName() + "()"; - else - throw new UnsupportedAttributeException("property '" + name + "' of " + getBeanClass().getName() + " has no read method"); - } else - throw new UnsupportedAttributeException("property '" + name + "' could not be found in class " + getBeanClass().getName()); + } + throw new UnsupportedAttributeException("property '" + name + "' of " + getBeanClass().getName() + " has no read method"); + } + throw new UnsupportedAttributeException("property '" + name + "' could not be found in class " + getBeanClass().getName()); } @@ -956,12 +938,12 @@ public String getSetPropertyCode(String javaCode, String name, String valueCode, JAXXCompiler compiler) { JAXXPropertyDescriptor property = properties.get(name); if (property != null) { - if (property.getWriteMethodDescriptor() != null) + if (property.getWriteMethodDescriptor() != null) { return javaCode + '.' + property.getWriteMethodDescriptor().getName() + '(' + valueCode + ");"; - else - throw new UnsupportedAttributeException("property '" + name + "' of " + getBeanClass().getName() + " is read-only"); - } else - throw new UnsupportedAttributeException("property '" + name + "' could not be found in class " + getBeanClass().getName()); + } + throw new UnsupportedAttributeException("property '" + name + "' of " + getBeanClass().getName() + " is read-only"); + } + throw new UnsupportedAttributeException("property '" + name + "' could not be found in class " + getBeanClass().getName()); } @@ -1009,14 +991,16 @@ Object[] values = (Object[]) property.getValue("enumerationValues"); if (values != null) { for (int j = 0; j < values.length - 2; j += 3) { - if (((String) values[j]).toLowerCase().equals(lowercaseValue)) + if (((String) values[j]).toLowerCase().equals(lowercaseValue)) { return (Integer) values[j + 1]; + } } StringBuffer message = new StringBuffer("value of '" + key + "' must be one of: ["); for (int j = 0; j < values.length - 2; j += 3) { - if (j != 0) + if (j != 0) { message.append(", "); + } message.append(((String) values[j]).toLowerCase()); } message.append("] (found '").append(value).append("')"); @@ -1039,17 +1023,17 @@ * @see #constantValue */ protected Object convertFromString(String key, String value, Class type) { - if (type == null || type == Object.class) + if (type == null || type == Object.class) { return value; + } try { return TypeManager.convertFromString(value, type); - } - catch (NumberFormatException e) { - if (type == int.class || type == Integer.class) + } catch (NumberFormatException e) { + if (type == int.class || type == Integer.class) { return constantValue(key, value); - else - throw e; + } + throw e; } } @@ -1093,11 +1077,11 @@ if (nodeType == Node.ELEMENT_NODE) { Element child = (Element) node; compileChildTagSecondPass(child, compiler); - } else - if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { + } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = ((Text) node).getData().trim(); - if (text.length() > 0) + if (text.length() > 0) { compiler.reportError("tag '" + tag.getLocalName() + "' may not contain text ('" + ((Text) node).getData().trim() + "')"); + } } } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org