Java 1.5 source update / warning removal.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1478 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index 3495437..d103fd7 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -68,6 +68,7 @@
/**
* Short circuit binary operations.
*/
+ @Override
public void endVisit(JBinaryOperation x, Context ctx) {
JBinaryOperator op = x.getOp();
JExpression lhs = x.getLhs();
@@ -144,6 +145,7 @@
/**
* Prune empty blocks.
*/
+ @Override
public void endVisit(JBlock x, Context ctx) {
if (x.statements.size() == 0) {
if (ctx.canRemove()) {
@@ -152,6 +154,7 @@
}
}
+ @Override
public void endVisit(JConditional x, Context ctx) {
JExpression condExpr = x.getIfTest();
JExpression thenExpr = x.getThenExpr();
@@ -202,6 +205,7 @@
/**
* Convert do { } while (false); into a block.
*/
+ @Override
public void endVisit(JDoStatement x, Context ctx) {
JExpression expression = x.getTestExpr();
if (expression instanceof JBooleanLiteral) {
@@ -219,6 +223,7 @@
}
}
+ @Override
public void endVisit(JExpressionStatement x, Context ctx) {
if (!x.getExpr().hasSideEffects()) {
removeMe(x, ctx);
@@ -228,6 +233,7 @@
/**
* Prune for (X; false; Y) statements, but make sure X is run.
*/
+ @Override
public void endVisit(JForStatement x, Context ctx) {
JExpression expression = x.getTestExpr();
if (expression instanceof JBooleanLiteral) {
@@ -245,6 +251,7 @@
/**
* Simplify if statements.
*/
+ @Override
public void endVisit(JIfStatement x, Context ctx) {
JExpression expr = x.getIfExpr();
JStatement thenStmt = x.getThenStmt();
@@ -270,6 +277,7 @@
/**
* Resolve method calls that can be computed statically.
*/
+ @Override
public void endVisit(JMethodCall x, Context ctx) {
JMethod method = x.getTarget();
if (method.getEnclosingType() == program.getTypeJavaLangString()) {
@@ -280,6 +288,7 @@
/**
* Simplify the ! operator if possible.
*/
+ @Override
public void endVisit(JPrefixOperation x, Context ctx) {
if (x.getOp() == JUnaryOperator.NOT) {
JExpression arg = x.getArg();
@@ -334,12 +343,15 @@
* try statements with no body. 3) Hoist up try statements with no catches
* and an empty finally.
*/
+ @Override
public void endVisit(JTryStatement x, Context ctx) {
// 1) Remove catch blocks whose exception type is not instantiable.
- List catchArgs = x.getCatchArgs();
- List catchBlocks = x.getCatchBlocks();
- for (Iterator itA = catchArgs.iterator(), itB = catchBlocks.iterator(); itA.hasNext();) {
- JLocalRef localRef = (JLocalRef) itA.next();
+ List<JLocalRef> catchArgs = x.getCatchArgs();
+ List<JBlock> catchBlocks = x.getCatchBlocks();
+ Iterator<JLocalRef> itA = catchArgs.iterator();
+ Iterator<JBlock> itB = catchBlocks.iterator();
+ while (itA.hasNext()) {
+ JLocalRef localRef = itA.next();
itB.next();
JReferenceType type = (JReferenceType) localRef.getType();
if (!program.typeOracle.isInstantiatedType(type)
@@ -374,6 +386,7 @@
/**
* Prune while (false) statements.
*/
+ @Override
public void endVisit(JWhileStatement x, Context ctx) {
JExpression expression = x.getTestExpr();
if (expression instanceof JBooleanLiteral) {
@@ -396,8 +409,8 @@
return (stmt instanceof JBlock && ((JBlock) stmt).statements.isEmpty());
}
- private Class mapType(JType type) {
- return (Class) typeClassMap.get(type);
+ private Class<?> mapType(JType type) {
+ return typeClassMap.get(type);
}
private void removeMe(JStatement stmt, Context ctx) {
@@ -424,8 +437,7 @@
if (program.isStaticImpl(method)) {
// is it static implementation for instance method?
method = program.staticImplFor(method);
- instance = tryTranslateLiteral((JExpression) x.getArgs().get(0),
- String.class);
+ instance = tryTranslateLiteral(x.getArgs().get(0), String.class);
skip = 1;
} else {
// instance may be null
@@ -436,17 +448,16 @@
return;
}
- List params = method.getOriginalParamTypes();
- Class paramTypes[] = new Class[params.size()];
+ List<JType> params = method.getOriginalParamTypes();
+ Class<?> paramTypes[] = new Class<?>[params.size()];
Object paramValues[] = new Object[params.size()];
- ArrayList args = x.getArgs();
+ ArrayList<JExpression> args = x.getArgs();
for (int i = 0; i != params.size(); ++i) {
- paramTypes[i] = mapType((JType) params.get(i));
+ paramTypes[i] = mapType(params.get(i));
if (paramTypes[i] == null) {
return;
}
- paramValues[i] = tryTranslateLiteral((JExpression) args.get(i + skip),
- paramTypes[i]);
+ paramValues[i] = tryTranslateLiteral(args.get(i + skip), paramTypes[i]);
if (paramValues[i] == null) {
return;
}
@@ -466,16 +477,13 @@
ctx.replaceMe(program.getLiteralChar(((Character) result).charValue()));
} else if (result instanceof Integer) {
ctx.replaceMe(program.getLiteralInt(((Integer) result).intValue()));
- } else {
- boolean stopHere = true;
}
} catch (Exception e) {
// If the call threw an exception, just don't optimize
- boolean stopHere = true;
}
}
- private Object tryTranslateLiteral(JExpression maybeLit, Class type) {
+ private Object tryTranslateLiteral(JExpression maybeLit, Class<?> type) {
if (!(maybeLit instanceof JValueLiteral)) {
return null;
}
@@ -515,10 +523,12 @@
public static class FindBreakContinueStatementsVisitor extends JVisitor {
private boolean hasBreakContinueStatements = false;
+ @Override
public void endVisit(JBreakStatement x, Context ctx) {
hasBreakContinueStatements = true;
}
+ @Override
public void endVisit(JContinueStatement x, Context ctx) {
hasBreakContinueStatements = true;
}
@@ -534,7 +544,7 @@
private final JProgram program;
- private final Map typeClassMap = new IdentityHashMap();
+ private final Map<JType, Class<?>> typeClassMap = new IdentityHashMap<JType, Class<?>>();
public DeadCodeElimination(JProgram program) {
this.program = program;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
index 6e6f30a..f5bc249 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
@@ -42,7 +42,6 @@
import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -82,12 +81,12 @@
this.thisParam = thisParam;
}
- // @Override
+ @Override
public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
ctx.replaceMe(thisParam.makeRef());
}
- // @Override
+ @Override
public boolean visit(JsFunction x, JsContext<JsExpression> ctx) {
// Don't recurse into nested functions!
return false;
@@ -102,23 +101,23 @@
private class RewriteMethodBody extends JModVisitor {
private final JParameter thisParam;
- private final Map/* <JVariable, JVariable> */varMap;
+ private final Map<JParameter, JParameter> varMap;
public RewriteMethodBody(JParameter thisParam,
- Map/* <JVariable, JVariable> */varMap) {
+ Map<JParameter, JParameter> varMap) {
this.thisParam = thisParam;
this.varMap = varMap;
}
- // @Override
+ @Override
public void endVisit(JParameterRef x, Context ctx) {
- JParameter param = (JParameter) varMap.get(x.getTarget());
+ JParameter param = varMap.get(x.getTarget());
JParameterRef paramRef = new JParameterRef(program, x.getSourceInfo(),
param);
ctx.replaceMe(paramRef);
}
- // @Override
+ @Override
public void endVisit(JThisRef x, Context ctx) {
JParameterRef paramRef = new JParameterRef(program, x.getSourceInfo(),
thisParam);
@@ -126,7 +125,7 @@
}
}
- // @Override
+ @Override
public boolean visit(JMethod x, Context ctx) {
// Let's do it!
JClassType enclosingType = (JClassType) x.getEnclosingType();
@@ -148,9 +147,9 @@
// Setup parameters; map from the old params to the new params
JParameter thisParam = program.createParameter(null,
"this$static".toCharArray(), enclosingType, true, newMethod);
- Map/* <JVariable, JVariable> */varMap = new IdentityHashMap();
+ Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
for (int i = 0; i < x.params.size(); ++i) {
- JParameter oldVar = (JParameter) x.params.get(i);
+ JParameter oldVar = x.params.get(i);
JParameter newVar = program.createParameter(oldVar.getSourceInfo(),
oldVar.getName().toCharArray(), oldVar.getType(), oldVar.isFinal(),
newMethod);
@@ -169,7 +168,7 @@
newMethod);
newCall.getArgs().add(program.getExprThisRef(sourceInfo, enclosingType));
for (int i = 0; i < x.params.size(); ++i) {
- JParameter param = (JParameter) x.params.get(i);
+ JParameter param = x.params.get(i);
newCall.getArgs().add(new JParameterRef(program, sourceInfo, param));
}
JStatement statement;
@@ -212,7 +211,7 @@
*/
private class FindStaticDispatchSitesVisitor extends JVisitor {
- // @Override
+ @Override
public void endVisit(JMethodCall x, Context ctx) {
JMethod method = x.getTarget();
@@ -254,7 +253,7 @@
* instance methods, rewrite the call site to reference the newly-generated
* static method instead.
*/
- // @Override
+ @Override
public void endVisit(JMethodCall x, Context ctx) {
JMethod oldMethod = x.getTarget();
JMethod newMethod = program.getStaticImpl(oldMethod);
@@ -280,7 +279,7 @@
return new MakeCallsStatic(program).execImpl();
}
- public Set toBeMadeStatic = new HashSet();
+ public Set<JMethod> toBeMadeStatic = new HashSet<JMethod>();
private final JProgram program;
@@ -296,8 +295,7 @@
}
CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor();
- for (Iterator it = toBeMadeStatic.iterator(); it.hasNext();) {
- JMethod method = (JMethod) it.next();
+ for (JMethod method : toBeMadeStatic) {
creator.accept(method);
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
index 032fea4..53ff0de 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -81,6 +81,7 @@
*/
private class CleanupRefsVisitor extends JModVisitor {
+ @Override
public void endVisit(JBinaryOperation x, Context ctx) {
// The LHS of assignments may have been pruned.
if (x.getOp() == JBinaryOperator.ASG) {
@@ -107,18 +108,19 @@
private boolean didChange = false;
+ @Override
public boolean didChange() {
return didChange;
}
- // @Override
+ @Override
public boolean visit(JClassType type, Context ctx) {
assert (referencedTypes.contains(type));
boolean isInstantiated = program.typeOracle.isInstantiatedType(type);
- for (Iterator it = type.fields.iterator(); it.hasNext();) {
- JField field = (JField) it.next();
+ for (Iterator<JField> it = type.fields.iterator(); it.hasNext();) {
+ JField field = it.next();
if (!referencedNonTypes.contains(field)
|| pruneViaNoninstantiability(isInstantiated, field)) {
it.remove();
@@ -126,8 +128,8 @@
}
}
- for (Iterator it = type.methods.iterator(); it.hasNext();) {
- JMethod method = (JMethod) it.next();
+ for (Iterator<JMethod> it = type.methods.iterator(); it.hasNext();) {
+ JMethod method = it.next();
if (!methodIsReferenced(method)
|| pruneViaNoninstantiability(isInstantiated, method)) {
it.remove();
@@ -140,13 +142,13 @@
return false;
}
- // @Override
+ @Override
public boolean visit(JInterfaceType type, Context ctx) {
boolean isReferenced = referencedTypes.contains(type);
boolean isInstantiated = program.typeOracle.isInstantiatedType(type);
- for (Iterator it = type.fields.iterator(); it.hasNext();) {
- JField field = (JField) it.next();
+ for (Iterator<JField> it = type.fields.iterator(); it.hasNext();) {
+ JField field = it.next();
// all interface fields are static and final
if (!isReferenced || !referencedNonTypes.contains(field)) {
it.remove();
@@ -154,13 +156,13 @@
}
}
- Iterator it = type.methods.iterator();
+ Iterator<JMethod> it = type.methods.iterator();
if (it.hasNext()) {
// start at index 1; never prune clinit directly out of the interface
it.next();
}
while (it.hasNext()) {
- JMethod method = (JMethod) it.next();
+ JMethod method = it.next();
// all other interface methods are instance and abstract
if (!isInstantiated || !methodIsReferenced(method)) {
it.remove();
@@ -171,9 +173,10 @@
return false;
}
+ @Override
public boolean visit(JMethodBody x, Context ctx) {
- for (Iterator it = x.locals.iterator(); it.hasNext();) {
- JLocal local = (JLocal) it.next();
+ for (Iterator<JLocal> it = x.locals.iterator(); it.hasNext();) {
+ JLocal local = it.next();
if (!referencedNonTypes.contains(local)) {
it.remove();
didChange = true;
@@ -182,10 +185,10 @@
return false;
}
- // @Override
+ @Override
public boolean visit(JProgram program, Context ctx) {
- for (Iterator it = program.getDeclaredTypes().iterator(); it.hasNext();) {
- JReferenceType type = (JReferenceType) it.next();
+ for (Iterator<JReferenceType> it = program.getDeclaredTypes().iterator(); it.hasNext();) {
+ JReferenceType type = it.next();
if (referencedTypes.contains(type)
|| program.typeOracle.isInstantiatedType(type)) {
accept(type);
@@ -264,7 +267,7 @@
}
for (int i = 0; i < rLeafType.implments.size(); ++i) {
- JInterfaceType intfType = (JInterfaceType) rLeafType.implments.get(i);
+ JInterfaceType intfType = rLeafType.implments.get(i);
JArrayType intfArray = program.getTypeArray(intfType, dims);
rescue(intfArray, true, isInstantiated);
}
@@ -273,6 +276,7 @@
return false;
}
+ @Override
public boolean visit(JBinaryOperation x, Context ctx) {
// special string concat handling
if (x.getOp() == JBinaryOperator.ADD
@@ -322,7 +326,7 @@
return true;
}
- // @Override
+ @Override
public boolean visit(JClassLiteral literal, Context ctx) {
// rescue and instantiate java.lang.Class
// JLS 12.4.1: do not rescue the target type
@@ -330,7 +334,7 @@
return true;
}
- // @Override
+ @Override
public boolean visit(JClassType type, Context ctx) {
assert (referencedTypes.contains(type));
boolean isInstantiated = instantiatedTypes.contains(type);
@@ -342,7 +346,7 @@
*/
if (saveCodeGenTypes && program.codeGenTypes.contains(type)) {
for (int i = 0; i < type.methods.size(); ++i) {
- JMethod it = (JMethod) type.methods.get(i);
+ JMethod it = type.methods.get(i);
rescue(it);
}
}
@@ -351,19 +355,19 @@
rescue(type.extnds, true, isInstantiated);
// Rescue my clinit (it won't ever be explicitly referenced
- rescue((JMethod) type.methods.get(0));
+ rescue(type.methods.get(0));
// JLS 12.4.1: don't rescue my super interfaces just because I'm rescued.
// However, if I'm instantiated, let's mark them as instantiated.
for (int i = 0; i < type.implments.size(); ++i) {
- JInterfaceType intfType = (JInterfaceType) type.implments.get(i);
+ JInterfaceType intfType = type.implments.get(i);
rescue(intfType, false, isInstantiated);
}
return false;
}
- // @Override
+ @Override
public boolean visit(JFieldRef ref, Context ctx) {
JField target = ref.getField();
@@ -382,41 +386,41 @@
return true;
}
- // @Override
+ @Override
public boolean visit(JInterfaceType type, Context ctx) {
boolean isReferenced = referencedTypes.contains(type);
boolean isInstantiated = instantiatedTypes.contains(type);
assert (isReferenced || isInstantiated);
// Rescue my clinit (it won't ever be explicitly referenced
- rescue((JMethod) type.methods.get(0));
+ rescue(type.methods.get(0));
// JLS 12.4.1: don't rescue my super interfaces just because I'm rescued.
// However, if I'm instantiated, let's mark them as instantiated.
if (isInstantiated) {
for (int i = 0; i < type.implments.size(); ++i) {
- JInterfaceType intfType = (JInterfaceType) type.implments.get(i);
+ JInterfaceType intfType = type.implments.get(i);
rescue(intfType, false, true);
}
}
// visit any field initializers
for (int i = 0; i < type.fields.size(); ++i) {
- JField it = (JField) type.fields.get(i);
+ JField it = type.fields.get(i);
accept(it);
}
return false;
}
- // @Override
+ @Override
public boolean visit(JLocalRef ref, Context ctx) {
JLocal target = ref.getLocal();
rescue(target);
return true;
}
- // @Override
+ @Override
public boolean visit(JMethodCall call, Context ctx) {
JMethod target = call.getTarget();
// JLS 12.4.1: references to static methods rescue the enclosing class
@@ -427,7 +431,7 @@
return true;
}
- // @Override
+ @Override
public boolean visit(JNewArray newArray, Context ctx) {
// rescue and instantiate the array type
JArrayType arrayType = newArray.getArrayType();
@@ -449,14 +453,14 @@
return true;
}
- // @Override
+ @Override
public boolean visit(JNewInstance newInstance, Context ctx) {
// rescue and instantiate the target class!
rescue(newInstance.getClassType(), true, true);
return true;
}
- // @Override
+ @Override
public boolean visit(JsniFieldRef x, Context ctx) {
/*
* SPECIAL: this could be an assignment that passes a value from
@@ -578,7 +582,7 @@
*/
if (stringValueOfChar == null) {
for (int i = 0; i < stringType.methods.size(); ++i) {
- JMethod meth = (JMethod) stringType.methods.get(i);
+ JMethod meth = stringType.methods.get(i);
if (meth.getName().equals("valueOf")) {
List<JType> params = meth.getOriginalParamTypes();
if (params.size() == 1) {
@@ -613,14 +617,14 @@
return didRescue;
}
- // @Override
+ @Override
public boolean visit(JMethod x, Context ctx) {
if (referencedNonTypes.contains(x)) {
return false;
}
for (int i = 0; i < x.overrides.size(); ++i) {
- JMethod ref = (JMethod) x.overrides.get(i);
+ JMethod ref = x.overrides.get(i);
if (referencedNonTypes.contains(ref)) {
rescuer.rescue(x);
didRescue = true;
@@ -639,7 +643,7 @@
return false;
}
- // @Override
+ @Override
public boolean visit(JProgram x, Context ctx) {
didRescue = false;
return true;