public Type getASType(@NonNull EObject eObject) { Element pivotElement = newCreateMap.get(eObject); if (pivotElement == null) { Resource resource = eObject.eResource(); if ((resource != ecoreResource) && (resource != null)) { Ecore2AS converter = getAdapter(resource, environmentFactory); if (allConverters.add(converter)) { converter.getASModel(); // allEClassifiers.addAll(converter.allEClassifiers); // allNames.addAll(converter.allNames); for (Map.Entry<@NonNull EObject, @NonNull Element> entry : converter.newCreateMap.entrySet()) { newCreateMap.put(entry.getKey(), entry.getValue()); } } } pivotElement = newCreateMap.get(eObject); } if (pivotElement == null) { error("Unresolved " + eObject); } else if (!(pivotElement instanceof Type)) { error("Incompatible " + eObject); } else { return (Type) pivotElement; } return null; }
protected void installImports() { URI baseURI = getBaseURI(ecoreResource); List<Import> allImports = pivotModel.getOwnedImports(); for (EObject eContent : ecoreResource.getContents()) { if (eContent instanceof EModelElement) { EAnnotation importAnnotation = ((EModelElement) eContent).getEAnnotation(PivotConstants.IMPORT_ANNOTATION_SOURCE); if (importAnnotation != null) { EMap<String, String> details = importAnnotation.getDetails(); for (String key : details.keySet()) { URI uri = URI.createURI(details.get(key)); if (baseURI != null) { uri = uri.resolve(baseURI); } try { assert uri != null; Element importedObject = metamodelManager.loadResource(uri, null, ecoreResource.getResourceSet()); if (importedObject instanceof Namespace) { Import anImport = PivotFactory.eINSTANCE.createImport(); anImport.setName(key); anImport.setImportedNamespace((Namespace) importedObject); allImports.add(anImport); } } catch (ParserException e) { error(e.getMessage()); } } } } } }
public <T extends Element> T getASElement( @NonNull Class<T> requiredClass, @NonNull EObject eObject) { if (pivotModel == null) { getASModel(); } Element element = newCreateMap.get(eObject); if (element == null) { Resource resource = eObject.eResource(); if ((resource != ecoreResource) && (resource != null)) { Ecore2AS converter = getAdapter(resource, environmentFactory); if (allConverters.add(converter)) { converter.getASModel(); for (Map.Entry<@NonNull EObject, @NonNull Element> entry : converter.newCreateMap.entrySet()) { newCreateMap.put(entry.getKey(), entry.getValue()); } } } element = newCreateMap.get(eObject); } if (element == null) { error("Unresolved " + eObject); } else if (!requiredClass.isAssignableFrom(element.getClass())) { throw new ClassCastException( element.getClass().getName() + " is not assignable to " + requiredClass.getName()); } @SuppressWarnings("unchecked") T castElement = (T) element; return castElement; }
public void update(@NonNull Resource asResource, @NonNull Collection<EObject> ecoreContents) { newCreateMap = new HashMap<@NonNull EObject, @NonNull Element>(); referencers = new HashSet<@NonNull EObject>(); genericTypes = new ArrayList<@NonNull EGenericType>(); PivotUtilInternal.refreshList( asResource.getContents(), Collections.singletonList(ClassUtil.nonNull(pivotModel))); List<org.eclipse.ocl.pivot.Package> newPackages = new ArrayList<org.eclipse.ocl.pivot.Package>(); for (EObject eObject : ecoreContents) { EClass eClass = eObject.eClass(); if (eClass.getEPackage() != EcorePackage.eINSTANCE) { error("Non Ecore " + eClass.getName() + " for Ecore2AS.update"); } else { Object pivotElement = declarationPass.doInPackageSwitch(eObject); if (pivotElement instanceof org.eclipse.ocl.pivot.Package) { newPackages.add((org.eclipse.ocl.pivot.Package) pivotElement); } else { error("Bad ecore content"); } } } PivotUtilInternal.refreshList(pivotModel.getOwnedPackages(), newPackages); Map<@NonNull String, @NonNull Type> resolvedSpecializations = new HashMap<@NonNull String, @NonNull Type>(); for (@NonNull EGenericType eGenericType : genericTypes) { Type pivotType = resolveType(resolvedSpecializations, eGenericType); if (pivotType != null) { newCreateMap.put(eGenericType, pivotType); } } for (EObject eObject : referencers) { referencePass.doInPackageSwitch(eObject); } for (EObject eObject : referencers) { if (eObject instanceof EReference) { Property pivotElement = getCreated(Property.class, eObject); if (pivotElement != null) { Property oppositeProperty = pivotElement.getOpposite(); if ((oppositeProperty == null) && (eObject.eContainer() instanceof EClass)) { // Skip annotation references metamodelManager.installPropertyDeclaration(pivotElement); } } } } referencers = null; genericTypes = null; oldIdMap = new HashMap<@NonNull String, @NonNull Element>(); for (EObject ecoreContent : ecoreContents) { Resource resource = ecoreContent.eResource(); if (resource instanceof XMLResource) { XMLResource xmlResource = (XMLResource) resource; String id = xmlResource.getID(ecoreContent); if (id != null) { Element element = newCreateMap.get(ecoreContent); if (element != null) { oldIdMap.put(id, element); } } for (TreeIterator<EObject> tit = ecoreContent.eAllContents(); tit.hasNext(); ) { EObject eObject = tit.next(); id = xmlResource.getID(eObject); if (id != null) { Element element = newCreateMap.get(eObject); if (element != null) { oldIdMap.put(id, element); } } } } } }