private static JDefinedClass definedClassOrNullFromType(JType type) { if (type == null || type.isPrimitive()) { return null; } JClass fieldClass = type.boxify(); JPackage jPackage = fieldClass._package(); return jPackage._getClass(fieldClass.name()); }
public static JDefinedClass getObjectValidatorFactoryClass(final JPackage thePackage) { return thePackage._getClass("ObjectValidatorFactory"); }
public static JDefinedClass _getClass(JPackage _package, String name) { final int idx = name.lastIndexOf('$'); if (idx < 0) { return _package._getClass(name); } else { final String parentClassName = name.substring(0, idx); final JDefinedClass parentClass = _package ._getClass(parentClassName); if (parentClass == null) { return null; } else { return _getClass(parentClass, name.substring(idx + 1)); } } }
/** * Gets a reference to the already created generated class. * * @return null * If the class is not yet created. * @see JPackage#_getClass(String) */ public JDefinedClass _getClass(String fullyQualifiedName) { int idx = fullyQualifiedName.lastIndexOf('.'); if( idx<0 ) return rootPackage()._getClass(fullyQualifiedName); else return _package(fullyQualifiedName.substring(0,idx)) ._getClass( fullyQualifiedName.substring(idx+1) ); }
/** * Gets a reference to the already created generated class. * * @return null * If the class is not yet created. * @see JPackage#_getClass(String) */ public JDefinedClass _getClass(String fullyQualifiedName) { int idx = fullyQualifiedName.lastIndexOf('.'); if( idx<0 ) return rootPackage()._getClass(fullyQualifiedName); else return _package(fullyQualifiedName.substring(0,idx)) ._getClass( fullyQualifiedName.substring(idx+1) ); }
/** * Gets a reference to the already created generated class. * * @return null * If the class is not yet created. * @see JPackage#_getClass(String) */ public JDefinedClass _getClass(String fullyQualifiedName) { int idx = fullyQualifiedName.lastIndexOf('.'); if( idx<0 ) return rootPackage()._getClass(fullyQualifiedName); else return _package(fullyQualifiedName.substring(0,idx)) ._getClass( fullyQualifiedName.substring(idx+1) ); }
/** * Gets a reference to the already created generated class. * * @return null * If the class is not yet created. * @see JPackage#_getClass(String) */ public JDefinedClass _getClass(String fullyQualifiedName) { int idx = fullyQualifiedName.lastIndexOf('.'); if( idx<0 ) return rootPackage()._getClass(fullyQualifiedName); else return _package(fullyQualifiedName.substring(0,idx)) ._getClass( fullyQualifiedName.substring(idx+1) ); }
/** * Gets a reference to the already created generated class. * * @return null * If the class is not yet created. * @see JPackage#_getClass(String) */ public JDefinedClass _getClass(String fullyQualifiedName) { int idx = fullyQualifiedName.lastIndexOf('.'); if( idx<0 ) return rootPackage()._getClass(fullyQualifiedName); else return _package(fullyQualifiedName.substring(0,idx)) ._getClass( fullyQualifiedName.substring(idx+1) ); }
@Override public JDefinedClass apply(ApiResourceMetadata controllerMetadata, JPackage generatableType) { String controllerClassName = controllerMetadata.getResourceName().concat("Client"); JDefinedClass definedClass; try { definedClass = generatableType._interface(controllerClassName); } catch (JClassAlreadyExistsException e1) { definedClass = generatableType._getClass(controllerClassName); } return definedClass; }
@Override public JDefinedClass apply(ApiResourceMetadata controllerMetadata, JPackage generatableType) { String resourceClassName = controllerMetadata.getName() + classNameSuffix; JDefinedClass definedClass; try { definedClass = generatableType._class(resourceClassName); } catch (JClassAlreadyExistsException e1) { definedClass = generatableType._getClass(resourceClassName); } return definedClass; }
@Override public JDefinedClass apply(ApiResourceMetadata controllerMetadata, JPackage generatableType) { String controllerClassName = controllerMetadata.getName() + CONTROLLER_SUFFIX; JDefinedClass definedClass; try { definedClass = generatableType._interface(controllerClassName); } catch (JClassAlreadyExistsException e1) { definedClass = generatableType._getClass(controllerClassName); } return definedClass; }
@Override public JDefinedClass apply(ApiResourceMetadata controllerMetadata, JPackage generatableType) { String clientClassName = controllerMetadata.getName() + CLIENT_SUFFIX; JDefinedClass definedClass; try { definedClass = generatableType._interface(clientClassName); } catch (JClassAlreadyExistsException e1) { definedClass = generatableType._getClass(clientClassName); } return definedClass; }
public static JDefinedClass _getClass(JCodeModel codeModel, String fullyQualifiedName) { final int idx = fullyQualifiedName.lastIndexOf('.'); if (idx < 0) { return codeModel.rootPackage()._getClass(fullyQualifiedName); } else { final String packageName = fullyQualifiedName.substring(0, idx); for (Iterator<JPackage> iterator = codeModel.packages(); iterator .hasNext();) { final JPackage _package = iterator.next(); if (packageName.equals(_package.name())) { return _getClass(_package, fullyQualifiedName.substring(idx + 1)); } } return null; } }
/** * For the given class locate and add Object Factory classes to the map. * * @return {@code true} if value class generation is enabled */ public boolean addObjectFactoryForClass(JDefinedClass clazz) { JDefinedClass valueObjectFactoryClass = clazz._package()._getClass(FACTORY_CLASS_NAME); if (objectFactoryClasses.containsKey(valueObjectFactoryClass.fullName())) { return false; } objectFactoryClasses.put(valueObjectFactoryClass.fullName(), valueObjectFactoryClass); JDefinedClass objectFactoryClass = null; // If class has a non-hidden interface, then there is object factory in another package. for (Iterator<JClass> iter = clazz._implements(); iter.hasNext();) { JClass interfaceClass = iter.next(); if (!isHiddenClass(interfaceClass)) { objectFactoryClass = interfaceClass._package()._getClass(FACTORY_CLASS_NAME); if (objectFactoryClass != null) { objectFactoryClasses.put(objectFactoryClass.fullName(), objectFactoryClass); } } } return objectFactoryClass != null; }
/** * For the given class locate and add Object Factory classes to the map. * * @return {@code true} if value class generation is enabled */ public boolean addObjectFactoryForClass(JDefinedClass clazz) { JDefinedClass valueObjectFactoryClass = clazz._package()._getClass(FACTORY_CLASS_NAME); if (objectFactoryClasses.containsKey(valueObjectFactoryClass.fullName())) { return false; } objectFactoryClasses.put(valueObjectFactoryClass.fullName(), valueObjectFactoryClass); JDefinedClass objectFactoryClass = null; // If class has a non-hidden interface, then there is object factory in another package. for (Iterator<JClass> iter = clazz._implements(); iter.hasNext();) { JClass interfaceClass = iter.next(); if (!isHiddenClass(interfaceClass)) { objectFactoryClass = interfaceClass._package()._getClass(FACTORY_CLASS_NAME); if (objectFactoryClass != null) { objectFactoryClasses.put(objectFactoryClass.fullName(), objectFactoryClass); } } } return objectFactoryClass != null; }
public JFieldRef getAdapter(Class adapterType) { String adapterId = adapterType.getName(); JFieldRef ref = adapters.get(adapterId); if (ref == null) { final String fieldName = decapitalize(adapterType.getSimpleName()) + "Adapter"; final JPackage jPackage = jaxbObjectClass.getPackage(); final JDefinedClass definedClass; if (jPackage._getClass("Adapters") != null) { definedClass = jPackage._getClass("Adapters"); if (!definedClass.fields().containsKey(fieldName)) { JClass jClass = builderContext.toJClass(adapterType); definedClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, jClass, fieldName, JExpr._new(jClass)); } } else { try { definedClass = jPackage._class("Adapters"); JClass jClass = builderContext.toJClass(adapterType); definedClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, jClass, fieldName, JExpr._new(jClass)); } catch (JClassAlreadyExistsException e) { throw new IllegalStateException(e); } } ref = definedClass.staticRef(fieldName); adapters.put(adapterId, ref); } return ref; }
private static JDefinedClass definedClassOrNullFromType(JType type) { if (type == null || type.isPrimitive()) { return null; } JClass fieldClass = type.boxify(); JPackage jPackage = fieldClass._package(); return jPackage._getClass(fieldClass.name()); }
private JDefinedClass resolveClass( final Context ctx ) throws SAXException { // The output class JDefinedClass cd = ctx.co.ref; if( StringUtils.isStringNotEmpty( ctx.className ) ) { cd = ctx.co.ref._package()._getClass( ctx.className ); if( cd == null ) { try { cd = ctx.co.ref._package()._class( ctx.className ); } catch( JClassAlreadyExistsException ex ) { throw new SAXException( ex.getMessage(), ex ); } } if( cd == null ) { throw new SAXException( "Unable to locate " + ctx.className ); } } return cd; }
/** * If candidate class contains the inner class which is collection parametrisation (type), then this inner class has * to be moved to top class. For example from<br> * {@code TypeClass (is a collection type) -> ContainerClass (marked for removal) -> ElementClass}<br> * we need to get<br> * {@code TypeClass -> ElementClass}.<br> * Also this move should be reflected on factory method names. */ private boolean moveInnerClassToParent(Outline outline, Candidate candidate) { // Skip basic parametrisations like "List<String>": if (candidate.getFieldParametrisationClass() == null) { return false; } JDefinedClass fieldParametrisationImpl = candidate.getFieldParametrisationImpl(); if (candidate.getClazz() != fieldParametrisationImpl.parentContainer()) { // Field parametrisation class is not inner class of the candidate: return false; } JDefinedClass fieldParametrisationClass = candidate.getFieldParametrisationClass(); String oldFactoryMethodName = fieldParametrisationClass.outer().name() + fieldParametrisationClass.name(); moveClassLevelUp(outline, fieldParametrisationImpl); renameFactoryMethod(fieldParametrisationImpl._package()._getClass(FACTORY_CLASS_NAME), oldFactoryMethodName, fieldParametrisationClass.name()); if (candidate.isValueObjectDisabled()) { moveClassLevelUp(outline, fieldParametrisationClass); renameFactoryMethod(fieldParametrisationClass._package()._getClass(FACTORY_CLASS_NAME), oldFactoryMethodName, fieldParametrisationClass.name()); } return true; }
/** * If candidate class contains the inner class which is collection parametrisation (type), then this inner class has * to be moved to top class. For example from<br> * {@code TypeClass (is a collection type) -> ContainerClass (marked for removal) -> ElementClass}<br> * we need to get<br> * {@code TypeClass -> ElementClass}.<br> * Also this move should be reflected on factory method names. */ private boolean moveInnerClassToParent(Outline outline, Candidate candidate) { // Skip basic parametrisations like "List<String>": if (candidate.getFieldParametrisationClass() == null) { return false; } JDefinedClass fieldParametrisationImpl = candidate.getFieldParametrisationImpl(); if (candidate.getClazz() != fieldParametrisationImpl.parentContainer()) { // Field parametrisation class is not inner class of the candidate: return false; } JDefinedClass fieldParametrisationClass = candidate.getFieldParametrisationClass(); String oldFactoryMethodName = fieldParametrisationClass.outer().name() + fieldParametrisationClass.name(); moveClassLevelUp(outline, fieldParametrisationImpl); renameFactoryMethod(fieldParametrisationImpl._package()._getClass(FACTORY_CLASS_NAME), oldFactoryMethodName, fieldParametrisationClass.name()); if (candidate.isValueObjectDisabled()) { moveClassLevelUp(outline, fieldParametrisationClass); renameFactoryMethod(fieldParametrisationClass._package()._getClass(FACTORY_CLASS_NAME), oldFactoryMethodName, fieldParametrisationClass.name()); } return true; }