예제 #1
0
  @Override
  protected String elementName(final EObject p_element) {
    if (p_element instanceof NamedElement) {
      return ((NamedElement) p_element).getName() == null
          ? p_element.toString()
          : ((NamedElement) p_element).getName();
    }

    return p_element.toString();
  }
  /**
   * Check expected selected elements.
   *
   * @param editor the editor
   * @param objectsNameToCheck object names to check
   * @param expectedSize expected size
   * @param semanticObjectName true if objectsNameToCheck contains object names of the semantic
   *     object at the root of selected elements
   */
  protected void checkExpectedElementsInSelection(
      DialectEditor editor,
      List<String> objectsNameToCheck,
      int expectedSize,
      boolean semanticObjectName) {
    List<DSemanticDecorator> selections =
        Lists.newArrayList(DialectUIManager.INSTANCE.getSelection(editor));

    assertEquals("Bad selection size, after tool execution.", expectedSize, selections.size());

    if (objectsNameToCheck != null) {
      for (int i = 0; i < objectsNameToCheck.size(); i++) {
        String objectNameToCheck = objectsNameToCheck.get(i);
        String selectionName = "";
        if (semanticObjectName) {
          EObject target = selections.get(i).getTarget();
          if (target != null) {
            selectionName = target.toString();
          }
        } else {
          selectionName = selections.get(i).toString();
        }
        assertTrue(
            "Bad selection after tool execution. Missing object :" + objectNameToCheck,
            selectionName.contains(objectNameToCheck));
      }
    }
  }
예제 #3
0
파일: LabelAdapter.java 프로젝트: rnc/tools
 /**
  * @param objectForLabel Object needing a label
  * @return String for label
  */
 public static String getLabel(EObject objectForLabel) {
   if (objectForLabel instanceof Binding) {
     return getLabelForBindingType((Binding) objectForLabel);
   } else if (objectForLabel instanceof TransformType) {
     return getLabelForTransformType((TransformType) objectForLabel);
   } else if (objectForLabel instanceof ValidateType) {
     return getLabelForValidatorType((ValidateType) objectForLabel);
   }
   return objectForLabel.toString();
 }
 private String getLabel(EObject eObject) {
   AdapterFactory adapterFactory = getAdapterFactory(eObject);
   if (adapterFactory == null) {
     return "";
   }
   IItemLabelProvider itemLabelProvider =
       (IItemLabelProvider) adapterFactory.adapt(eObject, IItemLabelProvider.class);
   return itemLabelProvider != null
       ? itemLabelProvider.getText(eObject)
       : eObject == null ? "" : eObject.toString();
 }
예제 #5
0
 @Test
 public void map() {
   final List<EObject> list = new ArrayList<EObject>();
   final EObject o1 = EcoreFactory.eINSTANCE.createEObject();
   final EObject o2 = EcoreFactory.eINSTANCE.createEObject();
   list.add(o1);
   list.add(o2);
   final List<String> mapped =
       EMFUtils.map(
           list,
           new Object() {
             @SuppressWarnings("unused")
             public String doSwitch(EObject obj) {
               return obj.toString();
             }
           });
   final List<String> stringified = new ArrayList<String>();
   stringified.add(o1.toString());
   stringified.add(o2.toString());
   assertEquals(stringified, mapped);
 }
 protected String produceDeResolveErrorMessage(
     org.eclipse.emf.ecore.EObject refObject,
     org.eclipse.emf.ecore.EObject container,
     org.eclipse.emf.ecore.EReference reference,
     ssl.resource.ssl.ISslTextResource resource) {
   String msg =
       getClass().getSimpleName()
           + ": "
           + reference.getEType().getName()
           + " \""
           + refObject.toString()
           + "\" not de-resolveable";
   return msg;
 }
예제 #7
0
 public void verify(ContentAssistContext contentAssistContext) {
   EObject currentModel = contentAssistContext.getCurrentModel();
   assertEquals(currentModel.toString(), expectedClass, currentModel.eClass());
   if (expectedClassName != null) {
     assertTrue(
         contentAssistContext.getCurrentModel()
             instanceof org.eclipse.xtext.ui.tests.editor.contentassist.domainModelTest.Class);
     assertEquals(
         expectedClassName,
         ((org.eclipse.xtext.ui.tests.editor.contentassist.domainModelTest.Class)
                 contentAssistContext.getCurrentModel())
             .getName());
   }
 }
  public static String getEObjectLabel(EObject eObject) {
    String name = null;
    String label = null;
    String id = null;

    for (EAttribute attribute : eObject.eClass().getEAllAttributes()) {
      if (attribute.getName().equalsIgnoreCase("name")) {
        name = (String) eObject.eGet(attribute);
        break;
      }
    }

    for (EOperation operation : eObject.eClass().getEAllOperations()) {
      try {
        if (operation.getName().equals("getName") && name == null)
          name = (String) eObject.eInvoke(operation, null);
        if (operation.getName().equals("getLabel") && label == null)
          label = (String) eObject.eInvoke(operation, null);
        if (operation.getName().equals("getID") && id == null)
          id = (String) eObject.eInvoke(operation, null);
        if (operation.getName().equals("getId") && id == null)
          id = (String) eObject.eInvoke(operation, null);
      } catch (Exception e) {
      }
    }

    if (name != null && !name.isEmpty()) return name;
    if (label != null && !label.isEmpty()) return label;
    if (id != null && !id.isEmpty()) return id;

    if (eObject instanceof ENamedElement)
      if (((ENamedElement) eObject).getName() != null
          && !((ENamedElement) eObject).getName().equals(""))
        return ((ENamedElement) eObject).getName();
      else return eObject.toString();
    else return eObject.toString();
  }
예제 #9
0
 @Test
 public void filterMap() {
   final List<EObject> list = new ArrayList<EObject>();
   final EObject o1 = EcoreFactory.eINSTANCE.createEObject();
   final EObject o2 = EcoreFactory.eINSTANCE.createEObject();
   list.add(o1);
   list.add(o2);
   final List<String> mapped =
       EMFUtils.filterMap(
           list,
           new Object() {
             @SuppressWarnings("unused")
             public String doSwitch(EObject obj) {
               if (obj == o1) return obj.toString();
               return null;
             }
           });
   assertEquals(Collections.singletonList(o1.toString()), mapped);
 }
예제 #10
0
 protected String _grammarElementAccess(final EObject it) {
   String _string = it.toString();
   return ("Unsupported : grammarElementAccess for: " + _string);
 }
예제 #11
0
 protected String _grammarElementIdentifier(final EObject it) {
   String _string = it.toString();
   return ("Unsupported : grammarElementIdentifier for: " + _string);
 }
 /**
  * Default constructor.
  *
  * @param eObject the eObject that failed to serialize
  */
 public SerializationException(EObject eObject) {
   super(DE_SERIALIZATION_FAILED + ": " + eObject.toString()); // $NON-NLS-1$
 }
예제 #13
0
 protected String toString(EObject ele) {
   if (ele instanceof AbstractElement) return grammarToString.apply((AbstractElement) ele);
   if (ele instanceof AbstractRule)
     return ele.eClass().getName() + "'" + ((AbstractRule) ele).getName() + "'";
   return ele.toString();
 }