public String deResolve( Object value, org.eclipse.emf.ecore.EStructuralFeature feature, org.eclipse.emf.ecore.EObject container, String prefix, String suffix, String escapeCharacter) { // Step 1: convert Java object to text String result = null; if (value != null) { result = value.toString(); } // Step 2: escape suffixes, add prefix and suffix // Step 2a: escaped suffix if (suffix != null) { // take care of the escape character (may be null) if (escapeCharacter != null) { result = result.replace(escapeCharacter, escapeCharacter + escapeCharacter); result = result.replace(suffix, escapeCharacter + suffix); } // Step 2b: append suffix result += suffix; } // Step 2c: prepend prefix if (prefix != null) { result = prefix + result; } // Step 3: escape keywords if required if (escapeKeywords) { // Escape keywords if required for (String keyword : org.emftext.term.propositional.expression.resource.expression.grammar .ExpressionGrammarInformationProvider.INSTANCE.getKeywords()) { if (result.endsWith(keyword)) { String keywordPrefix = result.substring(0, result.length() - keyword.length()); if (keywordPrefix.matches("_*")) { result = "_" + result; break; } } } } return result; }
public void resolve( String lexem, org.eclipse.emf.ecore.EStructuralFeature feature, org.emftext.term.propositional.expression.resource.expression.IExpressionTokenResolveResult result, String suffix, String prefix, String escapeCharacter) { // Step 1: unescape keywords if required if (escapeKeywords && lexem.startsWith("_")) { for (String keyword : org.emftext.term.propositional.expression.resource.expression.grammar .ExpressionGrammarInformationProvider.INSTANCE.getKeywords()) { if (lexem.endsWith(keyword)) { String keywordPrefix = lexem.substring(0, lexem.length() - keyword.length()); if (keywordPrefix.matches("_+")) { lexem = lexem.substring(1); break; } } } } // Step 2: remove prefix, suffix and unescape escaped suffixes // Step 2a: remove prefix if (prefix != null) { int count = prefix.length(); lexem = lexem.substring(count); } // Step 2b: remove suffix if (suffix != null) { int count = suffix.length(); lexem = lexem.substring(0, lexem.length() - count); // take care of the escape character (may be null) // Step 2c: replaced escaped suffixes and escaped escape sequences if (escapeCharacter != null) { lexem = lexem.replace(escapeCharacter + suffix, suffix); lexem = lexem.replace(escapeCharacter + escapeCharacter, escapeCharacter); } } // Step 3: convert text to Java object if (feature instanceof org.eclipse.emf.ecore.EAttribute) { org.eclipse.emf.ecore.EClassifier featureType = feature.getEType(); if (featureType instanceof org.eclipse.emf.ecore.EEnum) { org.eclipse.emf.ecore.EEnumLiteral literal = ((org.eclipse.emf.ecore.EEnum) featureType).getEEnumLiteralByLiteral(lexem); if (literal != null) { result.setResolvedToken(literal.getInstance()); return; } else { result.setErrorMessage( "Could not map lexem '" + lexem + "' to enum '" + featureType.getName() + "'."); return; } } else if (featureType instanceof org.eclipse.emf.ecore.EDataType) { try { result.setResolvedToken( org.eclipse.emf.ecore.util.EcoreUtil.createFromString( (org.eclipse.emf.ecore.EDataType) featureType, lexem)); } catch (Exception e) { result.setErrorMessage( "Could not convert '" + lexem + "' to '" + featureType.getName() + "'."); } String typeName = featureType.getInstanceClassName(); if (typeName.equals("boolean") || java.lang.Boolean.class.getName().equals(typeName)) { String featureName = feature.getName(); boolean featureNameMatchesLexem = featureName.equals(lexem); if (featureNameMatchesLexem) { result.setResolvedToken(true); return; } if (featureName.length() > 2 && featureName.startsWith("is")) { if ((featureName.substring(2, 3).toLowerCase() + featureName.substring(3)) .equals(lexem)) { result.setResolvedToken(true); return; } } if (Boolean.parseBoolean(lexem)) { result.setResolvedToken(true); return; } } } else { assert false; } } else { result.setResolvedToken(lexem); return; } }