예제 #1
0
  protected Map<Declaration, Boolean> handleStyle(Style style) {
    if (style instanceof NamedStyle) {
      return Collections.emptyMap();
    }

    Map<Declaration, Boolean> declarations = new LinkedHashMap<Declaration, Boolean>();

    for (EStructuralFeature feature : style.eClass().getEAllStructuralFeatures()) {
      if (NotationPackage.eINSTANCE.getStyle().isSuperTypeOf(feature.getEContainingClass())) {
        Object currentValue = style.eGet(feature);
        Object defaultValue = feature.getDefaultValue();
        boolean check =
            currentValue == null
                ? currentValue != defaultValue
                : !currentValue.equals(defaultValue);

        Declaration declaration = handleStyleFeature(style, feature);
        if (declaration.getExpression()
            != null) { // If expression is null, the type of this property is not supported
          declarations.put(declaration, check);
        }
      }
    }

    return declarations;
  }
예제 #2
0
  /**
   * Tests the behavior of attribute <code>kind</code>'s accessors.
   *
   * @generated
   */
  @Test
  public void testKind() {
    EStructuralFeature feature = org.eclipse.emf.compare.ComparePackage.eINSTANCE.getDiff_Kind();
    ReferenceChange referenceChange = CompareFactory.eINSTANCE.createReferenceChange();
    referenceChange.eAdapters().add(new MockEAdapter());
    org.eclipse.emf.compare.DifferenceKind kindValue =
        (org.eclipse.emf.compare.DifferenceKind) feature.getDefaultValue();
    for (org.eclipse.emf.compare.DifferenceKind aDifferenceKind :
        org.eclipse.emf.compare.DifferenceKind.VALUES) {
      if (kindValue.getValue() != aDifferenceKind.getValue()) {
        kindValue = aDifferenceKind;
        break;
      }
    }

    assertFalse(referenceChange.eIsSet(feature));
    assertEquals(feature.getDefaultValue(), referenceChange.getKind());

    referenceChange.setKind(kindValue);
    assertTrue(notified);
    notified = false;
    assertEquals(kindValue, referenceChange.getKind());
    assertEquals(referenceChange.getKind(), referenceChange.eGet(feature));
    assertTrue(referenceChange.eIsSet(feature));

    referenceChange.eUnset(feature);
    assertTrue(notified);
    notified = false;
    assertEquals(feature.getDefaultValue(), referenceChange.getKind());
    assertEquals(referenceChange.getKind(), referenceChange.eGet(feature));
    assertFalse(referenceChange.eIsSet(feature));

    referenceChange.eSet(feature, kindValue);
    assertTrue(notified);
    notified = false;
    assertEquals(kindValue, referenceChange.getKind());
    assertEquals(referenceChange.getKind(), referenceChange.eGet(feature));
    assertTrue(referenceChange.eIsSet(feature));

    referenceChange.setKind(null);
    assertTrue(notified);
    notified = false;
    assertEquals(feature.getDefaultValue(), referenceChange.getKind());
    assertEquals(referenceChange.getKind(), referenceChange.eGet(feature));
    assertFalse(referenceChange.eIsSet(feature));
  }
예제 #3
0
  /**
   * Tests the behavior of reference <code>conflict</code>'s accessors.
   *
   * @generated
   */
  @Test
  public void testConflict() {
    EStructuralFeature feature =
        org.eclipse.emf.compare.ComparePackage.eINSTANCE.getDiff_Conflict();
    ReferenceChange referenceChange = CompareFactory.eINSTANCE.createReferenceChange();
    referenceChange.eAdapters().add(new MockEAdapter());
    org.eclipse.emf.compare.Conflict conflictValue =
        org.eclipse.emf.compare.CompareFactory.eINSTANCE.createConflict();

    assertFalse(referenceChange.eIsSet(feature));
    assertNull(referenceChange.getConflict());

    referenceChange.setConflict(conflictValue);
    assertTrue(notified);
    notified = false;
    assertSame(conflictValue, referenceChange.getConflict());
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature));
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(conflictValue.getDifferences().contains(referenceChange));

    referenceChange.eUnset(feature);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getConflict());
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature));
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));
    assertFalse(conflictValue.getDifferences().contains(referenceChange));

    referenceChange.setConflict(conflictValue);
    assertTrue(notified);
    notified = false;
    assertSame(conflictValue, referenceChange.getConflict());
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature));
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(conflictValue.getDifferences().contains(referenceChange));

    referenceChange.eSet(feature, conflictValue);
    assertTrue(notified);
    notified = false;
    assertSame(conflictValue, referenceChange.getConflict());
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature));
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(conflictValue.getDifferences().contains(referenceChange));

    referenceChange.setConflict(null);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getConflict());
    assertSame(feature.getDefaultValue(), referenceChange.getConflict());
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature));
    assertSame(referenceChange.getConflict(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));
    assertFalse(conflictValue.getDifferences().contains(referenceChange));
  }
