refactor: prevent casting by setting proper types
package brut.androlib.mod;
import java.io.*;
+import java.nio.charset.StandardCharsets;
+
import org.antlr.runtime.*;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
@@ -54,14 +56,14 @@ public class SmaliMod {
boolean printTokens) throws IOException, RecognitionException {
CommonTokenStream tokens;
- LexerErrorInterface lexer;
+ smaliFlexLexer lexer;
InputStream is = new FileInputStream(smaliFile);
- InputStreamReader reader = new InputStreamReader(is, "UTF-8");
+ InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
lexer = new smaliFlexLexer(reader, apiLevel);
- ((smaliFlexLexer)lexer).setSourceFile(smaliFile);
- tokens = new CommonTokenStream((TokenSource) lexer);
+ (lexer).setSourceFile(smaliFile);
+ tokens = new CommonTokenStream(lexer);
if (printTokens) {
tokens.getTokens();
@@ -88,7 +90,7 @@ public class SmaliMod {
return false;
}
- CommonTree t = (CommonTree) result.getTree();
+ CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
