You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/10/19 13:09:26 UTC
[1/2] groovy git commit: GROOVY-8343: Issue implementing Java
interface
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_5_X bdbcd0e89 -> fb1572c8c
GROOVY-8343: Issue implementing Java interface
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4acad3cf
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4acad3cf
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4acad3cf
Branch: refs/heads/GROOVY_2_5_X
Commit: 4acad3cf2c608aafb0c29a04977aa13783c5d513
Parents: bdbcd0e
Author: paulk <pa...@asert.com.au>
Authored: Thu Oct 19 22:01:52 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Oct 19 23:07:10 2017 +1000
----------------------------------------------------------------------
.../groovy/ast/tools/MethodNodeUtils.java | 1 -
.../stubgenerator/Groovy8343StubTest.groovy | 52 ++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/4acad3cf/src/main/org/apache/groovy/ast/tools/MethodNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/ast/tools/MethodNodeUtils.java b/src/main/org/apache/groovy/ast/tools/MethodNodeUtils.java
index b43fc31..94427f0 100644
--- a/src/main/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -34,7 +34,6 @@ public class MethodNodeUtils {
*/
public static String methodDescriptorWithoutReturnType(MethodNode mNode) {
StringBuilder sb = new StringBuilder();
- mNode.getTypeDescriptor();
sb.append(mNode.getName()).append(':');
for (Parameter p : mNode.getParameters()) {
sb.append(ClassNodeUtils.formatTypeName(p.getType())).append(',');
http://git-wip-us.apache.org/repos/asf/groovy/blob/4acad3cf/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8343StubTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8343StubTest.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8343StubTest.groovy
new file mode 100644
index 0000000..a8bf83d
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8343StubTest.groovy
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.tools.stubgenerator
+
+class Groovy8343StubTest extends StringSourcesStubTestCase {
+
+ @Override
+ Map<String, String> provideSources() {
+ [
+ 'groovy/Groovy8343.java': '''
+ package groovy;
+ /**
+ * Precompiled Java class in same package as Groovy8343Test
+ */
+ public interface Groovy8343 {
+ Groovy8343 createRelative(String relativePath);
+ }
+ ''',
+ 'groovy/Groovy8343Test.groovy': '''
+ package groovy
+ @groovy.transform.CompileStatic
+ class Groovy8343Impl implements Groovy8343 {
+ Groovy8343 createRelative(String relativePath) {
+ throw new UnsupportedOperationException("Method createRelative not supported")
+ }
+ }
+ assert new Groovy8343Impl()
+ '''
+ ]
+ }
+
+ @Override
+ void verifyStubs() {
+ // We are just testing that the above compiles ok and using stub test to create the correct conditions
+ }
+}
[2/2] groovy git commit: refactor
Posted by pa...@apache.org.
refactor
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/fb1572c8
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/fb1572c8
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/fb1572c8
Branch: refs/heads/GROOVY_2_5_X
Commit: fb1572c8c39ea7d7045180ba1e17a4ad8bfb1411
Parents: 4acad3c
Author: paulk <pa...@asert.com.au>
Authored: Thu Oct 19 22:12:26 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Oct 19 23:09:04 2017 +1000
----------------------------------------------------------------------
.../apache/groovy/ast/tools/ClassNodeUtils.java | 220 +++++++++++++++++++
src/main/org/codehaus/groovy/ast/ClassNode.java | 13 +-
.../groovy/ast/tools/ClassNodeUtils.java | 181 +++------------
.../classgen/ClassCompletionVerifier.java | 4 +-
.../org/codehaus/groovy/classgen/Verifier.java | 6 +-
.../groovy/control/StaticImportVisitor.java | 12 +-
.../codehaus/groovy/control/StaticVerifier.java | 2 +-
7 files changed, 261 insertions(+), 177 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java b/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
index b8fd27a..77509d0 100644
--- a/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
@@ -18,7 +18,23 @@
*/
package org.apache.groovy.ast.tools;
+import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.MapExpression;
+import org.codehaus.groovy.ast.expr.SpreadExpression;
+import org.codehaus.groovy.ast.expr.TupleExpression;
+
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.codehaus.groovy.ast.ClassHelper.boolean_TYPE;
/**
* Utility class for working with ClassNodes
@@ -49,5 +65,209 @@ public class ClassNodeUtils {
return cNode.getName();
}
+ /**
+ * Add methods from the super class.
+ *
+ * @param cNode The ClassNode
+ * @return A map of methods
+ */
+ public static Map<String, MethodNode> getDeclaredMethodsFromSuper(ClassNode cNode) {
+ ClassNode parent = cNode.getSuperClass();
+ if (parent == null) {
+ return new HashMap<String, MethodNode>();
+ }
+ return parent.getDeclaredMethodsMap();
+ }
+
+ /**
+ * Add in methods from all interfaces. Existing entries in the methods map take precedence.
+ * Methods from interfaces visited early take precedence over later ones.
+ *
+ * @param cNode The ClassNode
+ * @param methodsMap A map of existing methods to alter
+ */
+ public static void addDeclaredMethodsFromInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) {
+ // add in unimplemented abstract methods from the interfaces
+ for (ClassNode iface : cNode.getInterfaces()) {
+ Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap();
+ for (String methSig : ifaceMethodsMap.keySet()) {
+ if (!methodsMap.containsKey(methSig)) {
+ MethodNode methNode = ifaceMethodsMap.get(methSig);
+ methodsMap.put(methSig, methNode);
+ }
+ }
+ }
+ }
+
+ /**
+ * Get methods from all interfaces.
+ * Methods from interfaces visited early will be overwritten by later ones.
+ *
+ * @param cNode The ClassNode
+ * @return A map of methods
+ */
+ public static Map<String, MethodNode> getDeclaredMethodsFromInterfaces(ClassNode cNode) {
+ Map<String, MethodNode> result = new HashMap<String, MethodNode>();
+ ClassNode[] interfaces = cNode.getInterfaces();
+ for (ClassNode iface : interfaces) {
+ result.putAll(iface.getDeclaredMethodsMap());
+ }
+ return result;
+ }
+
+ /**
+ * Adds methods from interfaces and parent interfaces. Existing entries in the methods map take precedence.
+ * Methods from interfaces visited early take precedence over later ones.
+ *
+ * @param cNode The ClassNode
+ * @param methodsMap A map of existing methods to alter
+ */
+ public static void addDeclaredMethodsFromAllInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) {
+ List cnInterfaces = Arrays.asList(cNode.getInterfaces());
+ ClassNode parent = cNode.getSuperClass();
+ while (parent != null && !parent.equals(ClassHelper.OBJECT_TYPE)) {
+ ClassNode[] interfaces = parent.getInterfaces();
+ for (ClassNode iface : interfaces) {
+ if (!cnInterfaces.contains(iface)) {
+ methodsMap.putAll(iface.getDeclaredMethodsMap());
+ }
+ }
+ parent = parent.getSuperClass();
+ }
+ }
+
+ /**
+ * Returns true if the given method has a possibly matching static method with the given name and arguments.
+ * Handles default arguments and optionally spread expressions.
+ *
+ * @param cNode the ClassNode of interest
+ * @param name the name of the method of interest
+ * @param arguments the arguments to match against
+ * @param trySpread whether to try to account for SpreadExpressions within the arguments
+ * @return true if a matching method was found
+ */
+ public static boolean hasPossibleStaticMethod(ClassNode cNode, String name, Expression arguments, boolean trySpread) {
+ int count = 0;
+ boolean foundSpread = false;
+
+ if (arguments instanceof TupleExpression) {
+ TupleExpression tuple = (TupleExpression) arguments;
+ for (Expression arg : tuple.getExpressions()) {
+ if (arg instanceof SpreadExpression) {
+ foundSpread = true;
+ } else {
+ count++;
+ }
+ }
+ } else if (arguments instanceof MapExpression) {
+ count = 1;
+ }
+
+ for (MethodNode method : cNode.getMethods(name)) {
+ if (method.isStatic()) {
+ Parameter[] parameters = method.getParameters();
+ // do fuzzy match for spread case: count will be number of non-spread args
+ if (trySpread && foundSpread && parameters.length >= count) return true;
+
+ if (parameters.length == count) return true;
+
+ // handle varargs case
+ if (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray()) {
+ if (count >= parameters.length - 1) return true;
+ // fuzzy match any spread to a varargs
+ if (trySpread && foundSpread) return true;
+ }
+
+ // handle parameters with default values
+ int nonDefaultParameters = 0;
+ for (Parameter parameter : parameters) {
+ if (!parameter.hasInitialExpression()) {
+ nonDefaultParameters++;
+ }
+ }
+
+ if (count < parameters.length && nonDefaultParameters <= count) {
+ return true;
+ }
+ // TODO handle spread with nonDefaultParams?
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if we have a static accessor
+ */
+ public static boolean hasPossibleStaticProperty(ClassNode cNode, String methodName) {
+ // assume explicit static method call checked first so we can assume a simple check here
+ if (!methodName.startsWith("get") && !methodName.startsWith("is")) {
+ return false;
+ }
+ String propName = getPropNameForAccessor(methodName);
+ PropertyNode pNode = getStaticProperty(cNode, propName);
+ return pNode != null && (methodName.startsWith("get") || boolean_TYPE.equals(pNode.getType()));
+ }
+
+ /**
+ * Returns the property name, e.g. age, given an accessor name, e.g. getAge.
+ * Returns the original if a valid prefix cannot be removed.
+ *
+ * @param accessorName the accessor name of interest, e.g. getAge
+ * @return the property name, e.g. age, or original if not a valid property accessor name
+ */
+ public static String getPropNameForAccessor(String accessorName) {
+ if (!isValidAccessorName(accessorName)) return accessorName;
+ int prefixLength = accessorName.startsWith("is") ? 2 : 3;
+ return String.valueOf(accessorName.charAt(prefixLength)).toLowerCase() + accessorName.substring(prefixLength + 1);
+ }
+
+ /**
+ * Detect whether the given accessor name starts with "get", "set" or "is" followed by at least one character.
+ *
+ * @param accessorName the accessor name of interest, e.g. getAge
+ * @return true if a valid prefix is found
+ */
+ public static boolean isValidAccessorName(String accessorName) {
+ if (accessorName.startsWith("get") || accessorName.startsWith("is") || accessorName.startsWith("set")) {
+ int prefixLength = accessorName.startsWith("is") ? 2 : 3;
+ return accessorName.length() > prefixLength;
+ };
+ return false;
+ }
+
+ public static boolean hasStaticProperty(ClassNode cNode, String propName) {
+ return getStaticProperty(cNode, propName) != null;
+ }
+
+ /**
+ * Detect whether a static property with the given name is within the class
+ * or a super class.
+ *
+ * @param cNode the ClassNode of interest
+ * @param propName the property name
+ * @return the static property if found or else null
+ */
+ public static PropertyNode getStaticProperty(ClassNode cNode, String propName) {
+ ClassNode classNode = cNode;
+ while (classNode != null) {
+ for (PropertyNode pn : classNode.getProperties()) {
+ if (pn.getName().equals(propName) && pn.isStatic()) return pn;
+ }
+ classNode = classNode.getSuperClass();
+ }
+ return null;
+ }
+
+ /**
+ * Detect whether a given ClassNode is a inner class (non-static).
+ *
+ * @param cNode the ClassNode of interest
+ * @return true if the given node is a (non-static) inner class, else false
+ */
+ public static boolean isInnerClass(ClassNode cNode) {
+ return cNode.redirect().getOuterClass() != null
+ && !Modifier.isStatic(cNode.getModifiers());
+ }
+
private ClassNodeUtils() { }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/ast/ClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassNode.java b/src/main/org/codehaus/groovy/ast/ClassNode.java
index 117b502..9e96535 100644
--- a/src/main/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/org/codehaus/groovy/ast/ClassNode.java
@@ -18,12 +18,12 @@
*/
package org.codehaus.groovy.ast;
+import org.apache.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.expr.*;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.ast.tools.ParameterUtils;
import org.codehaus.groovy.control.CompilePhase;
import org.codehaus.groovy.transform.ASTTransformation;
@@ -439,15 +439,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
}
public Map<String, MethodNode> getDeclaredMethodsMap() {
- // Start off with the methods from the superclass.
- ClassNode parent = getSuperClass();
- Map<String, MethodNode> result;
- if (parent != null) {
- result = parent.getDeclaredMethodsMap();
- } else {
- result = new HashMap<String, MethodNode>();
- }
- ClassNodeUtils.addInterfaceMethods(this, result);
+ Map<String, MethodNode> result = ClassNodeUtils.getDeclaredMethodsFromSuper(this);
+ ClassNodeUtils.addDeclaredMethodsFromInterfaces(this, result);
// And add in the methods implemented in this class.
for (MethodNode method : getMethods()) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
index 077e6cb..5c43586 100644
--- a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
@@ -17,193 +17,64 @@
* under the License.
*
*/
-
package org.codehaus.groovy.ast.tools;
-import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
-import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.PropertyNode;
import org.codehaus.groovy.ast.expr.Expression;
-import org.codehaus.groovy.ast.expr.MapExpression;
-import org.codehaus.groovy.ast.expr.SpreadExpression;
-import org.codehaus.groovy.ast.expr.TupleExpression;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import static org.codehaus.groovy.ast.ClassHelper.boolean_TYPE;
-
+@Deprecated
public class ClassNodeUtils {
- public static void addInterfaceMethods(ClassNode cnode, Map<String, MethodNode> methodsMap) {
- // add in unimplemented abstract methods from the interfaces
- for (ClassNode iface : cnode.getInterfaces()) {
- Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap();
- for (String methSig : ifaceMethodsMap.keySet()) {
- if (!methodsMap.containsKey(methSig)) {
- MethodNode methNode = ifaceMethodsMap.get(methSig);
- methodsMap.put(methSig, methNode);
- }
- }
- }
+ @Deprecated
+ public static void addInterfaceMethods(ClassNode cNode, Map<String, MethodNode> methodsMap) {
+ org.apache.groovy.ast.tools.ClassNodeUtils.addDeclaredMethodsFromInterfaces(cNode, methodsMap);
}
- public static Map<String, MethodNode> getDeclaredMethodMapsFromInterfaces(ClassNode classNode) {
- Map<String, MethodNode> result = new HashMap<String, MethodNode>();
- ClassNode[] interfaces = classNode.getInterfaces();
- for (ClassNode iface : interfaces) {
- result.putAll(iface.getDeclaredMethodsMap());
- }
- return result;
+ @Deprecated
+ public static Map<String, MethodNode> getDeclaredMethodMapsFromInterfaces(ClassNode cNode) {
+ return org.apache.groovy.ast.tools.ClassNodeUtils.getDeclaredMethodsFromInterfaces(cNode);
}
- public static void addDeclaredMethodMapsFromSuperInterfaces(ClassNode cn, Map<String, MethodNode> allInterfaceMethods) {
- List cnInterfaces = Arrays.asList(cn.getInterfaces());
- ClassNode sn = cn.getSuperClass();
- while (sn != null && !sn.equals(ClassHelper.OBJECT_TYPE)) {
- ClassNode[] interfaces = sn.getInterfaces();
- for (ClassNode iface : interfaces) {
- if (!cnInterfaces.contains(iface)) {
- allInterfaceMethods.putAll(iface.getDeclaredMethodsMap());
- }
- }
- sn = sn.getSuperClass();
- }
+ @Deprecated
+ public static void addDeclaredMethodMapsFromSuperInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) {
+ org.apache.groovy.ast.tools.ClassNodeUtils.addDeclaredMethodsFromAllInterfaces(cNode, methodsMap);
}
- /**
- * Returns true if the given method has a possibly matching static method with the given name and arguments.
- *
- * @param cNode the ClassNode of interest
- * @param name the name of the method of interest
- * @param arguments the arguments to match against
- * @param trySpread whether to try to account for SpreadExpressions within the arguments
- * @return true if a matching method was found
- */
+ @Deprecated
public static boolean hasPossibleStaticMethod(ClassNode cNode, String name, Expression arguments, boolean trySpread) {
- int count = 0;
- boolean foundSpread = false;
-
- if (arguments instanceof TupleExpression) {
- TupleExpression tuple = (TupleExpression) arguments;
- for (Expression arg : tuple.getExpressions()) {
- if (arg instanceof SpreadExpression) {
- foundSpread = true;
- } else {
- count++;
- }
- }
- } else if (arguments instanceof MapExpression) {
- count = 1;
- }
-
- for (MethodNode method : cNode.getMethods(name)) {
- if (method.isStatic()) {
- Parameter[] parameters = method.getParameters();
- // do fuzzy match for spread case: count will be number of non-spread args
- if (trySpread && foundSpread && parameters.length >= count) return true;
-
- if (parameters.length == count) return true;
-
- // handle varargs case
- if (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray()) {
- if (count >= parameters.length - 1) return true;
- // fuzzy match any spread to a varargs
- if (trySpread && foundSpread) return true;
- }
-
- // handle parameters with default values
- int nonDefaultParameters = 0;
- for (Parameter parameter : parameters) {
- if (!parameter.hasInitialExpression()) {
- nonDefaultParameters++;
- }
- }
-
- if (count < parameters.length && nonDefaultParameters <= count) {
- return true;
- }
- // TODO handle spread with nonDefaultParams?
- }
- }
- return false;
+ return org.apache.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticMethod(cNode, name, arguments, trySpread);
}
- /**
- * Return true if we have a static accessor
- */
- public static boolean hasPossibleStaticProperty(ClassNode candidate, String methodName) {
- // assume explicit static method call checked first so we can assume a simple check here
- if (!methodName.startsWith("get") && !methodName.startsWith("is")) {
- return false;
- }
- String propName = getPropNameForAccessor(methodName);
- PropertyNode pNode = getStaticProperty(candidate, propName);
- return pNode != null && (methodName.startsWith("get") || boolean_TYPE.equals(pNode.getType()));
+ @Deprecated
+ public static boolean hasPossibleStaticProperty(ClassNode cNode, String methodName) {
+ return org.apache.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticProperty(cNode, methodName);
}
- /**
- * Returns the property name, e.g. age, given an accessor name, e.g. getAge.
- * Returns the original if a valid prefix cannot be removed.
- *
- * @param accessorName the accessor name of interest, e.g. getAge
- * @return the property name, e.g. age, or original if not a valid property accessor name
- */
+ @Deprecated
public static String getPropNameForAccessor(String accessorName) {
- if (!isValidAccessorName(accessorName)) return accessorName;
- int prefixLength = accessorName.startsWith("is") ? 2 : 3;
- return String.valueOf(accessorName.charAt(prefixLength)).toLowerCase() + accessorName.substring(prefixLength + 1);
+ return org.apache.groovy.ast.tools.ClassNodeUtils.getPropNameForAccessor(accessorName);
}
- /**
- * Detect whether the given accessor name starts with "get", "set" or "is" followed by at least one character.
- *
- * @param accessorName the accessor name of interest, e.g. getAge
- * @return true if a valid prefix is found
- */
+ @Deprecated
public static boolean isValidAccessorName(String accessorName) {
- if (accessorName.startsWith("get") || accessorName.startsWith("is") || accessorName.startsWith("set")) {
- int prefixLength = accessorName.startsWith("is") ? 2 : 3;
- return accessorName.length() > prefixLength;
- };
- return false;
+ return org.apache.groovy.ast.tools.ClassNodeUtils.isValidAccessorName(accessorName);
}
+ @Deprecated
public static boolean hasStaticProperty(ClassNode cNode, String propName) {
- return getStaticProperty(cNode, propName) != null;
+ return org.apache.groovy.ast.tools.ClassNodeUtils.hasStaticProperty(cNode, propName);
}
- /**
- * Detect whether a static property with the given name is within the class
- * or a super class.
- *
- * @param cNode the ClassNode of interest
- * @param propName the property name
- * @return the static property if found or else null
- */
+ @Deprecated
public static PropertyNode getStaticProperty(ClassNode cNode, String propName) {
- ClassNode classNode = cNode;
- while (classNode != null) {
- for (PropertyNode pn : classNode.getProperties()) {
- if (pn.getName().equals(propName) && pn.isStatic()) return pn;
- }
- classNode = classNode.getSuperClass();
- }
- return null;
+ return org.apache.groovy.ast.tools.ClassNodeUtils.getStaticProperty(cNode, propName);
}
- /**
- * Detect whether a given ClassNode is a inner class (non-static).
- *
- * @param currentClass the ClassNode of interest
- * @return true if the given node is a (non-static) inner class, else false
- */
- public static boolean isInnerClass(ClassNode currentClass) {
- return currentClass.redirect().getOuterClass() != null
- && !Modifier.isStatic(currentClass.getModifiers());
+ @Deprecated
+ public static boolean isInnerClass(ClassNode cNode) {
+ return org.apache.groovy.ast.tools.ClassNodeUtils.isInnerClass(cNode);
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
index 3cea76a..476253a 100644
--- a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
+++ b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
@@ -23,6 +23,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import org.apache.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.ast.expr.BinaryExpression;
import org.codehaus.groovy.ast.expr.ConstantExpression;
@@ -35,7 +36,6 @@ import org.codehaus.groovy.ast.expr.PropertyExpression;
import org.codehaus.groovy.ast.expr.TupleExpression;
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.CatchStatement;
-import org.codehaus.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.ast.tools.GeneralUtils;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.runtime.MetaClassHelper;
@@ -104,7 +104,7 @@ public class ClassCompletionVerifier extends ClassCodeVisitorSupport {
result = new HashMap<String, MethodNode>();
}
// add in unimplemented abstract methods from the interfaces
- ClassNodeUtils.addInterfaceMethods(node, result);
+ ClassNodeUtils.addDeclaredMethodsFromInterfaces(node, result);
for (MethodNode methodNode : node.getMethods()) {
MethodNode mn = result.get(methodNode.getTypeDescriptor());
if (mn != null && (mn.isStatic() ^ methodNode.isStatic()) && !methodNode.isStaticConstructor()) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/Verifier.java b/src/main/org/codehaus/groovy/classgen/Verifier.java
index da26a1b..77a910b 100644
--- a/src/main/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/org/codehaus/groovy/classgen/Verifier.java
@@ -22,6 +22,7 @@ import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import groovy.lang.MetaClass;
import groovy.transform.Generated;
+import org.apache.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.ast.expr.ArgumentListExpression;
@@ -39,7 +40,6 @@ import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.ReturnStatement;
import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.ast.tools.GenericsUtils;
import org.codehaus.groovy.ast.tools.PropertyNodeUtils;
import org.codehaus.groovy.classgen.asm.BytecodeHelper;
@@ -1201,9 +1201,9 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
Map genericsSpec = new HashMap();
// unimplemented abstract methods from interfaces
- Map<String, MethodNode> abstractMethods = ClassNodeUtils.getDeclaredMethodMapsFromInterfaces(classNode);
+ Map<String, MethodNode> abstractMethods = ClassNodeUtils.getDeclaredMethodsFromInterfaces(classNode);
Map<String, MethodNode> allInterfaceMethods = new HashMap<String, MethodNode>(abstractMethods);
- ClassNodeUtils.addDeclaredMethodMapsFromSuperInterfaces(classNode, allInterfaceMethods);
+ ClassNodeUtils.addDeclaredMethodsFromAllInterfaces(classNode, allInterfaceMethods);
List<MethodNode> declaredMethods = new ArrayList<MethodNode>(classNode.getMethods());
// remove all static, private and package private methods
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/StaticImportVisitor.java b/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
index e055ebb..a439197 100644
--- a/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -54,12 +54,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.getPropNameForAccessor;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticMethod;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticProperty;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.hasStaticProperty;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.isInnerClass;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.isValidAccessorName;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.getPropNameForAccessor;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticMethod;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.hasPossibleStaticProperty;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.hasStaticProperty;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.isInnerClass;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.isValidAccessorName;
import static org.codehaus.groovy.runtime.MetaClassHelper.capitalize;
/**
http://git-wip-us.apache.org/repos/asf/groovy/blob/fb1572c8/src/main/org/codehaus/groovy/control/StaticVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/StaticVerifier.java b/src/main/org/codehaus/groovy/control/StaticVerifier.java
index a1e6c1e..53706f9 100644
--- a/src/main/org/codehaus/groovy/control/StaticVerifier.java
+++ b/src/main/org/codehaus/groovy/control/StaticVerifier.java
@@ -39,7 +39,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import static org.codehaus.groovy.ast.tools.ClassNodeUtils.isInnerClass;
+import static org.apache.groovy.ast.tools.ClassNodeUtils.isInnerClass;
/**
* Verifier to check non-static access in static contexts