Exemple #1
0
 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;
 }
Exemple #2
0
 public static @NonNull <T extends Element> T getNonNullAst(
     @NonNull Class<T> pivotClass, @NonNull Pivotable pivotableElement) {
   //		if (pivotableElement == null) {
   //			return null;
   //		}
   Element pivotElement = pivotableElement.getPivot();
   if (pivotElement == null) {
     throw new IllegalStateException("Null pivotElementfor a " + pivotClass.getName());
   }
   if (!pivotClass.isAssignableFrom(pivotElement.getClass())) {
     throw new ClassCastException(
         pivotElement.getClass().getName() + " is not assignable to " + pivotClass.getName());
   }
   @SuppressWarnings("unchecked")
   T castElement = (T) pivotElement;
   return castElement;
 }
Exemple #3
0
 public @Nullable <T extends Element> T getASOfEcore(
     @NonNull Class<T> requiredClass, @NonNull EObject eObject) {
   if (pivotModel == null) {
     getASModel();
   }
   Element element = newCreateMap.get(eObject);
   if (element == null) {
     return null;
   }
   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;
 }