Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Nov 8, 2017
1 parent 128163a commit 6461df1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.codehaus.groovy.transform.ASTTransformation
import org.codehaus.groovy.transform.FieldASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.particleframework.ast.groovy.InjectTransform
import org.particleframework.ast.groovy.utils.AstAnnotationUtils
import org.particleframework.ast.groovy.utils.AstMessageUtils
import org.particleframework.ast.groovy.utils.AstUtils
import org.particleframework.context.ApplicationContext
Expand Down Expand Up @@ -220,6 +221,7 @@ class FunctionTransform implements ASTTransformation{

}
}
AstAnnotationUtils.invalidateCache()
new InjectTransform().visit(nodes, source)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class InjectTransform implements ASTTransformation, CompilationUnitAware {
}
superClasses = superClasses.reverse()
for (classNode in superClasses) {
if(classNode.name != ClassHelper.OBJECT_TYPE.name) {
if(classNode.name != ClassHelper.OBJECT_TYPE.name && classNode.name != GroovyObjectSupport.name && classNode.name != Script.name) {
classNode.visitContents(this)
}
}
Expand Down Expand Up @@ -499,8 +499,8 @@ class InjectTransform implements ASTTransformation, CompilationUnitAware {
}
else if(!isConstructor) {
boolean isPublic = methodNode.isPublic() && !methodNode.isStatic() && !methodNode.isAbstract()
boolean isExecutable = ((isExecutableType && isPublic) || methodAnnotationMetadata.hasStereotype(Executable)) && !methodAnnotationMetadata.hasAnnotation(Internal) && !methodNode.isSynthetic()
if(isExecutable && !methodNode.isPrivate()) {
boolean isExecutable = ((isExecutableType && isPublic) || methodAnnotationMetadata.hasStereotype(Executable)) && !methodAnnotationMetadata.hasAnnotation(Internal) && !methodNode.isSynthetic() && !methodNode.isStatic() && !methodNode.isAbstract() && !methodNode.isPrivate()
if(isExecutable) {
if(declaringClass != ClassHelper.OBJECT_TYPE) {

defineBeanDefinition(concreteClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.particleframework.ast.groovy.utils

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import groovy.transform.CompileStatic
import groovy.transform.Memoized
import org.codehaus.groovy.ast.AnnotatedNode
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.expr.Expression
import org.particleframework.ast.groovy.annotation.GroovyAnnotationMetadataBuilder
import org.particleframework.core.annotation.AnnotationMetadata
import org.particleframework.core.annotation.Internal

import java.lang.annotation.Annotation
import java.lang.annotation.Documented
Expand All @@ -24,14 +26,25 @@ import java.lang.annotation.Target
@CompileStatic
class AstAnnotationUtils {

private static final Cache<AnnotatedNode, AnnotationMetadata> annotationMetadataCache = Caffeine.newBuilder().maximumSize(100).build();

/**
* Get the {@link AnnotationMetadata} for the given annotated node
* @param annotatedNode The node
* @return The metadata
*/
@Memoized(maxCacheSize = 100)
static AnnotationMetadata getAnnotationMetadata(AnnotatedNode annotatedNode) {
return new GroovyAnnotationMetadataBuilder().build(annotatedNode)
return annotationMetadataCache.get(annotatedNode, { AnnotatedNode annotatedNode1 ->
new GroovyAnnotationMetadataBuilder().build(annotatedNode1)
})
}

/**
* Invalidates any cached metadata
*/
@Internal
static void invalidateCache() {
annotationMetadataCache.invalidateAll()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ interface ITest {

protected AnnotationMetadata writeAndLoad(String className, AnnotationMetadata toWrite) {
def stream = new ByteArrayOutputStream()

new AnnotationMetadataWriter(className, toWrite)
.writeTo(stream)

className = className + AnnotationMetadataWriter.CLASS_NAME_SUFFIX
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ public class AnnotationMetadataWriter extends AbstractClassFileWriter {
Map.class
)
);
static final String CLASS_NAME_SUFFIX = "$$AnnotationMetadata";

private final String className;
private final DefaultAnnotationMetadata annotationMetadata;

/**
* Constructs a new writer for the given class name and metadata
*
* @param className The class name for which the metadata relates
* @param annotationMetadata The annotation metadata
*/
public AnnotationMetadataWriter(String className, AnnotationMetadata annotationMetadata) {
this.className = className;
this.className = className + CLASS_NAME_SUFFIX;
if (annotationMetadata instanceof DefaultAnnotationMetadata) {
this.annotationMetadata = (DefaultAnnotationMetadata) annotationMetadata;
} else {
Expand Down

0 comments on commit 6461df1

Please sign in to comment.