コード例 #1
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 protected @NonNull URI createPivotURI() {
   if (ecoreURI != null) {
     return PivotUtilInternal.getASURI(ecoreURI.trimFragment());
   }
   URI uri = ecoreResource.getURI();
   if (uri == null) {
     throw new IllegalStateException("Missing resource URI");
   }
   return PivotUtilInternal.getASURI(uri);
 }
コード例 #2
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public LookupEnvironment addElement(final NamedElement element) {
   /**
    * LookupEnvironment{ namedElements = namedElements->including(element), parentEnv = parentEnv }
    */
   final /*@NonInvalid*/ org.eclipse.ocl.pivot.evaluation.@NonNull Executor executor =
       PivotUtilInternal.getExecutor(this);
   final /*@NonInvalid*/ org.eclipse.ocl.pivot.ids.@NonNull IdResolver idResolver =
       executor.getIdResolver();
   final /*@NonInvalid*/ org.eclipse.ocl.pivot.@NonNull Property CTORid_namedElements =
       idResolver.getProperty(EnvironmentTables.PROPid_namedElements);
   final /*@NonInvalid*/ org.eclipse.ocl.pivot.@NonNull Property CTORid_parentEnv =
       idResolver.getProperty(EnvironmentTables.PROPid_parentEnv);
   final /*@NonInvalid*/ org.eclipse.ocl.pivot.@NonNull Class TYP_lookup_c_c_LookupEnvironment_0 =
       idResolver.getClass(EnvironmentTables.CLSSid_LookupEnvironment, null);
   final /*@Thrown*/ example2.classes.lookup.@NonNull LookupEnvironment symbol_0 =
       (LookupEnvironment) TYP_lookup_c_c_LookupEnvironment_0.createInstance();
   @SuppressWarnings("null")
   final /*@Thrown*/ java.util.@NonNull List<NamedElement> namedElements = this.getNamedElements();
   final /*@Thrown*/ org.eclipse.ocl.pivot.values.@NonNull OrderedSetValue BOXED_namedElements =
       idResolver.createOrderedSetOfAll(EnvironmentTables.ORD_CLSSid_NamedElement, namedElements);
   final /*@Thrown*/ org.eclipse.ocl.pivot.values.@NonNull OrderedSetValue including =
       (OrderedSetValue)
           CollectionIncludingOperation.INSTANCE.evaluate(BOXED_namedElements, element);
   final List<NamedElement> UNBOXED_including =
       including.asEcoreObjects(idResolver, NamedElement.class);
   assert UNBOXED_including != null;
   CTORid_namedElements.initValue(symbol_0, UNBOXED_including);
   final /*@Thrown*/ example2.classes.lookup.@Nullable LookupEnvironment parentEnv =
       this.getParentEnv();
   CTORid_parentEnv.initValue(symbol_0, parentEnv);
   return symbol_0;
 }
コード例 #3
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
  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;
  }
コード例 #4
0
 public void addImportedElement(@NonNull URI baseURI) {
   if (PivotUtilInternal.isASURI(baseURI)) {
     baseURI = PivotUtilInternal.getNonASURI(baseURI);
   }
   String name = getName();
   if (name != null) {
     @NonNull URI uri = URI.createURI(name).resolve(baseURI);
     try {
       Element importedElement =
           environmentFactory.getMetamodelManager().loadResource(uri, null, null);
       if (importedElement != null) {
         addElement(name, importedElement);
       }
     } catch (Exception e) {
       // if it doesn't load just treat it as unresolved
     }
   }
 }
コード例 #5
0
 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);
     }
   }
 }
コード例 #6
0
ファイル: PivotUtilInternal.java プロジェクト: eclipse/ocl
 public static @NonNull EnvironmentFactoryInternal getEnvironmentFactory(
     @NonNull Resource resource) {
   EnvironmentFactoryInternal environmentFactory =
       PivotUtilInternal.findEnvironmentFactory(resource);
   if (environmentFactory == null) {
     ResourceSet resourceSet = resource.getResourceSet();
     if (resourceSet != null) {
       environmentFactory = OCLAdapter.createEnvironmentFactory(resourceSet);
     } else {
       environmentFactory = OCLAdapter.createEnvironmentFactory(resource);
     }
   }
   return environmentFactory;
 }
コード例 #7
0
 public void addElementsOfScope(@Nullable Element asElement, @NonNull ScopeView scopeView) {
   if (asElement != null) {
     Attribution attribution = PivotUtilInternal.getAttribution(asElement);
     attribution.computeLookup(asElement, this, scopeView);
   }
 }
コード例 #8
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 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);
           }
         }
       }
     }
   }
 }