
org.umlg.javageneration.util.PropertyWrapper Maven / Gradle / Ivy
package org.umlg.javageneration.util;
import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.uml2.uml.*;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;
import org.umlg.framework.ModelLoader;
import org.umlg.java.metamodel.OJPathName;
import org.umlg.javageneration.validation.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class PropertyWrapper extends MultiplicityWrapper implements Property {
private Property property;
private boolean recursive;
private boolean indexed;
private boolean refined;
public static PropertyWrapper from(Property sourceProperty) {
return new PropertyWrapper(sourceProperty);
}
public PropertyWrapper(Property property) {
super(property);
this.property = property;
}
public String asJavaPrimiteType() {
if (!isPrimitive()) {
throw new IllegalStateException("PropertyWrapper.asJavaPrimitive may only be called on a PrimitiveType, found " + toString());
}
switch (getType().getName()) {
case "Boolean":
return "boolean";
case "Integer":
return "int";
case "Real":
return "double";
case "String":
return "String";
case "UnlimitedNatural":
return "int";
case "boolean":
return "boolean";
case "int":
return "int";
case "float":
return "float";
case "double":
return "double";
case "long":
return "long";
case "byte":
return "byte";
default:
throw new IllegalStateException("Unknown Primitive, found " + getType().getName());
}
}
public boolean isInverseUnique() {
if (getOtherEnd() != null) {
return new PropertyWrapper(getOtherEnd()).isUnique();
} else {
return false;
}
}
public boolean isDataType() {
return getType() instanceof DataType;
}
public boolean needsLookup() {
return !isComposite() && !(getType() instanceof Enumeration)
&& !isDerived() && !isQualifier() && getOtherEnd() != null
&& !(getOtherEnd().getType() instanceof Enumeration)
&& !getOtherEnd().isComposite()
&& !isRefined();
}
public boolean hasLookup() {
if (!isComposite() && !(getType() instanceof Enumeration) && !isDerived() && !isQualifier() && getOtherEnd() != null && !(getOtherEnd().getType() instanceof Enumeration)
&& !getOtherEnd().isComposite()) {
return true;
} else {
return false;
}
}
public boolean isInverseComposite() {
if (getOtherEnd() != null) {
return new PropertyWrapper(getOtherEnd()).isComposite();
} else {
return false;
}
}
public boolean hasQualifiers() {
return !this.property.getQualifiers().isEmpty();
}
public boolean isQualified() {
return hasQualifiers();
}
public boolean isInverseQualified() {
if (getOtherEnd() != null) {
return new PropertyWrapper(getOtherEnd()).isQualified();
} else {
return false;
}
}
public boolean isQualifier() {
Element owner = this.property.getOwner();
return owner instanceof Property && ((Property) owner).getQualifiers().contains(this.property);
}
public boolean hasOtherEnd() {
return getOtherEnd() != null;
}
public String getOclValue() {
if (!this.property.isDerived()) {
throw new IllegalStateException("getOclValue can only be called on a derived property");
}
return this.property.getDefaultValue().stringValue();
}
public boolean hasOclDefaultValue() {
ValueSpecification v = getDefaultValue();
if (v instanceof OpaqueExpression) {
OpaqueExpression expr = (OpaqueExpression) v;
return expr.getLanguages().contains("ocl") || expr.getLanguages().contains("OCL");
} else {
return false;
}
}
public boolean hasJavaDefaultValue() {
ValueSpecification v = getDefaultValue();
if (v instanceof OpaqueExpression) {
OpaqueExpression expr = (OpaqueExpression) v;
return expr.getLanguages().contains("java") || expr.getLanguages().contains("JAVA");
} else {
return false;
}
}
public String getOclDerivedValue() {
if (!hasOclDefaultValue()) {
throw new IllegalStateException(String.format("Property %s does not have a default value", new Object[]{this.getName()}));
}
StringBuilder sb = new StringBuilder();
if (isQualified()) {
// Find the derived property on the qualified context
Property owner = (Property) getOwner();
Property derived = null;
for (Element e : owner.getType().getOwnedElements()) {
if (e instanceof Property && ((NamedElement) e).getName().equals(getName())) {
derived = (Property) e;
}
}
sb.append(PropertyWrapper.getOclDerivedValue(derived));
} else {
sb.append(PropertyWrapper.getOclDerivedValue(this.property));
}
return sb.toString();
}
private static String getOclDerivedValue(Property p) {
PropertyWrapper pWrap = new PropertyWrapper(p);
StringBuilder sb = new StringBuilder();
sb.append("package ");
sb.append(Namer.nameIncludingModel(pWrap.getOwningType().getNearestPackage()).replace(".", "::"));
sb.append("\n context ");
if (pWrap.getOwner() instanceof Association) {
sb.append(((Association) pWrap.getOwner()).getName());
// sb.append("::");
// sb.append(pWrap.getName());
} else {
sb.append(pWrap.getOwningType().getName());
}
sb.append("::");
sb.append(pWrap.getName());
sb.append(" : ");
if (pWrap.isMany()) {
sb.append(UmlgGenerationUtil.getCollectionInterface(pWrap));
sb.append("(");
sb.append(pWrap.getType().getQualifiedName());
sb.append(")");
} else {
sb.append(pWrap.getType().getQualifiedName());
}
sb.append("\n");
sb.append(" derive: ");
sb.append(pWrap.getDefaultValue().stringValue());
sb.append("\n");
sb.append("endpackage");
return sb.toString();
}
public String getJavaDefaultValue() {
return getDefaultValue().toString();
}
public String getOclDefaultValue() {
if (!hasOclDefaultValue()) {
throw new IllegalStateException(String.format("Property %s does not have a default value", new Object[]{this.getName()}));
}
StringBuilder sb = new StringBuilder();
if (isQualified()) {
// Find the derived property on the qualified context
Property owner = (Property) getOwner();
Property derived = null;
for (Element e : owner.getType().getOwnedElements()) {
if (e instanceof Property && ((NamedElement) e).getName().equals(getName())) {
derived = (Property) e;
}
}
sb.append(getOclDefaultValue(derived));
} else {
sb.append(getOclDefaultValue(this.property));
}
return sb.toString();
}
private String getOclDefaultValue(Property p) {
PropertyWrapper pWrap = new PropertyWrapper(p);
StringBuilder sb = new StringBuilder();
sb.append("package ");
sb.append(Namer.nameIncludingModel(pWrap.getOwningType().getNearestPackage()).replace(".", "::"));
sb.append("\ncontext ");
sb.append(pWrap.getOwningType().getName());
sb.append("::");
sb.append(getName());
sb.append("\n");
sb.append("init: ");
sb.append(pWrap.getDefaultValue().stringValue());
sb.append("\n");
sb.append("endpackage");
return sb.toString();
}
public PropertyWrapper getQualifierCorrespondingQualifierStereotypedProperty() {
PropertyWrapper result = null;
if (!isQualifier()) {
throw new IllegalStateException("getQualifierCorrespondingQualifierStereotypedProperty can only be called on a qualifier");
}
Property owner = (Property) getOwner();
Stereotype qualifierVisitor = ModelLoader.INSTANCE.findStereotype("QualifierListener");
for (Element e : UmlgClassOperations.getAllProperties((Class) owner.getType())) {
if (e instanceof Property) {
Property p = (Property) e;
if (p.isStereotypeApplied(qualifierVisitor)) {
List qualifierTemps = (List) p.getValue(qualifierVisitor, "qualifier");
if (qualifierTemps.isEmpty()) {
throw new IllegalStateException(String.format("Property %s QualifierVisitor stereotype does not have its qualifier property set!", new Object[]{p.getQualifiedName()}));
}
if (qualifierTemps.contains(this.property)) {
result = new PropertyWrapper(p);
break;
}
}
}
}
return result;
}
/**
* Validate that a qualifier has only one corresponding stereotyped property on its owning property's type
*/
public void validateQualifierCorrespondingQualifierStereotypedProperty() {
if (!isQualifier()) {
throw new IllegalStateException("getQualifierCorrespondingQualifierStereotypedProperty can only be called on a qualifier");
}
Property correspondingProperty = null;
Property owner = (Property) getOwner();
Stereotype qualifierVisitor = ModelLoader.INSTANCE.findStereotype("QualifierListener");
for (Element e : owner.getType().getOwnedElements()) {
if (e instanceof Property) {
Property p = (Property) e;
if (p.isStereotypeApplied(qualifierVisitor)) {
List qualifierTemps = (List) p.getValue(qualifierVisitor, "qualifier");
if (correspondingProperty != null && qualifierTemps.contains(this.property)) {
throw new IllegalStateException(String.format("Qualifier %s has more than one corresponding QualifierVisitor stereotype. %s and %s ",
new Object[]{this.getQualifiedName(), correspondingProperty.getQualifiedName(), p.getQualifiedName()}));
} else if (qualifierTemps.contains(this.property)) {
correspondingProperty = p;
}
}
}
}
}
public OJPathName getQualifierContextPathName() {
if (isQualifier()) {
throw new IllegalStateException("getQualifierContextPathName can not only be called on a qualifier");
}
if (!hasQualifiers()) {
throw new IllegalStateException("getQualifierContextPathName can not only be called on a qualified property");
}
return UmlgClassOperations.getPathName(getType());
}
public Type getQualifierContext() {
if (!isQualifier()) {
throw new IllegalStateException("getQualifierContext can only be called on a qualifier");
}
Property owner = (Property) getOwner();
return owner.getType();
}
public boolean hasQualifierCorrespondingQualifierVisitorStereotypedProperty() {
if (!isQualifier()) {
throw new IllegalStateException("getCorrespondingDerivedProperty can only be called on a qualifier");
}
return getQualifierCorrespondingQualifierStereotypedProperty() != null;
}
public String getQualifiedGetterName() {
return "getQualifierFor" + StringUtils.capitalize(getName());
}
public String getQualifiedNameFor(List qualifers) {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (PropertyWrapper q : qualifers) {
if (!first) {
sb.append("and");
}
sb.append(StringUtils.capitalize(q.getName()));
first = false;
}
return getter() + "For" + sb.toString();
}
public String getQualifiedNameForPartial(List qualifers) {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (PropertyWrapper q : qualifers) {
if (!first) {
sb.append("and");
}
sb.append(StringUtils.capitalize(q.getName()));
first = false;
}
return getter() + "ForPartial" + sb.toString();
}
public Property getProperty() {
return property;
}
public String getTumlRuntimePropertyEnum() {
return UmlgClassOperations.propertyEnumName(getOwningType()) + "." + fieldname();
}
/**
* Qualifier's corresponding property gets defaulted to make the ui work.
*
* @return
*/
public String getQualifierJippoDefaultValue() {
if (isString()) {
return "\"\"";
} else if (isBoolean()) {
return "false";
} else if (isInteger()) {
return "-1";
} else if (isDate()) {
return "LocalDate.now()";
} else if (isEnumeration()) {
Enumeration enumeration = (Enumeration) getType();
String name = Namer.qualifiedName(enumeration);
return name + "." + enumeration.getOwnedLiterals().get(0).getName();
} else {
throw new IllegalStateException(String.format("Qualified property %s is a %s, this is not supported for default values", new String[]{getQualifiedName(), getType().getQualifiedName()}));
}
}
public String getDefaultValueAsJava() {
ValueSpecification v = getDefaultValue();
if (v instanceof OpaqueExpression) {
if (hasOclDefaultValue()) {
return getOclDefaultValue();
} else {
return getDefaultValue().stringValue();
}
} else if (v instanceof LiteralString) {
if (!UmlgPropertyOperations.isString(getType())) {
//TODO move validation to some collector to show the user all validation failures in one go
throw new IllegalStateException(String.format("Property %s has a LiteralString default value but is of type %s. This is illegal!", getQualifiedName(), getType().getQualifiedName()));
}
LiteralString expr = (LiteralString) v;
String result = expr.getValue();
if (result != null) {
return "\"" + result.replaceAll("^\"|\"$", "") + "\"";
} else {
return "\"\"";
}
} else if (v instanceof LiteralReal) {
LiteralReal literalReal = (LiteralReal) v;
return String.valueOf(literalReal.getValue() + "D");
} else if (v instanceof LiteralInteger) {
LiteralInteger literalInteger = (LiteralInteger) v;
return String.valueOf(literalInteger.getValue());
} else if (v instanceof LiteralUnlimitedNatural) {
LiteralUnlimitedNatural literalUnlimitedNatural = (LiteralUnlimitedNatural) v;
return String.valueOf(literalUnlimitedNatural.getValue());
} else if (v instanceof LiteralBoolean) {
LiteralBoolean literalBoolean = (LiteralBoolean) v;
return String.valueOf(literalBoolean.isValue());
} else if (v instanceof LiteralNull) {
return "null";
} else if (v instanceof InstanceValue) {
InstanceValue instanceValue = (InstanceValue) v;
return UmlgClassOperations.getPathName(instanceValue.getType()).getTypeName() + "." + instanceValue.getInstance().getName();
} else {
throw new RuntimeException(String.format("ValueSpecification %s not supported", v.getClass().getSimpleName()));
}
}
public boolean isForQualifier() {
return !this.property.getOwner().getAppliedStereotypes().isEmpty();
}
public String toJson() {
if (isMany()) {
return "\\\"" + getName() + "\\\": \\\"\" + " + getter() + "() + \"\\\"";
} else {
return "\\\"" + getName() + "\\\": \\\"\" + " + getter() + "() + \"\\\"";
}
}
public boolean isComponent() {
return !this.property.isDerived() && this.property.getType() instanceof Classifier && this.property.isComposite()
&& this.property.getLower() >= 1;
}
public boolean isInverseOrdered() {
return getOtherEnd() != null && getOtherEnd().isOrdered();
}
public Type getOwningType() {
return UmlgPropertyOperations.getOwningType(this.property);
}
public boolean isControllingSide() {
return UmlgPropertyOperations.isControllingSide(this.property);
}
public String fieldname() {
return this.property.getName();
}
public String getter() {
if (!isDerived() && !isPrimitive() && !isDataType() && !isNavigable()) {
return UmlgPropertyOperations.internalGetter(this.property);
} else {
return UmlgPropertyOperations.getter(this.property);
}
}
public String finder() {
if (!isIndexed()) {
throw new IllegalStateException("Only indexed fields can have finder methods!");
} else {
return UmlgPropertyOperations.finder(this.property);
}
}
public String setter() {
// if (!isDerived() && !isPrimitive() && !isDataType() && !isNavigable()) {
// return UmlgPropertyOperations.internalSetter(this.property);
// } else {
return UmlgPropertyOperations.setter(this.property);
// }
}
public String validator() {
return UmlgPropertyOperations.validator(this.property);
}
public String checkConstraint(Constraint constraint) {
return UmlgPropertyOperations.checkConstraint(this.property, constraint);
}
public boolean isPrimitive() {
return UmlgPropertyOperations.isPrimitive(this.property);
}
public boolean isEnumeration() {
return UmlgPropertyOperations.isEnumeration(this.property);
}
public boolean isACUnique() {
return isACManyToOne() || isACOneToOne();
}
public boolean isACMany() {
return false;
}
public boolean isACOneToMany() {
return false;
}
public boolean isACManyToMany() {
return false;
}
public boolean isACManyToOne() {
return UmlgPropertyOperations.isManyToOne(this.property);
}
public boolean isACOneToOne() {
//Association classes have a manyToOne relationship with bags and lists
return ((isOneToMany() && isUnique()) || isOneToOne());
}
public boolean isOneToMany() {
return UmlgPropertyOperations.isOneToMany(this.property);
}
public boolean isManyToOne() {
return UmlgPropertyOperations.isManyToOne(this.property);
}
public boolean isManyToMany() {
return UmlgPropertyOperations.isManyToMany(this.property);
}
public boolean isOneToOne() {
return UmlgPropertyOperations.isOneToOne(this.property);
}
public String adder() {
return UmlgPropertyOperations.adder(this.property);
}
public String adderIgnoreInverse() {
return UmlgPropertyOperations.adder(this.property) + "IgnoreInverse";
}
public String remover() {
return UmlgPropertyOperations.remover(this.property);
}
public String clearer() {
return UmlgPropertyOperations.clearer(this.property);
}
public String internalRemover() {
return UmlgPropertyOperations.internalRemover(this.property);
}
public String internalAdder() {
return UmlgPropertyOperations.internalAdder(this.property);
}
public OJPathName javaBaseTypePath() {
return UmlgPropertyOperations.getTypePath(this.property);
}
public OJPathName javaAuditBaseTypePath() {
if (!isPrimitive() && !isEnumeration()) {
return UmlgPropertyOperations.getTypePath(this.property).appendToTail("Audit");
} else {
return UmlgPropertyOperations.getTypePath(this.property);
}
}
public OJPathName javaImplTypePath() {
return UmlgPropertyOperations.getDefaultTinkerCollection(this.property);
}
/*
* Attempting set semantics so the path is always a collection Call
* javaBaseTypePath to get the type of set This method return umlg special
* collection interface
*/
public OJPathName javaTumlTypePath() {
return javaTumlTypePath(false);
}
/*
* Attempting set semantics so the path is always a collection Call
* javaBaseTypePath to get the type of set This method return umlg special
* collection interface
*/
public OJPathName javaTumlTypePath(boolean ignoreAssociationClass) {
OJPathName fieldType;
if (isOrdered() && isUnique()) {
if (hasQualifiers() && !isDerived()) {
fieldType = UmlgCollectionKindEnum.QUALIFIED_ORDERED_SET.getInterfacePathName();
} else {
if (ignoreAssociationClass || !isMemberOfAssociationClass()) {
fieldType = UmlgCollectionKindEnum.ORDERED_SET.getInterfacePathName();
} else {
fieldType = UmlgCollectionKindEnum.ASSOCIATION_CLASS_ORDERED_SET.getInterfacePathName();
}
}
} else if (isOrdered() && !isUnique()) {
if (hasQualifiers() && !isDerived()) {
fieldType = UmlgCollectionKindEnum.QUALIFIED_SEQUENCE.getInterfacePathName();
} else {
if (ignoreAssociationClass || !isMemberOfAssociationClass()) {
fieldType = UmlgCollectionKindEnum.SEQUENCE.getInterfacePathName();
} else {
fieldType = UmlgCollectionKindEnum.ASSOCIATION_CLASS_SEQUENCE.getInterfacePathName();
}
}
} else if (!isOrdered() && !isUnique()) {
if (hasQualifiers() && !isDerived()) {
fieldType = UmlgCollectionKindEnum.QUALIFIED_BAG.getInterfacePathName();
} else {
if (ignoreAssociationClass || !isMemberOfAssociationClass()) {
fieldType = UmlgCollectionKindEnum.BAG.getInterfacePathName();
} else {
fieldType = UmlgCollectionKindEnum.ASSOCIATION_CLASS_BAG.getInterfacePathName();
}
}
} else if (!isOrdered() && isUnique()) {
if (hasQualifiers() && !isDerived()) {
fieldType = UmlgCollectionKindEnum.QUALIFIED_SET.getInterfacePathName();
} else {
if (ignoreAssociationClass || !isMemberOfAssociationClass()) {
fieldType = UmlgCollectionKindEnum.SET.getInterfacePathName();
} else {
fieldType = UmlgCollectionKindEnum.ASSOCIATION_CLASS_SET.getInterfacePathName();
}
}
} else {
throw new RuntimeException("wtf");
}
fieldType.addToGenerics(javaBaseTypePath());
if (!ignoreAssociationClass && isMemberOfAssociationClass()) {
fieldType.addToGenerics(getAssociationClassPathName());
}
return fieldType;
}
/*
* Attempting set semantics so the path is always a collection Call
* javaBaseTypePath to get the type of set
*/
public OJPathName javaTypePath() {
OJPathName fieldType;
if (!isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.SET.getInterfacePathName();
} else if (isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.SEQUENCE.getInterfacePathName();
} else if (!isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.BAG.getInterfacePathName();
} else if (isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.ORDERED_SET.getInterfacePathName();
} else {
throw new RuntimeException("wtf");
}
fieldType.addToGenerics(javaBaseTypePath());
return fieldType;
}
public OJPathName javaTypePathWithAssociationClass() {
OJPathName fieldType;
if (!isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.SET.getInterfacePathName();
} else if (isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.SEQUENCE.getInterfacePathName();
} else if (!isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.BAG.getInterfacePathName();
} else if (isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.ORDERED_SET.getInterfacePathName();
} else {
throw new RuntimeException("wtf");
}
fieldType.addToGenerics(getAssociationClassPair());
return fieldType;
}
public OJPathName getAssociationClassPair() {
OJPathName pair = UmlgGenerationUtil.Pair.getCopy();
pair.addToGenerics(javaBaseTypePath()).addToGenerics(UmlgClassOperations.getPathName(getAssociationClass()));
return pair;
}
public String getAssociationClassFakePropertyName() {
if (!isMemberOfAssociationClass()) {
throw new IllegalStateException("Can not call getAssociationClassFakePropertyName on a property that does not belong to an AssociationClass!");
}
return UmlgClassOperations.getPathName(getAssociationClass()).getLast() + "_" + fieldname();
}
public String getAssociationClassName() {
if (!isMemberOfAssociationClass()) {
throw new IllegalStateException("Can not call getAssociationClassFakePropertyName on a property that does not belong to an AssociationClass!");
}
return UmlgClassOperations.getPathName(getAssociationClass()).getLast();
}
public String associationClassGetter() {
if (!isMemberOfAssociationClass()) {
throw new IllegalStateException("Can not call associationClassGetter on a property that is not a member end of an association class. Property = " + getQualifiedName());
}
return "get" + getAssociationClassFakePropertyName();
}
public String associationClassGetterForProperty() {
if (!isMemberOfAssociationClass()) {
throw new IllegalStateException("Can not call associationClassGetterForProperty on a property that is not a member end of an association class. Property = " + getQualifiedName());
}
return "get" + getAssociationClassFakePropertyName() + "_" + getName();
}
public String associationClassMoverForProperty() {
if (!isMemberOfAssociationClass()) {
throw new IllegalStateException("Can not call associationClassMoverForProperty on a property that is not a member end of an association class. Property = " + getQualifiedName());
}
return "move" + StringUtils.capitalize(getName());
}
public OJPathName javaTumlMemoryTypePath() {
OJPathName memoryCollectionPathName;
if (isQualified()) {
memoryCollectionPathName = UmlgCollectionKindEnum.from(this).getQualifiedMemoryCollection();
} else {
memoryCollectionPathName = UmlgCollectionKindEnum.from(this).getMemoryCollection();
}
memoryCollectionPathName.addToGenerics(javaBaseTypePath());
return memoryCollectionPathName;
}
public OJPathName javaAuditTypePath() {
OJPathName fieldType;
if (!isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.SET.getInterfacePathName();
} else if (isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.SEQUENCE.getInterfacePathName();
} else if (!isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.BAG.getInterfacePathName();
} else if (isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.ORDERED_SET.getInterfacePathName();
} else {
throw new RuntimeException("wtf");
}
fieldType.addToGenerics(javaAuditBaseTypePath());
return fieldType;
}
public String emptyCollection() {
if (!isOrdered() && isUnique()) {
return "UmlgCollections.emptySet()";
} else if (isOrdered() && !isUnique()) {
return "UmlgCollections.emptySequence()";
} else if (!isOrdered() && !isUnique()) {
return "UmlgCollections.emptyBag()";
} else if (isOrdered() && isUnique()) {
return "UmlgCollections.emptyOrderedSet()";
} else {
throw new RuntimeException("wtf");
}
}
public OJPathName javaClosableIteratorTypePath() {
OJPathName fieldType;
if (!isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.SET.getClosableIteratorPathName();
} else if (isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.SEQUENCE.getClosableIteratorPathName();
} else if (!isOrdered() && !isUnique()) {
fieldType = UmlgCollectionKindEnum.BAG.getClosableIteratorPathName();
} else if (isOrdered() && isUnique()) {
fieldType = UmlgCollectionKindEnum.ORDERED_SET.getClosableIteratorPathName();
} else {
throw new RuntimeException("wtf");
}
fieldType.addToGenerics(javaBaseTypePath());
return fieldType;
}
// public OJPathName javaAuditImplTypePath() {
// OJPathName impl = javaImplTypePath().getCopy();
// if (!impl.getGenerics().isEmpty()) {
// impl.getGenerics().get(0).appendToTail("Audit");
// }
// return impl;
// }
public String javaDefaultInitialisation(Classifier propertyConcreteOwner) {
return javaDefaultInitialisation(propertyConcreteOwner, false);
}
/*
* The property might be owned by an interface but the initialisation is for
* a realization on a BehavioredClassifier
*/
public String javaDefaultInitialisation(Classifier propertyConcreteOwner, boolean ignoreAssociationClass) {
return UmlgPropertyOperations.getDefaultTinkerCollectionInitalisation(this.property, propertyConcreteOwner, ignoreAssociationClass).getExpression();
}
public String javaDefaultInitialisationForAssociationClass(Classifier propertyConcreteOwner) {
return javaDefaultInitialisationForAssociationClass(propertyConcreteOwner, false);
}
public String javaDefaultInitialisationForAssociationClass(Classifier propertyConcreteOwner, boolean withLoaded) {
return UmlgPropertyOperations.getDefaultTinkerCollectionInitalisationForAssociationClass(this.property, propertyConcreteOwner, withLoaded).getExpression();
}
public boolean isOne() {
return UmlgPropertyOperations.isOne(this.property);
}
/**
* Indicates the multipliticity as modelled. i.e. not the raw implied many on a qualified property
*
* @return
*/
public boolean isUnqualifiedOne() {
return UmlgPropertyOperations.isUnqualifiedOne(this.property);
}
public boolean isMany() {
return UmlgPropertyOperations.isMany(this.property);
}
public boolean isUnqualifiedMany() {
return UmlgPropertyOperations.isUnqualifiedMany(this.property);
}
public List getQualifiersAsPropertyWrappers() {
List result = new ArrayList();
for (Property q : this.property.getQualifiers()) {
result.add(new PropertyWrapper(q));
}
return result;
}
@Override
public boolean isReadOnly() {
return this.property.isReadOnly() || isDerived();
}
@Override
public void setIsReadOnly(boolean value) {
throw new RuntimeException("Not supported");
}
@Override
public boolean isStatic() {
return this.property.isStatic();
}
@Override
public void setIsStatic(boolean value) {
throw new RuntimeException("Not supported");
}
@Override
public EList getFeaturingClassifiers() {
return this.property.getFeaturingClassifiers();
}
@Override
public Classifier getFeaturingClassifier(String name) {
return this.property.getFeaturingClassifier(name);
}
@Override
public Classifier getFeaturingClassifier(String name, boolean ignoreCase, EClass eClass) {
return this.getFeaturingClassifier(name, ignoreCase, eClass);
}
@Override
public boolean isLeaf() {
return this.property.isLeaf();
}
@Override
public void setIsLeaf(boolean value) {
throw new RuntimeException("Not supported");
}
@Override
public EList getRedefinedElements() {
return this.property.getRedefinedElements();
}
@Override
public RedefinableElement getRedefinedElement(String name) {
return this.property.getRedefinedElement(name);
}
@Override
public RedefinableElement getRedefinedElement(String name, boolean ignoreCase, EClass eClass) {
return this.getRedefinedElement(name, ignoreCase, eClass);
}
@Override
public EList getRedefinitionContexts() {
return this.property.getRedefinitionContexts();
}
@Override
public Classifier getRedefinitionContext(String name) {
return this.getRedefinitionContext(name);
}
@Override
public Classifier getRedefinitionContext(String name, boolean ignoreCase, EClass eClass) {
return this.property.getRedefinitionContext(name, ignoreCase, eClass);
}
@Override
public boolean validateRedefinitionContextValid(DiagnosticChain diagnostics, Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy