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/02 11:13:03 UTC
[groovy] branch master updated: minor refactor: remove some
codenarc violations
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 971192e minor refactor: remove some codenarc violations
971192e is described below
commit 971192eca0142a4bceee92f8728260c9e4dce763
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 2 21:12:50 2019 +1000
minor refactor: remove some codenarc violations
---
src/main/groovy/groovy/beans/ListenerList.groovy | 2 +-
.../beans/ListenerListASTTransformation.groovy | 194 ++++++---------------
src/main/groovy/groovy/transform/Canonical.groovy | 2 +-
.../groovy/groovy/transform/CompileDynamic.groovy | 2 +-
.../groovy/transform/ConditionalInterrupt.groovy | 2 +-
.../groovy/groovy/transform/TailRecursive.groovy | 2 +-
.../groovy/groovy/transform/ThreadInterrupt.groovy | 2 +-
.../groovy/groovy/transform/TimedInterrupt.groovy | 2 +-
src/main/groovy/groovy/util/ConfigSlurper.groovy | 83 ++++-----
.../groovy/util/FileNameByRegexFinder.groovy | 4 +-
src/main/groovy/groovy/util/FileTreeBuilder.groovy | 2 +-
.../ASTTransformationCustomizerFactory.groovy | 6 +-
.../builder/CompilerCustomizationBuilder.groovy | 15 +-
.../groovy/tools/ast/TransformTestHelper.groovy | 17 +-
.../org/codehaus/groovy/util/StringUtil.groovy | 6 +-
15 files changed, 133 insertions(+), 208 deletions(-)
diff --git a/src/main/groovy/groovy/beans/ListenerList.groovy b/src/main/groovy/groovy/beans/ListenerList.groovy
index 29dee82..c8e88cc 100644
--- a/src/main/groovy/groovy/beans/ListenerList.groovy
+++ b/src/main/groovy/groovy/beans/ListenerList.groovy
@@ -120,7 +120,7 @@ import java.lang.annotation.Target
* defaulting to the name of the listener type, e.g. if name is set to MyListener,
* then the class will have addMyListener, removeMyListener, and getMyListeners methods.
*/
- String name() default ""
+ String name() default ''
/**
* Whether or not the methods created should be synchronized at the method level.
diff --git a/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy b/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
index 3dc0b57..9ac3f44 100644
--- a/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
+++ b/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
@@ -28,33 +28,33 @@ import org.codehaus.groovy.ast.GenericsType
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.Parameter
import org.codehaus.groovy.ast.VariableScope
-import org.codehaus.groovy.ast.expr.ArgumentListExpression
-import org.codehaus.groovy.ast.expr.BinaryExpression
-import org.codehaus.groovy.ast.expr.BooleanExpression
-import org.codehaus.groovy.ast.expr.CastExpression
-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.ListExpression
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.ast.stmt.BlockStatement
-import org.codehaus.groovy.ast.stmt.EmptyStatement
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
import org.codehaus.groovy.ast.stmt.ForStatement
-import org.codehaus.groovy.ast.stmt.IfStatement
-import org.codehaus.groovy.ast.stmt.ReturnStatement
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.control.messages.SyntaxErrorMessage
import org.codehaus.groovy.syntax.SyntaxException
-import org.codehaus.groovy.syntax.Token
-import org.codehaus.groovy.syntax.Types
import org.codehaus.groovy.transform.ASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.objectweb.asm.Opcodes
+import static org.codehaus.groovy.ast.stmt.ReturnStatement.RETURN_NULL_OR_VOID
+import static org.codehaus.groovy.ast.tools.GeneralUtils.args
+import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS
+import static org.codehaus.groovy.ast.tools.GeneralUtils.callX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.castX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.constX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.declS
+import static org.codehaus.groovy.ast.tools.GeneralUtils.equalsNullX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS
import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.notNullX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.param
+import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS
+import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
+import static org.codehaus.groovy.ast.tools.GeneralUtils.varX
/**
* Handles generation of code for the {@code @ListenerList} annotation.
@@ -66,10 +66,12 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX
* <p>
*/
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
+@SuppressWarnings('ParameterCount')
class ListenerListASTTransformation implements ASTTransformation, Opcodes {
- private static final Class MY_CLASS = groovy.beans.ListenerList.class
+ private static final Class MY_CLASS = groovy.beans.ListenerList
private static final ClassNode COLLECTION_TYPE = ClassHelper.make(Collection)
+ @SuppressWarnings('Instanceof')
void visit(ASTNode[] nodes, SourceUnit source) {
if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: ${node.class} / ${parent.class}")
@@ -119,13 +121,10 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
}
}
- private static def addError(AnnotationNode node, SourceUnit source, String message) {
+ private static addError(AnnotationNode node, SourceUnit source, String message) {
source.errorCollector.addError(
- new SyntaxErrorMessage(new SyntaxException(
- message,
- node.lineNumber,
- node.columnNumber),
- source))
+ new SyntaxErrorMessage(
+ new SyntaxException(message, node.lineNumber, node.columnNumber), source))
}
/**
@@ -147,7 +146,7 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
def methodName = "add${name.capitalize()}"
def cn = ClassHelper.makeWithoutCaching(listener.name)
cn.redirect = listener
- def methodParameter = [new Parameter(cn,'listener')] as Parameter[]
+ def methodParameter = [param(cn, 'listener')] as Parameter[]
if (declaringClass.hasMethod(methodName, methodParameter)) {
addError node, source, "Conflict using @${MY_CLASS.name}. Class $declaringClass.name already has method $methodName"
@@ -156,37 +155,15 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
BlockStatement block = new BlockStatement()
block.addStatements([
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression('listener'),
- Token.newSymbol(Types.COMPARE_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
- new ReturnStatement(ConstantExpression.NULL),
- EmptyStatement.INSTANCE
+ ifS(
+ equalsNullX(varX('listener')),
+ RETURN_NULL_OR_VOID
),
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.COMPARE_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
- new ExpressionStatement(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.EQUAL, 0, 0),
- new ListExpression()
- )
- ),
- EmptyStatement.INSTANCE
+ ifS(
+ equalsNullX(varX(field.name)),
+ assignS(varX(field.name), new ListExpression())
),
- new ExpressionStatement(
- new MethodCallExpression(new VariableExpression(field.name), new ConstantExpression('add'), new ArgumentListExpression(new VariableExpression('listener')))
- )
+ stmt(callX(varX(field.name), constX('add'), args(varX('listener'))))
])
declaringClass.addMethod(new MethodNode(methodName, methodModifiers, methodReturnType, methodParameter, [] as ClassNode[], block))
}
@@ -209,7 +186,7 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
def methodName = "remove${name.capitalize()}"
def cn = ClassHelper.makeWithoutCaching(listener.name)
cn.redirect = listener
- def methodParameter = [new Parameter(cn,'listener')] as Parameter[]
+ def methodParameter = [param(cn, 'listener')] as Parameter[]
if (declaringClass.hasMethod(methodName, methodParameter)) {
addError node, source, "Conflict using @${MY_CLASS.name}. Class $declaringClass.name already has method $methodName"
@@ -218,37 +195,15 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
BlockStatement block = new BlockStatement()
block.addStatements([
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression('listener'),
- Token.newSymbol(Types.COMPARE_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
- new ReturnStatement(ConstantExpression.NULL),
- EmptyStatement.INSTANCE
+ ifS(
+ equalsNullX(varX('listener')),
+ RETURN_NULL_OR_VOID
),
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.COMPARE_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
- new ExpressionStatement(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.EQUAL, 0, 0),
- new ListExpression()
- )
- ),
- EmptyStatement.INSTANCE
+ ifS(
+ equalsNullX(varX(field.name)),
+ assignS(varX(field.name), new ListExpression())
),
- new ExpressionStatement(
- new MethodCallExpression(new VariableExpression(field.name), new ConstantExpression('remove'), new ArgumentListExpression(new VariableExpression("listener")))
- )
+ stmt(callX(varX(field.name), constX('remove'), args(varX('listener'))))
])
declaringClass.addMethod(new MethodNode(methodName, methodModifiers, methodReturnType, methodParameter, [] as ClassNode[], block))
}
@@ -277,31 +232,12 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
BlockStatement block = new BlockStatement()
block.addStatements([
- new ExpressionStatement(
- new DeclarationExpression(
- localVarX("__result", ClassHelper.DYNAMIC_TYPE),
- Token.newSymbol(Types.EQUALS, 0, 0),
- new ListExpression()
- )),
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.COMPARE_NOT_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
- new ExpressionStatement(
- new MethodCallExpression(new VariableExpression('__result'), new ConstantExpression('addAll'), new ArgumentListExpression(new VariableExpression(field.name)))
- ),
- EmptyStatement.INSTANCE
+ declS(localVarX('__result', ClassHelper.DYNAMIC_TYPE), new ListExpression()),
+ ifS(
+ notNullX(varX(field.name)),
+ stmt(callX(varX('__result'), constX('addAll'), args(varX(field.name))))
),
- new ReturnStatement(
- new CastExpression(
- methodReturnType,
- new VariableExpression('__result')
- )
- )
+ returnS(castX(methodReturnType, varX('__result')))
])
declaringClass.addMethod(new MethodNode(methodName, methodModifiers, methodReturnType, methodParameter, [] as ClassNode[], block))
}
@@ -312,7 +248,7 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
* void fire${fireMethod.capitalize()}(${parameterList.join(', ')}) {
* if (${field.name} != null) {
* def __list = new ArrayList(${field.name})
- * __list.each { listener ->
+ * for (listener in __list) {
* listener.$eventMethod(${evt})
* }
* }
@@ -330,53 +266,35 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
return
}
- def args = new ArgumentListExpression(method.parameters)
+ def methodArgs = args(method.parameters)
BlockStatement block = new BlockStatement()
def listenerListType = ClassHelper.make(ArrayList).plainNodeReference
- listenerListType.setGenericsTypes(types)
+ listenerListType.genericsTypes = types
block.addStatements([
- new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression(field.name),
- Token.newSymbol(Types.COMPARE_NOT_EQUAL, 0, 0),
- ConstantExpression.NULL
- )
- ),
+ ifS(
+ notNullX(varX(field.name)),
new BlockStatement([
- new ExpressionStatement(
- new DeclarationExpression(
- localVarX('__list', listenerListType),
- Token.newSymbol(Types.EQUALS, 0, 0),
- new ConstructorCallExpression(listenerListType, new ArgumentListExpression(
- new VariableExpression(field.name)
- ))
- )
+ declS(
+ localVarX('__list', listenerListType),
+ ctorX(listenerListType, args(varX(field.name)))
),
new ForStatement(
- new Parameter(ClassHelper.DYNAMIC_TYPE, 'listener'),
- new VariableExpression('__list'),
+ param(ClassHelper.DYNAMIC_TYPE, 'listener'),
+ varX('__list'),
new BlockStatement([
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression('listener'),
- method.name,
- args
- )
- )
+ stmt(callX(varX('listener'), method.name, methodArgs))
], new VariableScope())
)
- ], new VariableScope()),
- EmptyStatement.INSTANCE
+ ], new VariableScope())
)
])
def params = method.parameters.collect {
def paramType = ClassHelper.getWrapper(it.type)
def cn = paramType.plainNodeReference
- cn.setRedirect(paramType)
- new Parameter(cn, it.name)
+ cn.redirect = paramType
+ param(cn, it.name)
}
declaringClass.addMethod(methodName, methodModifiers, methodReturnType, params as Parameter[], [] as ClassNode[], block)
}
diff --git a/src/main/groovy/groovy/transform/Canonical.groovy b/src/main/groovy/groovy/transform/Canonical.groovy
index 6f99c80..c75a0ff 100644
--- a/src/main/groovy/groovy/transform/Canonical.groovy
+++ b/src/main/groovy/groovy/transform/Canonical.groovy
@@ -128,4 +128,4 @@ package groovy.transform
* @since 1.8.0
*/
@AnnotationCollector(value=[ToString, TupleConstructor, EqualsAndHashCode], mode=AnnotationCollectorMode.PREFER_EXPLICIT_MERGED)
-public @interface Canonical { }
+@interface Canonical { }
diff --git a/src/main/groovy/groovy/transform/CompileDynamic.groovy b/src/main/groovy/groovy/transform/CompileDynamic.groovy
index 11cd23b..013dcfa 100644
--- a/src/main/groovy/groovy/transform/CompileDynamic.groovy
+++ b/src/main/groovy/groovy/transform/CompileDynamic.groovy
@@ -28,6 +28,6 @@ import java.lang.annotation.Documented
* @since 2.1.0
*/
@Documented
-@AnnotationCollector(processor = "org.codehaus.groovy.transform.CompileDynamicProcessor")
+@AnnotationCollector(processor = 'org.codehaus.groovy.transform.CompileDynamicProcessor')
@interface CompileDynamic {
}
\ No newline at end of file
diff --git a/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy b/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy
index 0877775..621ed36 100644
--- a/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy
+++ b/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy
@@ -107,7 +107,7 @@ import java.lang.annotation.Target
@java.lang.annotation.Documented
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE])
-@GroovyASTTransformationClass(["org.codehaus.groovy.transform.ConditionalInterruptibleASTTransformation"])
+@GroovyASTTransformationClass(['org.codehaus.groovy.transform.ConditionalInterruptibleASTTransformation'])
@interface ConditionalInterrupt {
/**
* Set this to false if you have multiple classes within one source file and only
diff --git a/src/main/groovy/groovy/transform/TailRecursive.groovy b/src/main/groovy/groovy/transform/TailRecursive.groovy
index e4e9936..066a6a8 100644
--- a/src/main/groovy/groovy/transform/TailRecursive.groovy
+++ b/src/main/groovy/groovy/transform/TailRecursive.groovy
@@ -81,6 +81,6 @@ import java.lang.annotation.Target
*/
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.METHOD])
-@GroovyASTTransformationClass(["org.codehaus.groovy.transform.tailrec.TailRecursiveASTTransformation"])
+@GroovyASTTransformationClass(['org.codehaus.groovy.transform.tailrec.TailRecursiveASTTransformation'])
@interface TailRecursive {
}
diff --git a/src/main/groovy/groovy/transform/ThreadInterrupt.groovy b/src/main/groovy/groovy/transform/ThreadInterrupt.groovy
index 59cd2a9..d2dc5fb 100644
--- a/src/main/groovy/groovy/transform/ThreadInterrupt.groovy
+++ b/src/main/groovy/groovy/transform/ThreadInterrupt.groovy
@@ -105,7 +105,7 @@ import java.lang.annotation.Target
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE])
-@GroovyASTTransformationClass(["org.codehaus.groovy.transform.ThreadInterruptibleASTTransformation"])
+@GroovyASTTransformationClass(['org.codehaus.groovy.transform.ThreadInterruptibleASTTransformation'])
@interface ThreadInterrupt {
/**
* Set this to false if you have multiple classes within one source file and only
diff --git a/src/main/groovy/groovy/transform/TimedInterrupt.groovy b/src/main/groovy/groovy/transform/TimedInterrupt.groovy
index 03fe784..14c04dc 100644
--- a/src/main/groovy/groovy/transform/TimedInterrupt.groovy
+++ b/src/main/groovy/groovy/transform/TimedInterrupt.groovy
@@ -86,7 +86,7 @@ import java.util.concurrent.TimeoutException
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE])
-@GroovyASTTransformationClass(["org.codehaus.groovy.transform.TimedInterruptibleASTTransformation"])
+@GroovyASTTransformationClass(['org.codehaus.groovy.transform.TimedInterruptibleASTTransformation'])
@interface TimedInterrupt {
/**
* Set this to false if you have multiple classes within one source file and only want
diff --git a/src/main/groovy/groovy/util/ConfigSlurper.groovy b/src/main/groovy/groovy/util/ConfigSlurper.groovy
index dd0c90e..d7f47d5 100644
--- a/src/main/groovy/groovy/util/ConfigSlurper.groovy
+++ b/src/main/groovy/groovy/util/ConfigSlurper.groovy
@@ -30,7 +30,7 @@ import org.codehaus.groovy.runtime.InvokerHelper
* mail.host = 'smtp.myisp.com'
* mail.auth.user = 'server'
* }
- * resources.URL = "http://localhost:80/resources"
+ * resources.URL = 'http://localhost:80/resources'
* </code></pre>
*
* Settings can either be bound into nested maps or onto a specified JavaBean instance.
@@ -74,7 +74,7 @@ class ConfigSlurper {
}
String getEnvironment() {
- return conditionValues[ENVIRONMENTS_METHOD]
+ conditionValues[ENVIRONMENTS_METHOD]
}
void setEnvironment(String environment) {
@@ -96,48 +96,52 @@ class ConfigSlurper {
ConfigObject parse(Properties properties) {
ConfigObject config = new ConfigObject()
for (key in properties.keySet()) {
- def tokens = key.split(/\./)
+ parseKey(key, config, properties)
+ }
+ config
+ }
- def current = config
- def last
- def lastToken
- def foundBase = false
- for (token in tokens) {
- if (foundBase) {
- // handle not properly nested tokens by ignoring
- // hierarchy below this point
- lastToken += "." + token
- current = last
- } else {
- last = current
- lastToken = token
- current = current."${token}"
- if (!(current instanceof ConfigObject)) foundBase = true
- }
+ @SuppressWarnings('Instanceof')
+ private void parseKey(key, ConfigObject config, Properties properties) {
+ def tokens = key.split(/\./)
+
+ def current = config
+ def last
+ def lastToken
+ def foundBase = false
+ for (token in tokens) {
+ if (foundBase) {
+ // handle not properly nested tokens by ignoring
+ // hierarchy below this point
+ lastToken += '.' + token
+ current = last
+ } else {
+ last = current
+ lastToken = token
+ current = current."${token}"
+ if (!(current instanceof ConfigObject)) foundBase = true
}
+ }
- if (current instanceof ConfigObject) {
- if (last[lastToken]) {
- def flattened = last.flatten()
- last.clear()
- flattened.each { k2, v2 -> last[k2] = v2 }
- last[lastToken] = properties.get(key)
- }
- else {
- last[lastToken] = properties.get(key)
- }
+ if (current instanceof ConfigObject) {
+ if (last[lastToken]) {
+ def flattened = last.flatten()
+ last.clear()
+ flattened.each { k2, v2 -> last[k2] = v2 }
+ last[lastToken] = properties.get(key)
+ } else {
+ last[lastToken] = properties.get(key)
}
- current = config
}
- return config
}
+
/**
* Parse the given script as a string and return the configuration object
*
* @see ConfigSlurper#parse(groovy.lang.Script)
*/
ConfigObject parse(String script) {
- return parse(classLoader.parseClass(script))
+ parse(classLoader.parseClass(script))
}
/**
@@ -146,7 +150,7 @@ class ConfigSlurper {
* @see ConfigSlurper#parse(groovy.lang.Script)
*/
ConfigObject parse(Class scriptClass) {
- return parse(scriptClass.newInstance())
+ parse(scriptClass.newInstance())
}
/**
@@ -157,7 +161,7 @@ class ConfigSlurper {
* @return A Map of maps that can be navigating with dot de-referencing syntax to obtain configuration entries
*/
ConfigObject parse(Script script) {
- return parse(script, null)
+ parse(script, null)
}
/**
@@ -167,7 +171,7 @@ class ConfigSlurper {
* @return The ConfigObject instance
*/
ConfigObject parse(URL scriptLocation) {
- return parse(classLoader.parseClass(scriptLocation.text).newInstance(), scriptLocation)
+ parse(classLoader.parseClass(scriptLocation.text).newInstance(), scriptLocation)
}
/**
@@ -178,12 +182,13 @@ class ConfigSlurper {
* @param location The original location of the Script as a URL
* @return The ConfigObject instance
*/
+ @SuppressWarnings('Instanceof')
ConfigObject parse(Script script, URL location) {
Stack<String> currentConditionalBlock = new Stack<String>()
def config = location ? new ConfigObject(location) : new ConfigObject()
GroovySystem.metaClassRegistry.removeMetaClass(script.class)
def mc = script.class.metaClass
- def prefix = ""
+ def prefix = ''
LinkedList stack = new LinkedList()
stack << [config: config, scope: [:]]
def pushStack = { co ->
@@ -261,7 +266,7 @@ class ConfigSlurper {
prefix = name + '.'
assignName.call(name, args[0])
args[1].call()
- } finally { prefix = "" }
+ } finally { prefix = '' }
} else {
MetaMethod mm = mc.getMetaMethod(name, args)
if (mm) {
@@ -279,7 +284,7 @@ class ConfigSlurper {
}
def binding = new ConfigBinding(setProperty)
if (this.bindingVars) {
- binding.getVariables().putAll(this.bindingVars)
+ binding.variables.putAll(this.bindingVars)
}
script.binding = binding
@@ -287,7 +292,7 @@ class ConfigSlurper {
config.merge(overrides)
- return config
+ config
}
}
diff --git a/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy b/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
index f6f10a2..7754995 100644
--- a/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
+++ b/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
@@ -25,7 +25,7 @@ package groovy.util
class FileNameByRegexFinder implements IFileNameFinder {
List<String> getFileNames(String basedir, String pattern) {
- getFileNames(basedir, pattern, "")
+ getFileNames(basedir, pattern, '')
}
List<String> getFileNames(String basedir, String pattern, String excludesPattern) {
@@ -35,6 +35,6 @@ class FileNameByRegexFinder implements IFileNameFinder {
result << it.absolutePath
}
}
- return result
+ result
}
}
diff --git a/src/main/groovy/groovy/util/FileTreeBuilder.groovy b/src/main/groovy/groovy/util/FileTreeBuilder.groovy
index f76c95a..af41a6c 100644
--- a/src/main/groovy/groovy/util/FileTreeBuilder.groovy
+++ b/src/main/groovy/groovy/util/FileTreeBuilder.groovy
@@ -165,7 +165,7 @@ class FileTreeBuilder {
baseDir
}
-
+ @SuppressWarnings('Instanceof')
def methodMissing(String name, args) {
if (args instanceof Object[] && ((Object[]) args).length == 1) {
def arg = ((Object[]) args)[0]
diff --git a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/ASTTransformationCustomizerFactory.groovy b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/ASTTransformationCustomizerFactory.groovy
index 1784f29..cdd06e8 100644
--- a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/ASTTransformationCustomizerFactory.groovy
+++ b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/ASTTransformationCustomizerFactory.groovy
@@ -36,18 +36,18 @@ class ASTTransformationCustomizerFactory extends AbstractFactory {
@Override
@CompileStatic
- public boolean isLeaf() {
+ boolean isLeaf() {
true
}
@Override
@CompileStatic
- public boolean onHandleNodeAttributes(final FactoryBuilderSupport builder, final Object node, final Map attributes) {
+ boolean onHandleNodeAttributes(final FactoryBuilderSupport builder, final Object node, final Map attributes) {
false
}
@Override
- public Object newInstance(final FactoryBuilderSupport builder, final Object name, final Object value, final Map attributes) throws InstantiationException, IllegalAccessException {
+ Object newInstance(final FactoryBuilderSupport builder, final Object name, final Object value, final Map attributes) throws InstantiationException, IllegalAccessException {
ASTTransformationCustomizer customizer
if (attributes) {
customizer = new ASTTransformationCustomizer(attributes, value)
diff --git a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy
index babc545..2ed466d 100644
--- a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy
+++ b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy
@@ -34,13 +34,14 @@ class CompilerCustomizationBuilder extends FactoryBuilderSupport {
}
static CompilerConfiguration withConfig(CompilerConfiguration config,
- @DelegatesTo(type = "org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder") Closure code) {
+ @DelegatesTo(type = 'org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder') Closure code) {
CompilerCustomizationBuilder builder = new CompilerCustomizationBuilder()
config.invokeMethod('addCompilationCustomizers', builder.invokeMethod('customizers', code))
config
}
@Override
+ @SuppressWarnings('Instanceof')
protected Object postNodeCompletion(final Object parent, final Object node) {
Object value = super.postNodeCompletion(parent, node)
Object factory = getContextAttribute(CURRENT_FACTORY)
@@ -52,11 +53,11 @@ class CompilerCustomizationBuilder extends FactoryBuilderSupport {
}
private void registerFactories() {
- registerFactory("ast", new ASTTransformationCustomizerFactory())
- registerFactory("customizers", new CustomizersFactory())
- registerFactory("imports", new ImportCustomizerFactory())
- registerFactory("inline", new InlinedASTCustomizerFactory())
- registerFactory("secureAst", new SecureASTCustomizerFactory())
- registerFactory("source", new SourceAwareCustomizerFactory())
+ registerFactory('ast', new ASTTransformationCustomizerFactory())
+ registerFactory('customizers', new CustomizersFactory())
+ registerFactory('imports', new ImportCustomizerFactory())
+ registerFactory('inline', new InlinedASTCustomizerFactory())
+ registerFactory('secureAst', new SecureASTCustomizerFactory())
+ registerFactory('source', new SourceAwareCustomizerFactory())
}
}
diff --git a/src/main/groovy/org/codehaus/groovy/tools/ast/TransformTestHelper.groovy b/src/main/groovy/org/codehaus/groovy/tools/ast/TransformTestHelper.groovy
index 266ed76..d4005e6 100644
--- a/src/main/groovy/org/codehaus/groovy/tools/ast/TransformTestHelper.groovy
+++ b/src/main/groovy/org/codehaus/groovy/tools/ast/TransformTestHelper.groovy
@@ -18,6 +18,7 @@
*/
package org.codehaus.groovy.tools.ast
+import groovy.transform.PackageScope
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.classgen.GeneratorContext
import org.codehaus.groovy.control.CompilationUnit
@@ -65,7 +66,7 @@ class TransformTestHelper {
*/
Class parse(File input) {
TestHarnessClassLoader loader = new TestHarnessClassLoader(transform, phase)
- return loader.parseClass(input)
+ loader.parseClass(input)
}
/**
@@ -74,14 +75,14 @@ class TransformTestHelper {
*/
Class parse(String input) {
TestHarnessClassLoader loader = new TestHarnessClassLoader(transform, phase)
- return loader.parseClass(input)
+ loader.parseClass(input)
}
}
/**
* ClassLoader exists so that TestHarnessOperation can be wired into the compile.
*/
-@groovy.transform.PackageScope
+@PackageScope
class TestHarnessClassLoader extends GroovyClassLoader {
private final ASTTransformation transform
@@ -94,24 +95,24 @@ class TestHarnessClassLoader extends GroovyClassLoader {
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource codeSource) {
CompilationUnit cu = super.createCompilationUnit(config, codeSource)
- cu.addPhaseOperation(new TestHarnessOperation(transform), phase.getPhaseNumber())
- return cu
+ cu.addPhaseOperation(new TestHarnessOperation(transform), phase.phaseNumber)
+ cu
}
}
/**
* Operation exists so that an AstTransformation can be run against the SourceUnit.
*/
-@groovy.transform.PackageScope
+@PackageScope
class TestHarnessOperation extends PrimaryClassNodeOperation {
private final ASTTransformation transform
TestHarnessOperation(transform) {
- this.transform = transform;
+ this.transform = transform
}
- void call(SourceUnit source, GeneratorContext context, ClassNode classNode) {
+ void call(SourceUnit source, GeneratorContext ignoredContext, ClassNode ignoredNode) {
transform.visit(null, source)
}
}
diff --git a/src/main/groovy/org/codehaus/groovy/util/StringUtil.groovy b/src/main/groovy/org/codehaus/groovy/util/StringUtil.groovy
index 339d92c..e283826 100644
--- a/src/main/groovy/org/codehaus/groovy/util/StringUtil.groovy
+++ b/src/main/groovy/org/codehaus/groovy/util/StringUtil.groovy
@@ -38,9 +38,9 @@ class StringUtil {
replacement = expandHyphen(replacement)
// padding replacement with a last character, if necessary
- replacement = replacement.padRight(source.size(), replacement[replacement.size() - 1])
+ replacement = replacement.padRight(source.size(), replacement[-1])
- return text.collect { String original ->
+ text.collect { String original ->
if (source.contains(original)) {
replacement[source.lastIndexOf(original)]
} else {
@@ -52,6 +52,6 @@ class StringUtil {
// no expansion for hyphen at start or end of Strings
private static String expandHyphen(String text) {
if (!text.contains('-')) { return text }
- return text.replaceAll(/(.)-(.)/, { all, begin, end -> (begin..end).join('') })
+ text.replaceAll(/(.)-(.)/, { all, begin, end -> (begin..end).join('') })
}
}