From 44ef41ff29e95d49402830e8f34c326ca34684e1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 18 Jul 2012 12:32:37 -0500 Subject: [PATCH] Remove unnecessary variable initializations --- .../src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java | 4 ++-- runtime/Java/src/org/antlr/v4/runtime/misc/LogManager.java | 4 ++-- runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java | 2 +- tool/src/org/antlr/v4/Tool.java | 4 ++-- .../org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java | 2 +- tool/src/org/antlr/v4/automata/ATNPrinter.java | 2 +- tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java | 2 +- tool/src/org/antlr/v4/parse/ToolANTLRParser.java | 2 +- tool/src/org/antlr/v4/semantics/RuleCollector.java | 2 +- tool/src/org/antlr/v4/semantics/SymbolChecks.java | 4 ++-- tool/src/org/antlr/v4/tool/Grammar.java | 6 +++--- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java index c19d75778..2a98f5b9e 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java @@ -112,7 +112,7 @@ public class ParserATNPathFinder extends ParserATNSimulator { int n = s.getNumberOfTransitions(); boolean aGoodPath = false; - TraceTree found = null; + TraceTree found; for (int j=0; j { TraceTree root, Transition t) { SemanticContext.Predicate pred = ((PredicateTransition) t).getPredicate(); - boolean pass = false; + boolean pass; if ( pred.isCtxDependent ) { if ( ctx instanceof ParserRuleContext && ctx==initialContext ) { System.out.println("eval pred "+pred+"="+pred.eval(parser, ctx)); diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/LogManager.java b/runtime/Java/src/org/antlr/v4/runtime/misc/LogManager.java index cce9a4214..3222716ec 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/LogManager.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/LogManager.java @@ -90,8 +90,8 @@ public class LogManager { } public String save() throws IOException { - String dir = System.getProperty("java.io.tmpdir"); - dir = "."; + //String dir = System.getProperty("java.io.tmpdir"); + String dir = "."; String defaultFilename = dir + "/antlr-" + new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss").format(new Date()) + ".log"; diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java b/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java index b22fa22d9..fc67e8a98 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java @@ -127,7 +127,7 @@ public class TestRig { // System.out.println("exec "+grammarName+"."+startRuleName); String lexerName = grammarName+"Lexer"; ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Class lexerClass = null; + Class lexerClass; try { lexerClass = cl.loadClass(lexerName); } diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 097f87474..dd7221b56 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -306,8 +306,8 @@ public class Tool { GrammarTransformPipeline transform = new GrammarTransformPipeline(g, this); transform.process(); - LexerGrammar lexerg = null; - GrammarRootAST lexerAST = null; + LexerGrammar lexerg; + GrammarRootAST lexerAST; if ( g.ast!=null && g.ast.grammarType== ANTLRParser.COMBINED && !g.ast.hasErrors ) { diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java index fd70c683e..8972493a9 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java @@ -115,7 +115,7 @@ public class LeftRecursiveRuleTransformer { String ruleName = prevRuleAST.getChild(0).getText(); LeftRecursiveRuleAnalyzer leftRecursiveRuleWalker = new LeftRecursiveRuleAnalyzer(tokens, prevRuleAST, tool, ruleName, language); - boolean isLeftRec = false; + boolean isLeftRec; try { // System.out.println("TESTING ---------------\n"+ // leftRecursiveRuleWalker.text(ruleAST)); diff --git a/tool/src/org/antlr/v4/automata/ATNPrinter.java b/tool/src/org/antlr/v4/automata/ATNPrinter.java index 4d4eeba82..41ced4639 100644 --- a/tool/src/org/antlr/v4/automata/ATNPrinter.java +++ b/tool/src/org/antlr/v4/automata/ATNPrinter.java @@ -57,7 +57,7 @@ public class ATNPrinter { work.add(start); StringBuilder buf = new StringBuilder(); - ATNState s = null; + ATNState s; while ( !work.isEmpty() ) { s = work.remove(0); diff --git a/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java b/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java index 455db744f..fe73da6f9 100644 --- a/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java +++ b/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java @@ -50,7 +50,7 @@ public class GrammarASTAdaptor extends CommonTreeAdaptor { @Override /** Make sure even imaginary nodes know the input stream */ public Object create(int tokenType, String text) { - GrammarAST t = null; + GrammarAST t; if ( tokenType==ANTLRParser.RULE ) { // needed by TreeWizard to make RULE tree t = new RuleAST(new CommonToken(tokenType, text)); diff --git a/tool/src/org/antlr/v4/parse/ToolANTLRParser.java b/tool/src/org/antlr/v4/parse/ToolANTLRParser.java index b039e29a1..7eea31821 100644 --- a/tool/src/org/antlr/v4/parse/ToolANTLRParser.java +++ b/tool/src/org/antlr/v4/parse/ToolANTLRParser.java @@ -59,7 +59,7 @@ public class ToolANTLRParser extends ANTLRParser { } public String getParserErrorMessage(Parser parser, RecognitionException e) { - String msg = null; + String msg; if ( e instanceof NoViableAltException) { String name = parser.getTokenErrorDisplay(e.token); msg = name+" came as a complete surprise to me"; diff --git a/tool/src/org/antlr/v4/semantics/RuleCollector.java b/tool/src/org/antlr/v4/semantics/RuleCollector.java index 3ce7baace..129732633 100644 --- a/tool/src/org/antlr/v4/semantics/RuleCollector.java +++ b/tool/src/org/antlr/v4/semantics/RuleCollector.java @@ -62,7 +62,7 @@ public class RuleCollector extends GrammarTreeVisitor { GrammarAST block) { int numAlts = block.getChildCount(); - Rule r = null; + Rule r; if ( LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(rule, ID.getText()) ) { r = new LeftRecursiveRule(g, ID.getText(), rule); } diff --git a/tool/src/org/antlr/v4/semantics/SymbolChecks.java b/tool/src/org/antlr/v4/semantics/SymbolChecks.java index 75d068f38..3da44bb26 100644 --- a/tool/src/org/antlr/v4/semantics/SymbolChecks.java +++ b/tool/src/org/antlr/v4/semantics/SymbolChecks.java @@ -103,8 +103,8 @@ public class SymbolChecks { public void checkActionRedefinitions(List actions) { if ( actions==null ) return; String scope = g.getDefaultActionScope(); - String name = null; - GrammarAST nameNode = null; + String name; + GrammarAST nameNode; for (GrammarAST ampersandAST : actions) { nameNode = (GrammarAST)ampersandAST.getChild(0); if ( ampersandAST.getChildCount()==2 ) { diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java index d94d405a7..6bf65787f 100644 --- a/tool/src/org/antlr/v4/tool/Grammar.java +++ b/tool/src/org/antlr/v4/tool/Grammar.java @@ -420,7 +420,7 @@ public class Grammar implements AttributeResolver { } public int getTokenType(String token) { - Integer I = null; + Integer I; if ( token.charAt(0)=='\'') { I = stringLiteralToTypeMap.get(token); } @@ -437,7 +437,7 @@ public class Grammar implements AttributeResolver { * char vocabulary, compute an ANTLR-valid (possibly escaped) char literal. */ public String getTokenDisplayName(int ttype) { - String tokenName = null; + String tokenName; // inside any target's char range and is lexer grammar? if ( isLexer() && ttype >= Lexer.MIN_CHAR_VALUE && ttype <= Lexer.MAX_CHAR_VALUE ) @@ -766,7 +766,7 @@ public class Grammar implements AttributeResolver { Tree name = r.getChild(0); if ( name.getType()==ANTLRParser.TOKEN_REF ) { // check rule against patterns - boolean isLitRule = false; + boolean isLitRule; for (String pattern : patterns) { isLitRule = defAlias(r, pattern, wiz, lexerRuleToStringLiteral);