boolean isSpec(ClassNode clazz) { return clazz.isDerivedFrom(nodeCache.Specification); }
@Override public boolean isDerivedFrom(final ClassNode type) { for (ClassNode delegate : delegates) { if (delegate.isDerivedFrom(type)) return true; } return false; }
public static boolean derivesFromDate(ClassNode fieldType) { return fieldType.isDerivedFrom(DATE_TYPE); }
private ClassNode getCommonSuperClassNode(ClassNode c, ClassNode d) { // adapted from ClassWriter code if (c.isDerivedFrom(d)) return d; if (d.isDerivedFrom(c)) return c; if (c.isInterface() || d.isInterface()) return ClassHelper.OBJECT_TYPE; do { c = c.getSuperClass(); } while (c!=null && !d.isDerivedFrom(c)); if (c==null) return ClassHelper.OBJECT_TYPE; return c; } @Override
public boolean isScript() { return redirect().script || isDerivedFrom(ClassHelper.SCRIPT_TYPE); }
public static boolean isNumberCategory(ClassNode type) { return isBigDecCategory(type) || type.isDerivedFrom(Number_TYPE); }
private static boolean hasCompatibleType(ClassNode attrType, ClassNode wrapperType) { return wrapperType.isDerivedFrom(ClassHelper.getWrapper(attrType)); }
public String getNextClosureInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod) { String methodName = ""; if (enclosingMethod != null) { methodName = enclosingMethod.getName(); if (enclosingClass.isDerivedFrom(ClassHelper.CLOSURE_TYPE)) { methodName = ""; } else { methodName = "_"+encodeAsValidClassName(methodName); } } return methodName + "_closure" + closureClassIdx++; }
private static boolean noExceptionToAvoid(ConstructorNode fromStub, ConstructorNode fromSuper) { ClassNode[] superExceptions = fromSuper.getExceptions(); if (superExceptions==null || superExceptions.length==0) return true; ClassNode[] stubExceptions = fromStub.getExceptions(); if (stubExceptions==null || stubExceptions.length==0) return false; // if all remaining exceptions are used in the stub we are good outer: for (int i=0; i<superExceptions.length; i++) { ClassNode superExc = superExceptions[i]; for (ClassNode stub:stubExceptions) { if (stub.isDerivedFrom(superExc)) continue outer; } // not found return false; } return true; }
/** * Determine if a type is derived from Number (or array thereof). * * @param targetType the candidate type * @param recurse true if we can have multi-dimension arrays; should be false for annotation member types * @return true if the type equals the targetType or array thereof */ public static boolean isNumberOrArrayOfNumber(ClassNode targetType, boolean recurse) { if (targetType == null) return false; return targetType.isDerivedFrom(ClassHelper.Number_TYPE) || (targetType.isArray() && recurse ? isNumberOrArrayOfNumber(targetType.getComponentType(), recurse) : targetType.isArray() && targetType.getComponentType().isDerivedFrom(ClassHelper.Number_TYPE)); }
public void visitCatchStatement(CatchStatement cs) { if (!(cs.getExceptionType().isDerivedFrom(ClassHelper.make(Throwable.class)))) { addError("Catch statement parameter type is not a subclass of Throwable.", cs); } super.visitCatchStatement(cs); }
private MethodNode getCompatibleMethod(ClassNode current, String getAt, ClassNode aType) { // TODO this really should find "best" match or find all matches and complain about ambiguity if more than one // TODO handle getAt with more than one parameter // TODO handle default getAt methods on Java 8 interfaces for (MethodNode methodNode : current.getDeclaredMethods("getAt")) { if (methodNode.getParameters().length == 1) { ClassNode paramType = methodNode.getParameters()[0].getType(); if (aType.isDerivedFrom(paramType) || aType.declaresInterface(paramType)) { return methodNode; } } } return null; }
private static boolean isValidFieldNodeForByteCodeAccess(FieldNode fn, ClassNode accessingNode) { if (fn == null) return false; ClassNode declaringClass = fn.getDeclaringClass(); // same class is always allowed access if (Modifier.isPublic(fn.getModifiers()) || declaringClass.equals(accessingNode)) return true; boolean samePackages = samePackages(declaringClass.getPackageName(), accessingNode.getPackageName()); // protected means same class or same package, or subclass if (Modifier.isProtected(fn.getModifiers()) && (samePackages || accessingNode.isDerivedFrom(declaringClass))) { return true; } if (!fn.isPrivate()) { // package private is the only modifier left. It means same package is allowed, subclass not, same class is return samePackages; } return false; }
private static boolean isCovariant(ClassNode left, ClassNode right) { if (left.isArray() && right.isArray()) { return isCovariant(left.getComponentType(), right.getComponentType()); } return left.isDerivedFrom(right) || left.implementsInterface(right); }
protected void visitEnumExpression(String attrName, PropertyExpression propExpr, ClassNode attrType) { if (!propExpr.getObjectExpression().getType().isDerivedFrom(attrType)) { addError("Attribute '" + attrName + "' should have type '" + attrType.getName() + "' (Enum), but found " + propExpr.getObjectExpression().getType().getName(), propExpr); } }
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 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 boolean shouldImplicitlyPassThisPara(ConstructorCallExpression cce) { boolean pass = false; ClassNode superCN = classNode.getSuperClass(); if (cce.isThisCall()) { pass = true; } else if (cce.isSuperCall()) { // if the super class is another non-static inner class in the same outer class hierarchy, implicit this // needs to be passed if (!superCN.isEnum() && !superCN.isInterface() && superCN instanceof InnerClassNode) { InnerClassNode superInnerCN = (InnerClassNode) superCN; if (!isStatic(superInnerCN) && classNode.getOuterClass().isDerivedFrom(superCN.getOuterClass())) { pass = true; } } } return pass; }
public void coerce(ClassNode from, ClassNode target) { if (from.isDerivedFrom(target)) return; MethodVisitor mv = controller.getMethodVisitor(); OperandStack os = controller.getOperandStack(); os.box(); (new ClassExpression(target)).visit(controller.getAcg()); os.remove(1); asTypeMethod.call(mv); BytecodeHelper.doCast(mv,target); os.replace(target); } }
private boolean compatibleArgumentType(ClassNode argumentType, ClassNode paramType) { if (argumentType == null) return false; if (ClassHelper.getWrapper(argumentType).equals(ClassHelper.getWrapper(paramType))) return true; if (paramType.isInterface()) return argumentType.implementsInterface(paramType); if (paramType.isArray() && argumentType.isArray()) return compatibleArgumentType(argumentType.getComponentType(), paramType.getComponentType()); return ClassHelper.getWrapper(argumentType).isDerivedFrom(ClassHelper.getWrapper(paramType)); }