예제 #4
0
  /**
   * Tests the behavior of reference <code>value</code>'s accessors.
   *
   * @generated
   */
  @Test
  public void testValue() {
    EStructuralFeature feature =
        org.eclipse.emf.compare.ComparePackage.eINSTANCE.getReferenceChange_Value();
    ReferenceChange referenceChange = CompareFactory.eINSTANCE.createReferenceChange();
    referenceChange.eAdapters().add(new MockEAdapter());
    org.eclipse.emf.ecore.EObject valueValue =
        org.eclipse.emf.ecore.EcoreFactory.eINSTANCE.createEObject();

    assertFalse(referenceChange.eIsSet(feature));
    assertNull(referenceChange.getValue());

    referenceChange.setValue(valueValue);
    assertTrue(notified);
    notified = false;
    assertSame(valueValue, referenceChange.getValue());
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature));
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));

    referenceChange.eUnset(feature);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getValue());
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature));
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));

    referenceChange.setValue(valueValue);
    assertTrue(notified);
    notified = false;
    assertSame(valueValue, referenceChange.getValue());
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature));
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));

    referenceChange.eSet(feature, valueValue);
    assertTrue(notified);
    notified = false;
    assertSame(valueValue, referenceChange.getValue());
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature));
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));

    referenceChange.setValue(null);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getValue());
    assertSame(feature.getDefaultValue(), referenceChange.getValue());
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature));
    assertSame(referenceChange.getValue(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));
  }
예제 #5
0
  protected Map<Attribute, Boolean> handleSemantic(View view) {
    Map<Attribute, Boolean> result = new LinkedHashMap<Attribute, Boolean>();

    EObject semanticElement = view.getElement();

    for (EStructuralFeature feature : semanticElement.eClass().getEAllStructuralFeatures()) {
      if (isBoolean(feature) || isInteger(feature) || feature.getEType() instanceof EEnum) {
        Attribute attributeCondition = CssFactory.eINSTANCE.createAttribute();
        attributeCondition.setName(feature.getName());

        AttributeValue attributeValue = CssFactory.eINSTANCE.createAttributeValue();
        attributeValue.setOperator(ATTRIBUTE_OP.EQUALS);
        attributeValue.setValue(semanticElement.eGet(feature).toString());
        attributeCondition.setValue(attributeValue);

        boolean check = semanticElement.eGet(feature) != feature.getDefaultValue();

        result.put(attributeCondition, check);
      }
    }

    return result;
  }
예제 #6
0
  // TODO ! need new presentation of set-text-selection command or hide args
  protected void convertSimple(Command command, ICommandFormatter formatter, boolean hasInput) {
    String commandName = CoreUtils.getScriptletNameByClass(command.eClass());
    formatter.addCommandName(commandName);

    Map<EStructuralFeature, Command> bindingMap = new HashMap<EStructuralFeature, Command>();
    for (Binding b : command.getBindings()) {
      bindingMap.put(b.getFeature(), b.getCommand());
    }

    List<EStructuralFeature> attributes = CoreUtils.getFeatures(command.eClass());

    boolean forced = false;
    boolean bigTextCommand =
        commandName.equals("upload-file") || commandName.equals("match-binary");

    for (EStructuralFeature feature : attributes) {
      if (feature.getEAnnotation(CoreUtils.INTERNAL_ANN) != null) continue;
      if (feature.getEAnnotation(CoreUtils.INPUT_ANN) != null && hasInput) continue;
      String name = feature.getName();
      if (isForced(commandName, name)) forced = true;
      Object val = command.eGet(feature);
      boolean skippped = true;
      Object defaultValue = feature.getDefaultValue();
      boolean isDefault = val == null || val.equals(defaultValue);
      if (!isDefault) {
        if (feature instanceof EAttribute) {
          EAttribute attr = (EAttribute) feature;
          String type = attr.getEAttributeType().getInstanceTypeName();
          if (val instanceof List<?>) {
            List<?> list = (List<?>) val;
            for (Object o : list) {
              String value = convertValue(o, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                formatter.addAttrValue(value);
                skippped = false;
              }
            }
          } else {
            if (val.equals(true)) {
              forced = true;
              formatter.addAttrName(name, forced);
            } else {
              String value = convertValue(val, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                if (bigTextCommand) formatter.addAttrValueWithLineBreak(value);
                else formatter.addAttrValue(value);
                skippped = false;
              }
            }
          }
        } else {
          EReference ref = (EReference) feature;
          EClass eclass = ref.getEReferenceType();
          if (eclass.getEPackage() == CorePackage.eINSTANCE
              && eclass.getClassifierID() == CorePackage.COMMAND) {
            boolean singleLine = !(val instanceof Sequence);
            formatter.addAttrName(name, forced);
            formatter.openGroup(singleLine);
            doConvert((Command) val, formatter, true);
            formatter.closeGroup(singleLine);
            skippped = false;
          } else {
            IParamConverter<?> converter =
                ParamConverterManager.getInstance().getConverter(eclass.getInstanceClass());
            if (converter != null) {
              try {
                String strVal = String.format("\"%s\"", converter.convertToCode(val));
                formatter.addAttrValue(strVal);
              } catch (CoreException e) {
                CorePlugin.log(e.getStatus());
              }
            }
          }
        }
      } else {
        Command c = bindingMap.get(feature);
        if (c != null) {
          formatter.addAttrName(name, forced);
          formatter.openExec();
          doConvert(c, formatter, hasInput);
          formatter.closeExec();
          skippped = false;
        }
      }
      if (skippped) forced = true;
    }
  }