You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/05/27 21:07:16 UTC
[5/6] groovy git commit: refactor: type safety and formatting (closes
#544)
refactor: type safety and formatting (closes #544)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/77441591
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/77441591
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/77441591
Branch: refs/heads/master
Commit: 774415910b4f34eb09e0fa2154be91df3902974d
Parents: e2640dd
Author: John Wagenleitner <jw...@apache.org>
Authored: Sat May 20 09:00:23 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 27 13:39:00 2017 -0700
----------------------------------------------------------------------
.../transform/AnnotationCollectorTransform.java | 53 ++++++++++++--------
.../codehaus/groovy/transform/trait/Traits.java | 12 ++---
2 files changed, 39 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/77441591/src/main/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/AnnotationCollectorTransform.java b/src/main/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
index cf153f7..9e2059c 100644
--- a/src/main/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
+++ b/src/main/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
@@ -97,8 +97,9 @@ public class AnnotationCollectorTransform {
break;
}
}
- if (collector==null) return;
-
+ if (collector == null) {
+ return;
+ }
// force final class, remove interface, annotation, enum and abstract modifiers
cn.setModifiers((ACC_FINAL+cn.getModifiers()) & ~(ACC_ENUM|ACC_INTERFACE|ACC_ANNOTATION|ACC_ABSTRACT));
// force Object super class
@@ -124,7 +125,9 @@ public class AnnotationCollectorTransform {
// remove annotations
for (ListIterator<AnnotationNode> it = cn.getAnnotations().listIterator(); it.hasNext();) {
AnnotationNode an = it.next();
- if (an==collector) continue;
+ if (an == collector) {
+ continue;
+ }
it.remove();
}
}
@@ -157,8 +160,7 @@ public class AnnotationCollectorTransform {
List<Expression> l = new ArrayList<Expression>(2);
l.add(new ClassExpression(an.getClassNode()));
l.add(map);
- ArrayExpression ae = new ArrayExpression(ClassHelper.OBJECT_TYPE, l);
- return ae;
+ return new ArrayExpression(ClassHelper.OBJECT_TYPE, l);
}
}
@@ -177,14 +179,18 @@ public class AnnotationCollectorTransform {
private List<AnnotationNode> getTargetListFromValue(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, SourceUnit source) {
Expression memberValue = collector.getMember("value");
- if (memberValue == null) return Collections.EMPTY_LIST;
+ if (memberValue == null) {
+ return Collections.emptyList();
+ }
if (!(memberValue instanceof ListExpression)) {
addError("Annotation collector expected a list of classes, but got a "+memberValue.getClass(), collector, source);
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
ListExpression memberListExp = (ListExpression) memberValue;
List<Expression> memberList = memberListExp.getExpressions();
- if (memberList.isEmpty()) return Collections.EMPTY_LIST;
+ if (memberList.isEmpty()) {
+ return Collections.emptyList();
+ }
List<AnnotationNode> ret = new ArrayList<AnnotationNode>();
for (Expression e : memberList) {
AnnotationNode toAdd = new AnnotationNode(e.getType());
@@ -214,8 +220,9 @@ public class AnnotationCollectorTransform {
private static List<AnnotationNode> getTargetListFromAnnotations(ClassNode alias) {
List<AnnotationNode> annotations = alias.getAnnotations();
- if (annotations.size() < 2) return Collections.EMPTY_LIST;
-
+ if (annotations.size() < 2) {
+ return Collections.emptyList();
+ }
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(annotations.size());
for (AnnotationNode an : annotations) {
ClassNode type = an.getClassNode();
@@ -251,29 +258,33 @@ public class AnnotationCollectorTransform {
}
private static List<AnnotationNode> makeListOfAnnotations(Object[][] data) {
- if (data.length==0) return Collections.EMPTY_LIST;
-
+ if (data.length == 0) {
+ return Collections.emptyList();
+ }
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(data.length);
for (Object[] inner : data) {
- Class anno = (Class) inner[0];
+ Class<?> anno = (Class) inner[0];
AnnotationNode toAdd = new AnnotationNode(ClassHelper.make(anno));
ret.add(toAdd);
@SuppressWarnings("unchecked")
Map<String,Object> member = (Map<String, Object>) inner[1];
- if (member.isEmpty()) continue;
+ if (member.isEmpty()) {
+ continue;
+ }
Map<String, Expression> generated = new HashMap<String, Expression>(member.size());
- for (String name : member.keySet()) {
- Object val = member.get(name);
- generated.put(name, makeExpression(val));
+ for (Map.Entry<String, Object> entry : member.entrySet()) {
+ generated.put(entry.getKey(), makeExpression(entry.getValue()));
}
copyMembers(generated, toAdd);
}
return ret;
}
-
+
private static Expression makeExpression(Object o) {
- if (o instanceof Class) return new ClassExpression(ClassHelper.make((Class) o));
+ if (o instanceof Class) {
+ return new ClassExpression(ClassHelper.make((Class) o));
+ }
//TODO: value as Annotation here!
if (o instanceof Object[][]) {
List<AnnotationNode> annotations = makeListOfAnnotations((Object[][])o);
@@ -305,7 +316,9 @@ public class AnnotationCollectorTransform {
List<AnnotationNode> stored = getStoredTargetList(aliasAnnotationUsage, source);
List<AnnotationNode> targetList = getTargetListFromValue(collector, aliasAnnotationUsage, source);
int size = targetList.size()+stored.size();
- if (size==0) return Collections.EMPTY_LIST;
+ if (size == 0) {
+ return Collections.emptyList();
+ }
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(size);
ret.addAll(stored);
ret.addAll(targetList);
http://git-wip-us.apache.org/repos/asf/groovy/blob/77441591/src/main/org/codehaus/groovy/transform/trait/Traits.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/trait/Traits.java b/src/main/org/codehaus/groovy/transform/trait/Traits.java
index 508af26..2143ff1 100644
--- a/src/main/org/codehaus/groovy/transform/trait/Traits.java
+++ b/src/main/org/codehaus/groovy/transform/trait/Traits.java
@@ -55,7 +55,7 @@ import java.util.List;
public abstract class Traits {
public static final ClassNode IMPLEMENTED_CLASSNODE = ClassHelper.make(Implemented.class);
public static final ClassNode TRAITBRIDGE_CLASSNODE = ClassHelper.make(TraitBridge.class);
- public static final Class TRAIT_CLASS = Trait.class;
+ public static final Class<Trait> TRAIT_CLASS = Trait.class;
public static final ClassNode TRAIT_CLASSNODE = ClassHelper.make(TRAIT_CLASS);
public static final ClassNode GENERATED_PROXY_CLASSNODE = ClassHelper.make(GeneratedGroovyProxy.class);
public static final ClassNode SELFTYPE_CLASSNODE = ClassHelper.make(SelfType.class);
@@ -163,7 +163,7 @@ public abstract class Traits {
* @param clazz a class to test
* @return true if the classnode represents a trait
*/
- public static boolean isTrait(final Class clazz) {
+ public static boolean isTrait(final Class<?> clazz) {
return clazz!=null && clazz.getAnnotation(Trait.class)!=null;
}
@@ -217,7 +217,7 @@ public abstract class Traits {
if (annotation==null) {
return null;
}
- Class aClass = annotation.traitClass();
+ Class<?> aClass = annotation.traitClass();
String desc = annotation.desc();
for (Method method : aClass.getDeclaredMethods()) {
String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameterTypes());
@@ -355,7 +355,7 @@ public abstract class Traits {
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
- public static @interface Implemented {}
+ public @interface Implemented {}
/**
* Internal annotation used to indicate that a method is a bridge method to a trait
@@ -363,11 +363,11 @@ public abstract class Traits {
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
- public static @interface TraitBridge {
+ public @interface TraitBridge {
/**
* @return the trait class
*/
- Class traitClass();
+ Class<?> traitClass();
/**
* @return The method descriptor of the method from the trait