/** * Indicates if this <code>JavaClass</code> is <code>abstract</code>. * * @return <code>true</code> if this <code>JavaClass</code> is <code>abstract</code>, otherwise <code>false</code>. */ public boolean isAbstract() { return xjcClass.isAbstract(); }
public DefaultValueWriter createDefaultValueWriterForWrappedElement(QName wrapperElement, QName item) { if (defaultValues != null) { Mapping mapping = rawJaxbModelGenCode.get(wrapperElement); if (mapping != null) { List<? extends Property> propList = mapping.getWrapperStyleDrilldown(); for (Property pro : propList) { if (pro.elementName().getNamespaceURI().equals(item.getNamespaceURI()) && pro.elementName().getLocalPart().equals(item.getLocalPart())) { JType type = pro.type(); if (type instanceof JDefinedClass && ((JDefinedClass)type).isAbstract()) { //no default values for abstract classes return null; } return new JAXBDefaultValueWriter(pro.type()); } } } } return null; }
public DefaultValueWriter createDefaultValueWriterForWrappedElement(QName wrapperElement, QName item) { if (defaultValues != null) { Mapping mapping = rawJaxbModelGenCode.get(wrapperElement); if (mapping != null) { List<? extends Property> propList = mapping.getWrapperStyleDrilldown(); for (Property pro : propList) { if (pro.elementName().getNamespaceURI().equals(item.getNamespaceURI()) && pro.elementName().getLocalPart().equals(item.getLocalPart())) { JType type = pro.type(); if (type instanceof JDefinedClass && ((JDefinedClass)type).isAbstract()) { //no default values for abstract classes return null; } return new JAXBDefaultValueWriter(pro.type()); } } } } return null; }
throw ex; } else if (jdc.isAbstract()) { writer.write("null;"); } else {
throw ex; } else if (jdc.isAbstract()) { writer.write("null;"); } else {
private void createAsPrismObject(JDefinedClass definedClass) { JClass prismObjectClass = CLASS_MAP.get(PrismObject.class); JType returnType; if (definedClass.isAbstract()) { returnType = prismObjectClass.narrow(definedClass.wildcard()); } else { // e.g. PrismObject<TaskType> for TaskType // we assume that we don't subclass a non-abstract object class into another one returnType = prismObjectClass.narrow(definedClass); } JMethod asPrismObject = definedClass.method(JMod.PUBLIC, returnType, METHOD_AS_PRISM_OBJECT); asPrismObject.annotate(CLASS_MAP.get(Override.class)); //create method body JBlock body = asPrismObject.body(); body._return(JExpr.invoke(METHOD_AS_PRISM_CONTAINER)); }
void generateDefaultConstructor() { final JMethod defaultConstructor = this.classOutline.implClass.constructor( this.classOutline.implClass.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); defaultConstructor.body().directStatement("// " + getMessage("defaultConstructor.bodyComment")); defaultConstructor.javadoc().append(getMessage("defaultConstructor.javadoc.desc")); }
public DefaultValueWriter createDefaultValueWriter(QName qname, boolean element) { if (defaultValues == null) { return null; } TypeAndAnnotation typeAnno = rawJaxbModelGenCode.getJavaType(qname); if (element) { Mapping mapping = rawJaxbModelGenCode.get(qname); if (mapping != null) { typeAnno = mapping.getType(); } } if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) { JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass(); if (dc.isAbstract()) { //no default values for abstract classes typeAnno = null; } } if (typeAnno != null) { final JType type = typeAnno.getTypeClass(); return new JAXBDefaultValueWriter(type); } return null; }
public DefaultValueWriter createDefaultValueWriter(QName qname, boolean element) { if (defaultValues == null) { return null; } TypeAndAnnotation typeAnno = rawJaxbModelGenCode.getJavaType(qname); if (element) { Mapping mapping = rawJaxbModelGenCode.get(qname); if (mapping != null) { typeAnno = mapping.getType(); } } if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) { JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass(); if (dc.isAbstract()) { //no default values for abstract classes typeAnno = null; } } if (typeAnno != null) { final JType type = typeAnno.getTypeClass(); return new JAXBDefaultValueWriter(type); } return null; }
private boolean containsDefaultValue(Outline outline, FieldOutline field) { ClassOutline fClass = null; for (ClassOutline classOutline : outline.getClasses()) { if (classOutline.implClass == field.getRawType() && !classOutline.implClass.isAbstract()) { fClass = classOutline; break; } } if (fClass == null) { return false; } for (FieldOutline f : fClass.getDeclaredFields()) { if (f.getPropertyInfo().getSchemaComponent() instanceof XSParticle) { XSParticle particle = (XSParticle)f.getPropertyInfo().getSchemaComponent(); XSTerm term = particle.getTerm(); if (term.isElementDecl() && term.asElementDecl().getDefaultValue() != null) { return true; } } } return false; }
JMethod generateNewCopyBuilderMethod(final boolean partial) { final JDefinedClass typeDefinition = this.typeOutline.isInterface() && ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() != null ? ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() : this.definedClass; final int mods = this.implement ? this.definedClass.isAbstract() ? JMod.PUBLIC | JMod.ABSTRACT : JMod.PUBLIC : JMod.NONE; final JMethod copyBuilderMethod = typeDefinition.method(mods, this.builderClass.raw, this.settings.getNewCopyBuilderMethodName()); final JTypeVar copyBuilderMethodTypeParam = copyBuilderMethod.generify(BuilderGenerator.PARENT_BUILDER_TYPE_PARAMETER_NAME); final JVar parentBuilderParam = copyBuilderMethod.param(JMod.FINAL, copyBuilderMethodTypeParam, BuilderGenerator.PARENT_BUILDER_PARAM_NAME); final CopyGenerator copyGenerator = this.pluginContext.createCopyGenerator(copyBuilderMethod, partial); copyBuilderMethod.type(this.builderClass.raw.narrow(copyBuilderMethodTypeParam)); final JMethod copyBuilderConvenienceMethod = typeDefinition.method(mods, this.builderClass.raw.narrow(this.pluginContext.voidClass), this.settings.getNewCopyBuilderMethodName()); final CopyGenerator copyConvenienceGenerator = this.pluginContext.createCopyGenerator(copyBuilderConvenienceMethod, partial); if (this.implement && !this.definedClass.isAbstract()) { copyBuilderMethod.body()._return(copyGenerator.generatePartialArgs(this.pluginContext._new((JClass)copyBuilderMethod.type()).arg(parentBuilderParam).arg(JExpr._this()).arg(JExpr.TRUE))); copyBuilderConvenienceMethod.body()._return(copyConvenienceGenerator.generatePartialArgs(this.pluginContext.invoke(this.settings.getNewCopyBuilderMethodName()).arg(JExpr._null()))); } if (this.typeOutline.getSuperClass() != null) { copyBuilderMethod.annotate(Override.class); copyBuilderConvenienceMethod.annotate(Override.class); } return copyBuilderMethod; }
JMethod generateBuildMethod(final JMethod initMethod) { final JMethod buildMethod = this.builderClass.raw.method(JMod.PUBLIC, this.definedClass, this.settings.getBuildMethodName()); if (!(this.builderClass.type._extends() == null || this.builderClass.type._extends().name().equals("java.lang.Object"))) { buildMethod.annotate(Override.class); } if (this.implement) { final JExpression buildExpression = JExpr._this().invoke(initMethod).arg(JExpr._new(this.definedClass)); if (this.settings.isCopyAlways()) { buildMethod.body()._return(buildExpression); } else if (this.definedClass.isAbstract()) { buildMethod.body()._return(JExpr.cast(this.definedClass, this.storedValueField)); } else { final JConditional jConditional = buildMethod.body()._if(this.storedValueField.eq(JExpr._null())); jConditional._then()._return(buildExpression); jConditional._else()._return(JExpr.cast(this.definedClass, this.storedValueField)); } } return buildMethod; }
if (!clazz.implClass.isAbstract()) { JDefinedClass builderClass; if ((builderClass = addBuilderClass(clazz, declaredFields, superclassFields)) == null) { if (clazz.getSuperClass() != null) { clazz.getSuperClass().implClass.mods().setFinal(false); } else if (clazz.implClass.isAbstract()) { clazz.implClass.mods().setFinal(false);
generateCopyToMethod(false); generateNewCopyBuilderMethod(false); if (this.implement && !this.definedClass.isAbstract()) { generateNewBuilderMethod(); generateCopyOfMethod(this.typeOutline, false); generateCopyToMethod(true); generateNewCopyBuilderMethod(true); if (this.implement && !this.definedClass.isAbstract()) { final JMethod partialCopyOfMethod = generateCopyOfMethod(this.typeOutline, true); generateConveniencePartialCopyMethod(this.typeOutline, partialCopyOfMethod, this.pluginContext.copyExceptMethodName, this.pluginContext.excludeConst);
void generateCopyConstructor(final boolean partial) { final JDefinedClass definedClass = this.classOutline.implClass; final JMethod constructor = definedClass.constructor(definedClass.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); final JVar otherParam = constructor.param(JMod.FINAL, this.classOutline.implClass, DeepCopyGenerator.OTHER_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(constructor, partial); final JDocComment docComment = constructor.javadoc(); docComment.append(getMessage("copyConstructor.javadoc.desc", definedClass.name())); docComment.addParam(otherParam).append(getMessage("copyConstructor.javadoc.param.other", definedClass.name())); if(partial) { docComment.addParam(cloneGenerator.getPropertyTreeParam()).append(getMessage("copyConstructor.javadoc.param.propertyPath", definedClass.name())); docComment.addParam(cloneGenerator.getPropertyTreeUseParam()).append(getMessage("copyConstructor.javadoc.param.propertyPathUse", definedClass.name())); } if (this.classOutline.getSuperClass() != null) { constructor.body().add(cloneGenerator.generatePartialArgs(this.pluginContext._super().arg(otherParam))); } final JBlock body = constructor.body(); generateFieldCopyExpressions(cloneGenerator, body, JExpr._this(), otherParam); }
final void generateCopyConstructor(final boolean partial) { final JMethod constructor = this.builderClass.raw.constructor(this.builderClass.raw.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); final JVar parentBuilderParam = constructor.param(JMod.FINAL, this.builderClass.typeParam, BuilderGenerator.PARENT_BUILDER_PARAM_NAME); final JVar otherParam = constructor.param(JMod.FINAL, this.typeOutline.getImplClass(), BuilderGenerator.OTHER_PARAM_NAME); final JVar copyParam = constructor.param(JMod.FINAL, this.pluginContext.codeModel.BOOLEAN, BuilderGenerator.COPY_FLAG_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(constructor, partial); if (this.typeOutline.getSuperClass() != null) { constructor.body().add(cloneGenerator.generatePartialArgs(this.pluginContext._super().arg(parentBuilderParam).arg(otherParam).arg(copyParam))); } else { constructor.body().assign(JExpr._this().ref(this.parentBuilderField), parentBuilderParam); } final JConditional ifNullStmt = constructor.body()._if(otherParam.ne(JExpr._null())); final JBlock body; if (!this.settings.isCopyAlways() && this.typeOutline.getSuperClass() == null) { final JConditional ifCopyStmt = ifNullStmt._then()._if(copyParam); ifCopyStmt._else().assign(this.storedValueField, otherParam); ifNullStmt._else().assign(this.storedValueField, JExpr._null()); body = ifCopyStmt._then(); body.assign(this.storedValueField, JExpr._null()); } else { body = ifNullStmt._then(); } generateFieldCopyExpressions(cloneGenerator, body, JExpr._this(), otherParam); }
JBlock body = cloneMethod.body(); if (impl.isAbstract()) { body._return(JExpr._this());