idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
6,500
public List rows ( int offset , int maxRows ) throws SQLException { return rows ( getSql ( ) , getParameters ( ) , offset , maxRows ) ; }
Returns a page of the rows from the table a DataSet represents . A page is defined as starting at a 1 - based offset and containing a maximum number of rows .
6,501
public Object firstRow ( ) throws SQLException { List rows = rows ( ) ; if ( rows . isEmpty ( ) ) return null ; return ( rows . get ( 0 ) ) ; }
Returns the first row from a DataSet s underlying table
6,502
protected void addError ( String message , ASTNode node , SourceUnit source ) { source . getErrorCollector ( ) . addErrorAndContinue ( new SyntaxErrorMessage ( new SyntaxException ( message , node . getLineNumber ( ) , node . getColumnNumber ( ) , node . getLastLineNumber ( ) , node . getLastColumnNumber ( ) ) , source ) ) ; }
Adds a new syntax error to the source unit and then continues .
6,503
private static ClassNode getSerializeClass ( ClassNode alias ) { List < AnnotationNode > annotations = alias . getAnnotations ( ClassHelper . make ( AnnotationCollector . class ) ) ; if ( ! annotations . isEmpty ( ) ) { AnnotationNode annotationNode = annotations . get ( 0 ) ; Expression member = annotationNode . getMember ( "serializeClass" ) ; if ( member instanceof ClassExpression ) { ClassExpression ce = ( ClassExpression ) member ; if ( ! ce . getType ( ) . getName ( ) . equals ( AnnotationCollector . class . getName ( ) ) ) { alias = ce . getType ( ) ; } } } return alias ; }
2 . 5 . 3 and above gets from annotation attribute otherwise self
6,504
protected List < AnnotationNode > getTargetAnnotationList ( AnnotationNode collector , AnnotationNode aliasAnnotationUsage , SourceUnit source ) { List < AnnotationNode > stored = getStoredTargetList ( aliasAnnotationUsage , source ) ; List < AnnotationNode > targetList = getTargetListFromValue ( collector , aliasAnnotationUsage , source ) ; int size = targetList . size ( ) + stored . size ( ) ; if ( size == 0 ) { return Collections . emptyList ( ) ; } List < AnnotationNode > ret = new ArrayList < AnnotationNode > ( size ) ; ret . addAll ( stored ) ; ret . addAll ( targetList ) ; return ret ; }
Returns a list of AnnotationNodes for the value attribute of the given AnnotationNode .
6,505
public List < AnnotationNode > visit ( AnnotationNode collector , AnnotationNode aliasAnnotationUsage , AnnotatedNode aliasAnnotated , SourceUnit source ) { List < AnnotationNode > ret = getTargetAnnotationList ( collector , aliasAnnotationUsage , source ) ; Set < String > unusedNames = new HashSet < String > ( aliasAnnotationUsage . getMembers ( ) . keySet ( ) ) ; for ( AnnotationNode an : ret ) { for ( String name : aliasAnnotationUsage . getMembers ( ) . keySet ( ) ) { if ( an . getClassNode ( ) . hasMethod ( name , Parameter . EMPTY_ARRAY ) ) { unusedNames . remove ( name ) ; an . setMember ( name , aliasAnnotationUsage . getMember ( name ) ) ; } } } if ( ! unusedNames . isEmpty ( ) ) { String message = "Annotation collector got unmapped names " + unusedNames . toString ( ) + "." ; addError ( message , aliasAnnotationUsage , source ) ; } return ret ; }
Implementation method of the alias annotation processor . This method will get the list of annotations we aliased from the collector and adds it to aliasAnnotationUsage . The method will also map all members from aliasAnnotationUsage to the aliased nodes . Should a member stay unmapped we will ad an error . Further processing of those members is done by the annotations .
6,506
public String namespaceURI ( ) { if ( namespacePrefix == null || namespacePrefix . isEmpty ( ) ) return "" ; String uri = namespaceTagHints . get ( namespacePrefix ) ; return uri == null ? "" : uri ; }
Returns the URI of the namespace of this Attribute .
6,507
public static < K , V > EntryWeigher < K , V > asEntryWeigher ( final Weigher < ? super V > weigher ) { return ( weigher == singleton ( ) ) ? Weighers . < K , V > entrySingleton ( ) : new EntryWeigherView < K , V > ( weigher ) ; }
A entry weigher backed by the specified weigher . The weight of the value determines the weight of the entry .
6,508
public static void addReturnIfNeeded ( MethodNode node ) { ReturnAdder adder = new ReturnAdder ( ) ; adder . visitMethod ( node ) ; }
Adds return statements in method code whenever an implicit return is detected .
6,509
public synchronized void touch ( final Object key , final Object value ) { remove ( key ) ; put ( key , value ) ; }
The touch method can be used to renew an element and move it to the from of the LRU queue .
6,510
public synchronized Object get ( final Object key ) { final Object value = remove ( key ) ; if ( value != null ) put ( key , value ) ; return value ; }
Makes sure the retrieved object is moved to the head of the LRU list
6,511
public static Class getCallingClass ( int matchLevel , Collection < String > extraIgnoredPackages ) { Class [ ] classContext = HELPER . getClassContext ( ) ; int depth = 0 ; try { Class c ; Class sc ; do { do { c = classContext [ depth ++ ] ; if ( c != null ) { sc = c . getSuperclass ( ) ; } else { sc = null ; } } while ( classShouldBeIgnored ( c , extraIgnoredPackages ) || superClassShouldBeIgnored ( sc ) ) ; } while ( c != null && matchLevel -- > 0 && depth < classContext . length ) ; return c ; } catch ( Throwable t ) { return null ; } }
Get the called that is matchLevel stack frames before the call ignoring MOP frames and desired exclude packages .
6,512
public boolean isOneOf ( int [ ] types ) { int meaning = getMeaning ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { if ( Types . ofType ( meaning , types [ i ] ) ) { return true ; } } return false ; }
Returns true if the node s meaning matches any of the specified types .
6,513
public int getMeaningAs ( int [ ] types ) { for ( int i = 0 ; i < types . length ; i ++ ) { if ( isA ( types [ i ] ) ) { return types [ i ] ; } } return Types . UNKNOWN ; }
Returns the first matching meaning of the specified types . Returns Types . UNKNOWN if there are no matches .
6,514
boolean matches ( int type , int child1 , int child2 ) { return matches ( type , child1 ) && get ( 2 , true ) . isA ( child2 ) ; }
Returns true if the node and it s first and second child match the specified types . Missing nodes are Token . NULL .
6,515
public Token getRoot ( boolean safe ) { Token root = getRoot ( ) ; if ( root == null && safe ) { root = Token . NULL ; } return root ; }
Returns the root of the node the Token that indicates it s type . Returns a Token . NULL if safe and the actual root is null .
6,516
public void addChildrenOf ( CSTNode of ) { for ( int i = 1 ; i < of . size ( ) ; i ++ ) { add ( of . get ( i ) ) ; } }
Adds all children of the specified node to this one . Not all nodes support this operation!
6,517
public Closure < V > ncurry ( int n , final Object argument ) { return ncurry ( n , new Object [ ] { argument } ) ; }
Support for Closure currying at a given index .
6,518
@ SuppressWarnings ( "unchecked" ) public Closure < V > dehydrate ( ) { Closure < V > result = ( Closure < V > ) this . clone ( ) ; result . delegate = null ; result . owner = null ; result . thisObject = null ; return result ; }
Returns a copy of this closure where the owner delegate and thisObject fields are null allowing proper serialization when one of them is not serializable .
6,519
public Object beforeInvoke ( Object object , String methodName , Object [ ] arguments ) { if ( ! calls . containsKey ( methodName ) ) calls . put ( methodName , new LinkedList ( ) ) ; ( ( List ) calls . get ( methodName ) ) . add ( System . currentTimeMillis ( ) ) ; return null ; }
This code is executed before the method is called .
6,520
public Object afterInvoke ( Object object , String methodName , Object [ ] arguments , Object result ) { ( ( List ) calls . get ( methodName ) ) . add ( System . currentTimeMillis ( ) ) ; return result ; }
This code is executed after the method is called .
6,521
protected static Class getWrapperClass ( Class c ) { if ( c == Integer . TYPE ) { c = Integer . class ; } else if ( c == Byte . TYPE ) { c = Byte . class ; } else if ( c == Long . TYPE ) { c = Long . class ; } else if ( c == Double . TYPE ) { c = Double . class ; } else if ( c == Float . TYPE ) { c = Float . class ; } else if ( c == Boolean . TYPE ) { c = Boolean . class ; } else if ( c == Character . TYPE ) { c = Character . class ; } else if ( c == Short . TYPE ) { c = Short . class ; } return c ; }
Get wrapper class for a given class . If the class is for a primitive number type then the wrapper class will be returned . If it is no primitive number type we return the class itself .
6,522
protected static boolean argumentClassIsParameterClass ( Class argumentClass , Class parameterClass ) { if ( argumentClass == parameterClass ) return true ; if ( getWrapperClass ( parameterClass ) == argumentClass ) return true ; return false ; }
Realizes an unsharp equal for the class . In general we return true if the provided arguments are the same . But we will also return true if our argument class is a wrapper for the parameter class . For example the parameter is an int and the argument class is a wrapper .
6,523
protected static MethodType replaceWithMoreSpecificType ( Object [ ] args , MethodType callSiteType ) { for ( int i = 0 ; i < args . length ; i ++ ) { if ( args [ i ] == null ) continue ; if ( callSiteType . parameterType ( i ) . isPrimitive ( ) ) continue ; Class argClass = args [ i ] . getClass ( ) ; callSiteType = callSiteType . changeParameterType ( i , argClass ) ; } return callSiteType ; }
Replaces the types in the callSiteType parameter if more specific types given through the arguments . This is in general the case unless the argument is null .
6,524
public void setPackagenames ( String packages ) { StringTokenizer tok = new StringTokenizer ( packages , "," ) ; while ( tok . hasMoreTokens ( ) ) { String packageName = tok . nextToken ( ) ; packageNames . add ( packageName ) ; } }
Set the package names to be processed .
6,525
public static final double random ( double max ) { last = ( last * IA + IC ) % IM ; return max * last / IM ; }
pseudo - random number generator
6,526
private JsonToken readingConstant ( JsonTokenType type , JsonToken token ) { try { int numCharsToRead = ( ( String ) type . getValidator ( ) ) . length ( ) ; char [ ] chars = new char [ numCharsToRead ] ; reader . read ( chars ) ; String stringRead = new String ( chars ) ; if ( stringRead . equals ( type . getValidator ( ) ) ) { token . setEndColumn ( token . getStartColumn ( ) + numCharsToRead ) ; token . setText ( stringRead ) ; return token ; } else { throwJsonException ( stringRead , type ) ; } } catch ( IOException ioe ) { throw new JsonException ( "An IO exception occurred while reading the JSON payload" , ioe ) ; } return null ; }
When a constant token type is expected check that the expected constant is read and update the content of the token accordingly .
6,527
public int skipWhitespace ( ) { try { int readChar = 20 ; char c = SPACE ; while ( Character . isWhitespace ( c ) ) { reader . mark ( 1 ) ; readChar = reader . read ( ) ; c = ( char ) readChar ; } reader . reset ( ) ; return readChar ; } catch ( IOException ioe ) { throw new JsonException ( "An IO exception occurred while reading the JSON payload" , ioe ) ; } }
Skips all the whitespace characters and moves the cursor to the next non - space character .
6,528
private static VariableExpression getTarget ( VariableExpression ve ) { if ( ve . getAccessedVariable ( ) == null || ve . getAccessedVariable ( ) == ve || ( ! ( ve . getAccessedVariable ( ) instanceof VariableExpression ) ) ) return ve ; return getTarget ( ( VariableExpression ) ve . getAccessedVariable ( ) ) ; }
The inferred type in case of a variable expression can be set on the accessed variable so we take it instead of the facade one .
6,529
public String getLine ( int lineNumber , Janitor janitor ) { if ( lineSource != null && number > lineNumber ) { cleanup ( ) ; } if ( lineSource == null ) { try { lineSource = new BufferedReader ( getReader ( ) ) ; } catch ( Exception e ) { } number = 0 ; } if ( lineSource != null ) { while ( number < lineNumber ) { try { line = lineSource . readLine ( ) ; number ++ ; } catch ( IOException e ) { cleanup ( ) ; } } if ( janitor == null ) { final String result = line ; cleanup ( ) ; return result ; } else { janitor . register ( this ) ; } } return line ; }
Returns a line from the source or null if unavailable . If you supply a Janitor resources will be cached .
6,530
public Object getAt ( int index ) { try { if ( index < 0 ) index += result . size ( ) ; Iterator it = result . values ( ) . iterator ( ) ; int i = 0 ; Object obj = null ; while ( ( obj == null ) && ( it . hasNext ( ) ) ) { if ( i == index ) obj = it . next ( ) ; else it . next ( ) ; i ++ ; } return obj ; } catch ( Exception e ) { throw new MissingPropertyException ( Integer . toString ( index ) , GroovyRowResult . class , e ) ; } }
Retrieve the value of the property by its index . A negative index will count backwards from the last column .
6,531
@ SuppressWarnings ( "unchecked" ) public Object put ( Object key , Object value ) { Object orig = remove ( key ) ; result . put ( key , value ) ; return orig ; }
Associates the specified value with the specified property name in this result .
6,532
public static < T > T withObjectOutputStream ( Path self , @ ClosureParams ( value = SimpleType . class , options = "java.io.ObjectOutputStream" ) Closure < T > closure ) throws IOException { return IOGroovyMethods . withStream ( newObjectOutputStream ( self ) , closure ) ; }
Create a new ObjectOutputStream for this path and then pass it to the closure . This method ensures the stream is closed after the closure returns .
6,533
public static ObjectInputStream newObjectInputStream ( Path self , final ClassLoader classLoader ) throws IOException { return IOGroovyMethods . newObjectInputStream ( Files . newInputStream ( self ) , classLoader ) ; }
Create an object input stream for this path using the given class loader .
6,534
public static < T > T withObjectInputStream ( Path self , ClassLoader classLoader , @ ClosureParams ( value = SimpleType . class , options = "java.io.ObjectInputStream" ) Closure < T > closure ) throws IOException { return IOGroovyMethods . withStream ( newObjectInputStream ( self , classLoader ) , closure ) ; }
Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure . This method ensures the stream is closed after the closure returns .
6,535
public static String getText ( Path self , String charset ) throws IOException { return IOGroovyMethods . getText ( newReader ( self , charset ) ) ; }
Read the content of the Path using the specified encoding and return it as a String .
6,536
public static void setBytes ( Path self , byte [ ] bytes ) throws IOException { IOGroovyMethods . setBytes ( Files . newOutputStream ( self ) , bytes ) ; }
Write the bytes from the byte array to the Path .
6,537
public static Path leftShift ( Path self , byte [ ] bytes ) throws IOException { append ( self , bytes ) ; return self ; }
Write bytes to a Path .
6,538
public static void write ( Path self , String text , String charset ) throws IOException { write ( self , text , charset , false ) ; }
Write the text to the Path without writing a BOM using the specified encoding .
6,539
public static void append ( Path self , Object text ) throws IOException { append ( self , text , Charset . defaultCharset ( ) . name ( ) , false ) ; }
Append the text at the end of the Path without writing a BOM .
6,540
public static void append ( Path self , Object text , String charset ) throws IOException { append ( self , text , charset , false ) ; }
Append the text at the end of the Path without writing a BOM using a specified encoding .
6,541
public static void eachDir ( Path self , @ ClosureParams ( value = SimpleType . class , options = "java.nio.file.Path" ) Closure closure ) throws IOException { eachFile ( self , FileType . DIRECTORIES , closure ) ; }
Invokes the closure for each subdirectory in this directory ignoring regular files .
6,542
public static boolean renameTo ( final Path self , URI newPathName ) { try { Files . move ( self , Paths . get ( newPathName ) ) ; return true ; } catch ( IOException e ) { return false ; } }
Renames a file .
6,543
public static BufferedWriter newWriter ( Path self ) throws IOException { return Files . newBufferedWriter ( self , Charset . defaultCharset ( ) ) ; }
Create a buffered writer for this file .
6,544
public static BufferedWriter newWriter ( Path self , String charset , boolean append ) throws IOException { return newWriter ( self , charset , append , false ) ; }
Helper method to create a buffered writer for a file without writing a BOM .
6,545
public static < T > T withWriter ( Path self , String charset , @ ClosureParams ( value = SimpleType . class , options = "java.io.Writer" ) Closure < T > closure ) throws IOException { return withWriter ( self , charset , false , closure ) ; }
Creates a new BufferedWriter for this file passes it to the closure and ensures the stream is flushed and closed after the closure returns . The writer will use the given charset encoding but will not write a BOM .
6,546
public static < T > T withWriterAppend ( Path self , @ ClosureParams ( value = SimpleType . class , options = "java.io.Writer" ) Closure < T > closure ) throws IOException { return withWriterAppend ( self , Charset . defaultCharset ( ) . name ( ) , closure ) ; }
Create a new BufferedWriter for this file in append mode . The writer is passed to the closure and is closed after the closure returns . The writer will not write a BOM .
6,547
public static PrintWriter newPrintWriter ( Path self , String charset ) throws IOException { return new GroovyPrintWriter ( newWriter ( self , charset ) ) ; }
Create a new PrintWriter for this file using specified charset .
6,548
public static void eachByte ( Path self , int bufferLen , @ ClosureParams ( value = FromString . class , options = "byte[],Integer" ) Closure closure ) throws IOException { BufferedInputStream is = newInputStream ( self ) ; IOGroovyMethods . eachByte ( is , bufferLen , closure ) ; }
Traverse through the bytes of this Path bufferLen bytes at a time .
6,549
public int compareTo ( Object that ) { if ( that instanceof GroovyDoc ) { return name . compareTo ( ( ( GroovyDoc ) that ) . name ( ) ) ; } else { throw new ClassCastException ( String . format ( "Cannot compare object of type %s." , that . getClass ( ) ) ) ; } }
Methods from Comparable
6,550
public static void setProperties ( Object object , Map map ) { MetaClass mc = getMetaClass ( object ) ; for ( Object o : map . entrySet ( ) ) { Map . Entry entry = ( Map . Entry ) o ; String key = entry . getKey ( ) . toString ( ) ; Object value = entry . getValue ( ) ; setPropertySafe ( object , mc , key , value ) ; } }
Sets the properties on the given object
6,551
public static void write ( Writer out , Object object ) throws IOException { if ( object instanceof String ) { out . write ( ( String ) object ) ; } else if ( object instanceof Object [ ] ) { out . write ( toArrayString ( ( Object [ ] ) object ) ) ; } else if ( object instanceof Map ) { out . write ( toMapString ( ( Map ) object ) ) ; } else if ( object instanceof Collection ) { out . write ( toListString ( ( Collection ) object ) ) ; } else if ( object instanceof Writable ) { Writable writable = ( Writable ) object ; writable . writeTo ( out ) ; } else if ( object instanceof InputStream || object instanceof Reader ) { Reader reader ; if ( object instanceof InputStream ) { reader = new InputStreamReader ( ( InputStream ) object ) ; } else { reader = ( Reader ) object ; } try ( Reader r = reader ) { char [ ] chars = new char [ 8192 ] ; for ( int i ; ( i = r . read ( chars ) ) != - 1 ; ) { out . write ( chars , 0 , i ) ; } } } else { out . write ( toString ( object ) ) ; } }
Writes an object to a Writer using Groovy s default representation for the object .
6,552
public static void append ( Appendable out , Object object ) throws IOException { if ( object instanceof String ) { out . append ( ( String ) object ) ; } else if ( object instanceof Object [ ] ) { out . append ( toArrayString ( ( Object [ ] ) object ) ) ; } else if ( object instanceof Map ) { out . append ( toMapString ( ( Map ) object ) ) ; } else if ( object instanceof Collection ) { out . append ( toListString ( ( Collection ) object ) ) ; } else if ( object instanceof Writable ) { Writable writable = ( Writable ) object ; Writer stringWriter = new StringBuilderWriter ( ) ; writable . writeTo ( stringWriter ) ; out . append ( stringWriter . toString ( ) ) ; } else if ( object instanceof InputStream || object instanceof Reader ) { Reader reader ; if ( object instanceof InputStream ) { reader = new InputStreamReader ( ( InputStream ) object ) ; } else { reader = ( Reader ) object ; } char [ ] chars = new char [ 8192 ] ; int i ; while ( ( i = reader . read ( chars ) ) != - 1 ) { for ( int j = 0 ; j < i ; j ++ ) { out . append ( chars [ j ] ) ; } } reader . close ( ) ; } else { out . append ( toString ( object ) ) ; } }
Appends an object to an Appendable using Groovy s default representation for the object .
6,553
public void setSrcdir ( Path srcDir ) { if ( src == null ) { src = srcDir ; } else { src . append ( srcDir ) ; } }
Set the source directories to find the source Java files .
6,554
public void setSourcepath ( Path sourcepath ) { if ( compileSourcepath == null ) { compileSourcepath = sourcepath ; } else { compileSourcepath . append ( sourcepath ) ; } }
Set the sourcepath to be used for this compilation .
6,555
public synchronized void updatePath ( PropertyChangeListener listener , Object newObject , Set updateSet ) { if ( currentObject != newObject ) { removeListeners ( ) ; } if ( ( children != null ) && ( children . length > 0 ) ) { try { Object newValue = null ; if ( newObject != null ) { updateSet . add ( newObject ) ; newValue = extractNewValue ( newObject ) ; } for ( BindPath child : children ) { child . updatePath ( listener , newValue , updateSet ) ; } } catch ( Exception e ) { } } if ( currentObject != newObject ) { addListeners ( listener , newObject , updateSet ) ; } }
Called when we detect a change somewhere down our path . First check to see if our object is changing . If so remove our old listener Next update the reference object the children have and recurse Finally add listeners if we have a different object
6,556
public void addAllListeners ( PropertyChangeListener listener , Object newObject , Set updateSet ) { addListeners ( listener , newObject , updateSet ) ; if ( ( children != null ) && ( children . length > 0 ) ) { try { Object newValue = null ; if ( newObject != null ) { updateSet . add ( newObject ) ; newValue = extractNewValue ( newObject ) ; } for ( BindPath child : children ) { child . addAllListeners ( listener , newValue , updateSet ) ; } } catch ( Exception e ) { e . printStackTrace ( System . out ) ; } } }
Adds all the listeners to the objects in the bind path . This assumes that we are not added as listeners to any of them hence it is not idempotent .
6,557
public void addListeners ( PropertyChangeListener listener , Object newObject , Set updateSet ) { removeListeners ( ) ; if ( newObject != null ) { TriggerBinding syntheticTrigger = getSyntheticTriggerBinding ( newObject ) ; MetaClass mc = InvokerHelper . getMetaClass ( newObject ) ; if ( syntheticTrigger != null ) { PropertyBinding psb = new PropertyBinding ( newObject , propertyName ) ; PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding ( newObject , propertyName , listener ) ; syntheticFullBinding = syntheticTrigger . createBinding ( psb , proxytb ) ; syntheticFullBinding . bind ( ) ; updateSet . add ( newObject ) ; } else if ( ! mc . respondsTo ( newObject , "addPropertyChangeListener" , NAME_PARAMS ) . isEmpty ( ) ) { InvokerHelper . invokeMethod ( newObject , "addPropertyChangeListener" , new Object [ ] { propertyName , listener } ) ; localListener = listener ; updateSet . add ( newObject ) ; } else if ( ! mc . respondsTo ( newObject , "addPropertyChangeListener" , GLOBAL_PARAMS ) . isEmpty ( ) ) { InvokerHelper . invokeMethod ( newObject , "addPropertyChangeListener" , listener ) ; globalListener = listener ; updateSet . add ( newObject ) ; } } currentObject = newObject ; }
Add listeners to a specific object . Updates the bould flags and update set
6,558
public void removeListeners ( ) { if ( globalListener != null ) { try { InvokerHelper . invokeMethod ( currentObject , "removePropertyChangeListener" , globalListener ) ; } catch ( Exception e ) { } globalListener = null ; } if ( localListener != null ) { try { InvokerHelper . invokeMethod ( currentObject , "removePropertyChangeListener" , new Object [ ] { propertyName , localListener } ) ; } catch ( Exception e ) { } localListener = null ; } if ( syntheticFullBinding != null ) { syntheticFullBinding . unbind ( ) ; } }
Remove listeners believing that our bould flags are accurate and it removes only as declared .
6,559
private boolean tryMacroMethod ( MethodCallExpression call , ExtensionMethodNode macroMethod , Object [ ] macroArguments ) { Expression result = ( Expression ) InvokerHelper . invokeStaticMethod ( macroMethod . getExtensionMethodNode ( ) . getDeclaringClass ( ) . getTypeClass ( ) , macroMethod . getName ( ) , macroArguments ) ; if ( result == null ) { return false ; } call . setObjectExpression ( MACRO_STUB_INSTANCE ) ; call . setMethod ( new ConstantExpression ( MACRO_STUB_METHOD_NAME ) ) ; call . setSpreadSafe ( false ) ; call . setSafe ( false ) ; call . setImplicitThis ( false ) ; call . setArguments ( result ) ; call . setGenericsTypes ( GenericsType . EMPTY_ARRAY ) ; return true ; }
Attempts to call given macroMethod
6,560
public void setProperty ( final Object object , Object newValue ) { AccessPermissionChecker . checkAccessPermission ( field ) ; final Object goalValue = DefaultTypeTransformation . castToType ( newValue , field . getType ( ) ) ; if ( isFinal ( ) ) { throw new GroovyRuntimeException ( "Cannot set the property '" + name + "' because the backing field is final." ) ; } try { field . set ( object , goalValue ) ; } catch ( IllegalAccessException ex ) { throw new GroovyRuntimeException ( "Cannot set the property '" + name + "'." , ex ) ; } }
Sets the property on the given object to the new value
6,561
public static void putAt ( StringBuilder self , IntRange range , Object value ) { RangeInfo info = subListBorders ( self . length ( ) , range ) ; self . replace ( info . from , info . to , value . toString ( ) ) ; }
Support the range subscript operator for StringBuilder . Index values are treated as characters within the builder .
6,562
public Node parse ( File file ) throws IOException , SAXException { InputSource input = new InputSource ( new FileInputStream ( file ) ) ; input . setSystemId ( "file://" + file . getAbsolutePath ( ) ) ; getXMLReader ( ) . parse ( input ) ; return parent ; }
Parses the content of the given file as XML turning it into a tree of Nodes .
6,563
public Node parse ( InputSource input ) throws IOException , SAXException { getXMLReader ( ) . parse ( input ) ; return parent ; }
Parse the content of the specified input source into a tree of Nodes .
6,564
public Node parse ( String uri ) throws IOException , SAXException { InputSource is = new InputSource ( uri ) ; getXMLReader ( ) . parse ( is ) ; return parent ; }
Parse the content of the specified URI into a tree of Nodes .
6,565
protected Object getElementName ( String namespaceURI , String localName , String qName ) { String name = localName ; String prefix = "" ; if ( ( name == null ) || ( name . length ( ) < 1 ) ) { name = qName ; } if ( namespaceURI == null || namespaceURI . length ( ) <= 0 ) { return name ; } if ( qName != null && qName . length ( ) > 0 && namespaceAware ) { int index = qName . lastIndexOf ( ":" ) ; if ( index > 0 ) { prefix = qName . substring ( 0 , index ) ; } } return new QName ( namespaceURI , name , prefix ) ; }
Return a name given the namespaceURI localName and qName .
6,566
public static ClassNode pickGenericType ( ClassNode type , int gtIndex ) { final GenericsType [ ] genericsTypes = type . getGenericsTypes ( ) ; if ( genericsTypes == null || genericsTypes . length < gtIndex ) { return ClassHelper . OBJECT_TYPE ; } return genericsTypes [ gtIndex ] . getType ( ) ; }
A helper method which will extract the n - th generic type from a class node .
6,567
public static ClassNode pickGenericType ( MethodNode node , int parameterIndex , int gtIndex ) { final Parameter [ ] parameters = node . getParameters ( ) ; final ClassNode type = parameters [ parameterIndex ] . getOriginType ( ) ; return pickGenericType ( type , gtIndex ) ; }
A helper method which will extract the n - th generic type from the n - th parameter of a method node .
6,568
protected ClassNode findClassNode ( final SourceUnit sourceUnit , final CompilationUnit compilationUnit , final String className ) { if ( className . endsWith ( "[]" ) ) { return findClassNode ( sourceUnit , compilationUnit , className . substring ( 0 , className . length ( ) - 2 ) ) . makeArray ( ) ; } ClassNode cn = compilationUnit . getClassNode ( className ) ; if ( cn == null ) { try { cn = ClassHelper . make ( Class . forName ( className , false , sourceUnit . getClassLoader ( ) ) ) ; } catch ( ClassNotFoundException e ) { cn = ClassHelper . make ( className ) ; } } return cn ; }
Finds a class node given a string representing the type . Performs a lookup in the compilation unit to check if it is done in the same source unit .
6,569
public static String render ( String text , ValueRecorder recorder ) { return new AssertionRenderer ( text , recorder ) . render ( ) ; }
Creates a string representation of an assertion and its recorded values .
6,570
public static Object setBeanProperties ( MetaClass mc , Object bean , Map properties ) { for ( Iterator iter = properties . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) iter . next ( ) ; String key = entry . getKey ( ) . toString ( ) ; Object value = entry . getValue ( ) ; mc . setProperty ( bean , key , value ) ; } return bean ; }
This method is called by he handle to realize the bean constructor with property map .
6,571
public static boolean isSameMetaClass ( MetaClass mc , Object receiver ) { return receiver instanceof GroovyObject && mc == ( ( GroovyObject ) receiver ) . getMetaClass ( ) ; }
called by handle
6,572
public static boolean sameClass ( Class c , Object o ) { if ( o == null ) return false ; return o . getClass ( ) == c ; }
Guard to check if the provided Object has the same class as the provided Class . This method will return false if the Object is null .
6,573
public static Thread start ( Thread self , Closure closure ) { return createThread ( null , false , closure ) ; }
Start a Thread with the given closure as a Runnable instance .
6,574
public static Thread start ( Thread self , String name , Closure closure ) { return createThread ( name , false , closure ) ; }
Start a Thread with a given name and the given closure as a Runnable instance .
6,575
public static Thread startDaemon ( Thread self , Closure closure ) { return createThread ( null , true , closure ) ; }
Start a daemon Thread with the given closure as a Runnable instance .
6,576
public static Thread startDaemon ( Thread self , String name , Closure closure ) { return createThread ( name , true , closure ) ; }
Start a daemon Thread with a given name and the given closure as a Runnable instance .
6,577
private static void createSuperForwarder ( ClassNode targetNode , MethodNode forwarder , final Map < String , ClassNode > genericsSpec ) { List < ClassNode > interfaces = new ArrayList < ClassNode > ( Traits . collectAllInterfacesReverseOrder ( targetNode , new LinkedHashSet < ClassNode > ( ) ) ) ; String name = forwarder . getName ( ) ; Parameter [ ] forwarderParameters = forwarder . getParameters ( ) ; LinkedHashSet < ClassNode > traits = new LinkedHashSet < ClassNode > ( ) ; List < MethodNode > superForwarders = new LinkedList < MethodNode > ( ) ; for ( ClassNode node : interfaces ) { if ( Traits . isTrait ( node ) ) { MethodNode method = node . getDeclaredMethod ( name , forwarderParameters ) ; if ( method != null ) { traits . add ( node ) ; superForwarders . add ( method ) ; } } } for ( MethodNode superForwarder : superForwarders ) { doCreateSuperForwarder ( targetNode , superForwarder , traits . toArray ( ClassNode . EMPTY_ARRAY ) , genericsSpec ) ; } }
Creates if necessary a super forwarder method for stackable traits .
6,578
public void visitConstantExpression ( ConstantExpression expression ) { final String constantName = expression . getConstantName ( ) ; if ( controller . isStaticConstructor ( ) || constantName == null ) { controller . getOperandStack ( ) . pushConstant ( expression ) ; } else { controller . getMethodVisitor ( ) . visitFieldInsn ( GETSTATIC , controller . getInternalClassName ( ) , constantName , BytecodeHelper . getTypeDescription ( expression . getType ( ) ) ) ; controller . getOperandStack ( ) . push ( expression . getType ( ) ) ; } }
Generate byte code for constants
6,579
public void visitBooleanExpression ( BooleanExpression expression ) { controller . getCompileStack ( ) . pushBooleanExpression ( ) ; int mark = controller . getOperandStack ( ) . getStackLength ( ) ; Expression inner = expression . getExpression ( ) ; inner . visit ( this ) ; controller . getOperandStack ( ) . castToBool ( mark , true ) ; controller . getCompileStack ( ) . pop ( ) ; }
return a primitive boolean value of the BooleanExpression .
6,580
public void visitClassExpression ( ClassExpression expression ) { ClassNode type = expression . getType ( ) ; MethodVisitor mv = controller . getMethodVisitor ( ) ; if ( BytecodeHelper . isClassLiteralPossible ( type ) || BytecodeHelper . isSameCompilationUnit ( controller . getClassNode ( ) , type ) ) { if ( controller . getClassNode ( ) . isInterface ( ) ) { InterfaceHelperClassNode interfaceClassLoadingClass = controller . getInterfaceClassLoadingClass ( ) ; if ( BytecodeHelper . isClassLiteralPossible ( interfaceClassLoadingClass ) ) { BytecodeHelper . visitClassLiteral ( mv , interfaceClassLoadingClass ) ; controller . getOperandStack ( ) . push ( ClassHelper . CLASS_Type ) ; return ; } } else { BytecodeHelper . visitClassLiteral ( mv , type ) ; controller . getOperandStack ( ) . push ( ClassHelper . CLASS_Type ) ; return ; } } String staticFieldName = getStaticFieldName ( type ) ; referencedClasses . put ( staticFieldName , type ) ; String internalClassName = controller . getInternalClassName ( ) ; if ( controller . getClassNode ( ) . isInterface ( ) ) { internalClassName = BytecodeHelper . getClassInternalName ( controller . getInterfaceClassLoadingClass ( ) ) ; mv . visitFieldInsn ( GETSTATIC , internalClassName , staticFieldName , "Ljava/lang/Class;" ) ; } else { mv . visitMethodInsn ( INVOKESTATIC , internalClassName , "$get$" + staticFieldName , "()Ljava/lang/Class;" , false ) ; } controller . getOperandStack ( ) . push ( ClassHelper . CLASS_Type ) ; }
load class object on stack
6,581
private void visitAnnotationAttributes ( AnnotationNode an , AnnotationVisitor av ) { Map < String , Object > constantAttrs = new HashMap < String , Object > ( ) ; Map < String , PropertyExpression > enumAttrs = new HashMap < String , PropertyExpression > ( ) ; Map < String , Object > atAttrs = new HashMap < String , Object > ( ) ; Map < String , ListExpression > arrayAttrs = new HashMap < String , ListExpression > ( ) ; for ( String name : an . getMembers ( ) . keySet ( ) ) { Expression expr = an . getMember ( name ) ; if ( expr instanceof AnnotationConstantExpression ) { atAttrs . put ( name , ( ( AnnotationConstantExpression ) expr ) . getValue ( ) ) ; } else if ( expr instanceof ConstantExpression ) { constantAttrs . put ( name , ( ( ConstantExpression ) expr ) . getValue ( ) ) ; } else if ( expr instanceof ClassExpression ) { constantAttrs . put ( name , Type . getType ( BytecodeHelper . getTypeDescription ( ( expr . getType ( ) ) ) ) ) ; } else if ( expr instanceof PropertyExpression ) { enumAttrs . put ( name , ( PropertyExpression ) expr ) ; } else if ( expr instanceof ListExpression ) { arrayAttrs . put ( name , ( ListExpression ) expr ) ; } else if ( expr instanceof ClosureExpression ) { ClassNode closureClass = controller . getClosureWriter ( ) . getOrAddClosureClass ( ( ClosureExpression ) expr , ACC_PUBLIC ) ; constantAttrs . put ( name , Type . getType ( BytecodeHelper . getTypeDescription ( closureClass ) ) ) ; } } for ( Map . Entry entry : constantAttrs . entrySet ( ) ) { av . visit ( ( String ) entry . getKey ( ) , entry . getValue ( ) ) ; } for ( Map . Entry entry : enumAttrs . entrySet ( ) ) { PropertyExpression propExp = ( PropertyExpression ) entry . getValue ( ) ; av . visitEnum ( ( String ) entry . getKey ( ) , BytecodeHelper . getTypeDescription ( propExp . getObjectExpression ( ) . getType ( ) ) , String . valueOf ( ( ( ConstantExpression ) propExp . getProperty ( ) ) . getValue ( ) ) ) ; } for ( Map . Entry entry : atAttrs . entrySet ( ) ) { AnnotationNode atNode = ( AnnotationNode ) entry . getValue ( ) ; AnnotationVisitor av2 = av . visitAnnotation ( ( String ) entry . getKey ( ) , BytecodeHelper . getTypeDescription ( atNode . getClassNode ( ) ) ) ; visitAnnotationAttributes ( atNode , av2 ) ; av2 . visitEnd ( ) ; } visitArrayAttributes ( an , arrayAttrs , av ) ; }
Generate the annotation attributes .
6,582
private ListExpression determineClasses ( Expression expr , boolean searchSourceUnit ) { ListExpression list = new ListExpression ( ) ; if ( expr instanceof ClassExpression ) { list . addExpression ( expr ) ; } else if ( expr instanceof VariableExpression && searchSourceUnit ) { VariableExpression ve = ( VariableExpression ) expr ; ClassNode fromSourceUnit = getSourceUnitClass ( ve ) ; if ( fromSourceUnit != null ) { ClassExpression found = classX ( fromSourceUnit ) ; found . setSourcePosition ( ve ) ; list . addExpression ( found ) ; } else { addError ( BASE_BAD_PARAM_ERROR + "an unresolvable reference to '" + ve . getName ( ) + "'." , expr ) ; } } else if ( expr instanceof ListExpression ) { list = ( ListExpression ) expr ; final List < Expression > expressions = list . getExpressions ( ) ; for ( int i = 0 ; i < expressions . size ( ) ; i ++ ) { Expression next = expressions . get ( i ) ; if ( next instanceof VariableExpression && searchSourceUnit ) { VariableExpression ve = ( VariableExpression ) next ; ClassNode fromSourceUnit = getSourceUnitClass ( ve ) ; if ( fromSourceUnit != null ) { ClassExpression found = classX ( fromSourceUnit ) ; found . setSourcePosition ( ve ) ; expressions . set ( i , found ) ; } else { addError ( BASE_BAD_PARAM_ERROR + "a list containing an unresolvable reference to '" + ve . getName ( ) + "'." , next ) ; } } else if ( ! ( next instanceof ClassExpression ) ) { addError ( BASE_BAD_PARAM_ERROR + "a list containing type: " + next . getType ( ) . getName ( ) + "." , next ) ; } } checkDuplicateNameClashes ( list ) ; } else if ( expr != null ) { addError ( BASE_BAD_PARAM_ERROR + "a type: " + expr . getType ( ) . getName ( ) + "." , expr ) ; } return list ; }
allow non - strict mode in scripts because parsing not complete at that point
6,583
public static String methodDescriptorWithoutReturnType ( MethodNode mNode ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( mNode . getName ( ) ) . append ( ':' ) ; for ( Parameter p : mNode . getParameters ( ) ) { sb . append ( ClassNodeUtils . formatTypeName ( p . getType ( ) ) ) . append ( ',' ) ; } return sb . toString ( ) ; }
Return the method node s descriptor including its name and parameter types without generics .
6,584
public static String methodDescriptor ( MethodNode mNode ) { StringBuilder sb = new StringBuilder ( mNode . getName ( ) . length ( ) + mNode . getParameters ( ) . length * 10 ) ; sb . append ( mNode . getReturnType ( ) . getName ( ) ) ; sb . append ( ' ' ) ; sb . append ( mNode . getName ( ) ) ; sb . append ( '(' ) ; for ( int i = 0 ; i < mNode . getParameters ( ) . length ; i ++ ) { if ( i > 0 ) { sb . append ( ", " ) ; } Parameter p = mNode . getParameters ( ) [ i ] ; sb . append ( ClassNodeUtils . formatTypeName ( p . getType ( ) ) ) ; } sb . append ( ')' ) ; return sb . toString ( ) ; }
Return the method node s descriptor which includes its return type name and parameter types without generics .
6,585
public static String getPropertyName ( MethodNode mNode ) { String name = mNode . getName ( ) ; if ( name . startsWith ( "set" ) || name . startsWith ( "get" ) || name . startsWith ( "is" ) ) { String pname = decapitalize ( name . substring ( name . startsWith ( "is" ) ? 2 : 3 ) ) ; if ( ! pname . isEmpty ( ) ) { if ( name . startsWith ( "set" ) ) { if ( mNode . getParameters ( ) . length == 1 ) { return pname ; } } else if ( mNode . getParameters ( ) . length == 0 && ! ClassHelper . VOID_TYPE . equals ( mNode . getReturnType ( ) ) ) { if ( name . startsWith ( "get" ) || ClassHelper . boolean_TYPE . equals ( mNode . getReturnType ( ) ) ) { return pname ; } } } } return null ; }
For a method node potentially representing a property returns the name of the property .
6,586
public static boolean isIntCategory ( ClassNode type ) { return type == byte_TYPE || type == char_TYPE || type == int_TYPE || type == short_TYPE ; }
It is of an int category if the provided type is a byte char short int .
6,587
public static ClassNode lowestUpperBound ( List < ClassNode > nodes ) { if ( nodes . size ( ) == 1 ) return nodes . get ( 0 ) ; return lowestUpperBound ( nodes . get ( 0 ) , lowestUpperBound ( nodes . subList ( 1 , nodes . size ( ) ) ) ) ; }
Given a list of class nodes returns the first common supertype . For example Double and Float would return Number while Set and String would return Object .
6,588
public static ClassNode lowestUpperBound ( ClassNode a , ClassNode b ) { ClassNode lub = lowestUpperBound ( a , b , null , null ) ; if ( lub == null || ! lub . isUsingGenerics ( ) ) return lub ; if ( lub instanceof LowestUpperBoundClassNode ) { ClassNode superClass = lub . getSuperClass ( ) ; ClassNode psc = superClass . isUsingGenerics ( ) ? parameterizeLowestUpperBound ( superClass , a , b , lub ) : superClass ; ClassNode [ ] interfaces = lub . getInterfaces ( ) ; ClassNode [ ] pinterfaces = new ClassNode [ interfaces . length ] ; for ( int i = 0 , interfacesLength = interfaces . length ; i < interfacesLength ; i ++ ) { final ClassNode icn = interfaces [ i ] ; if ( icn . isUsingGenerics ( ) ) { pinterfaces [ i ] = parameterizeLowestUpperBound ( icn , a , b , lub ) ; } else { pinterfaces [ i ] = icn ; } } return new LowestUpperBoundClassNode ( ( ( LowestUpperBoundClassNode ) lub ) . name , psc , pinterfaces ) ; } else { return parameterizeLowestUpperBound ( lub , a , b , lub ) ; } }
Given two class nodes returns the first common supertype or the class itself if there are equal . For example Double and Float would return Number while Set and String would return Object .
6,589
private static ClassNode parameterizeLowestUpperBound ( final ClassNode lub , final ClassNode a , final ClassNode b , final ClassNode fallback ) { if ( ! lub . isUsingGenerics ( ) ) return lub ; ClassNode holderForA = findGenericsTypeHolderForClass ( a , lub ) ; ClassNode holderForB = findGenericsTypeHolderForClass ( b , lub ) ; GenericsType [ ] agt = holderForA == null ? null : holderForA . getGenericsTypes ( ) ; GenericsType [ ] bgt = holderForB == null ? null : holderForB . getGenericsTypes ( ) ; if ( agt == null || bgt == null || agt . length != bgt . length ) { return lub ; } GenericsType [ ] lubgt = new GenericsType [ agt . length ] ; for ( int i = 0 ; i < agt . length ; i ++ ) { ClassNode t1 = agt [ i ] . getType ( ) ; ClassNode t2 = bgt [ i ] . getType ( ) ; ClassNode basicType ; if ( areEqualWithGenerics ( t1 , a ) && areEqualWithGenerics ( t2 , b ) ) { basicType = fallback ; } else { basicType = lowestUpperBound ( t1 , t2 ) ; } if ( t1 . equals ( t2 ) ) { lubgt [ i ] = new GenericsType ( basicType ) ; } else { lubgt [ i ] = GenericsUtils . buildWildcardType ( basicType ) ; } } ClassNode plain = lub . getPlainNodeReference ( ) ; plain . setGenericsTypes ( lubgt ) ; return plain ; }
Given a lowest upper bound computed without generic type information but which requires to be parameterized and the two implementing classnodes which are parameterized with potentially two different types returns a parameterized lowest upper bound .
6,590
private static List < ClassNode > keepLowestCommonInterfaces ( List < ClassNode > fromA , List < ClassNode > fromB ) { if ( fromA == null || fromB == null ) return EMPTY_CLASSNODE_LIST ; Set < ClassNode > common = new HashSet < ClassNode > ( fromA ) ; common . retainAll ( fromB ) ; List < ClassNode > result = new ArrayList < ClassNode > ( common . size ( ) ) ; for ( ClassNode classNode : common ) { addMostSpecificInterface ( classNode , result ) ; } return result ; }
Given the list of interfaces implemented by two class nodes returns the list of the most specific common implemented interfaces .
6,591
private static ClassNode buildTypeWithInterfaces ( ClassNode baseType1 , ClassNode baseType2 , Collection < ClassNode > interfaces ) { boolean noInterface = interfaces . isEmpty ( ) ; if ( noInterface ) { if ( baseType1 . equals ( baseType2 ) ) return baseType1 ; if ( baseType1 . isDerivedFrom ( baseType2 ) ) return baseType2 ; if ( baseType2 . isDerivedFrom ( baseType1 ) ) return baseType1 ; } if ( OBJECT_TYPE . equals ( baseType1 ) && OBJECT_TYPE . equals ( baseType2 ) && interfaces . size ( ) == 1 ) { if ( interfaces instanceof List ) { return ( ( List < ClassNode > ) interfaces ) . get ( 0 ) ; } return interfaces . iterator ( ) . next ( ) ; } LowestUpperBoundClassNode type ; ClassNode superClass ; String name ; if ( baseType1 . equals ( baseType2 ) ) { if ( OBJECT_TYPE . equals ( baseType1 ) ) { superClass = baseType1 ; name = "Virtual$Object" ; } else { superClass = baseType1 ; name = "Virtual$" + baseType1 . getName ( ) ; } } else { superClass = OBJECT_TYPE ; if ( baseType1 . isDerivedFrom ( baseType2 ) ) { superClass = baseType2 ; } else if ( baseType2 . isDerivedFrom ( baseType1 ) ) { superClass = baseType1 ; } name = "CommonAssignOf$" + baseType1 . getName ( ) + "$" + baseType2 . getName ( ) ; } Iterator < ClassNode > itcn = interfaces . iterator ( ) ; while ( itcn . hasNext ( ) ) { ClassNode next = itcn . next ( ) ; if ( superClass . isDerivedFrom ( next ) || superClass . implementsInterface ( next ) ) { itcn . remove ( ) ; } } ClassNode [ ] interfaceArray = interfaces . toArray ( ClassNode . EMPTY_ARRAY ) ; Arrays . sort ( interfaceArray , INTERFACE_CLASSNODE_COMPARATOR ) ; type = new LowestUpperBoundClassNode ( name , superClass , interfaceArray ) ; return type ; }
Given two class nodes supposedly at the upper common level returns a class node which is able to represent their lowest upper bound .
6,592
private static boolean areEqualWithGenerics ( ClassNode a , ClassNode b ) { if ( a == null ) return b == null ; if ( ! a . equals ( b ) ) return false ; if ( a . isUsingGenerics ( ) && ! b . isUsingGenerics ( ) ) return false ; GenericsType [ ] gta = a . getGenericsTypes ( ) ; GenericsType [ ] gtb = b . getGenericsTypes ( ) ; if ( gta == null && gtb != null ) return false ; if ( gtb == null && gta != null ) return false ; if ( gta != null && gtb != null ) { if ( gta . length != gtb . length ) return false ; for ( int i = 0 ; i < gta . length ; i ++ ) { GenericsType ga = gta [ i ] ; GenericsType gb = gtb [ i ] ; boolean result = ga . isPlaceholder ( ) == gb . isPlaceholder ( ) && ga . isWildcard ( ) == gb . isWildcard ( ) ; result = result && ga . isResolved ( ) && gb . isResolved ( ) ; result = result && ga . getName ( ) . equals ( gb . getName ( ) ) ; result = result && areEqualWithGenerics ( ga . getType ( ) , gb . getType ( ) ) ; result = result && areEqualWithGenerics ( ga . getLowerBound ( ) , gb . getLowerBound ( ) ) ; if ( result ) { ClassNode [ ] upA = ga . getUpperBounds ( ) ; if ( upA != null ) { ClassNode [ ] upB = gb . getUpperBounds ( ) ; if ( upB == null || upB . length != upA . length ) return false ; for ( int j = 0 ; j < upA . length ; j ++ ) { if ( ! areEqualWithGenerics ( upA [ j ] , upB [ j ] ) ) return false ; } } } if ( ! result ) return false ; } } return true ; }
Compares two class nodes but including their generics types .
6,593
public Object parse ( char [ ] chars ) { if ( chars == null ) { throw new IllegalArgumentException ( "chars must not be null" ) ; } Object content ; content = createParser ( ) . parse ( chars ) ; return content ; }
Parse a JSON data structure from content from a char array .
6,594
public void addPropertyChangeListener ( PropertyChangeListener listener ) { if ( propertyChangeSupport == null ) { propertyChangeSupport = new PropertyChangeSupport ( this ) ; } propertyChangeSupport . addPropertyChangeListener ( listener ) ; }
Add a PropertyChangeListener to the listener list .
6,595
public static Number parseInteger ( AST reportNode , String text ) { text = text . replace ( "_" , "" ) ; char c = ' ' ; int length = text . length ( ) ; boolean negative = false ; if ( ( c = text . charAt ( 0 ) ) == '-' || c == '+' ) { negative = ( c == '-' ) ; text = text . substring ( 1 , length ) ; length -= 1 ; } int radix = 10 ; if ( text . charAt ( 0 ) == '0' && length > 1 ) { c = text . charAt ( 1 ) ; if ( c == 'X' || c == 'x' ) { radix = 16 ; text = text . substring ( 2 , length ) ; length -= 2 ; } else if ( c == 'B' || c == 'b' ) { radix = 2 ; text = text . substring ( 2 , length ) ; length -= 2 ; } else { radix = 8 ; } } char type = 'x' ; if ( isNumericTypeSpecifier ( text . charAt ( length - 1 ) , false ) ) { type = Character . toLowerCase ( text . charAt ( length - 1 ) ) ; text = text . substring ( 0 , length - 1 ) ; length -= 1 ; } if ( negative ) { text = "-" + text ; } BigInteger value = new BigInteger ( text , radix ) ; switch ( type ) { case 'i' : if ( radix == 10 && ( value . compareTo ( MAX_INTEGER ) > 0 || value . compareTo ( MIN_INTEGER ) < 0 ) ) { throw new ASTRuntimeException ( reportNode , "Number of value " + value + " does not fit in the range of int, but int was enforced." ) ; } else { return value . intValue ( ) ; } case 'l' : if ( radix == 10 && ( value . compareTo ( MAX_LONG ) > 0 || value . compareTo ( MIN_LONG ) < 0 ) ) { throw new ASTRuntimeException ( reportNode , "Number of value " + value + " does not fit in the range of long, but long was enforced." ) ; } else { return value . longValue ( ) ; } case 'g' : return value ; default : if ( value . compareTo ( MAX_INTEGER ) <= 0 && value . compareTo ( MIN_INTEGER ) >= 0 ) { return value . intValue ( ) ; } else if ( value . compareTo ( MAX_LONG ) <= 0 && value . compareTo ( MIN_LONG ) >= 0 ) { return value . longValue ( ) ; } return value ; } }
Builds a Number from the given integer descriptor . Creates the narrowest type possible or a specific type if specified .
6,596
public static Number parseDecimal ( String text ) { text = text . replace ( "_" , "" ) ; int length = text . length ( ) ; char type = 'x' ; if ( isNumericTypeSpecifier ( text . charAt ( length - 1 ) , true ) ) { type = Character . toLowerCase ( text . charAt ( length - 1 ) ) ; text = text . substring ( 0 , length - 1 ) ; } BigDecimal value = new BigDecimal ( text ) ; switch ( type ) { case 'f' : if ( value . compareTo ( MAX_FLOAT ) <= 0 && value . compareTo ( MIN_FLOAT ) >= 0 ) { return Float . parseFloat ( text ) ; } throw new NumberFormatException ( "out of range" ) ; case 'd' : if ( value . compareTo ( MAX_DOUBLE ) <= 0 && value . compareTo ( MIN_DOUBLE ) >= 0 ) { return Double . parseDouble ( text ) ; } throw new NumberFormatException ( "out of range" ) ; case 'g' : default : return value ; } }
Builds a Number from the given decimal descriptor . Uses BigDecimal unless Double or Float is requested .
6,597
public void registerBeanProperty ( final String property , final Object newValue ) { performOperationOnMetaClass ( new Callable ( ) { public void call ( ) { Class type = newValue == null ? Object . class : newValue . getClass ( ) ; MetaBeanProperty mbp = newValue instanceof MetaBeanProperty ? ( MetaBeanProperty ) newValue : new ThreadManagedMetaBeanProperty ( theClass , property , type , newValue ) ; final MetaMethod getter = mbp . getGetter ( ) ; final MethodKey getterKey = new DefaultCachedMethodKey ( theClass , getter . getName ( ) , CachedClass . EMPTY_ARRAY , false ) ; final MetaMethod setter = mbp . getSetter ( ) ; final MethodKey setterKey = new DefaultCachedMethodKey ( theClass , setter . getName ( ) , setter . getParameterTypes ( ) , false ) ; addMetaMethod ( getter ) ; addMetaMethod ( setter ) ; expandoMethods . put ( setterKey , setter ) ; expandoMethods . put ( getterKey , getter ) ; expandoProperties . put ( mbp . getName ( ) , mbp ) ; addMetaBeanProperty ( mbp ) ; performRegistryCallbacks ( ) ; } } ) ; }
Registers a new bean property
6,598
public void registerInstanceMethod ( final MetaMethod metaMethod ) { final boolean inited = this . initCalled ; performOperationOnMetaClass ( new Callable ( ) { public void call ( ) { String methodName = metaMethod . getName ( ) ; checkIfGroovyObjectMethod ( metaMethod ) ; MethodKey key = new DefaultCachedMethodKey ( theClass , methodName , metaMethod . getParameterTypes ( ) , false ) ; if ( isInitialized ( ) ) { throw new RuntimeException ( "Already initialized, cannot add new method: " + metaMethod ) ; } addMetaMethodToIndex ( metaMethod , metaMethodIndex . getHeader ( theClass ) ) ; dropMethodCache ( methodName ) ; expandoMethods . put ( key , metaMethod ) ; if ( inited && isGetter ( methodName , metaMethod . getParameterTypes ( ) ) ) { String propertyName = getPropertyForGetter ( methodName ) ; registerBeanPropertyForMethod ( metaMethod , propertyName , true , false ) ; } else if ( inited && isSetter ( methodName , metaMethod . getParameterTypes ( ) ) ) { String propertyName = getPropertyForSetter ( methodName ) ; registerBeanPropertyForMethod ( metaMethod , propertyName , false , false ) ; } performRegistryCallbacks ( ) ; } } ) ; }
Registers a new instance method for the given method name and closure on this MetaClass
6,599
protected void registerStaticMethod ( final String name , final Closure callable , final Class [ ] paramTypes ) { performOperationOnMetaClass ( new Callable ( ) { public void call ( ) { String methodName ; if ( name . equals ( METHOD_MISSING ) ) methodName = STATIC_METHOD_MISSING ; else if ( name . equals ( PROPERTY_MISSING ) ) methodName = STATIC_PROPERTY_MISSING ; else methodName = name ; ClosureStaticMetaMethod metaMethod = null ; if ( paramTypes != null ) { metaMethod = new ClosureStaticMetaMethod ( methodName , theClass , callable , paramTypes ) ; } else { metaMethod = new ClosureStaticMetaMethod ( methodName , theClass , callable ) ; } if ( methodName . equals ( INVOKE_METHOD_METHOD ) && callable . getParameterTypes ( ) . length == 2 ) { invokeStaticMethodMethod = metaMethod ; } else { if ( methodName . equals ( METHOD_MISSING ) ) { methodName = STATIC_METHOD_MISSING ; } MethodKey key = new DefaultCachedMethodKey ( theClass , methodName , metaMethod . getParameterTypes ( ) , false ) ; addMetaMethod ( metaMethod ) ; dropStaticMethodCache ( methodName ) ; if ( isGetter ( methodName , metaMethod . getParameterTypes ( ) ) ) { String propertyName = getPropertyForGetter ( methodName ) ; registerBeanPropertyForMethod ( metaMethod , propertyName , true , true ) ; } else if ( isSetter ( methodName , metaMethod . getParameterTypes ( ) ) ) { String propertyName = getPropertyForSetter ( methodName ) ; registerBeanPropertyForMethod ( metaMethod , propertyName , false , true ) ; } performRegistryCallbacks ( ) ; expandoMethods . put ( key , metaMethod ) ; } } } ) ; }
Registers a new static method for the given method name and closure on this MetaClass