[ https://issues.apache.org/jira/browse/GROOVY-11263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801496#comment-17801496 ]
ASF GitHub Bot commented on GROOVY-11263: ----------------------------------------- daniellansun commented on code in PR #2023: URL: https://github.com/apache/groovy/pull/2023#discussion_r1438949628 ########## src/main/java/org/codehaus/groovy/classgen/DeadCodeAnalyzer.java: ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.codehaus.groovy.classgen; + +import org.codehaus.groovy.ast.ClassCodeVisitorSupport; +import org.codehaus.groovy.ast.stmt.BlockStatement; +import org.codehaus.groovy.ast.stmt.BreakStatement; +import org.codehaus.groovy.ast.stmt.ContinueStatement; +import org.codehaus.groovy.ast.stmt.ReturnStatement; +import org.codehaus.groovy.ast.stmt.Statement; +import org.codehaus.groovy.control.SourceUnit; + +/** + * Analyze AST for dead code + * + * @since 5.0.0 + */ +public class DeadCodeAnalyzer extends ClassCodeVisitorSupport { + + private final SourceUnit sourceUnit; + + public DeadCodeAnalyzer(final SourceUnit sourceUnit) { + this.sourceUnit = sourceUnit; + } + + @Override + protected SourceUnit getSourceUnit() { + return sourceUnit; Review Comment: The method `org.codehaus.groovy.ast.ClassCodeVisitorSupport#addError` needs source unit, I use `addError` to collect and report errors. ``` @Override public void addError(final String error, final ASTNode node) { getSourceUnit().addErrorAndContinue(new SyntaxException(error + '\n', node)); } ``` > Analyze dead code > ----------------- > > Key: GROOVY-11263 > URL: https://issues.apache.org/jira/browse/GROOVY-11263 > Project: Groovy > Issue Type: Improvement > Reporter: Daniel Sun > Priority: Major > Labels: breaking_change > > Groovy allows dead code after {{return}}, {{break}} and {{continue}}, e.g. > {code:java} > def m() { > return > def a = 1 > } > {code} > It's better to avoid such dead code. -- This message was sent by Atlassian Jira (v8.20.10#820010)