Exemple #1
0
 @MPSLaunch
 public void test_testLazyObject() throws Exception {
   Assert.assertNull(LazyTestObject.INSTANCE);
   Iterable<Extension<LazyTestObject>> extensions =
       ((ExtensionPoint<LazyTestObject>)
               ExtensionPoint.<LazyTestObject>generify(
                   new ExtensionPoint(
                       "jetbrains.mps.lang.extension.tests.lazyTestExtensionPoint",
                       LazyTestObject.class)))
           .getExtensions();
   LazyTestObject lzo = extensions.iterator().next().get();
   Assert.assertNotNull(lzo);
   Assert.assertSame(LazyTestObject.INSTANCE, lzo);
 }
  @Test
  public void allExtensions() {
    ExtensionPoint ep1 = mockExtensionPoint("ep1", EP1);
    ExtensionDescriptor ed1 =
        mockExtensionDescriptor("ed1", new ExtensionPoint[] {ep1}, new Extension[] {});
    ExtensionDescriptor ed2 =
        mockExtensionDescriptor(
            "ed2", new ExtensionPoint[] {}, new Extension[] {mockExtension("e1", EP1)});
    ExtensionDescriptor ed3 =
        mockExtensionDescriptor(
            "ed3", new ExtensionPoint[] {}, new Extension[] {mockExtension("e2", EP1)});
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed3);
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed2);
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed1);

    Iterable<Extension<?>> extensions = ep1.getExtensions();
    List<Extension> extensionList = new ArrayList();
    for (Iterator<Extension> it = ExtensionRegistry.getInstance().getExtensions(ep1).iterator();
        it.hasNext(); ) {
      extensionList.add(it.next());
    }
    assertSame(2, extensionList.size());
    Collections.sort(
        extensionList,
        new Comparator<Extension>() {
          @Override
          public int compare(Extension o1, Extension o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(String.valueOf(o1), String.valueOf(o2));
          }
        });
    assertEquals("[e1, e2]", extensionList.toString());

    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed3);
    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed2);
    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed1);
  }
Exemple #3
0
 @MPSLaunch
 public void test_extensionPointExpression() throws Exception {
   String string =
       IterableUtils.join(
           Sequence.fromIterable(
                   ExtensionPoint.<String>generify(
                           new ExtensionPoint(
                               "jetbrains.mps.lang.extension.tests.multiExtensionPoint",
                               String.class))
                       .getObjects())
               .sort(
                   new ISelector<String, String>() {
                     public String select(String it) {
                       return it;
                     }
                   },
                   false),
           ", ");
   Assert.assertEquals("salam, dunya", string);
 }
Exemple #4
0
 @MPSLaunch
 public void test_testObject() throws Exception {
   Iterable<Extension<TestObject>> extensions =
       ((ExtensionPoint<TestObject>)
               ExtensionPoint.<TestObject>generify(
                   new ExtensionPoint(
                       "jetbrains.mps.lang.extension.tests.testExtensionPoint", TestObject.class)))
           .getExtensions();
   Assert.assertNotNull(extensions);
   Iterator<Extension<TestObject>> it = extensions.iterator();
   Assert.assertTrue(it.hasNext());
   Extension<TestObject> ext = it.next();
   try {
     it.next();
     Assert.fail("unexpected value");
   } catch (NoSuchElementException e) {
     // expected exception
   }
   TestObject to = ext.get();
   TEST_OBJECT = to;
   Assert.assertEquals("foobar", to.getValue());
   Assert.assertFalse(to.getShutDown());
 }