use of org.eclipse.xtext.parser.encoding.encodingTest.Model in project xtext-core by eclipse.
the class EncodingTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == EncodingTestPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case EncodingTestPackage.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
case EncodingTestPackage.WORD:
sequence_Word(context, (Word) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.parser.encoding.encodingTest.Model in project xtext-core by eclipse.
the class Bug306325Test method performTestWithEncoding.
protected void performTestWithEncoding(String encoding) throws UnsupportedEncodingException, IOException {
String model = "�cl�p� M�d�l�ng Pr�j�kt";
byte[] utfBytes = model.getBytes(encoding);
XtextResource resource = createXtextResource();
resource.load(new ByteArrayInputStream(utfBytes), Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding));
Model root = (Model) resource.getContents().get(0);
EList<Word> words = root.getWords();
assertEquals(3, words.size());
String[] lexemes = model.split(" ");
ILocationInFileProvider locationInFileProvider = getInjector().getInstance(ILocationInFileProvider.class);
ITextRegion location0 = locationInFileProvider.getSignificantTextRegion(words.get(0));
assertEquals(0, location0.getOffset());
assertEquals(lexemes[0].length(), location0.getLength());
ITextRegion location1 = locationInFileProvider.getSignificantTextRegion(words.get(1));
assertEquals(lexemes[0].length() + 1, location1.getOffset());
assertEquals(lexemes[1].length(), location1.getLength());
ITextRegion location2 = locationInFileProvider.getSignificantTextRegion(words.get(2));
assertEquals(lexemes[0].length() + lexemes[1].length() + 2, location2.getOffset());
assertEquals(lexemes[2].length(), location2.getLength());
}
Aggregations