Use Class.asSubclass instead of unchecked cast

This commit is contained in:
Sam Harwell 2012-02-21 07:50:02 -06:00
parent 1970ac240e
commit 05930b04ce
1 changed files with 2 additions and 4 deletions

View File

@ -441,10 +441,8 @@ public class TestPerformance extends BaseTest {
protected ParserFactory getParserFactory(String lexerName, String parserName, String listenerName, final String entryPoint) { protected ParserFactory getParserFactory(String lexerName, String parserName, String listenerName, final String entryPoint) {
try { try {
ClassLoader loader = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader()); ClassLoader loader = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader());
@SuppressWarnings({"unchecked"}) final Class<? extends Lexer> lexerClass = loader.loadClass(lexerName).asSubclass(Lexer.class);
final Class<? extends Lexer> lexerClass = (Class<? extends Lexer>)loader.loadClass(lexerName); final Class<? extends Parser> parserClass = loader.loadClass(parserName).asSubclass(Parser.class);
@SuppressWarnings({"unchecked"})
final Class<? extends Parser> parserClass = (Class<? extends Parser>)loader.loadClass(parserName);
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
final Class<? extends ParseTreeListener<Token>> listenerClass = (Class<? extends ParseTreeListener<Token>>)loader.loadClass(listenerName); final Class<? extends ParseTreeListener<Token>> listenerClass = (Class<? extends ParseTreeListener<Token>>)loader.loadClass(listenerName);
TestPerformance.sharedListener = listenerClass.newInstance(); TestPerformance.sharedListener = listenerClass.newInstance();