Java Code Examples for org.codehaus.groovy.ast.MethodNode#getGenericsTypes()
The following examples show how to use
org.codehaus.groovy.ast.MethodNode#getGenericsTypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaticTypeCheckingSupport.java From groovy with Apache License 2.0 | 6 votes |
protected static boolean typeCheckMethodsWithGenerics(final ClassNode receiver, final ClassNode[] argumentTypes, final MethodNode candidateMethod) { if (isUsingUncheckedGenerics(receiver)) { return true; } if (CLASS_Type.equals(receiver) && receiver.isUsingGenerics() && !candidateMethod.getDeclaringClass().equals(receiver) && !(candidateMethod instanceof ExtensionMethodNode)) { return typeCheckMethodsWithGenerics(receiver.getGenericsTypes()[0].getType(), argumentTypes, candidateMethod); } // both candidate method and receiver have generic information so a check is possible GenericsType[] genericsTypes = candidateMethod.getGenericsTypes(); boolean methodUsesGenerics = (genericsTypes != null && genericsTypes.length > 0); boolean isExtensionMethod = candidateMethod instanceof ExtensionMethodNode; if (isExtensionMethod && methodUsesGenerics) { ClassNode[] dgmArgs = new ClassNode[argumentTypes.length + 1]; dgmArgs[0] = receiver; System.arraycopy(argumentTypes, 0, dgmArgs, 1, argumentTypes.length); MethodNode extensionMethodNode = ((ExtensionMethodNode) candidateMethod).getExtensionMethodNode(); return typeCheckMethodsWithGenerics(extensionMethodNode.getDeclaringClass(), dgmArgs, extensionMethodNode, true); } else { return typeCheckMethodsWithGenerics(receiver, argumentTypes, candidateMethod, false); } }
Example 2
Source File: BytecodeHelper.java From groovy with Apache License 2.0 | 6 votes |
public static String getGenericsMethodSignature(MethodNode node) { GenericsType[] generics = node.getGenericsTypes(); Parameter[] param = node.getParameters(); ClassNode returnType = node.getReturnType(); if (generics == null && !hasGenerics(param) && !hasGenerics(returnType)) return null; StringBuilder ret = new StringBuilder(100); getGenericsTypeSpec(ret, generics); GenericsType[] paramTypes = new GenericsType[param.length]; for (int i = 0; i < param.length; i++) { ClassNode pType = param[i].getType(); if (pType.getGenericsTypes() == null || !pType.isGenericsPlaceHolder()) { paramTypes[i] = new GenericsType(pType); } else { paramTypes[i] = pType.getGenericsTypes()[0]; } } addSubTypes(ret, paramTypes, "(", ")"); addSubTypes(ret, new GenericsType[]{new GenericsType(returnType)}, "", ""); return ret.toString(); }
Example 3
Source File: DelegateASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
private static List<String> genericPlaceholderNames(MethodNode candidate) { GenericsType[] candidateGenericsTypes = candidate.getGenericsTypes(); List<String> names = new ArrayList<String>(); if (candidateGenericsTypes != null) { for (GenericsType gt : candidateGenericsTypes) { names.add(gt.getName()); } } return names; }
Example 4
Source File: StaticCompilationVisitor.java From groovy with Apache License 2.0 | 5 votes |
private static List<String> methodSpecificGenerics(final MethodNode method) { List<String> genericTypeNames = new ArrayList<>(); GenericsType[] genericsTypes = method.getGenericsTypes(); if (genericsTypes != null) { for (GenericsType gt : genericsTypes) { genericTypeNames.add(gt.getName()); } } return genericTypeNames; }
Example 5
Source File: GenericsUtils.java From groovy with Apache License 2.0 | 5 votes |
public static MethodNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn) { if (genericsSpec == null) return mn; if (mn.getGenericsTypes() != null) genericsSpec = addMethodGenerics(mn, genericsSpec); ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec, mn.getReturnType()); Parameter[] origParameters = mn.getParameters(); Parameter[] newParameters = new Parameter[origParameters.length]; for (int i = 0; i < origParameters.length; i++) { Parameter origParameter = origParameters[i]; newParameters[i] = new Parameter(correctToGenericsSpecRecurse(genericsSpec, origParameter.getType()), origParameter.getName(), origParameter.getInitialExpression()); } return new MethodNode(mn.getName(), mn.getModifiers(), correctedType, newParameters, mn.getExceptions(), mn.getCode()); }
Example 6
Source File: GenericsUtils.java From groovy with Apache License 2.0 | 5 votes |
public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<String, ClassNode> oldSpec) { Map<String, ClassNode> newSpec = new HashMap<>(oldSpec); GenericsType[] gts = current.getGenericsTypes(); if (gts != null) { for (GenericsType gt : gts) { String name = gt.getName(); ClassNode type = gt.getType(); if (gt.isPlaceholder()) { ClassNode redirect; if (gt.getUpperBounds() != null) { redirect = gt.getUpperBounds()[0]; } else if (gt.getLowerBound() != null) { redirect = gt.getLowerBound(); } else { redirect = ClassHelper.OBJECT_TYPE; } if (redirect.isGenericsPlaceHolder()) { // "T extends U" or "T super U" type = redirect; } else { // "T" or "T extends Thing" or "T super Thing" type = ClassHelper.makeWithoutCaching(name); type.setGenericsPlaceHolder(true); type.setRedirect(redirect); } } newSpec.put(name, type); } } return newSpec; }