public @NonNull Model importObjects( @NonNull Collection<EObject> ecoreContents, @NonNull URI pivotURI) { EPackage libraryEPackage = isLibrary(ecoreContents); if (libraryEPackage != null) { newCreateMap = new HashMap<@NonNull EObject, @NonNull Element>(); org.eclipse.ocl.pivot.Package asLibrary = standardLibrary.getPackage(); newCreateMap.put(libraryEPackage, asLibrary); List<org.eclipse.ocl.pivot.Class> ownedType = asLibrary.getOwnedClasses(); // int prefix = LibraryConstants.ECORE_STDLIB_PREFIX.length(); for (@SuppressWarnings("null") @NonNull EClassifier eClassifier : libraryEPackage.getEClassifiers()) { String name = environmentFactory.getTechnology().getOriginalName(eClassifier); // .substring(prefix); Type asType = NameUtil.getNameable(ownedType, name); if (asType != null) { newCreateMap.put(eClassifier, asType); } } Model containingRoot = PivotUtil.getContainingModel(asLibrary); return ClassUtil.nonNullModel(containingRoot); } @NonNull ASResource asResource = metamodelManager.getResource(pivotURI, ASResource.ECORE_CONTENT_TYPE); // try { if ((metamodelManager.getLibraryResource() == null) && isPivot(ecoreContents)) { String nsURI = ((EPackage) ecoreContents.iterator().next()).getNsURI(); if (nsURI != null) { String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION; OCLstdlib library = OCLstdlib.create(stdlibASUri); metamodelManager.installResource(library); // metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE); } } URI uri = ecoreURI != null ? ecoreURI : ecoreResource.getURI(); Model pivotModel2 = null; if (asResource.getContents().size() > 0) { EObject eObject = asResource.getContents().get(0); if (eObject instanceof Model) { pivotModel2 = (Model) eObject; } } if (pivotModel2 == null) { pivotModel2 = pivotModel = PivotUtil.createModel(uri.toString()); } pivotModel = pivotModel2; // installImports(); update(asResource, ecoreContents); // } // catch (Exception e) { // if (errors == null) { // errors = new ArrayList<Resource.Diagnostic>(); // } // errors.add(new XMIException("Failed to load '" + pivotURI + "'", e)); // } List<Diagnostic> errors2 = errors; if (errors2 != null) { asResource.getErrors().addAll(ClassUtil.nullFree(errors2)); } return pivotModel2; }
public boolean accepts(/*@NonNull*/ EClass eClass) { assert eClass != null; // If eClass conformsTo requiredType every candidate will be type-compatible // If requiredType conformsTo eClass some candidates may be type-compatible // else no candidates can be type-compatible return (name == null) || PivotUtil.conformsTo(requiredType, eClass) || ((requiredType != null) && PivotUtil.conformsTo(eClass, requiredType)); }
public void addAllOperations( org.eclipse.ocl.pivot.@NonNull Class type, @Nullable FeatureFilter featureFilter) { if (accepts( PivotPackage.Literals.ITERATION) // If ITERATION is acceptable then so too is OPERATION && (requiredType != PivotPackage.Literals .NAMESPACE)) { // Don't really want operations when looking for NAMESPACE assert environmentFactory.getMetamodelManager().isTypeServeable(type); type = PivotUtil.getUnspecializedTemplateableElement(type); CompleteClass completeClass = environmentFactory.getMetamodelManager().getCompleteClass(type); String name2 = name; if (name2 != null) { for (Operation operation : completeClass.getOperations(featureFilter, name2)) { if ((operation != null) /*&& (operation.isStatic() == selectStatic)*/) { addElement(name2, operation); } } } else { for (Operation operation : completeClass.getOperations(featureFilter)) { if ((operation != null) /*&& (operation.isStatic() == selectStatic)*/) { addNamedElement(operation); } } } } }
public static Ecore2AS loadFromEcore(@NonNull ASResource ecoreASResource, @NonNull URI ecoreURI) { EnvironmentFactoryInternal environmentFactory = PivotUtilInternal.getEnvironmentFactory(ecoreASResource); ResourceSet resourceSet = environmentFactory.getResourceSet(); Resource ecoreResource = resourceSet.getResource(ecoreURI, true); if (ecoreResource == null) { return null; } Ecore2AS conversion = getAdapter(ecoreResource, environmentFactory); conversion.loadImports(ecoreResource); // if (asMetamodels != null) { // // } PivotMetamodelManager metamodelManager = environmentFactory.getMetamodelManager(); conversion.pivotModel = PivotUtil.createModel(ecoreASResource.getURI().toString()); // conversion.installImports(); conversion.update(ecoreASResource, ClassUtil.nonNullEMF(ecoreResource.getContents())); AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource); if (ecoreAdapter != null) { Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap(); AliasAdapter pivotAdapter = AliasAdapter.getAdapter(ecoreASResource); Map<EObject, String> pivotAliasMap = pivotAdapter.getAliasMap(); for (EObject eObject : ecoreAliasMap.keySet()) { String alias = ecoreAliasMap.get(eObject); Element element = conversion.newCreateMap.get(eObject); pivotAliasMap.put(element, alias); } } metamodelManager.installResource(ecoreASResource); conversion.installImports(); return conversion; }
@Override public int compare( @NonNull EnvironmentFactoryInternal environmentFactory, @NonNull Feature match1, @NonNull Feature match2) { org.eclipse.ocl.pivot.Package p1 = PivotUtil.getContainingPackage(match1); org.eclipse.ocl.pivot.Package p2 = PivotUtil.getContainingPackage(match2); if (p1 == null) { return 0; } if (p2 == null) { return 0; } CompleteModel completeModel = environmentFactory.getCompleteModel(); CompletePackage s1 = completeModel.getCompletePackage(p1); CompletePackage s2 = completeModel.getCompletePackage(p2); if (s1 != s2) { return 0; } int i1 = s1.getIndex(p1); int i2 = s2.getIndex(p2); return i2 - i1; }
public void addAllElements( org.eclipse.ocl.pivot.@NonNull Class asClass, @NonNull ScopeView scopeView) { Attribution attribution = PivotUtilInternal.getAttribution(asClass); attribution.computeLookup(asClass, this, scopeView); org.eclipse.ocl.pivot.Class asUnspecializedClass = PivotUtil.getUnspecializedTemplateableElement(asClass); org.eclipse.ocl.pivot.Package asPackage = asUnspecializedClass.getOwningPackage(); if (asPackage != null) { attribution = PivotUtilInternal.getAttribution(asPackage); attribution.computeLookup(asPackage, this, scopeView); } { // FIXME redundant asPackage = asUnspecializedClass.getOwningPackage(); if (asPackage != null) { attribution = PivotUtilInternal.getAttribution(asPackage); attribution.computeLookup(asPackage, this, scopeView); } } }
@Override public ScopeView computeLookup( @NonNull EObject target, @NonNull EnvironmentView environmentView, @NonNull ScopeView scopeView) { EStructuralFeature containmentFeature = scopeView.getContainmentFeature(); if (containmentFeature == EssentialOCLCSPackage.Literals.SHADOW_PART_CS__REFERRED_PROPERTY) { ShadowPartCS targetElement = (ShadowPartCS) target; CurlyBracketedClauseCS csCurlyBracketClause = targetElement.getOwningCurlyBracketClause(); AbstractNameExpCS csNameExp = csCurlyBracketClause.getOwningNameExp(); ShadowExp pivot = PivotUtil.getPivot(ShadowExp.class, csNameExp); if (pivot != null) { Type type = pivot.getType(); if (type instanceof org.eclipse.ocl.pivot.Class) { environmentView.addAllProperties( (org.eclipse.ocl.pivot.Class) type, FeatureFilter.SELECT_NON_STATIC); } } return null; } return scopeView.getParent(); }
public void setRequiredType(@Nullable EClassifier requiredType) { assert (requiredType == null) || PivotUtil.conformsTo(reference.getEType(), requiredType); this.requiredType = requiredType; }