idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
6,700 | public GroovyRunner remove ( Object key ) { if ( key == null ) { return null ; } Map < String , GroovyRunner > map = getMap ( ) ; writeLock . lock ( ) ; try { cachedValues = null ; return map . remove ( key ) ; } finally { writeLock . unlock ( ) ; } } | Removes a registered runner from the registry . |
6,701 | public void clear ( ) { Map < String , GroovyRunner > map = getMap ( ) ; writeLock . lock ( ) ; try { cachedValues = null ; map . clear ( ) ; loadDefaultRunners ( ) ; } finally { writeLock . unlock ( ) ; } } | Clears all registered runners from the registry and resets the registry so that it contains only the default set of runners . |
6,702 | public Collection < GroovyRunner > values ( ) { List < GroovyRunner > values = cachedValues ; if ( values == null ) { Map < String , GroovyRunner > map = getMap ( ) ; readLock . lock ( ) ; try { if ( ( values = cachedValues ) == null ) { cachedValues = values = Collections . unmodifiableList ( new ArrayList < > ( map . values ( ) ) ) ; } } finally { readLock . unlock ( ) ; } } return values ; } | Returns a collection of all registered runners . This is a snapshot of the registry and any subsequent registry changes will not be reflected in the collection . |
6,703 | public Set < Entry < String , GroovyRunner > > entrySet ( ) { Map < String , GroovyRunner > map = getMap ( ) ; readLock . lock ( ) ; try { if ( map . isEmpty ( ) ) { return Collections . emptySet ( ) ; } return Collections . unmodifiableSet ( new LinkedHashSet < > ( map . entrySet ( ) ) ) ; } finally { readLock . unlock ( ) ; } } | Returns a set of entries for registered runners . This is a snapshot of the registry and any subsequent registry changes will not be reflected in the set . |
6,704 | public int read ( char cbuf [ ] , int off , int len ) throws IOException { int c = 0 ; int count = 0 ; while ( count < len && ( c = read ( ) ) != - 1 ) { cbuf [ off + count ] = ( char ) c ; count ++ ; } return ( count == 0 && c == - 1 ) ? - 1 : count ; } | Reads characters from the underlying reader . |
6,705 | public int read ( ) throws IOException { if ( hasNextChar ) { hasNextChar = false ; write ( nextChar ) ; return nextChar ; } if ( previousLine != lexer . getLine ( ) ) { numUnicodeEscapesFoundOnCurrentLine = 0 ; previousLine = lexer . getLine ( ) ; } int c = reader . read ( ) ; if ( c != '\\' ) { write ( c ) ; return c ; } c = reader . read ( ) ; if ( c != 'u' ) { hasNextChar = true ; nextChar = c ; write ( '\\' ) ; return '\\' ; } int numberOfUChars = 0 ; do { numberOfUChars ++ ; c = reader . read ( ) ; } while ( c == 'u' ) ; checkHexDigit ( c ) ; StringBuilder charNum = new StringBuilder ( ) ; charNum . append ( ( char ) c ) ; for ( int i = 0 ; i < 3 ; i ++ ) { c = reader . read ( ) ; checkHexDigit ( c ) ; charNum . append ( ( char ) c ) ; } int rv = Integer . parseInt ( charNum . toString ( ) , 16 ) ; write ( rv ) ; numUnicodeEscapesFound += 4 + numberOfUChars ; numUnicodeEscapesFoundOnCurrentLine += 4 + numberOfUChars ; return rv ; } | Gets the next character from the underlying reader translating escapes as required . |
6,706 | private void checkHexDigit ( int c ) throws IOException { if ( c >= '0' && c <= '9' ) { return ; } if ( c >= 'a' && c <= 'f' ) { return ; } if ( c >= 'A' && c <= 'F' ) { return ; } hasNextChar = true ; nextChar = c ; throw new IOException ( "Did not find four digit hex character code." + " line: " + lexer . getLine ( ) + " col:" + lexer . getColumn ( ) ) ; } | Checks that the given character is indeed a hex digit . |
6,707 | public void run ( ) { try { ServerSocket serverSocket = new ServerSocket ( url . getPort ( ) ) ; while ( true ) { Script script = groovy . parse ( source ) ; new GroovyClientConnection ( script , autoOutput , serverSocket . accept ( ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } | Runs this server . There is typically no need to call this method as the object s constructor creates a new thread and runs this object automatically . |
6,708 | private boolean run ( ) { try { if ( processSockets ) { processSockets ( ) ; } else if ( processFiles ) { processFiles ( ) ; } else { processOnce ( ) ; } return true ; } catch ( CompilationFailedException e ) { System . err . println ( e ) ; return false ; } catch ( Throwable e ) { if ( e instanceof InvokerInvocationException ) { InvokerInvocationException iie = ( InvokerInvocationException ) e ; e = iie . getCause ( ) ; } System . err . println ( "Caught: " + e ) ; if ( ! debug ) { StackTraceUtils . deepSanitize ( e ) ; } e . printStackTrace ( ) ; return false ; } } | Run the script . |
6,709 | private void processSockets ( ) throws CompilationFailedException , IOException , URISyntaxException { GroovyShell groovy = new GroovyShell ( conf ) ; new GroovySocketServer ( groovy , getScriptSource ( isScriptFile , script ) , autoOutput , port ) ; } | Process Sockets . |
6,710 | public static File searchForGroovyScriptFile ( String input ) { String scriptFileName = input . trim ( ) ; File scriptFile = new File ( scriptFileName ) ; String [ ] standardExtensions = { ".groovy" , ".gvy" , ".gy" , ".gsh" } ; int i = 0 ; while ( i < standardExtensions . length && ! scriptFile . exists ( ) ) { scriptFile = new File ( scriptFileName + standardExtensions [ i ] ) ; i ++ ; } if ( ! scriptFile . exists ( ) ) { scriptFile = new File ( scriptFileName ) ; } return scriptFile ; } | Search for the script file doesn t bother if it is named precisely . |
6,711 | private static void setupContextClassLoader ( GroovyShell shell ) { final Thread current = Thread . currentThread ( ) ; class DoSetContext implements PrivilegedAction { ClassLoader classLoader ; public DoSetContext ( ClassLoader loader ) { classLoader = loader ; } public Object run ( ) { current . setContextClassLoader ( classLoader ) ; return null ; } } AccessController . doPrivileged ( new DoSetContext ( shell . getClassLoader ( ) ) ) ; } | GROOVY - 6771 |
6,712 | private void processFiles ( ) throws CompilationFailedException , IOException , URISyntaxException { GroovyShell groovy = new GroovyShell ( conf ) ; setupContextClassLoader ( groovy ) ; Script s = groovy . parse ( getScriptSource ( isScriptFile , script ) ) ; if ( args . isEmpty ( ) ) { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { PrintWriter writer = new PrintWriter ( System . out ) ; processReader ( s , reader , writer ) ; writer . flush ( ) ; } } else { Iterator i = args . iterator ( ) ; while ( i . hasNext ( ) ) { String filename = ( String ) i . next ( ) ; File file = huntForTheScriptFile ( filename ) ; processFile ( s , file ) ; } } } | Process the input files . |
6,713 | private void processFile ( Script s , File file ) throws IOException { if ( ! file . exists ( ) ) throw new FileNotFoundException ( file . getName ( ) ) ; if ( ! editFiles ) { try ( BufferedReader reader = new BufferedReader ( new FileReader ( file ) ) ) { PrintWriter writer = new PrintWriter ( System . out ) ; processReader ( s , reader , writer ) ; writer . flush ( ) ; } } else { File backup ; if ( backupExtension == null ) { backup = File . createTempFile ( "groovy_" , ".tmp" ) ; backup . deleteOnExit ( ) ; } else { backup = new File ( file . getPath ( ) + backupExtension ) ; } backup . delete ( ) ; if ( ! file . renameTo ( backup ) ) throw new IOException ( "unable to rename " + file + " to " + backup ) ; try ( BufferedReader reader = new BufferedReader ( new FileReader ( backup ) ) ; PrintWriter writer = new PrintWriter ( new FileWriter ( file ) ) ) { processReader ( s , reader , writer ) ; } } } | Process a single input file . |
6,714 | private void processReader ( Script s , BufferedReader reader , PrintWriter pw ) throws IOException { String line ; String lineCountName = "count" ; s . setProperty ( lineCountName , BigInteger . ZERO ) ; String autoSplitName = "split" ; s . setProperty ( "out" , pw ) ; try { InvokerHelper . invokeMethod ( s , "begin" , null ) ; } catch ( MissingMethodException mme ) { } while ( ( line = reader . readLine ( ) ) != null ) { s . setProperty ( "line" , line ) ; s . setProperty ( lineCountName , ( ( BigInteger ) s . getProperty ( lineCountName ) ) . add ( BigInteger . ONE ) ) ; if ( autoSplit ) { s . setProperty ( autoSplitName , line . split ( splitPattern ) ) ; } Object o = s . run ( ) ; if ( autoOutput && o != null ) { pw . println ( o ) ; } } try { InvokerHelper . invokeMethod ( s , "end" , null ) ; } catch ( MissingMethodException mme ) { } } | Process a script against a single input file . |
6,715 | private void processOnce ( ) throws CompilationFailedException , IOException , URISyntaxException { GroovyShell groovy = new GroovyShell ( conf ) ; setupContextClassLoader ( groovy ) ; groovy . run ( getScriptSource ( isScriptFile , script ) , args ) ; } | Process the standard single script with args . |
6,716 | protected List < Expression > transformExpressions ( List < ? extends Expression > expressions , ExpressionTransformer transformer ) { List < Expression > list = new ArrayList < Expression > ( expressions . size ( ) ) ; for ( Expression expr : expressions ) { list . add ( transformer . transform ( expr ) ) ; } return list ; } | Transforms the list of expressions |
6,717 | protected < T extends Expression > List < T > transformExpressions ( List < ? extends Expression > expressions , ExpressionTransformer transformer , Class < T > transformedType ) { List < T > list = new ArrayList < T > ( expressions . size ( ) ) ; for ( Expression expr : expressions ) { Expression transformed = transformer . transform ( expr ) ; if ( ! transformedType . isInstance ( transformed ) ) throw new GroovyBugError ( String . format ( "Transformed expression should have type %s but has type %s" , transformedType , transformed . getClass ( ) ) ) ; list . add ( transformedType . cast ( transformed ) ) ; } return list ; } | Transforms the list of expressions and checks that all transformed expressions have the given type . |
6,718 | public static ClassNode [ ] make ( Class [ ] classes ) { ClassNode [ ] cns = new ClassNode [ classes . length ] ; for ( int i = 0 ; i < cns . length ; i ++ ) { cns [ i ] = make ( classes [ i ] ) ; } return cns ; } | Creates an array of ClassNodes using an array of classes . For each of the given classes a new ClassNode will be created |
6,719 | public static ClassNode make ( String name ) { if ( name == null || name . length ( ) == 0 ) return DYNAMIC_TYPE ; for ( int i = 0 ; i < primitiveClassNames . length ; i ++ ) { if ( primitiveClassNames [ i ] . equals ( name ) ) return types [ i ] ; } for ( int i = 0 ; i < classes . length ; i ++ ) { String cname = classes [ i ] . getName ( ) ; if ( name . equals ( cname ) ) return types [ i ] ; } return makeWithoutCaching ( name ) ; } | Creates a ClassNode using a given class . If the name is one of the predefined ClassNodes then the corresponding ClassNode instance will be returned . If the name is null or of length 0 the dynamic type is returned |
6,720 | public static ClassNode getNextSuperClass ( ClassNode clazz , ClassNode goalClazz ) { if ( clazz . isArray ( ) ) { if ( ! goalClazz . isArray ( ) ) return null ; ClassNode cn = getNextSuperClass ( clazz . getComponentType ( ) , goalClazz . getComponentType ( ) ) ; if ( cn != null ) cn = cn . makeArray ( ) ; return cn ; } if ( ! goalClazz . isInterface ( ) ) { if ( clazz . isInterface ( ) ) { if ( OBJECT_TYPE . equals ( clazz ) ) return null ; return OBJECT_TYPE ; } else { return clazz . getUnresolvedSuperClass ( ) ; } } ClassNode [ ] interfaces = clazz . getUnresolvedInterfaces ( ) ; for ( ClassNode anInterface : interfaces ) { if ( StaticTypeCheckingSupport . implementsInterfaceOrIsSubclassOf ( anInterface , goalClazz ) ) { return anInterface ; } } return clazz . getUnresolvedSuperClass ( ) ; } | Returns a super class or interface for a given class depending on a given target . If the target is no super class or interface then null will be returned . For a non - primitive array type returns an array of the componentType s super class or interface if the target is also an array . |
6,721 | public static Number minus ( Number left , Number right ) { return NumberMath . subtract ( left , right ) ; } | Subtraction of two Numbers . |
6,722 | public static OutputStream leftShift ( Socket self , byte [ ] value ) throws IOException { return IOGroovyMethods . leftShift ( self . getOutputStream ( ) , value ) ; } | Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket |
6,723 | public static Socket accept ( ServerSocket serverSocket , @ ClosureParams ( value = SimpleType . class , options = "java.net.Socket" ) final Closure closure ) throws IOException { return accept ( serverSocket , true , closure ) ; } | Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread . |
6,724 | public static Socket accept ( ServerSocket serverSocket , final boolean runInANewThread , @ ClosureParams ( value = SimpleType . class , options = "java.net.Socket" ) final Closure closure ) throws IOException { final Socket socket = serverSocket . accept ( ) ; if ( runInANewThread ) { new Thread ( new Runnable ( ) { public void run ( ) { invokeClosureWithSocket ( socket , closure ) ; } } ) . start ( ) ; } else { invokeClosureWithSocket ( socket , closure ) ; } return socket ; } | Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread as needed . |
6,725 | private void passThisReference ( ConstructorCallExpression call ) { ClassNode cn = call . getType ( ) . redirect ( ) ; if ( ! shouldHandleImplicitThisForInnerClass ( cn ) ) return ; boolean isInStaticContext = true ; if ( currentMethod != null ) isInStaticContext = currentMethod . getVariableScope ( ) . isInStaticContext ( ) ; else if ( currentField != null ) isInStaticContext = currentField . isStatic ( ) ; else if ( processingObjInitStatements ) isInStaticContext = false ; if ( isInStaticContext ) { Expression args = call . getArguments ( ) ; if ( args instanceof TupleExpression && ( ( TupleExpression ) args ) . getExpressions ( ) . isEmpty ( ) ) { addError ( "No enclosing instance passed in constructor call of a non-static inner class" , call ) ; } return ; } insertThis0ToSuperCall ( call , cn ) ; } | passed as the first argument implicitly . |
6,726 | public static Sql newInstance ( String url ) throws SQLException { Connection connection = DriverManager . getConnection ( url ) ; return new Sql ( connection ) ; } | Creates a new Sql instance given a JDBC connection URL . |
6,727 | public static Sql newInstance ( String url , String user , String password ) throws SQLException { Connection connection = DriverManager . getConnection ( url , user , password ) ; return new Sql ( connection ) ; } | Creates a new Sql instance given a JDBC connection URL a username and a password . |
6,728 | public static Sql newInstance ( String url , String user , String password , String driverClassName ) throws SQLException , ClassNotFoundException { loadDriver ( driverClassName ) ; return newInstance ( url , user , password ) ; } | Creates a new Sql instance given a JDBC connection URL a username a password and a driver class name . |
6,729 | public static Sql newInstance ( String url , String driverClassName ) throws SQLException , ClassNotFoundException { loadDriver ( driverClassName ) ; return newInstance ( url ) ; } | Creates a new Sql instance given a JDBC connection URL and a driver class name . |
6,730 | public static void loadDriver ( String driverClassName ) throws ClassNotFoundException { try { Class . forName ( driverClassName ) ; } catch ( ClassNotFoundException e ) { try { Thread . currentThread ( ) . getContextClassLoader ( ) . loadClass ( driverClassName ) ; } catch ( ClassNotFoundException e2 ) { try { Sql . class . getClassLoader ( ) . loadClass ( driverClassName ) ; } catch ( ClassNotFoundException e3 ) { throw e ; } } } } | Attempts to load the JDBC driver on the thread current or system class loaders |
6,731 | public static InParameter in ( final int type , final Object value ) { return new InParameter ( ) { public int getType ( ) { return type ; } public Object getValue ( ) { return value ; } } ; } | Create a new InParameter |
6,732 | public static InOutParameter inout ( final InParameter in ) { return new InOutParameter ( ) { public int getType ( ) { return in . getType ( ) ; } public Object getValue ( ) { return in . getValue ( ) ; } } ; } | Create an inout parameter using this in parameter . |
6,733 | public void commit ( ) throws SQLException { if ( useConnection == null ) { LOG . info ( "Commit operation not supported when using datasets unless using withTransaction or cacheConnection - attempt to commit ignored" ) ; return ; } try { useConnection . commit ( ) ; } catch ( SQLException e ) { LOG . warning ( "Caught exception committing connection: " + e . getMessage ( ) ) ; throw e ; } } | If this SQL object was created with a Connection then this method commits the connection . If this SQL object was created from a DataSource then this method does nothing . |
6,734 | public void cacheConnection ( Closure closure ) throws SQLException { boolean savedCacheConnection = cacheConnection ; cacheConnection = true ; Connection connection = null ; try { connection = createConnection ( ) ; callClosurePossiblyWithConnection ( closure , connection ) ; } finally { cacheConnection = false ; closeResources ( connection , null ) ; cacheConnection = savedCacheConnection ; if ( dataSource != null && ! cacheConnection ) { useConnection = null ; } } } | Caches the connection used while the closure is active . If the closure takes a single argument it will be called with the connection otherwise it will be called with no arguments . |
6,735 | protected final ResultSet executePreparedQuery ( String sql , List < Object > params ) throws SQLException { AbstractQueryCommand command = createPreparedQueryCommand ( sql , params ) ; ResultSet rs = null ; try { rs = command . execute ( ) ; } finally { command . closeResources ( ) ; } return rs ; } | Useful helper method which handles resource management when executing a prepared query which returns a result set . Derived classes of Sql can override createPreparedQueryCommand and then call this method to access the ResultSet returned from the provided query . |
6,736 | protected String asSql ( GString gstring , List < Object > values ) { String [ ] strings = gstring . getStrings ( ) ; if ( strings . length <= 0 ) { throw new IllegalArgumentException ( "No SQL specified in GString: " + gstring ) ; } boolean nulls = false ; StringBuilder buffer = new StringBuilder ( ) ; boolean warned = false ; Iterator < Object > iter = values . iterator ( ) ; for ( int i = 0 ; i < strings . length ; i ++ ) { String text = strings [ i ] ; if ( text != null ) { buffer . append ( text ) ; } if ( iter . hasNext ( ) ) { Object value = iter . next ( ) ; if ( value != null ) { if ( value instanceof ExpandedVariable ) { buffer . append ( ( ( ExpandedVariable ) value ) . getObject ( ) ) ; iter . remove ( ) ; } else { boolean validBinding = true ; if ( i < strings . length - 1 ) { String nextText = strings [ i + 1 ] ; if ( ( text . endsWith ( "\"" ) || text . endsWith ( "'" ) ) && ( nextText . startsWith ( "'" ) || nextText . startsWith ( "\"" ) ) ) { if ( ! warned ) { LOG . warning ( "In Groovy SQL please do not use quotes around dynamic expressions " + "(which start with $) as this means we cannot use a JDBC PreparedStatement " + "and so is a security hole. Groovy has worked around your mistake but the security hole is still there. " + "The expression so far is: " + buffer . toString ( ) + "?" + nextText ) ; warned = true ; } buffer . append ( value ) ; iter . remove ( ) ; validBinding = false ; } } if ( validBinding ) { buffer . append ( "?" ) ; } } } else { nulls = true ; iter . remove ( ) ; buffer . append ( "?'\"?" ) ; } } } String sql = buffer . toString ( ) ; if ( nulls ) { sql = nullify ( sql ) ; } return sql ; } | Hook to allow derived classes to override sql generation from GStrings . |
6,737 | protected String nullify ( String sql ) { int firstWhere = findWhereKeyword ( sql ) ; if ( firstWhere >= 0 ) { Pattern [ ] patterns = { Pattern . compile ( "(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)" ) , Pattern . compile ( "(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)" ) , Pattern . compile ( "(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)" ) , } ; String [ ] replacements = { "$1 is not $2null$3" , "$1 is not $2null$3" , "$1 is $2null$3" , } ; for ( int i = 0 ; i < patterns . length ; i ++ ) { Matcher matcher = patterns [ i ] . matcher ( sql ) ; while ( matcher . matches ( ) ) { sql = matcher . replaceAll ( replacements [ i ] ) ; matcher = patterns [ i ] . matcher ( sql ) ; } } } return sql . replaceAll ( "\\?'\"\\?" , "null" ) ; } | Hook to allow derived classes to override null handling . Default behavior is to replace ? ? references with NULLish |
6,738 | protected int findWhereKeyword ( String sql ) { char [ ] chars = sql . toLowerCase ( ) . toCharArray ( ) ; char [ ] whereChars = "where" . toCharArray ( ) ; int i = 0 ; boolean inString = false ; int inWhere = 0 ; while ( i < chars . length ) { switch ( chars [ i ] ) { case '\'' : inString = ! inString ; break ; default : if ( ! inString && chars [ i ] == whereChars [ inWhere ] ) { inWhere ++ ; if ( inWhere == whereChars . length ) { return i ; } } else { inWhere = 0 ; } } i ++ ; } return - 1 ; } | Hook to allow derived classes to override where clause sniffing . Default behavior is to find the first where keyword in the sql doing simple avoidance of the word where within quotes . |
6,739 | protected List < Object > getParameters ( GString gstring ) { return new ArrayList < Object > ( Arrays . asList ( gstring . getValues ( ) ) ) ; } | Hook to allow derived classes to override behavior associated with extracting params from a GString . |
6,740 | protected void setObject ( PreparedStatement statement , int i , Object value ) throws SQLException { if ( value instanceof InParameter || value instanceof OutParameter ) { if ( value instanceof InParameter ) { InParameter in = ( InParameter ) value ; Object val = in . getValue ( ) ; if ( null == val ) { statement . setNull ( i , in . getType ( ) ) ; } else { statement . setObject ( i , val , in . getType ( ) ) ; } } if ( value instanceof OutParameter ) { try { OutParameter out = ( OutParameter ) value ; ( ( CallableStatement ) statement ) . registerOutParameter ( i , out . getType ( ) ) ; } catch ( ClassCastException e ) { throw new SQLException ( "Cannot register out parameter." ) ; } } } else { try { statement . setObject ( i , value ) ; } catch ( SQLException e ) { if ( value == null ) { SQLException se = new SQLException ( "Your JDBC driver may not support null arguments for setObject. Consider using Groovy's InParameter feature." + ( e . getMessage ( ) == null ? "" : " (CAUSE: " + e . getMessage ( ) + ")" ) ) ; se . setNextException ( e ) ; throw se ; } else { throw e ; } } } } | Strategy method allowing derived classes to handle types differently such as for CLOBs etc . |
6,741 | protected Connection createConnection ( ) throws SQLException { if ( ( cacheStatements || cacheConnection ) && useConnection != null ) { return useConnection ; } if ( dataSource != null ) { Connection con ; try { con = AccessController . doPrivileged ( new PrivilegedExceptionAction < Connection > ( ) { public Connection run ( ) throws SQLException { return dataSource . getConnection ( ) ; } } ) ; } catch ( PrivilegedActionException pae ) { Exception e = pae . getException ( ) ; if ( e instanceof SQLException ) { throw ( SQLException ) e ; } else { throw ( RuntimeException ) e ; } } if ( cacheStatements || cacheConnection ) { useConnection = con ; } return con ; } return useConnection ; } | An extension point allowing derived classes to change the behavior of connection creation . The default behavior is to either use the supplied connection or obtain it from the supplied datasource . |
6,742 | protected void closeResources ( Connection connection , Statement statement , ResultSet results ) { if ( results != null ) { try { results . close ( ) ; } catch ( SQLException e ) { LOG . finest ( "Caught exception closing resultSet: " + e . getMessage ( ) + " - continuing" ) ; } } closeResources ( connection , statement ) ; } | An extension point allowing derived classes to change the behavior of resource closing . |
6,743 | protected void closeResources ( Connection connection ) { if ( cacheConnection ) return ; if ( connection != null && dataSource != null ) { try { connection . close ( ) ; } catch ( SQLException e ) { LOG . finest ( "Caught exception closing connection: " + e . getMessage ( ) + " - continuing" ) ; } } } | An extension point allowing the behavior of resource closing to be overridden in derived classes . |
6,744 | protected void configure ( Statement statement ) { Closure configureStatement = this . configureStatement ; if ( configureStatement != null ) { configureStatement . call ( statement ) ; } } | Provides a hook for derived classes to be able to configure JDBC statements . Default behavior is to call a previously saved closure if any using the statement as a parameter . |
6,745 | protected SqlWithParams buildSqlWithIndexedProps ( String sql ) { if ( ! enableNamedQueries || ! ExtractIndexAndSql . hasNamedParameters ( sql ) ) { return null ; } String newSql ; List < Tuple > propList ; if ( cacheNamedQueries && namedParamSqlCache . containsKey ( sql ) ) { newSql = namedParamSqlCache . get ( sql ) ; propList = namedParamIndexPropCache . get ( sql ) ; } else { ExtractIndexAndSql extractIndexAndSql = ExtractIndexAndSql . from ( sql ) ; newSql = extractIndexAndSql . getNewSql ( ) ; propList = extractIndexAndSql . getIndexPropList ( ) ; namedParamSqlCache . put ( sql , newSql ) ; namedParamIndexPropCache . put ( sql , propList ) ; } if ( sql . equals ( newSql ) ) { return null ; } List < Object > indexPropList = new ArrayList < Object > ( propList ) ; return new SqlWithParams ( newSql , indexPropList ) ; } | Hook to allow derived classes to override behavior associated with the parsing and indexing of parameters from a given sql statement . |
6,746 | protected AbstractQueryCommand createPreparedQueryCommand ( String sql , List < Object > queryParams ) { return new PreparedQueryCommand ( sql , queryParams ) ; } | Factory for the PreparedQueryCommand command pattern object allows subclass to supply implementations of the command class . |
6,747 | public void printf ( String format , Object value ) { Object object ; try { object = getProperty ( "out" ) ; } catch ( MissingPropertyException e ) { DefaultGroovyMethods . printf ( System . out , format , value ) ; return ; } InvokerHelper . invokeMethod ( object , "printf" , new Object [ ] { format , value } ) ; } | Prints a formatted string using the specified format string and argument . |
6,748 | public void run ( File file , String [ ] arguments ) throws CompilationFailedException , IOException { GroovyShell shell = new GroovyShell ( getClass ( ) . getClassLoader ( ) , binding ) ; shell . run ( file , arguments ) ; } | A helper method to allow scripts to be run taking command line arguments |
6,749 | public static GroovyRowResult toRowResult ( ResultSet rs ) throws SQLException { ResultSetMetaData metadata = rs . getMetaData ( ) ; Map < String , Object > lhm = new LinkedHashMap < String , Object > ( metadata . getColumnCount ( ) , 1 ) ; for ( int i = 1 ; i <= metadata . getColumnCount ( ) ; i ++ ) { lhm . put ( metadata . getColumnLabel ( i ) , rs . getObject ( i ) ) ; } return new GroovyRowResult ( lhm ) ; } | Returns a GroovyRowResult given a ResultSet . |
6,750 | public static < T > T min ( Iterable < T > items ) { T answer = null ; for ( T value : items ) { if ( value != null ) { if ( answer == null || ScriptBytecodeAdapter . compareLessThan ( value , answer ) ) { answer = value ; } } } return answer ; } | Selects the minimum value found in an Iterable of items . |
6,751 | public static < T > T max ( Iterable < T > items ) { T answer = null ; for ( T value : items ) { if ( value != null ) { if ( answer == null || ScriptBytecodeAdapter . compareGreaterThan ( value , answer ) ) { answer = value ; } } } return answer ; } | Selects the maximum value found in an Iterable . |
6,752 | public static Expression transformListOfConstants ( ListExpression origList , ClassNode attrType ) { ListExpression newList = new ListExpression ( ) ; boolean changed = false ; for ( Expression e : origList . getExpressions ( ) ) { try { Expression transformed = transformInlineConstants ( e , attrType ) ; newList . addExpression ( transformed ) ; if ( transformed != e ) changed = true ; } catch ( Exception ignored ) { newList . addExpression ( e ) ; } } if ( changed ) { newList . setSourcePosition ( origList ) ; return newList ; } return origList ; } | Given a list of constants transform each item in the list . |
6,753 | public Template createTemplate ( final Reader reader ) throws CompilationFailedException , ClassNotFoundException , IOException { return new StreamingTemplate ( reader , parentLoader ) ; } | Creates a template instance using the template source from the provided Reader . |
6,754 | private void fillMethodIndex ( ) { mainClassMethodHeader = metaMethodIndex . getHeader ( theClass ) ; LinkedList < CachedClass > superClasses = getSuperClasses ( ) ; CachedClass firstGroovySuper = calcFirstGroovySuperClass ( superClasses ) ; Set < CachedClass > interfaces = theCachedClass . getInterfaces ( ) ; addInterfaceMethods ( interfaces ) ; populateMethods ( superClasses , firstGroovySuper ) ; inheritInterfaceNewMetaMethods ( interfaces ) ; if ( isGroovyObject ) { metaMethodIndex . copyMethodsToSuper ( ) ; connectMultimethods ( superClasses , firstGroovySuper ) ; removeMultimethodsOverloadedWithPrivateMethods ( ) ; replaceWithMOPCalls ( theCachedClass . mopMethods ) ; } } | Fills the method index |
6,755 | private Object getMethods ( Class sender , String name , boolean isCallToSuper ) { Object answer ; final MetaMethodIndex . Entry entry = metaMethodIndex . getMethods ( sender , name ) ; if ( entry == null ) answer = FastArray . EMPTY_LIST ; else if ( isCallToSuper ) { answer = entry . methodsForSuper ; } else { answer = entry . methods ; } if ( answer == null ) answer = FastArray . EMPTY_LIST ; if ( ! isCallToSuper ) { List used = GroovyCategorySupport . getCategoryMethods ( name ) ; if ( used != null ) { FastArray arr ; if ( answer instanceof MetaMethod ) { arr = new FastArray ( ) ; arr . add ( answer ) ; } else arr = ( ( FastArray ) answer ) . copy ( ) ; for ( Iterator iter = used . iterator ( ) ; iter . hasNext ( ) ; ) { MetaMethod element = ( MetaMethod ) iter . next ( ) ; if ( ! element . getDeclaringClass ( ) . getTheClass ( ) . isAssignableFrom ( sender ) ) continue ; filterMatchingMethodForCategory ( arr , element ) ; } answer = arr ; } } return answer ; } | Gets all instance methods available on this class for the given name |
6,756 | private Object getStaticMethods ( Class sender , String name ) { final MetaMethodIndex . Entry entry = metaMethodIndex . getMethods ( sender , name ) ; if ( entry == null ) return FastArray . EMPTY_LIST ; Object answer = entry . staticMethods ; if ( answer == null ) return FastArray . EMPTY_LIST ; return answer ; } | Returns all the normal static methods on this class for the given name |
6,757 | public void addNewInstanceMethod ( Method method ) { final CachedMethod cachedMethod = CachedMethod . find ( method ) ; NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod ( cachedMethod ) ; final CachedClass declaringClass = newMethod . getDeclaringClass ( ) ; addNewInstanceMethodToIndex ( newMethod , metaMethodIndex . getHeader ( declaringClass . getTheClass ( ) ) ) ; } | Adds an instance method to this metaclass . |
6,758 | public void addNewStaticMethod ( Method method ) { final CachedMethod cachedMethod = CachedMethod . find ( method ) ; NewStaticMetaMethod newMethod = new NewStaticMetaMethod ( cachedMethod ) ; final CachedClass declaringClass = newMethod . getDeclaringClass ( ) ; addNewStaticMethodToIndex ( newMethod , metaMethodIndex . getHeader ( declaringClass . getTheClass ( ) ) ) ; } | Adds a static method to this metaclass . |
6,759 | public Object invokeMethod ( Object object , String methodName , Object arguments ) { if ( arguments == null ) { return invokeMethod ( object , methodName , MetaClassHelper . EMPTY_ARRAY ) ; } if ( arguments instanceof Tuple ) { Tuple tuple = ( Tuple ) arguments ; return invokeMethod ( object , methodName , tuple . toArray ( ) ) ; } if ( arguments instanceof Object [ ] ) { return invokeMethod ( object , methodName , ( Object [ ] ) arguments ) ; } else { return invokeMethod ( object , methodName , new Object [ ] { arguments } ) ; } } | Invoke a method on the given object with the given arguments . |
6,760 | public Object invokeMissingMethod ( Object instance , String methodName , Object [ ] arguments ) { return invokeMissingMethod ( instance , methodName , arguments , null , false ) ; } | Invoke a missing method on the given object with the given arguments . |
6,761 | public Object invokeMissingProperty ( Object instance , String propertyName , Object optionalValue , boolean isGetter ) { Class theClass = instance instanceof Class ? ( Class ) instance : instance . getClass ( ) ; CachedClass superClass = theCachedClass ; while ( superClass != null && superClass != ReflectionCache . OBJECT_CLASS ) { final MetaBeanProperty property = findPropertyInClassHierarchy ( propertyName , superClass ) ; if ( property != null ) { onSuperPropertyFoundInHierarchy ( property ) ; if ( ! isGetter ) { property . setProperty ( instance , optionalValue ) ; return null ; } else { return property . getProperty ( instance ) ; } } superClass = superClass . getCachedSuperClass ( ) ; } if ( isGetter ) { final Class [ ] getPropertyArgs = { String . class } ; final MetaMethod method = findMethodInClassHierarchy ( instance . getClass ( ) , GET_PROPERTY_METHOD , getPropertyArgs , this ) ; if ( method instanceof ClosureMetaMethod ) { onGetPropertyFoundInHierarchy ( method ) ; return method . invoke ( instance , new Object [ ] { propertyName } ) ; } } else { final Class [ ] setPropertyArgs = { String . class , Object . class } ; final MetaMethod method = findMethodInClassHierarchy ( instance . getClass ( ) , SET_PROPERTY_METHOD , setPropertyArgs , this ) ; if ( method instanceof ClosureMetaMethod ) { onSetPropertyFoundInHierarchy ( method ) ; return method . invoke ( instance , new Object [ ] { propertyName , optionalValue } ) ; } } try { if ( ! ( instance instanceof Class ) ) { if ( isGetter ) { if ( propertyMissingGet != null ) { return propertyMissingGet . invoke ( instance , new Object [ ] { propertyName } ) ; } } else { if ( propertyMissingSet != null ) { return propertyMissingSet . invoke ( instance , new Object [ ] { propertyName , optionalValue } ) ; } } } } catch ( InvokerInvocationException iie ) { boolean shouldHandle = isGetter && propertyMissingGet != null ; if ( ! shouldHandle ) shouldHandle = ! isGetter && propertyMissingSet != null ; if ( shouldHandle && iie . getCause ( ) instanceof MissingPropertyException ) { throw ( MissingPropertyException ) iie . getCause ( ) ; } throw iie ; } if ( instance instanceof Class && theClass != Class . class ) { final MetaProperty metaProperty = InvokerHelper . getMetaClass ( Class . class ) . hasProperty ( instance , propertyName ) ; if ( metaProperty != null ) if ( isGetter ) return metaProperty . getProperty ( instance ) ; else { metaProperty . setProperty ( instance , optionalValue ) ; return null ; } } throw new MissingPropertyExceptionNoStack ( propertyName , theClass ) ; } | Invoke a missing property on the given object with the given arguments . |
6,762 | protected Object invokeStaticMissingProperty ( Object instance , String propertyName , Object optionalValue , boolean isGetter ) { MetaClass mc = instance instanceof Class ? registry . getMetaClass ( ( Class ) instance ) : this ; if ( isGetter ) { MetaMethod propertyMissing = mc . getMetaMethod ( STATIC_PROPERTY_MISSING , GETTER_MISSING_ARGS ) ; if ( propertyMissing != null ) { return propertyMissing . invoke ( instance , new Object [ ] { propertyName } ) ; } } else { MetaMethod propertyMissing = mc . getMetaMethod ( STATIC_PROPERTY_MISSING , SETTER_MISSING_ARGS ) ; if ( propertyMissing != null ) { return propertyMissing . invoke ( instance , new Object [ ] { propertyName , optionalValue } ) ; } } if ( instance instanceof Class ) { throw new MissingPropertyException ( propertyName , ( Class ) instance ) ; } throw new MissingPropertyException ( propertyName , theClass ) ; } | Hook to deal with the case of MissingProperty for static properties . The method will look attempt to look up propertyMissing handlers and invoke them otherwise thrown a MissingPropertyException |
6,763 | public Object invokeMethod ( Object object , String methodName , Object [ ] originalArguments ) { return invokeMethod ( theClass , object , methodName , originalArguments , false , false ) ; } | Invokes a method on the given receiver for the specified arguments . The MetaClass will attempt to establish the method to invoke based on the name and arguments provided . |
6,764 | private MetaMethod getMethodWithCachingInternal ( Class sender , CallSite site , Class [ ] params ) { if ( GroovyCategorySupport . hasCategoryInCurrentThread ( ) ) return getMethodWithoutCaching ( sender , site . getName ( ) , params , false ) ; final MetaMethodIndex . Entry e = metaMethodIndex . getMethods ( sender , site . getName ( ) ) ; if ( e == null ) { return null ; } MetaMethodIndex . CacheEntry cacheEntry ; final Object methods = e . methods ; if ( methods == null ) return null ; cacheEntry = e . cachedMethod ; if ( cacheEntry != null && ( sameClasses ( cacheEntry . params , params ) ) ) { return cacheEntry . method ; } cacheEntry = new MetaMethodIndex . CacheEntry ( params , ( MetaMethod ) chooseMethod ( e . name , methods , params ) ) ; e . cachedMethod = cacheEntry ; return cacheEntry . method ; } | This method should be called by CallSite only |
6,765 | public MetaMethod retrieveConstructor ( Object [ ] arguments ) { checkInitalised ( ) ; if ( arguments == null ) arguments = EMPTY_ARGUMENTS ; Class [ ] argClasses = MetaClassHelper . convertToTypeArray ( arguments ) ; MetaClassHelper . unwrap ( arguments ) ; Object res = chooseMethod ( "<init>" , constructors , argClasses ) ; if ( res instanceof MetaMethod ) return ( MetaMethod ) res ; CachedConstructor constructor = ( CachedConstructor ) res ; if ( constructor != null ) return new MetaConstructor ( constructor , false ) ; if ( arguments . length == 1 && arguments [ 0 ] instanceof Map ) { res = chooseMethod ( "<init>" , constructors , MetaClassHelper . EMPTY_TYPE_ARRAY ) ; } else if ( arguments . length == 2 && arguments [ 1 ] instanceof Map && theClass . getEnclosingClass ( ) != null && theClass . getEnclosingClass ( ) . isAssignableFrom ( argClasses [ 0 ] ) ) { res = chooseMethod ( "<init>" , constructors , new Class [ ] { argClasses [ 0 ] } ) ; } if ( res instanceof MetaMethod ) return ( MetaMethod ) res ; constructor = ( CachedConstructor ) res ; if ( constructor != null ) return new MetaConstructor ( constructor , true ) ; return null ; } | This is a helper method added in Groovy 2 . 1 . 0 which is used only by indy . This method is for internal use only . |
6,766 | public void setProperties ( Object bean , Map map ) { checkInitalised ( ) ; for ( Iterator iter = map . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) iter . next ( ) ; String key = entry . getKey ( ) . toString ( ) ; Object value = entry . getValue ( ) ; setProperty ( bean , key , value ) ; } } | Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set |
6,767 | public List < MetaProperty > getProperties ( ) { checkInitalised ( ) ; SingleKeyHashMap propertyMap = classPropertyIndex . getNullable ( theCachedClass ) ; if ( propertyMap == null ) { propertyMap = new SingleKeyHashMap ( ) ; } List ret = new ArrayList ( propertyMap . size ( ) ) ; for ( ComplexKeyHashMap . EntryIterator iter = propertyMap . getEntrySetIterator ( ) ; iter . hasNext ( ) ; ) { MetaProperty element = ( MetaProperty ) ( ( SingleKeyHashMap . Entry ) iter . next ( ) ) . value ; if ( element instanceof CachedField ) continue ; if ( element instanceof MetaBeanProperty ) { MetaBeanProperty mp = ( MetaBeanProperty ) element ; boolean setter = true ; boolean getter = true ; if ( mp . getGetter ( ) == null || mp . getGetter ( ) instanceof GeneratedMetaMethod || mp . getGetter ( ) instanceof NewInstanceMetaMethod ) { getter = false ; } if ( mp . getSetter ( ) == null || mp . getSetter ( ) instanceof GeneratedMetaMethod || mp . getSetter ( ) instanceof NewInstanceMetaMethod ) { setter = false ; } if ( ! setter && ! getter ) continue ; } ret . add ( element ) ; } return ret ; } | Get all the properties defined for this type |
6,768 | public void addMetaBeanProperty ( MetaBeanProperty mp ) { MetaProperty staticProperty = establishStaticMetaProperty ( mp ) ; if ( staticProperty != null ) { staticPropertyIndex . put ( mp . getName ( ) , mp ) ; } else { SingleKeyHashMap propertyMap = classPropertyIndex . getNotNull ( theCachedClass ) ; CachedField field ; MetaProperty old = ( MetaProperty ) propertyMap . get ( mp . getName ( ) ) ; if ( old != null ) { if ( old instanceof MetaBeanProperty ) { field = ( ( MetaBeanProperty ) old ) . getField ( ) ; } else if ( old instanceof MultipleSetterProperty ) { field = ( ( MultipleSetterProperty ) old ) . getField ( ) ; } else { field = ( CachedField ) old ; } mp . setField ( field ) ; } propertyMap . put ( mp . getName ( ) , mp ) ; } } | Adds a new MetaBeanProperty to this MetaClass |
6,769 | public ClassNode getClassNode ( ) { if ( classNode == null && GroovyObject . class . isAssignableFrom ( theClass ) ) { String groovyFile = theClass . getName ( ) ; int idx = groovyFile . indexOf ( '$' ) ; if ( idx > 0 ) { groovyFile = groovyFile . substring ( 0 , idx ) ; } groovyFile = groovyFile . replace ( '.' , '/' ) + ".groovy" ; URL url = theClass . getClassLoader ( ) . getResource ( groovyFile ) ; if ( url == null ) { url = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( groovyFile ) ; } if ( url != null ) { try { CompilationUnit . ClassgenCallback search = new CompilationUnit . ClassgenCallback ( ) { public void call ( ClassVisitor writer , ClassNode node ) { if ( node . getName ( ) . equals ( theClass . getName ( ) ) ) { MetaClassImpl . this . classNode = node ; } } } ; CompilationUnit unit = new CompilationUnit ( ) ; unit . setClassgenCallback ( search ) ; unit . addSource ( url ) ; unit . compile ( Phases . CLASS_GENERATION ) ; } catch ( Exception e ) { throw new GroovyRuntimeException ( "Exception thrown parsing: " + groovyFile + ". Reason: " + e , e ) ; } } } return classNode ; } | Obtains a reference to the original AST for the MetaClass if it is available at runtime |
6,770 | protected final void checkIfGroovyObjectMethod ( MetaMethod metaMethod ) { if ( metaMethod instanceof ClosureMetaMethod || metaMethod instanceof MixinInstanceMetaMethod ) { if ( isGetPropertyMethod ( metaMethod ) ) { getPropertyMethod = metaMethod ; } else if ( isInvokeMethod ( metaMethod ) ) { invokeMethodMethod = metaMethod ; } else if ( isSetPropertyMethod ( metaMethod ) ) { setPropertyMethod = metaMethod ; } } } | Checks if the metaMethod is a method from the GroovyObject interface such as setProperty getProperty and invokeMethod |
6,771 | protected Object chooseMethod ( String methodName , Object methodOrList , Class [ ] arguments ) { Object method = chooseMethodInternal ( methodName , methodOrList , arguments ) ; if ( method instanceof GeneratedMetaMethod . Proxy ) return ( ( GeneratedMetaMethod . Proxy ) method ) . proxy ( ) ; return method ; } | Chooses the correct method to use from a list of methods which match by name . |
6,772 | public MetaMethod pickMethod ( String methodName , Class [ ] arguments ) { return getMethodWithoutCaching ( theClass , methodName , arguments , false ) ; } | Selects a method by name and argument classes . This method does not search for an exact match it searches for a compatible method . For this the method selection mechanism is used as provided by the implementation of this MetaClass . pickMethod may or may not be used during the method selection process when invoking a method . There is no warranty for that . |
6,773 | public static SourceUnit create ( String name , String source ) { CompilerConfiguration configuration = new CompilerConfiguration ( ) ; configuration . setTolerance ( 1 ) ; return new SourceUnit ( name , source , configuration , null , new ErrorCollector ( configuration ) ) ; } | A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable . |
6,774 | public static Number div ( Number left , Number right ) { return NumberMath . divide ( left , right ) ; } | Divide two Numbers . |
6,775 | private final void print_30_permut ( ) { final int [ ] permutation = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { permutation [ i ] = i ; System . out . print ( ( 1 + i ) ) ; } System . out . println ( ) ; final int [ ] perm_remain = new int [ n ] ; for ( int i = 1 ; i <= n ; i ++ ) perm_remain [ i - 1 ] = i ; int numPermutationsPrinted = 1 ; for ( int pos_right = 2 ; pos_right <= n ; pos_right ++ ) { int pos_left = pos_right - 1 ; do { next_perm ( permutation , pos_left ) ; if ( -- perm_remain [ pos_left ] > 0 ) { if ( numPermutationsPrinted ++ < 30 ) { for ( int i = 0 ; i < n ; ++ i ) System . out . print ( ( 1 + permutation [ i ] ) ) ; System . out . println ( ) ; } else return ; for ( ; pos_left != 1 ; -- pos_left ) perm_remain [ pos_left - 1 ] = pos_left ; } else ++ pos_left ; } while ( pos_left < pos_right ) ; } } | this function will correctly print first 30 permutations |
6,776 | private static final int count_flip ( final int [ ] perm_flip ) { int v0 = perm_flip [ 0 ] ; int tmp ; int flip_count = 0 ; do { for ( int i = 1 , j = v0 - 1 ; i < j ; ++ i , -- j ) { tmp = perm_flip [ i ] ; perm_flip [ i ] = perm_flip [ j ] ; perm_flip [ j ] = tmp ; } tmp = perm_flip [ v0 ] ; perm_flip [ v0 ] = v0 ; v0 = tmp ; flip_count ++ ; } while ( v0 != 0 ) ; return flip_count ; } | Return flipping times |
6,777 | public static < T1 , T2 , T3 > Tuple3 < T1 , T2 , T3 > tuple ( T1 v1 , T2 v2 , T3 v3 ) { return new Tuple3 < > ( v1 , v2 , v3 ) ; } | Construct a tuple of degree 3 . |
6,778 | public DefaultTableColumn addPropertyColumn ( Object headerValue , String property , Class type ) { return addColumn ( headerValue , property , new PropertyModel ( rowModel , property , type ) ) ; } | Adds a property model column to the table |
6,779 | public DefaultTableColumn addClosureColumn ( Object headerValue , Closure readClosure , Closure writeClosure , Class type ) { return addColumn ( headerValue , new ClosureModel ( rowModel , readClosure , writeClosure , type ) ) ; } | Adds a closure based column to the table |
6,780 | public void addColumn ( DefaultTableColumn column ) { column . setModelIndex ( columnModel . getColumnCount ( ) ) ; columnModel . addColumn ( column ) ; } | Adds a new column definition to the table |
6,781 | public void setRedirect ( ClassNode cn ) { if ( isPrimaryNode ) throw new GroovyBugError ( "tried to set a redirect for a primary ClassNode (" + getName ( ) + "->" + cn . getName ( ) + ")." ) ; if ( cn != null ) cn = cn . redirect ( ) ; if ( cn == this ) return ; redirect = cn ; } | Sets this instance as proxy for the given ClassNode . |
6,782 | public ClassNode makeArray ( ) { if ( redirect != null ) { ClassNode res = redirect ( ) . makeArray ( ) ; res . componentType = this ; return res ; } ClassNode cn ; if ( clazz != null ) { Class ret = Array . newInstance ( clazz , 0 ) . getClass ( ) ; cn = new ClassNode ( ret , this ) ; } else { cn = new ClassNode ( this ) ; } return cn ; } | Returns a ClassNode representing an array of the class represented by this ClassNode |
6,783 | private void lazyClassInit ( ) { if ( lazyInitDone ) return ; synchronized ( lazyInitLock ) { if ( redirect != null ) { throw new GroovyBugError ( "lazyClassInit called on a proxy ClassNode, that must not happen." + "A redirect() call is missing somewhere!" ) ; } if ( lazyInitDone ) return ; VMPluginFactory . getPlugin ( ) . configureClassNode ( compileUnit , this ) ; lazyInitDone = true ; } } | The complete class structure will be initialized only when really needed to avoid having too many objects during compilation |
6,784 | public ConstructorNode getDeclaredConstructor ( Parameter [ ] parameters ) { for ( ConstructorNode method : getDeclaredConstructors ( ) ) { if ( parametersEqual ( method . getParameters ( ) , parameters ) ) { return method ; } } return null ; } | Finds a constructor matching the given parameters in this class . |
6,785 | public MethodNode addSyntheticMethod ( String name , int modifiers , ClassNode returnType , Parameter [ ] parameters , ClassNode [ ] exceptions , Statement code ) { MethodNode answer = addMethod ( name , modifiers | ACC_SYNTHETIC , returnType , parameters , exceptions , code ) ; answer . setSynthetic ( true ) ; return answer ; } | Adds a synthetic method as part of the compilation process |
6,786 | public FieldNode getDeclaredField ( String name ) { if ( redirect != null ) return redirect ( ) . getDeclaredField ( name ) ; lazyClassInit ( ) ; return fieldIndex == null ? null : fieldIndex . get ( name ) ; } | Finds a field matching the given name in this class . |
6,787 | public FieldNode getField ( String name ) { ClassNode node = this ; while ( node != null ) { FieldNode fn = node . getDeclaredField ( name ) ; if ( fn != null ) return fn ; node = node . getSuperClass ( ) ; } return null ; } | Finds a field matching the given name in this class or a parent class . |
6,788 | public List < MethodNode > getDeclaredMethods ( String name ) { if ( redirect != null ) return redirect ( ) . getDeclaredMethods ( name ) ; lazyClassInit ( ) ; return methods . getNotNull ( name ) ; } | This methods returns a list of all methods of the given name defined in the current class |
6,789 | public List < MethodNode > getMethods ( String name ) { List < MethodNode > answer = new ArrayList < MethodNode > ( ) ; ClassNode node = this ; while ( node != null ) { answer . addAll ( node . getDeclaredMethods ( name ) ) ; node = node . getSuperClass ( ) ; } return answer ; } | This methods creates a list of all methods with this name of the current class and of all super classes |
6,790 | public MethodNode getDeclaredMethod ( String name , Parameter [ ] parameters ) { for ( MethodNode method : getDeclaredMethods ( name ) ) { if ( parametersEqual ( method . getParameters ( ) , parameters ) ) { return method ; } } return null ; } | Finds a method matching the given name and parameters in this class . |
6,791 | public MethodNode getMethod ( String name , Parameter [ ] parameters ) { for ( MethodNode method : getMethods ( name ) ) { if ( parametersEqual ( method . getParameters ( ) , parameters ) ) { return method ; } } return null ; } | Finds a method matching the given name and parameters in this class or any parent class . |
6,792 | public static String getMopMethodName ( MethodNode method , boolean useThis ) { ClassNode declaringNode = method . getDeclaringClass ( ) ; int distance = 0 ; for ( ; declaringNode != null ; declaringNode = declaringNode . getSuperClass ( ) ) { distance ++ ; } return ( useThis ? "this" : "super" ) + "$" + distance + "$" + method . getName ( ) ; } | creates a MOP method name from a method |
6,793 | public static void serialize ( Element element , OutputStream os ) { Source source = new DOMSource ( element ) ; serialize ( source , os ) ; } | Write a pretty version of the Element to the OutputStream . |
6,794 | public static void serialize ( Element element , Writer w ) { Source source = new DOMSource ( element ) ; serialize ( source , w ) ; } | Write a pretty version of the Element to the Writer . |
6,795 | public static SAXParser newSAXParser ( String schemaLanguage , Source ... schemas ) throws SAXException , ParserConfigurationException { return newSAXParser ( schemaLanguage , true , false , schemas ) ; } | Factory method to create a SAXParser configured to validate according to a particular schema language and optionally providing the schema sources to validate with . The created SAXParser will be namespace - aware and not validate against DTDs . |
6,796 | public static SAXParser newSAXParser ( String schemaLanguage , boolean namespaceAware , boolean validating , Source ... schemas ) throws SAXException , ParserConfigurationException { SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setValidating ( validating ) ; factory . setNamespaceAware ( namespaceAware ) ; if ( schemas . length != 0 ) { SchemaFactory schemaFactory = SchemaFactory . newInstance ( schemaLanguage ) ; factory . setSchema ( schemaFactory . newSchema ( schemas ) ) ; } SAXParser saxParser = factory . newSAXParser ( ) ; if ( schemas . length == 0 ) { saxParser . setProperty ( "http://java.sun.com/xml/jaxp/properties/schemaLanguage" , schemaLanguage ) ; } return saxParser ; } | Factory method to create a SAXParser configured to validate according to a particular schema language and optionally providing the schema sources to validate with . |
6,797 | public static SAXParser newSAXParser ( String schemaLanguage , File schema ) throws SAXException , ParserConfigurationException { return newSAXParser ( schemaLanguage , true , false , schema ) ; } | Factory method to create a SAXParser configured to validate according to a particular schema language and a File containing the schema to validate against . The created SAXParser will be namespace - aware and not validate against DTDs . |
6,798 | public static SAXParser newSAXParser ( String schemaLanguage , boolean namespaceAware , boolean validating , File schema ) throws SAXException , ParserConfigurationException { SchemaFactory schemaFactory = SchemaFactory . newInstance ( schemaLanguage ) ; return newSAXParser ( namespaceAware , validating , schemaFactory . newSchema ( schema ) ) ; } | Factory method to create a SAXParser configured to validate according to a particular schema language and a File containing the schema to validate against . |
6,799 | public Object run ( final File scriptFile , String [ ] args ) throws CompilationFailedException , IOException { String scriptName = scriptFile . getName ( ) ; int p = scriptName . lastIndexOf ( "." ) ; if ( p ++ >= 0 ) { if ( scriptName . substring ( p ) . equals ( "java" ) ) { throw new CompilationFailedException ( 0 , null ) ; } } final Thread thread = Thread . currentThread ( ) ; class DoSetContext implements PrivilegedAction { ClassLoader classLoader ; public DoSetContext ( ClassLoader loader ) { classLoader = loader ; } public Object run ( ) { thread . setContextClassLoader ( classLoader ) ; return null ; } } AccessController . doPrivileged ( new DoSetContext ( loader ) ) ; Class scriptClass ; try { scriptClass = AccessController . doPrivileged ( new PrivilegedExceptionAction < Class > ( ) { public Class run ( ) throws CompilationFailedException , IOException { return loader . parseClass ( scriptFile ) ; } } ) ; } catch ( PrivilegedActionException pae ) { Exception e = pae . getException ( ) ; if ( e instanceof CompilationFailedException ) { throw ( CompilationFailedException ) e ; } else if ( e instanceof IOException ) { throw ( IOException ) e ; } else { throw ( RuntimeException ) pae . getException ( ) ; } } return runScriptOrMainOrTestOrRunnable ( scriptClass , args ) ; } | Runs the given script file name with the given command line arguments |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.