id
int32 0
252k
| repo
stringlengths 7
58
| path
stringlengths 4
218
| func_name
stringlengths 1
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 2
values | code
stringlengths 73
34.1k
| code_tokens
sequencelengths 20
4.08k
| docstring
stringlengths 3
17.3k
| docstring_tokens
sequencelengths 3
222
| sha
stringlengths 40
40
| url
stringlengths 87
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
0 | wg/scrypt | src/main/java/com/lambdaworks/crypto/SCryptUtil.java | SCryptUtil.check | public static boolean check(String passwd, String hashed) {
try {
String[] parts = hashed.split("\\$");
if (parts.length != 5 || !parts[1].equals("s0")) {
throw new IllegalArgumentException("Invalid hashed value");
}
long params = Long.parseLong(parts[2], 16);
byte[] salt = decode(parts[3].toCharArray());
byte[] derived0 = decode(parts[4].toCharArray());
int N = (int) Math.pow(2, params >> 16 & 0xffff);
int r = (int) params >> 8 & 0xff;
int p = (int) params & 0xff;
byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
if (derived0.length != derived1.length) return false;
int result = 0;
for (int i = 0; i < derived0.length; i++) {
result |= derived0[i] ^ derived1[i];
}
return result == 0;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("JVM doesn't support UTF-8?");
} catch (GeneralSecurityException e) {
throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");
}
} | java | public static boolean check(String passwd, String hashed) {
try {
String[] parts = hashed.split("\\$");
if (parts.length != 5 || !parts[1].equals("s0")) {
throw new IllegalArgumentException("Invalid hashed value");
}
long params = Long.parseLong(parts[2], 16);
byte[] salt = decode(parts[3].toCharArray());
byte[] derived0 = decode(parts[4].toCharArray());
int N = (int) Math.pow(2, params >> 16 & 0xffff);
int r = (int) params >> 8 & 0xff;
int p = (int) params & 0xff;
byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
if (derived0.length != derived1.length) return false;
int result = 0;
for (int i = 0; i < derived0.length; i++) {
result |= derived0[i] ^ derived1[i];
}
return result == 0;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("JVM doesn't support UTF-8?");
} catch (GeneralSecurityException e) {
throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");
}
} | [
"public",
"static",
"boolean",
"check",
"(",
"String",
"passwd",
",",
"String",
"hashed",
")",
"{",
"try",
"{",
"String",
"[",
"]",
"parts",
"=",
"hashed",
".",
"split",
"(",
"\"\\\\$\"",
")",
";",
"if",
"(",
"parts",
".",
"length",
"!=",
"5",
"||",
"!",
"parts",
"[",
"1",
"]",
".",
"equals",
"(",
"\"s0\"",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid hashed value\"",
")",
";",
"}",
"long",
"params",
"=",
"Long",
".",
"parseLong",
"(",
"parts",
"[",
"2",
"]",
",",
"16",
")",
";",
"byte",
"[",
"]",
"salt",
"=",
"decode",
"(",
"parts",
"[",
"3",
"]",
".",
"toCharArray",
"(",
")",
")",
";",
"byte",
"[",
"]",
"derived0",
"=",
"decode",
"(",
"parts",
"[",
"4",
"]",
".",
"toCharArray",
"(",
")",
")",
";",
"int",
"N",
"=",
"(",
"int",
")",
"Math",
".",
"pow",
"(",
"2",
",",
"params",
">>",
"16",
"&",
"0xffff",
")",
";",
"int",
"r",
"=",
"(",
"int",
")",
"params",
">>",
"8",
"&",
"0xff",
";",
"int",
"p",
"=",
"(",
"int",
")",
"params",
"&",
"0xff",
";",
"byte",
"[",
"]",
"derived1",
"=",
"SCrypt",
".",
"scrypt",
"(",
"passwd",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
",",
"salt",
",",
"N",
",",
"r",
",",
"p",
",",
"32",
")",
";",
"if",
"(",
"derived0",
".",
"length",
"!=",
"derived1",
".",
"length",
")",
"return",
"false",
";",
"int",
"result",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"derived0",
".",
"length",
";",
"i",
"++",
")",
"{",
"result",
"|=",
"derived0",
"[",
"i",
"]",
"^",
"derived1",
"[",
"i",
"]",
";",
"}",
"return",
"result",
"==",
"0",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"JVM doesn't support UTF-8?\"",
")",
";",
"}",
"catch",
"(",
"GeneralSecurityException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"JVM doesn't support SHA1PRNG or HMAC_SHA256?\"",
")",
";",
"}",
"}"
] | Compare the supplied plaintext password to a hashed password.
@param passwd Plaintext password.
@param hashed scrypt hashed password.
@return true if passwd matches hashed value. | [
"Compare",
"the",
"supplied",
"plaintext",
"password",
"to",
"a",
"hashed",
"password",
"."
] | 0675236370458e819ee21e4427c5f7f3f9485d33 | https://github.com/wg/scrypt/blob/0675236370458e819ee21e4427c5f7f3f9485d33/src/main/java/com/lambdaworks/crypto/SCryptUtil.java#L72-L102 |
1 | wg/scrypt | src/main/java/com/lambdaworks/jni/Platform.java | Platform.detect | public static Platform detect() throws UnsupportedPlatformException {
String osArch = getProperty("os.arch");
String osName = getProperty("os.name");
for (Arch arch : Arch.values()) {
if (arch.pattern.matcher(osArch).matches()) {
for (OS os : OS.values()) {
if (os.pattern.matcher(osName).matches()) {
return new Platform(arch, os);
}
}
}
}
String msg = String.format("Unsupported platform %s %s", osArch, osName);
throw new UnsupportedPlatformException(msg);
} | java | public static Platform detect() throws UnsupportedPlatformException {
String osArch = getProperty("os.arch");
String osName = getProperty("os.name");
for (Arch arch : Arch.values()) {
if (arch.pattern.matcher(osArch).matches()) {
for (OS os : OS.values()) {
if (os.pattern.matcher(osName).matches()) {
return new Platform(arch, os);
}
}
}
}
String msg = String.format("Unsupported platform %s %s", osArch, osName);
throw new UnsupportedPlatformException(msg);
} | [
"public",
"static",
"Platform",
"detect",
"(",
")",
"throws",
"UnsupportedPlatformException",
"{",
"String",
"osArch",
"=",
"getProperty",
"(",
"\"os.arch\"",
")",
";",
"String",
"osName",
"=",
"getProperty",
"(",
"\"os.name\"",
")",
";",
"for",
"(",
"Arch",
"arch",
":",
"Arch",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"arch",
".",
"pattern",
".",
"matcher",
"(",
"osArch",
")",
".",
"matches",
"(",
")",
")",
"{",
"for",
"(",
"OS",
"os",
":",
"OS",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"os",
".",
"pattern",
".",
"matcher",
"(",
"osName",
")",
".",
"matches",
"(",
")",
")",
"{",
"return",
"new",
"Platform",
"(",
"arch",
",",
"os",
")",
";",
"}",
"}",
"}",
"}",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Unsupported platform %s %s\"",
",",
"osArch",
",",
"osName",
")",
";",
"throw",
"new",
"UnsupportedPlatformException",
"(",
"msg",
")",
";",
"}"
] | Attempt to detect the current platform.
@return The current platform.
@throws UnsupportedPlatformException if the platform cannot be detected. | [
"Attempt",
"to",
"detect",
"the",
"current",
"platform",
"."
] | 0675236370458e819ee21e4427c5f7f3f9485d33 | https://github.com/wg/scrypt/blob/0675236370458e819ee21e4427c5f7f3f9485d33/src/main/java/com/lambdaworks/jni/Platform.java#L56-L72 |
2 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ASTNode.java | ASTNode.getNodeMetaData | public <T> T getNodeMetaData(Object key) {
if (metaDataMap == null) {
return (T) null;
}
return (T) metaDataMap.get(key);
} | java | public <T> T getNodeMetaData(Object key) {
if (metaDataMap == null) {
return (T) null;
}
return (T) metaDataMap.get(key);
} | [
"public",
"<",
"T",
">",
"T",
"getNodeMetaData",
"(",
"Object",
"key",
")",
"{",
"if",
"(",
"metaDataMap",
"==",
"null",
")",
"{",
"return",
"(",
"T",
")",
"null",
";",
"}",
"return",
"(",
"T",
")",
"metaDataMap",
".",
"get",
"(",
"key",
")",
";",
"}"
] | Gets the node meta data.
@param key - the meta data key
@return the node meta data value for this key | [
"Gets",
"the",
"node",
"meta",
"data",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L119-L124 |
3 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ASTNode.java | ASTNode.copyNodeMetaData | public void copyNodeMetaData(ASTNode other) {
if (other.metaDataMap == null) {
return;
}
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
metaDataMap.putAll(other.metaDataMap);
} | java | public void copyNodeMetaData(ASTNode other) {
if (other.metaDataMap == null) {
return;
}
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
metaDataMap.putAll(other.metaDataMap);
} | [
"public",
"void",
"copyNodeMetaData",
"(",
"ASTNode",
"other",
")",
"{",
"if",
"(",
"other",
".",
"metaDataMap",
"==",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"metaDataMap",
"==",
"null",
")",
"{",
"metaDataMap",
"=",
"new",
"ListHashMap",
"(",
")",
";",
"}",
"metaDataMap",
".",
"putAll",
"(",
"other",
".",
"metaDataMap",
")",
";",
"}"
] | Copies all node meta data from the other node to this one
@param other - the other node | [
"Copies",
"all",
"node",
"meta",
"data",
"from",
"the",
"other",
"node",
"to",
"this",
"one"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L130-L138 |
4 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ASTNode.java | ASTNode.setNodeMetaData | public void setNodeMetaData(Object key, Object value) {
if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
Object old = metaDataMap.put(key,value);
if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+".");
} | java | public void setNodeMetaData(Object key, Object value) {
if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
Object old = metaDataMap.put(key,value);
if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+".");
} | [
"public",
"void",
"setNodeMetaData",
"(",
"Object",
"key",
",",
"Object",
"value",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"throw",
"new",
"GroovyBugError",
"(",
"\"Tried to set meta data with null key on \"",
"+",
"this",
"+",
"\".\"",
")",
";",
"if",
"(",
"metaDataMap",
"==",
"null",
")",
"{",
"metaDataMap",
"=",
"new",
"ListHashMap",
"(",
")",
";",
"}",
"Object",
"old",
"=",
"metaDataMap",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"if",
"(",
"old",
"!=",
"null",
")",
"throw",
"new",
"GroovyBugError",
"(",
"\"Tried to overwrite existing meta data \"",
"+",
"this",
"+",
"\".\"",
")",
";",
"}"
] | Sets the node meta data.
@param key - the meta data key
@param value - the meta data value
@throws GroovyBugError if key is null or there is already meta
data under that key | [
"Sets",
"the",
"node",
"meta",
"data",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L148-L155 |
5 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ASTNode.java | ASTNode.putNodeMetaData | public Object putNodeMetaData(Object key, Object value) {
if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + ".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
return metaDataMap.put(key, value);
} | java | public Object putNodeMetaData(Object key, Object value) {
if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + ".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
return metaDataMap.put(key, value);
} | [
"public",
"Object",
"putNodeMetaData",
"(",
"Object",
"key",
",",
"Object",
"value",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"throw",
"new",
"GroovyBugError",
"(",
"\"Tried to set meta data with null key on \"",
"+",
"this",
"+",
"\".\"",
")",
";",
"if",
"(",
"metaDataMap",
"==",
"null",
")",
"{",
"metaDataMap",
"=",
"new",
"ListHashMap",
"(",
")",
";",
"}",
"return",
"metaDataMap",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"}"
] | Sets the node meta data but allows overwriting values.
@param key - the meta data key
@param value - the meta data value
@return the old node meta data value for this key
@throws GroovyBugError if key is null | [
"Sets",
"the",
"node",
"meta",
"data",
"but",
"allows",
"overwriting",
"values",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L165-L171 |
6 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ASTNode.java | ASTNode.removeNodeMetaData | public void removeNodeMetaData(Object key) {
if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+".");
if (metaDataMap == null) {
return;
}
metaDataMap.remove(key);
} | java | public void removeNodeMetaData(Object key) {
if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+".");
if (metaDataMap == null) {
return;
}
metaDataMap.remove(key);
} | [
"public",
"void",
"removeNodeMetaData",
"(",
"Object",
"key",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"throw",
"new",
"GroovyBugError",
"(",
"\"Tried to remove meta data with null key \"",
"+",
"this",
"+",
"\".\"",
")",
";",
"if",
"(",
"metaDataMap",
"==",
"null",
")",
"{",
"return",
";",
"}",
"metaDataMap",
".",
"remove",
"(",
"key",
")",
";",
"}"
] | Removes a node meta data entry.
@param key - the meta data key
@throws GroovyBugError if the key is null | [
"Removes",
"a",
"node",
"meta",
"data",
"entry",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L179-L185 |
7 | groovy/groovy-core | src/main/groovy/lang/IntRange.java | IntRange.subListBorders | public RangeInfo subListBorders(int size) {
if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange");
int tempFrom = from;
if (tempFrom < 0) {
tempFrom += size;
}
int tempTo = to;
if (tempTo < 0) {
tempTo += size;
}
if (tempFrom > tempTo) {
return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);
}
return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);
} | java | public RangeInfo subListBorders(int size) {
if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange");
int tempFrom = from;
if (tempFrom < 0) {
tempFrom += size;
}
int tempTo = to;
if (tempTo < 0) {
tempTo += size;
}
if (tempFrom > tempTo) {
return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);
}
return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);
} | [
"public",
"RangeInfo",
"subListBorders",
"(",
"int",
"size",
")",
"{",
"if",
"(",
"inclusive",
"==",
"null",
")",
"throw",
"new",
"IllegalStateException",
"(",
"\"Should not call subListBorders on a non-inclusive aware IntRange\"",
")",
";",
"int",
"tempFrom",
"=",
"from",
";",
"if",
"(",
"tempFrom",
"<",
"0",
")",
"{",
"tempFrom",
"+=",
"size",
";",
"}",
"int",
"tempTo",
"=",
"to",
";",
"if",
"(",
"tempTo",
"<",
"0",
")",
"{",
"tempTo",
"+=",
"size",
";",
"}",
"if",
"(",
"tempFrom",
">",
"tempTo",
")",
"{",
"return",
"new",
"RangeInfo",
"(",
"inclusive",
"?",
"tempTo",
":",
"tempTo",
"+",
"1",
",",
"tempFrom",
"+",
"1",
",",
"true",
")",
";",
"}",
"return",
"new",
"RangeInfo",
"(",
"tempFrom",
",",
"inclusive",
"?",
"tempTo",
"+",
"1",
":",
"tempTo",
",",
"false",
")",
";",
"}"
] | A method for determining from and to information when using this IntRange to index an aggregate object of the specified size.
Normally only used internally within Groovy but useful if adding range indexing support for your own aggregates.
@param size the size of the aggregate being indexed
@return the calculated range information (with 1 added to the to value, ready for providing to subList | [
"A",
"method",
"for",
"determining",
"from",
"and",
"to",
"information",
"when",
"using",
"this",
"IntRange",
"to",
"index",
"an",
"aggregate",
"object",
"of",
"the",
"specified",
"size",
".",
"Normally",
"only",
"used",
"internally",
"within",
"Groovy",
"but",
"useful",
"if",
"adding",
"range",
"indexing",
"support",
"for",
"your",
"own",
"aggregates",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/IntRange.java#L197-L211 |
8 | groovy/groovy-core | src/main/groovy/beans/BindableASTTransformation.java | BindableASTTransformation.createSetterMethod | protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) {
MethodNode setter = new MethodNode(
setterName,
propertyNode.getModifiers(),
ClassHelper.VOID_TYPE,
params(param(propertyNode.getType(), "value")),
ClassNode.EMPTY_ARRAY,
setterBlock);
setter.setSynthetic(true);
// add it to the class
declaringClass.addMethod(setter);
} | java | protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) {
MethodNode setter = new MethodNode(
setterName,
propertyNode.getModifiers(),
ClassHelper.VOID_TYPE,
params(param(propertyNode.getType(), "value")),
ClassNode.EMPTY_ARRAY,
setterBlock);
setter.setSynthetic(true);
// add it to the class
declaringClass.addMethod(setter);
} | [
"protected",
"void",
"createSetterMethod",
"(",
"ClassNode",
"declaringClass",
",",
"PropertyNode",
"propertyNode",
",",
"String",
"setterName",
",",
"Statement",
"setterBlock",
")",
"{",
"MethodNode",
"setter",
"=",
"new",
"MethodNode",
"(",
"setterName",
",",
"propertyNode",
".",
"getModifiers",
"(",
")",
",",
"ClassHelper",
".",
"VOID_TYPE",
",",
"params",
"(",
"param",
"(",
"propertyNode",
".",
"getType",
"(",
")",
",",
"\"value\"",
")",
")",
",",
"ClassNode",
".",
"EMPTY_ARRAY",
",",
"setterBlock",
")",
";",
"setter",
".",
"setSynthetic",
"(",
"true",
")",
";",
"// add it to the class\r",
"declaringClass",
".",
"addMethod",
"(",
"setter",
")",
";",
"}"
] | Creates a setter method with the given body.
@param declaringClass the class to which we will add the setter
@param propertyNode the field to back the setter
@param setterName the name of the setter
@param setterBlock the statement representing the setter block | [
"Creates",
"a",
"setter",
"method",
"with",
"the",
"given",
"body",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/beans/BindableASTTransformation.java#L247-L258 |
9 | groovy/groovy-core | src/main/org/codehaus/groovy/control/CompilationUnit.java | CompilationUnit.applyToPrimaryClassNodes | public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException {
Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator();
while (classNodes.hasNext()) {
SourceUnit context = null;
try {
ClassNode classNode = (ClassNode) classNodes.next();
context = classNode.getModule().getContext();
if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) {
int offset = 1;
Iterator<InnerClassNode> iterator = classNode.getInnerClasses();
while (iterator.hasNext()) {
iterator.next();
offset++;
}
body.call(context, new GeneratorContext(this.ast, offset), classNode);
}
} catch (CompilationFailedException e) {
// fall through, getErrorReporter().failIfErrors() will trigger
} catch (NullPointerException npe) {
GroovyBugError gbe = new GroovyBugError("unexpected NullpointerException", npe);
changeBugText(gbe, context);
throw gbe;
} catch (GroovyBugError e) {
changeBugText(e, context);
throw e;
} catch (NoClassDefFoundError e) {
// effort to get more logging in case a dependency of a class is loaded
// although it shouldn't have
convertUncaughtExceptionToCompilationError(e);
} catch (Exception e) {
convertUncaughtExceptionToCompilationError(e);
}
}
getErrorCollector().failIfErrors();
} | java | public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException {
Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator();
while (classNodes.hasNext()) {
SourceUnit context = null;
try {
ClassNode classNode = (ClassNode) classNodes.next();
context = classNode.getModule().getContext();
if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) {
int offset = 1;
Iterator<InnerClassNode> iterator = classNode.getInnerClasses();
while (iterator.hasNext()) {
iterator.next();
offset++;
}
body.call(context, new GeneratorContext(this.ast, offset), classNode);
}
} catch (CompilationFailedException e) {
// fall through, getErrorReporter().failIfErrors() will trigger
} catch (NullPointerException npe) {
GroovyBugError gbe = new GroovyBugError("unexpected NullpointerException", npe);
changeBugText(gbe, context);
throw gbe;
} catch (GroovyBugError e) {
changeBugText(e, context);
throw e;
} catch (NoClassDefFoundError e) {
// effort to get more logging in case a dependency of a class is loaded
// although it shouldn't have
convertUncaughtExceptionToCompilationError(e);
} catch (Exception e) {
convertUncaughtExceptionToCompilationError(e);
}
}
getErrorCollector().failIfErrors();
} | [
"public",
"void",
"applyToPrimaryClassNodes",
"(",
"PrimaryClassNodeOperation",
"body",
")",
"throws",
"CompilationFailedException",
"{",
"Iterator",
"classNodes",
"=",
"getPrimaryClassNodes",
"(",
"body",
".",
"needSortedInput",
"(",
")",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"classNodes",
".",
"hasNext",
"(",
")",
")",
"{",
"SourceUnit",
"context",
"=",
"null",
";",
"try",
"{",
"ClassNode",
"classNode",
"=",
"(",
"ClassNode",
")",
"classNodes",
".",
"next",
"(",
")",
";",
"context",
"=",
"classNode",
".",
"getModule",
"(",
")",
".",
"getContext",
"(",
")",
";",
"if",
"(",
"context",
"==",
"null",
"||",
"context",
".",
"phase",
"<",
"phase",
"||",
"(",
"context",
".",
"phase",
"==",
"phase",
"&&",
"!",
"context",
".",
"phaseComplete",
")",
")",
"{",
"int",
"offset",
"=",
"1",
";",
"Iterator",
"<",
"InnerClassNode",
">",
"iterator",
"=",
"classNode",
".",
"getInnerClasses",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"iterator",
".",
"next",
"(",
")",
";",
"offset",
"++",
";",
"}",
"body",
".",
"call",
"(",
"context",
",",
"new",
"GeneratorContext",
"(",
"this",
".",
"ast",
",",
"offset",
")",
",",
"classNode",
")",
";",
"}",
"}",
"catch",
"(",
"CompilationFailedException",
"e",
")",
"{",
"// fall through, getErrorReporter().failIfErrors() will trigger",
"}",
"catch",
"(",
"NullPointerException",
"npe",
")",
"{",
"GroovyBugError",
"gbe",
"=",
"new",
"GroovyBugError",
"(",
"\"unexpected NullpointerException\"",
",",
"npe",
")",
";",
"changeBugText",
"(",
"gbe",
",",
"context",
")",
";",
"throw",
"gbe",
";",
"}",
"catch",
"(",
"GroovyBugError",
"e",
")",
"{",
"changeBugText",
"(",
"e",
",",
"context",
")",
";",
"throw",
"e",
";",
"}",
"catch",
"(",
"NoClassDefFoundError",
"e",
")",
"{",
"// effort to get more logging in case a dependency of a class is loaded",
"// although it shouldn't have",
"convertUncaughtExceptionToCompilationError",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"convertUncaughtExceptionToCompilationError",
"(",
"e",
")",
";",
"}",
"}",
"getErrorCollector",
"(",
")",
".",
"failIfErrors",
"(",
")",
";",
"}"
] | A loop driver for applying operations to all primary ClassNodes in
our AST. Automatically skips units that have already been processed
through the current phase. | [
"A",
"loop",
"driver",
"for",
"applying",
"operations",
"to",
"all",
"primary",
"ClassNodes",
"in",
"our",
"AST",
".",
"Automatically",
"skips",
"units",
"that",
"have",
"already",
"been",
"processed",
"through",
"the",
"current",
"phase",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/CompilationUnit.java#L1041-L1076 |
10 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java | SocketGroovyMethods.withStreams | public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
try {
T result = closure.call(new Object[]{input, output});
InputStream temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(input);
closeWithWarning(output);
}
} | java | public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
try {
T result = closure.call(new Object[]{input, output});
InputStream temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(input);
closeWithWarning(output);
}
} | [
"public",
"static",
"<",
"T",
">",
"T",
"withStreams",
"(",
"Socket",
"socket",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"{",
"\"java.io.InputStream\"",
",",
"\"java.io.OutputStream\"",
"}",
")",
"Closure",
"<",
"T",
">",
"closure",
")",
"throws",
"IOException",
"{",
"InputStream",
"input",
"=",
"socket",
".",
"getInputStream",
"(",
")",
";",
"OutputStream",
"output",
"=",
"socket",
".",
"getOutputStream",
"(",
")",
";",
"try",
"{",
"T",
"result",
"=",
"closure",
".",
"call",
"(",
"new",
"Object",
"[",
"]",
"{",
"input",
",",
"output",
"}",
")",
";",
"InputStream",
"temp1",
"=",
"input",
";",
"input",
"=",
"null",
";",
"temp1",
".",
"close",
"(",
")",
";",
"OutputStream",
"temp2",
"=",
"output",
";",
"output",
"=",
"null",
";",
"temp2",
".",
"close",
"(",
")",
";",
"return",
"result",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"input",
")",
";",
"closeWithWarning",
"(",
"output",
")",
";",
"}",
"}"
] | Passes the Socket's InputStream and OutputStream to the closure. The
streams will be closed after the closure returns, even if an exception
is thrown.
@param socket a Socket
@param closure a Closure
@return the value returned by the closure
@throws IOException if an IOException occurs.
@since 1.5.2 | [
"Passes",
"the",
"Socket",
"s",
"InputStream",
"and",
"OutputStream",
"to",
"the",
"closure",
".",
"The",
"streams",
"will",
"be",
"closed",
"after",
"the",
"closure",
"returns",
"even",
"if",
"an",
"exception",
"is",
"thrown",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L61-L79 |
11 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java | SocketGroovyMethods.withObjectStreams | public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(output);
ObjectInputStream ois = new ObjectInputStream(input);
try {
T result = closure.call(new Object[]{ois, oos});
InputStream temp1 = ois;
ois = null;
temp1.close();
temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = oos;
oos = null;
temp2.close();
temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(ois);
closeWithWarning(input);
closeWithWarning(oos);
closeWithWarning(output);
}
} | java | public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(output);
ObjectInputStream ois = new ObjectInputStream(input);
try {
T result = closure.call(new Object[]{ois, oos});
InputStream temp1 = ois;
ois = null;
temp1.close();
temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = oos;
oos = null;
temp2.close();
temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(ois);
closeWithWarning(input);
closeWithWarning(oos);
closeWithWarning(output);
}
} | [
"public",
"static",
"<",
"T",
">",
"T",
"withObjectStreams",
"(",
"Socket",
"socket",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"{",
"\"java.io.ObjectInputStream\"",
",",
"\"java.io.ObjectOutputStream\"",
"}",
")",
"Closure",
"<",
"T",
">",
"closure",
")",
"throws",
"IOException",
"{",
"InputStream",
"input",
"=",
"socket",
".",
"getInputStream",
"(",
")",
";",
"OutputStream",
"output",
"=",
"socket",
".",
"getOutputStream",
"(",
")",
";",
"ObjectOutputStream",
"oos",
"=",
"new",
"ObjectOutputStream",
"(",
"output",
")",
";",
"ObjectInputStream",
"ois",
"=",
"new",
"ObjectInputStream",
"(",
"input",
")",
";",
"try",
"{",
"T",
"result",
"=",
"closure",
".",
"call",
"(",
"new",
"Object",
"[",
"]",
"{",
"ois",
",",
"oos",
"}",
")",
";",
"InputStream",
"temp1",
"=",
"ois",
";",
"ois",
"=",
"null",
";",
"temp1",
".",
"close",
"(",
")",
";",
"temp1",
"=",
"input",
";",
"input",
"=",
"null",
";",
"temp1",
".",
"close",
"(",
")",
";",
"OutputStream",
"temp2",
"=",
"oos",
";",
"oos",
"=",
"null",
";",
"temp2",
".",
"close",
"(",
")",
";",
"temp2",
"=",
"output",
";",
"output",
"=",
"null",
";",
"temp2",
".",
"close",
"(",
")",
";",
"return",
"result",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"ois",
")",
";",
"closeWithWarning",
"(",
"input",
")",
";",
"closeWithWarning",
"(",
"oos",
")",
";",
"closeWithWarning",
"(",
"output",
")",
";",
"}",
"}"
] | Creates an InputObjectStream and an OutputObjectStream from a Socket, and
passes them to the closure. The streams will be closed after the closure
returns, even if an exception is thrown.
@param socket this Socket
@param closure a Closure
@return the value returned by the closure
@throws IOException if an IOException occurs.
@since 1.5.0 | [
"Creates",
"an",
"InputObjectStream",
"and",
"an",
"OutputObjectStream",
"from",
"a",
"Socket",
"and",
"passes",
"them",
"to",
"the",
"closure",
".",
"The",
"streams",
"will",
"be",
"closed",
"after",
"the",
"closure",
"returns",
"even",
"if",
"an",
"exception",
"is",
"thrown",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L92-L120 |
12 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/MethodKey.java | MethodKey.createCopy | public MethodKey createCopy() {
int size = getParameterCount();
Class[] paramTypes = new Class[size];
for (int i = 0; i < size; i++) {
paramTypes[i] = getParameterType(i);
}
return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper);
} | java | public MethodKey createCopy() {
int size = getParameterCount();
Class[] paramTypes = new Class[size];
for (int i = 0; i < size; i++) {
paramTypes[i] = getParameterType(i);
}
return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper);
} | [
"public",
"MethodKey",
"createCopy",
"(",
")",
"{",
"int",
"size",
"=",
"getParameterCount",
"(",
")",
";",
"Class",
"[",
"]",
"paramTypes",
"=",
"new",
"Class",
"[",
"size",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"paramTypes",
"[",
"i",
"]",
"=",
"getParameterType",
"(",
"i",
")",
";",
"}",
"return",
"new",
"DefaultMethodKey",
"(",
"sender",
",",
"name",
",",
"paramTypes",
",",
"isCallToSuper",
")",
";",
"}"
] | Creates an immutable copy that we can cache. | [
"Creates",
"an",
"immutable",
"copy",
"that",
"we",
"can",
"cache",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/MethodKey.java#L49-L56 |
13 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/trait/TraitComposer.java | TraitComposer.doExtendTraits | public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
if (cNode.isInterface()) return;
boolean isItselfTrait = Traits.isTrait(cNode);
SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
if (isItselfTrait) {
checkTraitAllowed(cNode, unit);
return;
}
if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) {
List<ClassNode> traits = findTraits(cNode);
for (ClassNode trait : traits) {
TraitHelpersTuple helpers = Traits.findHelpers(trait);
applyTrait(trait, cNode, helpers);
superCallTransformer.visitClass(cNode);
if (unit!=null) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader());
collector.visitClass(cNode);
}
}
}
} | java | public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
if (cNode.isInterface()) return;
boolean isItselfTrait = Traits.isTrait(cNode);
SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
if (isItselfTrait) {
checkTraitAllowed(cNode, unit);
return;
}
if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) {
List<ClassNode> traits = findTraits(cNode);
for (ClassNode trait : traits) {
TraitHelpersTuple helpers = Traits.findHelpers(trait);
applyTrait(trait, cNode, helpers);
superCallTransformer.visitClass(cNode);
if (unit!=null) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader());
collector.visitClass(cNode);
}
}
}
} | [
"public",
"static",
"void",
"doExtendTraits",
"(",
"final",
"ClassNode",
"cNode",
",",
"final",
"SourceUnit",
"unit",
",",
"final",
"CompilationUnit",
"cu",
")",
"{",
"if",
"(",
"cNode",
".",
"isInterface",
"(",
")",
")",
"return",
";",
"boolean",
"isItselfTrait",
"=",
"Traits",
".",
"isTrait",
"(",
"cNode",
")",
";",
"SuperCallTraitTransformer",
"superCallTransformer",
"=",
"new",
"SuperCallTraitTransformer",
"(",
"unit",
")",
";",
"if",
"(",
"isItselfTrait",
")",
"{",
"checkTraitAllowed",
"(",
"cNode",
",",
"unit",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"cNode",
".",
"getNameWithoutPackage",
"(",
")",
".",
"endsWith",
"(",
"Traits",
".",
"TRAIT_HELPER",
")",
")",
"{",
"List",
"<",
"ClassNode",
">",
"traits",
"=",
"findTraits",
"(",
"cNode",
")",
";",
"for",
"(",
"ClassNode",
"trait",
":",
"traits",
")",
"{",
"TraitHelpersTuple",
"helpers",
"=",
"Traits",
".",
"findHelpers",
"(",
"trait",
")",
";",
"applyTrait",
"(",
"trait",
",",
"cNode",
",",
"helpers",
")",
";",
"superCallTransformer",
".",
"visitClass",
"(",
"cNode",
")",
";",
"if",
"(",
"unit",
"!=",
"null",
")",
"{",
"ASTTransformationCollectorCodeVisitor",
"collector",
"=",
"new",
"ASTTransformationCollectorCodeVisitor",
"(",
"unit",
",",
"cu",
".",
"getTransformLoader",
"(",
")",
")",
";",
"collector",
".",
"visitClass",
"(",
"cNode",
")",
";",
"}",
"}",
"}",
"}"
] | Given a class node, if this class node implements a trait, then generate all the appropriate
code which delegates calls to the trait. It is safe to call this method on a class node which
does not implement a trait.
@param cNode a class node
@param unit the source unit | [
"Given",
"a",
"class",
"node",
"if",
"this",
"class",
"node",
"implements",
"a",
"trait",
"then",
"generate",
"all",
"the",
"appropriate",
"code",
"which",
"delegates",
"calls",
"to",
"the",
"trait",
".",
"It",
"is",
"safe",
"to",
"call",
"this",
"method",
"on",
"a",
"class",
"node",
"which",
"does",
"not",
"implement",
"a",
"trait",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/trait/TraitComposer.java#L102-L122 |
14 | groovy/groovy-core | src/main/org/codehaus/groovy/control/ErrorCollector.java | ErrorCollector.getSyntaxError | public SyntaxException getSyntaxError(int index) {
SyntaxException exception = null;
Message message = getError(index);
if (message != null && message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
return exception;
} | java | public SyntaxException getSyntaxError(int index) {
SyntaxException exception = null;
Message message = getError(index);
if (message != null && message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
return exception;
} | [
"public",
"SyntaxException",
"getSyntaxError",
"(",
"int",
"index",
")",
"{",
"SyntaxException",
"exception",
"=",
"null",
";",
"Message",
"message",
"=",
"getError",
"(",
"index",
")",
";",
"if",
"(",
"message",
"!=",
"null",
"&&",
"message",
"instanceof",
"SyntaxErrorMessage",
")",
"{",
"exception",
"=",
"(",
"(",
"SyntaxErrorMessage",
")",
"message",
")",
".",
"getCause",
"(",
")",
";",
"}",
"return",
"exception",
";",
"}"
] | Convenience routine to return the specified error's
underlying SyntaxException, or null if it isn't one. | [
"Convenience",
"routine",
"to",
"return",
"the",
"specified",
"error",
"s",
"underlying",
"SyntaxException",
"or",
"null",
"if",
"it",
"isn",
"t",
"one",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/ErrorCollector.java#L240-L248 |
15 | groovy/groovy-core | src/main/org/apache/commons/cli/GroovyInternalPosixParser.java | GroovyInternalPosixParser.gobble | private void gobble(Iterator iter)
{
if (eatTheRest)
{
while (iter.hasNext())
{
tokens.add(iter.next());
}
}
} | java | private void gobble(Iterator iter)
{
if (eatTheRest)
{
while (iter.hasNext())
{
tokens.add(iter.next());
}
}
} | [
"private",
"void",
"gobble",
"(",
"Iterator",
"iter",
")",
"{",
"if",
"(",
"eatTheRest",
")",
"{",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"tokens",
".",
"add",
"(",
"iter",
".",
"next",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Adds the remaining tokens to the processed tokens list.
@param iter An iterator over the remaining tokens | [
"Adds",
"the",
"remaining",
"tokens",
"to",
"the",
"processed",
"tokens",
"list",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/apache/commons/cli/GroovyInternalPosixParser.java#L165-L174 |
16 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java | StaticTypeCheckingSupport.allParametersAndArgumentsMatch | public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) {
if (params==null) {
params = Parameter.EMPTY_ARRAY;
}
int dist = 0;
if (args.length<params.length) return -1;
// we already know the lengths are equal
for (int i = 0; i < params.length; i++) {
ClassNode paramType = params[i].getType();
ClassNode argType = args[i];
if (!isAssignableTo(argType, paramType)) return -1;
else {
if (!paramType.equals(argType)) dist+=getDistance(argType, paramType);
}
}
return dist;
} | java | public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) {
if (params==null) {
params = Parameter.EMPTY_ARRAY;
}
int dist = 0;
if (args.length<params.length) return -1;
// we already know the lengths are equal
for (int i = 0; i < params.length; i++) {
ClassNode paramType = params[i].getType();
ClassNode argType = args[i];
if (!isAssignableTo(argType, paramType)) return -1;
else {
if (!paramType.equals(argType)) dist+=getDistance(argType, paramType);
}
}
return dist;
} | [
"public",
"static",
"int",
"allParametersAndArgumentsMatch",
"(",
"Parameter",
"[",
"]",
"params",
",",
"ClassNode",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"params",
"==",
"null",
")",
"{",
"params",
"=",
"Parameter",
".",
"EMPTY_ARRAY",
";",
"}",
"int",
"dist",
"=",
"0",
";",
"if",
"(",
"args",
".",
"length",
"<",
"params",
".",
"length",
")",
"return",
"-",
"1",
";",
"// we already know the lengths are equal",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"params",
".",
"length",
";",
"i",
"++",
")",
"{",
"ClassNode",
"paramType",
"=",
"params",
"[",
"i",
"]",
".",
"getType",
"(",
")",
";",
"ClassNode",
"argType",
"=",
"args",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"isAssignableTo",
"(",
"argType",
",",
"paramType",
")",
")",
"return",
"-",
"1",
";",
"else",
"{",
"if",
"(",
"!",
"paramType",
".",
"equals",
"(",
"argType",
")",
")",
"dist",
"+=",
"getDistance",
"(",
"argType",
",",
"paramType",
")",
";",
"}",
"}",
"return",
"dist",
";",
"}"
] | Checks that arguments and parameter types match.
@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",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L216-L232 |
17 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java | StaticTypeCheckingSupport.excessArgumentsMatchesVargsParameter | static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) {
// we already know parameter length is bigger zero and last is a vargs
// the excess arguments are all put in an array for the vargs call
// so check against the component type
int dist = 0;
ClassNode vargsBase = params[params.length - 1].getType().getComponentType();
for (int i = params.length; i < args.length; i++) {
if (!isAssignableTo(args[i],vargsBase)) return -1;
else if (!args[i].equals(vargsBase)) dist+=getDistance(args[i], vargsBase);
}
return dist;
} | java | static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) {
// we already know parameter length is bigger zero and last is a vargs
// the excess arguments are all put in an array for the vargs call
// so check against the component type
int dist = 0;
ClassNode vargsBase = params[params.length - 1].getType().getComponentType();
for (int i = params.length; i < args.length; i++) {
if (!isAssignableTo(args[i],vargsBase)) return -1;
else if (!args[i].equals(vargsBase)) dist+=getDistance(args[i], vargsBase);
}
return dist;
} | [
"static",
"int",
"excessArgumentsMatchesVargsParameter",
"(",
"Parameter",
"[",
"]",
"params",
",",
"ClassNode",
"[",
"]",
"args",
")",
"{",
"// we already know parameter length is bigger zero and last is a vargs",
"// the excess arguments are all put in an array for the vargs call",
"// so check against the component type",
"int",
"dist",
"=",
"0",
";",
"ClassNode",
"vargsBase",
"=",
"params",
"[",
"params",
".",
"length",
"-",
"1",
"]",
".",
"getType",
"(",
")",
".",
"getComponentType",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"params",
".",
"length",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isAssignableTo",
"(",
"args",
"[",
"i",
"]",
",",
"vargsBase",
")",
")",
"return",
"-",
"1",
";",
"else",
"if",
"(",
"!",
"args",
"[",
"i",
"]",
".",
"equals",
"(",
"vargsBase",
")",
")",
"dist",
"+=",
"getDistance",
"(",
"args",
"[",
"i",
"]",
",",
"vargsBase",
")",
";",
"}",
"return",
"dist",
";",
"}"
] | Checks that excess arguments match the vararg signature parameter.
@param params
@param args
@return -1 if no match, 0 if all arguments matches the vararg type and >0 if one or more vararg argument is
assignable to the vararg type, but still not an exact match | [
"Checks",
"that",
"excess",
"arguments",
"match",
"the",
"vararg",
"signature",
"parameter",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L276-L287 |
18 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java | StaticTypeCheckingSupport.lastArgMatchesVarg | static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) {
if (!isVargs(params)) return -1;
// case length ==0 handled already
// we have now two cases,
// the argument is wrapped in the vargs array or
// the argument is an array that can be used for the vargs part directly
// we test only the wrapping part, since the non wrapping is done already
ClassNode lastParamType = params[params.length - 1].getType();
ClassNode ptype = lastParamType.getComponentType();
ClassNode arg = args[args.length - 1];
if (isNumberType(ptype) && isNumberType(arg) && !ptype.equals(arg)) return -1;
return isAssignableTo(arg, ptype)?Math.min(getDistance(arg, lastParamType), getDistance(arg, ptype)):-1;
} | java | static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) {
if (!isVargs(params)) return -1;
// case length ==0 handled already
// we have now two cases,
// the argument is wrapped in the vargs array or
// the argument is an array that can be used for the vargs part directly
// we test only the wrapping part, since the non wrapping is done already
ClassNode lastParamType = params[params.length - 1].getType();
ClassNode ptype = lastParamType.getComponentType();
ClassNode arg = args[args.length - 1];
if (isNumberType(ptype) && isNumberType(arg) && !ptype.equals(arg)) return -1;
return isAssignableTo(arg, ptype)?Math.min(getDistance(arg, lastParamType), getDistance(arg, ptype)):-1;
} | [
"static",
"int",
"lastArgMatchesVarg",
"(",
"Parameter",
"[",
"]",
"params",
",",
"ClassNode",
"...",
"args",
")",
"{",
"if",
"(",
"!",
"isVargs",
"(",
"params",
")",
")",
"return",
"-",
"1",
";",
"// case length ==0 handled already",
"// we have now two cases,",
"// the argument is wrapped in the vargs array or",
"// the argument is an array that can be used for the vargs part directly",
"// we test only the wrapping part, since the non wrapping is done already",
"ClassNode",
"lastParamType",
"=",
"params",
"[",
"params",
".",
"length",
"-",
"1",
"]",
".",
"getType",
"(",
")",
";",
"ClassNode",
"ptype",
"=",
"lastParamType",
".",
"getComponentType",
"(",
")",
";",
"ClassNode",
"arg",
"=",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"isNumberType",
"(",
"ptype",
")",
"&&",
"isNumberType",
"(",
"arg",
")",
"&&",
"!",
"ptype",
".",
"equals",
"(",
"arg",
")",
")",
"return",
"-",
"1",
";",
"return",
"isAssignableTo",
"(",
"arg",
",",
"ptype",
")",
"?",
"Math",
".",
"min",
"(",
"getDistance",
"(",
"arg",
",",
"lastParamType",
")",
",",
"getDistance",
"(",
"arg",
",",
"ptype",
")",
")",
":",
"-",
"1",
";",
"}"
] | Checks if the last argument matches the vararg type.
@param params
@param args
@return -1 if no match, 0 if the last argument is exactly the vararg type and 1 if of an assignable type | [
"Checks",
"if",
"the",
"last",
"argument",
"matches",
"the",
"vararg",
"type",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L295-L307 |
19 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java | StaticTypeCheckingSupport.buildParameter | private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) {
if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) {
return methodParameter;
}
if (paramType.isArray()) {
ClassNode componentType = paramType.getComponentType();
Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName());
Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType);
return new Parameter(component.getType().makeArray(), component.getName());
}
ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType);
return new Parameter(resolved, methodParameter.getName());
} | java | private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) {
if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) {
return methodParameter;
}
if (paramType.isArray()) {
ClassNode componentType = paramType.getComponentType();
Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName());
Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType);
return new Parameter(component.getType().makeArray(), component.getName());
}
ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType);
return new Parameter(resolved, methodParameter.getName());
} | [
"private",
"static",
"Parameter",
"buildParameter",
"(",
"final",
"Map",
"<",
"String",
",",
"GenericsType",
">",
"genericFromReceiver",
",",
"final",
"Map",
"<",
"String",
",",
"GenericsType",
">",
"placeholdersFromContext",
",",
"final",
"Parameter",
"methodParameter",
",",
"final",
"ClassNode",
"paramType",
")",
"{",
"if",
"(",
"genericFromReceiver",
".",
"isEmpty",
"(",
")",
"&&",
"(",
"placeholdersFromContext",
"==",
"null",
"||",
"placeholdersFromContext",
".",
"isEmpty",
"(",
")",
")",
")",
"{",
"return",
"methodParameter",
";",
"}",
"if",
"(",
"paramType",
".",
"isArray",
"(",
")",
")",
"{",
"ClassNode",
"componentType",
"=",
"paramType",
".",
"getComponentType",
"(",
")",
";",
"Parameter",
"subMethodParameter",
"=",
"new",
"Parameter",
"(",
"componentType",
",",
"methodParameter",
".",
"getName",
"(",
")",
")",
";",
"Parameter",
"component",
"=",
"buildParameter",
"(",
"genericFromReceiver",
",",
"placeholdersFromContext",
",",
"subMethodParameter",
",",
"componentType",
")",
";",
"return",
"new",
"Parameter",
"(",
"component",
".",
"getType",
"(",
")",
".",
"makeArray",
"(",
")",
",",
"component",
".",
"getName",
"(",
")",
")",
";",
"}",
"ClassNode",
"resolved",
"=",
"resolveClassNodeGenerics",
"(",
"genericFromReceiver",
",",
"placeholdersFromContext",
",",
"paramType",
")",
";",
"return",
"new",
"Parameter",
"(",
"resolved",
",",
"methodParameter",
".",
"getName",
"(",
")",
")",
";",
"}"
] | Given a parameter, builds a new parameter for which the known generics placeholders are resolved.
@param genericFromReceiver resolved generics from the receiver of the message
@param placeholdersFromContext, resolved generics from the method context
@param methodParameter the method parameter for which we want to resolve generic types
@param paramType the (unresolved) type of the method parameter
@return a new parameter with the same name and type as the original one, but with resolved generic types | [
"Given",
"a",
"parameter",
"builds",
"a",
"new",
"parameter",
"for",
"which",
"the",
"known",
"generics",
"placeholders",
"are",
"resolved",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1170-L1183 |
20 | groovy/groovy-core | src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java | StaticTypeCheckingSupport.isClassClassNodeWrappingConcreteType | public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) {
GenericsType[] genericsTypes = classNode.getGenericsTypes();
return ClassHelper.CLASS_Type.equals(classNode)
&& classNode.isUsingGenerics()
&& genericsTypes!=null
&& !genericsTypes[0].isPlaceholder()
&& !genericsTypes[0].isWildcard();
} | java | public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) {
GenericsType[] genericsTypes = classNode.getGenericsTypes();
return ClassHelper.CLASS_Type.equals(classNode)
&& classNode.isUsingGenerics()
&& genericsTypes!=null
&& !genericsTypes[0].isPlaceholder()
&& !genericsTypes[0].isWildcard();
} | [
"public",
"static",
"boolean",
"isClassClassNodeWrappingConcreteType",
"(",
"ClassNode",
"classNode",
")",
"{",
"GenericsType",
"[",
"]",
"genericsTypes",
"=",
"classNode",
".",
"getGenericsTypes",
"(",
")",
";",
"return",
"ClassHelper",
".",
"CLASS_Type",
".",
"equals",
"(",
"classNode",
")",
"&&",
"classNode",
".",
"isUsingGenerics",
"(",
")",
"&&",
"genericsTypes",
"!=",
"null",
"&&",
"!",
"genericsTypes",
"[",
"0",
"]",
".",
"isPlaceholder",
"(",
")",
"&&",
"!",
"genericsTypes",
"[",
"0",
"]",
".",
"isWildcard",
"(",
")",
";",
"}"
] | Returns true if the class node represents a the class node for the Class class
and if the parametrized type is a neither a placeholder or a wildcard. For example,
the class node Class<Foo> where Foo is a class would return true, but the class
node for Class<?> would return false.
@param classNode a class node to be tested
@return true if it is the class node for Class and its generic type is a real class | [
"Returns",
"true",
"if",
"the",
"class",
"node",
"represents",
"a",
"the",
"class",
"node",
"for",
"the",
"Class",
"class",
"and",
"if",
"the",
"parametrized",
"type",
"is",
"a",
"neither",
"a",
"placeholder",
"or",
"a",
"wildcard",
".",
"For",
"example",
"the",
"class",
"node",
"Class<",
";",
"Foo>",
";",
"where",
"Foo",
"is",
"a",
"class",
"would",
"return",
"true",
"but",
"the",
"class",
"node",
"for",
"Class<",
";",
"?>",
";",
"would",
"return",
"false",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L2069-L2076 |
21 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java | IOGroovyMethods.splitEachLine | public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException {
return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure);
} | java | public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException {
return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure);
} | [
"public",
"static",
"<",
"T",
">",
"T",
"splitEachLine",
"(",
"InputStream",
"stream",
",",
"String",
"regex",
",",
"String",
"charset",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"FromString",
".",
"class",
",",
"options",
"=",
"\"List<String>\"",
")",
"Closure",
"<",
"T",
">",
"closure",
")",
"throws",
"IOException",
"{",
"return",
"splitEachLine",
"(",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"stream",
",",
"charset",
")",
")",
",",
"regex",
",",
"closure",
")",
";",
"}"
] | Iterates through the given InputStream line by line using the specified
encoding, splitting each line using the given separator. The list of tokens
for each line is then passed to the given closure. Finally, the stream
is closed.
@param stream an InputStream
@param regex the delimiting regular expression
@param charset opens the stream with a specified charset
@param closure a closure
@return the last value returned by the closure
@throws IOException if an IOException occurs.
@throws java.util.regex.PatternSyntaxException
if the regular expression's syntax is invalid
@see #splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
@since 1.5.5 | [
"Iterates",
"through",
"the",
"given",
"InputStream",
"line",
"by",
"line",
"using",
"the",
"specified",
"encoding",
"splitting",
"each",
"line",
"using",
"the",
"given",
"separator",
".",
"The",
"list",
"of",
"tokens",
"for",
"each",
"line",
"is",
"then",
"passed",
"to",
"the",
"given",
"closure",
".",
"Finally",
"the",
"stream",
"is",
"closed",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L603-L605 |
22 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java | IOGroovyMethods.transformChar | public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException {
int c;
try {
char[] chars = new char[1];
while ((c = self.read()) != -1) {
chars[0] = (char) c;
writer.write((String) closure.call(new String(chars)));
}
writer.flush();
Writer temp2 = writer;
writer = null;
temp2.close();
Reader temp1 = self;
self = null;
temp1.close();
} finally {
closeWithWarning(self);
closeWithWarning(writer);
}
} | java | public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException {
int c;
try {
char[] chars = new char[1];
while ((c = self.read()) != -1) {
chars[0] = (char) c;
writer.write((String) closure.call(new String(chars)));
}
writer.flush();
Writer temp2 = writer;
writer = null;
temp2.close();
Reader temp1 = self;
self = null;
temp1.close();
} finally {
closeWithWarning(self);
closeWithWarning(writer);
}
} | [
"public",
"static",
"void",
"transformChar",
"(",
"Reader",
"self",
",",
"Writer",
"writer",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"\"java.lang.String\"",
")",
"Closure",
"closure",
")",
"throws",
"IOException",
"{",
"int",
"c",
";",
"try",
"{",
"char",
"[",
"]",
"chars",
"=",
"new",
"char",
"[",
"1",
"]",
";",
"while",
"(",
"(",
"c",
"=",
"self",
".",
"read",
"(",
")",
")",
"!=",
"-",
"1",
")",
"{",
"chars",
"[",
"0",
"]",
"=",
"(",
"char",
")",
"c",
";",
"writer",
".",
"write",
"(",
"(",
"String",
")",
"closure",
".",
"call",
"(",
"new",
"String",
"(",
"chars",
")",
")",
")",
";",
"}",
"writer",
".",
"flush",
"(",
")",
";",
"Writer",
"temp2",
"=",
"writer",
";",
"writer",
"=",
"null",
";",
"temp2",
".",
"close",
"(",
")",
";",
"Reader",
"temp1",
"=",
"self",
";",
"self",
"=",
"null",
";",
"temp1",
".",
"close",
"(",
")",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"self",
")",
";",
"closeWithWarning",
"(",
"writer",
")",
";",
"}",
"}"
] | Transforms each character from this reader by passing it to the given
closure. The Closure should return each transformed character, which
will be passed to the Writer. The reader and writer will be both be
closed before this method returns.
@param self a Reader object
@param writer a Writer to receive the transformed characters
@param closure a closure that performs the required transformation
@throws IOException if an IOException occurs.
@since 1.5.0 | [
"Transforms",
"each",
"character",
"from",
"this",
"reader",
"by",
"passing",
"it",
"to",
"the",
"given",
"closure",
".",
"The",
"Closure",
"should",
"return",
"each",
"transformed",
"character",
"which",
"will",
"be",
"passed",
"to",
"the",
"Writer",
".",
"The",
"reader",
"and",
"writer",
"will",
"be",
"both",
"be",
"closed",
"before",
"this",
"method",
"returns",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1398-L1418 |
23 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java | IOGroovyMethods.withCloseable | public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException {
try {
T result = action.call(self);
Closeable temp = self;
self = null;
temp.close();
return result;
} finally {
DefaultGroovyMethodsSupport.closeWithWarning(self);
}
} | java | public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException {
try {
T result = action.call(self);
Closeable temp = self;
self = null;
temp.close();
return result;
} finally {
DefaultGroovyMethodsSupport.closeWithWarning(self);
}
} | [
"public",
"static",
"<",
"T",
",",
"U",
"extends",
"Closeable",
">",
"T",
"withCloseable",
"(",
"U",
"self",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"FirstParam",
".",
"class",
")",
"Closure",
"<",
"T",
">",
"action",
")",
"throws",
"IOException",
"{",
"try",
"{",
"T",
"result",
"=",
"action",
".",
"call",
"(",
"self",
")",
";",
"Closeable",
"temp",
"=",
"self",
";",
"self",
"=",
"null",
";",
"temp",
".",
"close",
"(",
")",
";",
"return",
"result",
";",
"}",
"finally",
"{",
"DefaultGroovyMethodsSupport",
".",
"closeWithWarning",
"(",
"self",
")",
";",
"}",
"}"
] | Allows this closeable to be used within the closure, ensuring that it
is closed once the closure has been executed and before this method returns.
@param self the Closeable
@param action the closure taking the Closeable as parameter
@return the value returned by the closure
@throws IOException if an IOException occurs.
@since 2.4.0 | [
"Allows",
"this",
"closeable",
"to",
"be",
"used",
"within",
"the",
"closure",
"ensuring",
"that",
"it",
"is",
"closed",
"once",
"the",
"closure",
"has",
"been",
"executed",
"and",
"before",
"this",
"method",
"returns",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1620-L1632 |
24 | groovy/groovy-core | src/main/groovy/lang/MetaArrayLengthProperty.java | MetaArrayLengthProperty.getProperty | public Object getProperty(Object object) {
return java.lang.reflect.Array.getLength(object);
} | java | public Object getProperty(Object object) {
return java.lang.reflect.Array.getLength(object);
} | [
"public",
"Object",
"getProperty",
"(",
"Object",
"object",
")",
"{",
"return",
"java",
".",
"lang",
".",
"reflect",
".",
"Array",
".",
"getLength",
"(",
"object",
")",
";",
"}"
] | Get this property from the given object.
@param object an array
@return the length of the array object
@throws IllegalArgumentException if object is not an array | [
"Get",
"this",
"property",
"from",
"the",
"given",
"object",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaArrayLengthProperty.java#L43-L45 |
25 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java | ProxyGeneratorAdapter.makeDelegateCall | protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) {
MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions);
mv.visitVarInsn(ALOAD, 0); // load this
mv.visitFieldInsn(GETFIELD, proxyName, DELEGATE_OBJECT_FIELD, BytecodeHelper.getTypeDescription(delegateClass)); // load delegate
// using InvokerHelper to allow potential intercepted calls
int size;
mv.visitLdcInsn(name); // method name
Type[] args = Type.getArgumentTypes(desc);
BytecodeHelper.pushConstant(mv, args.length);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
size = 6;
int idx = 1;
for (int i = 0; i < args.length; i++) {
Type arg = args[i];
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
// primitive types must be boxed
if (isPrimitive(arg)) {
mv.visitIntInsn(getLoadInsn(arg), idx);
String wrappedType = getWrappedClassDescriptor(arg);
mv.visitMethodInsn(INVOKESTATIC, wrappedType, "valueOf", "(" + arg.getDescriptor() + ")L" + wrappedType + ";", false);
} else {
mv.visitVarInsn(ALOAD, idx); // load argument i
}
size = Math.max(size, 5+registerLen(arg));
idx += registerLen(arg);
mv.visitInsn(AASTORE); // store value into array
}
mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper", "invokeMethod", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", false);
unwrapResult(mv, desc);
mv.visitMaxs(size, registerLen(args) + 1);
return mv;
} | java | protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) {
MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions);
mv.visitVarInsn(ALOAD, 0); // load this
mv.visitFieldInsn(GETFIELD, proxyName, DELEGATE_OBJECT_FIELD, BytecodeHelper.getTypeDescription(delegateClass)); // load delegate
// using InvokerHelper to allow potential intercepted calls
int size;
mv.visitLdcInsn(name); // method name
Type[] args = Type.getArgumentTypes(desc);
BytecodeHelper.pushConstant(mv, args.length);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
size = 6;
int idx = 1;
for (int i = 0; i < args.length; i++) {
Type arg = args[i];
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
// primitive types must be boxed
if (isPrimitive(arg)) {
mv.visitIntInsn(getLoadInsn(arg), idx);
String wrappedType = getWrappedClassDescriptor(arg);
mv.visitMethodInsn(INVOKESTATIC, wrappedType, "valueOf", "(" + arg.getDescriptor() + ")L" + wrappedType + ";", false);
} else {
mv.visitVarInsn(ALOAD, idx); // load argument i
}
size = Math.max(size, 5+registerLen(arg));
idx += registerLen(arg);
mv.visitInsn(AASTORE); // store value into array
}
mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper", "invokeMethod", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", false);
unwrapResult(mv, desc);
mv.visitMaxs(size, registerLen(args) + 1);
return mv;
} | [
"protected",
"MethodVisitor",
"makeDelegateCall",
"(",
"final",
"String",
"name",
",",
"final",
"String",
"desc",
",",
"final",
"String",
"signature",
",",
"final",
"String",
"[",
"]",
"exceptions",
",",
"final",
"int",
"accessFlags",
")",
"{",
"MethodVisitor",
"mv",
"=",
"super",
".",
"visitMethod",
"(",
"accessFlags",
",",
"name",
",",
"desc",
",",
"signature",
",",
"exceptions",
")",
";",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"0",
")",
";",
"// load this",
"mv",
".",
"visitFieldInsn",
"(",
"GETFIELD",
",",
"proxyName",
",",
"DELEGATE_OBJECT_FIELD",
",",
"BytecodeHelper",
".",
"getTypeDescription",
"(",
"delegateClass",
")",
")",
";",
"// load delegate",
"// using InvokerHelper to allow potential intercepted calls",
"int",
"size",
";",
"mv",
".",
"visitLdcInsn",
"(",
"name",
")",
";",
"// method name",
"Type",
"[",
"]",
"args",
"=",
"Type",
".",
"getArgumentTypes",
"(",
"desc",
")",
";",
"BytecodeHelper",
".",
"pushConstant",
"(",
"mv",
",",
"args",
".",
"length",
")",
";",
"mv",
".",
"visitTypeInsn",
"(",
"ANEWARRAY",
",",
"\"java/lang/Object\"",
")",
";",
"size",
"=",
"6",
";",
"int",
"idx",
"=",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"Type",
"arg",
"=",
"args",
"[",
"i",
"]",
";",
"mv",
".",
"visitInsn",
"(",
"DUP",
")",
";",
"BytecodeHelper",
".",
"pushConstant",
"(",
"mv",
",",
"i",
")",
";",
"// primitive types must be boxed",
"if",
"(",
"isPrimitive",
"(",
"arg",
")",
")",
"{",
"mv",
".",
"visitIntInsn",
"(",
"getLoadInsn",
"(",
"arg",
")",
",",
"idx",
")",
";",
"String",
"wrappedType",
"=",
"getWrappedClassDescriptor",
"(",
"arg",
")",
";",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKESTATIC",
",",
"wrappedType",
",",
"\"valueOf\"",
",",
"\"(\"",
"+",
"arg",
".",
"getDescriptor",
"(",
")",
"+",
"\")L\"",
"+",
"wrappedType",
"+",
"\";\"",
",",
"false",
")",
";",
"}",
"else",
"{",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"idx",
")",
";",
"// load argument i",
"}",
"size",
"=",
"Math",
".",
"max",
"(",
"size",
",",
"5",
"+",
"registerLen",
"(",
"arg",
")",
")",
";",
"idx",
"+=",
"registerLen",
"(",
"arg",
")",
";",
"mv",
".",
"visitInsn",
"(",
"AASTORE",
")",
";",
"// store value into array",
"}",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKESTATIC",
",",
"\"org/codehaus/groovy/runtime/InvokerHelper\"",
",",
"\"invokeMethod\"",
",",
"\"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;\"",
",",
"false",
")",
";",
"unwrapResult",
"(",
"mv",
",",
"desc",
")",
";",
"mv",
".",
"visitMaxs",
"(",
"size",
",",
"registerLen",
"(",
"args",
")",
"+",
"1",
")",
";",
"return",
"mv",
";",
"}"
] | Generate a call to the delegate object. | [
"Generate",
"a",
"call",
"to",
"the",
"delegate",
"object",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java#L708-L741 |
26 | groovy/groovy-core | src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java | CachedSAMClass.getSAMMethod | public static Method getSAMMethod(Class<?> c) {
// SAM = single public abstract method
// if the class is not abstract there is no abstract method
if (!Modifier.isAbstract(c.getModifiers())) return null;
if (c.isInterface()) {
Method[] methods = c.getMethods();
// res stores the first found abstract method
Method res = null;
for (Method mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (mi.getAnnotation(Traits.Implemented.class)!=null) continue;
try {
Object.class.getMethod(mi.getName(), mi.getParameterTypes());
continue;
} catch (NoSuchMethodException e) {/*ignore*/}
// we have two methods, so no SAM
if (res!=null) return null;
res = mi;
}
return res;
} else {
LinkedList<Method> methods = new LinkedList();
getAbstractMethods(c, methods);
if (methods.isEmpty()) return null;
ListIterator<Method> it = methods.listIterator();
while (it.hasNext()) {
Method m = it.next();
if (hasUsableImplementation(c, m)) it.remove();
}
return getSingleNonDuplicateMethod(methods);
}
} | java | public static Method getSAMMethod(Class<?> c) {
// SAM = single public abstract method
// if the class is not abstract there is no abstract method
if (!Modifier.isAbstract(c.getModifiers())) return null;
if (c.isInterface()) {
Method[] methods = c.getMethods();
// res stores the first found abstract method
Method res = null;
for (Method mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (mi.getAnnotation(Traits.Implemented.class)!=null) continue;
try {
Object.class.getMethod(mi.getName(), mi.getParameterTypes());
continue;
} catch (NoSuchMethodException e) {/*ignore*/}
// we have two methods, so no SAM
if (res!=null) return null;
res = mi;
}
return res;
} else {
LinkedList<Method> methods = new LinkedList();
getAbstractMethods(c, methods);
if (methods.isEmpty()) return null;
ListIterator<Method> it = methods.listIterator();
while (it.hasNext()) {
Method m = it.next();
if (hasUsableImplementation(c, m)) it.remove();
}
return getSingleNonDuplicateMethod(methods);
}
} | [
"public",
"static",
"Method",
"getSAMMethod",
"(",
"Class",
"<",
"?",
">",
"c",
")",
"{",
"// SAM = single public abstract method",
"// if the class is not abstract there is no abstract method",
"if",
"(",
"!",
"Modifier",
".",
"isAbstract",
"(",
"c",
".",
"getModifiers",
"(",
")",
")",
")",
"return",
"null",
";",
"if",
"(",
"c",
".",
"isInterface",
"(",
")",
")",
"{",
"Method",
"[",
"]",
"methods",
"=",
"c",
".",
"getMethods",
"(",
")",
";",
"// res stores the first found abstract method",
"Method",
"res",
"=",
"null",
";",
"for",
"(",
"Method",
"mi",
":",
"methods",
")",
"{",
"// ignore methods, that are not abstract and from Object",
"if",
"(",
"!",
"Modifier",
".",
"isAbstract",
"(",
"mi",
".",
"getModifiers",
"(",
")",
")",
")",
"continue",
";",
"// ignore trait methods which have a default implementation",
"if",
"(",
"mi",
".",
"getAnnotation",
"(",
"Traits",
".",
"Implemented",
".",
"class",
")",
"!=",
"null",
")",
"continue",
";",
"try",
"{",
"Object",
".",
"class",
".",
"getMethod",
"(",
"mi",
".",
"getName",
"(",
")",
",",
"mi",
".",
"getParameterTypes",
"(",
")",
")",
";",
"continue",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e",
")",
"{",
"/*ignore*/",
"}",
"// we have two methods, so no SAM",
"if",
"(",
"res",
"!=",
"null",
")",
"return",
"null",
";",
"res",
"=",
"mi",
";",
"}",
"return",
"res",
";",
"}",
"else",
"{",
"LinkedList",
"<",
"Method",
">",
"methods",
"=",
"new",
"LinkedList",
"(",
")",
";",
"getAbstractMethods",
"(",
"c",
",",
"methods",
")",
";",
"if",
"(",
"methods",
".",
"isEmpty",
"(",
")",
")",
"return",
"null",
";",
"ListIterator",
"<",
"Method",
">",
"it",
"=",
"methods",
".",
"listIterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"Method",
"m",
"=",
"it",
".",
"next",
"(",
")",
";",
"if",
"(",
"hasUsableImplementation",
"(",
"c",
",",
"m",
")",
")",
"it",
".",
"remove",
"(",
")",
";",
"}",
"return",
"getSingleNonDuplicateMethod",
"(",
"methods",
")",
";",
"}",
"}"
] | returns the abstract method from a SAM type, if it is a SAM type.
@param c the SAM class
@return null if nothing was found, the method otherwise | [
"returns",
"the",
"abstract",
"method",
"from",
"a",
"SAM",
"type",
"if",
"it",
"is",
"a",
"SAM",
"type",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java#L159-L195 |
27 | groovy/groovy-core | src/main/org/codehaus/groovy/classgen/asm/MopWriter.java | MopWriter.generateMopCalls | protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) {
for (MethodNode method : mopCalls) {
String name = getMopMethodName(method, useThis);
Parameter[] parameters = method.getParameters();
String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters());
MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null);
controller.setMethodVisitor(mv);
mv.visitVarInsn(ALOAD, 0);
int newRegister = 1;
OperandStack operandStack = controller.getOperandStack();
for (Parameter parameter : parameters) {
ClassNode type = parameter.getType();
operandStack.load(parameter.getType(), newRegister);
// increment to next register, double/long are using two places
newRegister++;
if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++;
}
operandStack.remove(parameters.length);
ClassNode declaringClass = method.getDeclaringClass();
// JDK 8 support for default methods in interfaces
// this should probably be strenghtened when we support the A.super.foo() syntax
int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL;
mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE);
BytecodeHelper.doReturn(mv, method.getReturnType());
mv.visitMaxs(0, 0);
mv.visitEnd();
controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null);
}
} | java | protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) {
for (MethodNode method : mopCalls) {
String name = getMopMethodName(method, useThis);
Parameter[] parameters = method.getParameters();
String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters());
MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null);
controller.setMethodVisitor(mv);
mv.visitVarInsn(ALOAD, 0);
int newRegister = 1;
OperandStack operandStack = controller.getOperandStack();
for (Parameter parameter : parameters) {
ClassNode type = parameter.getType();
operandStack.load(parameter.getType(), newRegister);
// increment to next register, double/long are using two places
newRegister++;
if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++;
}
operandStack.remove(parameters.length);
ClassNode declaringClass = method.getDeclaringClass();
// JDK 8 support for default methods in interfaces
// this should probably be strenghtened when we support the A.super.foo() syntax
int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL;
mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE);
BytecodeHelper.doReturn(mv, method.getReturnType());
mv.visitMaxs(0, 0);
mv.visitEnd();
controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null);
}
} | [
"protected",
"void",
"generateMopCalls",
"(",
"LinkedList",
"<",
"MethodNode",
">",
"mopCalls",
",",
"boolean",
"useThis",
")",
"{",
"for",
"(",
"MethodNode",
"method",
":",
"mopCalls",
")",
"{",
"String",
"name",
"=",
"getMopMethodName",
"(",
"method",
",",
"useThis",
")",
";",
"Parameter",
"[",
"]",
"parameters",
"=",
"method",
".",
"getParameters",
"(",
")",
";",
"String",
"methodDescriptor",
"=",
"BytecodeHelper",
".",
"getMethodDescriptor",
"(",
"method",
".",
"getReturnType",
"(",
")",
",",
"method",
".",
"getParameters",
"(",
")",
")",
";",
"MethodVisitor",
"mv",
"=",
"controller",
".",
"getClassVisitor",
"(",
")",
".",
"visitMethod",
"(",
"ACC_PUBLIC",
"|",
"ACC_SYNTHETIC",
",",
"name",
",",
"methodDescriptor",
",",
"null",
",",
"null",
")",
";",
"controller",
".",
"setMethodVisitor",
"(",
"mv",
")",
";",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"0",
")",
";",
"int",
"newRegister",
"=",
"1",
";",
"OperandStack",
"operandStack",
"=",
"controller",
".",
"getOperandStack",
"(",
")",
";",
"for",
"(",
"Parameter",
"parameter",
":",
"parameters",
")",
"{",
"ClassNode",
"type",
"=",
"parameter",
".",
"getType",
"(",
")",
";",
"operandStack",
".",
"load",
"(",
"parameter",
".",
"getType",
"(",
")",
",",
"newRegister",
")",
";",
"// increment to next register, double/long are using two places",
"newRegister",
"++",
";",
"if",
"(",
"type",
"==",
"ClassHelper",
".",
"double_TYPE",
"||",
"type",
"==",
"ClassHelper",
".",
"long_TYPE",
")",
"newRegister",
"++",
";",
"}",
"operandStack",
".",
"remove",
"(",
"parameters",
".",
"length",
")",
";",
"ClassNode",
"declaringClass",
"=",
"method",
".",
"getDeclaringClass",
"(",
")",
";",
"// JDK 8 support for default methods in interfaces",
"// this should probably be strenghtened when we support the A.super.foo() syntax",
"int",
"opcode",
"=",
"declaringClass",
".",
"isInterface",
"(",
")",
"?",
"INVOKEINTERFACE",
":",
"INVOKESPECIAL",
";",
"mv",
".",
"visitMethodInsn",
"(",
"opcode",
",",
"BytecodeHelper",
".",
"getClassInternalName",
"(",
"declaringClass",
")",
",",
"method",
".",
"getName",
"(",
")",
",",
"methodDescriptor",
",",
"opcode",
"==",
"INVOKEINTERFACE",
")",
";",
"BytecodeHelper",
".",
"doReturn",
"(",
"mv",
",",
"method",
".",
"getReturnType",
"(",
")",
")",
";",
"mv",
".",
"visitMaxs",
"(",
"0",
",",
"0",
")",
";",
"mv",
".",
"visitEnd",
"(",
")",
";",
"controller",
".",
"getClassNode",
"(",
")",
".",
"addMethod",
"(",
"name",
",",
"ACC_PUBLIC",
"|",
"ACC_SYNTHETIC",
",",
"method",
".",
"getReturnType",
"(",
")",
",",
"parameters",
",",
"null",
",",
"null",
")",
";",
"}",
"}"
] | generates a Meta Object Protocol method, that is used to call a non public
method, or to make a call to super.
@param mopCalls list of methods a mop call method should be generated for
@param useThis true if "this" should be used for the naming | [
"generates",
"a",
"Meta",
"Object",
"Protocol",
"method",
"that",
"is",
"used",
"to",
"call",
"a",
"non",
"public",
"method",
"or",
"to",
"make",
"a",
"call",
"to",
"super",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java#L174-L202 |
28 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ClassHelper.java | ClassHelper.getWrapper | public static ClassNode getWrapper(ClassNode cn) {
cn = cn.redirect();
if (!isPrimitiveType(cn)) return cn;
if (cn==boolean_TYPE) {
return Boolean_TYPE;
} else if (cn==byte_TYPE) {
return Byte_TYPE;
} else if (cn==char_TYPE) {
return Character_TYPE;
} else if (cn==short_TYPE) {
return Short_TYPE;
} else if (cn==int_TYPE) {
return Integer_TYPE;
} else if (cn==long_TYPE) {
return Long_TYPE;
} else if (cn==float_TYPE) {
return Float_TYPE;
} else if (cn==double_TYPE) {
return Double_TYPE;
} else if (cn==VOID_TYPE) {
return void_WRAPPER_TYPE;
}
else {
return cn;
}
} | java | public static ClassNode getWrapper(ClassNode cn) {
cn = cn.redirect();
if (!isPrimitiveType(cn)) return cn;
if (cn==boolean_TYPE) {
return Boolean_TYPE;
} else if (cn==byte_TYPE) {
return Byte_TYPE;
} else if (cn==char_TYPE) {
return Character_TYPE;
} else if (cn==short_TYPE) {
return Short_TYPE;
} else if (cn==int_TYPE) {
return Integer_TYPE;
} else if (cn==long_TYPE) {
return Long_TYPE;
} else if (cn==float_TYPE) {
return Float_TYPE;
} else if (cn==double_TYPE) {
return Double_TYPE;
} else if (cn==VOID_TYPE) {
return void_WRAPPER_TYPE;
}
else {
return cn;
}
} | [
"public",
"static",
"ClassNode",
"getWrapper",
"(",
"ClassNode",
"cn",
")",
"{",
"cn",
"=",
"cn",
".",
"redirect",
"(",
")",
";",
"if",
"(",
"!",
"isPrimitiveType",
"(",
"cn",
")",
")",
"return",
"cn",
";",
"if",
"(",
"cn",
"==",
"boolean_TYPE",
")",
"{",
"return",
"Boolean_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"byte_TYPE",
")",
"{",
"return",
"Byte_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"char_TYPE",
")",
"{",
"return",
"Character_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"short_TYPE",
")",
"{",
"return",
"Short_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"int_TYPE",
")",
"{",
"return",
"Integer_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"long_TYPE",
")",
"{",
"return",
"Long_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"float_TYPE",
")",
"{",
"return",
"Float_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"double_TYPE",
")",
"{",
"return",
"Double_TYPE",
";",
"}",
"else",
"if",
"(",
"cn",
"==",
"VOID_TYPE",
")",
"{",
"return",
"void_WRAPPER_TYPE",
";",
"}",
"else",
"{",
"return",
"cn",
";",
"}",
"}"
] | Creates a ClassNode containing the wrapper of a ClassNode
of primitive type. Any ClassNode representing a primitive
type should be created using the predefined types used in
class. The method will check the parameter for known
references of ClassNode representing a primitive type. If
Reference is found, then a ClassNode will be contained that
represents the wrapper class. For example for boolean, the
wrapper class is java.lang.Boolean.
If the parameter is no primitive type, the redirected
ClassNode will be returned
@see #make(Class)
@see #make(String)
@param cn the ClassNode containing a possible primitive type | [
"Creates",
"a",
"ClassNode",
"containing",
"the",
"wrapper",
"of",
"a",
"ClassNode",
"of",
"primitive",
"type",
".",
"Any",
"ClassNode",
"representing",
"a",
"primitive",
"type",
"should",
"be",
"created",
"using",
"the",
"predefined",
"types",
"used",
"in",
"class",
".",
"The",
"method",
"will",
"check",
"the",
"parameter",
"for",
"known",
"references",
"of",
"ClassNode",
"representing",
"a",
"primitive",
"type",
".",
"If",
"Reference",
"is",
"found",
"then",
"a",
"ClassNode",
"will",
"be",
"contained",
"that",
"represents",
"the",
"wrapper",
"class",
".",
"For",
"example",
"for",
"boolean",
"the",
"wrapper",
"class",
"is",
"java",
".",
"lang",
".",
"Boolean",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ClassHelper.java#L257-L282 |
29 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/ClassHelper.java | ClassHelper.findSAM | public static MethodNode findSAM(ClassNode type) {
if (!Modifier.isAbstract(type.getModifiers())) return null;
if (type.isInterface()) {
List<MethodNode> methods = type.getMethods();
MethodNode found=null;
for (MethodNode mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (Traits.hasDefaultImplementation(mi)) continue;
if (mi.getDeclaringClass().equals(OBJECT_TYPE)) continue;
if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters())!=null) continue;
// we have two methods, so no SAM
if (found!=null) return null;
found = mi;
}
return found;
} else {
List<MethodNode> methods = type.getAbstractMethods();
MethodNode found = null;
if (methods!=null) {
for (MethodNode mi : methods) {
if (!hasUsableImplementation(type, mi)) {
if (found!=null) return null;
found = mi;
}
}
}
return found;
}
} | java | public static MethodNode findSAM(ClassNode type) {
if (!Modifier.isAbstract(type.getModifiers())) return null;
if (type.isInterface()) {
List<MethodNode> methods = type.getMethods();
MethodNode found=null;
for (MethodNode mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (Traits.hasDefaultImplementation(mi)) continue;
if (mi.getDeclaringClass().equals(OBJECT_TYPE)) continue;
if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters())!=null) continue;
// we have two methods, so no SAM
if (found!=null) return null;
found = mi;
}
return found;
} else {
List<MethodNode> methods = type.getAbstractMethods();
MethodNode found = null;
if (methods!=null) {
for (MethodNode mi : methods) {
if (!hasUsableImplementation(type, mi)) {
if (found!=null) return null;
found = mi;
}
}
}
return found;
}
} | [
"public",
"static",
"MethodNode",
"findSAM",
"(",
"ClassNode",
"type",
")",
"{",
"if",
"(",
"!",
"Modifier",
".",
"isAbstract",
"(",
"type",
".",
"getModifiers",
"(",
")",
")",
")",
"return",
"null",
";",
"if",
"(",
"type",
".",
"isInterface",
"(",
")",
")",
"{",
"List",
"<",
"MethodNode",
">",
"methods",
"=",
"type",
".",
"getMethods",
"(",
")",
";",
"MethodNode",
"found",
"=",
"null",
";",
"for",
"(",
"MethodNode",
"mi",
":",
"methods",
")",
"{",
"// ignore methods, that are not abstract and from Object",
"if",
"(",
"!",
"Modifier",
".",
"isAbstract",
"(",
"mi",
".",
"getModifiers",
"(",
")",
")",
")",
"continue",
";",
"// ignore trait methods which have a default implementation",
"if",
"(",
"Traits",
".",
"hasDefaultImplementation",
"(",
"mi",
")",
")",
"continue",
";",
"if",
"(",
"mi",
".",
"getDeclaringClass",
"(",
")",
".",
"equals",
"(",
"OBJECT_TYPE",
")",
")",
"continue",
";",
"if",
"(",
"OBJECT_TYPE",
".",
"getDeclaredMethod",
"(",
"mi",
".",
"getName",
"(",
")",
",",
"mi",
".",
"getParameters",
"(",
")",
")",
"!=",
"null",
")",
"continue",
";",
"// we have two methods, so no SAM",
"if",
"(",
"found",
"!=",
"null",
")",
"return",
"null",
";",
"found",
"=",
"mi",
";",
"}",
"return",
"found",
";",
"}",
"else",
"{",
"List",
"<",
"MethodNode",
">",
"methods",
"=",
"type",
".",
"getAbstractMethods",
"(",
")",
";",
"MethodNode",
"found",
"=",
"null",
";",
"if",
"(",
"methods",
"!=",
"null",
")",
"{",
"for",
"(",
"MethodNode",
"mi",
":",
"methods",
")",
"{",
"if",
"(",
"!",
"hasUsableImplementation",
"(",
"type",
",",
"mi",
")",
")",
"{",
"if",
"(",
"found",
"!=",
"null",
")",
"return",
"null",
";",
"found",
"=",
"mi",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}",
"}"
] | Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.
@param type a type for which to search for a single abstract method
@return the method node if type is a SAM type, null otherwise | [
"Returns",
"the",
"single",
"abstract",
"method",
"of",
"a",
"class",
"node",
"if",
"it",
"is",
"a",
"SAM",
"type",
"or",
"null",
"otherwise",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ClassHelper.java#L395-L428 |
30 | groovy/groovy-core | src/main/org/codehaus/groovy/syntax/Types.java | Types.getPrecedence | public static int getPrecedence( int type, boolean throwIfInvalid ) {
switch( type ) {
case LEFT_PARENTHESIS:
return 0;
case EQUAL:
case PLUS_EQUAL:
case MINUS_EQUAL:
case MULTIPLY_EQUAL:
case DIVIDE_EQUAL:
case INTDIV_EQUAL:
case MOD_EQUAL:
case POWER_EQUAL:
case LOGICAL_OR_EQUAL:
case LOGICAL_AND_EQUAL:
case LEFT_SHIFT_EQUAL:
case RIGHT_SHIFT_EQUAL:
case RIGHT_SHIFT_UNSIGNED_EQUAL:
case BITWISE_OR_EQUAL:
case BITWISE_AND_EQUAL:
case BITWISE_XOR_EQUAL:
return 5;
case QUESTION:
return 10;
case LOGICAL_OR:
return 15;
case LOGICAL_AND:
return 20;
case BITWISE_OR:
case BITWISE_AND:
case BITWISE_XOR:
return 22;
case COMPARE_IDENTICAL:
case COMPARE_NOT_IDENTICAL:
return 24;
case COMPARE_NOT_EQUAL:
case COMPARE_EQUAL:
case COMPARE_LESS_THAN:
case COMPARE_LESS_THAN_EQUAL:
case COMPARE_GREATER_THAN:
case COMPARE_GREATER_THAN_EQUAL:
case COMPARE_TO:
case FIND_REGEX:
case MATCH_REGEX:
case KEYWORD_INSTANCEOF:
return 25;
case DOT_DOT:
case DOT_DOT_DOT:
return 30;
case LEFT_SHIFT:
case RIGHT_SHIFT:
case RIGHT_SHIFT_UNSIGNED:
return 35;
case PLUS:
case MINUS:
return 40;
case MULTIPLY:
case DIVIDE:
case INTDIV:
case MOD:
return 45;
case NOT:
case REGEX_PATTERN:
return 50;
case SYNTH_CAST:
return 55;
case PLUS_PLUS:
case MINUS_MINUS:
case PREFIX_PLUS_PLUS:
case PREFIX_MINUS_MINUS:
case POSTFIX_PLUS_PLUS:
case POSTFIX_MINUS_MINUS:
return 65;
case PREFIX_PLUS:
case PREFIX_MINUS:
return 70;
case POWER:
return 72;
case SYNTH_METHOD:
case LEFT_SQUARE_BRACKET:
return 75;
case DOT:
case NAVIGATE:
return 80;
case KEYWORD_NEW:
return 85;
}
if( throwIfInvalid ) {
throw new GroovyBugError( "precedence requested for non-operator" );
}
return -1;
} | java | public static int getPrecedence( int type, boolean throwIfInvalid ) {
switch( type ) {
case LEFT_PARENTHESIS:
return 0;
case EQUAL:
case PLUS_EQUAL:
case MINUS_EQUAL:
case MULTIPLY_EQUAL:
case DIVIDE_EQUAL:
case INTDIV_EQUAL:
case MOD_EQUAL:
case POWER_EQUAL:
case LOGICAL_OR_EQUAL:
case LOGICAL_AND_EQUAL:
case LEFT_SHIFT_EQUAL:
case RIGHT_SHIFT_EQUAL:
case RIGHT_SHIFT_UNSIGNED_EQUAL:
case BITWISE_OR_EQUAL:
case BITWISE_AND_EQUAL:
case BITWISE_XOR_EQUAL:
return 5;
case QUESTION:
return 10;
case LOGICAL_OR:
return 15;
case LOGICAL_AND:
return 20;
case BITWISE_OR:
case BITWISE_AND:
case BITWISE_XOR:
return 22;
case COMPARE_IDENTICAL:
case COMPARE_NOT_IDENTICAL:
return 24;
case COMPARE_NOT_EQUAL:
case COMPARE_EQUAL:
case COMPARE_LESS_THAN:
case COMPARE_LESS_THAN_EQUAL:
case COMPARE_GREATER_THAN:
case COMPARE_GREATER_THAN_EQUAL:
case COMPARE_TO:
case FIND_REGEX:
case MATCH_REGEX:
case KEYWORD_INSTANCEOF:
return 25;
case DOT_DOT:
case DOT_DOT_DOT:
return 30;
case LEFT_SHIFT:
case RIGHT_SHIFT:
case RIGHT_SHIFT_UNSIGNED:
return 35;
case PLUS:
case MINUS:
return 40;
case MULTIPLY:
case DIVIDE:
case INTDIV:
case MOD:
return 45;
case NOT:
case REGEX_PATTERN:
return 50;
case SYNTH_CAST:
return 55;
case PLUS_PLUS:
case MINUS_MINUS:
case PREFIX_PLUS_PLUS:
case PREFIX_MINUS_MINUS:
case POSTFIX_PLUS_PLUS:
case POSTFIX_MINUS_MINUS:
return 65;
case PREFIX_PLUS:
case PREFIX_MINUS:
return 70;
case POWER:
return 72;
case SYNTH_METHOD:
case LEFT_SQUARE_BRACKET:
return 75;
case DOT:
case NAVIGATE:
return 80;
case KEYWORD_NEW:
return 85;
}
if( throwIfInvalid ) {
throw new GroovyBugError( "precedence requested for non-operator" );
}
return -1;
} | [
"public",
"static",
"int",
"getPrecedence",
"(",
"int",
"type",
",",
"boolean",
"throwIfInvalid",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"LEFT_PARENTHESIS",
":",
"return",
"0",
";",
"case",
"EQUAL",
":",
"case",
"PLUS_EQUAL",
":",
"case",
"MINUS_EQUAL",
":",
"case",
"MULTIPLY_EQUAL",
":",
"case",
"DIVIDE_EQUAL",
":",
"case",
"INTDIV_EQUAL",
":",
"case",
"MOD_EQUAL",
":",
"case",
"POWER_EQUAL",
":",
"case",
"LOGICAL_OR_EQUAL",
":",
"case",
"LOGICAL_AND_EQUAL",
":",
"case",
"LEFT_SHIFT_EQUAL",
":",
"case",
"RIGHT_SHIFT_EQUAL",
":",
"case",
"RIGHT_SHIFT_UNSIGNED_EQUAL",
":",
"case",
"BITWISE_OR_EQUAL",
":",
"case",
"BITWISE_AND_EQUAL",
":",
"case",
"BITWISE_XOR_EQUAL",
":",
"return",
"5",
";",
"case",
"QUESTION",
":",
"return",
"10",
";",
"case",
"LOGICAL_OR",
":",
"return",
"15",
";",
"case",
"LOGICAL_AND",
":",
"return",
"20",
";",
"case",
"BITWISE_OR",
":",
"case",
"BITWISE_AND",
":",
"case",
"BITWISE_XOR",
":",
"return",
"22",
";",
"case",
"COMPARE_IDENTICAL",
":",
"case",
"COMPARE_NOT_IDENTICAL",
":",
"return",
"24",
";",
"case",
"COMPARE_NOT_EQUAL",
":",
"case",
"COMPARE_EQUAL",
":",
"case",
"COMPARE_LESS_THAN",
":",
"case",
"COMPARE_LESS_THAN_EQUAL",
":",
"case",
"COMPARE_GREATER_THAN",
":",
"case",
"COMPARE_GREATER_THAN_EQUAL",
":",
"case",
"COMPARE_TO",
":",
"case",
"FIND_REGEX",
":",
"case",
"MATCH_REGEX",
":",
"case",
"KEYWORD_INSTANCEOF",
":",
"return",
"25",
";",
"case",
"DOT_DOT",
":",
"case",
"DOT_DOT_DOT",
":",
"return",
"30",
";",
"case",
"LEFT_SHIFT",
":",
"case",
"RIGHT_SHIFT",
":",
"case",
"RIGHT_SHIFT_UNSIGNED",
":",
"return",
"35",
";",
"case",
"PLUS",
":",
"case",
"MINUS",
":",
"return",
"40",
";",
"case",
"MULTIPLY",
":",
"case",
"DIVIDE",
":",
"case",
"INTDIV",
":",
"case",
"MOD",
":",
"return",
"45",
";",
"case",
"NOT",
":",
"case",
"REGEX_PATTERN",
":",
"return",
"50",
";",
"case",
"SYNTH_CAST",
":",
"return",
"55",
";",
"case",
"PLUS_PLUS",
":",
"case",
"MINUS_MINUS",
":",
"case",
"PREFIX_PLUS_PLUS",
":",
"case",
"PREFIX_MINUS_MINUS",
":",
"case",
"POSTFIX_PLUS_PLUS",
":",
"case",
"POSTFIX_MINUS_MINUS",
":",
"return",
"65",
";",
"case",
"PREFIX_PLUS",
":",
"case",
"PREFIX_MINUS",
":",
"return",
"70",
";",
"case",
"POWER",
":",
"return",
"72",
";",
"case",
"SYNTH_METHOD",
":",
"case",
"LEFT_SQUARE_BRACKET",
":",
"return",
"75",
";",
"case",
"DOT",
":",
"case",
"NAVIGATE",
":",
"return",
"80",
";",
"case",
"KEYWORD_NEW",
":",
"return",
"85",
";",
"}",
"if",
"(",
"throwIfInvalid",
")",
"{",
"throw",
"new",
"GroovyBugError",
"(",
"\"precedence requested for non-operator\"",
")",
";",
"}",
"return",
"-",
"1",
";",
"}"
] | Returns the precedence of the specified operator. Non-operator's will
receive -1 or a GroovyBugError, depending on your preference. | [
"Returns",
"the",
"precedence",
"of",
"the",
"specified",
"operator",
".",
"Non",
"-",
"operator",
"s",
"will",
"receive",
"-",
"1",
"or",
"a",
"GroovyBugError",
"depending",
"on",
"your",
"preference",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Types.java#L976-L1089 |
31 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/NullObject.java | NullObject.with | public <T> T with( Closure<T> closure ) {
return DefaultGroovyMethods.with( null, closure ) ;
} | java | public <T> T with( Closure<T> closure ) {
return DefaultGroovyMethods.with( null, closure ) ;
} | [
"public",
"<",
"T",
">",
"T",
"with",
"(",
"Closure",
"<",
"T",
">",
"closure",
")",
"{",
"return",
"DefaultGroovyMethods",
".",
"with",
"(",
"null",
",",
"closure",
")",
";",
"}"
] | Allows the closure to be called for NullObject
@param closure the closure to call on the object
@return result of calling the closure | [
"Allows",
"the",
"closure",
"to",
"be",
"called",
"for",
"NullObject"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/NullObject.java#L69-L71 |
32 | groovy/groovy-core | src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java | DefaultGrailsDomainClassInjector.implementsMethod | private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
List methods = classNode.getMethods();
if (argTypes == null || argTypes.length ==0) {
for (Iterator i = methods.iterator(); i.hasNext();) {
MethodNode mn = (MethodNode) i.next();
boolean methodMatch = mn.getName().equals(methodName);
if(methodMatch)return true;
// TODO Implement further parameter analysis
}
}
return false;
} | java | private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
List methods = classNode.getMethods();
if (argTypes == null || argTypes.length ==0) {
for (Iterator i = methods.iterator(); i.hasNext();) {
MethodNode mn = (MethodNode) i.next();
boolean methodMatch = mn.getName().equals(methodName);
if(methodMatch)return true;
// TODO Implement further parameter analysis
}
}
return false;
} | [
"private",
"static",
"boolean",
"implementsMethod",
"(",
"ClassNode",
"classNode",
",",
"String",
"methodName",
",",
"Class",
"[",
"]",
"argTypes",
")",
"{",
"List",
"methods",
"=",
"classNode",
".",
"getMethods",
"(",
")",
";",
"if",
"(",
"argTypes",
"==",
"null",
"||",
"argTypes",
".",
"length",
"==",
"0",
")",
"{",
"for",
"(",
"Iterator",
"i",
"=",
"methods",
".",
"iterator",
"(",
")",
";",
"i",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"MethodNode",
"mn",
"=",
"(",
"MethodNode",
")",
"i",
".",
"next",
"(",
")",
";",
"boolean",
"methodMatch",
"=",
"mn",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"methodName",
")",
";",
"if",
"(",
"methodMatch",
")",
"return",
"true",
";",
"// TODO Implement further parameter analysis\r",
"}",
"}",
"return",
"false",
";",
"}"
] | Tests whether the ClassNode implements the specified method name
@param classNode The ClassNode
@param methodName The method name
@param argTypes
@return True if it implements the method | [
"Tests",
"whether",
"the",
"ClassNode",
"implements",
"the",
"specified",
"method",
"name"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java#L243-L254 |
33 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/MethodNode.java | MethodNode.getTypeDescriptor | public String getTypeDescriptor() {
if (typeDescriptor == null) {
StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10);
buf.append(returnType.getName());
buf.append(' ');
buf.append(name);
buf.append('(');
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
buf.append(", ");
}
Parameter param = parameters[i];
buf.append(formatTypeName(param.getType()));
}
buf.append(')');
typeDescriptor = buf.toString();
}
return typeDescriptor;
} | java | public String getTypeDescriptor() {
if (typeDescriptor == null) {
StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10);
buf.append(returnType.getName());
buf.append(' ');
buf.append(name);
buf.append('(');
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
buf.append(", ");
}
Parameter param = parameters[i];
buf.append(formatTypeName(param.getType()));
}
buf.append(')');
typeDescriptor = buf.toString();
}
return typeDescriptor;
} | [
"public",
"String",
"getTypeDescriptor",
"(",
")",
"{",
"if",
"(",
"typeDescriptor",
"==",
"null",
")",
"{",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
"name",
".",
"length",
"(",
")",
"+",
"parameters",
".",
"length",
"*",
"10",
")",
";",
"buf",
".",
"append",
"(",
"returnType",
".",
"getName",
"(",
")",
")",
";",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"buf",
".",
"append",
"(",
"name",
")",
";",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parameters",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"buf",
".",
"append",
"(",
"\", \"",
")",
";",
"}",
"Parameter",
"param",
"=",
"parameters",
"[",
"i",
"]",
";",
"buf",
".",
"append",
"(",
"formatTypeName",
"(",
"param",
".",
"getType",
"(",
")",
")",
")",
";",
"}",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"typeDescriptor",
"=",
"buf",
".",
"toString",
"(",
")",
";",
"}",
"return",
"typeDescriptor",
";",
"}"
] | The type descriptor for a method node is a string containing the name of the method, its return type,
and its parameter types in a canonical form. For simplicity, I'm using the format of a Java declaration
without parameter names.
@return the type descriptor | [
"The",
"type",
"descriptor",
"for",
"a",
"method",
"node",
"is",
"a",
"string",
"containing",
"the",
"name",
"of",
"the",
"method",
"its",
"return",
"type",
"and",
"its",
"parameter",
"types",
"in",
"a",
"canonical",
"form",
".",
"For",
"simplicity",
"I",
"m",
"using",
"the",
"format",
"of",
"a",
"Java",
"declaration",
"without",
"parameter",
"names",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/MethodNode.java#L76-L94 |
34 | groovy/groovy-core | src/main/org/codehaus/groovy/ast/MethodNode.java | MethodNode.getText | @Override
public String getText() {
String retType = AstToTextHelper.getClassText(returnType);
String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions);
String parms = AstToTextHelper.getParametersText(parameters);
return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name + "(" + parms + ") " + exceptionTypes + " { ... }";
} | java | @Override
public String getText() {
String retType = AstToTextHelper.getClassText(returnType);
String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions);
String parms = AstToTextHelper.getParametersText(parameters);
return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name + "(" + parms + ") " + exceptionTypes + " { ... }";
} | [
"@",
"Override",
"public",
"String",
"getText",
"(",
")",
"{",
"String",
"retType",
"=",
"AstToTextHelper",
".",
"getClassText",
"(",
"returnType",
")",
";",
"String",
"exceptionTypes",
"=",
"AstToTextHelper",
".",
"getThrowsClauseText",
"(",
"exceptions",
")",
";",
"String",
"parms",
"=",
"AstToTextHelper",
".",
"getParametersText",
"(",
"parameters",
")",
";",
"return",
"AstToTextHelper",
".",
"getModifiersText",
"(",
"modifiers",
")",
"+",
"\" \"",
"+",
"retType",
"+",
"\" \"",
"+",
"name",
"+",
"\"(\"",
"+",
"parms",
"+",
"\") \"",
"+",
"exceptionTypes",
"+",
"\" { ... }\"",
";",
"}"
] | Provides a nicely formatted string of the method definition. For simplicity, generic types on some of the elements
are not displayed.
@return
string form of node with some generic elements suppressed | [
"Provides",
"a",
"nicely",
"formatted",
"string",
"of",
"the",
"method",
"definition",
".",
"For",
"simplicity",
"generic",
"types",
"on",
"some",
"of",
"the",
"elements",
"are",
"not",
"displayed",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/MethodNode.java#L300-L306 |
35 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.constructors | public GroovyConstructorDoc[] constructors() {
Collections.sort(constructors);
return constructors.toArray(new GroovyConstructorDoc[constructors.size()]);
} | java | public GroovyConstructorDoc[] constructors() {
Collections.sort(constructors);
return constructors.toArray(new GroovyConstructorDoc[constructors.size()]);
} | [
"public",
"GroovyConstructorDoc",
"[",
"]",
"constructors",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"constructors",
")",
";",
"return",
"constructors",
".",
"toArray",
"(",
"new",
"GroovyConstructorDoc",
"[",
"constructors",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of constructors | [
"returns",
"a",
"sorted",
"array",
"of",
"constructors"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L100-L103 |
36 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.innerClasses | public GroovyClassDoc[] innerClasses() {
Collections.sort(nested);
return nested.toArray(new GroovyClassDoc[nested.size()]);
} | java | public GroovyClassDoc[] innerClasses() {
Collections.sort(nested);
return nested.toArray(new GroovyClassDoc[nested.size()]);
} | [
"public",
"GroovyClassDoc",
"[",
"]",
"innerClasses",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"nested",
")",
";",
"return",
"nested",
".",
"toArray",
"(",
"new",
"GroovyClassDoc",
"[",
"nested",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of nested classes and interfaces | [
"returns",
"a",
"sorted",
"array",
"of",
"nested",
"classes",
"and",
"interfaces"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L129-L132 |
37 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.fields | public GroovyFieldDoc[] fields() {
Collections.sort(fields);
return fields.toArray(new GroovyFieldDoc[fields.size()]);
} | java | public GroovyFieldDoc[] fields() {
Collections.sort(fields);
return fields.toArray(new GroovyFieldDoc[fields.size()]);
} | [
"public",
"GroovyFieldDoc",
"[",
"]",
"fields",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"fields",
")",
";",
"return",
"fields",
".",
"toArray",
"(",
"new",
"GroovyFieldDoc",
"[",
"fields",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of fields | [
"returns",
"a",
"sorted",
"array",
"of",
"fields"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L141-L144 |
38 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.properties | public GroovyFieldDoc[] properties() {
Collections.sort(properties);
return properties.toArray(new GroovyFieldDoc[properties.size()]);
} | java | public GroovyFieldDoc[] properties() {
Collections.sort(properties);
return properties.toArray(new GroovyFieldDoc[properties.size()]);
} | [
"public",
"GroovyFieldDoc",
"[",
"]",
"properties",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"properties",
")",
";",
"return",
"properties",
".",
"toArray",
"(",
"new",
"GroovyFieldDoc",
"[",
"properties",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of properties | [
"returns",
"a",
"sorted",
"array",
"of",
"properties"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L153-L156 |
39 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.enumConstants | public GroovyFieldDoc[] enumConstants() {
Collections.sort(enumConstants);
return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]);
} | java | public GroovyFieldDoc[] enumConstants() {
Collections.sort(enumConstants);
return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]);
} | [
"public",
"GroovyFieldDoc",
"[",
"]",
"enumConstants",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"enumConstants",
")",
";",
"return",
"enumConstants",
".",
"toArray",
"(",
"new",
"GroovyFieldDoc",
"[",
"enumConstants",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of enum constants | [
"returns",
"a",
"sorted",
"array",
"of",
"enum",
"constants"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L165-L168 |
40 | groovy/groovy-core | subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java | SimpleGroovyClassDoc.methods | public GroovyMethodDoc[] methods() {
Collections.sort(methods);
return methods.toArray(new GroovyMethodDoc[methods.size()]);
} | java | public GroovyMethodDoc[] methods() {
Collections.sort(methods);
return methods.toArray(new GroovyMethodDoc[methods.size()]);
} | [
"public",
"GroovyMethodDoc",
"[",
"]",
"methods",
"(",
")",
"{",
"Collections",
".",
"sort",
"(",
"methods",
")",
";",
"return",
"methods",
".",
"toArray",
"(",
"new",
"GroovyMethodDoc",
"[",
"methods",
".",
"size",
"(",
")",
"]",
")",
";",
"}"
] | returns a sorted array of methods | [
"returns",
"a",
"sorted",
"array",
"of",
"methods"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L177-L180 |
41 | groovy/groovy-core | subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java | DataSet.add | public void add(Map<String, Object> map) throws SQLException {
if (withinDataSetBatch) {
if (batchData.size() == 0) {
batchKeys = map.keySet();
} else {
if (!map.keySet().equals(batchKeys)) {
throw new IllegalArgumentException("Inconsistent keys found for batch add!");
}
}
batchData.add(map);
return;
}
int answer = executeUpdate(buildListQuery(map), new ArrayList<Object>(map.values()));
if (answer != 1) {
LOG.warning("Should have updated 1 row not " + answer + " when trying to add: " + map);
}
} | java | public void add(Map<String, Object> map) throws SQLException {
if (withinDataSetBatch) {
if (batchData.size() == 0) {
batchKeys = map.keySet();
} else {
if (!map.keySet().equals(batchKeys)) {
throw new IllegalArgumentException("Inconsistent keys found for batch add!");
}
}
batchData.add(map);
return;
}
int answer = executeUpdate(buildListQuery(map), new ArrayList<Object>(map.values()));
if (answer != 1) {
LOG.warning("Should have updated 1 row not " + answer + " when trying to add: " + map);
}
} | [
"public",
"void",
"add",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"map",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"withinDataSetBatch",
")",
"{",
"if",
"(",
"batchData",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"batchKeys",
"=",
"map",
".",
"keySet",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"map",
".",
"keySet",
"(",
")",
".",
"equals",
"(",
"batchKeys",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Inconsistent keys found for batch add!\"",
")",
";",
"}",
"}",
"batchData",
".",
"add",
"(",
"map",
")",
";",
"return",
";",
"}",
"int",
"answer",
"=",
"executeUpdate",
"(",
"buildListQuery",
"(",
"map",
")",
",",
"new",
"ArrayList",
"<",
"Object",
">",
"(",
"map",
".",
"values",
"(",
")",
")",
")",
";",
"if",
"(",
"answer",
"!=",
"1",
")",
"{",
"LOG",
".",
"warning",
"(",
"\"Should have updated 1 row not \"",
"+",
"answer",
"+",
"\" when trying to add: \"",
"+",
"map",
")",
";",
"}",
"}"
] | Adds the provided map of key-value pairs as a new row in the table represented by this DataSet.
@param map the key (column-name), value pairs to add as a new row
@throws SQLException if a database error occurs | [
"Adds",
"the",
"provided",
"map",
"of",
"key",
"-",
"value",
"pairs",
"as",
"a",
"new",
"row",
"in",
"the",
"table",
"represented",
"by",
"this",
"DataSet",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L233-L249 |
42 | groovy/groovy-core | subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java | DataSet.each | public void each(int offset, int maxRows, Closure closure) throws SQLException {
eachRow(getSql(), getParameters(), offset, maxRows, closure);
} | java | public void each(int offset, int maxRows, Closure closure) throws SQLException {
eachRow(getSql(), getParameters(), offset, maxRows, closure);
} | [
"public",
"void",
"each",
"(",
"int",
"offset",
",",
"int",
"maxRows",
",",
"Closure",
"closure",
")",
"throws",
"SQLException",
"{",
"eachRow",
"(",
"getSql",
"(",
")",
",",
"getParameters",
"(",
")",
",",
"offset",
",",
"maxRows",
",",
"closure",
")",
";",
"}"
] | Calls the provided closure for a "page" of rows from the table represented by this DataSet.
A page is defined as starting at a 1-based offset, and containing a maximum number of rows.
@param offset the 1-based offset for the first row to be processed
@param maxRows the maximum number of rows to be processed
@param closure called for each row with a GroovyResultSet
@throws SQLException if a database access error occurs
@see groovy.sql.Sql#eachRow(String, java.util.List, int, int, groovy.lang.Closure) | [
"Calls",
"the",
"provided",
"closure",
"for",
"a",
"page",
"of",
"rows",
"from",
"the",
"table",
"represented",
"by",
"this",
"DataSet",
".",
"A",
"page",
"is",
"defined",
"as",
"starting",
"at",
"a",
"1",
"-",
"based",
"offset",
"and",
"containing",
"a",
"maximum",
"number",
"of",
"rows",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L349-L351 |
43 | groovy/groovy-core | src/main/groovy/beans/VetoableASTTransformation.java | VetoableASTTransformation.wrapSetterMethod | private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) {
String getterName = "get" + MetaClassHelper.capitalize(propertyName);
MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName));
if (setter != null) {
// Get the existing code block
Statement code = setter.getCode();
Expression oldValue = varX("$oldValue");
Expression newValue = varX("$newValue");
Expression proposedValue = varX(setter.getParameters()[0].getName());
BlockStatement block = new BlockStatement();
// create a local variable to hold the old value from the getter
block.addStatement(declS(oldValue, callThisX(getterName)));
// add the fireVetoableChange method call
block.addStatement(stmt(callThisX("fireVetoableChange", args(
constX(propertyName), oldValue, proposedValue))));
// call the existing block, which will presumably set the value properly
block.addStatement(code);
if (bindable) {
// get the new value to emit in the event
block.addStatement(declS(newValue, callThisX(getterName)));
// add the firePropertyChange method call
block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue))));
}
// replace the existing code block with our new one
setter.setCode(block);
}
} | java | private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) {
String getterName = "get" + MetaClassHelper.capitalize(propertyName);
MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName));
if (setter != null) {
// Get the existing code block
Statement code = setter.getCode();
Expression oldValue = varX("$oldValue");
Expression newValue = varX("$newValue");
Expression proposedValue = varX(setter.getParameters()[0].getName());
BlockStatement block = new BlockStatement();
// create a local variable to hold the old value from the getter
block.addStatement(declS(oldValue, callThisX(getterName)));
// add the fireVetoableChange method call
block.addStatement(stmt(callThisX("fireVetoableChange", args(
constX(propertyName), oldValue, proposedValue))));
// call the existing block, which will presumably set the value properly
block.addStatement(code);
if (bindable) {
// get the new value to emit in the event
block.addStatement(declS(newValue, callThisX(getterName)));
// add the firePropertyChange method call
block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue))));
}
// replace the existing code block with our new one
setter.setCode(block);
}
} | [
"private",
"void",
"wrapSetterMethod",
"(",
"ClassNode",
"classNode",
",",
"boolean",
"bindable",
",",
"String",
"propertyName",
")",
"{",
"String",
"getterName",
"=",
"\"get\"",
"+",
"MetaClassHelper",
".",
"capitalize",
"(",
"propertyName",
")",
";",
"MethodNode",
"setter",
"=",
"classNode",
".",
"getSetterMethod",
"(",
"\"set\"",
"+",
"MetaClassHelper",
".",
"capitalize",
"(",
"propertyName",
")",
")",
";",
"if",
"(",
"setter",
"!=",
"null",
")",
"{",
"// Get the existing code block\r",
"Statement",
"code",
"=",
"setter",
".",
"getCode",
"(",
")",
";",
"Expression",
"oldValue",
"=",
"varX",
"(",
"\"$oldValue\"",
")",
";",
"Expression",
"newValue",
"=",
"varX",
"(",
"\"$newValue\"",
")",
";",
"Expression",
"proposedValue",
"=",
"varX",
"(",
"setter",
".",
"getParameters",
"(",
")",
"[",
"0",
"]",
".",
"getName",
"(",
")",
")",
";",
"BlockStatement",
"block",
"=",
"new",
"BlockStatement",
"(",
")",
";",
"// create a local variable to hold the old value from the getter\r",
"block",
".",
"addStatement",
"(",
"declS",
"(",
"oldValue",
",",
"callThisX",
"(",
"getterName",
")",
")",
")",
";",
"// add the fireVetoableChange method call\r",
"block",
".",
"addStatement",
"(",
"stmt",
"(",
"callThisX",
"(",
"\"fireVetoableChange\"",
",",
"args",
"(",
"constX",
"(",
"propertyName",
")",
",",
"oldValue",
",",
"proposedValue",
")",
")",
")",
")",
";",
"// call the existing block, which will presumably set the value properly\r",
"block",
".",
"addStatement",
"(",
"code",
")",
";",
"if",
"(",
"bindable",
")",
"{",
"// get the new value to emit in the event\r",
"block",
".",
"addStatement",
"(",
"declS",
"(",
"newValue",
",",
"callThisX",
"(",
"getterName",
")",
")",
")",
";",
"// add the firePropertyChange method call\r",
"block",
".",
"addStatement",
"(",
"stmt",
"(",
"callThisX",
"(",
"\"firePropertyChange\"",
",",
"args",
"(",
"constX",
"(",
"propertyName",
")",
",",
"oldValue",
",",
"newValue",
")",
")",
")",
")",
";",
"}",
"// replace the existing code block with our new one\r",
"setter",
".",
"setCode",
"(",
"block",
")",
";",
"}",
"}"
] | Wrap an existing setter. | [
"Wrap",
"an",
"existing",
"setter",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/beans/VetoableASTTransformation.java#L169-L203 |
44 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.directorySize | public static long directorySize(File self) throws IOException, IllegalArgumentException
{
final long[] size = {0L};
eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) {
public void doCall(Object[] args) {
size[0] += ((File) args[0]).length();
}
});
return size[0];
} | java | public static long directorySize(File self) throws IOException, IllegalArgumentException
{
final long[] size = {0L};
eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) {
public void doCall(Object[] args) {
size[0] += ((File) args[0]).length();
}
});
return size[0];
} | [
"public",
"static",
"long",
"directorySize",
"(",
"File",
"self",
")",
"throws",
"IOException",
",",
"IllegalArgumentException",
"{",
"final",
"long",
"[",
"]",
"size",
"=",
"{",
"0L",
"}",
";",
"eachFileRecurse",
"(",
"self",
",",
"FileType",
".",
"FILES",
",",
"new",
"Closure",
"<",
"Void",
">",
"(",
"null",
")",
"{",
"public",
"void",
"doCall",
"(",
"Object",
"[",
"]",
"args",
")",
"{",
"size",
"[",
"0",
"]",
"+=",
"(",
"(",
"File",
")",
"args",
"[",
"0",
"]",
")",
".",
"length",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"size",
"[",
"0",
"]",
";",
"}"
] | Calculates directory size as total size of all its files, recursively.
@param self a file object
@return directory size (length)
@since 2.1
@throws IOException if File object specified does not exist
@throws IllegalArgumentException if the provided File object does not represent a directory | [
"Calculates",
"directory",
"size",
"as",
"total",
"size",
"of",
"all",
"its",
"files",
"recursively",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L118-L129 |
45 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.splitEachLine | public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException {
return IOGroovyMethods.splitEachLine(newReader(self), regex, closure);
} | java | public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException {
return IOGroovyMethods.splitEachLine(newReader(self), regex, closure);
} | [
"public",
"static",
"<",
"T",
">",
"T",
"splitEachLine",
"(",
"File",
"self",
",",
"String",
"regex",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"\"java.lang.String[]\"",
")",
"Closure",
"<",
"T",
">",
"closure",
")",
"throws",
"IOException",
"{",
"return",
"IOGroovyMethods",
".",
"splitEachLine",
"(",
"newReader",
"(",
"self",
")",
",",
"regex",
",",
"closure",
")",
";",
"}"
] | Iterates through this file line by line, splitting each line using
the given regex separator. For each line, the given closure is called with
a single parameter being the list of strings computed by splitting the line
around matches of the given regular expression.
Finally the resources used for processing the file are closed.
@param self a File
@param regex the delimiting regular expression
@param closure a closure
@return the last value returned by the closure
@throws IOException if an IOException occurs.
@throws java.util.regex.PatternSyntaxException
if the regular expression's syntax is invalid
@see IOGroovyMethods#splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
@since 1.5.5 | [
"Iterates",
"through",
"this",
"file",
"line",
"by",
"line",
"splitting",
"each",
"line",
"using",
"the",
"given",
"regex",
"separator",
".",
"For",
"each",
"line",
"the",
"given",
"closure",
"is",
"called",
"with",
"a",
"single",
"parameter",
"being",
"the",
"list",
"of",
"strings",
"computed",
"by",
"splitting",
"the",
"line",
"around",
"matches",
"of",
"the",
"given",
"regular",
"expression",
".",
"Finally",
"the",
"resources",
"used",
"for",
"processing",
"the",
"file",
"are",
"closed",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L378-L380 |
46 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.write | public static void write(File file, String text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file);
writeUTF16BomIfRequired(charset, out);
writer = new OutputStreamWriter(out, charset);
writer.write(text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | public static void write(File file, String text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file);
writeUTF16BomIfRequired(charset, out);
writer = new OutputStreamWriter(out, charset);
writer.write(text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | [
"public",
"static",
"void",
"write",
"(",
"File",
"file",
",",
"String",
"text",
",",
"String",
"charset",
")",
"throws",
"IOException",
"{",
"Writer",
"writer",
"=",
"null",
";",
"try",
"{",
"FileOutputStream",
"out",
"=",
"new",
"FileOutputStream",
"(",
"file",
")",
";",
"writeUTF16BomIfRequired",
"(",
"charset",
",",
"out",
")",
";",
"writer",
"=",
"new",
"OutputStreamWriter",
"(",
"out",
",",
"charset",
")",
";",
"writer",
".",
"write",
"(",
"text",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"Writer",
"temp",
"=",
"writer",
";",
"writer",
"=",
"null",
";",
"temp",
".",
"close",
"(",
")",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"writer",
")",
";",
"}",
"}"
] | Write the text to the File, using the specified encoding.
@param file a File
@param text the text to write to the File
@param charset the charset used
@throws IOException if an IOException occurs.
@since 1.0 | [
"Write",
"the",
"text",
"to",
"the",
"File",
"using",
"the",
"specified",
"encoding",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L817-L832 |
47 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.append | public static void append(File file, Object text) throws IOException {
Writer writer = null;
try {
writer = new FileWriter(file, true);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | public static void append(File file, Object text) throws IOException {
Writer writer = null;
try {
writer = new FileWriter(file, true);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | [
"public",
"static",
"void",
"append",
"(",
"File",
"file",
",",
"Object",
"text",
")",
"throws",
"IOException",
"{",
"Writer",
"writer",
"=",
"null",
";",
"try",
"{",
"writer",
"=",
"new",
"FileWriter",
"(",
"file",
",",
"true",
")",
";",
"InvokerHelper",
".",
"write",
"(",
"writer",
",",
"text",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"Writer",
"temp",
"=",
"writer",
";",
"writer",
"=",
"null",
";",
"temp",
".",
"close",
"(",
")",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"writer",
")",
";",
"}",
"}"
] | Append the text at the end of the File.
@param file a File
@param text the text to append at the end of the File
@throws IOException if an IOException occurs.
@since 1.0 | [
"Append",
"the",
"text",
"at",
"the",
"end",
"of",
"the",
"File",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L842-L855 |
48 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.append | public static void append(File file, Object text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file, true);
if (!file.exists()) {
writeUTF16BomIfRequired(charset, out);
}
writer = new OutputStreamWriter(out, charset);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | public static void append(File file, Object text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file, true);
if (!file.exists()) {
writeUTF16BomIfRequired(charset, out);
}
writer = new OutputStreamWriter(out, charset);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | [
"public",
"static",
"void",
"append",
"(",
"File",
"file",
",",
"Object",
"text",
",",
"String",
"charset",
")",
"throws",
"IOException",
"{",
"Writer",
"writer",
"=",
"null",
";",
"try",
"{",
"FileOutputStream",
"out",
"=",
"new",
"FileOutputStream",
"(",
"file",
",",
"true",
")",
";",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"writeUTF16BomIfRequired",
"(",
"charset",
",",
"out",
")",
";",
"}",
"writer",
"=",
"new",
"OutputStreamWriter",
"(",
"out",
",",
"charset",
")",
";",
"InvokerHelper",
".",
"write",
"(",
"writer",
",",
"text",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"Writer",
"temp",
"=",
"writer",
";",
"writer",
"=",
"null",
";",
"temp",
".",
"close",
"(",
")",
";",
"}",
"finally",
"{",
"closeWithWarning",
"(",
"writer",
")",
";",
"}",
"}"
] | Append the text at the end of the File, using a specified encoding.
@param file a File
@param text the text to append at the end of the File
@param charset the charset used
@throws IOException if an IOException occurs.
@since 1.0 | [
"Append",
"the",
"text",
"at",
"the",
"end",
"of",
"the",
"File",
"using",
"a",
"specified",
"encoding",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L946-L963 |
49 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.append | public static void append(File file, Writer writer, String charset) throws IOException {
appendBuffered(file, writer, charset);
} | java | public static void append(File file, Writer writer, String charset) throws IOException {
appendBuffered(file, writer, charset);
} | [
"public",
"static",
"void",
"append",
"(",
"File",
"file",
",",
"Writer",
"writer",
",",
"String",
"charset",
")",
"throws",
"IOException",
"{",
"appendBuffered",
"(",
"file",
",",
"writer",
",",
"charset",
")",
";",
"}"
] | Append the text supplied by the Writer at the end of the File, using a specified encoding.
@param file a File
@param writer the Writer supplying the text to append at the end of the File
@param charset the charset used
@throws IOException if an IOException occurs.
@since 2.3 | [
"Append",
"the",
"text",
"supplied",
"by",
"the",
"Writer",
"at",
"the",
"end",
"of",
"the",
"File",
"using",
"a",
"specified",
"encoding",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L974-L976 |
50 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java | ResourceGroovyMethods.writeUtf16Bom | private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException {
if (bigEndian) {
stream.write(-2);
stream.write(-1);
} else {
stream.write(-1);
stream.write(-2);
}
} | java | private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException {
if (bigEndian) {
stream.write(-2);
stream.write(-1);
} else {
stream.write(-1);
stream.write(-2);
}
} | [
"private",
"static",
"void",
"writeUtf16Bom",
"(",
"OutputStream",
"stream",
",",
"boolean",
"bigEndian",
")",
"throws",
"IOException",
"{",
"if",
"(",
"bigEndian",
")",
"{",
"stream",
".",
"write",
"(",
"-",
"2",
")",
";",
"stream",
".",
"write",
"(",
"-",
"1",
")",
";",
"}",
"else",
"{",
"stream",
".",
"write",
"(",
"-",
"1",
")",
";",
"stream",
".",
"write",
"(",
"-",
"2",
")",
";",
"}",
"}"
] | Write a Byte Order Mark at the beginning of the file
@param stream the FileOutputStream to write the BOM to
@param bigEndian true if UTF 16 Big Endian or false if Low Endian
@throws IOException if an IOException occurs.
@since 1.0 | [
"Write",
"a",
"Byte",
"Order",
"Mark",
"at",
"the",
"beginning",
"of",
"the",
"file"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1825-L1833 |
51 | groovy/groovy-core | src/main/groovy/lang/GroovyClassLoader.java | GroovyClassLoader.getClassCacheEntry | protected Class getClassCacheEntry(String name) {
if (name == null) return null;
synchronized (classCache) {
return classCache.get(name);
}
} | java | protected Class getClassCacheEntry(String name) {
if (name == null) return null;
synchronized (classCache) {
return classCache.get(name);
}
} | [
"protected",
"Class",
"getClassCacheEntry",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"return",
"null",
";",
"synchronized",
"(",
"classCache",
")",
"{",
"return",
"classCache",
".",
"get",
"(",
"name",
")",
";",
"}",
"}"
] | gets a class from the class cache. This cache contains only classes loaded through
this class loader or an InnerLoader instance. If no class is stored for a
specific name, then the method should return null.
@param name of the class
@return the class stored for the given name
@see #removeClassCacheEntry(String)
@see #setClassCacheEntry(Class)
@see #clearCache() | [
"gets",
"a",
"class",
"from",
"the",
"class",
"cache",
".",
"This",
"cache",
"contains",
"only",
"classes",
"loaded",
"through",
"this",
"class",
"loader",
"or",
"an",
"InnerLoader",
"instance",
".",
"If",
"no",
"class",
"is",
"stored",
"for",
"a",
"specific",
"name",
"then",
"the",
"method",
"should",
"return",
"null",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/GroovyClassLoader.java#L560-L565 |
52 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java | MetaClassRegistryImpl.getMetaClassRegistryChangeEventListeners | public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() {
synchronized (changeListenerList) {
ArrayList<MetaClassRegistryChangeEventListener> ret =
new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeListenerList.size());
ret.addAll(nonRemoveableChangeListenerList);
ret.addAll(changeListenerList);
return ret.toArray(new MetaClassRegistryChangeEventListener[ret.size()]);
}
} | java | public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() {
synchronized (changeListenerList) {
ArrayList<MetaClassRegistryChangeEventListener> ret =
new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeListenerList.size());
ret.addAll(nonRemoveableChangeListenerList);
ret.addAll(changeListenerList);
return ret.toArray(new MetaClassRegistryChangeEventListener[ret.size()]);
}
} | [
"public",
"MetaClassRegistryChangeEventListener",
"[",
"]",
"getMetaClassRegistryChangeEventListeners",
"(",
")",
"{",
"synchronized",
"(",
"changeListenerList",
")",
"{",
"ArrayList",
"<",
"MetaClassRegistryChangeEventListener",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"MetaClassRegistryChangeEventListener",
">",
"(",
"changeListenerList",
".",
"size",
"(",
")",
"+",
"nonRemoveableChangeListenerList",
".",
"size",
"(",
")",
")",
";",
"ret",
".",
"addAll",
"(",
"nonRemoveableChangeListenerList",
")",
";",
"ret",
".",
"addAll",
"(",
"changeListenerList",
")",
";",
"return",
"ret",
".",
"toArray",
"(",
"new",
"MetaClassRegistryChangeEventListener",
"[",
"ret",
".",
"size",
"(",
")",
"]",
")",
";",
"}",
"}"
] | Gets an array of of all registered ConstantMetaClassListener instances. | [
"Gets",
"an",
"array",
"of",
"of",
"all",
"registered",
"ConstantMetaClassListener",
"instances",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java#L400-L408 |
53 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java | MetaClassRegistryImpl.getInstance | public static MetaClassRegistry getInstance(int includeExtension) {
if (includeExtension != DONT_LOAD_DEFAULT) {
if (instanceInclude == null) {
instanceInclude = new MetaClassRegistryImpl();
}
return instanceInclude;
} else {
if (instanceExclude == null) {
instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT);
}
return instanceExclude;
}
} | java | public static MetaClassRegistry getInstance(int includeExtension) {
if (includeExtension != DONT_LOAD_DEFAULT) {
if (instanceInclude == null) {
instanceInclude = new MetaClassRegistryImpl();
}
return instanceInclude;
} else {
if (instanceExclude == null) {
instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT);
}
return instanceExclude;
}
} | [
"public",
"static",
"MetaClassRegistry",
"getInstance",
"(",
"int",
"includeExtension",
")",
"{",
"if",
"(",
"includeExtension",
"!=",
"DONT_LOAD_DEFAULT",
")",
"{",
"if",
"(",
"instanceInclude",
"==",
"null",
")",
"{",
"instanceInclude",
"=",
"new",
"MetaClassRegistryImpl",
"(",
")",
";",
"}",
"return",
"instanceInclude",
";",
"}",
"else",
"{",
"if",
"(",
"instanceExclude",
"==",
"null",
")",
"{",
"instanceExclude",
"=",
"new",
"MetaClassRegistryImpl",
"(",
"DONT_LOAD_DEFAULT",
")",
";",
"}",
"return",
"instanceExclude",
";",
"}",
"}"
] | Singleton of MetaClassRegistry.
@param includeExtension
@return the registry | [
"Singleton",
"of",
"MetaClassRegistry",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java#L416-L428 |
54 | groovy/groovy-core | src/main/org/codehaus/groovy/syntax/Reduction.java | Reduction.get | public CSTNode get( int index )
{
CSTNode element = null;
if( index < size() )
{
element = (CSTNode)elements.get( index );
}
return element;
} | java | public CSTNode get( int index )
{
CSTNode element = null;
if( index < size() )
{
element = (CSTNode)elements.get( index );
}
return element;
} | [
"public",
"CSTNode",
"get",
"(",
"int",
"index",
")",
"{",
"CSTNode",
"element",
"=",
"null",
";",
"if",
"(",
"index",
"<",
"size",
"(",
")",
")",
"{",
"element",
"=",
"(",
"CSTNode",
")",
"elements",
".",
"get",
"(",
"index",
")",
";",
"}",
"return",
"element",
";",
"}"
] | Returns the specified element, or null. | [
"Returns",
"the",
"specified",
"element",
"or",
"null",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Reduction.java#L118-L128 |
55 | groovy/groovy-core | src/main/org/codehaus/groovy/syntax/Reduction.java | Reduction.set | public CSTNode set( int index, CSTNode element )
{
if( elements == null )
{
throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" );
}
if( index == 0 && !(element instanceof Token) )
{
//
// It's not the greatest of design that the interface allows this, but it
// is a tradeoff with convenience, and the convenience is more important.
throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" );
}
//
// Fill slots with nulls, if necessary.
int count = elements.size();
if( index >= count )
{
for( int i = count; i <= index; i++ )
{
elements.add( null );
}
}
//
// Then set in the element.
elements.set( index, element );
return element;
} | java | public CSTNode set( int index, CSTNode element )
{
if( elements == null )
{
throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" );
}
if( index == 0 && !(element instanceof Token) )
{
//
// It's not the greatest of design that the interface allows this, but it
// is a tradeoff with convenience, and the convenience is more important.
throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" );
}
//
// Fill slots with nulls, if necessary.
int count = elements.size();
if( index >= count )
{
for( int i = count; i <= index; i++ )
{
elements.add( null );
}
}
//
// Then set in the element.
elements.set( index, element );
return element;
} | [
"public",
"CSTNode",
"set",
"(",
"int",
"index",
",",
"CSTNode",
"element",
")",
"{",
"if",
"(",
"elements",
"==",
"null",
")",
"{",
"throw",
"new",
"GroovyBugError",
"(",
"\"attempt to set() on a EMPTY Reduction\"",
")",
";",
"}",
"if",
"(",
"index",
"==",
"0",
"&&",
"!",
"(",
"element",
"instanceof",
"Token",
")",
")",
"{",
"//",
"// It's not the greatest of design that the interface allows this, but it",
"// is a tradeoff with convenience, and the convenience is more important.",
"throw",
"new",
"GroovyBugError",
"(",
"\"attempt to set() a non-Token as root of a Reduction\"",
")",
";",
"}",
"//",
"// Fill slots with nulls, if necessary.",
"int",
"count",
"=",
"elements",
".",
"size",
"(",
")",
";",
"if",
"(",
"index",
">=",
"count",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"count",
";",
"i",
"<=",
"index",
";",
"i",
"++",
")",
"{",
"elements",
".",
"add",
"(",
"null",
")",
";",
"}",
"}",
"//",
"// Then set in the element.",
"elements",
".",
"set",
"(",
"index",
",",
"element",
")",
";",
"return",
"element",
";",
"}"
] | Sets an element in at the specified index. | [
"Sets",
"an",
"element",
"in",
"at",
"the",
"specified",
"index",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Reduction.java#L199-L236 |
56 | groovy/groovy-core | src/main/org/codehaus/groovy/util/ManagedLinkedList.java | ManagedLinkedList.add | public void add(T value) {
Element<T> element = new Element<T>(bundle, value);
element.previous = tail;
if (tail != null) tail.next = element;
tail = element;
if (head == null) head = element;
} | java | public void add(T value) {
Element<T> element = new Element<T>(bundle, value);
element.previous = tail;
if (tail != null) tail.next = element;
tail = element;
if (head == null) head = element;
} | [
"public",
"void",
"add",
"(",
"T",
"value",
")",
"{",
"Element",
"<",
"T",
">",
"element",
"=",
"new",
"Element",
"<",
"T",
">",
"(",
"bundle",
",",
"value",
")",
";",
"element",
".",
"previous",
"=",
"tail",
";",
"if",
"(",
"tail",
"!=",
"null",
")",
"tail",
".",
"next",
"=",
"element",
";",
"tail",
"=",
"element",
";",
"if",
"(",
"head",
"==",
"null",
")",
"head",
"=",
"element",
";",
"}"
] | adds a value to the list
@param value the value | [
"adds",
"a",
"value",
"to",
"the",
"list"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedLinkedList.java#L100-L106 |
57 | groovy/groovy-core | src/main/org/codehaus/groovy/util/ManagedLinkedList.java | ManagedLinkedList.toArray | public T[] toArray(T[] tArray) {
List<T> array = new ArrayList<T>(100);
for (Iterator<T> it = iterator(); it.hasNext();) {
T val = it.next();
if (val != null) array.add(val);
}
return array.toArray(tArray);
} | java | public T[] toArray(T[] tArray) {
List<T> array = new ArrayList<T>(100);
for (Iterator<T> it = iterator(); it.hasNext();) {
T val = it.next();
if (val != null) array.add(val);
}
return array.toArray(tArray);
} | [
"public",
"T",
"[",
"]",
"toArray",
"(",
"T",
"[",
"]",
"tArray",
")",
"{",
"List",
"<",
"T",
">",
"array",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
"100",
")",
";",
"for",
"(",
"Iterator",
"<",
"T",
">",
"it",
"=",
"iterator",
"(",
")",
";",
"it",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"T",
"val",
"=",
"it",
".",
"next",
"(",
")",
";",
"if",
"(",
"val",
"!=",
"null",
")",
"array",
".",
"add",
"(",
"val",
")",
";",
"}",
"return",
"array",
".",
"toArray",
"(",
"tArray",
")",
";",
"}"
] | Returns an array of non null elements from the source array.
@param tArray the source array
@return the array | [
"Returns",
"an",
"array",
"of",
"non",
"null",
"elements",
"from",
"the",
"source",
"array",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedLinkedList.java#L125-L132 |
58 | groovy/groovy-core | subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java | ValueMapImpl.get | public Value get(Object key) {
/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */
if (map == null && items.length < 20) {
for (Object item : items) {
MapItemValue miv = (MapItemValue) item;
if (key.equals(miv.name.toValue())) {
return miv.value;
}
}
return null;
} else {
if (map == null) buildIfNeededMap();
return map.get(key);
}
} | java | public Value get(Object key) {
/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */
if (map == null && items.length < 20) {
for (Object item : items) {
MapItemValue miv = (MapItemValue) item;
if (key.equals(miv.name.toValue())) {
return miv.value;
}
}
return null;
} else {
if (map == null) buildIfNeededMap();
return map.get(key);
}
} | [
"public",
"Value",
"get",
"(",
"Object",
"key",
")",
"{",
"/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */",
"if",
"(",
"map",
"==",
"null",
"&&",
"items",
".",
"length",
"<",
"20",
")",
"{",
"for",
"(",
"Object",
"item",
":",
"items",
")",
"{",
"MapItemValue",
"miv",
"=",
"(",
"MapItemValue",
")",
"item",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"miv",
".",
"name",
".",
"toValue",
"(",
")",
")",
")",
"{",
"return",
"miv",
".",
"value",
";",
"}",
"}",
"return",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"map",
"==",
"null",
")",
"buildIfNeededMap",
"(",
")",
";",
"return",
"map",
".",
"get",
"(",
"key",
")",
";",
"}",
"}"
] | Get the items for the key.
@param key
@return the items for the given key | [
"Get",
"the",
"items",
"for",
"the",
"key",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java#L80-L94 |
59 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.unique | public static <T> Iterator<T> unique(Iterator<T> self) {
return toList((Iterable<T>) unique(toList(self))).listIterator();
} | java | public static <T> Iterator<T> unique(Iterator<T> self) {
return toList((Iterable<T>) unique(toList(self))).listIterator();
} | [
"public",
"static",
"<",
"T",
">",
"Iterator",
"<",
"T",
">",
"unique",
"(",
"Iterator",
"<",
"T",
">",
"self",
")",
"{",
"return",
"toList",
"(",
"(",
"Iterable",
"<",
"T",
">",
")",
"unique",
"(",
"toList",
"(",
"self",
")",
")",
")",
".",
"listIterator",
"(",
")",
";",
"}"
] | Returns an iterator equivalent to this iterator with all duplicated items removed
by using the default comparator. The original iterator will become
exhausted of elements after determining the unique values. A new iterator
for the unique values will be returned.
@param self an Iterator
@return the modified Iterator
@since 1.5.5 | [
"Returns",
"an",
"iterator",
"equivalent",
"to",
"this",
"iterator",
"with",
"all",
"duplicated",
"items",
"removed",
"by",
"using",
"the",
"default",
"comparator",
".",
"The",
"original",
"iterator",
"will",
"become",
"exhausted",
"of",
"elements",
"after",
"determining",
"the",
"unique",
"values",
".",
"A",
"new",
"iterator",
"for",
"the",
"unique",
"values",
"will",
"be",
"returned",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L1014-L1016 |
60 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.numberAwareCompareTo | public static int numberAwareCompareTo(Comparable self, Comparable other) {
NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>();
return numberAwareComparator.compare(self, other);
} | java | public static int numberAwareCompareTo(Comparable self, Comparable other) {
NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>();
return numberAwareComparator.compare(self, other);
} | [
"public",
"static",
"int",
"numberAwareCompareTo",
"(",
"Comparable",
"self",
",",
"Comparable",
"other",
")",
"{",
"NumberAwareComparator",
"<",
"Comparable",
">",
"numberAwareComparator",
"=",
"new",
"NumberAwareComparator",
"<",
"Comparable",
">",
"(",
")",
";",
"return",
"numberAwareComparator",
".",
"compare",
"(",
"self",
",",
"other",
")",
";",
"}"
] | Provides a method that compares two comparables using Groovy's
default number aware comparator.
@param self a Comparable
@param other another Comparable
@return a -ve number, 0 or a +ve number according to Groovy's compareTo contract
@since 1.6.0 | [
"Provides",
"a",
"method",
"that",
"compares",
"two",
"comparables",
"using",
"Groovy",
"s",
"default",
"number",
"aware",
"comparator",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L1117-L1120 |
61 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.any | public static boolean any(Object self, Closure closure) {
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
if (bcw.call(iter.next())) return true;
}
return false;
} | java | public static boolean any(Object self, Closure closure) {
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
if (bcw.call(iter.next())) return true;
}
return false;
} | [
"public",
"static",
"boolean",
"any",
"(",
"Object",
"self",
",",
"Closure",
"closure",
")",
"{",
"BooleanClosureWrapper",
"bcw",
"=",
"new",
"BooleanClosureWrapper",
"(",
"closure",
")",
";",
"for",
"(",
"Iterator",
"iter",
"=",
"InvokerHelper",
".",
"asIterator",
"(",
"self",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"if",
"(",
"bcw",
".",
"call",
"(",
"iter",
".",
"next",
"(",
")",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Iterates over the contents of an object or collection, and checks whether a
predicate is valid for at least one element.
@param self the object over which we iterate
@param closure the closure predicate used for matching
@return true if any iteration for the object matches the closure predicate
@since 1.0 | [
"Iterates",
"over",
"the",
"contents",
"of",
"an",
"object",
"or",
"collection",
"and",
"checks",
"whether",
"a",
"predicate",
"is",
"valid",
"for",
"at",
"least",
"one",
"element",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L2306-L2312 |
62 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.findResult | public static Object findResult(Object self, Object defaultResult, Closure closure) {
Object result = findResult(self, closure);
if (result == null) return defaultResult;
return result;
} | java | public static Object findResult(Object self, Object defaultResult, Closure closure) {
Object result = findResult(self, closure);
if (result == null) return defaultResult;
return result;
} | [
"public",
"static",
"Object",
"findResult",
"(",
"Object",
"self",
",",
"Object",
"defaultResult",
",",
"Closure",
"closure",
")",
"{",
"Object",
"result",
"=",
"findResult",
"(",
"self",
",",
"closure",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"return",
"defaultResult",
";",
"return",
"result",
";",
"}"
] | Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.
@param self an Object with an iterator returning its values
@param defaultResult an Object that should be returned if all closure results are null
@param closure a closure that returns a non-null value when processing should stop
@return the first non-null result of the closure, otherwise the default value
@since 1.7.5 | [
"Treats",
"the",
"object",
"as",
"iterable",
"iterating",
"through",
"the",
"values",
"it",
"represents",
"and",
"returns",
"the",
"first",
"non",
"-",
"null",
"result",
"obtained",
"from",
"calling",
"the",
"closure",
"otherwise",
"returns",
"the",
"defaultResult",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L3845-L3849 |
63 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.groupAnswer | protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) {
if (answer.containsKey(value)) {
answer.get(value).add(element);
} else {
List<T> groupedElements = new ArrayList<T>();
groupedElements.add(element);
answer.put(value, groupedElements);
}
} | java | protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) {
if (answer.containsKey(value)) {
answer.get(value).add(element);
} else {
List<T> groupedElements = new ArrayList<T>();
groupedElements.add(element);
answer.put(value, groupedElements);
}
} | [
"protected",
"static",
"<",
"K",
",",
"T",
">",
"void",
"groupAnswer",
"(",
"final",
"Map",
"<",
"K",
",",
"List",
"<",
"T",
">",
">",
"answer",
",",
"T",
"element",
",",
"K",
"value",
")",
"{",
"if",
"(",
"answer",
".",
"containsKey",
"(",
"value",
")",
")",
"{",
"answer",
".",
"get",
"(",
"value",
")",
".",
"add",
"(",
"element",
")",
";",
"}",
"else",
"{",
"List",
"<",
"T",
">",
"groupedElements",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
")",
";",
"groupedElements",
".",
"add",
"(",
"element",
")",
";",
"answer",
".",
"put",
"(",
"value",
",",
"groupedElements",
")",
";",
"}",
"}"
] | Groups the current element according to the value
@param answer the map containing the results
@param element the element to be placed
@param value the value according to which the element will be placed
@since 1.5.0 | [
"Groups",
"the",
"current",
"element",
"according",
"to",
"the",
"value"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L5205-L5213 |
64 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.asImmutable | public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) {
return Collections.unmodifiableMap(self);
} | java | public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) {
return Collections.unmodifiableMap(self);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"Map",
"<",
"K",
",",
"V",
">",
"asImmutable",
"(",
"Map",
"<",
"?",
"extends",
"K",
",",
"?",
"extends",
"V",
">",
"self",
")",
"{",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"self",
")",
";",
"}"
] | A convenience method for creating an immutable map.
@param self a Map
@return an immutable Map
@see java.util.Collections#unmodifiableMap(java.util.Map)
@since 1.0 | [
"A",
"convenience",
"method",
"for",
"creating",
"an",
"immutable",
"map",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7493-L7495 |
65 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.asImmutable | public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) {
return Collections.unmodifiableSortedMap(self);
} | java | public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) {
return Collections.unmodifiableSortedMap(self);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"SortedMap",
"<",
"K",
",",
"V",
">",
"asImmutable",
"(",
"SortedMap",
"<",
"K",
",",
"?",
"extends",
"V",
">",
"self",
")",
"{",
"return",
"Collections",
".",
"unmodifiableSortedMap",
"(",
"self",
")",
";",
"}"
] | A convenience method for creating an immutable sorted map.
@param self a SortedMap
@return an immutable SortedMap
@see java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
@since 1.0 | [
"A",
"convenience",
"method",
"for",
"creating",
"an",
"immutable",
"sorted",
"map",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7505-L7507 |
66 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.asImmutable | public static <T> List<T> asImmutable(List<? extends T> self) {
return Collections.unmodifiableList(self);
} | java | public static <T> List<T> asImmutable(List<? extends T> self) {
return Collections.unmodifiableList(self);
} | [
"public",
"static",
"<",
"T",
">",
"List",
"<",
"T",
">",
"asImmutable",
"(",
"List",
"<",
"?",
"extends",
"T",
">",
"self",
")",
"{",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"self",
")",
";",
"}"
] | A convenience method for creating an immutable list
@param self a List
@return an immutable List
@see java.util.Collections#unmodifiableList(java.util.List)
@since 1.0 | [
"A",
"convenience",
"method",
"for",
"creating",
"an",
"immutable",
"list"
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7517-L7519 |
67 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.asImmutable | public static <T> Set<T> asImmutable(Set<? extends T> self) {
return Collections.unmodifiableSet(self);
} | java | public static <T> Set<T> asImmutable(Set<? extends T> self) {
return Collections.unmodifiableSet(self);
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"asImmutable",
"(",
"Set",
"<",
"?",
"extends",
"T",
">",
"self",
")",
"{",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"self",
")",
";",
"}"
] | A convenience method for creating an immutable list.
@param self a Set
@return an immutable Set
@see java.util.Collections#unmodifiableSet(java.util.Set)
@since 1.0 | [
"A",
"convenience",
"method",
"for",
"creating",
"an",
"immutable",
"list",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7529-L7531 |
68 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.asImmutable | public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
return Collections.unmodifiableSortedSet(self);
} | java | public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
return Collections.unmodifiableSortedSet(self);
} | [
"public",
"static",
"<",
"T",
">",
"SortedSet",
"<",
"T",
">",
"asImmutable",
"(",
"SortedSet",
"<",
"T",
">",
"self",
")",
"{",
"return",
"Collections",
".",
"unmodifiableSortedSet",
"(",
"self",
")",
";",
"}"
] | A convenience method for creating an immutable sorted set.
@param self a SortedSet
@return an immutable SortedSet
@see java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
@since 1.0 | [
"A",
"convenience",
"method",
"for",
"creating",
"an",
"immutable",
"sorted",
"set",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7541-L7543 |
69 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.sort | public static <T> T[] sort(T[] self, Comparator<T> comparator) {
return sort(self, true, comparator);
} | java | public static <T> T[] sort(T[] self, Comparator<T> comparator) {
return sort(self, true, comparator);
} | [
"public",
"static",
"<",
"T",
">",
"T",
"[",
"]",
"sort",
"(",
"T",
"[",
"]",
"self",
",",
"Comparator",
"<",
"T",
">",
"comparator",
")",
"{",
"return",
"sort",
"(",
"self",
",",
"true",
",",
"comparator",
")",
";",
"}"
] | Sorts the given array into sorted order using the given comparator.
@param self the array to be sorted
@param comparator a Comparator used for the comparison
@return the sorted array
@since 1.5.5 | [
"Sorts",
"the",
"given",
"array",
"into",
"sorted",
"order",
"using",
"the",
"given",
"comparator",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L8292-L8294 |
70 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.addAll | public static <T> boolean addAll(Collection<T> self, Iterator<T> items) {
boolean changed = false;
while (items.hasNext()) {
T next = items.next();
if (self.add(next)) changed = true;
}
return changed;
} | java | public static <T> boolean addAll(Collection<T> self, Iterator<T> items) {
boolean changed = false;
while (items.hasNext()) {
T next = items.next();
if (self.add(next)) changed = true;
}
return changed;
} | [
"public",
"static",
"<",
"T",
">",
"boolean",
"addAll",
"(",
"Collection",
"<",
"T",
">",
"self",
",",
"Iterator",
"<",
"T",
">",
"items",
")",
"{",
"boolean",
"changed",
"=",
"false",
";",
"while",
"(",
"items",
".",
"hasNext",
"(",
")",
")",
"{",
"T",
"next",
"=",
"items",
".",
"next",
"(",
")",
";",
"if",
"(",
"self",
".",
"add",
"(",
"next",
")",
")",
"changed",
"=",
"true",
";",
"}",
"return",
"changed",
";",
"}"
] | Adds all items from the iterator to the Collection.
@param self the collection
@param items the items to add
@return true if the collection changed | [
"Adds",
"all",
"items",
"from",
"the",
"iterator",
"to",
"the",
"Collection",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L9371-L9378 |
71 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.addAll | public static <T> boolean addAll(Collection<T> self, Iterable<T> items) {
boolean changed = false;
for (T next : items) {
if (self.add(next)) changed = true;
}
return changed;
} | java | public static <T> boolean addAll(Collection<T> self, Iterable<T> items) {
boolean changed = false;
for (T next : items) {
if (self.add(next)) changed = true;
}
return changed;
} | [
"public",
"static",
"<",
"T",
">",
"boolean",
"addAll",
"(",
"Collection",
"<",
"T",
">",
"self",
",",
"Iterable",
"<",
"T",
">",
"items",
")",
"{",
"boolean",
"changed",
"=",
"false",
";",
"for",
"(",
"T",
"next",
":",
"items",
")",
"{",
"if",
"(",
"self",
".",
"add",
"(",
"next",
")",
")",
"changed",
"=",
"true",
";",
"}",
"return",
"changed",
";",
"}"
] | Adds all items from the iterable to the Collection.
@param self the collection
@param items the items to add
@return true if the collection changed | [
"Adds",
"all",
"items",
"from",
"the",
"iterable",
"to",
"the",
"Collection",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L9387-L9393 |
72 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.minus | public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) {
final Map<K,V> ansMap = createSimilarMap(self);
ansMap.putAll(self);
if (removeMe != null && removeMe.size() > 0) {
for (Map.Entry<K, V> e1 : self.entrySet()) {
for (Object e2 : removeMe.entrySet()) {
if (DefaultTypeTransformation.compareEqual(e1, e2)) {
ansMap.remove(e1.getKey());
}
}
}
}
return ansMap;
} | java | public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) {
final Map<K,V> ansMap = createSimilarMap(self);
ansMap.putAll(self);
if (removeMe != null && removeMe.size() > 0) {
for (Map.Entry<K, V> e1 : self.entrySet()) {
for (Object e2 : removeMe.entrySet()) {
if (DefaultTypeTransformation.compareEqual(e1, e2)) {
ansMap.remove(e1.getKey());
}
}
}
}
return ansMap;
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"Map",
"<",
"K",
",",
"V",
">",
"minus",
"(",
"Map",
"<",
"K",
",",
"V",
">",
"self",
",",
"Map",
"removeMe",
")",
"{",
"final",
"Map",
"<",
"K",
",",
"V",
">",
"ansMap",
"=",
"createSimilarMap",
"(",
"self",
")",
";",
"ansMap",
".",
"putAll",
"(",
"self",
")",
";",
"if",
"(",
"removeMe",
"!=",
"null",
"&&",
"removeMe",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"K",
",",
"V",
">",
"e1",
":",
"self",
".",
"entrySet",
"(",
")",
")",
"{",
"for",
"(",
"Object",
"e2",
":",
"removeMe",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"DefaultTypeTransformation",
".",
"compareEqual",
"(",
"e1",
",",
"e2",
")",
")",
"{",
"ansMap",
".",
"remove",
"(",
"e1",
".",
"getKey",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"ansMap",
";",
"}"
] | Create a Map composed of the entries of the first map minus the
entries of the given map.
@param self a map object
@param removeMe the entries to remove from the map
@return the resulting map
@since 1.7.4 | [
"Create",
"a",
"Map",
"composed",
"of",
"the",
"entries",
"of",
"the",
"first",
"map",
"minus",
"the",
"entries",
"of",
"the",
"given",
"map",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L11931-L11944 |
73 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.findLastIndexOf | public static int findLastIndexOf(Object self, int startIndex, Closure closure) {
int result = -1;
int i = 0;
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) {
Object value = iter.next();
if (i < startIndex) {
continue;
}
if (bcw.call(value)) {
result = i;
}
}
return result;
} | java | public static int findLastIndexOf(Object self, int startIndex, Closure closure) {
int result = -1;
int i = 0;
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) {
Object value = iter.next();
if (i < startIndex) {
continue;
}
if (bcw.call(value)) {
result = i;
}
}
return result;
} | [
"public",
"static",
"int",
"findLastIndexOf",
"(",
"Object",
"self",
",",
"int",
"startIndex",
",",
"Closure",
"closure",
")",
"{",
"int",
"result",
"=",
"-",
"1",
";",
"int",
"i",
"=",
"0",
";",
"BooleanClosureWrapper",
"bcw",
"=",
"new",
"BooleanClosureWrapper",
"(",
"closure",
")",
";",
"for",
"(",
"Iterator",
"iter",
"=",
"InvokerHelper",
".",
"asIterator",
"(",
"self",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
"i",
"++",
")",
"{",
"Object",
"value",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"i",
"<",
"startIndex",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"bcw",
".",
"call",
"(",
"value",
")",
")",
"{",
"result",
"=",
"i",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Iterates over the elements of an iterable collection of items, starting
from a specified startIndex, and returns the index of the last item that
matches the condition specified in the closure.
@param self the iteration object over which to iterate
@param startIndex start matching from this index
@param closure the filter to perform a match on the collection
@return an integer that is the index of the last matched object or -1 if no match was found
@since 1.5.2 | [
"Iterates",
"over",
"the",
"elements",
"of",
"an",
"iterable",
"collection",
"of",
"items",
"starting",
"from",
"a",
"specified",
"startIndex",
"and",
"returns",
"the",
"index",
"of",
"the",
"last",
"item",
"that",
"matches",
"the",
"condition",
"specified",
"in",
"the",
"closure",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15414-L15428 |
74 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.findIndexValues | public static List<Number> findIndexValues(Object self, Closure closure) {
return findIndexValues(self, 0, closure);
} | java | public static List<Number> findIndexValues(Object self, Closure closure) {
return findIndexValues(self, 0, closure);
} | [
"public",
"static",
"List",
"<",
"Number",
">",
"findIndexValues",
"(",
"Object",
"self",
",",
"Closure",
"closure",
")",
"{",
"return",
"findIndexValues",
"(",
"self",
",",
"0",
",",
"closure",
")",
";",
"}"
] | Iterates over the elements of an iterable collection of items and returns
the index values of the items that match the condition specified in the closure.
@param self the iteration object over which to iterate
@param closure the filter to perform a match on the collection
@return a list of numbers corresponding to the index values of all matched objects
@since 1.5.2 | [
"Iterates",
"over",
"the",
"elements",
"of",
"an",
"iterable",
"collection",
"of",
"items",
"and",
"returns",
"the",
"index",
"values",
"of",
"the",
"items",
"that",
"match",
"the",
"condition",
"specified",
"in",
"the",
"closure",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15439-L15441 |
75 | groovy/groovy-core | src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | DefaultGroovyMethods.findIndexValues | public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) {
List<Number> result = new ArrayList<Number>();
long count = 0;
long startCount = startIndex.longValue();
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); count++) {
Object value = iter.next();
if (count < startCount) {
continue;
}
if (bcw.call(value)) {
result.add(count);
}
}
return result;
} | java | public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) {
List<Number> result = new ArrayList<Number>();
long count = 0;
long startCount = startIndex.longValue();
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); count++) {
Object value = iter.next();
if (count < startCount) {
continue;
}
if (bcw.call(value)) {
result.add(count);
}
}
return result;
} | [
"public",
"static",
"List",
"<",
"Number",
">",
"findIndexValues",
"(",
"Object",
"self",
",",
"Number",
"startIndex",
",",
"Closure",
"closure",
")",
"{",
"List",
"<",
"Number",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"Number",
">",
"(",
")",
";",
"long",
"count",
"=",
"0",
";",
"long",
"startCount",
"=",
"startIndex",
".",
"longValue",
"(",
")",
";",
"BooleanClosureWrapper",
"bcw",
"=",
"new",
"BooleanClosureWrapper",
"(",
"closure",
")",
";",
"for",
"(",
"Iterator",
"iter",
"=",
"InvokerHelper",
".",
"asIterator",
"(",
"self",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
"count",
"++",
")",
"{",
"Object",
"value",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"count",
"<",
"startCount",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"bcw",
".",
"call",
"(",
"value",
")",
")",
"{",
"result",
".",
"add",
"(",
"count",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Iterates over the elements of an iterable collection of items, starting from
a specified startIndex, and returns the index values of the items that match
the condition specified in the closure.
@param self the iteration object over which to iterate
@param startIndex start matching from this index
@param closure the filter to perform a match on the collection
@return a list of numbers corresponding to the index values of all matched objects
@since 1.5.2 | [
"Iterates",
"over",
"the",
"elements",
"of",
"an",
"iterable",
"collection",
"of",
"items",
"starting",
"from",
"a",
"specified",
"startIndex",
"and",
"returns",
"the",
"index",
"values",
"of",
"the",
"items",
"that",
"match",
"the",
"condition",
"specified",
"in",
"the",
"closure",
"."
] | 01309f9d4be34ddf93c4a9943b5a97843bff6181 | https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15454-L15469 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 66