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
partition
stringclasses
1 value
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/HasManyModel.java
HasManyModel.findAllChildren
public List<C> findAllChildren() { List<String> objects = getChildrenList(); List<C> children = new ArrayList<C>(); try { Model dummy = (Model) childClazz.newInstance(); dummy.setContext(context); for (String id : objects) { children.add((C) dummy.find(id)); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } return children; }
java
public List<C> findAllChildren() { List<String> objects = getChildrenList(); List<C> children = new ArrayList<C>(); try { Model dummy = (Model) childClazz.newInstance(); dummy.setContext(context); for (String id : objects) { children.add((C) dummy.find(id)); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } return children; }
[ "public", "List", "<", "C", ">", "findAllChildren", "(", ")", "{", "List", "<", "String", ">", "objects", "=", "getChildrenList", "(", ")", ";", "List", "<", "C", ">", "children", "=", "new", "ArrayList", "<", "C", ">", "(", ")", ";", "try", "{", ...
Find all objects from the child list. TODO: Figure out how to make this accesible without... creating a dummy instance. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context. @return A list of all children.
[ "Find", "all", "objects", "from", "the", "child", "list", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/HasManyModel.java#L196-L215
train
fnklabs/draenei
src/main/java/com/fnklabs/draenei/analytics/search/DraeneiSearchService.java
DraeneiSearchService.filter
private Collection<Facet> filter(Collection<Facet> facets) { if (NotStopWordPredicate == null) { return facets; } return facets.stream() .filter(NotStopWordPredicate) .collect(Collectors.toList()); }
java
private Collection<Facet> filter(Collection<Facet> facets) { if (NotStopWordPredicate == null) { return facets; } return facets.stream() .filter(NotStopWordPredicate) .collect(Collectors.toList()); }
[ "private", "Collection", "<", "Facet", ">", "filter", "(", "Collection", "<", "Facet", ">", "facets", ")", "{", "if", "(", "NotStopWordPredicate", "==", "null", ")", "{", "return", "facets", ";", "}", "return", "facets", ".", "stream", "(", ")", ".", "...
Filter stop word facets @param facets Input facets @return
[ "Filter", "stop", "word", "facets" ]
0a8cac54f1f635be3e2950375a23291d38453ae8
https://github.com/fnklabs/draenei/blob/0a8cac54f1f635be3e2950375a23291d38453ae8/src/main/java/com/fnklabs/draenei/analytics/search/DraeneiSearchService.java#L238-L247
train
NessComputing/service-discovery
client/src/main/java/com/nesscomputing/service/discovery/client/internal/ConsistentRingGroup.java
ConsistentRingGroup.getRing
public ConsistentHashRing getRing(String type) { ConsistentHashRing ring = rings.get(type); if (ring != null) { return ring; } if (type == null) { //If there's no ring without a type, then any type will do //Use weighted random among the types, based on how many servers are serving each type int selection = rand.nextInt() % totalServers; for (ConsistentHashRing candidateRing: rings.values()) { if (selection <= 0) { return candidateRing; } else { selection -= candidateRing.size(); } } //It's possible there are no rings Preconditions.checkState(totalServers == 0, "It shouldn't be possible to get here, " + "unless there are no rings"); return null; } else { //If there's no server for this type, then pick one without a type return rings.get(null); } }
java
public ConsistentHashRing getRing(String type) { ConsistentHashRing ring = rings.get(type); if (ring != null) { return ring; } if (type == null) { //If there's no ring without a type, then any type will do //Use weighted random among the types, based on how many servers are serving each type int selection = rand.nextInt() % totalServers; for (ConsistentHashRing candidateRing: rings.values()) { if (selection <= 0) { return candidateRing; } else { selection -= candidateRing.size(); } } //It's possible there are no rings Preconditions.checkState(totalServers == 0, "It shouldn't be possible to get here, " + "unless there are no rings"); return null; } else { //If there's no server for this type, then pick one without a type return rings.get(null); } }
[ "public", "ConsistentHashRing", "getRing", "(", "String", "type", ")", "{", "ConsistentHashRing", "ring", "=", "rings", ".", "get", "(", "type", ")", ";", "if", "(", "ring", "!=", "null", ")", "{", "return", "ring", ";", "}", "if", "(", "type", "==", ...
Get the server ring for a particular type. Notes on running time: if type != null: O(1) if type == null and there is at least 1 service with null type: O(1) otherwise: O(N) where N is the number of types @param type @return
[ "Get", "the", "server", "ring", "for", "a", "particular", "type", "." ]
5091ffdb1de6b12d216d1c238f72858037c7b765
https://github.com/NessComputing/service-discovery/blob/5091ffdb1de6b12d216d1c238f72858037c7b765/client/src/main/java/com/nesscomputing/service/discovery/client/internal/ConsistentRingGroup.java#L75-L99
train
dbracewell/mango
src/main/java/com/davidbracewell/collection/index/InvertedIndex.java
InvertedIndex.add
public void add(DOCUMENT doc) { if (doc != null) { documents.add(doc); int id = documents.size() - 1; for (KEY key : documentMapper.apply(doc)) { index.put(key, id); } } }
java
public void add(DOCUMENT doc) { if (doc != null) { documents.add(doc); int id = documents.size() - 1; for (KEY key : documentMapper.apply(doc)) { index.put(key, id); } } }
[ "public", "void", "add", "(", "DOCUMENT", "doc", ")", "{", "if", "(", "doc", "!=", "null", ")", "{", "documents", ".", "add", "(", "doc", ")", ";", "int", "id", "=", "documents", ".", "size", "(", ")", "-", "1", ";", "for", "(", "KEY", "key", ...
Add void. @param doc the doc
[ "Add", "void", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/collection/index/InvertedIndex.java#L64-L72
train
dbracewell/mango
src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java
ScriptEnvironmentManager.getEnvironment
public ScriptEnvironment getEnvironment(String environmentName) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName), "Environment name cannot be null or empty" ); ScriptEngine engine = engineManager.getEngineByName(environmentName); Preconditions.checkArgument(engine != null, environmentName + " is an unknown."); environmentName = engine.getFactory().getEngineName(); if (!environments.containsKey(environmentName)) { environments.put(environmentName, new ScriptEnvironment(engine)); } return environments.get(environmentName); }
java
public ScriptEnvironment getEnvironment(String environmentName) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName), "Environment name cannot be null or empty" ); ScriptEngine engine = engineManager.getEngineByName(environmentName); Preconditions.checkArgument(engine != null, environmentName + " is an unknown."); environmentName = engine.getFactory().getEngineName(); if (!environments.containsKey(environmentName)) { environments.put(environmentName, new ScriptEnvironment(engine)); } return environments.get(environmentName); }
[ "public", "ScriptEnvironment", "getEnvironment", "(", "String", "environmentName", ")", "{", "Preconditions", ".", "checkArgument", "(", "StringUtils", ".", "isNotNullOrBlank", "(", "environmentName", ")", ",", "\"Environment name cannot be null or empty\"", ")", ";", "Sc...
Gets the scripting environment given the environment name. @param environmentName the scripting environment name @return the scripting environment
[ "Gets", "the", "scripting", "environment", "given", "the", "environment", "name", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java#L67-L78
train
dbracewell/mango
src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java
ScriptEnvironmentManager.getTemporaryEnvironment
public static ScriptEnvironment getTemporaryEnvironment(String environmentName) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName), "Environment name cannot be null or empty" ); ScriptEngine engine = ScriptEnvironmentManager.getInstance().engineManager.getEngineByName(environmentName); Preconditions.checkArgument(engine != null, environmentName + " is an unknown."); return new ScriptEnvironment(engine); }
java
public static ScriptEnvironment getTemporaryEnvironment(String environmentName) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName), "Environment name cannot be null or empty" ); ScriptEngine engine = ScriptEnvironmentManager.getInstance().engineManager.getEngineByName(environmentName); Preconditions.checkArgument(engine != null, environmentName + " is an unknown."); return new ScriptEnvironment(engine); }
[ "public", "static", "ScriptEnvironment", "getTemporaryEnvironment", "(", "String", "environmentName", ")", "{", "Preconditions", ".", "checkArgument", "(", "StringUtils", ".", "isNotNullOrBlank", "(", "environmentName", ")", ",", "\"Environment name cannot be null or empty\""...
Gets a temporary scripting environment given the environment name. @param environmentName the scripting environment name @return the scripting environment
[ "Gets", "a", "temporary", "scripting", "environment", "given", "the", "environment", "name", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java#L86-L93
train
dbracewell/mango
src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java
ScriptEnvironmentManager.getEnvironmentNameForExtension
public String getEnvironmentNameForExtension(String extension) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(extension), "Extension name cannot be null or empty"); ScriptEngine engine = engineManager.getEngineByExtension(extension); Preconditions.checkArgument(engine != null, extension + " is not a recognized scripting extension."); return engine.getFactory().getLanguageName(); }
java
public String getEnvironmentNameForExtension(String extension) { Preconditions.checkArgument(StringUtils.isNotNullOrBlank(extension), "Extension name cannot be null or empty"); ScriptEngine engine = engineManager.getEngineByExtension(extension); Preconditions.checkArgument(engine != null, extension + " is not a recognized scripting extension."); return engine.getFactory().getLanguageName(); }
[ "public", "String", "getEnvironmentNameForExtension", "(", "String", "extension", ")", "{", "Preconditions", ".", "checkArgument", "(", "StringUtils", ".", "isNotNullOrBlank", "(", "extension", ")", ",", "\"Extension name cannot be null or empty\"", ")", ";", "ScriptEngin...
Gets the scripting environment name given the script extension. @param extension the scripting environment extension @return the scripting environment name
[ "Gets", "the", "scripting", "environment", "name", "given", "the", "script", "extension", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/scripting/ScriptEnvironmentManager.java#L125-L130
train
dbracewell/mango
src/main/java/com/davidbracewell/reflection/ClassDescriptor.java
ClassDescriptor.getConstructors
public Set<Constructor<?>> getConstructors(boolean privileged) { if (privileged) { return Collections.unmodifiableSet(Sets.union(constructors, declaredConstructors)); } else { return Collections.unmodifiableSet(constructors); } }
java
public Set<Constructor<?>> getConstructors(boolean privileged) { if (privileged) { return Collections.unmodifiableSet(Sets.union(constructors, declaredConstructors)); } else { return Collections.unmodifiableSet(constructors); } }
[ "public", "Set", "<", "Constructor", "<", "?", ">", ">", "getConstructors", "(", "boolean", "privileged", ")", "{", "if", "(", "privileged", ")", "{", "return", "Collections", ".", "unmodifiableSet", "(", "Sets", ".", "union", "(", "constructors", ",", "de...
Gets constructors. @param privileged the privileged @return the constructors
[ "Gets", "constructors", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/reflection/ClassDescriptor.java#L89-L95
train
dbracewell/mango
src/main/java/com/davidbracewell/reflection/ClassDescriptor.java
ClassDescriptor.getFields
public Set<Field> getFields(boolean privileged) { if (privileged) { return Collections.unmodifiableSet(Sets.union(fields, declaredFields)); } else { return Collections.unmodifiableSet(fields); } }
java
public Set<Field> getFields(boolean privileged) { if (privileged) { return Collections.unmodifiableSet(Sets.union(fields, declaredFields)); } else { return Collections.unmodifiableSet(fields); } }
[ "public", "Set", "<", "Field", ">", "getFields", "(", "boolean", "privileged", ")", "{", "if", "(", "privileged", ")", "{", "return", "Collections", ".", "unmodifiableSet", "(", "Sets", ".", "union", "(", "fields", ",", "declaredFields", ")", ")", ";", "...
Gets fields. @param privileged the privileged @return the fields
[ "Gets", "fields", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/reflection/ClassDescriptor.java#L103-L109
train
dbracewell/mango
src/main/java/com/davidbracewell/HierarchicalEnumValue.java
HierarchicalEnumValue.getParentFromConfig
protected T getParentFromConfig() { //TODO: Move this to a converter String parentName = Config.get(canonicalName(), "parent").asString(null); if (parentName != null && DynamicEnum.isDefined(Cast.as(getClass()), parentName)) { return DynamicEnum.valueOf(Cast.as(getClass()), parentName); } else if (parentName != null) { try { parentName = parentName.replaceFirst(Pattern.quote(getClass().getCanonicalName()), ""); DynamicEnum.register(Cast.as(Reflect.onClass(getClass()).invoke("create", parentName).get())); } catch (ReflectionException e) { return null; } } return null; }
java
protected T getParentFromConfig() { //TODO: Move this to a converter String parentName = Config.get(canonicalName(), "parent").asString(null); if (parentName != null && DynamicEnum.isDefined(Cast.as(getClass()), parentName)) { return DynamicEnum.valueOf(Cast.as(getClass()), parentName); } else if (parentName != null) { try { parentName = parentName.replaceFirst(Pattern.quote(getClass().getCanonicalName()), ""); DynamicEnum.register(Cast.as(Reflect.onClass(getClass()).invoke("create", parentName).get())); } catch (ReflectionException e) { return null; } } return null; }
[ "protected", "T", "getParentFromConfig", "(", ")", "{", "//TODO: Move this to a converter", "String", "parentName", "=", "Config", ".", "get", "(", "canonicalName", "(", ")", ",", "\"parent\"", ")", ".", "asString", "(", "null", ")", ";", "if", "(", "parentNam...
Determines the parent via a configuration setting. @return the parent via the configuration property or null
[ "Determines", "the", "parent", "via", "a", "configuration", "setting", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/HierarchicalEnumValue.java#L193-L207
train
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/handler/HandlerManager.java
HandlerManager.createRootHandler
public static HttpHandler createRootHandler( List<MappedEndpoint> mappedEndpoints, List<Interceptor> rootInterceptors, List<Interceptor> endpointInterceptors, ExceptionMapper exceptionMapper, String basePath, boolean httpTracer) { final RoutingHandler routingRestHandler = new HttpRootHandler(false); final PathTemplateHandler websocketHandler = Handlers.pathTemplate(false); HttpHandler staticHandler = null; for (MappedEndpoint me : mappedEndpoints) { if (MappedEndpoint.Type.REST.equals(me.type)) { HttpHandler httpDispatcher = new BlockingHandler( new HttpDispatcher( new ConnegHandler( new InterceptorHandler(me.handler, endpointInterceptors), me.mediaTypes ), exceptionMapper ) ); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; HttpHandler httpHandler = wrapCompressionHandler(httpDispatcher, me); routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.MULTIPART.equals(me.type)) { HttpHandler httpDispatcher = new BlockingHandler( new HttpDispatcher( new ConnegHandler( new InterceptorHandler(me.handler, endpointInterceptors), me.mediaTypes), exceptionMapper) ); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; HttpHandler httpHandler = wrapCompressionHandler(httpDispatcher, me); routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.SSE.equals(me.type)) { InterceptorHandler interceptorHandler = new InterceptorHandler(me.handler, endpointInterceptors); HttpHandler httpHandler = wrapCompressionHandler(interceptorHandler, me); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.WS.equals(me.type)) { InterceptorHandler interceptorHandler = new InterceptorHandler(me.handler, endpointInterceptors); HttpHandler httpHandler = wrapCompressionHandler(interceptorHandler, me); websocketHandler.add(me.url, httpHandler); } if (MappedEndpoint.Type.STATIC.equals(me.type)) { staticHandler = wrapCompressionHandler(me.handler, me); } } HttpHandler resolved = resolveHandlers(routingRestHandler, websocketHandler, staticHandler, mappedEndpoints); HttpHandler root = wrapRootInterceptorHandler(resolved, rootInterceptors); HttpHandler handler = wrapRequestDump(root, httpTracer); // handler = wrapServerName(handler); return Handlers.gracefulShutdown(handler); }
java
public static HttpHandler createRootHandler( List<MappedEndpoint> mappedEndpoints, List<Interceptor> rootInterceptors, List<Interceptor> endpointInterceptors, ExceptionMapper exceptionMapper, String basePath, boolean httpTracer) { final RoutingHandler routingRestHandler = new HttpRootHandler(false); final PathTemplateHandler websocketHandler = Handlers.pathTemplate(false); HttpHandler staticHandler = null; for (MappedEndpoint me : mappedEndpoints) { if (MappedEndpoint.Type.REST.equals(me.type)) { HttpHandler httpDispatcher = new BlockingHandler( new HttpDispatcher( new ConnegHandler( new InterceptorHandler(me.handler, endpointInterceptors), me.mediaTypes ), exceptionMapper ) ); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; HttpHandler httpHandler = wrapCompressionHandler(httpDispatcher, me); routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.MULTIPART.equals(me.type)) { HttpHandler httpDispatcher = new BlockingHandler( new HttpDispatcher( new ConnegHandler( new InterceptorHandler(me.handler, endpointInterceptors), me.mediaTypes), exceptionMapper) ); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; HttpHandler httpHandler = wrapCompressionHandler(httpDispatcher, me); routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.SSE.equals(me.type)) { InterceptorHandler interceptorHandler = new InterceptorHandler(me.handler, endpointInterceptors); HttpHandler httpHandler = wrapCompressionHandler(interceptorHandler, me); String endpointPath = HandlerUtil.BASE_PATH.equals(basePath) ? me.url : basePath + me.url; routingRestHandler.add(me.method, endpointPath, httpHandler); } if (MappedEndpoint.Type.WS.equals(me.type)) { InterceptorHandler interceptorHandler = new InterceptorHandler(me.handler, endpointInterceptors); HttpHandler httpHandler = wrapCompressionHandler(interceptorHandler, me); websocketHandler.add(me.url, httpHandler); } if (MappedEndpoint.Type.STATIC.equals(me.type)) { staticHandler = wrapCompressionHandler(me.handler, me); } } HttpHandler resolved = resolveHandlers(routingRestHandler, websocketHandler, staticHandler, mappedEndpoints); HttpHandler root = wrapRootInterceptorHandler(resolved, rootInterceptors); HttpHandler handler = wrapRequestDump(root, httpTracer); // handler = wrapServerName(handler); return Handlers.gracefulShutdown(handler); }
[ "public", "static", "HttpHandler", "createRootHandler", "(", "List", "<", "MappedEndpoint", ">", "mappedEndpoints", ",", "List", "<", "Interceptor", ">", "rootInterceptors", ",", "List", "<", "Interceptor", ">", "endpointInterceptors", ",", "ExceptionMapper", "excepti...
chain of responsibility
[ "chain", "of", "responsibility" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/handler/HandlerManager.java#L52-L121
train
LevelFourAB/commons
commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java
BinaryOutput.increaseLevel
private void increaseLevel(boolean list) { level++; if(hasData.length == level) { // Grow lists when needed hasData = Arrays.copyOf(hasData, hasData.length * 2); lists = Arrays.copyOf(lists, hasData.length * 2); } hasData[level] = false; lists[level] = list; }
java
private void increaseLevel(boolean list) { level++; if(hasData.length == level) { // Grow lists when needed hasData = Arrays.copyOf(hasData, hasData.length * 2); lists = Arrays.copyOf(lists, hasData.length * 2); } hasData[level] = false; lists[level] = list; }
[ "private", "void", "increaseLevel", "(", "boolean", "list", ")", "{", "level", "++", ";", "if", "(", "hasData", ".", "length", "==", "level", ")", "{", "// Grow lists when needed", "hasData", "=", "Arrays", ".", "copyOf", "(", "hasData", ",", "hasData", "....
Increase the level by one. @param list
[ "Increase", "the", "level", "by", "one", "." ]
aa121b3a5504b43d0c10450a1b984694fcd2b8ee
https://github.com/LevelFourAB/commons/blob/aa121b3a5504b43d0c10450a1b984694fcd2b8ee/commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java#L66-L78
train
LevelFourAB/commons
commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java
BinaryOutput.writeName
private void writeName(String name) throws IOException { if(shouldOutputName()) { out.write(TAG_KEY); writeStringNoTag(name); } }
java
private void writeName(String name) throws IOException { if(shouldOutputName()) { out.write(TAG_KEY); writeStringNoTag(name); } }
[ "private", "void", "writeName", "(", "String", "name", ")", "throws", "IOException", "{", "if", "(", "shouldOutputName", "(", ")", ")", "{", "out", ".", "write", "(", "TAG_KEY", ")", ";", "writeStringNoTag", "(", "name", ")", ";", "}", "}" ]
Write the name if needed. @param name @throws IOException
[ "Write", "the", "name", "if", "needed", "." ]
aa121b3a5504b43d0c10450a1b984694fcd2b8ee
https://github.com/LevelFourAB/commons/blob/aa121b3a5504b43d0c10450a1b984694fcd2b8ee/commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java#L120-L128
train
LevelFourAB/commons
commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java
BinaryOutput.writeIntegerNoTag
private void writeIntegerNoTag(int value) throws IOException { while(true) { if((value & ~0x7F) == 0) { out.write(value); break; } else { out.write((value & 0x7f) | 0x80); value >>>= 7; } } }
java
private void writeIntegerNoTag(int value) throws IOException { while(true) { if((value & ~0x7F) == 0) { out.write(value); break; } else { out.write((value & 0x7f) | 0x80); value >>>= 7; } } }
[ "private", "void", "writeIntegerNoTag", "(", "int", "value", ")", "throws", "IOException", "{", "while", "(", "true", ")", "{", "if", "(", "(", "value", "&", "~", "0x7F", ")", "==", "0", ")", "{", "out", ".", "write", "(", "value", ")", ";", "break...
Write an integer to the output stream without tagging it. @param value @throws IOException
[ "Write", "an", "integer", "to", "the", "output", "stream", "without", "tagging", "it", "." ]
aa121b3a5504b43d0c10450a1b984694fcd2b8ee
https://github.com/LevelFourAB/commons/blob/aa121b3a5504b43d0c10450a1b984694fcd2b8ee/commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java#L136-L152
train
LevelFourAB/commons
commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java
BinaryOutput.writeInteger
private void writeInteger(int value) throws IOException { if(value < 0) { out.write(TAG_NEGATIVE_INT); writeIntegerNoTag(-value); } else { out.write(TAG_POSITIVE_INT); writeIntegerNoTag(value); } }
java
private void writeInteger(int value) throws IOException { if(value < 0) { out.write(TAG_NEGATIVE_INT); writeIntegerNoTag(-value); } else { out.write(TAG_POSITIVE_INT); writeIntegerNoTag(value); } }
[ "private", "void", "writeInteger", "(", "int", "value", ")", "throws", "IOException", "{", "if", "(", "value", "<", "0", ")", "{", "out", ".", "write", "(", "TAG_NEGATIVE_INT", ")", ";", "writeIntegerNoTag", "(", "-", "value", ")", ";", "}", "else", "{...
Write an integer to the output stream. @param value @throws IOException
[ "Write", "an", "integer", "to", "the", "output", "stream", "." ]
aa121b3a5504b43d0c10450a1b984694fcd2b8ee
https://github.com/LevelFourAB/commons/blob/aa121b3a5504b43d0c10450a1b984694fcd2b8ee/commons-serialization/src/main/java/se/l4/commons/serialization/format/BinaryOutput.java#L160-L173
train
wg/scrypt
src/main/java/com/lambdaworks/crypto/SCryptUtil.java
SCryptUtil.check
public static boolean check(String passwd, String hashed) { try { String[] parts = hashed.split("\\$"); if (parts.length != 5 || !parts[1].equals("s0")) { throw new IllegalArgumentException("Invalid hashed value"); } long params = Long.parseLong(parts[2], 16); byte[] salt = decode(parts[3].toCharArray()); byte[] derived0 = decode(parts[4].toCharArray()); int N = (int) Math.pow(2, params >> 16 & 0xffff); int r = (int) params >> 8 & 0xff; int p = (int) params & 0xff; byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32); if (derived0.length != derived1.length) return false; int result = 0; for (int i = 0; i < derived0.length; i++) { result |= derived0[i] ^ derived1[i]; } return result == 0; } catch (UnsupportedEncodingException e) { throw new IllegalStateException("JVM doesn't support UTF-8?"); } catch (GeneralSecurityException e) { throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?"); } }
java
public static boolean check(String passwd, String hashed) { try { String[] parts = hashed.split("\\$"); if (parts.length != 5 || !parts[1].equals("s0")) { throw new IllegalArgumentException("Invalid hashed value"); } long params = Long.parseLong(parts[2], 16); byte[] salt = decode(parts[3].toCharArray()); byte[] derived0 = decode(parts[4].toCharArray()); int N = (int) Math.pow(2, params >> 16 & 0xffff); int r = (int) params >> 8 & 0xff; int p = (int) params & 0xff; byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32); if (derived0.length != derived1.length) return false; int result = 0; for (int i = 0; i < derived0.length; i++) { result |= derived0[i] ^ derived1[i]; } return result == 0; } catch (UnsupportedEncodingException e) { throw new IllegalStateException("JVM doesn't support UTF-8?"); } catch (GeneralSecurityException e) { throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?"); } }
[ "public", "static", "boolean", "check", "(", "String", "passwd", ",", "String", "hashed", ")", "{", "try", "{", "String", "[", "]", "parts", "=", "hashed", ".", "split", "(", "\"\\\\$\"", ")", ";", "if", "(", "parts", ".", "length", "!=", "5", "||", ...
Compare the supplied plaintext password to a hashed password. @param passwd Plaintext password. @param hashed scrypt hashed password. @return true if passwd matches hashed value.
[ "Compare", "the", "supplied", "plaintext", "password", "to", "a", "hashed", "password", "." ]
0675236370458e819ee21e4427c5f7f3f9485d33
https://github.com/wg/scrypt/blob/0675236370458e819ee21e4427c5f7f3f9485d33/src/main/java/com/lambdaworks/crypto/SCryptUtil.java#L72-L102
train
wg/scrypt
src/main/java/com/lambdaworks/jni/Platform.java
Platform.detect
public static Platform detect() throws UnsupportedPlatformException { String osArch = getProperty("os.arch"); String osName = getProperty("os.name"); for (Arch arch : Arch.values()) { if (arch.pattern.matcher(osArch).matches()) { for (OS os : OS.values()) { if (os.pattern.matcher(osName).matches()) { return new Platform(arch, os); } } } } String msg = String.format("Unsupported platform %s %s", osArch, osName); throw new UnsupportedPlatformException(msg); }
java
public static Platform detect() throws UnsupportedPlatformException { String osArch = getProperty("os.arch"); String osName = getProperty("os.name"); for (Arch arch : Arch.values()) { if (arch.pattern.matcher(osArch).matches()) { for (OS os : OS.values()) { if (os.pattern.matcher(osName).matches()) { return new Platform(arch, os); } } } } String msg = String.format("Unsupported platform %s %s", osArch, osName); throw new UnsupportedPlatformException(msg); }
[ "public", "static", "Platform", "detect", "(", ")", "throws", "UnsupportedPlatformException", "{", "String", "osArch", "=", "getProperty", "(", "\"os.arch\"", ")", ";", "String", "osName", "=", "getProperty", "(", "\"os.name\"", ")", ";", "for", "(", "Arch", "...
Attempt to detect the current platform. @return The current platform. @throws UnsupportedPlatformException if the platform cannot be detected.
[ "Attempt", "to", "detect", "the", "current", "platform", "." ]
0675236370458e819ee21e4427c5f7f3f9485d33
https://github.com/wg/scrypt/blob/0675236370458e819ee21e4427c5f7f3f9485d33/src/main/java/com/lambdaworks/jni/Platform.java#L56-L72
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ASTNode.java
ASTNode.getNodeMetaData
public <T> T getNodeMetaData(Object key) { if (metaDataMap == null) { return (T) null; } return (T) metaDataMap.get(key); }
java
public <T> T getNodeMetaData(Object key) { if (metaDataMap == null) { return (T) null; } return (T) metaDataMap.get(key); }
[ "public", "<", "T", ">", "T", "getNodeMetaData", "(", "Object", "key", ")", "{", "if", "(", "metaDataMap", "==", "null", ")", "{", "return", "(", "T", ")", "null", ";", "}", "return", "(", "T", ")", "metaDataMap", ".", "get", "(", "key", ")", ";"...
Gets the node meta data. @param key - the meta data key @return the node meta data value for this key
[ "Gets", "the", "node", "meta", "data", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L119-L124
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ASTNode.java
ASTNode.copyNodeMetaData
public void copyNodeMetaData(ASTNode other) { if (other.metaDataMap == null) { return; } if (metaDataMap == null) { metaDataMap = new ListHashMap(); } metaDataMap.putAll(other.metaDataMap); }
java
public void copyNodeMetaData(ASTNode other) { if (other.metaDataMap == null) { return; } if (metaDataMap == null) { metaDataMap = new ListHashMap(); } metaDataMap.putAll(other.metaDataMap); }
[ "public", "void", "copyNodeMetaData", "(", "ASTNode", "other", ")", "{", "if", "(", "other", ".", "metaDataMap", "==", "null", ")", "{", "return", ";", "}", "if", "(", "metaDataMap", "==", "null", ")", "{", "metaDataMap", "=", "new", "ListHashMap", "(", ...
Copies all node meta data from the other node to this one @param other - the other node
[ "Copies", "all", "node", "meta", "data", "from", "the", "other", "node", "to", "this", "one" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L130-L138
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ASTNode.java
ASTNode.setNodeMetaData
public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
java
public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
[ "public", "void", "setNodeMetaData", "(", "Object", "key", ",", "Object", "value", ")", "{", "if", "(", "key", "==", "null", ")", "throw", "new", "GroovyBugError", "(", "\"Tried to set meta data with null key on \"", "+", "this", "+", "\".\"", ")", ";", "if", ...
Sets the node meta data. @param key - the meta data key @param value - the meta data value @throws GroovyBugError if key is null or there is already meta data under that key
[ "Sets", "the", "node", "meta", "data", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L148-L155
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ASTNode.java
ASTNode.putNodeMetaData
public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
java
public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
[ "public", "Object", "putNodeMetaData", "(", "Object", "key", ",", "Object", "value", ")", "{", "if", "(", "key", "==", "null", ")", "throw", "new", "GroovyBugError", "(", "\"Tried to set meta data with null key on \"", "+", "this", "+", "\".\"", ")", ";", "if"...
Sets the node meta data but allows overwriting values. @param key - the meta data key @param value - the meta data value @return the old node meta data value for this key @throws GroovyBugError if key is null
[ "Sets", "the", "node", "meta", "data", "but", "allows", "overwriting", "values", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L165-L171
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ASTNode.java
ASTNode.removeNodeMetaData
public void removeNodeMetaData(Object key) { if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+"."); if (metaDataMap == null) { return; } metaDataMap.remove(key); }
java
public void removeNodeMetaData(Object key) { if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+"."); if (metaDataMap == null) { return; } metaDataMap.remove(key); }
[ "public", "void", "removeNodeMetaData", "(", "Object", "key", ")", "{", "if", "(", "key", "==", "null", ")", "throw", "new", "GroovyBugError", "(", "\"Tried to remove meta data with null key \"", "+", "this", "+", "\".\"", ")", ";", "if", "(", "metaDataMap", "...
Removes a node meta data entry. @param key - the meta data key @throws GroovyBugError if the key is null
[ "Removes", "a", "node", "meta", "data", "entry", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ASTNode.java#L179-L185
train
groovy/groovy-core
src/main/groovy/lang/IntRange.java
IntRange.subListBorders
public RangeInfo subListBorders(int size) { if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange"); int tempFrom = from; if (tempFrom < 0) { tempFrom += size; } int tempTo = to; if (tempTo < 0) { tempTo += size; } if (tempFrom > tempTo) { return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true); } return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false); }
java
public RangeInfo subListBorders(int size) { if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange"); int tempFrom = from; if (tempFrom < 0) { tempFrom += size; } int tempTo = to; if (tempTo < 0) { tempTo += size; } if (tempFrom > tempTo) { return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true); } return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false); }
[ "public", "RangeInfo", "subListBorders", "(", "int", "size", ")", "{", "if", "(", "inclusive", "==", "null", ")", "throw", "new", "IllegalStateException", "(", "\"Should not call subListBorders on a non-inclusive aware IntRange\"", ")", ";", "int", "tempFrom", "=", "f...
A method for determining from and to information when using this IntRange to index an aggregate object of the specified size. Normally only used internally within Groovy but useful if adding range indexing support for your own aggregates. @param size the size of the aggregate being indexed @return the calculated range information (with 1 added to the to value, ready for providing to subList
[ "A", "method", "for", "determining", "from", "and", "to", "information", "when", "using", "this", "IntRange", "to", "index", "an", "aggregate", "object", "of", "the", "specified", "size", ".", "Normally", "only", "used", "internally", "within", "Groovy", "but"...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/IntRange.java#L197-L211
train
groovy/groovy-core
src/main/groovy/beans/BindableASTTransformation.java
BindableASTTransformation.createSetterMethod
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) { MethodNode setter = new MethodNode( setterName, propertyNode.getModifiers(), ClassHelper.VOID_TYPE, params(param(propertyNode.getType(), "value")), ClassNode.EMPTY_ARRAY, setterBlock); setter.setSynthetic(true); // add it to the class declaringClass.addMethod(setter); }
java
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) { MethodNode setter = new MethodNode( setterName, propertyNode.getModifiers(), ClassHelper.VOID_TYPE, params(param(propertyNode.getType(), "value")), ClassNode.EMPTY_ARRAY, setterBlock); setter.setSynthetic(true); // add it to the class declaringClass.addMethod(setter); }
[ "protected", "void", "createSetterMethod", "(", "ClassNode", "declaringClass", ",", "PropertyNode", "propertyNode", ",", "String", "setterName", ",", "Statement", "setterBlock", ")", "{", "MethodNode", "setter", "=", "new", "MethodNode", "(", "setterName", ",", "pro...
Creates a setter method with the given body. @param declaringClass the class to which we will add the setter @param propertyNode the field to back the setter @param setterName the name of the setter @param setterBlock the statement representing the setter block
[ "Creates", "a", "setter", "method", "with", "the", "given", "body", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/beans/BindableASTTransformation.java#L247-L258
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/CompilationUnit.java
CompilationUnit.applyToPrimaryClassNodes
public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException { Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator(); while (classNodes.hasNext()) { SourceUnit context = null; try { ClassNode classNode = (ClassNode) classNodes.next(); context = classNode.getModule().getContext(); if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) { int offset = 1; Iterator<InnerClassNode> iterator = classNode.getInnerClasses(); while (iterator.hasNext()) { iterator.next(); offset++; } body.call(context, new GeneratorContext(this.ast, offset), classNode); } } catch (CompilationFailedException e) { // fall through, getErrorReporter().failIfErrors() will trigger } catch (NullPointerException npe) { GroovyBugError gbe = new GroovyBugError("unexpected NullpointerException", npe); changeBugText(gbe, context); throw gbe; } catch (GroovyBugError e) { changeBugText(e, context); throw e; } catch (NoClassDefFoundError e) { // effort to get more logging in case a dependency of a class is loaded // although it shouldn't have convertUncaughtExceptionToCompilationError(e); } catch (Exception e) { convertUncaughtExceptionToCompilationError(e); } } getErrorCollector().failIfErrors(); }
java
public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException { Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator(); while (classNodes.hasNext()) { SourceUnit context = null; try { ClassNode classNode = (ClassNode) classNodes.next(); context = classNode.getModule().getContext(); if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) { int offset = 1; Iterator<InnerClassNode> iterator = classNode.getInnerClasses(); while (iterator.hasNext()) { iterator.next(); offset++; } body.call(context, new GeneratorContext(this.ast, offset), classNode); } } catch (CompilationFailedException e) { // fall through, getErrorReporter().failIfErrors() will trigger } catch (NullPointerException npe) { GroovyBugError gbe = new GroovyBugError("unexpected NullpointerException", npe); changeBugText(gbe, context); throw gbe; } catch (GroovyBugError e) { changeBugText(e, context); throw e; } catch (NoClassDefFoundError e) { // effort to get more logging in case a dependency of a class is loaded // although it shouldn't have convertUncaughtExceptionToCompilationError(e); } catch (Exception e) { convertUncaughtExceptionToCompilationError(e); } } getErrorCollector().failIfErrors(); }
[ "public", "void", "applyToPrimaryClassNodes", "(", "PrimaryClassNodeOperation", "body", ")", "throws", "CompilationFailedException", "{", "Iterator", "classNodes", "=", "getPrimaryClassNodes", "(", "body", ".", "needSortedInput", "(", ")", ")", ".", "iterator", "(", "...
A loop driver for applying operations to all primary ClassNodes in our AST. Automatically skips units that have already been processed through the current phase.
[ "A", "loop", "driver", "for", "applying", "operations", "to", "all", "primary", "ClassNodes", "in", "our", "AST", ".", "Automatically", "skips", "units", "that", "have", "already", "been", "processed", "through", "the", "current", "phase", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/CompilationUnit.java#L1041-L1076
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java
SocketGroovyMethods.withStreams
public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException { InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); try { T result = closure.call(new Object[]{input, output}); InputStream temp1 = input; input = null; temp1.close(); OutputStream temp2 = output; output = null; temp2.close(); return result; } finally { closeWithWarning(input); closeWithWarning(output); } }
java
public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException { InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); try { T result = closure.call(new Object[]{input, output}); InputStream temp1 = input; input = null; temp1.close(); OutputStream temp2 = output; output = null; temp2.close(); return result; } finally { closeWithWarning(input); closeWithWarning(output); } }
[ "public", "static", "<", "T", ">", "T", "withStreams", "(", "Socket", "socket", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "{", "\"java.io.InputStream\"", ",", "\"java.io.OutputStream\"", "}", ")", "Closure",...
Passes the Socket's InputStream and OutputStream to the closure. The streams will be closed after the closure returns, even if an exception is thrown. @param socket a Socket @param closure a Closure @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.2
[ "Passes", "the", "Socket", "s", "InputStream", "and", "OutputStream", "to", "the", "closure", ".", "The", "streams", "will", "be", "closed", "after", "the", "closure", "returns", "even", "if", "an", "exception", "is", "thrown", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L61-L79
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java
SocketGroovyMethods.withObjectStreams
public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException { InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(output); ObjectInputStream ois = new ObjectInputStream(input); try { T result = closure.call(new Object[]{ois, oos}); InputStream temp1 = ois; ois = null; temp1.close(); temp1 = input; input = null; temp1.close(); OutputStream temp2 = oos; oos = null; temp2.close(); temp2 = output; output = null; temp2.close(); return result; } finally { closeWithWarning(ois); closeWithWarning(input); closeWithWarning(oos); closeWithWarning(output); } }
java
public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException { InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(output); ObjectInputStream ois = new ObjectInputStream(input); try { T result = closure.call(new Object[]{ois, oos}); InputStream temp1 = ois; ois = null; temp1.close(); temp1 = input; input = null; temp1.close(); OutputStream temp2 = oos; oos = null; temp2.close(); temp2 = output; output = null; temp2.close(); return result; } finally { closeWithWarning(ois); closeWithWarning(input); closeWithWarning(oos); closeWithWarning(output); } }
[ "public", "static", "<", "T", ">", "T", "withObjectStreams", "(", "Socket", "socket", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "{", "\"java.io.ObjectInputStream\"", ",", "\"java.io.ObjectOutputStream\"", "}", ...
Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure. The streams will be closed after the closure returns, even if an exception is thrown. @param socket this Socket @param closure a Closure @return the value returned by the closure @throws IOException if an IOException occurs. @since 1.5.0
[ "Creates", "an", "InputObjectStream", "and", "an", "OutputObjectStream", "from", "a", "Socket", "and", "passes", "them", "to", "the", "closure", ".", "The", "streams", "will", "be", "closed", "after", "the", "closure", "returns", "even", "if", "an", "exception...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/SocketGroovyMethods.java#L92-L120
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/MethodKey.java
MethodKey.createCopy
public MethodKey createCopy() { int size = getParameterCount(); Class[] paramTypes = new Class[size]; for (int i = 0; i < size; i++) { paramTypes[i] = getParameterType(i); } return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper); }
java
public MethodKey createCopy() { int size = getParameterCount(); Class[] paramTypes = new Class[size]; for (int i = 0; i < size; i++) { paramTypes[i] = getParameterType(i); } return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper); }
[ "public", "MethodKey", "createCopy", "(", ")", "{", "int", "size", "=", "getParameterCount", "(", ")", ";", "Class", "[", "]", "paramTypes", "=", "new", "Class", "[", "size", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "size", ";", ...
Creates an immutable copy that we can cache.
[ "Creates", "an", "immutable", "copy", "that", "we", "can", "cache", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/MethodKey.java#L49-L56
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/trait/TraitComposer.java
TraitComposer.doExtendTraits
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) { if (cNode.isInterface()) return; boolean isItselfTrait = Traits.isTrait(cNode); SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit); if (isItselfTrait) { checkTraitAllowed(cNode, unit); return; } if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) { List<ClassNode> traits = findTraits(cNode); for (ClassNode trait : traits) { TraitHelpersTuple helpers = Traits.findHelpers(trait); applyTrait(trait, cNode, helpers); superCallTransformer.visitClass(cNode); if (unit!=null) { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader()); collector.visitClass(cNode); } } } }
java
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) { if (cNode.isInterface()) return; boolean isItselfTrait = Traits.isTrait(cNode); SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit); if (isItselfTrait) { checkTraitAllowed(cNode, unit); return; } if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) { List<ClassNode> traits = findTraits(cNode); for (ClassNode trait : traits) { TraitHelpersTuple helpers = Traits.findHelpers(trait); applyTrait(trait, cNode, helpers); superCallTransformer.visitClass(cNode); if (unit!=null) { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader()); collector.visitClass(cNode); } } } }
[ "public", "static", "void", "doExtendTraits", "(", "final", "ClassNode", "cNode", ",", "final", "SourceUnit", "unit", ",", "final", "CompilationUnit", "cu", ")", "{", "if", "(", "cNode", ".", "isInterface", "(", ")", ")", "return", ";", "boolean", "isItselfT...
Given a class node, if this class node implements a trait, then generate all the appropriate code which delegates calls to the trait. It is safe to call this method on a class node which does not implement a trait. @param cNode a class node @param unit the source unit
[ "Given", "a", "class", "node", "if", "this", "class", "node", "implements", "a", "trait", "then", "generate", "all", "the", "appropriate", "code", "which", "delegates", "calls", "to", "the", "trait", ".", "It", "is", "safe", "to", "call", "this", "method",...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/trait/TraitComposer.java#L102-L122
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/ErrorCollector.java
ErrorCollector.getSyntaxError
public SyntaxException getSyntaxError(int index) { SyntaxException exception = null; Message message = getError(index); if (message != null && message instanceof SyntaxErrorMessage) { exception = ((SyntaxErrorMessage) message).getCause(); } return exception; }
java
public SyntaxException getSyntaxError(int index) { SyntaxException exception = null; Message message = getError(index); if (message != null && message instanceof SyntaxErrorMessage) { exception = ((SyntaxErrorMessage) message).getCause(); } return exception; }
[ "public", "SyntaxException", "getSyntaxError", "(", "int", "index", ")", "{", "SyntaxException", "exception", "=", "null", ";", "Message", "message", "=", "getError", "(", "index", ")", ";", "if", "(", "message", "!=", "null", "&&", "message", "instanceof", ...
Convenience routine to return the specified error's underlying SyntaxException, or null if it isn't one.
[ "Convenience", "routine", "to", "return", "the", "specified", "error", "s", "underlying", "SyntaxException", "or", "null", "if", "it", "isn", "t", "one", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/ErrorCollector.java#L240-L248
train
groovy/groovy-core
src/main/org/apache/commons/cli/GroovyInternalPosixParser.java
GroovyInternalPosixParser.gobble
private void gobble(Iterator iter) { if (eatTheRest) { while (iter.hasNext()) { tokens.add(iter.next()); } } }
java
private void gobble(Iterator iter) { if (eatTheRest) { while (iter.hasNext()) { tokens.add(iter.next()); } } }
[ "private", "void", "gobble", "(", "Iterator", "iter", ")", "{", "if", "(", "eatTheRest", ")", "{", "while", "(", "iter", ".", "hasNext", "(", ")", ")", "{", "tokens", ".", "add", "(", "iter", ".", "next", "(", ")", ")", ";", "}", "}", "}" ]
Adds the remaining tokens to the processed tokens list. @param iter An iterator over the remaining tokens
[ "Adds", "the", "remaining", "tokens", "to", "the", "processed", "tokens", "list", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/apache/commons/cli/GroovyInternalPosixParser.java#L165-L174
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.allParametersAndArgumentsMatch
public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) { if (params==null) { params = Parameter.EMPTY_ARRAY; } int dist = 0; if (args.length<params.length) return -1; // we already know the lengths are equal for (int i = 0; i < params.length; i++) { ClassNode paramType = params[i].getType(); ClassNode argType = args[i]; if (!isAssignableTo(argType, paramType)) return -1; else { if (!paramType.equals(argType)) dist+=getDistance(argType, paramType); } } return dist; }
java
public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) { if (params==null) { params = Parameter.EMPTY_ARRAY; } int dist = 0; if (args.length<params.length) return -1; // we already know the lengths are equal for (int i = 0; i < params.length; i++) { ClassNode paramType = params[i].getType(); ClassNode argType = args[i]; if (!isAssignableTo(argType, paramType)) return -1; else { if (!paramType.equals(argType)) dist+=getDistance(argType, paramType); } } return dist; }
[ "public", "static", "int", "allParametersAndArgumentsMatch", "(", "Parameter", "[", "]", "params", ",", "ClassNode", "[", "]", "args", ")", "{", "if", "(", "params", "==", "null", ")", "{", "params", "=", "Parameter", ".", "EMPTY_ARRAY", ";", "}", "int", ...
Checks that arguments and parameter types match. @param params method parameters @param args type arguments @return -1 if arguments do not match, 0 if arguments are of the exact type and >0 when one or more argument is not of the exact type but still match
[ "Checks", "that", "arguments", "and", "parameter", "types", "match", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L216-L232
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.excessArgumentsMatchesVargsParameter
static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) { // we already know parameter length is bigger zero and last is a vargs // the excess arguments are all put in an array for the vargs call // so check against the component type int dist = 0; ClassNode vargsBase = params[params.length - 1].getType().getComponentType(); for (int i = params.length; i < args.length; i++) { if (!isAssignableTo(args[i],vargsBase)) return -1; else if (!args[i].equals(vargsBase)) dist+=getDistance(args[i], vargsBase); } return dist; }
java
static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) { // we already know parameter length is bigger zero and last is a vargs // the excess arguments are all put in an array for the vargs call // so check against the component type int dist = 0; ClassNode vargsBase = params[params.length - 1].getType().getComponentType(); for (int i = params.length; i < args.length; i++) { if (!isAssignableTo(args[i],vargsBase)) return -1; else if (!args[i].equals(vargsBase)) dist+=getDistance(args[i], vargsBase); } return dist; }
[ "static", "int", "excessArgumentsMatchesVargsParameter", "(", "Parameter", "[", "]", "params", ",", "ClassNode", "[", "]", "args", ")", "{", "// we already know parameter length is bigger zero and last is a vargs", "// the excess arguments are all put in an array for the vargs call",...
Checks that excess arguments match the vararg signature parameter. @param params @param args @return -1 if no match, 0 if all arguments matches the vararg type and >0 if one or more vararg argument is assignable to the vararg type, but still not an exact match
[ "Checks", "that", "excess", "arguments", "match", "the", "vararg", "signature", "parameter", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L276-L287
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.lastArgMatchesVarg
static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) { if (!isVargs(params)) return -1; // case length ==0 handled already // we have now two cases, // the argument is wrapped in the vargs array or // the argument is an array that can be used for the vargs part directly // we test only the wrapping part, since the non wrapping is done already ClassNode lastParamType = params[params.length - 1].getType(); ClassNode ptype = lastParamType.getComponentType(); ClassNode arg = args[args.length - 1]; if (isNumberType(ptype) && isNumberType(arg) && !ptype.equals(arg)) return -1; return isAssignableTo(arg, ptype)?Math.min(getDistance(arg, lastParamType), getDistance(arg, ptype)):-1; }
java
static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) { if (!isVargs(params)) return -1; // case length ==0 handled already // we have now two cases, // the argument is wrapped in the vargs array or // the argument is an array that can be used for the vargs part directly // we test only the wrapping part, since the non wrapping is done already ClassNode lastParamType = params[params.length - 1].getType(); ClassNode ptype = lastParamType.getComponentType(); ClassNode arg = args[args.length - 1]; if (isNumberType(ptype) && isNumberType(arg) && !ptype.equals(arg)) return -1; return isAssignableTo(arg, ptype)?Math.min(getDistance(arg, lastParamType), getDistance(arg, ptype)):-1; }
[ "static", "int", "lastArgMatchesVarg", "(", "Parameter", "[", "]", "params", ",", "ClassNode", "...", "args", ")", "{", "if", "(", "!", "isVargs", "(", "params", ")", ")", "return", "-", "1", ";", "// case length ==0 handled already", "// we have now two cases,"...
Checks if the last argument matches the vararg type. @param params @param args @return -1 if no match, 0 if the last argument is exactly the vararg type and 1 if of an assignable type
[ "Checks", "if", "the", "last", "argument", "matches", "the", "vararg", "type", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L295-L307
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.buildParameter
private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) { if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) { return methodParameter; } if (paramType.isArray()) { ClassNode componentType = paramType.getComponentType(); Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName()); Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType); return new Parameter(component.getType().makeArray(), component.getName()); } ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType); return new Parameter(resolved, methodParameter.getName()); }
java
private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) { if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) { return methodParameter; } if (paramType.isArray()) { ClassNode componentType = paramType.getComponentType(); Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName()); Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType); return new Parameter(component.getType().makeArray(), component.getName()); } ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType); return new Parameter(resolved, methodParameter.getName()); }
[ "private", "static", "Parameter", "buildParameter", "(", "final", "Map", "<", "String", ",", "GenericsType", ">", "genericFromReceiver", ",", "final", "Map", "<", "String", ",", "GenericsType", ">", "placeholdersFromContext", ",", "final", "Parameter", "methodParame...
Given a parameter, builds a new parameter for which the known generics placeholders are resolved. @param genericFromReceiver resolved generics from the receiver of the message @param placeholdersFromContext, resolved generics from the method context @param methodParameter the method parameter for which we want to resolve generic types @param paramType the (unresolved) type of the method parameter @return a new parameter with the same name and type as the original one, but with resolved generic types
[ "Given", "a", "parameter", "builds", "a", "new", "parameter", "for", "which", "the", "known", "generics", "placeholders", "are", "resolved", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1170-L1183
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
StaticTypeCheckingSupport.isClassClassNodeWrappingConcreteType
public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) { GenericsType[] genericsTypes = classNode.getGenericsTypes(); return ClassHelper.CLASS_Type.equals(classNode) && classNode.isUsingGenerics() && genericsTypes!=null && !genericsTypes[0].isPlaceholder() && !genericsTypes[0].isWildcard(); }
java
public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) { GenericsType[] genericsTypes = classNode.getGenericsTypes(); return ClassHelper.CLASS_Type.equals(classNode) && classNode.isUsingGenerics() && genericsTypes!=null && !genericsTypes[0].isPlaceholder() && !genericsTypes[0].isWildcard(); }
[ "public", "static", "boolean", "isClassClassNodeWrappingConcreteType", "(", "ClassNode", "classNode", ")", "{", "GenericsType", "[", "]", "genericsTypes", "=", "classNode", ".", "getGenericsTypes", "(", ")", ";", "return", "ClassHelper", ".", "CLASS_Type", ".", "equ...
Returns true if the class node represents a the class node for the Class class and if the parametrized type is a neither a placeholder or a wildcard. For example, the class node Class&lt;Foo&gt; where Foo is a class would return true, but the class node for Class&lt;?&gt; would return false. @param classNode a class node to be tested @return true if it is the class node for Class and its generic type is a real class
[ "Returns", "true", "if", "the", "class", "node", "represents", "a", "the", "class", "node", "for", "the", "Class", "class", "and", "if", "the", "parametrized", "type", "is", "a", "neither", "a", "placeholder", "or", "a", "wildcard", ".", "For", "example", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L2069-L2076
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.splitEachLine
public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure); }
java
public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure); }
[ "public", "static", "<", "T", ">", "T", "splitEachLine", "(", "InputStream", "stream", ",", "String", "regex", ",", "String", "charset", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "\"List<String>\"", ")", ...
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed. @param stream an InputStream @param regex the delimiting regular expression @param charset opens the stream with a specified charset @param closure a closure @return the last value returned by the closure @throws IOException if an IOException occurs. @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid @see #splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure) @since 1.5.5
[ "Iterates", "through", "the", "given", "InputStream", "line", "by", "line", "using", "the", "specified", "encoding", "splitting", "each", "line", "using", "the", "given", "separator", ".", "The", "list", "of", "tokens", "for", "each", "line", "is", "then", "...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L603-L605
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.transformChar
public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { int c; try { char[] chars = new char[1]; while ((c = self.read()) != -1) { chars[0] = (char) c; writer.write((String) closure.call(new String(chars))); } writer.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = self; self = null; temp1.close(); } finally { closeWithWarning(self); closeWithWarning(writer); } }
java
public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException { int c; try { char[] chars = new char[1]; while ((c = self.read()) != -1) { chars[0] = (char) c; writer.write((String) closure.call(new String(chars))); } writer.flush(); Writer temp2 = writer; writer = null; temp2.close(); Reader temp1 = self; self = null; temp1.close(); } finally { closeWithWarning(self); closeWithWarning(writer); } }
[ "public", "static", "void", "transformChar", "(", "Reader", "self", ",", "Writer", "writer", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String\"", ")", "Closure", "closure", ")", "throws", "IOExc...
Transforms each character from this reader by passing it to the given closure. The Closure should return each transformed character, which will be passed to the Writer. The reader and writer will be both be closed before this method returns. @param self a Reader object @param writer a Writer to receive the transformed characters @param closure a closure that performs the required transformation @throws IOException if an IOException occurs. @since 1.5.0
[ "Transforms", "each", "character", "from", "this", "reader", "by", "passing", "it", "to", "the", "given", "closure", ".", "The", "Closure", "should", "return", "each", "transformed", "character", "which", "will", "be", "passed", "to", "the", "Writer", ".", "...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1398-L1418
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java
IOGroovyMethods.withCloseable
public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException { try { T result = action.call(self); Closeable temp = self; self = null; temp.close(); return result; } finally { DefaultGroovyMethodsSupport.closeWithWarning(self); } }
java
public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException { try { T result = action.call(self); Closeable temp = self; self = null; temp.close(); return result; } finally { DefaultGroovyMethodsSupport.closeWithWarning(self); } }
[ "public", "static", "<", "T", ",", "U", "extends", "Closeable", ">", "T", "withCloseable", "(", "U", "self", ",", "@", "ClosureParams", "(", "value", "=", "FirstParam", ".", "class", ")", "Closure", "<", "T", ">", "action", ")", "throws", "IOException", ...
Allows this closeable to be used within the closure, ensuring that it is closed once the closure has been executed and before this method returns. @param self the Closeable @param action the closure taking the Closeable as parameter @return the value returned by the closure @throws IOException if an IOException occurs. @since 2.4.0
[ "Allows", "this", "closeable", "to", "be", "used", "within", "the", "closure", "ensuring", "that", "it", "is", "closed", "once", "the", "closure", "has", "been", "executed", "and", "before", "this", "method", "returns", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java#L1620-L1632
train
groovy/groovy-core
src/main/groovy/lang/MetaArrayLengthProperty.java
MetaArrayLengthProperty.getProperty
public Object getProperty(Object object) { return java.lang.reflect.Array.getLength(object); }
java
public Object getProperty(Object object) { return java.lang.reflect.Array.getLength(object); }
[ "public", "Object", "getProperty", "(", "Object", "object", ")", "{", "return", "java", ".", "lang", ".", "reflect", ".", "Array", ".", "getLength", "(", "object", ")", ";", "}" ]
Get this property from the given object. @param object an array @return the length of the array object @throws IllegalArgumentException if object is not an array
[ "Get", "this", "property", "from", "the", "given", "object", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaArrayLengthProperty.java#L43-L45
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
ProxyGeneratorAdapter.makeDelegateCall
protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) { MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); // load this mv.visitFieldInsn(GETFIELD, proxyName, DELEGATE_OBJECT_FIELD, BytecodeHelper.getTypeDescription(delegateClass)); // load delegate // using InvokerHelper to allow potential intercepted calls int size; mv.visitLdcInsn(name); // method name Type[] args = Type.getArgumentTypes(desc); BytecodeHelper.pushConstant(mv, args.length); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); size = 6; int idx = 1; for (int i = 0; i < args.length; i++) { Type arg = args[i]; mv.visitInsn(DUP); BytecodeHelper.pushConstant(mv, i); // primitive types must be boxed if (isPrimitive(arg)) { mv.visitIntInsn(getLoadInsn(arg), idx); String wrappedType = getWrappedClassDescriptor(arg); mv.visitMethodInsn(INVOKESTATIC, wrappedType, "valueOf", "(" + arg.getDescriptor() + ")L" + wrappedType + ";", false); } else { mv.visitVarInsn(ALOAD, idx); // load argument i } size = Math.max(size, 5+registerLen(arg)); idx += registerLen(arg); mv.visitInsn(AASTORE); // store value into array } mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper", "invokeMethod", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", false); unwrapResult(mv, desc); mv.visitMaxs(size, registerLen(args) + 1); return mv; }
java
protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) { MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); // load this mv.visitFieldInsn(GETFIELD, proxyName, DELEGATE_OBJECT_FIELD, BytecodeHelper.getTypeDescription(delegateClass)); // load delegate // using InvokerHelper to allow potential intercepted calls int size; mv.visitLdcInsn(name); // method name Type[] args = Type.getArgumentTypes(desc); BytecodeHelper.pushConstant(mv, args.length); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); size = 6; int idx = 1; for (int i = 0; i < args.length; i++) { Type arg = args[i]; mv.visitInsn(DUP); BytecodeHelper.pushConstant(mv, i); // primitive types must be boxed if (isPrimitive(arg)) { mv.visitIntInsn(getLoadInsn(arg), idx); String wrappedType = getWrappedClassDescriptor(arg); mv.visitMethodInsn(INVOKESTATIC, wrappedType, "valueOf", "(" + arg.getDescriptor() + ")L" + wrappedType + ";", false); } else { mv.visitVarInsn(ALOAD, idx); // load argument i } size = Math.max(size, 5+registerLen(arg)); idx += registerLen(arg); mv.visitInsn(AASTORE); // store value into array } mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper", "invokeMethod", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", false); unwrapResult(mv, desc); mv.visitMaxs(size, registerLen(args) + 1); return mv; }
[ "protected", "MethodVisitor", "makeDelegateCall", "(", "final", "String", "name", ",", "final", "String", "desc", ",", "final", "String", "signature", ",", "final", "String", "[", "]", "exceptions", ",", "final", "int", "accessFlags", ")", "{", "MethodVisitor", ...
Generate a call to the delegate object.
[ "Generate", "a", "call", "to", "the", "delegate", "object", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java#L708-L741
train
groovy/groovy-core
src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java
CachedSAMClass.getSAMMethod
public static Method getSAMMethod(Class<?> c) { // SAM = single public abstract method // if the class is not abstract there is no abstract method if (!Modifier.isAbstract(c.getModifiers())) return null; if (c.isInterface()) { Method[] methods = c.getMethods(); // res stores the first found abstract method Method res = null; for (Method mi : methods) { // ignore methods, that are not abstract and from Object if (!Modifier.isAbstract(mi.getModifiers())) continue; // ignore trait methods which have a default implementation if (mi.getAnnotation(Traits.Implemented.class)!=null) continue; try { Object.class.getMethod(mi.getName(), mi.getParameterTypes()); continue; } catch (NoSuchMethodException e) {/*ignore*/} // we have two methods, so no SAM if (res!=null) return null; res = mi; } return res; } else { LinkedList<Method> methods = new LinkedList(); getAbstractMethods(c, methods); if (methods.isEmpty()) return null; ListIterator<Method> it = methods.listIterator(); while (it.hasNext()) { Method m = it.next(); if (hasUsableImplementation(c, m)) it.remove(); } return getSingleNonDuplicateMethod(methods); } }
java
public static Method getSAMMethod(Class<?> c) { // SAM = single public abstract method // if the class is not abstract there is no abstract method if (!Modifier.isAbstract(c.getModifiers())) return null; if (c.isInterface()) { Method[] methods = c.getMethods(); // res stores the first found abstract method Method res = null; for (Method mi : methods) { // ignore methods, that are not abstract and from Object if (!Modifier.isAbstract(mi.getModifiers())) continue; // ignore trait methods which have a default implementation if (mi.getAnnotation(Traits.Implemented.class)!=null) continue; try { Object.class.getMethod(mi.getName(), mi.getParameterTypes()); continue; } catch (NoSuchMethodException e) {/*ignore*/} // we have two methods, so no SAM if (res!=null) return null; res = mi; } return res; } else { LinkedList<Method> methods = new LinkedList(); getAbstractMethods(c, methods); if (methods.isEmpty()) return null; ListIterator<Method> it = methods.listIterator(); while (it.hasNext()) { Method m = it.next(); if (hasUsableImplementation(c, m)) it.remove(); } return getSingleNonDuplicateMethod(methods); } }
[ "public", "static", "Method", "getSAMMethod", "(", "Class", "<", "?", ">", "c", ")", "{", "// SAM = single public abstract method", "// if the class is not abstract there is no abstract method", "if", "(", "!", "Modifier", ".", "isAbstract", "(", "c", ".", "getModifiers...
returns the abstract method from a SAM type, if it is a SAM type. @param c the SAM class @return null if nothing was found, the method otherwise
[ "returns", "the", "abstract", "method", "from", "a", "SAM", "type", "if", "it", "is", "a", "SAM", "type", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java#L159-L195
train
groovy/groovy-core
src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
MopWriter.generateMopCalls
protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) { for (MethodNode method : mopCalls) { String name = getMopMethodName(method, useThis); Parameter[] parameters = method.getParameters(); String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters()); MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null); controller.setMethodVisitor(mv); mv.visitVarInsn(ALOAD, 0); int newRegister = 1; OperandStack operandStack = controller.getOperandStack(); for (Parameter parameter : parameters) { ClassNode type = parameter.getType(); operandStack.load(parameter.getType(), newRegister); // increment to next register, double/long are using two places newRegister++; if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++; } operandStack.remove(parameters.length); ClassNode declaringClass = method.getDeclaringClass(); // JDK 8 support for default methods in interfaces // this should probably be strenghtened when we support the A.super.foo() syntax int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL; mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE); BytecodeHelper.doReturn(mv, method.getReturnType()); mv.visitMaxs(0, 0); mv.visitEnd(); controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null); } }
java
protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) { for (MethodNode method : mopCalls) { String name = getMopMethodName(method, useThis); Parameter[] parameters = method.getParameters(); String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters()); MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null); controller.setMethodVisitor(mv); mv.visitVarInsn(ALOAD, 0); int newRegister = 1; OperandStack operandStack = controller.getOperandStack(); for (Parameter parameter : parameters) { ClassNode type = parameter.getType(); operandStack.load(parameter.getType(), newRegister); // increment to next register, double/long are using two places newRegister++; if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++; } operandStack.remove(parameters.length); ClassNode declaringClass = method.getDeclaringClass(); // JDK 8 support for default methods in interfaces // this should probably be strenghtened when we support the A.super.foo() syntax int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL; mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE); BytecodeHelper.doReturn(mv, method.getReturnType()); mv.visitMaxs(0, 0); mv.visitEnd(); controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null); } }
[ "protected", "void", "generateMopCalls", "(", "LinkedList", "<", "MethodNode", ">", "mopCalls", ",", "boolean", "useThis", ")", "{", "for", "(", "MethodNode", "method", ":", "mopCalls", ")", "{", "String", "name", "=", "getMopMethodName", "(", "method", ",", ...
generates a Meta Object Protocol method, that is used to call a non public method, or to make a call to super. @param mopCalls list of methods a mop call method should be generated for @param useThis true if "this" should be used for the naming
[ "generates", "a", "Meta", "Object", "Protocol", "method", "that", "is", "used", "to", "call", "a", "non", "public", "method", "or", "to", "make", "a", "call", "to", "super", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java#L174-L202
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ClassHelper.java
ClassHelper.getWrapper
public static ClassNode getWrapper(ClassNode cn) { cn = cn.redirect(); if (!isPrimitiveType(cn)) return cn; if (cn==boolean_TYPE) { return Boolean_TYPE; } else if (cn==byte_TYPE) { return Byte_TYPE; } else if (cn==char_TYPE) { return Character_TYPE; } else if (cn==short_TYPE) { return Short_TYPE; } else if (cn==int_TYPE) { return Integer_TYPE; } else if (cn==long_TYPE) { return Long_TYPE; } else if (cn==float_TYPE) { return Float_TYPE; } else if (cn==double_TYPE) { return Double_TYPE; } else if (cn==VOID_TYPE) { return void_WRAPPER_TYPE; } else { return cn; } }
java
public static ClassNode getWrapper(ClassNode cn) { cn = cn.redirect(); if (!isPrimitiveType(cn)) return cn; if (cn==boolean_TYPE) { return Boolean_TYPE; } else if (cn==byte_TYPE) { return Byte_TYPE; } else if (cn==char_TYPE) { return Character_TYPE; } else if (cn==short_TYPE) { return Short_TYPE; } else if (cn==int_TYPE) { return Integer_TYPE; } else if (cn==long_TYPE) { return Long_TYPE; } else if (cn==float_TYPE) { return Float_TYPE; } else if (cn==double_TYPE) { return Double_TYPE; } else if (cn==VOID_TYPE) { return void_WRAPPER_TYPE; } else { return cn; } }
[ "public", "static", "ClassNode", "getWrapper", "(", "ClassNode", "cn", ")", "{", "cn", "=", "cn", ".", "redirect", "(", ")", ";", "if", "(", "!", "isPrimitiveType", "(", "cn", ")", ")", "return", "cn", ";", "if", "(", "cn", "==", "boolean_TYPE", ")",...
Creates a ClassNode containing the wrapper of a ClassNode of primitive type. Any ClassNode representing a primitive type should be created using the predefined types used in class. The method will check the parameter for known references of ClassNode representing a primitive type. If Reference is found, then a ClassNode will be contained that represents the wrapper class. For example for boolean, the wrapper class is java.lang.Boolean. If the parameter is no primitive type, the redirected ClassNode will be returned @see #make(Class) @see #make(String) @param cn the ClassNode containing a possible primitive type
[ "Creates", "a", "ClassNode", "containing", "the", "wrapper", "of", "a", "ClassNode", "of", "primitive", "type", ".", "Any", "ClassNode", "representing", "a", "primitive", "type", "should", "be", "created", "using", "the", "predefined", "types", "used", "in", "...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ClassHelper.java#L257-L282
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ClassHelper.java
ClassHelper.findSAM
public static MethodNode findSAM(ClassNode type) { if (!Modifier.isAbstract(type.getModifiers())) return null; if (type.isInterface()) { List<MethodNode> methods = type.getMethods(); MethodNode found=null; for (MethodNode mi : methods) { // ignore methods, that are not abstract and from Object if (!Modifier.isAbstract(mi.getModifiers())) continue; // ignore trait methods which have a default implementation if (Traits.hasDefaultImplementation(mi)) continue; if (mi.getDeclaringClass().equals(OBJECT_TYPE)) continue; if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters())!=null) continue; // we have two methods, so no SAM if (found!=null) return null; found = mi; } return found; } else { List<MethodNode> methods = type.getAbstractMethods(); MethodNode found = null; if (methods!=null) { for (MethodNode mi : methods) { if (!hasUsableImplementation(type, mi)) { if (found!=null) return null; found = mi; } } } return found; } }
java
public static MethodNode findSAM(ClassNode type) { if (!Modifier.isAbstract(type.getModifiers())) return null; if (type.isInterface()) { List<MethodNode> methods = type.getMethods(); MethodNode found=null; for (MethodNode mi : methods) { // ignore methods, that are not abstract and from Object if (!Modifier.isAbstract(mi.getModifiers())) continue; // ignore trait methods which have a default implementation if (Traits.hasDefaultImplementation(mi)) continue; if (mi.getDeclaringClass().equals(OBJECT_TYPE)) continue; if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters())!=null) continue; // we have two methods, so no SAM if (found!=null) return null; found = mi; } return found; } else { List<MethodNode> methods = type.getAbstractMethods(); MethodNode found = null; if (methods!=null) { for (MethodNode mi : methods) { if (!hasUsableImplementation(type, mi)) { if (found!=null) return null; found = mi; } } } return found; } }
[ "public", "static", "MethodNode", "findSAM", "(", "ClassNode", "type", ")", "{", "if", "(", "!", "Modifier", ".", "isAbstract", "(", "type", ".", "getModifiers", "(", ")", ")", ")", "return", "null", ";", "if", "(", "type", ".", "isInterface", "(", ")"...
Returns the single abstract method of a class node, if it is a SAM type, or null otherwise. @param type a type for which to search for a single abstract method @return the method node if type is a SAM type, null otherwise
[ "Returns", "the", "single", "abstract", "method", "of", "a", "class", "node", "if", "it", "is", "a", "SAM", "type", "or", "null", "otherwise", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ClassHelper.java#L395-L428
train
groovy/groovy-core
src/main/org/codehaus/groovy/syntax/Types.java
Types.getPrecedence
public static int getPrecedence( int type, boolean throwIfInvalid ) { switch( type ) { case LEFT_PARENTHESIS: return 0; case EQUAL: case PLUS_EQUAL: case MINUS_EQUAL: case MULTIPLY_EQUAL: case DIVIDE_EQUAL: case INTDIV_EQUAL: case MOD_EQUAL: case POWER_EQUAL: case LOGICAL_OR_EQUAL: case LOGICAL_AND_EQUAL: case LEFT_SHIFT_EQUAL: case RIGHT_SHIFT_EQUAL: case RIGHT_SHIFT_UNSIGNED_EQUAL: case BITWISE_OR_EQUAL: case BITWISE_AND_EQUAL: case BITWISE_XOR_EQUAL: return 5; case QUESTION: return 10; case LOGICAL_OR: return 15; case LOGICAL_AND: return 20; case BITWISE_OR: case BITWISE_AND: case BITWISE_XOR: return 22; case COMPARE_IDENTICAL: case COMPARE_NOT_IDENTICAL: return 24; case COMPARE_NOT_EQUAL: case COMPARE_EQUAL: case COMPARE_LESS_THAN: case COMPARE_LESS_THAN_EQUAL: case COMPARE_GREATER_THAN: case COMPARE_GREATER_THAN_EQUAL: case COMPARE_TO: case FIND_REGEX: case MATCH_REGEX: case KEYWORD_INSTANCEOF: return 25; case DOT_DOT: case DOT_DOT_DOT: return 30; case LEFT_SHIFT: case RIGHT_SHIFT: case RIGHT_SHIFT_UNSIGNED: return 35; case PLUS: case MINUS: return 40; case MULTIPLY: case DIVIDE: case INTDIV: case MOD: return 45; case NOT: case REGEX_PATTERN: return 50; case SYNTH_CAST: return 55; case PLUS_PLUS: case MINUS_MINUS: case PREFIX_PLUS_PLUS: case PREFIX_MINUS_MINUS: case POSTFIX_PLUS_PLUS: case POSTFIX_MINUS_MINUS: return 65; case PREFIX_PLUS: case PREFIX_MINUS: return 70; case POWER: return 72; case SYNTH_METHOD: case LEFT_SQUARE_BRACKET: return 75; case DOT: case NAVIGATE: return 80; case KEYWORD_NEW: return 85; } if( throwIfInvalid ) { throw new GroovyBugError( "precedence requested for non-operator" ); } return -1; }
java
public static int getPrecedence( int type, boolean throwIfInvalid ) { switch( type ) { case LEFT_PARENTHESIS: return 0; case EQUAL: case PLUS_EQUAL: case MINUS_EQUAL: case MULTIPLY_EQUAL: case DIVIDE_EQUAL: case INTDIV_EQUAL: case MOD_EQUAL: case POWER_EQUAL: case LOGICAL_OR_EQUAL: case LOGICAL_AND_EQUAL: case LEFT_SHIFT_EQUAL: case RIGHT_SHIFT_EQUAL: case RIGHT_SHIFT_UNSIGNED_EQUAL: case BITWISE_OR_EQUAL: case BITWISE_AND_EQUAL: case BITWISE_XOR_EQUAL: return 5; case QUESTION: return 10; case LOGICAL_OR: return 15; case LOGICAL_AND: return 20; case BITWISE_OR: case BITWISE_AND: case BITWISE_XOR: return 22; case COMPARE_IDENTICAL: case COMPARE_NOT_IDENTICAL: return 24; case COMPARE_NOT_EQUAL: case COMPARE_EQUAL: case COMPARE_LESS_THAN: case COMPARE_LESS_THAN_EQUAL: case COMPARE_GREATER_THAN: case COMPARE_GREATER_THAN_EQUAL: case COMPARE_TO: case FIND_REGEX: case MATCH_REGEX: case KEYWORD_INSTANCEOF: return 25; case DOT_DOT: case DOT_DOT_DOT: return 30; case LEFT_SHIFT: case RIGHT_SHIFT: case RIGHT_SHIFT_UNSIGNED: return 35; case PLUS: case MINUS: return 40; case MULTIPLY: case DIVIDE: case INTDIV: case MOD: return 45; case NOT: case REGEX_PATTERN: return 50; case SYNTH_CAST: return 55; case PLUS_PLUS: case MINUS_MINUS: case PREFIX_PLUS_PLUS: case PREFIX_MINUS_MINUS: case POSTFIX_PLUS_PLUS: case POSTFIX_MINUS_MINUS: return 65; case PREFIX_PLUS: case PREFIX_MINUS: return 70; case POWER: return 72; case SYNTH_METHOD: case LEFT_SQUARE_BRACKET: return 75; case DOT: case NAVIGATE: return 80; case KEYWORD_NEW: return 85; } if( throwIfInvalid ) { throw new GroovyBugError( "precedence requested for non-operator" ); } return -1; }
[ "public", "static", "int", "getPrecedence", "(", "int", "type", ",", "boolean", "throwIfInvalid", ")", "{", "switch", "(", "type", ")", "{", "case", "LEFT_PARENTHESIS", ":", "return", "0", ";", "case", "EQUAL", ":", "case", "PLUS_EQUAL", ":", "case", "MINU...
Returns the precedence of the specified operator. Non-operator's will receive -1 or a GroovyBugError, depending on your preference.
[ "Returns", "the", "precedence", "of", "the", "specified", "operator", ".", "Non", "-", "operator", "s", "will", "receive", "-", "1", "or", "a", "GroovyBugError", "depending", "on", "your", "preference", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Types.java#L976-L1089
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/NullObject.java
NullObject.with
public <T> T with( Closure<T> closure ) { return DefaultGroovyMethods.with( null, closure ) ; }
java
public <T> T with( Closure<T> closure ) { return DefaultGroovyMethods.with( null, closure ) ; }
[ "public", "<", "T", ">", "T", "with", "(", "Closure", "<", "T", ">", "closure", ")", "{", "return", "DefaultGroovyMethods", ".", "with", "(", "null", ",", "closure", ")", ";", "}" ]
Allows the closure to be called for NullObject @param closure the closure to call on the object @return result of calling the closure
[ "Allows", "the", "closure", "to", "be", "called", "for", "NullObject" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/NullObject.java#L69-L71
train
groovy/groovy-core
src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java
DefaultGrailsDomainClassInjector.implementsMethod
private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) { List methods = classNode.getMethods(); if (argTypes == null || argTypes.length ==0) { for (Iterator i = methods.iterator(); i.hasNext();) { MethodNode mn = (MethodNode) i.next(); boolean methodMatch = mn.getName().equals(methodName); if(methodMatch)return true; // TODO Implement further parameter analysis } } return false; }
java
private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) { List methods = classNode.getMethods(); if (argTypes == null || argTypes.length ==0) { for (Iterator i = methods.iterator(); i.hasNext();) { MethodNode mn = (MethodNode) i.next(); boolean methodMatch = mn.getName().equals(methodName); if(methodMatch)return true; // TODO Implement further parameter analysis } } return false; }
[ "private", "static", "boolean", "implementsMethod", "(", "ClassNode", "classNode", ",", "String", "methodName", ",", "Class", "[", "]", "argTypes", ")", "{", "List", "methods", "=", "classNode", ".", "getMethods", "(", ")", ";", "if", "(", "argTypes", "==", ...
Tests whether the ClassNode implements the specified method name @param classNode The ClassNode @param methodName The method name @param argTypes @return True if it implements the method
[ "Tests", "whether", "the", "ClassNode", "implements", "the", "specified", "method", "name" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java#L243-L254
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/MethodNode.java
MethodNode.getTypeDescriptor
public String getTypeDescriptor() { if (typeDescriptor == null) { StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10); buf.append(returnType.getName()); buf.append(' '); buf.append(name); buf.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); } Parameter param = parameters[i]; buf.append(formatTypeName(param.getType())); } buf.append(')'); typeDescriptor = buf.toString(); } return typeDescriptor; }
java
public String getTypeDescriptor() { if (typeDescriptor == null) { StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10); buf.append(returnType.getName()); buf.append(' '); buf.append(name); buf.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); } Parameter param = parameters[i]; buf.append(formatTypeName(param.getType())); } buf.append(')'); typeDescriptor = buf.toString(); } return typeDescriptor; }
[ "public", "String", "getTypeDescriptor", "(", ")", "{", "if", "(", "typeDescriptor", "==", "null", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "name", ".", "length", "(", ")", "+", "parameters", ".", "length", "*", "10", ")", ";",...
The type descriptor for a method node is a string containing the name of the method, its return type, and its parameter types in a canonical form. For simplicity, I'm using the format of a Java declaration without parameter names. @return the type descriptor
[ "The", "type", "descriptor", "for", "a", "method", "node", "is", "a", "string", "containing", "the", "name", "of", "the", "method", "its", "return", "type", "and", "its", "parameter", "types", "in", "a", "canonical", "form", ".", "For", "simplicity", "I", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/MethodNode.java#L76-L94
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/MethodNode.java
MethodNode.getText
@Override public String getText() { String retType = AstToTextHelper.getClassText(returnType); String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions); String parms = AstToTextHelper.getParametersText(parameters); return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name + "(" + parms + ") " + exceptionTypes + " { ... }"; }
java
@Override public String getText() { String retType = AstToTextHelper.getClassText(returnType); String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions); String parms = AstToTextHelper.getParametersText(parameters); return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name + "(" + parms + ") " + exceptionTypes + " { ... }"; }
[ "@", "Override", "public", "String", "getText", "(", ")", "{", "String", "retType", "=", "AstToTextHelper", ".", "getClassText", "(", "returnType", ")", ";", "String", "exceptionTypes", "=", "AstToTextHelper", ".", "getThrowsClauseText", "(", "exceptions", ")", ...
Provides a nicely formatted string of the method definition. For simplicity, generic types on some of the elements are not displayed. @return string form of node with some generic elements suppressed
[ "Provides", "a", "nicely", "formatted", "string", "of", "the", "method", "definition", ".", "For", "simplicity", "generic", "types", "on", "some", "of", "the", "elements", "are", "not", "displayed", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/MethodNode.java#L300-L306
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.constructors
public GroovyConstructorDoc[] constructors() { Collections.sort(constructors); return constructors.toArray(new GroovyConstructorDoc[constructors.size()]); }
java
public GroovyConstructorDoc[] constructors() { Collections.sort(constructors); return constructors.toArray(new GroovyConstructorDoc[constructors.size()]); }
[ "public", "GroovyConstructorDoc", "[", "]", "constructors", "(", ")", "{", "Collections", ".", "sort", "(", "constructors", ")", ";", "return", "constructors", ".", "toArray", "(", "new", "GroovyConstructorDoc", "[", "constructors", ".", "size", "(", ")", "]",...
returns a sorted array of constructors
[ "returns", "a", "sorted", "array", "of", "constructors" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L100-L103
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.innerClasses
public GroovyClassDoc[] innerClasses() { Collections.sort(nested); return nested.toArray(new GroovyClassDoc[nested.size()]); }
java
public GroovyClassDoc[] innerClasses() { Collections.sort(nested); return nested.toArray(new GroovyClassDoc[nested.size()]); }
[ "public", "GroovyClassDoc", "[", "]", "innerClasses", "(", ")", "{", "Collections", ".", "sort", "(", "nested", ")", ";", "return", "nested", ".", "toArray", "(", "new", "GroovyClassDoc", "[", "nested", ".", "size", "(", ")", "]", ")", ";", "}" ]
returns a sorted array of nested classes and interfaces
[ "returns", "a", "sorted", "array", "of", "nested", "classes", "and", "interfaces" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L129-L132
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.fields
public GroovyFieldDoc[] fields() { Collections.sort(fields); return fields.toArray(new GroovyFieldDoc[fields.size()]); }
java
public GroovyFieldDoc[] fields() { Collections.sort(fields); return fields.toArray(new GroovyFieldDoc[fields.size()]); }
[ "public", "GroovyFieldDoc", "[", "]", "fields", "(", ")", "{", "Collections", ".", "sort", "(", "fields", ")", ";", "return", "fields", ".", "toArray", "(", "new", "GroovyFieldDoc", "[", "fields", ".", "size", "(", ")", "]", ")", ";", "}" ]
returns a sorted array of fields
[ "returns", "a", "sorted", "array", "of", "fields" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L141-L144
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.properties
public GroovyFieldDoc[] properties() { Collections.sort(properties); return properties.toArray(new GroovyFieldDoc[properties.size()]); }
java
public GroovyFieldDoc[] properties() { Collections.sort(properties); return properties.toArray(new GroovyFieldDoc[properties.size()]); }
[ "public", "GroovyFieldDoc", "[", "]", "properties", "(", ")", "{", "Collections", ".", "sort", "(", "properties", ")", ";", "return", "properties", ".", "toArray", "(", "new", "GroovyFieldDoc", "[", "properties", ".", "size", "(", ")", "]", ")", ";", "}"...
returns a sorted array of properties
[ "returns", "a", "sorted", "array", "of", "properties" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L153-L156
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.enumConstants
public GroovyFieldDoc[] enumConstants() { Collections.sort(enumConstants); return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]); }
java
public GroovyFieldDoc[] enumConstants() { Collections.sort(enumConstants); return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]); }
[ "public", "GroovyFieldDoc", "[", "]", "enumConstants", "(", ")", "{", "Collections", ".", "sort", "(", "enumConstants", ")", ";", "return", "enumConstants", ".", "toArray", "(", "new", "GroovyFieldDoc", "[", "enumConstants", ".", "size", "(", ")", "]", ")", ...
returns a sorted array of enum constants
[ "returns", "a", "sorted", "array", "of", "enum", "constants" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L165-L168
train
groovy/groovy-core
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
SimpleGroovyClassDoc.methods
public GroovyMethodDoc[] methods() { Collections.sort(methods); return methods.toArray(new GroovyMethodDoc[methods.size()]); }
java
public GroovyMethodDoc[] methods() { Collections.sort(methods); return methods.toArray(new GroovyMethodDoc[methods.size()]); }
[ "public", "GroovyMethodDoc", "[", "]", "methods", "(", ")", "{", "Collections", ".", "sort", "(", "methods", ")", ";", "return", "methods", ".", "toArray", "(", "new", "GroovyMethodDoc", "[", "methods", ".", "size", "(", ")", "]", ")", ";", "}" ]
returns a sorted array of methods
[ "returns", "a", "sorted", "array", "of", "methods" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java#L177-L180
train
groovy/groovy-core
subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java
DataSet.add
public void add(Map<String, Object> map) throws SQLException { if (withinDataSetBatch) { if (batchData.size() == 0) { batchKeys = map.keySet(); } else { if (!map.keySet().equals(batchKeys)) { throw new IllegalArgumentException("Inconsistent keys found for batch add!"); } } batchData.add(map); return; } int answer = executeUpdate(buildListQuery(map), new ArrayList<Object>(map.values())); if (answer != 1) { LOG.warning("Should have updated 1 row not " + answer + " when trying to add: " + map); } }
java
public void add(Map<String, Object> map) throws SQLException { if (withinDataSetBatch) { if (batchData.size() == 0) { batchKeys = map.keySet(); } else { if (!map.keySet().equals(batchKeys)) { throw new IllegalArgumentException("Inconsistent keys found for batch add!"); } } batchData.add(map); return; } int answer = executeUpdate(buildListQuery(map), new ArrayList<Object>(map.values())); if (answer != 1) { LOG.warning("Should have updated 1 row not " + answer + " when trying to add: " + map); } }
[ "public", "void", "add", "(", "Map", "<", "String", ",", "Object", ">", "map", ")", "throws", "SQLException", "{", "if", "(", "withinDataSetBatch", ")", "{", "if", "(", "batchData", ".", "size", "(", ")", "==", "0", ")", "{", "batchKeys", "=", "map",...
Adds the provided map of key-value pairs as a new row in the table represented by this DataSet. @param map the key (column-name), value pairs to add as a new row @throws SQLException if a database error occurs
[ "Adds", "the", "provided", "map", "of", "key", "-", "value", "pairs", "as", "a", "new", "row", "in", "the", "table", "represented", "by", "this", "DataSet", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L233-L249
train
groovy/groovy-core
subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java
DataSet.each
public void each(int offset, int maxRows, Closure closure) throws SQLException { eachRow(getSql(), getParameters(), offset, maxRows, closure); }
java
public void each(int offset, int maxRows, Closure closure) throws SQLException { eachRow(getSql(), getParameters(), offset, maxRows, closure); }
[ "public", "void", "each", "(", "int", "offset", ",", "int", "maxRows", ",", "Closure", "closure", ")", "throws", "SQLException", "{", "eachRow", "(", "getSql", "(", ")", ",", "getParameters", "(", ")", ",", "offset", ",", "maxRows", ",", "closure", ")", ...
Calls the provided closure for a "page" of rows from the table represented by this DataSet. A page is defined as starting at a 1-based offset, and containing a maximum number of rows. @param offset the 1-based offset for the first row to be processed @param maxRows the maximum number of rows to be processed @param closure called for each row with a GroovyResultSet @throws SQLException if a database access error occurs @see groovy.sql.Sql#eachRow(String, java.util.List, int, int, groovy.lang.Closure)
[ "Calls", "the", "provided", "closure", "for", "a", "page", "of", "rows", "from", "the", "table", "represented", "by", "this", "DataSet", ".", "A", "page", "is", "defined", "as", "starting", "at", "a", "1", "-", "based", "offset", "and", "containing", "a"...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L349-L351
train
groovy/groovy-core
src/main/groovy/beans/VetoableASTTransformation.java
VetoableASTTransformation.wrapSetterMethod
private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) { String getterName = "get" + MetaClassHelper.capitalize(propertyName); MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName)); if (setter != null) { // Get the existing code block Statement code = setter.getCode(); Expression oldValue = varX("$oldValue"); Expression newValue = varX("$newValue"); Expression proposedValue = varX(setter.getParameters()[0].getName()); BlockStatement block = new BlockStatement(); // create a local variable to hold the old value from the getter block.addStatement(declS(oldValue, callThisX(getterName))); // add the fireVetoableChange method call block.addStatement(stmt(callThisX("fireVetoableChange", args( constX(propertyName), oldValue, proposedValue)))); // call the existing block, which will presumably set the value properly block.addStatement(code); if (bindable) { // get the new value to emit in the event block.addStatement(declS(newValue, callThisX(getterName))); // add the firePropertyChange method call block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue)))); } // replace the existing code block with our new one setter.setCode(block); } }
java
private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) { String getterName = "get" + MetaClassHelper.capitalize(propertyName); MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName)); if (setter != null) { // Get the existing code block Statement code = setter.getCode(); Expression oldValue = varX("$oldValue"); Expression newValue = varX("$newValue"); Expression proposedValue = varX(setter.getParameters()[0].getName()); BlockStatement block = new BlockStatement(); // create a local variable to hold the old value from the getter block.addStatement(declS(oldValue, callThisX(getterName))); // add the fireVetoableChange method call block.addStatement(stmt(callThisX("fireVetoableChange", args( constX(propertyName), oldValue, proposedValue)))); // call the existing block, which will presumably set the value properly block.addStatement(code); if (bindable) { // get the new value to emit in the event block.addStatement(declS(newValue, callThisX(getterName))); // add the firePropertyChange method call block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue)))); } // replace the existing code block with our new one setter.setCode(block); } }
[ "private", "void", "wrapSetterMethod", "(", "ClassNode", "classNode", ",", "boolean", "bindable", ",", "String", "propertyName", ")", "{", "String", "getterName", "=", "\"get\"", "+", "MetaClassHelper", ".", "capitalize", "(", "propertyName", ")", ";", "MethodNode...
Wrap an existing setter.
[ "Wrap", "an", "existing", "setter", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/beans/VetoableASTTransformation.java#L169-L203
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.directorySize
public static long directorySize(File self) throws IOException, IllegalArgumentException { final long[] size = {0L}; eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) { public void doCall(Object[] args) { size[0] += ((File) args[0]).length(); } }); return size[0]; }
java
public static long directorySize(File self) throws IOException, IllegalArgumentException { final long[] size = {0L}; eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) { public void doCall(Object[] args) { size[0] += ((File) args[0]).length(); } }); return size[0]; }
[ "public", "static", "long", "directorySize", "(", "File", "self", ")", "throws", "IOException", ",", "IllegalArgumentException", "{", "final", "long", "[", "]", "size", "=", "{", "0L", "}", ";", "eachFileRecurse", "(", "self", ",", "FileType", ".", "FILES", ...
Calculates directory size as total size of all its files, recursively. @param self a file object @return directory size (length) @since 2.1 @throws IOException if File object specified does not exist @throws IllegalArgumentException if the provided File object does not represent a directory
[ "Calculates", "directory", "size", "as", "total", "size", "of", "all", "its", "files", "recursively", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L118-L129
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.splitEachLine
public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self), regex, closure); }
java
public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException { return IOGroovyMethods.splitEachLine(newReader(self), regex, closure); }
[ "public", "static", "<", "T", ">", "T", "splitEachLine", "(", "File", "self", ",", "String", "regex", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String[]\"", ")", "Closure", "<", "T", ">", ...
Iterates through this file line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed. @param self a File @param regex the delimiting regular expression @param closure a closure @return the last value returned by the closure @throws IOException if an IOException occurs. @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid @see IOGroovyMethods#splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure) @since 1.5.5
[ "Iterates", "through", "this", "file", "line", "by", "line", "splitting", "each", "line", "using", "the", "given", "regex", "separator", ".", "For", "each", "line", "the", "given", "closure", "is", "called", "with", "a", "single", "parameter", "being", "the"...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L378-L380
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.write
public static void write(File file, String text, String charset) throws IOException { Writer writer = null; try { FileOutputStream out = new FileOutputStream(file); writeUTF16BomIfRequired(charset, out); writer = new OutputStreamWriter(out, charset); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
java
public static void write(File file, String text, String charset) throws IOException { Writer writer = null; try { FileOutputStream out = new FileOutputStream(file); writeUTF16BomIfRequired(charset, out); writer = new OutputStreamWriter(out, charset); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
[ "public", "static", "void", "write", "(", "File", "file", ",", "String", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "Writer", "writer", "=", "null", ";", "try", "{", "FileOutputStream", "out", "=", "new", "FileOutputStream", "(", ...
Write the text to the File, using the specified encoding. @param file a File @param text the text to write to the File @param charset the charset used @throws IOException if an IOException occurs. @since 1.0
[ "Write", "the", "text", "to", "the", "File", "using", "the", "specified", "encoding", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L817-L832
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Object text) throws IOException { Writer writer = null; try { writer = new FileWriter(file, true); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
java
public static void append(File file, Object text) throws IOException { Writer writer = null; try { writer = new FileWriter(file, true); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Object", "text", ")", "throws", "IOException", "{", "Writer", "writer", "=", "null", ";", "try", "{", "writer", "=", "new", "FileWriter", "(", "file", ",", "true", ")", ";", "InvokerHelper"...
Append the text at the end of the File. @param file a File @param text the text to append at the end of the File @throws IOException if an IOException occurs. @since 1.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "File", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L842-L855
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Object text, String charset) throws IOException { Writer writer = null; try { FileOutputStream out = new FileOutputStream(file, true); if (!file.exists()) { writeUTF16BomIfRequired(charset, out); } writer = new OutputStreamWriter(out, charset); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
java
public static void append(File file, Object text, String charset) throws IOException { Writer writer = null; try { FileOutputStream out = new FileOutputStream(file, true); if (!file.exists()) { writeUTF16BomIfRequired(charset, out); } writer = new OutputStreamWriter(out, charset); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Object", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "Writer", "writer", "=", "null", ";", "try", "{", "FileOutputStream", "out", "=", "new", "FileOutputStream", "(", ...
Append the text at the end of the File, using a specified encoding. @param file a File @param text the text to append at the end of the File @param charset the charset used @throws IOException if an IOException occurs. @since 1.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "File", "using", "a", "specified", "encoding", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L946-L963
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.append
public static void append(File file, Writer writer, String charset) throws IOException { appendBuffered(file, writer, charset); }
java
public static void append(File file, Writer writer, String charset) throws IOException { appendBuffered(file, writer, charset); }
[ "public", "static", "void", "append", "(", "File", "file", ",", "Writer", "writer", ",", "String", "charset", ")", "throws", "IOException", "{", "appendBuffered", "(", "file", ",", "writer", ",", "charset", ")", ";", "}" ]
Append the text supplied by the Writer at the end of the File, using a specified encoding. @param file a File @param writer the Writer supplying the text to append at the end of the File @param charset the charset used @throws IOException if an IOException occurs. @since 2.3
[ "Append", "the", "text", "supplied", "by", "the", "Writer", "at", "the", "end", "of", "the", "File", "using", "a", "specified", "encoding", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L974-L976
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
ResourceGroovyMethods.writeUtf16Bom
private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException { if (bigEndian) { stream.write(-2); stream.write(-1); } else { stream.write(-1); stream.write(-2); } }
java
private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException { if (bigEndian) { stream.write(-2); stream.write(-1); } else { stream.write(-1); stream.write(-2); } }
[ "private", "static", "void", "writeUtf16Bom", "(", "OutputStream", "stream", ",", "boolean", "bigEndian", ")", "throws", "IOException", "{", "if", "(", "bigEndian", ")", "{", "stream", ".", "write", "(", "-", "2", ")", ";", "stream", ".", "write", "(", "...
Write a Byte Order Mark at the beginning of the file @param stream the FileOutputStream to write the BOM to @param bigEndian true if UTF 16 Big Endian or false if Low Endian @throws IOException if an IOException occurs. @since 1.0
[ "Write", "a", "Byte", "Order", "Mark", "at", "the", "beginning", "of", "the", "file" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java#L1825-L1833
train
groovy/groovy-core
src/main/groovy/lang/GroovyClassLoader.java
GroovyClassLoader.getClassCacheEntry
protected Class getClassCacheEntry(String name) { if (name == null) return null; synchronized (classCache) { return classCache.get(name); } }
java
protected Class getClassCacheEntry(String name) { if (name == null) return null; synchronized (classCache) { return classCache.get(name); } }
[ "protected", "Class", "getClassCacheEntry", "(", "String", "name", ")", "{", "if", "(", "name", "==", "null", ")", "return", "null", ";", "synchronized", "(", "classCache", ")", "{", "return", "classCache", ".", "get", "(", "name", ")", ";", "}", "}" ]
gets a class from the class cache. This cache contains only classes loaded through this class loader or an InnerLoader instance. If no class is stored for a specific name, then the method should return null. @param name of the class @return the class stored for the given name @see #removeClassCacheEntry(String) @see #setClassCacheEntry(Class) @see #clearCache()
[ "gets", "a", "class", "from", "the", "class", "cache", ".", "This", "cache", "contains", "only", "classes", "loaded", "through", "this", "class", "loader", "or", "an", "InnerLoader", "instance", ".", "If", "no", "class", "is", "stored", "for", "a", "specif...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/GroovyClassLoader.java#L560-L565
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
MetaClassRegistryImpl.getMetaClassRegistryChangeEventListeners
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() { synchronized (changeListenerList) { ArrayList<MetaClassRegistryChangeEventListener> ret = new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeListenerList.size()); ret.addAll(nonRemoveableChangeListenerList); ret.addAll(changeListenerList); return ret.toArray(new MetaClassRegistryChangeEventListener[ret.size()]); } }
java
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() { synchronized (changeListenerList) { ArrayList<MetaClassRegistryChangeEventListener> ret = new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeListenerList.size()); ret.addAll(nonRemoveableChangeListenerList); ret.addAll(changeListenerList); return ret.toArray(new MetaClassRegistryChangeEventListener[ret.size()]); } }
[ "public", "MetaClassRegistryChangeEventListener", "[", "]", "getMetaClassRegistryChangeEventListeners", "(", ")", "{", "synchronized", "(", "changeListenerList", ")", "{", "ArrayList", "<", "MetaClassRegistryChangeEventListener", ">", "ret", "=", "new", "ArrayList", "<", ...
Gets an array of of all registered ConstantMetaClassListener instances.
[ "Gets", "an", "array", "of", "of", "all", "registered", "ConstantMetaClassListener", "instances", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java#L400-L408
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
MetaClassRegistryImpl.getInstance
public static MetaClassRegistry getInstance(int includeExtension) { if (includeExtension != DONT_LOAD_DEFAULT) { if (instanceInclude == null) { instanceInclude = new MetaClassRegistryImpl(); } return instanceInclude; } else { if (instanceExclude == null) { instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT); } return instanceExclude; } }
java
public static MetaClassRegistry getInstance(int includeExtension) { if (includeExtension != DONT_LOAD_DEFAULT) { if (instanceInclude == null) { instanceInclude = new MetaClassRegistryImpl(); } return instanceInclude; } else { if (instanceExclude == null) { instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT); } return instanceExclude; } }
[ "public", "static", "MetaClassRegistry", "getInstance", "(", "int", "includeExtension", ")", "{", "if", "(", "includeExtension", "!=", "DONT_LOAD_DEFAULT", ")", "{", "if", "(", "instanceInclude", "==", "null", ")", "{", "instanceInclude", "=", "new", "MetaClassReg...
Singleton of MetaClassRegistry. @param includeExtension @return the registry
[ "Singleton", "of", "MetaClassRegistry", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java#L416-L428
train
groovy/groovy-core
src/main/org/codehaus/groovy/syntax/Reduction.java
Reduction.get
public CSTNode get( int index ) { CSTNode element = null; if( index < size() ) { element = (CSTNode)elements.get( index ); } return element; }
java
public CSTNode get( int index ) { CSTNode element = null; if( index < size() ) { element = (CSTNode)elements.get( index ); } return element; }
[ "public", "CSTNode", "get", "(", "int", "index", ")", "{", "CSTNode", "element", "=", "null", ";", "if", "(", "index", "<", "size", "(", ")", ")", "{", "element", "=", "(", "CSTNode", ")", "elements", ".", "get", "(", "index", ")", ";", "}", "ret...
Returns the specified element, or null.
[ "Returns", "the", "specified", "element", "or", "null", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Reduction.java#L118-L128
train
groovy/groovy-core
src/main/org/codehaus/groovy/syntax/Reduction.java
Reduction.set
public CSTNode set( int index, CSTNode element ) { if( elements == null ) { throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" ); } if( index == 0 && !(element instanceof Token) ) { // // It's not the greatest of design that the interface allows this, but it // is a tradeoff with convenience, and the convenience is more important. throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" ); } // // Fill slots with nulls, if necessary. int count = elements.size(); if( index >= count ) { for( int i = count; i <= index; i++ ) { elements.add( null ); } } // // Then set in the element. elements.set( index, element ); return element; }
java
public CSTNode set( int index, CSTNode element ) { if( elements == null ) { throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" ); } if( index == 0 && !(element instanceof Token) ) { // // It's not the greatest of design that the interface allows this, but it // is a tradeoff with convenience, and the convenience is more important. throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" ); } // // Fill slots with nulls, if necessary. int count = elements.size(); if( index >= count ) { for( int i = count; i <= index; i++ ) { elements.add( null ); } } // // Then set in the element. elements.set( index, element ); return element; }
[ "public", "CSTNode", "set", "(", "int", "index", ",", "CSTNode", "element", ")", "{", "if", "(", "elements", "==", "null", ")", "{", "throw", "new", "GroovyBugError", "(", "\"attempt to set() on a EMPTY Reduction\"", ")", ";", "}", "if", "(", "index", "==", ...
Sets an element in at the specified index.
[ "Sets", "an", "element", "in", "at", "the", "specified", "index", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/syntax/Reduction.java#L199-L236
train
groovy/groovy-core
src/main/org/codehaus/groovy/util/ManagedLinkedList.java
ManagedLinkedList.add
public void add(T value) { Element<T> element = new Element<T>(bundle, value); element.previous = tail; if (tail != null) tail.next = element; tail = element; if (head == null) head = element; }
java
public void add(T value) { Element<T> element = new Element<T>(bundle, value); element.previous = tail; if (tail != null) tail.next = element; tail = element; if (head == null) head = element; }
[ "public", "void", "add", "(", "T", "value", ")", "{", "Element", "<", "T", ">", "element", "=", "new", "Element", "<", "T", ">", "(", "bundle", ",", "value", ")", ";", "element", ".", "previous", "=", "tail", ";", "if", "(", "tail", "!=", "null",...
adds a value to the list @param value the value
[ "adds", "a", "value", "to", "the", "list" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedLinkedList.java#L100-L106
train
groovy/groovy-core
src/main/org/codehaus/groovy/util/ManagedLinkedList.java
ManagedLinkedList.toArray
public T[] toArray(T[] tArray) { List<T> array = new ArrayList<T>(100); for (Iterator<T> it = iterator(); it.hasNext();) { T val = it.next(); if (val != null) array.add(val); } return array.toArray(tArray); }
java
public T[] toArray(T[] tArray) { List<T> array = new ArrayList<T>(100); for (Iterator<T> it = iterator(); it.hasNext();) { T val = it.next(); if (val != null) array.add(val); } return array.toArray(tArray); }
[ "public", "T", "[", "]", "toArray", "(", "T", "[", "]", "tArray", ")", "{", "List", "<", "T", ">", "array", "=", "new", "ArrayList", "<", "T", ">", "(", "100", ")", ";", "for", "(", "Iterator", "<", "T", ">", "it", "=", "iterator", "(", ")", ...
Returns an array of non null elements from the source array. @param tArray the source array @return the array
[ "Returns", "an", "array", "of", "non", "null", "elements", "from", "the", "source", "array", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedLinkedList.java#L125-L132
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java
ValueMapImpl.get
public Value get(Object key) { /* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */ if (map == null && items.length < 20) { for (Object item : items) { MapItemValue miv = (MapItemValue) item; if (key.equals(miv.name.toValue())) { return miv.value; } } return null; } else { if (map == null) buildIfNeededMap(); return map.get(key); } }
java
public Value get(Object key) { /* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */ if (map == null && items.length < 20) { for (Object item : items) { MapItemValue miv = (MapItemValue) item; if (key.equals(miv.name.toValue())) { return miv.value; } } return null; } else { if (map == null) buildIfNeededMap(); return map.get(key); } }
[ "public", "Value", "get", "(", "Object", "key", ")", "{", "/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */", "if", "(", "map", "==", "null", "&&", "items", ".", "length", "<", "20", ")", "{", "for", "(", "Ob...
Get the items for the key. @param key @return the items for the given key
[ "Get", "the", "items", "for", "the", "key", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java#L80-L94
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.unique
public static <T> Iterator<T> unique(Iterator<T> self) { return toList((Iterable<T>) unique(toList(self))).listIterator(); }
java
public static <T> Iterator<T> unique(Iterator<T> self) { return toList((Iterable<T>) unique(toList(self))).listIterator(); }
[ "public", "static", "<", "T", ">", "Iterator", "<", "T", ">", "unique", "(", "Iterator", "<", "T", ">", "self", ")", "{", "return", "toList", "(", "(", "Iterable", "<", "T", ">", ")", "unique", "(", "toList", "(", "self", ")", ")", ")", ".", "l...
Returns an iterator equivalent to this iterator with all duplicated items removed by using the default comparator. The original iterator will become exhausted of elements after determining the unique values. A new iterator for the unique values will be returned. @param self an Iterator @return the modified Iterator @since 1.5.5
[ "Returns", "an", "iterator", "equivalent", "to", "this", "iterator", "with", "all", "duplicated", "items", "removed", "by", "using", "the", "default", "comparator", ".", "The", "original", "iterator", "will", "become", "exhausted", "of", "elements", "after", "de...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L1014-L1016
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.numberAwareCompareTo
public static int numberAwareCompareTo(Comparable self, Comparable other) { NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>(); return numberAwareComparator.compare(self, other); }
java
public static int numberAwareCompareTo(Comparable self, Comparable other) { NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>(); return numberAwareComparator.compare(self, other); }
[ "public", "static", "int", "numberAwareCompareTo", "(", "Comparable", "self", ",", "Comparable", "other", ")", "{", "NumberAwareComparator", "<", "Comparable", ">", "numberAwareComparator", "=", "new", "NumberAwareComparator", "<", "Comparable", ">", "(", ")", ";", ...
Provides a method that compares two comparables using Groovy's default number aware comparator. @param self a Comparable @param other another Comparable @return a -ve number, 0 or a +ve number according to Groovy's compareTo contract @since 1.6.0
[ "Provides", "a", "method", "that", "compares", "two", "comparables", "using", "Groovy", "s", "default", "number", "aware", "comparator", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L1117-L1120
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.any
public static boolean any(Object self, Closure closure) { BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) { if (bcw.call(iter.next())) return true; } return false; }
java
public static boolean any(Object self, Closure closure) { BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) { if (bcw.call(iter.next())) return true; } return false; }
[ "public", "static", "boolean", "any", "(", "Object", "self", ",", "Closure", "closure", ")", "{", "BooleanClosureWrapper", "bcw", "=", "new", "BooleanClosureWrapper", "(", "closure", ")", ";", "for", "(", "Iterator", "iter", "=", "InvokerHelper", ".", "asItera...
Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element. @param self the object over which we iterate @param closure the closure predicate used for matching @return true if any iteration for the object matches the closure predicate @since 1.0
[ "Iterates", "over", "the", "contents", "of", "an", "object", "or", "collection", "and", "checks", "whether", "a", "predicate", "is", "valid", "for", "at", "least", "one", "element", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L2306-L2312
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.findResult
public static Object findResult(Object self, Object defaultResult, Closure closure) { Object result = findResult(self, closure); if (result == null) return defaultResult; return result; }
java
public static Object findResult(Object self, Object defaultResult, Closure closure) { Object result = findResult(self, closure); if (result == null) return defaultResult; return result; }
[ "public", "static", "Object", "findResult", "(", "Object", "self", ",", "Object", "defaultResult", ",", "Closure", "closure", ")", "{", "Object", "result", "=", "findResult", "(", "self", ",", "closure", ")", ";", "if", "(", "result", "==", "null", ")", ...
Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult. @param self an Object with an iterator returning its values @param defaultResult an Object that should be returned if all closure results are null @param closure a closure that returns a non-null value when processing should stop @return the first non-null result of the closure, otherwise the default value @since 1.7.5
[ "Treats", "the", "object", "as", "iterable", "iterating", "through", "the", "values", "it", "represents", "and", "returns", "the", "first", "non", "-", "null", "result", "obtained", "from", "calling", "the", "closure", "otherwise", "returns", "the", "defaultResu...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L3845-L3849
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.groupAnswer
protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) { if (answer.containsKey(value)) { answer.get(value).add(element); } else { List<T> groupedElements = new ArrayList<T>(); groupedElements.add(element); answer.put(value, groupedElements); } }
java
protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) { if (answer.containsKey(value)) { answer.get(value).add(element); } else { List<T> groupedElements = new ArrayList<T>(); groupedElements.add(element); answer.put(value, groupedElements); } }
[ "protected", "static", "<", "K", ",", "T", ">", "void", "groupAnswer", "(", "final", "Map", "<", "K", ",", "List", "<", "T", ">", ">", "answer", ",", "T", "element", ",", "K", "value", ")", "{", "if", "(", "answer", ".", "containsKey", "(", "valu...
Groups the current element according to the value @param answer the map containing the results @param element the element to be placed @param value the value according to which the element will be placed @since 1.5.0
[ "Groups", "the", "current", "element", "according", "to", "the", "value" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L5205-L5213
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.asImmutable
public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) { return Collections.unmodifiableMap(self); }
java
public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) { return Collections.unmodifiableMap(self); }
[ "public", "static", "<", "K", ",", "V", ">", "Map", "<", "K", ",", "V", ">", "asImmutable", "(", "Map", "<", "?", "extends", "K", ",", "?", "extends", "V", ">", "self", ")", "{", "return", "Collections", ".", "unmodifiableMap", "(", "self", ")", ...
A convenience method for creating an immutable map. @param self a Map @return an immutable Map @see java.util.Collections#unmodifiableMap(java.util.Map) @since 1.0
[ "A", "convenience", "method", "for", "creating", "an", "immutable", "map", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7493-L7495
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.asImmutable
public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) { return Collections.unmodifiableSortedMap(self); }
java
public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) { return Collections.unmodifiableSortedMap(self); }
[ "public", "static", "<", "K", ",", "V", ">", "SortedMap", "<", "K", ",", "V", ">", "asImmutable", "(", "SortedMap", "<", "K", ",", "?", "extends", "V", ">", "self", ")", "{", "return", "Collections", ".", "unmodifiableSortedMap", "(", "self", ")", ";...
A convenience method for creating an immutable sorted map. @param self a SortedMap @return an immutable SortedMap @see java.util.Collections#unmodifiableSortedMap(java.util.SortedMap) @since 1.0
[ "A", "convenience", "method", "for", "creating", "an", "immutable", "sorted", "map", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7505-L7507
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.asImmutable
public static <T> List<T> asImmutable(List<? extends T> self) { return Collections.unmodifiableList(self); }
java
public static <T> List<T> asImmutable(List<? extends T> self) { return Collections.unmodifiableList(self); }
[ "public", "static", "<", "T", ">", "List", "<", "T", ">", "asImmutable", "(", "List", "<", "?", "extends", "T", ">", "self", ")", "{", "return", "Collections", ".", "unmodifiableList", "(", "self", ")", ";", "}" ]
A convenience method for creating an immutable list @param self a List @return an immutable List @see java.util.Collections#unmodifiableList(java.util.List) @since 1.0
[ "A", "convenience", "method", "for", "creating", "an", "immutable", "list" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7517-L7519
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.asImmutable
public static <T> Set<T> asImmutable(Set<? extends T> self) { return Collections.unmodifiableSet(self); }
java
public static <T> Set<T> asImmutable(Set<? extends T> self) { return Collections.unmodifiableSet(self); }
[ "public", "static", "<", "T", ">", "Set", "<", "T", ">", "asImmutable", "(", "Set", "<", "?", "extends", "T", ">", "self", ")", "{", "return", "Collections", ".", "unmodifiableSet", "(", "self", ")", ";", "}" ]
A convenience method for creating an immutable list. @param self a Set @return an immutable Set @see java.util.Collections#unmodifiableSet(java.util.Set) @since 1.0
[ "A", "convenience", "method", "for", "creating", "an", "immutable", "list", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7529-L7531
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.asImmutable
public static <T> SortedSet<T> asImmutable(SortedSet<T> self) { return Collections.unmodifiableSortedSet(self); }
java
public static <T> SortedSet<T> asImmutable(SortedSet<T> self) { return Collections.unmodifiableSortedSet(self); }
[ "public", "static", "<", "T", ">", "SortedSet", "<", "T", ">", "asImmutable", "(", "SortedSet", "<", "T", ">", "self", ")", "{", "return", "Collections", ".", "unmodifiableSortedSet", "(", "self", ")", ";", "}" ]
A convenience method for creating an immutable sorted set. @param self a SortedSet @return an immutable SortedSet @see java.util.Collections#unmodifiableSortedSet(java.util.SortedSet) @since 1.0
[ "A", "convenience", "method", "for", "creating", "an", "immutable", "sorted", "set", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L7541-L7543
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.sort
public static <T> T[] sort(T[] self, Comparator<T> comparator) { return sort(self, true, comparator); }
java
public static <T> T[] sort(T[] self, Comparator<T> comparator) { return sort(self, true, comparator); }
[ "public", "static", "<", "T", ">", "T", "[", "]", "sort", "(", "T", "[", "]", "self", ",", "Comparator", "<", "T", ">", "comparator", ")", "{", "return", "sort", "(", "self", ",", "true", ",", "comparator", ")", ";", "}" ]
Sorts the given array into sorted order using the given comparator. @param self the array to be sorted @param comparator a Comparator used for the comparison @return the sorted array @since 1.5.5
[ "Sorts", "the", "given", "array", "into", "sorted", "order", "using", "the", "given", "comparator", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L8292-L8294
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.addAll
public static <T> boolean addAll(Collection<T> self, Iterator<T> items) { boolean changed = false; while (items.hasNext()) { T next = items.next(); if (self.add(next)) changed = true; } return changed; }
java
public static <T> boolean addAll(Collection<T> self, Iterator<T> items) { boolean changed = false; while (items.hasNext()) { T next = items.next(); if (self.add(next)) changed = true; } return changed; }
[ "public", "static", "<", "T", ">", "boolean", "addAll", "(", "Collection", "<", "T", ">", "self", ",", "Iterator", "<", "T", ">", "items", ")", "{", "boolean", "changed", "=", "false", ";", "while", "(", "items", ".", "hasNext", "(", ")", ")", "{",...
Adds all items from the iterator to the Collection. @param self the collection @param items the items to add @return true if the collection changed
[ "Adds", "all", "items", "from", "the", "iterator", "to", "the", "Collection", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L9371-L9378
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.addAll
public static <T> boolean addAll(Collection<T> self, Iterable<T> items) { boolean changed = false; for (T next : items) { if (self.add(next)) changed = true; } return changed; }
java
public static <T> boolean addAll(Collection<T> self, Iterable<T> items) { boolean changed = false; for (T next : items) { if (self.add(next)) changed = true; } return changed; }
[ "public", "static", "<", "T", ">", "boolean", "addAll", "(", "Collection", "<", "T", ">", "self", ",", "Iterable", "<", "T", ">", "items", ")", "{", "boolean", "changed", "=", "false", ";", "for", "(", "T", "next", ":", "items", ")", "{", "if", "...
Adds all items from the iterable to the Collection. @param self the collection @param items the items to add @return true if the collection changed
[ "Adds", "all", "items", "from", "the", "iterable", "to", "the", "Collection", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L9387-L9393
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.minus
public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) { final Map<K,V> ansMap = createSimilarMap(self); ansMap.putAll(self); if (removeMe != null && removeMe.size() > 0) { for (Map.Entry<K, V> e1 : self.entrySet()) { for (Object e2 : removeMe.entrySet()) { if (DefaultTypeTransformation.compareEqual(e1, e2)) { ansMap.remove(e1.getKey()); } } } } return ansMap; }
java
public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) { final Map<K,V> ansMap = createSimilarMap(self); ansMap.putAll(self); if (removeMe != null && removeMe.size() > 0) { for (Map.Entry<K, V> e1 : self.entrySet()) { for (Object e2 : removeMe.entrySet()) { if (DefaultTypeTransformation.compareEqual(e1, e2)) { ansMap.remove(e1.getKey()); } } } } return ansMap; }
[ "public", "static", "<", "K", ",", "V", ">", "Map", "<", "K", ",", "V", ">", "minus", "(", "Map", "<", "K", ",", "V", ">", "self", ",", "Map", "removeMe", ")", "{", "final", "Map", "<", "K", ",", "V", ">", "ansMap", "=", "createSimilarMap", "...
Create a Map composed of the entries of the first map minus the entries of the given map. @param self a map object @param removeMe the entries to remove from the map @return the resulting map @since 1.7.4
[ "Create", "a", "Map", "composed", "of", "the", "entries", "of", "the", "first", "map", "minus", "the", "entries", "of", "the", "given", "map", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L11931-L11944
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.findLastIndexOf
public static int findLastIndexOf(Object self, int startIndex, Closure closure) { int result = -1; int i = 0; BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) { Object value = iter.next(); if (i < startIndex) { continue; } if (bcw.call(value)) { result = i; } } return result; }
java
public static int findLastIndexOf(Object self, int startIndex, Closure closure) { int result = -1; int i = 0; BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) { Object value = iter.next(); if (i < startIndex) { continue; } if (bcw.call(value)) { result = i; } } return result; }
[ "public", "static", "int", "findLastIndexOf", "(", "Object", "self", ",", "int", "startIndex", ",", "Closure", "closure", ")", "{", "int", "result", "=", "-", "1", ";", "int", "i", "=", "0", ";", "BooleanClosureWrapper", "bcw", "=", "new", "BooleanClosureW...
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure. @param self the iteration object over which to iterate @param startIndex start matching from this index @param closure the filter to perform a match on the collection @return an integer that is the index of the last matched object or -1 if no match was found @since 1.5.2
[ "Iterates", "over", "the", "elements", "of", "an", "iterable", "collection", "of", "items", "starting", "from", "a", "specified", "startIndex", "and", "returns", "the", "index", "of", "the", "last", "item", "that", "matches", "the", "condition", "specified", "...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15414-L15428
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.findIndexValues
public static List<Number> findIndexValues(Object self, Closure closure) { return findIndexValues(self, 0, closure); }
java
public static List<Number> findIndexValues(Object self, Closure closure) { return findIndexValues(self, 0, closure); }
[ "public", "static", "List", "<", "Number", ">", "findIndexValues", "(", "Object", "self", ",", "Closure", "closure", ")", "{", "return", "findIndexValues", "(", "self", ",", "0", ",", "closure", ")", ";", "}" ]
Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure. @param self the iteration object over which to iterate @param closure the filter to perform a match on the collection @return a list of numbers corresponding to the index values of all matched objects @since 1.5.2
[ "Iterates", "over", "the", "elements", "of", "an", "iterable", "collection", "of", "items", "and", "returns", "the", "index", "values", "of", "the", "items", "that", "match", "the", "condition", "specified", "in", "the", "closure", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15439-L15441
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
DefaultGroovyMethods.findIndexValues
public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) { List<Number> result = new ArrayList<Number>(); long count = 0; long startCount = startIndex.longValue(); BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); count++) { Object value = iter.next(); if (count < startCount) { continue; } if (bcw.call(value)) { result.add(count); } } return result; }
java
public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) { List<Number> result = new ArrayList<Number>(); long count = 0; long startCount = startIndex.longValue(); BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); count++) { Object value = iter.next(); if (count < startCount) { continue; } if (bcw.call(value)) { result.add(count); } } return result; }
[ "public", "static", "List", "<", "Number", ">", "findIndexValues", "(", "Object", "self", ",", "Number", "startIndex", ",", "Closure", "closure", ")", "{", "List", "<", "Number", ">", "result", "=", "new", "ArrayList", "<", "Number", ">", "(", ")", ";", ...
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure. @param self the iteration object over which to iterate @param startIndex start matching from this index @param closure the filter to perform a match on the collection @return a list of numbers corresponding to the index values of all matched objects @since 1.5.2
[ "Iterates", "over", "the", "elements", "of", "an", "iterable", "collection", "of", "items", "starting", "from", "a", "specified", "startIndex", "and", "returns", "the", "index", "values", "of", "the", "items", "that", "match", "the", "condition", "specified", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L15454-L15469
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/HandleMetaClass.java
HandleMetaClass.getProperty
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || myMetaClass.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return myMetaClass.getProperty(this, property); }
java
public Object getProperty(String property) { if(ExpandoMetaClass.isValidExpandoProperty(property)) { if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) || property.equals(ExpandoMetaClass.CONSTRUCTOR) || myMetaClass.hasProperty(this, property) == null) { return replaceDelegate().getProperty(property); } } return myMetaClass.getProperty(this, property); }
[ "public", "Object", "getProperty", "(", "String", "property", ")", "{", "if", "(", "ExpandoMetaClass", ".", "isValidExpandoProperty", "(", "property", ")", ")", "{", "if", "(", "property", ".", "equals", "(", "ExpandoMetaClass", ".", "STATIC_QUALIFIER", ")", "...
this method mimics EMC behavior
[ "this", "method", "mimics", "EMC", "behavior" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/HandleMetaClass.java#L82-L91
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/messages/Message.java
Message.create
public static Message create( String text, Object data, ProcessingUnit owner ) { return new SimpleMessage( text, data, owner); }
java
public static Message create( String text, Object data, ProcessingUnit owner ) { return new SimpleMessage( text, data, owner); }
[ "public", "static", "Message", "create", "(", "String", "text", ",", "Object", "data", ",", "ProcessingUnit", "owner", ")", "{", "return", "new", "SimpleMessage", "(", "text", ",", "data", ",", "owner", ")", ";", "}" ]
Creates a new Message from the specified text.
[ "Creates", "a", "new", "Message", "from", "the", "specified", "text", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/messages/Message.java#L80-L83
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/JsonDelegate.java
JsonDelegate.invokeMethod
public Object invokeMethod(String name, Object args) { Object val = null; if (args != null && Object[].class.isAssignableFrom(args.getClass())) { Object[] arr = (Object[]) args; if (arr.length == 1) { val = arr[0]; } else if (arr.length == 2 && arr[0] instanceof Collection && arr[1] instanceof Closure) { Closure<?> closure = (Closure<?>) arr[1]; Iterator<?> iterator = ((Collection) arr[0]).iterator(); List<Object> list = new ArrayList<Object>(); while (iterator.hasNext()) { list.add(curryDelegateAndGetContent(closure, iterator.next())); } val = list; } else { val = Arrays.asList(arr); } } content.put(name, val); return val; }
java
public Object invokeMethod(String name, Object args) { Object val = null; if (args != null && Object[].class.isAssignableFrom(args.getClass())) { Object[] arr = (Object[]) args; if (arr.length == 1) { val = arr[0]; } else if (arr.length == 2 && arr[0] instanceof Collection && arr[1] instanceof Closure) { Closure<?> closure = (Closure<?>) arr[1]; Iterator<?> iterator = ((Collection) arr[0]).iterator(); List<Object> list = new ArrayList<Object>(); while (iterator.hasNext()) { list.add(curryDelegateAndGetContent(closure, iterator.next())); } val = list; } else { val = Arrays.asList(arr); } } content.put(name, val); return val; }
[ "public", "Object", "invokeMethod", "(", "String", "name", ",", "Object", "args", ")", "{", "Object", "val", "=", "null", ";", "if", "(", "args", "!=", "null", "&&", "Object", "[", "]", ".", "class", ".", "isAssignableFrom", "(", "args", ".", "getClass...
Intercepts calls for setting a key and value for a JSON object @param name the key name @param args the value associated with the key
[ "Intercepts", "calls", "for", "setting", "a", "key", "and", "value", "for", "a", "JSON", "object" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/JsonDelegate.java#L43-L65
train
groovy/groovy-core
src/main/groovy/lang/Binding.java
Binding.setVariable
public void setVariable(String name, Object value) { if (variables == null) variables = new LinkedHashMap(); variables.put(name, value); }
java
public void setVariable(String name, Object value) { if (variables == null) variables = new LinkedHashMap(); variables.put(name, value); }
[ "public", "void", "setVariable", "(", "String", "name", ",", "Object", "value", ")", "{", "if", "(", "variables", "==", "null", ")", "variables", "=", "new", "LinkedHashMap", "(", ")", ";", "variables", ".", "put", "(", "name", ",", "value", ")", ";", ...
Sets the value of the given variable @param name the name of the variable to set @param value the new value for the given variable
[ "Sets", "the", "value", "of", "the", "given", "variable" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/Binding.java#L76-L80
train
groovy/groovy-core
src/main/groovy/lang/MetaBeanProperty.java
MetaBeanProperty.getProperty
public Object getProperty(Object object) { MetaMethod getter = getGetter(); if (getter == null) { if (field != null) return field.getProperty(object); //TODO: create a WriteOnlyException class? throw new GroovyRuntimeException("Cannot read write-only property: " + name); } return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY); }
java
public Object getProperty(Object object) { MetaMethod getter = getGetter(); if (getter == null) { if (field != null) return field.getProperty(object); //TODO: create a WriteOnlyException class? throw new GroovyRuntimeException("Cannot read write-only property: " + name); } return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY); }
[ "public", "Object", "getProperty", "(", "Object", "object", ")", "{", "MetaMethod", "getter", "=", "getGetter", "(", ")", ";", "if", "(", "getter", "==", "null", ")", "{", "if", "(", "field", "!=", "null", ")", "return", "field", ".", "getProperty", "(...
Get the property of the given object. @param object which to be got @return the property of the given object @throws RuntimeException if the property could not be evaluated
[ "Get", "the", "property", "of", "the", "given", "object", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaBeanProperty.java#L56-L64
train
groovy/groovy-core
src/main/groovy/lang/MetaBeanProperty.java
MetaBeanProperty.setProperty
public void setProperty(Object object, Object newValue) { MetaMethod setter = getSetter(); if (setter == null) { if (field != null && !Modifier.isFinal(field.getModifiers())) { field.setProperty(object, newValue); return; } throw new GroovyRuntimeException("Cannot set read-only property: " + name); } newValue = DefaultTypeTransformation.castToType(newValue, getType()); setter.invoke(object, new Object[]{newValue}); }
java
public void setProperty(Object object, Object newValue) { MetaMethod setter = getSetter(); if (setter == null) { if (field != null && !Modifier.isFinal(field.getModifiers())) { field.setProperty(object, newValue); return; } throw new GroovyRuntimeException("Cannot set read-only property: " + name); } newValue = DefaultTypeTransformation.castToType(newValue, getType()); setter.invoke(object, new Object[]{newValue}); }
[ "public", "void", "setProperty", "(", "Object", "object", ",", "Object", "newValue", ")", "{", "MetaMethod", "setter", "=", "getSetter", "(", ")", ";", "if", "(", "setter", "==", "null", ")", "{", "if", "(", "field", "!=", "null", "&&", "!", "Modifier"...
Set the property on the given object to the new value. @param object on which to set the property @param newValue the new value of the property @throws RuntimeException if the property could not be set
[ "Set", "the", "property", "on", "the", "given", "object", "to", "the", "new", "value", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaBeanProperty.java#L73-L84
train
groovy/groovy-core
src/main/groovy/lang/MetaBeanProperty.java
MetaBeanProperty.getModifiers
public int getModifiers() { MetaMethod getter = getGetter(); MetaMethod setter = getSetter(); if (setter != null && getter == null) return setter.getModifiers(); if (getter != null && setter == null) return getter.getModifiers(); int modifiers = getter.getModifiers() | setter.getModifiers(); int visibility = 0; if (Modifier.isPublic(modifiers)) visibility = Modifier.PUBLIC; if (Modifier.isProtected(modifiers)) visibility = Modifier.PROTECTED; if (Modifier.isPrivate(modifiers)) visibility = Modifier.PRIVATE; int states = getter.getModifiers() & setter.getModifiers(); states &= ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE); states |= visibility; return states; }
java
public int getModifiers() { MetaMethod getter = getGetter(); MetaMethod setter = getSetter(); if (setter != null && getter == null) return setter.getModifiers(); if (getter != null && setter == null) return getter.getModifiers(); int modifiers = getter.getModifiers() | setter.getModifiers(); int visibility = 0; if (Modifier.isPublic(modifiers)) visibility = Modifier.PUBLIC; if (Modifier.isProtected(modifiers)) visibility = Modifier.PROTECTED; if (Modifier.isPrivate(modifiers)) visibility = Modifier.PRIVATE; int states = getter.getModifiers() & setter.getModifiers(); states &= ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE); states |= visibility; return states; }
[ "public", "int", "getModifiers", "(", ")", "{", "MetaMethod", "getter", "=", "getGetter", "(", ")", ";", "MetaMethod", "setter", "=", "getSetter", "(", ")", ";", "if", "(", "setter", "!=", "null", "&&", "getter", "==", "null", ")", "return", "setter", ...
Gets the visibility modifiers for the property as defined by the getter and setter methods. @return the visibility modifer of the getter, the setter, or both depending on which exist
[ "Gets", "the", "visibility", "modifiers", "for", "the", "property", "as", "defined", "by", "the", "getter", "and", "setter", "methods", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaBeanProperty.java#L127-L141
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/trait/Traits.java
Traits.isTrait
public static boolean isTrait(final ClassNode cNode) { return cNode!=null && ((cNode.isInterface() && !cNode.getAnnotations(TRAIT_CLASSNODE).isEmpty()) || isAnnotatedWithTrait(cNode)); }
java
public static boolean isTrait(final ClassNode cNode) { return cNode!=null && ((cNode.isInterface() && !cNode.getAnnotations(TRAIT_CLASSNODE).isEmpty()) || isAnnotatedWithTrait(cNode)); }
[ "public", "static", "boolean", "isTrait", "(", "final", "ClassNode", "cNode", ")", "{", "return", "cNode", "!=", "null", "&&", "(", "(", "cNode", ".", "isInterface", "(", ")", "&&", "!", "cNode", ".", "getAnnotations", "(", "TRAIT_CLASSNODE", ")", ".", "...
Returns true if the specified class node is a trait. @param cNode a class node to test @return true if the classnode represents a trait
[ "Returns", "true", "if", "the", "specified", "class", "node", "is", "a", "trait", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/trait/Traits.java#L149-L153
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/trait/Traits.java
Traits.getBridgeMethodTarget
public static Method getBridgeMethodTarget(Method someMethod) { TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class); if (annotation==null) { return null; } Class aClass = annotation.traitClass(); String desc = annotation.desc(); for (Method method : aClass.getDeclaredMethods()) { String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameterTypes()); if (desc.equals(methodDescriptor)) { return method; } } return null; }
java
public static Method getBridgeMethodTarget(Method someMethod) { TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class); if (annotation==null) { return null; } Class aClass = annotation.traitClass(); String desc = annotation.desc(); for (Method method : aClass.getDeclaredMethods()) { String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameterTypes()); if (desc.equals(methodDescriptor)) { return method; } } return null; }
[ "public", "static", "Method", "getBridgeMethodTarget", "(", "Method", "someMethod", ")", "{", "TraitBridge", "annotation", "=", "someMethod", ".", "getAnnotation", "(", "TraitBridge", ".", "class", ")", ";", "if", "(", "annotation", "==", "null", ")", "{", "re...
Reflection API to find the method corresponding to the default implementation of a trait, given a bridge method. @param someMethod a method node @return null if it is not a method implemented in a trait. If it is, returns the method from the trait class.
[ "Reflection", "API", "to", "find", "the", "method", "corresponding", "to", "the", "default", "implementation", "of", "a", "trait", "given", "a", "bridge", "method", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/trait/Traits.java#L209-L223
train