Search in sources :

Example 1 with LangATestLanguageStandaloneSetup

use of org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup 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 LangATestLanguageStandaloneSetup

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

the class DefaultReferenceDescriptionTest method testgetReferenceDescriptions.

@Test
public void testgetReferenceDescriptions() throws Exception {
    with(new LangATestLanguageStandaloneSetup());
    XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
    EObject typeC = targetResource.getContents().get(0).eContents().get(0);
    XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
    resource.load(new StringInputStream("type A extends C type B extends A"), null);
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
    Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
    Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
    assertEquals(1, collection.size());
    IReferenceDescription refDesc = descriptions.iterator().next();
    Main m = (Main) resource.getParseResult().getRootASTElement();
    assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(), false));
    assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(), false));
    assertEquals(-1, refDesc.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS, refDesc.getEReference());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 3 with LangATestLanguageStandaloneSetup

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

the class DefaultResourceDescription2Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    with(new LangATestLanguageStandaloneSetup());
}
Also used : LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)

Example 4 with LangATestLanguageStandaloneSetup

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

the class DefaultReferenceDescriptionTest method testgetReferenceDescriptionForMultiValue.

@Test
public void testgetReferenceDescriptionForMultiValue() throws Exception {
    with(new LangATestLanguageStandaloneSetup());
    XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
    EObject typeC = targetResource.getContents().get(0).eContents().get(0);
    EObject typeD = targetResource.getContents().get(0).eContents().get(1);
    XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
    resource.load(new StringInputStream("type A implements B,C,D type B"), null);
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
    Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
    Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
    assertEquals(2, collection.size());
    Iterator<IReferenceDescription> iterator = descriptions.iterator();
    IReferenceDescription refDesc1 = iterator.next();
    IReferenceDescription refDesc2 = iterator.next();
    Main m = (Main) resource.getParseResult().getRootASTElement();
    assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(), false));
    assertEquals(typeC, resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(), false));
    assertEquals(1, refDesc1.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc1.getEReference());
    assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(), false));
    assertEquals(typeD, resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(), false));
    assertEquals(2, refDesc2.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc2.getEReference());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 5 with LangATestLanguageStandaloneSetup

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

the class PortableURIsTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    LangATestLanguageStandaloneSetup _langATestLanguageStandaloneSetup = new LangATestLanguageStandaloneSetup();
    this.with(_langATestLanguageStandaloneSetup);
}
Also used : LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)

Aggregations

LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)5 EObject (org.eclipse.emf.ecore.EObject)3 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Main (org.eclipse.xtext.linking.langATestLanguage.Main)2 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 Test (org.junit.Test)2 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EValidator (org.eclipse.emf.ecore.EValidator)1 Type (org.eclipse.xtext.linking.langATestLanguage.Type)1