private boolean directlyImplementsTrait(ClassNode trait) { ClassNode[] interfaces = currentClass.getInterfaces(); if (interfaces==null) { return currentClass.getSuperClass().equals(trait); } for (ClassNode node : interfaces) { if (node.equals(trait)) { return true; } } return currentClass.getSuperClass().equals(trait); }
private static void visitInsnByType(ClassNode top, MethodVisitor mv, int iInsn, int lInsn, int fInsn, int dInsn) { if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) { mv.visitInsn(iInsn); } else if (long_TYPE.equals(top)) { mv.visitInsn(lInsn); } else if (float_TYPE.equals(top)) { mv.visitInsn(fInsn); } else if (double_TYPE.equals(top)) { mv.visitInsn(dInsn); } }
public List<ClassNode> getOuterClasses() { if (!(this instanceof InnerClassNode)) { return Collections.emptyList(); } List<ClassNode> result = new LinkedList<>(); ClassNode outestClass = ((InnerClassNode) this).getOuterMostClass(); ClassNode cn = this; do { result.add(cn = cn.getOuterClass()); } while (!cn.equals(outestClass)); return result; }
private static Character tryCharConstant(final Expression expr) { if (expr instanceof ConstantExpression) { ConstantExpression ce = (ConstantExpression) expr; if (ClassHelper.STRING_TYPE.equals(ce.getType())) { String val = (String) ce.getValue(); if (val!=null && val.length()==1) { return val.charAt(0); } } } return null; }
/** * 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())); }
public static boolean equalParameterTypes(Parameter[] p1, Parameter[] p2) { if (p1.length != p2.length) return false; for (int i = 0; i < p1.length; i++) { if (!p1[i].getType().equals(p2[i].getType())) return false; } return true; }
public boolean equals(Object o) { if (redirect!=null) return redirect().equals(o); if (!(o instanceof ClassNode)) return false; ClassNode cn = (ClassNode) o; return (cn.getText().equals(getText())); }
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); } }
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode node = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(node.getClassNode())) return; if (parent instanceof ClassNode) { processClass((ClassNode) parent, node); } }
public void checkReturnType(ClassNode attrType, ASTNode node) { if (attrType.isArray()) { checkReturnType(attrType.getComponentType(), node); } else if (ClassHelper.isPrimitiveType(attrType)) { } else if (ClassHelper.STRING_TYPE.equals(attrType)) { } else if (ClassHelper.CLASS_Type.equals(attrType)) { } else if (attrType.isDerivedFrom(ClassHelper.Enum_Type)) { } else if (isValidAnnotationClass(attrType)) { } else { addError("Unexpected return type " + attrType.getName(), node); } }
private static FieldNode tryGetFieldNode(final ClassNode weavedType, final String fieldName) { FieldNode fn = weavedType.getDeclaredField(fieldName); if (fn == null && ClassHelper.CLASS_Type.equals(weavedType)) { GenericsType[] genericsTypes = weavedType.getGenericsTypes(); if (genericsTypes != null && genericsTypes.length == 1) { // for static properties fn = genericsTypes[0].getType().getDeclaredField(fieldName); } } return fn; }
@Override public void coerce(ClassNode from, ClassNode target) { ClassNode wrapper = ClassHelper.getWrapper(target); makeIndyCall(invokeMethod, EmptyExpression.INSTANCE, false, false, "asType", new ClassExpression(wrapper)); if (ClassHelper.boolean_TYPE.equals(target) || ClassHelper.Boolean_TYPE.equals(target)) { writeIndyCast(ClassHelper.OBJECT_TYPE,target); } else { BytecodeHelper.doCast(controller.getMethodVisitor(), wrapper); controller.getOperandStack().replace(wrapper); controller.getOperandStack().doGroovyCast(target); } }
private static void addMethod(FieldNode fieldNode, BlockStatement body, ClassNode type) { int visibility = ACC_PUBLIC; if (fieldNode.isStatic()) visibility |= ACC_STATIC; String propName = MetaClassHelper.capitalize(fieldNode.getName().substring(1)); ClassNode declaringClass = fieldNode.getDeclaringClass(); addGeneratedMethod(declaringClass, "get" + propName, visibility, type, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body); if (ClassHelper.boolean_TYPE.equals(type)) { addGeneratedMethod(declaringClass, "is" + propName, visibility, type, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, stmt(callThisX("get" + propName))); } }
private static String getterName(ClassNode annotatedNode, PropertyNode pNode) { String getterName = "get" + MetaClassHelper.capitalize(pNode.getName()); boolean existingExplicitGetter = annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY) != null; if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && !existingExplicitGetter) { getterName = "is" + MetaClassHelper.capitalize(pNode.getName()); } return getterName; }
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 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 boolean isAssignable(ClassNode node, ClassNode testNode) { if (node.isArray() && testNode.isArray()) { return isArrayAssignable(node.getComponentType(), testNode.getComponentType()); } if (testNode.isInterface()) { if (node.equals(testNode) || node.implementsInterface(testNode)) return true; } return node.isDerivedFrom(testNode); }
public void visitField(FieldNode node) { if (currentClass.getDeclaredField(node.getName()) != node) { addError("The " + getDescription(node) + " is declared multiple times.", node); } checkInterfaceFieldModifiers(node); checkGenericsUsage(node, node.getType()); if (node.getType().equals(VOID_TYPE)) { addError("The " + getDescription(node) + " has invalid type void", node); } super.visitField(node); }