Changeset 2d81bf0e2ed8217c6cb2a26fcb22d09b8441f7a3
- Timestamp:
- 06/28/09 23:36:50 (9 months ago)
- Author:
- mb0 <mb0@…>
- git-author:
- mb0 <mb0@mb0.org> / 2009-06-09T21:53:24Z+0200
- Parents:
- 82cecb85d4b9fff471d3eadd986735ad736c6c3f
- Children:
- 69d1ca8cf4ab8b63f93d4467f3d504c0ffdfabb7
- git-committer:
- mb0 <mb0@mb0.org> / 2009-06-28T23:36:50Z+0200
- Message:
-
renamed axdoc preference option, root package serialization file name and axutil functions
rootLevel is not transient. a dirty flag was added to axroot.
pulled getReference up to axindexnode.
index0r got a package cache and some simple lookup methods.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r85b4650
|
r2d81bf0
|
|
| 62 | 62 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="url" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> |
| 63 | 63 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="rootType" eType="#//AXRootType"/> |
| 64 | | <eStructuralFeatures xsi:type="ecore:EAttribute" name="rootLevel" eType="#//AXLevel" |
| 65 | | transient="true"/> |
| | 64 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="rootLevel" eType="#//AXLevel"/> |
| | 65 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="dirty" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" |
| | 66 | transient="true" defaultValueLiteral="false"/> |
| 66 | 67 | </eClassifiers> |
| 67 | 68 | <eClassifiers xsi:type="ecore:EEnum" name="AXRootType"> |
| … |
… |
|
| 92 | 93 | </eOperations> |
| 93 | 94 | <eOperations name="getOrCreateReference" eType="#//AXNode"/> |
| | 95 | <eOperations name="getReference" eType="#//AXNode"/> |
| 94 | 96 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> |
| 95 | 97 | <eStructuralFeatures xsi:type="ecore:EReference" name="entries" upperBound="-1" |
-
|
r87f02d1
|
r2d81bf0
|
|
| 88 | 88 | <xsd:attribute name="url" type="xsd:string"/> |
| 89 | 89 | <xsd:attribute name="rootType" type="axdoc:AXRootType"/> |
| | 90 | <xsd:attribute name="rootLevel" type="axdoc:AXLevel"/> |
| 90 | 91 | </xsd:extension> |
| 91 | 92 | </xsd:complexContent> |
-
|
r85b4650
|
r2d81bf0
|
|
| 592 | 592 | |
| 593 | 593 | /** |
| | 594 | * The feature id for the '<em><b>Dirty</b></em>' attribute. |
| | 595 | * <!-- begin-user-doc --> |
| | 596 | * <!-- end-user-doc --> |
| | 597 | * @generated |
| | 598 | * @ordered |
| | 599 | */ |
| | 600 | int AX_ROOT__DIRTY = AX_INDEX_FEATURE_COUNT + 3; |
| | 601 | |
| | 602 | /** |
| 594 | 603 | * The number of structural features of the '<em>AX Root</em>' class. |
| 595 | 604 | * <!-- begin-user-doc --> |
| … |
… |
|
| 598 | 607 | * @ordered |
| 599 | 608 | */ |
| 600 | | int AX_ROOT_FEATURE_COUNT = AX_INDEX_FEATURE_COUNT + 3; |
| | 609 | int AX_ROOT_FEATURE_COUNT = AX_INDEX_FEATURE_COUNT + 4; |
| 601 | 610 | |
| 602 | 611 | /** |
| … |
… |
|
| 947 | 956 | */ |
| 948 | 957 | EAttribute getAXRoot_RootLevel(); |
| | 958 | |
| | 959 | /** |
| | 960 | * Returns the meta object for the attribute '{@link org.axdt.axdoc.model.AXRoot#isDirty <em>Dirty</em>}'. |
| | 961 | * <!-- begin-user-doc --> |
| | 962 | * <!-- end-user-doc --> |
| | 963 | * @return the meta object for the attribute '<em>Dirty</em>'. |
| | 964 | * @see org.axdt.axdoc.model.AXRoot#isDirty() |
| | 965 | * @see #getAXRoot() |
| | 966 | * @generated |
| | 967 | */ |
| | 968 | EAttribute getAXRoot_Dirty(); |
| 949 | 969 | |
| 950 | 970 | /** |
| … |
… |
|
| 1307 | 1327 | |
| 1308 | 1328 | /** |
| | 1329 | * The meta object literal for the '<em><b>Dirty</b></em>' attribute feature. |
| | 1330 | * <!-- begin-user-doc --> |
| | 1331 | * <!-- end-user-doc --> |
| | 1332 | * @generated |
| | 1333 | */ |
| | 1334 | EAttribute AX_ROOT__DIRTY = eINSTANCE.getAXRoot_Dirty(); |
| | 1335 | |
| | 1336 | /** |
| 1309 | 1337 | * The meta object literal for the '{@link org.axdt.axdoc.model.impl.AXEntryImpl <em>AX Entry</em>}' class. |
| 1310 | 1338 | * <!-- begin-user-doc --> |
-
|
r85b4650
|
r2d81bf0
|
|
| 152 | 152 | AXNode getOrCreateReference(); |
| 153 | 153 | |
| | 154 | /** |
| | 155 | * <!-- begin-user-doc --> |
| | 156 | * <!-- end-user-doc --> |
| | 157 | * @model kind="operation" |
| | 158 | * @generated |
| | 159 | */ |
| | 160 | AXNode getReference(); |
| | 161 | |
| 154 | 162 | } // AXIndexNode |
-
|
r79dd699
|
r2d81bf0
|
|
| 18 | 18 | * <li>{@link org.axdt.axdoc.model.AXRoot#getRootType <em>Root Type</em>}</li> |
| 19 | 19 | * <li>{@link org.axdt.axdoc.model.AXRoot#getRootLevel <em>Root Level</em>}</li> |
| | 20 | * <li>{@link org.axdt.axdoc.model.AXRoot#isDirty <em>Dirty</em>}</li> |
| 20 | 21 | * </ul> |
| 21 | 22 | * </p> |
| … |
… |
|
| 94 | 95 | * @see #setRootLevel(AXLevel) |
| 95 | 96 | * @see org.axdt.axdoc.model.AXDocPackage#getAXRoot_RootLevel() |
| 96 | | * @model transient="true" |
| | 97 | * @model |
| 97 | 98 | * @generated |
| 98 | 99 | */ |
| … |
… |
|
| 109 | 110 | */ |
| 110 | 111 | void setRootLevel(AXLevel value); |
| | 112 | |
| | 113 | /** |
| | 114 | * Returns the value of the '<em><b>Dirty</b></em>' attribute. |
| | 115 | * The default value is <code>"false"</code>. |
| | 116 | * <!-- begin-user-doc --> |
| | 117 | * <p> |
| | 118 | * If the meaning of the '<em>Dirty</em>' attribute isn't clear, |
| | 119 | * there really should be more of a description here... |
| | 120 | * </p> |
| | 121 | * <!-- end-user-doc --> |
| | 122 | * @return the value of the '<em>Dirty</em>' attribute. |
| | 123 | * @see #setDirty(boolean) |
| | 124 | * @see org.axdt.axdoc.model.AXDocPackage#getAXRoot_Dirty() |
| | 125 | * @model default="false" transient="true" |
| | 126 | * @generated |
| | 127 | */ |
| | 128 | boolean isDirty(); |
| | 129 | |
| | 130 | /** |
| | 131 | * Sets the value of the '{@link org.axdt.axdoc.model.AXRoot#isDirty <em>Dirty</em>}' attribute. |
| | 132 | * <!-- begin-user-doc --> |
| | 133 | * <!-- end-user-doc --> |
| | 134 | * @param value the new value of the '<em>Dirty</em>' attribute. |
| | 135 | * @see #isDirty() |
| | 136 | * @generated |
| | 137 | */ |
| | 138 | void setDirty(boolean value); |
| 111 | 139 | |
| 112 | 140 | /** |
-
|
r85b4650
|
r2d81bf0
|
|
| 396 | 396 | * @generated |
| 397 | 397 | */ |
| | 398 | public EAttribute getAXRoot_Dirty() { |
| | 399 | return (EAttribute) axRootEClass.getEStructuralFeatures().get(3); |
| | 400 | } |
| | 401 | |
| | 402 | /** |
| | 403 | * <!-- begin-user-doc --> |
| | 404 | * <!-- end-user-doc --> |
| | 405 | * @generated |
| | 406 | */ |
| 398 | 407 | public EClass getAXEntry() { |
| 399 | 408 | return axEntryEClass; |
| … |
… |
|
| 577 | 586 | createEAttribute(axRootEClass, AX_ROOT__ROOT_TYPE); |
| 578 | 587 | createEAttribute(axRootEClass, AX_ROOT__ROOT_LEVEL); |
| | 588 | createEAttribute(axRootEClass, AX_ROOT__DIRTY); |
| 579 | 589 | |
| 580 | 590 | axEntryEClass = createEClass(AX_ENTRY); |
| … |
… |
|
| 736 | 746 | IS_ORDERED); |
| 737 | 747 | initEAttribute(getAXRoot_RootLevel(), this.getAXLevel(), "rootLevel", |
| 738 | | null, 0, 1, AXRoot.class, IS_TRANSIENT, !IS_VOLATILE, |
| | 748 | null, 0, 1, AXRoot.class, !IS_TRANSIENT, !IS_VOLATILE, |
| | 749 | IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, |
| | 750 | IS_ORDERED); |
| | 751 | initEAttribute(getAXRoot_Dirty(), ecorePackage.getEBoolean(), "dirty", |
| | 752 | "false", 0, 1, AXRoot.class, IS_TRANSIENT, !IS_VOLATILE, |
| 739 | 753 | IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, |
| 740 | 754 | IS_ORDERED); |
| … |
… |
|
| 816 | 830 | "getOrCreateReference", 0, 1, IS_UNIQUE, IS_ORDERED); |
| 817 | 831 | |
| | 832 | addEOperation(axIndexNodeEClass, this.getAXNode(), "getReference", 0, |
| | 833 | 1, IS_UNIQUE, IS_ORDERED); |
| | 834 | |
| 818 | 835 | // Initialize enums and add enum literals |
| 819 | 836 | initEEnum(axLevelEEnum, AXLevel.class, "AXLevel"); |
-
|
r85b4650
|
r2d81bf0
|
|
| 448 | 448 | AXIndexNode parent = getParent(); |
| 449 | 449 | // we need a parent ! |
| 450 | | if (parent == null) return null; |
| | 450 | if (parent == null) |
| | 451 | return null; |
| 451 | 452 | // lets work down the index tree and create all needed references |
| 452 | 453 | AXNode parentRef = parent.getOrCreateReference(); |
| 453 | 454 | // parent ref does not exist and cannot be created |
| 454 | | if (parentRef == null) return null; |
| | 455 | if (parentRef == null) |
| | 456 | return null; |
| 455 | 457 | if (getType().isMember()) { |
| 456 | 458 | // should never happen |
| 457 | | if (!(parentRef instanceof AXMemberHolder)) return null; |
| | 459 | if (!(parentRef instanceof AXMemberHolder)) |
| | 460 | return null; |
| 458 | 461 | AXMemberHolder holder = (AXMemberHolder) parentRef; |
| 459 | 462 | AXMember result = null; |
| 460 | | for (AXMember member:holder.getMembers()) { |
| | 463 | for (AXMember member : holder.getMembers()) { |
| 461 | 464 | if (getName().equals(member.getName())) { |
| 462 | 465 | result = member; |
| … |
… |
|
| 481 | 484 | // we need a package to add types |
| 482 | 485 | // XXX: think about private classes in source indexes |
| 483 | | if (!(parentRef instanceof AXPackage)) return null; |
| | 486 | if (!(parentRef instanceof AXPackage)) |
| | 487 | return null; |
| 484 | 488 | AXPackage pack = (AXPackage) parentRef; |
| 485 | 489 | AXType result = null; |
| 486 | | for (AXType type:pack.getTypes()) { |
| | 490 | for (AXType type : pack.getTypes()) { |
| 487 | 491 | if (getName().equals(type.getName())) { |
| 488 | 492 | result = type; |
-
|
r85b4650
|
r2d81bf0
|
|
| 518 | 518 | pack = AXDocFactory.eINSTANCE.createAXPackage(); |
| 519 | 519 | pack.setName(getName()); |
| | 520 | String fileName = this instanceof AXRoot ? "root-package.axdoc" |
| | 521 | : getId() + ".axdoc"; |
| 520 | 522 | URI uri = eResource().getURI().trimSegments(1).appendSegment( |
| 521 | | getId() + ".axdoc"); |
| 522 | | AXUtil.getResource(eResource().getResourceSet(), pack, uri |
| | 523 | fileName); |
| | 524 | AXUtil.getOrCreateResource(eResource().getResourceSet(), pack, uri |
| 523 | 525 | .toString()); |
| 524 | 526 | setReference(pack); |
-
|
r85b4650
|
r2d81bf0
|
|
| 258 | 258 | * <!-- begin-user-doc --> |
| 259 | 259 | * <!-- end-user-doc --> |
| | 260 | */ |
| | 261 | public abstract AXNode getReference(); |
| | 262 | |
| | 263 | /** |
| | 264 | * <!-- begin-user-doc --> |
| | 265 | * <!-- end-user-doc --> |
| 260 | 266 | * @generated |
| 261 | 267 | */ |
-
|
r79dd699
|
r2d81bf0
|
|
| 30 | 30 | * <li>{@link org.axdt.axdoc.model.impl.AXRootImpl#getRootType <em>Root Type</em>}</li> |
| 31 | 31 | * <li>{@link org.axdt.axdoc.model.impl.AXRootImpl#getRootLevel <em>Root Level</em>}</li> |
| | 32 | * <li>{@link org.axdt.axdoc.model.impl.AXRootImpl#isDirty <em>Dirty</em>}</li> |
| 32 | 33 | * </ul> |
| 33 | 34 | * </p> |
| … |
… |
|
| 97 | 98 | |
| 98 | 99 | /** |
| | 100 | * The default value of the '{@link #isDirty() <em>Dirty</em>}' attribute. |
| | 101 | * <!-- begin-user-doc --> |
| | 102 | * <!-- end-user-doc --> |
| | 103 | * @see #isDirty() |
| | 104 | * @generated |
| | 105 | * @ordered |
| | 106 | */ |
| | 107 | protected static final boolean DIRTY_EDEFAULT = false; |
| | 108 | |
| | 109 | /** |
| | 110 | * The flag representing the value of the '{@link #isDirty() <em>Dirty</em>}' attribute. |
| | 111 | * <!-- begin-user-doc --> |
| | 112 | * <!-- end-user-doc --> |
| | 113 | * @see #isDirty() |
| | 114 | * @generated |
| | 115 | * @ordered |
| | 116 | */ |
| | 117 | protected static final int DIRTY_EFLAG = 1 << 0; |
| | 118 | |
| | 119 | /** |
| 99 | 120 | * <!-- begin-user-doc --> |
| 100 | 121 | * <!-- end-user-doc --> |
| … |
… |
|
| 179 | 200 | eNotify(new ENotificationImpl(this, Notification.SET, |
| 180 | 201 | AXDocPackage.AX_ROOT__ROOT_LEVEL, oldRootLevel, rootLevel)); |
| | 202 | } |
| | 203 | |
| | 204 | /** |
| | 205 | * <!-- begin-user-doc --> |
| | 206 | * <!-- end-user-doc --> |
| | 207 | * @generated |
| | 208 | */ |
| | 209 | public boolean isDirty() { |
| | 210 | return (flags & DIRTY_EFLAG) != 0; |
| | 211 | } |
| | 212 | |
| | 213 | /** |
| | 214 | * <!-- begin-user-doc --> |
| | 215 | * <!-- end-user-doc --> |
| | 216 | * @generated |
| | 217 | */ |
| | 218 | public void setDirty(boolean newDirty) { |
| | 219 | boolean oldDirty = (flags & DIRTY_EFLAG) != 0; |
| | 220 | if (newDirty) |
| | 221 | flags |= DIRTY_EFLAG; |
| | 222 | else |
| | 223 | flags &= ~DIRTY_EFLAG; |
| | 224 | if (eNotificationRequired()) |
| | 225 | eNotify(new ENotificationImpl(this, Notification.SET, |
| | 226 | AXDocPackage.AX_ROOT__DIRTY, oldDirty, newDirty)); |
| 181 | 227 | } |
| 182 | 228 | |
| … |
… |
|
| 245 | 291 | case AXDocPackage.AX_ROOT__ROOT_LEVEL: |
| 246 | 292 | return getRootLevel(); |
| | 293 | case AXDocPackage.AX_ROOT__DIRTY: |
| | 294 | return isDirty() ? Boolean.TRUE : Boolean.FALSE; |
| 247 | 295 | } |
| 248 | 296 | return eDynamicGet(featureID, resolve, coreType); |
| … |
… |
|
| 287 | 335 | setRootLevel((AXLevel) newValue); |
| 288 | 336 | return; |
| | 337 | case AXDocPackage.AX_ROOT__DIRTY: |
| | 338 | setDirty(((Boolean) newValue).booleanValue()); |
| | 339 | return; |
| 289 | 340 | } |
| 290 | 341 | eDynamicSet(featureID, newValue); |
| … |
… |
|
| 325 | 376 | case AXDocPackage.AX_ROOT__ROOT_LEVEL: |
| 326 | 377 | setRootLevel(ROOT_LEVEL_EDEFAULT); |
| | 378 | return; |
| | 379 | case AXDocPackage.AX_ROOT__DIRTY: |
| | 380 | setDirty(DIRTY_EDEFAULT); |
| 327 | 381 | return; |
| 328 | 382 | } |
| … |
… |
|
| 362 | 416 | case AXDocPackage.AX_ROOT__ROOT_LEVEL: |
| 363 | 417 | return rootLevel != ROOT_LEVEL_EDEFAULT; |
| | 418 | case AXDocPackage.AX_ROOT__DIRTY: |
| | 419 | return ((flags & DIRTY_EFLAG) != 0) != DIRTY_EDEFAULT; |
| 364 | 420 | } |
| 365 | 421 | return eDynamicIsSet(featureID); |
| … |
… |
|
| 383 | 439 | result.append(", rootLevel: "); |
| 384 | 440 | result.append(rootLevel); |
| | 441 | result.append(", dirty: "); |
| | 442 | result.append((flags & DIRTY_EFLAG) != 0); |
| 385 | 443 | result.append(')'); |
| 386 | 444 | return result.toString(); |
-
|
r87f02d1
|
r2d81bf0
|
|
| 20 | 20 | private static AXDocXMLProcessor xmlProcessor = new AXDocXMLProcessor(); |
| 21 | 21 | private static AXDocFactory factory = AXDocFactory.eINSTANCE; |
| 22 | | public static Resource getResource(String path) { |
| | 22 | public static Resource createResource(String path) { |
| 23 | 23 | return xmlProcessor.createResourceSet().createResource(URI.createURI(path)); |
| 24 | 24 | } |
| 25 | | public static Resource getRelatedResource(Resource resource, EObject node, |
| 26 | | String path) { |
| 27 | | ResourceSet set = (resource != null) ? resource.getResourceSet() : null; |
| 28 | | return getResource(set, node, path); |
| 29 | | } |
| 30 | | public static Resource getResource(ResourceSet set, EObject rootNode, String path) { |
| 31 | | Resource resource = rootNode.eResource(); |
| | 25 | public static Resource getOrCreateResource(ResourceSet set, EObject node, String path) { |
| | 26 | Resource resource = node.eResource(); |
| 32 | 27 | if (resource == null) { |
| 33 | 28 | if (set == null) |
| 34 | 29 | set = xmlProcessor.createResourceSet(); |
| 35 | 30 | resource = set.createResource(URI.createURI(path)); |
| 36 | | resource.getContents().add(rootNode); |
| | 31 | resource.getContents().add(node); |
| 37 | 32 | } else if (path != null) { |
| 38 | 33 | resource.setURI(URI.createURI(path)); |
| … |
… |
|
| 41 | 36 | } |
| 42 | 37 | public static String writeToString(EObject node) throws IOException { |
| 43 | | return writeToString(getRelatedResource(node.eResource(),node, null)); |
| | 38 | ResourceSet set = (node.eResource() != null) ? node.eResource().getResourceSet() : null; |
| | 39 | return writeToString(getOrCreateResource(set, node, null)); |
| 44 | 40 | } |
| 45 | 41 | public static String writeToString(Resource resource) throws IOException { |
| … |
… |
|
| 49 | 45 | } |
| 50 | 46 | public static Resource readFromString(String text, String path) throws IOException { |
| 51 | | Resource resource = getResource(path); |
| | 47 | Resource resource = createResource(path); |
| 52 | 48 | ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes()); |
| 53 | 49 | resource.load(inputStream, null); |
| 54 | 50 | return resource; |
| 55 | | } |
| 56 | | public static Resource writeToFile(EObject rootNode, String path) throws IOException { |
| 57 | | Resource resource = getRelatedResource(null,rootNode,path); |
| 58 | | resource.save(null); |
| 59 | | return resource; |
| 60 | | } |
| 61 | | public static void writeToDir(AXRoot rootNode, String path) throws IOException { |
| 62 | | ResourceSet set = rootNode.eResource().getResourceSet(); |
| 63 | | for (Resource res : set.getResources()) { |
| 64 | | res.save(null); |
| 65 | | } |
| 66 | 51 | } |
| 67 | 52 | public static AXRoot createRoot(String url, String basePath) { |
| … |
… |
|
| 73 | 58 | root.setUrl(url); |
| 74 | 59 | ResourceSet set = xmlProcessor.createResourceSet(); |
| 75 | | getResource(set, root, resourceUrl); |
| | 60 | getOrCreateResource(set, root, resourceUrl); |
| 76 | 61 | return root; |
| 77 | 62 | } |
-
|
r85b4650
|
r2d81bf0
|
|
| 101 | 101 | // still need package |
| 102 | 102 | assertNull(getFixture().getOrCreateReference()); |
| 103 | | AXRoot root = AXUtil.createRoot("test", "file:/tmp/axdoc.entryTest/asdoc", "file:/tmp/axdoc.entryTest/resources"); |
| | 103 | AXRoot root = AXUtil.createRoot("test", |
| | 104 | "file:/tmp/axdoc.entryTest/asdoc", |
| | 105 | "file:/tmp/axdoc.entryTest/resources"); |
| 104 | 106 | root.getEntries().add(getFixture()); |
| 105 | 107 | AXNode ref = getFixture().getOrCreateReference(); |
| … |
… |
|
| 110 | 112 | assertEquals("Array", type.getName()); |
| 111 | 113 | assertSame(type, getFixture().getOrCreateReference()); |
| 112 | | |
| 113 | | AXEntry entry = getFixture().createEntry("toString", AXEntryType.METHOD); |
| | 114 | |
| | 115 | AXEntry entry = getFixture() |
| | 116 | .createEntry("toString", AXEntryType.METHOD); |
| 114 | 117 | ref = entry.getOrCreateReference(); |
| 115 | 118 | assertNotNull(ref); |
-
|
r85b4650
|
r2d81bf0
|
|
| 31 | 31 | * <li>{@link org.axdt.axdoc.model.AXIndexNode#createEntry(java.lang.String, org.axdt.axdoc.model.AXEntryType) <em>Create Entry</em>}</li> |
| 32 | 32 | * <li>{@link org.axdt.axdoc.model.AXIndexNode#getOrCreateReference() <em>Get Or Create Reference</em>}</li> |
| | 33 | * <li>{@link org.axdt.axdoc.model.AXIndexNode#getReference() <em>Get Reference</em>}</li> |
| 33 | 34 | * </ul> |
| 34 | 35 | * </p> |
| … |
… |
|
| 193 | 194 | */ |
| 194 | 195 | public void testGetOrCreateReference() { |
| 195 | | // should be tested in concrete implementations |
| | 196 | // should be tested in concrete implementations |
| | 197 | } |
| | 198 | |
| | 199 | /** |
| | 200 | * Tests the '{@link org.axdt.axdoc.model.AXIndexNode#getReference() <em>Get Reference</em>}' operation. |
| | 201 | * <!-- begin-user-doc --> |
| | 202 | * <!-- end-user-doc --> |
| | 203 | * @see org.axdt.axdoc.model.AXIndexNode#getReference() |
| | 204 | */ |
| | 205 | public void testGetReference() { |
| | 206 | // no tests needed. uses generated getter in implementations. |
| 196 | 207 | } |
| 197 | 208 | |
-
|
r85b4650
|
r2d81bf0
|
|
| 197 | 197 | // needs resource set |
| 198 | 198 | assertNull(reference); |
| 199 | | Resource resource = AXUtil.getResource("test"); |
| | 199 | Resource resource = AXUtil.createResource("test"); |
| 200 | 200 | resource.getContents().add(getFixture()); |
| 201 | 201 | reference = getFixture().getOrCreateReference(); |
-
|
r79dd699
|
r2d81bf0
|
|
| 6 | 6 | */ |
| 7 | 7 | package org.axdt.axdoc.model; |
| | 8 | |
| | 9 | import org.axdt.axdoc.model.util.AXUtil; |
| 8 | 10 | |
| 9 | 11 | import junit.textui.TestRunner; |
| … |
… |
|
| 121 | 123 | @Override |
| 122 | 124 | public void testGetId() { |
| | 125 | // not used for package serialization file name |
| 123 | 126 | assertEquals("", getFixture().getId()); |
| 124 | 127 | getFixture().setName("my lib"); |
| 125 | 128 | assertEquals("", getFixture().getId()); |
| | 129 | assertNull(getFixture().eResource()); |
| | 130 | AXUtil.getOrCreateResource(null, getFixture(), "test"); |
| | 131 | assertNotNull(getFixture().eResource()); |
| | 132 | AXPackage reference = getFixture().getOrCreateReference(); |
| | 133 | assertNotNull(reference.eResource()); |
| | 134 | assertEquals("root-package.axdoc", reference.eResource().getURI().lastSegment()); |
| 126 | 135 | |
| 127 | 136 | AXIndex index = AXDocFactory.eINSTANCE.createAXIndex(); |
-
|
r85b4650
|
r2d81bf0
|
|
| 27 | 27 | String xmlNs = "xmlns:axdoc=\"http://axdt.org/axdoc\" "; |
| 28 | 28 | String linebreak = "\n "; |
| 29 | | assertNull(AXUtil.writeToString(AXUtil.getResource("test"))); |
| | 29 | assertNull(AXUtil.writeToString(AXUtil.createResource("test"))); |
| 30 | 30 | String simpleStart = header +"<axdoc:AXRoot "+ xmlNs; |
| 31 | 31 | // create a some packages |
| … |
… |
|
| 45 | 45 | assertNull(pack.getReference()); |
| 46 | 46 | AXPackage axp = AXDocFactory.eINSTANCE.createAXPackage(); |
| 47 | | AXUtil.getResource(pack.eResource().getResourceSet(), axp, "org.axdt.test.axdoc"); |
| | 47 | AXUtil.getOrCreateResource(pack.eResource().getResourceSet(), axp, "org.axdt.test.axdoc"); |
| 48 | 48 | axp.setName(pack.getName()); |
| 49 | 49 | axp.getAsdoc().add("test"); |
-
|
r85b4650
|
r2d81bf0
|
|
| 12 | 12 | public class AXDocPreferences extends AbstractPreferences { |
| 13 | 13 | |
| 14 | | public final static String LANGREF_PATH = "LANGREF_PATH"; |
| | 14 | public final static String AXDOC_URLS = "AXDOC_URLS"; |
| 15 | 15 | private static AXDocPreferences instance; |
| 16 | 16 | |
| … |
… |
|
| 32 | 32 | @Override |
| 33 | 33 | public void initializeFieldSpecs() { |
| 34 | | add(new DocTableField(LANGREF_PATH, "Asdoc uris", "file:/home/mb0/workspace/axdt/org.axdt.axdoc.test/data/asdoc")); |
| | 34 | add(new DocTableField(AXDOC_URLS, "Asdoc URLs", "file:/home/mb0/workspace/axdt/org.axdt.axdoc.test/data/asdoc")); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public static String getLangRefPathString() { |
| 38 | 38 | IPreferenceStore store = getInstance().getStore(); |
| 39 | | return store.getString(LANGREF_PATH); |
| | 39 | return store.getString(AXDOC_URLS); |
| 40 | 40 | } |
| 41 | 41 | public static void checkAXDocPaths(Index0r index0r) { |
-
|
r85b4650
|
r2d81bf0
|
|
| 24 | 24 | "b","code","div","ol","p","pre","span","table","ul" |
| 25 | 25 | }; |
| 26 | | protected static String URL_PACKAGE_LIST = "package-list.html"; |
| 27 | | protected static String URL_PACKAGE_SUMMARY = "package-summary.html"; |
| 28 | | protected static String URL_PACKAGE = "package.html"; |
| 29 | | protected static String URL_PACKAGE_DETAIL = "package-detail.html"; |
| 30 | | protected static String URL_CLASS_LIST = "class-list.html"; |
| | 26 | public static String URL_PACKAGE_LIST = "package-list.html"; |
| | 27 | public static String URL_PACKAGE_SUMMARY = "package-summary.html"; |
| | 28 | public static String URL_PACKAGE = "package.html"; |
| | 29 | public static String URL_PACKAGE_DETAIL = "package-detail.html"; |
| | 30 | public static String URL_CLASS_LIST = "class-list.html"; |
| 31 | 31 | /** |
| 32 | 32 | * set whether to load detailed description |
| … |
… |
|
| 79 | 79 | int rLevel = root.getRootLevel().getValue(); |
| 80 | 80 | if (AXLevel.PACKAGE_VALUE <= level.getValue() |
| 81 | | && rLevel < AXLevel.PACKAGE_VALUE) |
| | 81 | && rLevel < AXLevel.PACKAGE_VALUE) { |
| 82 | 82 | parsePackageLevel(root); |
| 83 | 83 | root.setRootLevel(AXLevel.PACKAGE); |
| | 84 | root.setDirty(true); |
| | 85 | } |
| 84 | 86 | if (AXLevel.TYPE_VALUE <= level.getValue() |
| 85 | 87 | && rLevel < AXLevel.TYPE_VALUE) { |
| … |
… |
|
| 87 | 89 | parseTypeLevel(root); |
| 88 | 90 | root.setRootLevel(AXLevel.TYPE); |
| | 91 | root.setDirty(true); |
| 89 | 92 | } |
| 90 | 93 | if (AXLevel.MEMBER_VALUE <= level.getValue() |
| … |
… |
|
| 93 | 96 | parseMemberLevel(root); |
| 94 | 97 | root.setRootLevel(AXLevel.MEMBER); |
| | 98 | root.setDirty(true); |
| 95 | 99 | } |
| 96 | 100 | return root; |
-
|
r85b4650
|
r2d81bf0
|
|
| 3 | 3 | import java.io.IOException; |
| 4 | 4 | import java.util.ArrayList; |
| | 5 | import java.util.Collection; |
| 5 | 6 | import java.util.HashMap; |
| | 7 | import java.util.List; |
| 6 | 8 | import java.util.Map; |
| 7 | 9 | |
| … |
… |
|
| 17 | 19 | import org.eclipse.core.runtime.Path; |
| 18 | 20 | import org.eclipse.emf.common.CommonPlugin; |
| | 21 | import org.eclipse.emf.common.util.EList; |
| 19 | 22 | import org.eclipse.emf.common.util.URI; |
| 20 | 23 | import org.eclipse.emf.ecore.EObject; |
| … |
… |
|
| 36 | 39 | |
| 37 | 40 | protected Map<String, AXRoot> roots; |
| | 41 | protected Map<String, List<AXIndex>> packages; |
| 38 | 42 | protected AXDocParser docParser; |
| 39 | 43 | protected URI baseURI; |
| … |
… |
|
| 41 | 45 | public Index0r() { |
| 42 | 46 | roots = new HashMap<String, AXRoot>(); |
| | 47 | packages = new HashMap<String, List<AXIndex>>(); |
| 43 | 48 | docParser = new AXDocParser(); |
| 44 | 49 | baseURI = createBaseUri(); |
| … |
… |
|
| 94 | 99 | AXRoot root = roots.get(url); |
| 95 | 100 | if (root == null) { |
| 96 | | URI resourcePath = baseURI.appendSegment(Integer.toHexString(url.hashCode())).appendSegment("root-index.axdoc"); |
| 97 | | if (new Path(resourcePath.toString()).toFile().exists()) { |
| | 101 | URI resourcePath = baseURI; |
| | 102 | if (resourcePath.hasTrailingPathSeparator()) resourcePath = resourcePath.trimSegments(1); |
| | 103 | resourcePath = resourcePath.appendSegment(Integer.toHexString(url.hashCode())).appendSegment("root-index.axdoc"); |
| | 104 | if (new Path(resourcePath.toFileString()).toFile().exists()) { |
| 98 | 105 | ResourceSet resset = new ResourceSetImpl(); |
| 99 | 106 | Resource resource = resset.createResource(resourcePath); |
| … |
… |
|
| 102 | 109 | if (resource.getContents().size()>0) { |
| 103 | 110 | EObject object = resource.getContents().get(0); |
| 104 | | if (object instanceof AXRoot) |
| 105 | | return (AXRoot) object; |
| | 111 | if (object instanceof AXRoot) { |
| | 112 | root = (AXRoot) object; |
| | 113 | } |
| 106 | 114 | } |
| 107 | 115 | } catch (IOException e) { |
| 108 | | AXDocPlugin.getDefault().log("error loading axdoc file",e); |
| | 116 | log("error loading axdoc file",e); |
| 109 | 117 | } |
| 110 | 118 | } else { |
| … |
… |
|
| 125 | 133 | try { |
| 126 | 134 | docParser.parseDoc(root, level); |
| 127 | | root.eResource().save(null); |
| | 135 | if (root.isDirty()) |
| | 136 | saveRoot(root); |
| 128 | 137 | } catch (Exception e) { |
| 129 | | if (AXDocPlugin.getDefault() != null) |
| 130 | | AXDocPlugin.getDefault().log("error parsing asdoc at "+root.getUrl(), e); |
| 131 | | else e.printStackTrace(); |
| | 138 | log("error parsing asdoc at "+root.getUrl(), e); |
| 132 | 139 | } |
| 133 | 140 | } else { |
| 134 | | if (AXDocPlugin.getDefault() != null) |
| 135 | | AXDocPlugin.getDefault().log("only asoc index is available"); |
| | 141 | log("only asoc index is available", null); |
| | 142 | } |
| | 143 | cachePackages(root); |
| | 144 | } |
| | 145 | protected void saveRoot(AXRoot root) throws IOException { |
| | 146 | Resource index = root.eResource(); |
| | 147 | index.save(null); |
| | 148 | EList<Resource> resources = index.getResourceSet().getResources(); |
| | 149 | for (Resource res:resources) { |
| | 150 | if (index.getURI().equals(res.getURI())) continue; |
| | 151 | try { |
| | 152 | res.save(null); |
| | 153 | } catch (IOException e) { |
| | 154 | log("error parsing asdoc at "+root.getUrl(), e); |
| | 155 | } |
| 136 | 156 | } |
| 137 | 157 | } |
| | 158 | protected void log(String text, Exception e) { |
| | 159 | if (AXDocPlugin.getDefault() != null) { |
| | 160 | AXDocPlugin.getDefault().log(text, e); |
| | 161 | } else { |
| | 162 | System.err.println(text); |
| | 163 | if (e!= null) |
| | 164 | e.printStackTrace(); |
| | 165 | } |
| | 166 | } |
| | 167 | public Collection<String> getPackageNames() { |
| | 168 | return packages.keySet(); |
| | 169 | } |
| | 170 | private void cachePackages(AXIndex index) { |
| | 171 | String id = index.getId(); |
| | 172 | if (id != null && id.length()>0) { |
| | 173 | List<AXIndex> list = packages.get(id); |
| | 174 | if (list == null) { |
| | 175 | list = new ArrayList<AXIndex>(); |
| | 176 | packages.put(id, list); |
| | 177 | } |
| | 178 | if (!list.contains(index)) { |
| | 179 | list.add(index); |
| | 180 | } |
| | 181 | } |
| | 182 | for (AXIndex child:index.getIndexes()) { |
| | 183 | cachePackages(child); |
| | 184 | } |
| | 185 | } |
| | 186 | protected void cachePackages() { |
| | 187 | for (AXRoot root:roots.values()) { |
| | 188 | cachePackages(root); |
| | 189 | } |
| | 190 | } |
| | 191 | public List<AXIndex> getPackages(String packname) { |
| | 192 | return packages.get(packname); |
| | 193 | } |
| 138 | 194 | } |