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; }
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 MappingDefinition getDefinition(final MetaClass clazz) { MappingDefinition def = getDefinition(clazz.getFullyQualifiedName()); if (def == null) { def = getDefinition(clazz.getInternalName()); } return def; }
@Override public MappingDefinition getDefinition(final MetaClass clazz) { MappingDefinition def = getDefinition(clazz.getFullyQualifiedName()); if (def == null) { def = getDefinition(clazz.getInternalName()); } return def; }
public static String methodAccess(final MetaMethod method) { final StringBuilder buf = new StringBuilder(50); if (!method.getReturnType().isVoid()) { buf.append("return "); } if (!method.isStatic()) { buf.append("instance."); } buf.append('@').append(method.getDeclaringClass().getFullyQualifiedName().replace('$', '.')) .append("::").append(method instanceof MetaConstructor ? "new" : method.getName()).append('('); for (final MetaParameter parm : method.getParameters()) { buf.append(parm.getType().getInternalName()); } buf.append(")("); final int length = method.getParameters().length; for (int i = 0; i < length; i++) { buf.append("a").append(i); if (i + 1 < length) buf.append(","); } buf.append(")"); return buf.toString(); } }
public static String methodAccess(final MetaMethod method) { final StringBuilder buf = new StringBuilder(50); if (!method.getReturnType().isVoid()) { buf.append("return "); } if (!method.isStatic()) { buf.append("instance."); } buf.append('@').append(method.getDeclaringClass().getFullyQualifiedName().replace('$', '.')) .append("::").append(method instanceof MetaConstructor ? "new" : method.getName()).append('('); for (final MetaParameter parm : method.getParameters()) { buf.append(parm.getType().getInternalName()); } buf.append(")("); final int length = method.getParameters().length; for (int i = 0; i < length; i++) { buf.append("a").append(i); if (i + 1 < length) buf.append(","); } buf.append(")"); return buf.toString(); } }
@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); }
@Test public void testInternalNameForMultiDimensionalPrimitiveArray() { final String internalName = getMetaClass(char[][].class).getInternalName(); assertEquals("Wrong internal name generated for multidimensional primitive array", "[[C", internalName); }
@Test public void testInternalNameForOneDimensionalPrimitiveArray() { final String internalName = getMetaClass(char[].class).getInternalName(); assertEquals("Wrong internal name generated for one-dimensional primitive array", "[C", internalName); }
@Test public void testInternalNameForOneDimensionalObjectArray() { final String internalName = getMetaClass(String[].class).getInternalName(); assertEquals("Wrong internal name generated for one-dimensional object array", "[Ljava/lang/String;", internalName); }
@Test public void testInternalNameForMultiDimensionalObjectArray() { final String internalName = getMetaClass(String[][].class).getInternalName(); assertEquals("Wrong internal name generated for multidimensional object array", "[[Ljava/lang/String;", internalName); }
@Test public void testNamingMethods() throws Exception { final MetaClass child = getMetaClass(Child.class); assertEquals(Child.class.getSimpleName(), child.getName()); assertEquals(Child.class.getName(), child.getFullyQualifiedName()); assertEquals(Child.class.getName(), child.getCanonicalName()); assertEquals("L" + Child.class.getName().replace('.', '/') + ";", child.getInternalName()); }
private void addArrayMarshaller(final MetaClass type) { MetaClass compType = type.getOuterComponentType().asBoxed(); if (!factory.hasDefinition(type.getFullyQualifiedName()) && !factory.hasDefinition(type.getInternalName())) { MappingDefinition outerDef = factory.getDefinition(compType); Marshaller<Object> marshaller; if (outerDef != null && !factory.shouldUseObjectMarshaller(compType)) { marshaller = outerDef.getMarshallerInstance(); } else { compType = MetaClassFactory.get(Object.class); marshaller = factory.getDefinition(Object.class).getMarshallerInstance(); } if (marshaller == null) { throw new MarshallingException("Failed to generate array marshaller for " + type.getCanonicalName() + " because marshaller for " + compType + " could not be found."); } MappingDefinition newDef = new MappingDefinition( EncDecUtil.qualifyMarshaller( new DefaultArrayMarshaller(type, marshaller), (Class<Object>) type.asClass() ), type, true); if (outerDef != null) { newDef.setClientMarshallerClass(outerDef.getClientMarshallerClass()); } factory.addDefinition(newDef); } }
private void addArrayMarshaller(final MetaClass type) { MetaClass compType = type.getOuterComponentType().asBoxed(); if (!factory.hasDefinition(type.getFullyQualifiedName()) && !factory.hasDefinition(type.getInternalName())) { MappingDefinition outerDef = factory.getDefinition(compType); Marshaller<Object> marshaller; if (outerDef != null && !factory.shouldUseObjectMarshaller(compType)) { marshaller = outerDef.getMarshallerInstance(); } else { compType = MetaClassFactory.get(Object.class); marshaller = factory.getDefinition(Object.class).getMarshallerInstance(); } if (marshaller == null) { throw new MarshallingException("Failed to generate array marshaller for " + type.getCanonicalName() + " because marshaller for " + compType + " could not be found."); } MappingDefinition newDef = new MappingDefinition( EncDecUtil.qualifyMarshaller( new DefaultArrayMarshaller(type, marshaller), (Class<Object>) type.asClass() ), type, true); if (outerDef != null) { newDef.setClientMarshallerClass(outerDef.getClientMarshallerClass()); } factory.addDefinition(newDef); } }