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/01/09 01:39:10 UTC
[groovy] branch master updated: whitespace/formatting plus
cleanup/remove @author tags as per Apache recommended practices cont'd
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 a41e02d whitespace/formatting plus cleanup/remove @author tags as per Apache recommended practices cont'd
a41e02d is described below
commit a41e02d2c3fa66f61350e1eb8eb408627947b142
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Jan 9 11:17:38 2019 +1000
whitespace/formatting plus cleanup/remove @author tags as per Apache recommended practices cont'd
---
gradle/pomconfigurer.gradle | 20 +-
src/main/groovy/groovy/beans/ListenerList.groovy | 2 -
.../beans/ListenerListASTTransformation.groovy | 3 -
src/main/groovy/groovy/lang/GString.java | 27 +-
src/main/groovy/groovy/util/ConfigSlurper.groovy | 2 -
.../groovy/util/FileNameByRegexFinder.groovy | 3 -
.../codehaus/groovy/ast/builder/AstBuilder.groovy | 29 +-
.../ast/builder/AstSpecificationCompiler.groovy | 161 +-
.../groovy/ast/builder/AstStringCompiler.groovy | 11 +-
src/test/groovy/StringTest.groovy | 2 -
src/test/groovy/beans/ListenerListASTTest.groovy | 3 -
src/test/groovy/beans/VetoableTest.groovy | 919 +++++------
src/test/groovy/bugs/AsBoolBug.groovy | 2 -
.../groovy/bugs/AttributeSetExpressionBug.groovy | 4 -
.../bugs/BadLineNumberOnExceptionBugTest.groovy | 2 -
src/test/groovy/bugs/BadScriptNameBug.groovy | 3 -
.../groovy/bugs/ClosureParameterPassingBug.groovy | 3 -
src/test/groovy/bugs/ConstructorBug.groovy | 3 -
.../groovy/bugs/DoubleSizeParametersBug.groovy | 19 +-
src/test/groovy/bugs/ForLoopBug.groovy | 3 -
src/test/groovy/bugs/Groovy1018_Bug.groovy | 2 -
src/test/groovy/bugs/Groovy1059_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy239_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy278_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy3464Bug.groovy | 2 -
src/test/groovy/bugs/Groovy3871Bug.groovy | 1 -
...Groovy4457GenericTypeDeclarationLeakTest.groovy | 3 -
src/test/groovy/bugs/Groovy4480Bug.groovy | 2 -
src/test/groovy/bugs/Groovy4614Bug.groovy | 3 -
src/test/groovy/bugs/Groovy4720Bug.groovy | 3 -
src/test/groovy/bugs/Groovy4857Bug.groovy | 4 -
src/test/groovy/bugs/Groovy5425_Bug.groovy | 2 -
src/test/groovy/bugs/Groovy558_616_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy662Bug.groovy | 2 -
src/test/groovy/bugs/Groovy666_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy674_Bug.groovy | 2 -
src/test/groovy/bugs/Groovy675_Bug.groovy | 3 -
src/test/groovy/bugs/Groovy831_Bug.groovy | 2 -
src/test/groovy/bugs/Groovy965_Bug.groovy | 2 -
src/test/groovy/bugs/GuillaumesBug.groovy | 3 -
src/test/groovy/bugs/GuillaumesMapBug.groovy | 3 -
src/test/groovy/bugs/InterfaceImplBug.groovy | 8 +-
...vokeNormalMethodFromBuilder_Groovy657Bug.groovy | 2 -
src/test/groovy/bugs/MethodPointerBug.groovy | 9 +-
src/test/groovy/bugs/MorgansBug.groovy | 3 -
.../groovy/bugs/NullAsBooleanCoercionTest.groovy | 2 -
src/test/groovy/bugs/PrimitivePropertyBug.groovy | 2 -
src/test/groovy/bugs/PrintlnWithNewBug.groovy | 3 -
src/test/groovy/bugs/PropertyNameBug.groovy | 7 +-
src/test/groovy/bugs/RodsBug.groovy | 13 +-
.../groovy/bugs/StaticClosurePropertyBug.groovy | 3 -
.../groovy/bugs/SynchronizedBytecodeBug.groovy | 3 -
src/test/groovy/bugs/TryCatch2Bug.groovy | 3 -
src/test/groovy/bugs/TryCatchBug.groovy | 3 -
src/test/groovy/bugs/VariablePrecedence.groovy | 3 -
src/test/groovy/bugs/ZoharsBug.groovy | 3 -
.../groovy/execute/ExecuteTest_LinuxSolaris.groovy | 2 -
src/test/groovy/execute/ExecuteTest_Windows.groovy | 2 -
src/test/groovy/grape/GrabResolverTest.groovy | 199 ++-
src/test/groovy/grape/GrapeIvyTest.groovy | 798 +++++----
.../stc/AnonymousInnerClassSTCTest.groovy | 4 -
.../stc/ArraysAndCollectionsSTCTest.groovy | 2 -
.../groovy/transform/stc/CategoriesSTCTest.groovy | 2 -
.../groovy/transform/stc/ClosuresSTCTest.groovy | 3 -
.../groovy/transform/stc/CoercionSTCTest.groovy | 2 -
.../transform/stc/ConstructorsSTCTest.groovy | 2 -
.../stc/CustomErrorCollectorSTCTest.groovy | 2 -
.../groovy/transform/stc/DelegatesToSTCTest.groovy | 3 -
.../stc/FieldsAndPropertiesSTCTest.groovy | 12 +-
.../groovy/transform/stc/GenericsSTCTest.groovy | 2 -
.../IOGMClosureParamTypeInferenceSTCTest.groovy | 2 -
src/test/groovy/transform/stc/LoopsSTCTest.groovy | 2 -
.../groovy/transform/stc/MethodCallsSTCTest.groovy | 2 -
...sourceGMClosureParamTypeInferenceSTCTest.groovy | 2 -
.../groovy/transform/stc/ReturnsSTCTest.groovy | 2 -
.../transform/stc/STCExtensionMethodsTest.groovy | 2 -
.../transform/stc/STCnAryExpressionTest.groovy | 2 -
.../stc/STCwithTransformationsTest.groovy | 2 -
...SocketGMClosureParamTypeInferenceSTCTest.groovy | 2 -
.../transform/stc/TernaryOperatorSTCTest.groovy | 2 -
.../stc/TypeCheckingExtensionsTest.groovy | 2 -
.../transform/stc/TypeCheckingModeTest.groovy | 2 -
.../transform/stc/TypeInferenceSTCTest.groovy | 2 -
.../transform/stc/UnaryOperatorSTCTest.groovy | 2 -
src/test/groovy/transform/stc/WithSTCTest.groovy | 2 -
.../transform/stc/vm6/MethodCallsSTCTest.groovy | 2 -
src/test/groovy/util/BufferedIteratorTest.groovy | 2 -
src/test/groovy/util/BuilderSupportTest.groovy | 13 +-
src/test/groovy/util/ConfigSlurperTest.groovy | 10 +-
.../groovy/util/FactoryBuilderSupportTest.groovy | 2 -
.../util/GroovyCollectionsStarImportTest.groovy | 4 +-
src/test/groovy/util/GroovyCollectionsTest.groovy | 4 +-
src/test/groovy/util/GroovyScriptEngineTest.groovy | 3 -
src/test/groovy/util/IndentPrinterTest.groovy | 1 -
.../util/JavadocAssertionTestBuilderTest.groovy | 267 ++-
src/test/groovy/util/NodeTest.groovy | 5 +-
src/test/groovy/util/ObservableListTest.groovy | 635 ++++---
src/test/groovy/util/ObservableMapTest.groovy | 473 +++---
src/test/groovy/util/ObservableSetTests.groovy | 5 +-
src/test/groovy/util/OrderByTest.groovy | 3 -
src/test/groovy/util/ProxyGeneratorTest.groovy | 3 -
src/test/groovy/util/ProxyTest.groovy | 3 -
.../ClosureAndInnerClassNodeStructureTest.groovy | 2 -
.../groovy/ast/CodeVisitorSupportTest.groovy | 49 +-
.../codehaus/groovy/ast/GenericsTestCase.groovy | 2 -
.../org/codehaus/groovy/ast/MethodNodeTest.groovy | 151 +-
.../codehaus/groovy/ast/builder/AstAssert.groovy | 16 -
.../ast/builder/AstBuilderFromCodeTest.groovy | 1744 ++++++++++----------
.../ast/builder/AstBuilderFromStringTest.groovy | 702 ++++----
.../groovy/ast/builder/WithAstBuilder.groovy | 77 +-
.../AstBuilderFromCodePackageImportTest.groovy | 84 +-
111 files changed, 3192 insertions(+), 3477 deletions(-)
diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle
index 49e447e..d0ba492 100644
--- a/gradle/pomconfigurer.gradle
+++ b/gradle/pomconfigurer.gradle
@@ -717,6 +717,15 @@ project.ext.pomConfigureClosureWithoutTweaks = {
name 'Stephane Landelle'
}
contributor {
+ name 'Stephane Maldini'
+ }
+ contributor {
+ name 'Mark Volkmann'
+ }
+ contributor {
+ name 'Andrew Taylor'
+ }
+ contributor {
name 'Vladimir Vivien'
}
contributor {
@@ -744,6 +753,15 @@ project.ext.pomConfigureClosureWithoutTweaks = {
name 'Dominik Przybysz'
}
contributor {
+ name 'Jason Thomas'
+ }
+ contributor {
+ name 'Trygve Amundsens'
+ }
+ contributor {
+ name 'Morgan Hankins'
+ }
+ contributor {
name 'Shruti Gupta'
}
contributor {
@@ -815,7 +833,7 @@ project.ext.pomConfigureClosure = {
// add 'packaging' node
pom.withXml { xmlProvider ->
def xml = xmlProvider.asString()
- def pomXml = new XmlParser().parse(new ByteArrayInputStream(xml.toString().bytes))
+ def pomXml = new XmlParser().parse(new ByteArrayInputStream(xml.toString().getBytes("UTF-8")))
pomXml.version[0] + { packaging('jar') }
diff --git a/src/main/groovy/groovy/beans/ListenerList.groovy b/src/main/groovy/groovy/beans/ListenerList.groovy
index b8119f1..29dee82 100644
--- a/src/main/groovy/groovy/beans/ListenerList.groovy
+++ b/src/main/groovy/groovy/beans/ListenerList.groovy
@@ -109,8 +109,6 @@ import java.lang.annotation.Target
* </ul>
*
* @see ListenerListASTTransformation
- * @author Alexander Klein
- * @author Hamlet D'Arcy
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
diff --git a/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy b/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
index 1d7fbf7..ef61a78 100644
--- a/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
+++ b/src/main/groovy/groovy/beans/ListenerListASTTransformation.groovy
@@ -62,9 +62,6 @@ import org.objectweb.asm.Opcodes
* <p>
* Additionally it adds corresponding fire<Event> methods.
* <p>
- *
- * @author Alexander Klein
- * @author Hamlet D'Arcy
*/
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
class ListenerListASTTransformation implements ASTTransformation, Opcodes {
diff --git a/src/main/groovy/groovy/lang/GString.java b/src/main/groovy/groovy/lang/GString.java
index d2b1d5b..2a0c40e 100644
--- a/src/main/groovy/groovy/lang/GString.java
+++ b/src/main/groovy/groovy/lang/GString.java
@@ -34,11 +34,10 @@ import java.util.regex.Pattern;
* ${user} how are you?" which can be evaluated lazily. Advanced users can
* iterate over the text and values to perform special processing, such as for
* performing SQL operations, the values can be substituted for ? and the
- * actual value objects can be bound to a JDBC statement. The lovely name of
- * this class was suggested by Jules Gosnell and was such a good idea, I
- * couldn't resist :)
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
+ * actual value objects can be bound to a JDBC statement.
+ * <p>
+ * James Strachan: The lovely name of this class was suggested by Jules Gosnell
+ * and was such a good idea, I couldn't resist :)
*/
public abstract class GString extends GroovyObjectSupport implements Comparable, CharSequence, Writable, Buildable, Serializable {
@@ -57,7 +56,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
@Override
public String[] getStrings() {
- return new String[]{ "" };
+ return new String[]{""};
}
};
@@ -85,8 +84,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
public Object invokeMethod(String name, Object args) {
try {
return super.invokeMethod(name, args);
- }
- catch (MissingMethodException e) {
+ } catch (MissingMethodException e) {
// lets try invoke the method on the real String
return InvokerHelper.invokeMethod(toString(), name, args);
}
@@ -135,7 +133,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
}
public GString plus(String that) {
- return plus(new GStringImpl(EMPTY_OBJECT_ARRAY, new String[] { that }));
+ return plus(new GStringImpl(EMPTY_OBJECT_ARRAY, new String[]{that}));
}
public int getValueCount() {
@@ -151,8 +149,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
Writer buffer = new StringBuilderWriter(calcInitialCapacity());
try {
writeTo(buffer);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new StringWriterIOException(e);
}
@@ -169,7 +166,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
initialCapacity += values.length * Math.max(initialCapacity / strings.length, 8);
- return Math.max((int) (initialCapacity * 1.2), 16);
+ return Math.max((int) (initialCapacity * 1.2), 16);
}
@Override
@@ -212,10 +209,10 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
for (int i = 0, size = s.length; i < size; i++) {
builder.getProperty(MKP);
- builder.invokeMethod(YIELD, new Object[]{ s[i] });
+ builder.invokeMethod(YIELD, new Object[]{s[i]});
if (i < numberOfValues) {
builder.getProperty(MKP);
- builder.invokeMethod(YIELD, new Object[]{ values[i] });
+ builder.invokeMethod(YIELD, new Object[]{values[i]});
}
}
}
@@ -271,6 +268,6 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
}
public byte[] getBytes(String charset) throws UnsupportedEncodingException {
- return toString().getBytes(charset);
+ return toString().getBytes(charset);
}
}
diff --git a/src/main/groovy/groovy/util/ConfigSlurper.groovy b/src/main/groovy/groovy/util/ConfigSlurper.groovy
index 20d0723..dd0c90e 100644
--- a/src/main/groovy/groovy/util/ConfigSlurper.groovy
+++ b/src/main/groovy/groovy/util/ConfigSlurper.groovy
@@ -36,8 +36,6 @@ import org.codehaus.groovy.runtime.InvokerHelper
* Settings can either be bound into nested maps or onto a specified JavaBean instance.
* In the latter case, an error will be thrown if a property cannot be bound.
*
- * @author Graeme Rocher
- * @author Andres Almiray
* @since 1.5
*/
class ConfigSlurper {
diff --git a/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy b/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
index fbb16e7..f6f10a2 100644
--- a/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
+++ b/src/main/groovy/groovy/util/FileNameByRegexFinder.groovy
@@ -21,9 +21,6 @@ package groovy.util
/**
* Find files according to a base directory and an includes and excludes pattern.
* The include and exclude patterns conform to regex conventions.
- *
- * @author Dierk Koenig
- * @author Paul King
*/
class FileNameByRegexFinder implements IFileNameFinder {
diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstBuilder.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstBuilder.groovy
index 3c5efc9..f181b23 100644
--- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstBuilder.groovy
+++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstBuilder.groovy
@@ -29,13 +29,11 @@ import org.codehaus.groovy.control.CompilePhase
* You can convert a String into AST using the buildFromString method.
* You can convert code into AST using the buildFromCode method.
* You can use the AST DSL with the buildFromSpec method.
- *
- * For more information, see the resources on the Groovy wiki pages.
*
- * @author Hamlet D'Arcy
+ * For more information, see the resources on the Groovy wiki pages.
*/
@CompileStatic
-public class AstBuilder {
+class AstBuilder {
/**
* Builds AST based on the code within the {@link Closure} parameter.
@@ -45,16 +43,12 @@ public class AstBuilder {
* you most likely need to add stronger typing. For instance, this will not work:
* <code>
* def builder = new AstBuilder()
- * builder.buildFromCode {
- * // some code
- * }
- * </code>
+ * builder.buildFromCode {* // some code
+ *}* </code>
* While this code will:
* <code>
- * new AstBuilder().buildFromCode {
- * // some code
- * }
- * </code>
+ * new AstBuilder().buildFromCode {* // some code
+ *}* </code>
*
* The compiler rewrites buildFromCode invocations into {@link AstBuilder#buildFromString(CompilePhase, boolean, String)}
* invocations. An exception raised during AST generation will show a stack trace from {@link AstBuilder#buildFromString(CompilePhase, boolean, String)}
@@ -73,8 +67,7 @@ public class AstBuilder {
* @param block
* the code that will be converted
* @returns a List of {@link ASTNode} .
- * @throws IllegalStateException
- * this method may not be invoked at runtime. It works via a compile-time transformation
+ * @throws IllegalStateException* this method may not be invoked at runtime. It works via a compile-time transformation
* of the closure source code into a String, which is sent to the {@link AstBuilder#buildFromString(CompilePhase, boolean, String)}
* method. The buildFromCode() method must be invoked against a strongly typed AstBuilder.
*/
@@ -96,8 +89,7 @@ Are you sure you are using it correctly?
* @param source
* The source code String that will be compiled.
* @returns a List of {@link ASTNode} .
- * @throws IllegalArgumentException
- * if source is null or empty
+ * @throws IllegalArgumentException* if source is null or empty
*/
List<ASTNode> buildFromString(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, String source) {
if (!source || "" == source.trim()) throw new IllegalArgumentException("A source must be specified")
@@ -116,8 +108,7 @@ Are you sure you are using it correctly?
* @param source
* The source code String that will be compiled. The string must be a block wrapped in curly braces.
* @returns a List of {@link ASTNode} .
- * @throws IllegalArgumentException
- * if source is null or empty
+ * @throws IllegalArgumentException* if source is null or empty
*/
private List<ASTNode> buildFromBlock(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, String source) {
if (!source || "" == source.trim()) throw new IllegalArgumentException("A source must be specified")
@@ -126,7 +117,7 @@ Are you sure you are using it correctly?
// find the block statement from the result, and unwrap it from one level.
result.collect { node ->
if (node instanceof BlockStatement) {
- ((BlockStatement)node).statements[0] //unwrap the artifact of pre-pending the goto label
+ ((BlockStatement) node).statements[0] //unwrap the artifact of pre-pending the goto label
} else {
node
}
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 c596a66..b450a09 100644
--- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy
+++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstSpecificationCompiler.groovy
@@ -94,14 +94,12 @@ import org.codehaus.groovy.syntax.Types
/**
* Handles parsing the properties from the closure into values that can be referenced.
- *
+ *
* This object is very stateful and not threadsafe. It accumulates expressions in the
* 'expression' field as they are found and executed within the DSL.
- *
+ *
* 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.
- *
- * @author Hamlet D'Arcy
*/
class AstSpecificationCompiler implements GroovyInterceptable {
@@ -123,17 +121,17 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * This method takes a List of Classes (a "spec"), and makes sure that the expression field
- * contains those classes. It is a safety mechanism to enforce that the DSL is being called
- * properly.
- *
- * @param methodName
- * the name of the method within the DSL that is being invoked. Used in creating error messages.
- * @param spec
- * the list of Class objects that the method expects to have in the expression field when invoked.
- * @return
- * the portions of the expression field that adhere to the spec.
- */
+ * This method takes a List of Classes (a "spec"), and makes sure that the expression field
+ * contains those classes. It is a safety mechanism to enforce that the DSL is being called
+ * properly.
+ *
+ * @param methodName
+ * the name of the method within the DSL that is being invoked. Used in creating error messages.
+ * @param spec
+ * the list of Class objects that the method expects to have in the expression field when invoked.
+ * @return
+ * the portions of the expression field that adhere to the spec.
+ */
private List<ASTNode> enforceConstraints(String methodName, List<Class> spec) {
// enforce that the correct # arguments was passed
@@ -153,15 +151,15 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * This method helps you take Closure parameters to a method and bundle them into
- * constructor calls to a specific ASTNode subtype.
- * @param name
- * name of object being constructed, used to create helpful error message.
- * @param argBlock
- * the actual parameters being specified for the node
- * @param constructorStatement
- * the type specific construction code that will be run
- */
+ * This method helps you take Closure parameters to a method and bundle them into
+ * constructor calls to a specific ASTNode subtype.
+ * @param name
+ * name of object being constructed, used to create helpful error message.
+ * @param argBlock
+ * the actual parameters being specified for the node
+ * @param constructorStatement
+ * the type specific construction code that will be run
+ */
@CompileStatic
private void captureAndCreateNode(String name, @DelegatesTo(AstSpecificationCompiler) Closure argBlock, Closure constructorStatement) {
if (!argBlock) throw new IllegalArgumentException("nodes of type $name require arguments to be specified")
@@ -176,17 +174,17 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * Helper method to convert a DSL invocation into an ASTNode instance.
- *
- * @param target
- * the class you are going to create
- * @param typeAlias
- * the DSL keyword that was used to invoke this type
- * @param ctorArgs
- * a specification of what arguments the constructor expects
- * @param argBlock
- * the single closure argument used during invocation
- */
+ * Helper method to convert a DSL invocation into an ASTNode instance.
+ *
+ * @param target
+ * the class you are going to create
+ * @param typeAlias
+ * the DSL keyword that was used to invoke this type
+ * @param ctorArgs
+ * a specification of what arguments the constructor expects
+ * @param argBlock
+ * the single closure argument used during invocation
+ */
private void makeNode(Class target, String typeAlias, List<Class<? super ASTNode>> ctorArgs, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode(target.class.simpleName, argBlock) {
target.newInstance(*enforceConstraints(typeAlias, ctorArgs))
@@ -194,14 +192,14 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * Helper method to convert a DSL invocation with a list of parameters specified
- * in a Closure into an ASTNode instance.
- *
- * @param target
- * the class you are going to create
- * @param argBlock
- * the single closure argument used during invocation
- */
+ * Helper method to convert a DSL invocation with a list of parameters specified
+ * in a Closure into an ASTNode instance.
+ *
+ * @param target
+ * the class you are going to create
+ * @param argBlock
+ * the single closure argument used during invocation
+ */
private void makeNodeFromList(Class target, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
//todo: add better error handling?
captureAndCreateNode(target.simpleName, argBlock) {
@@ -210,13 +208,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * Helper method to convert a DSL invocation with a String parameter into a List of ASTNode instances.
- *
- * @param argBlock
- * the single closure argument used during invocation
- * @param input
- * the single String argument used during invocation
- */
+ * Helper method to convert a DSL invocation with a String parameter into a List of ASTNode instances.
+ *
+ * @param argBlock
+ * the single closure argument used during invocation
+ * @param input
+ * the single String argument used during invocation
+ */
private void makeListOfNodes(@DelegatesTo(AstSpecificationCompiler) Closure argBlock, String input) {
captureAndCreateNode(input, argBlock) {
new ArrayList(expression)
@@ -224,33 +222,33 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
/**
- * Helper method to convert a DSL invocation with a String parameter into an Array of ASTNode instances.
- *
- * @param argBlock
- * the single closure argument used during invocation
- * @param target
- * the target type
- */
+ * Helper method to convert a DSL invocation with a String parameter into an Array of ASTNode instances.
+ *
+ * @param argBlock
+ * the single closure argument used during invocation
+ * @param target
+ * the target type
+ */
private void makeArrayOfNodes(Object target, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode(target.class.simpleName, argBlock) {
expression.toArray(target)
}
}
-
- /**
- * Helper method to convert a DSL invocation into an ASTNode instance when a Class parameter is specified.
- *
- * @param target
- * the class you are going to create
- * @param alias
- * the DSL keyword that was used to invoke this type
- * @param spec
- * the list of Classes that you expect to be present as parameters
- * @param argBlock
- * the single closure argument used during invocation
- * @param type
- * a type parameter
- */
+
+ /**
+ * Helper method to convert a DSL invocation into an ASTNode instance when a Class parameter is specified.
+ *
+ * @param target
+ * the class you are going to create
+ * @param alias
+ * the DSL keyword that was used to invoke this type
+ * @param spec
+ * the list of Classes that you expect to be present as parameters
+ * @param argBlock
+ * the single closure argument used during invocation
+ * @param type
+ * a type parameter
+ */
private void makeNodeWithClassParameter(Class target, String alias, List<Class> spec, @DelegatesTo(AstSpecificationCompiler) Closure argBlock, Class type) {
captureAndCreateNode(target.class.simpleName, argBlock) {
expression.add(0, ClassHelper.make(type))
@@ -732,13 +730,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
//todo: add better error handling?
if (argBlock) {
- args.each {name, type ->
+ args.each { name, type ->
captureAndCreateNode("Parameter", argBlock) {
new Parameter(ClassHelper.make(type), name, expression[0])
}
}
} else {
- args.each {name, type ->
+ args.each { name, type ->
expression << (new Parameter(ClassHelper.make(type), name))
}
}
@@ -847,24 +845,24 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
if (expression[3].size() > 0) {
def clazz = expression[3][0].getClass()
- switch(clazz) {
+ switch (clazz) {
case GenericsType:
result.setGenericsTypes(new ArrayList(expression[3]) as GenericsType[])
break
case MethodNode:
- expression[3].each{ result.addMethod(it) }
+ expression[3].each { result.addMethod(it) }
break
case ConstructorNode:
- expression[3].each{ result.addConstructor(it) }
+ expression[3].each { result.addConstructor(it) }
break
case PropertyNode:
- expression[3].each{
+ expression[3].each {
it.field.owner = result
result.addProperty(it)
}
break
case FieldNode:
- expression[3].each{
+ expression[3].each {
it.owner = result
result.addField(it)
}
@@ -902,7 +900,7 @@ class AstSpecificationCompiler implements GroovyInterceptable {
captureAndCreateNode("TryCatchStatement", argBlock) {
def result = new TryCatchStatement(expression[0], expression[1])
def catchStatements = expression.tail().tail()
- catchStatements.each {statement -> result.addCatch(statement) }
+ catchStatements.each { statement -> result.addCatch(statement) }
return result
}
}
@@ -948,7 +946,8 @@ 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) //default is inclusive
+ expression << new RangeExpression(new ConstantExpression(range.getFrom()), new ConstantExpression(range.getTo()), true)
+ //default is inclusive
}
/**
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 400566e..3947819 100644
--- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy
+++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy
@@ -31,12 +31,11 @@ import java.security.PrivilegedAction
/**
* This class handles converting Strings to ASTNode lists.
- *
- * @author Hamlet D'Arcy
*/
@CompileStatic
-@PackageScope class AstStringCompiler {
-
+@PackageScope
+class AstStringCompiler {
+
/**
* Performs the String source to {@link List} of {@link ASTNode}.
*
@@ -49,7 +48,9 @@ import java.security.PrivilegedAction
List<ASTNode> compile(String script, CompilePhase compilePhase, boolean statementsOnly) {
final scriptClassName = makeScriptClassName()
GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", "/groovy/script")
- CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, AccessController.doPrivileged({ new GroovyClassLoader() } as PrivilegedAction<GroovyClassLoader>))
+ CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, AccessController.doPrivileged({
+ new GroovyClassLoader()
+ } as PrivilegedAction<GroovyClassLoader>))
cu.addSource(codeSource.getName(), script)
cu.compile(compilePhase.getPhaseNumber())
// collect all the ASTNodes into the result, possibly ignoring the script body if desired
diff --git a/src/test/groovy/StringTest.groovy b/src/test/groovy/StringTest.groovy
index 7d70733..a8cc253 100644
--- a/src/test/groovy/StringTest.groovy
+++ b/src/test/groovy/StringTest.groovy
@@ -20,8 +20,6 @@ package groovy
/**
* Various tests for Strings.
- *
- * @author Michael Baehr
*/
class StringTest extends GroovyTestCase {
diff --git a/src/test/groovy/beans/ListenerListASTTest.groovy b/src/test/groovy/beans/ListenerListASTTest.groovy
index dae62aa..d36f66b 100644
--- a/src/test/groovy/beans/ListenerListASTTest.groovy
+++ b/src/test/groovy/beans/ListenerListASTTest.groovy
@@ -20,9 +20,6 @@ package groovy.beans
/**
* Unit test for ListenerList.
- *
- * @author Alexander Klein
- * @author Hamlet D'Arcy
*/
class ListenerListASTTest extends GroovyTestCase {
diff --git a/src/test/groovy/beans/VetoableTest.groovy b/src/test/groovy/beans/VetoableTest.groovy
index e46c8b7..2a8519a 100644
--- a/src/test/groovy/beans/VetoableTest.groovy
+++ b/src/test/groovy/beans/VetoableTest.groovy
@@ -1,462 +1,459 @@
-/*
- * 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.beans
-
-import org.codehaus.groovy.control.CompilationFailedException
-
-/**
- * @author Danno Ferrin (shemnon)
- */
-class VetoableTest extends GroovyTestCase {
-
- void testSimpleConstrainedProperty() {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- class VetoableTestBean1 {
- @Vetoable String name
- }
-
- sb = new VetoableTestBean1()
- sb.name = "foo"
- changed = false
- sb.vetoableChange = { pce ->
- if (changed) {
- throw new java.beans.PropertyVetoException("Twice, even!", pce)
- } else {
- changed = true
- }
- }
- sb.name = "foo"
- sb.name = "bar"
- try {
- sb.name = "baz"
- changed = false
- } catch (java.beans.PropertyVetoException pve) {
- // yep, we were vetoed
- }
- """)
- assert shell.changed
- }
-
- void testBindableVetoableProperty() {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Bindable
- import groovy.beans.Vetoable
-
- class VetoableTestBean2 {
- @Bindable @Vetoable String name
- }
-
- sb = new VetoableTestBean2()
- sb.name = "foo"
- vetoCheck = false
- changed = false
- sb.vetoableChange = { vetoCheck = true }
- sb.propertyChange = { changed = true }
- sb.name = "foo"
- assert !vetoCheck
- assert !changed
- sb.name = "bar"
- """)
- assert shell.changed
- assert shell.vetoCheck
- }
-
- void testMultipleProperties() {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Bindable
- import groovy.beans.Vetoable
-
- class VetoableTestBean3 {
- String u1
- @Bindable String b1
- @Vetoable String c1
- @Bindable @Vetoable String bc1
- String u2
- @Bindable String b2
- @Vetoable String c2
- @Bindable @Vetoable String bc2
- }
-
- sb = new VetoableTestBean3(u1:'a', b1:'b', c1:'c', bc1:'d', u2:'e', b2:'f', c2:'g', bc2:'h')
- changed = 0
- sb.vetoableChange = { changed++ }
- sb.propertyChange = { changed++ }
- sb.u1 = 'i'
- sb.b1 = 'j'
- sb.c1 = 'k'
- sb.bc1 = 'l'
- sb.u2 = 'm'
- sb.b2 = 'n'
- sb.c2 = 'o'
- sb.bc2 = 'p'
- """)
- assert shell.changed == 8
- }
-
- void testExisingSetter() {
- assertScript """
- class VetoableTestBean4 {
- @groovy.beans.Vetoable String name
- void setName() { }
- }
- new VetoableTestBean4()
- """
- }
-
- void testWithSettersAndGetters() {
- for (int i = 0; i < 16; i++) {
- boolean vetoClass = i & 1
- boolean field = i & 2
- boolean setter = i & 4
- boolean getter = i & 8
- int expectedCount = (vetoClass && !field)?2:1
- String script = """
- import groovy.beans.Vetoable
-
- ${vetoClass?'@Vetoable ':''}class VetoableTestSettersAndGetters$i {
-
- @Vetoable String alwaysVetoable
- ${field?'protected ':''} String name
-
- ${setter?'':'//'}void setName(String newName) { this.@name = "x\$newName" }
- ${getter?'':'//'}String getName() { return this.@name }
- }
- sb = new VetoableTestSettersAndGetters$i(name:"foo", alwaysVetoable:"bar")
- changed = 0
- sb.vetoableChange = {evt ->
- changed++
- }
- sb.alwaysVetoable = "baz"
- sb.name = "bif"
- assert changed == $expectedCount
- """
- try {
- GroovyShell shell = new GroovyShell()
- shell.evaluate(script);
- } catch (Throwable t) {
- System.out.println("Failed Script: $script")
- throw t
- }
- }
- }
-
-
- void testOnField() {
- GroovyShell shell = new GroovyShell()
- shouldFail(CompilationFailedException) {
- shell.evaluate("""
- class VetoableTestBean5 {
- public @groovy.beans.Vetoable String name
- }
- """)
- }
- }
-
- void testOnStaticField() {
- GroovyShell shell = new GroovyShell()
- shouldFail(CompilationFailedException) {
- shell.evaluate("""
- class VetoableTestBean6 {
- @groovy.beans.Vetoable static String name
- }
- """)
- }
- }
-
- void testInheritance() {
- for (int i = 0; i < 15; i++) {
- boolean bindParent = i & 1
- boolean bindChild = i & 2
- boolean vetoParent = i & 4
- boolean vetoChild = i & 8
- int count = (bindParent?1:0) + (bindChild?1:0) + (vetoParent?1:0) + (vetoChild?1:0)
- String script = """
- import groovy.beans.Bindable
- import groovy.beans.Vetoable
-
- class InheritanceParentBean$i {
- ${bindParent?'@Bindable':''} String bp
- ${vetoParent?'@Vetoable':''} String vp
- }
-
- class InheritanceChildBean$i extends InheritanceParentBean$i {
- ${bindChild?'@Bindable':''} String bc
- ${vetoChild?'@Vetoable':''} String vc
- }
-
- cb = new InheritanceChildBean$i(bp:'a', vp:'b', bc:'c', vc:'d')
- changed = 0
- ${bindParent|bindChild?'cb.propertyChange = { changed++ }':''}
- ${vetoParent|vetoChild?'cb.vetoableChange = { changed++ }':''}
- cb.bp = 'e'
- cb.vp = 'f'
- cb.bc = 'g'
- cb.vc = 'h'
- assert changed == $count
- """
- try {
- GroovyShell shell = new GroovyShell()
- shell.evaluate(script);
- } catch (Throwable t) {
- System.out.println("Failed Script: $script")
- throw t
- }
- }
- }
-
- void testPrimitiveTypes() {
- assertScript """
- import groovy.beans.Vetoable
-
- class VetoableTestBean8 {
- @Vetoable String testField
- @Vetoable boolean testBoolean
- @Vetoable byte testByte
- @Vetoable short testShort
- @Vetoable int testInt
- @Vetoable long testLong
- @Vetoable float testFloat
- @Vetoable double testDouble
- }
-
- sb = new VetoableTestBean8()
- sb.testField = "bar"
- int changed = 0
- sb.vetoableChange = {changed++}
- sb.testField = "foo"
- sb.testBoolean = true
- sb.testByte = 1
- sb.testShort = 1
- sb.testInt = 1
- sb.testLong = 1
- sb.testFloat = 1
- sb.testDouble = 1
- assert changed == 8
- """
- }
-
- void testBadInheritance() {
- shouldFail(CompilationFailedException) {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- class VetoableTestBean9 {
- @Vetoable String testField
- void addVetoableChangeListener(java.beans.VetoableChangeListener l) {}
- }
- new VetoableTestBean9()
- """)
- }
- shouldFail(CompilationFailedException) {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- class VetoableTestBean10 {
- void addPropertyChangeListener(java.beans.VetoableChangeListener l) {}
- }
-
- class VetoableTestBean11 extends VetoableTestBean9 {
- @Vetoable String testField
- }
-
- new VetoableTestBean10()
- """)
- }
- }
-
- void testVetoableParent() {
- assertScript """
- import groovy.beans.Vetoable
- import java.beans.PropertyChangeEvent
- import java.beans.VetoableChangeListener
-
- @Vetoable
- class VetoableTestBeanChild extends VetoableTestBeanParent {
- String prop2
- VetoableTestBeanChild() {
- super()
- }
- }
-
- @Vetoable
- class VetoableTestBeanParent implements VetoableChangeListener {
- String prop1
- VetoableTestBeanParent() {
- addVetoableChangeListener(this)
- }
-
- void vetoableChange(PropertyChangeEvent event) {}
- }
-
- new VetoableTestBeanChild()
- """
- }
-
- void testFinalProperty() {
- shouldFail(CompilationFailedException) {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- class VetoableTestBean11 {
- @Vetoable final String testField
- }
- 1+1
- """)
- }
- }
-
- void testOnClassFinalProperty() {
- shouldFail(ReadOnlyPropertyException) {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- @Vetoable class VetoableTestBean12 {
- String testField
- final String anotherTestField = 'Fixed'
- }
-
- sb = new VetoableTestBean12()
- int changed = 0
- sb.vetoableChange = {changed++}
- sb.testField = 'newValue'
- assert changed == 1
-
- sb.anotherTestField = 'Changed'
- """)
- }
- }
-
- void testFinalClass() {
- shouldFail(ReadOnlyPropertyException) {
- GroovyShell shell = new GroovyShell()
- shell.evaluate("""
- import groovy.beans.Vetoable
-
- @Vetoable final class VetoableTestBean12 {
- String testField
- final String anotherTestField = 'Fixed'
- }
-
- sb = new VetoableTestBean12()
- int changed = 0
- sb.vetoableChange = {changed++}
- sb.testField = 'newValue'
- assert changed == 1
-
- sb.anotherTestField = 'Changed'
- """)
- }
- }
-
- void testClassMarkers() {
- for (int i = 0; i < 31; i++) {
- boolean bindField = i & 1
- boolean bindClass = i & 2
- boolean vetoField = i & 4
- boolean vetoClass = i & 8
- boolean staticField = i & 16
- int vetoCount = vetoClass?(staticField?4:5):(vetoField?2:0);
- int bindCount = bindClass?(staticField?4:5):(bindField?2:0);
-
- String script = """
- import groovy.beans.Bindable
- import groovy.beans.Vetoable
-
- ${vetoClass?'@Vetoable ':''}${bindClass?'@Bindable ':''}class ClassMarkerBean$i {
- String neither
-
- ${vetoField?'@Vetoable ':''}String veto
-
- ${bindField?'@Bindable ':''}String bind
-
- ${vetoField?'@Vetoable ':''}${bindField?'@Bindable ':''}String both
-
- ${staticField?'static ':''}String staticField
- }
-
- cb = new ClassMarkerBean$i(neither:'a', veto:'b', bind:'c', both:'d', staticField:'e')
- vetoCount = 0
- bindCount = 0
- ${bindClass|bindField?'cb.propertyChange = { bindCount++ }':''}
- ${vetoClass|vetoField?'cb.vetoableChange = { vetoCount++ }':''}
- cb.neither = 'f'
- cb.bind = 'g'
- cb.veto = 'h'
- cb.both = 'i'
- cb.staticField = 'j'
- assert vetoCount == $vetoCount
- assert bindCount == $bindCount
- """
- try {
- GroovyShell shell = new GroovyShell()
- shell.evaluate(script);
- } catch (Throwable t) {
- System.out.println("Failed Script: $script")
- throw t
- }
- }
- }
-
- void testGetVetoableChangeListeners() {
- assertScript """
- import groovy.beans.Vetoable
- import java.beans.VetoableChangeListener
- import java.beans.PropertyChangeEvent
-
- class VetoableTestBean14 {
- @Vetoable String foo
- @Vetoable String bar
- }
-
- class FooVetoListener implements VetoableChangeListener {
- void vetoableChange( PropertyChangeEvent e ) { }
- }
-
- sb = new VetoableTestBean14()
- assert !sb.vetoableChangeListeners
- listener = new FooVetoListener()
- sb.addVetoableChangeListener("foo",listener)
- assert !sb.getVetoableChangeListeners("bar")
- assert sb.getVetoableChangeListeners("foo") == [listener]
- assert sb.vetoableChangeListeners.size() == 1
- """
- }
-
- void testPropertyChangeMethodWithCompileStatic() {
- assertScript """
- import groovy.beans.Vetoable
- import groovy.transform.CompileStatic
-
- @CompileStatic
- class MyBean {
- @Vetoable String test = "a test"
- }
- assert new MyBean()
- """
- }
+/*
+ * 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.beans
+
+import org.codehaus.groovy.control.CompilationFailedException
+
+class VetoableTest extends GroovyTestCase {
+
+ void testSimpleConstrainedProperty() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean1 {
+ @Vetoable String name
+ }
+
+ sb = new VetoableTestBean1()
+ sb.name = "foo"
+ changed = false
+ sb.vetoableChange = { pce ->
+ if (changed) {
+ throw new java.beans.PropertyVetoException("Twice, even!", pce)
+ } else {
+ changed = true
+ }
+ }
+ sb.name = "foo"
+ sb.name = "bar"
+ try {
+ sb.name = "baz"
+ changed = false
+ } catch (java.beans.PropertyVetoException pve) {
+ // yep, we were vetoed
+ }
+ """)
+ assert shell.changed
+ }
+
+ void testBindableVetoableProperty() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Bindable
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean2 {
+ @Bindable @Vetoable String name
+ }
+
+ sb = new VetoableTestBean2()
+ sb.name = "foo"
+ vetoCheck = false
+ changed = false
+ sb.vetoableChange = { vetoCheck = true }
+ sb.propertyChange = { changed = true }
+ sb.name = "foo"
+ assert !vetoCheck
+ assert !changed
+ sb.name = "bar"
+ """)
+ assert shell.changed
+ assert shell.vetoCheck
+ }
+
+ void testMultipleProperties() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Bindable
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean3 {
+ String u1
+ @Bindable String b1
+ @Vetoable String c1
+ @Bindable @Vetoable String bc1
+ String u2
+ @Bindable String b2
+ @Vetoable String c2
+ @Bindable @Vetoable String bc2
+ }
+
+ sb = new VetoableTestBean3(u1:'a', b1:'b', c1:'c', bc1:'d', u2:'e', b2:'f', c2:'g', bc2:'h')
+ changed = 0
+ sb.vetoableChange = { changed++ }
+ sb.propertyChange = { changed++ }
+ sb.u1 = 'i'
+ sb.b1 = 'j'
+ sb.c1 = 'k'
+ sb.bc1 = 'l'
+ sb.u2 = 'm'
+ sb.b2 = 'n'
+ sb.c2 = 'o'
+ sb.bc2 = 'p'
+ """)
+ assert shell.changed == 8
+ }
+
+ void testExisingSetter() {
+ assertScript """
+ class VetoableTestBean4 {
+ @groovy.beans.Vetoable String name
+ void setName() { }
+ }
+ new VetoableTestBean4()
+ """
+ }
+
+ void testWithSettersAndGetters() {
+ for (int i = 0; i < 16; i++) {
+ boolean vetoClass = i & 1
+ boolean field = i & 2
+ boolean setter = i & 4
+ boolean getter = i & 8
+ int expectedCount = (vetoClass && !field)?2:1
+ String script = """
+ import groovy.beans.Vetoable
+
+ ${vetoClass?'@Vetoable ':''}class VetoableTestSettersAndGetters$i {
+
+ @Vetoable String alwaysVetoable
+ ${field?'protected ':''} String name
+
+ ${setter?'':'//'}void setName(String newName) { this.@name = "x\$newName" }
+ ${getter?'':'//'}String getName() { return this.@name }
+ }
+ sb = new VetoableTestSettersAndGetters$i(name:"foo", alwaysVetoable:"bar")
+ changed = 0
+ sb.vetoableChange = {evt ->
+ changed++
+ }
+ sb.alwaysVetoable = "baz"
+ sb.name = "bif"
+ assert changed == $expectedCount
+ """
+ try {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate(script);
+ } catch (Throwable t) {
+ System.out.println("Failed Script: $script")
+ throw t
+ }
+ }
+ }
+
+
+ void testOnField() {
+ GroovyShell shell = new GroovyShell()
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("""
+ class VetoableTestBean5 {
+ public @groovy.beans.Vetoable String name
+ }
+ """)
+ }
+ }
+
+ void testOnStaticField() {
+ GroovyShell shell = new GroovyShell()
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("""
+ class VetoableTestBean6 {
+ @groovy.beans.Vetoable static String name
+ }
+ """)
+ }
+ }
+
+ void testInheritance() {
+ for (int i = 0; i < 15; i++) {
+ boolean bindParent = i & 1
+ boolean bindChild = i & 2
+ boolean vetoParent = i & 4
+ boolean vetoChild = i & 8
+ int count = (bindParent?1:0) + (bindChild?1:0) + (vetoParent?1:0) + (vetoChild?1:0)
+ String script = """
+ import groovy.beans.Bindable
+ import groovy.beans.Vetoable
+
+ class InheritanceParentBean$i {
+ ${bindParent?'@Bindable':''} String bp
+ ${vetoParent?'@Vetoable':''} String vp
+ }
+
+ class InheritanceChildBean$i extends InheritanceParentBean$i {
+ ${bindChild?'@Bindable':''} String bc
+ ${vetoChild?'@Vetoable':''} String vc
+ }
+
+ cb = new InheritanceChildBean$i(bp:'a', vp:'b', bc:'c', vc:'d')
+ changed = 0
+ ${bindParent|bindChild?'cb.propertyChange = { changed++ }':''}
+ ${vetoParent|vetoChild?'cb.vetoableChange = { changed++ }':''}
+ cb.bp = 'e'
+ cb.vp = 'f'
+ cb.bc = 'g'
+ cb.vc = 'h'
+ assert changed == $count
+ """
+ try {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate(script);
+ } catch (Throwable t) {
+ System.out.println("Failed Script: $script")
+ throw t
+ }
+ }
+ }
+
+ void testPrimitiveTypes() {
+ assertScript """
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean8 {
+ @Vetoable String testField
+ @Vetoable boolean testBoolean
+ @Vetoable byte testByte
+ @Vetoable short testShort
+ @Vetoable int testInt
+ @Vetoable long testLong
+ @Vetoable float testFloat
+ @Vetoable double testDouble
+ }
+
+ sb = new VetoableTestBean8()
+ sb.testField = "bar"
+ int changed = 0
+ sb.vetoableChange = {changed++}
+ sb.testField = "foo"
+ sb.testBoolean = true
+ sb.testByte = 1
+ sb.testShort = 1
+ sb.testInt = 1
+ sb.testLong = 1
+ sb.testFloat = 1
+ sb.testDouble = 1
+ assert changed == 8
+ """
+ }
+
+ void testBadInheritance() {
+ shouldFail(CompilationFailedException) {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean9 {
+ @Vetoable String testField
+ void addVetoableChangeListener(java.beans.VetoableChangeListener l) {}
+ }
+ new VetoableTestBean9()
+ """)
+ }
+ shouldFail(CompilationFailedException) {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean10 {
+ void addPropertyChangeListener(java.beans.VetoableChangeListener l) {}
+ }
+
+ class VetoableTestBean11 extends VetoableTestBean9 {
+ @Vetoable String testField
+ }
+
+ new VetoableTestBean10()
+ """)
+ }
+ }
+
+ void testVetoableParent() {
+ assertScript """
+ import groovy.beans.Vetoable
+ import java.beans.PropertyChangeEvent
+ import java.beans.VetoableChangeListener
+
+ @Vetoable
+ class VetoableTestBeanChild extends VetoableTestBeanParent {
+ String prop2
+ VetoableTestBeanChild() {
+ super()
+ }
+ }
+
+ @Vetoable
+ class VetoableTestBeanParent implements VetoableChangeListener {
+ String prop1
+ VetoableTestBeanParent() {
+ addVetoableChangeListener(this)
+ }
+
+ void vetoableChange(PropertyChangeEvent event) {}
+ }
+
+ new VetoableTestBeanChild()
+ """
+ }
+
+ void testFinalProperty() {
+ shouldFail(CompilationFailedException) {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ class VetoableTestBean11 {
+ @Vetoable final String testField
+ }
+ 1+1
+ """)
+ }
+ }
+
+ void testOnClassFinalProperty() {
+ shouldFail(ReadOnlyPropertyException) {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ @Vetoable class VetoableTestBean12 {
+ String testField
+ final String anotherTestField = 'Fixed'
+ }
+
+ sb = new VetoableTestBean12()
+ int changed = 0
+ sb.vetoableChange = {changed++}
+ sb.testField = 'newValue'
+ assert changed == 1
+
+ sb.anotherTestField = 'Changed'
+ """)
+ }
+ }
+
+ void testFinalClass() {
+ shouldFail(ReadOnlyPropertyException) {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate("""
+ import groovy.beans.Vetoable
+
+ @Vetoable final class VetoableTestBean12 {
+ String testField
+ final String anotherTestField = 'Fixed'
+ }
+
+ sb = new VetoableTestBean12()
+ int changed = 0
+ sb.vetoableChange = {changed++}
+ sb.testField = 'newValue'
+ assert changed == 1
+
+ sb.anotherTestField = 'Changed'
+ """)
+ }
+ }
+
+ void testClassMarkers() {
+ for (int i = 0; i < 31; i++) {
+ boolean bindField = i & 1
+ boolean bindClass = i & 2
+ boolean vetoField = i & 4
+ boolean vetoClass = i & 8
+ boolean staticField = i & 16
+ int vetoCount = vetoClass?(staticField?4:5):(vetoField?2:0);
+ int bindCount = bindClass?(staticField?4:5):(bindField?2:0);
+
+ String script = """
+ import groovy.beans.Bindable
+ import groovy.beans.Vetoable
+
+ ${vetoClass?'@Vetoable ':''}${bindClass?'@Bindable ':''}class ClassMarkerBean$i {
+ String neither
+
+ ${vetoField?'@Vetoable ':''}String veto
+
+ ${bindField?'@Bindable ':''}String bind
+
+ ${vetoField?'@Vetoable ':''}${bindField?'@Bindable ':''}String both
+
+ ${staticField?'static ':''}String staticField
+ }
+
+ cb = new ClassMarkerBean$i(neither:'a', veto:'b', bind:'c', both:'d', staticField:'e')
+ vetoCount = 0
+ bindCount = 0
+ ${bindClass|bindField?'cb.propertyChange = { bindCount++ }':''}
+ ${vetoClass|vetoField?'cb.vetoableChange = { vetoCount++ }':''}
+ cb.neither = 'f'
+ cb.bind = 'g'
+ cb.veto = 'h'
+ cb.both = 'i'
+ cb.staticField = 'j'
+ assert vetoCount == $vetoCount
+ assert bindCount == $bindCount
+ """
+ try {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate(script);
+ } catch (Throwable t) {
+ System.out.println("Failed Script: $script")
+ throw t
+ }
+ }
+ }
+
+ void testGetVetoableChangeListeners() {
+ assertScript """
+ import groovy.beans.Vetoable
+ import java.beans.VetoableChangeListener
+ import java.beans.PropertyChangeEvent
+
+ class VetoableTestBean14 {
+ @Vetoable String foo
+ @Vetoable String bar
+ }
+
+ class FooVetoListener implements VetoableChangeListener {
+ void vetoableChange( PropertyChangeEvent e ) { }
+ }
+
+ sb = new VetoableTestBean14()
+ assert !sb.vetoableChangeListeners
+ listener = new FooVetoListener()
+ sb.addVetoableChangeListener("foo",listener)
+ assert !sb.getVetoableChangeListeners("bar")
+ assert sb.getVetoableChangeListeners("foo") == [listener]
+ assert sb.vetoableChangeListeners.size() == 1
+ """
+ }
+
+ void testPropertyChangeMethodWithCompileStatic() {
+ assertScript """
+ import groovy.beans.Vetoable
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class MyBean {
+ @Vetoable String test = "a test"
+ }
+ assert new MyBean()
+ """
+ }
}
\ No newline at end of file
diff --git a/src/test/groovy/bugs/AsBoolBug.groovy b/src/test/groovy/bugs/AsBoolBug.groovy
index d8f3f7e..bfc6b29 100644
--- a/src/test/groovy/bugs/AsBoolBug.groovy
+++ b/src/test/groovy/bugs/AsBoolBug.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* Test to fix the Jira issues GROOVY-810 and GROOVY-811.
* Test of "string as Boolean" against the issue GROOVY-812.
- *
- * @author Pilho Kim
*/
public class AsBoolBug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/AttributeSetExpressionBug.groovy b/src/test/groovy/bugs/AttributeSetExpressionBug.groovy
index cf22bc0..40fdded 100644
--- a/src/test/groovy/bugs/AttributeSetExpressionBug.groovy
+++ b/src/test/groovy/bugs/AttributeSetExpressionBug.groovy
@@ -16,10 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-/**
- * @author Pilho Kim
- */
-
package groovy.bugs
class AttributeSetExpressionBug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/BadLineNumberOnExceptionBugTest.groovy b/src/test/groovy/bugs/BadLineNumberOnExceptionBugTest.groovy
index 7b82945..4be9613 100644
--- a/src/test/groovy/bugs/BadLineNumberOnExceptionBugTest.groovy
+++ b/src/test/groovy/bugs/BadLineNumberOnExceptionBugTest.groovy
@@ -24,8 +24,6 @@ package groovy.bugs
* This test covers: <ul>
* <li><a href="https://issues.apache.org/jira/browse/GROOVY-3067">GROOVY-3067</a></li>
* <li><a href="https://issues.apache.org/jira/browse/GROOVY-2983">GROOVY-2983</a></li>
- *
- * @author Guillaume Laforge
*/
class BadLineNumberOnExceptionBugTest extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/BadScriptNameBug.groovy b/src/test/groovy/bugs/BadScriptNameBug.groovy
index be6074d..45f071f 100644
--- a/src/test/groovy/bugs/BadScriptNameBug.groovy
+++ b/src/test/groovy/bugs/BadScriptNameBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Sergey Udovenko
- */
class BadScriptNameBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/ClosureParameterPassingBug.groovy b/src/test/groovy/bugs/ClosureParameterPassingBug.groovy
index e9cae2a..e6e6761 100644
--- a/src/test/groovy/bugs/ClosureParameterPassingBug.groovy
+++ b/src/test/groovy/bugs/ClosureParameterPassingBug.groovy
@@ -20,9 +20,6 @@ package groovy.bugs
import org.codehaus.groovy.classgen.TestSupport
-/**
- * @author John Wilson
- */
class ClosureParameterPassingBug extends TestSupport {
void testBugInMethod() {
diff --git a/src/test/groovy/bugs/ConstructorBug.groovy b/src/test/groovy/bugs/ConstructorBug.groovy
index 0c58a2e..19cf5e7 100644
--- a/src/test/groovy/bugs/ConstructorBug.groovy
+++ b/src/test/groovy/bugs/ConstructorBug.groovy
@@ -20,9 +20,6 @@ package groovy.bugs
import org.codehaus.groovy.runtime.InvokerHelper
-/**
- * @author Jason Thomas
- */
class ConstructorBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/DoubleSizeParametersBug.groovy b/src/test/groovy/bugs/DoubleSizeParametersBug.groovy
index 1b45c91..e4617b4 100644
--- a/src/test/groovy/bugs/DoubleSizeParametersBug.groovy
+++ b/src/test/groovy/bugs/DoubleSizeParametersBug.groovy
@@ -18,21 +18,16 @@
*/
package groovy.bugs
-/**
- * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
- */
class DoubleSizeParametersBug extends TestSupport {
void testBug() {
- assertScript( """
-def foo(double x, y) {
- println "x: "+x
- println "y: "+y
-}
+ assertScript """
+ def foo(double x, y) {
+ println "x: "+x
+ println "y: "+y
+ }
-foo(10.0d, 0)
-""" );
+ foo(10.0d, 0)
+ """
}
}
-
-
diff --git a/src/test/groovy/bugs/ForLoopBug.groovy b/src/test/groovy/bugs/ForLoopBug.groovy
index 00887a9..a965558 100644
--- a/src/test/groovy/bugs/ForLoopBug.groovy
+++ b/src/test/groovy/bugs/ForLoopBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author John Wilson
- */
class ForLoopBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/Groovy1018_Bug.groovy b/src/test/groovy/bugs/Groovy1018_Bug.groovy
index 5e766d1..54cfa2a 100644
--- a/src/test/groovy/bugs/Groovy1018_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy1018_Bug.groovy
@@ -22,8 +22,6 @@ package groovy.bugs
* Test to fix the Jira issues GROOVY-1018 and GROOVY-732.
* Access to a static field member by a class name:
* ClassName.fieldName or ClassName.@fieldName.
- *
- * @author Pilho Kim
*/
class Groovy1018_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy1059_Bug.groovy b/src/test/groovy/bugs/Groovy1059_Bug.groovy
index 5385690..5d77d2d 100644
--- a/src/test/groovy/bugs/Groovy1059_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy1059_Bug.groovy
@@ -30,9 +30,6 @@ package groovy.bugs
* (object.@closure)()
*
* have the same meaning.
- *
- * @author John Wilson
- * @author Pilho Kim
*/
class Groovy1059_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy239_Bug.groovy b/src/test/groovy/bugs/Groovy239_Bug.groovy
index 09c5479..38fa6ae 100644
--- a/src/test/groovy/bugs/Groovy239_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy239_Bug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author John Wilson
- */
class Groovy239_Bug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/Groovy278_Bug.groovy b/src/test/groovy/bugs/Groovy278_Bug.groovy
index 0dbc0a5..458bb6b 100644
--- a/src/test/groovy/bugs/Groovy278_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy278_Bug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author John Wilson
- */
class Groovy278_Bug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/Groovy3464Bug.groovy b/src/test/groovy/bugs/Groovy3464Bug.groovy
index 7708c9c..1171285 100644
--- a/src/test/groovy/bugs/Groovy3464Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3464Bug.groovy
@@ -24,8 +24,6 @@ import org.codehaus.groovy.control.CompilerConfiguration
/**
* GROOVY-3463:
* Spring/CGLIB proxies throw exception "object is not an instance of declaring class"
- *
- * @author Guillaume Laforge
*/
class Groovy3464Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy3871Bug.groovy b/src/test/groovy/bugs/Groovy3871Bug.groovy
index 692b282..bdb2a78 100644
--- a/src/test/groovy/bugs/Groovy3871Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3871Bug.groovy
@@ -20,7 +20,6 @@ package groovy.bugs
/**
* Fix for https://issues.apache.org/jira/browse/GROOVY-3871
- * @author Guillaume Laforge
*/
class Groovy3871Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy4457GenericTypeDeclarationLeakTest.groovy b/src/test/groovy/bugs/Groovy4457GenericTypeDeclarationLeakTest.groovy
index 7e6d1ab..d684408 100644
--- a/src/test/groovy/bugs/Groovy4457GenericTypeDeclarationLeakTest.groovy
+++ b/src/test/groovy/bugs/Groovy4457GenericTypeDeclarationLeakTest.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Guillaume Laforge
- */
class Groovy4457GenericTypeDeclarationLeakTest extends GroovyTestCase {
void testLeak() {
diff --git a/src/test/groovy/bugs/Groovy4480Bug.groovy b/src/test/groovy/bugs/Groovy4480Bug.groovy
index a817098..1461f75 100644
--- a/src/test/groovy/bugs/Groovy4480Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4480Bug.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* Checks that if else can be used on a single line.
* A regression got introduced wiht extended command expression that dissallowed if else on the same line
- *
- * @author Guillaume Laforge
*/
class Groovy4480Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy4614Bug.groovy b/src/test/groovy/bugs/Groovy4614Bug.groovy
index 4e73f9e..08e4472 100644
--- a/src/test/groovy/bugs/Groovy4614Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4614Bug.groovy
@@ -20,9 +20,6 @@ package groovy.bugs
import gls.CompilableTestSupport
-/**
- * @author Guillaume Laforge
- */
class Groovy4614Bug extends CompilableTestSupport {
void testStaticOnOuterClassForbidden() {
diff --git a/src/test/groovy/bugs/Groovy4720Bug.groovy b/src/test/groovy/bugs/Groovy4720Bug.groovy
index 89214a2..cb89523 100644
--- a/src/test/groovy/bugs/Groovy4720Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4720Bug.groovy
@@ -20,9 +20,6 @@ package groovy.bugs
/**
* Groovy-4720: Method overriding with ExpandoMetaClass is partially broken
- *
- * @author Graeme Rocher
- * @author Guillaume Laforge
*/
class Groovy4720Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy4857Bug.groovy b/src/test/groovy/bugs/Groovy4857Bug.groovy
index 6077860..090cdcb 100644
--- a/src/test/groovy/bugs/Groovy4857Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4857Bug.groovy
@@ -18,10 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Tim Yates
- * @author Trygve Amundsens
- */
class Groovy4857Bug extends GroovyTestCase {
void testMissingMethodNotUnsupportedOperation() {
try {
diff --git a/src/test/groovy/bugs/Groovy5425_Bug.groovy b/src/test/groovy/bugs/Groovy5425_Bug.groovy
index 3cf7307..1b7d500 100644
--- a/src/test/groovy/bugs/Groovy5425_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy5425_Bug.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* Check Range.size finishes in a timely fashion. If we get a regression on this bug,
* the build will take 10 - 20 minutes longer than normal
- *
- * @author Tim Yates
*/
class Groovy5425_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy558_616_Bug.groovy b/src/test/groovy/bugs/Groovy558_616_Bug.groovy
index 340c681..7b3ac27 100644
--- a/src/test/groovy/bugs/Groovy558_616_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy558_616_Bug.groovy
@@ -21,9 +21,6 @@ package groovy.bugs
/**
* Fixes GROOVY-558 and GROOVY-616.
* A fully qualified class name ending with .class or not were not recognized properly.
- *
- * @author Jochen Theodorou
- * @author Guillaume Laforge
*/
class Groovy558_616_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy662Bug.groovy b/src/test/groovy/bugs/Groovy662Bug.groovy
index c4e2af8..99b871a 100644
--- a/src/test/groovy/bugs/Groovy662Bug.groovy
+++ b/src/test/groovy/bugs/Groovy662Bug.groovy
@@ -25,8 +25,6 @@ package groovy.bugs
* Test class and support to realize the GROOVY-662 test. There is a difference between
* improper uses of properties between Groovy defined classes and Java defined classes. There
* is no difference between correct uses so this is not a problem just an anti-regression test.
- *
- * @author Russel Winder
*/
class Groovy662 extends GroovyTestCase {
private String expected = "Hello"
diff --git a/src/test/groovy/bugs/Groovy666_Bug.groovy b/src/test/groovy/bugs/Groovy666_Bug.groovy
index 77e6beb..6c4c5c6 100644
--- a/src/test/groovy/bugs/Groovy666_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy666_Bug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Russel Winder
- */
class Groovy666_Bug extends GroovyShellTestCase {
void testRunScript() {
evaluate("x = 1")
diff --git a/src/test/groovy/bugs/Groovy674_Bug.groovy b/src/test/groovy/bugs/Groovy674_Bug.groovy
index 50b6883..bd3a043 100644
--- a/src/test/groovy/bugs/Groovy674_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy674_Bug.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* Test to ensure all the right exceptions are thrown for all the right/wrong combinations of
* parentheses and no parameters for print and println.
- *
- * @author Russel Winder
*/
class Groovy674_Bug extends GroovyTestCase {
void testTopLevelPrintParenthesesNoParameter ( ) {
diff --git a/src/test/groovy/bugs/Groovy675_Bug.groovy b/src/test/groovy/bugs/Groovy675_Bug.groovy
index 3701887..9f72f85 100644
--- a/src/test/groovy/bugs/Groovy675_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy675_Bug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Pilho Kim
- */
class Groovy675_Bug extends GroovyTestCase {
void testStringAndGString() {
assert "\\"!="\\\\"
diff --git a/src/test/groovy/bugs/Groovy831_Bug.groovy b/src/test/groovy/bugs/Groovy831_Bug.groovy
index 8f550cc..f79b646 100644
--- a/src/test/groovy/bugs/Groovy831_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy831_Bug.groovy
@@ -20,8 +20,6 @@ package groovy.bugs
/**
* Test for fixing the Jira issue GROOVY-831
- *
- * @author Pilho Kim
*/
class Groovy831_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/Groovy965_Bug.groovy b/src/test/groovy/bugs/Groovy965_Bug.groovy
index e1cbb2b..1a9a4ae 100644
--- a/src/test/groovy/bugs/Groovy965_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy965_Bug.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* A test case to ensure that Groovy can compile class names and variable names with non-ASCII
* characters and that non-ASCII characters in Strings do the right thing.
- *
- * @author Russel Winder
*/
class Groovy965_Bug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/GuillaumesBug.groovy b/src/test/groovy/bugs/GuillaumesBug.groovy
index 6786021..168ad8d 100644
--- a/src/test/groovy/bugs/GuillaumesBug.groovy
+++ b/src/test/groovy/bugs/GuillaumesBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Guillaume Laforge
- */
class GuillaumesBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/GuillaumesMapBug.groovy b/src/test/groovy/bugs/GuillaumesMapBug.groovy
index 8b9999f..c3aa1b0 100644
--- a/src/test/groovy/bugs/GuillaumesMapBug.groovy
+++ b/src/test/groovy/bugs/GuillaumesMapBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Guillaume Laforge
- */
class GuillaumesMapBug extends GroovyTestCase {
void testBug2() {
diff --git a/src/test/groovy/bugs/InterfaceImplBug.groovy b/src/test/groovy/bugs/InterfaceImplBug.groovy
index 217ff3b..d1cbe99 100644
--- a/src/test/groovy/bugs/InterfaceImplBug.groovy
+++ b/src/test/groovy/bugs/InterfaceImplBug.groovy
@@ -18,19 +18,15 @@
*/
package groovy.bugs
-import java.io.Reader
import org.codehaus.groovy.dummy.FooHandler
-/**
- * @author Robert Fuller
- */
class InterfaceImplBug extends GroovyTestCase implements FooHandler {
void testMethodCall() {
handle(null)
}
-
- void handle(Reader reader){
+
+ void handle(Reader reader) {
def called = true
}
}
\ No newline at end of file
diff --git a/src/test/groovy/bugs/InvokeNormalMethodFromBuilder_Groovy657Bug.groovy b/src/test/groovy/bugs/InvokeNormalMethodFromBuilder_Groovy657Bug.groovy
index 3913148..609cabb 100644
--- a/src/test/groovy/bugs/InvokeNormalMethodFromBuilder_Groovy657Bug.groovy
+++ b/src/test/groovy/bugs/InvokeNormalMethodFromBuilder_Groovy657Bug.groovy
@@ -25,8 +25,6 @@ package groovy.bugs
* <li>it is possible to call normal methods from the builder,
* without the methods being trapped endlessly by createNode()</li>
* </ul>
- *
- * @author Guillaume Laforge
*/
class InvokeNormalMethodFromBuilder_Bug657 extends GroovyTestCase {
void testInvokeNormalMethod() {
diff --git a/src/test/groovy/bugs/MethodPointerBug.groovy b/src/test/groovy/bugs/MethodPointerBug.groovy
index d3fe120..0fc7d26 100644
--- a/src/test/groovy/bugs/MethodPointerBug.groovy
+++ b/src/test/groovy/bugs/MethodPointerBug.groovy
@@ -18,16 +18,13 @@
*/
package groovy.bugs
-/**
- * @author Pilho Kim
- */
class MethodPointerBug extends GroovyTestCase {
- def void sayHello() {
+ void sayHello() {
println "hello"
}
- def MethodPointerBug getThisObject() {
+ MethodPointerBug getThisObject() {
return this
}
@@ -44,7 +41,6 @@ class MethodPointerBug extends GroovyTestCase {
y()
}
- ///////////////////////////////////////////////////////////////////////////////////////////
// Test a default method pointer operator "&" with this object. For example, &bar.
// This shows that the issue GROOVY-826 has been fixed in groovy-1.0-jar-02.
/*
@@ -54,6 +50,7 @@ class MethodPointerBug extends GroovyTestCase {
z()
}
*/
+
// Test a default method pointer operator ".&" with returned object. For example, someMethod().&bar.
void testMethodPointerWithReturn() {
def u = getThisObject().&sayHello
diff --git a/src/test/groovy/bugs/MorgansBug.groovy b/src/test/groovy/bugs/MorgansBug.groovy
index c357325..51e3f61 100644
--- a/src/test/groovy/bugs/MorgansBug.groovy
+++ b/src/test/groovy/bugs/MorgansBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Morgan Hankins
- */
class MorgansBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/NullAsBooleanCoercionTest.groovy b/src/test/groovy/bugs/NullAsBooleanCoercionTest.groovy
index 9883495..2394fd7 100644
--- a/src/test/groovy/bugs/NullAsBooleanCoercionTest.groovy
+++ b/src/test/groovy/bugs/NullAsBooleanCoercionTest.groovy
@@ -21,8 +21,6 @@ package groovy.bugs
/**
* NullObject has no asBoolean() method,
* making null.asBoolean() return true instead of false.
- *
- * @author Guillaume Laforge
*/
class NullAsBooleanCoercionTest extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/PrimitivePropertyBug.groovy b/src/test/groovy/bugs/PrimitivePropertyBug.groovy
index 6d9bd1e..187f904 100644
--- a/src/test/groovy/bugs/PrimitivePropertyBug.groovy
+++ b/src/test/groovy/bugs/PrimitivePropertyBug.groovy
@@ -19,9 +19,7 @@
package groovy.bugs
/**
- *
* Fix Bug GROOVY-683
- * @author Pilho Kim
*/
class PrimitivePropertyBug extends GroovyTestCase {
diff --git a/src/test/groovy/bugs/PrintlnWithNewBug.groovy b/src/test/groovy/bugs/PrintlnWithNewBug.groovy
index 21500d7..1c59bfb 100644
--- a/src/test/groovy/bugs/PrintlnWithNewBug.groovy
+++ b/src/test/groovy/bugs/PrintlnWithNewBug.groovy
@@ -20,9 +20,6 @@ package groovy.bugs
import groovy.Foo
-/**
- * @author Mark Volkmann
- */
class PrintlnWithNewBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/PropertyNameBug.groovy b/src/test/groovy/bugs/PropertyNameBug.groovy
index 339b97e..a54fb0f 100644
--- a/src/test/groovy/bugs/PropertyNameBug.groovy
+++ b/src/test/groovy/bugs/PropertyNameBug.groovy
@@ -20,11 +20,8 @@ package groovy.bugs
/**
* Test to fix the issue GROOVY-843.
- *
- * @author Pilho Kim
*/
-
-public class PropertyNameBug extends GroovyTestCase {
+class PropertyNameBug extends GroovyTestCase {
void testNonJavaIdentifierChacactersWithJavaSyntax() {
Map map = new HashMap()
map.put("foo.bar", "FooBar")
@@ -39,5 +36,3 @@ public class PropertyNameBug extends GroovyTestCase {
map."foo.=;&|^*-+-/\\'?.*:arbitrary()[]{}%#@!" = "Any character"
}
}
-
-
diff --git a/src/test/groovy/bugs/RodsBug.groovy b/src/test/groovy/bugs/RodsBug.groovy
index 94a251e..b9ee14a 100644
--- a/src/test/groovy/bugs/RodsBug.groovy
+++ b/src/test/groovy/bugs/RodsBug.groovy
@@ -18,11 +18,8 @@
*/
package groovy.bugs
-/**
- * @author Rod Cope
- */
class RodsBug extends GroovyTestCase {
-
+
void testBug() {
doTest(true)
/*
@@ -33,7 +30,7 @@ class RodsBug extends GroovyTestCase {
}
*/
}
-
+
void testBug2() {
def x = 1
if (x > 0) {
@@ -41,7 +38,7 @@ class RodsBug extends GroovyTestCase {
def name = "Rod"
}
}
-
+
void doTest(flag) {
if (flag) {
String name = "Rod"
@@ -49,12 +46,12 @@ class RodsBug extends GroovyTestCase {
doAssert(name)
}
}
-
+
void doTest() {
String name = "Rod"
doAssert(name)
}
-
+
void doAssert(text) {
assert text != null
}
diff --git a/src/test/groovy/bugs/StaticClosurePropertyBug.groovy b/src/test/groovy/bugs/StaticClosurePropertyBug.groovy
index 27c1330..f08e00f 100644
--- a/src/test/groovy/bugs/StaticClosurePropertyBug.groovy
+++ b/src/test/groovy/bugs/StaticClosurePropertyBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Robert Kuzelj
- */
class StaticClosurePropertyBug extends GroovyTestCase {
static def out = {System.out.println(it)}
diff --git a/src/test/groovy/bugs/SynchronizedBytecodeBug.groovy b/src/test/groovy/bugs/SynchronizedBytecodeBug.groovy
index aef4531..e20e065 100644
--- a/src/test/groovy/bugs/SynchronizedBytecodeBug.groovy
+++ b/src/test/groovy/bugs/SynchronizedBytecodeBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Guillaume Laforge
- */
class SynchronizedBytecodeBug extends GroovyTestCase {
/**
diff --git a/src/test/groovy/bugs/TryCatch2Bug.groovy b/src/test/groovy/bugs/TryCatch2Bug.groovy
index ea6e911..36b30a6 100644
--- a/src/test/groovy/bugs/TryCatch2Bug.groovy
+++ b/src/test/groovy/bugs/TryCatch2Bug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Morgan Hankins
- */
class TryCatch2Bug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/TryCatchBug.groovy b/src/test/groovy/bugs/TryCatchBug.groovy
index 22c7de8..f874562 100644
--- a/src/test/groovy/bugs/TryCatchBug.groovy
+++ b/src/test/groovy/bugs/TryCatchBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author John Wilson
- */
class TryCatchBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/bugs/VariablePrecedence.groovy b/src/test/groovy/bugs/VariablePrecedence.groovy
index f1faf35..90f38c5 100644
--- a/src/test/groovy/bugs/VariablePrecedence.groovy
+++ b/src/test/groovy/bugs/VariablePrecedence.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author John Wilson
- */
class VariblePrecedence extends GroovyTestCase {
void testVariablePrecedence() {
diff --git a/src/test/groovy/bugs/ZoharsBug.groovy b/src/test/groovy/bugs/ZoharsBug.groovy
index db5a516..5396a68 100644
--- a/src/test/groovy/bugs/ZoharsBug.groovy
+++ b/src/test/groovy/bugs/ZoharsBug.groovy
@@ -18,9 +18,6 @@
*/
package groovy.bugs
-/**
- * @author Zohar Melamed
- */
class ZoharsBug extends GroovyTestCase {
void testBug() {
diff --git a/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy b/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
index 9c8307f..338bd8b 100644
--- a/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
+++ b/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
@@ -34,8 +34,6 @@ import static org.junit.Assume.assumeTrue
* path is partway reasonable so we can access sh and echo.
* <p>
* These test are a bit trivial but at least they are here :-)
- *
- * @author Russel Winder
*/
@RunWith(JUnit4)
class ExecuteTest_LinuxSolaris extends GroovyTestCase {
diff --git a/src/test/groovy/execute/ExecuteTest_Windows.groovy b/src/test/groovy/execute/ExecuteTest_Windows.groovy
index 41a97ce..49d994f 100644
--- a/src/test/groovy/execute/ExecuteTest_Windows.groovy
+++ b/src/test/groovy/execute/ExecuteTest_Windows.groovy
@@ -29,8 +29,6 @@ import static org.junit.Assume.assumeTrue
* Test to ensure that the execute mechanism works fine on Windows systems.
* <p>
* These test are a bit trivial but at least they are here :-)
- *
- * @author Paul King
*/
@RunWith(JUnit4)
class ExecuteTest_Windows extends GroovyTestCase {
diff --git a/src/test/groovy/grape/GrabResolverTest.groovy b/src/test/groovy/grape/GrabResolverTest.groovy
index be7e0eb..da4f09a 100644
--- a/src/test/groovy/grape/GrabResolverTest.groovy
+++ b/src/test/groovy/grape/GrabResolverTest.groovy
@@ -1,101 +1,98 @@
-/*
- * 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.grape
-
-import org.codehaus.groovy.control.CompilationFailedException
-
-/**
- * @author Merlyn Albery-Speyer
- */
-class GrabResolverTest extends GroovyTestCase {
- def originalGrapeRoot
- def grapeRoot
-
- public void setUp() {
- Grape.@instance = null // isolate our test from other tests
-
- // create a new grape root directory so as to insure a clean slate for this test
- originalGrapeRoot = System.getProperty("grape.root")
- grapeRoot = new File(System.getProperty("java.io.tmpdir"), "GrabResolverTest${System.currentTimeMillis()}")
- assert grapeRoot.mkdir()
- grapeRoot.deleteOnExit()
- System.setProperty("grape.root", grapeRoot.path)
- }
-
- public void tearDown() {
- if (originalGrapeRoot == null) {
- // SDN bug: 4463345
- System.getProperties().remove("grape.root")
- } else {
- System.setProperty("grape.root", originalGrapeRoot)
- }
-
- Grape.@instance = null // isolate our test from other tests
- }
-
- public void manualTestChecksumsCanBeDisabled() {
- // TODO someone has cleaned up the checksum info in the public repos that this test
- // was relying on and so this test no longer fails unless you have the corrupt SHA1
- // value cached in your local grapes repo, change test to not rely on that fact and
- // then reinstate (use a local file repo?)
- GroovyShell shell = new GroovyShell(new GroovyClassLoader())
- shouldFail(RuntimeException) {
- shell.evaluate """
- @Grab('org.mvel:mvel2:2.1.3.Final')
- import org.mvel2.MVEL
- assert MVEL.name == 'org.mvel2.MVEL'
- """
- }
- shell.evaluate """
- @Grab('org.mvel:mvel2:2.1.3.Final')
- @GrabConfig(disableChecksums=true)
- import org.mvel2.MVEL
- assert MVEL.name == 'org.mvel2.MVEL'
- """
- }
-
- public void testResolverDefinitionIsRequired() {
- GroovyShell shell = new GroovyShell(new GroovyClassLoader())
- shouldFail(CompilationFailedException) {
- shell.evaluate("""
- @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
- class AnnotationHost {}
- import org.restlet.Application
- """)
- }
- }
-
- public void testResolverDefinitionResolvesDependency() {
- GroovyShell shell = new GroovyShell(new GroovyClassLoader())
- shell.evaluate("""
- @GrabResolver(name='restlet.org', root='http://maven.restlet.org')
- @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
- class AnnotationHost {}
- assert org.restlet.Application.class.simpleName == 'Application'""")
- }
-
- public void testResolverDefinitionResolvesDependencyWithShorthand() {
- GroovyShell shell = new GroovyShell(new GroovyClassLoader())
- shell.evaluate("""
- @GrabResolver('http://maven.restlet.org')
- @Grab('org.restlet:org.restlet:1.1.6')
- class AnnotationHost {}
- assert org.restlet.Application.class.simpleName == 'Application'""")
- }
-}
+/*
+ * 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.grape
+
+import org.codehaus.groovy.control.CompilationFailedException
+
+class GrabResolverTest extends GroovyTestCase {
+ def originalGrapeRoot
+ def grapeRoot
+
+ void setUp() {
+ Grape.@instance = null // isolate our test from other tests
+
+ // create a new grape root directory so as to insure a clean slate for this test
+ originalGrapeRoot = System.getProperty("grape.root")
+ grapeRoot = new File(System.getProperty("java.io.tmpdir"), "GrabResolverTest${System.currentTimeMillis()}")
+ assert grapeRoot.mkdir()
+ grapeRoot.deleteOnExit()
+ System.setProperty("grape.root", grapeRoot.path)
+ }
+
+ void tearDown() {
+ if (originalGrapeRoot == null) {
+ // SDN bug: 4463345
+ System.getProperties().remove("grape.root")
+ } else {
+ System.setProperty("grape.root", originalGrapeRoot)
+ }
+
+ Grape.@instance = null // isolate our test from other tests
+ }
+
+ void manualTestChecksumsCanBeDisabled() {
+ // TODO someone has cleaned up the checksum info in the public repos that this test
+ // was relying on and so this test no longer fails unless you have the corrupt SHA1
+ // value cached in your local grapes repo, change test to not rely on that fact and
+ // then reinstate (use a local file repo?)
+ GroovyShell shell = new GroovyShell(new GroovyClassLoader())
+ shouldFail(RuntimeException) {
+ shell.evaluate """
+ @Grab('org.mvel:mvel2:2.1.3.Final')
+ import org.mvel2.MVEL
+ assert MVEL.name == 'org.mvel2.MVEL'
+ """
+ }
+ shell.evaluate """
+ @Grab('org.mvel:mvel2:2.1.3.Final')
+ @GrabConfig(disableChecksums=true)
+ import org.mvel2.MVEL
+ assert MVEL.name == 'org.mvel2.MVEL'
+ """
+ }
+
+ void testResolverDefinitionIsRequired() {
+ GroovyShell shell = new GroovyShell(new GroovyClassLoader())
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("""
+ @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
+ class AnnotationHost {}
+ import org.restlet.Application
+ """)
+ }
+ }
+
+ void testResolverDefinitionResolvesDependency() {
+ GroovyShell shell = new GroovyShell(new GroovyClassLoader())
+ shell.evaluate("""
+ @GrabResolver(name='restlet.org', root='http://maven.restlet.org')
+ @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
+ class AnnotationHost {}
+ assert org.restlet.Application.class.simpleName == 'Application'""")
+ }
+
+ void testResolverDefinitionResolvesDependencyWithShorthand() {
+ GroovyShell shell = new GroovyShell(new GroovyClassLoader())
+ shell.evaluate("""
+ @GrabResolver('http://maven.restlet.org')
+ @Grab('org.restlet:org.restlet:1.1.6')
+ class AnnotationHost {}
+ assert org.restlet.Application.class.simpleName == 'Application'""")
+ }
+}
diff --git a/src/test/groovy/grape/GrapeIvyTest.groovy b/src/test/groovy/grape/GrapeIvyTest.groovy
index 1bc845f..0fb05b5 100644
--- a/src/test/groovy/grape/GrapeIvyTest.groovy
+++ b/src/test/groovy/grape/GrapeIvyTest.groovy
@@ -1,401 +1,397 @@
-/*
- * 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.grape
-
-import org.codehaus.groovy.control.CompilationFailedException
-import gls.CompilableTestSupport
-
-/**
- * @author Danno Ferrin
- * @author Paul King
- */
-class GrapeIvyTest extends CompilableTestSupport {
-
- GrapeIvyTest() {
- // make sure files are installed locally
- [[groupId:'log4j', artifactId:'log4j', version:'1.1.3'],
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'2.2.12'],
- [groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:['default', 'optional']],
- [groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15']
- ].each {
- Grape.resolve([autoDownload:true, classLoader:new GroovyClassLoader()], it)
- }
- }
-
- void testSingleArtifact() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- Grape.grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', classLoader:loader)
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- }
-
- void testModuleWithDependencies() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
- Grape.grab(groupId:'org.apache.poi', artifactId:'poi', version:'3.7', classLoader:loader)
- assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
- }
-
- void testMultipleDependencies() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
-
- Grape.grab(classLoader:loader,
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])
-
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
- }
-
- void testListDependencies() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
-
- Grape.grab(classLoader:loader,
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])
-
- def loadedDependencies = Grape.listDependencies(loader)
- assert loadedDependencies == [
- [group:'org.apache.poi', module:'poi', version:'3.7'],
- [group:'com.jidesoft', module:'jide-oss', version:'[2.2.1,2.3)']
- ]
- }
-
- void testGrabRefless() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)')")
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- }
-
- void testGrabScriptClass() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', refObject:this)")
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- }
-
- void testGrabScriptLoader() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shell.setVariable("loader", loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', classLoader:loader)")
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- }
-
- void testGrabReflessMultiple() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("""new groovy.grape.Grape().grab([:],
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
-
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
- }
-
- void testGrabScriptClassMultiple() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("""new groovy.grape.Grape().grab(refObject: this,
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
-
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
- }
-
- void testGrabScriptLoaderMultiple() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shell.setVariable("loader", loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
- }
- shouldFail(CompilationFailedException) {
- shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
- }
- shell.evaluate("""new groovy.grape.Grape().grab(classLoader:loader,
- [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
- [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
-
- assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
- assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
- }
-
- void testSerialGrabs() {
- GroovyClassLoader loader = new GroovyClassLoader()
- Grape.grab(groupId:'log4j', artifactId:'log4j', version:'1.1.3', classLoader:loader)
- Grape.grab(groupId:'org.apache.poi', artifactId:'poi', version:'3.7', classLoader:loader)
- def jars = jarNames(loader)
- // because poi asks for log4j 1.2.13, but we already have 1.1.3 so it won't be loaded
- assert jars.contains ("log4j-1.1.3.jar")
- assert !jars.contains ("log4j-1.2.13.jar")
-
- Grape.grab(groupId:'log4j', artifactId:'log4j', version:'1.2.13', classLoader:loader)
- jars = jarNames(loader)
- // because log4j 1.1.3 was loaded first, 1.2.13 should not get loaded
- // even though it was explicitly asked for
- assert jars.contains ("log4j-1.1.3.jar")
- assert !jars.contains ("log4j-1.2.13.jar")
- }
-
- void testConf() {
- GroovyClassLoader loader = new GroovyClassLoader()
-
- def coreJars = ["ivy-2.0.0.jar"] as Set
- def optionalJars = [
- "ant-1.6.2.jar",
- "ant-trax-1.6.2.jar",
- "ant-nodeps-1.6.2.jar",
- "commons-httpclient-3.0.jar",
- "junit-3.8.1.jar",
- "commons-codec-1.2.jar",
- "oro-2.0.8.jar",
- "commons-vfs-1.0.jar",
- "commons-logging-1.0.4.jar",
- "jsch-0.1.31.jar",
- ] as Set
- def testJars = [
- "junit-3.8.2.jar",
- "commons-lang-2.3.jar",
- ] as Set
-
- Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', classLoader:loader, preserveFiles:true)
- def jars = jarNames(loader)
- assert coreJars - jars == Collections.EMPTY_SET, "assert that all core jars are present"
- assert testJars - jars == testJars, "assert that no test jars are present"
- assert optionalJars - jars == optionalJars, "assert that no optional jars are present"
- assert jars == coreJars, "assert that no extraneous jars are present"
-
- loader = new GroovyClassLoader()
- Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:'optional', classLoader:loader)
- jars = jarNames(loader)
- assert coreJars - jars == coreJars, "assert that no core jars are present"
- assert testJars - jars == testJars, "assert that no test jars are present"
- assert optionalJars - jars == Collections.EMPTY_SET, "assert that all optional jars are present"
- assert jars == optionalJars, "assert that no extraneous jars are present"
-
- loader = new GroovyClassLoader()
- Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:['default', 'optional'], classLoader:loader)
- jars = jarNames(loader)
- assert coreJars - jars == Collections.EMPTY_SET, "assert that all core jars are present"
- assert testJars - jars == testJars, "assert that no test jars are present"
- assert optionalJars - jars == Collections.EMPTY_SET, "assert that all optional jars are present"
- assert jars == coreJars + optionalJars, "assert that no extraneous jars are present"
- }
-
- private static Set<String> jarNames(GroovyClassLoader loader) {
- loader.getURLs().collect { URL it -> it.getPath().split('/')[-1] } as Set
- }
-
- void testClassifier() {
- GroovyClassLoader loader = new GroovyClassLoader()
- GroovyShell shell = new GroovyShell(loader)
- shouldFail(CompilationFailedException) {
- shell.evaluate("import net.sf.json.JSON; JSON")
- }
- Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', classLoader:loader)
- assert shell.evaluate("import net.sf.json.JSON; JSON").name == 'net.sf.json.JSON'
- }
-
- void testClassifierWithConf() {
- def coreJars = [
- "json-lib-2.2.3-jdk15.jar",
- "commons-lang-2.4.jar",
- "commons-collections-3.2.jar",
- "ezmorph-1.0.6.jar",
- "commons-logging-1.1.1.jar",
- "commons-beanutils-1.7.0.jar"
- ] as Set
- def optionalJars = [
- "xercesImpl-2.6.2.jar",
- "xmlParserAPIs-2.6.2.jar",
- "groovy-all-1.5.7.jar",
- "oro-2.0.8.jar",
- "jruby-1.1.jar",
- "junit-3.8.2.jar",
- "ant-launcher-1.7.0.jar",
- "xalan-2.7.0.jar",
- "json-lib-2.2.3-jdk15.jar",
- "ant-1.7.0.jar",
- "xom-1.1.jar",
- "jaxen-1.1-beta-8.jar",
- "jdom-1.0.jar",
- "jline-0.9.94.jar",
- "log4j-1.2.14.jar",
- "dom4j-1.6.1.jar"
- ] as Set
-
- GroovyClassLoader loader = new GroovyClassLoader()
- Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', classLoader:loader, preserveFiles:true)
- assert jarNames(loader) == coreJars
-
- loader = new GroovyClassLoader()
- Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', conf:'optional', classLoader:loader)
- assert jarNames(loader) == optionalJars
-
- loader = new GroovyClassLoader()
- Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', conf:['default', 'optional'], classLoader:loader)
- assert jarNames(loader) == coreJars + optionalJars
- }
-
- void testTransitiveShorthandControl() {
- // BeanUtils is a transitive dependency for Digester
- assertScript '''
- @Grab('commons-digester:commons-digester:2.1')
- import org.apache.commons.digester.Digester
-
- assert Digester.name.size() == 36
- assert org.apache.commons.beanutils.BeanUtils.name.size() == 38
- '''
- }
-
- void testTransitiveShorthandExpectFailure() {
- assertScript '''
- @Grab('commons-digester:commons-digester:2.1;transitive=false')
- import org.apache.commons.digester.Digester
-
- assert Digester.name.size() == 36
- try {
- assert org.apache.commons.beanutils.BeanUtils.name.size() == 38
- assert false
- } catch(MissingPropertyException mpe) { }
- '''
- }
-
- void testAutoDownloadGrapeConfig() {
-
- assertScript '''
- @Grab('commons-digester:commons-digester:2.1;transitive=false')
- import org.apache.commons.digester.Digester
-
- assert Digester.name.size() == 36
- '''
-
- assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'downloadGrapes'
-
- assertScript '''
- @Grab('commons-digester:commons-digester:2.1;transitive=false')
- @GrabConfig(autoDownload=false)
- import org.apache.commons.digester.Digester
-
- assert Digester.name.size() == 36
- '''
-
- assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'cachedGrapes'
-
- assertScript '''
- @Grab('commons-digester:commons-digester:2.1;transitive=false')
- @GrabConfig(autoDownload=true)
- import org.apache.commons.digester.Digester
-
- assert Digester.name.size() == 36
- '''
-
- assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'downloadGrapes'
- }
-
- /**
- * GROOVY-470: multiple jars should be loaded for an artifacts with and without a classifier
- */
- void testClassifierAndNonClassifierOnSameArtifact() {
- GroovyClassLoader loader = new GroovyClassLoader()
- Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classLoader:loader)
- Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classifier:'tests', classLoader:loader)
-
- def jars = jarNames(loader)
- assert jars.contains ("neo4j-kernel-2.0.0-RC1.jar")
- assert jars.contains ("neo4j-kernel-2.0.0-RC1-tests.jar")
-
- // also check reverse ordering of deps
- loader = new GroovyClassLoader()
- Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classifier:'tests', classLoader:loader)
- Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classLoader:loader)
-
- jars = jarNames(loader)
- assert jars.contains ("neo4j-kernel-2.0.0-RC1.jar")
- assert jars.contains ("neo4j-kernel-2.0.0-RC1-tests.jar")
- }
-
- void testSystemProperties_groovy7548() {
- System.setProperty('groovy7548prop', 'x')
- assert System.getProperty('groovy7548prop') == 'x'
- new GroovyShell().evaluate '''
- @GrabConfig(systemProperties='groovy7548prop=y')
- @Grab('commons-lang:commons-lang:2.6')
- import org.apache.commons.lang.StringUtils
- assert StringUtils.name == 'org.apache.commons.lang.StringUtils'
- '''
- assert System.getProperty('groovy7548prop') == 'y'
- }
-
- // GROOVY-7649
- void testResolveSucceedsAfterFailure() {
- GroovyClassLoader loader = new GroovyClassLoader()
-
- shouldFail{
- Grape.resolve([classLoader:loader], [], [groupId:'bogus', artifactId:'bogus', version:'0.1'])
- }
-
- Grape.resolve([classLoader:loader], [], [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'])
- }
-}
+/*
+ * 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.grape
+
+import org.codehaus.groovy.control.CompilationFailedException
+import gls.CompilableTestSupport
+
+class GrapeIvyTest extends CompilableTestSupport {
+
+ GrapeIvyTest() {
+ // make sure files are installed locally
+ [[groupId:'log4j', artifactId:'log4j', version:'1.1.3'],
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'2.2.12'],
+ [groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:['default', 'optional']],
+ [groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15']
+ ].each {
+ Grape.resolve([autoDownload:true, classLoader:new GroovyClassLoader()], it)
+ }
+ }
+
+ void testSingleArtifact() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ Grape.grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', classLoader:loader)
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ }
+
+ void testModuleWithDependencies() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+ Grape.grab(groupId:'org.apache.poi', artifactId:'poi', version:'3.7', classLoader:loader)
+ assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
+ }
+
+ void testMultipleDependencies() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+
+ Grape.grab(classLoader:loader,
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])
+
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
+ }
+
+ void testListDependencies() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+
+ Grape.grab(classLoader:loader,
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])
+
+ def loadedDependencies = Grape.listDependencies(loader)
+ assert loadedDependencies == [
+ [group:'org.apache.poi', module:'poi', version:'3.7'],
+ [group:'com.jidesoft', module:'jide-oss', version:'[2.2.1,2.3)']
+ ]
+ }
+
+ void testGrabRefless() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)')")
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ }
+
+ void testGrabScriptClass() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', refObject:this)")
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ }
+
+ void testGrabScriptLoader() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shell.setVariable("loader", loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("new groovy.grape.Grape().grab(groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)', classLoader:loader)")
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ }
+
+ void testGrabReflessMultiple() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("""new groovy.grape.Grape().grab([:],
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
+
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
+ }
+
+ void testGrabScriptClassMultiple() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("""new groovy.grape.Grape().grab(refObject: this,
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
+
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
+ }
+
+ void testGrabScriptLoaderMultiple() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shell.setVariable("loader", loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class")
+ }
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class")
+ }
+ shell.evaluate("""new groovy.grape.Grape().grab(classLoader:loader,
+ [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'],
+ [groupId:'com.jidesoft', artifactId:'jide-oss', version:'[2.2.1,2.3)'])""")
+
+ assert shell.evaluate("import com.jidesoft.swing.JideSplitButton; JideSplitButton.class").name == 'com.jidesoft.swing.JideSplitButton';
+ assert shell.evaluate("import org.apache.poi.POIDocument; POIDocument.class").name == 'org.apache.poi.POIDocument'
+ }
+
+ void testSerialGrabs() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ Grape.grab(groupId:'log4j', artifactId:'log4j', version:'1.1.3', classLoader:loader)
+ Grape.grab(groupId:'org.apache.poi', artifactId:'poi', version:'3.7', classLoader:loader)
+ def jars = jarNames(loader)
+ // because poi asks for log4j 1.2.13, but we already have 1.1.3 so it won't be loaded
+ assert jars.contains ("log4j-1.1.3.jar")
+ assert !jars.contains ("log4j-1.2.13.jar")
+
+ Grape.grab(groupId:'log4j', artifactId:'log4j', version:'1.2.13', classLoader:loader)
+ jars = jarNames(loader)
+ // because log4j 1.1.3 was loaded first, 1.2.13 should not get loaded
+ // even though it was explicitly asked for
+ assert jars.contains ("log4j-1.1.3.jar")
+ assert !jars.contains ("log4j-1.2.13.jar")
+ }
+
+ void testConf() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+
+ def coreJars = ["ivy-2.0.0.jar"] as Set
+ def optionalJars = [
+ "ant-1.6.2.jar",
+ "ant-trax-1.6.2.jar",
+ "ant-nodeps-1.6.2.jar",
+ "commons-httpclient-3.0.jar",
+ "junit-3.8.1.jar",
+ "commons-codec-1.2.jar",
+ "oro-2.0.8.jar",
+ "commons-vfs-1.0.jar",
+ "commons-logging-1.0.4.jar",
+ "jsch-0.1.31.jar",
+ ] as Set
+ def testJars = [
+ "junit-3.8.2.jar",
+ "commons-lang-2.3.jar",
+ ] as Set
+
+ Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', classLoader:loader, preserveFiles:true)
+ def jars = jarNames(loader)
+ assert coreJars - jars == Collections.EMPTY_SET, "assert that all core jars are present"
+ assert testJars - jars == testJars, "assert that no test jars are present"
+ assert optionalJars - jars == optionalJars, "assert that no optional jars are present"
+ assert jars == coreJars, "assert that no extraneous jars are present"
+
+ loader = new GroovyClassLoader()
+ Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:'optional', classLoader:loader)
+ jars = jarNames(loader)
+ assert coreJars - jars == coreJars, "assert that no core jars are present"
+ assert testJars - jars == testJars, "assert that no test jars are present"
+ assert optionalJars - jars == Collections.EMPTY_SET, "assert that all optional jars are present"
+ assert jars == optionalJars, "assert that no extraneous jars are present"
+
+ loader = new GroovyClassLoader()
+ Grape.grab(groupId:'org.apache.ivy', artifactId:'ivy', version:'2.0.0', conf:['default', 'optional'], classLoader:loader)
+ jars = jarNames(loader)
+ assert coreJars - jars == Collections.EMPTY_SET, "assert that all core jars are present"
+ assert testJars - jars == testJars, "assert that no test jars are present"
+ assert optionalJars - jars == Collections.EMPTY_SET, "assert that all optional jars are present"
+ assert jars == coreJars + optionalJars, "assert that no extraneous jars are present"
+ }
+
+ private static Set<String> jarNames(GroovyClassLoader loader) {
+ loader.getURLs().collect { URL it -> it.getPath().split('/')[-1] } as Set
+ }
+
+ void testClassifier() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ GroovyShell shell = new GroovyShell(loader)
+ shouldFail(CompilationFailedException) {
+ shell.evaluate("import net.sf.json.JSON; JSON")
+ }
+ Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', classLoader:loader)
+ assert shell.evaluate("import net.sf.json.JSON; JSON").name == 'net.sf.json.JSON'
+ }
+
+ void testClassifierWithConf() {
+ def coreJars = [
+ "json-lib-2.2.3-jdk15.jar",
+ "commons-lang-2.4.jar",
+ "commons-collections-3.2.jar",
+ "ezmorph-1.0.6.jar",
+ "commons-logging-1.1.1.jar",
+ "commons-beanutils-1.7.0.jar"
+ ] as Set
+ def optionalJars = [
+ "xercesImpl-2.6.2.jar",
+ "xmlParserAPIs-2.6.2.jar",
+ "groovy-all-1.5.7.jar",
+ "oro-2.0.8.jar",
+ "jruby-1.1.jar",
+ "junit-3.8.2.jar",
+ "ant-launcher-1.7.0.jar",
+ "xalan-2.7.0.jar",
+ "json-lib-2.2.3-jdk15.jar",
+ "ant-1.7.0.jar",
+ "xom-1.1.jar",
+ "jaxen-1.1-beta-8.jar",
+ "jdom-1.0.jar",
+ "jline-0.9.94.jar",
+ "log4j-1.2.14.jar",
+ "dom4j-1.6.1.jar"
+ ] as Set
+
+ GroovyClassLoader loader = new GroovyClassLoader()
+ Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', classLoader:loader, preserveFiles:true)
+ assert jarNames(loader) == coreJars
+
+ loader = new GroovyClassLoader()
+ Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', conf:'optional', classLoader:loader)
+ assert jarNames(loader) == optionalJars
+
+ loader = new GroovyClassLoader()
+ Grape.grab(groupId:'net.sf.json-lib', artifactId:'json-lib', version:'2.2.3', classifier:'jdk15', conf:['default', 'optional'], classLoader:loader)
+ assert jarNames(loader) == coreJars + optionalJars
+ }
+
+ void testTransitiveShorthandControl() {
+ // BeanUtils is a transitive dependency for Digester
+ assertScript '''
+ @Grab('commons-digester:commons-digester:2.1')
+ import org.apache.commons.digester.Digester
+
+ assert Digester.name.size() == 36
+ assert org.apache.commons.beanutils.BeanUtils.name.size() == 38
+ '''
+ }
+
+ void testTransitiveShorthandExpectFailure() {
+ assertScript '''
+ @Grab('commons-digester:commons-digester:2.1;transitive=false')
+ import org.apache.commons.digester.Digester
+
+ assert Digester.name.size() == 36
+ try {
+ assert org.apache.commons.beanutils.BeanUtils.name.size() == 38
+ assert false
+ } catch(MissingPropertyException mpe) { }
+ '''
+ }
+
+ void testAutoDownloadGrapeConfig() {
+
+ assertScript '''
+ @Grab('commons-digester:commons-digester:2.1;transitive=false')
+ import org.apache.commons.digester.Digester
+
+ assert Digester.name.size() == 36
+ '''
+
+ assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'downloadGrapes'
+
+ assertScript '''
+ @Grab('commons-digester:commons-digester:2.1;transitive=false')
+ @GrabConfig(autoDownload=false)
+ import org.apache.commons.digester.Digester
+
+ assert Digester.name.size() == 36
+ '''
+
+ assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'cachedGrapes'
+
+ assertScript '''
+ @Grab('commons-digester:commons-digester:2.1;transitive=false')
+ @GrabConfig(autoDownload=true)
+ import org.apache.commons.digester.Digester
+
+ assert Digester.name.size() == 36
+ '''
+
+ assert Grape.getInstance().ivyInstance.settings.defaultResolver.name == 'downloadGrapes'
+ }
+
+ /**
+ * GROOVY-470: multiple jars should be loaded for an artifacts with and without a classifier
+ */
+ void testClassifierAndNonClassifierOnSameArtifact() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+ Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classLoader:loader)
+ Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classifier:'tests', classLoader:loader)
+
+ def jars = jarNames(loader)
+ assert jars.contains ("neo4j-kernel-2.0.0-RC1.jar")
+ assert jars.contains ("neo4j-kernel-2.0.0-RC1-tests.jar")
+
+ // also check reverse ordering of deps
+ loader = new GroovyClassLoader()
+ Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classifier:'tests', classLoader:loader)
+ Grape.grab(groupId:'org.neo4j', artifactId:'neo4j-kernel', version:'2.0.0-RC1', classLoader:loader)
+
+ jars = jarNames(loader)
+ assert jars.contains ("neo4j-kernel-2.0.0-RC1.jar")
+ assert jars.contains ("neo4j-kernel-2.0.0-RC1-tests.jar")
+ }
+
+ void testSystemProperties_groovy7548() {
+ System.setProperty('groovy7548prop', 'x')
+ assert System.getProperty('groovy7548prop') == 'x'
+ new GroovyShell().evaluate '''
+ @GrabConfig(systemProperties='groovy7548prop=y')
+ @Grab('commons-lang:commons-lang:2.6')
+ import org.apache.commons.lang.StringUtils
+ assert StringUtils.name == 'org.apache.commons.lang.StringUtils'
+ '''
+ assert System.getProperty('groovy7548prop') == 'y'
+ }
+
+ // GROOVY-7649
+ void testResolveSucceedsAfterFailure() {
+ GroovyClassLoader loader = new GroovyClassLoader()
+
+ shouldFail{
+ Grape.resolve([classLoader:loader], [], [groupId:'bogus', artifactId:'bogus', version:'0.1'])
+ }
+
+ Grape.resolve([classLoader:loader], [], [groupId:'org.apache.poi', artifactId:'poi', version:'3.7'])
+ }
+}
diff --git a/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy b/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
index 6a4a0a3..28a1703 100644
--- a/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
+++ b/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
@@ -18,13 +18,9 @@
*/
package groovy.transform.stc
-import groovy.transform.NotYetImplemented
-
/**
* Test cases specifically aimed at testing the behaviour of the type checker
* with regards to anonymous inner classes.
- *
- * @author Cedric Champeau
*/
class AnonymousInnerClassSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy b/src/test/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
index badff32..e248442 100644
--- a/src/test/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
@@ -21,8 +21,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : arrays and collections.
- *
- * @author Cedric Champeau
*/
class ArraysAndCollectionsSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/CategoriesSTCTest.groovy b/src/test/groovy/transform/stc/CategoriesSTCTest.groovy
index 335201f..4b30c56 100644
--- a/src/test/groovy/transform/stc/CategoriesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/CategoriesSTCTest.groovy
@@ -21,8 +21,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : categories.
- *
- * @author Cedric Champeau
*/
class CategoriesSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 686336c..102e1c5 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -20,9 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : closures.
- *
- * @author Cedric Champeau
- * @author Jochen Theodorou
*/
class ClosuresSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/CoercionSTCTest.groovy b/src/test/groovy/transform/stc/CoercionSTCTest.groovy
index f670e82..0bbad56 100644
--- a/src/test/groovy/transform/stc/CoercionSTCTest.groovy
+++ b/src/test/groovy/transform/stc/CoercionSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : coercions.
- *
- * @author Cedric Champeau
*/
class CoercionSTCTest extends StaticTypeCheckingTestCase {
void testCoerceToArray() {
diff --git a/src/test/groovy/transform/stc/ConstructorsSTCTest.groovy b/src/test/groovy/transform/stc/ConstructorsSTCTest.groovy
index 69a62a6..e2bc7e4 100644
--- a/src/test/groovy/transform/stc/ConstructorsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ConstructorsSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : constructors.
- *
- * @author Cedric Champeau
*/
class ConstructorsSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/CustomErrorCollectorSTCTest.groovy b/src/test/groovy/transform/stc/CustomErrorCollectorSTCTest.groovy
index c2c82aa..ea10e42 100644
--- a/src/test/groovy/transform/stc/CustomErrorCollectorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/CustomErrorCollectorSTCTest.groovy
@@ -31,8 +31,6 @@ import org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor
/**
* Unit tests for static type checking : custom error collector.
- *
- * @author Cedric Champeau
*/
class CustomErrorCollectorSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy b/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
index f20220e..724ea21 100644
--- a/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
+++ b/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
@@ -23,9 +23,6 @@ import org.codehaus.groovy.control.ParserVersion
/**
* Units tests aimed at testing the behavior of {@link DelegatesTo} in combination
* with static type checking.
- *
- * @author Cedric Champeau
- * @author <a href="mailto:blackdrag@gmx.org">Jochen "blackdrag" Theodorou</a>
*/
class DelegatesToSTCTest extends StaticTypeCheckingTestCase {
void testShouldChooseMethodFromOwner() {
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 91834e1..2cf90b3 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -18,12 +18,8 @@
*/
package groovy.transform.stc
-import org.codehaus.groovy.ast.ASTNode
-
/**
* Unit tests for static type checking : fields and properties.
- *
- * @author Cedric Champeau
*/
class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
@@ -580,7 +576,7 @@ new FooWorker().doSomething()''', 'Cannot assign value of type java.util.ArrayLi
'''
}
- public void testPropertyWithMultipleSetters() {
+ void testPropertyWithMultipleSetters() {
assertScript '''import org.codehaus.groovy.ast.expr.BinaryExpression
import org.codehaus.groovy.ast.expr.BooleanExpression
import org.codehaus.groovy.ast.stmt.AssertStatement
@@ -813,15 +809,15 @@ import org.codehaus.groovy.ast.stmt.AssertStatement
'''
}
- public static interface InterfaceWithField {
+ static interface InterfaceWithField {
String boo = "I don't fancy fields in interfaces"
}
- public static class BaseClass {
+ static class BaseClass {
int x
}
- public static class BaseClass2 extends BaseClass {
+ static class BaseClass2 extends BaseClass {
}
}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 9084cca..fd204e1 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -23,8 +23,6 @@ import org.codehaus.groovy.control.ParserVersion
/**
* Unit tests for static type checking : generics.
- *
- * @author Cedric Champeau
*/
class GenericsSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/IOGMClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/IOGMClosureParamTypeInferenceSTCTest.groovy
index a57e44f..6ddf6b9 100644
--- a/src/test/groovy/transform/stc/IOGMClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/IOGMClosureParamTypeInferenceSTCTest.groovy
@@ -20,8 +20,6 @@
package groovy.transform.stc
/**
* Unit tests for static type checking : closure parameter type inference for {@link org.codehaus.groovy.runtime.IOGroovyMethods}.
- *
- * @author Cedric Champeau
*/
class IOGMClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/LoopsSTCTest.groovy b/src/test/groovy/transform/stc/LoopsSTCTest.groovy
index 0bf2e1f..6a9bff6 100644
--- a/src/test/groovy/transform/stc/LoopsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/LoopsSTCTest.groovy
@@ -22,8 +22,6 @@ import groovy.transform.CompileStatic
/**
* Unit tests for static type checking : loops.
- *
- * @author Cedric Champeau
*/
class LoopsSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
index 2437379..13bf500 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -23,8 +23,6 @@ import org.codehaus.groovy.control.customizers.ImportCustomizer
/**
* Unit tests for static type checking : method calls.
- *
- * @author Cedric Champeau
*/
class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
@Override
diff --git a/src/test/groovy/transform/stc/ResourceGMClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ResourceGMClosureParamTypeInferenceSTCTest.groovy
index 76da18f..757a9db 100644
--- a/src/test/groovy/transform/stc/ResourceGMClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ResourceGMClosureParamTypeInferenceSTCTest.groovy
@@ -20,8 +20,6 @@
package groovy.transform.stc
/**
* Unit tests for static type checking : closure parameter type inference for {@link org.codehaus.groovy.runtime.ResourceGroovyMethods}.
- *
- * @author Cedric Champeau
*/
class ResourceGMClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
void testEachByte() {
diff --git a/src/test/groovy/transform/stc/ReturnsSTCTest.groovy b/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
index 0b0e60a..5e2a870 100644
--- a/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : implicit and explicit returns.
- *
- * @author Cedric Champeau
*/
class ReturnsSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
index a45a989..169ab1c 100644
--- a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
+++ b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
@@ -22,8 +22,6 @@ import org.codehaus.groovy.runtime.m12n.ExtensionModuleHelperForTests
/**
* Unit tests for static type checking : extension methods.
- *
- * @author Cedric Champeau
*/
class STCExtensionMethodsTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/STCnAryExpressionTest.groovy b/src/test/groovy/transform/stc/STCnAryExpressionTest.groovy
index 35e9ca0..ac378b8 100644
--- a/src/test/groovy/transform/stc/STCnAryExpressionTest.groovy
+++ b/src/test/groovy/transform/stc/STCnAryExpressionTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : unary and binary expressions.
- *
- * @author Cedric Champeau
*/
class STCnAryExpressionTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/STCwithTransformationsTest.groovy b/src/test/groovy/transform/stc/STCwithTransformationsTest.groovy
index 4c68c5b..80a14cc 100644
--- a/src/test/groovy/transform/stc/STCwithTransformationsTest.groovy
+++ b/src/test/groovy/transform/stc/STCwithTransformationsTest.groovy
@@ -31,8 +31,6 @@ import java.lang.reflect.Modifier
/**
* Unit tests for static type checking and AST.
- *
- * @author Stephane Maldini
*/
class STCwithTransformationsTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/SocketGMClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/SocketGMClosureParamTypeInferenceSTCTest.groovy
index d1830a8..aca978a 100644
--- a/src/test/groovy/transform/stc/SocketGMClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/SocketGMClosureParamTypeInferenceSTCTest.groovy
@@ -20,8 +20,6 @@
package groovy.transform.stc
/**
* Unit tests for static type checking : closure parameter type inference for {@link org.codehaus.groovy.runtime.SocketGroovyMethods}.
- *
- * @author Cedric Champeau
*/
class SocketGMClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
void testAccept() {
diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 7776a83..d7c7da6 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : ternary operator tests.
- *
- * @author Cedric Champeau
*/
class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/TypeCheckingExtensionsTest.groovy b/src/test/groovy/transform/stc/TypeCheckingExtensionsTest.groovy
index f73f8ed..2ae60e4 100644
--- a/src/test/groovy/transform/stc/TypeCheckingExtensionsTest.groovy
+++ b/src/test/groovy/transform/stc/TypeCheckingExtensionsTest.groovy
@@ -24,8 +24,6 @@ import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport
/**
* Units tests for type checking extensions.
- *
- * @author Cedric Champeau
*/
class TypeCheckingExtensionsTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/TypeCheckingModeTest.groovy b/src/test/groovy/transform/stc/TypeCheckingModeTest.groovy
index fcfbc88..c083dac 100644
--- a/src/test/groovy/transform/stc/TypeCheckingModeTest.groovy
+++ b/src/test/groovy/transform/stc/TypeCheckingModeTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : type checking mode.
- *
- * @author Cedric Champeau
*/
class TypeCheckingModeTest extends StaticTypeCheckingTestCase {
void testShouldThrowErrorBecauseTypeCheckingIsOn() {
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index d1f61d8..f95ccc9 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -30,8 +30,6 @@ import org.codehaus.groovy.ast.tools.WideningCategories
/**
* Unit tests for static type checking : type inference.
- *
- * @author Cedric Champeau
*/
class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/UnaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/UnaryOperatorSTCTest.groovy
index aeba489..9770160 100644
--- a/src/test/groovy/transform/stc/UnaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/UnaryOperatorSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : unary operator tests.
- *
- * @author Cedric Champeau
*/
class UnaryOperatorSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/WithSTCTest.groovy b/src/test/groovy/transform/stc/WithSTCTest.groovy
index ff99bdf..afae05c 100644
--- a/src/test/groovy/transform/stc/WithSTCTest.groovy
+++ b/src/test/groovy/transform/stc/WithSTCTest.groovy
@@ -21,8 +21,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : with method.
- *
- * @author Andre Steingress
*/
class WithSTCTest extends StaticTypeCheckingTestCase {
diff --git a/src/test/groovy/transform/stc/vm6/MethodCallsSTCTest.groovy b/src/test/groovy/transform/stc/vm6/MethodCallsSTCTest.groovy
index 77ed504..0e1bcfa 100644
--- a/src/test/groovy/transform/stc/vm6/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/vm6/MethodCallsSTCTest.groovy
@@ -22,8 +22,6 @@ import groovy.transform.stc.StaticTypeCheckingTestCase
/**
* Unit tests for static type checking : method calls.
- *
- * @author Cedric Champeau
*/
class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
// GROOVY-5525
diff --git a/src/test/groovy/util/BufferedIteratorTest.groovy b/src/test/groovy/util/BufferedIteratorTest.groovy
index 104238f..6a4bf47 100644
--- a/src/test/groovy/util/BufferedIteratorTest.groovy
+++ b/src/test/groovy/util/BufferedIteratorTest.groovy
@@ -23,8 +23,6 @@ import org.codehaus.groovy.util.IteratorBufferedIterator;
/**
* Test class for BufferedIterators.
- *
- * @author Andrew Taylor
*/
class BufferedIteratorTest extends GroovyTestCase {
diff --git a/src/test/groovy/util/BuilderSupportTest.groovy b/src/test/groovy/util/BuilderSupportTest.groovy
index 534810d..304cbfb 100644
--- a/src/test/groovy/util/BuilderSupportTest.groovy
+++ b/src/test/groovy/util/BuilderSupportTest.groovy
@@ -19,15 +19,10 @@
package groovy.util
/**
- Testing BuilderSupport and reveal how calling
- methods on it result in implementation callbacks.
- Using the SpoofBuilder (see below) to call it in various ways
- and analyze the "spoofed" logs.
- This is especially useful when designing subclasses of BuilderSupport.
- @author Dierk Koenig
-**/
-
-
+ * Testing BuilderSupport and reveal how calling methods on it result in implementation callbacks.
+ * Using the SpoofBuilder (see below) to call it in various ways and analyze the "spoofed" logs.
+ * This is especially useful when designing subclasses of BuilderSupport.
+ */
class BuilderSupportTest extends GroovyTestCase{
void testSimpleNode() {
def b = new SpoofBuilder()
diff --git a/src/test/groovy/util/ConfigSlurperTest.groovy b/src/test/groovy/util/ConfigSlurperTest.groovy
index a69347f..894ed83 100644
--- a/src/test/groovy/util/ConfigSlurperTest.groovy
+++ b/src/test/groovy/util/ConfigSlurperTest.groovy
@@ -19,17 +19,9 @@
package groovy.util
/**
* Tests for the ConfigSlurper class
-
- * @author Graeme Rocher
- * @author Guillaume Laforge
- * @author Andres Almiray
- * @since 0.6
- *
- * Created: Jun 19, 2007
- * Time: 6:29:33 PM
*
+ * @since 0.6
*/
-
class ConfigSlurperTest extends GroovyTestCase {
void testConsecutiveSlurperValues() {
def config = new ConfigSlurper().parse('''
diff --git a/src/test/groovy/util/FactoryBuilderSupportTest.groovy b/src/test/groovy/util/FactoryBuilderSupportTest.groovy
index 970f825..d9ab7b8 100644
--- a/src/test/groovy/util/FactoryBuilderSupportTest.groovy
+++ b/src/test/groovy/util/FactoryBuilderSupportTest.groovy
@@ -21,9 +21,7 @@ package groovy.util
/**
* Test for FactoryBuilderSupport based in BuilderSupportTest
* as it should comply with the same contract
- * @author Andres Almiray
*/
-
class FactoryBuilderSupportTest extends GroovyTestCase {
void testSimpleNode() {
def b = new SpoofFactoryBuilder()
diff --git a/src/test/groovy/util/GroovyCollectionsStarImportTest.groovy b/src/test/groovy/util/GroovyCollectionsStarImportTest.groovy
index d0d23cf..20c4213 100644
--- a/src/test/groovy/util/GroovyCollectionsStarImportTest.groovy
+++ b/src/test/groovy/util/GroovyCollectionsStarImportTest.groovy
@@ -22,10 +22,8 @@ import static groovy.util.GroovyCollections.*
/**
* Tests GroovyCollections
-*
-* @author Paul King
*/
-public class GroovyCollectionsStarImportTest extends GroovyTestCase {
+class GroovyCollectionsStarImportTest extends GroovyTestCase {
void testCombinations() {
// use Sets because we don't care about order
diff --git a/src/test/groovy/util/GroovyCollectionsTest.groovy b/src/test/groovy/util/GroovyCollectionsTest.groovy
index 1678f5b..05e44c8 100644
--- a/src/test/groovy/util/GroovyCollectionsTest.groovy
+++ b/src/test/groovy/util/GroovyCollectionsTest.groovy
@@ -26,10 +26,8 @@ import static GroovyCollections.sum
/**
* Tests GroovyCollections
-*
-* @author Paul King
*/
-public class GroovyCollectionsTest extends GroovyTestCase {
+class GroovyCollectionsTest extends GroovyTestCase {
void testCombinations() {
// use Sets because we don't care about order
diff --git a/src/test/groovy/util/GroovyScriptEngineTest.groovy b/src/test/groovy/util/GroovyScriptEngineTest.groovy
index 1466f57..b62e589 100644
--- a/src/test/groovy/util/GroovyScriptEngineTest.groovy
+++ b/src/test/groovy/util/GroovyScriptEngineTest.groovy
@@ -30,9 +30,6 @@ import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-/**
- * @author Andre Steingress
- */
@RunWith(JUnit4)
class GroovyScriptEngineTest extends GroovyTestCase {
diff --git a/src/test/groovy/util/IndentPrinterTest.groovy b/src/test/groovy/util/IndentPrinterTest.groovy
index 609ab19..a16226b 100644
--- a/src/test/groovy/util/IndentPrinterTest.groovy
+++ b/src/test/groovy/util/IndentPrinterTest.groovy
@@ -20,7 +20,6 @@ package groovy.util
/**
* Unit test for IndentPrinter.
- * @author Hamlet D'Arcy
*/
class IndentPrinterTest extends GroovyTestCase {
diff --git a/src/test/groovy/util/JavadocAssertionTestBuilderTest.groovy b/src/test/groovy/util/JavadocAssertionTestBuilderTest.groovy
index f4597a7..fcf8e6d 100644
--- a/src/test/groovy/util/JavadocAssertionTestBuilderTest.groovy
+++ b/src/test/groovy/util/JavadocAssertionTestBuilderTest.groovy
@@ -1,135 +1,132 @@
-/*
- * 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
-
-import junit.framework.TestCase
-import org.codehaus.groovy.control.MultipleCompilationErrorsException
-
-/**
- * @author Merlyn Albery-Speyer
- */
-class JavadocAssertionTestBuilderTest extends GroovyTestCase {
- def builder
-
- void setUp() {
- builder = new JavadocAssertionTestBuilder()
- }
-
- void testBuildsTest() {
- Class test = builder.buildTest("SomeClass.java", '/** <pre class="groovyTestCase"> assert true </pre> */ public class SomeClass { }')
- assert test.newInstance() instanceof TestCase
- assert test.simpleName == "SomeClassJavadocAssertionTest"
- test.newInstance().testAssertionFromSomeClassLine1()
- }
-
- void testAssertionsAreCalled() {
- Class test = builder.buildTest("SomeClass.java", '/** <pre class="groovyTestCase"> assert false </pre> */ public class SomeClass { }')
- shouldFail(AssertionError) {
- test.newInstance().testAssertionFromSomeClassLine1()
- }
- }
-
- void testLineNumbering() {
- Class test = builder.buildTest("SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert true </pre>
- * Nothing on line 3
- * Two on this line <pre class="groovyTestCase"> assert true </pre> <pre class="groovyTestCase"> assert true </pre>
- */
- public class SomeClass { }
- ''')
- assert test.methods.findAll { it.name =~ /test.*/ }.size() == 3
- test.newInstance().testAssertionFromSomeClassLine2()
- test.newInstance().testAssertionFromSomeClassLine4a()
- test.newInstance().testAssertionFromSomeClassLine4b()
- }
-
- void testNoTestBuiltWhenThereAreNoAssertions() {
- Class test = builder.buildTest("SomeClass.java", "/** .. */ public class SomeClass { }")
- assert test == null
- }
-
- void testAssertionsMaySpanMultipleLines() {
- Class test = builder.buildTest("SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert(
- * true)
- * assert true </pre>
- */
- public class SomeClass { }
- ''')
- test.newInstance().testAssertionFromSomeClassLine2()
- }
-
- void testTagMustBeInsideJavadoc() {
- Class test = builder.buildTest("SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert true </pre>
- */
- public class SomeClass {
- public static void main(String[] args) {
- // <pre class="groovyTestCase"> assert false </pre>
- }
- }
- ''')
- assert test.methods.findAll { it.name =~ /test.*/ }.size() == 1
- test.newInstance().testAssertionFromSomeClassLine2()
- }
-
- void testClassNamesMayBeReusedAcrossPackages() {
- Class package1Test = builder.buildTest("./test/com/someplace/package1/SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert true </pre>
- */
- public class SomeClass { }
- ''')
- Class package2Test = builder.buildTest("./test/com/someplace/package2/SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert true </pre>
- */
- public class SomeClass { }
- ''')
- assert package1Test.simpleName == "SomeClassJavadocAssertionTest"
- assert package2Test.simpleName == "SomeClassJavadocAssertionTest"
- assert package1Test != package2Test
- }
-
- void testClassNeedNotBeAPreTag() {
- Class test = builder.buildTest("./test/com/someplace/package1/SomeClass.java", '''
- /** <code class="groovyTestCase"> assert true </code>
- */
- public class SomeClass { }
- ''')
- test.newInstance().testAssertionFromSomeClassLine2()
- }
-
- void testAssertionSyntaxErrorsReportedAtTestTime() {
- Class test = builder.buildTest("SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert #@$@ </pre> */
- public class SomeClass { }
- ''')
- shouldFail(MultipleCompilationErrorsException) {
- test.newInstance().testAssertionFromSomeClassLine2()
- }
- }
-
- void testDecodesCommonHtml() {
- Class test = builder.buildTest("SomeClass.java", '''
- /** <pre class="groovyTestCase"> assert 3 < 5
- * assert """ ><"&'&at;–""" == """ ><"&'@-"""</pre> */
- public class SomeClass { }
- ''')
- test.newInstance().testAssertionFromSomeClassLine2();
- }
-}
+/*
+ * 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
+
+import junit.framework.TestCase
+import org.codehaus.groovy.control.MultipleCompilationErrorsException
+
+class JavadocAssertionTestBuilderTest extends GroovyTestCase {
+ def builder
+
+ void setUp() {
+ builder = new JavadocAssertionTestBuilder()
+ }
+
+ void testBuildsTest() {
+ Class test = builder.buildTest("SomeClass.java", '/** <pre class="groovyTestCase"> assert true </pre> */ public class SomeClass { }')
+ assert test.newInstance() instanceof TestCase
+ assert test.simpleName == "SomeClassJavadocAssertionTest"
+ test.newInstance().testAssertionFromSomeClassLine1()
+ }
+
+ void testAssertionsAreCalled() {
+ Class test = builder.buildTest("SomeClass.java", '/** <pre class="groovyTestCase"> assert false </pre> */ public class SomeClass { }')
+ shouldFail(AssertionError) {
+ test.newInstance().testAssertionFromSomeClassLine1()
+ }
+ }
+
+ void testLineNumbering() {
+ Class test = builder.buildTest("SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert true </pre>
+ * Nothing on line 3
+ * Two on this line <pre class="groovyTestCase"> assert true </pre> <pre class="groovyTestCase"> assert true </pre>
+ */
+ public class SomeClass { }
+ ''')
+ assert test.methods.findAll { it.name =~ /test.*/ }.size() == 3
+ test.newInstance().testAssertionFromSomeClassLine2()
+ test.newInstance().testAssertionFromSomeClassLine4a()
+ test.newInstance().testAssertionFromSomeClassLine4b()
+ }
+
+ void testNoTestBuiltWhenThereAreNoAssertions() {
+ Class test = builder.buildTest("SomeClass.java", "/** .. */ public class SomeClass { }")
+ assert test == null
+ }
+
+ void testAssertionsMaySpanMultipleLines() {
+ Class test = builder.buildTest("SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert(
+ * true)
+ * assert true </pre>
+ */
+ public class SomeClass { }
+ ''')
+ test.newInstance().testAssertionFromSomeClassLine2()
+ }
+
+ void testTagMustBeInsideJavadoc() {
+ Class test = builder.buildTest("SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert true </pre>
+ */
+ public class SomeClass {
+ public static void main(String[] args) {
+ // <pre class="groovyTestCase"> assert false </pre>
+ }
+ }
+ ''')
+ assert test.methods.findAll { it.name =~ /test.*/ }.size() == 1
+ test.newInstance().testAssertionFromSomeClassLine2()
+ }
+
+ void testClassNamesMayBeReusedAcrossPackages() {
+ Class package1Test = builder.buildTest("./test/com/someplace/package1/SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert true </pre>
+ */
+ public class SomeClass { }
+ ''')
+ Class package2Test = builder.buildTest("./test/com/someplace/package2/SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert true </pre>
+ */
+ public class SomeClass { }
+ ''')
+ assert package1Test.simpleName == "SomeClassJavadocAssertionTest"
+ assert package2Test.simpleName == "SomeClassJavadocAssertionTest"
+ assert package1Test != package2Test
+ }
+
+ void testClassNeedNotBeAPreTag() {
+ Class test = builder.buildTest("./test/com/someplace/package1/SomeClass.java", '''
+ /** <code class="groovyTestCase"> assert true </code>
+ */
+ public class SomeClass { }
+ ''')
+ test.newInstance().testAssertionFromSomeClassLine2()
+ }
+
+ void testAssertionSyntaxErrorsReportedAtTestTime() {
+ Class test = builder.buildTest("SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert #@$@ </pre> */
+ public class SomeClass { }
+ ''')
+ shouldFail(MultipleCompilationErrorsException) {
+ test.newInstance().testAssertionFromSomeClassLine2()
+ }
+ }
+
+ void testDecodesCommonHtml() {
+ Class test = builder.buildTest("SomeClass.java", '''
+ /** <pre class="groovyTestCase"> assert 3 < 5
+ * assert """ ><"&'&at;–""" == """ ><"&'@-"""</pre> */
+ public class SomeClass { }
+ ''')
+ test.newInstance().testAssertionFromSomeClassLine2();
+ }
+}
diff --git a/src/test/groovy/util/NodeTest.groovy b/src/test/groovy/util/NodeTest.groovy
index 0f86d35..f9e4716 100644
--- a/src/test/groovy/util/NodeTest.groovy
+++ b/src/test/groovy/util/NodeTest.groovy
@@ -22,11 +22,8 @@ import groovy.xml.QName
/**
* Tests the use of the structured Attribute type
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- * @author Paul King
*/
-public class NodeTest extends GroovyTestCase {
+class NodeTest extends GroovyTestCase {
void testSimpleAttribute() {
Node node = new Node(null, "transactional");
diff --git a/src/test/groovy/util/ObservableListTest.groovy b/src/test/groovy/util/ObservableListTest.groovy
index 4e76604..616f11d 100644
--- a/src/test/groovy/util/ObservableListTest.groovy
+++ b/src/test/groovy/util/ObservableListTest.groovy
@@ -1,319 +1,316 @@
-/*
- * 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
-
-import java.beans.PropertyChangeEvent
-import java.beans.PropertyChangeListener
-
-/**
- * @author <a href="mailto:aalmiray@users.sourceforge.net">Andres Almiray</a>
- */
-class ObservableListTest extends GroovyTestCase {
- void testFireEvent_add_withoutTest() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- def value2 = 'value2'
-
- list << value1
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertNull(contentListener.event.oldValue)
- assertEquals(value1, contentListener.event.newValue)
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(0i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
-
- list << value2
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertNull(contentListener.event.oldValue)
- assertEquals(value2, contentListener.event.newValue)
-
- contentListener.event = null
- list[1] = value1
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(value2, contentListener.event.oldValue)
- assertEquals(value1, contentListener.event.newValue)
- assertEquals(1, contentListener.event.index)
-
- contentListener.event = null
- list[0] = value1
- assertNull(contentListener.event)
- }
-
- void testFireEvent_remove() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- def value2 = 'value2'
-
- list << value1
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertNull(contentListener.event.oldValue)
- assertEquals(value1, contentListener.event.newValue)
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(0i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
-
- list << value2
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertNull(contentListener.event.oldValue)
- assertEquals(value2, contentListener.event.newValue)
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(1i, sizeListener.event.oldValue)
- assertEquals(2i, sizeListener.event.newValue)
-
- list.remove(value2)
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.ElementRemovedEvent)
- assertEquals(list, contentListener.event.source)
- assertEquals(value2, contentListener.event.oldValue)
- assertEquals(1, contentListener.event.index)
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(2i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
-
- list.remove(value1)
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.ElementRemovedEvent)
- assertEquals(list, contentListener.event.source)
- assertEquals(value1, contentListener.event.oldValue)
- assertEquals(0, contentListener.event.index)
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(1i, sizeListener.event.oldValue)
- assertEquals(0i, sizeListener.event.newValue)
- }
-
- void testFireEvent_clear() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- def value2 = 'value2'
- list << value1
- list << value2
-
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(1i, sizeListener.event.oldValue)
- assertEquals(2i, sizeListener.event.newValue)
-
- list.clear()
-
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.ElementClearedEvent)
- assertEquals(list, contentListener.event.source)
- def values = contentListener.event.values
- assertNotNull(values)
- assertEquals(2, values.size())
- assertEquals(value1, values[0])
- assertEquals(value2, values[1])
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(2i, sizeListener.event.oldValue)
- assertEquals(0i, sizeListener.event.newValue)
- }
-
- void testFireEvent_addAll() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- list << value1
-
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(0i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
- assertEquals(0i, contentListener.event.index)
-
- def value2 = 'value2'
- list.addAll([value2, value1])
-
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.MultiElementAddedEvent)
- assertEquals(list, contentListener.event.source)
- def values = contentListener.event.values
- assertNotNull(values)
- assertEquals(2, values.size())
- assertEquals(value2, values[0])
- assertEquals(value1, values[1])
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(1i, sizeListener.event.oldValue)
- assertEquals(3i, sizeListener.event.newValue)
- assertEquals(1i, contentListener.event.index)
- }
-
- void testFireEvent_removeAll() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- def value2 = 'value2'
- list << value1
- list << value2
-
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(1i, sizeListener.event.oldValue)
- assertEquals(2i, sizeListener.event.newValue)
-
- list.removeAll([value2])
-
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.MultiElementRemovedEvent)
- assertEquals(list, contentListener.event.source)
- def values = contentListener.event.values
- assertNotNull(values)
- assertEquals(1, values.size())
- assertEquals(value2, values[0])
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(2i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
- }
-
- void testFireEvent_retainAll() {
- def list = new ObservableList()
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
-
- def value1 = 'value1'
- def value2 = 'value2'
- def value3 = 'value3'
- list << value1
- list << value2
- list << value3
-
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(2i, sizeListener.event.oldValue)
- assertEquals(3i, sizeListener.event.newValue)
-
- list.retainAll([value2])
-
- assertNotNull(contentListener.event)
- assertTrue(contentListener.event instanceof ObservableList.MultiElementRemovedEvent)
- assertEquals(list, contentListener.event.source)
- def values = contentListener.event.values
- assertNotNull(values)
- assertEquals(2, values.size())
- assertEquals(value1, values[0])
- assertEquals(value3, values[1])
- assertNotNull(sizeListener.event)
- assertEquals(list, contentListener.event.source)
- assertEquals(3i, sizeListener.event.oldValue)
- assertEquals(1i, sizeListener.event.newValue)
- }
-
- void testFireEvent_withTest() {
- def list = new ObservableList({ !(it instanceof String) })
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
-
- def value1 = 1
- def value2 = 'value2'
- list << value1
- assertNotNull(contentListener.event)
- assertEquals(list, contentListener.event.source)
- assertNull(contentListener.event.oldValue)
- assertEquals(value1, contentListener.event.newValue)
-
- contentListener.event = null
- list << value2
- assertNull(contentListener.event)
- }
-
- void testSort_Groovy4937() {
- def list = [3, 2, 1] as ObservableList
- list = list.sort()
- assert list == [1, 2, 3]
- }
-
- void testListIterator() {
- def list = [1, 2, 3, 4, 5] as ObservableList
- assert list.listIterator(2).collect { it } == [3, 4, 5]
- assert list.listIterator().collect { it } == [1, 2, 3, 4, 5]
- }
-
- void testRetainAllBugGroovy4699() {
- def list = new ObservableList(['test', 'test2'])
- def contentListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
- def sizeListener = new SampleListPropertyChangeListener()
- list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
- list.retainAll { false }
- assert list.isEmpty()
-
- // we are storing one event, so should see second element removed
- assertNotNull(contentListener.event)
- contentListener.event.with {
- assert it instanceof ObservableList.ElementRemovedEvent
- assert source == list
- assert oldValue == 'test2'
- assert index == 0
- }
- // and size property changed from 1 to 0
- assertNotNull(sizeListener.event)
- sizeListener.event.with {
- assert it instanceof java.beans.PropertyChangeEvent
- assert source == list
- assert propertyName == 'size'
- assert oldValue == 1
- assert newValue == 0
- }
- }
-}
-
-class SampleListPropertyChangeListener implements PropertyChangeListener {
- PropertyChangeEvent event
-
- public void propertyChange(PropertyChangeEvent evt) {
- event = evt
- }
-}
+/*
+ * 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
+
+import java.beans.PropertyChangeEvent
+import java.beans.PropertyChangeListener
+
+class ObservableListTest extends GroovyTestCase {
+ void testFireEvent_add_withoutTest() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ def value2 = 'value2'
+
+ list << value1
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertNull(contentListener.event.oldValue)
+ assertEquals(value1, contentListener.event.newValue)
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(0i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+
+ list << value2
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertNull(contentListener.event.oldValue)
+ assertEquals(value2, contentListener.event.newValue)
+
+ contentListener.event = null
+ list[1] = value1
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(value2, contentListener.event.oldValue)
+ assertEquals(value1, contentListener.event.newValue)
+ assertEquals(1, contentListener.event.index)
+
+ contentListener.event = null
+ list[0] = value1
+ assertNull(contentListener.event)
+ }
+
+ void testFireEvent_remove() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ def value2 = 'value2'
+
+ list << value1
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertNull(contentListener.event.oldValue)
+ assertEquals(value1, contentListener.event.newValue)
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(0i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+
+ list << value2
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertNull(contentListener.event.oldValue)
+ assertEquals(value2, contentListener.event.newValue)
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(1i, sizeListener.event.oldValue)
+ assertEquals(2i, sizeListener.event.newValue)
+
+ list.remove(value2)
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.ElementRemovedEvent)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(value2, contentListener.event.oldValue)
+ assertEquals(1, contentListener.event.index)
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(2i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+
+ list.remove(value1)
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.ElementRemovedEvent)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(value1, contentListener.event.oldValue)
+ assertEquals(0, contentListener.event.index)
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(1i, sizeListener.event.oldValue)
+ assertEquals(0i, sizeListener.event.newValue)
+ }
+
+ void testFireEvent_clear() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ def value2 = 'value2'
+ list << value1
+ list << value2
+
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(1i, sizeListener.event.oldValue)
+ assertEquals(2i, sizeListener.event.newValue)
+
+ list.clear()
+
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.ElementClearedEvent)
+ assertEquals(list, contentListener.event.source)
+ def values = contentListener.event.values
+ assertNotNull(values)
+ assertEquals(2, values.size())
+ assertEquals(value1, values[0])
+ assertEquals(value2, values[1])
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(2i, sizeListener.event.oldValue)
+ assertEquals(0i, sizeListener.event.newValue)
+ }
+
+ void testFireEvent_addAll() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ list << value1
+
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(0i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+ assertEquals(0i, contentListener.event.index)
+
+ def value2 = 'value2'
+ list.addAll([value2, value1])
+
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.MultiElementAddedEvent)
+ assertEquals(list, contentListener.event.source)
+ def values = contentListener.event.values
+ assertNotNull(values)
+ assertEquals(2, values.size())
+ assertEquals(value2, values[0])
+ assertEquals(value1, values[1])
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(1i, sizeListener.event.oldValue)
+ assertEquals(3i, sizeListener.event.newValue)
+ assertEquals(1i, contentListener.event.index)
+ }
+
+ void testFireEvent_removeAll() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ def value2 = 'value2'
+ list << value1
+ list << value2
+
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(1i, sizeListener.event.oldValue)
+ assertEquals(2i, sizeListener.event.newValue)
+
+ list.removeAll([value2])
+
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.MultiElementRemovedEvent)
+ assertEquals(list, contentListener.event.source)
+ def values = contentListener.event.values
+ assertNotNull(values)
+ assertEquals(1, values.size())
+ assertEquals(value2, values[0])
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(2i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+ }
+
+ void testFireEvent_retainAll() {
+ def list = new ObservableList()
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+
+ def value1 = 'value1'
+ def value2 = 'value2'
+ def value3 = 'value3'
+ list << value1
+ list << value2
+ list << value3
+
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(2i, sizeListener.event.oldValue)
+ assertEquals(3i, sizeListener.event.newValue)
+
+ list.retainAll([value2])
+
+ assertNotNull(contentListener.event)
+ assertTrue(contentListener.event instanceof ObservableList.MultiElementRemovedEvent)
+ assertEquals(list, contentListener.event.source)
+ def values = contentListener.event.values
+ assertNotNull(values)
+ assertEquals(2, values.size())
+ assertEquals(value1, values[0])
+ assertEquals(value3, values[1])
+ assertNotNull(sizeListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertEquals(3i, sizeListener.event.oldValue)
+ assertEquals(1i, sizeListener.event.newValue)
+ }
+
+ void testFireEvent_withTest() {
+ def list = new ObservableList({ !(it instanceof String) })
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+
+ def value1 = 1
+ def value2 = 'value2'
+ list << value1
+ assertNotNull(contentListener.event)
+ assertEquals(list, contentListener.event.source)
+ assertNull(contentListener.event.oldValue)
+ assertEquals(value1, contentListener.event.newValue)
+
+ contentListener.event = null
+ list << value2
+ assertNull(contentListener.event)
+ }
+
+ void testSort_Groovy4937() {
+ def list = [3, 2, 1] as ObservableList
+ list = list.sort()
+ assert list == [1, 2, 3]
+ }
+
+ void testListIterator() {
+ def list = [1, 2, 3, 4, 5] as ObservableList
+ assert list.listIterator(2).collect { it } == [3, 4, 5]
+ assert list.listIterator().collect { it } == [1, 2, 3, 4, 5]
+ }
+
+ void testRetainAllBugGroovy4699() {
+ def list = new ObservableList(['test', 'test2'])
+ def contentListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, contentListener)
+ def sizeListener = new SampleListPropertyChangeListener()
+ list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
+ list.retainAll { false }
+ assert list.isEmpty()
+
+ // we are storing one event, so should see second element removed
+ assertNotNull(contentListener.event)
+ contentListener.event.with {
+ assert it instanceof ObservableList.ElementRemovedEvent
+ assert source == list
+ assert oldValue == 'test2'
+ assert index == 0
+ }
+ // and size property changed from 1 to 0
+ assertNotNull(sizeListener.event)
+ sizeListener.event.with {
+ assert it instanceof java.beans.PropertyChangeEvent
+ assert source == list
+ assert propertyName == 'size'
+ assert oldValue == 1
+ assert newValue == 0
+ }
+ }
+}
+
+class SampleListPropertyChangeListener implements PropertyChangeListener {
+ PropertyChangeEvent event
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ event = evt
+ }
+}
diff --git a/src/test/groovy/util/ObservableMapTest.groovy b/src/test/groovy/util/ObservableMapTest.groovy
index eb59486..8346ea0 100644
--- a/src/test/groovy/util/ObservableMapTest.groovy
+++ b/src/test/groovy/util/ObservableMapTest.groovy
@@ -1,238 +1,235 @@
-/*
- * 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
-
-import java.beans.PropertyChangeEvent
-import java.beans.PropertyChangeListener
-
-/**
- * @author <a href="mailto:aalmiray@users.sourceforge.net">Andres Almiray</a>
- */
-class ObservableMapTest extends GroovyTestCase {
- void testFireEvent_withoutTest(){
- def map = new ObservableMap()
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key = 'key'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key] = null
- assertNotNull( propertyListener.event )
- assertTrue( propertyListener.event instanceof ObservableMap.PropertyAddedEvent )
- assertEquals( key, propertyListener.event.propertyName )
- assertNull( propertyListener.event.oldValue )
- assertNull( propertyListener.event.newValue )
- assert sizeListener.event
- assert 0 == sizeListener.event.oldValue
- assert 1 == sizeListener.event.newValue
-
- sizeListener.event = null
- map[key] = value1
- assertNotNull( propertyListener.event )
- assertEquals( map, propertyListener.event.source )
- assertEquals( key, propertyListener.event.propertyName )
- assertNull( propertyListener.event.oldValue )
- assertEquals( value1, propertyListener.event.newValue )
- assert !sizeListener.event
-
- map[key] = value2
- assertNotNull( propertyListener.event )
- assertEquals( map, propertyListener.event.source )
- assertEquals( key, propertyListener.event.propertyName )
- assertEquals( value1, propertyListener.event.oldValue )
- assertEquals( value2, propertyListener.event.newValue )
- assert !sizeListener.event
-
- propertyListener.event = null
- map[key] = value2
- assertNull( propertyListener.event )
-
- }
-
- void testFireEvent_removeKey(){
- def map = new ObservableMap()
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key = 'key'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key] = null
- assertNotNull( propertyListener.event )
- assertTrue( propertyListener.event instanceof ObservableMap.PropertyAddedEvent )
- assertEquals( key, propertyListener.event.propertyName )
- assertNull( propertyListener.event.newValue )
- assert sizeListener.event
- assert 0 == sizeListener.event.oldValue
- assert 1 == sizeListener.event.newValue
-
- sizeListener.event = null
- map[key] = value1
- assertNotNull( propertyListener.event )
- assertEquals( map, propertyListener.event.source )
- assertEquals( key, propertyListener.event.propertyName )
- assertNull( propertyListener.event.oldValue )
- assertEquals( value1, propertyListener.event.newValue )
- assert !sizeListener.event
-
- map.remove(key)
- assertNotNull( propertyListener.event )
- assertTrue( propertyListener.event instanceof ObservableMap.PropertyRemovedEvent )
- assertEquals( map, propertyListener.event.source )
- assertEquals( key, propertyListener.event.propertyName )
- assertEquals( value1, propertyListener.event.oldValue )
- assert sizeListener.event
- assert 1 == sizeListener.event.oldValue
- assert 0 == sizeListener.event.newValue
- }
-
- void testFireEvent_clearMap(){
- def map = new ObservableMap()
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key1 = 'key1'
- def key2 = 'key2'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key1] = value1
- map[key2] = value2
-
- assert sizeListener.event
- assert 1 == sizeListener.event.oldValue
- assert 2 == sizeListener.event.newValue
-
- map.clear()
-
- assertNotNull( propertyListener.event )
- assert propertyListener.event instanceof ObservableMap.PropertyClearedEvent
- assertEquals( map, propertyListener.event.source )
- def values = propertyListener.event.values
- assertNotNull( values )
- assertEquals( 2, values.size() )
- assertEquals( value1, values[key1] )
- assertEquals( value2, values[key2] )
- assert sizeListener.event
- assert 2 == sizeListener.event.oldValue
- assert 0 == sizeListener.event.newValue
- }
-
- void testFireEvent_putAll(){
- def map = new ObservableMap()
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key1 = 'key1'
- def key2 = 'key2'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key1] = null
-
- assert sizeListener.event
- assert 0 == sizeListener.event.oldValue
- assert 1 == sizeListener.event.newValue
-
- map.putAll( [key1: value1, key2: value2] )
-
- assertNotNull( propertyListener.event )
- assert propertyListener.event instanceof ObservableMap.MultiPropertyEvent
- assertEquals( map, propertyListener.event.source )
- assertEquals( 2, propertyListener.event.events.size() )
- assertTrue( propertyListener.event.events[0] instanceof ObservableMap.PropertyUpdatedEvent )
- assertEquals( key1, propertyListener.event.events[0].propertyName )
- assertEquals( value1, propertyListener.event.events[0].newValue )
- assertTrue( propertyListener.event.events[1] instanceof ObservableMap.PropertyAddedEvent )
- assertEquals( key2, propertyListener.event.events[1].propertyName )
- assertEquals( value2, propertyListener.event.events[1].newValue )
-
- assert sizeListener.event
- assert 1 == sizeListener.event.oldValue
- assert 2 == sizeListener.event.newValue
- }
-
- void testFireEvent_withTest(){
- def map = new ObservableMap( { it != 'value2' } )
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key = 'key'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key] = value1
- assertNotNull( propertyListener.event )
- assertEquals( map, propertyListener.event.source )
- assertEquals( key, propertyListener.event.propertyName )
- assertEquals( value1, propertyListener.event.newValue )
-
- propertyListener.event = null
- map[key] = value2
- assertNull( propertyListener.event )
- }
-
- void testFireEvent_withTestOnKey(){
- def map = new ObservableMap( { name, value -> name != 'key' } )
- def propertyListener = new SamplePropertyChangeListener()
- map.addPropertyChangeListener( propertyListener )
- def sizeListener = new SamplePropertyChangeListener(false)
- map.addPropertyChangeListener( ObservableMap.SIZE_PROPERTY, sizeListener )
-
- def key = 'key'
- def value1 = 'value1'
- def value2 = 'value2'
- map[key] = value1
- assertNull( propertyListener.event )
- map[key] = value2
- assertNull( propertyListener.event )
-
- map['key2'] = value1
- assertNotNull( propertyListener.event )
- assertEquals( map, propertyListener.event.source )
- assertEquals( 'key2', propertyListener.event.propertyName )
- assertEquals( value1, propertyListener.event.newValue )
- }
-}
-
-class SamplePropertyChangeListener implements PropertyChangeListener {
- PropertyChangeEvent event
- private final boolean skip
-
- SamplePropertyChangeListener() {
- this(true)
- }
-
- SamplePropertyChangeListener(boolean skip) {
- this.skip = skip;
- }
-
- public void propertyChange( PropertyChangeEvent evt ) {
- if(skip && evt.propertyName in [ObservableMap.SIZE_PROPERTY]) return
- event = evt
- }
-}
+/*
+ * 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
+
+import java.beans.PropertyChangeEvent
+import java.beans.PropertyChangeListener
+
+class ObservableMapTest extends GroovyTestCase {
+ void testFireEvent_withoutTest() {
+ def map = new ObservableMap()
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key = 'key'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key] = null
+ assertNotNull(propertyListener.event)
+ assertTrue(propertyListener.event instanceof ObservableMap.PropertyAddedEvent)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertNull(propertyListener.event.oldValue)
+ assertNull(propertyListener.event.newValue)
+ assert sizeListener.event
+ assert 0 == sizeListener.event.oldValue
+ assert 1 == sizeListener.event.newValue
+
+ sizeListener.event = null
+ map[key] = value1
+ assertNotNull(propertyListener.event)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertNull(propertyListener.event.oldValue)
+ assertEquals(value1, propertyListener.event.newValue)
+ assert !sizeListener.event
+
+ map[key] = value2
+ assertNotNull(propertyListener.event)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertEquals(value1, propertyListener.event.oldValue)
+ assertEquals(value2, propertyListener.event.newValue)
+ assert !sizeListener.event
+
+ propertyListener.event = null
+ map[key] = value2
+ assertNull(propertyListener.event)
+
+ }
+
+ void testFireEvent_removeKey() {
+ def map = new ObservableMap()
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key = 'key'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key] = null
+ assertNotNull(propertyListener.event)
+ assertTrue(propertyListener.event instanceof ObservableMap.PropertyAddedEvent)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertNull(propertyListener.event.newValue)
+ assert sizeListener.event
+ assert 0 == sizeListener.event.oldValue
+ assert 1 == sizeListener.event.newValue
+
+ sizeListener.event = null
+ map[key] = value1
+ assertNotNull(propertyListener.event)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertNull(propertyListener.event.oldValue)
+ assertEquals(value1, propertyListener.event.newValue)
+ assert !sizeListener.event
+
+ map.remove(key)
+ assertNotNull(propertyListener.event)
+ assertTrue(propertyListener.event instanceof ObservableMap.PropertyRemovedEvent)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertEquals(value1, propertyListener.event.oldValue)
+ assert sizeListener.event
+ assert 1 == sizeListener.event.oldValue
+ assert 0 == sizeListener.event.newValue
+ }
+
+ void testFireEvent_clearMap() {
+ def map = new ObservableMap()
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key1 = 'key1'
+ def key2 = 'key2'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key1] = value1
+ map[key2] = value2
+
+ assert sizeListener.event
+ assert 1 == sizeListener.event.oldValue
+ assert 2 == sizeListener.event.newValue
+
+ map.clear()
+
+ assertNotNull(propertyListener.event)
+ assert propertyListener.event instanceof ObservableMap.PropertyClearedEvent
+ assertEquals(map, propertyListener.event.source)
+ def values = propertyListener.event.values
+ assertNotNull(values)
+ assertEquals(2, values.size())
+ assertEquals(value1, values[key1])
+ assertEquals(value2, values[key2])
+ assert sizeListener.event
+ assert 2 == sizeListener.event.oldValue
+ assert 0 == sizeListener.event.newValue
+ }
+
+ void testFireEvent_putAll() {
+ def map = new ObservableMap()
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key1 = 'key1'
+ def key2 = 'key2'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key1] = null
+
+ assert sizeListener.event
+ assert 0 == sizeListener.event.oldValue
+ assert 1 == sizeListener.event.newValue
+
+ map.putAll([key1: value1, key2: value2])
+
+ assertNotNull(propertyListener.event)
+ assert propertyListener.event instanceof ObservableMap.MultiPropertyEvent
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(2, propertyListener.event.events.size())
+ assertTrue(propertyListener.event.events[0] instanceof ObservableMap.PropertyUpdatedEvent)
+ assertEquals(key1, propertyListener.event.events[0].propertyName)
+ assertEquals(value1, propertyListener.event.events[0].newValue)
+ assertTrue(propertyListener.event.events[1] instanceof ObservableMap.PropertyAddedEvent)
+ assertEquals(key2, propertyListener.event.events[1].propertyName)
+ assertEquals(value2, propertyListener.event.events[1].newValue)
+
+ assert sizeListener.event
+ assert 1 == sizeListener.event.oldValue
+ assert 2 == sizeListener.event.newValue
+ }
+
+ void testFireEvent_withTest() {
+ def map = new ObservableMap({ it != 'value2' })
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key = 'key'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key] = value1
+ assertNotNull(propertyListener.event)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals(key, propertyListener.event.propertyName)
+ assertEquals(value1, propertyListener.event.newValue)
+
+ propertyListener.event = null
+ map[key] = value2
+ assertNull(propertyListener.event)
+ }
+
+ void testFireEvent_withTestOnKey() {
+ def map = new ObservableMap({ name, value -> name != 'key' })
+ def propertyListener = new SamplePropertyChangeListener()
+ map.addPropertyChangeListener(propertyListener)
+ def sizeListener = new SamplePropertyChangeListener(false)
+ map.addPropertyChangeListener(ObservableMap.SIZE_PROPERTY, sizeListener)
+
+ def key = 'key'
+ def value1 = 'value1'
+ def value2 = 'value2'
+ map[key] = value1
+ assertNull(propertyListener.event)
+ map[key] = value2
+ assertNull(propertyListener.event)
+
+ map['key2'] = value1
+ assertNotNull(propertyListener.event)
+ assertEquals(map, propertyListener.event.source)
+ assertEquals('key2', propertyListener.event.propertyName)
+ assertEquals(value1, propertyListener.event.newValue)
+ }
+}
+
+class SamplePropertyChangeListener implements PropertyChangeListener {
+ PropertyChangeEvent event
+ private final boolean skip
+
+ SamplePropertyChangeListener() {
+ this(true)
+ }
+
+ SamplePropertyChangeListener(boolean skip) {
+ this.skip = skip;
+ }
+
+ void propertyChange(PropertyChangeEvent evt) {
+ if (skip && evt.propertyName in [ObservableMap.SIZE_PROPERTY]) return
+ event = evt
+ }
+}
diff --git a/src/test/groovy/util/ObservableSetTests.groovy b/src/test/groovy/util/ObservableSetTests.groovy
index a8bf730..d6519f3 100644
--- a/src/test/groovy/util/ObservableSetTests.groovy
+++ b/src/test/groovy/util/ObservableSetTests.groovy
@@ -21,9 +21,6 @@ package groovy.util
import java.beans.PropertyChangeEvent
import java.beans.PropertyChangeListener
-/**
- * @author <a href="mailto:aalmiray@users.sourceforge.net">Andres Almiray</a>
- */
class ObservableSetTests extends GroovyTestCase {
void testFireEvent_add_withoutTest() {
def set = new ObservableSet()
@@ -290,7 +287,7 @@ class ObservableSetTests extends GroovyTestCase {
class SampleSetPropertyChangeListener implements PropertyChangeListener {
PropertyChangeEvent event
- public void propertyChange(PropertyChangeEvent evt) {
+ void propertyChange(PropertyChangeEvent evt) {
event = evt
}
}
diff --git a/src/test/groovy/util/OrderByTest.groovy b/src/test/groovy/util/OrderByTest.groovy
index ad20e6e..6f6919a 100644
--- a/src/test/groovy/util/OrderByTest.groovy
+++ b/src/test/groovy/util/OrderByTest.groovy
@@ -22,9 +22,6 @@ import org.codehaus.groovy.runtime.DefaultGroovyMethods
/**
* Tests OrderBy
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- * @author Rod Code
*/
class OrderByTest extends GroovyTestCase {
diff --git a/src/test/groovy/util/ProxyGeneratorTest.groovy b/src/test/groovy/util/ProxyGeneratorTest.groovy
index b5a2a6d..53af084 100644
--- a/src/test/groovy/util/ProxyGeneratorTest.groovy
+++ b/src/test/groovy/util/ProxyGeneratorTest.groovy
@@ -18,9 +18,6 @@
*/
package groovy.util
-/**
- * @author Paul King
- */
class ProxyGeneratorTest extends GroovyTestCase {
ProxyGenerator generator = ProxyGenerator.INSTANCE
diff --git a/src/test/groovy/util/ProxyTest.groovy b/src/test/groovy/util/ProxyTest.groovy
index a7fc954..1845a2b 100644
--- a/src/test/groovy/util/ProxyTest.groovy
+++ b/src/test/groovy/util/ProxyTest.groovy
@@ -18,9 +18,6 @@
*/
package groovy.util
-/**
-* @author Dierk Koenig
-**/
class ProxyTest extends GroovyTestCase {
void testStringDecoration(){
diff --git a/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy b/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
index 4cbffa1..23bdf47 100644
--- a/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
+++ b/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
@@ -31,8 +31,6 @@ import org.codehaus.groovy.ast.ClassNode
*
* This test checks that closure inner classes are direct child of their enclosing class,
* instead of being child of the outermost class.
- *
- * @author Guillaume Laforge
*/
class ClosureAndInnerClassNodeStructureTest extends GroovyTestCase {
diff --git a/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy b/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
index 6d8e973..79c1a33 100644
--- a/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
@@ -16,23 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.codehaus.groovy.ast;
-
+package org.codehaus.groovy.ast
import org.codehaus.groovy.ast.builder.AstBuilder
-import org.codehaus.groovy.ast.stmt.*
-import org.codehaus.groovy.ast.expr.*
+import org.codehaus.groovy.ast.expr.BooleanExpression
+import org.codehaus.groovy.ast.stmt.BlockStatement
+import org.codehaus.groovy.ast.stmt.CatchStatement
+import org.codehaus.groovy.ast.stmt.EmptyStatement
+import org.codehaus.groovy.ast.stmt.IfStatement
+import org.codehaus.groovy.ast.stmt.TryCatchStatement
import org.codehaus.groovy.control.CompilePhase
/**
* Tests the CodeVisitorSupport.
- *
- * @author Hamlet D'Arcy
*/
+class CodeVisitorSupportTest extends GroovyTestCase {
-public class CodeVisitorSupportTest extends GroovyTestCase {
-
- public void testIfElse() {
+ void testIfElse() {
def ast = new AstBuilder().buildFromCode { if (true) { 1 } else { 2 } }
def visitor = new RecordingCodeVisitorSupport()
visitor.visitBlockStatement(ast[0]) // first element is always BlockStatement
@@ -45,7 +45,7 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
assert visitor.history.size == 5
}
- public void testEmptyStatementsOnIfElse() {
+ void testEmptyStatementsOnIfElse() {
def ast = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS, true, {
if (true) { 1 }
})
@@ -60,7 +60,7 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
assert visitor.history.size == 5
}
- public void testTryCatchFinally() {
+ void testTryCatchFinally() {
def ast = new AstBuilder().buildFromCode {
def x
try {
@@ -81,7 +81,7 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
assert visitor.history[4] == BlockStatement
}
- public void testEmptyStatementsOnTryCatch() {
+ void testEmptyStatementsOnTryCatch() {
def ast = new AstBuilder().buildFromCode {
def x
try {
@@ -103,26 +103,25 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
}
/**
-* Records the visit method that were called so that they can be queried and verified later.
-* This would be better implemented using invokeMethod but it is called from Java so it
-* won't dispatch correctly.
-*
-* @author Hamlet D'Arcy
-*/
-@groovy.transform.PackageScope class RecordingCodeVisitorSupport extends CodeVisitorSupport implements GroovyInterceptable {
+ * Records the visit method that were called so that they can be queried and verified later.
+ * This would be better implemented using invokeMethod but it is called from Java so it
+ * won't dispatch correctly.
+ */
+@groovy.transform.PackageScope
+class RecordingCodeVisitorSupport extends CodeVisitorSupport implements GroovyInterceptable {
def history = []
- public void visitBlockStatement(BlockStatement node) {
+ void visitBlockStatement(BlockStatement node) {
history << node.getClass()
super.visitBlockStatement(node)
}
- public void visitIfElse(IfStatement node) {
+ void visitIfElse(IfStatement node) {
history << node.getClass()
super.visitIfElse(node)
}
- public void visitBooleanExpression(BooleanExpression node) {
+ void visitBooleanExpression(BooleanExpression node) {
history << node.getClass()
super.visitBooleanExpression(node)
}
@@ -132,14 +131,14 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
super.visitEmptyStatement(node)
}
- public void visitTryCatchFinally(TryCatchStatement node) {
+ void visitTryCatchFinally(TryCatchStatement node) {
history << node.getClass()
super.visitTryCatchFinally(node);
}
- public void visitCatchStatement(CatchStatement node) {
+ void visitCatchStatement(CatchStatement node) {
history << node.getClass()
- super.visitCatchStatement(node);
+ super.visitCatchStatement(node);
}
}
diff --git a/src/test/org/codehaus/groovy/ast/GenericsTestCase.groovy b/src/test/org/codehaus/groovy/ast/GenericsTestCase.groovy
index a14900e..7e2c4a2 100644
--- a/src/test/org/codehaus/groovy/ast/GenericsTestCase.groovy
+++ b/src/test/org/codehaus/groovy/ast/GenericsTestCase.groovy
@@ -27,8 +27,6 @@ import org.codehaus.groovy.ast.expr.VariableExpression
/**
* Adds several utility methods which are used in tests on generics.
- *
- * @author Cedric Champeau
*/
abstract class GenericsTestCase extends GroovyTestCase {
diff --git a/src/test/org/codehaus/groovy/ast/MethodNodeTest.groovy b/src/test/org/codehaus/groovy/ast/MethodNodeTest.groovy
index 808650c..a8d51a2 100644
--- a/src/test/org/codehaus/groovy/ast/MethodNodeTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/MethodNodeTest.groovy
@@ -1,78 +1,73 @@
-/*
- * 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.ast;
-
-import org.codehaus.groovy.ast.builder.AstBuilder;
-import org.codehaus.groovy.ast.stmt.BlockStatement;
-import org.objectweb.asm.Opcodes;
-
-import junit.framework.TestCase
-import org.codehaus.groovy.control.CompilePhase;
-
-/**
- * Tests the VariableExpressionNode
- *
- * @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf</a>
- * @author Hamlet D'Arcy
- *
- */
-
-public class MethodNodeTest extends TestCase implements Opcodes {
-
- public void testGetTextSimple() {
- def ast = new AstBuilder().buildFromString CompilePhase.SEMANTIC_ANALYSIS, false, '''
-
- def myMethod() {
- }
-'''
- assert ast[1].@methods.get('myMethod')[0].text ==
- 'public java.lang.Object myMethod() { ... }'
- }
-
- public void testGetTextAdvanced() {
- def ast = new AstBuilder().buildFromString CompilePhase.SEMANTIC_ANALYSIS, false, '''
-
- private static final <T> T myMethod(String p1, int p2 = 1) throws Exception, IOException {
- }
-'''
- assert ast[1].@methods.get('myMethod')[0].text ==
- 'private static final java.lang.Object myMethod(java.lang.String p1, int p2 = 1) throws java.lang.Exception, java.io.IOException { ... }'
- }
-
- public void testIsDynamicReturnTypeExplicitObject() {
- def methodNode = new MethodNode('foo', ACC_PUBLIC, new ClassNode(Object.class), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
- assert !methodNode.isDynamicReturnType()
- }
-
- public void testIsDynamicReturnTypeDYNAMIC_TYPE() {
- MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
- assert methodNode.isDynamicReturnType()
- }
-
- public void testIsDynamicReturnTypeVoid() {
- MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
- assert !methodNode.isDynamicReturnType()
- }
-
- public void testIsDynamicReturnTypNull() {
- MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, null, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
- assert !methodNode.isDynamicReturnType()
- assertNotNull(methodNode.getReturnType())
- }
-}
+/*
+ * 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.ast
+
+import org.codehaus.groovy.ast.builder.AstBuilder
+import org.codehaus.groovy.ast.stmt.BlockStatement
+import org.objectweb.asm.Opcodes
+
+import junit.framework.TestCase
+import org.codehaus.groovy.control.CompilePhase
+
+/**
+ * Tests the VariableExpressionNode
+ */
+class MethodNodeTest extends TestCase implements Opcodes {
+
+ void testGetTextSimple() {
+ def ast = new AstBuilder().buildFromString CompilePhase.SEMANTIC_ANALYSIS, false, '''
+
+ def myMethod() {
+ }
+'''
+ assert ast[1].@methods.get('myMethod')[0].text ==
+ 'public java.lang.Object myMethod() { ... }'
+ }
+
+ void testGetTextAdvanced() {
+ def ast = new AstBuilder().buildFromString CompilePhase.SEMANTIC_ANALYSIS, false, '''
+
+ private static final <T> T myMethod(String p1, int p2 = 1) throws Exception, IOException {
+ }
+'''
+ assert ast[1].@methods.get('myMethod')[0].text ==
+ 'private static final java.lang.Object myMethod(java.lang.String p1, int p2 = 1) throws java.lang.Exception, java.io.IOException { ... }'
+ }
+
+ void testIsDynamicReturnTypeExplicitObject() {
+ def methodNode = new MethodNode('foo', ACC_PUBLIC, new ClassNode(Object.class), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
+ assert !methodNode.isDynamicReturnType()
+ }
+
+ void testIsDynamicReturnTypeDYNAMIC_TYPE() {
+ MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
+ assert methodNode.isDynamicReturnType()
+ }
+
+ void testIsDynamicReturnTypeVoid() {
+ MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
+ assert !methodNode.isDynamicReturnType()
+ }
+
+ void testIsDynamicReturnTypNull() {
+ MethodNode methodNode = new MethodNode('foo', ACC_PUBLIC, null, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement())
+ assert !methodNode.isDynamicReturnType()
+ assertNotNull(methodNode.getReturnType())
+ }
+}
diff --git a/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy b/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
index 3fc0611..4a0dde1 100644
--- a/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
@@ -18,26 +18,10 @@
*/
package org.codehaus.groovy.ast.builder
-import org.codehaus.groovy.ast.ASTNode
-import org.codehaus.groovy.ast.ClassNode
import org.junit.Assert
-import org.codehaus.groovy.ast.stmt.BlockStatement
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
-import org.codehaus.groovy.ast.expr.ConstantExpression
-import org.codehaus.groovy.ast.expr.DeclarationExpression
-import org.codehaus.groovy.ast.expr.VariableExpression
-import org.codehaus.groovy.ast.stmt.ReturnStatement
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.ArgumentListExpression
-import org.codehaus.groovy.ast.expr.AnnotationConstantExpression
-import org.codehaus.groovy.ast.AnnotationNode
-import org.codehaus.groovy.ast.expr.AttributeExpression
-
/**
- *
* Some useful AST assertion methods.
- * @author Hamlet D'Arcy
*/
class AstAssert {
diff --git a/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromCodeTest.groovy b/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromCodeTest.groovy
index 5da46a5..d1c5aca 100644
--- a/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromCodeTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromCodeTest.groovy
@@ -1,872 +1,872 @@
-/*
- * 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.ast.builder
-
-import org.codehaus.groovy.ast.builder.AstBuilder as FactoryAlias
-import org.codehaus.groovy.control.CompilePhase
-import org.codehaus.groovy.ast.ASTNode
-import org.codehaus.groovy.ast.ClassNode
-import org.codehaus.groovy.ast.Parameter
-import org.codehaus.groovy.ast.stmt.BlockStatement
-import org.codehaus.groovy.ast.VariableScope
-import org.codehaus.groovy.ast.expr.ConstantExpression
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
-import org.codehaus.groovy.ast.expr.BinaryExpression
-import org.codehaus.groovy.ast.expr.VariableExpression
-import org.codehaus.groovy.syntax.Token
-import org.codehaus.groovy.syntax.Types
-import org.codehaus.groovy.ast.expr.ConstructorCallExpression
-import org.codehaus.groovy.ast.expr.TupleExpression
-import org.codehaus.groovy.ast.expr.NamedArgumentListExpression
-import org.codehaus.groovy.ast.expr.MapEntryExpression
-import org.codehaus.groovy.ast.stmt.ReturnStatement
-import org.codehaus.groovy.ast.expr.ElvisOperatorExpression
-import org.codehaus.groovy.ast.expr.BooleanExpression
-import org.codehaus.groovy.ast.stmt.WhileStatement
-import org.codehaus.groovy.ast.expr.PostfixExpression
-import org.codehaus.groovy.ast.stmt.ContinueStatement
-import org.codehaus.groovy.ast.expr.TernaryExpression
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.SpreadMapExpression
-import org.codehaus.groovy.ast.expr.ArgumentListExpression
-import org.codehaus.groovy.ast.stmt.ForStatement
-import org.codehaus.groovy.ast.expr.ClosureListExpression
-import org.codehaus.groovy.ast.expr.DeclarationExpression
-import org.codehaus.groovy.ast.stmt.TryCatchStatement
-import org.codehaus.groovy.ast.stmt.SynchronizedStatement
-import org.codehaus.groovy.ast.stmt.AssertStatement
-import org.codehaus.groovy.ast.stmt.BreakStatement
-import org.codehaus.groovy.ast.stmt.SwitchStatement
-import org.codehaus.groovy.ast.stmt.CaseStatement
-import org.codehaus.groovy.ast.stmt.EmptyStatement
-import org.codehaus.groovy.ast.expr.RangeExpression
-import org.codehaus.groovy.ast.expr.MethodPointerExpression
-import org.codehaus.groovy.ast.expr.ClassExpression
-import org.codehaus.groovy.ast.expr.GStringExpression
-import org.codehaus.groovy.ast.expr.MapExpression
-import org.codehaus.groovy.ast.expr.UnaryPlusExpression
-import org.codehaus.groovy.ast.expr.UnaryMinusExpression
-import org.codehaus.groovy.ast.expr.PrefixExpression
-import org.codehaus.groovy.ast.expr.NotExpression
-import org.codehaus.groovy.ast.expr.ClosureExpression
-import org.codehaus.groovy.ast.expr.CastExpression
-import org.codehaus.groovy.ast.expr.ListExpression
-import org.codehaus.groovy.ast.stmt.IfStatement
-import org.codehaus.groovy.ast.ClassHelper
-
-/**
- * Test case to show an ASTBuilder working off of a code block.
- *
- * The field declarations, static initializers, instance initializers,
- * and most of the comments are all meaningful and tested.
- *
- * @author Hamlet D'Arcy
- */
-@WithAstBuilder
-public class AstBuilderFromCodeTest extends GroovyTestCase {
-
- List<ASTNode> normalField = new AstBuilder().buildFromCode { "constant#1" }
-
- static List<ASTNode> staticInitializedField
- static {
- staticInitializedField = new AstBuilder().buildFromCode { "constant#3" }
- }
- List<ASTNode> constructorInializedField
-
- AstBuilderFromCodeTest() {
- constructorInializedField = new AstBuilder().buildFromCode { "constant#4" }
- }
-
- List<ASTNode> normalProperty = new AstBuilder().buildFromCode { "constant#5" }
-
-
- public void testImportedClassName() {
-
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testFullyQualifiedClassName() {
-
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- // it is important for this to remain a method invocation on a fully qualified class name
- def result = new org.codehaus.groovy.ast.builder.AstBuilder().buildFromCode {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testAliasedClassName() {
-
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new FactoryAlias().buildFromCode {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testVariableInvocation() {
-
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- AstBuilder factory = new AstBuilder() //temporary variable is important to test
- def result = factory.buildFromCode {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testMethodReturnTypeInvocation() {
- shouldFail(IllegalStateException) {
- //todo: is there any way to make this work?
- makeAstFactory().buildFromCode { // typed as Object in AST :(
- println "Hello World"
- }
- }
- }
-
- /**
- * Factory method used in testing.
- */
- private AstBuilder makeAstFactory() {
- return new AstBuilder()
- }
-
-
- public void testPhase_SemanticAnalysis() {
-
- def expected = new AstBuilder().buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """ println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testPhase_Conversion() {
-
- def expected = new AstBuilder().buildFromString(CompilePhase.CONVERSION, """ println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode(CompilePhase.CONVERSION) {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testStatementsOnly_ReturnsScriptClass() {
- def expected = new AstBuilder().buildFromString(CompilePhase.CONVERSION, false, """ println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode(CompilePhase.CONVERSION, false) {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testSingleLineClosure() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {println "Hello World"}
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testSingleLineClosure_WithComment() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {println "Hello World"} // a comment DO NOT REMOVE
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testSingleLineClosure_MultipleStatements() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {println "Hello World"};4+5
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testMultilineClosure_WithComments() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {//comment1
- println "Hello World"//comment2
- }//comment3
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testSingleLineClosure_WithCStyleComment() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {println "Hello World"} /* a comment DO NOT REMOVE */
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testSingleLineClosure_WithMultipleCStyleComments() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder()./*comment1*/buildFromCode/*comment2*/{/*comment3*/println/*comment4*/"Hello World"/*comment5*/}/*comment6*/
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testThreeLineClosure() {
- def expected = new AstBuilder().buildFromString(""" println "I"; println "Love"; println "Groovy" """)
-
- def result = new AstBuilder().buildFromCode {
- println "I"
- println "Love"
- println "Groovy"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
- public void testInitializationInFieldDeclaration() {
- def expected = new AstBuilder().buildFromString(""" "constant#1" """)
- AstAssert.assertSyntaxTree(expected, normalField)
- }
-
- public void testInitializationInstaticInialization() {
- def expected = new AstBuilder().buildFromString(""" "constant#3" """)
- AstAssert.assertSyntaxTree(expected, staticInitializedField)
- }
-
- public void testInitializationInConstructor() {
- def expected = new AstBuilder().buildFromString(""" "constant#4" """)
- AstAssert.assertSyntaxTree(expected, constructorInializedField)
- }
-
- public void testInitializationInPropertyDeclaration() {
- def expected = new AstBuilder().buildFromString(""" "constant#5" """)
- AstAssert.assertSyntaxTree(expected, normalProperty)
- }
-
- public void testNamedArgumentListExpression() {
-
- def result = new AstBuilder().buildFromCode {
- new String(foo: 'bar')
- }
-
- def expected = new BlockStatement(
- [new ReturnStatement(
- new ConstructorCallExpression(
- new ClassNode(String),
- new TupleExpression(
- new NamedArgumentListExpression(
- [
- new MapEntryExpression(
- new ConstantExpression('foo'),
- new ConstantExpression('bar'),
- )
- ]
- )
- )
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testElvisOperatorExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- name ?: 'Anonymous'
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new ElvisOperatorExpression(
- new VariableExpression('name'),
- new ConstantExpression('Anonymous')
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testWhileStatementAndContinue() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- while (true) {
- x++;
- continue
- }
- }
-
- def expected = new BlockStatement(
- [new WhileStatement(
- new BooleanExpression(
- new ConstantExpression(true)
- ),
- new BlockStatement(
- [
- new ExpressionStatement(
- new PostfixExpression(
- new VariableExpression("x"),
- new Token(Types.PLUS_PLUS, "++", -1, -1),
- )
- ),
- new ContinueStatement()
- ],
- new VariableScope()
- )
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testTernaryExpression() {
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- true ? 'male' : 'female'
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new TernaryExpression(
- new BooleanExpression(
- new ConstantExpression(true)
- ),
- new ConstantExpression('male'),
- new ConstantExpression('female')
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testSpreadMapExpression() {
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- func(*: m)
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression('this', ClassHelper.OBJECT_TYPE),
- 'func',
- new NamedArgumentListExpression(
- [new MapEntryExpression(
- new SpreadMapExpression(
- new VariableExpression('m', ClassHelper.OBJECT_TYPE)
- ),
- new VariableExpression('m', ClassHelper.OBJECT_TYPE)
- )]
- )
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testForStatementAndClosureListExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- for (int x = 0; x < 10; x++) {
- println x
- }
- }
-
- def expected = new BlockStatement([new ForStatement(
- new Parameter(ClassHelper.OBJECT_TYPE, "forLoopDummyParameter"),
- new ClosureListExpression(
- [
- new DeclarationExpression(
- new VariableExpression("x"),
- new Token(Types.EQUALS, "=", -1, -1),
- new ConstantExpression(0)
- ),
- new BinaryExpression(
- new VariableExpression("x"),
- new Token(Types.COMPARE_LESS_THAN, "<", -1, -1),
- new ConstantExpression(10)
- ),
- new PostfixExpression(
- new VariableExpression("x"),
- new Token(Types.PLUS_PLUS, "++", -1, -1)
- )
- ]
- ),
- new BlockStatement(
- [
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- new VariableExpression("x"),
- )
- )
- )
- ],
- new VariableScope()
- )
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testFinallyStatement() {
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- try {
- return 1
- } finally {
- x.close()
- }
- }
-
- def expected = new BlockStatement(
- [new TryCatchStatement(
- new BlockStatement(
- [new ReturnStatement(
- new ConstantExpression(1)
- )],
- new VariableScope()
- ),
- new BlockStatement(
- [
- new BlockStatement(
- [
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression('x'),
- 'close',
- new ArgumentListExpression()
- )
- )
- ],
- new VariableScope())
- ],
- new VariableScope()
- )
- )], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testReturnAndSynchronizedStatement() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- synchronized (this) {
- return 1
- }
- }
-
- def expected = new BlockStatement(
- [new SynchronizedStatement(
- new VariableExpression("this"),
- new BlockStatement(
- [new ReturnStatement(
- new ConstantExpression(1)
- )],
- new VariableScope()
- )
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testAssertStatement() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- assert true: "should always be true"
- assert 1 == 2
- }
-
- def expected = new BlockStatement(
- [
- new AssertStatement(
- new BooleanExpression(
- new ConstantExpression(true)
- ),
- new ConstantExpression("should always be true")
- ),
- new AssertStatement(
- new BooleanExpression(
- new BinaryExpression(
- new ConstantExpression(1),
- new Token(Types.COMPARE_EQUAL, "==", -1, -1),
- new ConstantExpression(2)
- )
- )
- ),
- ],
- new VariableScope()
- )
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testSwitchAndCaseAndBreakStatements() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- switch (foo) {
- case 0:
- break
- case 1:
- case 2:
- println "<3"
- break
- default:
- println ">2"
- }
- }
-
- def expected = new BlockStatement(
- [new SwitchStatement(
- new VariableExpression("foo"),
- [
- new CaseStatement(
- new ConstantExpression(0),
- new BlockStatement(
- [new BreakStatement()], new VariableScope())
- ),
- new CaseStatement(
- new ConstantExpression(1),
- EmptyStatement.INSTANCE
- ),
- new CaseStatement(
- new ConstantExpression(2),
- new BlockStatement(
- [
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("<3")]
- )
- )
- ),
- new BreakStatement()
- ], new VariableScope()
- )
- )
- ],
- new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression(">2")]
- )
- )
- )],
- new VariableScope()
- )
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testRangeExpression_SimpleForm() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- (0..10)
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new RangeExpression(
- new ConstantExpression(0),
- new ConstantExpression(10),
- true
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testMethodPointerExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- Integer.&toString
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new MethodPointerExpression(
- new ClassExpression(ClassHelper.Integer_TYPE),
- new ConstantExpression("toString")
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testGStringExpression() {
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- "$foo"
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new GStringExpression('$foo',
- [new ConstantExpression(''), new ConstantExpression('')],
- [new VariableExpression('foo')])
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testMapAndMapEntryExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- [foo: 'bar', baz: 'buz']
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new MapExpression(
- [
- new MapEntryExpression(
- new ConstantExpression('foo'),
- new ConstantExpression('bar')
- ),
- new MapEntryExpression(
- new ConstantExpression('baz'),
- new ConstantExpression('buz')
- ),
- ]
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testClassExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- def foo = String
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new DeclarationExpression(
- new VariableExpression("foo"),
- new Token(Types.EQUALS, "=", -1, -1),
- new ClassExpression(ClassHelper.STRING_TYPE)
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testUnaryPlusExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- (+foo)
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new UnaryPlusExpression(
- new VariableExpression("foo")
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testUnaryMinusExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- (-foo)
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new UnaryMinusExpression(
- new VariableExpression("foo")
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testPrefixExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- ++1
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new PrefixExpression(
- new Token(Types.PLUS_PLUS, "++", -1, -1),
- new ConstantExpression(1)
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testPostfixExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- 1++
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new PostfixExpression(
- new ConstantExpression(1),
- new Token(Types.PLUS_PLUS, "++", -1, -1)
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testNotExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- !true
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new NotExpression(
- new ConstantExpression(true)
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testConstructorCallExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- new Integer(4)
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new ConstructorCallExpression(
- new ClassNode(Integer),
- new ArgumentListExpression(
- new ConstantExpression(4)
- )
- ))], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testClosureExpression_MultipleParameters() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- {x, y, z -> println z }
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new ClosureExpression(
- [
- new Parameter(ClassHelper.OBJECT_TYPE, "x"),
- new Parameter(ClassHelper.OBJECT_TYPE, "y"),
- new Parameter(ClassHelper.OBJECT_TYPE, "z")] as Parameter[],
- new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- new VariableExpression("z")
- )
- )
- )],
- new VariableScope()
- )
- ))], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testCastExpression() {
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- (Integer) ""
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new CastExpression(
- new ClassNode(Integer),
- new ConstantExpression("")
- ))], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testDeclarationAndListExpression() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- def foo = [1, 2, 3]
- }
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new DeclarationExpression(
- new VariableExpression("foo"),
- new Token(Types.EQUALS, "=", -1, -1),
- new ListExpression(
- [new ConstantExpression(1),
- new ConstantExpression(2),
- new ConstantExpression(3),]
- )
- ))], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testIfStatement() {
-
- def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
- if (foo == bar) println "Hello" else println "World"
- }
-
- def expected = new BlockStatement(
- [new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression("foo"),
- new Token(Types.COMPARE_EQUAL, "==", -1, -1),
- new VariableExpression("bar")
- )
- ),
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("Hello")]
- )
- )
- ),
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("World")]
- )
- )
- )
- )], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-}
+/*
+ * 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.ast.builder
+
+import org.codehaus.groovy.ast.ASTNode
+import org.codehaus.groovy.ast.ClassHelper
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.VariableScope
+import org.codehaus.groovy.ast.builder.AstBuilder as FactoryAlias
+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.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
+import org.codehaus.groovy.ast.expr.GStringExpression
+import org.codehaus.groovy.ast.expr.ListExpression
+import org.codehaus.groovy.ast.expr.MapEntryExpression
+import org.codehaus.groovy.ast.expr.MapExpression
+import org.codehaus.groovy.ast.expr.MethodCallExpression
+import org.codehaus.groovy.ast.expr.MethodPointerExpression
+import org.codehaus.groovy.ast.expr.NamedArgumentListExpression
+import org.codehaus.groovy.ast.expr.NotExpression
+import org.codehaus.groovy.ast.expr.PostfixExpression
+import org.codehaus.groovy.ast.expr.PrefixExpression
+import org.codehaus.groovy.ast.expr.RangeExpression
+import org.codehaus.groovy.ast.expr.SpreadMapExpression
+import org.codehaus.groovy.ast.expr.TernaryExpression
+import org.codehaus.groovy.ast.expr.TupleExpression
+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.ContinueStatement
+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.ast.stmt.SwitchStatement
+import org.codehaus.groovy.ast.stmt.SynchronizedStatement
+import org.codehaus.groovy.ast.stmt.TryCatchStatement
+import org.codehaus.groovy.ast.stmt.WhileStatement
+import org.codehaus.groovy.control.CompilePhase
+import org.codehaus.groovy.syntax.Token
+import org.codehaus.groovy.syntax.Types
+
+/**
+ * Test case to show an ASTBuilder working off of a code block.
+ *
+ * The field declarations, static initializers, instance initializers,
+ * and most of the comments are all meaningful and tested.
+ */
+@WithAstBuilder
+class AstBuilderFromCodeTest extends GroovyTestCase {
+
+ List<ASTNode> normalField = new AstBuilder().buildFromCode { "constant#1" }
+
+ static List<ASTNode> staticInitializedField
+ static {
+ staticInitializedField = new AstBuilder().buildFromCode { "constant#3" }
+ }
+ List<ASTNode> constructorInializedField
+
+ AstBuilderFromCodeTest() {
+ constructorInializedField = new AstBuilder().buildFromCode { "constant#4" }
+ }
+
+ List<ASTNode> normalProperty = new AstBuilder().buildFromCode { "constant#5" }
+
+
+ void testImportedClassName() {
+
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testFullyQualifiedClassName() {
+
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ // it is important for this to remain a method invocation on a fully qualified class name
+ def result = new org.codehaus.groovy.ast.builder.AstBuilder().buildFromCode {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testAliasedClassName() {
+
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new FactoryAlias().buildFromCode {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testVariableInvocation() {
+
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ AstBuilder factory = new AstBuilder() //temporary variable is important to test
+ def result = factory.buildFromCode {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testMethodReturnTypeInvocation() {
+ shouldFail(IllegalStateException) {
+ //todo: is there any way to make this work?
+ makeAstFactory().buildFromCode { // typed as Object in AST :(
+ println "Hello World"
+ }
+ }
+ }
+
+ /**
+ * Factory method used in testing.
+ */
+ private AstBuilder makeAstFactory() {
+ return new AstBuilder()
+ }
+
+
+ void testPhase_SemanticAnalysis() {
+
+ def expected = new AstBuilder().buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """ println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testPhase_Conversion() {
+
+ def expected = new AstBuilder().buildFromString(CompilePhase.CONVERSION, """ println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.CONVERSION) {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testStatementsOnly_ReturnsScriptClass() {
+ def expected = new AstBuilder().buildFromString(CompilePhase.CONVERSION, false, """ println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.CONVERSION, false) {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testSingleLineClosure() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode { println "Hello World" }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testSingleLineClosure_WithComment() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode { println "Hello World" } // a comment DO NOT REMOVE
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testSingleLineClosure_MultipleStatements() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode { println "Hello World" }; 4 + 5
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testMultilineClosure_WithComments() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode {//comment1
+ println "Hello World"//comment2
+ }//comment3
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testSingleLineClosure_WithCStyleComment() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode { println "Hello World" } /* a comment DO NOT REMOVE */
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testSingleLineClosure_WithMultipleCStyleComments() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder()./*comment1*/ buildFromCode/*comment2*/ {/*comment3*/
+ println/*comment4*/ "Hello World"/*comment5*/
+ }/*comment6*/
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testThreeLineClosure() {
+ def expected = new AstBuilder().buildFromString(""" println "I"; println "Love"; println "Groovy" """)
+
+ def result = new AstBuilder().buildFromCode {
+ println "I"
+ println "Love"
+ println "Groovy"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+ void testInitializationInFieldDeclaration() {
+ def expected = new AstBuilder().buildFromString(""" "constant#1" """)
+ AstAssert.assertSyntaxTree(expected, normalField)
+ }
+
+ void testInitializationInstaticInialization() {
+ def expected = new AstBuilder().buildFromString(""" "constant#3" """)
+ AstAssert.assertSyntaxTree(expected, staticInitializedField)
+ }
+
+ void testInitializationInConstructor() {
+ def expected = new AstBuilder().buildFromString(""" "constant#4" """)
+ AstAssert.assertSyntaxTree(expected, constructorInializedField)
+ }
+
+ void testInitializationInPropertyDeclaration() {
+ def expected = new AstBuilder().buildFromString(""" "constant#5" """)
+ AstAssert.assertSyntaxTree(expected, normalProperty)
+ }
+
+ void testNamedArgumentListExpression() {
+
+ def result = new AstBuilder().buildFromCode {
+ new String(foo: 'bar')
+ }
+
+ def expected = new BlockStatement(
+ [new ReturnStatement(
+ new ConstructorCallExpression(
+ new ClassNode(String),
+ new TupleExpression(
+ new NamedArgumentListExpression(
+ [
+ new MapEntryExpression(
+ new ConstantExpression('foo'),
+ new ConstantExpression('bar'),
+ )
+ ]
+ )
+ )
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testElvisOperatorExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ name ?: 'Anonymous'
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new ElvisOperatorExpression(
+ new VariableExpression('name'),
+ new ConstantExpression('Anonymous')
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testWhileStatementAndContinue() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ while (true) {
+ x++
+ continue
+ }
+ }
+
+ def expected = new BlockStatement(
+ [new WhileStatement(
+ new BooleanExpression(
+ new ConstantExpression(true)
+ ),
+ new BlockStatement(
+ [
+ new ExpressionStatement(
+ new PostfixExpression(
+ new VariableExpression("x"),
+ new Token(Types.PLUS_PLUS, "++", -1, -1),
+ )
+ ),
+ new ContinueStatement()
+ ],
+ new VariableScope()
+ )
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testTernaryExpression() {
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ true ? 'male' : 'female'
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new TernaryExpression(
+ new BooleanExpression(
+ new ConstantExpression(true)
+ ),
+ new ConstantExpression('male'),
+ new ConstantExpression('female')
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testSpreadMapExpression() {
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ func(*: m)
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression('this', ClassHelper.OBJECT_TYPE),
+ 'func',
+ new NamedArgumentListExpression(
+ [new MapEntryExpression(
+ new SpreadMapExpression(
+ new VariableExpression('m', ClassHelper.OBJECT_TYPE)
+ ),
+ new VariableExpression('m', ClassHelper.OBJECT_TYPE)
+ )]
+ )
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testForStatementAndClosureListExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ for (int x = 0; x < 10; x++) {
+ println x
+ }
+ }
+
+ def expected = new BlockStatement([new ForStatement(
+ new Parameter(ClassHelper.OBJECT_TYPE, "forLoopDummyParameter"),
+ new ClosureListExpression(
+ [
+ new DeclarationExpression(
+ new VariableExpression("x"),
+ new Token(Types.EQUALS, "=", -1, -1),
+ new ConstantExpression(0)
+ ),
+ new BinaryExpression(
+ new VariableExpression("x"),
+ new Token(Types.COMPARE_LESS_THAN, "<", -1, -1),
+ new ConstantExpression(10)
+ ),
+ new PostfixExpression(
+ new VariableExpression("x"),
+ new Token(Types.PLUS_PLUS, "++", -1, -1)
+ )
+ ]
+ ),
+ new BlockStatement(
+ [
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ new VariableExpression("x"),
+ )
+ )
+ )
+ ],
+ new VariableScope()
+ )
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testFinallyStatement() {
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ try {
+ return 1
+ } finally {
+ x.close()
+ }
+ }
+
+ def expected = new BlockStatement(
+ [new TryCatchStatement(
+ new BlockStatement(
+ [new ReturnStatement(
+ new ConstantExpression(1)
+ )],
+ new VariableScope()
+ ),
+ new BlockStatement(
+ [
+ new BlockStatement(
+ [
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression('x'),
+ 'close',
+ new ArgumentListExpression()
+ )
+ )
+ ],
+ new VariableScope())
+ ],
+ new VariableScope()
+ )
+ )], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testReturnAndSynchronizedStatement() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ synchronized (this) {
+ return 1
+ }
+ }
+
+ def expected = new BlockStatement(
+ [new SynchronizedStatement(
+ new VariableExpression("this"),
+ new BlockStatement(
+ [new ReturnStatement(
+ new ConstantExpression(1)
+ )],
+ new VariableScope()
+ )
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testAssertStatement() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ assert true: "should always be true"
+ assert 1 == 2
+ }
+
+ def expected = new BlockStatement(
+ [
+ new AssertStatement(
+ new BooleanExpression(
+ new ConstantExpression(true)
+ ),
+ new ConstantExpression("should always be true")
+ ),
+ new AssertStatement(
+ new BooleanExpression(
+ new BinaryExpression(
+ new ConstantExpression(1),
+ new Token(Types.COMPARE_EQUAL, "==", -1, -1),
+ new ConstantExpression(2)
+ )
+ )
+ ),
+ ],
+ new VariableScope()
+ )
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testSwitchAndCaseAndBreakStatements() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ switch (foo) {
+ case 0:
+ break
+ case 1:
+ case 2:
+ println "<3"
+ break
+ default:
+ println ">2"
+ }
+ }
+
+ def expected = new BlockStatement(
+ [new SwitchStatement(
+ new VariableExpression("foo"),
+ [
+ new CaseStatement(
+ new ConstantExpression(0),
+ new BlockStatement(
+ [new BreakStatement()], new VariableScope())
+ ),
+ new CaseStatement(
+ new ConstantExpression(1),
+ EmptyStatement.INSTANCE
+ ),
+ new CaseStatement(
+ new ConstantExpression(2),
+ new BlockStatement(
+ [
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("<3")]
+ )
+ )
+ ),
+ new BreakStatement()
+ ], new VariableScope()
+ )
+ )
+ ],
+ new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression(">2")]
+ )
+ )
+ )],
+ new VariableScope()
+ )
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testRangeExpression_SimpleForm() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ (0..10)
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new RangeExpression(
+ new ConstantExpression(0),
+ new ConstantExpression(10),
+ true
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testMethodPointerExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ Integer.&toString
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new MethodPointerExpression(
+ new ClassExpression(ClassHelper.Integer_TYPE),
+ new ConstantExpression("toString")
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testGStringExpression() {
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ "$foo"
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new GStringExpression('$foo',
+ [new ConstantExpression(''), new ConstantExpression('')],
+ [new VariableExpression('foo')])
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testMapAndMapEntryExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ [foo: 'bar', baz: 'buz']
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new MapExpression(
+ [
+ new MapEntryExpression(
+ new ConstantExpression('foo'),
+ new ConstantExpression('bar')
+ ),
+ new MapEntryExpression(
+ new ConstantExpression('baz'),
+ new ConstantExpression('buz')
+ ),
+ ]
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testClassExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ def foo = String
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new DeclarationExpression(
+ new VariableExpression("foo"),
+ new Token(Types.EQUALS, "=", -1, -1),
+ new ClassExpression(ClassHelper.STRING_TYPE)
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testUnaryPlusExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ (+foo)
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new UnaryPlusExpression(
+ new VariableExpression("foo")
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testUnaryMinusExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ (-foo)
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new UnaryMinusExpression(
+ new VariableExpression("foo")
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testPrefixExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ ++1
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new PrefixExpression(
+ new Token(Types.PLUS_PLUS, "++", -1, -1),
+ new ConstantExpression(1)
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testPostfixExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ 1++
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new PostfixExpression(
+ new ConstantExpression(1),
+ new Token(Types.PLUS_PLUS, "++", -1, -1)
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testNotExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ !true
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new NotExpression(
+ new ConstantExpression(true)
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testConstructorCallExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ new Integer(4)
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new ConstructorCallExpression(
+ new ClassNode(Integer),
+ new ArgumentListExpression(
+ new ConstantExpression(4)
+ )
+ ))], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testClosureExpression_MultipleParameters() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ { x, y, z -> println z }
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new ClosureExpression(
+ [
+ new Parameter(ClassHelper.OBJECT_TYPE, "x"),
+ new Parameter(ClassHelper.OBJECT_TYPE, "y"),
+ new Parameter(ClassHelper.OBJECT_TYPE, "z")] as Parameter[],
+ new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ new VariableExpression("z")
+ )
+ )
+ )],
+ new VariableScope()
+ )
+ ))], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testCastExpression() {
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ (Integer) ""
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new CastExpression(
+ new ClassNode(Integer),
+ new ConstantExpression("")
+ ))], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testDeclarationAndListExpression() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ def foo = [1, 2, 3]
+ }
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new DeclarationExpression(
+ new VariableExpression("foo"),
+ new Token(Types.EQUALS, "=", -1, -1),
+ new ListExpression(
+ [new ConstantExpression(1),
+ new ConstantExpression(2),
+ new ConstantExpression(3),]
+ )
+ ))], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testIfStatement() {
+
+ def result = new AstBuilder().buildFromCode(CompilePhase.SEMANTIC_ANALYSIS) {
+ if (foo == bar) println "Hello" else println "World"
+ }
+
+ def expected = new BlockStatement(
+ [new IfStatement(
+ new BooleanExpression(
+ new BinaryExpression(
+ new VariableExpression("foo"),
+ new Token(Types.COMPARE_EQUAL, "==", -1, -1),
+ new VariableExpression("bar")
+ )
+ ),
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("Hello")]
+ )
+ )
+ ),
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("World")]
+ )
+ )
+ )
+ )], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+}
diff --git a/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromStringTest.groovy b/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromStringTest.groovy
index 6d0330f..4e5f6f1 100644
--- a/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromStringTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/AstBuilderFromStringTest.groovy
@@ -1,352 +1,350 @@
-/*
- * 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.ast.builder
-
-import org.codehaus.groovy.ast.ASTNode
-import org.codehaus.groovy.ast.ClassNode
-import org.codehaus.groovy.ast.VariableScope
-import org.codehaus.groovy.ast.expr.ConstantExpression
-import org.codehaus.groovy.ast.expr.DeclarationExpression
-import org.codehaus.groovy.ast.expr.VariableExpression
-import org.codehaus.groovy.ast.stmt.BlockStatement
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
-import org.codehaus.groovy.control.CompilePhase
-import org.codehaus.groovy.syntax.Token
-import org.codehaus.groovy.syntax.Types
-import org.codehaus.groovy.ast.stmt.ReturnStatement
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.ArgumentListExpression
-import org.codehaus.groovy.ast.stmt.IfStatement
-import org.codehaus.groovy.ast.expr.BooleanExpression
-import org.codehaus.groovy.ast.expr.BinaryExpression
-import org.codehaus.groovy.ast.stmt.BreakStatement
-import org.codehaus.groovy.ast.stmt.SwitchStatement
-import org.codehaus.groovy.ast.stmt.CaseStatement
-import org.codehaus.groovy.ast.stmt.EmptyStatement
-import org.objectweb.asm.Opcodes
-import org.codehaus.groovy.ast.FieldNode
-import org.codehaus.groovy.ast.MethodNode
-import org.codehaus.groovy.ast.Parameter
-import org.codehaus.groovy.ast.ConstructorNode
-import org.codehaus.groovy.ast.ClassHelper
-
-/**
- * Unit test for the AstBuilder class. Shows the usage of how to create AST from string input.
- * @author Hamlet D'Arcy
- */
-
-public class AstBuilderFromStringTest extends GroovyTestCase {
-
- private AstBuilder factory
-
- protected void setUp() {
- super.setUp()
- factory = new AstBuilder()
- }
-
-
- /**
- * This shows how to compile a simple script that returns a constant,
- * discarding the generated Script subclass.
- */
- public void testSimpleConstant() {
- List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, " \"Some String\" ")
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new ConstantExpression("Some String")
- )],
- new VariableScope()
- )
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- /**
- * This shows how to compile a script that includes declarations,
- * discarding the generated Script subclass.
- */
- public void testAssignment() {
- List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, " def x = 2; def y = 4 ")
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new DeclarationExpression(
- new VariableExpression("x"),
- Token.newSymbol(Types.EQUAL, 0, 0),
- new ConstantExpression(2)
- )
- ),
- new ExpressionStatement(
- new DeclarationExpression(
- new VariableExpression("y"),
- Token.newSymbol(Types.EQUAL, 0, 0),
- new ConstantExpression(4)
- )
- )],
- new VariableScope()
- )
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- /**
- * This shows how to compile a script that includes method calls,
- * discarding the generated Script subclass.
- */
- public void testMethodCall() {
- List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, """ println "Hello World" """)
-
- def expected = new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("Hello World")]
- )
- )
- )],
- new VariableScope()
- )
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- /**
- * This shows how to get the Script subclass off of the compiled result, compiling
- * all the way to CLASS_GENERATION.
- */
- public void testWithScriptClassAndClassGeneration() {
- List<ASTNode> result = factory.buildFromString(CompilePhase.CLASS_GENERATION, false, " \"Some String\" ")
-
- def expectedScriptBody = new BlockStatement(
- [new ReturnStatement(
- new ConstantExpression("Some String")
- )],
- new VariableScope()
- )
-
- def expectedClassNode = new ClassNode("synthesized", 1024, ClassHelper.make(Script))
-
- AstAssert.assertSyntaxTree([expectedScriptBody, expectedClassNode], result)
- }
-
- /**
- * Proves default value is CLASS_GENERATION and statementsOnly = true.
- */
- public void testDefaultValues() {
- List<ASTNode> result = factory.buildFromString(" \"Some String\" ")
-
- def expectedScriptBody = new BlockStatement(
- [new ReturnStatement(
- new ConstantExpression("Some String")
- )],
- new VariableScope()
- )
-
- AstAssert.assertSyntaxTree([expectedScriptBody], result)
- }
-
- /**
- * This tests the contract of the build method, trying to pass null
- * arguments when those arguments are required.
- */
- public void testContract() {
-
- // source is required
- shouldFail(IllegalArgumentException) {
- factory.buildFromString((String) null)
- }
-
- // source must not be empty
- shouldFail(IllegalArgumentException) {
- factory.buildFromString(" ")
- }
- }
-
-
- public void testIfStatement() {
-
- def result = factory.buildFromString(
- CompilePhase.SEMANTIC_ANALYSIS,
- """ if (foo == bar) println "Hello" else println "World" """)
-
- def expected = new BlockStatement(
- [new IfStatement(
- new BooleanExpression(
- new BinaryExpression(
- new VariableExpression("foo"),
- new Token(Types.COMPARE_EQUAL, "==", -1, -1),
- new VariableExpression("bar")
- )
- ),
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("Hello")]
- )
- )
- ),
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("World")]
- )
- )
- )
- )], new VariableScope())
- AstAssert.assertSyntaxTree([expected], result)
- }
-
-
- public void testSwitchAndCaseAndBreakStatements() {
-
- def result = new AstBuilder().buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """
- switch (foo) {
- case 0:
- break
- case 1:
- case 2:
- println "<3"
- break
- default:
- println ">2"
- }
- """)
-
- def expected = new BlockStatement(
- [new SwitchStatement(
- new VariableExpression("foo"),
- [
- new CaseStatement(
- new ConstantExpression(0),
- new BlockStatement(
- [new BreakStatement()], new VariableScope())
- ),
- new CaseStatement(
- new ConstantExpression(1),
- EmptyStatement.INSTANCE
- ),
- new CaseStatement(
- new ConstantExpression(2),
- new BlockStatement(
- [
- new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression("<3")]
- )
- )
- ),
- new BreakStatement()
- ], new VariableScope()
- )
- )
- ],
- new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression("this"),
- new ConstantExpression("println"),
- new ArgumentListExpression(
- [new ConstantExpression(">2")]
- )
- )
- )],
- new VariableScope()
- )
- )], new VariableScope())
-
- AstAssert.assertSyntaxTree([expected], result)
- }
-
- public void testCreatingClassAndMethods() {
- def result = factory.buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """
- class MyClass {
- private String myField = "a field value"
- MyClass() {
- println "In constructor!"
- }
-
- def myMethod() {
- println "In method!"
- }
- }
- """)
-
- def expected = [
- new BlockStatement(),
- new ClassNode("MyClass", Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE)
- ]
- AstAssert.assertSyntaxTree(expected, result)
-
- def classNode = result[1]
- def field = classNode?.fields?.find {FieldNode f -> f.name == 'myField' }
- def expectedField = new FieldNode(
- 'myField',
- Opcodes.ACC_PRIVATE,
- ClassHelper.STRING_TYPE,
- classNode,
- new ConstantExpression('a field value')
- )
- AstAssert.assertSyntaxTree([expectedField], [field])
-
- def method = classNode?.methods?.find {MethodNode m -> m.name == 'myMethod' }
- def expectedMethod = new MethodNode(
- 'myMethod',
- Opcodes.ACC_PUBLIC,
- ClassHelper.OBJECT_TYPE,
- [] as Parameter[],
- [] as ClassNode[],
- new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression('this'),
- 'println',
- new ArgumentListExpression(
- new ConstantExpression('In method!')
- )
- ))], new VariableScope())
- )
- AstAssert.assertSyntaxTree([expectedMethod], [method])
-
- def ctor = classNode?.constructors?.get(0)
- def expectedCtor = new ConstructorNode(
- Opcodes.ACC_PUBLIC,
- [] as Parameter[],
- [] as ClassNode[],
- new BlockStatement(
- [new ExpressionStatement(
- new MethodCallExpression(
- new VariableExpression('this'),
- 'println',
- new ArgumentListExpression(
- new ConstantExpression('In constructor!')
- )
- ))], new VariableScope())
- )
- AstAssert.assertSyntaxTree([expectedCtor], [ctor])
- }
-}
+/*
+ * 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.ast.builder
+
+import org.codehaus.groovy.ast.ASTNode
+import org.codehaus.groovy.ast.ClassHelper
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.ConstructorNode
+import org.codehaus.groovy.ast.FieldNode
+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.ConstantExpression
+import org.codehaus.groovy.ast.expr.DeclarationExpression
+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.BreakStatement
+import org.codehaus.groovy.ast.stmt.CaseStatement
+import org.codehaus.groovy.ast.stmt.EmptyStatement
+import org.codehaus.groovy.ast.stmt.ExpressionStatement
+import org.codehaus.groovy.ast.stmt.IfStatement
+import org.codehaus.groovy.ast.stmt.ReturnStatement
+import org.codehaus.groovy.ast.stmt.SwitchStatement
+import org.codehaus.groovy.control.CompilePhase
+import org.codehaus.groovy.syntax.Token
+import org.codehaus.groovy.syntax.Types
+import org.objectweb.asm.Opcodes
+
+/**
+ * Unit test for the AstBuilder class. Shows the usage of how to create AST from string input.
+ */
+class AstBuilderFromStringTest extends GroovyTestCase {
+
+ private AstBuilder factory
+
+ protected void setUp() {
+ super.setUp()
+ factory = new AstBuilder()
+ }
+
+
+ /**
+ * This shows how to compile a simple script that returns a constant,
+ * discarding the generated Script subclass.
+ */
+ void testSimpleConstant() {
+ List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, " \"Some String\" ")
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new ConstantExpression("Some String")
+ )],
+ new VariableScope()
+ )
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ /**
+ * This shows how to compile a script that includes declarations,
+ * discarding the generated Script subclass.
+ */
+ void testAssignment() {
+ List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, " def x = 2; def y = 4 ")
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new DeclarationExpression(
+ new VariableExpression("x"),
+ Token.newSymbol(Types.EQUAL, 0, 0),
+ new ConstantExpression(2)
+ )
+ ),
+ new ExpressionStatement(
+ new DeclarationExpression(
+ new VariableExpression("y"),
+ Token.newSymbol(Types.EQUAL, 0, 0),
+ new ConstantExpression(4)
+ )
+ )],
+ new VariableScope()
+ )
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ /**
+ * This shows how to compile a script that includes method calls,
+ * discarding the generated Script subclass.
+ */
+ void testMethodCall() {
+ List<ASTNode> result = factory.buildFromString(CompilePhase.CONVERSION, """ println "Hello World" """)
+
+ def expected = new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("Hello World")]
+ )
+ )
+ )],
+ new VariableScope()
+ )
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ /**
+ * This shows how to get the Script subclass off of the compiled result, compiling
+ * all the way to CLASS_GENERATION.
+ */
+ void testWithScriptClassAndClassGeneration() {
+ List<ASTNode> result = factory.buildFromString(CompilePhase.CLASS_GENERATION, false, " \"Some String\" ")
+
+ def expectedScriptBody = new BlockStatement(
+ [new ReturnStatement(
+ new ConstantExpression("Some String")
+ )],
+ new VariableScope()
+ )
+
+ def expectedClassNode = new ClassNode("synthesized", 1024, ClassHelper.make(Script))
+
+ AstAssert.assertSyntaxTree([expectedScriptBody, expectedClassNode], result)
+ }
+
+ /**
+ * Proves default value is CLASS_GENERATION and statementsOnly = true.
+ */
+ void testDefaultValues() {
+ List<ASTNode> result = factory.buildFromString(" \"Some String\" ")
+
+ def expectedScriptBody = new BlockStatement(
+ [new ReturnStatement(
+ new ConstantExpression("Some String")
+ )],
+ new VariableScope()
+ )
+
+ AstAssert.assertSyntaxTree([expectedScriptBody], result)
+ }
+
+ /**
+ * This tests the contract of the build method, trying to pass null
+ * arguments when those arguments are required.
+ */
+ void testContract() {
+
+ // source is required
+ shouldFail(IllegalArgumentException) {
+ factory.buildFromString((String) null)
+ }
+
+ // source must not be empty
+ shouldFail(IllegalArgumentException) {
+ factory.buildFromString(" ")
+ }
+ }
+
+
+ void testIfStatement() {
+
+ def result = factory.buildFromString(
+ CompilePhase.SEMANTIC_ANALYSIS,
+ """ if (foo == bar) println "Hello" else println "World" """)
+
+ def expected = new BlockStatement(
+ [new IfStatement(
+ new BooleanExpression(
+ new BinaryExpression(
+ new VariableExpression("foo"),
+ new Token(Types.COMPARE_EQUAL, "==", -1, -1),
+ new VariableExpression("bar")
+ )
+ ),
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("Hello")]
+ )
+ )
+ ),
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("World")]
+ )
+ )
+ )
+ )], new VariableScope())
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+
+ void testSwitchAndCaseAndBreakStatements() {
+
+ def result = new AstBuilder().buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """
+ switch (foo) {
+ case 0:
+ break
+ case 1:
+ case 2:
+ println "<3"
+ break
+ default:
+ println ">2"
+ }
+ """)
+
+ def expected = new BlockStatement(
+ [new SwitchStatement(
+ new VariableExpression("foo"),
+ [
+ new CaseStatement(
+ new ConstantExpression(0),
+ new BlockStatement(
+ [new BreakStatement()], new VariableScope())
+ ),
+ new CaseStatement(
+ new ConstantExpression(1),
+ EmptyStatement.INSTANCE
+ ),
+ new CaseStatement(
+ new ConstantExpression(2),
+ new BlockStatement(
+ [
+ new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression("<3")]
+ )
+ )
+ ),
+ new BreakStatement()
+ ], new VariableScope()
+ )
+ )
+ ],
+ new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression("this"),
+ new ConstantExpression("println"),
+ new ArgumentListExpression(
+ [new ConstantExpression(">2")]
+ )
+ )
+ )],
+ new VariableScope()
+ )
+ )], new VariableScope())
+
+ AstAssert.assertSyntaxTree([expected], result)
+ }
+
+ void testCreatingClassAndMethods() {
+ def result = factory.buildFromString(CompilePhase.SEMANTIC_ANALYSIS, """
+ class MyClass {
+ private String myField = "a field value"
+ MyClass() {
+ println "In constructor!"
+ }
+
+ def myMethod() {
+ println "In method!"
+ }
+ }
+ """)
+
+ def expected = [
+ new BlockStatement(),
+ new ClassNode("MyClass", Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE)
+ ]
+ AstAssert.assertSyntaxTree(expected, result)
+
+ def classNode = result[1]
+ def field = classNode?.fields?.find { FieldNode f -> f.name == 'myField' }
+ def expectedField = new FieldNode(
+ 'myField',
+ Opcodes.ACC_PRIVATE,
+ ClassHelper.STRING_TYPE,
+ classNode,
+ new ConstantExpression('a field value')
+ )
+ AstAssert.assertSyntaxTree([expectedField], [field])
+
+ def method = classNode?.methods?.find { MethodNode m -> m.name == 'myMethod' }
+ def expectedMethod = new MethodNode(
+ 'myMethod',
+ Opcodes.ACC_PUBLIC,
+ ClassHelper.OBJECT_TYPE,
+ [] as Parameter[],
+ [] as ClassNode[],
+ new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression('this'),
+ 'println',
+ new ArgumentListExpression(
+ new ConstantExpression('In method!')
+ )
+ ))], new VariableScope())
+ )
+ AstAssert.assertSyntaxTree([expectedMethod], [method])
+
+ def ctor = classNode?.constructors?.get(0)
+ def expectedCtor = new ConstructorNode(
+ Opcodes.ACC_PUBLIC,
+ [] as Parameter[],
+ [] as ClassNode[],
+ new BlockStatement(
+ [new ExpressionStatement(
+ new MethodCallExpression(
+ new VariableExpression('this'),
+ 'println',
+ new ArgumentListExpression(
+ new ConstantExpression('In constructor!')
+ )
+ ))], new VariableScope())
+ )
+ AstAssert.assertSyntaxTree([expectedCtor], [ctor])
+ }
+}
diff --git a/src/test/org/codehaus/groovy/ast/builder/WithAstBuilder.groovy b/src/test/org/codehaus/groovy/ast/builder/WithAstBuilder.groovy
index 415ff1f..8f183bb 100644
--- a/src/test/org/codehaus/groovy/ast/builder/WithAstBuilder.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/WithAstBuilder.groovy
@@ -1,40 +1,37 @@
-/*
- * 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.ast.builder;
-
-import org.codehaus.groovy.transform.GroovyASTTransformationClass;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Retention
-import java.lang.annotation.ElementType;
-
-/**
- * This transformation annotation allows you to run AstBuilder.fromCode transformations
- * as local transformations in situations where the Global Transformation cannot be used.
- * There is no reason to ever use this outside the Groovy test sources tree.
- *
- * @author Hamlet D'Arcy
- */
-
-@Retention(RetentionPolicy.SOURCE)
-@Target([ElementType.TYPE])
-@GroovyASTTransformationClass(["org.codehaus.groovy.ast.builder.AstBuilderTransformation"])
-public @interface WithAstBuilder {
-}
+/*
+ * 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.ast.builder
+
+import org.codehaus.groovy.transform.GroovyASTTransformationClass
+
+import java.lang.annotation.ElementType
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import java.lang.annotation.Target
+
+/**
+ * This transformation annotation allows you to run AstBuilder.fromCode transformations
+ * as local transformations in situations where the Global Transformation cannot be used.
+ * There is no reason to ever use this outside the Groovy test sources tree.
+ */
+@Retention(RetentionPolicy.SOURCE)
+@Target([ElementType.TYPE])
+@GroovyASTTransformationClass(["org.codehaus.groovy.ast.builder.AstBuilderTransformation"])
+@interface WithAstBuilder {
+}
diff --git a/src/test/org/codehaus/groovy/ast/builder/testpackage/AstBuilderFromCodePackageImportTest.groovy b/src/test/org/codehaus/groovy/ast/builder/testpackage/AstBuilderFromCodePackageImportTest.groovy
index dec250c..5e42116 100644
--- a/src/test/org/codehaus/groovy/ast/builder/testpackage/AstBuilderFromCodePackageImportTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/testpackage/AstBuilderFromCodePackageImportTest.groovy
@@ -1,42 +1,42 @@
-/*
- * 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.ast.builder.testpackage
-
-import org.codehaus.groovy.ast.builder.*
-
-/**
- * Test package imports in AstBuilder.
- *
- * It is important that this class contains an import of builder.* and not
- * the AstBuilder class individually.
- *
- * @author Hamlet D'Arcy
- */
-@WithAstBuilder
-public class AstBuilderFromCodePackageImportTest extends GroovyTestCase {
- public void testPackageImport() {
- def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
-
- def result = new AstBuilder().buildFromCode {
- println "Hello World"
- }
- AstAssert.assertSyntaxTree(expected, result)
- }
-
-}
+/*
+ * 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.ast.builder.testpackage
+
+import org.codehaus.groovy.ast.builder.AstAssert
+import org.codehaus.groovy.ast.builder.AstBuilder
+import org.codehaus.groovy.ast.builder.WithAstBuilder
+
+/**
+ * Test package imports in AstBuilder.
+ *
+ * It is important that this class contains an import of builder.* and not
+ * the AstBuilder class individually.
+ */
+@WithAstBuilder
+class AstBuilderFromCodePackageImportTest extends GroovyTestCase {
+ void testPackageImport() {
+ def expected = new AstBuilder().buildFromString(""" println "Hello World" """)
+
+ def result = new AstBuilder().buildFromCode {
+ println "Hello World"
+ }
+ AstAssert.assertSyntaxTree(expected, result)
+ }
+
+}