This is an automated email from the ASF dual-hosted git repository.
emilles 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 5fd3168 minor refactor
5fd3168 is described below
commit 5fd3168e449672fa82623ad02fae7854889c0c45
Author: Eric Milles <[email protected]>
AuthorDate: Sat Oct 5 00:05:03 2019 -0500
minor refactor
---
.../apache/groovy/ast/tools/ClassNodeUtils.java | 3 +-
.../java/org/codehaus/groovy/ast/MethodNode.java | 92 ++++++++++++----------
2 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
b/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
index f4617dd..5eea16a 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
@@ -45,6 +45,7 @@ import java.util.Set;
import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.hasAnnotation;
import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.markAsGenerated;
import static org.codehaus.groovy.ast.ClassHelper.boolean_TYPE;
+import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
/**
* Utility class for working with ClassNodes
@@ -162,7 +163,7 @@ public class ClassNodeUtils {
for (ClassNode iface : cNode.getInterfaces()) {
Map<String, MethodNode> declaredMethods =
iface.getDeclaredMethodsMap();
for (Map.Entry<String, MethodNode> entry :
declaredMethods.entrySet()) {
- if (entry.getValue().getDeclaringClass().isInterface()) {
+ if (entry.getValue().getDeclaringClass().isInterface() &&
(entry.getValue().getModifiers() & ACC_SYNTHETIC) == 0) {
methodsMap.putIfAbsent(entry.getKey(), entry.getValue());
}
}
diff --git a/src/main/java/org/codehaus/groovy/ast/MethodNode.java
b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
index e260d83..4b8bc36 100644
--- a/src/main/java/org/codehaus/groovy/ast/MethodNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
@@ -35,19 +35,19 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
private boolean syntheticPublic;
private ClassNode returnType;
private Parameter[] parameters;
- private boolean hasDefaultValue = false;
+ private boolean hasDefaultValue;
private Statement code;
private boolean dynamicReturnType;
private VariableScope variableScope;
private final ClassNode[] exceptions;
private final boolean staticConstructor;
+ private boolean hasDefault; // annotation method value
// type spec for generics
- private GenericsType[] genericsTypes = null;
- private boolean hasDefault;
+ private GenericsType[] genericsTypes;
// cached data
- String typeDescriptor;
+ private String typeDescriptor;
public MethodNode(String name, int modifiers, ClassNode returnType,
Parameter[] parameters, ClassNode[] exceptions, Statement code) {
this.name = name;
@@ -64,8 +64,6 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
* The type descriptor for a method node is a string containing the name
of the method, its return type,
* and its parameter types in a canonical form. For simplicity, we use the
format of a Java declaration
* without parameter names or generics.
- *
- * @return the type descriptor
*/
public String getTypeDescriptor() {
if (typeDescriptor == null) {
@@ -78,10 +76,6 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
typeDescriptor = null;
}
- public boolean isVoidMethod() {
- return returnType == ClassHelper.VOID_TYPE;
- }
-
public Statement getCode() {
return code;
}
@@ -123,10 +117,31 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
setVariableScope(scope);
}
+ /**
+ * @return {@code true} if any parameter has a default value
+ */
+ public boolean hasDefaultValue() {
+ return hasDefaultValue;
+ }
+
public ClassNode getReturnType() {
return returnType;
}
+ public void setReturnType(ClassNode returnType) {
+ invalidateCachedData();
+ this.dynamicReturnType |= ClassHelper.DYNAMIC_TYPE == returnType;
+ this.returnType = returnType != null ? returnType :
ClassHelper.OBJECT_TYPE;
+ }
+
+ public boolean isDynamicReturnType() {
+ return dynamicReturnType;
+ }
+
+ public boolean isVoidMethod() {
+ return ClassHelper.VOID_TYPE.equals(getReturnType());
+ }
+
public VariableScope getVariableScope() {
return variableScope;
}
@@ -136,14 +151,18 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
variableScope.setInStaticContext(isStatic());
}
- public boolean isDynamicReturnType() {
- return dynamicReturnType;
- }
-
public boolean isAbstract() {
return (modifiers & ACC_ABSTRACT) != 0;
}
+ public boolean isDefault() {
+ return (modifiers & (ACC_ABSTRACT | ACC_PUBLIC | ACC_STATIC)) ==
ACC_PUBLIC && getDeclaringClass() != null && getDeclaringClass().isInterface();
+ }
+
+ public boolean isFinal() {
+ return (modifiers & ACC_FINAL) != 0;
+ }
+
public boolean isStatic() {
return (modifiers & ACC_STATIC) != 0;
}
@@ -156,24 +175,16 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
return (modifiers & ACC_PRIVATE) != 0;
}
- public boolean isFinal() {
- return (modifiers & ACC_FINAL) != 0;
- }
-
public boolean isProtected() {
return (modifiers & ACC_PROTECTED) != 0;
}
public boolean isPackageScope() {
- return !(this.isPrivate() || this.isProtected() || this.isPublic());
- }
-
- public boolean hasDefaultValue() {
- return this.hasDefaultValue;
+ return (modifiers & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED)) == 0;
}
/**
- * @return true if this method is the run method from a script
+ * @return {@code true} if this method is the run method from a script
*/
public boolean isScriptBody() {
return getNodeMetaData(SCRIPT_BODY_METHOD_KEY) != null;
@@ -181,21 +192,11 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
/**
* Set the metadata flag for this method to indicate that it is a script
body implementation.
- * @see ModuleNode createStatementsClass().
+ *
+ * @see ModuleNode#createStatementsClass()
*/
public void setIsScriptBody() {
- setNodeMetaData(SCRIPT_BODY_METHOD_KEY, true);
- }
-
- public String toString() {
- return super.toString() + "[" + getDeclaringClass().getName() + "#" +
getTypeDescriptor() + "]";
- }
-
- public void setReturnType(ClassNode returnType) {
- invalidateCachedData();
- dynamicReturnType |= ClassHelper.DYNAMIC_TYPE == returnType;
- this.returnType = returnType;
- if (returnType == null) this.returnType = ClassHelper.OBJECT_TYPE;
+ setNodeMetaData(SCRIPT_BODY_METHOD_KEY, Boolean.TRUE);
}
public ClassNode[] getExceptions() {
@@ -225,8 +226,8 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
this.genericsTypes = genericsTypes;
}
- public void setAnnotationDefault(boolean b) {
- this.hasDefault = b;
+ public void setAnnotationDefault(boolean hasDefault) {
+ this.hasDefault = hasDefault;
}
public boolean hasAnnotationDefault() {
@@ -244,7 +245,7 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
* Groovy's "public methods by default" rule. This property is
* typically only of interest to AST transform writers.
*
- * @return true if this class is public but had no explicit public modifier
+ * @return {@code true} if this class is public but had no explicit public
modifier
*/
public boolean isSyntheticPublic() {
return syntheticPublic;
@@ -256,9 +257,9 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
/**
* Provides a nicely formatted string of the method definition. For
simplicity, generic types on some of the elements
- * are not displayed.
- * @return
- * string form of node with some generic elements suppressed
+ * are not displayed.
+ *
+ * @return string form of node with some generic elements suppressed
*/
@Override
public String getText() {
@@ -267,4 +268,9 @@ public class MethodNode extends AnnotatedNode implements
Opcodes {
String params = AstToTextHelper.getParametersText(parameters);
return AstToTextHelper.getModifiersText(modifiers) + " " + retType + "
" + name + "(" + params + ") " + exceptionTypes + " { ... }";
}
+
+ @Override
+ public String toString() {
+ return super.toString() + "[" + getDeclaringClass().getName() + "#" +
getTypeDescriptor() + "]";
+ }
}