Search in sources :

Example 1 with Element

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Element 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 Element

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Element 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 Element

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Element 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 Element

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

the class ElementImpl method basicSetChild.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetChild(Element newChild, NotificationChain msgs) {
    Element oldChild = child;
    child = newChild;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CommentAssociationPackage.ELEMENT__CHILD, oldChild, newChild);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Element(org.eclipse.xtext.parsetree.impl.commentAssociation.Element)

Example 5 with Element

use of org.eclipse.xtext.parsetree.impl.commentAssociation.Element 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)

Aggregations

Element (org.eclipse.xtext.parsetree.impl.commentAssociation.Element)7 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 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 Ignore (org.junit.Ignore)1