Skip to content

Commit

Permalink
Fix for #1002: load DGMs from VMPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 12, 2019
1 parent b35a659 commit 620a3fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -997,6 +998,20 @@ public void testDGSMDeclaring6() {
assertDeclType(contents, "minus", "org.codehaus.groovy.runtime.dgmimpl.NumberNumberMinus");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1002
public void testDGSMDeclaring7() {
String contents = "new StringBuilder().size()";
assertDeclType(contents, "size", "org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1002
public void testDGSMDeclaring8() {
assumeTrue(isAtLeastGroovy(25));

String contents = "['x','y','z'].stream().toList()";
assertDeclType(contents, "toList", "org.codehaus.groovy.vmplugin.v8.PluginDefaultGroovyMethods");
}

@Test
public void testStaticMixinDGM() {
String contents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ public Set<Class> getDefaultCategories() {
Collections.addAll(objectCategories, (Class[]) dgm.getField("DGM_LIKE_CLASSES").get(dgm));
Collections.addAll(objectCategories, (Class[]) dgm.getField("ADDITIONAL_CLASSES").get(dgm));

staticCategories.add(dgsm);
Class vmpf = loadClass("org.codehaus.groovy.vmplugin.VMPluginFactory", false, true);
@SuppressWarnings("unchecked") Object vmp = vmpf.getMethod("getPlugin").invoke(vmpf);

Collections.addAll(objectCategories, (Class[]) vmp.getClass().getMethod("getPluginDefaultGroovyMethods").invoke(vmp));
Collections.addAll(staticCategories, (Class[]) vmp.getClass().getMethod("getPluginStaticGroovyMethods").invoke(vmp));

new ExtensionModuleScanner(module -> {
if (module instanceof SimpleExtensionModule) {
Expand All @@ -283,6 +287,7 @@ public Set<Class> getDefaultCategories() {
}
}, this).scanClasspathModules();

staticCategories.add(dgsm);
objectCategories.addAll(staticCategories);

defaultCategories = objectCategories;
Expand Down

0 comments on commit 620a3fb

Please sign in to comment.