Skip to content
Browse files

release of GROOVY 1.6 RC2

git-svn-id: http://svn.codehaus.org/groovy/tags/GROOVY_1_6_RC_2@15148 a5544e8c-8a19-0410-ba12-f9af4593a198
  • Loading branch information...
2 parents 11b307b + fec2f6f commit d1a46bbe60483c4f96a54a7271e20ead7c9cc781 @blackdrag blackdrag committed Jan 22, 2009
View
13 src/main/org/codehaus/groovy/control/CompilationUnit.java
@@ -119,9 +119,16 @@ public CompilationUnit(CompilerConfiguration configuration, CodeSource security,
/**
* Initializes the CompilationUnit with a CodeSource for controlling
* security stuff, a class loader for loading classes, and a class
- * loader for loading AST transformations. Note that the latter must be
- * able to load compiler classes, and must delegate such requests to the
- * compiler's defining class loader.
+ * loader for loading AST transformations.
+ * <b>Note</b> The transform loader must be
+ * able to load compiler classes. That means CompilationUnit.class.classLoader
+ * must be at last a parent to transformLoader. The other loader has no such constraint.
+ *
+ * @param transformLoader - the loader for transforms
+ * @param loader - loader used to resolve classes against during compilation
+ * @param security - security setting for the compilation
+ * @param configuration - compilation configuration
+ *
*/
public CompilationUnit(CompilerConfiguration configuration, CodeSource security,
GroovyClassLoader loader, GroovyClassLoader transformLoader)
View
43 src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
@@ -16,6 +16,7 @@
package org.codehaus.groovy.transform;
+import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassCodeVisitorSupport;
@@ -25,6 +26,8 @@
import groovy.lang.GroovyClassLoader;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.util.Collection;
/**
@@ -38,6 +41,16 @@
* @author Danno Ferrin (shemnon)
*/
public class ASTTransformationCollectorCodeVisitor extends ClassCodeVisitorSupport {
+
+ private final static Method valueMethod;
+ static {
+ try {
+ valueMethod = GroovyASTTransformationClass.class.getMethod("value");
+ } catch (Exception e) {
+ throw new GroovyBugError("unable to get value method of GroovyASTTransformationClass",e);
+ }
+ }
+
private SourceUnit source;
private ClassNode classNode;
private GroovyClassLoader transformLoader;
@@ -67,12 +80,12 @@ public void visitClass(ClassNode klassNode) {
public void visitAnnotations(AnnotatedNode node) {
super.visitAnnotations(node);
for (AnnotationNode annotation : (Collection<AnnotationNode>) node.getAnnotations()) {
- GroovyASTTransformationClass transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode());
+ Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode());
if (transformClassAnnotation == null) {
// skip if there is no such annotation
continue;
}
- for (String transformClass : transformClassAnnotation.value()) {
+ for (String transformClass : getTransformClasses(transformClassAnnotation)) {
try {
Class klass = transformLoader.loadClass(transformClass, false, true, false);
if (ASTTransformation.class.isAssignableFrom(klass)) {
@@ -85,7 +98,7 @@ public void visitAnnotations(AnnotatedNode node) {
source));
}
} catch (ClassNotFoundException e) {
- source.getErrorCollector().addError(
+ source.getErrorCollector().addErrorAndContinue(
new SimpleMessage(
"Could not find class for Transformation Processor " + transformClass
+ " declared by " + annotation.getClassNode().getName(),
@@ -95,9 +108,29 @@ public void visitAnnotations(AnnotatedNode node) {
}
}
- private static GroovyASTTransformationClass getTransformClassAnnotation(ClassNode annotatedType) {
+ private static Annotation getTransformClassAnnotation(ClassNode annotatedType) {
if (!annotatedType.isResolved()) return null;
- return (GroovyASTTransformationClass) annotatedType.getTypeClass().getAnnotation(GroovyASTTransformationClass.class);
+
+ for (Annotation ann : annotatedType.getTypeClass().getAnnotations()) {
+ // because compiler clients are free to choose any GroovyClassLoader for
+ // resolving ClassNodeS such as annotatedType, we have to compare by name,
+ // and cannot cast the return value to GroovyASTTransformationClass
+ if (ann.annotationType().getName().equals(GroovyASTTransformationClass.class.getName())){
+ return ann;
+ }
+ }
+
+ return null;
}
+ private String[] getTransformClasses(Annotation transformClassAnnotation) {
+ try {
+ return (String[]) valueMethod.invoke(transformClassAnnotation);
+ } catch (Exception e) {
+ source.addException(e);
+ return new String[0];
+ }
+ }
+
+
}

0 comments on commit d1a46bb

Please sign in to comment.
Something went wrong with that request. Please try again.