public static boolean isNumericallyCoercible(final MetaClass target, final MetaClass parm) { MetaClass boxedTarget = target.isPrimitive() ? target.asBoxed() : target; if (boxedTarget != null && Number_MetaClass.isAssignableFrom(target)) { if ((boxedTarget = parm.isPrimitive() ? parm.asBoxed() : parm) != null) { return Number_MetaClass.isAssignableFrom(boxedTarget); } } return false; }
@Override public void addDefinition(final MappingDefinition definition) { final String fqcn = definition.getMappingClass().getFullyQualifiedName(); final String internalName = definition.getMappingClass().getInternalName(); putDefinitionIfAbsent(fqcn, definition); if (definition.getMappingClass().isPrimitiveWrapper()) { putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getInternalName(), definition); putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getFullyQualifiedName(), definition); } if (!fqcn.equals(internalName) && definition.getMappingClass().isArray() && definition.getMappingClass().getOuterComponentType().isPrimitive()) { putDefinitionIfAbsent(internalName, definition); } if (log.isDebugEnabled()) log.debug("loaded definition: " + fqcn); }
public static boolean isNumericallyCoercible(final MetaClass target, final MetaClass parm) { MetaClass boxedTarget = target.isPrimitive() ? target.asBoxed() : target; if (boxedTarget != null && Number_MetaClass.isAssignableFrom(target)) { if ((boxedTarget = parm.isPrimitive() ? parm.asBoxed() : parm) != null) { return Number_MetaClass.isAssignableFrom(boxedTarget); } } return false; }
@Override public void addDefinition(final MappingDefinition definition) { final String fqcn = definition.getMappingClass().getFullyQualifiedName(); final String internalName = definition.getMappingClass().getInternalName(); putDefinitionIfAbsent(fqcn, definition); if (definition.getMappingClass().isPrimitiveWrapper()) { putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getInternalName(), definition); putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getFullyQualifiedName(), definition); } if (!fqcn.equals(internalName) && definition.getMappingClass().isArray() && definition.getMappingClass().getOuterComponentType().isPrimitive()) { putDefinitionIfAbsent(internalName, definition); } if (log.isDebugEnabled()) log.debug("loaded definition: " + fqcn); }
public static boolean canHandle(final MetaClass type, final String mimeType) { boolean canHandle = false; if (("text/plain".equals(mimeType) && type.asUnboxed().isPrimitive()) || type.equals(MetaClassFactory.get(String.class)) || type.equals(MetaClassFactory.get(Date.class)) || type.isEnum()) { canHandle = true; } return canHandle; }
private static void processEnvironmentConfigExtensions(final Set<MetaClass> exposedClasses) { final Collection<MetaClass> exts = ClassScanner.getTypesAnnotatedWith(EnvironmentConfigExtension.class, true); for (final MetaClass cls : exts) { try { final Class<? extends ExposedTypesProvider> providerClass = cls.asClass().asSubclass(ExposedTypesProvider.class); for (final MetaClass exposedType : providerClass.newInstance().provideTypesToExpose()) { if (exposedType.isPrimitive()) { exposedClasses.add(exposedType.asBoxed()); } else if (exposedType.isConcrete()) { exposedClasses.add(exposedType); } } } catch (final Throwable e) { throw new RuntimeException("unable to load environment extension: " + cls.getFullyQualifiedName(), e); } } }
private static void processEnvironmentConfigExtensions(final Set<MetaClass> exposedClasses) { final Collection<MetaClass> exts = ClassScanner.getTypesAnnotatedWith(EnvironmentConfigExtension.class, true); for (final MetaClass cls : exts) { try { final Class<? extends ExposedTypesProvider> providerClass = cls.asClass().asSubclass(ExposedTypesProvider.class); for (final MetaClass exposedType : providerClass.newInstance().provideTypesToExpose()) { if (exposedType.isPrimitive()) { exposedClasses.add(exposedType.asBoxed()); } else if (exposedType.isConcrete()) { exposedClasses.add(exposedType); } } } catch (final Throwable e) { throw new RuntimeException("unable to load environment extension: " + cls.getFullyQualifiedName(), e); } } }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
@Override public synchronized String getInternalName() { if (_internalNameCache != null) return _internalNameCache; String name = getFullyQualifiedName(); String dimString = ""; MetaClass type = this; if (isArray()) { type = type.getComponentType(); int dim = 1; while (type.isArray()) { dim++; type = type.getComponentType(); } for (int i = 0; i < dim; i++) { dimString += "["; } name = type.getFullyQualifiedName(); } if (type.isPrimitive()) { name = getInternalPrimitiveNameFrom(name.trim()); } else { name = "L".concat(getInternalPrimitiveNameFrom(name.trim()).replace('.', '/')).concat(";"); } return _internalNameCache = dimString + name; }
private boolean isVisibleType(final MetaClass type) { if (type.isArray()) { return isVisibleType(type.getComponentType()); } else { return type.isPublic() || type.isProtected() || type.isPrimitive(); } }
@Override public String getFullyQualifiedName() { if (fqcn != null) { return fqcn; } if (isArray()) { if (getOuterComponentType().isPrimitive()) { fqcn = getInternalName(); } else { fqcn = getInternalName().replace('/', '.'); } } else { fqcn = getEnclosedMetaObject().getQualifiedBinaryName(); } return fqcn; }
@Override public String getFullyQualifiedName() { if (fqcn != null) { return fqcn; } if (isArray()) { if (getOuterComponentType().isPrimitive()) { fqcn = getInternalName(); } else { fqcn = getInternalName().replace('/', '.'); } } else { fqcn = getEnclosedMetaObject().getQualifiedBinaryName(); } return fqcn; }
private Statement defaultValueStatement(MetaClass type) { if (type.isPrimitive()) { if (type.asBoxed().isAssignableTo(Number.class)) { return Stmt.castTo(type, Stmt.load(0)); } else if (type.isAssignableTo(boolean.class)) { return Stmt.load(false); } else { throw new UnsupportedOperationException("Don't know how to make a default value for @PageState field of type " + type.getFullyQualifiedName()); } } else { return Stmt.load(null); } }
public boolean isConcrete() { return !isInterface() && !isAbstract() && !isSynthetic() && !isAnonymousClass() && !isPrimitive() && !isArray() && !isAnnotation() && !isEnum(); }
private Statement defaultValueStatement(MetaClass type) { if (type.isPrimitive()) { if (type.asBoxed().isAssignableTo(Number.class)) { return Stmt.castTo(type, Stmt.load(0)); } else if (type.isAssignableTo(boolean.class)) { return Stmt.load(false); } else { throw new UnsupportedOperationException("Don't know how to make a default value for @PageState field of type " + type.getFullyQualifiedName()); } } else { return Stmt.load(null); } }
public boolean isConcrete() { return !isInterface() && !isAbstract() && !isSynthetic() && !isAnonymousClass() && !isPrimitive() && !isArray() && !isAnnotation() && !isEnum(); }
private static Statement marshal(final MetaClass type, final Statement statement) { ContextualStatementBuilder s = null; if (type.isPrimitive()) { s = Stmt.nestedCall(Stmt.newObject(type.asBoxed()).withParameters(statement)).invoke("toString"); } else if (type.getFullyQualifiedName().equals(Date.class.getName())) { s = Stmt.nestedCall(new TernaryStatement(Bool.isNull(statement), Stmt.load(""), Stmt.nestedCall(statement).invoke("toGMTString"))); } else { s = Stmt.nestedCall(new TernaryStatement(Bool.isNull(statement), Stmt.load(""), Stmt.nestedCall(statement))); if (!type.equals(MetaClassFactory.get(String.class))) { s = s.invoke("toString"); } } return s; }
@Override public String generate(final Context context) { final String stmt = statement.generate(context); if (!toType.isPrimitive() && !toType.isAssignableFrom(statement.getType()) && !toType.isAssignableTo(statement.getType()) && !toType.isInterface() && !statement.getType().asBoxed().equals(toType)) { if (context.isPermissiveMode()) { return "(" + LoadClassReference.getClassReference(toType, context) + ") " + stmt; } else { throw new InvalidTypeException(statement.getType() + " cannot be cast to " + toType); } } else if (toType.isAssignableFrom(statement.getType()) && !statement.getType().equals(MetaClassFactory.get(NullType.class))) { return stmt; } else { return "(" + LoadClassReference.getClassReference(toType, context) + ") " + stmt; } }
@Override public String generate(final Context context) { final String stmt = statement.generate(context); if (!toType.isPrimitive() && !toType.isAssignableFrom(statement.getType()) && !toType.isAssignableTo(statement.getType()) && !toType.isInterface() && !statement.getType().asBoxed().equals(toType)) { if (context.isPermissiveMode()) { return "(" + LoadClassReference.getClassReference(toType, context) + ") " + stmt; } else { throw new InvalidTypeException(statement.getType() + " cannot be cast to " + toType); } } else if (toType.isAssignableFrom(statement.getType()) && !statement.getType().equals(MetaClassFactory.get(NullType.class))) { return stmt; } else { return "(" + LoadClassReference.getClassReference(toType, context) + ") " + stmt; } }