id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
13,100
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
XmlUtil.newSAXParser
public static SAXParser newSAXParser(String schemaLanguage, File schema) throws SAXException, ParserConfigurationException { return newSAXParser(schemaLanguage, true, false, schema); }
java
public static SAXParser newSAXParser(String schemaLanguage, File schema) throws SAXException, ParserConfigurationException { return newSAXParser(schemaLanguage, true, false, schema); }
[ "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. @param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants) @param schema a file containing the schema to validate against @return the created SAXParser @throws SAXException @throws ParserConfigurationException @see #newSAXParser(String, boolean, boolean, File) @since 1.8.7
[ "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", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L274-L276
13,101
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
XmlUtil.newSAXParser
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)); }
java
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)); }
[ "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. @param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants) @param namespaceAware will the parser be namespace aware @param validating will the parser also validate against DTDs @param schema a file containing the schema to validate against @return the created SAXParser @throws SAXException @throws ParserConfigurationException @since 1.8.7
[ "Factory", "method", "to", "create", "a", "SAXParser", "configured", "to", "validate", "according", "to", "a", "particular", "schema", "language", "and", "a", "File", "containing", "the", "schema", "to", "validate", "against", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L291-L294
13,102
apache/groovy
src/main/groovy/groovy/lang/GroovyShell.java
GroovyShell.run
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); } } // Get the current context classloader and save it on the stack final Thread thread = Thread.currentThread(); //ClassLoader currentClassLoader = thread.getContextClassLoader(); 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)); // Parse the script, generate the class, and invoke the main method. This is a little looser than // if you are compiling the script because the JVM isn't executing the main method. 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); // Set the context classloader back to what it was. //AccessController.doPrivileged(new DoSetContext(currentClassLoader)); }
java
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); } } // Get the current context classloader and save it on the stack final Thread thread = Thread.currentThread(); //ClassLoader currentClassLoader = thread.getContextClassLoader(); 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)); // Parse the script, generate the class, and invoke the main method. This is a little looser than // if you are compiling the script because the JVM isn't executing the main method. 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); // Set the context classloader back to what it was. //AccessController.doPrivileged(new DoSetContext(currentClassLoader)); }
[ "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", ")", ";", "}", "}", "// Get the current context classloader and save it on the stack", "final", "Thread", "thread", "=", "Thread", ".", "currentThread", "(", ")", ";", "//ClassLoader currentClassLoader = thread.getContextClassLoader();", "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", ")", ")", ";", "// Parse the script, generate the class, and invoke the main method. This is a little looser than", "// if you are compiling the script because the JVM isn't executing the main method.", "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", ")", ";", "// Set the context classloader back to what it was.", "//AccessController.doPrivileged(new DoSetContext(currentClassLoader));", "}" ]
Runs the given script file name with the given command line arguments @param scriptFile the file name of the script to run @param args the command line arguments to pass in
[ "Runs", "the", "given", "script", "file", "name", "with", "the", "given", "command", "line", "arguments" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/GroovyShell.java#L177-L229
13,103
apache/groovy
src/main/groovy/groovy/lang/GroovyShell.java
GroovyShell.run
public Object run(final String scriptText, final String fileName, String[] args) throws CompilationFailedException { GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() { public GroovyCodeSource run() { return new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE); } }); return run(gcs, args); }
java
public Object run(final String scriptText, final String fileName, String[] args) throws CompilationFailedException { GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() { public GroovyCodeSource run() { return new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE); } }); return run(gcs, args); }
[ "public", "Object", "run", "(", "final", "String", "scriptText", ",", "final", "String", "fileName", ",", "String", "[", "]", "args", ")", "throws", "CompilationFailedException", "{", "GroovyCodeSource", "gcs", "=", "AccessController", ".", "doPrivileged", "(", "new", "PrivilegedAction", "<", "GroovyCodeSource", ">", "(", ")", "{", "public", "GroovyCodeSource", "run", "(", ")", "{", "return", "new", "GroovyCodeSource", "(", "scriptText", ",", "fileName", ",", "DEFAULT_CODE_BASE", ")", ";", "}", "}", ")", ";", "return", "run", "(", "gcs", ",", "args", ")", ";", "}" ]
Runs the given script text with command line arguments @param scriptText is the text content of the script @param fileName is the logical file name of the script (which is used to create the class name of the script) @param args the command line arguments to pass in
[ "Runs", "the", "given", "script", "text", "with", "command", "line", "arguments" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/GroovyShell.java#L343-L350
13,104
apache/groovy
src/main/groovy/groovy/lang/GroovyShell.java
GroovyShell.evaluate
public Object evaluate(final String scriptText, final String fileName, final String codeBase) throws CompilationFailedException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new GroovyCodeSourcePermission(codeBase)); } GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() { public GroovyCodeSource run() { return new GroovyCodeSource(scriptText, fileName, codeBase); } }); return evaluate(gcs); }
java
public Object evaluate(final String scriptText, final String fileName, final String codeBase) throws CompilationFailedException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new GroovyCodeSourcePermission(codeBase)); } GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() { public GroovyCodeSource run() { return new GroovyCodeSource(scriptText, fileName, codeBase); } }); return evaluate(gcs); }
[ "public", "Object", "evaluate", "(", "final", "String", "scriptText", ",", "final", "String", "fileName", ",", "final", "String", "codeBase", ")", "throws", "CompilationFailedException", "{", "SecurityManager", "sm", "=", "System", ".", "getSecurityManager", "(", ")", ";", "if", "(", "sm", "!=", "null", ")", "{", "sm", ".", "checkPermission", "(", "new", "GroovyCodeSourcePermission", "(", "codeBase", ")", ")", ";", "}", "GroovyCodeSource", "gcs", "=", "AccessController", ".", "doPrivileged", "(", "new", "PrivilegedAction", "<", "GroovyCodeSource", ">", "(", ")", "{", "public", "GroovyCodeSource", "run", "(", ")", "{", "return", "new", "GroovyCodeSource", "(", "scriptText", ",", "fileName", ",", "codeBase", ")", ";", "}", "}", ")", ";", "return", "evaluate", "(", "gcs", ")", ";", "}" ]
Evaluates some script against the current Binding and returns the result. The .class file created from the script is given the supplied codeBase
[ "Evaluates", "some", "script", "against", "the", "current", "Binding", "and", "returns", "the", "result", ".", "The", ".", "class", "file", "created", "from", "the", "script", "is", "given", "the", "supplied", "codeBase" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/GroovyShell.java#L467-L480
13,105
apache/groovy
src/main/java/org/apache/groovy/util/SystemUtil.java
SystemUtil.getIntegerSafe
public static Integer getIntegerSafe(String name, Integer def) { try { return Integer.getInteger(name, def); } catch (SecurityException ignore) { // suppress exception } return def; }
java
public static Integer getIntegerSafe(String name, Integer def) { try { return Integer.getInteger(name, def); } catch (SecurityException ignore) { // suppress exception } return def; }
[ "public", "static", "Integer", "getIntegerSafe", "(", "String", "name", ",", "Integer", "def", ")", "{", "try", "{", "return", "Integer", ".", "getInteger", "(", "name", ",", "def", ")", ";", "}", "catch", "(", "SecurityException", "ignore", ")", "{", "// suppress exception", "}", "return", "def", ";", "}" ]
Retrieves an Integer System property @param name the name of the system property. @param def the default value @return value of the Integer system property or false
[ "Retrieves", "an", "Integer", "System", "property" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/util/SystemUtil.java#L130-L138
13,106
apache/groovy
src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
SortableASTTransformation.compareExpr
private static BinaryExpression compareExpr(Expression lhv, Expression rhv, boolean reversed) { return (reversed) ? cmpX(rhv, lhv) : cmpX(lhv, rhv); }
java
private static BinaryExpression compareExpr(Expression lhv, Expression rhv, boolean reversed) { return (reversed) ? cmpX(rhv, lhv) : cmpX(lhv, rhv); }
[ "private", "static", "BinaryExpression", "compareExpr", "(", "Expression", "lhv", ",", "Expression", "rhv", ",", "boolean", "reversed", ")", "{", "return", "(", "reversed", ")", "?", "cmpX", "(", "rhv", ",", "lhv", ")", ":", "cmpX", "(", "lhv", ",", "rhv", ")", ";", "}" ]
Helper method used to build a binary expression that compares two values with the option to handle reverse order.
[ "Helper", "method", "used", "to", "build", "a", "binary", "expression", "that", "compares", "two", "values", "with", "the", "option", "to", "handle", "reverse", "order", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java#L261-L263
13,107
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.dup
public Token dup() { Token token = new Token(this.type, this.text, this.startLine, this.startColumn); token.setMeaning(this.meaning); return token; }
java
public Token dup() { Token token = new Token(this.type, this.text, this.startLine, this.startColumn); token.setMeaning(this.meaning); return token; }
[ "public", "Token", "dup", "(", ")", "{", "Token", "token", "=", "new", "Token", "(", "this", ".", "type", ",", "this", ".", "text", ",", "this", ".", "startLine", ",", "this", ".", "startColumn", ")", ";", "token", ".", "setMeaning", "(", "this", ".", "meaning", ")", ";", "return", "token", ";", "}" ]
Returns a copy of this Token.
[ "Returns", "a", "copy", "of", "this", "Token", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L65-L70
13,108
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newKeyword
public static Token newKeyword(String text, int startLine, int startColumn) { int type = Types.lookupKeyword(text); if (type != Types.UNKNOWN) { return new Token(type, text, startLine, startColumn); } return null; }
java
public static Token newKeyword(String text, int startLine, int startColumn) { int type = Types.lookupKeyword(text); if (type != Types.UNKNOWN) { return new Token(type, text, startLine, startColumn); } return null; }
[ "public", "static", "Token", "newKeyword", "(", "String", "text", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "int", "type", "=", "Types", ".", "lookupKeyword", "(", "text", ")", ";", "if", "(", "type", "!=", "Types", ".", "UNKNOWN", ")", "{", "return", "new", "Token", "(", "type", ",", "text", ",", "startLine", ",", "startColumn", ")", ";", "}", "return", "null", ";", "}" ]
Creates a token that represents a keyword. Returns null if the specified text isn't a keyword.
[ "Creates", "a", "token", "that", "represents", "a", "keyword", ".", "Returns", "null", "if", "the", "specified", "text", "isn", "t", "a", "keyword", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L220-L228
13,109
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newString
public static Token newString(String text, int startLine, int startColumn) { return new Token(Types.STRING, text, startLine, startColumn); }
java
public static Token newString(String text, int startLine, int startColumn) { return new Token(Types.STRING, text, startLine, startColumn); }
[ "public", "static", "Token", "newString", "(", "String", "text", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "Types", ".", "STRING", ",", "text", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents a double-quoted string.
[ "Creates", "a", "token", "that", "represents", "a", "double", "-", "quoted", "string", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L233-L235
13,110
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newIdentifier
public static Token newIdentifier(String text, int startLine, int startColumn) { return new Token(Types.IDENTIFIER, text, startLine, startColumn); }
java
public static Token newIdentifier(String text, int startLine, int startColumn) { return new Token(Types.IDENTIFIER, text, startLine, startColumn); }
[ "public", "static", "Token", "newIdentifier", "(", "String", "text", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "Types", ".", "IDENTIFIER", ",", "text", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents an identifier.
[ "Creates", "a", "token", "that", "represents", "an", "identifier", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L240-L242
13,111
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newInteger
public static Token newInteger(String text, int startLine, int startColumn) { return new Token(Types.INTEGER_NUMBER, text, startLine, startColumn); }
java
public static Token newInteger(String text, int startLine, int startColumn) { return new Token(Types.INTEGER_NUMBER, text, startLine, startColumn); }
[ "public", "static", "Token", "newInteger", "(", "String", "text", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "Types", ".", "INTEGER_NUMBER", ",", "text", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents an integer.
[ "Creates", "a", "token", "that", "represents", "an", "integer", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L247-L249
13,112
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newDecimal
public static Token newDecimal(String text, int startLine, int startColumn) { return new Token(Types.DECIMAL_NUMBER, text, startLine, startColumn); }
java
public static Token newDecimal(String text, int startLine, int startColumn) { return new Token(Types.DECIMAL_NUMBER, text, startLine, startColumn); }
[ "public", "static", "Token", "newDecimal", "(", "String", "text", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "Types", ".", "DECIMAL_NUMBER", ",", "text", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents a decimal number.
[ "Creates", "a", "token", "that", "represents", "a", "decimal", "number", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L254-L256
13,113
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newSymbol
public static Token newSymbol(int type, int startLine, int startColumn) { return new Token(type, Types.getText(type), startLine, startColumn); }
java
public static Token newSymbol(int type, int startLine, int startColumn) { return new Token(type, Types.getText(type), startLine, startColumn); }
[ "public", "static", "Token", "newSymbol", "(", "int", "type", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "type", ",", "Types", ".", "getText", "(", "type", ")", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents a symbol, using a library for the text.
[ "Creates", "a", "token", "that", "represents", "a", "symbol", "using", "a", "library", "for", "the", "text", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L261-L263
13,114
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newSymbol
public static Token newSymbol(String type, int startLine, int startColumn) { return new Token(Types.lookupSymbol(type), type, startLine, startColumn); }
java
public static Token newSymbol(String type, int startLine, int startColumn) { return new Token(Types.lookupSymbol(type), type, startLine, startColumn); }
[ "public", "static", "Token", "newSymbol", "(", "String", "type", ",", "int", "startLine", ",", "int", "startColumn", ")", "{", "return", "new", "Token", "(", "Types", ".", "lookupSymbol", "(", "type", ")", ",", "type", ",", "startLine", ",", "startColumn", ")", ";", "}" ]
Creates a token that represents a symbol, using a library for the type.
[ "Creates", "a", "token", "that", "represents", "a", "symbol", "using", "a", "library", "for", "the", "type", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L268-L270
13,115
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Token.java
Token.newPlaceholder
public static Token newPlaceholder(int type) { Token token = new Token(Types.UNKNOWN, "", -1, -1); token.setMeaning(type); return token; }
java
public static Token newPlaceholder(int type) { Token token = new Token(Types.UNKNOWN, "", -1, -1); token.setMeaning(type); return token; }
[ "public", "static", "Token", "newPlaceholder", "(", "int", "type", ")", "{", "Token", "token", "=", "new", "Token", "(", "Types", ".", "UNKNOWN", ",", "\"\"", ",", "-", "1", ",", "-", "1", ")", ";", "token", ".", "setMeaning", "(", "type", ")", ";", "return", "token", ";", "}" ]
Creates a token with the specified meaning.
[ "Creates", "a", "token", "with", "the", "specified", "meaning", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Token.java#L275-L280
13,116
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/AbstractTypeCheckingExtension.java
AbstractTypeCheckingExtension.makeDynamic
public MethodNode makeDynamic(MethodCall call, ClassNode returnType) { TypeCheckingContext.EnclosingClosure enclosingClosure = context.getEnclosingClosure(); MethodNode enclosingMethod = context.getEnclosingMethod(); ((ASTNode)call).putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); if (enclosingClosure!=null) { enclosingClosure.getClosureExpression().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } else { enclosingMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } setHandled(true); if (debug) { LOG.info("Turning "+call.getText()+" into a dynamic method call returning "+returnType.toString(false)); } return new MethodNode(call.getMethodAsString(), 0, returnType, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE); }
java
public MethodNode makeDynamic(MethodCall call, ClassNode returnType) { TypeCheckingContext.EnclosingClosure enclosingClosure = context.getEnclosingClosure(); MethodNode enclosingMethod = context.getEnclosingMethod(); ((ASTNode)call).putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); if (enclosingClosure!=null) { enclosingClosure.getClosureExpression().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } else { enclosingMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } setHandled(true); if (debug) { LOG.info("Turning "+call.getText()+" into a dynamic method call returning "+returnType.toString(false)); } return new MethodNode(call.getMethodAsString(), 0, returnType, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE); }
[ "public", "MethodNode", "makeDynamic", "(", "MethodCall", "call", ",", "ClassNode", "returnType", ")", "{", "TypeCheckingContext", ".", "EnclosingClosure", "enclosingClosure", "=", "context", ".", "getEnclosingClosure", "(", ")", ";", "MethodNode", "enclosingMethod", "=", "context", ".", "getEnclosingMethod", "(", ")", ";", "(", "(", "ASTNode", ")", "call", ")", ".", "putNodeMetaData", "(", "StaticTypesMarker", ".", "DYNAMIC_RESOLUTION", ",", "returnType", ")", ";", "if", "(", "enclosingClosure", "!=", "null", ")", "{", "enclosingClosure", ".", "getClosureExpression", "(", ")", ".", "putNodeMetaData", "(", "StaticTypesMarker", ".", "DYNAMIC_RESOLUTION", ",", "Boolean", ".", "TRUE", ")", ";", "}", "else", "{", "enclosingMethod", ".", "putNodeMetaData", "(", "StaticTypesMarker", ".", "DYNAMIC_RESOLUTION", ",", "Boolean", ".", "TRUE", ")", ";", "}", "setHandled", "(", "true", ")", ";", "if", "(", "debug", ")", "{", "LOG", ".", "info", "(", "\"Turning \"", "+", "call", ".", "getText", "(", ")", "+", "\" into a dynamic method call returning \"", "+", "returnType", ".", "toString", "(", "false", ")", ")", ";", "}", "return", "new", "MethodNode", "(", "call", ".", "getMethodAsString", "(", ")", ",", "0", ",", "returnType", ",", "Parameter", ".", "EMPTY_ARRAY", ",", "ClassNode", ".", "EMPTY_ARRAY", ",", "EmptyStatement", ".", "INSTANCE", ")", ";", "}" ]
Used to instruct the type checker that the call is a dynamic method call. Calling this method automatically sets the handled flag to true. @param call the method call which is a dynamic method call @param returnType the expected return type of the dynamic call @return a virtual method node with the same name as the expected call
[ "Used", "to", "instruct", "the", "type", "checker", "that", "the", "call", "is", "a", "dynamic", "method", "call", ".", "Calling", "this", "method", "automatically", "sets", "the", "handled", "flag", "to", "true", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/AbstractTypeCheckingExtension.java#L275-L289
13,117
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/AbstractTypeCheckingExtension.java
AbstractTypeCheckingExtension.makeDynamic
public void makeDynamic(PropertyExpression pexp, ClassNode returnType) { context.getEnclosingMethod().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); pexp.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); storeType(pexp, returnType); setHandled(true); if (debug) { LOG.info("Turning '"+pexp.getText()+"' into a dynamic property access of type "+returnType.toString(false)); } }
java
public void makeDynamic(PropertyExpression pexp, ClassNode returnType) { context.getEnclosingMethod().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); pexp.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); storeType(pexp, returnType); setHandled(true); if (debug) { LOG.info("Turning '"+pexp.getText()+"' into a dynamic property access of type "+returnType.toString(false)); } }
[ "public", "void", "makeDynamic", "(", "PropertyExpression", "pexp", ",", "ClassNode", "returnType", ")", "{", "context", ".", "getEnclosingMethod", "(", ")", ".", "putNodeMetaData", "(", "StaticTypesMarker", ".", "DYNAMIC_RESOLUTION", ",", "Boolean", ".", "TRUE", ")", ";", "pexp", ".", "putNodeMetaData", "(", "StaticTypesMarker", ".", "DYNAMIC_RESOLUTION", ",", "returnType", ")", ";", "storeType", "(", "pexp", ",", "returnType", ")", ";", "setHandled", "(", "true", ")", ";", "if", "(", "debug", ")", "{", "LOG", ".", "info", "(", "\"Turning '\"", "+", "pexp", ".", "getText", "(", ")", "+", "\"' into a dynamic property access of type \"", "+", "returnType", ".", "toString", "(", "false", ")", ")", ";", "}", "}" ]
Instructs the type checker that a property access is dynamic. Calling this method automatically sets the handled flag to true. @param pexp the property or attribute expression @param returnType the type of the property
[ "Instructs", "the", "type", "checker", "that", "a", "property", "access", "is", "dynamic", ".", "Calling", "this", "method", "automatically", "sets", "the", "handled", "flag", "to", "true", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/AbstractTypeCheckingExtension.java#L306-L314
13,118
apache/groovy
src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
ClassNodeResolver.getFromClassCache
public ClassNode getFromClassCache(String name) { // We use here the class cache cachedClasses to prevent // calls to ClassLoader#loadClass. Disabling this cache will // cause a major performance hit. ClassNode cached = cachedClasses.get(name); return cached; }
java
public ClassNode getFromClassCache(String name) { // We use here the class cache cachedClasses to prevent // calls to ClassLoader#loadClass. Disabling this cache will // cause a major performance hit. ClassNode cached = cachedClasses.get(name); return cached; }
[ "public", "ClassNode", "getFromClassCache", "(", "String", "name", ")", "{", "// We use here the class cache cachedClasses to prevent", "// calls to ClassLoader#loadClass. Disabling this cache will", "// cause a major performance hit.", "ClassNode", "cached", "=", "cachedClasses", ".", "get", "(", "name", ")", ";", "return", "cached", ";", "}" ]
returns whatever is stored in the class cache for the given name @param name - the name of the class @return the result of the lookup, which may be null
[ "returns", "whatever", "is", "stored", "in", "the", "class", "cache", "for", "the", "given", "name" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java#L149-L155
13,119
apache/groovy
src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
ClassNodeResolver.findByClassLoading
private static LookupResult findByClassLoading(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) { Class cls; try { // NOTE: it's important to do no lookup against script files // here since the GroovyClassLoader would create a new CompilationUnit cls = loader.loadClass(name, false, true); } catch (ClassNotFoundException cnfe) { LookupResult lr = tryAsScript(name, compilationUnit, null); return lr; } catch (CompilationFailedException cfe) { throw new GroovyBugError("The lookup for " + name + " caused a failed compilation. There should not have been any compilation from this call.", cfe); } //TODO: the case of a NoClassDefFoundError needs a bit more research // a simple recompilation is not possible it seems. The current class // we are searching for is there, so we should mark that somehow. // Basically the missing class needs to be completely compiled before // we can again search for the current name. /*catch (NoClassDefFoundError ncdfe) { cachedClasses.put(name,SCRIPT); return false; }*/ if (cls == null) return null; //NOTE: we might return false here even if we found a class, // because we want to give a possible script a chance to // recompile. This can only be done if the loader was not // the instance defining the class. ClassNode cn = ClassHelper.make(cls); if (cls.getClassLoader() != loader) { return tryAsScript(name, compilationUnit, cn); } return new LookupResult(null,cn); }
java
private static LookupResult findByClassLoading(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) { Class cls; try { // NOTE: it's important to do no lookup against script files // here since the GroovyClassLoader would create a new CompilationUnit cls = loader.loadClass(name, false, true); } catch (ClassNotFoundException cnfe) { LookupResult lr = tryAsScript(name, compilationUnit, null); return lr; } catch (CompilationFailedException cfe) { throw new GroovyBugError("The lookup for " + name + " caused a failed compilation. There should not have been any compilation from this call.", cfe); } //TODO: the case of a NoClassDefFoundError needs a bit more research // a simple recompilation is not possible it seems. The current class // we are searching for is there, so we should mark that somehow. // Basically the missing class needs to be completely compiled before // we can again search for the current name. /*catch (NoClassDefFoundError ncdfe) { cachedClasses.put(name,SCRIPT); return false; }*/ if (cls == null) return null; //NOTE: we might return false here even if we found a class, // because we want to give a possible script a chance to // recompile. This can only be done if the loader was not // the instance defining the class. ClassNode cn = ClassHelper.make(cls); if (cls.getClassLoader() != loader) { return tryAsScript(name, compilationUnit, cn); } return new LookupResult(null,cn); }
[ "private", "static", "LookupResult", "findByClassLoading", "(", "String", "name", ",", "CompilationUnit", "compilationUnit", ",", "GroovyClassLoader", "loader", ")", "{", "Class", "cls", ";", "try", "{", "// NOTE: it's important to do no lookup against script files", "// here since the GroovyClassLoader would create a new CompilationUnit", "cls", "=", "loader", ".", "loadClass", "(", "name", ",", "false", ",", "true", ")", ";", "}", "catch", "(", "ClassNotFoundException", "cnfe", ")", "{", "LookupResult", "lr", "=", "tryAsScript", "(", "name", ",", "compilationUnit", ",", "null", ")", ";", "return", "lr", ";", "}", "catch", "(", "CompilationFailedException", "cfe", ")", "{", "throw", "new", "GroovyBugError", "(", "\"The lookup for \"", "+", "name", "+", "\" caused a failed compilation. There should not have been any compilation from this call.\"", ",", "cfe", ")", ";", "}", "//TODO: the case of a NoClassDefFoundError needs a bit more research", "// a simple recompilation is not possible it seems. The current class", "// we are searching for is there, so we should mark that somehow.", "// Basically the missing class needs to be completely compiled before", "// we can again search for the current name.", "/*catch (NoClassDefFoundError ncdfe) {\n cachedClasses.put(name,SCRIPT);\n return false;\n }*/", "if", "(", "cls", "==", "null", ")", "return", "null", ";", "//NOTE: we might return false here even if we found a class,", "// because we want to give a possible script a chance to", "// recompile. This can only be done if the loader was not", "// the instance defining the class.", "ClassNode", "cn", "=", "ClassHelper", ".", "make", "(", "cls", ")", ";", "if", "(", "cls", ".", "getClassLoader", "(", ")", "!=", "loader", ")", "{", "return", "tryAsScript", "(", "name", ",", "compilationUnit", ",", "cn", ")", ";", "}", "return", "new", "LookupResult", "(", "null", ",", "cn", ")", ";", "}" ]
Search for classes using class loading
[ "Search", "for", "classes", "using", "class", "loading" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java#L204-L235
13,120
apache/groovy
src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
ClassNodeResolver.findDecompiled
private LookupResult findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) { ClassNode node = ClassHelper.make(name); if (node.isResolved()) { return new LookupResult(null, node); } DecompiledClassNode asmClass = null; String fileName = name.replace('.', '/') + ".class"; URL resource = loader.getResource(fileName); if (resource != null) { try { asmClass = new DecompiledClassNode(AsmDecompiler.parseClass(resource), new AsmReferenceResolver(this, compilationUnit)); if (!asmClass.getName().equals(name)) { // this may happen under Windows because getResource is case insensitive under that OS! asmClass = null; } } catch (IOException e) { // fall through and attempt other search strategies } } if (asmClass != null) { if (isFromAnotherClassLoader(loader, fileName)) { return tryAsScript(name, compilationUnit, asmClass); } return new LookupResult(null, asmClass); } return null; }
java
private LookupResult findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) { ClassNode node = ClassHelper.make(name); if (node.isResolved()) { return new LookupResult(null, node); } DecompiledClassNode asmClass = null; String fileName = name.replace('.', '/') + ".class"; URL resource = loader.getResource(fileName); if (resource != null) { try { asmClass = new DecompiledClassNode(AsmDecompiler.parseClass(resource), new AsmReferenceResolver(this, compilationUnit)); if (!asmClass.getName().equals(name)) { // this may happen under Windows because getResource is case insensitive under that OS! asmClass = null; } } catch (IOException e) { // fall through and attempt other search strategies } } if (asmClass != null) { if (isFromAnotherClassLoader(loader, fileName)) { return tryAsScript(name, compilationUnit, asmClass); } return new LookupResult(null, asmClass); } return null; }
[ "private", "LookupResult", "findDecompiled", "(", "String", "name", ",", "CompilationUnit", "compilationUnit", ",", "GroovyClassLoader", "loader", ")", "{", "ClassNode", "node", "=", "ClassHelper", ".", "make", "(", "name", ")", ";", "if", "(", "node", ".", "isResolved", "(", ")", ")", "{", "return", "new", "LookupResult", "(", "null", ",", "node", ")", ";", "}", "DecompiledClassNode", "asmClass", "=", "null", ";", "String", "fileName", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", "+", "\".class\"", ";", "URL", "resource", "=", "loader", ".", "getResource", "(", "fileName", ")", ";", "if", "(", "resource", "!=", "null", ")", "{", "try", "{", "asmClass", "=", "new", "DecompiledClassNode", "(", "AsmDecompiler", ".", "parseClass", "(", "resource", ")", ",", "new", "AsmReferenceResolver", "(", "this", ",", "compilationUnit", ")", ")", ";", "if", "(", "!", "asmClass", ".", "getName", "(", ")", ".", "equals", "(", "name", ")", ")", "{", "// this may happen under Windows because getResource is case insensitive under that OS!", "asmClass", "=", "null", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "// fall through and attempt other search strategies", "}", "}", "if", "(", "asmClass", "!=", "null", ")", "{", "if", "(", "isFromAnotherClassLoader", "(", "loader", ",", "fileName", ")", ")", "{", "return", "tryAsScript", "(", "name", ",", "compilationUnit", ",", "asmClass", ")", ";", "}", "return", "new", "LookupResult", "(", "null", ",", "asmClass", ")", ";", "}", "return", "null", ";", "}" ]
Search for classes using ASM decompiler
[ "Search", "for", "classes", "using", "ASM", "decompiler" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java#L240-L269
13,121
apache/groovy
src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
ClassNodeResolver.tryAsScript
private static LookupResult tryAsScript(String name, CompilationUnit compilationUnit, ClassNode oldClass) { LookupResult lr = null; if (oldClass!=null) { lr = new LookupResult(null, oldClass); } if (name.startsWith("java.")) return lr; //TODO: don't ignore inner static classes completely if (name.indexOf('$') != -1) return lr; // try to find a script from classpath*/ GroovyClassLoader gcl = compilationUnit.getClassLoader(); URL url = null; try { url = gcl.getResourceLoader().loadGroovySource(name); } catch (MalformedURLException e) { // fall through and let the URL be null } if (url != null && ( oldClass==null || isSourceNewer(url, oldClass))) { SourceUnit su = compilationUnit.addSource(url); return new LookupResult(su,null); } return lr; }
java
private static LookupResult tryAsScript(String name, CompilationUnit compilationUnit, ClassNode oldClass) { LookupResult lr = null; if (oldClass!=null) { lr = new LookupResult(null, oldClass); } if (name.startsWith("java.")) return lr; //TODO: don't ignore inner static classes completely if (name.indexOf('$') != -1) return lr; // try to find a script from classpath*/ GroovyClassLoader gcl = compilationUnit.getClassLoader(); URL url = null; try { url = gcl.getResourceLoader().loadGroovySource(name); } catch (MalformedURLException e) { // fall through and let the URL be null } if (url != null && ( oldClass==null || isSourceNewer(url, oldClass))) { SourceUnit su = compilationUnit.addSource(url); return new LookupResult(su,null); } return lr; }
[ "private", "static", "LookupResult", "tryAsScript", "(", "String", "name", ",", "CompilationUnit", "compilationUnit", ",", "ClassNode", "oldClass", ")", "{", "LookupResult", "lr", "=", "null", ";", "if", "(", "oldClass", "!=", "null", ")", "{", "lr", "=", "new", "LookupResult", "(", "null", ",", "oldClass", ")", ";", "}", "if", "(", "name", ".", "startsWith", "(", "\"java.\"", ")", ")", "return", "lr", ";", "//TODO: don't ignore inner static classes completely", "if", "(", "name", ".", "indexOf", "(", "'", "'", ")", "!=", "-", "1", ")", "return", "lr", ";", "// try to find a script from classpath*/", "GroovyClassLoader", "gcl", "=", "compilationUnit", ".", "getClassLoader", "(", ")", ";", "URL", "url", "=", "null", ";", "try", "{", "url", "=", "gcl", ".", "getResourceLoader", "(", ")", ".", "loadGroovySource", "(", "name", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "// fall through and let the URL be null", "}", "if", "(", "url", "!=", "null", "&&", "(", "oldClass", "==", "null", "||", "isSourceNewer", "(", "url", ",", "oldClass", ")", ")", ")", "{", "SourceUnit", "su", "=", "compilationUnit", ".", "addSource", "(", "url", ")", ";", "return", "new", "LookupResult", "(", "su", ",", "null", ")", ";", "}", "return", "lr", ";", "}" ]
try to find a script using the compilation unit class loader.
[ "try", "to", "find", "a", "script", "using", "the", "compilation", "unit", "class", "loader", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java#L279-L302
13,122
apache/groovy
src/main/groovy/groovy/util/DelegatingScript.java
DelegatingScript.setDelegate
public void setDelegate(Object delegate) { this.delegate = delegate; this.metaClass = InvokerHelper.getMetaClass(delegate.getClass()); }
java
public void setDelegate(Object delegate) { this.delegate = delegate; this.metaClass = InvokerHelper.getMetaClass(delegate.getClass()); }
[ "public", "void", "setDelegate", "(", "Object", "delegate", ")", "{", "this", ".", "delegate", "=", "delegate", ";", "this", ".", "metaClass", "=", "InvokerHelper", ".", "getMetaClass", "(", "delegate", ".", "getClass", "(", ")", ")", ";", "}" ]
Sets the delegation target.
[ "Sets", "the", "delegation", "target", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/util/DelegatingScript.java#L101-L104
13,123
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
DefaultJsonGenerator.writeRaw
protected void writeRaw(CharSequence seq, CharBuf buffer) { if (seq != null) { buffer.add(seq.toString()); } }
java
protected void writeRaw(CharSequence seq, CharBuf buffer) { if (seq != null) { buffer.add(seq.toString()); } }
[ "protected", "void", "writeRaw", "(", "CharSequence", "seq", ",", "CharBuf", "buffer", ")", "{", "if", "(", "seq", "!=", "null", ")", "{", "buffer", ".", "add", "(", "seq", ".", "toString", "(", ")", ")", ";", "}", "}" ]
Serializes any char sequence and writes it into specified buffer without performing any manipulation of the given text.
[ "Serializes", "any", "char", "sequence", "and", "writes", "it", "into", "specified", "buffer", "without", "performing", "any", "manipulation", "of", "the", "given", "text", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java#L264-L268
13,124
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
DefaultJsonGenerator.writeMapEntry
protected void writeMapEntry(String key, Object value, CharBuf buffer) { buffer.addJsonFieldName(key, disableUnicodeEscaping); writeObject(key, value, buffer); }
java
protected void writeMapEntry(String key, Object value, CharBuf buffer) { buffer.addJsonFieldName(key, disableUnicodeEscaping); writeObject(key, value, buffer); }
[ "protected", "void", "writeMapEntry", "(", "String", "key", ",", "Object", "value", ",", "CharBuf", "buffer", ")", "{", "buffer", ".", "addJsonFieldName", "(", "key", ",", "disableUnicodeEscaping", ")", ";", "writeObject", "(", "key", ",", "value", ",", "buffer", ")", ";", "}" ]
Serializes a map entry and writes it into specified buffer.
[ "Serializes", "a", "map", "entry", "and", "writes", "it", "into", "specified", "buffer", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java#L385-L388
13,125
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
DefaultJsonGenerator.shouldExcludeType
protected boolean shouldExcludeType(Class<?> type) { for (Class<?> t : excludedFieldTypes) { if (t.isAssignableFrom(type)) { return true; } } return false; }
java
protected boolean shouldExcludeType(Class<?> type) { for (Class<?> t : excludedFieldTypes) { if (t.isAssignableFrom(type)) { return true; } } return false; }
[ "protected", "boolean", "shouldExcludeType", "(", "Class", "<", "?", ">", "type", ")", "{", "for", "(", "Class", "<", "?", ">", "t", ":", "excludedFieldTypes", ")", "{", "if", "(", "t", ".", "isAssignableFrom", "(", "type", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Indicates whether the given type should be excluded from the generated output. @param type the type to check @return {@code true} if the given type should not be output, else {@code false}
[ "Indicates", "whether", "the", "given", "type", "should", "be", "excluded", "from", "the", "generated", "output", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java#L435-L442
13,126
apache/groovy
subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/TableLayoutRow.java
TableLayoutRow.addCell
public void addCell(groovy.swing.impl.TableLayoutCell tag) { int gridx = 0; for (Iterator iter = cells.iterator(); iter.hasNext(); ) { groovy.swing.impl.TableLayoutCell cell = (groovy.swing.impl.TableLayoutCell) iter.next(); gridx += cell.getColspan(); } tag.getConstraints().gridx = gridx; cells.add(tag); }
java
public void addCell(groovy.swing.impl.TableLayoutCell tag) { int gridx = 0; for (Iterator iter = cells.iterator(); iter.hasNext(); ) { groovy.swing.impl.TableLayoutCell cell = (groovy.swing.impl.TableLayoutCell) iter.next(); gridx += cell.getColspan(); } tag.getConstraints().gridx = gridx; cells.add(tag); }
[ "public", "void", "addCell", "(", "groovy", ".", "swing", ".", "impl", ".", "TableLayoutCell", "tag", ")", "{", "int", "gridx", "=", "0", ";", "for", "(", "Iterator", "iter", "=", "cells", ".", "iterator", "(", ")", ";", "iter", ".", "hasNext", "(", ")", ";", ")", "{", "groovy", ".", "swing", ".", "impl", ".", "TableLayoutCell", "cell", "=", "(", "groovy", ".", "swing", ".", "impl", ".", "TableLayoutCell", ")", "iter", ".", "next", "(", ")", ";", "gridx", "+=", "cell", ".", "getColspan", "(", ")", ";", "}", "tag", ".", "getConstraints", "(", ")", ".", "gridx", "=", "gridx", ";", "cells", ".", "add", "(", "tag", ")", ";", "}" ]
Adds a new cell to this row @param tag the td element
[ "Adds", "a", "new", "cell", "to", "this", "row" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/TableLayoutRow.java#L43-L51
13,127
apache/groovy
src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
MetaClassHelper.convertToTypeArray
public static Class[] convertToTypeArray(Object[] args) { if (args == null) return null; int s = args.length; Class[] ans = new Class[s]; for (int i = 0; i < s; i++) { Object o = args[i]; ans[i] = getClassWithNullAndWrapper(o); } return ans; }
java
public static Class[] convertToTypeArray(Object[] args) { if (args == null) return null; int s = args.length; Class[] ans = new Class[s]; for (int i = 0; i < s; i++) { Object o = args[i]; ans[i] = getClassWithNullAndWrapper(o); } return ans; }
[ "public", "static", "Class", "[", "]", "convertToTypeArray", "(", "Object", "[", "]", "args", ")", "{", "if", "(", "args", "==", "null", ")", "return", "null", ";", "int", "s", "=", "args", ".", "length", ";", "Class", "[", "]", "ans", "=", "new", "Class", "[", "s", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "s", ";", "i", "++", ")", "{", "Object", "o", "=", "args", "[", "i", "]", ";", "ans", "[", "i", "]", "=", "getClassWithNullAndWrapper", "(", "o", ")", ";", "}", "return", "ans", ";", "}" ]
param instance array to the type array @param args the arguments @return the types of the arguments
[ "param", "instance", "array", "to", "the", "type", "array" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java#L610-L620
13,128
apache/groovy
src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java
LoaderConfiguration.addFile
public void addFile(File file) { if (file != null && file.exists()) { try { classPath.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw new AssertionError("converting an existing file to an url should have never thrown an exception!"); } } }
java
public void addFile(File file) { if (file != null && file.exists()) { try { classPath.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw new AssertionError("converting an existing file to an url should have never thrown an exception!"); } } }
[ "public", "void", "addFile", "(", "File", "file", ")", "{", "if", "(", "file", "!=", "null", "&&", "file", ".", "exists", "(", ")", ")", "{", "try", "{", "classPath", ".", "add", "(", "file", ".", "toURI", "(", ")", ".", "toURL", "(", ")", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "throw", "new", "AssertionError", "(", "\"converting an existing file to an url should have never thrown an exception!\"", ")", ";", "}", "}", "}" ]
Adds a file to the classpath if it exists. @param file the file to add
[ "Adds", "a", "file", "to", "the", "classpath", "if", "it", "exists", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java#L276-L284
13,129
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.withObjectOutputStream
public static <T> T withObjectOutputStream(File file, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectOutputStream(file), closure); }
java
public static <T> T withObjectOutputStream(File file, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectOutputStream(file), closure); }
[ "public", "static", "<", "T", ">", "T", "withObjectOutputStream", "(", "File", "file", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.ObjectOutputStream\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withStream", "(", "newObjectOutputStream", "(", "file", ")", ",", "closure", ")", ";", "}" ]
Create a new ObjectOutputStream for this file and then pass it to the closure. This method ensures the stream is closed after the closure returns. @param file a File @param closure a closure @return the value returned by the closure @throws IOException if an IOException occurs. @see IOGroovyMethods#withStream(java.io.OutputStream, groovy.lang.Closure) @since 1.5.0
[ "Create", "a", "new", "ObjectOutputStream", "for", "this", "file", "and", "then", "pass", "it", "to", "the", "closure", ".", "This", "method", "ensures", "the", "stream", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L149-L151
13,130
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.newObjectInputStream
public static ObjectInputStream newObjectInputStream(File file, final ClassLoader classLoader) throws IOException { return IOGroovyMethods.newObjectInputStream(new FileInputStream(file), classLoader); }
java
public static ObjectInputStream newObjectInputStream(File file, final ClassLoader classLoader) throws IOException { return IOGroovyMethods.newObjectInputStream(new FileInputStream(file), classLoader); }
[ "public", "static", "ObjectInputStream", "newObjectInputStream", "(", "File", "file", ",", "final", "ClassLoader", "classLoader", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "newObjectInputStream", "(", "new", "FileInputStream", "(", "file", ")", ",", "classLoader", ")", ";", "}" ]
Create an object input stream for this file using the given class loader. @param file a file @param classLoader the class loader to use when loading the class @return an object input stream @throws IOException if an IOException occurs. @since 1.5.0
[ "Create", "an", "object", "input", "stream", "for", "this", "file", "using", "the", "given", "class", "loader", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L174-L176
13,131
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.eachObject
public static void eachObject(File self, Closure closure) throws IOException, ClassNotFoundException { IOGroovyMethods.eachObject(newObjectInputStream(self), closure); }
java
public static void eachObject(File self, Closure closure) throws IOException, ClassNotFoundException { IOGroovyMethods.eachObject(newObjectInputStream(self), closure); }
[ "public", "static", "void", "eachObject", "(", "File", "self", ",", "Closure", "closure", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "IOGroovyMethods", ".", "eachObject", "(", "newObjectInputStream", "(", "self", ")", ",", "closure", ")", ";", "}" ]
Iterates through the given file object by object. @param self a File @param closure a closure @throws IOException if an IOException occurs. @throws ClassNotFoundException if the class is not found. @see IOGroovyMethods#eachObject(java.io.ObjectInputStream, groovy.lang.Closure) @since 1.0
[ "Iterates", "through", "the", "given", "file", "object", "by", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L188-L190
13,132
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.eachLine
public static <T> T eachLine(File self, @ClosureParams(value = FromString.class, options = {"String", "String,Integer"}) Closure<T> closure) throws IOException { return eachLine(self, 1, closure); }
java
public static <T> T eachLine(File self, @ClosureParams(value = FromString.class, options = {"String", "String,Integer"}) Closure<T> closure) throws IOException { return eachLine(self, 1, closure); }
[ "public", "static", "<", "T", ">", "T", "eachLine", "(", "File", "self", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "{", "\"String\"", ",", "\"String,Integer\"", "}", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "eachLine", "(", "self", ",", "1", ",", "closure", ")", ";", "}" ]
Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns. @param self a File @param closure a closure (arg 1 is line, optional arg 2 is line number starting at line 1) @return the last value returned by the closure @throws IOException if an IOException occurs. @see #eachLine(java.io.File, int, groovy.lang.Closure) @since 1.5.5
[ "Iterates", "through", "this", "file", "line", "by", "line", ".", "Each", "line", "is", "passed", "to", "the", "given", "1", "or", "2", "arg", "closure", ".", "The", "file", "is", "read", "using", "a", "reader", "which", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L235-L237
13,133
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.readLines
public static List<String> readLines(File file) throws IOException { return IOGroovyMethods.readLines(newReader(file)); }
java
public static List<String> readLines(File file) throws IOException { return IOGroovyMethods.readLines(newReader(file)); }
[ "public", "static", "List", "<", "String", ">", "readLines", "(", "File", "file", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "readLines", "(", "newReader", "(", "file", ")", ")", ";", "}" ]
Reads the file into a list of Strings, with one item for each line. @param file a File @return a List of lines @throws IOException if an IOException occurs. @see IOGroovyMethods#readLines(java.io.Reader) @since 1.0
[ "Reads", "the", "file", "into", "a", "list", "of", "Strings", "with", "one", "item", "for", "each", "line", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L524-L526
13,134
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.readLines
public static List<String> readLines(URL self, String charset) throws IOException { return IOGroovyMethods.readLines(newReader(self, charset)); }
java
public static List<String> readLines(URL self, String charset) throws IOException { return IOGroovyMethods.readLines(newReader(self, charset)); }
[ "public", "static", "List", "<", "String", ">", "readLines", "(", "URL", "self", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "readLines", "(", "newReader", "(", "self", ",", "charset", ")", ")", ";", "}" ]
Reads the URL contents into a list, with one element for each line. @param self a URL @param charset opens the URL with a specified charset @return a List of lines @throws IOException if an IOException occurs. @see IOGroovyMethods#readLines(java.io.Reader) @since 1.6.8
[ "Reads", "the", "URL", "contents", "into", "a", "list", "with", "one", "element", "for", "each", "line", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L565-L567
13,135
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.getText
public static String getText(File file, String charset) throws IOException { return IOGroovyMethods.getText(newReader(file, charset)); }
java
public static String getText(File file, String charset) throws IOException { return IOGroovyMethods.getText(newReader(file, charset)); }
[ "public", "static", "String", "getText", "(", "File", "file", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "getText", "(", "newReader", "(", "file", ",", "charset", ")", ")", ";", "}" ]
Read the content of the File using the specified encoding and return it as a String. @param file the file whose content we want to read @param charset the charset used to read the content of the file @return a String containing the content of the file @throws IOException if an IOException occurs. @since 1.0
[ "Read", "the", "content", "of", "the", "File", "using", "the", "specified", "encoding", "and", "return", "it", "as", "a", "String", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L579-L581
13,136
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.getText
public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().name()); }
java
public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().name()); }
[ "public", "static", "String", "getText", "(", "URL", "url", ")", "throws", "IOException", "{", "return", "getText", "(", "url", ",", "CharsetToolkit", ".", "getDefaultSystemCharset", "(", ")", ".", "name", "(", ")", ")", ";", "}" ]
Read the content of this URL and returns it as a String. @param url URL to read content from @return the text from that URL @throws IOException if an IOException occurs. @since 1.0
[ "Read", "the", "content", "of", "this", "URL", "and", "returns", "it", "as", "a", "String", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L603-L605
13,137
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.getText
public static String getText(URL url, String charset) throws IOException { BufferedReader reader = newReader(url, charset); return IOGroovyMethods.getText(reader); }
java
public static String getText(URL url, String charset) throws IOException { BufferedReader reader = newReader(url, charset); return IOGroovyMethods.getText(reader); }
[ "public", "static", "String", "getText", "(", "URL", "url", ",", "String", "charset", ")", "throws", "IOException", "{", "BufferedReader", "reader", "=", "newReader", "(", "url", ",", "charset", ")", ";", "return", "IOGroovyMethods", ".", "getText", "(", "reader", ")", ";", "}" ]
Read the data from this URL and return it as a String. The connection stream is closed before this method returns. @param url URL to read content from @param charset opens the stream with a specified charset @return the text from that URL @throws IOException if an IOException occurs. @see java.net.URLConnection#getInputStream() @since 1.0
[ "Read", "the", "data", "from", "this", "URL", "and", "return", "it", "as", "a", "String", ".", "The", "connection", "stream", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L640-L643
13,138
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.setBytes
public static void setBytes(File file, byte[] bytes) throws IOException { IOGroovyMethods.setBytes(new FileOutputStream(file), bytes); }
java
public static void setBytes(File file, byte[] bytes) throws IOException { IOGroovyMethods.setBytes(new FileOutputStream(file), bytes); }
[ "public", "static", "void", "setBytes", "(", "File", "file", ",", "byte", "[", "]", "bytes", ")", "throws", "IOException", "{", "IOGroovyMethods", ".", "setBytes", "(", "new", "FileOutputStream", "(", "file", ")", ",", "bytes", ")", ";", "}" ]
Write the bytes from the byte array to the File. @param file the file to write to @param bytes the byte[] to write to the file @throws IOException if an IOException occurs. @since 1.7.1
[ "Write", "the", "bytes", "from", "the", "byte", "array", "to", "the", "File", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L717-L719
13,139
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.leftShift
public static File leftShift(File file, byte[] bytes) throws IOException { append(file, bytes); return file; }
java
public static File leftShift(File file, byte[] bytes) throws IOException { append(file, bytes); return file; }
[ "public", "static", "File", "leftShift", "(", "File", "file", ",", "byte", "[", "]", "bytes", ")", "throws", "IOException", "{", "append", "(", "file", ",", "bytes", ")", ";", "return", "file", ";", "}" ]
Write bytes to a File. @param file a File @param bytes the byte array to append to the end of the File @return the original file @throws IOException if an IOException occurs. @since 1.5.0
[ "Write", "bytes", "to", "a", "File", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L807-L810
13,140
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.write
public static void write(File file, String text, String charset) throws IOException { write(file, text, charset, false); }
java
public static void write(File file, String text, String charset) throws IOException { write(file, text, charset, false); }
[ "public", "static", "void", "write", "(", "File", "file", ",", "String", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "write", "(", "file", ",", "text", ",", "charset", ",", "false", ")", ";", "}" ]
Write the text to the File without writing a BOM, using the specified encoding. @param file a File @param text the text to write to the File @param charset the charset used @throws IOException if an IOException occurs. @since 1.0
[ "Write", "the", "text", "to", "the", "File", "without", "writing", "a", "BOM", "using", "the", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L836-L838
13,141
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Object text) throws IOException { append(file, text, false); }
java
public static void append(File file, Object text) throws IOException { append(file, text, false); }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Object", "text", ")", "throws", "IOException", "{", "append", "(", "file", ",", "text", ",", "false", ")", ";", "}" ]
Append the text at the end of the File without writing a BOM. @param file a File @param text the text to append at the end of the File @throws IOException if an IOException occurs. @since 1.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "File", "without", "writing", "a", "BOM", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L880-L882
13,142
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Object text, String charset) throws IOException { append(file, text, charset, false); }
java
public static void append(File file, Object text, String charset) throws IOException { append(file, text, charset, false); }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Object", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "append", "(", "file", ",", "text", ",", "charset", ",", "false", ")", ";", "}" ]
Append the text at the end of the File without writing a BOM, using a specified encoding. @param file a File @param text the text to append at the end of the File @param charset the charset used @throws IOException if an IOException occurs. @since 1.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "File", "without", "writing", "a", "BOM", "using", "a", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1011-L1013
13,143
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Reader reader, String charset) throws IOException { append(file, reader, charset, false); }
java
public static void append(File file, Reader reader, String charset) throws IOException { append(file, reader, charset, false); }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Reader", "reader", ",", "String", "charset", ")", "throws", "IOException", "{", "append", "(", "file", ",", "reader", ",", "charset", ",", "false", ")", ";", "}" ]
Append the text supplied by the Reader at the end of the File without writing a BOM, using a specified encoding. @param file a File @param reader the Reader supplying the text to append at the end of the File @param charset the charset used @throws IOException if an IOException occurs. @since 2.3
[ "Append", "the", "text", "supplied", "by", "the", "Reader", "at", "the", "end", "of", "the", "File", "without", "writing", "a", "BOM", "using", "a", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1108-L1110
13,144
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.relativePath
public static String relativePath(File self, File to) throws IOException { String fromPath = self.getCanonicalPath(); String toPath = to.getCanonicalPath(); // build the path stack info to compare String[] fromPathStack = getPathStack(fromPath); String[] toPathStack = getPathStack(toPath); if (0 < toPathStack.length && 0 < fromPathStack.length) { if (!fromPathStack[0].equals(toPathStack[0])) { // not the same device (would be "" on Linux/Unix) return getPath(Arrays.asList(toPathStack)); } } else { // no comparison possible return getPath(Arrays.asList(toPathStack)); } int minLength = Math.min(fromPathStack.length, toPathStack.length); int same = 1; // Used outside the for loop // get index of parts which are equal while (same < minLength && fromPathStack[same].equals(toPathStack[same])) { same++; } List<String> relativePathStack = new ArrayList<String>(); // if "from" part is longer, fill it up with ".." // to reach path which is equal to both paths for (int i = same; i < fromPathStack.length; i++) { relativePathStack.add(".."); } // fill it up path with parts which were not equal relativePathStack.addAll(Arrays.asList(toPathStack).subList(same, toPathStack.length)); return getPath(relativePathStack); }
java
public static String relativePath(File self, File to) throws IOException { String fromPath = self.getCanonicalPath(); String toPath = to.getCanonicalPath(); // build the path stack info to compare String[] fromPathStack = getPathStack(fromPath); String[] toPathStack = getPathStack(toPath); if (0 < toPathStack.length && 0 < fromPathStack.length) { if (!fromPathStack[0].equals(toPathStack[0])) { // not the same device (would be "" on Linux/Unix) return getPath(Arrays.asList(toPathStack)); } } else { // no comparison possible return getPath(Arrays.asList(toPathStack)); } int minLength = Math.min(fromPathStack.length, toPathStack.length); int same = 1; // Used outside the for loop // get index of parts which are equal while (same < minLength && fromPathStack[same].equals(toPathStack[same])) { same++; } List<String> relativePathStack = new ArrayList<String>(); // if "from" part is longer, fill it up with ".." // to reach path which is equal to both paths for (int i = same; i < fromPathStack.length; i++) { relativePathStack.add(".."); } // fill it up path with parts which were not equal relativePathStack.addAll(Arrays.asList(toPathStack).subList(same, toPathStack.length)); return getPath(relativePathStack); }
[ "public", "static", "String", "relativePath", "(", "File", "self", ",", "File", "to", ")", "throws", "IOException", "{", "String", "fromPath", "=", "self", ".", "getCanonicalPath", "(", ")", ";", "String", "toPath", "=", "to", ".", "getCanonicalPath", "(", ")", ";", "// build the path stack info to compare", "String", "[", "]", "fromPathStack", "=", "getPathStack", "(", "fromPath", ")", ";", "String", "[", "]", "toPathStack", "=", "getPathStack", "(", "toPath", ")", ";", "if", "(", "0", "<", "toPathStack", ".", "length", "&&", "0", "<", "fromPathStack", ".", "length", ")", "{", "if", "(", "!", "fromPathStack", "[", "0", "]", ".", "equals", "(", "toPathStack", "[", "0", "]", ")", ")", "{", "// not the same device (would be \"\" on Linux/Unix)", "return", "getPath", "(", "Arrays", ".", "asList", "(", "toPathStack", ")", ")", ";", "}", "}", "else", "{", "// no comparison possible", "return", "getPath", "(", "Arrays", ".", "asList", "(", "toPathStack", ")", ")", ";", "}", "int", "minLength", "=", "Math", ".", "min", "(", "fromPathStack", ".", "length", ",", "toPathStack", ".", "length", ")", ";", "int", "same", "=", "1", ";", "// Used outside the for loop", "// get index of parts which are equal", "while", "(", "same", "<", "minLength", "&&", "fromPathStack", "[", "same", "]", ".", "equals", "(", "toPathStack", "[", "same", "]", ")", ")", "{", "same", "++", ";", "}", "List", "<", "String", ">", "relativePathStack", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "// if \"from\" part is longer, fill it up with \"..\"", "// to reach path which is equal to both paths", "for", "(", "int", "i", "=", "same", ";", "i", "<", "fromPathStack", ".", "length", ";", "i", "++", ")", "{", "relativePathStack", ".", "add", "(", "\"..\"", ")", ";", "}", "// fill it up path with parts which were not equal", "relativePathStack", ".", "addAll", "(", "Arrays", ".", "asList", "(", "toPathStack", ")", ".", "subList", "(", "same", ",", "toPathStack", ".", "length", ")", ")", ";", "return", "getPath", "(", "relativePathStack", ")", ";", "}" ]
Relative path to file. @param self the <code>File</code> to calculate the path from @param to the <code>File</code> to calculate the path to @return the relative path between the files
[ "Relative", "path", "to", "file", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1650-L1689
13,145
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.withInputStream
public static <T> T withInputStream(URL url, @ClosureParams(value = SimpleType.class, options = "java.io.InputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newInputStream(url), closure); }
java
public static <T> T withInputStream(URL url, @ClosureParams(value = SimpleType.class, options = "java.io.InputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newInputStream(url), closure); }
[ "public", "static", "<", "T", ">", "T", "withInputStream", "(", "URL", "url", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.InputStream\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withStream", "(", "newInputStream", "(", "url", ")", ",", "closure", ")", ";", "}" ]
Creates a new InputStream for this URL and passes it into the closure. This method ensures the stream is closed after the closure returns. @param url a URL @param closure a closure @return the value returned by the closure @throws IOException if an IOException occurs. @see IOGroovyMethods#withStream(java.io.InputStream, groovy.lang.Closure) @since 1.5.2
[ "Creates", "a", "new", "InputStream", "for", "this", "URL", "and", "passes", "it", "into", "the", "closure", ".", "This", "method", "ensures", "the", "stream", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1857-L1859
13,146
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.newWriter
public static BufferedWriter newWriter(File file, String charset) throws IOException { return newWriter(file, charset, false); }
java
public static BufferedWriter newWriter(File file, String charset) throws IOException { return newWriter(file, charset, false); }
[ "public", "static", "BufferedWriter", "newWriter", "(", "File", "file", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "newWriter", "(", "file", ",", "charset", ",", "false", ")", ";", "}" ]
Creates a buffered writer for this file, writing data without writing a BOM, using a specified encoding. @param file a File @param charset the name of the encoding used to write in this file @return a BufferedWriter @throws IOException if an IOException occurs. @since 1.0
[ "Creates", "a", "buffered", "writer", "for", "this", "file", "writing", "data", "without", "writing", "a", "BOM", "using", "a", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1972-L1974
13,147
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.withWriter
public static <T> T withWriter(File file, @ClosureParams(value = SimpleType.class, options = "java.io.BufferedWriter") Closure<T> closure) throws IOException { return IOGroovyMethods.withWriter(newWriter(file), closure); }
java
public static <T> T withWriter(File file, @ClosureParams(value = SimpleType.class, options = "java.io.BufferedWriter") Closure<T> closure) throws IOException { return IOGroovyMethods.withWriter(newWriter(file), closure); }
[ "public", "static", "<", "T", ">", "T", "withWriter", "(", "File", "file", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.BufferedWriter\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withWriter", "(", "newWriter", "(", "file", ")", ",", "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. @param file a File @param closure a closure @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Creates", "a", "new", "BufferedWriter", "for", "this", "file", "passes", "it", "to", "the", "closure", "and", "ensures", "the", "stream", "is", "flushed", "and", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1986-L1988
13,148
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.withReader
public static <T> T withReader(URL url, @ClosureParams(value = SimpleType.class, options = "java.io.Reader") Closure<T> closure) throws IOException { return IOGroovyMethods.withReader(url.openConnection().getInputStream(), closure); }
java
public static <T> T withReader(URL url, @ClosureParams(value = SimpleType.class, options = "java.io.Reader") Closure<T> closure) throws IOException { return IOGroovyMethods.withReader(url.openConnection().getInputStream(), closure); }
[ "public", "static", "<", "T", ">", "T", "withReader", "(", "URL", "url", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.Reader\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withReader", "(", "url", ".", "openConnection", "(", ")", ".", "getInputStream", "(", ")", ",", "closure", ")", ";", "}" ]
Helper method to create a new BufferedReader for a URL and then passes it to the closure. The reader is closed after the closure returns. @param url a URL @param closure the closure to invoke with the reader @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Helper", "method", "to", "create", "a", "new", "BufferedReader", "for", "a", "URL", "and", "then", "passes", "it", "to", "the", "closure", ".", "The", "reader", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2111-L2113
13,149
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.newInputStream
public static BufferedInputStream newInputStream(URL url) throws MalformedURLException, IOException { return new BufferedInputStream(configuredInputStream(null, url)); }
java
public static BufferedInputStream newInputStream(URL url) throws MalformedURLException, IOException { return new BufferedInputStream(configuredInputStream(null, url)); }
[ "public", "static", "BufferedInputStream", "newInputStream", "(", "URL", "url", ")", "throws", "MalformedURLException", ",", "IOException", "{", "return", "new", "BufferedInputStream", "(", "configuredInputStream", "(", "null", ",", "url", ")", ")", ";", "}" ]
Creates a buffered input stream for this URL. @param url a URL @return a BufferedInputStream for the URL @throws MalformedURLException is thrown if the URL is not well formed @throws IOException if an I/O error occurs while creating the input stream @since 1.5.2
[ "Creates", "a", "buffered", "input", "stream", "for", "this", "URL", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2195-L2197
13,150
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.newReader
public static BufferedReader newReader(URL url) throws MalformedURLException, IOException { return IOGroovyMethods.newReader(configuredInputStream(null, url)); }
java
public static BufferedReader newReader(URL url) throws MalformedURLException, IOException { return IOGroovyMethods.newReader(configuredInputStream(null, url)); }
[ "public", "static", "BufferedReader", "newReader", "(", "URL", "url", ")", "throws", "MalformedURLException", ",", "IOException", "{", "return", "IOGroovyMethods", ".", "newReader", "(", "configuredInputStream", "(", "null", ",", "url", ")", ")", ";", "}" ]
Creates a buffered reader for this URL. @param url a URL @return a BufferedReader for the URL @throws MalformedURLException is thrown if the URL is not well formed @throws IOException if an I/O error occurs while creating the input stream @since 1.5.5
[ "Creates", "a", "buffered", "reader", "for", "this", "URL", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2231-L2233
13,151
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.eachByte
public static void eachByte(URL url, @ClosureParams(value = SimpleType.class, options = "byte") Closure closure) throws IOException { InputStream is = url.openConnection().getInputStream(); IOGroovyMethods.eachByte(is, closure); }
java
public static void eachByte(URL url, @ClosureParams(value = SimpleType.class, options = "byte") Closure closure) throws IOException { InputStream is = url.openConnection().getInputStream(); IOGroovyMethods.eachByte(is, closure); }
[ "public", "static", "void", "eachByte", "(", "URL", "url", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"byte\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "InputStream", "is", "=", "url", ".", "openConnection", "(", ")", ".", "getInputStream", "(", ")", ";", "IOGroovyMethods", ".", "eachByte", "(", "is", ",", "closure", ")", ";", "}" ]
Reads the InputStream from this URL, passing each byte to the given closure. The URL stream will be closed before this method returns. @param url url to iterate over @param closure closure to apply to each byte @throws IOException if an IOException occurs. @see IOGroovyMethods#eachByte(java.io.InputStream, groovy.lang.Closure) @since 1.0
[ "Reads", "the", "InputStream", "from", "this", "URL", "passing", "each", "byte", "to", "the", "given", "closure", ".", "The", "URL", "stream", "will", "be", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2338-L2341
13,152
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.filterLine
public static Writable filterLine(File self, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { return IOGroovyMethods.filterLine(newReader(self), closure); }
java
public static Writable filterLine(File self, @ClosureParams(value = SimpleType.class, options = "java.lang.String") Closure closure) throws IOException { return IOGroovyMethods.filterLine(newReader(self), closure); }
[ "public", "static", "Writable", "filterLine", "(", "File", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "filterLine", "(", "newReader", "(", "self", ")", ",", "closure", ")", ";", "}" ]
Filters the lines of a File and creates a Writable in return to stream the filtered lines. @param self a File @param closure a closure which returns a boolean indicating to filter the line or not @return a Writable closure @throws IOException if <code>self</code> is not readable @see IOGroovyMethods#filterLine(java.io.Reader, groovy.lang.Closure) @since 1.0
[ "Filters", "the", "lines", "of", "a", "File", "and", "creates", "a", "Writable", "in", "return", "to", "stream", "the", "filtered", "lines", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2371-L2373
13,153
apache/groovy
src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.readBytes
public static byte[] readBytes(File file) throws IOException { byte[] bytes = new byte[(int) file.length()]; FileInputStream fileInputStream = new FileInputStream(file); DataInputStream dis = new DataInputStream(fileInputStream); try { dis.readFully(bytes); InputStream temp = dis; dis = null; temp.close(); } finally { closeWithWarning(dis); } return bytes; }
java
public static byte[] readBytes(File file) throws IOException { byte[] bytes = new byte[(int) file.length()]; FileInputStream fileInputStream = new FileInputStream(file); DataInputStream dis = new DataInputStream(fileInputStream); try { dis.readFully(bytes); InputStream temp = dis; dis = null; temp.close(); } finally { closeWithWarning(dis); } return bytes; }
[ "public", "static", "byte", "[", "]", "readBytes", "(", "File", "file", ")", "throws", "IOException", "{", "byte", "[", "]", "bytes", "=", "new", "byte", "[", "(", "int", ")", "file", ".", "length", "(", ")", "]", ";", "FileInputStream", "fileInputStream", "=", "new", "FileInputStream", "(", "file", ")", ";", "DataInputStream", "dis", "=", "new", "DataInputStream", "(", "fileInputStream", ")", ";", "try", "{", "dis", ".", "readFully", "(", "bytes", ")", ";", "InputStream", "temp", "=", "dis", ";", "dis", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "dis", ")", ";", "}", "return", "bytes", ";", "}" ]
Reads the content of the file into a byte array. @param file a File @return a byte array with the contents of the file. @throws IOException if an IOException occurs. @since 1.0
[ "Reads", "the", "content", "of", "the", "file", "into", "a", "byte", "array", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L2501-L2514
13,154
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
GenericsUtils.parameterizeSAM
public static Tuple2<ClassNode[], ClassNode> parameterizeSAM(ClassNode sam) { MethodNode methodNode = ClassHelper.findSAM(sam); final Map<GenericsType, GenericsType> map = makeDeclaringAndActualGenericsTypeMapOfExactType(methodNode.getDeclaringClass(), sam); ClassNode[] parameterTypes = Arrays.stream(methodNode.getParameters()) .map(e -> { ClassNode originalParameterType = e.getType(); return originalParameterType.isGenericsPlaceHolder() ? findActualTypeByGenericsPlaceholderName(originalParameterType.getUnresolvedName(), map) : originalParameterType; }) .toArray(ClassNode[]::new); ClassNode originalReturnType = methodNode.getReturnType(); ClassNode returnType = originalReturnType.isGenericsPlaceHolder() ? findActualTypeByGenericsPlaceholderName(originalReturnType.getUnresolvedName(), map) : originalReturnType; return tuple(parameterTypes, returnType); }
java
public static Tuple2<ClassNode[], ClassNode> parameterizeSAM(ClassNode sam) { MethodNode methodNode = ClassHelper.findSAM(sam); final Map<GenericsType, GenericsType> map = makeDeclaringAndActualGenericsTypeMapOfExactType(methodNode.getDeclaringClass(), sam); ClassNode[] parameterTypes = Arrays.stream(methodNode.getParameters()) .map(e -> { ClassNode originalParameterType = e.getType(); return originalParameterType.isGenericsPlaceHolder() ? findActualTypeByGenericsPlaceholderName(originalParameterType.getUnresolvedName(), map) : originalParameterType; }) .toArray(ClassNode[]::new); ClassNode originalReturnType = methodNode.getReturnType(); ClassNode returnType = originalReturnType.isGenericsPlaceHolder() ? findActualTypeByGenericsPlaceholderName(originalReturnType.getUnresolvedName(), map) : originalReturnType; return tuple(parameterTypes, returnType); }
[ "public", "static", "Tuple2", "<", "ClassNode", "[", "]", ",", "ClassNode", ">", "parameterizeSAM", "(", "ClassNode", "sam", ")", "{", "MethodNode", "methodNode", "=", "ClassHelper", ".", "findSAM", "(", "sam", ")", ";", "final", "Map", "<", "GenericsType", ",", "GenericsType", ">", "map", "=", "makeDeclaringAndActualGenericsTypeMapOfExactType", "(", "methodNode", ".", "getDeclaringClass", "(", ")", ",", "sam", ")", ";", "ClassNode", "[", "]", "parameterTypes", "=", "Arrays", ".", "stream", "(", "methodNode", ".", "getParameters", "(", ")", ")", ".", "map", "(", "e", "->", "{", "ClassNode", "originalParameterType", "=", "e", ".", "getType", "(", ")", ";", "return", "originalParameterType", ".", "isGenericsPlaceHolder", "(", ")", "?", "findActualTypeByGenericsPlaceholderName", "(", "originalParameterType", ".", "getUnresolvedName", "(", ")", ",", "map", ")", ":", "originalParameterType", ";", "}", ")", ".", "toArray", "(", "ClassNode", "[", "]", "::", "new", ")", ";", "ClassNode", "originalReturnType", "=", "methodNode", ".", "getReturnType", "(", ")", ";", "ClassNode", "returnType", "=", "originalReturnType", ".", "isGenericsPlaceHolder", "(", ")", "?", "findActualTypeByGenericsPlaceholderName", "(", "originalReturnType", ".", "getUnresolvedName", "(", ")", ",", "map", ")", ":", "originalReturnType", ";", "return", "tuple", "(", "parameterTypes", ",", "returnType", ")", ";", "}" ]
Get the parameter and return types of the abstract method of SAM If the abstract method is not parameterized, we will get generics placeholders, e.g. T, U For example, the abstract method of {@link java.util.function.Function} is <pre> R apply(T t); </pre> We parameterize the above interface as {@code Function<String, Integer>}, then the abstract method will be <pre> Integer apply(String t); </pre> When we call {@code parameterizeSAM} on the ClassNode {@code Function<String, Integer>}, we can get parameter types and return type of the above abstract method, i.e. ClassNode {@code ClassHelper.STRING_TYPE} and {@code ClassHelper.Integer_TYPE} @param sam the class node which contains only one abstract method @return the parameter and return types @since 3.0.0
[ "Get", "the", "parameter", "and", "return", "types", "of", "the", "abstract", "method", "of", "SAM" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java#L961-L982
13,155
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
GenericsUtils.findActualTypeByGenericsPlaceholderName
public static ClassNode findActualTypeByGenericsPlaceholderName(String placeholderName, Map<GenericsType, GenericsType> genericsPlaceholderAndTypeMap) { for (Map.Entry<GenericsType, GenericsType> entry : genericsPlaceholderAndTypeMap.entrySet()) { GenericsType declaringGenericsType = entry.getKey(); if (placeholderName.equals(declaringGenericsType.getName())) { return entry.getValue().getType().redirect(); } } return null; }
java
public static ClassNode findActualTypeByGenericsPlaceholderName(String placeholderName, Map<GenericsType, GenericsType> genericsPlaceholderAndTypeMap) { for (Map.Entry<GenericsType, GenericsType> entry : genericsPlaceholderAndTypeMap.entrySet()) { GenericsType declaringGenericsType = entry.getKey(); if (placeholderName.equals(declaringGenericsType.getName())) { return entry.getValue().getType().redirect(); } } return null; }
[ "public", "static", "ClassNode", "findActualTypeByGenericsPlaceholderName", "(", "String", "placeholderName", ",", "Map", "<", "GenericsType", ",", "GenericsType", ">", "genericsPlaceholderAndTypeMap", ")", "{", "for", "(", "Map", ".", "Entry", "<", "GenericsType", ",", "GenericsType", ">", "entry", ":", "genericsPlaceholderAndTypeMap", ".", "entrySet", "(", ")", ")", "{", "GenericsType", "declaringGenericsType", "=", "entry", ".", "getKey", "(", ")", ";", "if", "(", "placeholderName", ".", "equals", "(", "declaringGenericsType", ".", "getName", "(", ")", ")", ")", "{", "return", "entry", ".", "getValue", "(", ")", ".", "getType", "(", ")", ".", "redirect", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
Get the actual type according to the placeholder name @param placeholderName the placeholder name, e.g. T, E @param genericsPlaceholderAndTypeMap the result of {@link #makeDeclaringAndActualGenericsTypeMap(ClassNode, ClassNode)} @return the actual type
[ "Get", "the", "actual", "type", "according", "to", "the", "placeholder", "name" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java#L991-L1001
13,156
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java
TypeTransformers.addTransformer
protected static MethodHandle addTransformer(MethodHandle handle, int pos, Object arg, Class parameter) { MethodHandle transformer=null; if (arg instanceof GString) { transformer = TO_STRING; } else if (arg instanceof Closure) { transformer = createSAMTransform(arg, parameter); } else if (Number.class.isAssignableFrom(parameter)) { transformer = selectNumberTransformer(parameter, arg); } else if (parameter.isArray()) { transformer = MethodHandles.insertArguments(AS_ARRAY, 1, parameter); } if (transformer==null) throw new GroovyBugError("Unknown transformation for argument "+arg+" at position "+pos+" with "+arg.getClass()+" for parameter of type "+parameter); return applyUnsharpFilter(handle, pos, transformer); }
java
protected static MethodHandle addTransformer(MethodHandle handle, int pos, Object arg, Class parameter) { MethodHandle transformer=null; if (arg instanceof GString) { transformer = TO_STRING; } else if (arg instanceof Closure) { transformer = createSAMTransform(arg, parameter); } else if (Number.class.isAssignableFrom(parameter)) { transformer = selectNumberTransformer(parameter, arg); } else if (parameter.isArray()) { transformer = MethodHandles.insertArguments(AS_ARRAY, 1, parameter); } if (transformer==null) throw new GroovyBugError("Unknown transformation for argument "+arg+" at position "+pos+" with "+arg.getClass()+" for parameter of type "+parameter); return applyUnsharpFilter(handle, pos, transformer); }
[ "protected", "static", "MethodHandle", "addTransformer", "(", "MethodHandle", "handle", ",", "int", "pos", ",", "Object", "arg", ",", "Class", "parameter", ")", "{", "MethodHandle", "transformer", "=", "null", ";", "if", "(", "arg", "instanceof", "GString", ")", "{", "transformer", "=", "TO_STRING", ";", "}", "else", "if", "(", "arg", "instanceof", "Closure", ")", "{", "transformer", "=", "createSAMTransform", "(", "arg", ",", "parameter", ")", ";", "}", "else", "if", "(", "Number", ".", "class", ".", "isAssignableFrom", "(", "parameter", ")", ")", "{", "transformer", "=", "selectNumberTransformer", "(", "parameter", ",", "arg", ")", ";", "}", "else", "if", "(", "parameter", ".", "isArray", "(", ")", ")", "{", "transformer", "=", "MethodHandles", ".", "insertArguments", "(", "AS_ARRAY", ",", "1", ",", "parameter", ")", ";", "}", "if", "(", "transformer", "==", "null", ")", "throw", "new", "GroovyBugError", "(", "\"Unknown transformation for argument \"", "+", "arg", "+", "\" at position \"", "+", "pos", "+", "\" with \"", "+", "arg", ".", "getClass", "(", ")", "+", "\" for parameter of type \"", "+", "parameter", ")", ";", "return", "applyUnsharpFilter", "(", "handle", ",", "pos", ",", "transformer", ")", ";", "}" ]
Adds a type transformer applied at runtime. This method handles transformations to String from GString, array transformations and number based transformations
[ "Adds", "a", "type", "transformer", "applied", "at", "runtime", ".", "This", "method", "handles", "transformations", "to", "String", "from", "GString", "array", "transformations", "and", "number", "based", "transformations" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java#L126-L139
13,157
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java
TypeTransformers.createSAMTransform
private static MethodHandle createSAMTransform(Object arg, Class parameter) { Method method = CachedSAMClass.getSAMMethod(parameter); if (method == null) return null; // TODO: have to think about how to optimize this! if (parameter.isInterface()) { if (Traits.isTrait(parameter)) { // the following code will basically do this: // Map<String,Closure> impl = Collections.singletonMap(method.getName(),arg); // return ProxyGenerator.INSTANCE.instantiateAggregate(impl,Collections.singletonList(clazz)); // TO_SAMTRAIT_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject // where the second object is the input closure, everything else // needs to be provide and is in remaining order: method name, // ProxyGenerator.INSTANCE and singletonList(parameter) MethodHandle ret = TO_SAMTRAIT_PROXY; ret = MethodHandles.insertArguments(ret, 2, ProxyGenerator.INSTANCE, Collections.singletonList(parameter)); ret = MethodHandles.insertArguments(ret, 0, method.getName()); return ret; } // the following code will basically do this: // return Proxy.newProxyInstance( // arg.getClass().getClassLoader(), // new Class[]{parameter}, // new ConvertedClosure((Closure) arg)); // TO_REFLECTIVE_PROXY will do that for us, though // input is the closure, the method name, the class loader and the // class[]. All of that but the closure must be provided here MethodHandle ret = TO_REFLECTIVE_PROXY; ret = MethodHandles.insertArguments(ret, 1, method.getName(), arg.getClass().getClassLoader(), new Class[]{parameter}); return ret; } else { // the following code will basically do this: //Map<String, Object> m = Collections.singletonMap(method.getName(), arg); //return ProxyGenerator.INSTANCE. // instantiateAggregateFromBaseClass(m, parameter); // TO_GENERATED_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject // where the second object is the input closure, everything else // needs to be provide and is in remaining order: method name, // ProxyGenerator.INSTANCE and parameter MethodHandle ret = TO_GENERATED_PROXY; ret = MethodHandles.insertArguments(ret, 2, ProxyGenerator.INSTANCE, parameter); ret = MethodHandles.insertArguments(ret, 0, method.getName()); return ret; } }
java
private static MethodHandle createSAMTransform(Object arg, Class parameter) { Method method = CachedSAMClass.getSAMMethod(parameter); if (method == null) return null; // TODO: have to think about how to optimize this! if (parameter.isInterface()) { if (Traits.isTrait(parameter)) { // the following code will basically do this: // Map<String,Closure> impl = Collections.singletonMap(method.getName(),arg); // return ProxyGenerator.INSTANCE.instantiateAggregate(impl,Collections.singletonList(clazz)); // TO_SAMTRAIT_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject // where the second object is the input closure, everything else // needs to be provide and is in remaining order: method name, // ProxyGenerator.INSTANCE and singletonList(parameter) MethodHandle ret = TO_SAMTRAIT_PROXY; ret = MethodHandles.insertArguments(ret, 2, ProxyGenerator.INSTANCE, Collections.singletonList(parameter)); ret = MethodHandles.insertArguments(ret, 0, method.getName()); return ret; } // the following code will basically do this: // return Proxy.newProxyInstance( // arg.getClass().getClassLoader(), // new Class[]{parameter}, // new ConvertedClosure((Closure) arg)); // TO_REFLECTIVE_PROXY will do that for us, though // input is the closure, the method name, the class loader and the // class[]. All of that but the closure must be provided here MethodHandle ret = TO_REFLECTIVE_PROXY; ret = MethodHandles.insertArguments(ret, 1, method.getName(), arg.getClass().getClassLoader(), new Class[]{parameter}); return ret; } else { // the following code will basically do this: //Map<String, Object> m = Collections.singletonMap(method.getName(), arg); //return ProxyGenerator.INSTANCE. // instantiateAggregateFromBaseClass(m, parameter); // TO_GENERATED_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject // where the second object is the input closure, everything else // needs to be provide and is in remaining order: method name, // ProxyGenerator.INSTANCE and parameter MethodHandle ret = TO_GENERATED_PROXY; ret = MethodHandles.insertArguments(ret, 2, ProxyGenerator.INSTANCE, parameter); ret = MethodHandles.insertArguments(ret, 0, method.getName()); return ret; } }
[ "private", "static", "MethodHandle", "createSAMTransform", "(", "Object", "arg", ",", "Class", "parameter", ")", "{", "Method", "method", "=", "CachedSAMClass", ".", "getSAMMethod", "(", "parameter", ")", ";", "if", "(", "method", "==", "null", ")", "return", "null", ";", "// TODO: have to think about how to optimize this!", "if", "(", "parameter", ".", "isInterface", "(", ")", ")", "{", "if", "(", "Traits", ".", "isTrait", "(", "parameter", ")", ")", "{", "// the following code will basically do this:", "// Map<String,Closure> impl = Collections.singletonMap(method.getName(),arg);", "// return ProxyGenerator.INSTANCE.instantiateAggregate(impl,Collections.singletonList(clazz));", "// TO_SAMTRAIT_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject", "// where the second object is the input closure, everything else", "// needs to be provide and is in remaining order: method name,", "// ProxyGenerator.INSTANCE and singletonList(parameter)", "MethodHandle", "ret", "=", "TO_SAMTRAIT_PROXY", ";", "ret", "=", "MethodHandles", ".", "insertArguments", "(", "ret", ",", "2", ",", "ProxyGenerator", ".", "INSTANCE", ",", "Collections", ".", "singletonList", "(", "parameter", ")", ")", ";", "ret", "=", "MethodHandles", ".", "insertArguments", "(", "ret", ",", "0", ",", "method", ".", "getName", "(", ")", ")", ";", "return", "ret", ";", "}", "// the following code will basically do this:", "// return Proxy.newProxyInstance(", "// arg.getClass().getClassLoader(),", "// new Class[]{parameter},", "// new ConvertedClosure((Closure) arg));", "// TO_REFLECTIVE_PROXY will do that for us, though", "// input is the closure, the method name, the class loader and the ", "// class[]. All of that but the closure must be provided here ", "MethodHandle", "ret", "=", "TO_REFLECTIVE_PROXY", ";", "ret", "=", "MethodHandles", ".", "insertArguments", "(", "ret", ",", "1", ",", "method", ".", "getName", "(", ")", ",", "arg", ".", "getClass", "(", ")", ".", "getClassLoader", "(", ")", ",", "new", "Class", "[", "]", "{", "parameter", "}", ")", ";", "return", "ret", ";", "}", "else", "{", "// the following code will basically do this:", "//Map<String, Object> m = Collections.singletonMap(method.getName(), arg);", "//return ProxyGenerator.INSTANCE.", "// instantiateAggregateFromBaseClass(m, parameter);", "// TO_GENERATED_PROXY is a handle (Object,Object,ProxyGenerator,Class)GroovyObject", "// where the second object is the input closure, everything else", "// needs to be provide and is in remaining order: method name, ", "// ProxyGenerator.INSTANCE and parameter", "MethodHandle", "ret", "=", "TO_GENERATED_PROXY", ";", "ret", "=", "MethodHandles", ".", "insertArguments", "(", "ret", ",", "2", ",", "ProxyGenerator", ".", "INSTANCE", ",", "parameter", ")", ";", "ret", "=", "MethodHandles", ".", "insertArguments", "(", "ret", ",", "0", ",", "method", ".", "getName", "(", ")", ")", ";", "return", "ret", ";", "}", "}" ]
creates a method handle able to transform the given Closure into a SAM type if the given parameter is a SAM type
[ "creates", "a", "method", "handle", "able", "to", "transform", "the", "given", "Closure", "into", "a", "SAM", "type", "if", "the", "given", "parameter", "is", "a", "SAM", "type" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java#L145-L191
13,158
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java
TypeTransformers.selectNumberTransformer
private static MethodHandle selectNumberTransformer(Class param, Object arg) { param = TypeHelper.getWrapperClass(param); if (param == Byte.class) { return TO_BYTE; } else if (param == Character.class || param == Integer.class) { return TO_INT; } else if (param == Long.class) { return TO_LONG; } else if (param == Float.class) { return TO_FLOAT; } else if (param == Double.class) { return TO_DOUBLE; } else if (param == BigInteger.class) { return TO_BIG_INT; } else if (param == BigDecimal.class) { if (arg instanceof Double) { return DOUBLE_TO_BIG_DEC; } else if (arg instanceof Long) { return LONG_TO_BIG_DEC; } else if (arg instanceof BigInteger) { return BIG_INT_TO_BIG_DEC; } else { return DOUBLE_TO_BIG_DEC_WITH_CONVERSION; } } else if (param == Short.class) { return TO_SHORT; } else { return null; } }
java
private static MethodHandle selectNumberTransformer(Class param, Object arg) { param = TypeHelper.getWrapperClass(param); if (param == Byte.class) { return TO_BYTE; } else if (param == Character.class || param == Integer.class) { return TO_INT; } else if (param == Long.class) { return TO_LONG; } else if (param == Float.class) { return TO_FLOAT; } else if (param == Double.class) { return TO_DOUBLE; } else if (param == BigInteger.class) { return TO_BIG_INT; } else if (param == BigDecimal.class) { if (arg instanceof Double) { return DOUBLE_TO_BIG_DEC; } else if (arg instanceof Long) { return LONG_TO_BIG_DEC; } else if (arg instanceof BigInteger) { return BIG_INT_TO_BIG_DEC; } else { return DOUBLE_TO_BIG_DEC_WITH_CONVERSION; } } else if (param == Short.class) { return TO_SHORT; } else { return null; } }
[ "private", "static", "MethodHandle", "selectNumberTransformer", "(", "Class", "param", ",", "Object", "arg", ")", "{", "param", "=", "TypeHelper", ".", "getWrapperClass", "(", "param", ")", ";", "if", "(", "param", "==", "Byte", ".", "class", ")", "{", "return", "TO_BYTE", ";", "}", "else", "if", "(", "param", "==", "Character", ".", "class", "||", "param", "==", "Integer", ".", "class", ")", "{", "return", "TO_INT", ";", "}", "else", "if", "(", "param", "==", "Long", ".", "class", ")", "{", "return", "TO_LONG", ";", "}", "else", "if", "(", "param", "==", "Float", ".", "class", ")", "{", "return", "TO_FLOAT", ";", "}", "else", "if", "(", "param", "==", "Double", ".", "class", ")", "{", "return", "TO_DOUBLE", ";", "}", "else", "if", "(", "param", "==", "BigInteger", ".", "class", ")", "{", "return", "TO_BIG_INT", ";", "}", "else", "if", "(", "param", "==", "BigDecimal", ".", "class", ")", "{", "if", "(", "arg", "instanceof", "Double", ")", "{", "return", "DOUBLE_TO_BIG_DEC", ";", "}", "else", "if", "(", "arg", "instanceof", "Long", ")", "{", "return", "LONG_TO_BIG_DEC", ";", "}", "else", "if", "(", "arg", "instanceof", "BigInteger", ")", "{", "return", "BIG_INT_TO_BIG_DEC", ";", "}", "else", "{", "return", "DOUBLE_TO_BIG_DEC_WITH_CONVERSION", ";", "}", "}", "else", "if", "(", "param", "==", "Short", ".", "class", ")", "{", "return", "TO_SHORT", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
returns a transformer later applied as filter to transform one number into another
[ "returns", "a", "transformer", "later", "applied", "as", "filter", "to", "transform", "one", "number", "into", "another" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeTransformers.java#L211-L241
13,159
apache/groovy
subprojects/groovy-xml/src/main/java/org/codehaus/groovy/runtime/XmlGroovyMethods.java
XmlGroovyMethods.iterator
public static Iterator<Node> iterator(final NodeList nodeList) { return new Iterator<Node>() { private int current /* = 0 */; public boolean hasNext() { return current < nodeList.getLength(); } public Node next() { return nodeList.item(current++); } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a NodeList iterator"); } }; }
java
public static Iterator<Node> iterator(final NodeList nodeList) { return new Iterator<Node>() { private int current /* = 0 */; public boolean hasNext() { return current < nodeList.getLength(); } public Node next() { return nodeList.item(current++); } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a NodeList iterator"); } }; }
[ "public", "static", "Iterator", "<", "Node", ">", "iterator", "(", "final", "NodeList", "nodeList", ")", "{", "return", "new", "Iterator", "<", "Node", ">", "(", ")", "{", "private", "int", "current", "/* = 0 */", ";", "public", "boolean", "hasNext", "(", ")", "{", "return", "current", "<", "nodeList", ".", "getLength", "(", ")", ";", "}", "public", "Node", "next", "(", ")", "{", "return", "nodeList", ".", "item", "(", "current", "++", ")", ";", "}", "public", "void", "remove", "(", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Cannot remove() from a NodeList iterator\"", ")", ";", "}", "}", ";", "}" ]
Makes NodeList iterable by returning a read-only Iterator which traverses over each Node. @param nodeList a NodeList @return an Iterator for a NodeList @since 1.0
[ "Makes", "NodeList", "iterable", "by", "returning", "a", "read", "-", "only", "Iterator", "which", "traverses", "over", "each", "Node", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/org/codehaus/groovy/runtime/XmlGroovyMethods.java#L43-L59
13,160
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
StaticTypesCallSiteWriter.setField
private boolean setField(PropertyExpression expression, Expression objectExpression, ClassNode rType, String name) { if (expression.isSafe()) return false; FieldNode fn = AsmClassGenerator.getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(controller.getClassNode(), rType, name, false); if (fn==null) return false; OperandStack stack = controller.getOperandStack(); stack.doGroovyCast(fn.getType()); MethodVisitor mv = controller.getMethodVisitor(); String ownerName = BytecodeHelper.getClassInternalName(fn.getOwner()); if (!fn.isStatic()) { controller.getCompileStack().pushLHS(false); objectExpression.visit(controller.getAcg()); controller.getCompileStack().popLHS(); if (!rType.equals(stack.getTopOperand())) { BytecodeHelper.doCast(mv, rType); stack.replace(rType); } stack.swap(); mv.visitFieldInsn(PUTFIELD, ownerName, name, BytecodeHelper.getTypeDescription(fn.getType())); stack.remove(1); } else { mv.visitFieldInsn(PUTSTATIC, ownerName, name, BytecodeHelper.getTypeDescription(fn.getType())); } //mv.visitInsn(ACONST_NULL); //stack.replace(OBJECT_TYPE); return true; }
java
private boolean setField(PropertyExpression expression, Expression objectExpression, ClassNode rType, String name) { if (expression.isSafe()) return false; FieldNode fn = AsmClassGenerator.getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(controller.getClassNode(), rType, name, false); if (fn==null) return false; OperandStack stack = controller.getOperandStack(); stack.doGroovyCast(fn.getType()); MethodVisitor mv = controller.getMethodVisitor(); String ownerName = BytecodeHelper.getClassInternalName(fn.getOwner()); if (!fn.isStatic()) { controller.getCompileStack().pushLHS(false); objectExpression.visit(controller.getAcg()); controller.getCompileStack().popLHS(); if (!rType.equals(stack.getTopOperand())) { BytecodeHelper.doCast(mv, rType); stack.replace(rType); } stack.swap(); mv.visitFieldInsn(PUTFIELD, ownerName, name, BytecodeHelper.getTypeDescription(fn.getType())); stack.remove(1); } else { mv.visitFieldInsn(PUTSTATIC, ownerName, name, BytecodeHelper.getTypeDescription(fn.getType())); } //mv.visitInsn(ACONST_NULL); //stack.replace(OBJECT_TYPE); return true; }
[ "private", "boolean", "setField", "(", "PropertyExpression", "expression", ",", "Expression", "objectExpression", ",", "ClassNode", "rType", ",", "String", "name", ")", "{", "if", "(", "expression", ".", "isSafe", "(", ")", ")", "return", "false", ";", "FieldNode", "fn", "=", "AsmClassGenerator", ".", "getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper", "(", "controller", ".", "getClassNode", "(", ")", ",", "rType", ",", "name", ",", "false", ")", ";", "if", "(", "fn", "==", "null", ")", "return", "false", ";", "OperandStack", "stack", "=", "controller", ".", "getOperandStack", "(", ")", ";", "stack", ".", "doGroovyCast", "(", "fn", ".", "getType", "(", ")", ")", ";", "MethodVisitor", "mv", "=", "controller", ".", "getMethodVisitor", "(", ")", ";", "String", "ownerName", "=", "BytecodeHelper", ".", "getClassInternalName", "(", "fn", ".", "getOwner", "(", ")", ")", ";", "if", "(", "!", "fn", ".", "isStatic", "(", ")", ")", "{", "controller", ".", "getCompileStack", "(", ")", ".", "pushLHS", "(", "false", ")", ";", "objectExpression", ".", "visit", "(", "controller", ".", "getAcg", "(", ")", ")", ";", "controller", ".", "getCompileStack", "(", ")", ".", "popLHS", "(", ")", ";", "if", "(", "!", "rType", ".", "equals", "(", "stack", ".", "getTopOperand", "(", ")", ")", ")", "{", "BytecodeHelper", ".", "doCast", "(", "mv", ",", "rType", ")", ";", "stack", ".", "replace", "(", "rType", ")", ";", "}", "stack", ".", "swap", "(", ")", ";", "mv", ".", "visitFieldInsn", "(", "PUTFIELD", ",", "ownerName", ",", "name", ",", "BytecodeHelper", ".", "getTypeDescription", "(", "fn", ".", "getType", "(", ")", ")", ")", ";", "stack", ".", "remove", "(", "1", ")", ";", "}", "else", "{", "mv", ".", "visitFieldInsn", "(", "PUTSTATIC", ",", "ownerName", ",", "name", ",", "BytecodeHelper", ".", "getTypeDescription", "(", "fn", ".", "getType", "(", ")", ")", ")", ";", "}", "//mv.visitInsn(ACONST_NULL);", "//stack.replace(OBJECT_TYPE);", "return", "true", ";", "}" ]
this is just a simple set field handling static and non-static, but not Closure and inner classes
[ "this", "is", "just", "a", "simple", "set", "field", "handling", "static", "and", "non", "-", "static", "but", "not", "Closure", "and", "inner", "classes" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java#L902-L929
13,161
apache/groovy
src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java
ManagedConcurrentLinkedQueue.add
public void add(T value) { Element<T> e = new Element<T>(value); queue.offer(e); }
java
public void add(T value) { Element<T> e = new Element<T>(value); queue.offer(e); }
[ "public", "void", "add", "(", "T", "value", ")", "{", "Element", "<", "T", ">", "e", "=", "new", "Element", "<", "T", ">", "(", "value", ")", ";", "queue", ".", "offer", "(", "e", ")", ";", "}" ]
Adds the specified value to the queue. @param value the value to add
[ "Adds", "the", "specified", "value", "to", "the", "queue", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java#L61-L64
13,162
apache/groovy
src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java
ManagedConcurrentLinkedQueue.values
public List<T> values() { List<T> result = new ArrayList<T>(); for (Iterator<T> itr = iterator(); itr.hasNext(); ) { result.add(itr.next()); } return result; }
java
public List<T> values() { List<T> result = new ArrayList<T>(); for (Iterator<T> itr = iterator(); itr.hasNext(); ) { result.add(itr.next()); } return result; }
[ "public", "List", "<", "T", ">", "values", "(", ")", "{", "List", "<", "T", ">", "result", "=", "new", "ArrayList", "<", "T", ">", "(", ")", ";", "for", "(", "Iterator", "<", "T", ">", "itr", "=", "iterator", "(", ")", ";", "itr", ".", "hasNext", "(", ")", ";", ")", "{", "result", ".", "add", "(", "itr", ".", "next", "(", ")", ")", ";", "}", "return", "result", ";", "}" ]
Returns a list containing all values from this queue in the sequence they were added.
[ "Returns", "a", "list", "containing", "all", "values", "from", "this", "queue", "in", "the", "sequence", "they", "were", "added", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java#L92-L98
13,163
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionWriter.java
BinaryExpressionWriter.writeBitwiseOp
protected boolean writeBitwiseOp(int type, boolean simulate) { type = type-BITWISE_OR; if (type<0 || type>2) return false; if (!simulate) { int bytecode = getBitwiseOperationBytecode(type); controller.getMethodVisitor().visitInsn(bytecode); controller.getOperandStack().replace(getNormalOpResultType(), 2); } return true; }
java
protected boolean writeBitwiseOp(int type, boolean simulate) { type = type-BITWISE_OR; if (type<0 || type>2) return false; if (!simulate) { int bytecode = getBitwiseOperationBytecode(type); controller.getMethodVisitor().visitInsn(bytecode); controller.getOperandStack().replace(getNormalOpResultType(), 2); } return true; }
[ "protected", "boolean", "writeBitwiseOp", "(", "int", "type", ",", "boolean", "simulate", ")", "{", "type", "=", "type", "-", "BITWISE_OR", ";", "if", "(", "type", "<", "0", "||", "type", ">", "2", ")", "return", "false", ";", "if", "(", "!", "simulate", ")", "{", "int", "bytecode", "=", "getBitwiseOperationBytecode", "(", "type", ")", ";", "controller", ".", "getMethodVisitor", "(", ")", ".", "visitInsn", "(", "bytecode", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "replace", "(", "getNormalOpResultType", "(", ")", ",", "2", ")", ";", "}", "return", "true", ";", "}" ]
writes some the bitwise operations. type is one of BITWISE_OR, BITWISE_AND, BITWISE_XOR @param type the token type @return true if a successful bitwise operation write
[ "writes", "some", "the", "bitwise", "operations", ".", "type", "is", "one", "of", "BITWISE_OR", "BITWISE_AND", "BITWISE_XOR" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionWriter.java#L238-L248
13,164
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionWriter.java
BinaryExpressionWriter.writeShiftOp
protected boolean writeShiftOp(int type, boolean simulate) { type = type - LEFT_SHIFT; if (type < 0 || type > 2) return false; if (!simulate) { int bytecode = getShiftOperationBytecode(type); controller.getMethodVisitor().visitInsn(bytecode); controller.getOperandStack().replace(getNormalOpResultType(), 2); } return true; }
java
protected boolean writeShiftOp(int type, boolean simulate) { type = type - LEFT_SHIFT; if (type < 0 || type > 2) return false; if (!simulate) { int bytecode = getShiftOperationBytecode(type); controller.getMethodVisitor().visitInsn(bytecode); controller.getOperandStack().replace(getNormalOpResultType(), 2); } return true; }
[ "protected", "boolean", "writeShiftOp", "(", "int", "type", ",", "boolean", "simulate", ")", "{", "type", "=", "type", "-", "LEFT_SHIFT", ";", "if", "(", "type", "<", "0", "||", "type", ">", "2", ")", "return", "false", ";", "if", "(", "!", "simulate", ")", "{", "int", "bytecode", "=", "getShiftOperationBytecode", "(", "type", ")", ";", "controller", ".", "getMethodVisitor", "(", ")", ".", "visitInsn", "(", "bytecode", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "replace", "(", "getNormalOpResultType", "(", ")", ",", "2", ")", ";", "}", "return", "true", ";", "}" ]
Write shifting operations. Type is one of LEFT_SHIFT, RIGHT_SHIFT, or RIGHT_SHIFT_UNSIGNED @param type the token type @return true on a successful shift operation write
[ "Write", "shifting", "operations", ".", "Type", "is", "one", "of", "LEFT_SHIFT", "RIGHT_SHIFT", "or", "RIGHT_SHIFT_UNSIGNED" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionWriter.java#L259-L269
13,165
apache/groovy
subprojects/groovy-jmx/src/main/java/groovy/jmx/builder/JmxEventListener.java
JmxEventListener.handleNotification
public void handleNotification(Notification notification, Object handback) { Map event = (Map) handback; if (event != null) { Object del = event.get("managedObject"); Object callback = event.get("callback"); if (callback != null && callback instanceof Closure) { Closure closure = (Closure) callback; closure.setDelegate(del); if (closure.getMaximumNumberOfParameters() == 1) closure.call(buildOperationNotificationPacket(notification)); else closure.call(); } } }
java
public void handleNotification(Notification notification, Object handback) { Map event = (Map) handback; if (event != null) { Object del = event.get("managedObject"); Object callback = event.get("callback"); if (callback != null && callback instanceof Closure) { Closure closure = (Closure) callback; closure.setDelegate(del); if (closure.getMaximumNumberOfParameters() == 1) closure.call(buildOperationNotificationPacket(notification)); else closure.call(); } } }
[ "public", "void", "handleNotification", "(", "Notification", "notification", ",", "Object", "handback", ")", "{", "Map", "event", "=", "(", "Map", ")", "handback", ";", "if", "(", "event", "!=", "null", ")", "{", "Object", "del", "=", "event", ".", "get", "(", "\"managedObject\"", ")", ";", "Object", "callback", "=", "event", ".", "get", "(", "\"callback\"", ")", ";", "if", "(", "callback", "!=", "null", "&&", "callback", "instanceof", "Closure", ")", "{", "Closure", "closure", "=", "(", "Closure", ")", "callback", ";", "closure", ".", "setDelegate", "(", "del", ")", ";", "if", "(", "closure", ".", "getMaximumNumberOfParameters", "(", ")", "==", "1", ")", "closure", ".", "call", "(", "buildOperationNotificationPacket", "(", "notification", ")", ")", ";", "else", "closure", ".", "call", "(", ")", ";", "}", "}", "}" ]
This is the implemented method for NotificationListener. It is called by an event emitter to dispatch JMX events to listeners. Here it handles internal JmxBuilder events. @param notification the notification object passed to closure used to handle JmxBuilder events. @param handback - In this case, the handback is the closure to execute when the event is handled.
[ "This", "is", "the", "implemented", "method", "for", "NotificationListener", ".", "It", "is", "called", "by", "an", "event", "emitter", "to", "dispatch", "JMX", "events", "to", "listeners", ".", "Here", "it", "handles", "internal", "JmxBuilder", "events", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-jmx/src/main/java/groovy/jmx/builder/JmxEventListener.java#L56-L69
13,166
apache/groovy
src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java
ExtendedVerifier.visitAnnotation
private AnnotationNode visitAnnotation(AnnotationNode unvisited) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); AnnotationNode visited = visitor.visit(unvisited); this.source.getErrorCollector().addCollectorContents(errorCollector); return visited; }
java
private AnnotationNode visitAnnotation(AnnotationNode unvisited) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); AnnotationNode visited = visitor.visit(unvisited); this.source.getErrorCollector().addCollectorContents(errorCollector); return visited; }
[ "private", "AnnotationNode", "visitAnnotation", "(", "AnnotationNode", "unvisited", ")", "{", "ErrorCollector", "errorCollector", "=", "new", "ErrorCollector", "(", "this", ".", "source", ".", "getConfiguration", "(", ")", ")", ";", "AnnotationVisitor", "visitor", "=", "new", "AnnotationVisitor", "(", "this", ".", "source", ",", "errorCollector", ")", ";", "AnnotationNode", "visited", "=", "visitor", ".", "visit", "(", "unvisited", ")", ";", "this", ".", "source", ".", "getErrorCollector", "(", ")", ".", "addCollectorContents", "(", "errorCollector", ")", ";", "return", "visited", ";", "}" ]
Resolve metadata and details of the annotation. @param unvisited the node to visit @return the visited node
[ "Resolve", "metadata", "and", "details", "of", "the", "annotation", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java#L323-L329
13,167
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.setClasspath
public void setClasspath(String classpath) { this.classpath = new LinkedList<String>(); StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { this.classpath.add(tokenizer.nextToken()); } }
java
public void setClasspath(String classpath) { this.classpath = new LinkedList<String>(); StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { this.classpath.add(tokenizer.nextToken()); } }
[ "public", "void", "setClasspath", "(", "String", "classpath", ")", "{", "this", ".", "classpath", "=", "new", "LinkedList", "<", "String", ">", "(", ")", ";", "StringTokenizer", "tokenizer", "=", "new", "StringTokenizer", "(", "classpath", ",", "File", ".", "pathSeparator", ")", ";", "while", "(", "tokenizer", ".", "hasMoreTokens", "(", ")", ")", "{", "this", ".", "classpath", ".", "add", "(", "tokenizer", ".", "nextToken", "(", ")", ")", ";", "}", "}" ]
Sets the classpath.
[ "Sets", "the", "classpath", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L818-L824
13,168
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.setOptimizationOptions
public void setOptimizationOptions(Map<String, Boolean> options) { if (options == null) throw new IllegalArgumentException("provided option map must not be null"); optimizationOptions = options; }
java
public void setOptimizationOptions(Map<String, Boolean> options) { if (options == null) throw new IllegalArgumentException("provided option map must not be null"); optimizationOptions = options; }
[ "public", "void", "setOptimizationOptions", "(", "Map", "<", "String", ",", "Boolean", ">", "options", ")", "{", "if", "(", "options", "==", "null", ")", "throw", "new", "IllegalArgumentException", "(", "\"provided option map must not be null\"", ")", ";", "optimizationOptions", "=", "options", ";", "}" ]
Sets the optimization options for this configuration. No entry or a true for that entry means to enable that optimization, a false means the optimization is disabled. Valid keys are "all" and "int". @param options the options. @throws IllegalArgumentException if the options are null
[ "Sets", "the", "optimization", "options", "for", "this", "configuration", ".", "No", "entry", "or", "a", "true", "for", "that", "entry", "means", "to", "enable", "that", "optimization", "a", "false", "means", "the", "optimization", "is", "disabled", ".", "Valid", "keys", "are", "all", "and", "int", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1047-L1050
13,169
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.addCompilationCustomizers
public CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers) { if (customizers == null) throw new IllegalArgumentException("provided customizers list must not be null"); compilationCustomizers.addAll(Arrays.asList(customizers)); return this; }
java
public CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers) { if (customizers == null) throw new IllegalArgumentException("provided customizers list must not be null"); compilationCustomizers.addAll(Arrays.asList(customizers)); return this; }
[ "public", "CompilerConfiguration", "addCompilationCustomizers", "(", "CompilationCustomizer", "...", "customizers", ")", "{", "if", "(", "customizers", "==", "null", ")", "throw", "new", "IllegalArgumentException", "(", "\"provided customizers list must not be null\"", ")", ";", "compilationCustomizers", ".", "addAll", "(", "Arrays", ".", "asList", "(", "customizers", ")", ")", ";", "return", "this", ";", "}" ]
Adds compilation customizers to the compilation process. A compilation customizer is a class node operation which performs various operations going from adding imports to access control. @param customizers the list of customizers to be added @return this configuration instance
[ "Adds", "compilation", "customizers", "to", "the", "compilation", "process", ".", "A", "compilation", "customizer", "is", "a", "class", "node", "operation", "which", "performs", "various", "operations", "going", "from", "adding", "imports", "to", "access", "control", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1058-L1062
13,170
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.isIndyEnabled
public boolean isIndyEnabled() { Boolean indyEnabled = this.getOptimizationOptions().get(INVOKEDYNAMIC); if (null == indyEnabled) { return false; } return indyEnabled; }
java
public boolean isIndyEnabled() { Boolean indyEnabled = this.getOptimizationOptions().get(INVOKEDYNAMIC); if (null == indyEnabled) { return false; } return indyEnabled; }
[ "public", "boolean", "isIndyEnabled", "(", ")", "{", "Boolean", "indyEnabled", "=", "this", ".", "getOptimizationOptions", "(", ")", ".", "get", "(", "INVOKEDYNAMIC", ")", ";", "if", "(", "null", "==", "indyEnabled", ")", "{", "return", "false", ";", "}", "return", "indyEnabled", ";", "}" ]
Check whether invoke dynamic enabled @return the result
[ "Check", "whether", "invoke", "dynamic", "enabled" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1118-L1126
13,171
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.isGroovydocEnabled
public boolean isGroovydocEnabled() { Boolean groovydocEnabled = this.getOptimizationOptions().get(GROOVYDOC); if (null == groovydocEnabled) { return false; } return groovydocEnabled; }
java
public boolean isGroovydocEnabled() { Boolean groovydocEnabled = this.getOptimizationOptions().get(GROOVYDOC); if (null == groovydocEnabled) { return false; } return groovydocEnabled; }
[ "public", "boolean", "isGroovydocEnabled", "(", ")", "{", "Boolean", "groovydocEnabled", "=", "this", ".", "getOptimizationOptions", "(", ")", ".", "get", "(", "GROOVYDOC", ")", ";", "if", "(", "null", "==", "groovydocEnabled", ")", "{", "return", "false", ";", "}", "return", "groovydocEnabled", ";", "}" ]
Check whether groovydoc enabled @return the result
[ "Check", "whether", "groovydoc", "enabled" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1132-L1140
13,172
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.isRuntimeGroovydocEnabled
public boolean isRuntimeGroovydocEnabled() { Boolean runtimeGroovydocEnabled = this.getOptimizationOptions().get(RUNTIME_GROOVYDOC); if (null == runtimeGroovydocEnabled) { return false; } return runtimeGroovydocEnabled; }
java
public boolean isRuntimeGroovydocEnabled() { Boolean runtimeGroovydocEnabled = this.getOptimizationOptions().get(RUNTIME_GROOVYDOC); if (null == runtimeGroovydocEnabled) { return false; } return runtimeGroovydocEnabled; }
[ "public", "boolean", "isRuntimeGroovydocEnabled", "(", ")", "{", "Boolean", "runtimeGroovydocEnabled", "=", "this", ".", "getOptimizationOptions", "(", ")", ".", "get", "(", "RUNTIME_GROOVYDOC", ")", ";", "if", "(", "null", "==", "runtimeGroovydocEnabled", ")", "{", "return", "false", ";", "}", "return", "runtimeGroovydocEnabled", ";", "}" ]
Check whether runtime groovydoc enabled @return the result
[ "Check", "whether", "runtime", "groovydoc", "enabled" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1146-L1154
13,173
apache/groovy
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.isMemStubEnabled
public boolean isMemStubEnabled() { Object memStubEnabled = this.getJointCompilationOptions().get(MEM_STUB); if (null == memStubEnabled) { return false; } return "true".equals(memStubEnabled.toString()); }
java
public boolean isMemStubEnabled() { Object memStubEnabled = this.getJointCompilationOptions().get(MEM_STUB); if (null == memStubEnabled) { return false; } return "true".equals(memStubEnabled.toString()); }
[ "public", "boolean", "isMemStubEnabled", "(", ")", "{", "Object", "memStubEnabled", "=", "this", ".", "getJointCompilationOptions", "(", ")", ".", "get", "(", "MEM_STUB", ")", ";", "if", "(", "null", "==", "memStubEnabled", ")", "{", "return", "false", ";", "}", "return", "\"true\"", ".", "equals", "(", "memStubEnabled", ".", "toString", "(", ")", ")", ";", "}" ]
Check whether mem stub enabled @return the result
[ "Check", "whether", "mem", "stub", "enabled" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java#L1160-L1168
13,174
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java
LRUCache.cleanUpNullReferences
public void cleanUpNullReferences() { synchronized (map) { final Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<K, V> entry = iterator.next(); final Object value = entry.getValue(); if (!(value instanceof SoftReference)) continue; if (((SoftReference) value).get() == null) iterator.remove(); } } }
java
public void cleanUpNullReferences() { synchronized (map) { final Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<K, V> entry = iterator.next(); final Object value = entry.getValue(); if (!(value instanceof SoftReference)) continue; if (((SoftReference) value).get() == null) iterator.remove(); } } }
[ "public", "void", "cleanUpNullReferences", "(", ")", "{", "synchronized", "(", "map", ")", "{", "final", "Iterator", "<", "Map", ".", "Entry", "<", "K", ",", "V", ">", ">", "iterator", "=", "map", ".", "entrySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "iterator", ".", "hasNext", "(", ")", ")", "{", "final", "Map", ".", "Entry", "<", "K", ",", "V", ">", "entry", "=", "iterator", ".", "next", "(", ")", ";", "final", "Object", "value", "=", "entry", ".", "getValue", "(", ")", ";", "if", "(", "!", "(", "value", "instanceof", "SoftReference", ")", ")", "continue", ";", "if", "(", "(", "(", "SoftReference", ")", "value", ")", ".", "get", "(", ")", "==", "null", ")", "iterator", ".", "remove", "(", ")", ";", "}", "}", "}" ]
Remove all entries holding SoftReferences to gc-evicted objects.
[ "Remove", "all", "entries", "holding", "SoftReferences", "to", "gc", "-", "evicted", "objects", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java#L69-L80
13,175
apache/groovy
subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java
GroovyEngine.apply
public Object apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments) throws BSFException { Object object = eval(source, lineNo, columnNo, funcBody); if (object instanceof Closure) { // lets call the function Closure closure = (Closure) object; return closure.call(arguments.toArray()); } return object; }
java
public Object apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments) throws BSFException { Object object = eval(source, lineNo, columnNo, funcBody); if (object instanceof Closure) { // lets call the function Closure closure = (Closure) object; return closure.call(arguments.toArray()); } return object; }
[ "public", "Object", "apply", "(", "String", "source", ",", "int", "lineNo", ",", "int", "columnNo", ",", "Object", "funcBody", ",", "Vector", "paramNames", ",", "Vector", "arguments", ")", "throws", "BSFException", "{", "Object", "object", "=", "eval", "(", "source", ",", "lineNo", ",", "columnNo", ",", "funcBody", ")", ";", "if", "(", "object", "instanceof", "Closure", ")", "{", "// lets call the function", "Closure", "closure", "=", "(", "Closure", ")", "object", ";", "return", "closure", ".", "call", "(", "arguments", ".", "toArray", "(", ")", ")", ";", "}", "return", "object", ";", "}" ]
Allow an anonymous function to be declared and invoked
[ "Allow", "an", "anonymous", "function", "to", "be", "declared", "and", "invoked" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java#L72-L81
13,176
apache/groovy
subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java
GroovyEngine.call
public Object call(Object object, String method, Object[] args) throws BSFException { return InvokerHelper.invokeMethod(object, method, args); }
java
public Object call(Object object, String method, Object[] args) throws BSFException { return InvokerHelper.invokeMethod(object, method, args); }
[ "public", "Object", "call", "(", "Object", "object", ",", "String", "method", ",", "Object", "[", "]", "args", ")", "throws", "BSFException", "{", "return", "InvokerHelper", ".", "invokeMethod", "(", "object", ",", "method", ",", "args", ")", ";", "}" ]
Call the named method of the given object.
[ "Call", "the", "named", "method", "of", "the", "given", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java#L86-L88
13,177
apache/groovy
subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java
GroovyEngine.declareBean
public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
java
public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
[ "public", "void", "declareBean", "(", "BSFDeclaredBean", "bean", ")", "throws", "BSFException", "{", "shell", ".", "setVariable", "(", "bean", ".", "name", ",", "bean", ".", "bean", ")", ";", "}" ]
Declare a bean
[ "Declare", "a", "bean" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java#L136-L138
13,178
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
InvocationWriter.getMatchingConstructor
private static ConstructorNode getMatchingConstructor(List<ConstructorNode> constructors, List<Expression> argumentList) { ConstructorNode lastMatch = null; for (int i=0; i<constructors.size(); i++) { ConstructorNode cn = constructors.get(i); Parameter[] params = cn.getParameters(); // if number of parameters does not match we have no match if (argumentList.size()!=params.length) continue; if (lastMatch==null) { lastMatch = cn; } else { // we already had a match so we don't make a direct call at all return null; } } return lastMatch; }
java
private static ConstructorNode getMatchingConstructor(List<ConstructorNode> constructors, List<Expression> argumentList) { ConstructorNode lastMatch = null; for (int i=0; i<constructors.size(); i++) { ConstructorNode cn = constructors.get(i); Parameter[] params = cn.getParameters(); // if number of parameters does not match we have no match if (argumentList.size()!=params.length) continue; if (lastMatch==null) { lastMatch = cn; } else { // we already had a match so we don't make a direct call at all return null; } } return lastMatch; }
[ "private", "static", "ConstructorNode", "getMatchingConstructor", "(", "List", "<", "ConstructorNode", ">", "constructors", ",", "List", "<", "Expression", ">", "argumentList", ")", "{", "ConstructorNode", "lastMatch", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "constructors", ".", "size", "(", ")", ";", "i", "++", ")", "{", "ConstructorNode", "cn", "=", "constructors", ".", "get", "(", "i", ")", ";", "Parameter", "[", "]", "params", "=", "cn", ".", "getParameters", "(", ")", ";", "// if number of parameters does not match we have no match", "if", "(", "argumentList", ".", "size", "(", ")", "!=", "params", ".", "length", ")", "continue", ";", "if", "(", "lastMatch", "==", "null", ")", "{", "lastMatch", "=", "cn", ";", "}", "else", "{", "// we already had a match so we don't make a direct call at all", "return", "null", ";", "}", "}", "return", "lastMatch", ";", "}" ]
we match only on the number of arguments, not anything else
[ "we", "match", "only", "on", "the", "number", "of", "arguments", "not", "anything", "else" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java#L910-L925
13,179
apache/groovy
src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberPlus.java
NumberNumberPlus.plus
public static Number plus(Number left, Number right) { return NumberMath.add(left, right); }
java
public static Number plus(Number left, Number right) { return NumberMath.add(left, right); }
[ "public", "static", "Number", "plus", "(", "Number", "left", ",", "Number", "right", ")", "{", "return", "NumberMath", ".", "add", "(", "left", ",", "right", ")", ";", "}" ]
Add two numbers and return the result. @param left a Number @param right another Number to add @return the addition of both Numbers
[ "Add", "two", "numbers", "and", "return", "the", "result", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberPlus.java#L42-L44
13,180
apache/groovy
src/main/groovy/groovy/lang/Sequence.java
Sequence.checkType
protected void checkType(Object object) { if (object == null) { throw new NullPointerException("Sequences cannot contain null, use a List instead"); } if (type != null) { if (!type.isInstance(object)) { throw new IllegalArgumentException( "Invalid type of argument for sequence of type: " + type.getName() + " cannot add object: " + object); } } }
java
protected void checkType(Object object) { if (object == null) { throw new NullPointerException("Sequences cannot contain null, use a List instead"); } if (type != null) { if (!type.isInstance(object)) { throw new IllegalArgumentException( "Invalid type of argument for sequence of type: " + type.getName() + " cannot add object: " + object); } } }
[ "protected", "void", "checkType", "(", "Object", "object", ")", "{", "if", "(", "object", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", "\"Sequences cannot contain null, use a List instead\"", ")", ";", "}", "if", "(", "type", "!=", "null", ")", "{", "if", "(", "!", "type", ".", "isInstance", "(", "object", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid type of argument for sequence of type: \"", "+", "type", ".", "getName", "(", ")", "+", "\" cannot add object: \"", "+", "object", ")", ";", "}", "}", "}" ]
Checks that the given object instance is of the correct type otherwise a runtime exception is thrown
[ "Checks", "that", "the", "given", "object", "instance", "is", "of", "the", "correct", "type", "otherwise", "a", "runtime", "exception", "is", "thrown" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Sequence.java#L203-L216
13,181
apache/groovy
src/main/java/org/codehaus/groovy/antlr/treewalker/SourcePrinter.java
SourcePrinter.visitType
public void visitType(GroovySourceAST t,int visit) { GroovySourceAST parent = getParentNode(); GroovySourceAST modifiers = parent.childOfType(GroovyTokenTypes.MODIFIERS); // No need to print 'def' if we already have some modifiers if (modifiers == null || modifiers.getNumberOfChildren() == 0) { if (visit == OPENING_VISIT) { if (t.getNumberOfChildren() == 0 && parent.getType() != GroovyTokenTypes.PARAMETER_DEF) { // no need for 'def' if in a parameter list print(t,visit,"def"); } } if (visit == CLOSING_VISIT) { if ( parent.getType() == GroovyTokenTypes.VARIABLE_DEF || parent.getType() == GroovyTokenTypes.METHOD_DEF || parent.getType() == GroovyTokenTypes.ANNOTATION_FIELD_DEF || (parent.getType() == GroovyTokenTypes.PARAMETER_DEF && t.getNumberOfChildren()!=0)) { print(t,visit," "); } } /*if (visit == CLOSING_VISIT) { print(t,visit," "); }*/ } else { if (visit == CLOSING_VISIT) { if (t.getNumberOfChildren() != 0) { print(t,visit," "); } } } }
java
public void visitType(GroovySourceAST t,int visit) { GroovySourceAST parent = getParentNode(); GroovySourceAST modifiers = parent.childOfType(GroovyTokenTypes.MODIFIERS); // No need to print 'def' if we already have some modifiers if (modifiers == null || modifiers.getNumberOfChildren() == 0) { if (visit == OPENING_VISIT) { if (t.getNumberOfChildren() == 0 && parent.getType() != GroovyTokenTypes.PARAMETER_DEF) { // no need for 'def' if in a parameter list print(t,visit,"def"); } } if (visit == CLOSING_VISIT) { if ( parent.getType() == GroovyTokenTypes.VARIABLE_DEF || parent.getType() == GroovyTokenTypes.METHOD_DEF || parent.getType() == GroovyTokenTypes.ANNOTATION_FIELD_DEF || (parent.getType() == GroovyTokenTypes.PARAMETER_DEF && t.getNumberOfChildren()!=0)) { print(t,visit," "); } } /*if (visit == CLOSING_VISIT) { print(t,visit," "); }*/ } else { if (visit == CLOSING_VISIT) { if (t.getNumberOfChildren() != 0) { print(t,visit," "); } } } }
[ "public", "void", "visitType", "(", "GroovySourceAST", "t", ",", "int", "visit", ")", "{", "GroovySourceAST", "parent", "=", "getParentNode", "(", ")", ";", "GroovySourceAST", "modifiers", "=", "parent", ".", "childOfType", "(", "GroovyTokenTypes", ".", "MODIFIERS", ")", ";", "// No need to print 'def' if we already have some modifiers", "if", "(", "modifiers", "==", "null", "||", "modifiers", ".", "getNumberOfChildren", "(", ")", "==", "0", ")", "{", "if", "(", "visit", "==", "OPENING_VISIT", ")", "{", "if", "(", "t", ".", "getNumberOfChildren", "(", ")", "==", "0", "&&", "parent", ".", "getType", "(", ")", "!=", "GroovyTokenTypes", ".", "PARAMETER_DEF", ")", "{", "// no need for 'def' if in a parameter list", "print", "(", "t", ",", "visit", ",", "\"def\"", ")", ";", "}", "}", "if", "(", "visit", "==", "CLOSING_VISIT", ")", "{", "if", "(", "parent", ".", "getType", "(", ")", "==", "GroovyTokenTypes", ".", "VARIABLE_DEF", "||", "parent", ".", "getType", "(", ")", "==", "GroovyTokenTypes", ".", "METHOD_DEF", "||", "parent", ".", "getType", "(", ")", "==", "GroovyTokenTypes", ".", "ANNOTATION_FIELD_DEF", "||", "(", "parent", ".", "getType", "(", ")", "==", "GroovyTokenTypes", ".", "PARAMETER_DEF", "&&", "t", ".", "getNumberOfChildren", "(", ")", "!=", "0", ")", ")", "{", "print", "(", "t", ",", "visit", ",", "\" \"", ")", ";", "}", "}", "/*if (visit == CLOSING_VISIT) {\n print(t,visit,\" \");\n }*/", "}", "else", "{", "if", "(", "visit", "==", "CLOSING_VISIT", ")", "{", "if", "(", "t", ".", "getNumberOfChildren", "(", ")", "!=", "0", ")", "{", "print", "(", "t", ",", "visit", ",", "\" \"", ")", ";", "}", "}", "}", "}" ]
visit TripleDot, not used in the AST
[ "visit", "TripleDot", "not", "used", "in", "the", "AST" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/treewalker/SourcePrinter.java#L920-L953
13,182
apache/groovy
src/main/java/org/codehaus/groovy/antlr/treewalker/SourcePrinter.java
SourcePrinter.visitDefault
public void visitDefault(GroovySourceAST t,int visit) { if (visit == OPENING_VISIT) { print(t,visit,"<" + tokenNames[t.getType()] + ">"); //out.print("<" + t.getType() + ">"); } else { print(t,visit,"</" + tokenNames[t.getType()] + ">"); //out.print("</" + t.getType() + ">"); } }
java
public void visitDefault(GroovySourceAST t,int visit) { if (visit == OPENING_VISIT) { print(t,visit,"<" + tokenNames[t.getType()] + ">"); //out.print("<" + t.getType() + ">"); } else { print(t,visit,"</" + tokenNames[t.getType()] + ">"); //out.print("</" + t.getType() + ">"); } }
[ "public", "void", "visitDefault", "(", "GroovySourceAST", "t", ",", "int", "visit", ")", "{", "if", "(", "visit", "==", "OPENING_VISIT", ")", "{", "print", "(", "t", ",", "visit", ",", "\"<\"", "+", "tokenNames", "[", "t", ".", "getType", "(", ")", "]", "+", "\">\"", ")", ";", "//out.print(\"<\" + t.getType() + \">\");", "}", "else", "{", "print", "(", "t", ",", "visit", ",", "\"</\"", "+", "tokenNames", "[", "t", ".", "getType", "(", ")", "]", "+", "\">\"", ")", ";", "//out.print(\"</\" + t.getType() + \">\");", "}", "}" ]
visit WS - only used by lexer
[ "visit", "WS", "-", "only", "used", "by", "lexer" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/treewalker/SourcePrinter.java#L1007-L1015
13,183
apache/groovy
src/main/java/org/codehaus/groovy/reflection/ParameterTypes.java
ParameterTypes.fitToVargs
private static Object[] fitToVargs(Object[] argumentArrayOrig, CachedClass[] paramTypes) { Class vargsClassOrig = paramTypes[paramTypes.length - 1].getTheClass().getComponentType(); Class vargsClass = ReflectionCache.autoboxType(vargsClassOrig); Object[] argumentArray = argumentArrayOrig.clone(); MetaClassHelper.unwrap(argumentArray); if (argumentArray.length == paramTypes.length - 1) { // the vargs argument is missing, so fill it with an empty array Object[] newArgs = new Object[paramTypes.length]; System.arraycopy(argumentArray, 0, newArgs, 0, argumentArray.length); Object vargs = Array.newInstance(vargsClass, 0); newArgs[newArgs.length - 1] = vargs; return newArgs; } else if (argumentArray.length == paramTypes.length) { // the number of arguments is correct, but if the last argument // is no array we have to wrap it in a array. If the last argument // is null, then we don't have to do anything Object lastArgument = argumentArray[argumentArray.length - 1]; if (lastArgument != null && !lastArgument.getClass().isArray()) { // no array so wrap it Object wrapped = makeCommonArray(argumentArray, paramTypes.length - 1, vargsClass); Object[] newArgs = new Object[paramTypes.length]; System.arraycopy(argumentArray, 0, newArgs, 0, paramTypes.length - 1); newArgs[newArgs.length - 1] = wrapped; return newArgs; } else { // we may have to box the argument! return argumentArray; } } else if (argumentArray.length > paramTypes.length) { // the number of arguments is too big, wrap all exceeding elements // in an array, but keep the old elements that are no vargs Object[] newArgs = new Object[paramTypes.length]; // copy arguments that are not a varg System.arraycopy(argumentArray, 0, newArgs, 0, paramTypes.length - 1); // create a new array for the vargs and copy them Object vargs = makeCommonArray(argumentArray, paramTypes.length - 1, vargsClass); newArgs[newArgs.length - 1] = vargs; return newArgs; } else { throw new GroovyBugError("trying to call a vargs method without enough arguments"); } }
java
private static Object[] fitToVargs(Object[] argumentArrayOrig, CachedClass[] paramTypes) { Class vargsClassOrig = paramTypes[paramTypes.length - 1].getTheClass().getComponentType(); Class vargsClass = ReflectionCache.autoboxType(vargsClassOrig); Object[] argumentArray = argumentArrayOrig.clone(); MetaClassHelper.unwrap(argumentArray); if (argumentArray.length == paramTypes.length - 1) { // the vargs argument is missing, so fill it with an empty array Object[] newArgs = new Object[paramTypes.length]; System.arraycopy(argumentArray, 0, newArgs, 0, argumentArray.length); Object vargs = Array.newInstance(vargsClass, 0); newArgs[newArgs.length - 1] = vargs; return newArgs; } else if (argumentArray.length == paramTypes.length) { // the number of arguments is correct, but if the last argument // is no array we have to wrap it in a array. If the last argument // is null, then we don't have to do anything Object lastArgument = argumentArray[argumentArray.length - 1]; if (lastArgument != null && !lastArgument.getClass().isArray()) { // no array so wrap it Object wrapped = makeCommonArray(argumentArray, paramTypes.length - 1, vargsClass); Object[] newArgs = new Object[paramTypes.length]; System.arraycopy(argumentArray, 0, newArgs, 0, paramTypes.length - 1); newArgs[newArgs.length - 1] = wrapped; return newArgs; } else { // we may have to box the argument! return argumentArray; } } else if (argumentArray.length > paramTypes.length) { // the number of arguments is too big, wrap all exceeding elements // in an array, but keep the old elements that are no vargs Object[] newArgs = new Object[paramTypes.length]; // copy arguments that are not a varg System.arraycopy(argumentArray, 0, newArgs, 0, paramTypes.length - 1); // create a new array for the vargs and copy them Object vargs = makeCommonArray(argumentArray, paramTypes.length - 1, vargsClass); newArgs[newArgs.length - 1] = vargs; return newArgs; } else { throw new GroovyBugError("trying to call a vargs method without enough arguments"); } }
[ "private", "static", "Object", "[", "]", "fitToVargs", "(", "Object", "[", "]", "argumentArrayOrig", ",", "CachedClass", "[", "]", "paramTypes", ")", "{", "Class", "vargsClassOrig", "=", "paramTypes", "[", "paramTypes", ".", "length", "-", "1", "]", ".", "getTheClass", "(", ")", ".", "getComponentType", "(", ")", ";", "Class", "vargsClass", "=", "ReflectionCache", ".", "autoboxType", "(", "vargsClassOrig", ")", ";", "Object", "[", "]", "argumentArray", "=", "argumentArrayOrig", ".", "clone", "(", ")", ";", "MetaClassHelper", ".", "unwrap", "(", "argumentArray", ")", ";", "if", "(", "argumentArray", ".", "length", "==", "paramTypes", ".", "length", "-", "1", ")", "{", "// the vargs argument is missing, so fill it with an empty array", "Object", "[", "]", "newArgs", "=", "new", "Object", "[", "paramTypes", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "argumentArray", ",", "0", ",", "newArgs", ",", "0", ",", "argumentArray", ".", "length", ")", ";", "Object", "vargs", "=", "Array", ".", "newInstance", "(", "vargsClass", ",", "0", ")", ";", "newArgs", "[", "newArgs", ".", "length", "-", "1", "]", "=", "vargs", ";", "return", "newArgs", ";", "}", "else", "if", "(", "argumentArray", ".", "length", "==", "paramTypes", ".", "length", ")", "{", "// the number of arguments is correct, but if the last argument", "// is no array we have to wrap it in a array. If the last argument", "// is null, then we don't have to do anything", "Object", "lastArgument", "=", "argumentArray", "[", "argumentArray", ".", "length", "-", "1", "]", ";", "if", "(", "lastArgument", "!=", "null", "&&", "!", "lastArgument", ".", "getClass", "(", ")", ".", "isArray", "(", ")", ")", "{", "// no array so wrap it", "Object", "wrapped", "=", "makeCommonArray", "(", "argumentArray", ",", "paramTypes", ".", "length", "-", "1", ",", "vargsClass", ")", ";", "Object", "[", "]", "newArgs", "=", "new", "Object", "[", "paramTypes", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "argumentArray", ",", "0", ",", "newArgs", ",", "0", ",", "paramTypes", ".", "length", "-", "1", ")", ";", "newArgs", "[", "newArgs", ".", "length", "-", "1", "]", "=", "wrapped", ";", "return", "newArgs", ";", "}", "else", "{", "// we may have to box the argument!", "return", "argumentArray", ";", "}", "}", "else", "if", "(", "argumentArray", ".", "length", ">", "paramTypes", ".", "length", ")", "{", "// the number of arguments is too big, wrap all exceeding elements", "// in an array, but keep the old elements that are no vargs", "Object", "[", "]", "newArgs", "=", "new", "Object", "[", "paramTypes", ".", "length", "]", ";", "// copy arguments that are not a varg", "System", ".", "arraycopy", "(", "argumentArray", ",", "0", ",", "newArgs", ",", "0", ",", "paramTypes", ".", "length", "-", "1", ")", ";", "// create a new array for the vargs and copy them", "Object", "vargs", "=", "makeCommonArray", "(", "argumentArray", ",", "paramTypes", ".", "length", "-", "1", ",", "vargsClass", ")", ";", "newArgs", "[", "newArgs", ".", "length", "-", "1", "]", "=", "vargs", ";", "return", "newArgs", ";", "}", "else", "{", "throw", "new", "GroovyBugError", "(", "\"trying to call a vargs method without enough arguments\"", ")", ";", "}", "}" ]
this method is called when the number of arguments to a method is greater than 1 and if the method is a vargs method. This method will then transform the given arguments to make the method callable @param argumentArrayOrig the arguments used to call the method @param paramTypes the types of the parameters the method takes
[ "this", "method", "is", "called", "when", "the", "number", "of", "arguments", "to", "a", "method", "is", "greater", "than", "1", "and", "if", "the", "method", "is", "a", "vargs", "method", ".", "This", "method", "will", "then", "transform", "the", "given", "arguments", "to", "make", "the", "method", "callable" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/reflection/ParameterTypes.java#L187-L229
13,184
apache/groovy
src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
VariableScopeVisitor.checkPropertyOnExplicitThis
private void checkPropertyOnExplicitThis(PropertyExpression pe) { if (!currentScope.isInStaticContext()) return; Expression object = pe.getObjectExpression(); if (!(object instanceof VariableExpression)) return; VariableExpression ve = (VariableExpression) object; if (!ve.getName().equals("this")) return; String name = pe.getPropertyAsString(); if (name == null || name.equals("class")) return; Variable member = findClassMember(currentClass, name); if (member == null) return; checkVariableContextAccess(member, pe); }
java
private void checkPropertyOnExplicitThis(PropertyExpression pe) { if (!currentScope.isInStaticContext()) return; Expression object = pe.getObjectExpression(); if (!(object instanceof VariableExpression)) return; VariableExpression ve = (VariableExpression) object; if (!ve.getName().equals("this")) return; String name = pe.getPropertyAsString(); if (name == null || name.equals("class")) return; Variable member = findClassMember(currentClass, name); if (member == null) return; checkVariableContextAccess(member, pe); }
[ "private", "void", "checkPropertyOnExplicitThis", "(", "PropertyExpression", "pe", ")", "{", "if", "(", "!", "currentScope", ".", "isInStaticContext", "(", ")", ")", "return", ";", "Expression", "object", "=", "pe", ".", "getObjectExpression", "(", ")", ";", "if", "(", "!", "(", "object", "instanceof", "VariableExpression", ")", ")", "return", ";", "VariableExpression", "ve", "=", "(", "VariableExpression", ")", "object", ";", "if", "(", "!", "ve", ".", "getName", "(", ")", ".", "equals", "(", "\"this\"", ")", ")", "return", ";", "String", "name", "=", "pe", ".", "getPropertyAsString", "(", ")", ";", "if", "(", "name", "==", "null", "||", "name", ".", "equals", "(", "\"class\"", ")", ")", "return", ";", "Variable", "member", "=", "findClassMember", "(", "currentClass", ",", "name", ")", ";", "if", "(", "member", "==", "null", ")", "return", ";", "checkVariableContextAccess", "(", "member", ",", "pe", ")", ";", "}" ]
a property on "this", like this.x is transformed to a direct field access, so we need to check the static context here @param pe the property expression to check
[ "a", "property", "on", "this", "like", "this", ".", "x", "is", "transformed", "to", "a", "direct", "field", "access", "so", "we", "need", "to", "check", "the", "static", "context", "here" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java#L292-L303
13,185
apache/groovy
src/main/java/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java
FinalVariableAnalyzer.fixVar
private void fixVar(Variable var) { if (getTarget(var) == null && var instanceof VariableExpression && getState() != null && var.getName() != null) { for (Variable v: getState().keySet()) { if (var.getName().equals(v.getName())) { ((VariableExpression)var).setAccessedVariable(v); break; } } } }
java
private void fixVar(Variable var) { if (getTarget(var) == null && var instanceof VariableExpression && getState() != null && var.getName() != null) { for (Variable v: getState().keySet()) { if (var.getName().equals(v.getName())) { ((VariableExpression)var).setAccessedVariable(v); break; } } } }
[ "private", "void", "fixVar", "(", "Variable", "var", ")", "{", "if", "(", "getTarget", "(", "var", ")", "==", "null", "&&", "var", "instanceof", "VariableExpression", "&&", "getState", "(", ")", "!=", "null", "&&", "var", ".", "getName", "(", ")", "!=", "null", ")", "{", "for", "(", "Variable", "v", ":", "getState", "(", ")", ".", "keySet", "(", ")", ")", "{", "if", "(", "var", ".", "getName", "(", ")", ".", "equals", "(", "v", ".", "getName", "(", ")", ")", ")", "{", "(", "(", "VariableExpression", ")", "var", ")", ".", "setAccessedVariable", "(", "v", ")", ";", "break", ";", "}", "}", "}", "}" ]
This fixes xform declaration expressions but not other synthetic fields which aren't set up correctly
[ "This", "fixes", "xform", "declaration", "expressions", "but", "not", "other", "synthetic", "fields", "which", "aren", "t", "set", "up", "correctly" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java#L446-L455
13,186
apache/groovy
subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
AntBuilder.nodeCompleted
protected void nodeCompleted(final Object parent, final Object node) { if (parent == null) insideTask = false; antElementHandler.onEndElement(null, null, antXmlContext); lastCompletedNode = node; if (parent != null && !(parent instanceof Target)) { log.finest("parent is not null: no perform on nodeCompleted"); return; // parent will care about when children perform } if (definingTarget != null && definingTarget == parent && node instanceof Task) return; // inside defineTarget if (definingTarget == node) { definingTarget = null; } // as in Target.execute() if (node instanceof Task) { Task task = (Task) node; final String taskName = task.getTaskName(); if ("antcall".equals(taskName) && parent == null) { throw new BuildException("antcall not supported within AntBuilder, consider using 'ant.project.executeTarget('targetName')' instead."); } if (saveStreams) { // save original streams synchronized (AntBuilder.class) { int currentStreamCount = streamCount++; if (currentStreamCount == 0) { // we are first, save the streams savedProjectInputStream = project.getDefaultInputStream(); savedIn = System.in; savedErr = System.err; savedOut = System.out; if (!(savedIn instanceof DemuxInputStream)) { project.setDefaultInputStream(savedIn); demuxInputStream = new DemuxInputStream(project); System.setIn(demuxInputStream); } demuxOutputStream = new DemuxOutputStream(project, false); System.setOut(new PrintStream(demuxOutputStream)); demuxErrorStream = new DemuxOutputStream(project, true); System.setErr(new PrintStream(demuxErrorStream)); } } } try { lastCompletedNode = performTask(task); } finally { if (saveStreams) { synchronized (AntBuilder.class) { int currentStreamCount = --streamCount; if (currentStreamCount == 0) { // last to leave, turn out the lights: restore original streams project.setDefaultInputStream(savedProjectInputStream); System.setOut(savedOut); System.setErr(savedErr); if (demuxInputStream != null) { System.setIn(savedIn); DefaultGroovyMethodsSupport.closeQuietly(demuxInputStream); demuxInputStream = null; } DefaultGroovyMethodsSupport.closeQuietly(demuxOutputStream); DefaultGroovyMethodsSupport.closeQuietly(demuxErrorStream); demuxOutputStream = null; demuxErrorStream = null; } } } } // restore dummy collector target if ("import".equals(taskName)) { antXmlContext.setCurrentTarget(collectorTarget); } } else if (node instanceof Target) { // restore dummy collector target antXmlContext.setCurrentTarget(collectorTarget); } else { final RuntimeConfigurable r = (RuntimeConfigurable) node; r.maybeConfigure(project); } }
java
protected void nodeCompleted(final Object parent, final Object node) { if (parent == null) insideTask = false; antElementHandler.onEndElement(null, null, antXmlContext); lastCompletedNode = node; if (parent != null && !(parent instanceof Target)) { log.finest("parent is not null: no perform on nodeCompleted"); return; // parent will care about when children perform } if (definingTarget != null && definingTarget == parent && node instanceof Task) return; // inside defineTarget if (definingTarget == node) { definingTarget = null; } // as in Target.execute() if (node instanceof Task) { Task task = (Task) node; final String taskName = task.getTaskName(); if ("antcall".equals(taskName) && parent == null) { throw new BuildException("antcall not supported within AntBuilder, consider using 'ant.project.executeTarget('targetName')' instead."); } if (saveStreams) { // save original streams synchronized (AntBuilder.class) { int currentStreamCount = streamCount++; if (currentStreamCount == 0) { // we are first, save the streams savedProjectInputStream = project.getDefaultInputStream(); savedIn = System.in; savedErr = System.err; savedOut = System.out; if (!(savedIn instanceof DemuxInputStream)) { project.setDefaultInputStream(savedIn); demuxInputStream = new DemuxInputStream(project); System.setIn(demuxInputStream); } demuxOutputStream = new DemuxOutputStream(project, false); System.setOut(new PrintStream(demuxOutputStream)); demuxErrorStream = new DemuxOutputStream(project, true); System.setErr(new PrintStream(demuxErrorStream)); } } } try { lastCompletedNode = performTask(task); } finally { if (saveStreams) { synchronized (AntBuilder.class) { int currentStreamCount = --streamCount; if (currentStreamCount == 0) { // last to leave, turn out the lights: restore original streams project.setDefaultInputStream(savedProjectInputStream); System.setOut(savedOut); System.setErr(savedErr); if (demuxInputStream != null) { System.setIn(savedIn); DefaultGroovyMethodsSupport.closeQuietly(demuxInputStream); demuxInputStream = null; } DefaultGroovyMethodsSupport.closeQuietly(demuxOutputStream); DefaultGroovyMethodsSupport.closeQuietly(demuxErrorStream); demuxOutputStream = null; demuxErrorStream = null; } } } } // restore dummy collector target if ("import".equals(taskName)) { antXmlContext.setCurrentTarget(collectorTarget); } } else if (node instanceof Target) { // restore dummy collector target antXmlContext.setCurrentTarget(collectorTarget); } else { final RuntimeConfigurable r = (RuntimeConfigurable) node; r.maybeConfigure(project); } }
[ "protected", "void", "nodeCompleted", "(", "final", "Object", "parent", ",", "final", "Object", "node", ")", "{", "if", "(", "parent", "==", "null", ")", "insideTask", "=", "false", ";", "antElementHandler", ".", "onEndElement", "(", "null", ",", "null", ",", "antXmlContext", ")", ";", "lastCompletedNode", "=", "node", ";", "if", "(", "parent", "!=", "null", "&&", "!", "(", "parent", "instanceof", "Target", ")", ")", "{", "log", ".", "finest", "(", "\"parent is not null: no perform on nodeCompleted\"", ")", ";", "return", ";", "// parent will care about when children perform", "}", "if", "(", "definingTarget", "!=", "null", "&&", "definingTarget", "==", "parent", "&&", "node", "instanceof", "Task", ")", "return", ";", "// inside defineTarget", "if", "(", "definingTarget", "==", "node", ")", "{", "definingTarget", "=", "null", ";", "}", "// as in Target.execute()", "if", "(", "node", "instanceof", "Task", ")", "{", "Task", "task", "=", "(", "Task", ")", "node", ";", "final", "String", "taskName", "=", "task", ".", "getTaskName", "(", ")", ";", "if", "(", "\"antcall\"", ".", "equals", "(", "taskName", ")", "&&", "parent", "==", "null", ")", "{", "throw", "new", "BuildException", "(", "\"antcall not supported within AntBuilder, consider using 'ant.project.executeTarget('targetName')' instead.\"", ")", ";", "}", "if", "(", "saveStreams", ")", "{", "// save original streams", "synchronized", "(", "AntBuilder", ".", "class", ")", "{", "int", "currentStreamCount", "=", "streamCount", "++", ";", "if", "(", "currentStreamCount", "==", "0", ")", "{", "// we are first, save the streams", "savedProjectInputStream", "=", "project", ".", "getDefaultInputStream", "(", ")", ";", "savedIn", "=", "System", ".", "in", ";", "savedErr", "=", "System", ".", "err", ";", "savedOut", "=", "System", ".", "out", ";", "if", "(", "!", "(", "savedIn", "instanceof", "DemuxInputStream", ")", ")", "{", "project", ".", "setDefaultInputStream", "(", "savedIn", ")", ";", "demuxInputStream", "=", "new", "DemuxInputStream", "(", "project", ")", ";", "System", ".", "setIn", "(", "demuxInputStream", ")", ";", "}", "demuxOutputStream", "=", "new", "DemuxOutputStream", "(", "project", ",", "false", ")", ";", "System", ".", "setOut", "(", "new", "PrintStream", "(", "demuxOutputStream", ")", ")", ";", "demuxErrorStream", "=", "new", "DemuxOutputStream", "(", "project", ",", "true", ")", ";", "System", ".", "setErr", "(", "new", "PrintStream", "(", "demuxErrorStream", ")", ")", ";", "}", "}", "}", "try", "{", "lastCompletedNode", "=", "performTask", "(", "task", ")", ";", "}", "finally", "{", "if", "(", "saveStreams", ")", "{", "synchronized", "(", "AntBuilder", ".", "class", ")", "{", "int", "currentStreamCount", "=", "--", "streamCount", ";", "if", "(", "currentStreamCount", "==", "0", ")", "{", "// last to leave, turn out the lights: restore original streams", "project", ".", "setDefaultInputStream", "(", "savedProjectInputStream", ")", ";", "System", ".", "setOut", "(", "savedOut", ")", ";", "System", ".", "setErr", "(", "savedErr", ")", ";", "if", "(", "demuxInputStream", "!=", "null", ")", "{", "System", ".", "setIn", "(", "savedIn", ")", ";", "DefaultGroovyMethodsSupport", ".", "closeQuietly", "(", "demuxInputStream", ")", ";", "demuxInputStream", "=", "null", ";", "}", "DefaultGroovyMethodsSupport", ".", "closeQuietly", "(", "demuxOutputStream", ")", ";", "DefaultGroovyMethodsSupport", ".", "closeQuietly", "(", "demuxErrorStream", ")", ";", "demuxOutputStream", "=", "null", ";", "demuxErrorStream", "=", "null", ";", "}", "}", "}", "}", "// restore dummy collector target", "if", "(", "\"import\"", ".", "equals", "(", "taskName", ")", ")", "{", "antXmlContext", ".", "setCurrentTarget", "(", "collectorTarget", ")", ";", "}", "}", "else", "if", "(", "node", "instanceof", "Target", ")", "{", "// restore dummy collector target", "antXmlContext", ".", "setCurrentTarget", "(", "collectorTarget", ")", ";", "}", "else", "{", "final", "RuntimeConfigurable", "r", "=", "(", "RuntimeConfigurable", ")", "node", ";", "r", ".", "maybeConfigure", "(", "project", ")", ";", "}", "}" ]
Determines, when the ANT Task that is represented by the "node" should perform. Node must be an ANT Task or no "perform" is called. If node is an ANT Task, it performs right after complete construction. If node is nested in a TaskContainer, calling "perform" is delegated to that TaskContainer. @param parent note: null when node is root @param node the node that now has all its children applied
[ "Determines", "when", "the", "ANT", "Task", "that", "is", "represented", "by", "the", "node", "should", "perform", ".", "Node", "must", "be", "an", "ANT", "Task", "or", "no", "perform", "is", "called", ".", "If", "node", "is", "an", "ANT", "Task", "it", "performs", "right", "after", "complete", "construction", ".", "If", "node", "is", "nested", "in", "a", "TaskContainer", "calling", "perform", "is", "delegated", "to", "that", "TaskContainer", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java#L230-L313
13,187
apache/groovy
subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
AntBuilder.performTask
private Object performTask(Task task) { Throwable reason = null; try { // Have to call fireTestStared/fireTestFinished via reflection as they unfortunately have protected access in Project final Method fireTaskStarted = Project.class.getDeclaredMethod("fireTaskStarted", Task.class); fireTaskStarted.setAccessible(true); fireTaskStarted.invoke(project, task); Object realThing; realThing = task; task.maybeConfigure(); if (task instanceof UnknownElement) { realThing = ((UnknownElement) task).getRealThing(); } DispatchUtils.execute(task); return realThing != null ? realThing : task; } catch (BuildException ex) { if (ex.getLocation() == Location.UNKNOWN_LOCATION) { ex.setLocation(task.getLocation()); } reason = ex; throw ex; } catch (Exception ex) { reason = ex; BuildException be = new BuildException(ex); be.setLocation(task.getLocation()); throw be; } catch (Error ex) { reason = ex; throw ex; } finally { try { final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class); fireTaskFinished.setAccessible(true); fireTaskFinished.invoke(project, task, reason); } catch (Exception e) { BuildException be = new BuildException(e); be.setLocation(task.getLocation()); throw be; } } }
java
private Object performTask(Task task) { Throwable reason = null; try { // Have to call fireTestStared/fireTestFinished via reflection as they unfortunately have protected access in Project final Method fireTaskStarted = Project.class.getDeclaredMethod("fireTaskStarted", Task.class); fireTaskStarted.setAccessible(true); fireTaskStarted.invoke(project, task); Object realThing; realThing = task; task.maybeConfigure(); if (task instanceof UnknownElement) { realThing = ((UnknownElement) task).getRealThing(); } DispatchUtils.execute(task); return realThing != null ? realThing : task; } catch (BuildException ex) { if (ex.getLocation() == Location.UNKNOWN_LOCATION) { ex.setLocation(task.getLocation()); } reason = ex; throw ex; } catch (Exception ex) { reason = ex; BuildException be = new BuildException(ex); be.setLocation(task.getLocation()); throw be; } catch (Error ex) { reason = ex; throw ex; } finally { try { final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class); fireTaskFinished.setAccessible(true); fireTaskFinished.invoke(project, task, reason); } catch (Exception e) { BuildException be = new BuildException(e); be.setLocation(task.getLocation()); throw be; } } }
[ "private", "Object", "performTask", "(", "Task", "task", ")", "{", "Throwable", "reason", "=", "null", ";", "try", "{", "// Have to call fireTestStared/fireTestFinished via reflection as they unfortunately have protected access in Project", "final", "Method", "fireTaskStarted", "=", "Project", ".", "class", ".", "getDeclaredMethod", "(", "\"fireTaskStarted\"", ",", "Task", ".", "class", ")", ";", "fireTaskStarted", ".", "setAccessible", "(", "true", ")", ";", "fireTaskStarted", ".", "invoke", "(", "project", ",", "task", ")", ";", "Object", "realThing", ";", "realThing", "=", "task", ";", "task", ".", "maybeConfigure", "(", ")", ";", "if", "(", "task", "instanceof", "UnknownElement", ")", "{", "realThing", "=", "(", "(", "UnknownElement", ")", "task", ")", ".", "getRealThing", "(", ")", ";", "}", "DispatchUtils", ".", "execute", "(", "task", ")", ";", "return", "realThing", "!=", "null", "?", "realThing", ":", "task", ";", "}", "catch", "(", "BuildException", "ex", ")", "{", "if", "(", "ex", ".", "getLocation", "(", ")", "==", "Location", ".", "UNKNOWN_LOCATION", ")", "{", "ex", ".", "setLocation", "(", "task", ".", "getLocation", "(", ")", ")", ";", "}", "reason", "=", "ex", ";", "throw", "ex", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "reason", "=", "ex", ";", "BuildException", "be", "=", "new", "BuildException", "(", "ex", ")", ";", "be", ".", "setLocation", "(", "task", ".", "getLocation", "(", ")", ")", ";", "throw", "be", ";", "}", "catch", "(", "Error", "ex", ")", "{", "reason", "=", "ex", ";", "throw", "ex", ";", "}", "finally", "{", "try", "{", "final", "Method", "fireTaskFinished", "=", "Project", ".", "class", ".", "getDeclaredMethod", "(", "\"fireTaskFinished\"", ",", "Task", ".", "class", ",", "Throwable", ".", "class", ")", ";", "fireTaskFinished", ".", "setAccessible", "(", "true", ")", ";", "fireTaskFinished", ".", "invoke", "(", "project", ",", "task", ",", "reason", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "BuildException", "be", "=", "new", "BuildException", "(", "e", ")", ";", "be", ".", "setLocation", "(", "task", ".", "getLocation", "(", ")", ")", ";", "throw", "be", ";", "}", "}", "}" ]
Copied from org.apache.tools.ant.Task, since we need to get a real thing before it gets nulled in DispatchUtils.execute
[ "Copied", "from", "org", ".", "apache", ".", "tools", ".", "ant", ".", "Task", "since", "we", "need", "to", "get", "a", "real", "thing", "before", "it", "gets", "nulled", "in", "DispatchUtils", ".", "execute" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java#L317-L366
13,188
apache/groovy
src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java
SourceBuffer.getSnippet
public String getSnippet(LineColumn start, LineColumn end) { // preconditions if (start == null || end == null) { return null; } // no text to return if (start.equals(end)) { return null; } // no text to return if (lines.size() == 1 && current.length() == 0) { return null; } // buffer hasn't been filled yet // working variables int startLine = start.getLine(); int startColumn = start.getColumn(); int endLine = end.getLine(); int endColumn = end.getColumn(); // reset any out of bounds requests if (startLine < 1) { startLine = 1;} if (endLine < 1) { endLine = 1;} if (startColumn < 1) { startColumn = 1;} if (endColumn < 1) { endColumn = 1;} if (startLine > lines.size()) { startLine = lines.size(); } if (endLine > lines.size()) { endLine = lines.size(); } // obtain the snippet from the buffer within specified bounds StringBuilder snippet = new StringBuilder(); for (int i = startLine - 1; i < endLine;i++) { String line = ((StringBuilder)lines.get(i)).toString(); if (startLine == endLine) { // reset any out of bounds requests (again) if (startColumn > line.length()) { startColumn = line.length();} if (startColumn < 1) { startColumn = 1;} if (endColumn > line.length()) { endColumn = line.length() + 1;} if (endColumn < 1) { endColumn = 1;} if (endColumn < startColumn) { endColumn = startColumn;} line = line.substring(startColumn - 1, endColumn - 1); } else { if (i == startLine - 1) { if (startColumn - 1 < line.length()) { line = line.substring(startColumn - 1); } } if (i == endLine - 1) { if (endColumn - 1 < line.length()) { line = line.substring(0,endColumn - 1); } } } snippet.append(line); } return snippet.toString(); }
java
public String getSnippet(LineColumn start, LineColumn end) { // preconditions if (start == null || end == null) { return null; } // no text to return if (start.equals(end)) { return null; } // no text to return if (lines.size() == 1 && current.length() == 0) { return null; } // buffer hasn't been filled yet // working variables int startLine = start.getLine(); int startColumn = start.getColumn(); int endLine = end.getLine(); int endColumn = end.getColumn(); // reset any out of bounds requests if (startLine < 1) { startLine = 1;} if (endLine < 1) { endLine = 1;} if (startColumn < 1) { startColumn = 1;} if (endColumn < 1) { endColumn = 1;} if (startLine > lines.size()) { startLine = lines.size(); } if (endLine > lines.size()) { endLine = lines.size(); } // obtain the snippet from the buffer within specified bounds StringBuilder snippet = new StringBuilder(); for (int i = startLine - 1; i < endLine;i++) { String line = ((StringBuilder)lines.get(i)).toString(); if (startLine == endLine) { // reset any out of bounds requests (again) if (startColumn > line.length()) { startColumn = line.length();} if (startColumn < 1) { startColumn = 1;} if (endColumn > line.length()) { endColumn = line.length() + 1;} if (endColumn < 1) { endColumn = 1;} if (endColumn < startColumn) { endColumn = startColumn;} line = line.substring(startColumn - 1, endColumn - 1); } else { if (i == startLine - 1) { if (startColumn - 1 < line.length()) { line = line.substring(startColumn - 1); } } if (i == endLine - 1) { if (endColumn - 1 < line.length()) { line = line.substring(0,endColumn - 1); } } } snippet.append(line); } return snippet.toString(); }
[ "public", "String", "getSnippet", "(", "LineColumn", "start", ",", "LineColumn", "end", ")", "{", "// preconditions", "if", "(", "start", "==", "null", "||", "end", "==", "null", ")", "{", "return", "null", ";", "}", "// no text to return", "if", "(", "start", ".", "equals", "(", "end", ")", ")", "{", "return", "null", ";", "}", "// no text to return", "if", "(", "lines", ".", "size", "(", ")", "==", "1", "&&", "current", ".", "length", "(", ")", "==", "0", ")", "{", "return", "null", ";", "}", "// buffer hasn't been filled yet", "// working variables", "int", "startLine", "=", "start", ".", "getLine", "(", ")", ";", "int", "startColumn", "=", "start", ".", "getColumn", "(", ")", ";", "int", "endLine", "=", "end", ".", "getLine", "(", ")", ";", "int", "endColumn", "=", "end", ".", "getColumn", "(", ")", ";", "// reset any out of bounds requests", "if", "(", "startLine", "<", "1", ")", "{", "startLine", "=", "1", ";", "}", "if", "(", "endLine", "<", "1", ")", "{", "endLine", "=", "1", ";", "}", "if", "(", "startColumn", "<", "1", ")", "{", "startColumn", "=", "1", ";", "}", "if", "(", "endColumn", "<", "1", ")", "{", "endColumn", "=", "1", ";", "}", "if", "(", "startLine", ">", "lines", ".", "size", "(", ")", ")", "{", "startLine", "=", "lines", ".", "size", "(", ")", ";", "}", "if", "(", "endLine", ">", "lines", ".", "size", "(", ")", ")", "{", "endLine", "=", "lines", ".", "size", "(", ")", ";", "}", "// obtain the snippet from the buffer within specified bounds", "StringBuilder", "snippet", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "startLine", "-", "1", ";", "i", "<", "endLine", ";", "i", "++", ")", "{", "String", "line", "=", "(", "(", "StringBuilder", ")", "lines", ".", "get", "(", "i", ")", ")", ".", "toString", "(", ")", ";", "if", "(", "startLine", "==", "endLine", ")", "{", "// reset any out of bounds requests (again)", "if", "(", "startColumn", ">", "line", ".", "length", "(", ")", ")", "{", "startColumn", "=", "line", ".", "length", "(", ")", ";", "}", "if", "(", "startColumn", "<", "1", ")", "{", "startColumn", "=", "1", ";", "}", "if", "(", "endColumn", ">", "line", ".", "length", "(", ")", ")", "{", "endColumn", "=", "line", ".", "length", "(", ")", "+", "1", ";", "}", "if", "(", "endColumn", "<", "1", ")", "{", "endColumn", "=", "1", ";", "}", "if", "(", "endColumn", "<", "startColumn", ")", "{", "endColumn", "=", "startColumn", ";", "}", "line", "=", "line", ".", "substring", "(", "startColumn", "-", "1", ",", "endColumn", "-", "1", ")", ";", "}", "else", "{", "if", "(", "i", "==", "startLine", "-", "1", ")", "{", "if", "(", "startColumn", "-", "1", "<", "line", ".", "length", "(", ")", ")", "{", "line", "=", "line", ".", "substring", "(", "startColumn", "-", "1", ")", ";", "}", "}", "if", "(", "i", "==", "endLine", "-", "1", ")", "{", "if", "(", "endColumn", "-", "1", "<", "line", ".", "length", "(", ")", ")", "{", "line", "=", "line", ".", "substring", "(", "0", ",", "endColumn", "-", "1", ")", ";", "}", "}", "}", "snippet", ".", "append", "(", "line", ")", ";", "}", "return", "snippet", ".", "toString", "(", ")", ";", "}" ]
Obtains a snippet of the source code within the bounds specified @param start (inclusive line/ inclusive column) @param end (inclusive line / exclusive column) @return specified snippet of source code as a String, or null if no source available
[ "Obtains", "a", "snippet", "of", "the", "source", "code", "within", "the", "bounds", "specified" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java#L46-L94
13,189
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
DefaultGroovyMethodsSupport.tryClose
static Throwable tryClose(AutoCloseable closeable, boolean logWarning) { Throwable thrown = null; if (closeable != null) { try { closeable.close(); } catch (Exception e) { thrown = e; if (logWarning) { LOG.warning("Caught exception during close(): " + e); } } } return thrown; }
java
static Throwable tryClose(AutoCloseable closeable, boolean logWarning) { Throwable thrown = null; if (closeable != null) { try { closeable.close(); } catch (Exception e) { thrown = e; if (logWarning) { LOG.warning("Caught exception during close(): " + e); } } } return thrown; }
[ "static", "Throwable", "tryClose", "(", "AutoCloseable", "closeable", ",", "boolean", "logWarning", ")", "{", "Throwable", "thrown", "=", "null", ";", "if", "(", "closeable", "!=", "null", ")", "{", "try", "{", "closeable", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "thrown", "=", "e", ";", "if", "(", "logWarning", ")", "{", "LOG", ".", "warning", "(", "\"Caught exception during close(): \"", "+", "e", ")", ";", "}", "}", "}", "return", "thrown", ";", "}" ]
Attempts to close the closeable returning rather than throwing any Exception that may occur. @param closeable the thing to close @param logWarning if true will log a warning if an exception occurs @return throwable Exception from the close method, else null
[ "Attempts", "to", "close", "the", "closeable", "returning", "rather", "than", "throwing", "any", "Exception", "that", "may", "occur", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java#L132-L145
13,190
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
DefaultGroovyMethodsSupport.sameType
@SuppressWarnings("unchecked") protected static boolean sameType(Collection[] cols) { List all = new LinkedList(); for (Collection col : cols) { all.addAll(col); } if (all.isEmpty()) return true; Object first = all.get(0); //trying to determine the base class of the collections //special case for Numbers Class baseClass; if (first instanceof Number) { baseClass = Number.class; } else if (first == null) { baseClass = NullObject.class; } else { baseClass = first.getClass(); } for (Collection col : cols) { for (Object o : col) { if (!baseClass.isInstance(o)) { return false; } } } return true; }
java
@SuppressWarnings("unchecked") protected static boolean sameType(Collection[] cols) { List all = new LinkedList(); for (Collection col : cols) { all.addAll(col); } if (all.isEmpty()) return true; Object first = all.get(0); //trying to determine the base class of the collections //special case for Numbers Class baseClass; if (first instanceof Number) { baseClass = Number.class; } else if (first == null) { baseClass = NullObject.class; } else { baseClass = first.getClass(); } for (Collection col : cols) { for (Object o : col) { if (!baseClass.isInstance(o)) { return false; } } } return true; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "protected", "static", "boolean", "sameType", "(", "Collection", "[", "]", "cols", ")", "{", "List", "all", "=", "new", "LinkedList", "(", ")", ";", "for", "(", "Collection", "col", ":", "cols", ")", "{", "all", ".", "addAll", "(", "col", ")", ";", "}", "if", "(", "all", ".", "isEmpty", "(", ")", ")", "return", "true", ";", "Object", "first", "=", "all", ".", "get", "(", "0", ")", ";", "//trying to determine the base class of the collections", "//special case for Numbers", "Class", "baseClass", ";", "if", "(", "first", "instanceof", "Number", ")", "{", "baseClass", "=", "Number", ".", "class", ";", "}", "else", "if", "(", "first", "==", "null", ")", "{", "baseClass", "=", "NullObject", ".", "class", ";", "}", "else", "{", "baseClass", "=", "first", ".", "getClass", "(", ")", ";", "}", "for", "(", "Collection", "col", ":", "cols", ")", "{", "for", "(", "Object", "o", ":", "col", ")", "{", "if", "(", "!", "baseClass", ".", "isInstance", "(", "o", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Determines if all items of this array are of the same type. @param cols an array of collections @return true if the collections are all of the same type
[ "Determines", "if", "all", "items", "of", "this", "array", "are", "of", "the", "same", "type", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java#L352-L382
13,191
apache/groovy
subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java
DateTimeExtensions.defaultUnitFor
private static TemporalUnit defaultUnitFor(Temporal temporal) { return DEFAULT_UNITS.entrySet() .stream() .filter(e -> e.getKey().isAssignableFrom(temporal.getClass())) .findFirst() .map(Map.Entry::getValue) .orElse(ChronoUnit.SECONDS); }
java
private static TemporalUnit defaultUnitFor(Temporal temporal) { return DEFAULT_UNITS.entrySet() .stream() .filter(e -> e.getKey().isAssignableFrom(temporal.getClass())) .findFirst() .map(Map.Entry::getValue) .orElse(ChronoUnit.SECONDS); }
[ "private", "static", "TemporalUnit", "defaultUnitFor", "(", "Temporal", "temporal", ")", "{", "return", "DEFAULT_UNITS", ".", "entrySet", "(", ")", ".", "stream", "(", ")", ".", "filter", "(", "e", "->", "e", ".", "getKey", "(", ")", ".", "isAssignableFrom", "(", "temporal", ".", "getClass", "(", ")", ")", ")", ".", "findFirst", "(", ")", ".", "map", "(", "Map", ".", "Entry", "::", "getValue", ")", ".", "orElse", "(", "ChronoUnit", ".", "SECONDS", ")", ";", "}" ]
A number of extension methods permit a long or int to be provided as a parameter. This method determines what the unit should be for this number.
[ "A", "number", "of", "extension", "methods", "permit", "a", "long", "or", "int", "to", "be", "provided", "as", "a", "parameter", ".", "This", "method", "determines", "what", "the", "unit", "should", "be", "for", "this", "number", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java#L95-L102
13,192
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.negateBoolean
public static void negateBoolean(MethodVisitor mv) { // code to negate the primitive boolean Label endLabel = new Label(); Label falseLabel = new Label(); mv.visitJumpInsn(IFNE, falseLabel); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, endLabel); mv.visitLabel(falseLabel); mv.visitInsn(ICONST_0); mv.visitLabel(endLabel); }
java
public static void negateBoolean(MethodVisitor mv) { // code to negate the primitive boolean Label endLabel = new Label(); Label falseLabel = new Label(); mv.visitJumpInsn(IFNE, falseLabel); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, endLabel); mv.visitLabel(falseLabel); mv.visitInsn(ICONST_0); mv.visitLabel(endLabel); }
[ "public", "static", "void", "negateBoolean", "(", "MethodVisitor", "mv", ")", "{", "// code to negate the primitive boolean", "Label", "endLabel", "=", "new", "Label", "(", ")", ";", "Label", "falseLabel", "=", "new", "Label", "(", ")", ";", "mv", ".", "visitJumpInsn", "(", "IFNE", ",", "falseLabel", ")", ";", "mv", ".", "visitInsn", "(", "ICONST_1", ")", ";", "mv", ".", "visitJumpInsn", "(", "GOTO", ",", "endLabel", ")", ";", "mv", ".", "visitLabel", "(", "falseLabel", ")", ";", "mv", ".", "visitInsn", "(", "ICONST_0", ")", ";", "mv", ".", "visitLabel", "(", "endLabel", ")", ";", "}" ]
Negate a boolean on stack.
[ "Negate", "a", "boolean", "on", "stack", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L225-L235
13,193
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.unbox
public static void unbox(MethodVisitor mv, Class type) { if (type.isPrimitive() && type != Void.TYPE) { String returnString = "(Ljava/lang/Object;)" + BytecodeHelper.getTypeDescription(type); mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, type.getName() + "Unbox", returnString, false); } }
java
public static void unbox(MethodVisitor mv, Class type) { if (type.isPrimitive() && type != Void.TYPE) { String returnString = "(Ljava/lang/Object;)" + BytecodeHelper.getTypeDescription(type); mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, type.getName() + "Unbox", returnString, false); } }
[ "public", "static", "void", "unbox", "(", "MethodVisitor", "mv", ",", "Class", "type", ")", "{", "if", "(", "type", ".", "isPrimitive", "(", ")", "&&", "type", "!=", "Void", ".", "TYPE", ")", "{", "String", "returnString", "=", "\"(Ljava/lang/Object;)\"", "+", "BytecodeHelper", ".", "getTypeDescription", "(", "type", ")", ";", "mv", ".", "visitMethodInsn", "(", "INVOKESTATIC", ",", "DTT_CLASSNAME", ",", "type", ".", "getName", "(", ")", "+", "\"Unbox\"", ",", "returnString", ",", "false", ")", ";", "}", "}" ]
Generates the bytecode to unbox the current value on the stack
[ "Generates", "the", "bytecode", "to", "unbox", "the", "current", "value", "on", "the", "stack" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L492-L497
13,194
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.box
@Deprecated public static boolean box(MethodVisitor mv, ClassNode type) { if (type.isPrimaryClassNode()) return false; return box(mv, type.getTypeClass()); }
java
@Deprecated public static boolean box(MethodVisitor mv, ClassNode type) { if (type.isPrimaryClassNode()) return false; return box(mv, type.getTypeClass()); }
[ "@", "Deprecated", "public", "static", "boolean", "box", "(", "MethodVisitor", "mv", ",", "ClassNode", "type", ")", "{", "if", "(", "type", ".", "isPrimaryClassNode", "(", ")", ")", "return", "false", ";", "return", "box", "(", "mv", ",", "type", ".", "getTypeClass", "(", ")", ")", ";", "}" ]
box top level operand
[ "box", "top", "level", "operand" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L507-L511
13,195
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.box
@Deprecated public static boolean box(MethodVisitor mv, Class type) { if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) { String returnString = "(" + BytecodeHelper.getTypeDescription(type) + ")Ljava/lang/Object;"; mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, "box", returnString, false); return true; } return false; }
java
@Deprecated public static boolean box(MethodVisitor mv, Class type) { if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) { String returnString = "(" + BytecodeHelper.getTypeDescription(type) + ")Ljava/lang/Object;"; mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, "box", returnString, false); return true; } return false; }
[ "@", "Deprecated", "public", "static", "boolean", "box", "(", "MethodVisitor", "mv", ",", "Class", "type", ")", "{", "if", "(", "ReflectionCache", ".", "getCachedClass", "(", "type", ")", ".", "isPrimitive", "&&", "type", "!=", "void", ".", "class", ")", "{", "String", "returnString", "=", "\"(\"", "+", "BytecodeHelper", ".", "getTypeDescription", "(", "type", ")", "+", "\")Ljava/lang/Object;\"", ";", "mv", ".", "visitMethodInsn", "(", "INVOKESTATIC", ",", "DTT_CLASSNAME", ",", "\"box\"", ",", "returnString", ",", "false", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Generates the bytecode to autobox the current value on the stack
[ "Generates", "the", "bytecode", "to", "autobox", "the", "current", "value", "on", "the", "stack" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L517-L525
13,196
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.visitClassLiteral
public static void visitClassLiteral(MethodVisitor mv, ClassNode classNode) { if (ClassHelper.isPrimitiveType(classNode)) { mv.visitFieldInsn( GETSTATIC, getClassInternalName(ClassHelper.getWrapper(classNode)), "TYPE", "Ljava/lang/Class;"); } else { mv.visitLdcInsn(org.objectweb.asm.Type.getType(getTypeDescription(classNode))); } }
java
public static void visitClassLiteral(MethodVisitor mv, ClassNode classNode) { if (ClassHelper.isPrimitiveType(classNode)) { mv.visitFieldInsn( GETSTATIC, getClassInternalName(ClassHelper.getWrapper(classNode)), "TYPE", "Ljava/lang/Class;"); } else { mv.visitLdcInsn(org.objectweb.asm.Type.getType(getTypeDescription(classNode))); } }
[ "public", "static", "void", "visitClassLiteral", "(", "MethodVisitor", "mv", ",", "ClassNode", "classNode", ")", "{", "if", "(", "ClassHelper", ".", "isPrimitiveType", "(", "classNode", ")", ")", "{", "mv", ".", "visitFieldInsn", "(", "GETSTATIC", ",", "getClassInternalName", "(", "ClassHelper", ".", "getWrapper", "(", "classNode", ")", ")", ",", "\"TYPE\"", ",", "\"Ljava/lang/Class;\"", ")", ";", "}", "else", "{", "mv", ".", "visitLdcInsn", "(", "org", ".", "objectweb", ".", "asm", ".", "Type", ".", "getType", "(", "getTypeDescription", "(", "classNode", ")", ")", ")", ";", "}", "}" ]
Visits a class literal. If the type of the classnode is a primitive type, the generated bytecode will be a GETSTATIC Integer.TYPE. If the classnode is not a primitive type, we will generate a LDC instruction.
[ "Visits", "a", "class", "literal", ".", "If", "the", "type", "of", "the", "classnode", "is", "a", "primitive", "type", "the", "generated", "bytecode", "will", "be", "a", "GETSTATIC", "Integer", ".", "TYPE", ".", "If", "the", "classnode", "is", "not", "a", "primitive", "type", "we", "will", "generate", "a", "LDC", "instruction", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L532-L542
13,197
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.isSameCompilationUnit
public static boolean isSameCompilationUnit(ClassNode a, ClassNode b) { CompileUnit cu1 = a.getCompileUnit(); CompileUnit cu2 = b.getCompileUnit(); return cu1 != null && cu1 == cu2; }
java
public static boolean isSameCompilationUnit(ClassNode a, ClassNode b) { CompileUnit cu1 = a.getCompileUnit(); CompileUnit cu2 = b.getCompileUnit(); return cu1 != null && cu1 == cu2; }
[ "public", "static", "boolean", "isSameCompilationUnit", "(", "ClassNode", "a", ",", "ClassNode", "b", ")", "{", "CompileUnit", "cu1", "=", "a", ".", "getCompileUnit", "(", ")", ";", "CompileUnit", "cu2", "=", "b", ".", "getCompileUnit", "(", ")", ";", "return", "cu1", "!=", "null", "&&", "cu1", "==", "cu2", ";", "}" ]
Returns true if the two classes share the same compilation unit. @param a class a @param b class b @return true if both classes share the same compilation unit
[ "Returns", "true", "if", "the", "two", "classes", "share", "the", "same", "compilation", "unit", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L565-L569
13,198
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
BytecodeHelper.convertPrimitiveToBoolean
public static void convertPrimitiveToBoolean(MethodVisitor mv, ClassNode type) { if (type == boolean_TYPE) { return; } // Special handling is done for floating point types in order to // handle checking for 0 or NaN values. if (type == double_TYPE) { convertDoubleToBoolean(mv); return; } else if (type == float_TYPE) { convertFloatToBoolean(mv); return; } Label trueLabel = new Label(); Label falseLabel = new Label(); // Convert long to int for IFEQ comparison using LCMP if (type== long_TYPE) { mv.visitInsn(LCONST_0); mv.visitInsn(LCMP); } // This handles byte, short, char and int mv.visitJumpInsn(IFEQ, falseLabel); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, trueLabel); mv.visitLabel(falseLabel); mv.visitInsn(ICONST_0); mv.visitLabel(trueLabel); }
java
public static void convertPrimitiveToBoolean(MethodVisitor mv, ClassNode type) { if (type == boolean_TYPE) { return; } // Special handling is done for floating point types in order to // handle checking for 0 or NaN values. if (type == double_TYPE) { convertDoubleToBoolean(mv); return; } else if (type == float_TYPE) { convertFloatToBoolean(mv); return; } Label trueLabel = new Label(); Label falseLabel = new Label(); // Convert long to int for IFEQ comparison using LCMP if (type== long_TYPE) { mv.visitInsn(LCONST_0); mv.visitInsn(LCMP); } // This handles byte, short, char and int mv.visitJumpInsn(IFEQ, falseLabel); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, trueLabel); mv.visitLabel(falseLabel); mv.visitInsn(ICONST_0); mv.visitLabel(trueLabel); }
[ "public", "static", "void", "convertPrimitiveToBoolean", "(", "MethodVisitor", "mv", ",", "ClassNode", "type", ")", "{", "if", "(", "type", "==", "boolean_TYPE", ")", "{", "return", ";", "}", "// Special handling is done for floating point types in order to", "// handle checking for 0 or NaN values.", "if", "(", "type", "==", "double_TYPE", ")", "{", "convertDoubleToBoolean", "(", "mv", ")", ";", "return", ";", "}", "else", "if", "(", "type", "==", "float_TYPE", ")", "{", "convertFloatToBoolean", "(", "mv", ")", ";", "return", ";", "}", "Label", "trueLabel", "=", "new", "Label", "(", ")", ";", "Label", "falseLabel", "=", "new", "Label", "(", ")", ";", "// Convert long to int for IFEQ comparison using LCMP", "if", "(", "type", "==", "long_TYPE", ")", "{", "mv", ".", "visitInsn", "(", "LCONST_0", ")", ";", "mv", ".", "visitInsn", "(", "LCMP", ")", ";", "}", "// This handles byte, short, char and int", "mv", ".", "visitJumpInsn", "(", "IFEQ", ",", "falseLabel", ")", ";", "mv", ".", "visitInsn", "(", "ICONST_1", ")", ";", "mv", ".", "visitJumpInsn", "(", "GOTO", ",", "trueLabel", ")", ";", "mv", ".", "visitLabel", "(", "falseLabel", ")", ";", "mv", ".", "visitInsn", "(", "ICONST_0", ")", ";", "mv", ".", "visitLabel", "(", "trueLabel", ")", ";", "}" ]
Converts a primitive type to boolean. @param mv method visitor @param type primitive type to convert
[ "Converts", "a", "primitive", "type", "to", "boolean", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java#L592-L619
13,199
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java
BeanUtils.getAllProperties
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters) { return getAllProperties(type, includeSuperProperties, includeStatic, includePseudoGetters, false, false); }
java
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters) { return getAllProperties(type, includeSuperProperties, includeStatic, includePseudoGetters, false, false); }
[ "public", "static", "List", "<", "PropertyNode", ">", "getAllProperties", "(", "ClassNode", "type", ",", "boolean", "includeSuperProperties", ",", "boolean", "includeStatic", ",", "boolean", "includePseudoGetters", ")", "{", "return", "getAllProperties", "(", "type", ",", "includeSuperProperties", ",", "includeStatic", ",", "includePseudoGetters", ",", "false", ",", "false", ")", ";", "}" ]
Get all properties including JavaBean pseudo properties matching getter conventions. @param type the ClassNode @param includeSuperProperties whether to include super properties @param includeStatic whether to include static properties @param includePseudoGetters whether to include JavaBean pseudo (getXXX/isYYY) properties with no corresponding field @return the list of found property nodes
[ "Get", "all", "properties", "including", "JavaBean", "pseudo", "properties", "matching", "getter", "conventions", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java#L51-L53