id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
13,000
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.size
|
@Override
public int size() {
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
return map.size();
} finally {
readLock.unlock();
}
}
|
java
|
@Override
public int size() {
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
return map.size();
} finally {
readLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"int",
"size",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"return",
"map",
".",
"size",
"(",
")",
";",
"}",
"finally",
"{",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Returns the number of registered runners.
@return number of registered runners
|
[
"Returns",
"the",
"number",
"of",
"registered",
"runners",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L212-L221
|
13,001
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.get
|
@Override
public GroovyRunner get(Object key) {
if (key == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
return map.get(key);
} finally {
readLock.unlock();
}
}
|
java
|
@Override
public GroovyRunner get(Object key) {
if (key == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
return map.get(key);
} finally {
readLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"GroovyRunner",
"get",
"(",
"Object",
"key",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"return",
"map",
".",
"get",
"(",
"key",
")",
";",
"}",
"finally",
"{",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Returns the registered runner for the specified key.
@param key used to lookup the runner
@return the runner registered with the given key
|
[
"Returns",
"the",
"registered",
"runner",
"for",
"the",
"specified",
"key",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L288-L300
|
13,002
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.put
|
@Override
public GroovyRunner put(String key, GroovyRunner runner) {
if (key == null || runner == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
return map.put(key, runner);
} finally {
writeLock.unlock();
}
}
|
java
|
@Override
public GroovyRunner put(String key, GroovyRunner runner) {
if (key == null || runner == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
return map.put(key, runner);
} finally {
writeLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"GroovyRunner",
"put",
"(",
"String",
"key",
",",
"GroovyRunner",
"runner",
")",
"{",
"if",
"(",
"key",
"==",
"null",
"||",
"runner",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"cachedValues",
"=",
"null",
";",
"return",
"map",
".",
"put",
"(",
"key",
",",
"runner",
")",
";",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Registers a runner with the specified key.
@param key to associate with the runner
@param runner the runner to register
@return the previously registered runner for the given key,
if no runner was previously registered for the key
then {@code null}
|
[
"Registers",
"a",
"runner",
"with",
"the",
"specified",
"key",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L311-L324
|
13,003
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.remove
|
@Override
public GroovyRunner remove(Object key) {
if (key == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
return map.remove(key);
} finally {
writeLock.unlock();
}
}
|
java
|
@Override
public GroovyRunner remove(Object key) {
if (key == null) {
return null;
}
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
return map.remove(key);
} finally {
writeLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"GroovyRunner",
"remove",
"(",
"Object",
"key",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"cachedValues",
"=",
"null",
";",
"return",
"map",
".",
"remove",
"(",
"key",
")",
";",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Removes a registered runner from the registry.
@param key of the runner to remove
@return the runner instance that was removed, if no runner
instance was removed then {@code null}
|
[
"Removes",
"a",
"registered",
"runner",
"from",
"the",
"registry",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L333-L346
|
13,004
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.clear
|
@Override
public void clear() {
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
map.clear();
loadDefaultRunners();
} finally {
writeLock.unlock();
}
}
|
java
|
@Override
public void clear() {
Map<String, GroovyRunner> map = getMap();
writeLock.lock();
try {
cachedValues = null;
map.clear();
loadDefaultRunners();
} finally {
writeLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"void",
"clear",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"cachedValues",
"=",
"null",
";",
"map",
".",
"clear",
"(",
")",
";",
"loadDefaultRunners",
"(",
")",
";",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Clears all registered runners from the registry and resets
the registry so that it contains only the default set of
runners.
|
[
"Clears",
"all",
"registered",
"runners",
"from",
"the",
"registry",
"and",
"resets",
"the",
"registry",
"so",
"that",
"it",
"contains",
"only",
"the",
"default",
"set",
"of",
"runners",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L377-L388
|
13,005
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.values
|
@Override
public Collection<GroovyRunner> values() {
List<GroovyRunner> values = cachedValues;
if (values == null) {
Map<String, GroovyRunner> map = getMap();
// racy, multiple threads may set cachedValues but rather have that than take a write lock
readLock.lock();
try {
if ((values = cachedValues) == null) {
cachedValues = values = Collections.unmodifiableList(new ArrayList<>(map.values()));
}
} finally {
readLock.unlock();
}
}
return values;
}
|
java
|
@Override
public Collection<GroovyRunner> values() {
List<GroovyRunner> values = cachedValues;
if (values == null) {
Map<String, GroovyRunner> map = getMap();
// racy, multiple threads may set cachedValues but rather have that than take a write lock
readLock.lock();
try {
if ((values = cachedValues) == null) {
cachedValues = values = Collections.unmodifiableList(new ArrayList<>(map.values()));
}
} finally {
readLock.unlock();
}
}
return values;
}
|
[
"@",
"Override",
"public",
"Collection",
"<",
"GroovyRunner",
">",
"values",
"(",
")",
"{",
"List",
"<",
"GroovyRunner",
">",
"values",
"=",
"cachedValues",
";",
"if",
"(",
"values",
"==",
"null",
")",
"{",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"// racy, multiple threads may set cachedValues but rather have that than take a write lock",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"(",
"values",
"=",
"cachedValues",
")",
"==",
"null",
")",
"{",
"cachedValues",
"=",
"values",
"=",
"Collections",
".",
"unmodifiableList",
"(",
"new",
"ArrayList",
"<>",
"(",
"map",
".",
"values",
"(",
")",
")",
")",
";",
"}",
"}",
"finally",
"{",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"}",
"return",
"values",
";",
"}"
] |
Returns a collection of all registered runners.
This is a snapshot of the registry and any subsequent
registry changes will not be reflected in the collection.
@return an unmodifiable collection of registered runner instances
|
[
"Returns",
"a",
"collection",
"of",
"all",
"registered",
"runners",
".",
"This",
"is",
"a",
"snapshot",
"of",
"the",
"registry",
"and",
"any",
"subsequent",
"registry",
"changes",
"will",
"not",
"be",
"reflected",
"in",
"the",
"collection",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L418-L434
|
13,006
|
apache/groovy
|
src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java
|
GroovyRunnerRegistry.entrySet
|
@Override
public Set<Entry<String, GroovyRunner>> entrySet() {
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
if (map.isEmpty()) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new LinkedHashSet<>(map.entrySet()));
} finally {
readLock.unlock();
}
}
|
java
|
@Override
public Set<Entry<String, GroovyRunner>> entrySet() {
Map<String, GroovyRunner> map = getMap();
readLock.lock();
try {
if (map.isEmpty()) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new LinkedHashSet<>(map.entrySet()));
} finally {
readLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"Set",
"<",
"Entry",
"<",
"String",
",",
"GroovyRunner",
">",
">",
"entrySet",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"GroovyRunner",
">",
"map",
"=",
"getMap",
"(",
")",
";",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"map",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Collections",
".",
"emptySet",
"(",
")",
";",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"new",
"LinkedHashSet",
"<>",
"(",
"map",
".",
"entrySet",
"(",
")",
")",
")",
";",
"}",
"finally",
"{",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Returns a set of entries for registered runners.
This is a snapshot of the registry and any subsequent
registry changes will not be reflected in the set.
@return an unmodifiable set of registered runner entries
|
[
"Returns",
"a",
"set",
"of",
"entries",
"for",
"registered",
"runners",
".",
"This",
"is",
"a",
"snapshot",
"of",
"the",
"registry",
"and",
"any",
"subsequent",
"registry",
"changes",
"will",
"not",
"be",
"reflected",
"in",
"the",
"set",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/plugin/GroovyRunnerRegistry.java#L443-L455
|
13,007
|
apache/groovy
|
src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java
|
UnicodeEscapingReader.read
|
public int read(char cbuf[], int off, int len) throws IOException {
int c = 0;
int count = 0;
while (count < len && (c = read())!= -1) {
cbuf[off + count] = (char) c;
count++;
}
return (count == 0 && c == -1) ? -1 : count;
}
|
java
|
public int read(char cbuf[], int off, int len) throws IOException {
int c = 0;
int count = 0;
while (count < len && (c = read())!= -1) {
cbuf[off + count] = (char) c;
count++;
}
return (count == 0 && c == -1) ? -1 : count;
}
|
[
"public",
"int",
"read",
"(",
"char",
"cbuf",
"[",
"]",
",",
"int",
"off",
",",
"int",
"len",
")",
"throws",
"IOException",
"{",
"int",
"c",
"=",
"0",
";",
"int",
"count",
"=",
"0",
";",
"while",
"(",
"count",
"<",
"len",
"&&",
"(",
"c",
"=",
"read",
"(",
")",
")",
"!=",
"-",
"1",
")",
"{",
"cbuf",
"[",
"off",
"+",
"count",
"]",
"=",
"(",
"char",
")",
"c",
";",
"count",
"++",
";",
"}",
"return",
"(",
"count",
"==",
"0",
"&&",
"c",
"==",
"-",
"1",
")",
"?",
"-",
"1",
":",
"count",
";",
"}"
] |
Reads characters from the underlying reader.
@see java.io.Reader#read(char[],int,int)
|
[
"Reads",
"characters",
"from",
"the",
"underlying",
"reader",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java#L82-L90
|
13,008
|
apache/groovy
|
src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java
|
UnicodeEscapingReader.read
|
public int read() throws IOException {
if (hasNextChar) {
hasNextChar = false;
write(nextChar);
return nextChar;
}
if (previousLine != lexer.getLine()) {
// new line, so reset unicode escapes
numUnicodeEscapesFoundOnCurrentLine = 0;
previousLine = lexer.getLine();
}
int c = reader.read();
if (c != '\\') {
write(c);
return c;
}
// Have one backslash, continue if next char is 'u'
c = reader.read();
if (c != 'u') {
hasNextChar = true;
nextChar = c;
write('\\');
return '\\';
}
// Swallow multiple 'u's
int numberOfUChars = 0;
do {
numberOfUChars++;
c = reader.read();
} while (c == 'u');
// Get first hex digit
checkHexDigit(c);
StringBuilder charNum = new StringBuilder();
charNum.append((char) c);
// Must now be three more hex digits
for (int i = 0; i < 3; i++) {
c = reader.read();
checkHexDigit(c);
charNum.append((char) c);
}
int rv = Integer.parseInt(charNum.toString(), 16);
write(rv);
numUnicodeEscapesFound += 4 + numberOfUChars;
numUnicodeEscapesFoundOnCurrentLine += 4 + numberOfUChars;
return rv;
}
|
java
|
public int read() throws IOException {
if (hasNextChar) {
hasNextChar = false;
write(nextChar);
return nextChar;
}
if (previousLine != lexer.getLine()) {
// new line, so reset unicode escapes
numUnicodeEscapesFoundOnCurrentLine = 0;
previousLine = lexer.getLine();
}
int c = reader.read();
if (c != '\\') {
write(c);
return c;
}
// Have one backslash, continue if next char is 'u'
c = reader.read();
if (c != 'u') {
hasNextChar = true;
nextChar = c;
write('\\');
return '\\';
}
// Swallow multiple 'u's
int numberOfUChars = 0;
do {
numberOfUChars++;
c = reader.read();
} while (c == 'u');
// Get first hex digit
checkHexDigit(c);
StringBuilder charNum = new StringBuilder();
charNum.append((char) c);
// Must now be three more hex digits
for (int i = 0; i < 3; i++) {
c = reader.read();
checkHexDigit(c);
charNum.append((char) c);
}
int rv = Integer.parseInt(charNum.toString(), 16);
write(rv);
numUnicodeEscapesFound += 4 + numberOfUChars;
numUnicodeEscapesFoundOnCurrentLine += 4 + numberOfUChars;
return rv;
}
|
[
"public",
"int",
"read",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"hasNextChar",
")",
"{",
"hasNextChar",
"=",
"false",
";",
"write",
"(",
"nextChar",
")",
";",
"return",
"nextChar",
";",
"}",
"if",
"(",
"previousLine",
"!=",
"lexer",
".",
"getLine",
"(",
")",
")",
"{",
"// new line, so reset unicode escapes",
"numUnicodeEscapesFoundOnCurrentLine",
"=",
"0",
";",
"previousLine",
"=",
"lexer",
".",
"getLine",
"(",
")",
";",
"}",
"int",
"c",
"=",
"reader",
".",
"read",
"(",
")",
";",
"if",
"(",
"c",
"!=",
"'",
"'",
")",
"{",
"write",
"(",
"c",
")",
";",
"return",
"c",
";",
"}",
"// Have one backslash, continue if next char is 'u'",
"c",
"=",
"reader",
".",
"read",
"(",
")",
";",
"if",
"(",
"c",
"!=",
"'",
"'",
")",
"{",
"hasNextChar",
"=",
"true",
";",
"nextChar",
"=",
"c",
";",
"write",
"(",
"'",
"'",
")",
";",
"return",
"'",
"'",
";",
"}",
"// Swallow multiple 'u's",
"int",
"numberOfUChars",
"=",
"0",
";",
"do",
"{",
"numberOfUChars",
"++",
";",
"c",
"=",
"reader",
".",
"read",
"(",
")",
";",
"}",
"while",
"(",
"c",
"==",
"'",
"'",
")",
";",
"// Get first hex digit",
"checkHexDigit",
"(",
"c",
")",
";",
"StringBuilder",
"charNum",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"charNum",
".",
"append",
"(",
"(",
"char",
")",
"c",
")",
";",
"// Must now be three more hex digits",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"c",
"=",
"reader",
".",
"read",
"(",
")",
";",
"checkHexDigit",
"(",
"c",
")",
";",
"charNum",
".",
"append",
"(",
"(",
"char",
")",
"c",
")",
";",
"}",
"int",
"rv",
"=",
"Integer",
".",
"parseInt",
"(",
"charNum",
".",
"toString",
"(",
")",
",",
"16",
")",
";",
"write",
"(",
"rv",
")",
";",
"numUnicodeEscapesFound",
"+=",
"4",
"+",
"numberOfUChars",
";",
"numUnicodeEscapesFoundOnCurrentLine",
"+=",
"4",
"+",
"numberOfUChars",
";",
"return",
"rv",
";",
"}"
] |
Gets the next character from the underlying reader,
translating escapes as required.
@see java.io.Reader#close()
|
[
"Gets",
"the",
"next",
"character",
"from",
"the",
"underlying",
"reader",
"translating",
"escapes",
"as",
"required",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java#L97-L150
|
13,009
|
apache/groovy
|
src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java
|
UnicodeEscapingReader.checkHexDigit
|
private void checkHexDigit(int c) throws IOException {
if (c >= '0' && c <= '9') {
return;
}
if (c >= 'a' && c <= 'f') {
return;
}
if (c >= 'A' && c <= 'F') {
return;
}
// Causes the invalid escape to be skipped
hasNextChar = true;
nextChar = c;
throw new IOException("Did not find four digit hex character code."
+ " line: " + lexer.getLine() + " col:" + lexer.getColumn());
}
|
java
|
private void checkHexDigit(int c) throws IOException {
if (c >= '0' && c <= '9') {
return;
}
if (c >= 'a' && c <= 'f') {
return;
}
if (c >= 'A' && c <= 'F') {
return;
}
// Causes the invalid escape to be skipped
hasNextChar = true;
nextChar = c;
throw new IOException("Did not find four digit hex character code."
+ " line: " + lexer.getLine() + " col:" + lexer.getColumn());
}
|
[
"private",
"void",
"checkHexDigit",
"(",
"int",
"c",
")",
"throws",
"IOException",
"{",
"if",
"(",
"c",
">=",
"'",
"'",
"&&",
"c",
"<=",
"'",
"'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"c",
">=",
"'",
"'",
"&&",
"c",
"<=",
"'",
"'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"c",
">=",
"'",
"'",
"&&",
"c",
"<=",
"'",
"'",
")",
"{",
"return",
";",
"}",
"// Causes the invalid escape to be skipped",
"hasNextChar",
"=",
"true",
";",
"nextChar",
"=",
"c",
";",
"throw",
"new",
"IOException",
"(",
"\"Did not find four digit hex character code.\"",
"+",
"\" line: \"",
"+",
"lexer",
".",
"getLine",
"(",
")",
"+",
"\" col:\"",
"+",
"lexer",
".",
"getColumn",
"(",
")",
")",
";",
"}"
] |
Checks that the given character is indeed a hex digit.
|
[
"Checks",
"that",
"the",
"given",
"character",
"is",
"indeed",
"a",
"hex",
"digit",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/antlr/UnicodeEscapingReader.java#L157-L172
|
13,010
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovySocketServer.java
|
GroovySocketServer.run
|
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(url.getPort());
while (true) {
// Create one script per socket connection.
// This is purposefully not caching the Script
// so that the script source file can be changed on the fly,
// as each connection is made to the server.
//FIXME: Groovy has other mechanisms specifically for watching to see if source code changes.
// We should probably be using that here.
// See also the comment about the fact we recompile a script that can't change.
Script script = groovy.parse(source);
new GroovyClientConnection(script, autoOutput, serverSocket.accept());
}
} catch (Exception e) {
e.printStackTrace();
}
}
|
java
|
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(url.getPort());
while (true) {
// Create one script per socket connection.
// This is purposefully not caching the Script
// so that the script source file can be changed on the fly,
// as each connection is made to the server.
//FIXME: Groovy has other mechanisms specifically for watching to see if source code changes.
// We should probably be using that here.
// See also the comment about the fact we recompile a script that can't change.
Script script = groovy.parse(source);
new GroovyClientConnection(script, autoOutput, serverSocket.accept());
}
} catch (Exception e) {
e.printStackTrace();
}
}
|
[
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"ServerSocket",
"serverSocket",
"=",
"new",
"ServerSocket",
"(",
"url",
".",
"getPort",
"(",
")",
")",
";",
"while",
"(",
"true",
")",
"{",
"// Create one script per socket connection.",
"// This is purposefully not caching the Script",
"// so that the script source file can be changed on the fly,",
"// as each connection is made to the server.",
"//FIXME: Groovy has other mechanisms specifically for watching to see if source code changes.",
"// We should probably be using that here.",
"// See also the comment about the fact we recompile a script that can't change.",
"Script",
"script",
"=",
"groovy",
".",
"parse",
"(",
"source",
")",
";",
"new",
"GroovyClientConnection",
"(",
"script",
",",
"autoOutput",
",",
"serverSocket",
".",
"accept",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] |
Runs this server. There is typically no need to call this method, as the object's constructor
creates a new thread and runs this object automatically.
|
[
"Runs",
"this",
"server",
".",
"There",
"is",
"typically",
"no",
"need",
"to",
"call",
"this",
"method",
"as",
"the",
"object",
"s",
"constructor",
"creates",
"a",
"new",
"thread",
"and",
"runs",
"this",
"object",
"automatically",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovySocketServer.java#L152-L169
|
13,011
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.run
|
private boolean run() {
try {
if (processSockets) {
processSockets();
} else if (processFiles) {
processFiles();
} else {
processOnce();
}
return true;
} catch (CompilationFailedException e) {
System.err.println(e);
return false;
} catch (Throwable e) {
if (e instanceof InvokerInvocationException) {
InvokerInvocationException iie = (InvokerInvocationException) e;
e = iie.getCause();
}
System.err.println("Caught: " + e);
if (!debug) {
StackTraceUtils.deepSanitize(e);
}
e.printStackTrace();
return false;
}
}
|
java
|
private boolean run() {
try {
if (processSockets) {
processSockets();
} else if (processFiles) {
processFiles();
} else {
processOnce();
}
return true;
} catch (CompilationFailedException e) {
System.err.println(e);
return false;
} catch (Throwable e) {
if (e instanceof InvokerInvocationException) {
InvokerInvocationException iie = (InvokerInvocationException) e;
e = iie.getCause();
}
System.err.println("Caught: " + e);
if (!debug) {
StackTraceUtils.deepSanitize(e);
}
e.printStackTrace();
return false;
}
}
|
[
"private",
"boolean",
"run",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"processSockets",
")",
"{",
"processSockets",
"(",
")",
";",
"}",
"else",
"if",
"(",
"processFiles",
")",
"{",
"processFiles",
"(",
")",
";",
"}",
"else",
"{",
"processOnce",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"catch",
"(",
"CompilationFailedException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"Throwable",
"e",
")",
"{",
"if",
"(",
"e",
"instanceof",
"InvokerInvocationException",
")",
"{",
"InvokerInvocationException",
"iie",
"=",
"(",
"InvokerInvocationException",
")",
"e",
";",
"e",
"=",
"iie",
".",
"getCause",
"(",
")",
";",
"}",
"System",
".",
"err",
".",
"println",
"(",
"\"Caught: \"",
"+",
"e",
")",
";",
"if",
"(",
"!",
"debug",
")",
"{",
"StackTraceUtils",
".",
"deepSanitize",
"(",
"e",
")",
";",
"}",
"e",
".",
"printStackTrace",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] |
Run the script.
|
[
"Run",
"the",
"script",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L329-L354
|
13,012
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.processSockets
|
private void processSockets() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
new GroovySocketServer(groovy, getScriptSource(isScriptFile, script), autoOutput, port);
}
|
java
|
private void processSockets() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
new GroovySocketServer(groovy, getScriptSource(isScriptFile, script), autoOutput, port);
}
|
[
"private",
"void",
"processSockets",
"(",
")",
"throws",
"CompilationFailedException",
",",
"IOException",
",",
"URISyntaxException",
"{",
"GroovyShell",
"groovy",
"=",
"new",
"GroovyShell",
"(",
"conf",
")",
";",
"new",
"GroovySocketServer",
"(",
"groovy",
",",
"getScriptSource",
"(",
"isScriptFile",
",",
"script",
")",
",",
"autoOutput",
",",
"port",
")",
";",
"}"
] |
Process Sockets.
|
[
"Process",
"Sockets",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L359-L362
|
13,013
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.searchForGroovyScriptFile
|
public static File searchForGroovyScriptFile(String input) {
String scriptFileName = input.trim();
File scriptFile = new File(scriptFileName);
// TODO: Shouldn't these extensions be kept elsewhere? What about CompilerConfiguration?
// This method probably shouldn't be in GroovyMain either.
String[] standardExtensions = {".groovy",".gvy",".gy",".gsh"};
int i = 0;
while (i < standardExtensions.length && !scriptFile.exists()) {
scriptFile = new File(scriptFileName + standardExtensions[i]);
i++;
}
// if we still haven't found the file, point back to the originally specified filename
if (!scriptFile.exists()) {
scriptFile = new File(scriptFileName);
}
return scriptFile;
}
|
java
|
public static File searchForGroovyScriptFile(String input) {
String scriptFileName = input.trim();
File scriptFile = new File(scriptFileName);
// TODO: Shouldn't these extensions be kept elsewhere? What about CompilerConfiguration?
// This method probably shouldn't be in GroovyMain either.
String[] standardExtensions = {".groovy",".gvy",".gy",".gsh"};
int i = 0;
while (i < standardExtensions.length && !scriptFile.exists()) {
scriptFile = new File(scriptFileName + standardExtensions[i]);
i++;
}
// if we still haven't found the file, point back to the originally specified filename
if (!scriptFile.exists()) {
scriptFile = new File(scriptFileName);
}
return scriptFile;
}
|
[
"public",
"static",
"File",
"searchForGroovyScriptFile",
"(",
"String",
"input",
")",
"{",
"String",
"scriptFileName",
"=",
"input",
".",
"trim",
"(",
")",
";",
"File",
"scriptFile",
"=",
"new",
"File",
"(",
"scriptFileName",
")",
";",
"// TODO: Shouldn't these extensions be kept elsewhere? What about CompilerConfiguration?",
"// This method probably shouldn't be in GroovyMain either.",
"String",
"[",
"]",
"standardExtensions",
"=",
"{",
"\".groovy\"",
",",
"\".gvy\"",
",",
"\".gy\"",
",",
"\".gsh\"",
"}",
";",
"int",
"i",
"=",
"0",
";",
"while",
"(",
"i",
"<",
"standardExtensions",
".",
"length",
"&&",
"!",
"scriptFile",
".",
"exists",
"(",
")",
")",
"{",
"scriptFile",
"=",
"new",
"File",
"(",
"scriptFileName",
"+",
"standardExtensions",
"[",
"i",
"]",
")",
";",
"i",
"++",
";",
"}",
"// if we still haven't found the file, point back to the originally specified filename",
"if",
"(",
"!",
"scriptFile",
".",
"exists",
"(",
")",
")",
"{",
"scriptFile",
"=",
"new",
"File",
"(",
"scriptFileName",
")",
";",
"}",
"return",
"scriptFile",
";",
"}"
] |
Search for the script file, doesn't bother if it is named precisely.
Tries in this order:
- actual supplied name
- name.groovy
- name.gvy
- name.gy
- name.gsh
@since 2.3.0
|
[
"Search",
"for",
"the",
"script",
"file",
"doesn",
"t",
"bother",
"if",
"it",
"is",
"named",
"precisely",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L432-L448
|
13,014
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.setupContextClassLoader
|
private static void setupContextClassLoader(GroovyShell shell) {
final Thread current = Thread.currentThread();
class DoSetContext implements PrivilegedAction {
ClassLoader classLoader;
public DoSetContext(ClassLoader loader) {
classLoader = loader;
}
public Object run() {
current.setContextClassLoader(classLoader);
return null;
}
}
AccessController.doPrivileged(new DoSetContext(shell.getClassLoader()));
}
|
java
|
private static void setupContextClassLoader(GroovyShell shell) {
final Thread current = Thread.currentThread();
class DoSetContext implements PrivilegedAction {
ClassLoader classLoader;
public DoSetContext(ClassLoader loader) {
classLoader = loader;
}
public Object run() {
current.setContextClassLoader(classLoader);
return null;
}
}
AccessController.doPrivileged(new DoSetContext(shell.getClassLoader()));
}
|
[
"private",
"static",
"void",
"setupContextClassLoader",
"(",
"GroovyShell",
"shell",
")",
"{",
"final",
"Thread",
"current",
"=",
"Thread",
".",
"currentThread",
"(",
")",
";",
"class",
"DoSetContext",
"implements",
"PrivilegedAction",
"{",
"ClassLoader",
"classLoader",
";",
"public",
"DoSetContext",
"(",
"ClassLoader",
"loader",
")",
"{",
"classLoader",
"=",
"loader",
";",
"}",
"public",
"Object",
"run",
"(",
")",
"{",
"current",
".",
"setContextClassLoader",
"(",
"classLoader",
")",
";",
"return",
"null",
";",
"}",
"}",
"AccessController",
".",
"doPrivileged",
"(",
"new",
"DoSetContext",
"(",
"shell",
".",
"getClassLoader",
"(",
")",
")",
")",
";",
"}"
] |
GROOVY-6771
|
[
"GROOVY",
"-",
"6771"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L460-L476
|
13,015
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.processFiles
|
private void processFiles() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
setupContextClassLoader(groovy);
Script s = groovy.parse(getScriptSource(isScriptFile, script));
if (args.isEmpty()) {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
PrintWriter writer = new PrintWriter(System.out);
processReader(s, reader, writer);
writer.flush();
}
} else {
Iterator i = args.iterator();
while (i.hasNext()) {
String filename = (String) i.next();
//TODO: These are the arguments for -p and -i. Why are we searching using Groovy script extensions?
// Where is this documented?
File file = huntForTheScriptFile(filename);
processFile(s, file);
}
}
}
|
java
|
private void processFiles() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
setupContextClassLoader(groovy);
Script s = groovy.parse(getScriptSource(isScriptFile, script));
if (args.isEmpty()) {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
PrintWriter writer = new PrintWriter(System.out);
processReader(s, reader, writer);
writer.flush();
}
} else {
Iterator i = args.iterator();
while (i.hasNext()) {
String filename = (String) i.next();
//TODO: These are the arguments for -p and -i. Why are we searching using Groovy script extensions?
// Where is this documented?
File file = huntForTheScriptFile(filename);
processFile(s, file);
}
}
}
|
[
"private",
"void",
"processFiles",
"(",
")",
"throws",
"CompilationFailedException",
",",
"IOException",
",",
"URISyntaxException",
"{",
"GroovyShell",
"groovy",
"=",
"new",
"GroovyShell",
"(",
"conf",
")",
";",
"setupContextClassLoader",
"(",
"groovy",
")",
";",
"Script",
"s",
"=",
"groovy",
".",
"parse",
"(",
"getScriptSource",
"(",
"isScriptFile",
",",
"script",
")",
")",
";",
"if",
"(",
"args",
".",
"isEmpty",
"(",
")",
")",
"{",
"try",
"(",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"System",
".",
"in",
")",
")",
")",
"{",
"PrintWriter",
"writer",
"=",
"new",
"PrintWriter",
"(",
"System",
".",
"out",
")",
";",
"processReader",
"(",
"s",
",",
"reader",
",",
"writer",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"}",
"}",
"else",
"{",
"Iterator",
"i",
"=",
"args",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"i",
".",
"hasNext",
"(",
")",
")",
"{",
"String",
"filename",
"=",
"(",
"String",
")",
"i",
".",
"next",
"(",
")",
";",
"//TODO: These are the arguments for -p and -i. Why are we searching using Groovy script extensions?",
"// Where is this documented?",
"File",
"file",
"=",
"huntForTheScriptFile",
"(",
"filename",
")",
";",
"processFile",
"(",
"s",
",",
"file",
")",
";",
"}",
"}",
"}"
] |
Process the input files.
|
[
"Process",
"the",
"input",
"files",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L481-L503
|
13,016
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.processFile
|
private void processFile(Script s, File file) throws IOException {
if (!file.exists())
throw new FileNotFoundException(file.getName());
if (!editFiles) {
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
PrintWriter writer = new PrintWriter(System.out);
processReader(s, reader, writer);
writer.flush();
}
} else {
File backup;
if (backupExtension == null) {
backup = File.createTempFile("groovy_", ".tmp");
backup.deleteOnExit();
} else {
backup = new File(file.getPath() + backupExtension);
}
backup.delete();
if (!file.renameTo(backup))
throw new IOException("unable to rename " + file + " to " + backup);
try(BufferedReader reader = new BufferedReader(new FileReader(backup));
PrintWriter writer = new PrintWriter(new FileWriter(file))) {
processReader(s, reader, writer);
}
}
}
|
java
|
private void processFile(Script s, File file) throws IOException {
if (!file.exists())
throw new FileNotFoundException(file.getName());
if (!editFiles) {
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
PrintWriter writer = new PrintWriter(System.out);
processReader(s, reader, writer);
writer.flush();
}
} else {
File backup;
if (backupExtension == null) {
backup = File.createTempFile("groovy_", ".tmp");
backup.deleteOnExit();
} else {
backup = new File(file.getPath() + backupExtension);
}
backup.delete();
if (!file.renameTo(backup))
throw new IOException("unable to rename " + file + " to " + backup);
try(BufferedReader reader = new BufferedReader(new FileReader(backup));
PrintWriter writer = new PrintWriter(new FileWriter(file))) {
processReader(s, reader, writer);
}
}
}
|
[
"private",
"void",
"processFile",
"(",
"Script",
"s",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"throw",
"new",
"FileNotFoundException",
"(",
"file",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"!",
"editFiles",
")",
"{",
"try",
"(",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"FileReader",
"(",
"file",
")",
")",
")",
"{",
"PrintWriter",
"writer",
"=",
"new",
"PrintWriter",
"(",
"System",
".",
"out",
")",
";",
"processReader",
"(",
"s",
",",
"reader",
",",
"writer",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"}",
"}",
"else",
"{",
"File",
"backup",
";",
"if",
"(",
"backupExtension",
"==",
"null",
")",
"{",
"backup",
"=",
"File",
".",
"createTempFile",
"(",
"\"groovy_\"",
",",
"\".tmp\"",
")",
";",
"backup",
".",
"deleteOnExit",
"(",
")",
";",
"}",
"else",
"{",
"backup",
"=",
"new",
"File",
"(",
"file",
".",
"getPath",
"(",
")",
"+",
"backupExtension",
")",
";",
"}",
"backup",
".",
"delete",
"(",
")",
";",
"if",
"(",
"!",
"file",
".",
"renameTo",
"(",
"backup",
")",
")",
"throw",
"new",
"IOException",
"(",
"\"unable to rename \"",
"+",
"file",
"+",
"\" to \"",
"+",
"backup",
")",
";",
"try",
"(",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"FileReader",
"(",
"backup",
")",
")",
";",
"PrintWriter",
"writer",
"=",
"new",
"PrintWriter",
"(",
"new",
"FileWriter",
"(",
"file",
")",
")",
")",
"{",
"processReader",
"(",
"s",
",",
"reader",
",",
"writer",
")",
";",
"}",
"}",
"}"
] |
Process a single input file.
@param s the script to execute.
@param file the input file.
|
[
"Process",
"a",
"single",
"input",
"file",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L511-L540
|
13,017
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.processReader
|
private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException {
String line;
String lineCountName = "count";
s.setProperty(lineCountName, BigInteger.ZERO);
String autoSplitName = "split";
s.setProperty("out", pw);
try {
InvokerHelper.invokeMethod(s, "begin", null);
} catch (MissingMethodException mme) {
// ignore the missing method exception
// as it means no begin() method is present
}
while ((line = reader.readLine()) != null) {
s.setProperty("line", line);
s.setProperty(lineCountName, ((BigInteger)s.getProperty(lineCountName)).add(BigInteger.ONE));
if(autoSplit) {
s.setProperty(autoSplitName, line.split(splitPattern));
}
Object o = s.run();
if (autoOutput && o != null) {
pw.println(o);
}
}
try {
InvokerHelper.invokeMethod(s, "end", null);
} catch (MissingMethodException mme) {
// ignore the missing method exception
// as it means no end() method is present
}
}
|
java
|
private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException {
String line;
String lineCountName = "count";
s.setProperty(lineCountName, BigInteger.ZERO);
String autoSplitName = "split";
s.setProperty("out", pw);
try {
InvokerHelper.invokeMethod(s, "begin", null);
} catch (MissingMethodException mme) {
// ignore the missing method exception
// as it means no begin() method is present
}
while ((line = reader.readLine()) != null) {
s.setProperty("line", line);
s.setProperty(lineCountName, ((BigInteger)s.getProperty(lineCountName)).add(BigInteger.ONE));
if(autoSplit) {
s.setProperty(autoSplitName, line.split(splitPattern));
}
Object o = s.run();
if (autoOutput && o != null) {
pw.println(o);
}
}
try {
InvokerHelper.invokeMethod(s, "end", null);
} catch (MissingMethodException mme) {
// ignore the missing method exception
// as it means no end() method is present
}
}
|
[
"private",
"void",
"processReader",
"(",
"Script",
"s",
",",
"BufferedReader",
"reader",
",",
"PrintWriter",
"pw",
")",
"throws",
"IOException",
"{",
"String",
"line",
";",
"String",
"lineCountName",
"=",
"\"count\"",
";",
"s",
".",
"setProperty",
"(",
"lineCountName",
",",
"BigInteger",
".",
"ZERO",
")",
";",
"String",
"autoSplitName",
"=",
"\"split\"",
";",
"s",
".",
"setProperty",
"(",
"\"out\"",
",",
"pw",
")",
";",
"try",
"{",
"InvokerHelper",
".",
"invokeMethod",
"(",
"s",
",",
"\"begin\"",
",",
"null",
")",
";",
"}",
"catch",
"(",
"MissingMethodException",
"mme",
")",
"{",
"// ignore the missing method exception",
"// as it means no begin() method is present",
"}",
"while",
"(",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"s",
".",
"setProperty",
"(",
"\"line\"",
",",
"line",
")",
";",
"s",
".",
"setProperty",
"(",
"lineCountName",
",",
"(",
"(",
"BigInteger",
")",
"s",
".",
"getProperty",
"(",
"lineCountName",
")",
")",
".",
"add",
"(",
"BigInteger",
".",
"ONE",
")",
")",
";",
"if",
"(",
"autoSplit",
")",
"{",
"s",
".",
"setProperty",
"(",
"autoSplitName",
",",
"line",
".",
"split",
"(",
"splitPattern",
")",
")",
";",
"}",
"Object",
"o",
"=",
"s",
".",
"run",
"(",
")",
";",
"if",
"(",
"autoOutput",
"&&",
"o",
"!=",
"null",
")",
"{",
"pw",
".",
"println",
"(",
"o",
")",
";",
"}",
"}",
"try",
"{",
"InvokerHelper",
".",
"invokeMethod",
"(",
"s",
",",
"\"end\"",
",",
"null",
")",
";",
"}",
"catch",
"(",
"MissingMethodException",
"mme",
")",
"{",
"// ignore the missing method exception",
"// as it means no end() method is present",
"}",
"}"
] |
Process a script against a single input file.
@param s script to execute.
@param reader input file.
@param pw output sink.
|
[
"Process",
"a",
"script",
"against",
"a",
"single",
"input",
"file",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L549-L584
|
13,018
|
apache/groovy
|
src/main/groovy/groovy/ui/GroovyMain.java
|
GroovyMain.processOnce
|
private void processOnce() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
setupContextClassLoader(groovy);
groovy.run(getScriptSource(isScriptFile, script), args);
}
|
java
|
private void processOnce() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
setupContextClassLoader(groovy);
groovy.run(getScriptSource(isScriptFile, script), args);
}
|
[
"private",
"void",
"processOnce",
"(",
")",
"throws",
"CompilationFailedException",
",",
"IOException",
",",
"URISyntaxException",
"{",
"GroovyShell",
"groovy",
"=",
"new",
"GroovyShell",
"(",
"conf",
")",
";",
"setupContextClassLoader",
"(",
"groovy",
")",
";",
"groovy",
".",
"run",
"(",
"getScriptSource",
"(",
"isScriptFile",
",",
"script",
")",
",",
"args",
")",
";",
"}"
] |
Process the standard, single script with args.
|
[
"Process",
"the",
"standard",
"single",
"script",
"with",
"args",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/ui/GroovyMain.java#L589-L593
|
13,019
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/expr/Expression.java
|
Expression.transformExpressions
|
protected List<Expression> transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer) {
List<Expression> list = new ArrayList<Expression>(expressions.size());
for (Expression expr : expressions ) {
list.add(transformer.transform(expr));
}
return list;
}
|
java
|
protected List<Expression> transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer) {
List<Expression> list = new ArrayList<Expression>(expressions.size());
for (Expression expr : expressions ) {
list.add(transformer.transform(expr));
}
return list;
}
|
[
"protected",
"List",
"<",
"Expression",
">",
"transformExpressions",
"(",
"List",
"<",
"?",
"extends",
"Expression",
">",
"expressions",
",",
"ExpressionTransformer",
"transformer",
")",
"{",
"List",
"<",
"Expression",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"Expression",
">",
"(",
"expressions",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Expression",
"expr",
":",
"expressions",
")",
"{",
"list",
".",
"add",
"(",
"transformer",
".",
"transform",
"(",
"expr",
")",
")",
";",
"}",
"return",
"list",
";",
"}"
] |
Transforms the list of expressions
@return a new list of transformed expressions
|
[
"Transforms",
"the",
"list",
"of",
"expressions"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/expr/Expression.java#L46-L52
|
13,020
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/expr/Expression.java
|
Expression.transformExpressions
|
protected <T extends Expression> List<T> transformExpressions(List<? extends Expression> expressions,
ExpressionTransformer transformer, Class<T> transformedType) {
List<T> list = new ArrayList<T>(expressions.size());
for (Expression expr : expressions) {
Expression transformed = transformer.transform(expr);
if (!transformedType.isInstance(transformed))
throw new GroovyBugError(String.format("Transformed expression should have type %s but has type %s",
transformedType, transformed.getClass()));
list.add(transformedType.cast(transformed));
}
return list;
}
|
java
|
protected <T extends Expression> List<T> transformExpressions(List<? extends Expression> expressions,
ExpressionTransformer transformer, Class<T> transformedType) {
List<T> list = new ArrayList<T>(expressions.size());
for (Expression expr : expressions) {
Expression transformed = transformer.transform(expr);
if (!transformedType.isInstance(transformed))
throw new GroovyBugError(String.format("Transformed expression should have type %s but has type %s",
transformedType, transformed.getClass()));
list.add(transformedType.cast(transformed));
}
return list;
}
|
[
"protected",
"<",
"T",
"extends",
"Expression",
">",
"List",
"<",
"T",
">",
"transformExpressions",
"(",
"List",
"<",
"?",
"extends",
"Expression",
">",
"expressions",
",",
"ExpressionTransformer",
"transformer",
",",
"Class",
"<",
"T",
">",
"transformedType",
")",
"{",
"List",
"<",
"T",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
"expressions",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Expression",
"expr",
":",
"expressions",
")",
"{",
"Expression",
"transformed",
"=",
"transformer",
".",
"transform",
"(",
"expr",
")",
";",
"if",
"(",
"!",
"transformedType",
".",
"isInstance",
"(",
"transformed",
")",
")",
"throw",
"new",
"GroovyBugError",
"(",
"String",
".",
"format",
"(",
"\"Transformed expression should have type %s but has type %s\"",
",",
"transformedType",
",",
"transformed",
".",
"getClass",
"(",
")",
")",
")",
";",
"list",
".",
"add",
"(",
"transformedType",
".",
"cast",
"(",
"transformed",
")",
")",
";",
"}",
"return",
"list",
";",
"}"
] |
Transforms the list of expressions, and checks that all transformed expressions have the given type.
@return a new list of transformed expressions
|
[
"Transforms",
"the",
"list",
"of",
"expressions",
"and",
"checks",
"that",
"all",
"transformed",
"expressions",
"have",
"the",
"given",
"type",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/expr/Expression.java#L59-L70
|
13,021
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassHelper.java
|
ClassHelper.make
|
public static ClassNode[] make(Class[] classes) {
ClassNode[] cns = new ClassNode[classes.length];
for (int i = 0; i < cns.length; i++) {
cns[i] = make(classes[i]);
}
return cns;
}
|
java
|
public static ClassNode[] make(Class[] classes) {
ClassNode[] cns = new ClassNode[classes.length];
for (int i = 0; i < cns.length; i++) {
cns[i] = make(classes[i]);
}
return cns;
}
|
[
"public",
"static",
"ClassNode",
"[",
"]",
"make",
"(",
"Class",
"[",
"]",
"classes",
")",
"{",
"ClassNode",
"[",
"]",
"cns",
"=",
"new",
"ClassNode",
"[",
"classes",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"cns",
".",
"length",
";",
"i",
"++",
")",
"{",
"cns",
"[",
"i",
"]",
"=",
"make",
"(",
"classes",
"[",
"i",
"]",
")",
";",
"}",
"return",
"cns",
";",
"}"
] |
Creates an array of ClassNodes using an array of classes.
For each of the given classes a new ClassNode will be
created
@param classes an array of classes used to create the ClassNodes
@return an array of ClassNodes
@see #make(Class)
|
[
"Creates",
"an",
"array",
"of",
"ClassNodes",
"using",
"an",
"array",
"of",
"classes",
".",
"For",
"each",
"of",
"the",
"given",
"classes",
"a",
"new",
"ClassNode",
"will",
"be",
"created"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassHelper.java#L186-L193
|
13,022
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassHelper.java
|
ClassHelper.make
|
public static ClassNode make(String name) {
if (name == null || name.length() == 0) return DYNAMIC_TYPE;
for (int i = 0; i < primitiveClassNames.length; i++) {
if (primitiveClassNames[i].equals(name)) return types[i];
}
for (int i = 0; i < classes.length; i++) {
String cname = classes[i].getName();
if (name.equals(cname)) return types[i];
}
return makeWithoutCaching(name);
}
|
java
|
public static ClassNode make(String name) {
if (name == null || name.length() == 0) return DYNAMIC_TYPE;
for (int i = 0; i < primitiveClassNames.length; i++) {
if (primitiveClassNames[i].equals(name)) return types[i];
}
for (int i = 0; i < classes.length; i++) {
String cname = classes[i].getName();
if (name.equals(cname)) return types[i];
}
return makeWithoutCaching(name);
}
|
[
"public",
"static",
"ClassNode",
"make",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"==",
"null",
"||",
"name",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"DYNAMIC_TYPE",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"primitiveClassNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"primitiveClassNames",
"[",
"i",
"]",
".",
"equals",
"(",
"name",
")",
")",
"return",
"types",
"[",
"i",
"]",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"classes",
".",
"length",
";",
"i",
"++",
")",
"{",
"String",
"cname",
"=",
"classes",
"[",
"i",
"]",
".",
"getName",
"(",
")",
";",
"if",
"(",
"name",
".",
"equals",
"(",
"cname",
")",
")",
"return",
"types",
"[",
"i",
"]",
";",
"}",
"return",
"makeWithoutCaching",
"(",
"name",
")",
";",
"}"
] |
Creates a ClassNode using a given class.
If the name is one of the predefined ClassNodes then the
corresponding ClassNode instance will be returned. If the
name is null or of length 0 the dynamic type is returned
@param name of the class the ClassNode is representing
|
[
"Creates",
"a",
"ClassNode",
"using",
"a",
"given",
"class",
".",
"If",
"the",
"name",
"is",
"one",
"of",
"the",
"predefined",
"ClassNodes",
"then",
"the",
"corresponding",
"ClassNode",
"instance",
"will",
"be",
"returned",
".",
"If",
"the",
"name",
"is",
"null",
"or",
"of",
"length",
"0",
"the",
"dynamic",
"type",
"is",
"returned"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassHelper.java#L263-L275
|
13,023
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassHelper.java
|
ClassHelper.getNextSuperClass
|
public static ClassNode getNextSuperClass(ClassNode clazz, ClassNode goalClazz) {
if (clazz.isArray()) {
if (!goalClazz.isArray()) return null;
ClassNode cn = getNextSuperClass(clazz.getComponentType(), goalClazz.getComponentType());
if (cn != null) cn = cn.makeArray();
return cn;
}
if (!goalClazz.isInterface()) {
if (clazz.isInterface()) {
if (OBJECT_TYPE.equals(clazz)) return null;
return OBJECT_TYPE;
} else {
return clazz.getUnresolvedSuperClass();
}
}
ClassNode[] interfaces = clazz.getUnresolvedInterfaces();
for (ClassNode anInterface : interfaces) {
if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(anInterface, goalClazz)) {
return anInterface;
}
}
//none of the interfaces here match, so continue with super class
return clazz.getUnresolvedSuperClass();
}
|
java
|
public static ClassNode getNextSuperClass(ClassNode clazz, ClassNode goalClazz) {
if (clazz.isArray()) {
if (!goalClazz.isArray()) return null;
ClassNode cn = getNextSuperClass(clazz.getComponentType(), goalClazz.getComponentType());
if (cn != null) cn = cn.makeArray();
return cn;
}
if (!goalClazz.isInterface()) {
if (clazz.isInterface()) {
if (OBJECT_TYPE.equals(clazz)) return null;
return OBJECT_TYPE;
} else {
return clazz.getUnresolvedSuperClass();
}
}
ClassNode[] interfaces = clazz.getUnresolvedInterfaces();
for (ClassNode anInterface : interfaces) {
if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(anInterface, goalClazz)) {
return anInterface;
}
}
//none of the interfaces here match, so continue with super class
return clazz.getUnresolvedSuperClass();
}
|
[
"public",
"static",
"ClassNode",
"getNextSuperClass",
"(",
"ClassNode",
"clazz",
",",
"ClassNode",
"goalClazz",
")",
"{",
"if",
"(",
"clazz",
".",
"isArray",
"(",
")",
")",
"{",
"if",
"(",
"!",
"goalClazz",
".",
"isArray",
"(",
")",
")",
"return",
"null",
";",
"ClassNode",
"cn",
"=",
"getNextSuperClass",
"(",
"clazz",
".",
"getComponentType",
"(",
")",
",",
"goalClazz",
".",
"getComponentType",
"(",
")",
")",
";",
"if",
"(",
"cn",
"!=",
"null",
")",
"cn",
"=",
"cn",
".",
"makeArray",
"(",
")",
";",
"return",
"cn",
";",
"}",
"if",
"(",
"!",
"goalClazz",
".",
"isInterface",
"(",
")",
")",
"{",
"if",
"(",
"clazz",
".",
"isInterface",
"(",
")",
")",
"{",
"if",
"(",
"OBJECT_TYPE",
".",
"equals",
"(",
"clazz",
")",
")",
"return",
"null",
";",
"return",
"OBJECT_TYPE",
";",
"}",
"else",
"{",
"return",
"clazz",
".",
"getUnresolvedSuperClass",
"(",
")",
";",
"}",
"}",
"ClassNode",
"[",
"]",
"interfaces",
"=",
"clazz",
".",
"getUnresolvedInterfaces",
"(",
")",
";",
"for",
"(",
"ClassNode",
"anInterface",
":",
"interfaces",
")",
"{",
"if",
"(",
"StaticTypeCheckingSupport",
".",
"implementsInterfaceOrIsSubclassOf",
"(",
"anInterface",
",",
"goalClazz",
")",
")",
"{",
"return",
"anInterface",
";",
"}",
"}",
"//none of the interfaces here match, so continue with super class",
"return",
"clazz",
".",
"getUnresolvedSuperClass",
"(",
")",
";",
"}"
] |
Returns a super class or interface for a given class depending on a given target.
If the target is no super class or interface, then null will be returned.
For a non-primitive array type, returns an array of the componentType's super class
or interface if the target is also an array.
@param clazz the start class
@param goalClazz the goal class
@return the next super class or interface
|
[
"Returns",
"a",
"super",
"class",
"or",
"interface",
"for",
"a",
"given",
"class",
"depending",
"on",
"a",
"given",
"target",
".",
"If",
"the",
"target",
"is",
"no",
"super",
"class",
"or",
"interface",
"then",
"null",
"will",
"be",
"returned",
".",
"For",
"a",
"non",
"-",
"primitive",
"array",
"type",
"returns",
"an",
"array",
"of",
"the",
"componentType",
"s",
"super",
"class",
"or",
"interface",
"if",
"the",
"target",
"is",
"also",
"an",
"array",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassHelper.java#L482-L507
|
13,024
|
apache/groovy
|
src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberMinus.java
|
NumberNumberMinus.minus
|
public static Number minus(Number left, Number right) {
return NumberMath.subtract(left, right);
}
|
java
|
public static Number minus(Number left, Number right) {
return NumberMath.subtract(left, right);
}
|
[
"public",
"static",
"Number",
"minus",
"(",
"Number",
"left",
",",
"Number",
"right",
")",
"{",
"return",
"NumberMath",
".",
"subtract",
"(",
"left",
",",
"right",
")",
";",
"}"
] |
Subtraction of two Numbers.
@param left a Number
@param right another Number to subtract to the first one
@return the subtraction
|
[
"Subtraction",
"of",
"two",
"Numbers",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberMinus.java#L42-L44
|
13,025
|
apache/groovy
|
src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
|
SocketGroovyMethods.leftShift
|
public static OutputStream leftShift(Socket self, byte[] value) throws IOException {
return IOGroovyMethods.leftShift(self.getOutputStream(), value);
}
|
java
|
public static OutputStream leftShift(Socket self, byte[] value) throws IOException {
return IOGroovyMethods.leftShift(self.getOutputStream(), value);
}
|
[
"public",
"static",
"OutputStream",
"leftShift",
"(",
"Socket",
"self",
",",
"byte",
"[",
"]",
"value",
")",
"throws",
"IOException",
"{",
"return",
"IOGroovyMethods",
".",
"leftShift",
"(",
"self",
".",
"getOutputStream",
"(",
")",
",",
"value",
")",
";",
"}"
] |
Overloads the left shift operator to provide an append mechanism
to add bytes to the output stream of a socket
@param self a Socket
@param value a value to append
@return an OutputStream
@throws IOException if an IOException occurs.
@since 1.0
|
[
"Overloads",
"the",
"left",
"shift",
"operator",
"to",
"provide",
"an",
"append",
"mechanism",
"to",
"add",
"bytes",
"to",
"the",
"output",
"stream",
"of",
"a",
"socket"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L146-L148
|
13,026
|
apache/groovy
|
src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
|
SocketGroovyMethods.accept
|
public static Socket accept(ServerSocket serverSocket, @ClosureParams(value=SimpleType.class, options="java.net.Socket") final Closure closure) throws IOException {
return accept(serverSocket, true, closure);
}
|
java
|
public static Socket accept(ServerSocket serverSocket, @ClosureParams(value=SimpleType.class, options="java.net.Socket") final Closure closure) throws IOException {
return accept(serverSocket, true, closure);
}
|
[
"public",
"static",
"Socket",
"accept",
"(",
"ServerSocket",
"serverSocket",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"\"java.net.Socket\"",
")",
"final",
"Closure",
"closure",
")",
"throws",
"IOException",
"{",
"return",
"accept",
"(",
"serverSocket",
",",
"true",
",",
"closure",
")",
";",
"}"
] |
Accepts a connection and passes the resulting Socket to the closure
which runs in a new Thread.
@param serverSocket a ServerSocket
@param closure a Closure
@return a Socket
@throws IOException if an IOException occurs.
@see java.net.ServerSocket#accept()
@since 1.0
|
[
"Accepts",
"a",
"connection",
"and",
"passes",
"the",
"resulting",
"Socket",
"to",
"the",
"closure",
"which",
"runs",
"in",
"a",
"new",
"Thread",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L161-L163
|
13,027
|
apache/groovy
|
src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
|
SocketGroovyMethods.accept
|
public static Socket accept(ServerSocket serverSocket, final boolean runInANewThread,
@ClosureParams(value=SimpleType.class, options="java.net.Socket") final Closure closure) throws IOException {
final Socket socket = serverSocket.accept();
if (runInANewThread) {
new Thread(new Runnable() {
public void run() {
invokeClosureWithSocket(socket, closure);
}
}).start();
} else {
invokeClosureWithSocket(socket, closure);
}
return socket;
}
|
java
|
public static Socket accept(ServerSocket serverSocket, final boolean runInANewThread,
@ClosureParams(value=SimpleType.class, options="java.net.Socket") final Closure closure) throws IOException {
final Socket socket = serverSocket.accept();
if (runInANewThread) {
new Thread(new Runnable() {
public void run() {
invokeClosureWithSocket(socket, closure);
}
}).start();
} else {
invokeClosureWithSocket(socket, closure);
}
return socket;
}
|
[
"public",
"static",
"Socket",
"accept",
"(",
"ServerSocket",
"serverSocket",
",",
"final",
"boolean",
"runInANewThread",
",",
"@",
"ClosureParams",
"(",
"value",
"=",
"SimpleType",
".",
"class",
",",
"options",
"=",
"\"java.net.Socket\"",
")",
"final",
"Closure",
"closure",
")",
"throws",
"IOException",
"{",
"final",
"Socket",
"socket",
"=",
"serverSocket",
".",
"accept",
"(",
")",
";",
"if",
"(",
"runInANewThread",
")",
"{",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"public",
"void",
"run",
"(",
")",
"{",
"invokeClosureWithSocket",
"(",
"socket",
",",
"closure",
")",
";",
"}",
"}",
")",
".",
"start",
"(",
")",
";",
"}",
"else",
"{",
"invokeClosureWithSocket",
"(",
"socket",
",",
"closure",
")",
";",
"}",
"return",
"socket",
";",
"}"
] |
Accepts a connection and passes the resulting Socket to the closure
which runs in a new Thread or the calling thread, as needed.
@param serverSocket a ServerSocket
@param runInANewThread This flag should be true, if the closure should be invoked in a new thread, else false.
@param closure a Closure
@return a Socket
@throws IOException if an IOException occurs.
@see java.net.ServerSocket#accept()
@since 1.7.6
|
[
"Accepts",
"a",
"connection",
"and",
"passes",
"the",
"resulting",
"Socket",
"to",
"the",
"closure",
"which",
"runs",
"in",
"a",
"new",
"Thread",
"or",
"the",
"calling",
"thread",
"as",
"needed",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L177-L190
|
13,028
|
apache/groovy
|
src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
|
InnerClassVisitor.passThisReference
|
private void passThisReference(ConstructorCallExpression call) {
ClassNode cn = call.getType().redirect();
if (!shouldHandleImplicitThisForInnerClass(cn)) return;
boolean isInStaticContext = true;
if (currentMethod != null)
isInStaticContext = currentMethod.getVariableScope().isInStaticContext();
else if (currentField != null)
isInStaticContext = currentField.isStatic();
else if (processingObjInitStatements)
isInStaticContext = false;
// if constructor call is not in static context, return
if (isInStaticContext) {
// constructor call is in static context and the inner class is non-static - 1st arg is supposed to be
// passed as enclosing "this" instance
//
Expression args = call.getArguments();
if (args instanceof TupleExpression && ((TupleExpression) args).getExpressions().isEmpty()) {
addError("No enclosing instance passed in constructor call of a non-static inner class", call);
}
return;
}
insertThis0ToSuperCall(call, cn);
}
|
java
|
private void passThisReference(ConstructorCallExpression call) {
ClassNode cn = call.getType().redirect();
if (!shouldHandleImplicitThisForInnerClass(cn)) return;
boolean isInStaticContext = true;
if (currentMethod != null)
isInStaticContext = currentMethod.getVariableScope().isInStaticContext();
else if (currentField != null)
isInStaticContext = currentField.isStatic();
else if (processingObjInitStatements)
isInStaticContext = false;
// if constructor call is not in static context, return
if (isInStaticContext) {
// constructor call is in static context and the inner class is non-static - 1st arg is supposed to be
// passed as enclosing "this" instance
//
Expression args = call.getArguments();
if (args instanceof TupleExpression && ((TupleExpression) args).getExpressions().isEmpty()) {
addError("No enclosing instance passed in constructor call of a non-static inner class", call);
}
return;
}
insertThis0ToSuperCall(call, cn);
}
|
[
"private",
"void",
"passThisReference",
"(",
"ConstructorCallExpression",
"call",
")",
"{",
"ClassNode",
"cn",
"=",
"call",
".",
"getType",
"(",
")",
".",
"redirect",
"(",
")",
";",
"if",
"(",
"!",
"shouldHandleImplicitThisForInnerClass",
"(",
"cn",
")",
")",
"return",
";",
"boolean",
"isInStaticContext",
"=",
"true",
";",
"if",
"(",
"currentMethod",
"!=",
"null",
")",
"isInStaticContext",
"=",
"currentMethod",
".",
"getVariableScope",
"(",
")",
".",
"isInStaticContext",
"(",
")",
";",
"else",
"if",
"(",
"currentField",
"!=",
"null",
")",
"isInStaticContext",
"=",
"currentField",
".",
"isStatic",
"(",
")",
";",
"else",
"if",
"(",
"processingObjInitStatements",
")",
"isInStaticContext",
"=",
"false",
";",
"// if constructor call is not in static context, return",
"if",
"(",
"isInStaticContext",
")",
"{",
"// constructor call is in static context and the inner class is non-static - 1st arg is supposed to be ",
"// passed as enclosing \"this\" instance",
"//",
"Expression",
"args",
"=",
"call",
".",
"getArguments",
"(",
")",
";",
"if",
"(",
"args",
"instanceof",
"TupleExpression",
"&&",
"(",
"(",
"TupleExpression",
")",
"args",
")",
".",
"getExpressions",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"addError",
"(",
"\"No enclosing instance passed in constructor call of a non-static inner class\"",
",",
"call",
")",
";",
"}",
"return",
";",
"}",
"insertThis0ToSuperCall",
"(",
"call",
",",
"cn",
")",
";",
"}"
] |
passed as the first argument implicitly.
|
[
"passed",
"as",
"the",
"first",
"argument",
"implicitly",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java#L241-L266
|
13,029
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.newInstance
|
public static Sql newInstance(String url) throws SQLException {
Connection connection = DriverManager.getConnection(url);
return new Sql(connection);
}
|
java
|
public static Sql newInstance(String url) throws SQLException {
Connection connection = DriverManager.getConnection(url);
return new Sql(connection);
}
|
[
"public",
"static",
"Sql",
"newInstance",
"(",
"String",
"url",
")",
"throws",
"SQLException",
"{",
"Connection",
"connection",
"=",
"DriverManager",
".",
"getConnection",
"(",
"url",
")",
";",
"return",
"new",
"Sql",
"(",
"connection",
")",
";",
"}"
] |
Creates a new Sql instance given a JDBC connection URL.
@param url a database url of the form
<code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
@return a new Sql instance with a connection
@throws SQLException if a database access error occurs
|
[
"Creates",
"a",
"new",
"Sql",
"instance",
"given",
"a",
"JDBC",
"connection",
"URL",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L282-L285
|
13,030
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.newInstance
|
public static Sql newInstance(String url, String user, String password) throws SQLException {
Connection connection = DriverManager.getConnection(url, user, password);
return new Sql(connection);
}
|
java
|
public static Sql newInstance(String url, String user, String password) throws SQLException {
Connection connection = DriverManager.getConnection(url, user, password);
return new Sql(connection);
}
|
[
"public",
"static",
"Sql",
"newInstance",
"(",
"String",
"url",
",",
"String",
"user",
",",
"String",
"password",
")",
"throws",
"SQLException",
"{",
"Connection",
"connection",
"=",
"DriverManager",
".",
"getConnection",
"(",
"url",
",",
"user",
",",
"password",
")",
";",
"return",
"new",
"Sql",
"(",
"connection",
")",
";",
"}"
] |
Creates a new Sql instance given a JDBC connection URL,
a username and a password.
@param url a database url of the form
<code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
@param user the database user on whose behalf the connection
is being made
@param password the user's password
@return a new Sql instance with a connection
@throws SQLException if a database access error occurs
|
[
"Creates",
"a",
"new",
"Sql",
"instance",
"given",
"a",
"JDBC",
"connection",
"URL",
"a",
"username",
"and",
"a",
"password",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L393-L396
|
13,031
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.newInstance
|
public static Sql newInstance(String url, String user, String password, String driverClassName)
throws SQLException, ClassNotFoundException {
loadDriver(driverClassName);
return newInstance(url, user, password);
}
|
java
|
public static Sql newInstance(String url, String user, String password, String driverClassName)
throws SQLException, ClassNotFoundException {
loadDriver(driverClassName);
return newInstance(url, user, password);
}
|
[
"public",
"static",
"Sql",
"newInstance",
"(",
"String",
"url",
",",
"String",
"user",
",",
"String",
"password",
",",
"String",
"driverClassName",
")",
"throws",
"SQLException",
",",
"ClassNotFoundException",
"{",
"loadDriver",
"(",
"driverClassName",
")",
";",
"return",
"newInstance",
"(",
"url",
",",
"user",
",",
"password",
")",
";",
"}"
] |
Creates a new Sql instance given a JDBC connection URL,
a username, a password and a driver class name.
@param url a database url of the form
<code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
@param user the database user on whose behalf the connection
is being made
@param password the user's password
@param driverClassName the fully qualified class name of the driver class
@return a new Sql instance with a connection
@throws SQLException if a database access error occurs
@throws ClassNotFoundException if the driver class cannot be found or loaded
|
[
"Creates",
"a",
"new",
"Sql",
"instance",
"given",
"a",
"JDBC",
"connection",
"URL",
"a",
"username",
"a",
"password",
"and",
"a",
"driver",
"class",
"name",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L431-L435
|
13,032
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.newInstance
|
public static Sql newInstance(String url, String driverClassName) throws SQLException, ClassNotFoundException {
loadDriver(driverClassName);
return newInstance(url);
}
|
java
|
public static Sql newInstance(String url, String driverClassName) throws SQLException, ClassNotFoundException {
loadDriver(driverClassName);
return newInstance(url);
}
|
[
"public",
"static",
"Sql",
"newInstance",
"(",
"String",
"url",
",",
"String",
"driverClassName",
")",
"throws",
"SQLException",
",",
"ClassNotFoundException",
"{",
"loadDriver",
"(",
"driverClassName",
")",
";",
"return",
"newInstance",
"(",
"url",
")",
";",
"}"
] |
Creates a new Sql instance given a JDBC connection URL
and a driver class name.
@param url a database url of the form
<code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
@param driverClassName the fully qualified class name of the driver class
@return a new Sql instance with a connection
@throws SQLException if a database access error occurs
@throws ClassNotFoundException if the driver class cannot be found or loaded
|
[
"Creates",
"a",
"new",
"Sql",
"instance",
"given",
"a",
"JDBC",
"connection",
"URL",
"and",
"a",
"driver",
"class",
"name",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L470-L473
|
13,033
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.loadDriver
|
public static void loadDriver(String driverClassName) throws ClassNotFoundException {
// let's try the thread context class loader first
// let's try to use the system class loader
try {
Class.forName(driverClassName);
}
catch (ClassNotFoundException e) {
try {
Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
}
catch (ClassNotFoundException e2) {
// now let's try the classloader which loaded us
try {
Sql.class.getClassLoader().loadClass(driverClassName);
}
catch (ClassNotFoundException e3) {
throw e;
}
}
}
}
|
java
|
public static void loadDriver(String driverClassName) throws ClassNotFoundException {
// let's try the thread context class loader first
// let's try to use the system class loader
try {
Class.forName(driverClassName);
}
catch (ClassNotFoundException e) {
try {
Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
}
catch (ClassNotFoundException e2) {
// now let's try the classloader which loaded us
try {
Sql.class.getClassLoader().loadClass(driverClassName);
}
catch (ClassNotFoundException e3) {
throw e;
}
}
}
}
|
[
"public",
"static",
"void",
"loadDriver",
"(",
"String",
"driverClassName",
")",
"throws",
"ClassNotFoundException",
"{",
"// let's try the thread context class loader first",
"// let's try to use the system class loader",
"try",
"{",
"Class",
".",
"forName",
"(",
"driverClassName",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"try",
"{",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
".",
"loadClass",
"(",
"driverClassName",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e2",
")",
"{",
"// now let's try the classloader which loaded us",
"try",
"{",
"Sql",
".",
"class",
".",
"getClassLoader",
"(",
")",
".",
"loadClass",
"(",
"driverClassName",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e3",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"}",
"}"
] |
Attempts to load the JDBC driver on the thread, current or system class
loaders
@param driverClassName the fully qualified class name of the driver class
@throws ClassNotFoundException if the class cannot be found or loaded
|
[
"Attempts",
"to",
"load",
"the",
"JDBC",
"driver",
"on",
"the",
"thread",
"current",
"or",
"system",
"class",
"loaders"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L724-L744
|
13,034
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.in
|
public static InParameter in(final int type, final Object value) {
return new InParameter() {
public int getType() {
return type;
}
public Object getValue() {
return value;
}
};
}
|
java
|
public static InParameter in(final int type, final Object value) {
return new InParameter() {
public int getType() {
return type;
}
public Object getValue() {
return value;
}
};
}
|
[
"public",
"static",
"InParameter",
"in",
"(",
"final",
"int",
"type",
",",
"final",
"Object",
"value",
")",
"{",
"return",
"new",
"InParameter",
"(",
")",
"{",
"public",
"int",
"getType",
"(",
")",
"{",
"return",
"type",
";",
"}",
"public",
"Object",
"getValue",
"(",
")",
"{",
"return",
"value",
";",
"}",
"}",
";",
"}"
] |
Create a new InParameter
@param type the JDBC data type
@param value the object value
@return an InParameter
|
[
"Create",
"a",
"new",
"InParameter"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L819-L829
|
13,035
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.inout
|
public static InOutParameter inout(final InParameter in) {
return new InOutParameter() {
public int getType() {
return in.getType();
}
public Object getValue() {
return in.getValue();
}
};
}
|
java
|
public static InOutParameter inout(final InParameter in) {
return new InOutParameter() {
public int getType() {
return in.getType();
}
public Object getValue() {
return in.getValue();
}
};
}
|
[
"public",
"static",
"InOutParameter",
"inout",
"(",
"final",
"InParameter",
"in",
")",
"{",
"return",
"new",
"InOutParameter",
"(",
")",
"{",
"public",
"int",
"getType",
"(",
")",
"{",
"return",
"in",
".",
"getType",
"(",
")",
";",
"}",
"public",
"Object",
"getValue",
"(",
")",
"{",
"return",
"in",
".",
"getValue",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Create an inout parameter using this in parameter.
@param in the InParameter of interest
@return the resulting InOutParameter
|
[
"Create",
"an",
"inout",
"parameter",
"using",
"this",
"in",
"parameter",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L851-L861
|
13,036
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.commit
|
public void commit() throws SQLException {
if (useConnection == null) {
LOG.info("Commit operation not supported when using datasets unless using withTransaction or cacheConnection - attempt to commit ignored");
return;
}
try {
useConnection.commit();
} catch (SQLException e) {
LOG.warning("Caught exception committing connection: " + e.getMessage());
throw e;
}
}
|
java
|
public void commit() throws SQLException {
if (useConnection == null) {
LOG.info("Commit operation not supported when using datasets unless using withTransaction or cacheConnection - attempt to commit ignored");
return;
}
try {
useConnection.commit();
} catch (SQLException e) {
LOG.warning("Caught exception committing connection: " + e.getMessage());
throw e;
}
}
|
[
"public",
"void",
"commit",
"(",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"useConnection",
"==",
"null",
")",
"{",
"LOG",
".",
"info",
"(",
"\"Commit operation not supported when using datasets unless using withTransaction or cacheConnection - attempt to commit ignored\"",
")",
";",
"return",
";",
"}",
"try",
"{",
"useConnection",
".",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"LOG",
".",
"warning",
"(",
"\"Caught exception committing connection: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"throw",
"e",
";",
"}",
"}"
] |
If this SQL object was created with a Connection then this method commits
the connection. If this SQL object was created from a DataSource then
this method does nothing.
@throws SQLException if a database access error occurs
|
[
"If",
"this",
"SQL",
"object",
"was",
"created",
"with",
"a",
"Connection",
"then",
"this",
"method",
"commits",
"the",
"connection",
".",
"If",
"this",
"SQL",
"object",
"was",
"created",
"from",
"a",
"DataSource",
"then",
"this",
"method",
"does",
"nothing",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L3441-L3452
|
13,037
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.cacheConnection
|
public void cacheConnection(Closure closure) throws SQLException {
boolean savedCacheConnection = cacheConnection;
cacheConnection = true;
Connection connection = null;
try {
connection = createConnection();
callClosurePossiblyWithConnection(closure, connection);
} finally {
cacheConnection = false;
closeResources(connection, null);
cacheConnection = savedCacheConnection;
if (dataSource != null && !cacheConnection) {
useConnection = null;
}
}
}
|
java
|
public void cacheConnection(Closure closure) throws SQLException {
boolean savedCacheConnection = cacheConnection;
cacheConnection = true;
Connection connection = null;
try {
connection = createConnection();
callClosurePossiblyWithConnection(closure, connection);
} finally {
cacheConnection = false;
closeResources(connection, null);
cacheConnection = savedCacheConnection;
if (dataSource != null && !cacheConnection) {
useConnection = null;
}
}
}
|
[
"public",
"void",
"cacheConnection",
"(",
"Closure",
"closure",
")",
"throws",
"SQLException",
"{",
"boolean",
"savedCacheConnection",
"=",
"cacheConnection",
";",
"cacheConnection",
"=",
"true",
";",
"Connection",
"connection",
"=",
"null",
";",
"try",
"{",
"connection",
"=",
"createConnection",
"(",
")",
";",
"callClosurePossiblyWithConnection",
"(",
"closure",
",",
"connection",
")",
";",
"}",
"finally",
"{",
"cacheConnection",
"=",
"false",
";",
"closeResources",
"(",
"connection",
",",
"null",
")",
";",
"cacheConnection",
"=",
"savedCacheConnection",
";",
"if",
"(",
"dataSource",
"!=",
"null",
"&&",
"!",
"cacheConnection",
")",
"{",
"useConnection",
"=",
"null",
";",
"}",
"}",
"}"
] |
Caches the connection used while the closure is active.
If the closure takes a single argument, it will be called
with the connection, otherwise it will be called with no arguments.
@param closure the given closure
@throws SQLException if a database error occurs
|
[
"Caches",
"the",
"connection",
"used",
"while",
"the",
"closure",
"is",
"active",
".",
"If",
"the",
"closure",
"takes",
"a",
"single",
"argument",
"it",
"will",
"be",
"called",
"with",
"the",
"connection",
"otherwise",
"it",
"will",
"be",
"called",
"with",
"no",
"arguments",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L3543-L3558
|
13,038
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.executePreparedQuery
|
protected final ResultSet executePreparedQuery(String sql, List<Object> params)
throws SQLException {
AbstractQueryCommand command = createPreparedQueryCommand(sql, params);
ResultSet rs = null;
try {
rs = command.execute();
} finally {
command.closeResources();
}
return rs;
}
|
java
|
protected final ResultSet executePreparedQuery(String sql, List<Object> params)
throws SQLException {
AbstractQueryCommand command = createPreparedQueryCommand(sql, params);
ResultSet rs = null;
try {
rs = command.execute();
} finally {
command.closeResources();
}
return rs;
}
|
[
"protected",
"final",
"ResultSet",
"executePreparedQuery",
"(",
"String",
"sql",
",",
"List",
"<",
"Object",
">",
"params",
")",
"throws",
"SQLException",
"{",
"AbstractQueryCommand",
"command",
"=",
"createPreparedQueryCommand",
"(",
"sql",
",",
"params",
")",
";",
"ResultSet",
"rs",
"=",
"null",
";",
"try",
"{",
"rs",
"=",
"command",
".",
"execute",
"(",
")",
";",
"}",
"finally",
"{",
"command",
".",
"closeResources",
"(",
")",
";",
"}",
"return",
"rs",
";",
"}"
] |
Useful helper method which handles resource management when executing a
prepared query which returns a result set.
Derived classes of Sql can override "createPreparedQueryCommand" and then
call this method to access the ResultSet returned from the provided query.
@param sql query to execute
@param params parameters matching question mark placeholders in the query
@return the resulting ResultSet
@throws SQLException if a database error occurs
|
[
"Useful",
"helper",
"method",
"which",
"handles",
"resource",
"management",
"when",
"executing",
"a",
"prepared",
"query",
"which",
"returns",
"a",
"result",
"set",
".",
"Derived",
"classes",
"of",
"Sql",
"can",
"override",
"createPreparedQueryCommand",
"and",
"then",
"call",
"this",
"method",
"to",
"access",
"the",
"ResultSet",
"returned",
"from",
"the",
"provided",
"query",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L3932-L3942
|
13,039
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.asSql
|
protected String asSql(GString gstring, List<Object> values) {
String[] strings = gstring.getStrings();
if (strings.length <= 0) {
throw new IllegalArgumentException("No SQL specified in GString: " + gstring);
}
boolean nulls = false;
StringBuilder buffer = new StringBuilder();
boolean warned = false;
Iterator<Object> iter = values.iterator();
for (int i = 0; i < strings.length; i++) {
String text = strings[i];
if (text != null) {
buffer.append(text);
}
if (iter.hasNext()) {
Object value = iter.next();
if (value != null) {
if (value instanceof ExpandedVariable) {
buffer.append(((ExpandedVariable) value).getObject());
iter.remove();
} else {
boolean validBinding = true;
if (i < strings.length - 1) {
String nextText = strings[i + 1];
if ((text.endsWith("\"") || text.endsWith("'")) && (nextText.startsWith("'") || nextText.startsWith("\""))) {
if (!warned) {
LOG.warning("In Groovy SQL please do not use quotes around dynamic expressions " +
"(which start with $) as this means we cannot use a JDBC PreparedStatement " +
"and so is a security hole. Groovy has worked around your mistake but the security hole is still there. " +
"The expression so far is: " + buffer.toString() + "?" + nextText);
warned = true;
}
buffer.append(value);
iter.remove();
validBinding = false;
}
}
if (validBinding) {
buffer.append("?");
}
}
} else {
nulls = true;
iter.remove();
buffer.append("?'\"?"); // will replace these with nullish values
}
}
}
String sql = buffer.toString();
if (nulls) {
sql = nullify(sql);
}
return sql;
}
|
java
|
protected String asSql(GString gstring, List<Object> values) {
String[] strings = gstring.getStrings();
if (strings.length <= 0) {
throw new IllegalArgumentException("No SQL specified in GString: " + gstring);
}
boolean nulls = false;
StringBuilder buffer = new StringBuilder();
boolean warned = false;
Iterator<Object> iter = values.iterator();
for (int i = 0; i < strings.length; i++) {
String text = strings[i];
if (text != null) {
buffer.append(text);
}
if (iter.hasNext()) {
Object value = iter.next();
if (value != null) {
if (value instanceof ExpandedVariable) {
buffer.append(((ExpandedVariable) value).getObject());
iter.remove();
} else {
boolean validBinding = true;
if (i < strings.length - 1) {
String nextText = strings[i + 1];
if ((text.endsWith("\"") || text.endsWith("'")) && (nextText.startsWith("'") || nextText.startsWith("\""))) {
if (!warned) {
LOG.warning("In Groovy SQL please do not use quotes around dynamic expressions " +
"(which start with $) as this means we cannot use a JDBC PreparedStatement " +
"and so is a security hole. Groovy has worked around your mistake but the security hole is still there. " +
"The expression so far is: " + buffer.toString() + "?" + nextText);
warned = true;
}
buffer.append(value);
iter.remove();
validBinding = false;
}
}
if (validBinding) {
buffer.append("?");
}
}
} else {
nulls = true;
iter.remove();
buffer.append("?'\"?"); // will replace these with nullish values
}
}
}
String sql = buffer.toString();
if (nulls) {
sql = nullify(sql);
}
return sql;
}
|
[
"protected",
"String",
"asSql",
"(",
"GString",
"gstring",
",",
"List",
"<",
"Object",
">",
"values",
")",
"{",
"String",
"[",
"]",
"strings",
"=",
"gstring",
".",
"getStrings",
"(",
")",
";",
"if",
"(",
"strings",
".",
"length",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No SQL specified in GString: \"",
"+",
"gstring",
")",
";",
"}",
"boolean",
"nulls",
"=",
"false",
";",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"boolean",
"warned",
"=",
"false",
";",
"Iterator",
"<",
"Object",
">",
"iter",
"=",
"values",
".",
"iterator",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strings",
".",
"length",
";",
"i",
"++",
")",
"{",
"String",
"text",
"=",
"strings",
"[",
"i",
"]",
";",
"if",
"(",
"text",
"!=",
"null",
")",
"{",
"buffer",
".",
"append",
"(",
"text",
")",
";",
"}",
"if",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"Object",
"value",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"if",
"(",
"value",
"instanceof",
"ExpandedVariable",
")",
"{",
"buffer",
".",
"append",
"(",
"(",
"(",
"ExpandedVariable",
")",
"value",
")",
".",
"getObject",
"(",
")",
")",
";",
"iter",
".",
"remove",
"(",
")",
";",
"}",
"else",
"{",
"boolean",
"validBinding",
"=",
"true",
";",
"if",
"(",
"i",
"<",
"strings",
".",
"length",
"-",
"1",
")",
"{",
"String",
"nextText",
"=",
"strings",
"[",
"i",
"+",
"1",
"]",
";",
"if",
"(",
"(",
"text",
".",
"endsWith",
"(",
"\"\\\"\"",
")",
"||",
"text",
".",
"endsWith",
"(",
"\"'\"",
")",
")",
"&&",
"(",
"nextText",
".",
"startsWith",
"(",
"\"'\"",
")",
"||",
"nextText",
".",
"startsWith",
"(",
"\"\\\"\"",
")",
")",
")",
"{",
"if",
"(",
"!",
"warned",
")",
"{",
"LOG",
".",
"warning",
"(",
"\"In Groovy SQL please do not use quotes around dynamic expressions \"",
"+",
"\"(which start with $) as this means we cannot use a JDBC PreparedStatement \"",
"+",
"\"and so is a security hole. Groovy has worked around your mistake but the security hole is still there. \"",
"+",
"\"The expression so far is: \"",
"+",
"buffer",
".",
"toString",
"(",
")",
"+",
"\"?\"",
"+",
"nextText",
")",
";",
"warned",
"=",
"true",
";",
"}",
"buffer",
".",
"append",
"(",
"value",
")",
";",
"iter",
".",
"remove",
"(",
")",
";",
"validBinding",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"validBinding",
")",
"{",
"buffer",
".",
"append",
"(",
"\"?\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"nulls",
"=",
"true",
";",
"iter",
".",
"remove",
"(",
")",
";",
"buffer",
".",
"append",
"(",
"\"?'\\\"?\"",
")",
";",
"// will replace these with nullish values",
"}",
"}",
"}",
"String",
"sql",
"=",
"buffer",
".",
"toString",
"(",
")",
";",
"if",
"(",
"nulls",
")",
"{",
"sql",
"=",
"nullify",
"(",
"sql",
")",
";",
"}",
"return",
"sql",
";",
"}"
] |
Hook to allow derived classes to override sql generation from GStrings.
@param gstring a GString containing the SQL query with embedded params
@param values the values to embed
@return the SQL version of the given query using ? instead of any parameter
@see #expand(Object)
|
[
"Hook",
"to",
"allow",
"derived",
"classes",
"to",
"override",
"sql",
"generation",
"from",
"GStrings",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4007-L4060
|
13,040
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.nullify
|
protected String nullify(String sql) {
/*
* Some drivers (Oracle classes12.zip) have difficulty resolving data
* type if setObject(null). We will modify the query to pass 'null', 'is
* null', and 'is not null'
*/
//could be more efficient by compiling expressions in advance.
int firstWhere = findWhereKeyword(sql);
if (firstWhere >= 0) {
Pattern[] patterns = {Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
Pattern.compile("(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),};
String[] replacements = {"$1 is not $2null$3", "$1 is not $2null$3", "$1 is $2null$3",};
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(sql);
while (matcher.matches()) {
sql = matcher.replaceAll(replacements[i]);
matcher = patterns[i].matcher(sql);
}
}
}
return sql.replaceAll("\\?'\"\\?", "null");
}
|
java
|
protected String nullify(String sql) {
/*
* Some drivers (Oracle classes12.zip) have difficulty resolving data
* type if setObject(null). We will modify the query to pass 'null', 'is
* null', and 'is not null'
*/
//could be more efficient by compiling expressions in advance.
int firstWhere = findWhereKeyword(sql);
if (firstWhere >= 0) {
Pattern[] patterns = {Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
Pattern.compile("(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),};
String[] replacements = {"$1 is not $2null$3", "$1 is not $2null$3", "$1 is $2null$3",};
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(sql);
while (matcher.matches()) {
sql = matcher.replaceAll(replacements[i]);
matcher = patterns[i].matcher(sql);
}
}
}
return sql.replaceAll("\\?'\"\\?", "null");
}
|
[
"protected",
"String",
"nullify",
"(",
"String",
"sql",
")",
"{",
"/*\n * Some drivers (Oracle classes12.zip) have difficulty resolving data\n * type if setObject(null). We will modify the query to pass 'null', 'is\n * null', and 'is not null'\n */",
"//could be more efficient by compiling expressions in advance.",
"int",
"firstWhere",
"=",
"findWhereKeyword",
"(",
"sql",
")",
";",
"if",
"(",
"firstWhere",
">=",
"0",
")",
"{",
"Pattern",
"[",
"]",
"patterns",
"=",
"{",
"Pattern",
".",
"compile",
"(",
"\"(?is)^(.{\"",
"+",
"firstWhere",
"+",
"\"}.*?)!=\\\\s{0,1}(\\\\s*)\\\\?'\\\"\\\\?(.*)\"",
")",
",",
"Pattern",
".",
"compile",
"(",
"\"(?is)^(.{\"",
"+",
"firstWhere",
"+",
"\"}.*?)<>\\\\s{0,1}(\\\\s*)\\\\?'\\\"\\\\?(.*)\"",
")",
",",
"Pattern",
".",
"compile",
"(",
"\"(?is)^(.{\"",
"+",
"firstWhere",
"+",
"\"}.*?[^<>])=\\\\s{0,1}(\\\\s*)\\\\?'\\\"\\\\?(.*)\"",
")",
",",
"}",
";",
"String",
"[",
"]",
"replacements",
"=",
"{",
"\"$1 is not $2null$3\"",
",",
"\"$1 is not $2null$3\"",
",",
"\"$1 is $2null$3\"",
",",
"}",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"patterns",
".",
"length",
";",
"i",
"++",
")",
"{",
"Matcher",
"matcher",
"=",
"patterns",
"[",
"i",
"]",
".",
"matcher",
"(",
"sql",
")",
";",
"while",
"(",
"matcher",
".",
"matches",
"(",
")",
")",
"{",
"sql",
"=",
"matcher",
".",
"replaceAll",
"(",
"replacements",
"[",
"i",
"]",
")",
";",
"matcher",
"=",
"patterns",
"[",
"i",
"]",
".",
"matcher",
"(",
"sql",
")",
";",
"}",
"}",
"}",
"return",
"sql",
".",
"replaceAll",
"(",
"\"\\\\?'\\\"\\\\?\"",
",",
"\"null\"",
")",
";",
"}"
] |
Hook to allow derived classes to override null handling.
Default behavior is to replace ?'"? references with NULLish
@param sql the SQL statement
@return the modified SQL String
|
[
"Hook",
"to",
"allow",
"derived",
"classes",
"to",
"override",
"null",
"handling",
".",
"Default",
"behavior",
"is",
"to",
"replace",
"?",
"?",
"references",
"with",
"NULLish"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4069-L4091
|
13,041
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.findWhereKeyword
|
protected int findWhereKeyword(String sql) {
char[] chars = sql.toLowerCase().toCharArray();
char[] whereChars = "where".toCharArray();
int i = 0;
boolean inString = false; //TODO: Cater for comments?
int inWhere = 0;
while (i < chars.length) {
switch (chars[i]) {
case '\'':
inString = !inString;
break;
default:
if (!inString && chars[i] == whereChars[inWhere]) {
inWhere++;
if (inWhere == whereChars.length) {
return i;
}
} else {
inWhere = 0;
}
}
i++;
}
return -1;
}
|
java
|
protected int findWhereKeyword(String sql) {
char[] chars = sql.toLowerCase().toCharArray();
char[] whereChars = "where".toCharArray();
int i = 0;
boolean inString = false; //TODO: Cater for comments?
int inWhere = 0;
while (i < chars.length) {
switch (chars[i]) {
case '\'':
inString = !inString;
break;
default:
if (!inString && chars[i] == whereChars[inWhere]) {
inWhere++;
if (inWhere == whereChars.length) {
return i;
}
} else {
inWhere = 0;
}
}
i++;
}
return -1;
}
|
[
"protected",
"int",
"findWhereKeyword",
"(",
"String",
"sql",
")",
"{",
"char",
"[",
"]",
"chars",
"=",
"sql",
".",
"toLowerCase",
"(",
")",
".",
"toCharArray",
"(",
")",
";",
"char",
"[",
"]",
"whereChars",
"=",
"\"where\"",
".",
"toCharArray",
"(",
")",
";",
"int",
"i",
"=",
"0",
";",
"boolean",
"inString",
"=",
"false",
";",
"//TODO: Cater for comments?",
"int",
"inWhere",
"=",
"0",
";",
"while",
"(",
"i",
"<",
"chars",
".",
"length",
")",
"{",
"switch",
"(",
"chars",
"[",
"i",
"]",
")",
"{",
"case",
"'",
"'",
":",
"inString",
"=",
"!",
"inString",
";",
"break",
";",
"default",
":",
"if",
"(",
"!",
"inString",
"&&",
"chars",
"[",
"i",
"]",
"==",
"whereChars",
"[",
"inWhere",
"]",
")",
"{",
"inWhere",
"++",
";",
"if",
"(",
"inWhere",
"==",
"whereChars",
".",
"length",
")",
"{",
"return",
"i",
";",
"}",
"}",
"else",
"{",
"inWhere",
"=",
"0",
";",
"}",
"}",
"i",
"++",
";",
"}",
"return",
"-",
"1",
";",
"}"
] |
Hook to allow derived classes to override where clause sniffing.
Default behavior is to find the first 'where' keyword in the sql
doing simple avoidance of the word 'where' within quotes.
@param sql the SQL statement
@return the index of the found keyword or -1 if not found
|
[
"Hook",
"to",
"allow",
"derived",
"classes",
"to",
"override",
"where",
"clause",
"sniffing",
".",
"Default",
"behavior",
"is",
"to",
"find",
"the",
"first",
"where",
"keyword",
"in",
"the",
"sql",
"doing",
"simple",
"avoidance",
"of",
"the",
"word",
"where",
"within",
"quotes",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4101-L4125
|
13,042
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.getParameters
|
protected List<Object> getParameters(GString gstring) {
return new ArrayList<Object>(Arrays.asList(gstring.getValues()));
}
|
java
|
protected List<Object> getParameters(GString gstring) {
return new ArrayList<Object>(Arrays.asList(gstring.getValues()));
}
|
[
"protected",
"List",
"<",
"Object",
">",
"getParameters",
"(",
"GString",
"gstring",
")",
"{",
"return",
"new",
"ArrayList",
"<",
"Object",
">",
"(",
"Arrays",
".",
"asList",
"(",
"gstring",
".",
"getValues",
"(",
")",
")",
")",
";",
"}"
] |
Hook to allow derived classes to override behavior associated with
extracting params from a GString.
@param gstring a GString containing the SQL query with embedded params
@return extracts the parameters from the expression as a List
@see #expand(Object)
|
[
"Hook",
"to",
"allow",
"derived",
"classes",
"to",
"override",
"behavior",
"associated",
"with",
"extracting",
"params",
"from",
"a",
"GString",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4135-L4137
|
13,043
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.setObject
|
protected void setObject(PreparedStatement statement, int i, Object value)
throws SQLException {
if (value instanceof InParameter || value instanceof OutParameter) {
if (value instanceof InParameter) {
InParameter in = (InParameter) value;
Object val = in.getValue();
if (null == val) {
statement.setNull(i, in.getType());
} else {
statement.setObject(i, val, in.getType());
}
}
if (value instanceof OutParameter) {
try {
OutParameter out = (OutParameter) value;
((CallableStatement) statement).registerOutParameter(i, out.getType());
} catch (ClassCastException e) {
throw new SQLException("Cannot register out parameter.");
}
}
} else {
try {
statement.setObject(i, value);
} catch (SQLException e) {
if (value == null) {
SQLException se = new SQLException("Your JDBC driver may not support null arguments for setObject. Consider using Groovy's InParameter feature." +
(e.getMessage() == null ? "" : " (CAUSE: " + e.getMessage() + ")"));
se.setNextException(e);
throw se;
} else {
throw e;
}
}
}
}
|
java
|
protected void setObject(PreparedStatement statement, int i, Object value)
throws SQLException {
if (value instanceof InParameter || value instanceof OutParameter) {
if (value instanceof InParameter) {
InParameter in = (InParameter) value;
Object val = in.getValue();
if (null == val) {
statement.setNull(i, in.getType());
} else {
statement.setObject(i, val, in.getType());
}
}
if (value instanceof OutParameter) {
try {
OutParameter out = (OutParameter) value;
((CallableStatement) statement).registerOutParameter(i, out.getType());
} catch (ClassCastException e) {
throw new SQLException("Cannot register out parameter.");
}
}
} else {
try {
statement.setObject(i, value);
} catch (SQLException e) {
if (value == null) {
SQLException se = new SQLException("Your JDBC driver may not support null arguments for setObject. Consider using Groovy's InParameter feature." +
(e.getMessage() == null ? "" : " (CAUSE: " + e.getMessage() + ")"));
se.setNextException(e);
throw se;
} else {
throw e;
}
}
}
}
|
[
"protected",
"void",
"setObject",
"(",
"PreparedStatement",
"statement",
",",
"int",
"i",
",",
"Object",
"value",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"value",
"instanceof",
"InParameter",
"||",
"value",
"instanceof",
"OutParameter",
")",
"{",
"if",
"(",
"value",
"instanceof",
"InParameter",
")",
"{",
"InParameter",
"in",
"=",
"(",
"InParameter",
")",
"value",
";",
"Object",
"val",
"=",
"in",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"null",
"==",
"val",
")",
"{",
"statement",
".",
"setNull",
"(",
"i",
",",
"in",
".",
"getType",
"(",
")",
")",
";",
"}",
"else",
"{",
"statement",
".",
"setObject",
"(",
"i",
",",
"val",
",",
"in",
".",
"getType",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"value",
"instanceof",
"OutParameter",
")",
"{",
"try",
"{",
"OutParameter",
"out",
"=",
"(",
"OutParameter",
")",
"value",
";",
"(",
"(",
"CallableStatement",
")",
"statement",
")",
".",
"registerOutParameter",
"(",
"i",
",",
"out",
".",
"getType",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ClassCastException",
"e",
")",
"{",
"throw",
"new",
"SQLException",
"(",
"\"Cannot register out parameter.\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"try",
"{",
"statement",
".",
"setObject",
"(",
"i",
",",
"value",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"SQLException",
"se",
"=",
"new",
"SQLException",
"(",
"\"Your JDBC driver may not support null arguments for setObject. Consider using Groovy's InParameter feature.\"",
"+",
"(",
"e",
".",
"getMessage",
"(",
")",
"==",
"null",
"?",
"\"\"",
":",
"\" (CAUSE: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
"+",
"\")\"",
")",
")",
";",
"se",
".",
"setNextException",
"(",
"e",
")",
";",
"throw",
"se",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}",
"}"
] |
Strategy method allowing derived classes to handle types differently
such as for CLOBs etc.
@param statement the statement of interest
@param i the index of the object of interest
@param value the new object value
@throws SQLException if a database access error occurs
|
[
"Strategy",
"method",
"allowing",
"derived",
"classes",
"to",
"handle",
"types",
"differently",
"such",
"as",
"for",
"CLOBs",
"etc",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4184-L4218
|
13,044
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.createConnection
|
protected Connection createConnection() throws SQLException {
if ((cacheStatements || cacheConnection) && useConnection != null) {
return useConnection;
}
if (dataSource != null) {
// Use a doPrivileged here as many different properties need to be
// read, and the policy shouldn't have to list them all.
Connection con;
try {
con = AccessController.doPrivileged(new PrivilegedExceptionAction<Connection>() {
public Connection run() throws SQLException {
return dataSource.getConnection();
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof SQLException) {
throw (SQLException) e;
} else {
throw (RuntimeException) e;
}
}
if (cacheStatements || cacheConnection) {
useConnection = con;
}
return con;
}
return useConnection;
}
|
java
|
protected Connection createConnection() throws SQLException {
if ((cacheStatements || cacheConnection) && useConnection != null) {
return useConnection;
}
if (dataSource != null) {
// Use a doPrivileged here as many different properties need to be
// read, and the policy shouldn't have to list them all.
Connection con;
try {
con = AccessController.doPrivileged(new PrivilegedExceptionAction<Connection>() {
public Connection run() throws SQLException {
return dataSource.getConnection();
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof SQLException) {
throw (SQLException) e;
} else {
throw (RuntimeException) e;
}
}
if (cacheStatements || cacheConnection) {
useConnection = con;
}
return con;
}
return useConnection;
}
|
[
"protected",
"Connection",
"createConnection",
"(",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"(",
"cacheStatements",
"||",
"cacheConnection",
")",
"&&",
"useConnection",
"!=",
"null",
")",
"{",
"return",
"useConnection",
";",
"}",
"if",
"(",
"dataSource",
"!=",
"null",
")",
"{",
"// Use a doPrivileged here as many different properties need to be",
"// read, and the policy shouldn't have to list them all.",
"Connection",
"con",
";",
"try",
"{",
"con",
"=",
"AccessController",
".",
"doPrivileged",
"(",
"new",
"PrivilegedExceptionAction",
"<",
"Connection",
">",
"(",
")",
"{",
"public",
"Connection",
"run",
"(",
")",
"throws",
"SQLException",
"{",
"return",
"dataSource",
".",
"getConnection",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"PrivilegedActionException",
"pae",
")",
"{",
"Exception",
"e",
"=",
"pae",
".",
"getException",
"(",
")",
";",
"if",
"(",
"e",
"instanceof",
"SQLException",
")",
"{",
"throw",
"(",
"SQLException",
")",
"e",
";",
"}",
"else",
"{",
"throw",
"(",
"RuntimeException",
")",
"e",
";",
"}",
"}",
"if",
"(",
"cacheStatements",
"||",
"cacheConnection",
")",
"{",
"useConnection",
"=",
"con",
";",
"}",
"return",
"con",
";",
"}",
"return",
"useConnection",
";",
"}"
] |
An extension point allowing derived classes to change the behavior of
connection creation. The default behavior is to either use the
supplied connection or obtain it from the supplied datasource.
@return the connection associated with this Sql
@throws java.sql.SQLException if a SQL error occurs
|
[
"An",
"extension",
"point",
"allowing",
"derived",
"classes",
"to",
"change",
"the",
"behavior",
"of",
"connection",
"creation",
".",
"The",
"default",
"behavior",
"is",
"to",
"either",
"use",
"the",
"supplied",
"connection",
"or",
"obtain",
"it",
"from",
"the",
"supplied",
"datasource",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4228-L4256
|
13,045
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.closeResources
|
protected void closeResources(Connection connection, Statement statement, ResultSet results) {
if (results != null) {
try {
results.close();
} catch (SQLException e) {
LOG.finest("Caught exception closing resultSet: " + e.getMessage() + " - continuing");
}
}
closeResources(connection, statement);
}
|
java
|
protected void closeResources(Connection connection, Statement statement, ResultSet results) {
if (results != null) {
try {
results.close();
} catch (SQLException e) {
LOG.finest("Caught exception closing resultSet: " + e.getMessage() + " - continuing");
}
}
closeResources(connection, statement);
}
|
[
"protected",
"void",
"closeResources",
"(",
"Connection",
"connection",
",",
"Statement",
"statement",
",",
"ResultSet",
"results",
")",
"{",
"if",
"(",
"results",
"!=",
"null",
")",
"{",
"try",
"{",
"results",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"LOG",
".",
"finest",
"(",
"\"Caught exception closing resultSet: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
"+",
"\" - continuing\"",
")",
";",
"}",
"}",
"closeResources",
"(",
"connection",
",",
"statement",
")",
";",
"}"
] |
An extension point allowing derived classes to change the behavior
of resource closing.
@param connection the connection to close
@param statement the statement to close
@param results the results to close
|
[
"An",
"extension",
"point",
"allowing",
"derived",
"classes",
"to",
"change",
"the",
"behavior",
"of",
"resource",
"closing",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4266-L4275
|
13,046
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.closeResources
|
protected void closeResources(Connection connection) {
if (cacheConnection) return;
if (connection != null && dataSource != null) {
try {
connection.close();
} catch (SQLException e) {
LOG.finest("Caught exception closing connection: " + e.getMessage() + " - continuing");
}
}
}
|
java
|
protected void closeResources(Connection connection) {
if (cacheConnection) return;
if (connection != null && dataSource != null) {
try {
connection.close();
} catch (SQLException e) {
LOG.finest("Caught exception closing connection: " + e.getMessage() + " - continuing");
}
}
}
|
[
"protected",
"void",
"closeResources",
"(",
"Connection",
"connection",
")",
"{",
"if",
"(",
"cacheConnection",
")",
"return",
";",
"if",
"(",
"connection",
"!=",
"null",
"&&",
"dataSource",
"!=",
"null",
")",
"{",
"try",
"{",
"connection",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"LOG",
".",
"finest",
"(",
"\"Caught exception closing connection: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
"+",
"\" - continuing\"",
")",
";",
"}",
"}",
"}"
] |
An extension point allowing the behavior of resource closing to be
overridden in derived classes.
@param connection the connection to close
|
[
"An",
"extension",
"point",
"allowing",
"the",
"behavior",
"of",
"resource",
"closing",
"to",
"be",
"overridden",
"in",
"derived",
"classes",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4317-L4326
|
13,047
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.configure
|
protected void configure(Statement statement) {
// for thread safety, grab local copy
Closure configureStatement = this.configureStatement;
if (configureStatement != null) {
configureStatement.call(statement);
}
}
|
java
|
protected void configure(Statement statement) {
// for thread safety, grab local copy
Closure configureStatement = this.configureStatement;
if (configureStatement != null) {
configureStatement.call(statement);
}
}
|
[
"protected",
"void",
"configure",
"(",
"Statement",
"statement",
")",
"{",
"// for thread safety, grab local copy",
"Closure",
"configureStatement",
"=",
"this",
".",
"configureStatement",
";",
"if",
"(",
"configureStatement",
"!=",
"null",
")",
"{",
"configureStatement",
".",
"call",
"(",
"statement",
")",
";",
"}",
"}"
] |
Provides a hook for derived classes to be able to configure JDBC statements.
Default behavior is to call a previously saved closure, if any, using the
statement as a parameter.
@param statement the statement to configure
|
[
"Provides",
"a",
"hook",
"for",
"derived",
"classes",
"to",
"be",
"able",
"to",
"configure",
"JDBC",
"statements",
".",
"Default",
"behavior",
"is",
"to",
"call",
"a",
"previously",
"saved",
"closure",
"if",
"any",
"using",
"the",
"statement",
"as",
"a",
"parameter",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4335-L4341
|
13,048
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.buildSqlWithIndexedProps
|
protected SqlWithParams buildSqlWithIndexedProps(String sql) {
// look for quick exit
if (!enableNamedQueries || !ExtractIndexAndSql.hasNamedParameters(sql)) {
return null;
}
String newSql;
List<Tuple> propList;
if (cacheNamedQueries && namedParamSqlCache.containsKey(sql)) {
newSql = namedParamSqlCache.get(sql);
propList = namedParamIndexPropCache.get(sql);
} else {
ExtractIndexAndSql extractIndexAndSql = ExtractIndexAndSql.from(sql);
newSql = extractIndexAndSql.getNewSql();
propList = extractIndexAndSql.getIndexPropList();
namedParamSqlCache.put(sql, newSql);
namedParamIndexPropCache.put(sql, propList);
}
if (sql.equals(newSql)) {
return null;
}
List<Object> indexPropList = new ArrayList<Object>(propList);
return new SqlWithParams(newSql, indexPropList);
}
|
java
|
protected SqlWithParams buildSqlWithIndexedProps(String sql) {
// look for quick exit
if (!enableNamedQueries || !ExtractIndexAndSql.hasNamedParameters(sql)) {
return null;
}
String newSql;
List<Tuple> propList;
if (cacheNamedQueries && namedParamSqlCache.containsKey(sql)) {
newSql = namedParamSqlCache.get(sql);
propList = namedParamIndexPropCache.get(sql);
} else {
ExtractIndexAndSql extractIndexAndSql = ExtractIndexAndSql.from(sql);
newSql = extractIndexAndSql.getNewSql();
propList = extractIndexAndSql.getIndexPropList();
namedParamSqlCache.put(sql, newSql);
namedParamIndexPropCache.put(sql, propList);
}
if (sql.equals(newSql)) {
return null;
}
List<Object> indexPropList = new ArrayList<Object>(propList);
return new SqlWithParams(newSql, indexPropList);
}
|
[
"protected",
"SqlWithParams",
"buildSqlWithIndexedProps",
"(",
"String",
"sql",
")",
"{",
"// look for quick exit",
"if",
"(",
"!",
"enableNamedQueries",
"||",
"!",
"ExtractIndexAndSql",
".",
"hasNamedParameters",
"(",
"sql",
")",
")",
"{",
"return",
"null",
";",
"}",
"String",
"newSql",
";",
"List",
"<",
"Tuple",
">",
"propList",
";",
"if",
"(",
"cacheNamedQueries",
"&&",
"namedParamSqlCache",
".",
"containsKey",
"(",
"sql",
")",
")",
"{",
"newSql",
"=",
"namedParamSqlCache",
".",
"get",
"(",
"sql",
")",
";",
"propList",
"=",
"namedParamIndexPropCache",
".",
"get",
"(",
"sql",
")",
";",
"}",
"else",
"{",
"ExtractIndexAndSql",
"extractIndexAndSql",
"=",
"ExtractIndexAndSql",
".",
"from",
"(",
"sql",
")",
";",
"newSql",
"=",
"extractIndexAndSql",
".",
"getNewSql",
"(",
")",
";",
"propList",
"=",
"extractIndexAndSql",
".",
"getIndexPropList",
"(",
")",
";",
"namedParamSqlCache",
".",
"put",
"(",
"sql",
",",
"newSql",
")",
";",
"namedParamIndexPropCache",
".",
"put",
"(",
"sql",
",",
"propList",
")",
";",
"}",
"if",
"(",
"sql",
".",
"equals",
"(",
"newSql",
")",
")",
"{",
"return",
"null",
";",
"}",
"List",
"<",
"Object",
">",
"indexPropList",
"=",
"new",
"ArrayList",
"<",
"Object",
">",
"(",
"propList",
")",
";",
"return",
"new",
"SqlWithParams",
"(",
"newSql",
",",
"indexPropList",
")",
";",
"}"
] |
Hook to allow derived classes to override behavior associated with the
parsing and indexing of parameters from a given sql statement.
@param sql the sql statement to process
@return a {@link SqlWithParams} instance containing the parsed sql
and parameters containing the indexed location and property
name of parameters or {@code null} if no parsing of
the sql was performed.
|
[
"Hook",
"to",
"allow",
"derived",
"classes",
"to",
"override",
"behavior",
"associated",
"with",
"the",
"parsing",
"and",
"indexing",
"of",
"parameters",
"from",
"a",
"given",
"sql",
"statement",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4474-L4499
|
13,049
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
|
Sql.createPreparedQueryCommand
|
protected AbstractQueryCommand createPreparedQueryCommand(String sql, List<Object> queryParams) {
return new PreparedQueryCommand(sql, queryParams);
}
|
java
|
protected AbstractQueryCommand createPreparedQueryCommand(String sql, List<Object> queryParams) {
return new PreparedQueryCommand(sql, queryParams);
}
|
[
"protected",
"AbstractQueryCommand",
"createPreparedQueryCommand",
"(",
"String",
"sql",
",",
"List",
"<",
"Object",
">",
"queryParams",
")",
"{",
"return",
"new",
"PreparedQueryCommand",
"(",
"sql",
",",
"queryParams",
")",
";",
"}"
] |
Factory for the PreparedQueryCommand command pattern object allows subclass to supply implementations
of the command class.
@param sql statement to be executed, including optional parameter placeholders (?)
@param queryParams List of parameter values corresponding to parameter placeholders
@return a command - invoke its execute() and closeResource() methods
@see #createQueryCommand(String)
|
[
"Factory",
"for",
"the",
"PreparedQueryCommand",
"command",
"pattern",
"object",
"allows",
"subclass",
"to",
"supply",
"implementations",
"of",
"the",
"command",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L4765-L4767
|
13,050
|
apache/groovy
|
src/main/groovy/groovy/lang/Script.java
|
Script.printf
|
public void printf(String format, Object value) {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
DefaultGroovyMethods.printf(System.out, format, value);
return;
}
InvokerHelper.invokeMethod(object, "printf", new Object[] { format, value });
}
|
java
|
public void printf(String format, Object value) {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
DefaultGroovyMethods.printf(System.out, format, value);
return;
}
InvokerHelper.invokeMethod(object, "printf", new Object[] { format, value });
}
|
[
"public",
"void",
"printf",
"(",
"String",
"format",
",",
"Object",
"value",
")",
"{",
"Object",
"object",
";",
"try",
"{",
"object",
"=",
"getProperty",
"(",
"\"out\"",
")",
";",
"}",
"catch",
"(",
"MissingPropertyException",
"e",
")",
"{",
"DefaultGroovyMethods",
".",
"printf",
"(",
"System",
".",
"out",
",",
"format",
",",
"value",
")",
";",
"return",
";",
"}",
"InvokerHelper",
".",
"invokeMethod",
"(",
"object",
",",
"\"printf\"",
",",
"new",
"Object",
"[",
"]",
"{",
"format",
",",
"value",
"}",
")",
";",
"}"
] |
Prints a formatted string using the specified format string and argument.
@param format the format to follow
@param value the value to be formatted
|
[
"Prints",
"a",
"formatted",
"string",
"using",
"the",
"specified",
"format",
"string",
"and",
"argument",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Script.java#L167-L178
|
13,051
|
apache/groovy
|
src/main/groovy/groovy/lang/Script.java
|
Script.run
|
public void run(File file, String[] arguments) throws CompilationFailedException, IOException {
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding);
shell.run(file, arguments);
}
|
java
|
public void run(File file, String[] arguments) throws CompilationFailedException, IOException {
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding);
shell.run(file, arguments);
}
|
[
"public",
"void",
"run",
"(",
"File",
"file",
",",
"String",
"[",
"]",
"arguments",
")",
"throws",
"CompilationFailedException",
",",
"IOException",
"{",
"GroovyShell",
"shell",
"=",
"new",
"GroovyShell",
"(",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
",",
"binding",
")",
";",
"shell",
".",
"run",
"(",
"file",
",",
"arguments",
")",
";",
"}"
] |
A helper method to allow scripts to be run taking command line arguments
|
[
"A",
"helper",
"method",
"to",
"allow",
"scripts",
"to",
"be",
"run",
"taking",
"command",
"line",
"arguments"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Script.java#L224-L227
|
13,052
|
apache/groovy
|
subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java
|
SqlExtensions.toRowResult
|
public static GroovyRowResult toRowResult(ResultSet rs) throws SQLException {
ResultSetMetaData metadata = rs.getMetaData();
Map<String, Object> lhm = new LinkedHashMap<String, Object>(metadata.getColumnCount(), 1);
for (int i = 1; i <= metadata.getColumnCount(); i++) {
lhm.put(metadata.getColumnLabel(i), rs.getObject(i));
}
return new GroovyRowResult(lhm);
}
|
java
|
public static GroovyRowResult toRowResult(ResultSet rs) throws SQLException {
ResultSetMetaData metadata = rs.getMetaData();
Map<String, Object> lhm = new LinkedHashMap<String, Object>(metadata.getColumnCount(), 1);
for (int i = 1; i <= metadata.getColumnCount(); i++) {
lhm.put(metadata.getColumnLabel(i), rs.getObject(i));
}
return new GroovyRowResult(lhm);
}
|
[
"public",
"static",
"GroovyRowResult",
"toRowResult",
"(",
"ResultSet",
"rs",
")",
"throws",
"SQLException",
"{",
"ResultSetMetaData",
"metadata",
"=",
"rs",
".",
"getMetaData",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"lhm",
"=",
"new",
"LinkedHashMap",
"<",
"String",
",",
"Object",
">",
"(",
"metadata",
".",
"getColumnCount",
"(",
")",
",",
"1",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"metadata",
".",
"getColumnCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"lhm",
".",
"put",
"(",
"metadata",
".",
"getColumnLabel",
"(",
"i",
")",
",",
"rs",
".",
"getObject",
"(",
"i",
")",
")",
";",
"}",
"return",
"new",
"GroovyRowResult",
"(",
"lhm",
")",
";",
"}"
] |
Returns a GroovyRowResult given a ResultSet.
@param rs a ResultSet
@return the resulting GroovyRowResult
@throws java.sql.SQLException if a database error occurs
@since 1.6.0
|
[
"Returns",
"a",
"GroovyRowResult",
"given",
"a",
"ResultSet",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java#L50-L57
|
13,053
|
apache/groovy
|
src/main/groovy/groovy/util/GroovyCollections.java
|
GroovyCollections.min
|
public static <T> T min(Iterable<T> items) {
T answer = null;
for (T value : items) {
if (value != null) {
if (answer == null || ScriptBytecodeAdapter.compareLessThan(value, answer)) {
answer = value;
}
}
}
return answer;
}
|
java
|
public static <T> T min(Iterable<T> items) {
T answer = null;
for (T value : items) {
if (value != null) {
if (answer == null || ScriptBytecodeAdapter.compareLessThan(value, answer)) {
answer = value;
}
}
}
return answer;
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"min",
"(",
"Iterable",
"<",
"T",
">",
"items",
")",
"{",
"T",
"answer",
"=",
"null",
";",
"for",
"(",
"T",
"value",
":",
"items",
")",
"{",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"if",
"(",
"answer",
"==",
"null",
"||",
"ScriptBytecodeAdapter",
".",
"compareLessThan",
"(",
"value",
",",
"answer",
")",
")",
"{",
"answer",
"=",
"value",
";",
"}",
"}",
"}",
"return",
"answer",
";",
"}"
] |
Selects the minimum value found in an Iterable of items.
@param items an Iterable
@return the minimum value
@since 2.2.0
|
[
"Selects",
"the",
"minimum",
"value",
"found",
"in",
"an",
"Iterable",
"of",
"items",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/util/GroovyCollections.java#L215-L225
|
13,054
|
apache/groovy
|
src/main/groovy/groovy/util/GroovyCollections.java
|
GroovyCollections.max
|
public static <T> T max(Iterable<T> items) {
T answer = null;
for (T value : items) {
if (value != null) {
if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) {
answer = value;
}
}
}
return answer;
}
|
java
|
public static <T> T max(Iterable<T> items) {
T answer = null;
for (T value : items) {
if (value != null) {
if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) {
answer = value;
}
}
}
return answer;
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"max",
"(",
"Iterable",
"<",
"T",
">",
"items",
")",
"{",
"T",
"answer",
"=",
"null",
";",
"for",
"(",
"T",
"value",
":",
"items",
")",
"{",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"if",
"(",
"answer",
"==",
"null",
"||",
"ScriptBytecodeAdapter",
".",
"compareGreaterThan",
"(",
"value",
",",
"answer",
")",
")",
"{",
"answer",
"=",
"value",
";",
"}",
"}",
"}",
"return",
"answer",
";",
"}"
] |
Selects the maximum value found in an Iterable.
@param items a Collection
@return the maximum value
@since 2.2.0
|
[
"Selects",
"the",
"maximum",
"value",
"found",
"in",
"an",
"Iterable",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/util/GroovyCollections.java#L253-L263
|
13,055
|
apache/groovy
|
src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
|
ExpressionUtils.transformListOfConstants
|
public static Expression transformListOfConstants(ListExpression origList, ClassNode attrType) {
ListExpression newList = new ListExpression();
boolean changed = false;
for (Expression e : origList.getExpressions()) {
try {
Expression transformed = transformInlineConstants(e, attrType);
newList.addExpression(transformed);
if (transformed != e) changed = true;
} catch(Exception ignored) {
newList.addExpression(e);
}
}
if (changed) {
newList.setSourcePosition(origList);
return newList;
}
return origList;
}
|
java
|
public static Expression transformListOfConstants(ListExpression origList, ClassNode attrType) {
ListExpression newList = new ListExpression();
boolean changed = false;
for (Expression e : origList.getExpressions()) {
try {
Expression transformed = transformInlineConstants(e, attrType);
newList.addExpression(transformed);
if (transformed != e) changed = true;
} catch(Exception ignored) {
newList.addExpression(e);
}
}
if (changed) {
newList.setSourcePosition(origList);
return newList;
}
return origList;
}
|
[
"public",
"static",
"Expression",
"transformListOfConstants",
"(",
"ListExpression",
"origList",
",",
"ClassNode",
"attrType",
")",
"{",
"ListExpression",
"newList",
"=",
"new",
"ListExpression",
"(",
")",
";",
"boolean",
"changed",
"=",
"false",
";",
"for",
"(",
"Expression",
"e",
":",
"origList",
".",
"getExpressions",
"(",
")",
")",
"{",
"try",
"{",
"Expression",
"transformed",
"=",
"transformInlineConstants",
"(",
"e",
",",
"attrType",
")",
";",
"newList",
".",
"addExpression",
"(",
"transformed",
")",
";",
"if",
"(",
"transformed",
"!=",
"e",
")",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"ignored",
")",
"{",
"newList",
".",
"addExpression",
"(",
"e",
")",
";",
"}",
"}",
"if",
"(",
"changed",
")",
"{",
"newList",
".",
"setSourcePosition",
"(",
"origList",
")",
";",
"return",
"newList",
";",
"}",
"return",
"origList",
";",
"}"
] |
Given a list of constants, transform each item in the list.
@param origList the list to transform
@param attrType the target type
@return the transformed list or the original if nothing was changed
|
[
"Given",
"a",
"list",
"of",
"constants",
"transform",
"each",
"item",
"in",
"the",
"list",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java#L276-L293
|
13,056
|
apache/groovy
|
subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
|
StreamingTemplateEngine.createTemplate
|
@Override
public Template createTemplate(final Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException {
return new StreamingTemplate(reader, parentLoader);
}
|
java
|
@Override
public Template createTemplate(final Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException {
return new StreamingTemplate(reader, parentLoader);
}
|
[
"@",
"Override",
"public",
"Template",
"createTemplate",
"(",
"final",
"Reader",
"reader",
")",
"throws",
"CompilationFailedException",
",",
"ClassNotFoundException",
",",
"IOException",
"{",
"return",
"new",
"StreamingTemplate",
"(",
"reader",
",",
"parentLoader",
")",
";",
"}"
] |
Creates a template instance using the template source from the provided Reader.
The template can be applied repeatedly on different bindings to produce custom output.
<strong>Technical detail</strong><br />
Under the hood the returned template is represented as a four argument
closure where the three first arguments are {@link groovy.lang.Closure#curry curried} in
while generating the template. <br />
<br />
In essence we start with a closure on the form:
<pre>
{ parentClass, stringSectionList, binding, out {@code ->}
//code generated by parsing the template data
}
</pre>
We then curry in the parentClass and stringSectionList arguments so that the StreamingTemplate
instance returned from 'createTemplate' internally contains a template closure on the form:
<pre>
{ binding, out {@code ->}
//code generated by parsing the template data
}
</pre>
Calling {@code template.make(binding)}, curries in the 'binding' argument:
<pre>
public Writable make(final Map map) {
final Closure template = this.template.curry(new Object[]{map});
return (Writable) template;
}
</pre>
This only leaves the 'out' argument unbound. The only method on the {@link groovy.lang.Writable writable} interface is
{@link groovy.lang.Writable#writeTo writeTo(Writer out)} so groovy rules about casting a closure to a one-method-interface
apply and the above works. I.e. we return the now one argument closure as the Writable
which can be serialized to System.out, a file, etc according to the Writable interface contract.
@see groovy.text.TemplateEngine#createTemplate(java.io.Reader)
|
[
"Creates",
"a",
"template",
"instance",
"using",
"the",
"template",
"source",
"from",
"the",
"provided",
"Reader",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java#L213-L216
|
13,057
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.fillMethodIndex
|
private void fillMethodIndex() {
mainClassMethodHeader = metaMethodIndex.getHeader(theClass);
LinkedList<CachedClass> superClasses = getSuperClasses();
CachedClass firstGroovySuper = calcFirstGroovySuperClass(superClasses);
Set<CachedClass> interfaces = theCachedClass.getInterfaces();
addInterfaceMethods(interfaces);
populateMethods(superClasses, firstGroovySuper);
inheritInterfaceNewMetaMethods(interfaces);
if (isGroovyObject) {
metaMethodIndex.copyMethodsToSuper();
connectMultimethods(superClasses, firstGroovySuper);
removeMultimethodsOverloadedWithPrivateMethods();
replaceWithMOPCalls(theCachedClass.mopMethods);
}
}
|
java
|
private void fillMethodIndex() {
mainClassMethodHeader = metaMethodIndex.getHeader(theClass);
LinkedList<CachedClass> superClasses = getSuperClasses();
CachedClass firstGroovySuper = calcFirstGroovySuperClass(superClasses);
Set<CachedClass> interfaces = theCachedClass.getInterfaces();
addInterfaceMethods(interfaces);
populateMethods(superClasses, firstGroovySuper);
inheritInterfaceNewMetaMethods(interfaces);
if (isGroovyObject) {
metaMethodIndex.copyMethodsToSuper();
connectMultimethods(superClasses, firstGroovySuper);
removeMultimethodsOverloadedWithPrivateMethods();
replaceWithMOPCalls(theCachedClass.mopMethods);
}
}
|
[
"private",
"void",
"fillMethodIndex",
"(",
")",
"{",
"mainClassMethodHeader",
"=",
"metaMethodIndex",
".",
"getHeader",
"(",
"theClass",
")",
";",
"LinkedList",
"<",
"CachedClass",
">",
"superClasses",
"=",
"getSuperClasses",
"(",
")",
";",
"CachedClass",
"firstGroovySuper",
"=",
"calcFirstGroovySuperClass",
"(",
"superClasses",
")",
";",
"Set",
"<",
"CachedClass",
">",
"interfaces",
"=",
"theCachedClass",
".",
"getInterfaces",
"(",
")",
";",
"addInterfaceMethods",
"(",
"interfaces",
")",
";",
"populateMethods",
"(",
"superClasses",
",",
"firstGroovySuper",
")",
";",
"inheritInterfaceNewMetaMethods",
"(",
"interfaces",
")",
";",
"if",
"(",
"isGroovyObject",
")",
"{",
"metaMethodIndex",
".",
"copyMethodsToSuper",
"(",
")",
";",
"connectMultimethods",
"(",
"superClasses",
",",
"firstGroovySuper",
")",
";",
"removeMultimethodsOverloadedWithPrivateMethods",
"(",
")",
";",
"replaceWithMOPCalls",
"(",
"theCachedClass",
".",
"mopMethods",
")",
";",
"}",
"}"
] |
Fills the method index
|
[
"Fills",
"the",
"method",
"index"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L348-L367
|
13,058
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.getMethods
|
private Object getMethods(Class sender, String name, boolean isCallToSuper) {
Object answer;
final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
if (entry == null)
answer = FastArray.EMPTY_LIST;
else
if (isCallToSuper) {
answer = entry.methodsForSuper;
} else {
answer = entry.methods;
}
if (answer == null) answer = FastArray.EMPTY_LIST;
if (!isCallToSuper) {
List used = GroovyCategorySupport.getCategoryMethods(name);
if (used != null) {
FastArray arr;
if (answer instanceof MetaMethod) {
arr = new FastArray();
arr.add(answer);
}
else
arr = ((FastArray) answer).copy();
for (Iterator iter = used.iterator(); iter.hasNext();) {
MetaMethod element = (MetaMethod) iter.next();
if (!element.getDeclaringClass().getTheClass().isAssignableFrom(sender))
continue;
filterMatchingMethodForCategory(arr, element);
}
answer = arr;
}
}
return answer;
}
|
java
|
private Object getMethods(Class sender, String name, boolean isCallToSuper) {
Object answer;
final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
if (entry == null)
answer = FastArray.EMPTY_LIST;
else
if (isCallToSuper) {
answer = entry.methodsForSuper;
} else {
answer = entry.methods;
}
if (answer == null) answer = FastArray.EMPTY_LIST;
if (!isCallToSuper) {
List used = GroovyCategorySupport.getCategoryMethods(name);
if (used != null) {
FastArray arr;
if (answer instanceof MetaMethod) {
arr = new FastArray();
arr.add(answer);
}
else
arr = ((FastArray) answer).copy();
for (Iterator iter = used.iterator(); iter.hasNext();) {
MetaMethod element = (MetaMethod) iter.next();
if (!element.getDeclaringClass().getTheClass().isAssignableFrom(sender))
continue;
filterMatchingMethodForCategory(arr, element);
}
answer = arr;
}
}
return answer;
}
|
[
"private",
"Object",
"getMethods",
"(",
"Class",
"sender",
",",
"String",
"name",
",",
"boolean",
"isCallToSuper",
")",
"{",
"Object",
"answer",
";",
"final",
"MetaMethodIndex",
".",
"Entry",
"entry",
"=",
"metaMethodIndex",
".",
"getMethods",
"(",
"sender",
",",
"name",
")",
";",
"if",
"(",
"entry",
"==",
"null",
")",
"answer",
"=",
"FastArray",
".",
"EMPTY_LIST",
";",
"else",
"if",
"(",
"isCallToSuper",
")",
"{",
"answer",
"=",
"entry",
".",
"methodsForSuper",
";",
"}",
"else",
"{",
"answer",
"=",
"entry",
".",
"methods",
";",
"}",
"if",
"(",
"answer",
"==",
"null",
")",
"answer",
"=",
"FastArray",
".",
"EMPTY_LIST",
";",
"if",
"(",
"!",
"isCallToSuper",
")",
"{",
"List",
"used",
"=",
"GroovyCategorySupport",
".",
"getCategoryMethods",
"(",
"name",
")",
";",
"if",
"(",
"used",
"!=",
"null",
")",
"{",
"FastArray",
"arr",
";",
"if",
"(",
"answer",
"instanceof",
"MetaMethod",
")",
"{",
"arr",
"=",
"new",
"FastArray",
"(",
")",
";",
"arr",
".",
"add",
"(",
"answer",
")",
";",
"}",
"else",
"arr",
"=",
"(",
"(",
"FastArray",
")",
"answer",
")",
".",
"copy",
"(",
")",
";",
"for",
"(",
"Iterator",
"iter",
"=",
"used",
".",
"iterator",
"(",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"MetaMethod",
"element",
"=",
"(",
"MetaMethod",
")",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"!",
"element",
".",
"getDeclaringClass",
"(",
")",
".",
"getTheClass",
"(",
")",
".",
"isAssignableFrom",
"(",
"sender",
")",
")",
"continue",
";",
"filterMatchingMethodForCategory",
"(",
"arr",
",",
"element",
")",
";",
"}",
"answer",
"=",
"arr",
";",
"}",
"}",
"return",
"answer",
";",
"}"
] |
Gets all instance methods available on this class for the given name
@return all the normal instance methods available on this class for the
given name
|
[
"Gets",
"all",
"instance",
"methods",
"available",
"on",
"this",
"class",
"for",
"the",
"given",
"name"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L704-L740
|
13,059
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.getStaticMethods
|
private Object getStaticMethods(Class sender, String name) {
final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
if (entry == null)
return FastArray.EMPTY_LIST;
Object answer = entry.staticMethods;
if (answer == null)
return FastArray.EMPTY_LIST;
return answer;
}
|
java
|
private Object getStaticMethods(Class sender, String name) {
final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
if (entry == null)
return FastArray.EMPTY_LIST;
Object answer = entry.staticMethods;
if (answer == null)
return FastArray.EMPTY_LIST;
return answer;
}
|
[
"private",
"Object",
"getStaticMethods",
"(",
"Class",
"sender",
",",
"String",
"name",
")",
"{",
"final",
"MetaMethodIndex",
".",
"Entry",
"entry",
"=",
"metaMethodIndex",
".",
"getMethods",
"(",
"sender",
",",
"name",
")",
";",
"if",
"(",
"entry",
"==",
"null",
")",
"return",
"FastArray",
".",
"EMPTY_LIST",
";",
"Object",
"answer",
"=",
"entry",
".",
"staticMethods",
";",
"if",
"(",
"answer",
"==",
"null",
")",
"return",
"FastArray",
".",
"EMPTY_LIST",
";",
"return",
"answer",
";",
"}"
] |
Returns all the normal static methods on this class for the given name
@return all the normal static methods available on this class for the
given name
|
[
"Returns",
"all",
"the",
"normal",
"static",
"methods",
"on",
"this",
"class",
"for",
"the",
"given",
"name"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L748-L756
|
13,060
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.addNewInstanceMethod
|
public void addNewInstanceMethod(Method method) {
final CachedMethod cachedMethod = CachedMethod.find(method);
NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
final CachedClass declaringClass = newMethod.getDeclaringClass();
addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
|
java
|
public void addNewInstanceMethod(Method method) {
final CachedMethod cachedMethod = CachedMethod.find(method);
NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
final CachedClass declaringClass = newMethod.getDeclaringClass();
addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
|
[
"public",
"void",
"addNewInstanceMethod",
"(",
"Method",
"method",
")",
"{",
"final",
"CachedMethod",
"cachedMethod",
"=",
"CachedMethod",
".",
"find",
"(",
"method",
")",
";",
"NewInstanceMetaMethod",
"newMethod",
"=",
"new",
"NewInstanceMetaMethod",
"(",
"cachedMethod",
")",
";",
"final",
"CachedClass",
"declaringClass",
"=",
"newMethod",
".",
"getDeclaringClass",
"(",
")",
";",
"addNewInstanceMethodToIndex",
"(",
"newMethod",
",",
"metaMethodIndex",
".",
"getHeader",
"(",
"declaringClass",
".",
"getTheClass",
"(",
")",
")",
")",
";",
"}"
] |
Adds an instance method to this metaclass.
@param method The method to be added
|
[
"Adds",
"an",
"instance",
"method",
"to",
"this",
"metaclass",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L773-L778
|
13,061
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.addNewStaticMethod
|
public void addNewStaticMethod(Method method) {
final CachedMethod cachedMethod = CachedMethod.find(method);
NewStaticMetaMethod newMethod = new NewStaticMetaMethod(cachedMethod);
final CachedClass declaringClass = newMethod.getDeclaringClass();
addNewStaticMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
|
java
|
public void addNewStaticMethod(Method method) {
final CachedMethod cachedMethod = CachedMethod.find(method);
NewStaticMetaMethod newMethod = new NewStaticMetaMethod(cachedMethod);
final CachedClass declaringClass = newMethod.getDeclaringClass();
addNewStaticMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
|
[
"public",
"void",
"addNewStaticMethod",
"(",
"Method",
"method",
")",
"{",
"final",
"CachedMethod",
"cachedMethod",
"=",
"CachedMethod",
".",
"find",
"(",
"method",
")",
";",
"NewStaticMetaMethod",
"newMethod",
"=",
"new",
"NewStaticMetaMethod",
"(",
"cachedMethod",
")",
";",
"final",
"CachedClass",
"declaringClass",
"=",
"newMethod",
".",
"getDeclaringClass",
"(",
")",
";",
"addNewStaticMethodToIndex",
"(",
"newMethod",
",",
"metaMethodIndex",
".",
"getHeader",
"(",
"declaringClass",
".",
"getTheClass",
"(",
")",
")",
")",
";",
"}"
] |
Adds a static method to this metaclass.
@param method The method to be added
|
[
"Adds",
"a",
"static",
"method",
"to",
"this",
"metaclass",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L792-L797
|
13,062
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.invokeMethod
|
public Object invokeMethod(Object object, String methodName, Object arguments) {
if (arguments == null) {
return invokeMethod(object, methodName, MetaClassHelper.EMPTY_ARRAY);
}
if (arguments instanceof Tuple) {
Tuple tuple = (Tuple) arguments;
return invokeMethod(object, methodName, tuple.toArray());
}
if (arguments instanceof Object[]) {
return invokeMethod(object, methodName, (Object[]) arguments);
} else {
return invokeMethod(object, methodName, new Object[]{arguments});
}
}
|
java
|
public Object invokeMethod(Object object, String methodName, Object arguments) {
if (arguments == null) {
return invokeMethod(object, methodName, MetaClassHelper.EMPTY_ARRAY);
}
if (arguments instanceof Tuple) {
Tuple tuple = (Tuple) arguments;
return invokeMethod(object, methodName, tuple.toArray());
}
if (arguments instanceof Object[]) {
return invokeMethod(object, methodName, (Object[]) arguments);
} else {
return invokeMethod(object, methodName, new Object[]{arguments});
}
}
|
[
"public",
"Object",
"invokeMethod",
"(",
"Object",
"object",
",",
"String",
"methodName",
",",
"Object",
"arguments",
")",
"{",
"if",
"(",
"arguments",
"==",
"null",
")",
"{",
"return",
"invokeMethod",
"(",
"object",
",",
"methodName",
",",
"MetaClassHelper",
".",
"EMPTY_ARRAY",
")",
";",
"}",
"if",
"(",
"arguments",
"instanceof",
"Tuple",
")",
"{",
"Tuple",
"tuple",
"=",
"(",
"Tuple",
")",
"arguments",
";",
"return",
"invokeMethod",
"(",
"object",
",",
"methodName",
",",
"tuple",
".",
"toArray",
"(",
")",
")",
";",
"}",
"if",
"(",
"arguments",
"instanceof",
"Object",
"[",
"]",
")",
"{",
"return",
"invokeMethod",
"(",
"object",
",",
"methodName",
",",
"(",
"Object",
"[",
"]",
")",
"arguments",
")",
";",
"}",
"else",
"{",
"return",
"invokeMethod",
"(",
"object",
",",
"methodName",
",",
"new",
"Object",
"[",
"]",
"{",
"arguments",
"}",
")",
";",
"}",
"}"
] |
Invoke a method on the given object with the given arguments.
@param object The object the method should be invoked on.
@param methodName The name of the method to invoke.
@param arguments The arguments to the invoked method as null, a Tuple, an array or a single argument of any type.
@return The result of the method invocation.
|
[
"Invoke",
"a",
"method",
"on",
"the",
"given",
"object",
"with",
"the",
"given",
"arguments",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L815-L828
|
13,063
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.invokeMissingMethod
|
public Object invokeMissingMethod(Object instance, String methodName, Object[] arguments) {
return invokeMissingMethod(instance, methodName, arguments, null, false);
}
|
java
|
public Object invokeMissingMethod(Object instance, String methodName, Object[] arguments) {
return invokeMissingMethod(instance, methodName, arguments, null, false);
}
|
[
"public",
"Object",
"invokeMissingMethod",
"(",
"Object",
"instance",
",",
"String",
"methodName",
",",
"Object",
"[",
"]",
"arguments",
")",
"{",
"return",
"invokeMissingMethod",
"(",
"instance",
",",
"methodName",
",",
"arguments",
",",
"null",
",",
"false",
")",
";",
"}"
] |
Invoke a missing method on the given object with the given arguments.
@param instance The object the method should be invoked on.
@param methodName The name of the method to invoke.
@param arguments The arguments to the invoked method.
@return The result of the method invocation.
|
[
"Invoke",
"a",
"missing",
"method",
"on",
"the",
"given",
"object",
"with",
"the",
"given",
"arguments",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L839-L841
|
13,064
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.invokeMissingProperty
|
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) {
Class theClass = instance instanceof Class ? (Class)instance : instance.getClass();
CachedClass superClass = theCachedClass;
while(superClass != null && superClass != ReflectionCache.OBJECT_CLASS) {
final MetaBeanProperty property = findPropertyInClassHierarchy(propertyName, superClass);
if(property != null) {
onSuperPropertyFoundInHierarchy(property);
if(!isGetter) {
property.setProperty(instance, optionalValue);
return null;
}
else {
return property.getProperty(instance);
}
}
superClass = superClass.getCachedSuperClass();
}
// got here to property not found, look for getProperty or setProperty overrides
if(isGetter) {
final Class[] getPropertyArgs = {String.class};
final MetaMethod method = findMethodInClassHierarchy(instance.getClass(), GET_PROPERTY_METHOD, getPropertyArgs, this);
if(method instanceof ClosureMetaMethod) {
onGetPropertyFoundInHierarchy(method);
return method.invoke(instance,new Object[]{propertyName});
}
}
else {
final Class[] setPropertyArgs = {String.class, Object.class};
final MetaMethod method = findMethodInClassHierarchy(instance.getClass(), SET_PROPERTY_METHOD, setPropertyArgs, this);
if(method instanceof ClosureMetaMethod) {
onSetPropertyFoundInHierarchy(method);
return method.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
try {
if (!(instance instanceof Class)) {
if (isGetter) {
if (propertyMissingGet != null) {
return propertyMissingGet.invoke(instance, new Object[]{propertyName});
}
} else {
if (propertyMissingSet != null) {
return propertyMissingSet.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
}
} catch (InvokerInvocationException iie) {
boolean shouldHandle = isGetter && propertyMissingGet != null;
if (!shouldHandle) shouldHandle = !isGetter && propertyMissingSet != null;
if (shouldHandle && iie.getCause() instanceof MissingPropertyException) {
throw (MissingPropertyException) iie.getCause();
}
throw iie;
}
if (instance instanceof Class && theClass != Class.class) {
final MetaProperty metaProperty = InvokerHelper.getMetaClass(Class.class).hasProperty(instance, propertyName);
if (metaProperty != null)
if (isGetter)
return metaProperty.getProperty(instance);
else {
metaProperty.setProperty(instance, optionalValue);
return null;
}
}
throw new MissingPropertyExceptionNoStack(propertyName, theClass);
}
|
java
|
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) {
Class theClass = instance instanceof Class ? (Class)instance : instance.getClass();
CachedClass superClass = theCachedClass;
while(superClass != null && superClass != ReflectionCache.OBJECT_CLASS) {
final MetaBeanProperty property = findPropertyInClassHierarchy(propertyName, superClass);
if(property != null) {
onSuperPropertyFoundInHierarchy(property);
if(!isGetter) {
property.setProperty(instance, optionalValue);
return null;
}
else {
return property.getProperty(instance);
}
}
superClass = superClass.getCachedSuperClass();
}
// got here to property not found, look for getProperty or setProperty overrides
if(isGetter) {
final Class[] getPropertyArgs = {String.class};
final MetaMethod method = findMethodInClassHierarchy(instance.getClass(), GET_PROPERTY_METHOD, getPropertyArgs, this);
if(method instanceof ClosureMetaMethod) {
onGetPropertyFoundInHierarchy(method);
return method.invoke(instance,new Object[]{propertyName});
}
}
else {
final Class[] setPropertyArgs = {String.class, Object.class};
final MetaMethod method = findMethodInClassHierarchy(instance.getClass(), SET_PROPERTY_METHOD, setPropertyArgs, this);
if(method instanceof ClosureMetaMethod) {
onSetPropertyFoundInHierarchy(method);
return method.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
try {
if (!(instance instanceof Class)) {
if (isGetter) {
if (propertyMissingGet != null) {
return propertyMissingGet.invoke(instance, new Object[]{propertyName});
}
} else {
if (propertyMissingSet != null) {
return propertyMissingSet.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
}
} catch (InvokerInvocationException iie) {
boolean shouldHandle = isGetter && propertyMissingGet != null;
if (!shouldHandle) shouldHandle = !isGetter && propertyMissingSet != null;
if (shouldHandle && iie.getCause() instanceof MissingPropertyException) {
throw (MissingPropertyException) iie.getCause();
}
throw iie;
}
if (instance instanceof Class && theClass != Class.class) {
final MetaProperty metaProperty = InvokerHelper.getMetaClass(Class.class).hasProperty(instance, propertyName);
if (metaProperty != null)
if (isGetter)
return metaProperty.getProperty(instance);
else {
metaProperty.setProperty(instance, optionalValue);
return null;
}
}
throw new MissingPropertyExceptionNoStack(propertyName, theClass);
}
|
[
"public",
"Object",
"invokeMissingProperty",
"(",
"Object",
"instance",
",",
"String",
"propertyName",
",",
"Object",
"optionalValue",
",",
"boolean",
"isGetter",
")",
"{",
"Class",
"theClass",
"=",
"instance",
"instanceof",
"Class",
"?",
"(",
"Class",
")",
"instance",
":",
"instance",
".",
"getClass",
"(",
")",
";",
"CachedClass",
"superClass",
"=",
"theCachedClass",
";",
"while",
"(",
"superClass",
"!=",
"null",
"&&",
"superClass",
"!=",
"ReflectionCache",
".",
"OBJECT_CLASS",
")",
"{",
"final",
"MetaBeanProperty",
"property",
"=",
"findPropertyInClassHierarchy",
"(",
"propertyName",
",",
"superClass",
")",
";",
"if",
"(",
"property",
"!=",
"null",
")",
"{",
"onSuperPropertyFoundInHierarchy",
"(",
"property",
")",
";",
"if",
"(",
"!",
"isGetter",
")",
"{",
"property",
".",
"setProperty",
"(",
"instance",
",",
"optionalValue",
")",
";",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"property",
".",
"getProperty",
"(",
"instance",
")",
";",
"}",
"}",
"superClass",
"=",
"superClass",
".",
"getCachedSuperClass",
"(",
")",
";",
"}",
"// got here to property not found, look for getProperty or setProperty overrides",
"if",
"(",
"isGetter",
")",
"{",
"final",
"Class",
"[",
"]",
"getPropertyArgs",
"=",
"{",
"String",
".",
"class",
"}",
";",
"final",
"MetaMethod",
"method",
"=",
"findMethodInClassHierarchy",
"(",
"instance",
".",
"getClass",
"(",
")",
",",
"GET_PROPERTY_METHOD",
",",
"getPropertyArgs",
",",
"this",
")",
";",
"if",
"(",
"method",
"instanceof",
"ClosureMetaMethod",
")",
"{",
"onGetPropertyFoundInHierarchy",
"(",
"method",
")",
";",
"return",
"method",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
"}",
")",
";",
"}",
"}",
"else",
"{",
"final",
"Class",
"[",
"]",
"setPropertyArgs",
"=",
"{",
"String",
".",
"class",
",",
"Object",
".",
"class",
"}",
";",
"final",
"MetaMethod",
"method",
"=",
"findMethodInClassHierarchy",
"(",
"instance",
".",
"getClass",
"(",
")",
",",
"SET_PROPERTY_METHOD",
",",
"setPropertyArgs",
",",
"this",
")",
";",
"if",
"(",
"method",
"instanceof",
"ClosureMetaMethod",
")",
"{",
"onSetPropertyFoundInHierarchy",
"(",
"method",
")",
";",
"return",
"method",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
",",
"optionalValue",
"}",
")",
";",
"}",
"}",
"try",
"{",
"if",
"(",
"!",
"(",
"instance",
"instanceof",
"Class",
")",
")",
"{",
"if",
"(",
"isGetter",
")",
"{",
"if",
"(",
"propertyMissingGet",
"!=",
"null",
")",
"{",
"return",
"propertyMissingGet",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
"}",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"propertyMissingSet",
"!=",
"null",
")",
"{",
"return",
"propertyMissingSet",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
",",
"optionalValue",
"}",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"InvokerInvocationException",
"iie",
")",
"{",
"boolean",
"shouldHandle",
"=",
"isGetter",
"&&",
"propertyMissingGet",
"!=",
"null",
";",
"if",
"(",
"!",
"shouldHandle",
")",
"shouldHandle",
"=",
"!",
"isGetter",
"&&",
"propertyMissingSet",
"!=",
"null",
";",
"if",
"(",
"shouldHandle",
"&&",
"iie",
".",
"getCause",
"(",
")",
"instanceof",
"MissingPropertyException",
")",
"{",
"throw",
"(",
"MissingPropertyException",
")",
"iie",
".",
"getCause",
"(",
")",
";",
"}",
"throw",
"iie",
";",
"}",
"if",
"(",
"instance",
"instanceof",
"Class",
"&&",
"theClass",
"!=",
"Class",
".",
"class",
")",
"{",
"final",
"MetaProperty",
"metaProperty",
"=",
"InvokerHelper",
".",
"getMetaClass",
"(",
"Class",
".",
"class",
")",
".",
"hasProperty",
"(",
"instance",
",",
"propertyName",
")",
";",
"if",
"(",
"metaProperty",
"!=",
"null",
")",
"if",
"(",
"isGetter",
")",
"return",
"metaProperty",
".",
"getProperty",
"(",
"instance",
")",
";",
"else",
"{",
"metaProperty",
".",
"setProperty",
"(",
"instance",
",",
"optionalValue",
")",
";",
"return",
"null",
";",
"}",
"}",
"throw",
"new",
"MissingPropertyExceptionNoStack",
"(",
"propertyName",
",",
"theClass",
")",
";",
"}"
] |
Invoke a missing property on the given object with the given arguments.
@param instance The object the method should be invoked on.
@param propertyName The name of the property to invoke.
@param optionalValue The (optional) new value for the property
@param isGetter Wether the method is a getter
@return The result of the method invocation.
|
[
"Invoke",
"a",
"missing",
"property",
"on",
"the",
"given",
"object",
"with",
"the",
"given",
"arguments",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L853-L920
|
13,065
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.invokeStaticMissingProperty
|
protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) {
MetaClass mc = instance instanceof Class ? registry.getMetaClass((Class) instance) : this;
if (isGetter) {
MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, GETTER_MISSING_ARGS);
if (propertyMissing != null) {
return propertyMissing.invoke(instance, new Object[]{propertyName});
}
} else {
MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, SETTER_MISSING_ARGS);
if (propertyMissing != null) {
return propertyMissing.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
if (instance instanceof Class) {
throw new MissingPropertyException(propertyName, (Class) instance);
}
throw new MissingPropertyException(propertyName, theClass);
}
|
java
|
protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) {
MetaClass mc = instance instanceof Class ? registry.getMetaClass((Class) instance) : this;
if (isGetter) {
MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, GETTER_MISSING_ARGS);
if (propertyMissing != null) {
return propertyMissing.invoke(instance, new Object[]{propertyName});
}
} else {
MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, SETTER_MISSING_ARGS);
if (propertyMissing != null) {
return propertyMissing.invoke(instance, new Object[]{propertyName, optionalValue});
}
}
if (instance instanceof Class) {
throw new MissingPropertyException(propertyName, (Class) instance);
}
throw new MissingPropertyException(propertyName, theClass);
}
|
[
"protected",
"Object",
"invokeStaticMissingProperty",
"(",
"Object",
"instance",
",",
"String",
"propertyName",
",",
"Object",
"optionalValue",
",",
"boolean",
"isGetter",
")",
"{",
"MetaClass",
"mc",
"=",
"instance",
"instanceof",
"Class",
"?",
"registry",
".",
"getMetaClass",
"(",
"(",
"Class",
")",
"instance",
")",
":",
"this",
";",
"if",
"(",
"isGetter",
")",
"{",
"MetaMethod",
"propertyMissing",
"=",
"mc",
".",
"getMetaMethod",
"(",
"STATIC_PROPERTY_MISSING",
",",
"GETTER_MISSING_ARGS",
")",
";",
"if",
"(",
"propertyMissing",
"!=",
"null",
")",
"{",
"return",
"propertyMissing",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
"}",
")",
";",
"}",
"}",
"else",
"{",
"MetaMethod",
"propertyMissing",
"=",
"mc",
".",
"getMetaMethod",
"(",
"STATIC_PROPERTY_MISSING",
",",
"SETTER_MISSING_ARGS",
")",
";",
"if",
"(",
"propertyMissing",
"!=",
"null",
")",
"{",
"return",
"propertyMissing",
".",
"invoke",
"(",
"instance",
",",
"new",
"Object",
"[",
"]",
"{",
"propertyName",
",",
"optionalValue",
"}",
")",
";",
"}",
"}",
"if",
"(",
"instance",
"instanceof",
"Class",
")",
"{",
"throw",
"new",
"MissingPropertyException",
"(",
"propertyName",
",",
"(",
"Class",
")",
"instance",
")",
";",
"}",
"throw",
"new",
"MissingPropertyException",
"(",
"propertyName",
",",
"theClass",
")",
";",
"}"
] |
Hook to deal with the case of MissingProperty for static properties. The method will look attempt to look up
"propertyMissing" handlers and invoke them otherwise thrown a MissingPropertyException
@param instance The instance
@param propertyName The name of the property
@param optionalValue The value in the case of a setter
@param isGetter True if its a getter
@return The value in the case of a getter or a MissingPropertyException
|
[
"Hook",
"to",
"deal",
"with",
"the",
"case",
"of",
"MissingProperty",
"for",
"static",
"properties",
".",
"The",
"method",
"will",
"look",
"attempt",
"to",
"look",
"up",
"propertyMissing",
"handlers",
"and",
"invoke",
"them",
"otherwise",
"thrown",
"a",
"MissingPropertyException"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L1009-L1027
|
13,066
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.invokeMethod
|
public Object invokeMethod(Object object, String methodName, Object[] originalArguments) {
return invokeMethod(theClass, object, methodName, originalArguments, false, false);
}
|
java
|
public Object invokeMethod(Object object, String methodName, Object[] originalArguments) {
return invokeMethod(theClass, object, methodName, originalArguments, false, false);
}
|
[
"public",
"Object",
"invokeMethod",
"(",
"Object",
"object",
",",
"String",
"methodName",
",",
"Object",
"[",
"]",
"originalArguments",
")",
"{",
"return",
"invokeMethod",
"(",
"theClass",
",",
"object",
",",
"methodName",
",",
"originalArguments",
",",
"false",
",",
"false",
")",
";",
"}"
] |
Invokes a method on the given receiver for the specified arguments.
The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
@param object The object which the method was invoked on
@param methodName The name of the method
@param originalArguments The arguments to the method
@return The return value of the method
@see MetaClass#invokeMethod(Class, Object, String, Object[], boolean, boolean)
|
[
"Invokes",
"a",
"method",
"on",
"the",
"given",
"receiver",
"for",
"the",
"specified",
"arguments",
".",
"The",
"MetaClass",
"will",
"attempt",
"to",
"establish",
"the",
"method",
"to",
"invoke",
"based",
"on",
"the",
"name",
"and",
"arguments",
"provided",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L1043-L1045
|
13,067
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.getMethodWithCachingInternal
|
private MetaMethod getMethodWithCachingInternal (Class sender, CallSite site, Class [] params) {
if (GroovyCategorySupport.hasCategoryInCurrentThread())
return getMethodWithoutCaching(sender, site.getName (), params, false);
final MetaMethodIndex.Entry e = metaMethodIndex.getMethods(sender, site.getName());
if (e == null) {
return null;
}
MetaMethodIndex.CacheEntry cacheEntry;
final Object methods = e.methods;
if (methods == null)
return null;
cacheEntry = e.cachedMethod;
if (cacheEntry != null && (sameClasses(cacheEntry.params, params))) {
return cacheEntry.method;
}
cacheEntry = new MetaMethodIndex.CacheEntry (params, (MetaMethod) chooseMethod(e.name, methods, params));
e.cachedMethod = cacheEntry;
return cacheEntry.method;
}
|
java
|
private MetaMethod getMethodWithCachingInternal (Class sender, CallSite site, Class [] params) {
if (GroovyCategorySupport.hasCategoryInCurrentThread())
return getMethodWithoutCaching(sender, site.getName (), params, false);
final MetaMethodIndex.Entry e = metaMethodIndex.getMethods(sender, site.getName());
if (e == null) {
return null;
}
MetaMethodIndex.CacheEntry cacheEntry;
final Object methods = e.methods;
if (methods == null)
return null;
cacheEntry = e.cachedMethod;
if (cacheEntry != null && (sameClasses(cacheEntry.params, params))) {
return cacheEntry.method;
}
cacheEntry = new MetaMethodIndex.CacheEntry (params, (MetaMethod) chooseMethod(e.name, methods, params));
e.cachedMethod = cacheEntry;
return cacheEntry.method;
}
|
[
"private",
"MetaMethod",
"getMethodWithCachingInternal",
"(",
"Class",
"sender",
",",
"CallSite",
"site",
",",
"Class",
"[",
"]",
"params",
")",
"{",
"if",
"(",
"GroovyCategorySupport",
".",
"hasCategoryInCurrentThread",
"(",
")",
")",
"return",
"getMethodWithoutCaching",
"(",
"sender",
",",
"site",
".",
"getName",
"(",
")",
",",
"params",
",",
"false",
")",
";",
"final",
"MetaMethodIndex",
".",
"Entry",
"e",
"=",
"metaMethodIndex",
".",
"getMethods",
"(",
"sender",
",",
"site",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"e",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"MetaMethodIndex",
".",
"CacheEntry",
"cacheEntry",
";",
"final",
"Object",
"methods",
"=",
"e",
".",
"methods",
";",
"if",
"(",
"methods",
"==",
"null",
")",
"return",
"null",
";",
"cacheEntry",
"=",
"e",
".",
"cachedMethod",
";",
"if",
"(",
"cacheEntry",
"!=",
"null",
"&&",
"(",
"sameClasses",
"(",
"cacheEntry",
".",
"params",
",",
"params",
")",
")",
")",
"{",
"return",
"cacheEntry",
".",
"method",
";",
"}",
"cacheEntry",
"=",
"new",
"MetaMethodIndex",
".",
"CacheEntry",
"(",
"params",
",",
"(",
"MetaMethod",
")",
"chooseMethod",
"(",
"e",
".",
"name",
",",
"methods",
",",
"params",
")",
")",
";",
"e",
".",
"cachedMethod",
"=",
"cacheEntry",
";",
"return",
"cacheEntry",
".",
"method",
";",
"}"
] |
This method should be called by CallSite only
|
[
"This",
"method",
"should",
"be",
"called",
"by",
"CallSite",
"only"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L1397-L1419
|
13,068
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.retrieveConstructor
|
public MetaMethod retrieveConstructor(Object[] arguments) {
checkInitalised();
if (arguments == null) arguments = EMPTY_ARGUMENTS;
Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
MetaClassHelper.unwrap(arguments);
Object res = chooseMethod("<init>", constructors, argClasses);
if (res instanceof MetaMethod) return (MetaMethod) res;
CachedConstructor constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, false);
if (arguments.length == 1 && arguments[0] instanceof Map) {
res = chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
} else if (
arguments.length == 2 && arguments[1] instanceof Map &&
theClass.getEnclosingClass()!=null &&
theClass.getEnclosingClass().isAssignableFrom(argClasses[0]))
{
res = chooseMethod("<init>", constructors, new Class[]{argClasses[0]});
}
if (res instanceof MetaMethod) return (MetaMethod) res;
constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, true);
return null;
}
|
java
|
public MetaMethod retrieveConstructor(Object[] arguments) {
checkInitalised();
if (arguments == null) arguments = EMPTY_ARGUMENTS;
Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
MetaClassHelper.unwrap(arguments);
Object res = chooseMethod("<init>", constructors, argClasses);
if (res instanceof MetaMethod) return (MetaMethod) res;
CachedConstructor constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, false);
if (arguments.length == 1 && arguments[0] instanceof Map) {
res = chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
} else if (
arguments.length == 2 && arguments[1] instanceof Map &&
theClass.getEnclosingClass()!=null &&
theClass.getEnclosingClass().isAssignableFrom(argClasses[0]))
{
res = chooseMethod("<init>", constructors, new Class[]{argClasses[0]});
}
if (res instanceof MetaMethod) return (MetaMethod) res;
constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, true);
return null;
}
|
[
"public",
"MetaMethod",
"retrieveConstructor",
"(",
"Object",
"[",
"]",
"arguments",
")",
"{",
"checkInitalised",
"(",
")",
";",
"if",
"(",
"arguments",
"==",
"null",
")",
"arguments",
"=",
"EMPTY_ARGUMENTS",
";",
"Class",
"[",
"]",
"argClasses",
"=",
"MetaClassHelper",
".",
"convertToTypeArray",
"(",
"arguments",
")",
";",
"MetaClassHelper",
".",
"unwrap",
"(",
"arguments",
")",
";",
"Object",
"res",
"=",
"chooseMethod",
"(",
"\"<init>\"",
",",
"constructors",
",",
"argClasses",
")",
";",
"if",
"(",
"res",
"instanceof",
"MetaMethod",
")",
"return",
"(",
"MetaMethod",
")",
"res",
";",
"CachedConstructor",
"constructor",
"=",
"(",
"CachedConstructor",
")",
"res",
";",
"if",
"(",
"constructor",
"!=",
"null",
")",
"return",
"new",
"MetaConstructor",
"(",
"constructor",
",",
"false",
")",
";",
"if",
"(",
"arguments",
".",
"length",
"==",
"1",
"&&",
"arguments",
"[",
"0",
"]",
"instanceof",
"Map",
")",
"{",
"res",
"=",
"chooseMethod",
"(",
"\"<init>\"",
",",
"constructors",
",",
"MetaClassHelper",
".",
"EMPTY_TYPE_ARRAY",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"==",
"2",
"&&",
"arguments",
"[",
"1",
"]",
"instanceof",
"Map",
"&&",
"theClass",
".",
"getEnclosingClass",
"(",
")",
"!=",
"null",
"&&",
"theClass",
".",
"getEnclosingClass",
"(",
")",
".",
"isAssignableFrom",
"(",
"argClasses",
"[",
"0",
"]",
")",
")",
"{",
"res",
"=",
"chooseMethod",
"(",
"\"<init>\"",
",",
"constructors",
",",
"new",
"Class",
"[",
"]",
"{",
"argClasses",
"[",
"0",
"]",
"}",
")",
";",
"}",
"if",
"(",
"res",
"instanceof",
"MetaMethod",
")",
"return",
"(",
"MetaMethod",
")",
"res",
";",
"constructor",
"=",
"(",
"CachedConstructor",
")",
"res",
";",
"if",
"(",
"constructor",
"!=",
"null",
")",
"return",
"new",
"MetaConstructor",
"(",
"constructor",
",",
"true",
")",
";",
"return",
"null",
";",
"}"
] |
This is a helper method added in Groovy 2.1.0, which is used only by indy.
This method is for internal use only.
@since Groovy 2.1.0
|
[
"This",
"is",
"a",
"helper",
"method",
"added",
"in",
"Groovy",
"2",
".",
"1",
".",
"0",
"which",
"is",
"used",
"only",
"by",
"indy",
".",
"This",
"method",
"is",
"for",
"internal",
"use",
"only",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L1761-L1784
|
13,069
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.setProperties
|
public void setProperties(Object bean, Map map) {
checkInitalised();
for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String key = entry.getKey().toString();
Object value = entry.getValue();
setProperty(bean, key, value);
}
}
|
java
|
public void setProperties(Object bean, Map map) {
checkInitalised();
for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String key = entry.getKey().toString();
Object value = entry.getValue();
setProperty(bean, key, value);
}
}
|
[
"public",
"void",
"setProperties",
"(",
"Object",
"bean",
",",
"Map",
"map",
")",
"{",
"checkInitalised",
"(",
")",
";",
"for",
"(",
"Iterator",
"iter",
"=",
"map",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"Map",
".",
"Entry",
"entry",
"=",
"(",
"Map",
".",
"Entry",
")",
"iter",
".",
"next",
"(",
")",
";",
"String",
"key",
"=",
"entry",
".",
"getKey",
"(",
")",
".",
"toString",
"(",
")",
";",
"Object",
"value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"setProperty",
"(",
"bean",
",",
"key",
",",
"value",
")",
";",
"}",
"}"
] |
Sets a number of bean properties from the given Map where the keys are
the String names of properties and the values are the values of the
properties to set
|
[
"Sets",
"a",
"number",
"of",
"bean",
"properties",
"from",
"the",
"given",
"Map",
"where",
"the",
"keys",
"are",
"the",
"String",
"names",
"of",
"properties",
"and",
"the",
"values",
"are",
"the",
"values",
"of",
"the",
"properties",
"to",
"set"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L1818-L1827
|
13,070
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.getProperties
|
public List<MetaProperty> getProperties() {
checkInitalised();
SingleKeyHashMap propertyMap = classPropertyIndex.getNullable(theCachedClass);
if (propertyMap==null) {
// GROOVY-6903: May happen in some special environment, like under Android, due
// to classloading issues
propertyMap = new SingleKeyHashMap();
}
// simply return the values of the metaproperty map as a List
List ret = new ArrayList(propertyMap.size());
for (ComplexKeyHashMap.EntryIterator iter = propertyMap.getEntrySetIterator(); iter.hasNext();) {
MetaProperty element = (MetaProperty) ((SingleKeyHashMap.Entry) iter.next()).value;
if (element instanceof CachedField) continue;
// filter out DGM beans
if (element instanceof MetaBeanProperty) {
MetaBeanProperty mp = (MetaBeanProperty) element;
boolean setter = true;
boolean getter = true;
if (mp.getGetter() == null || mp.getGetter() instanceof GeneratedMetaMethod || mp.getGetter() instanceof NewInstanceMetaMethod) {
getter = false;
}
if (mp.getSetter() == null || mp.getSetter() instanceof GeneratedMetaMethod || mp.getSetter() instanceof NewInstanceMetaMethod) {
setter = false;
}
if (!setter && !getter) continue;
// TODO: I (ait) don't know why these strange tricks needed and comment following as it effects some Grails tests
// if (!setter && mp.getSetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), mp.getGetter(), null);
// }
// if (!getter && mp.getGetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), null, mp.getSetter());
// }
}
ret.add(element);
}
return ret;
}
|
java
|
public List<MetaProperty> getProperties() {
checkInitalised();
SingleKeyHashMap propertyMap = classPropertyIndex.getNullable(theCachedClass);
if (propertyMap==null) {
// GROOVY-6903: May happen in some special environment, like under Android, due
// to classloading issues
propertyMap = new SingleKeyHashMap();
}
// simply return the values of the metaproperty map as a List
List ret = new ArrayList(propertyMap.size());
for (ComplexKeyHashMap.EntryIterator iter = propertyMap.getEntrySetIterator(); iter.hasNext();) {
MetaProperty element = (MetaProperty) ((SingleKeyHashMap.Entry) iter.next()).value;
if (element instanceof CachedField) continue;
// filter out DGM beans
if (element instanceof MetaBeanProperty) {
MetaBeanProperty mp = (MetaBeanProperty) element;
boolean setter = true;
boolean getter = true;
if (mp.getGetter() == null || mp.getGetter() instanceof GeneratedMetaMethod || mp.getGetter() instanceof NewInstanceMetaMethod) {
getter = false;
}
if (mp.getSetter() == null || mp.getSetter() instanceof GeneratedMetaMethod || mp.getSetter() instanceof NewInstanceMetaMethod) {
setter = false;
}
if (!setter && !getter) continue;
// TODO: I (ait) don't know why these strange tricks needed and comment following as it effects some Grails tests
// if (!setter && mp.getSetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), mp.getGetter(), null);
// }
// if (!getter && mp.getGetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), null, mp.getSetter());
// }
}
ret.add(element);
}
return ret;
}
|
[
"public",
"List",
"<",
"MetaProperty",
">",
"getProperties",
"(",
")",
"{",
"checkInitalised",
"(",
")",
";",
"SingleKeyHashMap",
"propertyMap",
"=",
"classPropertyIndex",
".",
"getNullable",
"(",
"theCachedClass",
")",
";",
"if",
"(",
"propertyMap",
"==",
"null",
")",
"{",
"// GROOVY-6903: May happen in some special environment, like under Android, due",
"// to classloading issues",
"propertyMap",
"=",
"new",
"SingleKeyHashMap",
"(",
")",
";",
"}",
"// simply return the values of the metaproperty map as a List",
"List",
"ret",
"=",
"new",
"ArrayList",
"(",
"propertyMap",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"ComplexKeyHashMap",
".",
"EntryIterator",
"iter",
"=",
"propertyMap",
".",
"getEntrySetIterator",
"(",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"MetaProperty",
"element",
"=",
"(",
"MetaProperty",
")",
"(",
"(",
"SingleKeyHashMap",
".",
"Entry",
")",
"iter",
".",
"next",
"(",
")",
")",
".",
"value",
";",
"if",
"(",
"element",
"instanceof",
"CachedField",
")",
"continue",
";",
"// filter out DGM beans",
"if",
"(",
"element",
"instanceof",
"MetaBeanProperty",
")",
"{",
"MetaBeanProperty",
"mp",
"=",
"(",
"MetaBeanProperty",
")",
"element",
";",
"boolean",
"setter",
"=",
"true",
";",
"boolean",
"getter",
"=",
"true",
";",
"if",
"(",
"mp",
".",
"getGetter",
"(",
")",
"==",
"null",
"||",
"mp",
".",
"getGetter",
"(",
")",
"instanceof",
"GeneratedMetaMethod",
"||",
"mp",
".",
"getGetter",
"(",
")",
"instanceof",
"NewInstanceMetaMethod",
")",
"{",
"getter",
"=",
"false",
";",
"}",
"if",
"(",
"mp",
".",
"getSetter",
"(",
")",
"==",
"null",
"||",
"mp",
".",
"getSetter",
"(",
")",
"instanceof",
"GeneratedMetaMethod",
"||",
"mp",
".",
"getSetter",
"(",
")",
"instanceof",
"NewInstanceMetaMethod",
")",
"{",
"setter",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"setter",
"&&",
"!",
"getter",
")",
"continue",
";",
"// TODO: I (ait) don't know why these strange tricks needed and comment following as it effects some Grails tests",
"// if (!setter && mp.getSetter() != null) {",
"// element = new MetaBeanProperty(mp.getName(), mp.getType(), mp.getGetter(), null);",
"// }",
"// if (!getter && mp.getGetter() != null) {",
"// element = new MetaBeanProperty(mp.getName(), mp.getType(), null, mp.getSetter());",
"// }",
"}",
"ret",
".",
"add",
"(",
"element",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Get all the properties defined for this type
@return a list of MetaProperty objects
|
[
"Get",
"all",
"the",
"properties",
"defined",
"for",
"this",
"type"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L2175-L2211
|
13,071
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.addMetaBeanProperty
|
public void addMetaBeanProperty(MetaBeanProperty mp) {
MetaProperty staticProperty = establishStaticMetaProperty(mp);
if (staticProperty != null) {
staticPropertyIndex.put(mp.getName(), mp);
} else {
SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
//keep field
CachedField field;
MetaProperty old = (MetaProperty) propertyMap.get(mp.getName());
if (old != null) {
if (old instanceof MetaBeanProperty) {
field = ((MetaBeanProperty) old).getField();
} else if (old instanceof MultipleSetterProperty) {
field = ((MultipleSetterProperty)old).getField();
} else {
field = (CachedField) old;
}
mp.setField(field);
}
// put it in the list
// this will overwrite a possible field property
propertyMap.put(mp.getName(), mp);
}
}
|
java
|
public void addMetaBeanProperty(MetaBeanProperty mp) {
MetaProperty staticProperty = establishStaticMetaProperty(mp);
if (staticProperty != null) {
staticPropertyIndex.put(mp.getName(), mp);
} else {
SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
//keep field
CachedField field;
MetaProperty old = (MetaProperty) propertyMap.get(mp.getName());
if (old != null) {
if (old instanceof MetaBeanProperty) {
field = ((MetaBeanProperty) old).getField();
} else if (old instanceof MultipleSetterProperty) {
field = ((MultipleSetterProperty)old).getField();
} else {
field = (CachedField) old;
}
mp.setField(field);
}
// put it in the list
// this will overwrite a possible field property
propertyMap.put(mp.getName(), mp);
}
}
|
[
"public",
"void",
"addMetaBeanProperty",
"(",
"MetaBeanProperty",
"mp",
")",
"{",
"MetaProperty",
"staticProperty",
"=",
"establishStaticMetaProperty",
"(",
"mp",
")",
";",
"if",
"(",
"staticProperty",
"!=",
"null",
")",
"{",
"staticPropertyIndex",
".",
"put",
"(",
"mp",
".",
"getName",
"(",
")",
",",
"mp",
")",
";",
"}",
"else",
"{",
"SingleKeyHashMap",
"propertyMap",
"=",
"classPropertyIndex",
".",
"getNotNull",
"(",
"theCachedClass",
")",
";",
"//keep field",
"CachedField",
"field",
";",
"MetaProperty",
"old",
"=",
"(",
"MetaProperty",
")",
"propertyMap",
".",
"get",
"(",
"mp",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"old",
"!=",
"null",
")",
"{",
"if",
"(",
"old",
"instanceof",
"MetaBeanProperty",
")",
"{",
"field",
"=",
"(",
"(",
"MetaBeanProperty",
")",
"old",
")",
".",
"getField",
"(",
")",
";",
"}",
"else",
"if",
"(",
"old",
"instanceof",
"MultipleSetterProperty",
")",
"{",
"field",
"=",
"(",
"(",
"MultipleSetterProperty",
")",
"old",
")",
".",
"getField",
"(",
")",
";",
"}",
"else",
"{",
"field",
"=",
"(",
"CachedField",
")",
"old",
";",
"}",
"mp",
".",
"setField",
"(",
"field",
")",
";",
"}",
"// put it in the list",
"// this will overwrite a possible field property",
"propertyMap",
".",
"put",
"(",
"mp",
".",
"getName",
"(",
")",
",",
"mp",
")",
";",
"}",
"}"
] |
Adds a new MetaBeanProperty to this MetaClass
@param mp The MetaBeanProperty
|
[
"Adds",
"a",
"new",
"MetaBeanProperty",
"to",
"this",
"MetaClass"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L2647-L2674
|
13,072
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.getClassNode
|
public ClassNode getClassNode() {
if (classNode == null && GroovyObject.class.isAssignableFrom(theClass)) {
// let's try load it from the classpath
String groovyFile = theClass.getName();
int idx = groovyFile.indexOf('$');
if (idx > 0) {
groovyFile = groovyFile.substring(0, idx);
}
groovyFile = groovyFile.replace('.', '/') + ".groovy";
//System.out.println("Attempting to load: " + groovyFile);
URL url = theClass.getClassLoader().getResource(groovyFile);
if (url == null) {
url = Thread.currentThread().getContextClassLoader().getResource(groovyFile);
}
if (url != null) {
try {
/*
* todo there is no CompileUnit in scope so class name
* checking won't work but that mostly affects the bytecode
* generation rather than viewing the AST
*/
CompilationUnit.ClassgenCallback search = new CompilationUnit.ClassgenCallback() {
public void call(ClassVisitor writer, ClassNode node) {
if (node.getName().equals(theClass.getName())) {
MetaClassImpl.this.classNode = node;
}
}
};
CompilationUnit unit = new CompilationUnit();
unit.setClassgenCallback(search);
unit.addSource(url);
unit.compile(Phases.CLASS_GENERATION);
}
catch (Exception e) {
throw new GroovyRuntimeException("Exception thrown parsing: " + groovyFile + ". Reason: " + e, e);
}
}
}
return classNode;
}
|
java
|
public ClassNode getClassNode() {
if (classNode == null && GroovyObject.class.isAssignableFrom(theClass)) {
// let's try load it from the classpath
String groovyFile = theClass.getName();
int idx = groovyFile.indexOf('$');
if (idx > 0) {
groovyFile = groovyFile.substring(0, idx);
}
groovyFile = groovyFile.replace('.', '/') + ".groovy";
//System.out.println("Attempting to load: " + groovyFile);
URL url = theClass.getClassLoader().getResource(groovyFile);
if (url == null) {
url = Thread.currentThread().getContextClassLoader().getResource(groovyFile);
}
if (url != null) {
try {
/*
* todo there is no CompileUnit in scope so class name
* checking won't work but that mostly affects the bytecode
* generation rather than viewing the AST
*/
CompilationUnit.ClassgenCallback search = new CompilationUnit.ClassgenCallback() {
public void call(ClassVisitor writer, ClassNode node) {
if (node.getName().equals(theClass.getName())) {
MetaClassImpl.this.classNode = node;
}
}
};
CompilationUnit unit = new CompilationUnit();
unit.setClassgenCallback(search);
unit.addSource(url);
unit.compile(Phases.CLASS_GENERATION);
}
catch (Exception e) {
throw new GroovyRuntimeException("Exception thrown parsing: " + groovyFile + ". Reason: " + e, e);
}
}
}
return classNode;
}
|
[
"public",
"ClassNode",
"getClassNode",
"(",
")",
"{",
"if",
"(",
"classNode",
"==",
"null",
"&&",
"GroovyObject",
".",
"class",
".",
"isAssignableFrom",
"(",
"theClass",
")",
")",
"{",
"// let's try load it from the classpath",
"String",
"groovyFile",
"=",
"theClass",
".",
"getName",
"(",
")",
";",
"int",
"idx",
"=",
"groovyFile",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"idx",
">",
"0",
")",
"{",
"groovyFile",
"=",
"groovyFile",
".",
"substring",
"(",
"0",
",",
"idx",
")",
";",
"}",
"groovyFile",
"=",
"groovyFile",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
"+",
"\".groovy\"",
";",
"//System.out.println(\"Attempting to load: \" + groovyFile);",
"URL",
"url",
"=",
"theClass",
".",
"getClassLoader",
"(",
")",
".",
"getResource",
"(",
"groovyFile",
")",
";",
"if",
"(",
"url",
"==",
"null",
")",
"{",
"url",
"=",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
".",
"getResource",
"(",
"groovyFile",
")",
";",
"}",
"if",
"(",
"url",
"!=",
"null",
")",
"{",
"try",
"{",
"/*\n * todo there is no CompileUnit in scope so class name\n * checking won't work but that mostly affects the bytecode\n * generation rather than viewing the AST\n */",
"CompilationUnit",
".",
"ClassgenCallback",
"search",
"=",
"new",
"CompilationUnit",
".",
"ClassgenCallback",
"(",
")",
"{",
"public",
"void",
"call",
"(",
"ClassVisitor",
"writer",
",",
"ClassNode",
"node",
")",
"{",
"if",
"(",
"node",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"theClass",
".",
"getName",
"(",
")",
")",
")",
"{",
"MetaClassImpl",
".",
"this",
".",
"classNode",
"=",
"node",
";",
"}",
"}",
"}",
";",
"CompilationUnit",
"unit",
"=",
"new",
"CompilationUnit",
"(",
")",
";",
"unit",
".",
"setClassgenCallback",
"(",
"search",
")",
";",
"unit",
".",
"addSource",
"(",
"url",
")",
";",
"unit",
".",
"compile",
"(",
"Phases",
".",
"CLASS_GENERATION",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"GroovyRuntimeException",
"(",
"\"Exception thrown parsing: \"",
"+",
"groovyFile",
"+",
"\". Reason: \"",
"+",
"e",
",",
"e",
")",
";",
"}",
"}",
"}",
"return",
"classNode",
";",
"}"
] |
Obtains a reference to the original AST for the MetaClass if it is available at runtime
@return The original AST or null if it cannot be returned
|
[
"Obtains",
"a",
"reference",
"to",
"the",
"original",
"AST",
"for",
"the",
"MetaClass",
"if",
"it",
"is",
"available",
"at",
"runtime"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L2984-L3027
|
13,073
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.checkIfGroovyObjectMethod
|
protected final void checkIfGroovyObjectMethod(MetaMethod metaMethod) {
if (metaMethod instanceof ClosureMetaMethod || metaMethod instanceof MixinInstanceMetaMethod) {
if(isGetPropertyMethod(metaMethod)) {
getPropertyMethod = metaMethod;
}
else if(isInvokeMethod(metaMethod)) {
invokeMethodMethod = metaMethod;
}
else if(isSetPropertyMethod(metaMethod)) {
setPropertyMethod = metaMethod;
}
}
}
|
java
|
protected final void checkIfGroovyObjectMethod(MetaMethod metaMethod) {
if (metaMethod instanceof ClosureMetaMethod || metaMethod instanceof MixinInstanceMetaMethod) {
if(isGetPropertyMethod(metaMethod)) {
getPropertyMethod = metaMethod;
}
else if(isInvokeMethod(metaMethod)) {
invokeMethodMethod = metaMethod;
}
else if(isSetPropertyMethod(metaMethod)) {
setPropertyMethod = metaMethod;
}
}
}
|
[
"protected",
"final",
"void",
"checkIfGroovyObjectMethod",
"(",
"MetaMethod",
"metaMethod",
")",
"{",
"if",
"(",
"metaMethod",
"instanceof",
"ClosureMetaMethod",
"||",
"metaMethod",
"instanceof",
"MixinInstanceMetaMethod",
")",
"{",
"if",
"(",
"isGetPropertyMethod",
"(",
"metaMethod",
")",
")",
"{",
"getPropertyMethod",
"=",
"metaMethod",
";",
"}",
"else",
"if",
"(",
"isInvokeMethod",
"(",
"metaMethod",
")",
")",
"{",
"invokeMethodMethod",
"=",
"metaMethod",
";",
"}",
"else",
"if",
"(",
"isSetPropertyMethod",
"(",
"metaMethod",
")",
")",
"{",
"setPropertyMethod",
"=",
"metaMethod",
";",
"}",
"}",
"}"
] |
Checks if the metaMethod is a method from the GroovyObject interface such as setProperty, getProperty and invokeMethod
@param metaMethod The metaMethod instance
@see GroovyObject
|
[
"Checks",
"if",
"the",
"metaMethod",
"is",
"a",
"method",
"from",
"the",
"GroovyObject",
"interface",
"such",
"as",
"setProperty",
"getProperty",
"and",
"invokeMethod"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L3077-L3089
|
13,074
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.chooseMethod
|
protected Object chooseMethod(String methodName, Object methodOrList, Class[] arguments) {
Object method = chooseMethodInternal(methodName, methodOrList, arguments);
if (method instanceof GeneratedMetaMethod.Proxy)
return ((GeneratedMetaMethod.Proxy)method).proxy ();
return method;
}
|
java
|
protected Object chooseMethod(String methodName, Object methodOrList, Class[] arguments) {
Object method = chooseMethodInternal(methodName, methodOrList, arguments);
if (method instanceof GeneratedMetaMethod.Proxy)
return ((GeneratedMetaMethod.Proxy)method).proxy ();
return method;
}
|
[
"protected",
"Object",
"chooseMethod",
"(",
"String",
"methodName",
",",
"Object",
"methodOrList",
",",
"Class",
"[",
"]",
"arguments",
")",
"{",
"Object",
"method",
"=",
"chooseMethodInternal",
"(",
"methodName",
",",
"methodOrList",
",",
"arguments",
")",
";",
"if",
"(",
"method",
"instanceof",
"GeneratedMetaMethod",
".",
"Proxy",
")",
"return",
"(",
"(",
"GeneratedMetaMethod",
".",
"Proxy",
")",
"method",
")",
".",
"proxy",
"(",
")",
";",
"return",
"method",
";",
"}"
] |
Chooses the correct method to use from a list of methods which match by
name.
@param methodOrList the possible methods to choose from
@param arguments the arguments
|
[
"Chooses",
"the",
"correct",
"method",
"to",
"use",
"from",
"a",
"list",
"of",
"methods",
"which",
"match",
"by",
"name",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L3248-L3253
|
13,075
|
apache/groovy
|
src/main/groovy/groovy/lang/MetaClassImpl.java
|
MetaClassImpl.pickMethod
|
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return getMethodWithoutCaching(theClass, methodName, arguments, false);
}
|
java
|
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return getMethodWithoutCaching(theClass, methodName, arguments, false);
}
|
[
"public",
"MetaMethod",
"pickMethod",
"(",
"String",
"methodName",
",",
"Class",
"[",
"]",
"arguments",
")",
"{",
"return",
"getMethodWithoutCaching",
"(",
"theClass",
",",
"methodName",
",",
"arguments",
",",
"false",
")",
";",
"}"
] |
Selects a method by name and argument classes. This method
does not search for an exact match, it searches for a compatible
method. For this the method selection mechanism is used as provided
by the implementation of this MetaClass. pickMethod may or may
not be used during the method selection process when invoking a method.
There is no warranty for that.
@return a matching MetaMethod or null
@throws GroovyRuntimeException if there is more than one matching method
@param methodName the name of the method to pick
@param arguments the method arguments
|
[
"Selects",
"a",
"method",
"by",
"name",
"and",
"argument",
"classes",
".",
"This",
"method",
"does",
"not",
"search",
"for",
"an",
"exact",
"match",
"it",
"searches",
"for",
"a",
"compatible",
"method",
".",
"For",
"this",
"the",
"method",
"selection",
"mechanism",
"is",
"used",
"as",
"provided",
"by",
"the",
"implementation",
"of",
"this",
"MetaClass",
".",
"pickMethod",
"may",
"or",
"may",
"not",
"be",
"used",
"during",
"the",
"method",
"selection",
"process",
"when",
"invoking",
"a",
"method",
".",
"There",
"is",
"no",
"warranty",
"for",
"that",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/MetaClassImpl.java#L3909-L3911
|
13,076
|
apache/groovy
|
src/main/java/org/codehaus/groovy/control/SourceUnit.java
|
SourceUnit.create
|
public static SourceUnit create(String name, String source) {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.setTolerance(1);
return new SourceUnit(name, source, configuration, null, new ErrorCollector(configuration));
}
|
java
|
public static SourceUnit create(String name, String source) {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.setTolerance(1);
return new SourceUnit(name, source, configuration, null, new ErrorCollector(configuration));
}
|
[
"public",
"static",
"SourceUnit",
"create",
"(",
"String",
"name",
",",
"String",
"source",
")",
"{",
"CompilerConfiguration",
"configuration",
"=",
"new",
"CompilerConfiguration",
"(",
")",
";",
"configuration",
".",
"setTolerance",
"(",
"1",
")",
";",
"return",
"new",
"SourceUnit",
"(",
"name",
",",
"source",
",",
"configuration",
",",
"null",
",",
"new",
"ErrorCollector",
"(",
"configuration",
")",
")",
";",
"}"
] |
A convenience routine to create a standalone SourceUnit on a String
with defaults for almost everything that is configurable.
|
[
"A",
"convenience",
"routine",
"to",
"create",
"a",
"standalone",
"SourceUnit",
"on",
"a",
"String",
"with",
"defaults",
"for",
"almost",
"everything",
"that",
"is",
"configurable",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/SourceUnit.java#L185-L190
|
13,077
|
apache/groovy
|
src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberDiv.java
|
NumberNumberDiv.div
|
public static Number div(Number left, Number right) {
return NumberMath.divide(left, right);
}
|
java
|
public static Number div(Number left, Number right) {
return NumberMath.divide(left, right);
}
|
[
"public",
"static",
"Number",
"div",
"(",
"Number",
"left",
",",
"Number",
"right",
")",
"{",
"return",
"NumberMath",
".",
"divide",
"(",
"left",
",",
"right",
")",
";",
"}"
] |
Divide two Numbers.
Note: Method name different from 'divide' to avoid collision with BigInteger method that has
different semantics. We want a BigDecimal result rather than a BigInteger.
@param left a Number
@param right another Number
@return a Number resulting of the divide operation
|
[
"Divide",
"two",
"Numbers",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/dgmimpl/NumberNumberDiv.java#L45-L47
|
13,078
|
apache/groovy
|
benchmark/bench/fannkuch.java
|
fannkuch.print_30_permut
|
private final void print_30_permut()
{
// declare and initialize
final int[] permutation = new int[n];
for ( int i = 0; i < n; i++ )
{
permutation[i] = i;
System.out.print((1 + i));
}
System.out.println();
final int[] perm_remain = new int[n];
for ( int i = 1; i <= n; i++ )
perm_remain[i -1] = i;
int numPermutationsPrinted = 1;
for ( int pos_right = 2; pos_right <= n; pos_right++ )
{
int pos_left = pos_right -1;
do
{
// rotate down perm[0..prev] by one
next_perm(permutation, pos_left);
if (--perm_remain[pos_left] > 0)
{
if (numPermutationsPrinted++ < 30)
{
for (int i = 0; i < n; ++i)
System.out.print((1 + permutation[i]));
System.out.println();
}
else
return;
for ( ; pos_left != 1; --pos_left)
perm_remain[pos_left -1] = pos_left;
}
else
++pos_left;
} while (pos_left < pos_right);
}
}
|
java
|
private final void print_30_permut()
{
// declare and initialize
final int[] permutation = new int[n];
for ( int i = 0; i < n; i++ )
{
permutation[i] = i;
System.out.print((1 + i));
}
System.out.println();
final int[] perm_remain = new int[n];
for ( int i = 1; i <= n; i++ )
perm_remain[i -1] = i;
int numPermutationsPrinted = 1;
for ( int pos_right = 2; pos_right <= n; pos_right++ )
{
int pos_left = pos_right -1;
do
{
// rotate down perm[0..prev] by one
next_perm(permutation, pos_left);
if (--perm_remain[pos_left] > 0)
{
if (numPermutationsPrinted++ < 30)
{
for (int i = 0; i < n; ++i)
System.out.print((1 + permutation[i]));
System.out.println();
}
else
return;
for ( ; pos_left != 1; --pos_left)
perm_remain[pos_left -1] = pos_left;
}
else
++pos_left;
} while (pos_left < pos_right);
}
}
|
[
"private",
"final",
"void",
"print_30_permut",
"(",
")",
"{",
"// declare and initialize",
"final",
"int",
"[",
"]",
"permutation",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"permutation",
"[",
"i",
"]",
"=",
"i",
";",
"System",
".",
"out",
".",
"print",
"(",
"(",
"1",
"+",
"i",
")",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
")",
";",
"final",
"int",
"[",
"]",
"perm_remain",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"n",
";",
"i",
"++",
")",
"perm_remain",
"[",
"i",
"-",
"1",
"]",
"=",
"i",
";",
"int",
"numPermutationsPrinted",
"=",
"1",
";",
"for",
"(",
"int",
"pos_right",
"=",
"2",
";",
"pos_right",
"<=",
"n",
";",
"pos_right",
"++",
")",
"{",
"int",
"pos_left",
"=",
"pos_right",
"-",
"1",
";",
"do",
"{",
"// rotate down perm[0..prev] by one",
"next_perm",
"(",
"permutation",
",",
"pos_left",
")",
";",
"if",
"(",
"--",
"perm_remain",
"[",
"pos_left",
"]",
">",
"0",
")",
"{",
"if",
"(",
"numPermutationsPrinted",
"++",
"<",
"30",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"System",
".",
"out",
".",
"print",
"(",
"(",
"1",
"+",
"permutation",
"[",
"i",
"]",
")",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
")",
";",
"}",
"else",
"return",
";",
"for",
"(",
";",
"pos_left",
"!=",
"1",
";",
"--",
"pos_left",
")",
"perm_remain",
"[",
"pos_left",
"-",
"1",
"]",
"=",
"pos_left",
";",
"}",
"else",
"++",
"pos_left",
";",
"}",
"while",
"(",
"pos_left",
"<",
"pos_right",
")",
";",
"}",
"}"
] |
this function will 'correctly' print first 30 permutations
|
[
"this",
"function",
"will",
"correctly",
"print",
"first",
"30",
"permutations"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/benchmark/bench/fannkuch.java#L63-L105
|
13,079
|
apache/groovy
|
benchmark/bench/fannkuch.java
|
fannkuch.count_flip
|
private static final int count_flip(final int[] perm_flip)
{
// cache first element, avoid swapping perm[0] and perm[k]
int v0 = perm_flip[0];
int tmp;
int flip_count = 0;
do
{
for (int i = 1, j = v0 - 1; i < j; ++i, --j)
{
tmp = perm_flip[i];
perm_flip[i] = perm_flip[j];
perm_flip[j] = tmp;
}
tmp = perm_flip[v0];
perm_flip[v0] = v0;
v0 = tmp;
flip_count++;
} while (v0 != 0); // first element == '1' ?
return flip_count;
}
|
java
|
private static final int count_flip(final int[] perm_flip)
{
// cache first element, avoid swapping perm[0] and perm[k]
int v0 = perm_flip[0];
int tmp;
int flip_count = 0;
do
{
for (int i = 1, j = v0 - 1; i < j; ++i, --j)
{
tmp = perm_flip[i];
perm_flip[i] = perm_flip[j];
perm_flip[j] = tmp;
}
tmp = perm_flip[v0];
perm_flip[v0] = v0;
v0 = tmp;
flip_count++;
} while (v0 != 0); // first element == '1' ?
return flip_count;
}
|
[
"private",
"static",
"final",
"int",
"count_flip",
"(",
"final",
"int",
"[",
"]",
"perm_flip",
")",
"{",
"// cache first element, avoid swapping perm[0] and perm[k]",
"int",
"v0",
"=",
"perm_flip",
"[",
"0",
"]",
";",
"int",
"tmp",
";",
"int",
"flip_count",
"=",
"0",
";",
"do",
"{",
"for",
"(",
"int",
"i",
"=",
"1",
",",
"j",
"=",
"v0",
"-",
"1",
";",
"i",
"<",
"j",
";",
"++",
"i",
",",
"--",
"j",
")",
"{",
"tmp",
"=",
"perm_flip",
"[",
"i",
"]",
";",
"perm_flip",
"[",
"i",
"]",
"=",
"perm_flip",
"[",
"j",
"]",
";",
"perm_flip",
"[",
"j",
"]",
"=",
"tmp",
";",
"}",
"tmp",
"=",
"perm_flip",
"[",
"v0",
"]",
";",
"perm_flip",
"[",
"v0",
"]",
"=",
"v0",
";",
"v0",
"=",
"tmp",
";",
"flip_count",
"++",
";",
"}",
"while",
"(",
"v0",
"!=",
"0",
")",
";",
"// first element == '1' ?",
"return",
"flip_count",
";",
"}"
] |
Return flipping times
|
[
"Return",
"flipping",
"times"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/benchmark/bench/fannkuch.java#L158-L182
|
13,080
|
apache/groovy
|
src/main/groovy/groovy/lang/Tuple.java
|
Tuple.tuple
|
public static <T1, T2, T3> Tuple3<T1, T2, T3> tuple(T1 v1, T2 v2, T3 v3) {
return new Tuple3<>(v1, v2, v3);
}
|
java
|
public static <T1, T2, T3> Tuple3<T1, T2, T3> tuple(T1 v1, T2 v2, T3 v3) {
return new Tuple3<>(v1, v2, v3);
}
|
[
"public",
"static",
"<",
"T1",
",",
"T2",
",",
"T3",
">",
"Tuple3",
"<",
"T1",
",",
"T2",
",",
"T3",
">",
"tuple",
"(",
"T1",
"v1",
",",
"T2",
"v2",
",",
"T3",
"v3",
")",
"{",
"return",
"new",
"Tuple3",
"<>",
"(",
"v1",
",",
"v2",
",",
"v3",
")",
";",
"}"
] |
Construct a tuple of degree 3.
|
[
"Construct",
"a",
"tuple",
"of",
"degree",
"3",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Tuple.java#L145-L147
|
13,081
|
apache/groovy
|
subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java
|
DefaultTableModel.addPropertyColumn
|
public DefaultTableColumn addPropertyColumn(Object headerValue, String property, Class type) {
return addColumn(headerValue, property, new PropertyModel(rowModel, property, type));
}
|
java
|
public DefaultTableColumn addPropertyColumn(Object headerValue, String property, Class type) {
return addColumn(headerValue, property, new PropertyModel(rowModel, property, type));
}
|
[
"public",
"DefaultTableColumn",
"addPropertyColumn",
"(",
"Object",
"headerValue",
",",
"String",
"property",
",",
"Class",
"type",
")",
"{",
"return",
"addColumn",
"(",
"headerValue",
",",
"property",
",",
"new",
"PropertyModel",
"(",
"rowModel",
",",
"property",
",",
"type",
")",
")",
";",
"}"
] |
Adds a property model column to the table
|
[
"Adds",
"a",
"property",
"model",
"column",
"to",
"the",
"table"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java#L63-L65
|
13,082
|
apache/groovy
|
subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java
|
DefaultTableModel.addClosureColumn
|
public DefaultTableColumn addClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type) {
return addColumn(headerValue, new ClosureModel(rowModel, readClosure, writeClosure, type));
}
|
java
|
public DefaultTableColumn addClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type) {
return addColumn(headerValue, new ClosureModel(rowModel, readClosure, writeClosure, type));
}
|
[
"public",
"DefaultTableColumn",
"addClosureColumn",
"(",
"Object",
"headerValue",
",",
"Closure",
"readClosure",
",",
"Closure",
"writeClosure",
",",
"Class",
"type",
")",
"{",
"return",
"addColumn",
"(",
"headerValue",
",",
"new",
"ClosureModel",
"(",
"rowModel",
",",
"readClosure",
",",
"writeClosure",
",",
"type",
")",
")",
";",
"}"
] |
Adds a closure based column to the table
|
[
"Adds",
"a",
"closure",
"based",
"column",
"to",
"the",
"table"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java#L77-L79
|
13,083
|
apache/groovy
|
subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java
|
DefaultTableModel.addColumn
|
public void addColumn(DefaultTableColumn column) {
column.setModelIndex(columnModel.getColumnCount());
columnModel.addColumn(column);
}
|
java
|
public void addColumn(DefaultTableColumn column) {
column.setModelIndex(columnModel.getColumnCount());
columnModel.addColumn(column);
}
|
[
"public",
"void",
"addColumn",
"(",
"DefaultTableColumn",
"column",
")",
"{",
"column",
".",
"setModelIndex",
"(",
"columnModel",
".",
"getColumnCount",
"(",
")",
")",
";",
"columnModel",
".",
"addColumn",
"(",
"column",
")",
";",
"}"
] |
Adds a new column definition to the table
|
[
"Adds",
"a",
"new",
"column",
"definition",
"to",
"the",
"table"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/groovy/model/DefaultTableModel.java#L94-L97
|
13,084
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.setRedirect
|
public void setRedirect(ClassNode cn) {
if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode ("+getName()+"->"+cn.getName()+").");
if (cn!=null) cn = cn.redirect();
if (cn==this) return;
redirect = cn;
}
|
java
|
public void setRedirect(ClassNode cn) {
if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode ("+getName()+"->"+cn.getName()+").");
if (cn!=null) cn = cn.redirect();
if (cn==this) return;
redirect = cn;
}
|
[
"public",
"void",
"setRedirect",
"(",
"ClassNode",
"cn",
")",
"{",
"if",
"(",
"isPrimaryNode",
")",
"throw",
"new",
"GroovyBugError",
"(",
"\"tried to set a redirect for a primary ClassNode (\"",
"+",
"getName",
"(",
")",
"+",
"\"->\"",
"+",
"cn",
".",
"getName",
"(",
")",
"+",
"\").\"",
")",
";",
"if",
"(",
"cn",
"!=",
"null",
")",
"cn",
"=",
"cn",
".",
"redirect",
"(",
")",
";",
"if",
"(",
"cn",
"==",
"this",
")",
"return",
";",
"redirect",
"=",
"cn",
";",
"}"
] |
Sets this instance as proxy for the given ClassNode.
@param cn the class to redirect to. If set to null the redirect will be removed
|
[
"Sets",
"this",
"instance",
"as",
"proxy",
"for",
"the",
"given",
"ClassNode",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L203-L208
|
13,085
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.makeArray
|
public ClassNode makeArray() {
if (redirect!=null) {
ClassNode res = redirect().makeArray();
res.componentType = this;
return res;
}
ClassNode cn;
if (clazz!=null) {
Class ret = Array.newInstance(clazz,0).getClass();
// don't use the ClassHelper here!
cn = new ClassNode(ret,this);
} else {
cn = new ClassNode(this);
}
return cn;
}
|
java
|
public ClassNode makeArray() {
if (redirect!=null) {
ClassNode res = redirect().makeArray();
res.componentType = this;
return res;
}
ClassNode cn;
if (clazz!=null) {
Class ret = Array.newInstance(clazz,0).getClass();
// don't use the ClassHelper here!
cn = new ClassNode(ret,this);
} else {
cn = new ClassNode(this);
}
return cn;
}
|
[
"public",
"ClassNode",
"makeArray",
"(",
")",
"{",
"if",
"(",
"redirect",
"!=",
"null",
")",
"{",
"ClassNode",
"res",
"=",
"redirect",
"(",
")",
".",
"makeArray",
"(",
")",
";",
"res",
".",
"componentType",
"=",
"this",
";",
"return",
"res",
";",
"}",
"ClassNode",
"cn",
";",
"if",
"(",
"clazz",
"!=",
"null",
")",
"{",
"Class",
"ret",
"=",
"Array",
".",
"newInstance",
"(",
"clazz",
",",
"0",
")",
".",
"getClass",
"(",
")",
";",
"// don't use the ClassHelper here!",
"cn",
"=",
"new",
"ClassNode",
"(",
"ret",
",",
"this",
")",
";",
"}",
"else",
"{",
"cn",
"=",
"new",
"ClassNode",
"(",
"this",
")",
";",
"}",
"return",
"cn",
";",
"}"
] |
Returns a ClassNode representing an array of the class
represented by this ClassNode
|
[
"Returns",
"a",
"ClassNode",
"representing",
"an",
"array",
"of",
"the",
"class",
"represented",
"by",
"this",
"ClassNode"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L214-L229
|
13,086
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.lazyClassInit
|
private void lazyClassInit() {
if (lazyInitDone) return;
synchronized (lazyInitLock) {
if (redirect!=null) {
throw new GroovyBugError("lazyClassInit called on a proxy ClassNode, that must not happen."+
"A redirect() call is missing somewhere!");
}
if (lazyInitDone) return;
VMPluginFactory.getPlugin().configureClassNode(compileUnit,this);
lazyInitDone = true;
}
}
|
java
|
private void lazyClassInit() {
if (lazyInitDone) return;
synchronized (lazyInitLock) {
if (redirect!=null) {
throw new GroovyBugError("lazyClassInit called on a proxy ClassNode, that must not happen."+
"A redirect() call is missing somewhere!");
}
if (lazyInitDone) return;
VMPluginFactory.getPlugin().configureClassNode(compileUnit,this);
lazyInitDone = true;
}
}
|
[
"private",
"void",
"lazyClassInit",
"(",
")",
"{",
"if",
"(",
"lazyInitDone",
")",
"return",
";",
"synchronized",
"(",
"lazyInitLock",
")",
"{",
"if",
"(",
"redirect",
"!=",
"null",
")",
"{",
"throw",
"new",
"GroovyBugError",
"(",
"\"lazyClassInit called on a proxy ClassNode, that must not happen.\"",
"+",
"\"A redirect() call is missing somewhere!\"",
")",
";",
"}",
"if",
"(",
"lazyInitDone",
")",
"return",
";",
"VMPluginFactory",
".",
"getPlugin",
"(",
")",
".",
"configureClassNode",
"(",
"compileUnit",
",",
"this",
")",
";",
"lazyInitDone",
"=",
"true",
";",
"}",
"}"
] |
The complete class structure will be initialized only when really
needed to avoid having too many objects during compilation
|
[
"The",
"complete",
"class",
"structure",
"will",
"be",
"initialized",
"only",
"when",
"really",
"needed",
"to",
"avoid",
"having",
"too",
"many",
"objects",
"during",
"compilation"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L273-L284
|
13,087
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getDeclaredConstructor
|
public ConstructorNode getDeclaredConstructor(Parameter[] parameters) {
for (ConstructorNode method : getDeclaredConstructors()) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
java
|
public ConstructorNode getDeclaredConstructor(Parameter[] parameters) {
for (ConstructorNode method : getDeclaredConstructors()) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
[
"public",
"ConstructorNode",
"getDeclaredConstructor",
"(",
"Parameter",
"[",
"]",
"parameters",
")",
"{",
"for",
"(",
"ConstructorNode",
"method",
":",
"getDeclaredConstructors",
"(",
")",
")",
"{",
"if",
"(",
"parametersEqual",
"(",
"method",
".",
"getParameters",
"(",
")",
",",
"parameters",
")",
")",
"{",
"return",
"method",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Finds a constructor matching the given parameters in this class.
@return the constructor matching the given parameters or null
|
[
"Finds",
"a",
"constructor",
"matching",
"the",
"given",
"parameters",
"in",
"this",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L502-L509
|
13,088
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.addSyntheticMethod
|
public MethodNode addSyntheticMethod(String name,
int modifiers,
ClassNode returnType,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code) {
MethodNode answer = addMethod(name, modifiers|ACC_SYNTHETIC, returnType, parameters, exceptions, code);
answer.setSynthetic(true);
return answer;
}
|
java
|
public MethodNode addSyntheticMethod(String name,
int modifiers,
ClassNode returnType,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code) {
MethodNode answer = addMethod(name, modifiers|ACC_SYNTHETIC, returnType, parameters, exceptions, code);
answer.setSynthetic(true);
return answer;
}
|
[
"public",
"MethodNode",
"addSyntheticMethod",
"(",
"String",
"name",
",",
"int",
"modifiers",
",",
"ClassNode",
"returnType",
",",
"Parameter",
"[",
"]",
"parameters",
",",
"ClassNode",
"[",
"]",
"exceptions",
",",
"Statement",
"code",
")",
"{",
"MethodNode",
"answer",
"=",
"addMethod",
"(",
"name",
",",
"modifiers",
"|",
"ACC_SYNTHETIC",
",",
"returnType",
",",
"parameters",
",",
"exceptions",
",",
"code",
")",
";",
"answer",
".",
"setSynthetic",
"(",
"true",
")",
";",
"return",
"answer",
";",
"}"
] |
Adds a synthetic method as part of the compilation process
|
[
"Adds",
"a",
"synthetic",
"method",
"as",
"part",
"of",
"the",
"compilation",
"process"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L680-L689
|
13,089
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getDeclaredField
|
public FieldNode getDeclaredField(String name) {
if (redirect != null) return redirect().getDeclaredField(name);
lazyClassInit();
return fieldIndex == null ? null : fieldIndex.get(name);
}
|
java
|
public FieldNode getDeclaredField(String name) {
if (redirect != null) return redirect().getDeclaredField(name);
lazyClassInit();
return fieldIndex == null ? null : fieldIndex.get(name);
}
|
[
"public",
"FieldNode",
"getDeclaredField",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"redirect",
"!=",
"null",
")",
"return",
"redirect",
"(",
")",
".",
"getDeclaredField",
"(",
"name",
")",
";",
"lazyClassInit",
"(",
")",
";",
"return",
"fieldIndex",
"==",
"null",
"?",
"null",
":",
"fieldIndex",
".",
"get",
"(",
"name",
")",
";",
"}"
] |
Finds a field matching the given name in this class.
@param name the name of the field of interest
@return the method matching the given name and parameters or null
|
[
"Finds",
"a",
"field",
"matching",
"the",
"given",
"name",
"in",
"this",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L757-L762
|
13,090
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getField
|
public FieldNode getField(String name) {
ClassNode node = this;
while (node != null) {
FieldNode fn = node.getDeclaredField(name);
if (fn != null) return fn;
node = node.getSuperClass();
}
return null;
}
|
java
|
public FieldNode getField(String name) {
ClassNode node = this;
while (node != null) {
FieldNode fn = node.getDeclaredField(name);
if (fn != null) return fn;
node = node.getSuperClass();
}
return null;
}
|
[
"public",
"FieldNode",
"getField",
"(",
"String",
"name",
")",
"{",
"ClassNode",
"node",
"=",
"this",
";",
"while",
"(",
"node",
"!=",
"null",
")",
"{",
"FieldNode",
"fn",
"=",
"node",
".",
"getDeclaredField",
"(",
"name",
")",
";",
"if",
"(",
"fn",
"!=",
"null",
")",
"return",
"fn",
";",
"node",
"=",
"node",
".",
"getSuperClass",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Finds a field matching the given name in this class or a parent class.
@param name the name of the field of interest
@return the method matching the given name and parameters or null
|
[
"Finds",
"a",
"field",
"matching",
"the",
"given",
"name",
"in",
"this",
"class",
"or",
"a",
"parent",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L770-L778
|
13,091
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getDeclaredMethods
|
public List<MethodNode> getDeclaredMethods(String name) {
if (redirect!=null) return redirect().getDeclaredMethods(name);
lazyClassInit();
return methods.getNotNull(name);
}
|
java
|
public List<MethodNode> getDeclaredMethods(String name) {
if (redirect!=null) return redirect().getDeclaredMethods(name);
lazyClassInit();
return methods.getNotNull(name);
}
|
[
"public",
"List",
"<",
"MethodNode",
">",
"getDeclaredMethods",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"redirect",
"!=",
"null",
")",
"return",
"redirect",
"(",
")",
".",
"getDeclaredMethods",
"(",
"name",
")",
";",
"lazyClassInit",
"(",
")",
";",
"return",
"methods",
".",
"getNotNull",
"(",
"name",
")",
";",
"}"
] |
This methods returns a list of all methods of the given name
defined in the current class
@return the method list
@see #getMethods(String)
|
[
"This",
"methods",
"returns",
"a",
"list",
"of",
"all",
"methods",
"of",
"the",
"given",
"name",
"defined",
"in",
"the",
"current",
"class"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L902-L906
|
13,092
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getMethods
|
public List<MethodNode> getMethods(String name) {
List<MethodNode> answer = new ArrayList<MethodNode>();
ClassNode node = this;
while (node != null) {
answer.addAll(node.getDeclaredMethods(name));
node = node.getSuperClass();
}
return answer;
}
|
java
|
public List<MethodNode> getMethods(String name) {
List<MethodNode> answer = new ArrayList<MethodNode>();
ClassNode node = this;
while (node != null) {
answer.addAll(node.getDeclaredMethods(name));
node = node.getSuperClass();
}
return answer;
}
|
[
"public",
"List",
"<",
"MethodNode",
">",
"getMethods",
"(",
"String",
"name",
")",
"{",
"List",
"<",
"MethodNode",
">",
"answer",
"=",
"new",
"ArrayList",
"<",
"MethodNode",
">",
"(",
")",
";",
"ClassNode",
"node",
"=",
"this",
";",
"while",
"(",
"node",
"!=",
"null",
")",
"{",
"answer",
".",
"addAll",
"(",
"node",
".",
"getDeclaredMethods",
"(",
"name",
")",
")",
";",
"node",
"=",
"node",
".",
"getSuperClass",
"(",
")",
";",
"}",
"return",
"answer",
";",
"}"
] |
This methods creates a list of all methods with this name of the
current class and of all super classes
@return the methods list
@see #getDeclaredMethods(String)
|
[
"This",
"methods",
"creates",
"a",
"list",
"of",
"all",
"methods",
"with",
"this",
"name",
"of",
"the",
"current",
"class",
"and",
"of",
"all",
"super",
"classes"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L914-L922
|
13,093
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getDeclaredMethod
|
public MethodNode getDeclaredMethod(String name, Parameter[] parameters) {
for (MethodNode method : getDeclaredMethods(name)) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
java
|
public MethodNode getDeclaredMethod(String name, Parameter[] parameters) {
for (MethodNode method : getDeclaredMethods(name)) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
[
"public",
"MethodNode",
"getDeclaredMethod",
"(",
"String",
"name",
",",
"Parameter",
"[",
"]",
"parameters",
")",
"{",
"for",
"(",
"MethodNode",
"method",
":",
"getDeclaredMethods",
"(",
"name",
")",
")",
"{",
"if",
"(",
"parametersEqual",
"(",
"method",
".",
"getParameters",
"(",
")",
",",
"parameters",
")",
")",
"{",
"return",
"method",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Finds a method matching the given name and parameters in this class.
@return the method matching the given name and parameters or null
|
[
"Finds",
"a",
"method",
"matching",
"the",
"given",
"name",
"and",
"parameters",
"in",
"this",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L929-L936
|
13,094
|
apache/groovy
|
src/main/java/org/codehaus/groovy/ast/ClassNode.java
|
ClassNode.getMethod
|
public MethodNode getMethod(String name, Parameter[] parameters) {
for (MethodNode method : getMethods(name)) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
java
|
public MethodNode getMethod(String name, Parameter[] parameters) {
for (MethodNode method : getMethods(name)) {
if (parametersEqual(method.getParameters(), parameters)) {
return method;
}
}
return null;
}
|
[
"public",
"MethodNode",
"getMethod",
"(",
"String",
"name",
",",
"Parameter",
"[",
"]",
"parameters",
")",
"{",
"for",
"(",
"MethodNode",
"method",
":",
"getMethods",
"(",
"name",
")",
")",
"{",
"if",
"(",
"parametersEqual",
"(",
"method",
".",
"getParameters",
"(",
")",
",",
"parameters",
")",
")",
"{",
"return",
"method",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Finds a method matching the given name and parameters in this class
or any parent class.
@return the method matching the given name and parameters or null
|
[
"Finds",
"a",
"method",
"matching",
"the",
"given",
"name",
"and",
"parameters",
"in",
"this",
"class",
"or",
"any",
"parent",
"class",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/ClassNode.java#L944-L951
|
13,095
|
apache/groovy
|
src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java
|
MopWriter.getMopMethodName
|
public static String getMopMethodName(MethodNode method, boolean useThis) {
ClassNode declaringNode = method.getDeclaringClass();
int distance = 0;
for (; declaringNode != null; declaringNode = declaringNode.getSuperClass()) {
distance++;
}
return (useThis ? "this" : "super") + "$" + distance + "$" + method.getName();
}
|
java
|
public static String getMopMethodName(MethodNode method, boolean useThis) {
ClassNode declaringNode = method.getDeclaringClass();
int distance = 0;
for (; declaringNode != null; declaringNode = declaringNode.getSuperClass()) {
distance++;
}
return (useThis ? "this" : "super") + "$" + distance + "$" + method.getName();
}
|
[
"public",
"static",
"String",
"getMopMethodName",
"(",
"MethodNode",
"method",
",",
"boolean",
"useThis",
")",
"{",
"ClassNode",
"declaringNode",
"=",
"method",
".",
"getDeclaringClass",
"(",
")",
";",
"int",
"distance",
"=",
"0",
";",
"for",
"(",
";",
"declaringNode",
"!=",
"null",
";",
"declaringNode",
"=",
"declaringNode",
".",
"getSuperClass",
"(",
")",
")",
"{",
"distance",
"++",
";",
"}",
"return",
"(",
"useThis",
"?",
"\"this\"",
":",
"\"super\"",
")",
"+",
"\"$\"",
"+",
"distance",
"+",
"\"$\"",
"+",
"method",
".",
"getName",
"(",
")",
";",
"}"
] |
creates a MOP method name from a method
@param method the method to be called by the mop method
@param useThis if true, then it is a call on "this", "super" else
@return the mop method name
|
[
"creates",
"a",
"MOP",
"method",
"name",
"from",
"a",
"method"
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java#L160-L167
|
13,096
|
apache/groovy
|
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
|
XmlUtil.serialize
|
public static void serialize(Element element, OutputStream os) {
Source source = new DOMSource(element);
serialize(source, os);
}
|
java
|
public static void serialize(Element element, OutputStream os) {
Source source = new DOMSource(element);
serialize(source, os);
}
|
[
"public",
"static",
"void",
"serialize",
"(",
"Element",
"element",
",",
"OutputStream",
"os",
")",
"{",
"Source",
"source",
"=",
"new",
"DOMSource",
"(",
"element",
")",
";",
"serialize",
"(",
"source",
",",
"os",
")",
";",
"}"
] |
Write a pretty version of the Element to the OutputStream.
@param element the Element to serialize
@param os the OutputStream to write to
|
[
"Write",
"a",
"pretty",
"version",
"of",
"the",
"Element",
"to",
"the",
"OutputStream",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L78-L81
|
13,097
|
apache/groovy
|
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
|
XmlUtil.serialize
|
public static void serialize(Element element, Writer w) {
Source source = new DOMSource(element);
serialize(source, w);
}
|
java
|
public static void serialize(Element element, Writer w) {
Source source = new DOMSource(element);
serialize(source, w);
}
|
[
"public",
"static",
"void",
"serialize",
"(",
"Element",
"element",
",",
"Writer",
"w",
")",
"{",
"Source",
"source",
"=",
"new",
"DOMSource",
"(",
"element",
")",
";",
"serialize",
"(",
"source",
",",
"w",
")",
";",
"}"
] |
Write a pretty version of the Element to the Writer.
@param element the Element to serialize
@param w the Writer to write to
|
[
"Write",
"a",
"pretty",
"version",
"of",
"the",
"Element",
"to",
"the",
"Writer",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L89-L92
|
13,098
|
apache/groovy
|
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
|
XmlUtil.newSAXParser
|
public static SAXParser newSAXParser(String schemaLanguage, Source... schemas) throws SAXException, ParserConfigurationException {
return newSAXParser(schemaLanguage, true, false, schemas);
}
|
java
|
public static SAXParser newSAXParser(String schemaLanguage, Source... schemas) throws SAXException, ParserConfigurationException {
return newSAXParser(schemaLanguage, true, false, schemas);
}
|
[
"public",
"static",
"SAXParser",
"newSAXParser",
"(",
"String",
"schemaLanguage",
",",
"Source",
"...",
"schemas",
")",
"throws",
"SAXException",
",",
"ParserConfigurationException",
"{",
"return",
"newSAXParser",
"(",
"schemaLanguage",
",",
"true",
",",
"false",
",",
"schemas",
")",
";",
"}"
] |
Factory method to create a SAXParser configured to validate according to a particular schema language and
optionally providing the schema sources to validate with.
The created SAXParser will be namespace-aware and not validate against DTDs.
@param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants)
@param schemas the schemas to validate against
@return the created SAXParser
@throws SAXException
@throws ParserConfigurationException
@see #newSAXParser(String, boolean, boolean, Source...)
@since 1.8.7
|
[
"Factory",
"method",
"to",
"create",
"a",
"SAXParser",
"configured",
"to",
"validate",
"according",
"to",
"a",
"particular",
"schema",
"language",
"and",
"optionally",
"providing",
"the",
"schema",
"sources",
"to",
"validate",
"with",
".",
"The",
"created",
"SAXParser",
"will",
"be",
"namespace",
"-",
"aware",
"and",
"not",
"validate",
"against",
"DTDs",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L229-L231
|
13,099
|
apache/groovy
|
subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
|
XmlUtil.newSAXParser
|
public static SAXParser newSAXParser(String schemaLanguage, boolean namespaceAware, boolean validating, Source... schemas) throws SAXException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
if (schemas.length != 0) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
factory.setSchema(schemaFactory.newSchema(schemas));
}
SAXParser saxParser = factory.newSAXParser();
if (schemas.length == 0) {
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", schemaLanguage);
}
return saxParser;
}
|
java
|
public static SAXParser newSAXParser(String schemaLanguage, boolean namespaceAware, boolean validating, Source... schemas) throws SAXException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
if (schemas.length != 0) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
factory.setSchema(schemaFactory.newSchema(schemas));
}
SAXParser saxParser = factory.newSAXParser();
if (schemas.length == 0) {
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", schemaLanguage);
}
return saxParser;
}
|
[
"public",
"static",
"SAXParser",
"newSAXParser",
"(",
"String",
"schemaLanguage",
",",
"boolean",
"namespaceAware",
",",
"boolean",
"validating",
",",
"Source",
"...",
"schemas",
")",
"throws",
"SAXException",
",",
"ParserConfigurationException",
"{",
"SAXParserFactory",
"factory",
"=",
"SAXParserFactory",
".",
"newInstance",
"(",
")",
";",
"factory",
".",
"setValidating",
"(",
"validating",
")",
";",
"factory",
".",
"setNamespaceAware",
"(",
"namespaceAware",
")",
";",
"if",
"(",
"schemas",
".",
"length",
"!=",
"0",
")",
"{",
"SchemaFactory",
"schemaFactory",
"=",
"SchemaFactory",
".",
"newInstance",
"(",
"schemaLanguage",
")",
";",
"factory",
".",
"setSchema",
"(",
"schemaFactory",
".",
"newSchema",
"(",
"schemas",
")",
")",
";",
"}",
"SAXParser",
"saxParser",
"=",
"factory",
".",
"newSAXParser",
"(",
")",
";",
"if",
"(",
"schemas",
".",
"length",
"==",
"0",
")",
"{",
"saxParser",
".",
"setProperty",
"(",
"\"http://java.sun.com/xml/jaxp/properties/schemaLanguage\"",
",",
"schemaLanguage",
")",
";",
"}",
"return",
"saxParser",
";",
"}"
] |
Factory method to create a SAXParser configured to validate according to a particular schema language and
optionally providing the schema sources to validate with.
@param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants)
@param namespaceAware will the parser be namespace aware
@param validating will the parser also validate against DTDs
@param schemas the schemas to validate against
@return the created SAXParser
@throws SAXException
@throws ParserConfigurationException
@since 1.8.7
|
[
"Factory",
"method",
"to",
"create",
"a",
"SAXParser",
"configured",
"to",
"validate",
"according",
"to",
"a",
"particular",
"schema",
"language",
"and",
"optionally",
"providing",
"the",
"schema",
"sources",
"to",
"validate",
"with",
"."
] |
71cf20addb611bb8d097a59e395fd20bc7f31772
|
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java#L246-L259
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.