janino-compiler / janino

Janino is a super-small, super-fast Java™ compiler.
http://janino-compiler.github.io/janino
Other
1.25k stars 208 forks source link

help #222

Closed UltraSina closed 3 months ago

UltraSina commented 3 months ago

hi , how i can make it ignore classes for import , for example java.lang is default ignored

Geolykt commented 3 months ago

You might want to use methods such as https://github.com/janino-compiler/janino/blob/4db1b8117bda36056f4eeab2d29e1f524b21b13c/commons-compiler/src/main/java/org/codehaus/commons/compiler/IScriptEvaluator.java#L457 or similar

UltraSina commented 3 months ago

thanks , but i use SimpleCompiler for compiling full classes with package name inside of them , and Simple Compiler does not have a methode for imports

Geolykt commented 3 months ago

First of all: Reminding anyone about issues isn't necessary as we generally get an email and a github notification for every message. This is also the reason why internet etiquette generally advises against doing so as you'll be senselessly distracting people unrelated to this issue (this repo has 58 watchers, a good chunk of them will get notifications for issues), too.

I personally believe that SimpleCompiler won't be able to accomplish this without you editing the code of the file you wish to compile manually. SimpleCompiler is primarily meant as - who guessed it - a simple implementation of the compiler and going beyond that will require you to use lower-level components of janino. For reference, this is how ClassBodyEvaluator does it (ClassBodyEvaluator is in turn used by ScriptEvaluator):

Import generation: https://github.com/janino-compiler/janino/blob/4db1b8117bda36056f4eeab2d29e1f524b21b13c/janino/src/main/java/org/codehaus/janino/ClassBodyEvaluator.java#L326-L357 Source file parsing process: https://github.com/janino-compiler/janino/blob/4db1b8117bda36056f4eeab2d29e1f524b21b13c/janino/src/main/java/org/codehaus/janino/ClassBodyEvaluator.java#L265-L298