public static int getArrayDimensions(final MetaClass type) { if (!type.isArray()) return 0; final String internalName = type.getInternalName(); for (int i = 0; i < internalName.length(); i++) { if (internalName.charAt(i) != '[') return i; } return 0; }
@Override public synchronized MetaClass getOuterComponentType() { if (_outerComponentCache != null) return _outerComponentCache; MetaClass c = this; while (c.isArray()) { c = c.getComponentType(); } return _outerComponentCache = c; }
@Override public synchronized MetaClass getOuterComponentType() { if (_outerComponentCache != null) return _outerComponentCache; MetaClass c = this; while (c.isArray()) { c = c.getComponentType(); } return _outerComponentCache = c; }
public static int getArrayDimensions(final MetaClass type) { if (!type.isArray()) return 0; final String internalName = type.getInternalName(); for (int i = 0; i < internalName.length(); i++) { if (internalName.charAt(i) != '[') return i; } return 0; }
private static String getTypeName(final MetaClass type) { if (type.isArray()) { return type.getName().replace("[]", "_array"); } else { return type.getName(); } }
private static String getTypeName(final MetaClass type) { if (type.isArray()) { return type.getName().replace("[]", "_array"); } else { return type.getName(); } }
/** * Checks whether the given class has been imported. * * @param clazz * the class to check, must not be null. * * @return true if import exists, otherwise false. */ public boolean hasImport(MetaClass clazz) { checkThread(); if (clazz.isArray()) { clazz = clazz.getComponentType(); } return imports != null && imports.containsKey(clazz.getName()) && imports.get(clazz.getName()).equals(getImportForClass(clazz)); }
/** * Checks whether the given class has been imported. * * @param clazz * the class to check, must not be null. * * @return true if import exists, otherwise false. */ public boolean hasImport(MetaClass clazz) { checkThread(); if (clazz.isArray()) { clazz = clazz.getComponentType(); } return imports != null && imports.containsKey(clazz.getName()) && imports.get(clazz.getName()).equals(getImportForClass(clazz)); }
@Override public boolean shouldUseObjectMarshaller(final MetaClass type) { final boolean hasPortableSubtypes = inheritanceMap.containsKey(type.getFullyQualifiedName()); final MappingDefinition definition = getDefinition(type); final boolean hasMarshaller = definition != null; if (hasMarshaller) { if (definition.getClass().isAnnotationPresent(CustomMapping.class) || definition.getClientMarshallerClass() != null) { return false; } } final boolean isConcrete = !(type.isAbstract() || type.isInterface()); if (!type.isArray() && !type.isEnum() && !isConcrete && !hasPortableSubtypes) { throw new IllegalStateException("A field of type " + type + " appears in a portable class, but " + type + " has no portable implementations."); } return (hasPortableSubtypes && !hasMarshaller) || (hasPortableSubtypes && hasMarshaller && isConcrete); }
private boolean isVisibleType(final MetaClass type) { if (type.isArray()) { return isVisibleType(type.getComponentType()); } else { return type.isPublic() || type.isProtected() || type.isPrimitive(); } }
public static void assertAssignableTypes(final Context context, final MetaClass from, final MetaClass to) { if (!to.asBoxed().isAssignableFrom(from.asBoxed())) { if (to.isArray() && from.isArray() && GenUtil.getArrayDimensions(to) == GenUtil.getArrayDimensions(from) && to.getOuterComponentType().isAssignableFrom(from.getOuterComponentType())) { return; } if (!context.isPermissiveMode()) { if (classAliases.contains(from.getFullyQualifiedName()) && classAliases.contains(to.getFullyQualifiedName())) { // handle convertibility between MetaClass API and java Class reference. return; } throw new InvalidTypeException(to.getFullyQualifiedName() + " is not assignable from " + from.getFullyQualifiedName()); } } }
public static void assertAssignableTypes(final Context context, final MetaClass from, final MetaClass to) { if (!to.asBoxed().isAssignableFrom(from.asBoxed())) { if (to.isArray() && from.isArray() && GenUtil.getArrayDimensions(to) == GenUtil.getArrayDimensions(from) && to.getOuterComponentType().isAssignableFrom(from.getOuterComponentType())) { return; } if (!context.isPermissiveMode()) { if (classAliases.contains(from.getFullyQualifiedName()) && classAliases.contains(to.getFullyQualifiedName())) { // handle convertibility between MetaClass API and java Class reference. return; } throw new InvalidTypeException(to.getFullyQualifiedName() + " is not assignable from " + from.getFullyQualifiedName()); } } }
public boolean isConcrete() { return !isInterface() && !isAbstract() && !isSynthetic() && !isAnonymousClass() && !isPrimitive() && !isArray() && !isAnnotation() && !isEnum(); }
public boolean isConcrete() { return !isInterface() && !isAbstract() && !isSynthetic() && !isAnonymousClass() && !isPrimitive() && !isArray() && !isAnnotation() && !isEnum(); }
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
@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); }
@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); }
@Override public String generate(final Context context) { MetaClass referenceType = reference.getType(); final Statement[] indexes = reference.getIndexes(); if (indexes!=null) { for (final Statement index : indexes) { if (!referenceType.isArray()) throw new InvalidTypeException("Variable is not a " + indexes.length + "-dimensional array!"); referenceType = referenceType.getComponentType(); } } operator.assertCanBeApplied(referenceType); operator.assertCanBeApplied(statement.getType()); return reference.generate(context) + generateIndexes(context, indexes) + " " + operator.getCanonicalString() + " " + statement.generate(context); }
@Override public String generate(final Context context) { MetaClass referenceType = reference.getType(); final Statement[] indexes = reference.getIndexes(); if (indexes!=null) { for (final Statement index : indexes) { if (!referenceType.isArray()) throw new InvalidTypeException("Variable is not a " + indexes.length + "-dimensional array!"); referenceType = referenceType.getComponentType(); } } operator.assertCanBeApplied(referenceType); operator.assertCanBeApplied(statement.getType()); return reference.generate(context) + generateIndexes(context, indexes) + " " + operator.getCanonicalString() + " " + statement.generate(context); }