summaryrefslogtreecommitdiff
path: root/gnu/xml
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-23 20:59:32 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-23 20:59:32 +0000
commitc4468c342efcd45bdc6cc08ea9c06ea6edd75f69 (patch)
treeab41d9ebe5fb4fea3c179d70b3e4ed89738c93fc /gnu/xml
parent7b5f1590c0b002ac59f31c5932977cb1d8d63339 (diff)
downloadclasspath-c4468c342efcd45bdc6cc08ea9c06ea6edd75f69.tar.gz
2008-06-23 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/xml/xpath/CountFunction.java, * gnu/xml/xpath/EqualityExpr.java, * gnu/xml/xpath/Expr.java, * gnu/xml/xpath/IdFunction.java, * gnu/xml/xpath/LocalNameFunction.java, * gnu/xml/xpath/NameFunction.java, * gnu/xml/xpath/NamespaceUriFunction.java, * gnu/xml/xpath/ParenthesizedExpr.java, * gnu/xml/xpath/Steps.java, * gnu/xml/xpath/SumFunction.java, * gnu/xml/xpath/UnionExpr.java, * gnu/xml/xpath/XPathParser.java, * gnu/xml/xpath/XPathParser.y, * java/lang/Enum.java, * java/lang/reflect/Constructor.java, * java/lang/reflect/Field.java, * java/lang/reflect/Method.java: Reduce scope of unchecked warning suppression, and remove unneeded uses.
Diffstat (limited to 'gnu/xml')
-rw-r--r--gnu/xml/xpath/CountFunction.java4
-rw-r--r--gnu/xml/xpath/EqualityExpr.java20
-rw-r--r--gnu/xml/xpath/Expr.java34
-rw-r--r--gnu/xml/xpath/IdFunction.java3
-rw-r--r--gnu/xml/xpath/LocalNameFunction.java4
-rw-r--r--gnu/xml/xpath/NameFunction.java15
-rw-r--r--gnu/xml/xpath/NamespaceUriFunction.java10
-rw-r--r--gnu/xml/xpath/ParenthesizedExpr.java8
-rw-r--r--gnu/xml/xpath/Steps.java14
-rw-r--r--gnu/xml/xpath/SumFunction.java8
-rw-r--r--gnu/xml/xpath/UnionExpr.java20
-rw-r--r--gnu/xml/xpath/XPathParser.java42
-rw-r--r--gnu/xml/xpath/XPathParser.y24
13 files changed, 136 insertions, 70 deletions
diff --git a/gnu/xml/xpath/CountFunction.java b/gnu/xml/xpath/CountFunction.java
index 25bbfa636..f29d83310 100644
--- a/gnu/xml/xpath/CountFunction.java
+++ b/gnu/xml/xpath/CountFunction.java
@@ -64,11 +64,11 @@ final class CountFunction
this.arg = arg;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
- return new Double((double) ((Collection<Node>) val).size());
+ return new Double((double) ((Collection<?>) val).size());
}
public Expr clone(Object context)
diff --git a/gnu/xml/xpath/EqualityExpr.java b/gnu/xml/xpath/EqualityExpr.java
index 0a8147d76..3b6fd568a 100644
--- a/gnu/xml/xpath/EqualityExpr.java
+++ b/gnu/xml/xpath/EqualityExpr.java
@@ -76,7 +76,6 @@ final class EqualityExpr
}
}
- @SuppressWarnings("unchecked")
private boolean evaluateImpl(Node context, int pos, int len)
{
Object left = lhs.evaluate(context, pos, len);
@@ -92,8 +91,11 @@ final class EqualityExpr
boolean frns = right instanceof Collection;
if (flns && frns)
{
- Collection<Node> lns = (Collection<Node>) left;
- Collection<Node> rns = (Collection<Node>) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> lns = (Collection<Node>) left;
+ @SuppressWarnings("unchecked")
+ Collection<Node> rns = (Collection<Node>) right;
if (lns.isEmpty())
{
return false;
@@ -138,7 +140,9 @@ final class EqualityExpr
boolean frn = right instanceof Double;
if ((flns && frn) || (frns && fln))
{
- Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
double n = fln ? ((Double) left).doubleValue() :
((Double) right).doubleValue();
boolean all = true;
@@ -170,7 +174,9 @@ final class EqualityExpr
boolean frs = right instanceof String;
if ((flns && frs) || (frns && fls))
{
- Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
String s = fls ? (String) left : (String) right;
boolean all = true;
for (Node test : ns)
@@ -200,7 +206,9 @@ final class EqualityExpr
boolean frb = right instanceof Boolean;
if ((flns && frb) || (frns && flb))
{
- Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
boolean b = flb ? ((Boolean) left).booleanValue() :
((Boolean) right).booleanValue();
return _boolean(context, ns) == b;
diff --git a/gnu/xml/xpath/Expr.java b/gnu/xml/xpath/Expr.java
index 30d4baa5b..87ce3dfb6 100644
--- a/gnu/xml/xpath/Expr.java
+++ b/gnu/xml/xpath/Expr.java
@@ -115,7 +115,6 @@ public abstract class Expr
}
- @SuppressWarnings("unchecked")
public Object evaluate(Object item, QName returnType)
throws XPathExpressionException
{
@@ -144,7 +143,10 @@ public abstract class Expr
{
if (ret instanceof Collection)
{
- Collection<Node> ns = (Collection<Node>) ret;
+ /* Suppression is safe, as we know context
+ produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = (Collection<Node>) ret;
switch (ns.size())
{
case 0:
@@ -169,7 +171,12 @@ public abstract class Expr
throw new XPathExpressionException("return value is not a node-set");
}
if (ret != null)
- ret = new ExprNodeSet((Collection<Node>) ret);
+ {
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ ret = new ExprNodeSet(nodes);
+ }
}
}
return ret;
@@ -232,13 +239,14 @@ public abstract class Expr
* same document as the context node that have a unique ID equal to any of
* the tokens in the list.
*/
- @SuppressWarnings("unchecked")
public static Collection<Node> _id(Node context, Object object)
{
Set<Node> ret = new HashSet<Node>();
if (object instanceof Collection)
{
- Collection<Node> nodeSet = (Collection<Node>) object;
+ /* Suppression is safe, as the iteration will check each value is a Node */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); )
{
String string = stringValue(i.next());
@@ -343,7 +351,6 @@ public abstract class Expr
/**
* Implementation of the XPath <code>string</code> function.
*/
- @SuppressWarnings("unchecked")
public static String _string(Node context, Object object)
{
if (object == null)
@@ -392,7 +399,10 @@ public abstract class Expr
}
if (object instanceof Collection)
{
- Collection<Node> nodeSet = (Collection<Node>) object;
+ /* Suppression is safe, as we fail immediately if the
+ * first element is not a Node and don't use the rest */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
if (nodeSet.isEmpty())
{
return "";
@@ -408,7 +418,6 @@ public abstract class Expr
/**
* Implementation of the XPath <code>boolean</code> function.
*/
- @SuppressWarnings("unchecked")
public static boolean _boolean(Node context, Object object)
{
if (object instanceof Boolean)
@@ -428,7 +437,7 @@ public abstract class Expr
}
if (object instanceof Collection)
{
- return ((Collection<Node>) object).size() != 0;
+ return ((Collection<?>) object).size() != 0;
}
return false; // TODO user defined types
}
@@ -438,7 +447,6 @@ public abstract class Expr
/**
* Implementation of the XPath <code>number</code> function.
*/
- @SuppressWarnings("unchecked")
public static double _number(Node context, Object object)
{
if (object == null)
@@ -455,8 +463,12 @@ public abstract class Expr
}
if (object instanceof Collection)
{
+ /* Suppression is safe, as we fail immediately if one
+ * of the elements is not a Node */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
// Convert node-set to string
- object = stringValue((Collection<Node>) object);
+ object = stringValue(nodeSet);
}
if (object instanceof String)
{
diff --git a/gnu/xml/xpath/IdFunction.java b/gnu/xml/xpath/IdFunction.java
index de6d3e4ba..b3d2208c8 100644
--- a/gnu/xml/xpath/IdFunction.java
+++ b/gnu/xml/xpath/IdFunction.java
@@ -72,11 +72,10 @@ public final class IdFunction
this.arg = arg;
}
- @SuppressWarnings("unchecked")
public boolean matches(Node context)
{
Object ret = evaluate(context, 1, 1);
- return !((Collection<Node>) ret).isEmpty();
+ return !((Collection<?>) ret).isEmpty();
}
@Override
diff --git a/gnu/xml/xpath/LocalNameFunction.java b/gnu/xml/xpath/LocalNameFunction.java
index a08a3df5f..dbad9d3b4 100644
--- a/gnu/xml/xpath/LocalNameFunction.java
+++ b/gnu/xml/xpath/LocalNameFunction.java
@@ -69,9 +69,11 @@ final class LocalNameFunction
this.arg = arg;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
Collection<Node> val = (arg == null) ? Collections.singleton(context) :
(Collection<Node>) arg.evaluate(context, pos, len);
return _local_name(context, val);
diff --git a/gnu/xml/xpath/NameFunction.java b/gnu/xml/xpath/NameFunction.java
index 7eefbc25c..239a53453 100644
--- a/gnu/xml/xpath/NameFunction.java
+++ b/gnu/xml/xpath/NameFunction.java
@@ -77,25 +77,30 @@ final class NameFunction
this.arg = arg;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Object val = (arg == null) ? Collections.singleton(context) :
- arg.evaluate(context, pos, len);
- return _name(context, (Collection<Node>) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> val = (arg == null) ? Collections.singleton(context) :
+ (Collection<Node>) arg.evaluate(context, pos, len);
+ return _name(context, val);
}
+ @Override
public Expr clone(Object context)
{
return new NameFunction((arg == null) ? null :
arg.clone(context));
}
-
+
+ @Override
public boolean references(QName var)
{
return (arg == null) ? false : arg.references(var);
}
+ @Override
public String toString()
{
return (arg == null) ? "name()" : "name(" + arg + ")";
diff --git a/gnu/xml/xpath/NamespaceUriFunction.java b/gnu/xml/xpath/NamespaceUriFunction.java
index c988e2aaa..56da90f8c 100644
--- a/gnu/xml/xpath/NamespaceUriFunction.java
+++ b/gnu/xml/xpath/NamespaceUriFunction.java
@@ -69,12 +69,14 @@ final class NamespaceUriFunction
this.arg = arg;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Object val = (arg == null) ? Collections.singleton(context) :
- arg.evaluate(context, pos, len);
- return _namespace_uri(context, (Collection<Node>) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> val = (arg == null) ? Collections.singleton(context) :
+ (Collection<Node>) arg.evaluate(context, pos, len);
+ return _namespace_uri(context, val);
}
public Expr clone(Object context)
diff --git a/gnu/xml/xpath/ParenthesizedExpr.java b/gnu/xml/xpath/ParenthesizedExpr.java
index 5ec3d2938..adadd6745 100644
--- a/gnu/xml/xpath/ParenthesizedExpr.java
+++ b/gnu/xml/xpath/ParenthesizedExpr.java
@@ -60,13 +60,17 @@ final class ParenthesizedExpr
this.expr = expr;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object ret = expr.evaluate(context, pos, len);
if (ret instanceof Collection)
{
- List<Node> list = new ArrayList<Node>((Collection<Node>) ret);
+ /* Suppression is safe, as we know context produces
+ Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ List<Node> list = new ArrayList<Node>(nodes);
Collections.sort(list, documentOrderComparator);
ret = list;
}
diff --git a/gnu/xml/xpath/Steps.java b/gnu/xml/xpath/Steps.java
index de22432c4..427fbe201 100644
--- a/gnu/xml/xpath/Steps.java
+++ b/gnu/xml/xpath/Steps.java
@@ -160,7 +160,7 @@ public final class Steps
return Collections.emptySet();
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
//System.err.println(toString()+" evaluate");
@@ -172,13 +172,16 @@ public final class Steps
while (val instanceof Collection && i.hasNext())
{
Path rhs = (Path) i.next();
- val = rhs.evaluate(context, (Collection<Node>) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) val;
+ val = rhs.evaluate(context, nodes);
//System.err.println("\tevaluate "+rhs+" = "+val);
}
return val;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
Collection<Node> evaluate(Node context, Collection<Node> ns)
{
// Left to right
@@ -197,7 +200,10 @@ public final class Steps
Object ret = lhs.evaluate(node, pos++, len);
if (ret instanceof Collection)
{
- acc.addAll((Collection<Node>) ret);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ acc.addAll(nodes);
}
}
ns = acc;
diff --git a/gnu/xml/xpath/SumFunction.java b/gnu/xml/xpath/SumFunction.java
index ce2989b4b..73db2a91d 100644
--- a/gnu/xml/xpath/SumFunction.java
+++ b/gnu/xml/xpath/SumFunction.java
@@ -66,14 +66,18 @@ final class SumFunction
this.arg = arg;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
double sum = 0.0d;
if (val instanceof Collection)
{
- for (Node node : ((Collection<Node>) val))
+ /* Suppression is safe, as we know context produces
+ Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) val;
+ for (Node node : nodes)
{
String s = stringValue(node);
sum += _number(context, s);
diff --git a/gnu/xml/xpath/UnionExpr.java b/gnu/xml/xpath/UnionExpr.java
index fcaee3d9b..03ae5c06d 100644
--- a/gnu/xml/xpath/UnionExpr.java
+++ b/gnu/xml/xpath/UnionExpr.java
@@ -74,21 +74,29 @@ public final class UnionExpr
return false;
}
- @Override @SuppressWarnings("unchecked")
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object left = lhs.evaluate(context, pos, len);
Object right = rhs.evaluate(context, pos, len);
+ List<Node> list;
if (left instanceof Collection && right instanceof Collection)
{
Set<Node> set = new HashSet<Node>();
- set.addAll ((Collection<Node>) left);
- set.addAll ((Collection<Node>) right);
- List<Node> list = new ArrayList<Node>(set);
+ /* Suppression is safe as addAll will check the types
+ of the elements and throw a ClassCastException as necessary */
+ @SuppressWarnings("unchecked")
+ Collection<Node> l = (Collection<Node>) left;
+ @SuppressWarnings("unchecked")
+ Collection<Node> r = (Collection<Node>) right;
+ set.addAll (l);
+ set.addAll (r);
+ list = new ArrayList<Node>(set);
Collections.sort(list, documentOrderComparator);
- return list;
}
- return Collections.EMPTY_SET;
+ else
+ list = Collections.emptyList();
+ return list;
}
public Expr clone(Object context)
diff --git a/gnu/xml/xpath/XPathParser.java b/gnu/xml/xpath/XPathParser.java
index 300f3161d..e8c8e94da 100644
--- a/gnu/xml/xpath/XPathParser.java
+++ b/gnu/xml/xpath/XPathParser.java
@@ -391,7 +391,6 @@ public class XPathParser
@return result of the last reduction, if any.
@throws yyException on irrecoverable parse error.
*/
- @SuppressWarnings("unchecked")
public Object yyparse (yyInput yyLex)
throws java.io.IOException, yyException {
if (yyMax <= 0) yyMax = 256; // initial size
@@ -566,20 +565,25 @@ case 9:
case 10:
// line 362 "XPathParser.y"
{
- yyVal = new Selector (Selector.CHILD, (List<Test>) yyVals[0+yyTop]);
- }
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (Selector.CHILD, tests);
+ }
break;
case 11:
// line 366 "XPathParser.y"
{
- yyVal = new Selector (Selector.ATTRIBUTE, (List<Test>) yyVals[0+yyTop]);
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (Selector.ATTRIBUTE, tests);
+ }
break;
case 12:
// line 370 "XPathParser.y"
{
- yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List<Test>) yyVals[0+yyTop]);
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), tests);
+ }
break;
case 13:
// line 374 "XPathParser.y"
@@ -606,10 +610,11 @@ case 15:
case 16:
// line 391 "XPathParser.y"
{
- List<Test> list = (List<Test>)yyVals[-1+yyTop];
- list.add((Test) yyVals[0+yyTop]);
- yyVal = list;
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>)yyVals[-1+yyTop];
+ tests.add((Test) yyVals[0+yyTop]);
+ yyVal = tests;
+ }
break;
case 17:
// line 415 "XPathParser.y"
@@ -735,8 +740,10 @@ case 39:
case 40:
// line 512 "XPathParser.y"
{
- yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]);
- }
+ /* This is safe as we create this below */
+ @SuppressWarnings("unchecked") List<Expr> exprs = (List<Expr>) yyVals[-1+yyTop];
+ yyVal = lookupFunction((String) yyVals[-3+yyTop], exprs);
+ }
break;
case 41:
// line 519 "XPathParser.y"
@@ -749,10 +756,11 @@ case 41:
case 42:
// line 525 "XPathParser.y"
{
- List<Expr> list = (List<Expr>) yyVals[0+yyTop];
- list.add(0, (Expr) yyVals[-2+yyTop]);
- yyVal = list;
- }
+ /* This is safe as we create this above */
+ @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) yyVals[0+yyTop];
+ list.add(0, (Expr) yyVals[-2+yyTop]);
+ yyVal = list;
+ }
break;
case 44:
// line 535 "XPathParser.y"
diff --git a/gnu/xml/xpath/XPathParser.y b/gnu/xml/xpath/XPathParser.y
index 520e82384..a6d3fd130 100644
--- a/gnu/xml/xpath/XPathParser.y
+++ b/gnu/xml/xpath/XPathParser.y
@@ -360,15 +360,18 @@ relative_location_path:
step:
step_node_test
{
- $$ = new Selector (Selector.CHILD, (List) $1);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $1;
+ $$ = new Selector (Selector.CHILD, tests);
}
| AT step_node_test
{
- $$ = new Selector (Selector.ATTRIBUTE, (List) $2);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $2;
+ $$ = new Selector (Selector.ATTRIBUTE, tests);
}
| axis_name DOUBLE_COLON step_node_test
{
- $$ = new Selector (((Integer) $1).intValue (), (List) $3);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $3;
+ $$ = new Selector (((Integer) $1).intValue (), tests);
}
| DOT
{
@@ -391,8 +394,9 @@ step_node_test:
}
| step_node_test predicate
{
- List<Test> list = (List<Test>)$1;
- list.add((Test) $2);
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>)$1;
+ tests.add((Test) $2);
$$ = list;
}
;
@@ -508,11 +512,14 @@ primary_expr:
function_call:
function_name LP RP
{
- $$ = lookupFunction((String) $1, Collections.emptyList());
+ List<Expr> emptyList = Collections.emptyList();
+ $$ = lookupFunction((String) $1, emptyList);
}
| function_name LP argument_list RP
{
- $$ = lookupFunction((String) $1, (List) $3);
+ /* This is safe as we create this below */
+ @SuppressWarnings("unchecked") List<Expr> exprs = (List<Expr>) $3;
+ $$ = lookupFunction((String) $1, (List) exprs);
}
;
@@ -525,7 +532,8 @@ argument_list:
}
| expr COMMA argument_list
{
- List<Expr> list = (List<Expr>) $3;
+ /* This is safe as we create this above */
+ @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) $3;
list.add(0, (Expr) $1);
$$ = list;
}