1 17 package org.eclipse.emf.codegen.ecore.genmodel.impl; 18 19 20 import java.util.Collection ; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Set ; 28 29 import org.eclipse.emf.codegen.ecore.genmodel.GenClass; 30 import org.eclipse.emf.codegen.ecore.genmodel.GenDataType; 31 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature; 32 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 33 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation; 34 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; 35 import org.eclipse.emf.codegen.ecore.genmodel.GenPropertyKind; 36 import org.eclipse.emf.common.notify.Notification; 37 import org.eclipse.emf.common.notify.NotificationChain; 38 import org.eclipse.emf.common.util.EList; 39 40 import org.eclipse.emf.ecore.EAttribute; 41 import org.eclipse.emf.ecore.EClass; 42 import org.eclipse.emf.ecore.EClassifier; 43 import org.eclipse.emf.ecore.EDataType; 44 import org.eclipse.emf.ecore.EEnum; 45 import org.eclipse.emf.ecore.EModelElement; 46 import org.eclipse.emf.ecore.EReference; 47 import org.eclipse.emf.ecore.EStructuralFeature; 48 import org.eclipse.emf.ecore.ETypedElement; 49 import org.eclipse.emf.ecore.InternalEObject; 50 import org.eclipse.emf.ecore.impl.ENotificationImpl; 51 import org.eclipse.emf.ecore.util.EDataTypeUniqueEList; 52 import org.eclipse.emf.ecore.util.EcoreUtil; 53 import org.eclipse.emf.ecore.util.ExtendedMetaData; 54 import org.eclipse.emf.ecore.xml.type.XMLTypePackage; 55 56 57 78 public class GenFeatureImpl extends GenTypedElementImpl implements GenFeature 79 { 80 88 protected static final GenPropertyKind PROPERTY_EDEFAULT = GenPropertyKind.EDITABLE_LITERAL; 89 90 98 protected GenPropertyKind property = PROPERTY_EDEFAULT; 99 100 108 protected static final boolean NOTIFY_EDEFAULT = true; 109 110 118 protected boolean notify = NOTIFY_EDEFAULT; 119 120 128 protected static final boolean CHILDREN_EDEFAULT = false; 129 130 138 protected boolean children = CHILDREN_EDEFAULT; 139 140 148 protected static final boolean CREATE_CHILD_EDEFAULT = false; 149 150 158 protected boolean createChild = CREATE_CHILD_EDEFAULT; 159 160 167 protected boolean createChildESet = false; 168 169 177 protected static final String PROPERTY_CATEGORY_EDEFAULT = null; 178 179 187 protected String propertyCategory = PROPERTY_CATEGORY_EDEFAULT; 188 189 197 protected EList propertyFilterFlags = null; 198 199 207 protected static final String PROPERTY_DESCRIPTION_EDEFAULT = null; 208 209 217 protected String propertyDescription = PROPERTY_DESCRIPTION_EDEFAULT; 218 219 227 protected EStructuralFeature ecoreFeature = null; 228 229 234 protected GenFeatureImpl() 235 { 236 super(); 237 } 238 239 244 protected EClass eStaticClass() 245 { 246 return GenModelPackage.eINSTANCE.getGenFeature(); 247 } 248 249 254 public GenPropertyKind getProperty() 255 { 256 return property; 257 } 258 259 public boolean isProperty() 260 { 261 return property != GenPropertyKind.NONE_LITERAL; 262 } 263 264 269 public void setProperty(GenPropertyKind newProperty) 270 { 271 GenPropertyKind oldProperty = property; 272 property = newProperty == null ? PROPERTY_EDEFAULT : newProperty; 273 if (eNotificationRequired()) 274 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__PROPERTY, oldProperty, property)); 275 } 276 277 282 public boolean isNotify() 283 { 284 return notify; 285 } 286 287 292 public void setNotify(boolean newNotify) 293 { 294 boolean oldNotify = notify; 295 notify = newNotify; 296 if (eNotificationRequired()) 297 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__NOTIFY, oldNotify, notify)); 298 } 299 300 305 public boolean isChildren() 306 { 307 return children; 308 } 309 310 315 public void setChildren(boolean newChildren) 316 { 317 boolean oldChildren = children; 318 children = newChildren; 319 if (eNotificationRequired()) 320 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__CHILDREN, oldChildren, children)); 321 } 322 323 326 public boolean isCreateChild() 327 { 328 autoSetCreateChild(); 329 return isCreateChildGen(); 330 } 331 332 337 public boolean isCreateChildGen() 338 { 339 return createChild; 340 } 341 342 347 public void setCreateChild(boolean newCreateChild) 348 { 349 boolean oldCreateChild = createChild; 350 createChild = newCreateChild; 351 boolean oldCreateChildESet = createChildESet; 352 createChildESet = true; 353 if (eNotificationRequired()) 354 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__CREATE_CHILD, oldCreateChild, createChild, !oldCreateChildESet)); 355 } 356 357 362 public void unsetCreateChild() 363 { 364 boolean oldCreateChild = createChild; 365 boolean oldCreateChildESet = createChildESet; 366 createChild = CREATE_CHILD_EDEFAULT; 367 createChildESet = false; 368 if (eNotificationRequired()) 369 eNotify(new ENotificationImpl(this, Notification.UNSET, GenModelPackage.GEN_FEATURE__CREATE_CHILD, oldCreateChild, CREATE_CHILD_EDEFAULT, oldCreateChildESet)); 370 } 371 372 375 public boolean isSetCreateChild() 376 { 377 autoSetCreateChild(); 378 return isSetCreateChildGen(); 379 } 380 381 386 public boolean isSetCreateChildGen() 387 { 388 return createChildESet; 389 } 390 391 396 public String getPropertyCategory() 397 { 398 return propertyCategory; 399 } 400 401 406 public void setPropertyCategory(String newPropertyCategory) 407 { 408 String oldPropertyCategory = propertyCategory; 409 propertyCategory = newPropertyCategory; 410 if (eNotificationRequired()) 411 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY, oldPropertyCategory, propertyCategory)); 412 } 413 414 419 public EList getPropertyFilterFlags() 420 { 421 if (propertyFilterFlags == null) 422 { 423 propertyFilterFlags = new EDataTypeUniqueEList(String .class, this, GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS); 424 } 425 return propertyFilterFlags; 426 } 427 428 433 public String getPropertyDescription() 434 { 435 return propertyDescription; 436 } 437 438 443 public void setPropertyDescription(String newPropertyDescription) 444 { 445 String oldPropertyDescription = propertyDescription; 446 propertyDescription = newPropertyDescription; 447 if (eNotificationRequired()) 448 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION, oldPropertyDescription, propertyDescription)); 449 } 450 451 protected void autoSetCreateChild() 452 { 453 if (!isSetCreateChildGen()) 454 { 455 setCreateChild(isChildren()); 456 } 457 } 458 459 464 public GenClass getGenClass() 465 { 466 if (eContainerFeatureID != GenModelPackage.GEN_FEATURE__GEN_CLASS) return null; 467 return (GenClass)eContainer; 468 } 469 470 475 public void setGenClass(GenClass newGenClass) 476 { 477 if (newGenClass != eContainer || (eContainerFeatureID != GenModelPackage.GEN_FEATURE__GEN_CLASS && newGenClass != null)) 478 { 479 if (EcoreUtil.isAncestor(this, newGenClass)) 480 throw new IllegalArgumentException ("Recursive containment not allowed for " + toString()); 481 NotificationChain msgs = null; 482 if (eContainer != null) 483 msgs = eBasicRemoveFromContainer(msgs); 484 if (newGenClass != null) 485 msgs = ((InternalEObject)newGenClass).eInverseAdd(this, GenModelPackage.GEN_CLASS__GEN_FEATURES, GenClass.class, msgs); 486 msgs = eBasicSetContainer((InternalEObject)newGenClass, GenModelPackage.GEN_FEATURE__GEN_CLASS, msgs); 487 if (msgs != null) msgs.dispatch(); 488 } 489 else if (eNotificationRequired()) 490 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__GEN_CLASS, newGenClass, newGenClass)); 491 } 492 493 498 public EStructuralFeature getEcoreFeature() 499 { 500 if (ecoreFeature != null && ecoreFeature.eIsProxy()) 501 { 502 EStructuralFeature oldEcoreFeature = ecoreFeature; 503 ecoreFeature = (EStructuralFeature)eResolveProxy((InternalEObject)ecoreFeature); 504 if (ecoreFeature != oldEcoreFeature) 505 { 506 if (eNotificationRequired()) 507 eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_FEATURE__ECORE_FEATURE, oldEcoreFeature, ecoreFeature)); 508 } 509 } 510 return ecoreFeature; 511 } 512 513 518 public EStructuralFeature basicGetEcoreFeature() 519 { 520 return ecoreFeature; 521 } 522 523 528 public void setEcoreFeature(EStructuralFeature newEcoreFeature) 529 { 530 EStructuralFeature oldEcoreFeature = ecoreFeature; 531 ecoreFeature = newEcoreFeature; 532 if (eNotificationRequired()) 533 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_FEATURE__ECORE_FEATURE, oldEcoreFeature, ecoreFeature)); 534 } 535 536 541 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 542 { 543 if (featureID >= 0) 544 { 545 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 546 { 547 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 548 if (eContainer != null) 549 msgs = eBasicRemoveFromContainer(msgs); 550 return eBasicSetContainer(otherEnd, GenModelPackage.GEN_FEATURE__GEN_CLASS, msgs); 551 default: 552 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 553 } 554 } 555 if (eContainer != null) 556 msgs = eBasicRemoveFromContainer(msgs); 557 return eBasicSetContainer(otherEnd, featureID, msgs); 558 } 559 560 565 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 566 { 567 if (featureID >= 0) 568 { 569 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 570 { 571 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 572 return eBasicSetContainer(null, GenModelPackage.GEN_FEATURE__GEN_CLASS, msgs); 573 default: 574 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 575 } 576 } 577 return eBasicSetContainer(null, featureID, msgs); 578 } 579 580 585 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 586 { 587 if (eContainerFeatureID >= 0) 588 { 589 switch (eContainerFeatureID) 590 { 591 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 592 return eContainer.eInverseRemove(this, GenModelPackage.GEN_CLASS__GEN_FEATURES, GenClass.class, msgs); 593 default: 594 return eDynamicBasicRemoveFromContainer(msgs); 595 } 596 } 597 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 598 } 599 600 605 public Object eGet(EStructuralFeature eFeature, boolean resolve) 606 { 607 switch (eDerivedStructuralFeatureID(eFeature)) 608 { 609 case GenModelPackage.GEN_FEATURE__PROPERTY: 610 return getProperty(); 611 case GenModelPackage.GEN_FEATURE__NOTIFY: 612 return isNotify() ? Boolean.TRUE : Boolean.FALSE; 613 case GenModelPackage.GEN_FEATURE__CHILDREN: 614 return isChildren() ? Boolean.TRUE : Boolean.FALSE; 615 case GenModelPackage.GEN_FEATURE__CREATE_CHILD: 616 return isCreateChild() ? Boolean.TRUE : Boolean.FALSE; 617 case GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY: 618 return getPropertyCategory(); 619 case GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS: 620 return getPropertyFilterFlags(); 621 case GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION: 622 return getPropertyDescription(); 623 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 624 return getGenClass(); 625 case GenModelPackage.GEN_FEATURE__ECORE_FEATURE: 626 if (resolve) return getEcoreFeature(); 627 return basicGetEcoreFeature(); 628 } 629 return eDynamicGet(eFeature, resolve); 630 } 631 632 637 public boolean eIsSet(EStructuralFeature eFeature) 638 { 639 switch (eDerivedStructuralFeatureID(eFeature)) 640 { 641 case GenModelPackage.GEN_FEATURE__PROPERTY: 642 return property != PROPERTY_EDEFAULT; 643 case GenModelPackage.GEN_FEATURE__NOTIFY: 644 return notify != NOTIFY_EDEFAULT; 645 case GenModelPackage.GEN_FEATURE__CHILDREN: 646 return children != CHILDREN_EDEFAULT; 647 case GenModelPackage.GEN_FEATURE__CREATE_CHILD: 648 return isSetCreateChild(); 649 case GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY: 650 return PROPERTY_CATEGORY_EDEFAULT == null ? propertyCategory != null : !PROPERTY_CATEGORY_EDEFAULT.equals(propertyCategory); 651 case GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS: 652 return propertyFilterFlags != null && !propertyFilterFlags.isEmpty(); 653 case GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION: 654 return PROPERTY_DESCRIPTION_EDEFAULT == null ? propertyDescription != null : !PROPERTY_DESCRIPTION_EDEFAULT.equals(propertyDescription); 655 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 656 return getGenClass() != null; 657 case GenModelPackage.GEN_FEATURE__ECORE_FEATURE: 658 return ecoreFeature != null; 659 } 660 return eDynamicIsSet(eFeature); 661 } 662 663 668 public void eSet(EStructuralFeature eFeature, Object newValue) 669 { 670 switch (eDerivedStructuralFeatureID(eFeature)) 671 { 672 case GenModelPackage.GEN_FEATURE__PROPERTY: 673 setProperty((GenPropertyKind)newValue); 674 return; 675 case GenModelPackage.GEN_FEATURE__NOTIFY: 676 setNotify(((Boolean )newValue).booleanValue()); 677 return; 678 case GenModelPackage.GEN_FEATURE__CHILDREN: 679 setChildren(((Boolean )newValue).booleanValue()); 680 return; 681 case GenModelPackage.GEN_FEATURE__CREATE_CHILD: 682 setCreateChild(((Boolean )newValue).booleanValue()); 683 return; 684 case GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY: 685 setPropertyCategory((String )newValue); 686 return; 687 case GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS: 688 getPropertyFilterFlags().clear(); 689 getPropertyFilterFlags().addAll((Collection )newValue); 690 return; 691 case GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION: 692 setPropertyDescription((String )newValue); 693 return; 694 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 695 setGenClass((GenClass)newValue); 696 return; 697 case GenModelPackage.GEN_FEATURE__ECORE_FEATURE: 698 setEcoreFeature((EStructuralFeature)newValue); 699 return; 700 } 701 eDynamicSet(eFeature, newValue); 702 } 703 704 709 public void eUnset(EStructuralFeature eFeature) 710 { 711 switch (eDerivedStructuralFeatureID(eFeature)) 712 { 713 case GenModelPackage.GEN_FEATURE__PROPERTY: 714 setProperty(PROPERTY_EDEFAULT); 715 return; 716 case GenModelPackage.GEN_FEATURE__NOTIFY: 717 setNotify(NOTIFY_EDEFAULT); 718 return; 719 case GenModelPackage.GEN_FEATURE__CHILDREN: 720 setChildren(CHILDREN_EDEFAULT); 721 return; 722 case GenModelPackage.GEN_FEATURE__CREATE_CHILD: 723 unsetCreateChild(); 724 return; 725 case GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY: 726 setPropertyCategory(PROPERTY_CATEGORY_EDEFAULT); 727 return; 728 case GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS: 729 getPropertyFilterFlags().clear(); 730 return; 731 case GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION: 732 setPropertyDescription(PROPERTY_DESCRIPTION_EDEFAULT); 733 return; 734 case GenModelPackage.GEN_FEATURE__GEN_CLASS: 735 setGenClass((GenClass)null); 736 return; 737 case GenModelPackage.GEN_FEATURE__ECORE_FEATURE: 738 setEcoreFeature((EStructuralFeature)null); 739 return; 740 } 741 eDynamicUnset(eFeature); 742 } 743 744 749 public String toString() 750 { 751 if (eIsProxy()) return super.toString(); 752 753 StringBuffer result = new StringBuffer (super.toString()); 754 result.append(" (property: "); 755 result.append(property); 756 result.append(", notify: "); 757 result.append(notify); 758 result.append(", children: "); 759 result.append(children); 760 result.append(", createChild: "); 761 if (createChildESet) result.append(createChild); else result.append("<unset>"); 762 result.append(", propertyCategory: "); 763 result.append(propertyCategory); 764 result.append(", propertyFilterFlags: "); 765 result.append(propertyFilterFlags); 766 result.append(", propertyDescription: "); 767 result.append(propertyDescription); 768 result.append(')'); 769 return result.toString(); 770 } 771 772 public ETypedElement getEcoreTypedElement() 773 { 774 return getEcoreFeature(); 775 } 776 777 public String getName() 778 { 779 return getEcoreFeature().getName(); 780 } 781 782 public String getCapName() 783 { 784 return capName(getName()); 785 } 786 787 public String getAccessorName() 788 { 789 return isMapEntryFeature() ? "Typed" + getCapName() : getCapName(); 790 } 791 792 public String getGetAccessor() 793 { 794 String capName = getCapName(); 795 if (isMapEntryFeature()) return "getTyped" + capName; 796 String result = isBooleanType() ? "is" + capName : "get" + ("Class".equals(capName) ? "Class_" : capName); 797 798 GenClass rootImplementsInterface = getGenModel().getRootImplementsInterfaceGenClass(); 799 if (rootImplementsInterface != null && !rootImplementsInterface.isEObject()) 800 { 801 for (Iterator i = rootImplementsInterface.getAllGenOperations().iterator(); i.hasNext(); ) 802 { 803 GenOperation genOperation = (GenOperation)i.next(); 804 if (genOperation.getName().equals(result) && 805 genOperation.getGenParameters().isEmpty() && 806 !genOperation.getType().equals(getType())) 807 { 808 result = result + "_"; 809 break; 810 } 811 } 812 } 813 814 return result; 815 } 816 817 public String getSafeName() 818 { 819 return safeName(uncapPrefixedName(getName())); 820 } 821 822 public String getSafeNameAsEObject() 823 { 824 String result = getSafeName(); 825 if (!isEObjectExtensionType()) 826 { 827 result = "((" + getGenModel().getImportedName("org.eclipse.emf.ecore.EObject") + ")" + result + ")"; 828 } 829 return result; 830 } 831 832 public String getFormattedName() 833 { 834 return format(getCapName(), ' ', null, false); 835 } 836 837 public String getUpperName() 838 { 839 return format(getName(), '_', null, false).toUpperCase(); 840 } 841 842 public String getUncapName() 843 { 844 return uncapPrefixedName(getName()); 845 } 846 847 public String getIsName() 848 { 849 String name = getName(); 850 if (name.startsWith("is") && name.length() > 2 && Character.isUpperCase(name.charAt(2))) 851 { 852 return name.substring(2); 853 } 854 else 855 { 856 return capName(name); 857 } 858 } 859 860 public GenPackage getGenPackage() 861 { 862 return getGenClass().getGenPackage(); 863 } 864 865 public String getFeatureAccessorName() 866 { 867 return getGenClass().getName() + "_" + getCapName(); 868 } 869 870 public String getQualifiedFeatureAccessorName() 871 { 872 return getGenPackage().getImportedPackageInterfaceName() + ".eINSTANCE.get" + getFeatureAccessorName(); 873 } 874 875 public String getMetaType() 876 { 877 String importedName = getImportedMetaType(); 878 return importedName.substring(importedName.lastIndexOf(".") + 1); 879 } 880 881 public String getImportedMetaType() 882 { 883 if (getEcoreFeature() instanceof EReference) 884 return getGenModel().getImportedName("org.eclipse.emf.ecore.EReference"); 885 else 886 return getGenModel().getImportedName("org.eclipse.emf.ecore.EAttribute"); 887 } 888 889 public String getFeatureKind() 890 { 891 String kind = 892 getEcoreFeature() instanceof EReference ? 893 isContains() ? 894 isJavaUtilMapEntry(getEcoreFeature().getEType().getInstanceClassName()) ? 895 "map" : 896 "containment reference" : 897 isContainer() ? "container reference" : "reference" : 898 "attribute"; 899 return 900 !"map".equals(kind) && getEcoreFeature().isMany() ? 901 kind + " list" : 902 kind; 903 } 904 905 public boolean isReferenceType() 906 { 907 return getEcoreFeature() instanceof EReference; 908 } 909 910 protected boolean isEObjectExtensionType() 911 { 912 return isReferenceType() && super.isEObjectExtensionType(); 913 } 914 915 protected boolean isEObjectType() 916 { 917 return isReferenceType() && super.isEObjectType(); 918 } 919 920 public boolean isMapType() 921 { 922 return !isContainer() && super.isMapType(); 923 } 924 925 public boolean isFlag() 926 { 927 return isBooleanType() && !isVolatile(); 928 } 929 930 public boolean isESetFlag() 931 { 932 return isUnsettable() && !isListType() && !isVolatile(); 933 } 934 935 public boolean isSetDefaultValue() 936 { 937 return getEcoreFeature().getDefaultValueLiteral() != null; 938 } 939 940 public String getDefaultValue() 941 { 942 if (!isSetDefaultValue()) return null; 943 return "\"" + getEcoreFeature().getDefaultValueLiteral() + "\""; 944 } 945 946 public String getStaticDefaultValue() 947 { 948 String defaultString = getEcoreFeature().getDefaultValueLiteral(); 949 EClassifier eType = getEcoreFeature().getEType(); 950 if (eType instanceof EDataType) 951 { 952 GenDataType genDataType = (GenDataType)findGenClassifier(eType); 953 return genDataType.getStaticValue(defaultString); 954 } 955 956 return "null"; 957 } 958 959 protected boolean isMapEntryFeature() 960 { 961 return getGenClass().isMapEntry() && ("key".equals(getName()) || "value".equals(getName())); 962 } 963 964 public boolean isContainer() 965 { 966 if (isReferenceType()) 967 { 968 EReference opposite = ((EReference)getEcoreFeature()).getEOpposite(); 969 return opposite != null && opposite.isContainment(); 970 } 971 return false; 972 } 973 974 public boolean isContains() 975 { 976 return isReferenceType() && ((EReference)getEcoreFeature()).isContainment(); 977 } 978 979 public boolean isBidirectional() 980 { 981 if (isReferenceType()) 982 { 983 EReference eReverseFeature = ((EReference)getEcoreFeature()).getEOpposite(); 984 return eReverseFeature != null; } 986 return false; 987 } 988 989 public GenFeature getReverse() 990 { 991 EReference eReverseFeature = ((EReference)getEcoreFeature()).getEOpposite(); 992 if (eReverseFeature != null) 993 { 994 EClass eReverseClass = (EClass)eReverseFeature.eContainer(); 995 GenClass genClass = findGenClass(eReverseClass); 996 if (genClass != null) 997 { 998 for (Iterator iter = genClass.getGenFeatures().iterator(); iter.hasNext(); ) 999 { 1000 GenFeature genFeature = (GenFeature)iter.next(); 1001 if (genFeature.getEcoreFeature() == eReverseFeature) 1002 { 1003 return genFeature; 1004 } 1005 } 1006 } 1007 } 1008 return null; 1009 } 1010 1011 public String getContainerClass() 1012 { 1013 return getGenClass().isDocumentRoot() ? "null" : getGenClass().getImportedInterfaceName() + ".class"; 1014 } 1015 1016 public String getDerivedFlag() 1017 { 1018 String result = !getEcoreFeature().isDerived() ? "!" : ""; 1019 return result + "IS_DERIVED"; 1020 } 1021 1022 public String getTransientFlag() 1023 { 1024 String result = !getEcoreFeature().isTransient() ? "!" : ""; 1025 return result + "IS_TRANSIENT"; 1026 } 1027 1028 public String getVolatileFlag() 1029 { 1030 String result = !getEcoreFeature().isVolatile() ? "!" : ""; 1031 return result + "IS_VOLATILE"; 1032 } 1033 1034 public String getChangeableFlag() 1035 { 1036 String result = !getEcoreFeature().isChangeable() ? "!" : ""; 1037 return result + "IS_CHANGEABLE"; 1038 } 1039 1040 public String getUnsettableFlag() 1041 { 1042 String result = !isUnsettable() ? "!" : ""; 1043 return result + "IS_UNSETTABLE"; 1044 } 1045 1046 public String getIDFlag() 1047 { 1048 String result = !isID() ? "!" : ""; 1049 return result + "IS_ID"; 1050 } 1051 1052 public String getContainmentFlag() 1053 { 1054 String result = !((EReference)getEcoreFeature()).isContainment() ? "!" : ""; 1055 return result + "IS_COMPOSITE"; 1056 } 1057 1058 public String getResolveProxiesFlag() 1059 { 1060 String result = !isResolveProxies() ? "!" : ""; 1061 return result + "IS_RESOLVE_PROXIES"; 1062 } 1063 1064 public boolean isResolveProxies() 1065 { 1066 EStructuralFeature eStructuralFeature = getEcoreFeature(); 1067 return !isContainer() && !isContains() && 1068 eStructuralFeature instanceof EReference && ((EReference)eStructuralFeature).isResolveProxies(); 1069 } 1070 1071 public boolean isVolatile() 1072 { 1073 1076 EReference eReverseFeature = isReferenceType() ? 1077 ((EReference)getEcoreFeature()).getEOpposite() : null; 1078 1079 return (getEcoreFeature().isVolatile() || 1080 (eReverseFeature != null && eReverseFeature.isVolatile())); 1081 } 1082 1083 public boolean isChangeable() 1084 { 1085 return getEcoreFeature().isChangeable(); 1086 } 1087 1088 public boolean isUnsettable() 1089 { 1090 EStructuralFeature eStructuralFeature = getEcoreFeature(); 1091 return eStructuralFeature.isUnsettable() && !isContainer(); 1092 } 1093 1094 public boolean isID() 1095 { 1096 EStructuralFeature eStructuralFeature = getEcoreFeature(); 1097 return eStructuralFeature instanceof EAttribute && ((EAttribute)eStructuralFeature).isID(); 1098 } 1099 public boolean isDerived() 1100 { 1101 return getEcoreFeature().isDerived(); 1102 } 1103 1104 public boolean hasDelegateFeature() 1105 { 1106 EStructuralFeature ecoreFeature = getEcoreFeature(); 1107 EClass ecoreClass = ecoreFeature.getEContainingClass(); 1108 EStructuralFeature mixedFeature = getExtendedMetaData().getMixedFeature(ecoreClass); 1109 return 1110 (mixedFeature != null && mixedFeature != ecoreFeature) || 1111 getExtendedMetaData().getGroup(ecoreFeature) != null; 1112 } 1113 1114 public GenFeature getDelegateFeature() 1115 { 1116 EStructuralFeature ecoreFeature = getEcoreFeature(); 1117 EClass ecoreClass = ecoreFeature.getEContainingClass(); 1118 EStructuralFeature eStructuralFeature = getExtendedMetaData().getGroup(ecoreFeature); 1119 if (eStructuralFeature == null) 1120 { 1121 eStructuralFeature = getExtendedMetaData().getMixedFeature(ecoreClass); 1122 } 1123 if (eStructuralFeature != null && eStructuralFeature != ecoreFeature) 1124 { 1125 return findGenFeature(eStructuralFeature); 1126 } 1127 else 1128 { 1129 return null; 1130 } 1131 } 1132 1133 1136 public List getDelegatedFeatures() 1137 { 1138 if (!isFeatureMapType()) return Collections.EMPTY_LIST; 1139 1140 GenClass genClass = getGenClass(); 1141 List delegated = new ArrayList (); 1142 1143 ExtendedMetaData extendedMetaData = getExtendedMetaData(); 1144 if (genClass.getMixedGenFeature() == this) 1145 { 1146 delegated.add(findGenFeature(XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Comment())); 1147 delegated.add(findGenFeature(XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text())); 1148 1149 if (!genClass.isDocumentRoot()) 1150 { 1151 delegated.add(findGenFeature(XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_CDATA())); 1152 } 1153 1154 for (Iterator iter = genClass.getGenFeatures().iterator(); iter.hasNext(); ) 1155 { 1156 GenFeature otherFeature = (GenFeature)iter.next(); 1157 if (otherFeature != this && otherFeature.isDerived() && 1158 extendedMetaData.getGroup(otherFeature.getEcoreFeature()) == null) 1159 { 1160 delegated.add(otherFeature); 1161 } 1162 } 1163 } 1164 else 1165 { 1166 switch (extendedMetaData.getFeatureKind(getEcoreFeature())) 1167 { 1168 case ExtendedMetaData.GROUP_FEATURE: 1169 { 1170 Set allDelegated = new HashSet (); 1171 Set qNames = new HashSet (); 1172 for (Iterator i = genClass.getGenFeatures().iterator(); i.hasNext(); ) 1173 { 1174 GenFeature otherFeature = (GenFeature)i.next(); 1175 if (otherFeature != this && otherFeature.isDerived() && 1176 extendedMetaData.getGroup(otherFeature.getEcoreFeature()) == getEcoreFeature()) 1177 { 1178 if (otherFeature.isChangeable()) 1179 { 1180 delegated.add(otherFeature); 1181 qNames.add 1182 (extendedMetaData.getNamespace(otherFeature.getEcoreFeature()) + "#" + 1183 extendedMetaData.getName(otherFeature.getEcoreFeature())); 1184 } 1185 allDelegated.add(otherFeature.getEcoreFeature()); 1186 } 1187 } 1188 1189 for (Iterator i = getGenModel().getAllGenAndUsedGenPackagesWithClassifiers().iterator(); i.hasNext(); ) 1190 { 1191 GenPackage genPackage = (GenPackage)i.next(); 1192 if (genPackage.hasDocumentRoot()) 1193 { 1194 GenClass documentRoot = findGenClass(extendedMetaData.getDocumentRoot(genPackage.getEcorePackage())); 1195 for (Iterator j = documentRoot.getGenFeatures().iterator(); j.hasNext(); ) 1196 { 1197 GenFeature otherFeature = (GenFeature)j.next(); 1198 if (otherFeature != this && 1199 otherFeature.isChangeable() && 1200 otherFeature.isDerived() && 1201 allDelegated.contains(extendedMetaData.getAffiliation(genClass.getEcoreClass(), otherFeature.getEcoreFeature()))) 1202 { 1203 if (qNames.add 1204 (extendedMetaData.getNamespace(otherFeature.getEcoreFeature()) + "#" + 1205 extendedMetaData.getName(otherFeature.getEcoreFeature()))) 1206 { 1207 delegated.add(otherFeature); 1208 } 1209 } 1210 } 1211 } 1212 } 1213 1214 break; 1215 } 1216 case ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE: 1217 case ExtendedMetaData.ELEMENT_WILDCARD_FEATURE: 1218 { 1219 for (Iterator i = getGenModel().getAllGenAndUsedGenPackagesWithClassifiers().iterator(); i.hasNext(); ) 1220 { 1221 GenPackage genPackage = (GenPackage)i.next(); 1222 if (genPackage.hasDocumentRoot()) 1223 { 1224 GenClass documentRoot = findGenClass(extendedMetaData.getDocumentRoot(genPackage.getEcorePackage())); 1225 for (Iterator j = documentRoot.getGenFeatures().iterator(); j.hasNext(); ) 1226 { 1227 GenFeature otherFeature = (GenFeature)j.next(); 1228 if (otherFeature != this && 1229 otherFeature.isChangeable() && 1230 otherFeature.isDerived() && 1231 extendedMetaData.getAffiliation(genClass.getEcoreClass(), otherFeature.getEcoreFeature()) == getEcoreFeature()) 1232 { 1233 delegated.add(otherFeature); 1234 } 1235 } 1236 } 1237 } 1238 break; 1239 } 1240 } 1241 } 1242 1256 1257 List result = new ArrayList (); 1258 for (Iterator iter = delegated.iterator(); iter.hasNext(); ) 1259 { 1260 GenFeature feature = (GenFeature)iter.next(); 1261 if (feature.isFeatureMapType()) 1262 { 1263 result.addAll(feature.getDelegatedFeatures()); 1264 } 1265 else 1266 { 1267 result.add(feature); 1268 } 1269 } 1270 return result; 1271 } 1272 1273 public String getCreateChildValueLiteral() 1274 { 1275 String result = getDefaultValue(); 1276 1277 if (result == null) 1278 { 1279 Class c = getEcoreFeature().getEType().getInstanceClass(); 1280 1281 if (c == Boolean.TYPE || c == Boolean .class) 1282 { 1283 result = "\"false\""; 1284 } 1285 else if (c == String .class) 1286 { 1287 result = "\"\""; 1288 } 1289 else if (c == Character .class) 1290 { 1291 result = "\"0\""; 1292 } 1293 else if (c == Byte.TYPE || c == Short.TYPE || c == Integer.TYPE || c == Long.TYPE || c == Float.TYPE || c == Double.TYPE || 1294 (c != null && Number .class.isAssignableFrom(c))) 1295 { 1296 result = "\"0\""; 1297 } 1298 } 1299 return result; 1300 } 1301 1302 public boolean isSuppressedGetVisibility() 1303 { 1304 return EcoreUtil.isSuppressedVisibility(getEcoreFeature(), EcoreUtil.GET); 1305 } 1306 1307 public boolean isSuppressedSetVisibility() 1308 { 1309 return EcoreUtil.isSuppressedVisibility(getEcoreFeature(), EcoreUtil.SET); 1310 } 1311 1312 public boolean isSuppressedIsSetVisibility() 1313 { 1314 return EcoreUtil.isSuppressedVisibility(getEcoreFeature(), EcoreUtil.IS_SET); 1315 } 1316 1317 public boolean isSuppressedUnsetVisibility() 1318 { 1319 return EcoreUtil.isSuppressedVisibility(getEcoreFeature(), EcoreUtil.UNSET); 1320 } 1321 1322 public void initialize(EStructuralFeature eFeature) 1323 { 1324 if (eFeature != getEcoreFeature()) 1325 { 1326 setEcoreFeature(eFeature); 1327 1328 if (eFeature instanceof EReference) 1329 { 1330 EReference eReference = (EReference)eFeature; 1331 if (!eReference.isContainer() && !eReference.isContainment()) 1332 { 1333 setProperty(eFeature.isChangeable() ? GenPropertyKind.EDITABLE_LITERAL : GenPropertyKind.READONLY_LITERAL); 1334 } 1335 else 1336 { 1337 setProperty(GenPropertyKind.NONE_LITERAL); 1338 } 1339 setChildren(eReference.isContainment() && !hasDelegateFeature()); 1340 setCreateChild(isChildren() && isChangeable()); 1341 setNotify(isChildren()); 1342 } 1343 else if (isFeatureMapType()) 1344 { 1345 setProperty(GenPropertyKind.NONE_LITERAL); 1346 setChildren(!hasDelegateFeature()); 1347 setCreateChild(isChildren() && isChangeable()); 1348 setNotify(isChildren()); 1349 } 1350 else 1351 { 1352 setProperty(eFeature.isChangeable() ? GenPropertyKind.EDITABLE_LITERAL : GenPropertyKind.READONLY_LITERAL); 1353 setChildren(false); 1354 setCreateChild(false); 1355 setNotify(true); 1356 } 1357 } 1358 } 1359 1360 public String getModelInfo() 1361 { 1362 return getModelInfo(false); 1363 } 1364 1365 public String getQualifiedModelInfo() 1366 { 1367 return getModelInfo(true); 1368 } 1369 1370 AnnotationFilter DEFAULT_GEN_FEATURE_ANNOTATION_FILTER = 1371 new AnnotationFilterImpl() 1372 { 1373 public boolean accept(EModelElement eModelElement, String source, String key, String value) 1374 { 1375 return 1376 super.accept(eModelElement, source, key, value) && 1377 !(GenModelPackage.eNS_URI.equals(source) && 1378 ("suppressedSetVisibility".equals(key) || 1379 "suppressedGetVisibility".equals(key) || 1380 "suppressedIsSetVisibility".equals(key) || 1381 "suppressedUnsetVisibility".equals(key))); 1382 } 1383 }; 1384 1385 public String getModelInfo(boolean qualified) 1386 { 1387 EStructuralFeature eStructuralFeature = getEcoreFeature(); 1388 StringBuffer result = new StringBuffer (); 1389 boolean defaultTransient = false; 1390 1391 String mapModelInfo = getMapModelInfo(qualified, (!qualified || isSuppressedGetVisibility()) && !isContainer()); 1396 if (mapModelInfo != null) 1397 { 1398 result.append(mapModelInfo); 1399 } 1400 else 1401 { 1402 if (eStructuralFeature.isMany() && !isFeatureMapType() || qualified) 1403 { 1404 appendModelSetting(result, qualified, "type", getType(eStructuralFeature.getEType(), false)); 1405 } 1406 1407 if (eStructuralFeature instanceof EReference) 1408 { 1409 EReference reference = (EReference) eStructuralFeature; 1410 EReference opposite = reference.getEOpposite(); 1411 if (opposite != null) 1412 { 1413 appendModelSetting(result, qualified, "opposite", opposite.getName()); 1414 1415 if (opposite.isContainment()) 1416 { 1417 defaultTransient = true; 1418 } 1419 } 1420 if (reference.isContainment()) 1421 { 1422 appendModelSetting(result, qualified, "containment", "true"); 1423 } 1424 if (!reference.isResolveProxies()) 1425 { 1426 appendModelSetting(result, qualified, "resolveProxies", "false"); 1427 } 1428 if (reference.isUnsettable()) 1429 { 1430 appendModelSetting(result, qualified, "unsettable", "true"); 1431 } 1432 } 1433 else if (eStructuralFeature instanceof EAttribute) 1434 { 1435 EAttribute attribute = (EAttribute) eStructuralFeature; 1436 if (eStructuralFeature.getDefaultValueLiteral() != null) 1437 { 1438 appendModelSetting(result, qualified, "default", eStructuralFeature.getDefaultValueLiteral()); 1439 } 1440 if (!eStructuralFeature.isUnique()) 1441 { 1442 appendModelSetting(result, qualified, "unique", "false"); 1443 } 1444 if (attribute.isUnsettable()) 1445 { 1446 appendModelSetting(result, qualified, "unsettable", "true"); 1447 } 1448 if (attribute.isID()) 1449 { 1450 appendModelSetting(result, qualified, "id", "true"); 1451 } 1452 1453 EDataType eDataType = attribute.getEAttributeType(); 1454 if (!(eDataType instanceof EEnum)) 1455 { 1456 GenPackage genPackage = findGenPackage(eDataType.getEPackage()); 1457 if (genPackage != null && (isFeatureMapType() || !genPackage.isEcorePackage())) 1458 { 1459 appendModelSetting(result, qualified, "dataType", genPackage.getInterfacePackageName() + '.' + eDataType.getName()); 1460 } 1461 } 1462 } 1463 1464 result.append(getMultiplicityModelInfo(qualified)); 1465 } 1466 1467 if (eStructuralFeature.isTransient() && !defaultTransient) 1468 { 1469 appendModelSetting(result, qualified, "transient", "true"); 1470 } 1471 1472 if (!eStructuralFeature.isChangeable()) 1473 { 1474 appendModelSetting(result, qualified, "changeable", "false"); 1475 } 1476 1477 if (eStructuralFeature.isVolatile()) 1478 { 1479 appendModelSetting(result, qualified, "volatile", "true"); 1480 } 1481 1482 if (eStructuralFeature.isDerived()) 1483 { 1484 appendModelSetting(result, qualified, "derived", "true"); 1485 } 1486 1487 if (!eStructuralFeature.isOrdered()) 1488 { 1489 appendModelSetting(result, qualified, "ordered", "false"); 1490 } 1491 1492 if (isSuppressedGetVisibility()) 1493 { 1494 appendModelSetting(result, qualified, "suppressedGetVisibility", "true"); 1495 } 1496 if (isSuppressedSetVisibility()) 1497 { 1498 appendModelSetting(result, qualified, "suppressedSetVisibility", "true"); 1499 } 1500 if (isSuppressedIsSetVisibility()) 1501 { 1502 appendModelSetting(result, qualified, "suppressedIsSetVisibility", "true"); 1503 } 1504 if (isSuppressedUnsetVisibility()) 1505 { 1506 appendModelSetting(result, qualified, "suppressedUnsetVisibility", "true"); 1507 } 1508 1509 appendAnnotationInfo(result, qualified, eStructuralFeature, DEFAULT_GEN_FEATURE_ANNOTATION_FILTER); 1510 return result.toString().trim(); 1511 } 1512 1513 1517 public String getPropertyImageName() 1518 { 1519 EClassifier eType = getEcoreFeature().getEType(); 1520 if (isPrimitiveType(eType)) 1521 { 1522 Class instanceClass = eType.getInstanceClass(); 1523 if (instanceClass == Boolean.TYPE || instanceClass == Boolean .class) 1524 { 1525 return "BOOLEAN_VALUE_IMAGE"; 1526 } 1527 else if (instanceClass == Byte.TYPE || instanceClass == Byte .class || 1528 instanceClass == Integer.TYPE || instanceClass == Integer .class || 1529 instanceClass == Long.TYPE || instanceClass == Long .class || 1530 instanceClass == Short.TYPE || instanceClass == Short .class) 1531 { 1532 return "INTEGRAL_VALUE_IMAGE"; 1533 } 1534 else if (instanceClass == Character.TYPE || instanceClass == Character .class || 1535 instanceClass == String .class) 1536 { 1537 return "TEXT_VALUE_IMAGE"; 1538 } 1539 else if (instanceClass == Double.TYPE || instanceClass == Double .class || 1540 instanceClass == Float.TYPE || instanceClass == Float .class) 1541 { 1542 return "REAL_VALUE_IMAGE"; 1543 } 1544 } 1545 1546 return "GENERIC_VALUE_IMAGE"; 1547 } 1548 1549 public boolean reconcile(GenFeature oldGenFeatureVersion) 1550 { 1551 if (getEcoreFeature().getName().equals(oldGenFeatureVersion.getEcoreFeature().getName())) 1552 { 1553 reconcileSettings(oldGenFeatureVersion); 1554 return true; 1555 } 1556 else 1557 { 1558 return false; 1559 } 1560 } 1561 1562 protected void reconcileSettings(GenFeature oldGenFeatureVersion) 1563 { 1564 setProperty(oldGenFeatureVersion.getProperty()); 1565 setNotify(oldGenFeatureVersion.isNotify()); 1566 setChildren(oldGenFeatureVersion.isChildren()); 1567 setCreateChild(oldGenFeatureVersion.isCreateChild()); 1568 setPropertyCategory(oldGenFeatureVersion.getPropertyCategory()); 1569 setPropertyDescription(oldGenFeatureVersion.getPropertyDescription()); 1570 1571 getPropertyFilterFlags().addAll(oldGenFeatureVersion.getPropertyFilterFlags()); 1572 } 1573 1574 public boolean reconcile() 1575 { 1576 EStructuralFeature eFeature = getEcoreFeature(); 1577 if (eFeature == null || eFeature.eIsProxy() || eFeature.eResource() == null) 1578 { 1579 return false; 1580 } 1581 else 1582 { 1583 return true; 1584 } 1585 } 1586 1587 public boolean isField() 1588 { 1589 return !isContainer() && !isVolatile(); 1590 } 1591 1592 public boolean isESetField() 1593 { 1594 return !isContainer() && !isListType() && isUnsettable() && !isVolatile(); 1595 } 1596 1597 public boolean isGet() 1598 { 1599 return true; 1600 } 1601 1602 public boolean isBasicGet() 1603 { 1604 return !getGenModel().isReflectiveDelegation() && isResolveProxies() && !isListType(); 1605 } 1606 1607 public boolean isBasicSet() 1608 { 1609 return !getGenModel().isReflectiveDelegation() && !isListType() 1610 && (isBidirectional() && !isContainer() && !isVolatile() || isContains()); 1611 } 1612 1613 public boolean isSet() 1614 { 1615 return !isListType() && isChangeable(); 1616 } 1617 1618 public boolean isBasicUnset() 1619 { 1620 return isUnsettable() && isChangeable() && !isListType() && isReferenceType() && (isBidirectional() || isContains()); 1621 } 1622 1623 public boolean isUnset() 1624 { 1625 return isUnsettable() && isChangeable(); 1626 } 1627 1628 public boolean isIsSet() 1629 { 1630 return isUnsettable(); 1631 } 1632 1633} | Popular Tags |