コード例 #1
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 /**
  * Convert an (annotated) Ecore resource to a Pivot Model.
  *
  * @param alias
  * @param ecoreResource the annotated Ecore resource
  * @return the Pivot root package
  */
 public static @NonNull Model importFromEcore(
     @NonNull EnvironmentFactoryInternal environmentFactory,
     String alias,
     @NonNull Resource ecoreResource) {
   Ecore2AS conversion = getAdapter(ecoreResource, environmentFactory);
   return conversion.getASModel();
 }
コード例 #2
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 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;
 }
コード例 #3
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 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;
 }
コード例 #4
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;
  }
コード例 #5
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 /**
  * Convert an (annotated) Ecore object to a pivot element.
  *
  * @param eObject the annotated Ecore object
  * @return the pivot element
  */
 public static Element importFromEcore(
     @NonNull EnvironmentFactoryInternal environmentFactory,
     String alias,
     @NonNull EObject eObject) {
   Resource ecoreResource = ClassUtil.nonNullEMF(eObject.eResource());
   Ecore2AS conversion = getAdapter(ecoreResource, environmentFactory);
   @SuppressWarnings("unused")
   Model pivotModel = conversion.getASModel();
   return conversion.newCreateMap.get(eObject);
 }
コード例 #6
0
ファイル: PivotUtilInternal.java プロジェクト: eclipse/ocl
 public static Type findTypeOf(
     @NonNull MetamodelManagerInternal metamodelManager, @NonNull EClassifier eClass) {
   Resource resource = eClass.eResource();
   if (resource != null) {
     External2AS adapter =
         Ecore2AS.findAdapter(resource, metamodelManager.getEnvironmentFactory());
     if (adapter != null) {
       Type type = adapter.getCreated(Type.class, eClass);
       if (type != null) {
         return type;
       }
     }
   }
   return null;
 }
コード例 #7
0
 public @NonNull Type getType(@NonNull EClassifier eClassifier) {
   Ecore2AS ecore2as =
       Ecore2AS.getAdapter(ClassUtil.nonNullEMF(eClassifier.eResource()), environmentFactory);
   Type pivotType = ecore2as.getCreated(Type.class, eClassifier);
   return ClassUtil.nonNullState(pivotType);
 }