public boolean run( Outline model, Options opt, ErrorHandler errorHandler ) { // we want this to work without requiring JSR-250 jar. annotation = model.getCodeModel().ref("javax.annotation.Generated"); for( ClassOutline co : model.getClasses() ) augument(co); for( EnumOutline eo : model.getEnums() ) augument(eo); //TODO: process generated ObjectFactory classes? return true; }
private static void createNameConstruction(Outline outline, JDefinedClass definedClass, String fieldName, QName reference, JExpression namespaceArgument, Class<?> nameClass) { JClass clazz = (JClass) outline.getModel().codeModel._ref(nameClass); JInvocation invocation = JExpr._new(clazz); invocation.arg(namespaceArgument); invocation.arg(reference.getLocalPart()); definedClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, nameClass, fieldName, invocation); }
public final List<String> getClassList() { List<String> classList = new ArrayList<String>(); // list up root classes for( PackageOutline p : outline.getAllPackageContexts() ) classList.add( p.objectFactory().fullName() ); return classList; } }
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { LOG.fine("Running toString() plugin."); if (!active) { return true; } final JClass toStringDelegateImpl = outline.getCodeModel() .ref("org.apache.commons.lang3.builder.ToStringBuilder"); final JClass styleClass = outline.getCodeModel().ref(styleClassName); final JFieldRef toStringDelegateStyleParam = styleClass.staticRef(styleFieldName); for (ClassOutline co : outline.getClasses()) { addToStringMethod(co, toStringDelegateImpl, toStringDelegateStyleParam); } return true; }
public static ClassOutline findClassOutline(Outline outline, QName type) { Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet(); for (Map.Entry<NClass, CClassInfo> entry : set) { ClassOutline classOutline = outline.getClazz(entry.getValue()); QName qname = entry.getValue().getTypeName(); if (!type.equals(qname)) { continue; } return classOutline; } throw new IllegalStateException("Object type class defined by qname '" + type + "' outline was not found."); }
public JExpression createConstant(Outline outline, XmlString lexical) { return JExpr._new(outline.getCodeModel().ref(BigInteger.class)).arg(lexical.value.trim()); } };
private JMethod generateLazyProxyInitGetter(final ClassOutline classOutline, final FieldOutline fieldOutline) { final JCodeModel m = classOutline.parent().getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final String fieldName = fieldOutline.getPropertyInfo().getName(false); final String getterName = "get" + fieldOutline.getPropertyInfo().getName(true); final JFieldVar collectionField = definedClass.fields().get(fieldName); final JClass elementType = ((JClass) collectionField.type()).getTypeParameters().get(0); final JClass proxyFieldType = m.ref(BoundList.class).narrow(elementType); final JFieldRef collectionFieldRef = JExpr._this().ref(collectionField); final JFieldRef proxyField = JExpr._this().ref(collectionField.name() + BoundPropertiesPlugin.PROXY_SUFFIX); final JMethod oldGetter = definedClass.getMethod(getterName, new JType[0]); definedClass.methods().remove(oldGetter); final JMethod newGetter = definedClass.method(JMod.PUBLIC, proxyFieldType, getterName); newGetter.body()._if(collectionFieldRef.eq(JExpr._null()))._then().assign(collectionFieldRef, JExpr._new(m.ref(ArrayList.class).narrow(elementType))); final JBlock ifProxyNull = newGetter.body()._if(proxyField.eq(JExpr._null()))._then(); ifProxyNull.assign(proxyField, JExpr._new(m.ref(BoundListProxy.class).narrow(elementType)).arg(collectionFieldRef)); newGetter.body()._return(proxyField); return newGetter; }
public boolean run( Outline outline, Options opt, ErrorHandler errorHandler ) { for( ClassOutline ci : outline.getClasses() ) { JDefinedClass impl = ci.implClass; if (ci.getSuperClass() == null) { JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName); $loc.annotate(XmlLocation.class); $loc.annotate(XmlTransient.class); impl._implements(Locatable.class); impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc); JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation"); JVar $newLoc = setter.param(Locator.class, "newLocator"); setter.body().assign($loc, $newLoc); } } return true; } }
public JExpression createConstant(Outline outline, XmlString lexical) { return outline.getCodeModel().ref(DatatypeConverter.class).staticInvoke("parseBase64Binary").arg(lexical.value); } };
private void createSupportProperty(final Outline outline, final ClassOutline classOutline, final Class<?> supportClass, final Class<?> listenerClass, final String aspectName) { final JCodeModel m = outline.getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final String aspectNameCap = aspectName.substring(0, 1).toUpperCase() + aspectName.substring(1); if (classOutline.getSuperClass() == null) { // only generate fields in topmost classes final JFieldVar supportField = definedClass.field(JMod.PROTECTED | JMod.FINAL | JMod.TRANSIENT, supportClass, aspectName + BoundPropertiesPlugin.SUPPORT_FIELD_SUFFIX, JExpr._new(m.ref(supportClass)).arg(JExpr._this())); final JMethod addMethod = definedClass.method(JMod.PUBLIC, m.VOID, "add" + aspectNameCap + "Listener"); final JVar addParam = addMethod.param(JMod.FINAL, listenerClass, aspectName + "Listener"); addMethod.body().invoke(JExpr._this().ref(supportField), "add" + aspectNameCap + "Listener").arg(addParam); final JMethod removeMethod = definedClass.method(JMod.PUBLIC, m.VOID, "remove" + aspectNameCap + "Listener"); final JVar removeParam = removeMethod.param(JMod.FINAL, listenerClass, aspectName + "Listener"); removeMethod.body().invoke(JExpr._this().ref(supportField), "remove" + aspectNameCap + "Listener").arg(removeParam); } final JMethod withMethod = definedClass.method(JMod.PUBLIC, definedClass, "with" + aspectNameCap + "Listener"); final JVar withParam = withMethod.param(JMod.FINAL, listenerClass, aspectName + "Listener"); withMethod.body().invoke("add" + aspectNameCap + "Listener").arg(withParam); withMethod.body()._return(JExpr._this()); if (classOutline.getSuperClass() != null) { withMethod.annotate(Override.class); } }
private void replaceGetter(final ClassOutline co, final JFieldVar field, final JType setType) { // Create the method name final String methodName = OPERATION_GET_PREFIX + capitalizeFirstLetter(field.name()); // Find and remove Old Getter! final JMethod oldGetter = co.implClass.getMethod(methodName, new JType[0]); co.implClass.methods().remove(oldGetter); final JMethod getter = co.implClass.method(JMod.PUBLIC, setType, methodName); if (checkNull()) { final JType classType = co.parent().getCodeModel().ref(getImplementationClass()); getter.body()._if(JExpr.ref(field.name()).eq(JExpr._null()))._then().assign(field, JExpr._new(classType)); } getter.body()._return(JExpr.ref(field.name())); }
private JFieldVar generateProxyField(final ClassOutline classOutline, final FieldOutline fieldOutline) { final JCodeModel m = classOutline.parent().getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final JFieldVar collectionField = definedClass.fields().get(fieldOutline.getPropertyInfo().getName(false)); final JClass elementType = ((JClass) collectionField.type()).getTypeParameters().get(0); return definedClass.field(JMod.PRIVATE | JMod.TRANSIENT, m.ref(BoundList.class).narrow(elementType), collectionField.name() + BoundPropertiesPlugin.PROXY_SUFFIX, JExpr._null()); }
private void generateRoundtripTestClass(Outline outline) { if (getRoundtripTestClassName() != null) { final JDefinedClass roundtripTestClass = GeneratorContextUtils .generateContextPathAwareClass(outline, getRoundtripTestClassName(), RoundtripTest.class); final String persistenceUnitName = getPersistenceUnitName() != null ? getPersistenceUnitName() : getNaming().getPersistenceUnitName(getMapping(), outline); JMethod getPersistenceUnitName = roundtripTestClass.method( JMod.PUBLIC, outline.getCodeModel().ref(String.class), "getPersistenceUnitName"); getPersistenceUnitName.body()._return( JExpr.lit(persistenceUnitName)); } }
private void replaceSetter(final ClassOutline co, final JFieldVar field, final JType setType) { // Create the method name final String methodName = OPERATION_SET_PREFIX + capitalizeFirstLetter(field.name()); // Create Date JType final JType dateType = co.parent().getCodeModel().ref(getReplaceableClass()); // Find and remove Old setter! final JMethod oldSetter = co.implClass.getMethod(methodName, new JType[] { dateType }); co.implClass.methods().remove(oldSetter); // Create New Setter final JMethod setter = co.implClass.method(JMod.PUBLIC, Void.TYPE, methodName); final JVar var = setter.param(JMod.FINAL, setType, PARAM_NAME); assignSetterValue(co.implClass, field, setter, var); }
private JExpression defaultValue(JType javaType, FieldOutline fieldOutline) { if (javaType.isPrimitive()) { if (fieldOutline.parent().parent().getCodeModel().BOOLEAN.equals(javaType)) { return JExpr.lit(false); } else if (fieldOutline.parent().parent().getCodeModel().SHORT.equals(javaType)) { return JExpr.cast(fieldOutline.parent().parent().getCodeModel().SHORT, JExpr.lit(0)); } else { return JExpr.lit(0); } } return JExpr._null(); }
public JClass toType(Outline o, Aspect aspect) { return o.getCodeModel().ref(List.class) .narrow(elementType.toType(o, aspect).boxify()); }
cfg.setUserTypeList(userTypes); for(ClassOutline co : outline.getClasses()) { JDefinedClass c = co.implClass; c._implements(PortableObject.class); c.annotate(Portable.class); userTypes.getUserTypeOrInclude().add(new UserType(BigInteger.valueOf(typeId++), c.fullName(), null)); for (EnumOutline eo : outline.getEnums()) { JDefinedClass c = eo.clazz; userTypes.getUserTypeOrInclude().add(new UserType(BigInteger.valueOf(typeId++), c.fullName(), enumSerializer));
private void generateNameOnlyMetaField(final PluginContext pluginContext, final JDefinedClass metaClass, final FieldOutline fieldOutline) { final PropertyOutline propertyOutline = new DefinedPropertyOutline(fieldOutline); final String constantName = getConstantName(fieldOutline); final Outline outline = pluginContext.outline; final String propertyName = constantName != null ? constantName : propertyOutline.getFieldName(); final String metaFieldName = this.camelCase ? propertyName : fieldOutline.parent().parent().getModel().getNameConverter().toConstantName(propertyName); metaClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL | JMod.TRANSIENT, String.class, metaFieldName, JExpr.lit(propertyName)); }
public static void createQName(Outline outline, JDefinedClass targetClass, String targetField, QName qname, JFieldVar namespaceField, boolean namespaceFieldIsLocal, boolean createPath) { JExpression namespaceArgument; if (namespaceField != null) { if (namespaceFieldIsLocal) { namespaceArgument = namespaceField; } else { JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.SCHEMA_CONSTANTS_GENERATED_CLASS_NAME); namespaceArgument = schemaClass.staticRef(namespaceField); } } else { namespaceArgument = JExpr.lit(qname.getNamespaceURI()); } createNameConstruction(outline, targetClass, targetField, qname, namespaceArgument, createPath ? ItemName.class : QName.class); }
private void removeDummyImplementation(final DefinedInterfaceOutline interfaceOutline) { final ClassOutline classToRemove = interfaceOutline.getClassOutline(); if (classToRemove != null) { final List<JMethod> methodsToRemove = new ArrayList<>(); for (final JMethod method : classToRemove._package().objectFactory().methods()) { if (method.name().equals("create" + classToRemove.implClass.name())) { methodsToRemove.add(method); } } for (final JMethod method : methodsToRemove) { classToRemove._package().objectFactory().methods().remove(method); } this.pluginContext.outline.getClasses().remove(classToRemove); } }