Browse files

Merge pull request #1 from shoenig/master

Eliminate all rawtype warnings
  • Loading branch information...
2 parents 067d76c + 5398c34 commit 691be25a66d6f029efd561c33f16ac41323d4971 Sam Pullara committed May 17, 2012
Showing with 16 additions and 15 deletions.
  1. +16 −15 src/main/java/com/sampullara/cli/Args.java
View
31 src/main/java/com/sampullara/cli/Args.java
@@ -5,6 +5,7 @@
package com.sampullara.cli;
+
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -24,7 +25,7 @@
public static List<String> parse(Object target, String[] args) {
List<String> arguments = new ArrayList<String>();
arguments.addAll(Arrays.asList(args));
- Class clazz;
+ Class<?> clazz;
if (target instanceof Class) {
clazz = (Class) target;
} else {
@@ -64,7 +65,7 @@ private static void processField(Object target, Field field, List<String> argume
arg = arg.substring(prefix.length());
if (arg.equals(name) || (alias != null && arg.equals(alias))) {
i.remove();
- Class type = field.getType();
+ Class<?> type = field.getType();
value = consumeArgumentValue(type, argument, i);
setField(type, field, target, value, delimiter);
set = true;
@@ -96,7 +97,7 @@ private static void processProperty(Object target, PropertyDescriptor property,
arg = arg.substring(prefix.length());
if (arg.equals(name) || (alias != null && arg.equals(alias))) {
i.remove();
- Class type = property.getPropertyType();
+ Class<?> type = property.getPropertyType();
value = consumeArgumentValue(type, argument, i);
setProperty(type, property, target, value, delimiter);
set = true;
@@ -128,7 +129,7 @@ public static void usage(Object target) {
* @param target An instance or class.
*/
public static void usage(PrintStream errStream, Object target) {
- Class clazz;
+ Class<?> clazz;
if (target instanceof Class) {
clazz = (Class) target;
} else {
@@ -159,7 +160,7 @@ private static void fieldUsage(PrintStream errStream, Object target, Field field
makeAccessible(field);
try {
Object defaultValue = field.get(target);
- Class type = field.getType();
+ Class<?> type = field.getType();
propertyUsage(errStream, prefix, name, alias, type, delimiter, description, defaultValue);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not use thie field " + field + " as an argument field", e);
@@ -185,7 +186,7 @@ private static void propertyUsage(PrintStream errStream, Object target, Property
} else {
defaultValue = readMethod.invoke(target, (Object[]) null);
}
- Class type = field.getPropertyType();
+ Class<?> type = field.getPropertyType();
propertyUsage(errStream, prefix, name, alias, type, delimiter, description, defaultValue);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not use thie field " + field + " as an argument field", e);
@@ -197,7 +198,7 @@ private static void propertyUsage(PrintStream errStream, Object target, Property
}
- private static void propertyUsage(PrintStream errStream, String prefix, String name, String alias, Class type, String delimiter, String description, Object defaultValue) {
+ private static void propertyUsage(PrintStream errStream, String prefix, String name, String alias, Class<?> type, String delimiter, String description, Object defaultValue) {
StringBuilder sb = new StringBuilder(" ");
sb.append(prefix);
sb.append(name);
@@ -227,7 +228,7 @@ private static void propertyUsage(PrintStream errStream, String prefix, String n
if (defaultValue != null) {
sb.append(" (");
if (type.isArray()) {
- List list = new ArrayList();
+ List<Object> list = new ArrayList<Object>();
int len = Array.getLength(defaultValue);
for (int i = 0; i < len; i++) {
list.add(Array.get(defaultValue, i));
@@ -243,7 +244,7 @@ private static void propertyUsage(PrintStream errStream, String prefix, String n
errStream.println(sb);
}
- private static String getTypeName(Class type) {
+ private static String getTypeName(Class<?> type) {
String typeName = type.getName();
int beginIndex = typeName.lastIndexOf(".");
typeName = typeName.substring(beginIndex + 1);
@@ -259,7 +260,7 @@ static String getName(Argument argument, PropertyDescriptor property) {
}
- private static Object consumeArgumentValue(Class type, Argument argument, Iterator<String> i) {
+ private static Object consumeArgumentValue(Class<?> type, Argument argument, Iterator<String> i) {
Object value;
if (type == Boolean.TYPE || type == Boolean.class) {
value = true;
@@ -274,7 +275,7 @@ private static Object consumeArgumentValue(Class type, Argument argument, Iterat
return value;
}
- static void setProperty(Class type, PropertyDescriptor property, Object target, Object value, String delimiter) {
+ static void setProperty(Class<?> type, PropertyDescriptor property, Object target, Object value, String delimiter) {
try {
value = getValue(type, value, delimiter);
property.getWriteMethod().invoke(target, value);
@@ -303,7 +304,7 @@ static String getName(Argument argument, Field field) {
return name;
}
- static void setField(Class type, Field field, Object target, Object value, String delimiter) {
+ static void setField(Class<?> type, Field field, Object target, Object value, String delimiter) {
makeAccessible(field);
try {
value = getValue(type, value, delimiter);
@@ -315,7 +316,7 @@ static void setField(Class type, Field field, Object target, Object value, Strin
}
}
- private static Object getValue(Class type, Object value, String delimiter) throws NoSuchMethodException {
+ private static Object getValue(Class<?> type, Object value, String delimiter) throws NoSuchMethodException {
if (type != String.class && type != Boolean.class && type != Boolean.TYPE) {
if (type.isArray()) {
String string = (String) value;
@@ -337,8 +338,8 @@ private static Object getValue(Class type, Object value, String delimiter) throw
return value;
}
- private static Object createValue(Class type, Object value) throws NoSuchMethodException {
- Constructor init = type.getDeclaredConstructor(String.class);
+ private static Object createValue(Class<?> type, Object value) throws NoSuchMethodException {
+ Constructor<?> init = type.getDeclaredConstructor(String.class);
try {
value = init.newInstance(value);
} catch (Exception e) {

0 comments on commit 691be25

Please sign in to comment.