Search in sources :

Example 16 with Main

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

the class InjectableValidatorTest method testCorrectResource.

@Test
public void testCorrectResource() throws Exception {
    Main main = LangATestLanguageFactory.eINSTANCE.createMain();
    xtextResource.getContents().add(main);
    assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), null));
    assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
    assertEquals(xtextResource.getLanguageName(), context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
    context.clear();
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), null));
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
    assertNull(context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 17 with Main

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

the class CrossRefTest method testNonDefaultLinkText.

/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=287813 */
@Test
public void testNonDefaultLinkText() throws Exception {
    XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB");
    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("TypeB", superType.getName());
    INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
    assertTrue(ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL == linkText);
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) INode(org.eclipse.xtext.nodemodel.INode) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 18 with Main

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

the class CrossRefTest method testSerializingProxiedCrossReference.

/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=325435 */
@Test
public void testSerializingProxiedCrossReference() 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();
    CrossRefLinkingService linkingService = (CrossRefLinkingService) get(ILinkingService.class);
    InternalEObject typeProxy = (InternalEObject) LangATestLanguageFactory.eINSTANCE.createType();
    typeProxy.eSetProxyURI(EcoreUtil.getURI(superType));
    linkingService.returnOnceForGetLinkedObjects(typeProxy);
    INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
    assertEquals(ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL, linkText);
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) INode(org.eclipse.xtext.nodemodel.INode) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Test(org.junit.Test)

Example 19 with Main

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

the class CrossRefTest method testSimple.

@Test
public void testSimple() throws Exception {
    Main model = (Main) getModel("type A extends B type B extends A");
    assertEquals("B", model.getTypes().get(0).getExtends().getName());
    assertEquals(model.getTypes().get(0), model.getTypes().get(0).getExtends().getExtends());
}
Also used : Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 20 with Main

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

the class LinkingErrorTest method testNoErrors.

@Test
public void testNoErrors() throws Exception {
    XtextResource resource = getResourceFromString(" type A extends B \n type B extends A");
    Main model = (Main) getModel(resource);
    assertEquals(2, model.getTypes().size());
    assertEquals(0, resource.getErrors().size());
    assertEquals(0, resource.getWarnings().size());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Aggregations

Main (org.eclipse.xtext.linking.langATestLanguage.Main)21 Test (org.junit.Test)18 XtextResource (org.eclipse.xtext.resource.XtextResource)12 Type (org.eclipse.xtext.linking.langATestLanguage.Type)9 EObject (org.eclipse.emf.ecore.EObject)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 INode (org.eclipse.xtext.nodemodel.INode)3 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)2 EReference (org.eclipse.emf.ecore.EReference)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 Assignment (org.eclipse.xtext.Assignment)2 CrossReference (org.eclipse.xtext.CrossReference)2 LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 StorageAwareResource (org.eclipse.xtext.resource.persistence.StorageAwareResource)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1