Search in sources :

Example 1 with Element

use of org.eclipse.xtext.ui.tests.folding.Element in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testShouldProcessContent.

@SuppressWarnings("deprecation")
@Test
public void testShouldProcessContent() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \n" + "element bar \n" + "end \n" + "end");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {

        @Override
        protected boolean shouldProcessContent(EObject object) {
            if (object instanceof Element) {
                return !"foo".equals(((Element) object).getName());
            }
            return super.shouldProcessContent(object);
        }
    };
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    assertEquals(0, regions.iterator().next().getOffset());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.ui.tests.folding.Element) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 2 with Element

use of org.eclipse.xtext.ui.tests.folding.Element in project xtext-eclipse by eclipse.

the class FoldingTestLanguageSemanticSequencer 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 == FoldingPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case FoldingPackage.ELEMENT:
                sequence_Element(context, (Element) semanticObject);
                return;
            case FoldingPackage.FOLDING_MODEL:
                sequence_FoldingModel(context, (FoldingModel) 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.ui.tests.folding.Element) FoldingModel(org.eclipse.xtext.ui.tests.folding.FoldingModel) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with Element

use of org.eclipse.xtext.ui.tests.folding.Element in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testIsHandled.

@SuppressWarnings("deprecation")
@Test
public void testIsHandled() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \n" + "element bar \n" + "end \n" + "end");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {

        @Override
        protected boolean isHandled(EObject object) {
            if (object instanceof Element) {
                return !"foo".equals(((Element) object).getName());
            }
            return super.isHandled(object);
        }
    };
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    assertEquals("element foo \n".length(), regions.iterator().next().getOffset());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.ui.tests.folding.Element) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Aggregations

Element (org.eclipse.xtext.ui.tests.folding.Element)3 IFile (org.eclipse.core.resources.IFile)2 EObject (org.eclipse.emf.ecore.EObject)2 DefaultLocationInFileProvider (org.eclipse.xtext.resource.DefaultLocationInFileProvider)2 DefaultFoldingRegionProvider (org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider)2 FoldedPosition (org.eclipse.xtext.ui.editor.folding.FoldedPosition)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)2 Test (org.junit.Test)2 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 FoldingModel (org.eclipse.xtext.ui.tests.folding.FoldingModel)1