Copilot commented on code in PR #2324: URL: https://github.com/apache/groovy/pull/2324#discussion_r2466738828
########## src/main/java/groovy/util/concurrent/async/SimplePromise.java: ########## @@ -0,0 +1,516 @@ +/* + * 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 groovy.util.concurrent.async; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * A simple implementation of {@link Promise} based on {@link CompletableFuture}. + * + * @since 6.0.0 + */ +public class SimplePromise<T> implements Promise<T> { + private final CompletableFuture<T> future; + + private SimplePromise(CompletableFuture<T> future) { + this.future = future; + } + + /** + * Creates a new Promise backed by the given CompletableFuture. + * + * @param future the CompletableFuture to back the Promise + * @param <T> the type of the Promise's result + * @return the new Promise + */ + public static <T> SimplePromise<T> of(CompletableFuture<T> future) { + return new SimplePromise<>(future); + } + + /** + * Returns a new Promise that is not yet completed. + * + * @param <T> the type of the Promise's result + * @return the new Promise + */ + public static <T> SimplePromise<T> of() { + return of(new CompletableFuture<>()); + } + + /** + * Returns a new Promise that is asynchronously completed by a task running in + * the {@link ForkJoinPool#commonPool()} with the value obtained by calling the + * provided Supplier. + * + * @param supplier a function returning the value to be used to complete the + * returned Promise + * @param <U> the function's return type + * @return the new Promise + */ + public static <U> SimplePromise<U> of(Supplier<U> supplier) { + return of(CompletableFuture.supplyAsync(supplier)); + } + + /** + * Returns a new Promise that is asynchronously completed by a task running in + * the provided executor with the value obtained by calling the provided Supplier. + * + * @param supplier a function returning the value to be used to complete the + * returned Promise + * @param executor the executor to use for asynchronous execution + * @param <U> the function's return type + * @return the new Promise + */ + public static <U> SimplePromise<U> of(Supplier<U> supplier, Executor executor) { + return of(CompletableFuture.supplyAsync(supplier, executor)); + } + +// /** +// * Returns a new Promise that is asynchronously completed by a task running in +// * the {@link ForkJoinPool#commonPool()} after it runs the provided action. +// * +// * @param runnable the action to run before completing the returned Promise +// * @return the new Promise +// */ +// public static SimplePromise<Void> of(Runnable runnable) { +// return of(CompletableFuture.runAsync(runnable)); +// } +// +// /** +// * Returns a new Promise that is asynchronously completed by a task running in +// * the provided executor after it runs the provided action. +// * +// * @param runnable the action to run before completing the returned Promise +// * @param executor the executor to use for asynchronous execution +// * @return the new Promise +// */ +// public static SimplePromise<Void> of(Runnable runnable, Executor executor) { +// return of(CompletableFuture.runAsync(runnable, executor)); +// } + Review Comment: These commented-out methods should either be removed or uncommented with a clear explanation of why they were included/excluded. Leaving large blocks of commented code in production reduces clarity about the intended API surface. ```suggestion ``` ########## src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java: ########## @@ -151,16 +155,222 @@ import java.util.stream.Collectors; import static groovy.lang.Tuple.tuple; -import static org.apache.groovy.parser.antlr4.GroovyParser.*; +import static org.apache.groovy.parser.antlr4.GroovyParser.ADD; +import static org.apache.groovy.parser.antlr4.GroovyParser.ARROW; +import static org.apache.groovy.parser.antlr4.GroovyParser.AS; +import static org.apache.groovy.parser.antlr4.GroovyParser.ASYNC; +import static org.apache.groovy.parser.antlr4.GroovyParser.AdditiveExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AndExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AnnotatedQualifiedClassNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AnnotationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AnnotationNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AnnotationsOptContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AnonymousInnerClassDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ArgumentsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ArrayInitializerContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AssertStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.AssignmentExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BlockContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BlockStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BlockStatementsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BlockStatementsOptContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BooleanLiteralAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BreakStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.BuiltInTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CASE; +import static org.apache.groovy.parser.antlr4.GroovyParser.CastExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CastParExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CatchClauseContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CatchTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassBodyContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassBodyDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassOrInterfaceModifierContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassOrInterfaceModifiersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClassOrInterfaceModifiersOptContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClosureContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ClosureOrLambdaExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CommandArgumentContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CommandExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CommandExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CompactConstructorDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CompilationUnitContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ConditionalExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ConditionalStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ContinueStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CreatedNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.CreatorContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.DEC; +import static org.apache.groovy.parser.antlr4.GroovyParser.DEF; +import static org.apache.groovy.parser.antlr4.GroovyParser.DEFAULT; +import static org.apache.groovy.parser.antlr4.GroovyParser.DoWhileStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.DynamicMemberNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ElementValueArrayInitializerContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ElementValueContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ElementValuePairContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ElementValuePairsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ElementValuesContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnhancedArgumentListElementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnhancedArgumentListInParContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnhancedExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnhancedForControlContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnhancedStatementExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnumConstantContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EnumConstantsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.EqualityExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ExclusiveOrExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ExpressionInParContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ExpressionListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ExpressionListElementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FINAL; +import static org.apache.groovy.parser.antlr4.GroovyParser.FieldDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FinallyBlockContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FloatingPointLiteralAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ForControlContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ForInitContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ForStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ForUpdateContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FormalParameterContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FormalParameterListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.FormalParametersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.GE; +import static org.apache.groovy.parser.antlr4.GroovyParser.GT; +import static org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.GstringContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.GstringPathContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.GstringValueContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IN; +import static org.apache.groovy.parser.antlr4.GroovyParser.INC; +import static org.apache.groovy.parser.antlr4.GroovyParser.INSTANCEOF; +import static org.apache.groovy.parser.antlr4.GroovyParser.IdentifierContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IdentifierPrmrAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IfElseStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ImplicationExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ImportDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.InclusiveOrExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IndexPropertyArgsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IndexVariableContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.IntegerLiteralAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.KeywordsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LE; +import static org.apache.groovy.parser.antlr4.GroovyParser.LT; +import static org.apache.groovy.parser.antlr4.GroovyParser.LabeledStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LambdaBodyContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LocalVariableDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LogicalAndExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LogicalOrExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.LoopStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MapContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MapEntryContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MapEntryLabelContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MapEntryListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MatchingTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MemberDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MethodBodyContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MethodDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MethodNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ModifierContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ModifiersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ModifiersOptContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MultipleAssignmentExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.MultiplicativeExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.NON_SEALED; +import static org.apache.groovy.parser.antlr4.GroovyParser.NOT_IN; +import static org.apache.groovy.parser.antlr4.GroovyParser.NOT_INSTANCEOF; +import static org.apache.groovy.parser.antlr4.GroovyParser.NamePartContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.NamedPropertyArgsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.NewPrmrAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.NonWildcardTypeArgumentsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.NullLiteralAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.OriginalForControlContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PRIVATE; +import static org.apache.groovy.parser.antlr4.GroovyParser.PackageDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ParExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PathElementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PathExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PostfixExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PowerExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.PrimitiveTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.QualifiedClassNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.QualifiedClassNameListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.QualifiedNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.QualifiedNameElementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.QualifiedStandardClassNameContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.RANGE_EXCLUSIVE_FULL; +import static org.apache.groovy.parser.antlr4.GroovyParser.RANGE_EXCLUSIVE_LEFT; +import static org.apache.groovy.parser.antlr4.GroovyParser.RANGE_EXCLUSIVE_RIGHT; +import static org.apache.groovy.parser.antlr4.GroovyParser.RANGE_INCLUSIVE; +import static org.apache.groovy.parser.antlr4.GroovyParser.ReferenceTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.RegexExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.RelationalExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ResourceContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ResourceListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ResourcesContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ReturnStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ReturnTypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SAFE_INDEX; +import static org.apache.groovy.parser.antlr4.GroovyParser.SEALED; +import static org.apache.groovy.parser.antlr4.GroovyParser.STATIC; +import static org.apache.groovy.parser.antlr4.GroovyParser.SUB; +import static org.apache.groovy.parser.antlr4.GroovyParser.ScriptStatementsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ShiftExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.StandardLambdaExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.StandardLambdaParametersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.StatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.StringLiteralContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SuperPrmrAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchBlockStatementExpressionGroupContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchBlockStatementGroupContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchExpressionContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchExpressionLabelContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchLabelContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SwitchStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.SynchronizedStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ThisFormalParameterContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ThisPrmrAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.ThrowStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TryCatchStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeArgumentContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeArgumentsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeArgumentsOrDiamondContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeBoundContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeListContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeNamePairContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeNamePairsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeParameterContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.TypeParametersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.UnaryAddExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.UnaryNotExprAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VAR; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableDeclarationContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableDeclaratorContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableDeclaratorIdContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableDeclaratorsContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableInitializerContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableModifierContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableModifiersContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableModifiersOptContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.VariableNamesContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.WhileStmtAltContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.YieldStatementContext; +import static org.apache.groovy.parser.antlr4.GroovyParser.YieldStmtAltContext; Review Comment: [nitpick] The wildcard import has been replaced with explicit imports spanning 200+ lines (158-362). While this avoids naming conflicts, it significantly impacts readability and maintainability. Consider organizing these imports into logical groups with comments, or using a hybrid approach where only conflicting imports (like ASYNC) are explicit while keeping the wildcard for non-conflicting imports. ```suggestion // Use explicit import for ASYNC to avoid naming conflicts import static org.apache.groovy.parser.antlr4.GroovyParser.ASYNC; // Import all other static members from GroovyParser via wildcard for readability import static org.apache.groovy.parser.antlr4.GroovyParser.*; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
