private static void extractParametersFromMethod(final List<ClassNode[]> signatures, final MethodNode method) { if (Traits.hasDefaultImplementation(method)) return; Parameter[] parameters = method.getParameters(); ClassNode[] typeParams = new ClassNode[parameters.length]; for (int i = 0; i < parameters.length; i++) { typeParams[i] = parameters[i].getOriginType(); } signatures.add(typeParams); } }
private static MethodNode getDeclaredMethodCorrected(Map genericsSpec, MethodNode mn, ClassNode correctedNext) { for (MethodNode orig : correctedNext.getDeclaredMethods(mn.getName())) { MethodNode method = correctToGenericsSpec(genericsSpec, orig); if (ParameterUtils.parametersEqual(method.getParameters(), mn.getParameters())) { return method; } } return null; }
private static MethodNode getDeclaredMethodCorrected(Map<String, ClassNode> genericsSpec, MethodNode origMethod, ClassNode correctedClass) { for (MethodNode nameMatch : correctedClass.getDeclaredMethods(origMethod.getName())) { MethodNode correctedMethod = correctToGenericsSpec(genericsSpec, nameMatch); if (ParameterUtils.parametersEqual(correctedMethod.getParameters(), origMethod.getParameters())) { return correctedMethod; } } return null; }
private static boolean isCustomScriptBodyMethod(MethodNode node) { return node != null && !(node.getDeclaringClass().equals(ClassHelper.SCRIPT_TYPE) && "run".equals(node.getName()) && node.getParameters().length == 0); } }
private boolean isCustomScriptBodyMethod(MethodNode node) { return node != null && !(node.getDeclaringClass().equals(ClassHelper.SCRIPT_TYPE) && "run".equals(node.getName()) && node.getParameters().length == 0); } }
private void checkRepetitiveMethod(MethodNode node) { if (isConstructor(node)) return; for (MethodNode method : currentClass.getMethods(node.getName())) { if (method == node) continue; if (!method.getDeclaringClass().equals(node.getDeclaringClass())) continue; Parameter[] p1 = node.getParameters(); Parameter[] p2 = method.getParameters(); if (p1.length != p2.length) continue; addErrorIfParamsAndReturnTypeEqual(p2, p1, node, method); } }
private void handleFeatureParameters() { Parameter[] parameters = whereBlock.getParent().getAst().getParameters(); if (parameters.length == 0) addFeatureParameters(); else checkAllParametersAreDataVariables(parameters); }
private void checkMethodsForOverridingFinal(ClassNode cn) { for (MethodNode method : cn.getMethods()) { Parameter[] params = method.getParameters(); for (MethodNode superMethod : cn.getSuperClass().getMethods(method.getName())) { Parameter[] superParams = superMethod.getParameters(); if (!hasEqualParameterTypes(params, superParams)) continue; if (!superMethod.isFinal()) break; addInvalidUseOfFinalError(method, params, superMethod.getDeclaringClass()); return; } } }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { visitAnnotations(node); visitClassCodeContainer(node.getCode()); for (Parameter param : node.getParameters()) { visitAnnotations(param); } }
@Override protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { // ClassCodeVisitorSupport doesn't seem to visit parameters for (Parameter param: node.getParameters()) { visitAnnotations(param); if (param.getInitialExpression() != null) param.getInitialExpression().visit(this); } super.visitConstructorOrMethod(node, isConstructor); }
private boolean handleImplicitCallOnMethodParam(MethodCallExpression expr) { if (!expr.isImplicitThis()) return false; String methodName = expr.getMethodAsString(); List<Parameter> params = Arrays.asList(resources.getCurrentMethod().getAst().getParameters()); for (Parameter param : params) { if (param.getName().equals(methodName)) { expr.setMethod(new ConstantExpression("call")); expr.setObjectExpression(new VariableExpression(methodName)); return true; } } return false; }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { for (Parameter p : node.getParameters()) { if (p.hasInitialExpression()) { Expression init = p.getInitialExpression(); p.setInitialExpression(transform(init)); } } super.visitConstructorOrMethod(node, isConstructor); }
@Override public void visitBlockStatement(BlockStatement stat) { super.visitBlockStatement(stat); if (resources.getCurrentMethod() instanceof FeatureMethod) { AstUtil.fixUpLocalVariables(resources.getCurrentMethod().getAst().getParameters(), stat.getVariableScope(), false); } }
private void createMethods(ClassNode cNode, ClassNode exception, String message, ClosureExpression code) { for (MethodNode candidate : getAllCorrectedMethodsMap(cNode).values()) { if (candidate.isAbstract()) { addGeneratedMethod(cNode, candidate.getName(), Opcodes.ACC_PUBLIC, candidate.getReturnType(), candidate.getParameters(), candidate.getExceptions(), methodBody(exception, message, code, candidate.getReturnType())); } } }
@Override protected void doVisitClosureExpression(ClosureExpression expr) { if (resources.getCurrentMethod() instanceof FeatureMethod) { AstUtil.fixUpLocalVariables(resources.getCurrentMethod().getAst().getParameters(), expr.getVariableScope(), true); } super.doVisitClosureExpression(expr); if (conditionFound || groupConditionFound) defineRecorders(expr, groupConditionFound); }
private static boolean hasUsableImplementation(ClassNode c, MethodNode m) { if (c == m.getDeclaringClass()) return false; MethodNode found = c.getDeclaredMethod(m.getName(), m.getParameters()); if (found == null) return false; int asp = found.getModifiers() & ABSTRACT_STATIC_PRIVATE; int visible = found.getModifiers() & VISIBILITY; if (visible != 0 && asp == 0) return true; if (c.equals(OBJECT_TYPE)) return false; return hasUsableImplementation(c.getSuperClass(), m); }
private void analyseMethodHead(MethodNode node) { visitNode(node.getReturnType()); analyseParameters(node.getParameters()); visitNodes(node.getExceptions()); }
public static MethodNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn) { 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()); }
private MethodNode copyMethod(MethodNode method, String newName) { // can't hurt to set return type to void MethodNode newMethod = new MethodNode(newName, method.getModifiers(), ClassHelper.VOID_TYPE, method.getParameters(), method.getExceptions(), method.getCode()); newMethod.addAnnotations(method.getAnnotations()); newMethod.setSynthetic(method.isSynthetic()); newMethod.setDeclaringClass(method.getDeclaringClass()); newMethod.setSourcePosition(method); newMethod.setVariableScope(method.getVariableScope()); newMethod.setGenericsTypes(method.getGenericsTypes()); newMethod.setAnnotationDefault(method.hasAnnotationDefault()); return newMethod; }
private void addFeatureMetadata(FeatureMethod feature) { AnnotationNode ann = new AnnotationNode(nodeCache.FeatureMetadata); ann.setMember(FeatureMetadata.NAME, new ConstantExpression(feature.getName())); ann.setMember(FeatureMetadata.ORDINAL, new ConstantExpression(feature.getOrdinal())); ann.setMember(FeatureMetadata.LINE, new ConstantExpression(feature.getAst().getLineNumber())); ann.setMember(FeatureMetadata.BLOCKS, blockAnnElems = new ListExpression()); ListExpression paramNames = new ListExpression(); for (Parameter param : feature.getAst().getParameters()) paramNames.addExpression(new ConstantExpression(param.getName())); ann.setMember(FeatureMetadata.PARAMETER_NAMES, paramNames); feature.getAst().addAnnotation(ann); }