[ 
https://issues.apache.org/jira/browse/GROOVY-11263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801490#comment-17801490
 ] 

ASF GitHub Bot commented on GROOVY-11263:
-----------------------------------------

blackdrag commented on code in PR #2023:
URL: https://github.com/apache/groovy/pull/2023#discussion_r1438940188


##########
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:
   why do you need the source unit? I think there is also a conceptional 
mistake. I may be wrong though, but do we not reuse the Verifier for multiple 
source units? If yes, then having the source unit in the constructor there is 
wrong. If you really need the source unit you should use a setter in case of 
the Verifier I think





> 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)

Reply via email to