Skip to content

Commit

Permalink
remove dependency on commons-lang from GrailsASTUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jan 30, 2014
1 parent c241ce1 commit 6bffcd7
Showing 1 changed file with 15 additions and 12 deletions.
Expand Up @@ -42,10 +42,6 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.map.DefaultedMap;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
Expand Down Expand Up @@ -88,11 +84,13 @@
import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
import org.codehaus.groovy.grails.commons.GrailsClassUtils;
import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.runtime.MetaClassHelper;
import org.codehaus.groovy.syntax.SyntaxException;
import org.codehaus.groovy.syntax.Token;
import org.codehaus.groovy.syntax.Types;
import org.codehaus.groovy.transform.sc.StaticCompileTransformation;
import org.springframework.util.StringUtils;

/**
* Helper methods for working with Groovy AST trees.
Expand Down Expand Up @@ -166,7 +164,7 @@ public static void error(final SourceUnit sourceUnit, final ASTNode astNode, fin
* @return true if the property exists in the ClassNode
*/
public static boolean hasProperty(ClassNode classNode, String propertyName) {
if (classNode == null || StringUtils.isBlank(propertyName)) {
if (classNode == null || !StringUtils.hasText(propertyName)) {
return false;
}

Expand Down Expand Up @@ -622,8 +620,13 @@ public static ClassNode nonGeneric(ClassNode type) {
}

@SuppressWarnings("unchecked")
public static ClassNode nonGeneric(ClassNode type, ClassNode wildcardReplacement) {
return replaceGenericsPlaceholders(type, DefaultedMap.decorate(emptyGenericsPlaceHoldersMap, wildcardReplacement));
public static ClassNode nonGeneric(ClassNode type, final ClassNode wildcardReplacement) {
return replaceGenericsPlaceholders(type, DefaultGroovyMethods.withDefault(emptyGenericsPlaceHoldersMap, new Closure(this) {
@Override
public Object call(Object... args) {
return wildcardReplacement;
}
}));
}

public static ClassNode replaceGenericsPlaceholders(ClassNode type, Map<String, ClassNode> genericsPlaceholders) {
Expand Down Expand Up @@ -825,12 +828,12 @@ public static boolean hasAnnotation(final ClassNode classNode, final Class<? ext
* @return true if classNode is marked with any of the annotations in annotationsToLookFor
*/
public static boolean hasAnyAnnotations(final ClassNode classNode, final Class<? extends Annotation>... annotationsToLookFor) {
return CollectionUtils.exists(Arrays.asList(annotationsToLookFor), new Predicate() {
@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean evaluate(Object object) {
return hasAnnotation(classNode, (Class)object);
for (Class<? extends Annotation> annotationClass : annotationsToLookFor) {
if(hasAnnotation(classNode, annotationClass)) {
return true;
}
});
}
return false;
}

public static void addMethodIfNotPresent(ClassNode controllerClassNode, MethodNode methodNode) {
Expand Down

0 comments on commit 6bffcd7

Please sign in to comment.