private static boolean isOptimizable(final ClassNode exprInferredType, final ClassNode castType) { if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(exprInferredType, castType)) { return true; } if (ClassHelper.isPrimitiveType(exprInferredType) && ClassHelper.isPrimitiveType(castType)) { return true; } return false; } }
public static ClassNode getUnwrapper(ClassNode cn) { cn = cn.redirect(); if (isPrimitiveType(cn)) return cn; ClassNode result = WRAPPER_TYPE_TO_PRIMITIVE_TYPE_MAP.get(cn); if (null != result) { return result; } return cn; }
/** * Returns a wrapped type if, and only if, the provided class node is a primitive type. * This method differs from {@link ClassHelper#getWrapper(org.codehaus.groovy.ast.ClassNode)} as it will * return the same instance if the provided type is not a generic type. * * @param type * @return the wrapped type */ protected static ClassNode wrapTypeIfNecessary(ClassNode type) { if (isPrimitiveType(type)) return getWrapper(type); return type; }
private static boolean validTypeForCall(ClassNode type) { // do call only for final classes and primitive types if (isPrimitiveType(type)) return true; return (type.getModifiers() & ACC_FINAL) > 0; }
private static boolean matchWithOrWithourBoxing(final ClassNode argType, final Class aClass) { final boolean match; ClassNode type = ClassHelper.make(aClass); if (ClassHelper.isPrimitiveType(type) && !ClassHelper.isPrimitiveType(argType)) { type = ClassHelper.getWrapper(type); } else if (ClassHelper.isPrimitiveType(argType) && !ClassHelper.isPrimitiveType(type)) { type = ClassHelper.getUnwrapper(type); } match = argType.equals(type); return match; }
private boolean isPrimitiveOnTop() { return isPrimitiveType(getTopOperand()); }
public ClassNode box() { MethodVisitor mv = controller.getMethodVisitor(); int size = stack.size(); ClassNode type = stack.get(size-1); if (ClassHelper.isPrimitiveType(type) && ClassHelper.VOID_TYPE!=type) { ClassNode wrapper = ClassHelper.getWrapper(type); BytecodeHelper.doCastToWrappedType(mv, type, wrapper); type = wrapper; } // else nothing to box stack.set(size-1, type); return type; }
private static boolean possiblyCloneable(ClassNode type) { return !isPrimitiveType(type) && ((isCloneableType(type) || (type.getModifiers() & ACC_FINAL) == 0)); }
private static void writeGenericsBoundType(StringBuilder ret, ClassNode printType, boolean writeInterfaceMarker) { if (writeInterfaceMarker && printType.isInterface()) ret.append(":"); if (printType.isGenericsPlaceHolder() && printType.getGenericsTypes()!=null) { ret.append("T"); ret.append(printType.getGenericsTypes()[0].getName()); ret.append(";"); } else { ret.append(getTypeDescription(printType, false)); addSubTypes(ret, printType.getGenericsTypes(), "<", ">"); if (!ClassHelper.isPrimitiveType(printType)) ret.append(";"); } }
public static ClassNode getSuperClass(ClassNode type, ClassNode target) { ClassNode superClass = ClassHelper.getNextSuperClass(type, target); if (superClass == null) { if (ClassHelper.isPrimitiveType(type)) { superClass = ClassHelper.getNextSuperClass(ClassHelper.getWrapper(type), target); } } return superClass; }
private void addTypeInformation(Expression expression, Expression orig) { ClassNode type = typeChooser.resolveType(expression, node); if (isPrimitiveType(type)) { StatementMeta meta = addMeta(orig); meta.type = type; opt.chainShouldOptimize(true); opt.chainInvolvedType(type); } }
private static Expression providedOrDefaultInitialValue(FieldNode fNode) { Expression initialExp = fNode.getInitialExpression() != null ? fNode.getInitialExpression() : ConstantExpression.NULL; final ClassNode paramType = fNode.getType(); if (ClassHelper.isPrimitiveType(paramType) && initialExp.equals(ConstantExpression.NULL)) { initialExp = primitivesInitialValues.get(paramType.getTypeClass()); } return initialExp; }
private void loadInitValue(ClassNode type) { MethodVisitor mv = controller.getMethodVisitor(); if (ClassHelper.isPrimitiveType(type)) { mv.visitLdcInsn(0); } else { mv.visitInsn(ACONST_NULL); } controller.getOperandStack().push(type); }
private static void pushInitValue(ClassNode type, MethodVisitor mv) { if (ClassHelper.isPrimitiveType(type)) { if (type== ClassHelper.long_TYPE) { mv.visitInsn(LCONST_0); } else if (type== ClassHelper.double_TYPE) { mv.visitInsn(DCONST_0); } else if (type== ClassHelper.float_TYPE) { mv.visitInsn(FCONST_0); } else { mv.visitLdcInsn(0); } } else { mv.visitInsn(ACONST_NULL); } }
public static void doCast(MethodVisitor mv, ClassNode type) { if (type == ClassHelper.OBJECT_TYPE) return; if (ClassHelper.isPrimitiveType(type) && type != VOID_TYPE) { unbox(mv, type); } else { mv.visitTypeInsn( CHECKCAST, type.isArray() ? BytecodeHelper.getTypeDescription(type) : BytecodeHelper.getClassInternalName(type.getName())); } }
public ClassNode getPlainNodeReference() { if (ClassHelper.isPrimitiveType(this)) return this; ClassNode n = new ClassNode(name, modifiers, superClass,null,null); n.isPrimaryNode = false; n.setRedirect(redirect()); if (isArray()) { n.componentType = redirect().getComponentType(); } return n; }
private void checkComparable(PropertyNode pNode) { if (pNode.getType().implementsInterface(COMPARABLE_TYPE) || isPrimitiveType(pNode.getType()) || hasAnnotation(pNode.getType(), MY_TYPE)) { return; } addError("Error during " + MY_TYPE_NAME + " processing: property '" + pNode.getName() + "' must be Comparable", pNode); }
private void checkProps(List<FieldNode> list, List<String> excludes, boolean checkPropertyTypes) { for (FieldNode fNode : list) { if (excludes != null && excludes.contains(fNode.getName())) continue; if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue; if ((fNode.getModifiers() & ACC_FINAL) != 0) { addError(MY_TYPE_NAME + ": The Externalizable property (or field) '" + fNode.getName() + "' cannot be final", fNode); } ClassNode propType = fNode.getType(); if (checkPropertyTypes && !isPrimitiveType(propType) && !implementsExternalizable(propType) && !implementsSerializable(propType)) { addError(MY_TYPE_NAME + ": strict type checking is enabled and the non-primitive property (or field) '" + fNode.getName() + "' in an Externalizable class has the type '" + propType.getName() + "' which isn't Externalizable or Serializable", fNode); } } }
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); } }
public static boolean isKnownImmutableType(ClassNode fieldType, List<String> knownImmutableClasses) { if (builtinOrDeemedType(fieldType, knownImmutableClasses)) return true; if (!fieldType.isResolved()) return false; if ("java.util.Optional".equals(fieldType.getName()) && fieldType.getGenericsTypes() != null && fieldType.getGenericsTypes().length == 1) { GenericsType optionalType = fieldType.getGenericsTypes()[0]; if (optionalType.isResolved() && !optionalType.isPlaceholder() && !optionalType.isWildcard()) { ClassNode valueType = optionalType.getType(); if (builtinOrDeemedType(valueType, knownImmutableClasses)) return true; if (valueType.isEnum()) return true; } } return fieldType.isEnum() || ClassHelper.isPrimitiveType(fieldType) || hasImmutableAnnotation(fieldType); }