You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/04/03 13:43:27 UTC
[groovy] branch GROOVY_2_5_X updated: minor refactor: remove some
codenarc violations (part 3)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 63ef785 minor refactor: remove some codenarc violations (part 3)
63ef785 is described below
commit 63ef785b0a0c9695b40f194517664f90d4d23548
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Apr 3 23:43:15 2019 +1000
minor refactor: remove some codenarc violations (part 3)
---
src/main/groovy/groovy/grape/GrapeIvy.groovy | 14 ++--
.../ast/builder/AstSpecificationCompiler.groovy | 92 +++++++++++-----------
.../groovy/ast/builder/AstStringCompiler.groovy | 10 +--
.../TimedInterruptibleASTTransformation.groovy | 10 +--
.../transform/tailrec/InWhileLoopWrapper.groovy | 3 -
.../tailrec/TernaryToIfStatementConverter.groovy | 6 +-
6 files changed, 67 insertions(+), 68 deletions(-)
diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index 2e72445..aa990a5 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -402,7 +402,7 @@ class GrapeIvy implements GrapeEngine {
InputStream is = null
try {
is = zf.getInputStream(pluginRunners)
- processRunners(is, f.getName(), loader)
+ processRunners(is, f.name, loader)
} finally {
closeQuietly(is)
}
@@ -469,11 +469,11 @@ class GrapeIvy implements GrapeEngine {
}
// resolve grab and dependencies
- ResolveOptions resolveOptions = new ResolveOptions()
- .setConfs(GrapeIvy.DEF_CONFIG as String[])
- .setOutputReport(false)
- .setValidate((boolean) (args.containsKey('validate') ? args.validate : false))
-
+ ResolveOptions resolveOptions = new ResolveOptions().tap {
+ confs = DEF_CONFIG as String[]
+ outputReport = false
+ validate = (boolean) (args.containsKey('validate') ? args.validate : false)
+ }
ivyInstance.settings.defaultResolver = args.autoDownload ? 'downloadGrapes' : 'cachedGrapes'
if (args.disableChecksums) {
ivyInstance.settings.setVariable('ivy.checksums', '')
@@ -738,7 +738,7 @@ class GrapeIvy implements GrapeEngine {
module : grabbed.mrid.name,
version: grabbed.mrid.revision
]
- if (grabbed.conf != GrapeIvy.DEF_CONFIG) {
+ if (grabbed.conf != DEF_CONFIG) {
dep.conf = grabbed.conf
}
if (grabbed.changing) {
diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy
index b450a09..fdc8a22 100644
--- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy
+++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy
@@ -45,7 +45,6 @@ import org.codehaus.groovy.ast.expr.CastExpression
import org.codehaus.groovy.ast.expr.ClassExpression
import org.codehaus.groovy.ast.expr.ClosureExpression
import org.codehaus.groovy.ast.expr.ClosureListExpression
-import org.codehaus.groovy.ast.expr.ConstantExpression
import org.codehaus.groovy.ast.expr.ConstructorCallExpression
import org.codehaus.groovy.ast.expr.DeclarationExpression
import org.codehaus.groovy.ast.expr.ElvisOperatorExpression
@@ -72,7 +71,6 @@ import org.codehaus.groovy.ast.expr.UnaryMinusExpression
import org.codehaus.groovy.ast.expr.UnaryPlusExpression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.ast.stmt.AssertStatement
-import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.ast.stmt.BreakStatement
import org.codehaus.groovy.ast.stmt.CaseStatement
import org.codehaus.groovy.ast.stmt.CatchStatement
@@ -92,6 +90,10 @@ import org.codehaus.groovy.runtime.MethodClosure
import org.codehaus.groovy.syntax.Token
import org.codehaus.groovy.syntax.Types
+import static org.codehaus.groovy.ast.tools.GeneralUtils.block
+import static org.codehaus.groovy.ast.tools.GeneralUtils.constX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.param
+
/**
* Handles parsing the properties from the closure into values that can be referenced.
*
@@ -101,6 +103,7 @@ import org.codehaus.groovy.syntax.Types
* Note: this class consists of many one-line method calls. A better implementation
* might be to take a declarative approach and replace the one-liners with map entries.
*/
+@SuppressWarnings('BuilderMethodWithSideEffects')
class AstSpecificationCompiler implements GroovyInterceptable {
private final List<ASTNode> expression = []
@@ -117,7 +120,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Gets the current generated expression.
*/
List<ASTNode> getExpression() {
- return expression
+ expression
}
/**
@@ -136,7 +139,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
// enforce that the correct # arguments was passed
if (spec.size() != expression.size()) {
- throw new IllegalArgumentException("$methodName could not be invoked. Expected to receive parameters $spec but found ${expression?.collect { it.class }}")
+ throw new IllegalArgumentException("$methodName could not be invoked. Expected to receive parameters $spec but found ${expression*.class}")
}
// enforce types and collect result
@@ -144,7 +147,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
def actualClass = expression[it].class
def expectedClass = spec[it]
if (!expectedClass.isAssignableFrom(actualClass)) {
- throw new IllegalArgumentException("$methodName could not be invoked. Expected to receive parameters $spec but found ${expression?.collect { it.class }}")
+ throw new IllegalArgumentException("$methodName could not be invoked. Expected to receive parameters $spec but found ${expression*.class}")
}
expression[it]
}
@@ -489,7 +492,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Designates a list of AnnotationNodes.
*/
void annotations(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<AnnotationNode>")
+ makeListOfNodes(argBlock, 'List<AnnotationNode>')
}
@@ -497,28 +500,28 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Designates a list of MethodNodes.
*/
void methods(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<MethodNode>")
+ makeListOfNodes(argBlock, 'List<MethodNode>')
}
/**
* Designates a list of ConstructorNodes.
*/
void constructors(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<ConstructorNode>")
+ makeListOfNodes(argBlock, 'List<ConstructorNode>')
}
/**
* Designates a list of {@code PropertyNode}s.
*/
void properties(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<PropertyNode>")
+ makeListOfNodes(argBlock, 'List<PropertyNode>')
}
/**
* Designates a list of {@code FieldNode}s.
*/
void fields(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<FieldNode>")
+ makeListOfNodes(argBlock, 'List<FieldNode>')
}
/**
@@ -526,7 +529,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void strings(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<ConstantExpression>")
+ makeListOfNodes(argBlock, 'List<ConstantExpression>')
}
/**
@@ -534,7 +537,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void values(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<Expression>")
+ makeListOfNodes(argBlock, 'List<Expression>')
}
/**
@@ -548,7 +551,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a ConstantExpression.
*/
void constant(Object value) {
- expression << new ConstantExpression(value)
+ expression << constX(value)
}
/**
@@ -666,6 +669,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
/**
* Creates an ExpressionStatement.
*/
+ @SuppressWarnings('ConfusingMethodName')
void expression(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
makeNode(ExpressionStatement, 'expression', [Expression], argBlock)
}
@@ -681,21 +685,21 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a ClassNode[].
*/
void interfaces(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<ClassNode>")
+ makeListOfNodes(argBlock, 'List<ClassNode>')
}
/**
* Creates a MixinNode[].
*/
void mixins(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<MixinNode>")
+ makeListOfNodes(argBlock, 'List<MixinNode>')
}
/**
* Creates a GenericsTypes[].
*/
void genericsTypes(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- makeListOfNodes(argBlock, "List<GenericsTypes>")
+ makeListOfNodes(argBlock, 'List<GenericsTypes>')
}
/**
@@ -716,8 +720,8 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a BlockStatement.
*/
void block(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("BlockStatement", argBlock) {
- return new BlockStatement(new ArrayList(expression), new VariableScope())
+ captureAndCreateNode('BlockStatement', argBlock) {
+ block(new VariableScope(), new ArrayList(expression))
}
}
@@ -731,13 +735,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
//todo: add better error handling?
if (argBlock) {
args.each { name, type ->
- captureAndCreateNode("Parameter", argBlock) {
- new Parameter(ClassHelper.make(type), name, expression[0])
+ captureAndCreateNode('Parameter', argBlock) {
+ param(ClassHelper.make(type), name, expression[0])
}
}
} else {
args.each { name, type ->
- expression << (new Parameter(ClassHelper.make(type), name))
+ expression << (param(ClassHelper.make(type), name))
}
}
}
@@ -746,7 +750,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates an ArrayExpression.
*/
void array(Class type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("ArrayExpression", argBlock) {
+ captureAndCreateNode('ArrayExpression', argBlock) {
new ArrayExpression(ClassHelper.make(type), new ArrayList(expression))
}
}
@@ -756,7 +760,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void genericsType(Class type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
- captureAndCreateNode("GenericsType", argBlock) {
+ captureAndCreateNode('GenericsType', argBlock) {
new GenericsType(ClassHelper.make(type), expression[0] as ClassNode[], expression[1])
}
} else {
@@ -782,7 +786,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a 2 element list of name and Annotation. Used with Annotation Members.
*/
void member(String name, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("Annotation Member", argBlock) {
+ captureAndCreateNode('Annotation Member', argBlock) {
[name, expression[0]]
}
}
@@ -804,7 +808,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
void annotation(Class target, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
//todo: add better error handling
- captureAndCreateNode("ArgumentListExpression", argBlock) {
+ captureAndCreateNode('ArgumentListExpression', argBlock) {
def node = new AnnotationNode(ClassHelper.make(target))
expression?.each {
node.addMember(it[0], it[1])
@@ -820,7 +824,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a MixinNode.
*/
void mixin(String name, int modifiers, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("AttributeExpression", argBlock) {
+ captureAndCreateNode('AttributeExpression', argBlock) {
if (expression.size() > 1) {
new MixinNode(name, modifiers, expression[0], new ArrayList(expression[1]) as ClassNode[])
} else {
@@ -833,7 +837,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a ClassNode
*/
void classNode(String name, int modifiers, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("ClassNode", argBlock) {
+ captureAndCreateNode('ClassNode', argBlock) {
def result = new ClassNode(name, modifiers,
expression[0],
new ArrayList(expression[1]) as ClassNode[],
@@ -841,13 +845,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
)
while (expression.size() > 3) {
if (!List.isAssignableFrom(expression[3].getClass())) {
- throw new IllegalArgumentException("Expecting to find list of additional items instead found: " + expression[3].getClass())
+ throw new IllegalArgumentException('Expecting to find list of additional items instead found: ' + expression[3].getClass())
}
if (expression[3].size() > 0) {
def clazz = expression[3][0].getClass()
switch (clazz) {
case GenericsType:
- result.setGenericsTypes(new ArrayList(expression[3]) as GenericsType[])
+ result.genericsTypes = new ArrayList(expression[3]) as GenericsType[]
break
case MethodNode:
expression[3].each { result.addMethod(it) }
@@ -884,7 +888,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates an AssertStatement.
*/
void assertStatement(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("AssertStatement", argBlock) {
+ captureAndCreateNode('AssertStatement', argBlock) {
if (expression.size() < 2) {
new AssertStatement(*enforceConstraints('assertStatement', [BooleanExpression]))
} else {
@@ -897,11 +901,11 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a TryCatchStatement.
*/
void tryCatch(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("TryCatchStatement", argBlock) {
+ captureAndCreateNode('TryCatchStatement', argBlock) {
def result = new TryCatchStatement(expression[0], expression[1])
def catchStatements = expression.tail().tail()
catchStatements.each { statement -> result.addCatch(statement) }
- return result
+ result
}
}
@@ -916,7 +920,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a MethodNode.
*/
void method(String name, int modifiers, Class returnType, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("MethodNode", argBlock) {
+ captureAndCreateNode('MethodNode', argBlock) {
//todo: enforce contract
def result = new MethodNode(name, modifiers, ClassHelper.make(returnType), expression[0], expression[1], expression[2])
if (expression[3]) {
@@ -930,7 +934,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a token.
*/
void token(String value) {
- if (value == null) throw new IllegalArgumentException("Null: value")
+ if (value == null) throw new IllegalArgumentException('Null: value')
def tokenID = Types.lookupKeyword(value)
if (tokenID == Types.UNKNOWN) {
@@ -946,7 +950,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void range(Range range) {
if (range == null) throw new IllegalArgumentException('Null: range')
- expression << new RangeExpression(new ConstantExpression(range.getFrom()), new ConstantExpression(range.getTo()), true)
+ expression << new RangeExpression(constX(range.from), constX(range.to), true)
//default is inclusive
}
@@ -954,7 +958,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a SwitchStatement.
*/
void switchStatement(@DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("SwitchStatement", argBlock) {
+ captureAndCreateNode('SwitchStatement', argBlock) {
def switchExpression = expression.head()
def caseStatements = expression.tail().tail()
def defaultExpression = expression.tail().head()
@@ -967,9 +971,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void mapEntry(Map map) {
map.entrySet().each {
- expression << new MapEntryExpression(
- new ConstantExpression(it.key),
- new ConstantExpression(it.value))
+ expression << new MapEntryExpression(constX(it.key), constX(it.value))
}
}
@@ -981,7 +983,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a FieldNode.
*/
void fieldNode(String name, int modifiers, Class type, Class owner, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("FieldNode", argBlock) {
+ captureAndCreateNode('FieldNode', argBlock) {
def annotations = null
if (expression.size() > 1) {
annotations = expression[1]
@@ -1003,7 +1005,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates an inner class.
*/
void innerClass(String name, int modifiers, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("InnerClassNode", argBlock) {
+ captureAndCreateNode('InnerClassNode', argBlock) {
//todo: enforce contract
new InnerClassNode(
expression[0],
@@ -1020,7 +1022,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
*/
void propertyNode(String name, int modifiers, Class type, Class owner, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
//todo: improve error handling?
- captureAndCreateNode("PropertyNode", argBlock) {
+ captureAndCreateNode('PropertyNode', argBlock) {
def annotations = null
// check if the last expression looks like annotations
if (List.isAssignableFrom(expression[-1].getClass())) {
@@ -1042,7 +1044,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a StaticMethodCallExpression.
*/
void staticMethodCall(Class target, String name, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("StaticMethodCallExpression", argBlock) {
+ captureAndCreateNode('StaticMethodCallExpression', argBlock) {
expression.add(0, name)
expression.add(0, ClassHelper.make(target))
new StaticMethodCallExpression(*enforceConstraints('staticMethodCall', [ClassNode, String, Expression]))
@@ -1053,7 +1055,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a StaticMethodCallExpression.
*/
void staticMethodCall(MethodClosure target, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("StaticMethodCallExpression", argBlock) {
+ captureAndCreateNode('StaticMethodCallExpression', argBlock) {
expression.add(0, target.method)
expression.add(0, ClassHelper.makeWithoutCaching(target.owner.class, false))
new StaticMethodCallExpression(*enforceConstraints('staticMethodCall', [ClassNode, String, Expression]))
@@ -1064,7 +1066,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
* Creates a ConstructorNode.
*/
void constructor(int modifiers, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
- captureAndCreateNode("ConstructorNode", argBlock) {
+ captureAndCreateNode('ConstructorNode', argBlock) {
def annotations = null
if (expression.size() > 3) {
annotations = expression[3]
diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy
index 3947819..a3818de 100644
--- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy
+++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy
@@ -47,14 +47,14 @@ class AstStringCompiler {
*/
List<ASTNode> compile(String script, CompilePhase compilePhase, boolean statementsOnly) {
final scriptClassName = makeScriptClassName()
- GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", "/groovy/script")
+ GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", '/groovy/script')
CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, AccessController.doPrivileged({
new GroovyClassLoader()
} as PrivilegedAction<GroovyClassLoader>))
- cu.addSource(codeSource.getName(), script)
- cu.compile(compilePhase.getPhaseNumber())
+ cu.addSource(codeSource.name, script)
+ cu.compile(compilePhase.phaseNumber)
// collect all the ASTNodes into the result, possibly ignoring the script body if desired
- return (List<ASTNode>) cu.getAST().modules.inject([]) { List acc, ModuleNode node ->
+ (List<ASTNode>) cu.AST.modules.inject([]) { List acc, ModuleNode node ->
if (node.statementBlock) acc.add(node.statementBlock)
node.classes?.each {
if (!(statementsOnly && it.name == scriptClassName)) {
@@ -66,6 +66,6 @@ class AstStringCompiler {
}
private static String makeScriptClassName() {
- return "Script${System.nanoTime()}"
+ "Script${System.nanoTime()}"
}
}
diff --git a/src/main/groovy/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy b/src/main/groovy/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
index 786fad9..02b7328 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
@@ -77,7 +77,7 @@ class TimedInterruptibleASTTransformation extends AbstractASTTransformation {
init(nodes, source)
AnnotationNode node = nodes[0]
AnnotatedNode annotatedNode = nodes[1]
- if (!MY_TYPE.equals(node.getClassNode())) {
+ if (!MY_TYPE.equals(node.classNode)) {
internalError("Transformation called from wrong annotation: $node.classNode.name")
}
@@ -87,13 +87,13 @@ class TimedInterruptibleASTTransformation extends AbstractASTTransformation {
def maximum = getConstantAnnotationParameter(node, 'value', Long.TYPE, Long.MAX_VALUE)
def thrown = AbstractInterruptibleASTTransformation.getClassAnnotationParameter(node, THROWN_EXCEPTION_TYPE, make(TimeoutException))
- Expression unit = node.getMember('unit') ?: propX(classX(TimeUnit), "SECONDS")
+ Expression unit = node.getMember('unit') ?: propX(classX(TimeUnit), 'SECONDS')
// should be limited to the current SourceUnit or propagated to the whole CompilationUnit
// DO NOT inline visitor creation in code below. It has state that must not persist between calls
if (applyToAllClasses) {
// guard every class and method defined in this script
- source.getAST()?.classes?.each { ClassNode it ->
+ source.AST?.classes?.each { ClassNode it ->
def visitor = new TimedInterruptionVisitor(source, checkOnMethodStart, applyToAllClasses, applyToAllMembers, maximum, unit, thrown, node.hashCode())
visitor.visitClass(it)
}
@@ -118,7 +118,7 @@ class TimedInterruptibleASTTransformation extends AbstractASTTransformation {
visitor.visitClass annotatedNode.declaringClass
} else {
// only guard the script class
- source.getAST()?.classes?.each { ClassNode it ->
+ source.AST?.classes?.each { ClassNode it ->
if (it.isScript()) {
def visitor = new TimedInterruptionVisitor(source, checkOnMethodStart, applyToAllClasses, applyToAllMembers, maximum, unit, thrown, node.hashCode())
visitor.visitClass(it)
@@ -232,7 +232,7 @@ class TimedInterruptibleASTTransformation extends AbstractASTTransformation {
args(constX(maximum, true), unit)
)
)
- );
+ )
expireTimeField.synthetic = true
startTimeField = node.addField(basename + '$startTime',
ACC_FINAL | ACC_PRIVATE,
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy b/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
index 5af2df8..c0ab449 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
@@ -21,10 +21,7 @@ package org.codehaus.groovy.transform.tailrec
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.MethodNode
-import org.codehaus.groovy.ast.Parameter
import org.codehaus.groovy.ast.VariableScope
-import org.codehaus.groovy.ast.expr.BooleanExpression
-import org.codehaus.groovy.ast.expr.ConstantExpression
import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.ast.stmt.CatchStatement
import org.codehaus.groovy.ast.stmt.ContinueStatement
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/TernaryToIfStatementConverter.groovy b/src/main/groovy/org/codehaus/groovy/transform/tailrec/TernaryToIfStatementConverter.groovy
index 012a7c7..165650f 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/tailrec/TernaryToIfStatementConverter.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/tailrec/TernaryToIfStatementConverter.groovy
@@ -20,11 +20,11 @@ package org.codehaus.groovy.transform.tailrec
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.expr.TernaryExpression
-import org.codehaus.groovy.ast.stmt.IfStatement
import org.codehaus.groovy.ast.stmt.ReturnStatement
import org.codehaus.groovy.ast.stmt.Statement
import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS
+import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS
/**
* Since a ternary statement has more than one exit point tail-recursiveness testing cannot be easily done.
@@ -38,6 +38,6 @@ class TernaryToIfStatementConverter {
if (!(statementWithInnerTernaryExpression.expression instanceof TernaryExpression))
return statementWithInnerTernaryExpression
TernaryExpression ternary = statementWithInnerTernaryExpression.expression as TernaryExpression
- ifElseS(ternary.booleanExpression, new ReturnStatement(ternary.trueExpression), new ReturnStatement(ternary.falseExpression))
+ ifElseS(ternary.booleanExpression, returnS(ternary.trueExpression), returnS(ternary.falseExpression))
}
-}
\ No newline at end of file
+}