You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jh...@apache.org on 2014/07/04 09:17:58 UTC
[16/17] checkstyle
http://git-wip-us.apache.org/repos/asf/ant/blob/1b76f1b6/src/main/org/apache/tools/ant/IntrospectionHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java
index e8a41ab..a1e6874 100644
--- a/src/main/org/apache/tools/ant/IntrospectionHelper.java
+++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java
@@ -75,9 +75,9 @@ public final class IntrospectionHelper {
// Set up PRIMITIVE_TYPE_MAP
static {
- Class<?>[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
+ final Class<?>[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
- Class<?>[] wrappers = {Boolean.class, Byte.class, Character.class, Short.class,
+ final Class<?>[] wrappers = {Boolean.class, Byte.class, Character.class, Short.class,
Integer.class, Long.class, Float.class, Double.class};
for (int i = 0; i < primitives.length; i++) {
PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
@@ -178,13 +178,13 @@ public final class IntrospectionHelper {
*/
private IntrospectionHelper(final Class<?> bean) {
this.bean = bean;
- Method[] methods = bean.getMethods();
+ final Method[] methods = bean.getMethods();
Method addTextMethod = null;
for (int i = 0; i < methods.length; i++) {
final Method m = methods[i];
final String name = m.getName();
- Class<?> returnType = m.getReturnType();
- Class<?>[] args = m.getParameterTypes();
+ final Class<?> returnType = m.getReturnType();
+ final Class<?>[] args = m.getParameterTypes();
// check of add[Configured](Class) pattern
if (args.length == 1 && java.lang.Void.TYPE.equals(returnType)
@@ -207,8 +207,8 @@ public final class IntrospectionHelper {
addTextMethod = methods[i];
} else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType)
&& args.length == 1 && !args[0].isArray()) {
- String propName = getPropertyName(name, "set");
- AttributeSetter as = (AttributeSetter) attributeSetters.get(propName);
+ final String propName = getPropertyName(name, "set");
+ AttributeSetter as = attributeSetters.get(propName);
if (as != null) {
if (java.lang.String.class.equals(args[0])) {
/*
@@ -243,7 +243,7 @@ public final class IntrospectionHelper {
} else if (name.startsWith("create") && !returnType.isArray()
&& !returnType.isPrimitive() && args.length == 0) {
- String propName = getPropertyName(name, "create");
+ final String propName = getPropertyName(name, "create");
// Check if a create of this property is already present
// add takes preference over create for CB purposes
if (nestedCreators.get(propName) == null) {
@@ -258,14 +258,14 @@ public final class IntrospectionHelper {
Constructor<?> constructor = null;
try {
constructor = args[0].getConstructor();
- } catch (NoSuchMethodException ex) {
+ } catch (final NoSuchMethodException ex) {
constructor = args[0].getConstructor(Project.class);
}
- String propName = getPropertyName(name, "addConfigured");
+ final String propName = getPropertyName(name, "addConfigured");
nestedTypes.put(propName, args[0]);
nestedCreators.put(propName, new AddNestedCreator(m,
constructor, AddNestedCreator.ADD_CONFIGURED));
- } catch (NoSuchMethodException nse) {
+ } catch (final NoSuchMethodException nse) {
// ignore
}
} else if (name.startsWith("add")
@@ -276,10 +276,10 @@ public final class IntrospectionHelper {
Constructor<?> constructor = null;
try {
constructor = args[0].getConstructor();
- } catch (NoSuchMethodException ex) {
+ } catch (final NoSuchMethodException ex) {
constructor = args[0].getConstructor(Project.class);
}
- String propName = getPropertyName(name, "add");
+ final String propName = getPropertyName(name, "add");
if (nestedTypes.get(propName) != null) {
/*
* Ignore this method as there is an addConfigured
@@ -291,7 +291,7 @@ public final class IntrospectionHelper {
nestedTypes.put(propName, args[0]);
nestedCreators.put(propName, new AddNestedCreator(m,
constructor, AddNestedCreator.ADD));
- } catch (NoSuchMethodException nse) {
+ } catch (final NoSuchMethodException nse) {
// ignore
}
}
@@ -307,7 +307,7 @@ public final class IntrospectionHelper {
* @param type the type of the set method's parameter
* @return true if the given set method is to be hidden.
*/
- private boolean isHiddenSetMethod(String name, Class<?> type) {
+ private boolean isHiddenSetMethod(final String name, final Class<?> type) {
if ("setLocation".equals(name) && org.apache.tools.ant.Location.class.equals(type)) {
return true;
}
@@ -326,7 +326,7 @@ public final class IntrospectionHelper {
*
* @return a helper for the specified class
*/
- public static synchronized IntrospectionHelper getHelper(Class<?> c) {
+ public static synchronized IntrospectionHelper getHelper(final Class<?> c) {
return getHelper(null, c);
}
@@ -343,7 +343,7 @@ public final class IntrospectionHelper {
*
* @return a helper for the specified class
*/
- public synchronized static IntrospectionHelper getHelper(Project p, Class<?> c) {
+ public static synchronized IntrospectionHelper getHelper(final Project p, final Class<?> c) {
IntrospectionHelper ih = HELPERS.get(c.getName());
// If a helper cannot be found, or if the helper is for another
// classloader, create a new IH
@@ -376,43 +376,43 @@ public final class IntrospectionHelper {
* the given attribute, or if the setting
* method fails.
*/
- public void setAttribute(Project p, Object element, String attributeName,
- Object value) throws BuildException {
- AttributeSetter as = (AttributeSetter) attributeSetters.get(
+ public void setAttribute(final Project p, final Object element, final String attributeName,
+ final Object value) throws BuildException {
+ final AttributeSetter as = attributeSetters.get(
attributeName.toLowerCase(Locale.ENGLISH));
if (as == null && value != null) {
if (element instanceof DynamicAttributeNS) {
- DynamicAttributeNS dc = (DynamicAttributeNS) element;
- String uriPlusPrefix = ProjectHelper.extractUriFromComponentName(attributeName);
- String uri = ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
- String localName = ProjectHelper.extractNameFromComponentName(attributeName);
- String qName = "".equals(uri) ? localName : uri + ":" + localName;
+ final DynamicAttributeNS dc = (DynamicAttributeNS) element;
+ final String uriPlusPrefix = ProjectHelper.extractUriFromComponentName(attributeName);
+ final String uri = ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
+ final String localName = ProjectHelper.extractNameFromComponentName(attributeName);
+ final String qName = "".equals(uri) ? localName : uri + ":" + localName;
dc.setDynamicAttribute(uri, localName, qName, value.toString());
return;
}
if (element instanceof DynamicObjectAttribute) {
- DynamicObjectAttribute dc = (DynamicObjectAttribute) element;
+ final DynamicObjectAttribute dc = (DynamicObjectAttribute) element;
dc.setDynamicAttribute(attributeName.toLowerCase(Locale.ENGLISH), value);
return;
}
if (element instanceof DynamicAttribute) {
- DynamicAttribute dc = (DynamicAttribute) element;
+ final DynamicAttribute dc = (DynamicAttribute) element;
dc.setDynamicAttribute(attributeName.toLowerCase(Locale.ENGLISH), value.toString());
return;
}
if (attributeName.indexOf(':') >= 0) {
return; // Ignore attribute from unknown uri's
}
- String msg = getElementName(p, element)
+ final String msg = getElementName(p, element)
+ " doesn't support the \"" + attributeName + "\" attribute.";
throw new UnsupportedAttributeException(msg, attributeName);
}
try {
as.setObject(p, element, value);
- } catch (IllegalAccessException ie) {
+ } catch (final IllegalAccessException ie) {
// impossible as getMethods should only return public methods
throw new BuildException(ie);
- } catch (InvocationTargetException ite) {
+ } catch (final InvocationTargetException ite) {
throw extractBuildException(ite);
}
}
@@ -435,8 +435,8 @@ public final class IntrospectionHelper {
* the given attribute, or if the setting
* method fails.
*/
- public void setAttribute(Project p, Object element, String attributeName,
- String value) throws BuildException {
+ public void setAttribute(final Project p, final Object element, final String attributeName,
+ final String value) throws BuildException {
setAttribute(p, element, attributeName, (Object) value);
}
@@ -457,7 +457,7 @@ public final class IntrospectionHelper {
* method is available to handle it, or if
* the handling method fails.
*/
- public void addText(Project project, Object element, String text)
+ public void addText(final Project project, final Object element, String text)
throws BuildException {
if (addText == null) {
text = text.trim();
@@ -472,10 +472,10 @@ public final class IntrospectionHelper {
}
try {
addText.invoke(element, new Object[] {text});
- } catch (IllegalAccessException ie) {
+ } catch (final IllegalAccessException ie) {
// impossible as getMethods should only return public methods
throw new BuildException(ie);
- } catch (InvocationTargetException ite) {
+ } catch (final InvocationTargetException ite) {
throw extractBuildException(ite);
}
}
@@ -502,8 +502,8 @@ public final class IntrospectionHelper {
* @param parent the object which doesn't support a requested element
* @param elementName the name of the Element which is trying to be created.
*/
- public void throwNotSupported(Project project, Object parent, String elementName) {
- String msg = project.getElementName(parent)
+ public void throwNotSupported(final Project project, final Object parent, final String elementName) {
+ final String msg = project.getElementName(parent)
+ NOT_SUPPORTED_CHILD_PREFIX + elementName
+ NOT_SUPPORTED_CHILD_POSTFIX;
throw new UnsupportedElementException(msg, elementName);
@@ -521,11 +521,11 @@ public final class IntrospectionHelper {
* @throws BuildException if the parent does not support child elements of that name
*/
private NestedCreator getNestedCreator(
- Project project, String parentUri, Object parent,
- String elementName, UnknownElement child) throws BuildException {
+ final Project project, String parentUri, final Object parent,
+ final String elementName, final UnknownElement child) throws BuildException {
String uri = ProjectHelper.extractUriFromComponentName(elementName);
- String name = ProjectHelper.extractNameFromComponentName(elementName);
+ final String name = ProjectHelper.extractNameFromComponentName(elementName);
if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
uri = "";
@@ -535,7 +535,7 @@ public final class IntrospectionHelper {
}
NestedCreator nc = null;
if (uri.equals(parentUri) || uri.length() == 0) {
- nc = (NestedCreator) nestedCreators.get(name.toLowerCase(Locale.ENGLISH));
+ nc = nestedCreators.get(name.toLowerCase(Locale.ENGLISH));
}
if (nc == null) {
nc = createAddTypeCreator(project, parent, elementName);
@@ -544,14 +544,15 @@ public final class IntrospectionHelper {
(parent instanceof DynamicElementNS
|| parent instanceof DynamicElement)
) {
- String qName = child == null ? name : child.getQName();
+ final String qName = child == null ? name : child.getQName();
final Object nestedElement =
createDynamicElement(parent,
child == null ? "" : child.getNamespace(),
name, qName);
if (nestedElement != null) {
nc = new NestedCreator(null) {
- Object create(Project project, Object parent, Object ignore) {
+ @Override
+ Object create(final Project project, final Object parent, final Object ignore) {
return nestedElement;
}
};
@@ -569,15 +570,15 @@ public final class IntrospectionHelper {
*
* @since Ant 1.8.0.
*/
- private Object createDynamicElement(Object parent, String ns,
- String localName, String qName) {
+ private Object createDynamicElement(final Object parent, final String ns,
+ final String localName, final String qName) {
Object nestedElement = null;
if (parent instanceof DynamicElementNS) {
- DynamicElementNS dc = (DynamicElementNS) parent;
+ final DynamicElementNS dc = (DynamicElementNS) parent;
nestedElement = dc.createDynamicElement(ns, localName, qName);
}
if (nestedElement == null && parent instanceof DynamicElement) {
- DynamicElement dc = (DynamicElement) parent;
+ final DynamicElement dc = (DynamicElement) parent;
nestedElement =
dc.createDynamicElement(localName.toLowerCase(Locale.ENGLISH));
}
@@ -606,22 +607,23 @@ public final class IntrospectionHelper {
* @exception BuildException if no method is available to create the
* element instance, or if the creating method fails.
*/
- public Object createElement(Project project, Object parent, String elementName)
+ @Deprecated
+ public Object createElement(final Project project, final Object parent, final String elementName)
throws BuildException {
- NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
+ final NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
try {
- Object nestedElement = nc.create(project, parent, null);
+ final Object nestedElement = nc.create(project, parent, null);
if (project != null) {
project.setProjectReference(nestedElement);
}
return nestedElement;
- } catch (IllegalAccessException ie) {
+ } catch (final IllegalAccessException ie) {
// impossible as getMethods should only return public methods
throw new BuildException(ie);
- } catch (InstantiationException ine) {
+ } catch (final InstantiationException ine) {
// impossible as getMethods should only return public methods
throw new BuildException(ine);
- } catch (InvocationTargetException ite) {
+ } catch (final InvocationTargetException ite) {
throw extractBuildException(ite);
}
}
@@ -639,8 +641,8 @@ public final class IntrospectionHelper {
* @return a creator object to create and store the element instance.
*/
public Creator getElementCreator(
- Project project, String parentUri, Object parent, String elementName, UnknownElement ue) {
- NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
+ final Project project, final String parentUri, final Object parent, final String elementName, final UnknownElement ue) {
+ final NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
return new Creator(project, parent, nc);
}
@@ -682,7 +684,7 @@ public final class IntrospectionHelper {
*
* @return true if the given nested element is supported
*/
- public boolean supportsNestedElement(String elementName) {
+ public boolean supportsNestedElement(final String elementName) {
return supportsNestedElement("", elementName);
}
@@ -701,7 +703,7 @@ public final class IntrospectionHelper {
*
* @return true if the given nested element is supported
*/
- public boolean supportsNestedElement(String parentUri, String elementName) {
+ public boolean supportsNestedElement(final String parentUri, final String elementName) {
if (isDynamic() || addTypeMethods.size() > 0) {
return true;
}
@@ -725,8 +727,8 @@ public final class IntrospectionHelper {
* @return true if the given nested element is supported
* @since Ant 1.8.0.
*/
- public boolean supportsNestedElement(String parentUri, String elementName,
- Project project, Object parent) {
+ public boolean supportsNestedElement(final String parentUri, final String elementName,
+ final Project project, final Object parent) {
if (addTypeMethods.size() > 0
&& createAddTypeCreator(project, parent, elementName) != null) {
return true;
@@ -744,8 +746,8 @@ public final class IntrospectionHelper {
* @since Ant 1.8.0
*/
public boolean supportsReflectElement(
- String parentUri, String elementName) {
- String name = ProjectHelper.extractNameFromComponentName(elementName);
+ String parentUri, final String elementName) {
+ final String name = ProjectHelper.extractNameFromComponentName(elementName);
if (!nestedCreators.containsKey(name.toLowerCase(Locale.ENGLISH))) {
return false;
}
@@ -782,24 +784,24 @@ public final class IntrospectionHelper {
*
* @exception BuildException if the storage method fails.
*/
- public void storeElement(Project project, Object parent, Object child,
- String elementName) throws BuildException {
+ public void storeElement(final Project project, final Object parent, final Object child,
+ final String elementName) throws BuildException {
if (elementName == null) {
return;
}
- NestedCreator ns = (NestedCreator) nestedCreators.get(elementName.toLowerCase(Locale.ENGLISH));
+ final NestedCreator ns = nestedCreators.get(elementName.toLowerCase(Locale.ENGLISH));
if (ns == null) {
return;
}
try {
ns.store(parent, child);
- } catch (IllegalAccessException ie) {
+ } catch (final IllegalAccessException ie) {
// impossible as getMethods should only return public methods
throw new BuildException(ie);
- } catch (InstantiationException ine) {
+ } catch (final InstantiationException ine) {
// impossible as getMethods should only return public methods
throw new BuildException(ine);
- } catch (InvocationTargetException ite) {
+ } catch (final InvocationTargetException ite) {
throw extractBuildException(ite);
}
}
@@ -811,8 +813,8 @@ public final class IntrospectionHelper {
* @param ite
* @return the nested exception
*/
- private static BuildException extractBuildException(InvocationTargetException ite) {
- Throwable t = ite.getTargetException();
+ private static BuildException extractBuildException(final InvocationTargetException ite) {
+ final Throwable t = ite.getTargetException();
if (t instanceof BuildException) {
return (BuildException) t;
}
@@ -831,8 +833,8 @@ public final class IntrospectionHelper {
* @exception BuildException if the introspected class does not
* support the named nested element.
*/
- public Class<?> getElementType(String elementName) throws BuildException {
- Class<?> nt = nestedTypes.get(elementName);
+ public Class<?> getElementType(final String elementName) throws BuildException {
+ final Class<?> nt = nestedTypes.get(elementName);
if (nt == null) {
throw new UnsupportedElementException("Class "
+ bean.getName() + " doesn't support the nested \""
@@ -853,8 +855,8 @@ public final class IntrospectionHelper {
* @exception BuildException if the introspected class does not
* support the named attribute.
*/
- public Class<?> getAttributeType(String attributeName) throws BuildException {
- Class<?> at = attributeTypes.get(attributeName);
+ public Class<?> getAttributeType(final String attributeName) throws BuildException {
+ final Class<?> at = attributeTypes.get(attributeName);
if (at == null) {
throw new UnsupportedAttributeException("Class "
+ bean.getName() + " doesn't support the \""
@@ -893,8 +895,8 @@ public final class IntrospectionHelper {
* support the named nested element.
* @since Ant 1.6.3
*/
- public Method getElementMethod(String elementName) throws BuildException {
- Object creator = nestedCreators.get(elementName);
+ public Method getElementMethod(final String elementName) throws BuildException {
+ final Object creator = nestedCreators.get(elementName);
if (creator == null) {
throw new UnsupportedElementException("Class "
+ bean.getName() + " doesn't support the nested \""
@@ -914,8 +916,8 @@ public final class IntrospectionHelper {
* support the named attribute.
* @since Ant 1.6.3
*/
- public Method getAttributeMethod(String attributeName) throws BuildException {
- Object setter = attributeSetters.get(attributeName);
+ public Method getAttributeMethod(final String attributeName) throws BuildException {
+ final Object setter = attributeSetters.get(attributeName);
if (setter == null) {
throw new UnsupportedAttributeException("Class "
+ bean.getName() + " doesn't support the \""
@@ -1036,7 +1038,7 @@ public final class IntrospectionHelper {
* if no appropriate conversion is available.
*/
private AttributeSetter createAttributeSetter(final Method m,
- Class<?> arg,
+ final Class<?> arg,
final String attrName) {
// use wrappers for primitive classes, e.g. int and
// Integer are treated identically
@@ -1046,7 +1048,8 @@ public final class IntrospectionHelper {
// Object.class - it gets handled differently by AttributeSetter
if (java.lang.Object.class == reflectedArg) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException,
IllegalAccessException {
throw new BuildException(
@@ -1057,7 +1060,8 @@ public final class IntrospectionHelper {
// simplest case - setAttribute expects String
if (java.lang.String.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException {
m.invoke(parent, (Object[]) new String[] {value});
}
@@ -1066,7 +1070,8 @@ public final class IntrospectionHelper {
// char and Character get special treatment - take the first character
if (java.lang.Character.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException {
if (value.length() == 0) {
throw new BuildException("The value \"\" is not a "
@@ -1079,7 +1084,8 @@ public final class IntrospectionHelper {
// boolean and Boolean get special treatment because we have a nice method in Project
if (java.lang.Boolean.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException {
m.invoke(parent, (Object[]) new Boolean[] {
Project.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE });
@@ -1089,11 +1095,12 @@ public final class IntrospectionHelper {
// Class doesn't have a String constructor but a decent factory method
if (java.lang.Class.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException, BuildException {
try {
m.invoke(parent, new Object[] {Class.forName(value)});
- } catch (ClassNotFoundException ce) {
+ } catch (final ClassNotFoundException ce) {
throw new BuildException(ce);
}
}
@@ -1102,7 +1109,8 @@ public final class IntrospectionHelper {
// resolve relative paths through Project
if (java.io.File.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException {
m.invoke(parent, new Object[] {p.resolveFile(value)});
}
@@ -1111,49 +1119,52 @@ public final class IntrospectionHelper {
// resolve Resources/FileProviders as FileResources relative to Project:
if (Resource.class.equals(reflectedArg) || FileProvider.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- void set(Project p, Object parent, String value) throws InvocationTargetException,
+ @Override
+ void set(final Project p, final Object parent, final String value) throws InvocationTargetException,
IllegalAccessException, BuildException {
- m.invoke(parent, new Object[] { new FileResource(p, p.resolveFile(value)) });
+ m.invoke(parent, new Object[] {new FileResource(p, p.resolveFile(value))});
};
};
}
// EnumeratedAttributes have their own helper class
if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException, BuildException {
try {
- EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
+ final EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
ea.setValue(value);
m.invoke(parent, new Object[] {ea});
- } catch (InstantiationException ie) {
+ } catch (final InstantiationException ie) {
throw new BuildException(ie);
}
}
};
}
- AttributeSetter setter = getEnumSetter(reflectedArg, m, arg);
+ final AttributeSetter setter = getEnumSetter(reflectedArg, m, arg);
if (setter != null) {
return setter;
}
if (java.lang.Long.class.equals(reflectedArg)) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException, BuildException {
try {
m.invoke(parent, new Object[] {
new Long(StringUtils.parseHumanSizes(value)) });
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
throw new BuildException("Can't assign non-numeric"
+ " value '" + value + "' to"
+ " attribute " + attrName);
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e;
- } catch (IllegalAccessException e) {
+ } catch (final IllegalAccessException e) {
throw e;
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new BuildException(e);
}
}
@@ -1169,12 +1180,12 @@ public final class IntrospectionHelper {
// First try with Project.
c = reflectedArg.getConstructor(Project.class, String.class);
includeProject = true;
- } catch (NoSuchMethodException nme) {
+ } catch (final NoSuchMethodException nme) {
// OK, try without.
try {
c = reflectedArg.getConstructor(String.class);
includeProject = false;
- } catch (NoSuchMethodException nme2) {
+ } catch (final NoSuchMethodException nme2) {
// Well, no matching constructor.
return null;
}
@@ -1183,19 +1194,20 @@ public final class IntrospectionHelper {
final Constructor<?> finalConstructor = c;
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException, BuildException {
try {
- Object[] args = finalIncludeProject
+ final Object[] args = finalIncludeProject
? new Object[] {p, value} : new Object[] {value};
- Object attribute = finalConstructor.newInstance(args);
+ final Object attribute = finalConstructor.newInstance(args);
if (p != null) {
p.setProjectReference(attribute);
}
m.invoke(parent, new Object[] {attribute});
- } catch (InvocationTargetException e) {
- Throwable cause = e.getCause();
+ } catch (final InvocationTargetException e) {
+ final Throwable cause = e.getCause();
if (cause instanceof IllegalArgumentException) {
throw new BuildException("Can't assign value '" + value
+ "' to attribute " + attrName
@@ -1205,7 +1217,7 @@ public final class IntrospectionHelper {
+ cause.getMessage() + "'");
}
throw e;
- } catch (InstantiationException ie) {
+ } catch (final InstantiationException ie) {
throw new BuildException(ie);
}
}
@@ -1213,19 +1225,21 @@ public final class IntrospectionHelper {
}
private AttributeSetter getEnumSetter(
- final Class<?> reflectedArg, final Method m, Class<?> arg) {
+ final Class<?> reflectedArg, final Method m, final Class<?> arg) {
if (reflectedArg.isEnum()) {
return new AttributeSetter(m, arg) {
- public void set(Project p, Object parent, String value)
+ @Override
+ public void set(final Project p, final Object parent, final String value)
throws InvocationTargetException, IllegalAccessException,
BuildException {
Enum<?> setValue;
try {
@SuppressWarnings({ "unchecked", "rawtypes" })
+ final
Enum<?> enumValue = Enum.valueOf((Class<? extends Enum>) reflectedArg,
value);
setValue = enumValue;
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
//there is specific logic here for the value
// being out of the allowed set of enumerations.
throw new BuildException("'" + value + "' is not a permitted value for "
@@ -1249,7 +1263,7 @@ public final class IntrospectionHelper {
*
* @return a description of the element type
*/
- private String getElementName(Project project, Object element) {
+ private String getElementName(final Project project, final Object element) {
return project.getElementName(element);
}
@@ -1264,7 +1278,7 @@ public final class IntrospectionHelper {
*
* @return the lower-cased method name with the prefix removed.
*/
- private static String getPropertyName(String methodName, String prefix) {
+ private static String getPropertyName(final String methodName, final String prefix) {
return methodName.substring(prefix.length()).toLowerCase(Locale.ENGLISH);
}
@@ -1274,9 +1288,9 @@ public final class IntrospectionHelper {
* The class is final as it has a private constructor.
*/
public static final class Creator {
- private NestedCreator nestedCreator;
- private Object parent;
- private Project project;
+ private final NestedCreator nestedCreator;
+ private final Object parent;
+ private final Project project;
private Object nestedObject;
private String polyType;
@@ -1293,7 +1307,7 @@ public final class IntrospectionHelper {
* @param parent the parent object to create the object in
* @param nestedCreator the nested creator object to use
*/
- private Creator(Project project, Object parent, NestedCreator nestedCreator) {
+ private Creator(final Project project, final Object parent, final NestedCreator nestedCreator) {
this.project = project;
this.parent = parent;
this.nestedCreator = nestedCreator;
@@ -1304,7 +1318,7 @@ public final class IntrospectionHelper {
*
* @param polyType a ant component type name
*/
- public void setPolyType(String polyType) {
+ public void setPolyType(final String polyType) {
this.polyType = polyType;
}
@@ -1319,7 +1333,7 @@ public final class IntrospectionHelper {
throw new BuildException(
"Not allowed to use the polymorphic form for this element");
}
- ComponentHelper helper = ComponentHelper.getComponentHelper(project);
+ final ComponentHelper helper = ComponentHelper.getComponentHelper(project);
nestedObject = helper.createComponent(polyType);
if (nestedObject == null) {
throw new BuildException("Unable to create object of type " + polyType);
@@ -1331,16 +1345,16 @@ public final class IntrospectionHelper {
project.setProjectReference(nestedObject);
}
return nestedObject;
- } catch (IllegalAccessException ex) {
+ } catch (final IllegalAccessException ex) {
throw new BuildException(ex);
- } catch (InstantiationException ex) {
+ } catch (final InstantiationException ex) {
throw new BuildException(ex);
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
if (polyType == null) {
throw ex;
}
throw new BuildException("Invalid type used " + polyType);
- } catch (InvocationTargetException ex) {
+ } catch (final InvocationTargetException ex) {
throw extractBuildException(ex);
}
}
@@ -1359,16 +1373,16 @@ public final class IntrospectionHelper {
public void store() {
try {
nestedCreator.store(parent, nestedObject);
- } catch (IllegalAccessException ex) {
+ } catch (final IllegalAccessException ex) {
throw new BuildException(ex);
- } catch (InstantiationException ex) {
+ } catch (final InstantiationException ex) {
throw new BuildException(ex);
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
if (polyType == null) {
throw ex;
}
throw new BuildException("Invalid type used " + polyType);
- } catch (InvocationTargetException ex) {
+ } catch (final InvocationTargetException ex) {
throw extractBuildException(ex);
}
}
@@ -1379,9 +1393,9 @@ public final class IntrospectionHelper {
* in detail for reasons of source code readability.
*/
private abstract static class NestedCreator {
- private Method method; // the method called to add/create the nested element
+ private final Method method; // the method called to add/create the nested element
- protected NestedCreator(Method m) {
+ protected NestedCreator(final Method m) {
method = m;
}
Method getMethod() {
@@ -1396,18 +1410,19 @@ public final class IntrospectionHelper {
abstract Object create(Project project, Object parent, Object child)
throws InvocationTargetException, IllegalAccessException, InstantiationException;
- void store(Object parent, Object child)
+ void store(final Object parent, final Object child)
throws InvocationTargetException, IllegalAccessException, InstantiationException {
// DO NOTHING
}
}
private static class CreateNestedCreator extends NestedCreator {
- CreateNestedCreator(Method m) {
+ CreateNestedCreator(final Method m) {
super(m);
}
- Object create(Project project, Object parent, Object ignore)
+ @Override
+ Object create(final Project project, final Object parent, final Object ignore)
throws InvocationTargetException, IllegalAccessException {
return getMethod().invoke(parent, new Object[] {});
}
@@ -1419,20 +1434,22 @@ public final class IntrospectionHelper {
static final int ADD = 1;
static final int ADD_CONFIGURED = 2;
- private Constructor<?> constructor;
- private int behavior; // ADD or ADD_CONFIGURED
+ private final Constructor<?> constructor;
+ private final int behavior; // ADD or ADD_CONFIGURED
- AddNestedCreator(Method m, Constructor<?> c, int behavior) {
+ AddNestedCreator(final Method m, final Constructor<?> c, final int behavior) {
super(m);
this.constructor = c;
this.behavior = behavior;
}
- boolean isPolyMorphic() {
+ @Override
+ boolean isPolyMorphic() {
return true;
}
- Object create(Project project, Object parent, Object child)
+ @Override
+ Object create(final Project project, final Object parent, Object child)
throws InvocationTargetException, IllegalAccessException, InstantiationException {
if (child == null) {
child = constructor.newInstance(
@@ -1448,14 +1465,15 @@ public final class IntrospectionHelper {
return child;
}
- void store(Object parent, Object child)
+ @Override
+ void store(final Object parent, final Object child)
throws InvocationTargetException, IllegalAccessException, InstantiationException {
if (behavior == ADD_CONFIGURED) {
istore(parent, child);
}
}
- private void istore(Object parent, Object child)
+ private void istore(final Object parent, final Object child)
throws InvocationTargetException, IllegalAccessException, InstantiationException {
getMethod().invoke(parent, new Object[] {child});
}
@@ -1466,13 +1484,13 @@ public final class IntrospectionHelper {
* in detail for reasons of source code readability.
*/
private abstract static class AttributeSetter {
- private Method method; // the method called to set the attribute
- private Class<?> type;
- protected AttributeSetter(Method m, Class<?> type) {
+ private final Method method; // the method called to set the attribute
+ private final Class<?> type;
+ protected AttributeSetter(final Method m, final Class<?> type) {
method = m;
this.type = type;
}
- void setObject(Project p, Object parent, Object value)
+ void setObject(final Project p, final Object parent, final Object value)
throws InvocationTargetException, IllegalAccessException, BuildException {
if (type != null) {
Class<?> useType = type;
@@ -1499,7 +1517,7 @@ public final class IntrospectionHelper {
/**
* Clears the static cache of on build finished.
*/
- public synchronized static void clearCache() {
+ public static synchronized void clearCache() {
HELPERS.clear();
}
@@ -1513,15 +1531,15 @@ public final class IntrospectionHelper {
* @throws BuildException
*/
private NestedCreator createAddTypeCreator(
- Project project, Object parent, String elementName) throws BuildException {
+ final Project project, final Object parent, final String elementName) throws BuildException {
if (addTypeMethods.size() == 0) {
return null;
}
- ComponentHelper helper = ComponentHelper.getComponentHelper(project);
+ final ComponentHelper helper = ComponentHelper.getComponentHelper(project);
- MethodAndObject restricted = createRestricted(
+ final MethodAndObject restricted = createRestricted(
helper, elementName, addTypeMethods);
- MethodAndObject topLevel = createTopLevel(
+ final MethodAndObject topLevel = createTopLevel(
helper, elementName, addTypeMethods);
if (restricted == null && topLevel == null) {
@@ -1534,7 +1552,7 @@ public final class IntrospectionHelper {
+ elementName);
}
- MethodAndObject methodAndObject
+ final MethodAndObject methodAndObject
= restricted != null ? restricted : topLevel;
Object rObject = methodAndObject.object;
@@ -1546,7 +1564,8 @@ public final class IntrospectionHelper {
final Object realObject = rObject;
return new NestedCreator(methodAndObject.method) {
- Object create(Project project, Object parent, Object ignore)
+ @Override
+ Object create(final Project project, final Object parent, final Object ignore)
throws InvocationTargetException, IllegalAccessException {
if (!getMethod().getName().endsWith("Configured")) {
getMethod().invoke(parent, new Object[] {realObject});
@@ -1554,11 +1573,13 @@ public final class IntrospectionHelper {
return nestedObject;
}
- Object getRealObject() {
+ @Override
+ Object getRealObject() {
return realObject;
}
- void store(Object parent, Object child) throws InvocationTargetException,
+ @Override
+ void store(final Object parent, final Object child) throws InvocationTargetException,
IllegalAccessException, InstantiationException {
if (getMethod().getName().endsWith("Configured")) {
getMethod().invoke(parent, new Object[] {realObject});
@@ -1574,11 +1595,11 @@ public final class IntrospectionHelper {
* If both add and addConfigured are present, the addConfigured will take priority.
* @param method the <code>Method</code> to insert.
*/
- private void insertAddTypeMethod(Method method) {
- Class<?> argClass = method.getParameterTypes()[0];
+ private void insertAddTypeMethod(final Method method) {
+ final Class<?> argClass = method.getParameterTypes()[0];
final int size = addTypeMethods.size();
for (int c = 0; c < size; ++c) {
- Method current = (Method) addTypeMethods.get(c);
+ final Method current = addTypeMethods.get(c);
if (current.getParameterTypes()[0].equals(argClass)) {
if (method.getName().equals("addConfigured")) {
// add configured replaces the add method
@@ -1601,7 +1622,7 @@ public final class IntrospectionHelper {
* @param methods the <code>List</code> of methods to search.
* @return a matching <code>Method</code>; null if none found.
*/
- private Method findMatchingMethod(Class<?> paramClass, List<Method> methods) {
+ private Method findMatchingMethod(final Class<?> paramClass, final List<Method> methods) {
if (paramClass == null) {
return null;
}
@@ -1610,8 +1631,8 @@ public final class IntrospectionHelper {
final int size = methods.size();
for (int i = 0; i < size; ++i) {
- Method method = methods.get(i);
- Class<?> methodClass = method.getParameterTypes()[0];
+ final Method method = methods.get(i);
+ final Class<?> methodClass = method.getParameterTypes()[0];
if (methodClass.isAssignableFrom(paramClass)) {
if (matchedClass == null) {
matchedClass = methodClass;
@@ -1629,15 +1650,15 @@ public final class IntrospectionHelper {
if (text.length() <= MAX_REPORT_NESTED_TEXT) {
return text;
}
- int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
+ final int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString();
}
private static class MethodAndObject {
- private Method method;
- private Object object;
- public MethodAndObject(Method method, Object object) {
+ private final Method method;
+ private final Object object;
+ public MethodAndObject(final Method method, final Object object) {
this.method = method;
this.object = object;
}
@@ -1647,23 +1668,23 @@ public final class IntrospectionHelper {
*
*/
private AntTypeDefinition findRestrictedDefinition(
- ComponentHelper helper, String componentName, List<Method> methods) {
+ final ComponentHelper helper, final String componentName, final List<Method> methods) {
AntTypeDefinition definition = null;
Class<?> matchedDefinitionClass = null;
- List<AntTypeDefinition> definitions = helper.getRestrictedDefinitions(componentName);
+ final List<AntTypeDefinition> definitions = helper.getRestrictedDefinitions(componentName);
if (definitions == null) {
return null;
}
synchronized (definitions) {
final int size = definitions.size();
for (int i = 0; i < size; ++i) {
- AntTypeDefinition d = definitions.get(i);
- Class<?> exposedClass = d.getExposedClass(helper.getProject());
+ final AntTypeDefinition d = definitions.get(i);
+ final Class<?> exposedClass = d.getExposedClass(helper.getProject());
if (exposedClass == null) {
continue;
}
- Method method = findMatchingMethod(exposedClass, methods);
+ final Method method = findMatchingMethod(exposedClass, methods);
if (method == null) {
continue;
}
@@ -1681,25 +1702,25 @@ public final class IntrospectionHelper {
}
private MethodAndObject createRestricted(
- ComponentHelper helper, String elementName, List<Method> addTypeMethods) {
+ final ComponentHelper helper, final String elementName, final List<Method> addTypeMethods) {
- Project project = helper.getProject();
+ final Project project = helper.getProject();
- AntTypeDefinition restrictedDefinition =
+ final AntTypeDefinition restrictedDefinition =
findRestrictedDefinition(helper, elementName, addTypeMethods);
if (restrictedDefinition == null) {
return null;
}
- Method addMethod = findMatchingMethod(
+ final Method addMethod = findMatchingMethod(
restrictedDefinition.getExposedClass(project), addTypeMethods);
if (addMethod == null) {
throw new BuildException(
"Ant Internal Error - contract mismatch for "
+ elementName);
}
- Object addedObject = restrictedDefinition.create(project);
+ final Object addedObject = restrictedDefinition.create(project);
if (addedObject == null) {
throw new BuildException(
"Failed to create object " + elementName
@@ -1709,16 +1730,16 @@ public final class IntrospectionHelper {
}
private MethodAndObject createTopLevel(
- ComponentHelper helper, String elementName, List<Method> methods) {
- Class<?> clazz = helper.getComponentClass(elementName);
+ final ComponentHelper helper, final String elementName, final List<Method> methods) {
+ final Class<?> clazz = helper.getComponentClass(elementName);
if (clazz == null) {
return null;
}
- Method addMethod = findMatchingMethod(clazz, addTypeMethods);
+ final Method addMethod = findMatchingMethod(clazz, addTypeMethods);
if (addMethod == null) {
return null;
}
- Object addedObject = helper.createComponent(elementName);
+ final Object addedObject = helper.createComponent(elementName);
return new MethodAndObject(addMethod, addedObject);
}