private static void removeMethodInSuperInterface(List<MethodNode> toBeRemoved, MethodNode one, MethodNode two) { ClassNode oneDC = one.getDeclaringClass(); ClassNode twoDC = two.getDeclaringClass(); if (oneDC.implementsInterface(twoDC)) { toBeRemoved.add(two); } else { toBeRemoved.add(one); } }
private static boolean methodNeedsReplacement(ClassNode classNode, MethodNode m) { // no method found, we need to replace if (m == null) return true; // method is in current class, nothing to be done if (m.getDeclaringClass() == classNode) return false; // do not overwrite final if ((m.getModifiers() & ACC_FINAL) != 0) return false; return true; }
private boolean methodNeedsReplacement(MethodNode m) { // no method found, we need to replace if (m == null) return true; // method is in current class, nothing to be done if (m.getDeclaringClass() == this.getClassNode()) return false; // do not overwrite final if (isFinal(m.getModifiers())) return false; return true; }
private void fixDeclaringClass(DeclarationExpression newDeclExpr) { if (newDeclExpr.getDeclaringClass() == null && currentMethod != null) { newDeclExpr.setDeclaringClass(currentMethod.getDeclaringClass()); } }
public IncorrectTypeHintException(final MethodNode mn, final String msg, final int line, final int column) { super("Incorrect type hint in @ClosureParams in class "+mn.getDeclaringClass().getName()+" method "+mn.getTypeDescriptor()+" : "+msg, line, column); } }
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 static List<MethodNode> filterMethods(ClassNode owner) { List<MethodNode> result = new LinkedList<MethodNode>(); List<MethodNode> methods = owner.getMethods(); for (MethodNode method : methods) { if (method.getDeclaringClass() == owner && !method.isSynthetic()) { if ("main".equals(method.getName()) || "run".equals(method.getName()) && owner.isScriptBody()) continue; result.add(method); } } return result; }
private static boolean areEquivalentInterfaceMethods(MethodNode one, MethodNode two) { return one.getName().equals(two.getName()) && one.getDeclaringClass().isInterface() && two.getDeclaringClass().isInterface() && ParameterUtils.parametersEqual(one.getParameters(), two.getParameters()); }
static Map<GenericsTypeName, GenericsType> extractGenericsParameterMapOfThis(MethodNode mn) { if (mn == null) return null; Map<GenericsTypeName, GenericsType> map; if (mn.isStatic()) { map = new HashMap<>(); } else { map = getGenericsParameterMapOfThis(mn.getDeclaringClass()); } return mergeGenerics(map, mn.getGenericsTypes()); }
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 Expression transformArrayConstructor(final ListExpression expr, final MethodNode target) { ArrayExpression aex = new ArrayExpression(target.getDeclaringClass().getComponentType(), transformArguments(expr)); aex.setSourcePosition(expr); return aex; }
Expression transformListExpression(final ListExpression expr) { MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (target instanceof ConstructorNode) { if (target.getDeclaringClass().isArray()) { return transformArrayConstructor(expr, target); } return transformRegularConstructor(expr, target); } else { return transformer.superTransform(expr); } }
@Override public void visitMethod(final MethodNode node) { if (isSkipMode(node)) { node.putNodeMetaData(STATIC_COMPILE_NODE, false); } super.visitMethod(node); checkForConstructorWithCSButClassWithout(node); if (isStaticallyCompiled(node)) addDynamicOuterClassAccessorsCallback(node.getDeclaringClass()); }
private Expression transformRegularConstructor(final ListExpression expr, final MethodNode target) { // can be replaced with a direct constructor call List<Expression> transformedArgs = transformArguments(expr); ConstructorCallExpression cce = new ConstructorCallExpression( target.getDeclaringClass(), new ArgumentListExpression(transformedArgs) ); cce.setSourcePosition(expr); cce.putNodeMetaData(DIRECT_METHOD_CALL_TARGET, target); return cce; }
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 static MethodNode createBuildMethodForMethod(AnnotationNode anno, ClassNode buildee, MethodNode mNode, Parameter[] params) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); ClassNode returnType; if (mNode instanceof ConstructorNode) { returnType = newClass(buildee); body.addStatement(returnS(ctorX(newClass(mNode.getDeclaringClass()), args(params)))); } else { body.addStatement(returnS(callX(newClass(mNode.getDeclaringClass()), mNode.getName(), args(params)))); returnType = newClass(mNode.getReturnType()); } return new MethodNode(buildMethodName, ACC_PUBLIC, returnType, NO_PARAMS, NO_EXCEPTIONS, body); }
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; } } }
private void addStaticVariableError(VariableExpression ve) { // closures are always dynamic // propertyExpressions will handle the error a bit differently if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return; if (ve.isThisExpression() || ve.isSuperExpression()) return; Variable v = ve.getAccessedVariable(); if (currentMethod != null && currentMethod.isStatic()) { FieldNode fieldNode = getDeclaredOrInheritedField(currentMethod.getDeclaringClass(), ve.getName()); if (fieldNode != null && fieldNode.isStatic()) return; } if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return; addVariableError(ve); }
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; }