private EClassifier resolveFeatureType( EStructuralFeature feature, Collection<EClassifierMapping> eClassifierMappings, Collection<EPackage> ePackages) { EAnnotation eAnnotation = feature.getEAnnotation(TypesPackage.eNS_URI); if (eAnnotation != null) { JvmTypeReference type = getEObject(eAnnotation.getReferences(), JvmTypeReference.class, null); if (type == null) { return null; } EClassifier eClassifier = null; for (EClassifierMapping eClassifierMapping : eClassifierMappings) { if (eClassifierMapping.getDeclaredType() == type) { eClassifier = eClassifierMapping.getEClassifier(); break; } } String typeName = getTypeName(type); if (eClassifier == null) { for (EPackage ePackage : ePackages) { eClassifier = findEClassifier(typeName, ePackage); if (eClassifier != null) { break; } } } if (eClassifier == null) { eClassifier = findEClassifier(typeName, EcorePackage.eINSTANCE); } feature.setEType(eClassifier); return eClassifier; } return null; }
private void writeEDataType(PrintWriter out, EObject object, EStructuralFeature feature) throws SerializerException { if (feature.getEAnnotation("derived") != null) { out.print(ASTERISK); } else if (feature.isMany()) { writeList(out, object, feature); } else { writeObject(out, object, feature); } }
@SuppressWarnings("unchecked") private void writeTable(PrintWriter out, EObject eObject) { out.println("<h1>" + eObject.eClass().getName() + "</h1>"); out.println("<table>"); for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) { if (eStructuralFeature.getEAnnotation("hidden") == null) { out.println("<tr>"); out.println("<td>" + eStructuralFeature.getName() + "</td>"); Object eGet = eObject.eGet(eStructuralFeature); if (eStructuralFeature instanceof EAttribute) { if (eStructuralFeature.getUpperBound() == 1) { out.println("<td>" + eGet + "</td>"); } else { List<Object> list = (List<Object>) eGet; out.println("<td>"); for (Object object : list) { out.println(object + " "); } out.println("</td>"); } } else if (eStructuralFeature instanceof EReference) { if (eStructuralFeature.getUpperBound() == 1) { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { EObject value = (EObject) eGet; if (value != null) { out.println( "<td>" + value.eGet(value.eClass().getEStructuralFeature("wrappedValue")) + "</td>"); } } else { } } else { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { List<EObject> list = (List<EObject>) eGet; out.println("<td>"); for (EObject object : list) { out.println( "<td>" + object.eGet(object.eClass().getEStructuralFeature("wrappedValue")) + "</td>"); } out.println("</td>"); } else { } } } } out.println("</tr>"); } out.println("</table>"); }
private void write(PrintWriter out, IdEObject object) throws SerializerException { EClass eClass = object.eClass(); if (eClass.getEAnnotation("hidden") != null) { return; } out.print(DASH); int convertedKey = getExpressId(object); if (convertedKey == -1) { throw new SerializerException( "Going to serialize an object with id -1 (" + object.eClass().getName() + ")"); } out.print(String.valueOf(convertedKey)); out.print("= "); String upperCase = upperCases.get(eClass); if (upperCase == null) { throw new SerializerException("Type not found: " + eClass.getName()); } out.print(upperCase); out.print(OPEN_PAREN); boolean isFirst = true; for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { if (!feature.isDerived() && feature.getEAnnotation("hidden") == null) { EClassifier type = feature.getEType(); if (type instanceof EEnum) { if (!isFirst) { out.print(COMMA); } writeEnum(out, object, feature); isFirst = false; } else if (type instanceof EClass) { if (!isInverse(feature)) { if (!isFirst) { out.print(COMMA); } writeEClass(out, object, feature); isFirst = false; } } else if (type instanceof EDataType) { if (!isFirst) { out.print(COMMA); } writeEDataType(out, object, feature); isFirst = false; } } } out.println(PAREN_CLOSE_SEMICOLON); }
private void writeEClass(PrintWriter out, EObject object, EStructuralFeature feature) throws SerializerException { Object referencedObject = object.eGet(feature); if (referencedObject instanceof IdEObject && ((IdEObject) referencedObject).eClass().getEAnnotation("wrapped") != null) { writeWrappedValue(out, object, feature, ((EObject) referencedObject).eClass()); } else { if (referencedObject instanceof EObject && model.contains((IdEObject) referencedObject)) { out.print(DASH); out.print(String.valueOf(getExpressId((IdEObject) referencedObject))); } else { if (feature.getEAnnotation("derived") != null) { out.print(ASTERISK); } else if (feature.isMany()) { writeList(out, object, feature); } else { writeObject(out, object, feature); } } } }
// 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; } }