Example #1
0
 public static <T extends Element> T getPivot(Class<T> pivotClass, Pivotable pivotableElement) {
   if (pivotableElement == null) {
     return null;
   }
   Element pivotElement = pivotableElement.getPivot();
   if (pivotElement == null) {
     return null;
   }
   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;
 }
Example #2
0
 @Override
 public String toString() {
   StringBuffer s = new StringBuffer();
   s.append(getClass().getSimpleName());
   s.append(" : ");
   if (pivotParent != null) {
     s.append(pivotParent.eClass().getName());
   } else if (csElement instanceof EObject) {
     s.append(((EObject) csElement).eClass().getName());
   } else {
     s.append("???");
   }
   s.append(".");
   s.append(pivotFeature != null ? pivotFeature.getName() : "*");
   s.append(" : ");
   String elementName = null;
   if (csElement instanceof MonikeredElementCS) {
     MonikeredElementCS csMonikeredElement = (MonikeredElementCS) csElement;
     if (csMonikeredElement.hasMoniker()) {
       elementName = csMonikeredElement.getMoniker();
     }
   }
   if (elementName == null) {
     elementName = csElement.toString();
   }
   s.append(elementName);
   return s.toString();
 }