From e3976ab203475b858e562809c6d460be86f3f873 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 25 Jan 2024 20:42:20 +0100 Subject: [PATCH] fixed bug in jar converter w.r.t. reading single class file (an NPE) and a classpath parameter was missing for looking up parent classes in the hierarchy --- src/org/rascalmpl/library/TestMe.rsc | 17 +++++++++++++++++ src/org/rascalmpl/library/lang/java/m3/Core.rsc | 2 +- .../java/m3/internal/EclipseJavaCompiler.java | 4 ++-- .../lang/java/m3/internal/JarConverter.java | 10 +++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 src/org/rascalmpl/library/TestMe.rsc diff --git a/src/org/rascalmpl/library/TestMe.rsc b/src/org/rascalmpl/library/TestMe.rsc new file mode 100644 index 00000000000..9d45aa225fc --- /dev/null +++ b/src/org/rascalmpl/library/TestMe.rsc @@ -0,0 +1,17 @@ +module TestMe + +import IO; +import util::Benchmark; +import util::Math; + +void main() { + results = for (i <- [2,3,4,5]) { + println("2^ chains"); + append cpuTimeOf(() { + R = { | j <- [0..toInt(pow(10,i))], j % 100 != 0}; + R+; + }); + } + + iprintln(results); +} diff --git a/src/org/rascalmpl/library/lang/java/m3/Core.rsc b/src/org/rascalmpl/library/lang/java/m3/Core.rsc index 08e21e84d13..fe871c1b9ad 100644 --- a/src/org/rascalmpl/library/lang/java/m3/Core.rsc +++ b/src/org/rascalmpl/library/lang/java/m3/Core.rsc @@ -115,7 +115,7 @@ java M3 createM3FromString(loc fileName, str contents, bool errorRecovery = fals java M3 createM3FromJarClass(loc jarClass, list[loc] classPath = []); @javaClass{org.rascalmpl.library.lang.java.m3.internal.EclipseJavaCompiler} -java M3 createM3FromSingleClass(loc jarClass, str className); +java M3 createM3FromSingleClass(loc jarClass, str className, list[loc] classPath = []); @javaClass{org.rascalmpl.library.lang.java.m3.internal.EclipseJavaCompiler} java M3 createM3FromJarFile(loc jarLoc, list[loc] classPath = []); diff --git a/src/org/rascalmpl/library/lang/java/m3/internal/EclipseJavaCompiler.java b/src/org/rascalmpl/library/lang/java/m3/internal/EclipseJavaCompiler.java index e01e61451f3..f044df7c7b9 100644 --- a/src/org/rascalmpl/library/lang/java/m3/internal/EclipseJavaCompiler.java +++ b/src/org/rascalmpl/library/lang/java/m3/internal/EclipseJavaCompiler.java @@ -67,9 +67,9 @@ public IValue createM3FromJarClass(ISourceLocation jarLoc, IList classPath) { return createM3FromJarClass(jarLoc, classPath, getM3Store()); } - public IValue createM3FromSingleClass(ISourceLocation classLoc, IString className) { + public IValue createM3FromSingleClass(ISourceLocation classLoc, IString className, IList classpath) { JarConverter converter = new JarConverter(getM3Store(), new HashMap<>()); - converter.convertJarFile(classLoc, ((IString) className).getValue()); + converter.convertJarFile(classLoc, ((IString) className).getValue(), classpath); return converter.getModel(false); } diff --git a/src/org/rascalmpl/library/lang/java/m3/internal/JarConverter.java b/src/org/rascalmpl/library/lang/java/m3/internal/JarConverter.java index 0061d3ee329..d0e59ad8a55 100644 --- a/src/org/rascalmpl/library/lang/java/m3/internal/JarConverter.java +++ b/src/org/rascalmpl/library/lang/java/m3/internal/JarConverter.java @@ -132,9 +132,9 @@ public void convertJar(ISourceLocation jar, IList classPath) { * @param classFile * @param className */ - public void convertJarFile(ISourceLocation classFile, String className) { + public void convertJarFile(ISourceLocation classFile, String className, IList classpath) { loc = classFile; - createSingleClassM3(className); + createSingleClassM3(className, classpath); } /** @@ -172,7 +172,11 @@ private void createM3() { * and parent packages is triggered. * @param className */ - private void createSingleClassM3(String className) { + private void createSingleClassM3(String className, IList classpath) { + if (resolver == null) { + resolver = new ASMNodeResolver(loc, classpath, typeStore); + } + String compUnit = className; ClassReader classReader = resolver.buildClassReader(className);