Search in sources :

Example 1 with Model

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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Word(org.eclipse.xtext.parser.encoding.encodingTest.Word) Model(org.eclipse.xtext.parser.encoding.encodingTest.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with Model

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());
}
Also used : Word(org.eclipse.xtext.parser.encoding.encodingTest.Word) ByteArrayInputStream(java.io.ByteArrayInputStream) ITextRegion(org.eclipse.xtext.util.ITextRegion) Model(org.eclipse.xtext.parser.encoding.encodingTest.Model)

Aggregations

Model (org.eclipse.xtext.parser.encoding.encodingTest.Model)2 Word (org.eclipse.xtext.parser.encoding.encodingTest.Word)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1