Search in sources :

Example 1 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class ResourceValidatorImplTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    with(new LangATestLanguageStandaloneSetup());
    EValidator.Registry.INSTANCE.put(LangATestLanguagePackage.eINSTANCE, new EValidator() {

        @Override
        public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
            if (eObject instanceof Type) {
                String name = ((Type) eObject).getName();
                if (name.equals("Foo"))
                    diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, "", 12, "Foo", null));
                if (name.equals("Bar"))
                    diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING, "", 12, "Foo", null));
            }
            return true;
        }

        @Override
        public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
            return validate(eObject, diagnostics, context);
        }

        @Override
        public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
            return false;
        }
    });
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Type(org.eclipse.xtext.linking.langATestLanguage.Type) EClass(org.eclipse.emf.ecore.EClass) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EDataType(org.eclipse.emf.ecore.EDataType) EObject(org.eclipse.emf.ecore.EObject) EValidator(org.eclipse.emf.ecore.EValidator) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)

Example 2 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class CrossRefTest method testGetSingleValuedLinkText.

@Test
public void testGetSingleValuedLinkText() throws Exception {
    XtextResource r = getResourceFromStringAndExpect("type TypeA extends ^extends type ^extends extends ^type", 1);
    Main model = (Main) r.getContents().get(0);
    assertEquals(2, model.getTypes().size());
    Type type = model.getTypes().get(0);
    assertEquals("TypeA", type.getName());
    Type superType = type.getExtends();
    assertEquals("extends", superType.getName());
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
    assertEquals("^extends", linkText);
    type = superType;
    superType = type.getExtends();
    assertTrue(superType.eIsProxy());
    INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
    linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
    assertEquals("^type", linkText);
    Adapter adapter = (Adapter) NodeModelUtils.getNode(type);
    type.eAdapters().remove(adapter);
    linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
    assertNull(linkText);
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) INode(org.eclipse.xtext.nodemodel.INode) XtextResource(org.eclipse.xtext.resource.XtextResource) Adapter(org.eclipse.emf.common.notify.Adapter) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 3 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class CrossRefTest method testOutOfSyncNodeModel.

/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=287813 */
@Test
public void testOutOfSyncNodeModel() throws Exception {
    XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB ");
    Main model = (Main) r.getContents().get(0);
    Type type = model.getTypes().get(0);
    Type superType = type.getExtends();
    superType.setName("TypeC");
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
    assertEquals("TypeC", linkText);
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 4 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class CrossRefTest method testGetMultiValuedLinkText.

@Test
public void testGetMultiValuedLinkText() throws Exception {
    with(LazyLinkingTestLanguageStandaloneSetup.class);
    crossRefSerializer = get(ICrossReferenceSerializer.class);
    final LazyLinkingTestLanguageGrammarAccess g = (LazyLinkingTestLanguageGrammarAccess) get(IGrammarAccess.class);
    final XtextResource r = CrossRefTest.this.getResourceFromStringAndExpect("type TypeA {} type TypeB { TypeA TypeC TypeB p1; }", 1);
    LogCapture log = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {

        @Override
        public void run() {
            Model model = (Model) r.getContents().get(0);
            assertEquals(2, model.getTypes().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type type = model.getTypes().get(1);
            assertEquals("TypeB", type.getName());
            assertEquals(1, type.getProperties().size());
            Property prop = type.getProperties().get(0);
            assertEquals("p1", prop.getName());
            assertEquals(3, prop.getType().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type propType = prop.getType().get(0);
            assertFalse(propType.eIsProxy());
            String linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeA", linkText);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            INode node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, node);
            assertEquals("TypeC", linkText);
            propType = prop.getType().get(2);
            assertFalse(propType.eIsProxy());
            node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeB", linkText);
            Adapter adapter = (Adapter) NodeModelUtils.getNode(prop);
            prop.eAdapters().remove(adapter);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertNull(linkText);
        }
    });
    log.assertNumberOfLogEntries(2);
}
Also used : ICrossReferenceSerializer(org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.ICrossReferenceSerializer) INode(org.eclipse.xtext.nodemodel.INode) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) XtextResource(org.eclipse.xtext.resource.XtextResource) Adapter(org.eclipse.emf.common.notify.Adapter) Type(org.eclipse.xtext.linking.langATestLanguage.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) LazyLinkingTestLanguageGrammarAccess(org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Example 5 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class CrossRefTest method testCrossReferenceValueConverter.

/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=298506 */
@Test
public void testCrossReferenceValueConverter() throws Exception {
    Resource r = get(XtextResourceSet.class).createResource(URI.createURI("test." + getCurrentFileExtension()));
    Main main = LangATestLanguageFactory.eINSTANCE.createMain();
    Type ele = LangATestLanguageFactory.eINSTANCE.createType();
    r.getContents().add(main);
    main.getTypes().add(ele);
    ele.setName("type");
    ele.setExtends(ele);
    assertEquals("type ^type extends ^type", getSerializer().serialize(main));
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Aggregations

Type (org.eclipse.xtext.linking.langATestLanguage.Type)12 Main (org.eclipse.xtext.linking.langATestLanguage.Main)9 Test (org.junit.Test)7 XtextResource (org.eclipse.xtext.resource.XtextResource)6 INode (org.eclipse.xtext.nodemodel.INode)4 Adapter (org.eclipse.emf.common.notify.Adapter)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EValidator (org.eclipse.emf.ecore.EValidator)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1