Search in sources :

Example 1 with Model

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Model in project xtext-core by eclipse.

the class CommentAssociationTest method testCommentAssociationWithAction.

@Test
public void testCommentAssociationWithAction() throws Exception {
    String textModel = "// comment pre x\n" + "element /* comment inside x */ x // comment post x\n" + "// comment pre y\n" + "parent /* comment inside y */ y // comment post y\n" + "// comment pre z\n" + "element z";
    Model model = (Model) getModel(textModel);
    Multimap<EObject, String> multimap = createModel2CommentMap(model);
    EList<Element> elements = model.getElements();
    Element y = elements.get(0);
    Element x = y.getChild();
    Element z = elements.get(1);
    checkComments(multimap, x, "// comment pre x\n", "/* comment inside x */", "// comment post x\n");
    checkComments(multimap, y, "// comment pre y\n", "/* comment inside y */", "// comment post y\n");
    checkComments(multimap, z, "// comment pre z\n");
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element) Model(org.eclipse.xtext.parsetree.impl.commentAssociation.Model) Test(org.junit.Test)

Example 2 with Model

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Model in project xtext-core by eclipse.

the class CommentAssociationTest method testCommentsAtEndOfFile.

@Test
public void testCommentsAtEndOfFile() throws Exception {
    String textModel = "element x // comment post x\n";
    Model model = (Model) getModel(textModel);
    EList<Element> elements = model.getElements();
    Element x = elements.get(0);
    Element y = CommentAssociationFactory.eINSTANCE.createElement();
    y.setName("y");
    y.setChild(x);
    Element z = CommentAssociationFactory.eINSTANCE.createElement();
    z.setName("z");
    model.getElements().add(y);
    model.getElements().add(z);
    String serialized = serialize(model);
    assertEquals("element x // comment post x\nparent y element z", serialized);
}
Also used : Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element) Model(org.eclipse.xtext.parsetree.impl.commentAssociation.Model) Test(org.junit.Test)

Example 3 with Model

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Model in project xtext-core by eclipse.

the class CommentAssociationTest method testCommentAssociation.

@Test
public void testCommentAssociation() throws Exception {
    String textModel = "element x // comment post x\n" + "// comment pre y\n" + "element /* comment inside y */ y // comment post y\n" + "// comment pre z\n" + "element z";
    Model model = (Model) getModel(textModel);
    Multimap<EObject, String> multimap = createModel2CommentMap(model);
    EList<Element> elements = model.getElements();
    Element x = elements.get(0);
    Element y = elements.get(1);
    Element z = elements.get(2);
    checkComments(multimap, x, "// comment post x\n");
    checkComments(multimap, y, "// comment pre y\n", "/* comment inside y */", "// comment post y\n");
    checkComments(multimap, z, "// comment pre z\n");
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element) Model(org.eclipse.xtext.parsetree.impl.commentAssociation.Model) Test(org.junit.Test)

Example 4 with Model

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Model in project xtext-core by eclipse.

the class CommentAssociationTestLanguageSemanticSequencer 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 == CommentAssociationPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case CommentAssociationPackage.ELEMENT:
                if (rule == grammarAccess.getElementRule()) {
                    sequence_Element(context, (Element) semanticObject);
                    return;
                } else if (action == grammarAccess.getElementAccess().getElementChildAction_2_0()) {
                    sequence_Element_Element_2_0(context, (Element) semanticObject);
                    return;
                } else
                    break;
            case CommentAssociationPackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element) Model(org.eclipse.xtext.parsetree.impl.commentAssociation.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 5 with Model

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Model in project xtext-core by eclipse.

the class CommentAssociationTest method testSerializeReplacement.

// TODO https://github.com/eclipse/xtext-core/issues/32
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=475457
@Ignore
@Test
public void testSerializeReplacement() throws Exception {
    String xBlock = "// comment pre x\n" + "element /* comment inside x */ x // comment post x\n" + "";
    String yBlock = "// comment pre y\n" + "element /* comment inside y */ y // comment post y\n" + "";
    String zBlock = "// comment pre z\n" + "element z";
    String textModel = xBlock + yBlock + zBlock;
    Model model = (Model) getModel(textModel);
    EList<Element> elements = model.getElements();
    Element x = elements.get(0);
    Element y = elements.get(1);
    Element z = elements.get(2);
    checkReplaceRegion(x, xBlock, textModel);
    checkReplaceRegion(y, yBlock, textModel);
    checkReplaceRegion(z, zBlock, textModel);
}
Also used : Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element) Model(org.eclipse.xtext.parsetree.impl.commentAssociation.Model) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Element (org.eclipse.xtext.parsetree.impl.commentAssociation.Element)6 Model (org.eclipse.xtext.parsetree.impl.commentAssociation.Model)6 Test (org.junit.Test)5 EObject (org.eclipse.emf.ecore.EObject)3 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 Ignore (org.junit.Ignore)1