-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialization fails for comment between concatenated strings #209
- Loading branch information
Showing
4 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
yang-lsp/io.typefox.yang/src/main/java/io/typefox/yang/resource/YangValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.typefox.yang.resource; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.xtext.Assignment; | ||
import org.eclipse.xtext.RuleCall; | ||
import org.eclipse.xtext.nodemodel.INode; | ||
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor; | ||
import org.eclipse.xtext.serializer.tokens.IValueSerializer; | ||
import org.eclipse.xtext.serializer.tokens.ValueSerializer; | ||
|
||
import com.google.inject.Inject; | ||
|
||
import io.typefox.yang.YangValueConverterService.StringConverter; | ||
import io.typefox.yang.services.YangGrammarAccess; | ||
import io.typefox.yang.yang.Pattern; | ||
import io.typefox.yang.yang.YangPackage; | ||
|
||
public class YangValueSerializer extends ValueSerializer implements IValueSerializer { | ||
|
||
@Inject | ||
private YangGrammarAccess grammar; | ||
|
||
@Override | ||
public String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node, | ||
Acceptor errors) { | ||
// when serializing programmatically created model, wrap regex in quotes. See | ||
// #220 | ||
String result = super.serializeAssignedValue(context, ruleCall, value, node, errors); | ||
if (node == null && result != null && context instanceof Pattern | ||
&& ruleCall.getRule() == grammar.getStringValueRule()) { | ||
if (ruleCall.eContainer() instanceof Assignment && YangPackage.eINSTANCE.getPattern_Regexp().getName() | ||
.equals(((Assignment) ruleCall.eContainer()).getFeature())) { | ||
if (result.length() > 2 && !StringConverter.isQuoted(result)) { | ||
return "'" + result + "'"; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters