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,200
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, boolean includePseudoSetters, boolean superFirst) { return getAllProperties(type, type, new HashSet<String>(), includeSuperProperties, includeStatic, includePseudoGetters, includePseudoSetters, superFirst); }
java
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters, boolean superFirst) { return getAllProperties(type, type, new HashSet<String>(), includeSuperProperties, includeStatic, includePseudoGetters, includePseudoSetters, superFirst); }
[ "public", "static", "List", "<", "PropertyNode", ">", "getAllProperties", "(", "ClassNode", "type", ",", "boolean", "includeSuperProperties", ",", "boolean", "includeStatic", ",", "boolean", "includePseudoGetters", ",", "boolean", "includePseudoSetters", ",", "boolean", "superFirst", ")", "{", "return", "getAllProperties", "(", "type", ",", "type", ",", "new", "HashSet", "<", "String", ">", "(", ")", ",", "includeSuperProperties", ",", "includeStatic", ",", "includePseudoGetters", ",", "includePseudoSetters", ",", "superFirst", ")", ";", "}" ]
Get all properties including JavaBean pseudo properties matching JavaBean getter or setter 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 @param includePseudoSetters whether to include JavaBean pseudo (setXXX) properties with no corresponding field @param superFirst are properties gathered first from parent classes @return the list of found property nodes
[ "Get", "all", "properties", "including", "JavaBean", "pseudo", "properties", "matching", "JavaBean", "getter", "or", "setter", "conventions", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java#L66-L68
13,201
apache/groovy
subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
GroovydocManager.handle
public void handle(ASTNode node, GroovyParser.GroovyParserRuleContext ctx) { if (!(groovydocEnabled || runtimeGroovydocEnabled)) { return; } if (!asBoolean(node) || !asBoolean(ctx)) { return; } String docCommentNodeText = this.findDocCommentByNode(ctx); if (null == docCommentNodeText) { return; } attachDocCommentAsMetaData(node, docCommentNodeText); attachGroovydocAnnotation(node, docCommentNodeText); }
java
public void handle(ASTNode node, GroovyParser.GroovyParserRuleContext ctx) { if (!(groovydocEnabled || runtimeGroovydocEnabled)) { return; } if (!asBoolean(node) || !asBoolean(ctx)) { return; } String docCommentNodeText = this.findDocCommentByNode(ctx); if (null == docCommentNodeText) { return; } attachDocCommentAsMetaData(node, docCommentNodeText); attachGroovydocAnnotation(node, docCommentNodeText); }
[ "public", "void", "handle", "(", "ASTNode", "node", ",", "GroovyParser", ".", "GroovyParserRuleContext", "ctx", ")", "{", "if", "(", "!", "(", "groovydocEnabled", "||", "runtimeGroovydocEnabled", ")", ")", "{", "return", ";", "}", "if", "(", "!", "asBoolean", "(", "node", ")", "||", "!", "asBoolean", "(", "ctx", ")", ")", "{", "return", ";", "}", "String", "docCommentNodeText", "=", "this", ".", "findDocCommentByNode", "(", "ctx", ")", ";", "if", "(", "null", "==", "docCommentNodeText", ")", "{", "return", ";", "}", "attachDocCommentAsMetaData", "(", "node", ",", "docCommentNodeText", ")", ";", "attachGroovydocAnnotation", "(", "node", ",", "docCommentNodeText", ")", ";", "}" ]
Attach doc comment to member node as meta data
[ "Attach", "doc", "comment", "to", "member", "node", "as", "meta", "data" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java#L64-L80
13,202
apache/groovy
src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java
ReflectorLoader.findClass
protected Class findClass(String name) throws ClassNotFoundException { if (delegatationLoader==null) return super.findClass(name); return delegatationLoader.loadClass(name); }
java
protected Class findClass(String name) throws ClassNotFoundException { if (delegatationLoader==null) return super.findClass(name); return delegatationLoader.loadClass(name); }
[ "protected", "Class", "findClass", "(", "String", "name", ")", "throws", "ClassNotFoundException", "{", "if", "(", "delegatationLoader", "==", "null", ")", "return", "super", ".", "findClass", "(", "name", ")", ";", "return", "delegatationLoader", ".", "loadClass", "(", "name", ")", ";", "}" ]
Tries to find a Groovy class. @return the class if found @throws ClassNotFoundException if not found
[ "Tries", "to", "find", "a", "Groovy", "class", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java#L52-L55
13,203
apache/groovy
src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java
ReflectorLoader.loadClass
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (inDefine) { if (name.equals(REFLECTOR)) return Reflector.class; } return super.loadClass(name, resolve); }
java
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (inDefine) { if (name.equals(REFLECTOR)) return Reflector.class; } return super.loadClass(name, resolve); }
[ "protected", "synchronized", "Class", "loadClass", "(", "String", "name", ",", "boolean", "resolve", ")", "throws", "ClassNotFoundException", "{", "if", "(", "inDefine", ")", "{", "if", "(", "name", ".", "equals", "(", "REFLECTOR", ")", ")", "return", "Reflector", ".", "class", ";", "}", "return", "super", ".", "loadClass", "(", "name", ",", "resolve", ")", ";", "}" ]
Loads a class per name. Unlike a normal loadClass this version behaves different during a class definition. In that case it checks if the class we want to load is Reflector and returns class if the check is successful. If it is not during a class definition it just calls the super class version of loadClass. @param name of the class to load @param resolve is true if the class should be resolved @see Reflector @see ClassLoader#loadClass(String, boolean)
[ "Loads", "a", "class", "per", "name", ".", "Unlike", "a", "normal", "loadClass", "this", "version", "behaves", "different", "during", "a", "class", "definition", ".", "In", "that", "case", "it", "checks", "if", "the", "class", "we", "want", "to", "load", "is", "Reflector", "and", "returns", "class", "if", "the", "check", "is", "successful", ".", "If", "it", "is", "not", "during", "a", "class", "definition", "it", "just", "calls", "the", "super", "class", "version", "of", "loadClass", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java#L69-L74
13,204
apache/groovy
src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java
ReflectorLoader.defineClass
public synchronized Class defineClass(String name, byte[] bytecode, ProtectionDomain domain) { inDefine = true; Class c = defineClass(name, bytecode, 0, bytecode.length, domain); loadedClasses.put(name,c); resolveClass(c); inDefine = false; return c; }
java
public synchronized Class defineClass(String name, byte[] bytecode, ProtectionDomain domain) { inDefine = true; Class c = defineClass(name, bytecode, 0, bytecode.length, domain); loadedClasses.put(name,c); resolveClass(c); inDefine = false; return c; }
[ "public", "synchronized", "Class", "defineClass", "(", "String", "name", ",", "byte", "[", "]", "bytecode", ",", "ProtectionDomain", "domain", ")", "{", "inDefine", "=", "true", ";", "Class", "c", "=", "defineClass", "(", "name", ",", "bytecode", ",", "0", ",", "bytecode", ".", "length", ",", "domain", ")", ";", "loadedClasses", ".", "put", "(", "name", ",", "c", ")", ";", "resolveClass", "(", "c", ")", ";", "inDefine", "=", "false", ";", "return", "c", ";", "}" ]
helper method to define Reflector classes. @param name of the Reflector @param bytecode the bytecode @param domain the protection domain @return the generated class
[ "helper", "method", "to", "define", "Reflector", "classes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.java#L83-L90
13,205
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/Traits.java
Traits.isBridgeMethod
public static boolean isBridgeMethod(Method someMethod) { TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class); return annotation!=null; }
java
public static boolean isBridgeMethod(Method someMethod) { TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class); return annotation!=null; }
[ "public", "static", "boolean", "isBridgeMethod", "(", "Method", "someMethod", ")", "{", "TraitBridge", "annotation", "=", "someMethod", ".", "getAnnotation", "(", "TraitBridge", ".", "class", ")", ";", "return", "annotation", "!=", "null", ";", "}" ]
Reflection API to indicate whether some method is a bridge method to the default implementation of a trait. @param someMethod a method node @return null if it is not a method implemented in a trait. If it is, returns the method from the trait class.
[ "Reflection", "API", "to", "indicate", "whether", "some", "method", "is", "a", "bridge", "method", "to", "the", "default", "implementation", "of", "a", "trait", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/Traits.java#L218-L221
13,206
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/Traits.java
Traits.decomposeSuperCallName
public static String[] decomposeSuperCallName(String origName) { if (origName.contains(SUPER_TRAIT_METHOD_PREFIX)) { int endIndex = origName.indexOf(SUPER_TRAIT_METHOD_PREFIX); String tName = origName.substring(0, endIndex).replace('_','.').replace("..","_"); String fName = origName.substring(endIndex+SUPER_TRAIT_METHOD_PREFIX.length()); return new String[]{tName, fName}; } return null; }
java
public static String[] decomposeSuperCallName(String origName) { if (origName.contains(SUPER_TRAIT_METHOD_PREFIX)) { int endIndex = origName.indexOf(SUPER_TRAIT_METHOD_PREFIX); String tName = origName.substring(0, endIndex).replace('_','.').replace("..","_"); String fName = origName.substring(endIndex+SUPER_TRAIT_METHOD_PREFIX.length()); return new String[]{tName, fName}; } return null; }
[ "public", "static", "String", "[", "]", "decomposeSuperCallName", "(", "String", "origName", ")", "{", "if", "(", "origName", ".", "contains", "(", "SUPER_TRAIT_METHOD_PREFIX", ")", ")", "{", "int", "endIndex", "=", "origName", ".", "indexOf", "(", "SUPER_TRAIT_METHOD_PREFIX", ")", ";", "String", "tName", "=", "origName", ".", "substring", "(", "0", ",", "endIndex", ")", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ".", "replace", "(", "\"..\"", ",", "\"_\"", ")", ";", "String", "fName", "=", "origName", ".", "substring", "(", "endIndex", "+", "SUPER_TRAIT_METHOD_PREFIX", ".", "length", "(", ")", ")", ";", "return", "new", "String", "[", "]", "{", "tName", ",", "fName", "}", ";", "}", "return", "null", ";", "}" ]
Returns the name of a method without the super trait specific prefix. If the method name doesn't correspond to a super trait method call, the result will be null. @param origName the name of a method @return null if the name doesn't start with the super trait prefix, otherwise the name without the prefix
[ "Returns", "the", "name", "of", "a", "method", "without", "the", "super", "trait", "specific", "prefix", ".", "If", "the", "method", "name", "doesn", "t", "correspond", "to", "a", "super", "trait", "method", "call", "the", "result", "will", "be", "null", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/Traits.java#L270-L278
13,207
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/Traits.java
Traits.collectSelfTypes
public static LinkedHashSet<ClassNode> collectSelfTypes( ClassNode receiver, LinkedHashSet<ClassNode> selfTypes) { return collectSelfTypes(receiver, selfTypes, true, true); }
java
public static LinkedHashSet<ClassNode> collectSelfTypes( ClassNode receiver, LinkedHashSet<ClassNode> selfTypes) { return collectSelfTypes(receiver, selfTypes, true, true); }
[ "public", "static", "LinkedHashSet", "<", "ClassNode", ">", "collectSelfTypes", "(", "ClassNode", "receiver", ",", "LinkedHashSet", "<", "ClassNode", ">", "selfTypes", ")", "{", "return", "collectSelfTypes", "(", "receiver", ",", "selfTypes", ",", "true", ",", "true", ")", ";", "}" ]
Collects all the self types that a type should extend or implement, given the traits is implements. Collects from interfaces and superclasses too. @param receiver a class node that may implement a trait @param selfTypes a collection where the list of self types will be written @return the selfTypes collection itself @since 2.4.0
[ "Collects", "all", "the", "self", "types", "that", "a", "type", "should", "extend", "or", "implement", "given", "the", "traits", "is", "implements", ".", "Collects", "from", "interfaces", "and", "superclasses", "too", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/Traits.java#L308-L312
13,208
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/Traits.java
Traits.collectSelfTypes
public static LinkedHashSet<ClassNode> collectSelfTypes( ClassNode receiver, LinkedHashSet<ClassNode> selfTypes, boolean checkInterfaces, boolean checkSuper) { if (Traits.isTrait(receiver)) { List<AnnotationNode> annotations = receiver.getAnnotations(SELFTYPE_CLASSNODE); for (AnnotationNode annotation : annotations) { Expression value = annotation.getMember("value"); if (value instanceof ClassExpression) { selfTypes.add(value.getType()); } else if (value instanceof ListExpression) { List<Expression> expressions = ((ListExpression) value).getExpressions(); for (Expression expression : expressions) { if (expression instanceof ClassExpression) { selfTypes.add(expression.getType()); } } } } } if (checkInterfaces) { ClassNode[] interfaces = receiver.getInterfaces(); for (ClassNode anInterface : interfaces) { collectSelfTypes(anInterface, selfTypes, true, checkSuper); } } if (checkSuper) { ClassNode superClass = receiver.getSuperClass(); if (superClass != null) { collectSelfTypes(superClass, selfTypes, checkInterfaces, true); } } return selfTypes; }
java
public static LinkedHashSet<ClassNode> collectSelfTypes( ClassNode receiver, LinkedHashSet<ClassNode> selfTypes, boolean checkInterfaces, boolean checkSuper) { if (Traits.isTrait(receiver)) { List<AnnotationNode> annotations = receiver.getAnnotations(SELFTYPE_CLASSNODE); for (AnnotationNode annotation : annotations) { Expression value = annotation.getMember("value"); if (value instanceof ClassExpression) { selfTypes.add(value.getType()); } else if (value instanceof ListExpression) { List<Expression> expressions = ((ListExpression) value).getExpressions(); for (Expression expression : expressions) { if (expression instanceof ClassExpression) { selfTypes.add(expression.getType()); } } } } } if (checkInterfaces) { ClassNode[] interfaces = receiver.getInterfaces(); for (ClassNode anInterface : interfaces) { collectSelfTypes(anInterface, selfTypes, true, checkSuper); } } if (checkSuper) { ClassNode superClass = receiver.getSuperClass(); if (superClass != null) { collectSelfTypes(superClass, selfTypes, checkInterfaces, true); } } return selfTypes; }
[ "public", "static", "LinkedHashSet", "<", "ClassNode", ">", "collectSelfTypes", "(", "ClassNode", "receiver", ",", "LinkedHashSet", "<", "ClassNode", ">", "selfTypes", ",", "boolean", "checkInterfaces", ",", "boolean", "checkSuper", ")", "{", "if", "(", "Traits", ".", "isTrait", "(", "receiver", ")", ")", "{", "List", "<", "AnnotationNode", ">", "annotations", "=", "receiver", ".", "getAnnotations", "(", "SELFTYPE_CLASSNODE", ")", ";", "for", "(", "AnnotationNode", "annotation", ":", "annotations", ")", "{", "Expression", "value", "=", "annotation", ".", "getMember", "(", "\"value\"", ")", ";", "if", "(", "value", "instanceof", "ClassExpression", ")", "{", "selfTypes", ".", "add", "(", "value", ".", "getType", "(", ")", ")", ";", "}", "else", "if", "(", "value", "instanceof", "ListExpression", ")", "{", "List", "<", "Expression", ">", "expressions", "=", "(", "(", "ListExpression", ")", "value", ")", ".", "getExpressions", "(", ")", ";", "for", "(", "Expression", "expression", ":", "expressions", ")", "{", "if", "(", "expression", "instanceof", "ClassExpression", ")", "{", "selfTypes", ".", "add", "(", "expression", ".", "getType", "(", ")", ")", ";", "}", "}", "}", "}", "}", "if", "(", "checkInterfaces", ")", "{", "ClassNode", "[", "]", "interfaces", "=", "receiver", ".", "getInterfaces", "(", ")", ";", "for", "(", "ClassNode", "anInterface", ":", "interfaces", ")", "{", "collectSelfTypes", "(", "anInterface", ",", "selfTypes", ",", "true", ",", "checkSuper", ")", ";", "}", "}", "if", "(", "checkSuper", ")", "{", "ClassNode", "superClass", "=", "receiver", ".", "getSuperClass", "(", ")", ";", "if", "(", "superClass", "!=", "null", ")", "{", "collectSelfTypes", "(", "superClass", ",", "selfTypes", ",", "checkInterfaces", ",", "true", ")", ";", "}", "}", "return", "selfTypes", ";", "}" ]
Collects all the self types that a type should extend or implement, given the traits is implements. @param receiver a class node that may implement a trait @param selfTypes a collection where the list of self types will be written @param checkInterfaces should the interfaces that the node implements be collected too @param checkSuper should we collect from the superclass too @return the selfTypes collection itself @since 2.4.0
[ "Collects", "all", "the", "self", "types", "that", "a", "type", "should", "extend", "or", "implement", "given", "the", "traits", "is", "implements", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/Traits.java#L324-L359
13,209
apache/groovy
src/main/java/org/codehaus/groovy/control/messages/SyntaxErrorMessage.java
SyntaxErrorMessage.write
public void write(PrintWriter output, Janitor janitor) { String name = source.getName(); int line = getCause().getStartLine(); int column = getCause().getStartColumn(); String sample = source.getSample(line, column, janitor); output.print(name + ": " + line + ": " + getCause().getMessage()); if (sample != null) { output.println(); output.print(sample); output.println(); } }
java
public void write(PrintWriter output, Janitor janitor) { String name = source.getName(); int line = getCause().getStartLine(); int column = getCause().getStartColumn(); String sample = source.getSample(line, column, janitor); output.print(name + ": " + line + ": " + getCause().getMessage()); if (sample != null) { output.println(); output.print(sample); output.println(); } }
[ "public", "void", "write", "(", "PrintWriter", "output", ",", "Janitor", "janitor", ")", "{", "String", "name", "=", "source", ".", "getName", "(", ")", ";", "int", "line", "=", "getCause", "(", ")", ".", "getStartLine", "(", ")", ";", "int", "column", "=", "getCause", "(", ")", ".", "getStartColumn", "(", ")", ";", "String", "sample", "=", "source", ".", "getSample", "(", "line", ",", "column", ",", "janitor", ")", ";", "output", ".", "print", "(", "name", "+", "\": \"", "+", "line", "+", "\": \"", "+", "getCause", "(", ")", ".", "getMessage", "(", ")", ")", ";", "if", "(", "sample", "!=", "null", ")", "{", "output", ".", "println", "(", ")", ";", "output", ".", "print", "(", "sample", ")", ";", "output", ".", "println", "(", ")", ";", "}", "}" ]
Writes out a nicely formatted summary of the syntax error.
[ "Writes", "out", "a", "nicely", "formatted", "summary", "of", "the", "syntax", "error", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/messages/SyntaxErrorMessage.java#L50-L62
13,210
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/IndyMath.java
IndyMath.chooseMathMethod
public static boolean chooseMathMethod(Selector info, MetaMethod metaMethod) { Map<MethodType,MethodHandle> xmap = methods.get(info.name); if (xmap==null) return false; MethodType type = replaceWithMoreSpecificType(info.args, info.targetType); type = widenOperators(type); MethodHandle handle = xmap.get(type); if (handle==null) return false; info.handle = handle; return true; }
java
public static boolean chooseMathMethod(Selector info, MetaMethod metaMethod) { Map<MethodType,MethodHandle> xmap = methods.get(info.name); if (xmap==null) return false; MethodType type = replaceWithMoreSpecificType(info.args, info.targetType); type = widenOperators(type); MethodHandle handle = xmap.get(type); if (handle==null) return false; info.handle = handle; return true; }
[ "public", "static", "boolean", "chooseMathMethod", "(", "Selector", "info", ",", "MetaMethod", "metaMethod", ")", "{", "Map", "<", "MethodType", ",", "MethodHandle", ">", "xmap", "=", "methods", ".", "get", "(", "info", ".", "name", ")", ";", "if", "(", "xmap", "==", "null", ")", "return", "false", ";", "MethodType", "type", "=", "replaceWithMoreSpecificType", "(", "info", ".", "args", ",", "info", ".", "targetType", ")", ";", "type", "=", "widenOperators", "(", "type", ")", ";", "MethodHandle", "handle", "=", "xmap", ".", "get", "(", "type", ")", ";", "if", "(", "handle", "==", "null", ")", "return", "false", ";", "info", ".", "handle", "=", "handle", ";", "return", "true", ";", "}" ]
Choose a method to replace the originally chosen metaMethod to have a more efficient call path.
[ "Choose", "a", "method", "to", "replace", "the", "originally", "chosen", "metaMethod", "to", "have", "a", "more", "efficient", "call", "path", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyMath.java#L108-L120
13,211
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/IndyMath.java
IndyMath.widenOperators
private static MethodType widenOperators(MethodType mt) { if (mt.parameterCount()==2) { Class leftType = mt.parameterType(0); Class rightType = mt.parameterType(1); if (isIntCategory(leftType) && isIntCategory(rightType)) return IIV; if (isLongCategory(leftType) && isLongCategory(rightType)) return LLV; if (isBigDecCategory(leftType) && isBigDecCategory(rightType)) return GGV; if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) return DDV; return OOV; } else if (mt.parameterCount()==1) { Class leftType = mt.parameterType(0); if (isIntCategory(leftType)) return IV; if (isLongCategory(leftType)) return LV; if (isBigDecCategory(leftType)) return GV; if (isDoubleCategory(leftType)) return DV; } return mt; }
java
private static MethodType widenOperators(MethodType mt) { if (mt.parameterCount()==2) { Class leftType = mt.parameterType(0); Class rightType = mt.parameterType(1); if (isIntCategory(leftType) && isIntCategory(rightType)) return IIV; if (isLongCategory(leftType) && isLongCategory(rightType)) return LLV; if (isBigDecCategory(leftType) && isBigDecCategory(rightType)) return GGV; if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) return DDV; return OOV; } else if (mt.parameterCount()==1) { Class leftType = mt.parameterType(0); if (isIntCategory(leftType)) return IV; if (isLongCategory(leftType)) return LV; if (isBigDecCategory(leftType)) return GV; if (isDoubleCategory(leftType)) return DV; } return mt; }
[ "private", "static", "MethodType", "widenOperators", "(", "MethodType", "mt", ")", "{", "if", "(", "mt", ".", "parameterCount", "(", ")", "==", "2", ")", "{", "Class", "leftType", "=", "mt", ".", "parameterType", "(", "0", ")", ";", "Class", "rightType", "=", "mt", ".", "parameterType", "(", "1", ")", ";", "if", "(", "isIntCategory", "(", "leftType", ")", "&&", "isIntCategory", "(", "rightType", ")", ")", "return", "IIV", ";", "if", "(", "isLongCategory", "(", "leftType", ")", "&&", "isLongCategory", "(", "rightType", ")", ")", "return", "LLV", ";", "if", "(", "isBigDecCategory", "(", "leftType", ")", "&&", "isBigDecCategory", "(", "rightType", ")", ")", "return", "GGV", ";", "if", "(", "isDoubleCategory", "(", "leftType", ")", "&&", "isDoubleCategory", "(", "rightType", ")", ")", "return", "DDV", ";", "return", "OOV", ";", "}", "else", "if", "(", "mt", ".", "parameterCount", "(", ")", "==", "1", ")", "{", "Class", "leftType", "=", "mt", ".", "parameterType", "(", "0", ")", ";", "if", "(", "isIntCategory", "(", "leftType", ")", ")", "return", "IV", ";", "if", "(", "isLongCategory", "(", "leftType", ")", ")", "return", "LV", ";", "if", "(", "isBigDecCategory", "(", "leftType", ")", ")", "return", "GV", ";", "if", "(", "isDoubleCategory", "(", "leftType", ")", ")", "return", "DV", ";", "}", "return", "mt", ";", "}" ]
Widens the operators. For math operations like a+b we generally execute them using a conversion to certain types. If a for example is an int and b a byte, we do the operation using integer math. This method gives a simplified MethodType that contains the two operators with this widening according to Groovy rules applied. That means both parameters in the MethodType will have the same type.
[ "Widens", "the", "operators", ".", "For", "math", "operations", "like", "a", "+", "b", "we", "generally", "execute", "them", "using", "a", "conversion", "to", "certain", "types", ".", "If", "a", "for", "example", "is", "an", "int", "and", "b", "a", "byte", "we", "do", "the", "operation", "using", "integer", "math", ".", "This", "method", "gives", "a", "simplified", "MethodType", "that", "contains", "the", "two", "operators", "with", "this", "widening", "according", "to", "Groovy", "rules", "applied", ".", "That", "means", "both", "parameters", "in", "the", "MethodType", "will", "have", "the", "same", "type", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyMath.java#L130-L149
13,212
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.checkParameters
public void checkParameters(Class[] arguments) { // lets check that the argument types are valid if (!isValidMethod(arguments)) { throw new IllegalArgumentException( "Parameters to method: " + getName() + " do not match types: " + InvokerHelper.toString(getParameterTypes()) + " for arguments: " + InvokerHelper.toString(arguments)); } }
java
public void checkParameters(Class[] arguments) { // lets check that the argument types are valid if (!isValidMethod(arguments)) { throw new IllegalArgumentException( "Parameters to method: " + getName() + " do not match types: " + InvokerHelper.toString(getParameterTypes()) + " for arguments: " + InvokerHelper.toString(arguments)); } }
[ "public", "void", "checkParameters", "(", "Class", "[", "]", "arguments", ")", "{", "// lets check that the argument types are valid", "if", "(", "!", "isValidMethod", "(", "arguments", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Parameters to method: \"", "+", "getName", "(", ")", "+", "\" do not match types: \"", "+", "InvokerHelper", ".", "toString", "(", "getParameterTypes", "(", ")", ")", "+", "\" for arguments: \"", "+", "InvokerHelper", ".", "toString", "(", "arguments", ")", ")", ";", "}", "}" ]
Checks that the given parameters are valid to call this method @param arguments the arguments to check @throws IllegalArgumentException if the parameters are not valid
[ "Checks", "that", "the", "given", "parameters", "are", "valid", "to", "call", "this", "method" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L96-L107
13,213
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.isMethod
public boolean isMethod(MetaMethod method) { return getName().equals(method.getName()) && getModifiers() == method.getModifiers() && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
java
public boolean isMethod(MetaMethod method) { return getName().equals(method.getName()) && getModifiers() == method.getModifiers() && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
[ "public", "boolean", "isMethod", "(", "MetaMethod", "method", ")", "{", "return", "getName", "(", ")", ".", "equals", "(", "method", ".", "getName", "(", ")", ")", "&&", "getModifiers", "(", ")", "==", "method", ".", "getModifiers", "(", ")", "&&", "getReturnType", "(", ")", ".", "equals", "(", "method", ".", "getReturnType", "(", ")", ")", "&&", "equal", "(", "getParameterTypes", "(", ")", ",", "method", ".", "getParameterTypes", "(", ")", ")", ";", "}" ]
Returns true if this this metamethod represents the same method as the argument. @param method A metaMethod instance @return true if method is for the same method as this method, false otherwise.
[ "Returns", "true", "if", "this", "this", "metamethod", "represents", "the", "same", "method", "as", "the", "argument", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L115-L120
13,214
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.compatibleModifiers
private static boolean compatibleModifiers(int modifiersA, int modifiersB) { int mask = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC | Modifier.STATIC; return (modifiersA & mask) == (modifiersB & mask); }
java
private static boolean compatibleModifiers(int modifiersA, int modifiersB) { int mask = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC | Modifier.STATIC; return (modifiersA & mask) == (modifiersB & mask); }
[ "private", "static", "boolean", "compatibleModifiers", "(", "int", "modifiersA", ",", "int", "modifiersB", ")", "{", "int", "mask", "=", "Modifier", ".", "PRIVATE", "|", "Modifier", ".", "PROTECTED", "|", "Modifier", ".", "PUBLIC", "|", "Modifier", ".", "STATIC", ";", "return", "(", "modifiersA", "&", "mask", ")", "==", "(", "modifiersB", "&", "mask", ")", ";", "}" ]
Checks the compatibility between two modifier masks. Checks that they are equal with regards to access and static modifier. @return true if the modifiers are compatible
[ "Checks", "the", "compatibility", "between", "two", "modifier", "masks", ".", "Checks", "that", "they", "are", "equal", "with", "regards", "to", "access", "and", "static", "modifier", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L229-L232
13,215
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.getSignature
public synchronized String getSignature() { if (signature == null) { CachedClass [] parameters = getParameterTypes(); final String name = getName(); StringBuilder buf = new StringBuilder(name.length()+parameters.length*10); buf.append(getReturnType().getName()); buf.append(' '); buf.append(name); buf.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); } buf.append(parameters[i].getName()); } buf.append(')'); signature = buf.toString(); } return signature; }
java
public synchronized String getSignature() { if (signature == null) { CachedClass [] parameters = getParameterTypes(); final String name = getName(); StringBuilder buf = new StringBuilder(name.length()+parameters.length*10); buf.append(getReturnType().getName()); buf.append(' '); buf.append(name); buf.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); } buf.append(parameters[i].getName()); } buf.append(')'); signature = buf.toString(); } return signature; }
[ "public", "synchronized", "String", "getSignature", "(", ")", "{", "if", "(", "signature", "==", "null", ")", "{", "CachedClass", "[", "]", "parameters", "=", "getParameterTypes", "(", ")", ";", "final", "String", "name", "=", "getName", "(", ")", ";", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "name", ".", "length", "(", ")", "+", "parameters", ".", "length", "*", "10", ")", ";", "buf", ".", "append", "(", "getReturnType", "(", ")", ".", "getName", "(", ")", ")", ";", "buf", ".", "append", "(", "'", "'", ")", ";", "buf", ".", "append", "(", "name", ")", ";", "buf", ".", "append", "(", "'", "'", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "parameters", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", ">", "0", ")", "{", "buf", ".", "append", "(", "\", \"", ")", ";", "}", "buf", ".", "append", "(", "parameters", "[", "i", "]", ".", "getName", "(", ")", ")", ";", "}", "buf", ".", "append", "(", "'", "'", ")", ";", "signature", "=", "buf", ".", "toString", "(", ")", ";", "}", "return", "signature", ";", "}" ]
Returns the signature of this method @return The signature of this method
[ "Returns", "the", "signature", "of", "this", "method" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L253-L273
13,216
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.processDoMethodInvokeException
public final RuntimeException processDoMethodInvokeException (Exception e, Object object, Object [] argumentArray) { // if (e instanceof IllegalArgumentException) { // //TODO: test if this is OK with new MOP, should be changed! // // we don't want the exception being unwrapped if it is a IllegalArgumentException // // but in the case it is for example a IllegalThreadStateException, we want the unwrapping // // from the runtime // //Note: the reason we want unwrapping sometimes and sometimes not is that the method // // invocation tries to invoke the method with and then reacts with type transformation // // if the invocation failed here. This is OK for IllegalArgumentException, but it is // // possible that a Reflector will be used to execute the call and then an Exception from inside // // the method is not wrapped in a InvocationTargetException and we will end here. // boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof org.codehaus.groovy.reflection.GeneratedMetaMethod; // return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, setReason); // } if (e instanceof RuntimeException) return (RuntimeException) e; return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, true); }
java
public final RuntimeException processDoMethodInvokeException (Exception e, Object object, Object [] argumentArray) { // if (e instanceof IllegalArgumentException) { // //TODO: test if this is OK with new MOP, should be changed! // // we don't want the exception being unwrapped if it is a IllegalArgumentException // // but in the case it is for example a IllegalThreadStateException, we want the unwrapping // // from the runtime // //Note: the reason we want unwrapping sometimes and sometimes not is that the method // // invocation tries to invoke the method with and then reacts with type transformation // // if the invocation failed here. This is OK for IllegalArgumentException, but it is // // possible that a Reflector will be used to execute the call and then an Exception from inside // // the method is not wrapped in a InvocationTargetException and we will end here. // boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof org.codehaus.groovy.reflection.GeneratedMetaMethod; // return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, setReason); // } if (e instanceof RuntimeException) return (RuntimeException) e; return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, true); }
[ "public", "final", "RuntimeException", "processDoMethodInvokeException", "(", "Exception", "e", ",", "Object", "object", ",", "Object", "[", "]", "argumentArray", ")", "{", "// if (e instanceof IllegalArgumentException) {", "// //TODO: test if this is OK with new MOP, should be changed!", "// // we don't want the exception being unwrapped if it is a IllegalArgumentException", "// // but in the case it is for example a IllegalThreadStateException, we want the unwrapping", "// // from the runtime", "// //Note: the reason we want unwrapping sometimes and sometimes not is that the method", "// // invocation tries to invoke the method with and then reacts with type transformation", "// // if the invocation failed here. This is OK for IllegalArgumentException, but it is", "// // possible that a Reflector will be used to execute the call and then an Exception from inside", "// // the method is not wrapped in a InvocationTargetException and we will end here.", "// boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof org.codehaus.groovy.reflection.GeneratedMetaMethod;", "// return MetaClassHelper.createExceptionText(\"failed to invoke method: \", this, object, argumentArray, e, setReason);", "// }", "if", "(", "e", "instanceof", "RuntimeException", ")", "return", "(", "RuntimeException", ")", "e", ";", "return", "MetaClassHelper", ".", "createExceptionText", "(", "\"failed to invoke method: \"", ",", "this", ",", "object", ",", "argumentArray", ",", "e", ",", "true", ")", ";", "}" ]
This method is called when an exception occurs while invoking this method.
[ "This", "method", "is", "called", "when", "an", "exception", "occurs", "while", "invoking", "this", "method", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L291-L310
13,217
apache/groovy
src/main/groovy/groovy/lang/MetaMethod.java
MetaMethod.doMethodInvoke
public Object doMethodInvoke(Object object, Object[] argumentArray) { argumentArray = coerceArgumentsToClasses(argumentArray); try { return invoke(object, argumentArray); } catch (Exception e) { throw processDoMethodInvokeException(e, object, argumentArray); } }
java
public Object doMethodInvoke(Object object, Object[] argumentArray) { argumentArray = coerceArgumentsToClasses(argumentArray); try { return invoke(object, argumentArray); } catch (Exception e) { throw processDoMethodInvokeException(e, object, argumentArray); } }
[ "public", "Object", "doMethodInvoke", "(", "Object", "object", ",", "Object", "[", "]", "argumentArray", ")", "{", "argumentArray", "=", "coerceArgumentsToClasses", "(", "argumentArray", ")", ";", "try", "{", "return", "invoke", "(", "object", ",", "argumentArray", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "processDoMethodInvokeException", "(", "e", ",", "object", ",", "argumentArray", ")", ";", "}", "}" ]
Invokes the method this object represents. This method is not final but it should be overloaded very carefully and only by generated methods there is no guarantee that it will be called @param object The object the method is to be called at. @param argumentArray Arguments for the method invocation. @return The return value of the invoked method.
[ "Invokes", "the", "method", "this", "object", "represents", ".", "This", "method", "is", "not", "final", "but", "it", "should", "be", "overloaded", "very", "carefully", "and", "only", "by", "generated", "methods", "there", "is", "no", "guarantee", "that", "it", "will", "be", "called" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaMethod.java#L320-L327
13,218
apache/groovy
src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
StaticCompilationVisitor.checkForConstructorWithCSButClassWithout
private void checkForConstructorWithCSButClassWithout(MethodNode node) { if (!(node instanceof ConstructorNode)) return; Object meta = node.getNodeMetaData(STATIC_COMPILE_NODE); if (!Boolean.TRUE.equals(meta)) return; ClassNode clz = typeCheckingContext.getEnclosingClassNode(); meta = clz.getNodeMetaData(STATIC_COMPILE_NODE); if (Boolean.TRUE.equals(meta)) return; if ( clz.getObjectInitializerStatements().isEmpty() && clz.getFields().isEmpty() && clz.getProperties().isEmpty()) { return; } addStaticTypeError("Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.",node); }
java
private void checkForConstructorWithCSButClassWithout(MethodNode node) { if (!(node instanceof ConstructorNode)) return; Object meta = node.getNodeMetaData(STATIC_COMPILE_NODE); if (!Boolean.TRUE.equals(meta)) return; ClassNode clz = typeCheckingContext.getEnclosingClassNode(); meta = clz.getNodeMetaData(STATIC_COMPILE_NODE); if (Boolean.TRUE.equals(meta)) return; if ( clz.getObjectInitializerStatements().isEmpty() && clz.getFields().isEmpty() && clz.getProperties().isEmpty()) { return; } addStaticTypeError("Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.",node); }
[ "private", "void", "checkForConstructorWithCSButClassWithout", "(", "MethodNode", "node", ")", "{", "if", "(", "!", "(", "node", "instanceof", "ConstructorNode", ")", ")", "return", ";", "Object", "meta", "=", "node", ".", "getNodeMetaData", "(", "STATIC_COMPILE_NODE", ")", ";", "if", "(", "!", "Boolean", ".", "TRUE", ".", "equals", "(", "meta", ")", ")", "return", ";", "ClassNode", "clz", "=", "typeCheckingContext", ".", "getEnclosingClassNode", "(", ")", ";", "meta", "=", "clz", ".", "getNodeMetaData", "(", "STATIC_COMPILE_NODE", ")", ";", "if", "(", "Boolean", ".", "TRUE", ".", "equals", "(", "meta", ")", ")", "return", ";", "if", "(", "clz", ".", "getObjectInitializerStatements", "(", ")", ".", "isEmpty", "(", ")", "&&", "clz", ".", "getFields", "(", ")", ".", "isEmpty", "(", ")", "&&", "clz", ".", "getProperties", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "addStaticTypeError", "(", "\"Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.\"", ",", "node", ")", ";", "}" ]
If we are in a constructor, that is static compiled, but in a class, that is not, it may happen that init code from object initializers, fields or properties is added into the constructor code. The backend assumes a purely static constructor, so it may fail if it encounters dynamic code here. Thus we make this kind of code fail
[ "If", "we", "are", "in", "a", "constructor", "that", "is", "static", "compiled", "but", "in", "a", "class", "that", "is", "not", "it", "may", "happen", "that", "init", "code", "from", "object", "initializers", "fields", "or", "properties", "is", "added", "into", "the", "constructor", "code", ".", "The", "backend", "assumes", "a", "purely", "static", "constructor", "so", "it", "may", "fail", "if", "it", "encounters", "dynamic", "code", "here", ".", "Thus", "we", "make", "this", "kind", "of", "code", "fail" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java#L202-L217
13,219
apache/groovy
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
DefaultTypeTransformation.isEnumSubclass
@Deprecated public static boolean isEnumSubclass(Object value) { if (value instanceof Class) { Class superclass = ((Class) value).getSuperclass(); while (superclass != null) { if (superclass.getName().equals("java.lang.Enum")) { return true; } superclass = superclass.getSuperclass(); } } return false; }
java
@Deprecated public static boolean isEnumSubclass(Object value) { if (value instanceof Class) { Class superclass = ((Class) value).getSuperclass(); while (superclass != null) { if (superclass.getName().equals("java.lang.Enum")) { return true; } superclass = superclass.getSuperclass(); } } return false; }
[ "@", "Deprecated", "public", "static", "boolean", "isEnumSubclass", "(", "Object", "value", ")", "{", "if", "(", "value", "instanceof", "Class", ")", "{", "Class", "superclass", "=", "(", "(", "Class", ")", "value", ")", ".", "getSuperclass", "(", ")", ";", "while", "(", "superclass", "!=", "null", ")", "{", "if", "(", "superclass", ".", "getName", "(", ")", ".", "equals", "(", "\"java.lang.Enum\"", ")", ")", "{", "return", "true", ";", "}", "superclass", "=", "superclass", ".", "getSuperclass", "(", ")", ";", "}", "}", "return", "false", ";", "}" ]
Determines whether the value object is a Class object representing a subclass of java.lang.Enum. Uses class name check to avoid breaking on pre-Java 5 JREs. @param value an object @return true if the object is an Enum
[ "Determines", "whether", "the", "value", "object", "is", "a", "Class", "object", "representing", "a", "subclass", "of", "java", ".", "lang", ".", "Enum", ".", "Uses", "class", "name", "check", "to", "avoid", "breaking", "on", "pre", "-", "Java", "5", "JREs", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java#L494-L507
13,220
apache/groovy
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
DefaultTypeTransformation.primitiveArrayToList
public static List primitiveArrayToList(Object array) { int size = Array.getLength(array); List list = new ArrayList(size); for (int i = 0; i < size; i++) { Object item = Array.get(array, i); if (item != null && item.getClass().isArray() && item.getClass().getComponentType().isPrimitive()) { item = primitiveArrayToList(item); } list.add(item); } return list; }
java
public static List primitiveArrayToList(Object array) { int size = Array.getLength(array); List list = new ArrayList(size); for (int i = 0; i < size; i++) { Object item = Array.get(array, i); if (item != null && item.getClass().isArray() && item.getClass().getComponentType().isPrimitive()) { item = primitiveArrayToList(item); } list.add(item); } return list; }
[ "public", "static", "List", "primitiveArrayToList", "(", "Object", "array", ")", "{", "int", "size", "=", "Array", ".", "getLength", "(", "array", ")", ";", "List", "list", "=", "new", "ArrayList", "(", "size", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "size", ";", "i", "++", ")", "{", "Object", "item", "=", "Array", ".", "get", "(", "array", ",", "i", ")", ";", "if", "(", "item", "!=", "null", "&&", "item", ".", "getClass", "(", ")", ".", "isArray", "(", ")", "&&", "item", ".", "getClass", "(", ")", ".", "getComponentType", "(", ")", ".", "isPrimitive", "(", ")", ")", "{", "item", "=", "primitiveArrayToList", "(", "item", ")", ";", "}", "list", ".", "add", "(", "item", ")", ";", "}", "return", "list", ";", "}" ]
Allows conversion of arrays into a mutable List @param array an array @return the array as a List
[ "Allows", "conversion", "of", "arrays", "into", "a", "mutable", "List" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java#L515-L526
13,221
apache/groovy
src/main/groovy/groovy/util/IndentPrinter.java
IndentPrinter.println
public void println(String text) { try { if(autoIndent) printIndent(); out.write(text); println(); } catch(IOException ioe) { throw new GroovyRuntimeException(ioe); } }
java
public void println(String text) { try { if(autoIndent) printIndent(); out.write(text); println(); } catch(IOException ioe) { throw new GroovyRuntimeException(ioe); } }
[ "public", "void", "println", "(", "String", "text", ")", "{", "try", "{", "if", "(", "autoIndent", ")", "printIndent", "(", ")", ";", "out", ".", "write", "(", "text", ")", ";", "println", "(", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "GroovyRuntimeException", "(", "ioe", ")", ";", "}", "}" ]
Prints a string followed by an end of line character. @param text String to be written
[ "Prints", "a", "string", "followed", "by", "an", "end", "of", "line", "character", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/util/IndentPrinter.java#L134-L142
13,222
apache/groovy
src/main/groovy/groovy/util/IndentPrinter.java
IndentPrinter.printIndent
public void printIndent() { for (int i = 0; i < indentLevel; i++) { try { out.write(indent); } catch(IOException ioe) { throw new GroovyRuntimeException(ioe); } } }
java
public void printIndent() { for (int i = 0; i < indentLevel; i++) { try { out.write(indent); } catch(IOException ioe) { throw new GroovyRuntimeException(ioe); } } }
[ "public", "void", "printIndent", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "indentLevel", ";", "i", "++", ")", "{", "try", "{", "out", ".", "write", "(", "indent", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "GroovyRuntimeException", "(", "ioe", ")", ";", "}", "}", "}" ]
Prints the current indent level.
[ "Prints", "the", "current", "indent", "level", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/util/IndentPrinter.java#L173-L181
13,223
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.getDeclaredMethodsFromSuper
public static Map<String, MethodNode> getDeclaredMethodsFromSuper(ClassNode cNode) { ClassNode parent = cNode.getSuperClass(); if (parent == null) { return new HashMap<String, MethodNode>(); } return parent.getDeclaredMethodsMap(); }
java
public static Map<String, MethodNode> getDeclaredMethodsFromSuper(ClassNode cNode) { ClassNode parent = cNode.getSuperClass(); if (parent == null) { return new HashMap<String, MethodNode>(); } return parent.getDeclaredMethodsMap(); }
[ "public", "static", "Map", "<", "String", ",", "MethodNode", ">", "getDeclaredMethodsFromSuper", "(", "ClassNode", "cNode", ")", "{", "ClassNode", "parent", "=", "cNode", ".", "getSuperClass", "(", ")", ";", "if", "(", "parent", "==", "null", ")", "{", "return", "new", "HashMap", "<", "String", ",", "MethodNode", ">", "(", ")", ";", "}", "return", "parent", ".", "getDeclaredMethodsMap", "(", ")", ";", "}" ]
Add methods from the super class. @param cNode The ClassNode @return A map of methods
[ "Add", "methods", "from", "the", "super", "class", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L143-L149
13,224
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.addDeclaredMethodsFromInterfaces
public static void addDeclaredMethodsFromInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { // add in unimplemented abstract methods from the interfaces for (ClassNode iface : cNode.getInterfaces()) { Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap(); for (Map.Entry<String, MethodNode> entry : ifaceMethodsMap.entrySet()) { String methSig = entry.getKey(); if (!methodsMap.containsKey(methSig)) { methodsMap.put(methSig, entry.getValue()); } } } }
java
public static void addDeclaredMethodsFromInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { // add in unimplemented abstract methods from the interfaces for (ClassNode iface : cNode.getInterfaces()) { Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap(); for (Map.Entry<String, MethodNode> entry : ifaceMethodsMap.entrySet()) { String methSig = entry.getKey(); if (!methodsMap.containsKey(methSig)) { methodsMap.put(methSig, entry.getValue()); } } } }
[ "public", "static", "void", "addDeclaredMethodsFromInterfaces", "(", "ClassNode", "cNode", ",", "Map", "<", "String", ",", "MethodNode", ">", "methodsMap", ")", "{", "// add in unimplemented abstract methods from the interfaces", "for", "(", "ClassNode", "iface", ":", "cNode", ".", "getInterfaces", "(", ")", ")", "{", "Map", "<", "String", ",", "MethodNode", ">", "ifaceMethodsMap", "=", "iface", ".", "getDeclaredMethodsMap", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "MethodNode", ">", "entry", ":", "ifaceMethodsMap", ".", "entrySet", "(", ")", ")", "{", "String", "methSig", "=", "entry", ".", "getKey", "(", ")", ";", "if", "(", "!", "methodsMap", ".", "containsKey", "(", "methSig", ")", ")", "{", "methodsMap", ".", "put", "(", "methSig", ",", "entry", ".", "getValue", "(", ")", ")", ";", "}", "}", "}", "}" ]
Add in methods from all interfaces. Existing entries in the methods map take precedence. Methods from interfaces visited early take precedence over later ones. @param cNode The ClassNode @param methodsMap A map of existing methods to alter
[ "Add", "in", "methods", "from", "all", "interfaces", ".", "Existing", "entries", "in", "the", "methods", "map", "take", "precedence", ".", "Methods", "from", "interfaces", "visited", "early", "take", "precedence", "over", "later", "ones", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L158-L169
13,225
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.getDeclaredMethodsFromInterfaces
public static Map<String, MethodNode> getDeclaredMethodsFromInterfaces(ClassNode cNode) { Map<String, MethodNode> result = new HashMap<String, MethodNode>(); ClassNode[] interfaces = cNode.getInterfaces(); for (ClassNode iface : interfaces) { result.putAll(iface.getDeclaredMethodsMap()); } return result; }
java
public static Map<String, MethodNode> getDeclaredMethodsFromInterfaces(ClassNode cNode) { Map<String, MethodNode> result = new HashMap<String, MethodNode>(); ClassNode[] interfaces = cNode.getInterfaces(); for (ClassNode iface : interfaces) { result.putAll(iface.getDeclaredMethodsMap()); } return result; }
[ "public", "static", "Map", "<", "String", ",", "MethodNode", ">", "getDeclaredMethodsFromInterfaces", "(", "ClassNode", "cNode", ")", "{", "Map", "<", "String", ",", "MethodNode", ">", "result", "=", "new", "HashMap", "<", "String", ",", "MethodNode", ">", "(", ")", ";", "ClassNode", "[", "]", "interfaces", "=", "cNode", ".", "getInterfaces", "(", ")", ";", "for", "(", "ClassNode", "iface", ":", "interfaces", ")", "{", "result", ".", "putAll", "(", "iface", ".", "getDeclaredMethodsMap", "(", ")", ")", ";", "}", "return", "result", ";", "}" ]
Get methods from all interfaces. Methods from interfaces visited early will be overwritten by later ones. @param cNode The ClassNode @return A map of methods
[ "Get", "methods", "from", "all", "interfaces", ".", "Methods", "from", "interfaces", "visited", "early", "will", "be", "overwritten", "by", "later", "ones", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L178-L185
13,226
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.addDeclaredMethodsFromAllInterfaces
public static void addDeclaredMethodsFromAllInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { List cnInterfaces = Arrays.asList(cNode.getInterfaces()); ClassNode parent = cNode.getSuperClass(); while (parent != null && !parent.equals(ClassHelper.OBJECT_TYPE)) { ClassNode[] interfaces = parent.getInterfaces(); for (ClassNode iface : interfaces) { if (!cnInterfaces.contains(iface)) { methodsMap.putAll(iface.getDeclaredMethodsMap()); } } parent = parent.getSuperClass(); } }
java
public static void addDeclaredMethodsFromAllInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { List cnInterfaces = Arrays.asList(cNode.getInterfaces()); ClassNode parent = cNode.getSuperClass(); while (parent != null && !parent.equals(ClassHelper.OBJECT_TYPE)) { ClassNode[] interfaces = parent.getInterfaces(); for (ClassNode iface : interfaces) { if (!cnInterfaces.contains(iface)) { methodsMap.putAll(iface.getDeclaredMethodsMap()); } } parent = parent.getSuperClass(); } }
[ "public", "static", "void", "addDeclaredMethodsFromAllInterfaces", "(", "ClassNode", "cNode", ",", "Map", "<", "String", ",", "MethodNode", ">", "methodsMap", ")", "{", "List", "cnInterfaces", "=", "Arrays", ".", "asList", "(", "cNode", ".", "getInterfaces", "(", ")", ")", ";", "ClassNode", "parent", "=", "cNode", ".", "getSuperClass", "(", ")", ";", "while", "(", "parent", "!=", "null", "&&", "!", "parent", ".", "equals", "(", "ClassHelper", ".", "OBJECT_TYPE", ")", ")", "{", "ClassNode", "[", "]", "interfaces", "=", "parent", ".", "getInterfaces", "(", ")", ";", "for", "(", "ClassNode", "iface", ":", "interfaces", ")", "{", "if", "(", "!", "cnInterfaces", ".", "contains", "(", "iface", ")", ")", "{", "methodsMap", ".", "putAll", "(", "iface", ".", "getDeclaredMethodsMap", "(", ")", ")", ";", "}", "}", "parent", "=", "parent", ".", "getSuperClass", "(", ")", ";", "}", "}" ]
Adds methods from interfaces and parent interfaces. Existing entries in the methods map take precedence. Methods from interfaces visited early take precedence over later ones. @param cNode The ClassNode @param methodsMap A map of existing methods to alter
[ "Adds", "methods", "from", "interfaces", "and", "parent", "interfaces", ".", "Existing", "entries", "in", "the", "methods", "map", "take", "precedence", ".", "Methods", "from", "interfaces", "visited", "early", "take", "precedence", "over", "later", "ones", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L194-L206
13,227
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.hasPossibleStaticMethod
public static boolean hasPossibleStaticMethod(ClassNode cNode, String name, Expression arguments, boolean trySpread) { int count = 0; boolean foundSpread = false; if (arguments instanceof TupleExpression) { TupleExpression tuple = (TupleExpression) arguments; for (Expression arg : tuple.getExpressions()) { if (arg instanceof SpreadExpression) { foundSpread = true; } else { count++; } } } else if (arguments instanceof MapExpression) { count = 1; } for (MethodNode method : cNode.getMethods(name)) { if (method.isStatic()) { Parameter[] parameters = method.getParameters(); // do fuzzy match for spread case: count will be number of non-spread args if (trySpread && foundSpread && parameters.length >= count) return true; if (parameters.length == count) return true; // handle varargs case if (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray()) { if (count >= parameters.length - 1) return true; // fuzzy match any spread to a varargs if (trySpread && foundSpread) return true; } // handle parameters with default values int nonDefaultParameters = 0; for (Parameter parameter : parameters) { if (!parameter.hasInitialExpression()) { nonDefaultParameters++; } } if (count < parameters.length && nonDefaultParameters <= count) { return true; } // TODO handle spread with nonDefaultParams? } } return false; }
java
public static boolean hasPossibleStaticMethod(ClassNode cNode, String name, Expression arguments, boolean trySpread) { int count = 0; boolean foundSpread = false; if (arguments instanceof TupleExpression) { TupleExpression tuple = (TupleExpression) arguments; for (Expression arg : tuple.getExpressions()) { if (arg instanceof SpreadExpression) { foundSpread = true; } else { count++; } } } else if (arguments instanceof MapExpression) { count = 1; } for (MethodNode method : cNode.getMethods(name)) { if (method.isStatic()) { Parameter[] parameters = method.getParameters(); // do fuzzy match for spread case: count will be number of non-spread args if (trySpread && foundSpread && parameters.length >= count) return true; if (parameters.length == count) return true; // handle varargs case if (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray()) { if (count >= parameters.length - 1) return true; // fuzzy match any spread to a varargs if (trySpread && foundSpread) return true; } // handle parameters with default values int nonDefaultParameters = 0; for (Parameter parameter : parameters) { if (!parameter.hasInitialExpression()) { nonDefaultParameters++; } } if (count < parameters.length && nonDefaultParameters <= count) { return true; } // TODO handle spread with nonDefaultParams? } } return false; }
[ "public", "static", "boolean", "hasPossibleStaticMethod", "(", "ClassNode", "cNode", ",", "String", "name", ",", "Expression", "arguments", ",", "boolean", "trySpread", ")", "{", "int", "count", "=", "0", ";", "boolean", "foundSpread", "=", "false", ";", "if", "(", "arguments", "instanceof", "TupleExpression", ")", "{", "TupleExpression", "tuple", "=", "(", "TupleExpression", ")", "arguments", ";", "for", "(", "Expression", "arg", ":", "tuple", ".", "getExpressions", "(", ")", ")", "{", "if", "(", "arg", "instanceof", "SpreadExpression", ")", "{", "foundSpread", "=", "true", ";", "}", "else", "{", "count", "++", ";", "}", "}", "}", "else", "if", "(", "arguments", "instanceof", "MapExpression", ")", "{", "count", "=", "1", ";", "}", "for", "(", "MethodNode", "method", ":", "cNode", ".", "getMethods", "(", "name", ")", ")", "{", "if", "(", "method", ".", "isStatic", "(", ")", ")", "{", "Parameter", "[", "]", "parameters", "=", "method", ".", "getParameters", "(", ")", ";", "// do fuzzy match for spread case: count will be number of non-spread args", "if", "(", "trySpread", "&&", "foundSpread", "&&", "parameters", ".", "length", ">=", "count", ")", "return", "true", ";", "if", "(", "parameters", ".", "length", "==", "count", ")", "return", "true", ";", "// handle varargs case", "if", "(", "parameters", ".", "length", ">", "0", "&&", "parameters", "[", "parameters", ".", "length", "-", "1", "]", ".", "getType", "(", ")", ".", "isArray", "(", ")", ")", "{", "if", "(", "count", ">=", "parameters", ".", "length", "-", "1", ")", "return", "true", ";", "// fuzzy match any spread to a varargs", "if", "(", "trySpread", "&&", "foundSpread", ")", "return", "true", ";", "}", "// handle parameters with default values", "int", "nonDefaultParameters", "=", "0", ";", "for", "(", "Parameter", "parameter", ":", "parameters", ")", "{", "if", "(", "!", "parameter", ".", "hasInitialExpression", "(", ")", ")", "{", "nonDefaultParameters", "++", ";", "}", "}", "if", "(", "count", "<", "parameters", ".", "length", "&&", "nonDefaultParameters", "<=", "count", ")", "{", "return", "true", ";", "}", "// TODO handle spread with nonDefaultParams?", "}", "}", "return", "false", ";", "}" ]
Returns true if the given method has a possibly matching static method with the given name and arguments. Handles default arguments and optionally spread expressions. @param cNode the ClassNode of interest @param name the name of the method of interest @param arguments the arguments to match against @param trySpread whether to try to account for SpreadExpressions within the arguments @return true if a matching method was found
[ "Returns", "true", "if", "the", "given", "method", "has", "a", "possibly", "matching", "static", "method", "with", "the", "given", "name", "and", "arguments", ".", "Handles", "default", "arguments", "and", "optionally", "spread", "expressions", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L218-L265
13,228
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.hasPossibleStaticProperty
public static boolean hasPossibleStaticProperty(ClassNode cNode, String methodName) { // assume explicit static method call checked first so we can assume a simple check here if (!methodName.startsWith("get") && !methodName.startsWith("is")) { return false; } String propName = getPropNameForAccessor(methodName); PropertyNode pNode = getStaticProperty(cNode, propName); return pNode != null && (methodName.startsWith("get") || boolean_TYPE.equals(pNode.getType())); }
java
public static boolean hasPossibleStaticProperty(ClassNode cNode, String methodName) { // assume explicit static method call checked first so we can assume a simple check here if (!methodName.startsWith("get") && !methodName.startsWith("is")) { return false; } String propName = getPropNameForAccessor(methodName); PropertyNode pNode = getStaticProperty(cNode, propName); return pNode != null && (methodName.startsWith("get") || boolean_TYPE.equals(pNode.getType())); }
[ "public", "static", "boolean", "hasPossibleStaticProperty", "(", "ClassNode", "cNode", ",", "String", "methodName", ")", "{", "// assume explicit static method call checked first so we can assume a simple check here", "if", "(", "!", "methodName", ".", "startsWith", "(", "\"get\"", ")", "&&", "!", "methodName", ".", "startsWith", "(", "\"is\"", ")", ")", "{", "return", "false", ";", "}", "String", "propName", "=", "getPropNameForAccessor", "(", "methodName", ")", ";", "PropertyNode", "pNode", "=", "getStaticProperty", "(", "cNode", ",", "propName", ")", ";", "return", "pNode", "!=", "null", "&&", "(", "methodName", ".", "startsWith", "(", "\"get\"", ")", "||", "boolean_TYPE", ".", "equals", "(", "pNode", ".", "getType", "(", ")", ")", ")", ";", "}" ]
Return true if we have a static accessor
[ "Return", "true", "if", "we", "have", "a", "static", "accessor" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L270-L278
13,229
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.isValidAccessorName
public static boolean isValidAccessorName(String accessorName) { if (accessorName.startsWith("get") || accessorName.startsWith("is") || accessorName.startsWith("set")) { int prefixLength = accessorName.startsWith("is") ? 2 : 3; return accessorName.length() > prefixLength; }; return false; }
java
public static boolean isValidAccessorName(String accessorName) { if (accessorName.startsWith("get") || accessorName.startsWith("is") || accessorName.startsWith("set")) { int prefixLength = accessorName.startsWith("is") ? 2 : 3; return accessorName.length() > prefixLength; }; return false; }
[ "public", "static", "boolean", "isValidAccessorName", "(", "String", "accessorName", ")", "{", "if", "(", "accessorName", ".", "startsWith", "(", "\"get\"", ")", "||", "accessorName", ".", "startsWith", "(", "\"is\"", ")", "||", "accessorName", ".", "startsWith", "(", "\"set\"", ")", ")", "{", "int", "prefixLength", "=", "accessorName", ".", "startsWith", "(", "\"is\"", ")", "?", "2", ":", "3", ";", "return", "accessorName", ".", "length", "(", ")", ">", "prefixLength", ";", "}", ";", "return", "false", ";", "}" ]
Detect whether the given accessor name starts with "get", "set" or "is" followed by at least one character. @param accessorName the accessor name of interest, e.g. getAge @return true if a valid prefix is found
[ "Detect", "whether", "the", "given", "accessor", "name", "starts", "with", "get", "set", "or", "is", "followed", "by", "at", "least", "one", "character", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L299-L305
13,230
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.getStaticProperty
public static PropertyNode getStaticProperty(ClassNode cNode, String propName) { ClassNode classNode = cNode; while (classNode != null) { for (PropertyNode pn : classNode.getProperties()) { if (pn.getName().equals(propName) && pn.isStatic()) return pn; } classNode = classNode.getSuperClass(); } return null; }
java
public static PropertyNode getStaticProperty(ClassNode cNode, String propName) { ClassNode classNode = cNode; while (classNode != null) { for (PropertyNode pn : classNode.getProperties()) { if (pn.getName().equals(propName) && pn.isStatic()) return pn; } classNode = classNode.getSuperClass(); } return null; }
[ "public", "static", "PropertyNode", "getStaticProperty", "(", "ClassNode", "cNode", ",", "String", "propName", ")", "{", "ClassNode", "classNode", "=", "cNode", ";", "while", "(", "classNode", "!=", "null", ")", "{", "for", "(", "PropertyNode", "pn", ":", "classNode", ".", "getProperties", "(", ")", ")", "{", "if", "(", "pn", ".", "getName", "(", ")", ".", "equals", "(", "propName", ")", "&&", "pn", ".", "isStatic", "(", ")", ")", "return", "pn", ";", "}", "classNode", "=", "classNode", ".", "getSuperClass", "(", ")", ";", "}", "return", "null", ";", "}" ]
Detect whether a static property with the given name is within the class or a super class. @param cNode the ClassNode of interest @param propName the property name @return the static property if found or else null
[ "Detect", "whether", "a", "static", "property", "with", "the", "given", "name", "is", "within", "the", "class", "or", "a", "super", "class", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L319-L328
13,231
apache/groovy
src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
ClassNodeUtils.samePackageName
public static boolean samePackageName(ClassNode first, ClassNode second) { return Objects.equals(first.getPackageName(), second.getPackageName()); }
java
public static boolean samePackageName(ClassNode first, ClassNode second) { return Objects.equals(first.getPackageName(), second.getPackageName()); }
[ "public", "static", "boolean", "samePackageName", "(", "ClassNode", "first", ",", "ClassNode", "second", ")", "{", "return", "Objects", ".", "equals", "(", "first", ".", "getPackageName", "(", ")", ",", "second", ".", "getPackageName", "(", ")", ")", ";", "}" ]
Determine if the given ClassNode values have the same package name. @param first a ClassNode @param second a ClassNode @return true if both given nodes have the same package name @throws NullPointerException if either of the given nodes are null
[ "Determine", "if", "the", "given", "ClassNode", "values", "have", "the", "same", "package", "name", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L385-L387
13,232
apache/groovy
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
Groovy.computeScriptName
private String computeScriptName() { if (srcFile != null) { return srcFile.getAbsolutePath(); } else { String name = PREFIX; if (getLocation().getFileName().length() > 0) name += getLocation().getFileName().replaceAll("[^\\w_\\.]", "_").replaceAll("[\\.]", "_dot_"); else name += SUFFIX; return name; } }
java
private String computeScriptName() { if (srcFile != null) { return srcFile.getAbsolutePath(); } else { String name = PREFIX; if (getLocation().getFileName().length() > 0) name += getLocation().getFileName().replaceAll("[^\\w_\\.]", "_").replaceAll("[\\.]", "_dot_"); else name += SUFFIX; return name; } }
[ "private", "String", "computeScriptName", "(", ")", "{", "if", "(", "srcFile", "!=", "null", ")", "{", "return", "srcFile", ".", "getAbsolutePath", "(", ")", ";", "}", "else", "{", "String", "name", "=", "PREFIX", ";", "if", "(", "getLocation", "(", ")", ".", "getFileName", "(", ")", ".", "length", "(", ")", ">", "0", ")", "name", "+=", "getLocation", "(", ")", ".", "getFileName", "(", ")", ".", "replaceAll", "(", "\"[^\\\\w_\\\\.]\"", ",", "\"_\"", ")", ".", "replaceAll", "(", "\"[\\\\.]\"", ",", "\"_dot_\"", ")", ";", "else", "name", "+=", "SUFFIX", ";", "return", "name", ";", "}", "}" ]
Try to build a script name for the script of the groovy task to have an helpful value in stack traces in case of exception @return the name to use when compiling the script
[ "Try", "to", "build", "a", "script", "name", "for", "the", "script", "of", "the", "groovy", "task", "to", "have", "an", "helpful", "value", "in", "stack", "traces", "in", "case", "of", "exception" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java#L620-L632
13,233
apache/groovy
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
Groovy.printResults
protected void printResults(PrintStream out) { log.debug("printResults()"); StringBuilder line = new StringBuilder(); out.println(line); out.println(); }
java
protected void printResults(PrintStream out) { log.debug("printResults()"); StringBuilder line = new StringBuilder(); out.println(line); out.println(); }
[ "protected", "void", "printResults", "(", "PrintStream", "out", ")", "{", "log", ".", "debug", "(", "\"printResults()\"", ")", ";", "StringBuilder", "line", "=", "new", "StringBuilder", "(", ")", ";", "out", ".", "println", "(", "line", ")", ";", "out", ".", "println", "(", ")", ";", "}" ]
print any results in the statement. @param out the output PrintStream to print to
[ "print", "any", "results", "in", "the", "statement", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java#L652-L657
13,234
apache/groovy
src/main/java/org/codehaus/groovy/antlr/java/PreJava2GroovyConverter.java
PreJava2GroovyConverter.swapTwoChildren
public void swapTwoChildren(GroovySourceAST t) { // this swaps the two child nodes, see javadoc above for explanation of implementation GroovySourceAST a = (GroovySourceAST) t.getFirstChild(); GroovySourceAST b = (GroovySourceAST) a.getNextSibling(); t.setFirstChild(b); a.setNextSibling(null); b.setNextSibling(a); }
java
public void swapTwoChildren(GroovySourceAST t) { // this swaps the two child nodes, see javadoc above for explanation of implementation GroovySourceAST a = (GroovySourceAST) t.getFirstChild(); GroovySourceAST b = (GroovySourceAST) a.getNextSibling(); t.setFirstChild(b); a.setNextSibling(null); b.setNextSibling(a); }
[ "public", "void", "swapTwoChildren", "(", "GroovySourceAST", "t", ")", "{", "// this swaps the two child nodes, see javadoc above for explanation of implementation", "GroovySourceAST", "a", "=", "(", "GroovySourceAST", ")", "t", ".", "getFirstChild", "(", ")", ";", "GroovySourceAST", "b", "=", "(", "GroovySourceAST", ")", "a", ".", "getNextSibling", "(", ")", ";", "t", ".", "setFirstChild", "(", "b", ")", ";", "a", ".", "setNextSibling", "(", "null", ")", ";", "b", ".", "setNextSibling", "(", "a", ")", ";", "}" ]
To swap two children of node t... <pre> (t) | | (a) -- (b) t.down = firstNode a.right = b b.right = null </pre> becomes <pre> (t) | | (b) -- (a) t.down = b a.right = null b.right = a </pre> todo - build API of basic tree mutations like this method.
[ "To", "swap", "two", "children", "of", "node", "t", "..." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/java/PreJava2GroovyConverter.java#L116-L124
13,235
apache/groovy
src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java
StackTraceUtils.extractRootCause
public static Throwable extractRootCause(Throwable t) { Throwable result = t; while (result.getCause() != null) { result = result.getCause(); } return result; }
java
public static Throwable extractRootCause(Throwable t) { Throwable result = t; while (result.getCause() != null) { result = result.getCause(); } return result; }
[ "public", "static", "Throwable", "extractRootCause", "(", "Throwable", "t", ")", "{", "Throwable", "result", "=", "t", ";", "while", "(", "result", ".", "getCause", "(", ")", "!=", "null", ")", "{", "result", "=", "result", ".", "getCause", "(", ")", ";", "}", "return", "result", ";", "}" ]
Extracts the root cause of the exception, no matter how nested it is @param t a Throwable @return The deepest cause of the exception that can be found
[ "Extracts", "the", "root", "cause", "of", "the", "exception", "no", "matter", "how", "nested", "it", "is" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java#L159-L165
13,236
apache/groovy
src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java
MethodCallExpression.getMethodAsString
public String getMethodAsString() { if (! (method instanceof ConstantExpression)) return null; ConstantExpression constant = (ConstantExpression) method; return constant.getText(); }
java
public String getMethodAsString() { if (! (method instanceof ConstantExpression)) return null; ConstantExpression constant = (ConstantExpression) method; return constant.getText(); }
[ "public", "String", "getMethodAsString", "(", ")", "{", "if", "(", "!", "(", "method", "instanceof", "ConstantExpression", ")", ")", "return", "null", ";", "ConstantExpression", "constant", "=", "(", "ConstantExpression", ")", "method", ";", "return", "constant", ".", "getText", "(", ")", ";", "}" ]
This method returns the method name as String if it is no dynamic calculated method name, but a constant.
[ "This", "method", "returns", "the", "method", "name", "as", "String", "if", "it", "is", "no", "dynamic", "calculated", "method", "name", "but", "a", "constant", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java#L112-L116
13,237
apache/groovy
subprojects/groovy-console/src/main/groovy/groovy/ui/SystemOutputInterceptor.java
SystemOutputInterceptor.write
public void write(int b) throws IOException { Boolean result = (Boolean) callback.call(consoleId.get(), String.valueOf((char) b)); if (result) { out.write(b); } }
java
public void write(int b) throws IOException { Boolean result = (Boolean) callback.call(consoleId.get(), String.valueOf((char) b)); if (result) { out.write(b); } }
[ "public", "void", "write", "(", "int", "b", ")", "throws", "IOException", "{", "Boolean", "result", "=", "(", "Boolean", ")", "callback", ".", "call", "(", "consoleId", ".", "get", "(", ")", ",", "String", ".", "valueOf", "(", "(", "char", ")", "b", ")", ")", ";", "if", "(", "result", ")", "{", "out", ".", "write", "(", "b", ")", ";", "}", "}" ]
Intercepts output - single characters
[ "Intercepts", "output", "-", "single", "characters" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-console/src/main/groovy/groovy/ui/SystemOutputInterceptor.java#L108-L113
13,238
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/TypeCheckingContext.java
TypeCheckingContext.pushEnclosingMethodCall
public void pushEnclosingMethodCall(Expression call) { if (call instanceof MethodCallExpression || call instanceof StaticMethodCallExpression) { enclosingMethodCalls.addFirst(call); } else { throw new IllegalArgumentException("Expression must be a method call or a static method call"); } }
java
public void pushEnclosingMethodCall(Expression call) { if (call instanceof MethodCallExpression || call instanceof StaticMethodCallExpression) { enclosingMethodCalls.addFirst(call); } else { throw new IllegalArgumentException("Expression must be a method call or a static method call"); } }
[ "public", "void", "pushEnclosingMethodCall", "(", "Expression", "call", ")", "{", "if", "(", "call", "instanceof", "MethodCallExpression", "||", "call", "instanceof", "StaticMethodCallExpression", ")", "{", "enclosingMethodCalls", ".", "addFirst", "(", "call", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Expression must be a method call or a static method call\"", ")", ";", "}", "}" ]
Pushes a method call into the method call stack. @param call the call expression to be pushed, either a {@link MethodCallExpression} or a {@link StaticMethodCallExpression}
[ "Pushes", "a", "method", "call", "into", "the", "method", "call", "stack", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/TypeCheckingContext.java#L345-L351
13,239
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
GeneralUtils.cmpX
public static BinaryExpression cmpX(Expression lhv, Expression rhv) { return new BinaryExpression(lhv, CMP, rhv); }
java
public static BinaryExpression cmpX(Expression lhv, Expression rhv) { return new BinaryExpression(lhv, CMP, rhv); }
[ "public", "static", "BinaryExpression", "cmpX", "(", "Expression", "lhv", ",", "Expression", "rhv", ")", "{", "return", "new", "BinaryExpression", "(", "lhv", ",", "CMP", ",", "rhv", ")", ";", "}" ]
Build a binary expression that compares two values @param lhv expression for the value to compare from @param rhv expression for the value value to compare to @return the expression comparing two values
[ "Build", "a", "binary", "expression", "that", "compares", "two", "values" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java#L238-L240
13,240
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
GeneralUtils.convertASTToSource
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws Exception { if (expression == null) throw new IllegalArgumentException("Null: expression"); StringBuilder result = new StringBuilder(); for (int x = expression.getLineNumber(); x <= expression.getLastLineNumber(); x++) { String line = readerSource.getLine(x, null); if (line == null) { throw new Exception( "Error calculating source code for expression. Trying to read line " + x + " from " + readerSource.getClass() ); } if (x == expression.getLastLineNumber()) { line = line.substring(0, expression.getLastColumnNumber() - 1); } if (x == expression.getLineNumber()) { line = line.substring(expression.getColumnNumber() - 1); } //restoring line breaks is important b/c of lack of semicolons result.append(line).append('\n'); } String source = result.toString().trim(); return source; }
java
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws Exception { if (expression == null) throw new IllegalArgumentException("Null: expression"); StringBuilder result = new StringBuilder(); for (int x = expression.getLineNumber(); x <= expression.getLastLineNumber(); x++) { String line = readerSource.getLine(x, null); if (line == null) { throw new Exception( "Error calculating source code for expression. Trying to read line " + x + " from " + readerSource.getClass() ); } if (x == expression.getLastLineNumber()) { line = line.substring(0, expression.getLastColumnNumber() - 1); } if (x == expression.getLineNumber()) { line = line.substring(expression.getColumnNumber() - 1); } //restoring line breaks is important b/c of lack of semicolons result.append(line).append('\n'); } String source = result.toString().trim(); return source; }
[ "public", "static", "String", "convertASTToSource", "(", "ReaderSource", "readerSource", ",", "ASTNode", "expression", ")", "throws", "Exception", "{", "if", "(", "expression", "==", "null", ")", "throw", "new", "IllegalArgumentException", "(", "\"Null: expression\"", ")", ";", "StringBuilder", "result", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "x", "=", "expression", ".", "getLineNumber", "(", ")", ";", "x", "<=", "expression", ".", "getLastLineNumber", "(", ")", ";", "x", "++", ")", "{", "String", "line", "=", "readerSource", ".", "getLine", "(", "x", ",", "null", ")", ";", "if", "(", "line", "==", "null", ")", "{", "throw", "new", "Exception", "(", "\"Error calculating source code for expression. Trying to read line \"", "+", "x", "+", "\" from \"", "+", "readerSource", ".", "getClass", "(", ")", ")", ";", "}", "if", "(", "x", "==", "expression", ".", "getLastLineNumber", "(", ")", ")", "{", "line", "=", "line", ".", "substring", "(", "0", ",", "expression", ".", "getLastColumnNumber", "(", ")", "-", "1", ")", ";", "}", "if", "(", "x", "==", "expression", ".", "getLineNumber", "(", ")", ")", "{", "line", "=", "line", ".", "substring", "(", "expression", ".", "getColumnNumber", "(", ")", "-", "1", ")", ";", "}", "//restoring line breaks is important b/c of lack of semicolons", "result", ".", "append", "(", "line", ")", ".", "append", "(", "'", "'", ")", ";", "}", "String", "source", "=", "result", ".", "toString", "(", ")", ".", "trim", "(", ")", ";", "return", "source", ";", "}" ]
Converts an expression into the String source. Only some specific expressions like closure expression support this. @param readerSource a source @param expression an expression. Can't be null @return the source the closure was created from @throws java.lang.IllegalArgumentException when expression is null @throws java.lang.Exception when closure can't be read from source
[ "Converts", "an", "expression", "into", "the", "String", "source", ".", "Only", "some", "specific", "expressions", "like", "closure", "expression", "support", "this", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java#L834-L859
13,241
apache/groovy
src/main/groovy/groovy/lang/ProxyMetaClass.java
ProxyMetaClass.getProperty
public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1) { if (null == interceptor) { return super.getProperty(aClass, object, property, b, b1); } if (interceptor instanceof PropertyAccessInterceptor) { PropertyAccessInterceptor pae = (PropertyAccessInterceptor) interceptor; Object result = pae.beforeGet(object, property); if (interceptor.doInvoke()) { result = super.getProperty(aClass, object, property, b, b1); } return result; } return super.getProperty(aClass, object, property, b, b1); }
java
public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1) { if (null == interceptor) { return super.getProperty(aClass, object, property, b, b1); } if (interceptor instanceof PropertyAccessInterceptor) { PropertyAccessInterceptor pae = (PropertyAccessInterceptor) interceptor; Object result = pae.beforeGet(object, property); if (interceptor.doInvoke()) { result = super.getProperty(aClass, object, property, b, b1); } return result; } return super.getProperty(aClass, object, property, b, b1); }
[ "public", "Object", "getProperty", "(", "Class", "aClass", ",", "Object", "object", ",", "String", "property", ",", "boolean", "b", ",", "boolean", "b1", ")", "{", "if", "(", "null", "==", "interceptor", ")", "{", "return", "super", ".", "getProperty", "(", "aClass", ",", "object", ",", "property", ",", "b", ",", "b1", ")", ";", "}", "if", "(", "interceptor", "instanceof", "PropertyAccessInterceptor", ")", "{", "PropertyAccessInterceptor", "pae", "=", "(", "PropertyAccessInterceptor", ")", "interceptor", ";", "Object", "result", "=", "pae", ".", "beforeGet", "(", "object", ",", "property", ")", ";", "if", "(", "interceptor", ".", "doInvoke", "(", ")", ")", "{", "result", "=", "super", ".", "getProperty", "(", "aClass", ",", "object", ",", "property", ",", "b", ",", "b1", ")", ";", "}", "return", "result", ";", "}", "return", "super", ".", "getProperty", "(", "aClass", ",", "object", ",", "property", ",", "b", ",", "b1", ")", ";", "}" ]
Interceptors the call to getProperty if a PropertyAccessInterceptor is available @param object the object to invoke the getter on @param property the property name @return the value of the property
[ "Interceptors", "the", "call", "to", "getProperty", "if", "a", "PropertyAccessInterceptor", "is", "available" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/ProxyMetaClass.java#L176-L190
13,242
apache/groovy
src/main/groovy/groovy/lang/ProxyMetaClass.java
ProxyMetaClass.setProperty
public void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1) { if (null == interceptor) { super.setProperty(aClass, object, property, newValue, b, b1); } if (interceptor instanceof PropertyAccessInterceptor) { PropertyAccessInterceptor pae = (PropertyAccessInterceptor) interceptor; pae.beforeSet(object, property, newValue); if (interceptor.doInvoke()) { super.setProperty(aClass, object, property, newValue, b, b1); } } else { super.setProperty(aClass, object, property, newValue, b, b1); } }
java
public void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1) { if (null == interceptor) { super.setProperty(aClass, object, property, newValue, b, b1); } if (interceptor instanceof PropertyAccessInterceptor) { PropertyAccessInterceptor pae = (PropertyAccessInterceptor) interceptor; pae.beforeSet(object, property, newValue); if (interceptor.doInvoke()) { super.setProperty(aClass, object, property, newValue, b, b1); } } else { super.setProperty(aClass, object, property, newValue, b, b1); } }
[ "public", "void", "setProperty", "(", "Class", "aClass", ",", "Object", "object", ",", "String", "property", ",", "Object", "newValue", ",", "boolean", "b", ",", "boolean", "b1", ")", "{", "if", "(", "null", "==", "interceptor", ")", "{", "super", ".", "setProperty", "(", "aClass", ",", "object", ",", "property", ",", "newValue", ",", "b", ",", "b1", ")", ";", "}", "if", "(", "interceptor", "instanceof", "PropertyAccessInterceptor", ")", "{", "PropertyAccessInterceptor", "pae", "=", "(", "PropertyAccessInterceptor", ")", "interceptor", ";", "pae", ".", "beforeSet", "(", "object", ",", "property", ",", "newValue", ")", ";", "if", "(", "interceptor", ".", "doInvoke", "(", ")", ")", "{", "super", ".", "setProperty", "(", "aClass", ",", "object", ",", "property", ",", "newValue", ",", "b", ",", "b1", ")", ";", "}", "}", "else", "{", "super", ".", "setProperty", "(", "aClass", ",", "object", ",", "property", ",", "newValue", ",", "b", ",", "b1", ")", ";", "}", "}" ]
Interceptors the call to a property setter if a PropertyAccessInterceptor is available @param object The object to invoke the setter on @param property The property name to set @param newValue The new value of the property
[ "Interceptors", "the", "call", "to", "a", "property", "setter", "if", "a", "PropertyAccessInterceptor", "is", "available" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/ProxyMetaClass.java#L200-L214
13,243
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.includeGroovy
public void includeGroovy(String templatePath) throws IOException, ClassNotFoundException { URL resource = engine.resolveTemplate(templatePath); engine.createTypeCheckedModelTemplate(resource, modelTypes).make(model).writeTo(out); }
java
public void includeGroovy(String templatePath) throws IOException, ClassNotFoundException { URL resource = engine.resolveTemplate(templatePath); engine.createTypeCheckedModelTemplate(resource, modelTypes).make(model).writeTo(out); }
[ "public", "void", "includeGroovy", "(", "String", "templatePath", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "URL", "resource", "=", "engine", ".", "resolveTemplate", "(", "templatePath", ")", ";", "engine", ".", "createTypeCheckedModelTemplate", "(", "resource", ",", "modelTypes", ")", ".", "make", "(", "model", ")", ".", "writeTo", "(", "out", ")", ";", "}" ]
Includes another template inside this template. @param templatePath the path to the included resource. @throws IOException @throws ClassNotFoundException
[ "Includes", "another", "template", "inside", "this", "template", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L303-L306
13,244
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.includeEscaped
public void includeEscaped(String templatePath) throws IOException { URL resource = engine.resolveTemplate(templatePath); yield(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding())); }
java
public void includeEscaped(String templatePath) throws IOException { URL resource = engine.resolveTemplate(templatePath); yield(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding())); }
[ "public", "void", "includeEscaped", "(", "String", "templatePath", ")", "throws", "IOException", "{", "URL", "resource", "=", "engine", ".", "resolveTemplate", "(", "templatePath", ")", ";", "yield", "(", "ResourceGroovyMethods", ".", "getText", "(", "resource", ",", "engine", ".", "getCompilerConfiguration", "(", ")", ".", "getSourceEncoding", "(", ")", ")", ")", ";", "}" ]
Includes contents of another file, not as a template but as escaped text. @param templatePath the path to the other file @throws IOException
[ "Includes", "contents", "of", "another", "file", "not", "as", "a", "template", "but", "as", "escaped", "text", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L315-L318
13,245
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.includeUnescaped
public void includeUnescaped(String templatePath) throws IOException { URL resource = engine.resolveTemplate(templatePath); yieldUnescaped(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding())); }
java
public void includeUnescaped(String templatePath) throws IOException { URL resource = engine.resolveTemplate(templatePath); yieldUnescaped(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding())); }
[ "public", "void", "includeUnescaped", "(", "String", "templatePath", ")", "throws", "IOException", "{", "URL", "resource", "=", "engine", ".", "resolveTemplate", "(", "templatePath", ")", ";", "yieldUnescaped", "(", "ResourceGroovyMethods", ".", "getText", "(", "resource", ",", "engine", ".", "getCompilerConfiguration", "(", ")", ".", "getSourceEncoding", "(", ")", ")", ")", ";", "}" ]
Includes contents of another file, not as a template but as unescaped text. @param templatePath the path to the other file @throws IOException
[ "Includes", "contents", "of", "another", "file", "not", "as", "a", "template", "but", "as", "unescaped", "text", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L326-L329
13,246
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.layout
public Object layout(Map model, String templateName, boolean inheritModel) throws IOException, ClassNotFoundException { Map submodel = inheritModel ? forkModel(model) : model; URL resource = engine.resolveTemplate(templateName); engine.createTypeCheckedModelTemplate(resource, modelTypes).make(submodel).writeTo(out); return this; }
java
public Object layout(Map model, String templateName, boolean inheritModel) throws IOException, ClassNotFoundException { Map submodel = inheritModel ? forkModel(model) : model; URL resource = engine.resolveTemplate(templateName); engine.createTypeCheckedModelTemplate(resource, modelTypes).make(submodel).writeTo(out); return this; }
[ "public", "Object", "layout", "(", "Map", "model", ",", "String", "templateName", ",", "boolean", "inheritModel", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "Map", "submodel", "=", "inheritModel", "?", "forkModel", "(", "model", ")", ":", "model", ";", "URL", "resource", "=", "engine", ".", "resolveTemplate", "(", "templateName", ")", ";", "engine", ".", "createTypeCheckedModelTemplate", "(", "resource", ",", "modelTypes", ")", ".", "make", "(", "submodel", ")", ".", "writeTo", "(", "out", ")", ";", "return", "this", ";", "}" ]
Imports a template and renders it using the specified model, allowing fine grained composition of templates and layouting. This works similarily to a template include but allows a distinct model to be used. If the layout inherits from the parent model, a new model is created, with the values from the parent model, eventually overridden with those provided specifically for this layout. @param model model to be passed to the template @param templateName the name of the template to be used as a layout @param inheritModel a boolean indicating if we should inherit the parent model @return this template instance @throws IOException @throws ClassNotFoundException
[ "Imports", "a", "template", "and", "renders", "it", "using", "the", "specified", "model", "allowing", "fine", "grained", "composition", "of", "templates", "and", "layouting", ".", "This", "works", "similarily", "to", "a", "template", "include", "but", "allows", "a", "distinct", "model", "to", "be", "used", ".", "If", "the", "layout", "inherits", "from", "the", "parent", "model", "a", "new", "model", "is", "created", "with", "the", "values", "from", "the", "parent", "model", "eventually", "overridden", "with", "those", "provided", "specifically", "for", "this", "layout", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L412-L417
13,247
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.contents
public Closure contents(final Closure cl) { return new Closure(cl.getOwner(), cl.getThisObject()) { private static final long serialVersionUID = -5733727697043906478L; @Override public Object call() { cl.call(); return ""; } @Override public Object call(final Object... args) { cl.call(args); return ""; } @Override public Object call(final Object arguments) { cl.call(arguments); return ""; } }; }
java
public Closure contents(final Closure cl) { return new Closure(cl.getOwner(), cl.getThisObject()) { private static final long serialVersionUID = -5733727697043906478L; @Override public Object call() { cl.call(); return ""; } @Override public Object call(final Object... args) { cl.call(args); return ""; } @Override public Object call(final Object arguments) { cl.call(arguments); return ""; } }; }
[ "public", "Closure", "contents", "(", "final", "Closure", "cl", ")", "{", "return", "new", "Closure", "(", "cl", ".", "getOwner", "(", ")", ",", "cl", ".", "getThisObject", "(", ")", ")", "{", "private", "static", "final", "long", "serialVersionUID", "=", "-", "5733727697043906478L", ";", "@", "Override", "public", "Object", "call", "(", ")", "{", "cl", ".", "call", "(", ")", ";", "return", "\"\"", ";", "}", "@", "Override", "public", "Object", "call", "(", "final", "Object", "...", "args", ")", "{", "cl", ".", "call", "(", "args", ")", ";", "return", "\"\"", ";", "}", "@", "Override", "public", "Object", "call", "(", "final", "Object", "arguments", ")", "{", "cl", ".", "call", "(", "arguments", ")", ";", "return", "\"\"", ";", "}", "}", ";", "}" ]
Wraps a closure so that it can be used as a prototype for inclusion in layouts. This is useful when you want to use a closure in a model, but that you don't want to render the result of the closure but instead call it as if it was a specification of a template fragment. @param cl the fragment to be wrapped @return a wrapped closure returning an empty string
[ "Wraps", "a", "closure", "so", "that", "it", "can", "be", "used", "as", "a", "prototype", "for", "inclusion", "in", "layouts", ".", "This", "is", "useful", "when", "you", "want", "to", "use", "a", "closure", "in", "a", "model", "but", "that", "you", "don", "t", "want", "to", "render", "the", "result", "of", "the", "closure", "but", "instead", "call", "it", "as", "if", "it", "was", "a", "specification", "of", "a", "template", "fragment", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L434-L456
13,248
apache/groovy
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
BaseTemplate.writeTo
public Writer writeTo(final Writer out) throws IOException { if (this.out!=null) { // StackOverflow prevention return NullWriter.DEFAULT; } try { this.out = createWriter(out); run(); return out; } finally { if (this.out!=null) { this.out.flush(); } this.out = null; } }
java
public Writer writeTo(final Writer out) throws IOException { if (this.out!=null) { // StackOverflow prevention return NullWriter.DEFAULT; } try { this.out = createWriter(out); run(); return out; } finally { if (this.out!=null) { this.out.flush(); } this.out = null; } }
[ "public", "Writer", "writeTo", "(", "final", "Writer", "out", ")", "throws", "IOException", "{", "if", "(", "this", ".", "out", "!=", "null", ")", "{", "// StackOverflow prevention", "return", "NullWriter", ".", "DEFAULT", ";", "}", "try", "{", "this", ".", "out", "=", "createWriter", "(", "out", ")", ";", "run", "(", ")", ";", "return", "out", ";", "}", "finally", "{", "if", "(", "this", ".", "out", "!=", "null", ")", "{", "this", ".", "out", ".", "flush", "(", ")", ";", "}", "this", ".", "out", "=", "null", ";", "}", "}" ]
Main method used to render a template. @param out the Writer to which this Writable should output its data. @return a writer instance @throws IOException
[ "Main", "method", "used", "to", "render", "a", "template", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java#L464-L479
13,249
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.findTargetVariable
protected static Variable findTargetVariable(VariableExpression ve) { final Variable accessedVariable = ve.getAccessedVariable() != null ? ve.getAccessedVariable() : ve; if (accessedVariable != ve) { if (accessedVariable instanceof VariableExpression) return findTargetVariable((VariableExpression) accessedVariable); } return accessedVariable; }
java
protected static Variable findTargetVariable(VariableExpression ve) { final Variable accessedVariable = ve.getAccessedVariable() != null ? ve.getAccessedVariable() : ve; if (accessedVariable != ve) { if (accessedVariable instanceof VariableExpression) return findTargetVariable((VariableExpression) accessedVariable); } return accessedVariable; }
[ "protected", "static", "Variable", "findTargetVariable", "(", "VariableExpression", "ve", ")", "{", "final", "Variable", "accessedVariable", "=", "ve", ".", "getAccessedVariable", "(", ")", "!=", "null", "?", "ve", ".", "getAccessedVariable", "(", ")", ":", "ve", ";", "if", "(", "accessedVariable", "!=", "ve", ")", "{", "if", "(", "accessedVariable", "instanceof", "VariableExpression", ")", "return", "findTargetVariable", "(", "(", "VariableExpression", ")", "accessedVariable", ")", ";", "}", "return", "accessedVariable", ";", "}" ]
Given a variable expression, returns the ultimately accessed variable. @param ve a variable expression @return the target variable
[ "Given", "a", "variable", "expression", "returns", "the", "ultimately", "accessed", "variable", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L289-L296
13,250
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.allParametersAndArgumentsMatchWithDefaultParams
static int allParametersAndArgumentsMatchWithDefaultParams(Parameter[] params, ClassNode[] args) { int dist = 0; ClassNode ptype = null; // we already know the lengths are equal for (int i = 0, j = 0; i < params.length; i++) { Parameter param = params[i]; ClassNode paramType = param.getType(); ClassNode arg = j >= args.length ? null : args[j]; if (arg == null || !isAssignableTo(arg, paramType)) { if (!param.hasInitialExpression() && (ptype == null || !ptype.equals(paramType))) { return -1; // no default value } // a default value exists, we can skip this param ptype = null; } else { j++; if (!paramType.equals(arg)) dist += getDistance(arg, paramType); if (param.hasInitialExpression()) { ptype = arg; } else { ptype = null; } } } return dist; }
java
static int allParametersAndArgumentsMatchWithDefaultParams(Parameter[] params, ClassNode[] args) { int dist = 0; ClassNode ptype = null; // we already know the lengths are equal for (int i = 0, j = 0; i < params.length; i++) { Parameter param = params[i]; ClassNode paramType = param.getType(); ClassNode arg = j >= args.length ? null : args[j]; if (arg == null || !isAssignableTo(arg, paramType)) { if (!param.hasInitialExpression() && (ptype == null || !ptype.equals(paramType))) { return -1; // no default value } // a default value exists, we can skip this param ptype = null; } else { j++; if (!paramType.equals(arg)) dist += getDistance(arg, paramType); if (param.hasInitialExpression()) { ptype = arg; } else { ptype = null; } } } return dist; }
[ "static", "int", "allParametersAndArgumentsMatchWithDefaultParams", "(", "Parameter", "[", "]", "params", ",", "ClassNode", "[", "]", "args", ")", "{", "int", "dist", "=", "0", ";", "ClassNode", "ptype", "=", "null", ";", "// we already know the lengths are equal", "for", "(", "int", "i", "=", "0", ",", "j", "=", "0", ";", "i", "<", "params", ".", "length", ";", "i", "++", ")", "{", "Parameter", "param", "=", "params", "[", "i", "]", ";", "ClassNode", "paramType", "=", "param", ".", "getType", "(", ")", ";", "ClassNode", "arg", "=", "j", ">=", "args", ".", "length", "?", "null", ":", "args", "[", "j", "]", ";", "if", "(", "arg", "==", "null", "||", "!", "isAssignableTo", "(", "arg", ",", "paramType", ")", ")", "{", "if", "(", "!", "param", ".", "hasInitialExpression", "(", ")", "&&", "(", "ptype", "==", "null", "||", "!", "ptype", ".", "equals", "(", "paramType", ")", ")", ")", "{", "return", "-", "1", ";", "// no default value", "}", "// a default value exists, we can skip this param", "ptype", "=", "null", ";", "}", "else", "{", "j", "++", ";", "if", "(", "!", "paramType", ".", "equals", "(", "arg", ")", ")", "dist", "+=", "getDistance", "(", "arg", ",", "paramType", ")", ";", "if", "(", "param", ".", "hasInitialExpression", "(", ")", ")", "{", "ptype", "=", "arg", ";", "}", "else", "{", "ptype", "=", "null", ";", "}", "}", "}", "return", "dist", ";", "}" ]
Checks that arguments and parameter types match, expecting that the number of parameters is strictly greater than the number of arguments, allowing possible inclusion of default parameters. @param params method parameters @param args type arguments @return -1 if arguments do not match, 0 if arguments are of the exact type and >0 when one or more argument is not of the exact type but still match
[ "Checks", "that", "arguments", "and", "parameter", "types", "match", "expecting", "that", "the", "number", "of", "parameters", "is", "strictly", "greater", "than", "the", "number", "of", "arguments", "allowing", "possible", "inclusion", "of", "default", "parameters", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L384-L409
13,251
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.isWildcardLeftHandSide
public static boolean isWildcardLeftHandSide(final ClassNode node) { if (OBJECT_TYPE.equals(node) || STRING_TYPE.equals(node) || boolean_TYPE.equals(node) || Boolean_TYPE.equals(node) || CLASS_Type.equals(node)) { return true; } return false; }
java
public static boolean isWildcardLeftHandSide(final ClassNode node) { if (OBJECT_TYPE.equals(node) || STRING_TYPE.equals(node) || boolean_TYPE.equals(node) || Boolean_TYPE.equals(node) || CLASS_Type.equals(node)) { return true; } return false; }
[ "public", "static", "boolean", "isWildcardLeftHandSide", "(", "final", "ClassNode", "node", ")", "{", "if", "(", "OBJECT_TYPE", ".", "equals", "(", "node", ")", "||", "STRING_TYPE", ".", "equals", "(", "node", ")", "||", "boolean_TYPE", ".", "equals", "(", "node", ")", "||", "Boolean_TYPE", ".", "equals", "(", "node", ")", "||", "CLASS_Type", ".", "equals", "(", "node", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Tells if a class is one of the "accept all" classes as the left hand side of an assignment. @param node the classnode to test @return true if it's an Object, String, boolean, Boolean or Class.
[ "Tells", "if", "a", "class", "is", "one", "of", "the", "accept", "all", "classes", "as", "the", "left", "hand", "side", "of", "an", "assignment", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L791-L800
13,252
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.parameterizeArguments
public static Parameter[] parameterizeArguments(final ClassNode receiver, final MethodNode m) { Map<GenericsTypeName, GenericsType> genericFromReceiver = GenericsUtils.extractPlaceholders(receiver); Map<GenericsTypeName, GenericsType> contextPlaceholders = extractGenericsParameterMapOfThis(m); Parameter[] methodParameters = m.getParameters(); Parameter[] params = new Parameter[methodParameters.length]; for (int i = 0; i < methodParameters.length; i++) { Parameter methodParameter = methodParameters[i]; ClassNode paramType = methodParameter.getType(); params[i] = buildParameter(genericFromReceiver, contextPlaceholders, methodParameter, paramType); } return params; }
java
public static Parameter[] parameterizeArguments(final ClassNode receiver, final MethodNode m) { Map<GenericsTypeName, GenericsType> genericFromReceiver = GenericsUtils.extractPlaceholders(receiver); Map<GenericsTypeName, GenericsType> contextPlaceholders = extractGenericsParameterMapOfThis(m); Parameter[] methodParameters = m.getParameters(); Parameter[] params = new Parameter[methodParameters.length]; for (int i = 0; i < methodParameters.length; i++) { Parameter methodParameter = methodParameters[i]; ClassNode paramType = methodParameter.getType(); params[i] = buildParameter(genericFromReceiver, contextPlaceholders, methodParameter, paramType); } return params; }
[ "public", "static", "Parameter", "[", "]", "parameterizeArguments", "(", "final", "ClassNode", "receiver", ",", "final", "MethodNode", "m", ")", "{", "Map", "<", "GenericsTypeName", ",", "GenericsType", ">", "genericFromReceiver", "=", "GenericsUtils", ".", "extractPlaceholders", "(", "receiver", ")", ";", "Map", "<", "GenericsTypeName", ",", "GenericsType", ">", "contextPlaceholders", "=", "extractGenericsParameterMapOfThis", "(", "m", ")", ";", "Parameter", "[", "]", "methodParameters", "=", "m", ".", "getParameters", "(", ")", ";", "Parameter", "[", "]", "params", "=", "new", "Parameter", "[", "methodParameters", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "methodParameters", ".", "length", ";", "i", "++", ")", "{", "Parameter", "methodParameter", "=", "methodParameters", "[", "i", "]", ";", "ClassNode", "paramType", "=", "methodParameter", ".", "getType", "(", ")", ";", "params", "[", "i", "]", "=", "buildParameter", "(", "genericFromReceiver", ",", "contextPlaceholders", ",", "methodParameter", ",", "paramType", ")", ";", "}", "return", "params", ";", "}" ]
Given a receiver and a method node, parameterize the method arguments using available generic type information. @param receiver the class @param m the method @return the parameterized arguments
[ "Given", "a", "receiver", "and", "a", "method", "node", "parameterize", "the", "method", "arguments", "using", "available", "generic", "type", "information", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1307-L1318
13,253
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.isUsingGenericsOrIsArrayUsingGenerics
public static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn) { if (cn.isArray()) { return isUsingGenericsOrIsArrayUsingGenerics(cn.getComponentType()); } return (cn.isUsingGenerics() && cn.getGenericsTypes() != null); }
java
public static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn) { if (cn.isArray()) { return isUsingGenericsOrIsArrayUsingGenerics(cn.getComponentType()); } return (cn.isUsingGenerics() && cn.getGenericsTypes() != null); }
[ "public", "static", "boolean", "isUsingGenericsOrIsArrayUsingGenerics", "(", "ClassNode", "cn", ")", "{", "if", "(", "cn", ".", "isArray", "(", ")", ")", "{", "return", "isUsingGenericsOrIsArrayUsingGenerics", "(", "cn", ".", "getComponentType", "(", ")", ")", ";", "}", "return", "(", "cn", ".", "isUsingGenerics", "(", ")", "&&", "cn", ".", "getGenericsTypes", "(", ")", "!=", "null", ")", ";", "}" ]
Returns true if a class node makes use of generic types. If the class node represents an array type, then checks if the component type is using generics. @param cn a class node for which to check if it is using generics @return true if the type (or component type) is using generics
[ "Returns", "true", "if", "a", "class", "node", "makes", "use", "of", "generic", "types", ".", "If", "the", "class", "node", "represents", "an", "array", "type", "then", "checks", "if", "the", "component", "type", "is", "using", "generics", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1351-L1356
13,254
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.fullyResolve
protected static GenericsType fullyResolve(GenericsType gt, Map<GenericsTypeName, GenericsType> placeholders) { GenericsType fromMap = placeholders.get(new GenericsTypeName(gt.getName())); if (gt.isPlaceholder() && fromMap != null) { gt = fromMap; } ClassNode type = fullyResolveType(gt.getType(), placeholders); ClassNode lowerBound = gt.getLowerBound(); if (lowerBound != null) lowerBound = fullyResolveType(lowerBound, placeholders); ClassNode[] upperBounds = gt.getUpperBounds(); if (upperBounds != null) { ClassNode[] copy = new ClassNode[upperBounds.length]; for (int i = 0, upperBoundsLength = upperBounds.length; i < upperBoundsLength; i++) { final ClassNode upperBound = upperBounds[i]; copy[i] = fullyResolveType(upperBound, placeholders); } upperBounds = copy; } GenericsType genericsType = new GenericsType(type, upperBounds, lowerBound); genericsType.setWildcard(gt.isWildcard()); return genericsType; }
java
protected static GenericsType fullyResolve(GenericsType gt, Map<GenericsTypeName, GenericsType> placeholders) { GenericsType fromMap = placeholders.get(new GenericsTypeName(gt.getName())); if (gt.isPlaceholder() && fromMap != null) { gt = fromMap; } ClassNode type = fullyResolveType(gt.getType(), placeholders); ClassNode lowerBound = gt.getLowerBound(); if (lowerBound != null) lowerBound = fullyResolveType(lowerBound, placeholders); ClassNode[] upperBounds = gt.getUpperBounds(); if (upperBounds != null) { ClassNode[] copy = new ClassNode[upperBounds.length]; for (int i = 0, upperBoundsLength = upperBounds.length; i < upperBoundsLength; i++) { final ClassNode upperBound = upperBounds[i]; copy[i] = fullyResolveType(upperBound, placeholders); } upperBounds = copy; } GenericsType genericsType = new GenericsType(type, upperBounds, lowerBound); genericsType.setWildcard(gt.isWildcard()); return genericsType; }
[ "protected", "static", "GenericsType", "fullyResolve", "(", "GenericsType", "gt", ",", "Map", "<", "GenericsTypeName", ",", "GenericsType", ">", "placeholders", ")", "{", "GenericsType", "fromMap", "=", "placeholders", ".", "get", "(", "new", "GenericsTypeName", "(", "gt", ".", "getName", "(", ")", ")", ")", ";", "if", "(", "gt", ".", "isPlaceholder", "(", ")", "&&", "fromMap", "!=", "null", ")", "{", "gt", "=", "fromMap", ";", "}", "ClassNode", "type", "=", "fullyResolveType", "(", "gt", ".", "getType", "(", ")", ",", "placeholders", ")", ";", "ClassNode", "lowerBound", "=", "gt", ".", "getLowerBound", "(", ")", ";", "if", "(", "lowerBound", "!=", "null", ")", "lowerBound", "=", "fullyResolveType", "(", "lowerBound", ",", "placeholders", ")", ";", "ClassNode", "[", "]", "upperBounds", "=", "gt", ".", "getUpperBounds", "(", ")", ";", "if", "(", "upperBounds", "!=", "null", ")", "{", "ClassNode", "[", "]", "copy", "=", "new", "ClassNode", "[", "upperBounds", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ",", "upperBoundsLength", "=", "upperBounds", ".", "length", ";", "i", "<", "upperBoundsLength", ";", "i", "++", ")", "{", "final", "ClassNode", "upperBound", "=", "upperBounds", "[", "i", "]", ";", "copy", "[", "i", "]", "=", "fullyResolveType", "(", "upperBound", ",", "placeholders", ")", ";", "}", "upperBounds", "=", "copy", ";", "}", "GenericsType", "genericsType", "=", "new", "GenericsType", "(", "type", ",", "upperBounds", ",", "lowerBound", ")", ";", "genericsType", ".", "setWildcard", "(", "gt", ".", "isWildcard", "(", ")", ")", ";", "return", "genericsType", ";", "}" ]
Given a generics type representing SomeClass&lt;T,V&gt; and a resolved placeholder map, returns a new generics type for which placeholders are resolved recursively.
[ "Given", "a", "generics", "type", "representing", "SomeClass&lt", ";", "T", "V&gt", ";", "and", "a", "resolved", "placeholder", "map", "returns", "a", "new", "generics", "type", "for", "which", "placeholders", "are", "resolved", "recursively", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1362-L1383
13,255
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.typeCheckMethodArgumentWithGenerics
protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg) { if (UNKNOWN_PARAMETER_TYPE == argumentType) { // called with null return !isPrimitiveType(parameterType); } if (!isAssignableTo(argumentType, parameterType) && !lastArg) { // incompatible assignment return false; } if (!isAssignableTo(argumentType, parameterType) && lastArg) { if (parameterType.isArray()) { if (!isAssignableTo(argumentType, parameterType.getComponentType())) { return false; } } else { return false; } } if (parameterType.isUsingGenerics() && argumentType.isUsingGenerics()) { GenericsType gt = GenericsUtils.buildWildcardType(parameterType); if (!gt.isCompatibleWith(argumentType)) { boolean samCoercion = isSAMType(parameterType) && argumentType.equals(CLOSURE_TYPE); if (!samCoercion) return false; } } else if (parameterType.isArray() && argumentType.isArray()) { // verify component type return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType.getComponentType(), lastArg); } else if (lastArg && parameterType.isArray()) { // verify component type, but if we reach that point, the only possibility is that the argument is // the last one of the call, so we're in the cast of a vargs call // (otherwise, we face a type checker bug) return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType, lastArg); } return true; }
java
protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg) { if (UNKNOWN_PARAMETER_TYPE == argumentType) { // called with null return !isPrimitiveType(parameterType); } if (!isAssignableTo(argumentType, parameterType) && !lastArg) { // incompatible assignment return false; } if (!isAssignableTo(argumentType, parameterType) && lastArg) { if (parameterType.isArray()) { if (!isAssignableTo(argumentType, parameterType.getComponentType())) { return false; } } else { return false; } } if (parameterType.isUsingGenerics() && argumentType.isUsingGenerics()) { GenericsType gt = GenericsUtils.buildWildcardType(parameterType); if (!gt.isCompatibleWith(argumentType)) { boolean samCoercion = isSAMType(parameterType) && argumentType.equals(CLOSURE_TYPE); if (!samCoercion) return false; } } else if (parameterType.isArray() && argumentType.isArray()) { // verify component type return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType.getComponentType(), lastArg); } else if (lastArg && parameterType.isArray()) { // verify component type, but if we reach that point, the only possibility is that the argument is // the last one of the call, so we're in the cast of a vargs call // (otherwise, we face a type checker bug) return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType, lastArg); } return true; }
[ "protected", "static", "boolean", "typeCheckMethodArgumentWithGenerics", "(", "ClassNode", "parameterType", ",", "ClassNode", "argumentType", ",", "boolean", "lastArg", ")", "{", "if", "(", "UNKNOWN_PARAMETER_TYPE", "==", "argumentType", ")", "{", "// called with null", "return", "!", "isPrimitiveType", "(", "parameterType", ")", ";", "}", "if", "(", "!", "isAssignableTo", "(", "argumentType", ",", "parameterType", ")", "&&", "!", "lastArg", ")", "{", "// incompatible assignment", "return", "false", ";", "}", "if", "(", "!", "isAssignableTo", "(", "argumentType", ",", "parameterType", ")", "&&", "lastArg", ")", "{", "if", "(", "parameterType", ".", "isArray", "(", ")", ")", "{", "if", "(", "!", "isAssignableTo", "(", "argumentType", ",", "parameterType", ".", "getComponentType", "(", ")", ")", ")", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "if", "(", "parameterType", ".", "isUsingGenerics", "(", ")", "&&", "argumentType", ".", "isUsingGenerics", "(", ")", ")", "{", "GenericsType", "gt", "=", "GenericsUtils", ".", "buildWildcardType", "(", "parameterType", ")", ";", "if", "(", "!", "gt", ".", "isCompatibleWith", "(", "argumentType", ")", ")", "{", "boolean", "samCoercion", "=", "isSAMType", "(", "parameterType", ")", "&&", "argumentType", ".", "equals", "(", "CLOSURE_TYPE", ")", ";", "if", "(", "!", "samCoercion", ")", "return", "false", ";", "}", "}", "else", "if", "(", "parameterType", ".", "isArray", "(", ")", "&&", "argumentType", ".", "isArray", "(", ")", ")", "{", "// verify component type", "return", "typeCheckMethodArgumentWithGenerics", "(", "parameterType", ".", "getComponentType", "(", ")", ",", "argumentType", ".", "getComponentType", "(", ")", ",", "lastArg", ")", ";", "}", "else", "if", "(", "lastArg", "&&", "parameterType", ".", "isArray", "(", ")", ")", "{", "// verify component type, but if we reach that point, the only possibility is that the argument is", "// the last one of the call, so we're in the cast of a vargs call", "// (otherwise, we face a type checker bug)", "return", "typeCheckMethodArgumentWithGenerics", "(", "parameterType", ".", "getComponentType", "(", ")", ",", "argumentType", ",", "lastArg", ")", ";", "}", "return", "true", ";", "}" ]
Checks that the parameterized generics of an argument are compatible with the generics of the parameter. @param parameterType the parameter type of a method @param argumentType the type of the argument passed to the method
[ "Checks", "that", "the", "parameterized", "generics", "of", "an", "argument", "are", "compatible", "with", "the", "generics", "of", "the", "parameter", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1421-L1455
13,256
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.boundUnboundedWildcards
static ClassNode boundUnboundedWildcards(ClassNode type) { if (type.isArray()) { return boundUnboundedWildcards(type.getComponentType()).makeArray(); } ClassNode target = type.redirect(); if (target == null || type == target || !isUsingGenericsOrIsArrayUsingGenerics(target)) return type; ClassNode newType = type.getPlainNodeReference(); newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder()); newType.setGenericsTypes(boundUnboundedWildcards(type.getGenericsTypes(), target.getGenericsTypes())); return newType; }
java
static ClassNode boundUnboundedWildcards(ClassNode type) { if (type.isArray()) { return boundUnboundedWildcards(type.getComponentType()).makeArray(); } ClassNode target = type.redirect(); if (target == null || type == target || !isUsingGenericsOrIsArrayUsingGenerics(target)) return type; ClassNode newType = type.getPlainNodeReference(); newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder()); newType.setGenericsTypes(boundUnboundedWildcards(type.getGenericsTypes(), target.getGenericsTypes())); return newType; }
[ "static", "ClassNode", "boundUnboundedWildcards", "(", "ClassNode", "type", ")", "{", "if", "(", "type", ".", "isArray", "(", ")", ")", "{", "return", "boundUnboundedWildcards", "(", "type", ".", "getComponentType", "(", ")", ")", ".", "makeArray", "(", ")", ";", "}", "ClassNode", "target", "=", "type", ".", "redirect", "(", ")", ";", "if", "(", "target", "==", "null", "||", "type", "==", "target", "||", "!", "isUsingGenericsOrIsArrayUsingGenerics", "(", "target", ")", ")", "return", "type", ";", "ClassNode", "newType", "=", "type", ".", "getPlainNodeReference", "(", ")", ";", "newType", ".", "setGenericsPlaceHolder", "(", "type", ".", "isGenericsPlaceHolder", "(", ")", ")", ";", "newType", ".", "setGenericsTypes", "(", "boundUnboundedWildcards", "(", "type", ".", "getGenericsTypes", "(", ")", ",", "target", ".", "getGenericsTypes", "(", ")", ")", ")", ";", "return", "newType", ";", "}" ]
Apply the bounds from the declared type when the using type simply declares a parameter as an unbounded wildcard. @param type A parameterized type @return A parameterized type with more precise wildcards
[ "Apply", "the", "bounds", "from", "the", "declared", "type", "when", "the", "using", "type", "simply", "declares", "a", "parameter", "as", "an", "unbounded", "wildcard", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L2023-L2033
13,257
apache/groovy
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.filterMethodsByVisibility
public static List<MethodNode> filterMethodsByVisibility(List<MethodNode> methodNodeList, ClassNode enclosingClassNode) { if (!asBoolean(methodNodeList)) { return StaticTypeCheckingVisitor.EMPTY_METHODNODE_LIST; } List<MethodNode> result = new LinkedList<>(); boolean isEnclosingInnerClass = enclosingClassNode instanceof InnerClassNode; List<ClassNode> outerClasses = enclosingClassNode.getOuterClasses(); outer: for (MethodNode methodNode : methodNodeList) { if (methodNode instanceof ExtensionMethodNode) { result.add(methodNode); continue; } ClassNode declaringClass = methodNode.getDeclaringClass(); if (isEnclosingInnerClass) { for (ClassNode outerClass : outerClasses) { if (outerClass.isDerivedFrom(declaringClass)) { if (outerClass.equals(declaringClass)) { result.add(methodNode); continue outer; } else { if (methodNode.isPublic() || methodNode.isProtected()) { result.add(methodNode); continue outer; } } } } } if (declaringClass instanceof InnerClassNode) { if (declaringClass.getOuterClasses().contains(enclosingClassNode)) { result.add(methodNode); continue; } } if (methodNode.isPrivate() && !enclosingClassNode.equals(declaringClass)) { continue; } if (methodNode.isProtected() && !enclosingClassNode.isDerivedFrom(declaringClass) && !samePackageName(enclosingClassNode, declaringClass)) { continue; } if (methodNode.isPackageScope() && !samePackageName(enclosingClassNode, declaringClass)) { continue; } result.add(methodNode); } return result; }
java
public static List<MethodNode> filterMethodsByVisibility(List<MethodNode> methodNodeList, ClassNode enclosingClassNode) { if (!asBoolean(methodNodeList)) { return StaticTypeCheckingVisitor.EMPTY_METHODNODE_LIST; } List<MethodNode> result = new LinkedList<>(); boolean isEnclosingInnerClass = enclosingClassNode instanceof InnerClassNode; List<ClassNode> outerClasses = enclosingClassNode.getOuterClasses(); outer: for (MethodNode methodNode : methodNodeList) { if (methodNode instanceof ExtensionMethodNode) { result.add(methodNode); continue; } ClassNode declaringClass = methodNode.getDeclaringClass(); if (isEnclosingInnerClass) { for (ClassNode outerClass : outerClasses) { if (outerClass.isDerivedFrom(declaringClass)) { if (outerClass.equals(declaringClass)) { result.add(methodNode); continue outer; } else { if (methodNode.isPublic() || methodNode.isProtected()) { result.add(methodNode); continue outer; } } } } } if (declaringClass instanceof InnerClassNode) { if (declaringClass.getOuterClasses().contains(enclosingClassNode)) { result.add(methodNode); continue; } } if (methodNode.isPrivate() && !enclosingClassNode.equals(declaringClass)) { continue; } if (methodNode.isProtected() && !enclosingClassNode.isDerivedFrom(declaringClass) && !samePackageName(enclosingClassNode, declaringClass)) { continue; } if (methodNode.isPackageScope() && !samePackageName(enclosingClassNode, declaringClass)) { continue; } result.add(methodNode); } return result; }
[ "public", "static", "List", "<", "MethodNode", ">", "filterMethodsByVisibility", "(", "List", "<", "MethodNode", ">", "methodNodeList", ",", "ClassNode", "enclosingClassNode", ")", "{", "if", "(", "!", "asBoolean", "(", "methodNodeList", ")", ")", "{", "return", "StaticTypeCheckingVisitor", ".", "EMPTY_METHODNODE_LIST", ";", "}", "List", "<", "MethodNode", ">", "result", "=", "new", "LinkedList", "<>", "(", ")", ";", "boolean", "isEnclosingInnerClass", "=", "enclosingClassNode", "instanceof", "InnerClassNode", ";", "List", "<", "ClassNode", ">", "outerClasses", "=", "enclosingClassNode", ".", "getOuterClasses", "(", ")", ";", "outer", ":", "for", "(", "MethodNode", "methodNode", ":", "methodNodeList", ")", "{", "if", "(", "methodNode", "instanceof", "ExtensionMethodNode", ")", "{", "result", ".", "add", "(", "methodNode", ")", ";", "continue", ";", "}", "ClassNode", "declaringClass", "=", "methodNode", ".", "getDeclaringClass", "(", ")", ";", "if", "(", "isEnclosingInnerClass", ")", "{", "for", "(", "ClassNode", "outerClass", ":", "outerClasses", ")", "{", "if", "(", "outerClass", ".", "isDerivedFrom", "(", "declaringClass", ")", ")", "{", "if", "(", "outerClass", ".", "equals", "(", "declaringClass", ")", ")", "{", "result", ".", "add", "(", "methodNode", ")", ";", "continue", "outer", ";", "}", "else", "{", "if", "(", "methodNode", ".", "isPublic", "(", ")", "||", "methodNode", ".", "isProtected", "(", ")", ")", "{", "result", ".", "add", "(", "methodNode", ")", ";", "continue", "outer", ";", "}", "}", "}", "}", "}", "if", "(", "declaringClass", "instanceof", "InnerClassNode", ")", "{", "if", "(", "declaringClass", ".", "getOuterClasses", "(", ")", ".", "contains", "(", "enclosingClassNode", ")", ")", "{", "result", ".", "add", "(", "methodNode", ")", ";", "continue", ";", "}", "}", "if", "(", "methodNode", ".", "isPrivate", "(", ")", "&&", "!", "enclosingClassNode", ".", "equals", "(", "declaringClass", ")", ")", "{", "continue", ";", "}", "if", "(", "methodNode", ".", "isProtected", "(", ")", "&&", "!", "enclosingClassNode", ".", "isDerivedFrom", "(", "declaringClass", ")", "&&", "!", "samePackageName", "(", "enclosingClassNode", ",", "declaringClass", ")", ")", "{", "continue", ";", "}", "if", "(", "methodNode", ".", "isPackageScope", "(", ")", "&&", "!", "samePackageName", "(", "enclosingClassNode", ",", "declaringClass", ")", ")", "{", "continue", ";", "}", "result", ".", "add", "(", "methodNode", ")", ";", "}", "return", "result", ";", "}" ]
Filter methods according to visibility @param methodNodeList method nodes to filter @param enclosingClassNode the enclosing class @return filtered method nodes @since 3.0.0
[ "Filter", "methods", "according", "to", "visibility" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L2097-L2155
13,258
apache/groovy
src/main/java/org/codehaus/groovy/antlr/treewalker/SourceCodeTraversal.java
SourceCodeTraversal.setUp
public void setUp(GroovySourceAST t) { super.setUp(t); // gather and sort all unvisited AST nodes unvisitedNodes = new ArrayList<GroovySourceAST>(); traverse(t); Collections.sort(unvisitedNodes); }
java
public void setUp(GroovySourceAST t) { super.setUp(t); // gather and sort all unvisited AST nodes unvisitedNodes = new ArrayList<GroovySourceAST>(); traverse(t); Collections.sort(unvisitedNodes); }
[ "public", "void", "setUp", "(", "GroovySourceAST", "t", ")", "{", "super", ".", "setUp", "(", "t", ")", ";", "// gather and sort all unvisited AST nodes", "unvisitedNodes", "=", "new", "ArrayList", "<", "GroovySourceAST", ">", "(", ")", ";", "traverse", "(", "t", ")", ";", "Collections", ".", "sort", "(", "unvisitedNodes", ")", ";", "}" ]
gather, sort and process all unvisited nodes @param t the AST to process
[ "gather", "sort", "and", "process", "all", "unvisited", "nodes" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/treewalker/SourceCodeTraversal.java#L45-L52
13,259
apache/groovy
subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/SimpleCache.java
SimpleCache.getSilent
public V getSilent(K key) { V value = cache.get(key); if (value != null) { cache.remove(key); cache.put(key, value); } return value; }
java
public V getSilent(K key) { V value = cache.get(key); if (value != null) { cache.remove(key); cache.put(key, value); } return value; }
[ "public", "V", "getSilent", "(", "K", "key", ")", "{", "V", "value", "=", "cache", ".", "get", "(", "key", ")", ";", "if", "(", "value", "!=", "null", ")", "{", "cache", ".", "remove", "(", "key", ")", ";", "cache", ".", "put", "(", "key", ",", "value", ")", ";", "}", "return", "value", ";", "}" ]
For testing only
[ "For", "testing", "only" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/SimpleCache.java#L49-L56
13,260
apache/groovy
subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableColumn.java
DefaultTableColumn.getValue
public Object getValue(Object row, int rowIndex, int columnIndex) { if (valueModel instanceof NestedValueModel) { NestedValueModel nestedModel = (NestedValueModel) valueModel; nestedModel.getSourceModel().setValue(row); } return valueModel.getValue(); }
java
public Object getValue(Object row, int rowIndex, int columnIndex) { if (valueModel instanceof NestedValueModel) { NestedValueModel nestedModel = (NestedValueModel) valueModel; nestedModel.getSourceModel().setValue(row); } return valueModel.getValue(); }
[ "public", "Object", "getValue", "(", "Object", "row", ",", "int", "rowIndex", ",", "int", "columnIndex", ")", "{", "if", "(", "valueModel", "instanceof", "NestedValueModel", ")", "{", "NestedValueModel", "nestedModel", "=", "(", "NestedValueModel", ")", "valueModel", ";", "nestedModel", ".", "getSourceModel", "(", ")", ".", "setValue", "(", "row", ")", ";", "}", "return", "valueModel", ".", "getValue", "(", ")", ";", "}" ]
Evaluates the value of a cell @return the value @param row the row of interest @param rowIndex the index of the row of interest @param columnIndex the column of interest
[ "Evaluates", "the", "value", "of", "a", "cell" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableColumn.java#L56-L62
13,261
apache/groovy
subprojects/groovy-servlet/src/main/java/groovy/servlet/GroovyServlet.java
GroovyServlet.init
public void init(ServletConfig config) throws ServletException { super.init(config); // Set up the scripting engine gse = createGroovyScriptEngine(); servletContext.log("Groovy servlet initialized on " + gse + "."); }
java
public void init(ServletConfig config) throws ServletException { super.init(config); // Set up the scripting engine gse = createGroovyScriptEngine(); servletContext.log("Groovy servlet initialized on " + gse + "."); }
[ "public", "void", "init", "(", "ServletConfig", "config", ")", "throws", "ServletException", "{", "super", ".", "init", "(", "config", ")", ";", "// Set up the scripting engine", "gse", "=", "createGroovyScriptEngine", "(", ")", ";", "servletContext", ".", "log", "(", "\"Groovy servlet initialized on \"", "+", "gse", "+", "\".\"", ")", ";", "}" ]
Initialize the GroovyServlet. @throws ServletException if this method encountered difficulties
[ "Initialize", "the", "GroovyServlet", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-servlet/src/main/java/groovy/servlet/GroovyServlet.java#L87-L94
13,262
apache/groovy
subprojects/groovy-servlet/src/main/java/groovy/servlet/GroovyServlet.java
GroovyServlet.service
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { // Get the script path from the request - include aware (GROOVY-815) final String scriptUri = getScriptUri(request); // Set it to HTML by default response.setContentType("text/html; charset="+encoding); // Set up the script context final ServletBinding binding = new ServletBinding(request, response, servletContext); setVariables(binding); // Run the script try { Closure closure = new Closure(gse) { public Object call() { try { return ((GroovyScriptEngine) getDelegate()).run(scriptUri, binding); } catch (ResourceException | ScriptException e) { throw new RuntimeException(e); } } }; GroovyCategorySupport.use(ServletCategory.class, closure); } catch (RuntimeException runtimeException) { StringBuilder error = new StringBuilder("GroovyServlet Error: "); error.append(" script: '"); error.append(scriptUri); error.append("': "); Throwable e = runtimeException.getCause(); /* * Null cause?! */ if (e == null) { error.append(" Script processing failed.\n"); error.append(runtimeException.getMessage()); if (runtimeException.getStackTrace().length > 0) error.append(runtimeException.getStackTrace()[0].toString()); servletContext.log(error.toString()); System.err.println(error.toString()); runtimeException.printStackTrace(System.err); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error.toString()); return; } /* * Resource not found. */ if (e instanceof ResourceException) { error.append(" Script not found, sending 404."); servletContext.log(error.toString()); System.err.println(error.toString()); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } /* * Other internal error. Perhaps syntax?! */ servletContext.log("An error occurred processing the request", runtimeException); error.append(e.getMessage()); if (e.getStackTrace().length > 0) error.append(e.getStackTrace()[0].toString()); servletContext.log(e.toString()); System.err.println(e.toString()); runtimeException.printStackTrace(System.err); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } }
java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { // Get the script path from the request - include aware (GROOVY-815) final String scriptUri = getScriptUri(request); // Set it to HTML by default response.setContentType("text/html; charset="+encoding); // Set up the script context final ServletBinding binding = new ServletBinding(request, response, servletContext); setVariables(binding); // Run the script try { Closure closure = new Closure(gse) { public Object call() { try { return ((GroovyScriptEngine) getDelegate()).run(scriptUri, binding); } catch (ResourceException | ScriptException e) { throw new RuntimeException(e); } } }; GroovyCategorySupport.use(ServletCategory.class, closure); } catch (RuntimeException runtimeException) { StringBuilder error = new StringBuilder("GroovyServlet Error: "); error.append(" script: '"); error.append(scriptUri); error.append("': "); Throwable e = runtimeException.getCause(); /* * Null cause?! */ if (e == null) { error.append(" Script processing failed.\n"); error.append(runtimeException.getMessage()); if (runtimeException.getStackTrace().length > 0) error.append(runtimeException.getStackTrace()[0].toString()); servletContext.log(error.toString()); System.err.println(error.toString()); runtimeException.printStackTrace(System.err); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error.toString()); return; } /* * Resource not found. */ if (e instanceof ResourceException) { error.append(" Script not found, sending 404."); servletContext.log(error.toString()); System.err.println(error.toString()); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } /* * Other internal error. Perhaps syntax?! */ servletContext.log("An error occurred processing the request", runtimeException); error.append(e.getMessage()); if (e.getStackTrace().length > 0) error.append(e.getStackTrace()[0].toString()); servletContext.log(e.toString()); System.err.println(e.toString()); runtimeException.printStackTrace(System.err); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } }
[ "public", "void", "service", "(", "HttpServletRequest", "request", ",", "HttpServletResponse", "response", ")", "throws", "IOException", "{", "// Get the script path from the request - include aware (GROOVY-815)", "final", "String", "scriptUri", "=", "getScriptUri", "(", "request", ")", ";", "// Set it to HTML by default", "response", ".", "setContentType", "(", "\"text/html; charset=\"", "+", "encoding", ")", ";", "// Set up the script context", "final", "ServletBinding", "binding", "=", "new", "ServletBinding", "(", "request", ",", "response", ",", "servletContext", ")", ";", "setVariables", "(", "binding", ")", ";", "// Run the script", "try", "{", "Closure", "closure", "=", "new", "Closure", "(", "gse", ")", "{", "public", "Object", "call", "(", ")", "{", "try", "{", "return", "(", "(", "GroovyScriptEngine", ")", "getDelegate", "(", ")", ")", ".", "run", "(", "scriptUri", ",", "binding", ")", ";", "}", "catch", "(", "ResourceException", "|", "ScriptException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}", "}", ";", "GroovyCategorySupport", ".", "use", "(", "ServletCategory", ".", "class", ",", "closure", ")", ";", "}", "catch", "(", "RuntimeException", "runtimeException", ")", "{", "StringBuilder", "error", "=", "new", "StringBuilder", "(", "\"GroovyServlet Error: \"", ")", ";", "error", ".", "append", "(", "\" script: '\"", ")", ";", "error", ".", "append", "(", "scriptUri", ")", ";", "error", ".", "append", "(", "\"': \"", ")", ";", "Throwable", "e", "=", "runtimeException", ".", "getCause", "(", ")", ";", "/*\n * Null cause?!\n */", "if", "(", "e", "==", "null", ")", "{", "error", ".", "append", "(", "\" Script processing failed.\\n\"", ")", ";", "error", ".", "append", "(", "runtimeException", ".", "getMessage", "(", ")", ")", ";", "if", "(", "runtimeException", ".", "getStackTrace", "(", ")", ".", "length", ">", "0", ")", "error", ".", "append", "(", "runtimeException", ".", "getStackTrace", "(", ")", "[", "0", "]", ".", "toString", "(", ")", ")", ";", "servletContext", ".", "log", "(", "error", ".", "toString", "(", ")", ")", ";", "System", ".", "err", ".", "println", "(", "error", ".", "toString", "(", ")", ")", ";", "runtimeException", ".", "printStackTrace", "(", "System", ".", "err", ")", ";", "response", ".", "sendError", "(", "HttpServletResponse", ".", "SC_INTERNAL_SERVER_ERROR", ",", "error", ".", "toString", "(", ")", ")", ";", "return", ";", "}", "/*\n * Resource not found.\n */", "if", "(", "e", "instanceof", "ResourceException", ")", "{", "error", ".", "append", "(", "\" Script not found, sending 404.\"", ")", ";", "servletContext", ".", "log", "(", "error", ".", "toString", "(", ")", ")", ";", "System", ".", "err", ".", "println", "(", "error", ".", "toString", "(", ")", ")", ";", "response", ".", "sendError", "(", "HttpServletResponse", ".", "SC_NOT_FOUND", ")", ";", "return", ";", "}", "/*\n * Other internal error. Perhaps syntax?!\n */", "servletContext", ".", "log", "(", "\"An error occurred processing the request\"", ",", "runtimeException", ")", ";", "error", ".", "append", "(", "e", ".", "getMessage", "(", ")", ")", ";", "if", "(", "e", ".", "getStackTrace", "(", ")", ".", "length", ">", "0", ")", "error", ".", "append", "(", "e", ".", "getStackTrace", "(", ")", "[", "0", "]", ".", "toString", "(", ")", ")", ";", "servletContext", ".", "log", "(", "e", ".", "toString", "(", ")", ")", ";", "System", ".", "err", ".", "println", "(", "e", ".", "toString", "(", ")", ")", ";", "runtimeException", ".", "printStackTrace", "(", "System", ".", "err", ")", ";", "response", ".", "sendError", "(", "HttpServletResponse", ".", "SC_INTERNAL_SERVER_ERROR", ",", "e", ".", "toString", "(", ")", ")", ";", "}", "}" ]
Handle web requests to the GroovyServlet
[ "Handle", "web", "requests", "to", "the", "GroovyServlet" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-servlet/src/main/java/groovy/servlet/GroovyServlet.java#L99-L167
13,263
apache/groovy
src/main/groovy/groovy/transform/builder/InitializerStrategy.java
InitializerStrategy.renameMethod
private static void renameMethod(ClassNode buildee, MethodNode mNode, String newName) { buildee.addMethod(newName, mNode.getModifiers(), mNode.getReturnType(), mNode.getParameters(), mNode.getExceptions(), mNode.getCode()); buildee.removeMethod(mNode); }
java
private static void renameMethod(ClassNode buildee, MethodNode mNode, String newName) { buildee.addMethod(newName, mNode.getModifiers(), mNode.getReturnType(), mNode.getParameters(), mNode.getExceptions(), mNode.getCode()); buildee.removeMethod(mNode); }
[ "private", "static", "void", "renameMethod", "(", "ClassNode", "buildee", ",", "MethodNode", "mNode", ",", "String", "newName", ")", "{", "buildee", ".", "addMethod", "(", "newName", ",", "mNode", ".", "getModifiers", "(", ")", ",", "mNode", ".", "getReturnType", "(", ")", ",", "mNode", ".", "getParameters", "(", ")", ",", "mNode", ".", "getExceptions", "(", ")", ",", "mNode", ".", "getCode", "(", ")", ")", ";", "buildee", ".", "removeMethod", "(", "mNode", ")", ";", "}" ]
no rename so delete and add
[ "no", "rename", "so", "delete", "and", "add" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/transform/builder/InitializerStrategy.java#L305-L308
13,264
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java
Memoize.buildMemoizeFunction
public static <V> Closure<V> buildMemoizeFunction(final MemoizeCache<Object, Object> cache, final Closure<V> closure) { return new MemoizeFunction<V>(cache, closure); }
java
public static <V> Closure<V> buildMemoizeFunction(final MemoizeCache<Object, Object> cache, final Closure<V> closure) { return new MemoizeFunction<V>(cache, closure); }
[ "public", "static", "<", "V", ">", "Closure", "<", "V", ">", "buildMemoizeFunction", "(", "final", "MemoizeCache", "<", "Object", ",", "Object", ">", "cache", ",", "final", "Closure", "<", "V", ">", "closure", ")", "{", "return", "new", "MemoizeFunction", "<", "V", ">", "(", "cache", ",", "closure", ")", ";", "}" ]
Creates a new closure delegating to the supplied one and memoizing all return values by the arguments. The supplied cache is used to store the memoized values and it is the cache's responsibility to put limits on the cache size or implement cache eviction strategy. The LRUCache, for example, allows to set the maximum cache size constraint and implements the LRU (Last Recently Used) eviction strategy. @param cache A map to hold memoized return values @param closure The closure to memoize @param <V> The closure's return type @return A new memoized closure
[ "Creates", "a", "new", "closure", "delegating", "to", "the", "supplied", "one", "and", "memoizing", "all", "return", "values", "by", "the", "arguments", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java#L54-L56
13,265
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java
Memoize.buildSoftReferenceMemoizeFunction
public static <V> Closure<V> buildSoftReferenceMemoizeFunction(final int protectedCacheSize, final MemoizeCache<Object, SoftReference<Object>> cache, final Closure<V> closure) { final ProtectionStorage lruProtectionStorage = protectedCacheSize > 0 ? new LRUProtectionStorage(protectedCacheSize) : new NullProtectionStorage(); // Nothing should be done when no elements need protection against eviction final ReferenceQueue queue = new ReferenceQueue(); return new SoftReferenceMemoizeFunction<V>(cache, closure, lruProtectionStorage, queue); }
java
public static <V> Closure<V> buildSoftReferenceMemoizeFunction(final int protectedCacheSize, final MemoizeCache<Object, SoftReference<Object>> cache, final Closure<V> closure) { final ProtectionStorage lruProtectionStorage = protectedCacheSize > 0 ? new LRUProtectionStorage(protectedCacheSize) : new NullProtectionStorage(); // Nothing should be done when no elements need protection against eviction final ReferenceQueue queue = new ReferenceQueue(); return new SoftReferenceMemoizeFunction<V>(cache, closure, lruProtectionStorage, queue); }
[ "public", "static", "<", "V", ">", "Closure", "<", "V", ">", "buildSoftReferenceMemoizeFunction", "(", "final", "int", "protectedCacheSize", ",", "final", "MemoizeCache", "<", "Object", ",", "SoftReference", "<", "Object", ">", ">", "cache", ",", "final", "Closure", "<", "V", ">", "closure", ")", "{", "final", "ProtectionStorage", "lruProtectionStorage", "=", "protectedCacheSize", ">", "0", "?", "new", "LRUProtectionStorage", "(", "protectedCacheSize", ")", ":", "new", "NullProtectionStorage", "(", ")", ";", "// Nothing should be done when no elements need protection against eviction", "final", "ReferenceQueue", "queue", "=", "new", "ReferenceQueue", "(", ")", ";", "return", "new", "SoftReferenceMemoizeFunction", "<", "V", ">", "(", "cache", ",", "closure", ",", "lruProtectionStorage", ",", "queue", ")", ";", "}" ]
Creates a new closure delegating to the supplied one and memoizing all return values by the arguments. The memoizing closure will use SoftReferences to remember the return values allowing the garbage collector to reclaim the memory, if needed. The supplied cache is used to store the memoized values and it is the cache's responsibility to put limits on the cache size or implement cache eviction strategy. The LRUCache, for example, allows to set the maximum cache size constraint and implements the LRU (Last Recently Used) eviction strategy. If the protectedCacheSize argument is greater than 0 an optional LRU (Last Recently Used) cache of hard references is maintained to protect recently touched memoized values against eviction by the garbage collector. @param protectedCacheSize The number of hard references to keep in order to prevent some (LRU) memoized return values from eviction @param cache A map to hold memoized return values @param closure The closure to memoize @param <V> The closure's return type @return A new memoized closure
[ "Creates", "a", "new", "closure", "delegating", "to", "the", "supplied", "one", "and", "memoizing", "all", "return", "values", "by", "the", "arguments", ".", "The", "memoizing", "closure", "will", "use", "SoftReferences", "to", "remember", "the", "return", "values", "allowing", "the", "garbage", "collector", "to", "reclaim", "the", "memory", "if", "needed", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java#L77-L85
13,266
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java
Memoize.generateKey
private static Object generateKey(final Object[] args) { if (args == null) return Collections.emptyList(); Object[] copyOfArgs = copyOf(args, args.length); return asList(copyOfArgs); }
java
private static Object generateKey(final Object[] args) { if (args == null) return Collections.emptyList(); Object[] copyOfArgs = copyOf(args, args.length); return asList(copyOfArgs); }
[ "private", "static", "Object", "generateKey", "(", "final", "Object", "[", "]", "args", ")", "{", "if", "(", "args", "==", "null", ")", "return", "Collections", ".", "emptyList", "(", ")", ";", "Object", "[", "]", "copyOfArgs", "=", "copyOf", "(", "args", ",", "args", ".", "length", ")", ";", "return", "asList", "(", "copyOfArgs", ")", ";", "}" ]
Creates a key to use in the memoize cache @param args The arguments supplied to the closure invocation @return The key - a list holding all arguments
[ "Creates", "a", "key", "to", "use", "in", "the", "memoize", "cache" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java#L94-L98
13,267
apache/groovy
src/main/java/org/codehaus/groovy/reflection/CachedClass.java
CachedClass.makeAccessible
private static AccessibleObject[] makeAccessible(final AccessibleObject[] aoa) { try { AccessibleObject.setAccessible(aoa, true); return aoa; } catch (Throwable outer) { // swallow for strict security managers, module systems, android or others, // but try one-by-one to get the allowed ones at least final ArrayList<AccessibleObject> ret = new ArrayList<>(aoa.length); for (final AccessibleObject ao : aoa) { try { ao.setAccessible(true); ret.add(ao); } catch (Throwable inner) { // swallow for strict security managers, module systems, android or others } } return ret.toArray((AccessibleObject[]) Array.newInstance(aoa.getClass().getComponentType(), ret.size())); } }
java
private static AccessibleObject[] makeAccessible(final AccessibleObject[] aoa) { try { AccessibleObject.setAccessible(aoa, true); return aoa; } catch (Throwable outer) { // swallow for strict security managers, module systems, android or others, // but try one-by-one to get the allowed ones at least final ArrayList<AccessibleObject> ret = new ArrayList<>(aoa.length); for (final AccessibleObject ao : aoa) { try { ao.setAccessible(true); ret.add(ao); } catch (Throwable inner) { // swallow for strict security managers, module systems, android or others } } return ret.toArray((AccessibleObject[]) Array.newInstance(aoa.getClass().getComponentType(), ret.size())); } }
[ "private", "static", "AccessibleObject", "[", "]", "makeAccessible", "(", "final", "AccessibleObject", "[", "]", "aoa", ")", "{", "try", "{", "AccessibleObject", ".", "setAccessible", "(", "aoa", ",", "true", ")", ";", "return", "aoa", ";", "}", "catch", "(", "Throwable", "outer", ")", "{", "// swallow for strict security managers, module systems, android or others,", "// but try one-by-one to get the allowed ones at least", "final", "ArrayList", "<", "AccessibleObject", ">", "ret", "=", "new", "ArrayList", "<>", "(", "aoa", ".", "length", ")", ";", "for", "(", "final", "AccessibleObject", "ao", ":", "aoa", ")", "{", "try", "{", "ao", ".", "setAccessible", "(", "true", ")", ";", "ret", ".", "add", "(", "ao", ")", ";", "}", "catch", "(", "Throwable", "inner", ")", "{", "// swallow for strict security managers, module systems, android or others", "}", "}", "return", "ret", ".", "toArray", "(", "(", "AccessibleObject", "[", "]", ")", "Array", ".", "newInstance", "(", "aoa", ".", "getClass", "(", ")", ".", "getComponentType", "(", ")", ",", "ret", ".", "size", "(", ")", ")", ")", ";", "}", "}" ]
to be run in PrivilegedAction!
[ "to", "be", "run", "in", "PrivilegedAction!" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/reflection/CachedClass.java#L96-L114
13,268
apache/groovy
src/main/groovy/groovy/lang/ExpandoMetaClassCreationHandle.java
ExpandoMetaClassCreationHandle.registerModifiedMetaClass
public void registerModifiedMetaClass(ExpandoMetaClass emc) { final Class klazz = emc.getJavaClass(); GroovySystem.getMetaClassRegistry().setMetaClass(klazz,emc); }
java
public void registerModifiedMetaClass(ExpandoMetaClass emc) { final Class klazz = emc.getJavaClass(); GroovySystem.getMetaClassRegistry().setMetaClass(klazz,emc); }
[ "public", "void", "registerModifiedMetaClass", "(", "ExpandoMetaClass", "emc", ")", "{", "final", "Class", "klazz", "=", "emc", ".", "getJavaClass", "(", ")", ";", "GroovySystem", ".", "getMetaClassRegistry", "(", ")", ".", "setMetaClass", "(", "klazz", ",", "emc", ")", ";", "}" ]
Registers a modified ExpandoMetaClass with the creation handle @param emc The EMC
[ "Registers", "a", "modified", "ExpandoMetaClass", "with", "the", "creation", "handle" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/ExpandoMetaClassCreationHandle.java#L59-L62
13,269
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.leftShift
public static Writer leftShift(Writer self, Object value) throws IOException { InvokerHelper.write(self, value); return self; }
java
public static Writer leftShift(Writer self, Object value) throws IOException { InvokerHelper.write(self, value); return self; }
[ "public", "static", "Writer", "leftShift", "(", "Writer", "self", ",", "Object", "value", ")", "throws", "IOException", "{", "InvokerHelper", ".", "write", "(", "self", ",", "value", ")", ";", "return", "self", ";", "}" ]
Overloads the leftShift operator for Writer to allow an object to be written using Groovy's default representation for the object. @param self a Writer @param value an Object whose default representation will be written to the Writer @return the writer on which this operation was invoked @throws IOException if an I/O error occurs. @since 1.0
[ "Overloads", "the", "leftShift", "operator", "for", "Writer", "to", "allow", "an", "object", "to", "be", "written", "using", "Groovy", "s", "default", "representation", "for", "the", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L92-L95
13,270
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.leftShift
public static Appendable leftShift(Appendable self, Object value) throws IOException { InvokerHelper.append(self, value); return self; }
java
public static Appendable leftShift(Appendable self, Object value) throws IOException { InvokerHelper.append(self, value); return self; }
[ "public", "static", "Appendable", "leftShift", "(", "Appendable", "self", ",", "Object", "value", ")", "throws", "IOException", "{", "InvokerHelper", ".", "append", "(", "self", ",", "value", ")", ";", "return", "self", ";", "}" ]
Overloads the leftShift operator for Appendable to allow an object to be appended using Groovy's default representation for the object. @param self an Appendable @param value an Object whose default representation will be appended to the Appendable @return the Appendable on which this operation was invoked @throws IOException if an I/O error occurs. @since 2.1.0
[ "Overloads", "the", "leftShift", "operator", "for", "Appendable", "to", "allow", "an", "object", "to", "be", "appended", "using", "Groovy", "s", "default", "representation", "for", "the", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L107-L110
13,271
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withFormatter
public static Appendable withFormatter(Appendable self, @ClosureParams(value=SimpleType.class, options="java.util.Formatter") Closure closure) { Formatter formatter = new Formatter(self); callWithFormatter(closure, formatter); return self; }
java
public static Appendable withFormatter(Appendable self, @ClosureParams(value=SimpleType.class, options="java.util.Formatter") Closure closure) { Formatter formatter = new Formatter(self); callWithFormatter(closure, formatter); return self; }
[ "public", "static", "Appendable", "withFormatter", "(", "Appendable", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.util.Formatter\"", ")", "Closure", "closure", ")", "{", "Formatter", "formatter", "=", "new", "Formatter", "(", "self", ")", ";", "callWithFormatter", "(", "closure", ",", "formatter", ")", ";", "return", "self", ";", "}" ]
Invokes a Closure that uses a Formatter taking care of resource handling. A Formatter is created and passed to the Closure as its argument. After the Closure executes, the Formatter is flushed and closed releasing any associated resources. @param self an Appendable @param closure a 1-arg Closure which will be called with a Formatter as its argument @return the Appendable on which this operation was invoked @since 2.1.0
[ "Invokes", "a", "Closure", "that", "uses", "a", "Formatter", "taking", "care", "of", "resource", "handling", ".", "A", "Formatter", "is", "created", "and", "passed", "to", "the", "Closure", "as", "its", "argument", ".", "After", "the", "Closure", "executes", "the", "Formatter", "is", "flushed", "and", "closed", "releasing", "any", "associated", "resources", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L123-L127
13,272
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.leftShift
public static Writer leftShift(OutputStream self, Object value) throws IOException { OutputStreamWriter writer = new FlushingStreamWriter(self); leftShift(writer, value); return writer; }
java
public static Writer leftShift(OutputStream self, Object value) throws IOException { OutputStreamWriter writer = new FlushingStreamWriter(self); leftShift(writer, value); return writer; }
[ "public", "static", "Writer", "leftShift", "(", "OutputStream", "self", ",", "Object", "value", ")", "throws", "IOException", "{", "OutputStreamWriter", "writer", "=", "new", "FlushingStreamWriter", "(", "self", ")", ";", "leftShift", "(", "writer", ",", "value", ")", ";", "return", "writer", ";", "}" ]
Overloads the leftShift operator to provide an append mechanism to add values to a stream. @param self an OutputStream @param value a value to append @return a Writer @throws java.io.IOException if an I/O error occurs. @since 1.0
[ "Overloads", "the", "leftShift", "operator", "to", "provide", "an", "append", "mechanism", "to", "add", "values", "to", "a", "stream", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L180-L184
13,273
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.leftShift
public static OutputStream leftShift(OutputStream self, byte[] value) throws IOException { self.write(value); self.flush(); return self; }
java
public static OutputStream leftShift(OutputStream self, byte[] value) throws IOException { self.write(value); self.flush(); return self; }
[ "public", "static", "OutputStream", "leftShift", "(", "OutputStream", "self", ",", "byte", "[", "]", "value", ")", "throws", "IOException", "{", "self", ".", "write", "(", "value", ")", ";", "self", ".", "flush", "(", ")", ";", "return", "self", ";", "}" ]
Overloads the leftShift operator to provide an append mechanism to add bytes to a stream. @param self an OutputStream @param value a value to append @return an OutputStream @throws IOException if an I/O error occurs. @since 1.0
[ "Overloads", "the", "leftShift", "operator", "to", "provide", "an", "append", "mechanism", "to", "add", "bytes", "to", "a", "stream", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L225-L229
13,274
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withObjectOutputStream
public static <T> T withObjectOutputStream(OutputStream outputStream, @ClosureParams(value=SimpleType.class, options="java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return withStream(newObjectOutputStream(outputStream), closure); }
java
public static <T> T withObjectOutputStream(OutputStream outputStream, @ClosureParams(value=SimpleType.class, options="java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return withStream(newObjectOutputStream(outputStream), closure); }
[ "public", "static", "<", "T", ">", "T", "withObjectOutputStream", "(", "OutputStream", "outputStream", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.ObjectOutputStream\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withStream", "(", "newObjectOutputStream", "(", "outputStream", ")", ",", "closure", ")", ";", "}" ]
Create a new ObjectOutputStream for this output stream and then pass it to the closure. This method ensures the stream is closed after the closure returns. @param outputStream am output stream @param closure a closure @return the value returned by the closure @throws IOException if an IOException occurs. @see #withStream(java.io.OutputStream, groovy.lang.Closure) @since 1.5.0
[ "Create", "a", "new", "ObjectOutputStream", "for", "this", "output", "stream", "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/IOGroovyMethods.java#L255-L257
13,275
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.newObjectInputStream
public static ObjectInputStream newObjectInputStream(InputStream inputStream, final ClassLoader classLoader) throws IOException { return new ObjectInputStream(inputStream) { protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { return Class.forName(desc.getName(), true, classLoader); } }; }
java
public static ObjectInputStream newObjectInputStream(InputStream inputStream, final ClassLoader classLoader) throws IOException { return new ObjectInputStream(inputStream) { protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { return Class.forName(desc.getName(), true, classLoader); } }; }
[ "public", "static", "ObjectInputStream", "newObjectInputStream", "(", "InputStream", "inputStream", ",", "final", "ClassLoader", "classLoader", ")", "throws", "IOException", "{", "return", "new", "ObjectInputStream", "(", "inputStream", ")", "{", "protected", "Class", "<", "?", ">", "resolveClass", "(", "ObjectStreamClass", "desc", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "return", "Class", ".", "forName", "(", "desc", ".", "getName", "(", ")", ",", "true", ",", "classLoader", ")", ";", "}", "}", ";", "}" ]
Create an object input stream for this input stream using the given class loader. @param inputStream an input stream @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", "input", "stream", "using", "the", "given", "class", "loader", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L280-L287
13,276
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.eachObject
public static void eachObject(ObjectInputStream ois, Closure closure) throws IOException, ClassNotFoundException { try { while (true) { try { Object obj = ois.readObject(); // we allow null objects in the object stream closure.call(obj); } catch (EOFException e) { break; } } InputStream temp = ois; ois = null; temp.close(); } finally { closeWithWarning(ois); } }
java
public static void eachObject(ObjectInputStream ois, Closure closure) throws IOException, ClassNotFoundException { try { while (true) { try { Object obj = ois.readObject(); // we allow null objects in the object stream closure.call(obj); } catch (EOFException e) { break; } } InputStream temp = ois; ois = null; temp.close(); } finally { closeWithWarning(ois); } }
[ "public", "static", "void", "eachObject", "(", "ObjectInputStream", "ois", ",", "Closure", "closure", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "try", "{", "while", "(", "true", ")", "{", "try", "{", "Object", "obj", "=", "ois", ".", "readObject", "(", ")", ";", "// we allow null objects in the object stream", "closure", ".", "call", "(", "obj", ")", ";", "}", "catch", "(", "EOFException", "e", ")", "{", "break", ";", "}", "}", "InputStream", "temp", "=", "ois", ";", "ois", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "ois", ")", ";", "}", "}" ]
Iterates through the given object stream object by object. The ObjectInputStream is closed afterwards. @param ois an ObjectInputStream, closed after the operation @param closure a closure @throws IOException if an IOException occurs. @throws ClassNotFoundException if the class is not found. @since 1.0
[ "Iterates", "through", "the", "given", "object", "stream", "object", "by", "object", ".", "The", "ObjectInputStream", "is", "closed", "afterwards", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L299-L316
13,277
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.eachLine
public static <T> T eachLine(InputStream stream, String charset, int firstLine, @ClosureParams(value=FromString.class,options={"String","String,Integer"}) Closure<T> closure) throws IOException { return eachLine(new InputStreamReader(stream, charset), firstLine, closure); }
java
public static <T> T eachLine(InputStream stream, String charset, int firstLine, @ClosureParams(value=FromString.class,options={"String","String,Integer"}) Closure<T> closure) throws IOException { return eachLine(new InputStreamReader(stream, charset), firstLine, closure); }
[ "public", "static", "<", "T", ">", "T", "eachLine", "(", "InputStream", "stream", ",", "String", "charset", ",", "int", "firstLine", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "{", "\"String\"", ",", "\"String,Integer\"", "}", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "eachLine", "(", "new", "InputStreamReader", "(", "stream", ",", "charset", ")", ",", "firstLine", ",", "closure", ")", ";", "}" ]
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed after this method returns. @param stream a stream @param charset opens the stream with a specified charset @param firstLine the line number value used for the first line (default is 1, set to 0 to start counting from 0) @param closure a closure (arg 1 is line, optional arg 2 is line number) @return the last value returned by the closure @throws IOException if an IOException occurs. @see #eachLine(java.io.Reader, int, groovy.lang.Closure) @since 1.5.7
[ "Iterates", "through", "this", "stream", "reading", "with", "the", "provided", "charset", "passing", "each", "line", "to", "the", "given", "1", "or", "2", "arg", "closure", ".", "The", "stream", "is", "closed", "after", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L378-L380
13,278
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.eachLine
public static <T> T eachLine(Reader self, int firstLine, @ClosureParams(value=FromString.class,options={"String","String,Integer"}) Closure<T> closure) throws IOException { BufferedReader br; int count = firstLine; T result = null; if (self instanceof BufferedReader) br = (BufferedReader) self; else br = new BufferedReader(self); try { while (true) { String line = br.readLine(); if (line == null) { break; } else { result = callClosureForLine(closure, line, count); count++; } } Reader temp = self; self = null; temp.close(); return result; } finally { closeWithWarning(self); closeWithWarning(br); } }
java
public static <T> T eachLine(Reader self, int firstLine, @ClosureParams(value=FromString.class,options={"String","String,Integer"}) Closure<T> closure) throws IOException { BufferedReader br; int count = firstLine; T result = null; if (self instanceof BufferedReader) br = (BufferedReader) self; else br = new BufferedReader(self); try { while (true) { String line = br.readLine(); if (line == null) { break; } else { result = callClosureForLine(closure, line, count); count++; } } Reader temp = self; self = null; temp.close(); return result; } finally { closeWithWarning(self); closeWithWarning(br); } }
[ "public", "static", "<", "T", ">", "T", "eachLine", "(", "Reader", "self", ",", "int", "firstLine", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "{", "\"String\"", ",", "\"String,Integer\"", "}", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "BufferedReader", "br", ";", "int", "count", "=", "firstLine", ";", "T", "result", "=", "null", ";", "if", "(", "self", "instanceof", "BufferedReader", ")", "br", "=", "(", "BufferedReader", ")", "self", ";", "else", "br", "=", "new", "BufferedReader", "(", "self", ")", ";", "try", "{", "while", "(", "true", ")", "{", "String", "line", "=", "br", ".", "readLine", "(", ")", ";", "if", "(", "line", "==", "null", ")", "{", "break", ";", "}", "else", "{", "result", "=", "callClosureForLine", "(", "closure", ",", "line", ",", "count", ")", ";", "count", "++", ";", "}", "}", "Reader", "temp", "=", "self", ";", "self", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "return", "result", ";", "}", "finally", "{", "closeWithWarning", "(", "self", ")", ";", "closeWithWarning", "(", "br", ")", ";", "}", "}" ]
Iterates through the given reader line by line. Each line is passed to the given 1 or 2 arg closure. If the closure has two arguments, the line count is passed as the second argument. The Reader is closed before this method returns. @param self a Reader, closed after the method returns @param firstLine the line number value used for the first line (default is 1, set to 0 to start counting from 0) @param closure a closure which will be passed each line (or for 2 arg closures the line and line count) @return the last value returned by the closure @throws IOException if an IOException occurs. @since 1.5.7
[ "Iterates", "through", "the", "given", "reader", "line", "by", "line", ".", "Each", "line", "is", "passed", "to", "the", "given", "1", "or", "2", "arg", "closure", ".", "If", "the", "closure", "has", "two", "arguments", "the", "line", "count", "is", "passed", "as", "the", "second", "argument", ".", "The", "Reader", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L441-L469
13,279
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.readLines
public static List<String> readLines(InputStream stream, String charset) throws IOException { return readLines(newReader(stream, charset)); }
java
public static List<String> readLines(InputStream stream, String charset) throws IOException { return readLines(newReader(stream, charset)); }
[ "public", "static", "List", "<", "String", ">", "readLines", "(", "InputStream", "stream", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "readLines", "(", "newReader", "(", "stream", ",", "charset", ")", ")", ";", "}" ]
Reads the stream into a list, with one element for each line. @param stream a stream @param charset opens the stream with a specified charset @return a List of lines @throws IOException if an IOException occurs. @see #readLines(java.io.Reader) @since 1.6.8
[ "Reads", "the", "stream", "into", "a", "list", "with", "one", "element", "for", "each", "line", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L783-L785
13,280
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.readLines
public static List<String> readLines(Reader reader) throws IOException { IteratorClosureAdapter<String> closure = new IteratorClosureAdapter<String>(reader); eachLine(reader, closure); return closure.asList(); }
java
public static List<String> readLines(Reader reader) throws IOException { IteratorClosureAdapter<String> closure = new IteratorClosureAdapter<String>(reader); eachLine(reader, closure); return closure.asList(); }
[ "public", "static", "List", "<", "String", ">", "readLines", "(", "Reader", "reader", ")", "throws", "IOException", "{", "IteratorClosureAdapter", "<", "String", ">", "closure", "=", "new", "IteratorClosureAdapter", "<", "String", ">", "(", "reader", ")", ";", "eachLine", "(", "reader", ",", "closure", ")", ";", "return", "closure", ".", "asList", "(", ")", ";", "}" ]
Reads the reader into a list of Strings, with one entry for each line. The reader is closed before this method returns. @param reader a Reader @return a List of lines @throws IOException if an IOException occurs. @since 1.0
[ "Reads", "the", "reader", "into", "a", "list", "of", "Strings", "with", "one", "entry", "for", "each", "line", ".", "The", "reader", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L796-L800
13,281
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.getText
public static String getText(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); return getText(reader); }
java
public static String getText(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); return getText(reader); }
[ "public", "static", "String", "getText", "(", "InputStream", "is", ")", "throws", "IOException", "{", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "is", ")", ")", ";", "return", "getText", "(", "reader", ")", ";", "}" ]
Read the content of this InputStream and return it as a String. The stream is closed before this method returns. @param is an input stream @return the text from that URL @throws IOException if an IOException occurs. @since 1.0
[ "Read", "the", "content", "of", "this", "InputStream", "and", "return", "it", "as", "a", "String", ".", "The", "stream", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L811-L814
13,282
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.getText
public static String getText(Reader reader) throws IOException { BufferedReader bufferedReader = new BufferedReader(reader); return getText(bufferedReader); }
java
public static String getText(Reader reader) throws IOException { BufferedReader bufferedReader = new BufferedReader(reader); return getText(bufferedReader); }
[ "public", "static", "String", "getText", "(", "Reader", "reader", ")", "throws", "IOException", "{", "BufferedReader", "bufferedReader", "=", "new", "BufferedReader", "(", "reader", ")", ";", "return", "getText", "(", "bufferedReader", ")", ";", "}" ]
Read the content of the Reader and return it as a String. The reader is closed before this method returns. @param reader a Reader whose content we want to read @return a String containing the content of the buffered reader @throws IOException if an IOException occurs. @see #getText(java.io.BufferedReader) @since 1.0
[ "Read", "the", "content", "of", "the", "Reader", "and", "return", "it", "as", "a", "String", ".", "The", "reader", "is", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L841-L844
13,283
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.getText
public static String getText(BufferedReader reader) throws IOException { StringBuilder answer = new StringBuilder(); // reading the content of the file within a char buffer // allow to keep the correct line endings char[] charBuffer = new char[8192]; int nbCharRead /* = 0*/; try { while ((nbCharRead = reader.read(charBuffer)) != -1) { // appends buffer answer.append(charBuffer, 0, nbCharRead); } Reader temp = reader; reader = null; temp.close(); } finally { closeWithWarning(reader); } return answer.toString(); }
java
public static String getText(BufferedReader reader) throws IOException { StringBuilder answer = new StringBuilder(); // reading the content of the file within a char buffer // allow to keep the correct line endings char[] charBuffer = new char[8192]; int nbCharRead /* = 0*/; try { while ((nbCharRead = reader.read(charBuffer)) != -1) { // appends buffer answer.append(charBuffer, 0, nbCharRead); } Reader temp = reader; reader = null; temp.close(); } finally { closeWithWarning(reader); } return answer.toString(); }
[ "public", "static", "String", "getText", "(", "BufferedReader", "reader", ")", "throws", "IOException", "{", "StringBuilder", "answer", "=", "new", "StringBuilder", "(", ")", ";", "// reading the content of the file within a char buffer", "// allow to keep the correct line endings", "char", "[", "]", "charBuffer", "=", "new", "char", "[", "8192", "]", ";", "int", "nbCharRead", "/* = 0*/", ";", "try", "{", "while", "(", "(", "nbCharRead", "=", "reader", ".", "read", "(", "charBuffer", ")", ")", "!=", "-", "1", ")", "{", "// appends buffer", "answer", ".", "append", "(", "charBuffer", ",", "0", ",", "nbCharRead", ")", ";", "}", "Reader", "temp", "=", "reader", ";", "reader", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "reader", ")", ";", "}", "return", "answer", ".", "toString", "(", ")", ";", "}" ]
Read the content of the BufferedReader and return it as a String. The BufferedReader is closed afterwards. @param reader a BufferedReader whose content we want to read @return a String containing the content of the buffered reader @throws IOException if an IOException occurs. @since 1.0
[ "Read", "the", "content", "of", "the", "BufferedReader", "and", "return", "it", "as", "a", "String", ".", "The", "BufferedReader", "is", "closed", "afterwards", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L855-L873
13,284
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.iterator
public static Iterator<String> iterator(Reader self) { final BufferedReader bufferedReader; if (self instanceof BufferedReader) bufferedReader = (BufferedReader) self; else bufferedReader = new BufferedReader(self); return new Iterator<String>() { String nextVal /* = null */; boolean nextMustRead = true; boolean hasNext = true; public boolean hasNext() { if (nextMustRead && hasNext) { try { nextVal = readNext(); nextMustRead = false; } catch (IOException e) { hasNext = false; } } return hasNext; } public String next() { String retval = null; if (nextMustRead) { try { retval = readNext(); } catch (IOException e) { hasNext = false; } } else retval = nextVal; nextMustRead = true; return retval; } private String readNext() throws IOException { String nv = bufferedReader.readLine(); if (nv == null) hasNext = false; return nv; } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a Reader Iterator"); } }; }
java
public static Iterator<String> iterator(Reader self) { final BufferedReader bufferedReader; if (self instanceof BufferedReader) bufferedReader = (BufferedReader) self; else bufferedReader = new BufferedReader(self); return new Iterator<String>() { String nextVal /* = null */; boolean nextMustRead = true; boolean hasNext = true; public boolean hasNext() { if (nextMustRead && hasNext) { try { nextVal = readNext(); nextMustRead = false; } catch (IOException e) { hasNext = false; } } return hasNext; } public String next() { String retval = null; if (nextMustRead) { try { retval = readNext(); } catch (IOException e) { hasNext = false; } } else retval = nextVal; nextMustRead = true; return retval; } private String readNext() throws IOException { String nv = bufferedReader.readLine(); if (nv == null) hasNext = false; return nv; } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a Reader Iterator"); } }; }
[ "public", "static", "Iterator", "<", "String", ">", "iterator", "(", "Reader", "self", ")", "{", "final", "BufferedReader", "bufferedReader", ";", "if", "(", "self", "instanceof", "BufferedReader", ")", "bufferedReader", "=", "(", "BufferedReader", ")", "self", ";", "else", "bufferedReader", "=", "new", "BufferedReader", "(", "self", ")", ";", "return", "new", "Iterator", "<", "String", ">", "(", ")", "{", "String", "nextVal", "/* = null */", ";", "boolean", "nextMustRead", "=", "true", ";", "boolean", "hasNext", "=", "true", ";", "public", "boolean", "hasNext", "(", ")", "{", "if", "(", "nextMustRead", "&&", "hasNext", ")", "{", "try", "{", "nextVal", "=", "readNext", "(", ")", ";", "nextMustRead", "=", "false", ";", "}", "catch", "(", "IOException", "e", ")", "{", "hasNext", "=", "false", ";", "}", "}", "return", "hasNext", ";", "}", "public", "String", "next", "(", ")", "{", "String", "retval", "=", "null", ";", "if", "(", "nextMustRead", ")", "{", "try", "{", "retval", "=", "readNext", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "hasNext", "=", "false", ";", "}", "}", "else", "retval", "=", "nextVal", ";", "nextMustRead", "=", "true", ";", "return", "retval", ";", "}", "private", "String", "readNext", "(", ")", "throws", "IOException", "{", "String", "nv", "=", "bufferedReader", ".", "readLine", "(", ")", ";", "if", "(", "nv", "==", "null", ")", "hasNext", "=", "false", ";", "return", "nv", ";", "}", "public", "void", "remove", "(", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Cannot remove() from a Reader Iterator\"", ")", ";", "}", "}", ";", "}" ]
Creates an iterator which will traverse through the reader a line at a time. @param self a Reader object @return an Iterator for the Reader @see java.io.BufferedReader#readLine() @since 1.5.0
[ "Creates", "an", "iterator", "which", "will", "traverse", "through", "the", "reader", "a", "line", "at", "a", "time", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L938-L986
13,285
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.iterator
public static Iterator<Byte> iterator(final DataInputStream self) { return new Iterator<Byte>() { Byte nextVal; boolean nextMustRead = true; boolean hasNext = true; public boolean hasNext() { if (nextMustRead && hasNext) { try { nextVal = self.readByte(); nextMustRead = false; } catch (IOException e) { hasNext = false; } } return hasNext; } public Byte next() { Byte retval = null; if (nextMustRead) { try { retval = self.readByte(); } catch (IOException e) { hasNext = false; } } else retval = nextVal; nextMustRead = true; return retval; } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a DataInputStream Iterator"); } }; }
java
public static Iterator<Byte> iterator(final DataInputStream self) { return new Iterator<Byte>() { Byte nextVal; boolean nextMustRead = true; boolean hasNext = true; public boolean hasNext() { if (nextMustRead && hasNext) { try { nextVal = self.readByte(); nextMustRead = false; } catch (IOException e) { hasNext = false; } } return hasNext; } public Byte next() { Byte retval = null; if (nextMustRead) { try { retval = self.readByte(); } catch (IOException e) { hasNext = false; } } else retval = nextVal; nextMustRead = true; return retval; } public void remove() { throw new UnsupportedOperationException("Cannot remove() from a DataInputStream Iterator"); } }; }
[ "public", "static", "Iterator", "<", "Byte", ">", "iterator", "(", "final", "DataInputStream", "self", ")", "{", "return", "new", "Iterator", "<", "Byte", ">", "(", ")", "{", "Byte", "nextVal", ";", "boolean", "nextMustRead", "=", "true", ";", "boolean", "hasNext", "=", "true", ";", "public", "boolean", "hasNext", "(", ")", "{", "if", "(", "nextMustRead", "&&", "hasNext", ")", "{", "try", "{", "nextVal", "=", "self", ".", "readByte", "(", ")", ";", "nextMustRead", "=", "false", ";", "}", "catch", "(", "IOException", "e", ")", "{", "hasNext", "=", "false", ";", "}", "}", "return", "hasNext", ";", "}", "public", "Byte", "next", "(", ")", "{", "Byte", "retval", "=", "null", ";", "if", "(", "nextMustRead", ")", "{", "try", "{", "retval", "=", "self", ".", "readByte", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "hasNext", "=", "false", ";", "}", "}", "else", "retval", "=", "nextVal", ";", "nextMustRead", "=", "true", ";", "return", "retval", ";", "}", "public", "void", "remove", "(", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Cannot remove() from a DataInputStream Iterator\"", ")", ";", "}", "}", ";", "}" ]
Standard iterator for a data input stream which iterates through the stream content a Byte at a time. @param self a DataInputStream object @return an Iterator for the DataInputStream @since 1.5.0
[ "Standard", "iterator", "for", "a", "data", "input", "stream", "which", "iterates", "through", "the", "stream", "content", "a", "Byte", "at", "a", "time", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1008-L1044
13,286
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.newReader
public static BufferedReader newReader(InputStream self, String charset) throws UnsupportedEncodingException { return new BufferedReader(new InputStreamReader(self, charset)); }
java
public static BufferedReader newReader(InputStream self, String charset) throws UnsupportedEncodingException { return new BufferedReader(new InputStreamReader(self, charset)); }
[ "public", "static", "BufferedReader", "newReader", "(", "InputStream", "self", ",", "String", "charset", ")", "throws", "UnsupportedEncodingException", "{", "return", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "self", ",", "charset", ")", ")", ";", "}" ]
Creates a reader for this input stream, using the specified charset as the encoding. @param self an input stream @param charset the charset for this input stream @return a reader @throws UnsupportedEncodingException if the encoding specified is not supported @since 1.6.0
[ "Creates", "a", "reader", "for", "this", "input", "stream", "using", "the", "specified", "charset", "as", "the", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1067-L1069
13,287
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withPrintWriter
public static <T> T withPrintWriter(Writer writer, @ClosureParams(value=SimpleType.class, options="java.io.PrintWriter") Closure<T> closure) throws IOException { return withWriter(newPrintWriter(writer), closure); }
java
public static <T> T withPrintWriter(Writer writer, @ClosureParams(value=SimpleType.class, options="java.io.PrintWriter") Closure<T> closure) throws IOException { return withWriter(newPrintWriter(writer), closure); }
[ "public", "static", "<", "T", ">", "T", "withPrintWriter", "(", "Writer", "writer", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.PrintWriter\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withWriter", "(", "newPrintWriter", "(", "writer", ")", ",", "closure", ")", ";", "}" ]
Create a new PrintWriter for this Writer. The writer is passed to the closure, and will be closed before this method returns. @param writer a writer @param closure the closure to invoke with the PrintWriter @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.6.0
[ "Create", "a", "new", "PrintWriter", "for", "this", "Writer", ".", "The", "writer", "is", "passed", "to", "the", "closure", "and", "will", "be", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1103-L1105
13,288
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withPrintWriter
public static <T> T withPrintWriter(OutputStream stream, @ClosureParams(value=SimpleType.class, options="java.io.PrintWriter") Closure<T> closure) throws IOException { return withWriter(newPrintWriter(stream), closure); }
java
public static <T> T withPrintWriter(OutputStream stream, @ClosureParams(value=SimpleType.class, options="java.io.PrintWriter") Closure<T> closure) throws IOException { return withWriter(newPrintWriter(stream), closure); }
[ "public", "static", "<", "T", ">", "T", "withPrintWriter", "(", "OutputStream", "stream", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.PrintWriter\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withWriter", "(", "newPrintWriter", "(", "stream", ")", ",", "closure", ")", ";", "}" ]
Create a new PrintWriter for this OutputStream. The writer is passed to the closure, and will be closed before this method returns. @param stream an OutputStream @param closure the closure to invoke with the PrintWriter @return the value returned by the closure @throws IOException if an IOException occurs. @since 2.2.0
[ "Create", "a", "new", "PrintWriter", "for", "this", "OutputStream", ".", "The", "writer", "is", "passed", "to", "the", "closure", "and", "will", "be", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1117-L1119
13,289
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withWriter
public static <T> T withWriter(Writer writer, @ClosureParams(FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(writer); try { writer.flush(); } catch (IOException e) { // try to continue even in case of error } Writer temp = writer; writer = null; temp.close(); return result; } finally { closeWithWarning(writer); } }
java
public static <T> T withWriter(Writer writer, @ClosureParams(FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(writer); try { writer.flush(); } catch (IOException e) { // try to continue even in case of error } Writer temp = writer; writer = null; temp.close(); return result; } finally { closeWithWarning(writer); } }
[ "public", "static", "<", "T", ">", "T", "withWriter", "(", "Writer", "writer", ",", "@", "ClosureParams", "(", "FirstParam", ".", "class", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "try", "{", "T", "result", "=", "closure", ".", "call", "(", "writer", ")", ";", "try", "{", "writer", ".", "flush", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "// try to continue even in case of error", "}", "Writer", "temp", "=", "writer", ";", "writer", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "return", "result", ";", "}", "finally", "{", "closeWithWarning", "(", "writer", ")", ";", "}", "}" ]
Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns. @param writer the writer which is used and then closed @param closure the closure that the writer is passed into @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Allows", "this", "writer", "to", "be", "used", "within", "the", "closure", "ensuring", "that", "it", "is", "flushed", "and", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1131-L1147
13,290
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withStream
public static <T, U extends InputStream> T withStream(U stream, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(stream); InputStream temp = stream; stream = null; temp.close(); return result; } finally { closeWithWarning(stream); } }
java
public static <T, U extends InputStream> T withStream(U stream, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(stream); InputStream temp = stream; stream = null; temp.close(); return result; } finally { closeWithWarning(stream); } }
[ "public", "static", "<", "T", ",", "U", "extends", "InputStream", ">", "T", "withStream", "(", "U", "stream", ",", "@", "ClosureParams", "(", "value", "=", "FirstParam", ".", "class", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "try", "{", "T", "result", "=", "closure", ".", "call", "(", "stream", ")", ";", "InputStream", "temp", "=", "stream", ";", "stream", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "return", "result", ";", "}", "finally", "{", "closeWithWarning", "(", "stream", ")", ";", "}", "}" ]
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns. @param stream the stream which is used and then closed @param closure the closure that the stream is passed into @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Allows", "this", "input", "stream", "to", "be", "used", "within", "the", "closure", "ensuring", "that", "it", "is", "flushed", "and", "closed", "before", "this", "method", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1183-L1195
13,291
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withWriter
public static <T> T withWriter(OutputStream stream, @ClosureParams(value=SimpleType.class, options="java.io.Writer") Closure<T> closure) throws IOException { return withWriter(new OutputStreamWriter(stream), closure); }
java
public static <T> T withWriter(OutputStream stream, @ClosureParams(value=SimpleType.class, options="java.io.Writer") Closure<T> closure) throws IOException { return withWriter(new OutputStreamWriter(stream), closure); }
[ "public", "static", "<", "T", ">", "T", "withWriter", "(", "OutputStream", "stream", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.Writer\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withWriter", "(", "new", "OutputStreamWriter", "(", "stream", ")", ",", "closure", ")", ";", "}" ]
Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns. @param stream the stream which is used and then closed @param closure the closure that the writer is passed into @return the value returned by the closure @throws IOException if an IOException occurs. @see #withWriter(java.io.Writer, groovy.lang.Closure) @since 1.5.2
[ "Creates", "a", "writer", "from", "this", "stream", "passing", "it", "to", "the", "given", "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/IOGroovyMethods.java#L1241-L1243
13,292
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.newWriter
public static Writer newWriter(OutputStream stream, String charset) throws UnsupportedEncodingException { return new OutputStreamWriter(stream, charset); }
java
public static Writer newWriter(OutputStream stream, String charset) throws UnsupportedEncodingException { return new OutputStreamWriter(stream, charset); }
[ "public", "static", "Writer", "newWriter", "(", "OutputStream", "stream", ",", "String", "charset", ")", "throws", "UnsupportedEncodingException", "{", "return", "new", "OutputStreamWriter", "(", "stream", ",", "charset", ")", ";", "}" ]
Creates a writer for this stream using the given charset. @param stream the stream which is used and then closed @param charset the charset used @return the newly created Writer @throws UnsupportedEncodingException if an encoding exception occurs. @since 2.2.0
[ "Creates", "a", "writer", "for", "this", "stream", "using", "the", "given", "charset", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1281-L1283
13,293
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withStream
public static <T, U extends OutputStream> T withStream(U os, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(os); os.flush(); OutputStream temp = os; os = null; temp.close(); return result; } finally { closeWithWarning(os); } }
java
public static <T, U extends OutputStream> T withStream(U os, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException { try { T result = closure.call(os); os.flush(); OutputStream temp = os; os = null; temp.close(); return result; } finally { closeWithWarning(os); } }
[ "public", "static", "<", "T", ",", "U", "extends", "OutputStream", ">", "T", "withStream", "(", "U", "os", ",", "@", "ClosureParams", "(", "value", "=", "FirstParam", ".", "class", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "try", "{", "T", "result", "=", "closure", ".", "call", "(", "os", ")", ";", "os", ".", "flush", "(", ")", ";", "OutputStream", "temp", "=", "os", ";", "os", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "return", "result", ";", "}", "finally", "{", "closeWithWarning", "(", "os", ")", ";", "}", "}" ]
Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors. @param os the stream which is used and then closed @param closure the closure that the stream is passed into @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Passes", "this", "OutputStream", "to", "the", "closure", "ensuring", "that", "the", "stream", "is", "closed", "after", "the", "closure", "returns", "regardless", "of", "errors", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1295-L1308
13,294
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.eachByte
public static void eachByte(InputStream is, @ClosureParams(value=SimpleType.class, options="byte") Closure closure) throws IOException { try { while (true) { int b = is.read(); if (b == -1) { break; } else { closure.call((byte) b); } } InputStream temp = is; is = null; temp.close(); } finally { closeWithWarning(is); } }
java
public static void eachByte(InputStream is, @ClosureParams(value=SimpleType.class, options="byte") Closure closure) throws IOException { try { while (true) { int b = is.read(); if (b == -1) { break; } else { closure.call((byte) b); } } InputStream temp = is; is = null; temp.close(); } finally { closeWithWarning(is); } }
[ "public", "static", "void", "eachByte", "(", "InputStream", "is", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"byte\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "try", "{", "while", "(", "true", ")", "{", "int", "b", "=", "is", ".", "read", "(", ")", ";", "if", "(", "b", "==", "-", "1", ")", "{", "break", ";", "}", "else", "{", "closure", ".", "call", "(", "(", "byte", ")", "b", ")", ";", "}", "}", "InputStream", "temp", "=", "is", ";", "is", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "is", ")", ";", "}", "}" ]
Traverse through each byte of the specified stream. The stream is closed after the closure returns. @param is stream to iterate over, closed after the method call @param closure closure to apply to each byte @throws IOException if an IOException occurs. @since 1.0
[ "Traverse", "through", "each", "byte", "of", "the", "specified", "stream", ".", "The", "stream", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1319-L1336
13,295
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.eachByte
public static void eachByte(InputStream is, int bufferLen, @ClosureParams(value=FromString.class, options="byte[],Integer") Closure closure) throws IOException { byte[] buffer = new byte[bufferLen]; int bytesRead; try { while ((bytesRead = is.read(buffer, 0, bufferLen)) > 0) { closure.call(buffer, bytesRead); } InputStream temp = is; is = null; temp.close(); } finally { closeWithWarning(is); } }
java
public static void eachByte(InputStream is, int bufferLen, @ClosureParams(value=FromString.class, options="byte[],Integer") Closure closure) throws IOException { byte[] buffer = new byte[bufferLen]; int bytesRead; try { while ((bytesRead = is.read(buffer, 0, bufferLen)) > 0) { closure.call(buffer, bytesRead); } InputStream temp = is; is = null; temp.close(); } finally { closeWithWarning(is); } }
[ "public", "static", "void", "eachByte", "(", "InputStream", "is", ",", "int", "bufferLen", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "\"byte[],Integer\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "bufferLen", "]", ";", "int", "bytesRead", ";", "try", "{", "while", "(", "(", "bytesRead", "=", "is", ".", "read", "(", "buffer", ",", "0", ",", "bufferLen", ")", ")", ">", "0", ")", "{", "closure", ".", "call", "(", "buffer", ",", "bytesRead", ")", ";", "}", "InputStream", "temp", "=", "is", ";", "is", "=", "null", ";", "temp", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "is", ")", ";", "}", "}" ]
Traverse through each the specified stream reading bytes into a buffer and calling the 2 parameter closure with this buffer and the number of bytes. @param is stream to iterate over, closed after the method call. @param bufferLen the length of the buffer to use. @param closure a 2 parameter closure which is passed the byte[] and a number of bytes successfully read. @throws IOException if an IOException occurs. @since 1.8
[ "Traverse", "through", "each", "the", "specified", "stream", "reading", "bytes", "into", "a", "buffer", "and", "calling", "the", "2", "parameter", "closure", "with", "this", "buffer", "and", "the", "number", "of", "bytes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1348-L1362
13,296
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.transformLine
public static void transformLine(Reader reader, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); String line; try { while ((line = br.readLine()) != null) { Object o = closure.call(line); if (o != null) { bw.write(o.toString()); bw.newLine(); } } bw.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = reader; reader = null; temp1.close(); } finally { closeWithWarning(br); closeWithWarning(reader); closeWithWarning(bw); closeWithWarning(writer); } }
java
public static void transformLine(Reader reader, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); String line; try { while ((line = br.readLine()) != null) { Object o = closure.call(line); if (o != null) { bw.write(o.toString()); bw.newLine(); } } bw.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = reader; reader = null; temp1.close(); } finally { closeWithWarning(br); closeWithWarning(reader); closeWithWarning(bw); closeWithWarning(writer); } }
[ "public", "static", "void", "transformLine", "(", "Reader", "reader", ",", "Writer", "writer", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "BufferedReader", "br", "=", "new", "BufferedReader", "(", "reader", ")", ";", "BufferedWriter", "bw", "=", "new", "BufferedWriter", "(", "writer", ")", ";", "String", "line", ";", "try", "{", "while", "(", "(", "line", "=", "br", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "Object", "o", "=", "closure", ".", "call", "(", "line", ")", ";", "if", "(", "o", "!=", "null", ")", "{", "bw", ".", "write", "(", "o", ".", "toString", "(", ")", ")", ";", "bw", ".", "newLine", "(", ")", ";", "}", "}", "bw", ".", "flush", "(", ")", ";", "Writer", "temp2", "=", "writer", ";", "writer", "=", "null", ";", "temp2", ".", "close", "(", ")", ";", "Reader", "temp1", "=", "reader", ";", "reader", "=", "null", ";", "temp1", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "br", ")", ";", "closeWithWarning", "(", "reader", ")", ";", "closeWithWarning", "(", "bw", ")", ";", "closeWithWarning", "(", "writer", ")", ";", "}", "}" ]
Transforms the lines from a reader with a Closure and write them to a writer. Both Reader and Writer are closed after the operation. @param reader Lines of text to be transformed. Reader is closed afterwards. @param writer Where transformed lines are written. Writer is closed afterwards. @param closure Single parameter closure that is called to transform each line of text from the reader, before writing it to the writer. @throws IOException if an IOException occurs. @since 1.0
[ "Transforms", "the", "lines", "from", "a", "reader", "with", "a", "Closure", "and", "write", "them", "to", "a", "writer", ".", "Both", "Reader", "and", "Writer", "are", "closed", "after", "the", "operation", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1413-L1439
13,297
apache/groovy
src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.filterLine
public static void filterLine(Reader reader, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); String line; try { BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); while ((line = br.readLine()) != null) { if (bcw.call(line)) { bw.write(line); bw.newLine(); } } bw.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = reader; reader = null; temp1.close(); } finally { closeWithWarning(br); closeWithWarning(reader); closeWithWarning(bw); closeWithWarning(writer); } }
java
public static void filterLine(Reader reader, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); String line; try { BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); while ((line = br.readLine()) != null) { if (bcw.call(line)) { bw.write(line); bw.newLine(); } } bw.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = reader; reader = null; temp1.close(); } finally { closeWithWarning(br); closeWithWarning(reader); closeWithWarning(bw); closeWithWarning(writer); } }
[ "public", "static", "void", "filterLine", "(", "Reader", "reader", ",", "Writer", "writer", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "BufferedReader", "br", "=", "new", "BufferedReader", "(", "reader", ")", ";", "BufferedWriter", "bw", "=", "new", "BufferedWriter", "(", "writer", ")", ";", "String", "line", ";", "try", "{", "BooleanClosureWrapper", "bcw", "=", "new", "BooleanClosureWrapper", "(", "closure", ")", ";", "while", "(", "(", "line", "=", "br", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "bcw", ".", "call", "(", "line", ")", ")", "{", "bw", ".", "write", "(", "line", ")", ";", "bw", ".", "newLine", "(", ")", ";", "}", "}", "bw", ".", "flush", "(", ")", ";", "Writer", "temp2", "=", "writer", ";", "writer", "=", "null", ";", "temp2", ".", "close", "(", ")", ";", "Reader", "temp1", "=", "reader", ";", "reader", "=", "null", ";", "temp1", ".", "close", "(", ")", ";", "}", "finally", "{", "closeWithWarning", "(", "br", ")", ";", "closeWithWarning", "(", "reader", ")", ";", "closeWithWarning", "(", "bw", ")", ";", "closeWithWarning", "(", "writer", ")", ";", "}", "}" ]
Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included. Both Reader and Writer are closed after the operation. @param reader a reader, closed after the call @param writer a writer, closed after the call @param closure the closure which returns booleans @throws IOException if an IOException occurs. @since 1.0
[ "Filter", "the", "lines", "from", "a", "reader", "and", "write", "them", "on", "the", "writer", "according", "to", "a", "closure", "which", "returns", "true", "if", "the", "line", "should", "be", "included", ".", "Both", "Reader", "and", "Writer", "are", "closed", "after", "the", "operation", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1452-L1479
13,298
apache/groovy
subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
DateUtilExtensions.putAt
public static void putAt(Date self, int field, int value) { Calendar cal = Calendar.getInstance(); cal.setTime(self); putAt(cal, field, value); self.setTime(cal.getTimeInMillis()); }
java
public static void putAt(Date self, int field, int value) { Calendar cal = Calendar.getInstance(); cal.setTime(self); putAt(cal, field, value); self.setTime(cal.getTimeInMillis()); }
[ "public", "static", "void", "putAt", "(", "Date", "self", ",", "int", "field", ",", "int", "value", ")", "{", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "setTime", "(", "self", ")", ";", "putAt", "(", "cal", ",", "field", ",", "value", ")", ";", "self", ".", "setTime", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ";", "}" ]
Support the subscript operator for mutating a Date. @param self A Date @param field A Calendar field, e.g. MONTH @param value The value for the given field, e.g. FEBRUARY @see #putAt(java.util.Calendar, int, int) @see java.util.Calendar#set(int, int) @since 1.7.3
[ "Support", "the", "subscript", "operator", "for", "mutating", "a", "Date", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java#L111-L116
13,299
apache/groovy
subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
DateUtilExtensions.plus
public static Timestamp plus(Timestamp self, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(self); calendar.add(Calendar.DATE, days); Timestamp ts = new Timestamp(calendar.getTime().getTime()); ts.setNanos(self.getNanos()); return ts; }
java
public static Timestamp plus(Timestamp self, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(self); calendar.add(Calendar.DATE, days); Timestamp ts = new Timestamp(calendar.getTime().getTime()); ts.setNanos(self.getNanos()); return ts; }
[ "public", "static", "Timestamp", "plus", "(", "Timestamp", "self", ",", "int", "days", ")", "{", "Calendar", "calendar", "=", "Calendar", ".", "getInstance", "(", ")", ";", "calendar", ".", "setTime", "(", "self", ")", ";", "calendar", ".", "add", "(", "Calendar", ".", "DATE", ",", "days", ")", ";", "Timestamp", "ts", "=", "new", "Timestamp", "(", "calendar", ".", "getTime", "(", ")", ".", "getTime", "(", ")", ")", ";", "ts", ".", "setNanos", "(", "self", ".", "getNanos", "(", ")", ")", ";", "return", "ts", ";", "}" ]
Add number of days to this Timestamp and returns the new Timestamp object. @param self a Timestamp @param days the number of days to increase @return the new Timestamp
[ "Add", "number", "of", "days", "to", "this", "Timestamp", "and", "returns", "the", "new", "Timestamp", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java#L403-L410