diff --git a/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/RubyVisitor.java b/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/RubyVisitor.java index 4353608..9059300 100644 --- a/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/RubyVisitor.java +++ b/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/RubyVisitor.java @@ -94,6 +94,7 @@ public class RubyVisitor { + private static final String BEGIN_ATTRIBUTE = "begin"; private static final String KEYWORD_ATTRIBUTE = "keyword"; private static final List EXCEPTION_BLOCK_TYPES = asList("resbody", "rescue", "ensure"); private static final Map BINARY_OPERATOR_MAP; @@ -160,7 +161,7 @@ public Tree visitNode(AstNode node, List children) { case "arg", "optarg", "restarg", "kwarg", "kwoptarg", "kwrestarg", "blockarg", "procarg0", "shadowarg": // note obj-c arguments are not supported https://github.com/whitequark/parser/blob/master/doc/AST_FORMAT.md#objective-c-arguments return createParameterTree(node, children); - case "begin": + case BEGIN_ATTRIBUTE: return createFromBeginNode(node, children); case "kwbegin": return createFromKwBeginNode(node, children); @@ -592,7 +593,7 @@ private Tree createStringLiteralTree(AstNode node, List children) { if (RubyConverter.FILENAME.equals(value)) { return createNativeTree(node, children); } - TextRange begin = node.textRangeForAttribute("begin"); + TextRange begin = node.textRangeForAttribute(BEGIN_ATTRIBUTE); TextRange end = node.textRangeForAttribute("end"); TreeMetaData treeMetaData; if (begin != null && end != null) { @@ -649,7 +650,7 @@ private Tree createLogicalOperation(AstNode node, List children, Operator ope } private Tree createFromBeginNode(AstNode node, List children) { - Optional beginToken = lookForTokenByAttribute(node, "begin"); + Optional beginToken = lookForTokenByAttribute(node, BEGIN_ATTRIBUTE); Optional endToken = lookForTokenByAttribute(node, "end"); if (beginToken.isPresent() && endToken.isPresent() && children.size() == 1 && beginToken.get().text().equals("(")) { return new ParenthesizedExpressionTreeImpl(metaData(node), ((Tree) children.get(0)), beginToken.get(), endToken.get());