📄 droolsscriptevaluator.java
字号:
Map appData ) { Set keys = appData.keySet( ); Iterator it = keys.iterator( ); String key; Class clazz; String type; int nestedClassPosition; while ( it.hasNext( ) ) { key = ( String ) it.next( ); clazz = (Class) appData.get( key ); type = clazz.getName( ); nestedClassPosition = type.indexOf( '$' ); if ( nestedClassPosition != -1 ) { type = type.substring( 0, nestedClassPosition ); } imports.add( type ); Scanner.Location loc = scanner.peek( ).getLocation( ); Java.VariableDeclarator[] variables = new Java.VariableDeclarator[]{ // variableDeclarators new Java.VariableDeclarator( loc, // location key, // name 0, // brackets new Java.Cast( // optionalInitializer loc, // location this.classToType( loc, clazz ), // targetType new Java.MethodInvocation( // value loc, // location block, // enclosingScope new Java.AmbiguousName( // optionalTarget loc, block, new String[]{"applicationData"} ), "get", // methodName new Java.Rvalue[]{ // arguments new Java.Literal( scanner.new StringLiteralToken( key ) )} ) ) )}; block .addStatement( new Java.LocalVariableDeclarationStatement( loc, // location block, // declaringBock Mod.FINAL, // modifiers this.classToType( loc, clazz ), // type variables ) ); } } private void addDeclarations(Scanner scanner, Java.Block block, Declaration[] declarations, Set imports) { ObjectType objectType; Class clazz; String identifier; Declaration declaration; String type; int nestedClassPosition; for ( int i = 0; i < declarations.length; i++ ) { declaration = declarations[i]; identifier = declaration.getIdentifier( ); objectType = declaration.getObjectType( ); clazz = ( ( ClassObjectType ) objectType ).getType( ); type = clazz.getName( ); nestedClassPosition = type.indexOf( '$' ); if ( nestedClassPosition != -1 ) { type = type.substring( 0, nestedClassPosition ); } imports.add( type ); Scanner.Location loc = scanner.peek( ).getLocation( ); Java.VariableDeclarator[] variables = new Java.VariableDeclarator[]{ // variableDeclarators new Java.VariableDeclarator( loc, // location identifier, // name 0, // brackets new Java.Cast( // optionalInitializer loc, // location this .classToType( loc, clazz ), // targetType new Java.MethodInvocation( // value loc, // location block, // enclosingScope new Java.AmbiguousName( // optionalTarget loc, block, new String[]{"tuple"} ), "get", // methodName new Java.Rvalue[]{new Java.ArrayAccessExpression( loc, new Java.AmbiguousName( loc, block, new String[]{"decls"} ), new Java.ConstantValue( loc, PrimitiveWrapper .wrap( i ) ) )} ) ) )}; block .addStatement( new Java.LocalVariableDeclarationStatement( loc, // location block, // declaringBock Mod.FINAL, // modifiers this .classToType( loc, clazz ), // type variables ) ); } } public static Object compile(String block, Class interfaceToImplement, String[] parameterNames, Declaration[] declarations, Set imports, Map applicationData) throws Java.CompileException, Parser.ParseException, Scanner.ScanException, IOException { DroolsScriptEvaluator scriptEvaluator = new DroolsScriptEvaluator( block, interfaceToImplement, parameterNames, declarations, imports, applicationData ); try { return scriptEvaluator.getMethod().getDeclaringClass().newInstance(); } catch ( InstantiationException e ) { // SNO - Declared class is always non-abstract. throw new RuntimeException( e.toString( ) ); } catch ( IllegalAccessException e ) { // SNO - interface methods are always PUBLIC. throw new RuntimeException( e.toString( ) ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -