private void convertExec(Exec exec, ICommandFormatter formatter, boolean hasInput) { if (exec.getNamespace() != null) formatter.addCommandName(exec.getNamespace() + "::" + exec.getName()); else formatter.addCommandName(exec.getName()); String lastParam = null; for (Parameter p : exec.getParameters()) { String name = p.getName(); formatter.addAttrName(name, isForced(exec.getName(), name) && !name.equals(lastParam)); lastParam = name; if (p instanceof LiteralParameter) { String value = convertValue(((LiteralParameter) p).getLiteral(), "string"); formatter.addAttrValue(value); } else if (p instanceof ExecutableParameter) { formatter.openExec(); doConvert(((ExecutableParameter) p).getCommand(), formatter, hasInput); formatter.closeExec(); } } }
// 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; } }