id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
12,800
apache/groovy
subprojects/groovy-swing/src/main/java/org/codehaus/groovy/runtime/SwingGroovyMethods.java
SwingGroovyMethods.setMnemonic
public static void setMnemonic(AbstractButton button, String mnemonic) { char c = ShortTypeHandling.castToChar(mnemonic); button.setMnemonic(c); }
java
public static void setMnemonic(AbstractButton button, String mnemonic) { char c = ShortTypeHandling.castToChar(mnemonic); button.setMnemonic(c); }
[ "public", "static", "void", "setMnemonic", "(", "AbstractButton", "button", ",", "String", "mnemonic", ")", "{", "char", "c", "=", "ShortTypeHandling", ".", "castToChar", "(", "mnemonic", ")", ";", "button", ".", "setMnemonic", "(", "c", ")", ";", "}" ]
Allows the usage of a one-element string for a mnemonic @param button a AbstractButton @param mnemonic the String @since 2.3.7
[ "Allows", "the", "usage", "of", "a", "one", "-", "element", "string", "for", "a", "mnemonic" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/runtime/SwingGroovyMethods.java#L1058-L1061
12,801
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
TraitASTTransformation.copyClassAnnotations
private static void copyClassAnnotations(final ClassNode cNode, final ClassNode helper) { List<AnnotationNode> annotations = cNode.getAnnotations(); for (AnnotationNode annotation : annotations) { if (!annotation.getClassNode().equals(Traits.TRAIT_CLASSNODE)) { helper.addAnnotation(annotation); } } }
java
private static void copyClassAnnotations(final ClassNode cNode, final ClassNode helper) { List<AnnotationNode> annotations = cNode.getAnnotations(); for (AnnotationNode annotation : annotations) { if (!annotation.getClassNode().equals(Traits.TRAIT_CLASSNODE)) { helper.addAnnotation(annotation); } } }
[ "private", "static", "void", "copyClassAnnotations", "(", "final", "ClassNode", "cNode", ",", "final", "ClassNode", "helper", ")", "{", "List", "<", "AnnotationNode", ">", "annotations", "=", "cNode", ".", "getAnnotations", "(", ")", ";", "for", "(", "AnnotationNode", "annotation", ":", "annotations", ")", "{", "if", "(", "!", "annotation", ".", "getClassNode", "(", ")", ".", "equals", "(", "Traits", ".", "TRAIT_CLASSNODE", ")", ")", "{", "helper", ".", "addAnnotation", "(", "annotation", ")", ";", "}", "}", "}" ]
Copies annotation from the trait to the helper, excluding the trait annotation itself @param cNode the trait class node @param helper the helper class node
[ "Copies", "annotation", "from", "the", "trait", "to", "the", "helper", "excluding", "the", "trait", "annotation", "itself" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java#L364-L371
12,802
apache/groovy
subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java
DataSet.each
public void each(@ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(getSql(), getParameters(), closure); }
java
public void each(@ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(getSql(), getParameters(), closure); }
[ "public", "void", "each", "(", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"groovy.sql.GroovyResultSet\"", ")", "Closure", "closure", ")", "throws", "SQLException", "{", "eachRow", "(", "getSql", "(", ")", ",", "getParameters", "(", ")", ",", "closure", ")", ";", "}" ]
Calls the provided closure for each of the rows of the table represented by this DataSet. @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, groovy.lang.Closure)
[ "Calls", "the", "provided", "closure", "for", "each", "of", "the", "rows", "of", "the", "table", "represented", "by", "this", "DataSet", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L338-L340
12,803
apache/groovy
subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java
DataSet.rows
public List rows(int offset, int maxRows) throws SQLException { return rows(getSql(), getParameters(), offset, maxRows); }
java
public List rows(int offset, int maxRows) throws SQLException { return rows(getSql(), getParameters(), offset, maxRows); }
[ "public", "List", "rows", "(", "int", "offset", ",", "int", "maxRows", ")", "throws", "SQLException", "{", "return", "rows", "(", "getSql", "(", ")", ",", "getParameters", "(", ")", ",", "offset", ",", "maxRows", ")", ";", "}" ]
Returns a "page" of the rows from the table a DataSet represents. 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 @return a list of GroovyRowResult objects from the dataset @throws SQLException if a database error occurs
[ "Returns", "a", "page", "of", "the", "rows", "from", "the", "table", "a", "DataSet", "represents", ".", "A", "page", "is", "defined", "as", "starting", "at", "a", "1", "-", "based", "offset", "and", "containing", "a", "maximum", "number", "of", "rows", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L479-L481
12,804
apache/groovy
subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java
DataSet.firstRow
public Object firstRow() throws SQLException { List rows = rows(); if (rows.isEmpty()) return null; return (rows.get(0)); }
java
public Object firstRow() throws SQLException { List rows = rows(); if (rows.isEmpty()) return null; return (rows.get(0)); }
[ "public", "Object", "firstRow", "(", ")", "throws", "SQLException", "{", "List", "rows", "=", "rows", "(", ")", ";", "if", "(", "rows", ".", "isEmpty", "(", ")", ")", "return", "null", ";", "return", "(", "rows", ".", "get", "(", "0", ")", ")", ";", "}" ]
Returns the first row from a DataSet's underlying table @return Returns the first GroovyRowResult object from the dataset @throws SQLException if a database error occurs
[ "Returns", "the", "first", "row", "from", "a", "DataSet", "s", "underlying", "table" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/DataSet.java#L489-L493
12,805
apache/groovy
src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
AnnotationCollectorTransform.addError
protected void addError(String message, ASTNode node, SourceUnit source) { source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException( message, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber() ), source)); }
java
protected void addError(String message, ASTNode node, SourceUnit source) { source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException( message, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber() ), source)); }
[ "protected", "void", "addError", "(", "String", "message", ",", "ASTNode", "node", ",", "SourceUnit", "source", ")", "{", "source", ".", "getErrorCollector", "(", ")", ".", "addErrorAndContinue", "(", "new", "SyntaxErrorMessage", "(", "new", "SyntaxException", "(", "message", ",", "node", ".", "getLineNumber", "(", ")", ",", "node", ".", "getColumnNumber", "(", ")", ",", "node", ".", "getLastLineNumber", "(", ")", ",", "node", ".", "getLastColumnNumber", "(", ")", ")", ",", "source", ")", ")", ";", "}" ]
Adds a new syntax error to the source unit and then continues. @param message the message @param node the node for the error report @param source the source unit for the error report
[ "Adds", "a", "new", "syntax", "error", "to", "the", "source", "unit", "and", "then", "continues", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java#L196-L200
12,806
apache/groovy
src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
AnnotationCollectorTransform.getSerializeClass
private static ClassNode getSerializeClass(ClassNode alias) { List<AnnotationNode> annotations = alias.getAnnotations(ClassHelper.make(AnnotationCollector.class)); if (!annotations.isEmpty()) { AnnotationNode annotationNode = annotations.get(0); Expression member = annotationNode.getMember("serializeClass"); if (member instanceof ClassExpression) { ClassExpression ce = (ClassExpression) member; if (!ce.getType().getName().equals(AnnotationCollector.class.getName())) { alias = ce.getType(); } } } return alias; }
java
private static ClassNode getSerializeClass(ClassNode alias) { List<AnnotationNode> annotations = alias.getAnnotations(ClassHelper.make(AnnotationCollector.class)); if (!annotations.isEmpty()) { AnnotationNode annotationNode = annotations.get(0); Expression member = annotationNode.getMember("serializeClass"); if (member instanceof ClassExpression) { ClassExpression ce = (ClassExpression) member; if (!ce.getType().getName().equals(AnnotationCollector.class.getName())) { alias = ce.getType(); } } } return alias; }
[ "private", "static", "ClassNode", "getSerializeClass", "(", "ClassNode", "alias", ")", "{", "List", "<", "AnnotationNode", ">", "annotations", "=", "alias", ".", "getAnnotations", "(", "ClassHelper", ".", "make", "(", "AnnotationCollector", ".", "class", ")", ")", ";", "if", "(", "!", "annotations", ".", "isEmpty", "(", ")", ")", "{", "AnnotationNode", "annotationNode", "=", "annotations", ".", "get", "(", "0", ")", ";", "Expression", "member", "=", "annotationNode", ".", "getMember", "(", "\"serializeClass\"", ")", ";", "if", "(", "member", "instanceof", "ClassExpression", ")", "{", "ClassExpression", "ce", "=", "(", "ClassExpression", ")", "member", ";", "if", "(", "!", "ce", ".", "getType", "(", ")", ".", "getName", "(", ")", ".", "equals", "(", "AnnotationCollector", ".", "class", ".", "getName", "(", ")", ")", ")", "{", "alias", "=", "ce", ".", "getType", "(", ")", ";", "}", "}", "}", "return", "alias", ";", "}" ]
2.5.3 and above gets from annotation attribute otherwise self
[ "2", ".", "5", ".", "3", "and", "above", "gets", "from", "annotation", "attribute", "otherwise", "self" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java#L284-L297
12,807
apache/groovy
src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
AnnotationCollectorTransform.getTargetAnnotationList
protected List<AnnotationNode> getTargetAnnotationList(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, SourceUnit source) { List<AnnotationNode> stored = getStoredTargetList(aliasAnnotationUsage, source); List<AnnotationNode> targetList = getTargetListFromValue(collector, aliasAnnotationUsage, source); int size = targetList.size()+stored.size(); if (size == 0) { return Collections.emptyList(); } List<AnnotationNode> ret = new ArrayList<AnnotationNode>(size); ret.addAll(stored); ret.addAll(targetList); return ret; }
java
protected List<AnnotationNode> getTargetAnnotationList(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, SourceUnit source) { List<AnnotationNode> stored = getStoredTargetList(aliasAnnotationUsage, source); List<AnnotationNode> targetList = getTargetListFromValue(collector, aliasAnnotationUsage, source); int size = targetList.size()+stored.size(); if (size == 0) { return Collections.emptyList(); } List<AnnotationNode> ret = new ArrayList<AnnotationNode>(size); ret.addAll(stored); ret.addAll(targetList); return ret; }
[ "protected", "List", "<", "AnnotationNode", ">", "getTargetAnnotationList", "(", "AnnotationNode", "collector", ",", "AnnotationNode", "aliasAnnotationUsage", ",", "SourceUnit", "source", ")", "{", "List", "<", "AnnotationNode", ">", "stored", "=", "getStoredTargetList", "(", "aliasAnnotationUsage", ",", "source", ")", ";", "List", "<", "AnnotationNode", ">", "targetList", "=", "getTargetListFromValue", "(", "collector", ",", "aliasAnnotationUsage", ",", "source", ")", ";", "int", "size", "=", "targetList", ".", "size", "(", ")", "+", "stored", ".", "size", "(", ")", ";", "if", "(", "size", "==", "0", ")", "{", "return", "Collections", ".", "emptyList", "(", ")", ";", "}", "List", "<", "AnnotationNode", ">", "ret", "=", "new", "ArrayList", "<", "AnnotationNode", ">", "(", "size", ")", ";", "ret", ".", "addAll", "(", "stored", ")", ";", "ret", ".", "addAll", "(", "targetList", ")", ";", "return", "ret", ";", "}" ]
Returns a list of AnnotationNodes for the value attribute of the given AnnotationNode. @param collector the node containing the value member with the list @param source the source unit for error reporting @return a list of string constants
[ "Returns", "a", "list", "of", "AnnotationNodes", "for", "the", "value", "attribute", "of", "the", "given", "AnnotationNode", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java#L354-L366
12,808
apache/groovy
src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
AnnotationCollectorTransform.visit
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) { List<AnnotationNode> ret = getTargetAnnotationList(collector, aliasAnnotationUsage, source); Set<String> unusedNames = new HashSet<String>(aliasAnnotationUsage.getMembers().keySet()); for (AnnotationNode an: ret) { for (String name : aliasAnnotationUsage.getMembers().keySet()) { if (an.getClassNode().hasMethod(name, Parameter.EMPTY_ARRAY)) { unusedNames.remove(name); an.setMember(name, aliasAnnotationUsage.getMember(name)); } } } if (!unusedNames.isEmpty()) { String message = "Annotation collector got unmapped names "+unusedNames.toString()+"."; addError(message, aliasAnnotationUsage, source); } return ret; }
java
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) { List<AnnotationNode> ret = getTargetAnnotationList(collector, aliasAnnotationUsage, source); Set<String> unusedNames = new HashSet<String>(aliasAnnotationUsage.getMembers().keySet()); for (AnnotationNode an: ret) { for (String name : aliasAnnotationUsage.getMembers().keySet()) { if (an.getClassNode().hasMethod(name, Parameter.EMPTY_ARRAY)) { unusedNames.remove(name); an.setMember(name, aliasAnnotationUsage.getMember(name)); } } } if (!unusedNames.isEmpty()) { String message = "Annotation collector got unmapped names "+unusedNames.toString()+"."; addError(message, aliasAnnotationUsage, source); } return ret; }
[ "public", "List", "<", "AnnotationNode", ">", "visit", "(", "AnnotationNode", "collector", ",", "AnnotationNode", "aliasAnnotationUsage", ",", "AnnotatedNode", "aliasAnnotated", ",", "SourceUnit", "source", ")", "{", "List", "<", "AnnotationNode", ">", "ret", "=", "getTargetAnnotationList", "(", "collector", ",", "aliasAnnotationUsage", ",", "source", ")", ";", "Set", "<", "String", ">", "unusedNames", "=", "new", "HashSet", "<", "String", ">", "(", "aliasAnnotationUsage", ".", "getMembers", "(", ")", ".", "keySet", "(", ")", ")", ";", "for", "(", "AnnotationNode", "an", ":", "ret", ")", "{", "for", "(", "String", "name", ":", "aliasAnnotationUsage", ".", "getMembers", "(", ")", ".", "keySet", "(", ")", ")", "{", "if", "(", "an", ".", "getClassNode", "(", ")", ".", "hasMethod", "(", "name", ",", "Parameter", ".", "EMPTY_ARRAY", ")", ")", "{", "unusedNames", ".", "remove", "(", "name", ")", ";", "an", ".", "setMember", "(", "name", ",", "aliasAnnotationUsage", ".", "getMember", "(", "name", ")", ")", ";", "}", "}", "}", "if", "(", "!", "unusedNames", ".", "isEmpty", "(", ")", ")", "{", "String", "message", "=", "\"Annotation collector got unmapped names \"", "+", "unusedNames", ".", "toString", "(", ")", "+", "\".\"", ";", "addError", "(", "message", ",", "aliasAnnotationUsage", ",", "source", ")", ";", "}", "return", "ret", ";", "}" ]
Implementation method of the alias annotation processor. This method will get the list of annotations we aliased from the collector and adds it to aliasAnnotationUsage. The method will also map all members from aliasAnnotationUsage to the aliased nodes. Should a member stay unmapped, we will ad an error. Further processing of those members is done by the annotations. @param collector reference to the annotation with {@link AnnotationCollector} @param aliasAnnotationUsage reference to the place of usage of the alias @param aliasAnnotated reference to the node that has been annotated by the alias @param source source unit for error reporting @return list of the new AnnotationNodes
[ "Implementation", "method", "of", "the", "alias", "annotation", "processor", ".", "This", "method", "will", "get", "the", "list", "of", "annotations", "we", "aliased", "from", "the", "collector", "and", "adds", "it", "to", "aliasAnnotationUsage", ".", "The", "method", "will", "also", "map", "all", "members", "from", "aliasAnnotationUsage", "to", "the", "aliased", "nodes", ".", "Should", "a", "member", "stay", "unmapped", "we", "will", "ad", "an", "error", ".", "Further", "processing", "of", "those", "members", "is", "done", "by", "the", "annotations", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java#L382-L401
12,809
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/Attribute.java
Attribute.namespaceURI
public String namespaceURI() { if (namespacePrefix == null || namespacePrefix.isEmpty()) return ""; String uri = namespaceTagHints.get(namespacePrefix); return uri == null ? "" : uri; }
java
public String namespaceURI() { if (namespacePrefix == null || namespacePrefix.isEmpty()) return ""; String uri = namespaceTagHints.get(namespacePrefix); return uri == null ? "" : uri; }
[ "public", "String", "namespaceURI", "(", ")", "{", "if", "(", "namespacePrefix", "==", "null", "||", "namespacePrefix", ".", "isEmpty", "(", ")", ")", "return", "\"\"", ";", "String", "uri", "=", "namespaceTagHints", ".", "get", "(", "namespacePrefix", ")", ";", "return", "uri", "==", "null", "?", "\"\"", ":", "uri", ";", "}" ]
Returns the URI of the namespace of this Attribute. @return the namespace of this Attribute
[ "Returns", "the", "URI", "of", "the", "namespace", "of", "this", "Attribute", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/Attribute.java#L74-L78
12,810
apache/groovy
src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java
Weighers.asEntryWeigher
public static <K, V> EntryWeigher<K, V> asEntryWeigher( final Weigher<? super V> weigher) { return (weigher == singleton()) ? Weighers.<K, V>entrySingleton() : new EntryWeigherView<K, V>(weigher); }
java
public static <K, V> EntryWeigher<K, V> asEntryWeigher( final Weigher<? super V> weigher) { return (weigher == singleton()) ? Weighers.<K, V>entrySingleton() : new EntryWeigherView<K, V>(weigher); }
[ "public", "static", "<", "K", ",", "V", ">", "EntryWeigher", "<", "K", ",", "V", ">", "asEntryWeigher", "(", "final", "Weigher", "<", "?", "super", "V", ">", "weigher", ")", "{", "return", "(", "weigher", "==", "singleton", "(", ")", ")", "?", "Weighers", ".", "<", "K", ",", "V", ">", "entrySingleton", "(", ")", ":", "new", "EntryWeigherView", "<", "K", ",", "V", ">", "(", "weigher", ")", ";", "}" ]
A entry weigher backed by the specified weigher. The weight of the value determines the weight of the entry. @param weigher the weigher to be "wrapped" in a entry weigher. @return A entry weigher view of the specified weigher.
[ "A", "entry", "weigher", "backed", "by", "the", "specified", "weigher", ".", "The", "weight", "of", "the", "value", "determines", "the", "weight", "of", "the", "entry", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java#L46-L51
12,811
apache/groovy
src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java
ReturnAdder.addReturnIfNeeded
@Deprecated public static void addReturnIfNeeded(MethodNode node) { ReturnAdder adder = new ReturnAdder(); adder.visitMethod(node); }
java
@Deprecated public static void addReturnIfNeeded(MethodNode node) { ReturnAdder adder = new ReturnAdder(); adder.visitMethod(node); }
[ "@", "Deprecated", "public", "static", "void", "addReturnIfNeeded", "(", "MethodNode", "node", ")", "{", "ReturnAdder", "adder", "=", "new", "ReturnAdder", "(", ")", ";", "adder", ".", "visitMethod", "(", "node", ")", ";", "}" ]
Adds return statements in method code whenever an implicit return is detected. @param node the method node where to add return statements @deprecated Use {@link #visitMethod(org.codehaus.groovy.ast.MethodNode)} instead
[ "Adds", "return", "statements", "in", "method", "code", "whenever", "an", "implicit", "return", "is", "detected", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java#L77-L81
12,812
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/LRUProtectionStorage.java
LRUProtectionStorage.touch
public synchronized void touch(final Object key, final Object value) { remove(key); put(key, value); }
java
public synchronized void touch(final Object key, final Object value) { remove(key); put(key, value); }
[ "public", "synchronized", "void", "touch", "(", "final", "Object", "key", ",", "final", "Object", "value", ")", "{", "remove", "(", "key", ")", ";", "put", "(", "key", ",", "value", ")", ";", "}" ]
The touch method can be used to renew an element and move it to the from of the LRU queue. @param key The key of the element to renew @param value A value to newly associate with the key
[ "The", "touch", "method", "can", "be", "used", "to", "renew", "an", "element", "and", "move", "it", "to", "the", "from", "of", "the", "LRU", "queue", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/LRUProtectionStorage.java#L53-L56
12,813
apache/groovy
src/main/java/org/codehaus/groovy/runtime/memoize/LRUProtectionStorage.java
LRUProtectionStorage.get
@Override public synchronized Object get(final Object key) { final Object value = remove(key); if (value != null) put(key, value); return value; }
java
@Override public synchronized Object get(final Object key) { final Object value = remove(key); if (value != null) put(key, value); return value; }
[ "@", "Override", "public", "synchronized", "Object", "get", "(", "final", "Object", "key", ")", "{", "final", "Object", "value", "=", "remove", "(", "key", ")", ";", "if", "(", "value", "!=", "null", ")", "put", "(", "key", ",", "value", ")", ";", "return", "value", ";", "}" ]
Makes sure the retrieved object is moved to the head of the LRU list
[ "Makes", "sure", "the", "retrieved", "object", "is", "moved", "to", "the", "head", "of", "the", "LRU", "list" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/memoize/LRUProtectionStorage.java#L61-L66
12,814
apache/groovy
src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
ReflectionUtils.getCallingClass
public static Class getCallingClass(int matchLevel, Collection<String> extraIgnoredPackages) { Class[] classContext = HELPER.getClassContext(); int depth = 0; try { Class c; // this super class stuff is for Java 1.4 support only // it isn't needed on a 5.0 VM Class sc; do { do { c = classContext[depth++]; if (c != null) { sc = c.getSuperclass(); } else { sc = null; } } while (classShouldBeIgnored(c, extraIgnoredPackages) || superClassShouldBeIgnored(sc)); } while (c != null && matchLevel-- > 0 && depth<classContext.length); return c; } catch (Throwable t) { return null; } }
java
public static Class getCallingClass(int matchLevel, Collection<String> extraIgnoredPackages) { Class[] classContext = HELPER.getClassContext(); int depth = 0; try { Class c; // this super class stuff is for Java 1.4 support only // it isn't needed on a 5.0 VM Class sc; do { do { c = classContext[depth++]; if (c != null) { sc = c.getSuperclass(); } else { sc = null; } } while (classShouldBeIgnored(c, extraIgnoredPackages) || superClassShouldBeIgnored(sc)); } while (c != null && matchLevel-- > 0 && depth<classContext.length); return c; } catch (Throwable t) { return null; } }
[ "public", "static", "Class", "getCallingClass", "(", "int", "matchLevel", ",", "Collection", "<", "String", ">", "extraIgnoredPackages", ")", "{", "Class", "[", "]", "classContext", "=", "HELPER", ".", "getClassContext", "(", ")", ";", "int", "depth", "=", "0", ";", "try", "{", "Class", "c", ";", "// this super class stuff is for Java 1.4 support only", "// it isn't needed on a 5.0 VM", "Class", "sc", ";", "do", "{", "do", "{", "c", "=", "classContext", "[", "depth", "++", "]", ";", "if", "(", "c", "!=", "null", ")", "{", "sc", "=", "c", ".", "getSuperclass", "(", ")", ";", "}", "else", "{", "sc", "=", "null", ";", "}", "}", "while", "(", "classShouldBeIgnored", "(", "c", ",", "extraIgnoredPackages", ")", "||", "superClassShouldBeIgnored", "(", "sc", ")", ")", ";", "}", "while", "(", "c", "!=", "null", "&&", "matchLevel", "--", ">", "0", "&&", "depth", "<", "classContext", ".", "length", ")", ";", "return", "c", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "return", "null", ";", "}", "}" ]
Get the called that is matchLevel stack frames before the call, ignoring MOP frames and desired exclude packages. @param matchLevel how may call stacks down to look. If it is less than 1 it is treated as though it was 1. @param extraIgnoredPackages A collection of string names of packages to exclude in addition to the MOP packages when counting stack frames. @return The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel
[ "Get", "the", "called", "that", "is", "matchLevel", "stack", "frames", "before", "the", "call", "ignoring", "MOP", "frames", "and", "desired", "exclude", "packages", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java#L97-L121
12,815
apache/groovy
src/main/java/org/codehaus/groovy/syntax/CSTNode.java
CSTNode.isOneOf
public boolean isOneOf(int[] types) { int meaning = getMeaning(); for (int i = 0; i < types.length; i++) { if (Types.ofType(meaning, types[i])) { return true; } } return false; }
java
public boolean isOneOf(int[] types) { int meaning = getMeaning(); for (int i = 0; i < types.length; i++) { if (Types.ofType(meaning, types[i])) { return true; } } return false; }
[ "public", "boolean", "isOneOf", "(", "int", "[", "]", "types", ")", "{", "int", "meaning", "=", "getMeaning", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "types", ".", "length", ";", "i", "++", ")", "{", "if", "(", "Types", ".", "ofType", "(", "meaning", ",", "types", "[", "i", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true if the node's meaning matches any of the specified types.
[ "Returns", "true", "if", "the", "node", "s", "meaning", "matches", "any", "of", "the", "specified", "types", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/CSTNode.java#L86-L95
12,816
apache/groovy
src/main/java/org/codehaus/groovy/syntax/CSTNode.java
CSTNode.getMeaningAs
public int getMeaningAs(int[] types) { for (int i = 0; i < types.length; i++) { if (isA(types[i])) { return types[i]; } } return Types.UNKNOWN; }
java
public int getMeaningAs(int[] types) { for (int i = 0; i < types.length; i++) { if (isA(types[i])) { return types[i]; } } return Types.UNKNOWN; }
[ "public", "int", "getMeaningAs", "(", "int", "[", "]", "types", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "types", ".", "length", ";", "i", "++", ")", "{", "if", "(", "isA", "(", "types", "[", "i", "]", ")", ")", "{", "return", "types", "[", "i", "]", ";", "}", "}", "return", "Types", ".", "UNKNOWN", ";", "}" ]
Returns the first matching meaning of the specified types. Returns Types.UNKNOWN if there are no matches.
[ "Returns", "the", "first", "matching", "meaning", "of", "the", "specified", "types", ".", "Returns", "Types", ".", "UNKNOWN", "if", "there", "are", "no", "matches", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/CSTNode.java#L115-L124
12,817
apache/groovy
src/main/java/org/codehaus/groovy/syntax/CSTNode.java
CSTNode.matches
boolean matches(int type, int child1, int child2) { return matches(type, child1) && get(2, true).isA(child2); }
java
boolean matches(int type, int child1, int child2) { return matches(type, child1) && get(2, true).isA(child2); }
[ "boolean", "matches", "(", "int", "type", ",", "int", "child1", ",", "int", "child2", ")", "{", "return", "matches", "(", "type", ",", "child1", ")", "&&", "get", "(", "2", ",", "true", ")", ".", "isA", "(", "child2", ")", ";", "}" ]
Returns true if the node and it's first and second child match the specified types. Missing nodes are Token.NULL.
[ "Returns", "true", "if", "the", "node", "and", "it", "s", "first", "and", "second", "child", "match", "the", "specified", "types", ".", "Missing", "nodes", "are", "Token", ".", "NULL", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/CSTNode.java#L149-L151
12,818
apache/groovy
src/main/java/org/codehaus/groovy/syntax/CSTNode.java
CSTNode.getRoot
public Token getRoot(boolean safe) { Token root = getRoot(); if (root == null && safe) { root = Token.NULL; } return root; }
java
public Token getRoot(boolean safe) { Token root = getRoot(); if (root == null && safe) { root = Token.NULL; } return root; }
[ "public", "Token", "getRoot", "(", "boolean", "safe", ")", "{", "Token", "root", "=", "getRoot", "(", ")", ";", "if", "(", "root", "==", "null", "&&", "safe", ")", "{", "root", "=", "Token", ".", "NULL", ";", "}", "return", "root", ";", "}" ]
Returns the root of the node, the Token that indicates it's type. Returns a Token.NULL if safe and the actual root is null.
[ "Returns", "the", "root", "of", "the", "node", "the", "Token", "that", "indicates", "it", "s", "type", ".", "Returns", "a", "Token", ".", "NULL", "if", "safe", "and", "the", "actual", "root", "is", "null", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/CSTNode.java#L232-L240
12,819
apache/groovy
src/main/java/org/codehaus/groovy/syntax/CSTNode.java
CSTNode.addChildrenOf
public void addChildrenOf(CSTNode of) { for (int i = 1; i < of.size(); i++) { add(of.get(i)); } }
java
public void addChildrenOf(CSTNode of) { for (int i = 1; i < of.size(); i++) { add(of.get(i)); } }
[ "public", "void", "addChildrenOf", "(", "CSTNode", "of", ")", "{", "for", "(", "int", "i", "=", "1", ";", "i", "<", "of", ".", "size", "(", ")", ";", "i", "++", ")", "{", "add", "(", "of", ".", "get", "(", "i", ")", ")", ";", "}", "}" ]
Adds all children of the specified node to this one. Not all nodes support this operation!
[ "Adds", "all", "children", "of", "the", "specified", "node", "to", "this", "one", ".", "Not", "all", "nodes", "support", "this", "operation!" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/CSTNode.java#L304-L308
12,820
apache/groovy
src/main/groovy/groovy/lang/Closure.java
Closure.ncurry
public Closure<V> ncurry(int n, final Object argument) { return ncurry(n, new Object[]{argument}); }
java
public Closure<V> ncurry(int n, final Object argument) { return ncurry(n, new Object[]{argument}); }
[ "public", "Closure", "<", "V", ">", "ncurry", "(", "int", "n", ",", "final", "Object", "argument", ")", "{", "return", "ncurry", "(", "n", ",", "new", "Object", "[", "]", "{", "argument", "}", ")", ";", "}" ]
Support for Closure currying at a given index. @param argument the argument to bind @return the new closure with the argument bound @see #ncurry(int, Object...)
[ "Support", "for", "Closure", "currying", "at", "a", "given", "index", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Closure.java#L617-L619
12,821
apache/groovy
src/main/groovy/groovy/lang/Closure.java
Closure.dehydrate
@SuppressWarnings("unchecked") public Closure<V> dehydrate() { Closure<V> result = (Closure<V>) this.clone(); result.delegate = null; result.owner = null; result.thisObject = null; return result; }
java
@SuppressWarnings("unchecked") public Closure<V> dehydrate() { Closure<V> result = (Closure<V>) this.clone(); result.delegate = null; result.owner = null; result.thisObject = null; return result; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "Closure", "<", "V", ">", "dehydrate", "(", ")", "{", "Closure", "<", "V", ">", "result", "=", "(", "Closure", "<", "V", ">", ")", "this", ".", "clone", "(", ")", ";", "result", ".", "delegate", "=", "null", ";", "result", ".", "owner", "=", "null", ";", "result", ".", "thisObject", "=", "null", ";", "return", "result", ";", "}" ]
Returns a copy of this closure where the "owner", "delegate" and "thisObject" fields are null, allowing proper serialization when one of them is not serializable. @return a serializable closure. @since 1.8.5
[ "Returns", "a", "copy", "of", "this", "closure", "where", "the", "owner", "delegate", "and", "thisObject", "fields", "are", "null", "allowing", "proper", "serialization", "when", "one", "of", "them", "is", "not", "serializable", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/Closure.java#L1014-L1021
12,822
apache/groovy
src/main/groovy/groovy/lang/BenchmarkInterceptor.java
BenchmarkInterceptor.beforeInvoke
public Object beforeInvoke(Object object, String methodName, Object[] arguments) { if (!calls.containsKey(methodName)) calls.put(methodName, new LinkedList()); ((List) calls.get(methodName)).add(System.currentTimeMillis()); return null; }
java
public Object beforeInvoke(Object object, String methodName, Object[] arguments) { if (!calls.containsKey(methodName)) calls.put(methodName, new LinkedList()); ((List) calls.get(methodName)).add(System.currentTimeMillis()); return null; }
[ "public", "Object", "beforeInvoke", "(", "Object", "object", ",", "String", "methodName", ",", "Object", "[", "]", "arguments", ")", "{", "if", "(", "!", "calls", ".", "containsKey", "(", "methodName", ")", ")", "calls", ".", "put", "(", "methodName", ",", "new", "LinkedList", "(", ")", ")", ";", "(", "(", "List", ")", "calls", ".", "get", "(", "methodName", ")", ")", ".", "add", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "return", "null", ";", "}" ]
This code is executed before the method is called. @param object receiver object for the method call @param methodName name of the method to call @param arguments arguments to the method call @return null relays this result.
[ "This", "code", "is", "executed", "before", "the", "method", "is", "called", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/BenchmarkInterceptor.java#L75-L80
12,823
apache/groovy
src/main/groovy/groovy/lang/BenchmarkInterceptor.java
BenchmarkInterceptor.afterInvoke
public Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) { ((List) calls.get(methodName)).add(System.currentTimeMillis()); return result; }
java
public Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) { ((List) calls.get(methodName)).add(System.currentTimeMillis()); return result; }
[ "public", "Object", "afterInvoke", "(", "Object", "object", ",", "String", "methodName", ",", "Object", "[", "]", "arguments", ",", "Object", "result", ")", "{", "(", "(", "List", ")", "calls", ".", "get", "(", "methodName", ")", ")", ".", "add", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "return", "result", ";", "}" ]
This code is executed after the method is called. @param object receiver object for the called method @param methodName name of the called method @param arguments arguments to the called method @param result result of the executed method call or result of beforeInvoke if method was not called @return result
[ "This", "code", "is", "executed", "after", "the", "method", "is", "called", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/lang/BenchmarkInterceptor.java#L89-L92
12,824
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java
TypeHelper.getWrapperClass
protected static Class getWrapperClass(Class c) { if (c == Integer.TYPE) { c = Integer.class; } else if (c == Byte.TYPE) { c = Byte.class; } else if (c == Long.TYPE) { c = Long.class; } else if (c == Double.TYPE) { c = Double.class; } else if (c == Float.TYPE) { c = Float.class; } else if (c == Boolean.TYPE) { c = Boolean.class; } else if (c == Character.TYPE) { c = Character.class; } else if (c == Short.TYPE) { c = Short.class; } return c; }
java
protected static Class getWrapperClass(Class c) { if (c == Integer.TYPE) { c = Integer.class; } else if (c == Byte.TYPE) { c = Byte.class; } else if (c == Long.TYPE) { c = Long.class; } else if (c == Double.TYPE) { c = Double.class; } else if (c == Float.TYPE) { c = Float.class; } else if (c == Boolean.TYPE) { c = Boolean.class; } else if (c == Character.TYPE) { c = Character.class; } else if (c == Short.TYPE) { c = Short.class; } return c; }
[ "protected", "static", "Class", "getWrapperClass", "(", "Class", "c", ")", "{", "if", "(", "c", "==", "Integer", ".", "TYPE", ")", "{", "c", "=", "Integer", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Byte", ".", "TYPE", ")", "{", "c", "=", "Byte", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Long", ".", "TYPE", ")", "{", "c", "=", "Long", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Double", ".", "TYPE", ")", "{", "c", "=", "Double", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Float", ".", "TYPE", ")", "{", "c", "=", "Float", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Boolean", ".", "TYPE", ")", "{", "c", "=", "Boolean", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Character", ".", "TYPE", ")", "{", "c", "=", "Character", ".", "class", ";", "}", "else", "if", "(", "c", "==", "Short", ".", "TYPE", ")", "{", "c", "=", "Short", ".", "class", ";", "}", "return", "c", ";", "}" ]
Get wrapper class for a given class. If the class is for a primitive number type, then the wrapper class will be returned. If it is no primitive number type, we return the class itself.
[ "Get", "wrapper", "class", "for", "a", "given", "class", ".", "If", "the", "class", "is", "for", "a", "primitive", "number", "type", "then", "the", "wrapper", "class", "will", "be", "returned", ".", "If", "it", "is", "no", "primitive", "number", "type", "we", "return", "the", "class", "itself", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java#L38-L57
12,825
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java
TypeHelper.argumentClassIsParameterClass
protected static boolean argumentClassIsParameterClass(Class argumentClass, Class parameterClass) { if (argumentClass == parameterClass) return true; if (getWrapperClass(parameterClass) == argumentClass) return true; return false; }
java
protected static boolean argumentClassIsParameterClass(Class argumentClass, Class parameterClass) { if (argumentClass == parameterClass) return true; if (getWrapperClass(parameterClass) == argumentClass) return true; return false; }
[ "protected", "static", "boolean", "argumentClassIsParameterClass", "(", "Class", "argumentClass", ",", "Class", "parameterClass", ")", "{", "if", "(", "argumentClass", "==", "parameterClass", ")", "return", "true", ";", "if", "(", "getWrapperClass", "(", "parameterClass", ")", "==", "argumentClass", ")", "return", "true", ";", "return", "false", ";", "}" ]
Realizes an unsharp equal for the class. In general we return true if the provided arguments are the same. But we will also return true if our argument class is a wrapper for the parameter class. For example the parameter is an int and the argument class is a wrapper.
[ "Realizes", "an", "unsharp", "equal", "for", "the", "class", ".", "In", "general", "we", "return", "true", "if", "the", "provided", "arguments", "are", "the", "same", ".", "But", "we", "will", "also", "return", "true", "if", "our", "argument", "class", "is", "a", "wrapper", "for", "the", "parameter", "class", ".", "For", "example", "the", "parameter", "is", "an", "int", "and", "the", "argument", "class", "is", "a", "wrapper", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java#L66-L70
12,826
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java
TypeHelper.replaceWithMoreSpecificType
protected static MethodType replaceWithMoreSpecificType(Object[] args, MethodType callSiteType) { for (int i=0; i<args.length; i++) { // if argument null, take the static type if (args[i]==null) continue; if (callSiteType.parameterType(i).isPrimitive()) continue; Class argClass = args[i].getClass(); callSiteType = callSiteType.changeParameterType(i, argClass); } return callSiteType; }
java
protected static MethodType replaceWithMoreSpecificType(Object[] args, MethodType callSiteType) { for (int i=0; i<args.length; i++) { // if argument null, take the static type if (args[i]==null) continue; if (callSiteType.parameterType(i).isPrimitive()) continue; Class argClass = args[i].getClass(); callSiteType = callSiteType.changeParameterType(i, argClass); } return callSiteType; }
[ "protected", "static", "MethodType", "replaceWithMoreSpecificType", "(", "Object", "[", "]", "args", ",", "MethodType", "callSiteType", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "// if argument null, take the static type", "if", "(", "args", "[", "i", "]", "==", "null", ")", "continue", ";", "if", "(", "callSiteType", ".", "parameterType", "(", "i", ")", ".", "isPrimitive", "(", ")", ")", "continue", ";", "Class", "argClass", "=", "args", "[", "i", "]", ".", "getClass", "(", ")", ";", "callSiteType", "=", "callSiteType", ".", "changeParameterType", "(", "i", ",", "argClass", ")", ";", "}", "return", "callSiteType", ";", "}" ]
Replaces the types in the callSiteType parameter if more specific types given through the arguments. This is in general the case, unless the argument is null.
[ "Replaces", "the", "types", "in", "the", "callSiteType", "parameter", "if", "more", "specific", "types", "given", "through", "the", "arguments", ".", "This", "is", "in", "general", "the", "case", "unless", "the", "argument", "is", "null", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/TypeHelper.java#L77-L86
12,827
apache/groovy
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
Groovydoc.setPackagenames
public void setPackagenames(String packages) { StringTokenizer tok = new StringTokenizer(packages, ","); while (tok.hasMoreTokens()) { String packageName = tok.nextToken(); packageNames.add(packageName); } }
java
public void setPackagenames(String packages) { StringTokenizer tok = new StringTokenizer(packages, ","); while (tok.hasMoreTokens()) { String packageName = tok.nextToken(); packageNames.add(packageName); } }
[ "public", "void", "setPackagenames", "(", "String", "packages", ")", "{", "StringTokenizer", "tok", "=", "new", "StringTokenizer", "(", "packages", ",", "\",\"", ")", ";", "while", "(", "tok", ".", "hasMoreTokens", "(", ")", ")", "{", "String", "packageName", "=", "tok", ".", "nextToken", "(", ")", ";", "packageNames", ".", "add", "(", "packageName", ")", ";", "}", "}" ]
Set the package names to be processed. @param packages a comma separated list of packages specs (may be wildcarded).
[ "Set", "the", "package", "names", "to", "be", "processed", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java#L183-L189
12,828
apache/groovy
benchmark/bench/fasta.java
fasta.random
public static final double random(double max) { last = (last * IA + IC) % IM; return max * last / IM; }
java
public static final double random(double max) { last = (last * IA + IC) % IM; return max * last / IM; }
[ "public", "static", "final", "double", "random", "(", "double", "max", ")", "{", "last", "=", "(", "last", "*", "IA", "+", "IC", ")", "%", "IM", ";", "return", "max", "*", "last", "/", "IM", ";", "}" ]
pseudo-random number generator
[ "pseudo", "-", "random", "number", "generator" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/benchmark/bench/fasta.java#L21-L24
12,829
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/JsonLexer.java
JsonLexer.readingConstant
private JsonToken readingConstant(JsonTokenType type, JsonToken token) { try { int numCharsToRead = ((String) type.getValidator()).length(); char[] chars = new char[numCharsToRead]; reader.read(chars); String stringRead = new String(chars); if (stringRead.equals(type.getValidator())) { token.setEndColumn(token.getStartColumn() + numCharsToRead); token.setText(stringRead); return token; } else { throwJsonException(stringRead, type); } } catch (IOException ioe) { throw new JsonException("An IO exception occurred while reading the JSON payload", ioe); } return null; }
java
private JsonToken readingConstant(JsonTokenType type, JsonToken token) { try { int numCharsToRead = ((String) type.getValidator()).length(); char[] chars = new char[numCharsToRead]; reader.read(chars); String stringRead = new String(chars); if (stringRead.equals(type.getValidator())) { token.setEndColumn(token.getStartColumn() + numCharsToRead); token.setText(stringRead); return token; } else { throwJsonException(stringRead, type); } } catch (IOException ioe) { throw new JsonException("An IO exception occurred while reading the JSON payload", ioe); } return null; }
[ "private", "JsonToken", "readingConstant", "(", "JsonTokenType", "type", ",", "JsonToken", "token", ")", "{", "try", "{", "int", "numCharsToRead", "=", "(", "(", "String", ")", "type", ".", "getValidator", "(", ")", ")", ".", "length", "(", ")", ";", "char", "[", "]", "chars", "=", "new", "char", "[", "numCharsToRead", "]", ";", "reader", ".", "read", "(", "chars", ")", ";", "String", "stringRead", "=", "new", "String", "(", "chars", ")", ";", "if", "(", "stringRead", ".", "equals", "(", "type", ".", "getValidator", "(", ")", ")", ")", "{", "token", ".", "setEndColumn", "(", "token", ".", "getStartColumn", "(", ")", "+", "numCharsToRead", ")", ";", "token", ".", "setText", "(", "stringRead", ")", ";", "return", "token", ";", "}", "else", "{", "throwJsonException", "(", "stringRead", ",", "type", ")", ";", "}", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "JsonException", "(", "\"An IO exception occurred while reading the JSON payload\"", ",", "ioe", ")", ";", "}", "return", "null", ";", "}" ]
When a constant token type is expected, check that the expected constant is read, and update the content of the token accordingly. @param type the token type @param token the token @return the token updated with end column and text updated
[ "When", "a", "constant", "token", "type", "is", "expected", "check", "that", "the", "expected", "constant", "is", "read", "and", "update", "the", "content", "of", "the", "token", "accordingly", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/JsonLexer.java#L190-L208
12,830
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/JsonLexer.java
JsonLexer.skipWhitespace
public int skipWhitespace() { try { int readChar = 20; char c = SPACE; while (Character.isWhitespace(c)) { reader.mark(1); readChar = reader.read(); c = (char) readChar; } reader.reset(); return readChar; } catch (IOException ioe) { throw new JsonException("An IO exception occurred while reading the JSON payload", ioe); } }
java
public int skipWhitespace() { try { int readChar = 20; char c = SPACE; while (Character.isWhitespace(c)) { reader.mark(1); readChar = reader.read(); c = (char) readChar; } reader.reset(); return readChar; } catch (IOException ioe) { throw new JsonException("An IO exception occurred while reading the JSON payload", ioe); } }
[ "public", "int", "skipWhitespace", "(", ")", "{", "try", "{", "int", "readChar", "=", "20", ";", "char", "c", "=", "SPACE", ";", "while", "(", "Character", ".", "isWhitespace", "(", "c", ")", ")", "{", "reader", ".", "mark", "(", "1", ")", ";", "readChar", "=", "reader", ".", "read", "(", ")", ";", "c", "=", "(", "char", ")", "readChar", ";", "}", "reader", ".", "reset", "(", ")", ";", "return", "readChar", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "JsonException", "(", "\"An IO exception occurred while reading the JSON payload\"", ",", "ioe", ")", ";", "}", "}" ]
Skips all the whitespace characters and moves the cursor to the next non-space character.
[ "Skips", "all", "the", "whitespace", "characters", "and", "moves", "the", "cursor", "to", "the", "next", "non", "-", "space", "character", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/JsonLexer.java#L213-L227
12,831
apache/groovy
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
StaticTypesTypeChooser.getTarget
private static VariableExpression getTarget(VariableExpression ve) { if (ve.getAccessedVariable() == null || ve.getAccessedVariable() == ve || (!(ve.getAccessedVariable() instanceof VariableExpression))) return ve; return getTarget((VariableExpression) ve.getAccessedVariable()); }
java
private static VariableExpression getTarget(VariableExpression ve) { if (ve.getAccessedVariable() == null || ve.getAccessedVariable() == ve || (!(ve.getAccessedVariable() instanceof VariableExpression))) return ve; return getTarget((VariableExpression) ve.getAccessedVariable()); }
[ "private", "static", "VariableExpression", "getTarget", "(", "VariableExpression", "ve", ")", "{", "if", "(", "ve", ".", "getAccessedVariable", "(", ")", "==", "null", "||", "ve", ".", "getAccessedVariable", "(", ")", "==", "ve", "||", "(", "!", "(", "ve", ".", "getAccessedVariable", "(", ")", "instanceof", "VariableExpression", ")", ")", ")", "return", "ve", ";", "return", "getTarget", "(", "(", "VariableExpression", ")", "ve", ".", "getAccessedVariable", "(", ")", ")", ";", "}" ]
The inferred type, in case of a variable expression, can be set on the accessed variable, so we take it instead of the facade one. @param ve the variable expression for which to return the target expression @return the target variable expression
[ "The", "inferred", "type", "in", "case", "of", "a", "variable", "expression", "can", "be", "set", "on", "the", "accessed", "variable", "so", "we", "take", "it", "instead", "of", "the", "facade", "one", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java#L68-L72
12,832
apache/groovy
src/main/java/org/codehaus/groovy/control/io/AbstractReaderSource.java
AbstractReaderSource.getLine
public String getLine(int lineNumber, Janitor janitor) { // If the source is already open and is passed the line we // want, close it. if (lineSource != null && number > lineNumber) { cleanup(); } // If the line source is closed, try to open it. if (lineSource == null) { try { lineSource = new BufferedReader(getReader()); } catch (Exception e) { // Ignore } number = 0; } // Read until the appropriate line number. if (lineSource != null) { while (number < lineNumber) { try { line = lineSource.readLine(); number++; } catch (IOException e) { cleanup(); } } if (janitor == null) { final String result = line; // otherwise cleanup() will wipe out value cleanup(); return result; } else { janitor.register(this); } } return line; }
java
public String getLine(int lineNumber, Janitor janitor) { // If the source is already open and is passed the line we // want, close it. if (lineSource != null && number > lineNumber) { cleanup(); } // If the line source is closed, try to open it. if (lineSource == null) { try { lineSource = new BufferedReader(getReader()); } catch (Exception e) { // Ignore } number = 0; } // Read until the appropriate line number. if (lineSource != null) { while (number < lineNumber) { try { line = lineSource.readLine(); number++; } catch (IOException e) { cleanup(); } } if (janitor == null) { final String result = line; // otherwise cleanup() will wipe out value cleanup(); return result; } else { janitor.register(this); } } return line; }
[ "public", "String", "getLine", "(", "int", "lineNumber", ",", "Janitor", "janitor", ")", "{", "// If the source is already open and is passed the line we", "// want, close it.", "if", "(", "lineSource", "!=", "null", "&&", "number", ">", "lineNumber", ")", "{", "cleanup", "(", ")", ";", "}", "// If the line source is closed, try to open it.", "if", "(", "lineSource", "==", "null", ")", "{", "try", "{", "lineSource", "=", "new", "BufferedReader", "(", "getReader", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "// Ignore", "}", "number", "=", "0", ";", "}", "// Read until the appropriate line number.", "if", "(", "lineSource", "!=", "null", ")", "{", "while", "(", "number", "<", "lineNumber", ")", "{", "try", "{", "line", "=", "lineSource", ".", "readLine", "(", ")", ";", "number", "++", ";", "}", "catch", "(", "IOException", "e", ")", "{", "cleanup", "(", ")", ";", "}", "}", "if", "(", "janitor", "==", "null", ")", "{", "final", "String", "result", "=", "line", ";", "// otherwise cleanup() will wipe out value", "cleanup", "(", ")", ";", "return", "result", ";", "}", "else", "{", "janitor", ".", "register", "(", "this", ")", ";", "}", "}", "return", "line", ";", "}" ]
Returns a line from the source, or null, if unavailable. If you supply a Janitor, resources will be cached.
[ "Returns", "a", "line", "from", "the", "source", "or", "null", "if", "unavailable", ".", "If", "you", "supply", "a", "Janitor", "resources", "will", "be", "cached", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/control/io/AbstractReaderSource.java#L59-L98
12,833
apache/groovy
subprojects/groovy-sql/src/main/java/groovy/sql/GroovyRowResult.java
GroovyRowResult.getAt
public Object getAt(int index) { try { // a negative index will count backwards from the last column. if (index < 0) index += result.size(); Iterator it = result.values().iterator(); int i = 0; Object obj = null; while ((obj == null) && (it.hasNext())) { if (i == index) obj = it.next(); else it.next(); i++; } return obj; } catch (Exception e) { throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e); } }
java
public Object getAt(int index) { try { // a negative index will count backwards from the last column. if (index < 0) index += result.size(); Iterator it = result.values().iterator(); int i = 0; Object obj = null; while ((obj == null) && (it.hasNext())) { if (i == index) obj = it.next(); else it.next(); i++; } return obj; } catch (Exception e) { throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e); } }
[ "public", "Object", "getAt", "(", "int", "index", ")", "{", "try", "{", "// a negative index will count backwards from the last column.", "if", "(", "index", "<", "0", ")", "index", "+=", "result", ".", "size", "(", ")", ";", "Iterator", "it", "=", "result", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "int", "i", "=", "0", ";", "Object", "obj", "=", "null", ";", "while", "(", "(", "obj", "==", "null", ")", "&&", "(", "it", ".", "hasNext", "(", ")", ")", ")", "{", "if", "(", "i", "==", "index", ")", "obj", "=", "it", ".", "next", "(", ")", ";", "else", "it", ".", "next", "(", ")", ";", "i", "++", ";", "}", "return", "obj", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "MissingPropertyException", "(", "Integer", ".", "toString", "(", "index", ")", ",", "GroovyRowResult", ".", "class", ",", "e", ")", ";", "}", "}" ]
Retrieve the value of the property by its index. A negative index will count backwards from the last column. @param index is the number of the column to look at @return the value of the property
[ "Retrieve", "the", "value", "of", "the", "property", "by", "its", "index", ".", "A", "negative", "index", "will", "count", "backwards", "from", "the", "last", "column", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/GroovyRowResult.java#L84-L104
12,834
apache/groovy
subprojects/groovy-sql/src/main/java/groovy/sql/GroovyRowResult.java
GroovyRowResult.put
@SuppressWarnings("unchecked") public Object put(Object key, Object value) { // avoid different case keys being added by explicit remove Object orig = remove(key); result.put(key, value); return orig; }
java
@SuppressWarnings("unchecked") public Object put(Object key, Object value) { // avoid different case keys being added by explicit remove Object orig = remove(key); result.put(key, value); return orig; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "Object", "put", "(", "Object", "key", ",", "Object", "value", ")", "{", "// avoid different case keys being added by explicit remove", "Object", "orig", "=", "remove", "(", "key", ")", ";", "result", ".", "put", "(", "key", ",", "value", ")", ";", "return", "orig", ";", "}" ]
Associates the specified value with the specified property name in this result. @param key the property name for the result @param value the property value for the result @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map previously associated <tt>null</tt> with <tt>key</tt>.)
[ "Associates", "the", "specified", "value", "with", "the", "specified", "property", "name", "in", "this", "result", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-sql/src/main/java/groovy/sql/GroovyRowResult.java#L175-L181
12,835
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.withObjectOutputStream
public static <T> T withObjectOutputStream(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectOutputStream(self), closure); }
java
public static <T> T withObjectOutputStream(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectOutputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectOutputStream(self), closure); }
[ "public", "static", "<", "T", ">", "T", "withObjectOutputStream", "(", "Path", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.ObjectOutputStream\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withStream", "(", "newObjectOutputStream", "(", "self", ")", ",", "closure", ")", ";", "}" ]
Create a new ObjectOutputStream for this path and then pass it to the closure. This method ensures the stream is closed after the closure returns. @param self a Path @param closure a closure @return the value returned by the closure @throws java.io.IOException if an IOException occurs. @see IOGroovyMethods#withStream(java.io.OutputStream, groovy.lang.Closure) @since 2.3.0
[ "Create", "a", "new", "ObjectOutputStream", "for", "this", "path", "and", "then", "pass", "it", "to", "the", "closure", ".", "This", "method", "ensures", "the", "stream", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L121-L123
12,836
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.newObjectInputStream
public static ObjectInputStream newObjectInputStream(Path self, final ClassLoader classLoader) throws IOException { return IOGroovyMethods.newObjectInputStream(Files.newInputStream(self), classLoader); }
java
public static ObjectInputStream newObjectInputStream(Path self, final ClassLoader classLoader) throws IOException { return IOGroovyMethods.newObjectInputStream(Files.newInputStream(self), classLoader); }
[ "public", "static", "ObjectInputStream", "newObjectInputStream", "(", "Path", "self", ",", "final", "ClassLoader", "classLoader", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "newObjectInputStream", "(", "Files", ".", "newInputStream", "(", "self", ")", ",", "classLoader", ")", ";", "}" ]
Create an object input stream for this path using the given class loader. @param self a {@code Path} object @param classLoader the class loader to use when loading the class @return an object input stream @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Create", "an", "object", "input", "stream", "for", "this", "path", "using", "the", "given", "class", "loader", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L146-L148
12,837
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.withObjectInputStream
public static <T> T withObjectInputStream(Path self, ClassLoader classLoader, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectInputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectInputStream(self, classLoader), closure); }
java
public static <T> T withObjectInputStream(Path self, ClassLoader classLoader, @ClosureParams(value = SimpleType.class, options = "java.io.ObjectInputStream") Closure<T> closure) throws IOException { return IOGroovyMethods.withStream(newObjectInputStream(self, classLoader), closure); }
[ "public", "static", "<", "T", ">", "T", "withObjectInputStream", "(", "Path", "self", ",", "ClassLoader", "classLoader", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.ObjectInputStream\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "withStream", "(", "newObjectInputStream", "(", "self", ",", "classLoader", ")", ",", "closure", ")", ";", "}" ]
Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. This method ensures the stream is closed after the closure returns. @param self a Path @param classLoader the class loader to use when loading the class @param closure a closure @return the value returned by the closure @throws java.io.IOException if an IOException occurs. @see org.codehaus.groovy.runtime.IOGroovyMethods#withStream(java.io.InputStream, groovy.lang.Closure) @since 2.3.0
[ "Create", "a", "new", "ObjectInputStream", "for", "this", "file", "associated", "with", "the", "given", "class", "loader", "and", "pass", "it", "to", "the", "closure", ".", "This", "method", "ensures", "the", "stream", "is", "closed", "after", "the", "closure", "returns", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L191-L193
12,838
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.getText
public static String getText(Path self, String charset) throws IOException { return IOGroovyMethods.getText(newReader(self, charset)); }
java
public static String getText(Path self, String charset) throws IOException { return IOGroovyMethods.getText(newReader(self, charset)); }
[ "public", "static", "String", "getText", "(", "Path", "self", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "getText", "(", "newReader", "(", "self", ",", "charset", ")", ")", ";", "}" ]
Read the content of the Path using the specified encoding and return it as a String. @param self the file whose content we want to read @param charset the charset used to read the content of the file @return a String containing the content of the file @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Read", "the", "content", "of", "the", "Path", "using", "the", "specified", "encoding", "and", "return", "it", "as", "a", "String", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L380-L382
12,839
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.setBytes
public static void setBytes(Path self, byte[] bytes) throws IOException { IOGroovyMethods.setBytes(Files.newOutputStream(self), bytes); }
java
public static void setBytes(Path self, byte[] bytes) throws IOException { IOGroovyMethods.setBytes(Files.newOutputStream(self), bytes); }
[ "public", "static", "void", "setBytes", "(", "Path", "self", ",", "byte", "[", "]", "bytes", ")", "throws", "IOException", "{", "IOGroovyMethods", ".", "setBytes", "(", "Files", ".", "newOutputStream", "(", "self", ")", ",", "bytes", ")", ";", "}" ]
Write the bytes from the byte array to the Path. @param self the file to write to @param bytes the byte[] to write to the file @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Write", "the", "bytes", "from", "the", "byte", "array", "to", "the", "Path", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L416-L418
12,840
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.leftShift
public static Path leftShift(Path self, byte[] bytes) throws IOException { append(self, bytes); return self; }
java
public static Path leftShift(Path self, byte[] bytes) throws IOException { append(self, bytes); return self; }
[ "public", "static", "Path", "leftShift", "(", "Path", "self", ",", "byte", "[", "]", "bytes", ")", "throws", "IOException", "{", "append", "(", "self", ",", "bytes", ")", ";", "return", "self", ";", "}" ]
Write bytes to a Path. @param self a Path @param bytes the byte array to append to the end of the Path @return the original file @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Write", "bytes", "to", "a", "Path", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L506-L509
12,841
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.write
public static void write(Path self, String text, String charset) throws IOException { write(self, text, charset, false); }
java
public static void write(Path self, String text, String charset) throws IOException { write(self, text, charset, false); }
[ "public", "static", "void", "write", "(", "Path", "self", ",", "String", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "write", "(", "self", ",", "text", ",", "charset", ",", "false", ")", ";", "}" ]
Write the text to the Path without writing a BOM, using the specified encoding. @param self a Path @param text the text to write to the Path @param charset the charset used @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Write", "the", "text", "to", "the", "Path", "without", "writing", "a", "BOM", "using", "the", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L534-L536
12,842
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.append
public static void append(Path self, Object text) throws IOException { append(self, text, Charset.defaultCharset().name(), false); }
java
public static void append(Path self, Object text) throws IOException { append(self, text, Charset.defaultCharset().name(), false); }
[ "public", "static", "void", "append", "(", "Path", "self", ",", "Object", "text", ")", "throws", "IOException", "{", "append", "(", "self", ",", "text", ",", "Charset", ".", "defaultCharset", "(", ")", ".", "name", "(", ")", ",", "false", ")", ";", "}" ]
Append the text at the end of the Path without writing a BOM. @param self a Path @param text the text to append at the end of the Path @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "Path", "without", "writing", "a", "BOM", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L578-L580
12,843
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.append
public static void append(Path self, Object text, String charset) throws IOException { append(self, text, charset, false); }
java
public static void append(Path self, Object text, String charset) throws IOException { append(self, text, charset, false); }
[ "public", "static", "void", "append", "(", "Path", "self", ",", "Object", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "append", "(", "self", ",", "text", ",", "charset", ",", "false", ")", ";", "}" ]
Append the text at the end of the Path without writing a BOM, using a specified encoding. @param self a Path @param text the text to append at the end of the Path @param charset the charset used @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "Path", "without", "writing", "a", "BOM", "using", "a", "specified", "encoding", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L675-L677
12,844
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.eachDir
public static void eachDir(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException { eachFile(self, FileType.DIRECTORIES, closure); }
java
public static void eachDir(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException { eachFile(self, FileType.DIRECTORIES, closure); }
[ "public", "static", "void", "eachDir", "(", "Path", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.nio.file.Path\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "// throws FileNotFoundException, IllegalArgumentException {", "eachFile", "(", "self", ",", "FileType", ".", "DIRECTORIES", ",", "closure", ")", ";", "}" ]
Invokes the closure for each subdirectory in this directory, ignoring regular files. @param self a Path (that happens to be a folder/directory) @param closure a closure (the parameter is the Path for the subdirectory file) @throws java.io.FileNotFoundException if the given directory does not exist @throws IllegalArgumentException if the provided Path object does not represent a directory @see #eachFile(Path, groovy.io.FileType, groovy.lang.Closure) @since 2.3.0
[ "Invokes", "the", "closure", "for", "each", "subdirectory", "in", "this", "directory", "ignoring", "regular", "files", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L901-L903
12,845
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.renameTo
public static boolean renameTo(final Path self, URI newPathName) { try { Files.move(self, Paths.get(newPathName)); return true; } catch (IOException e) { return false; } }
java
public static boolean renameTo(final Path self, URI newPathName) { try { Files.move(self, Paths.get(newPathName)); return true; } catch (IOException e) { return false; } }
[ "public", "static", "boolean", "renameTo", "(", "final", "Path", "self", ",", "URI", "newPathName", ")", "{", "try", "{", "Files", ".", "move", "(", "self", ",", "Paths", ".", "get", "(", "newPathName", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "false", ";", "}", "}" ]
Renames a file. @param self a Path @param newPathName The new target path specified as a URI object @return <code>true</code> if and only if the renaming succeeded; <code>false</code> otherwise @since 2.3.0
[ "Renames", "a", "file", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1341-L1348
12,846
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.newWriter
public static BufferedWriter newWriter(Path self) throws IOException { return Files.newBufferedWriter(self, Charset.defaultCharset()); }
java
public static BufferedWriter newWriter(Path self) throws IOException { return Files.newBufferedWriter(self, Charset.defaultCharset()); }
[ "public", "static", "BufferedWriter", "newWriter", "(", "Path", "self", ")", "throws", "IOException", "{", "return", "Files", ".", "newBufferedWriter", "(", "self", ",", "Charset", ".", "defaultCharset", "(", ")", ")", ";", "}" ]
Create a buffered writer for this file. @param self a Path @return a BufferedWriter @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Create", "a", "buffered", "writer", "for", "this", "file", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1542-L1544
12,847
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.newWriter
public static BufferedWriter newWriter(Path self, String charset, boolean append) throws IOException { return newWriter(self, charset, append, false); }
java
public static BufferedWriter newWriter(Path self, String charset, boolean append) throws IOException { return newWriter(self, charset, append, false); }
[ "public", "static", "BufferedWriter", "newWriter", "(", "Path", "self", ",", "String", "charset", ",", "boolean", "append", ")", "throws", "IOException", "{", "return", "newWriter", "(", "self", ",", "charset", ",", "append", ",", "false", ")", ";", "}" ]
Helper method to create a buffered writer for a file without writing a BOM. @param self a Path @param charset the name of the encoding used to write in this file @param append true if in append mode @return a BufferedWriter @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Helper", "method", "to", "create", "a", "buffered", "writer", "for", "a", "file", "without", "writing", "a", "BOM", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1573-L1575
12,848
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.withWriter
public static <T> T withWriter(Path self, String charset, @ClosureParams(value = SimpleType.class, options = "java.io.Writer") Closure<T> closure) throws IOException { return withWriter(self, charset, false, closure); }
java
public static <T> T withWriter(Path self, String charset, @ClosureParams(value = SimpleType.class, options = "java.io.Writer") Closure<T> closure) throws IOException { return withWriter(self, charset, false, closure); }
[ "public", "static", "<", "T", ">", "T", "withWriter", "(", "Path", "self", ",", "String", "charset", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.Writer\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withWriter", "(", "self", ",", "charset", ",", "false", ",", "closure", ")", ";", "}" ]
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. The writer will use the given charset encoding, but will not write a BOM. @param self a Path @param charset the charset used @param closure a closure @return the value returned by the closure @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Creates", "a", "new", "BufferedWriter", "for", "this", "file", "passes", "it", "to", "the", "closure", "and", "ensures", "the", "stream", "is", "flushed", "and", "closed", "after", "the", "closure", "returns", ".", "The", "writer", "will", "use", "the", "given", "charset", "encoding", "but", "will", "not", "write", "a", "BOM", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1649-L1651
12,849
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.withWriterAppend
public static <T> T withWriterAppend(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.Writer") Closure<T> closure) throws IOException { return withWriterAppend(self, Charset.defaultCharset().name(), closure); }
java
public static <T> T withWriterAppend(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.Writer") Closure<T> closure) throws IOException { return withWriterAppend(self, Charset.defaultCharset().name(), closure); }
[ "public", "static", "<", "T", ">", "T", "withWriterAppend", "(", "Path", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.io.Writer\"", ")", "Closure", "<", "T", ">", "closure", ")", "throws", "IOException", "{", "return", "withWriterAppend", "(", "self", ",", "Charset", ".", "defaultCharset", "(", ")", ".", "name", "(", ")", ",", "closure", ")", ";", "}" ]
Create a new BufferedWriter for this file in append mode. The writer is passed to the closure and is closed after the closure returns. The writer will not write a BOM. @param self a Path @param closure a closure @return the value returned by the closure @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Create", "a", "new", "BufferedWriter", "for", "this", "file", "in", "append", "mode", ".", "The", "writer", "is", "passed", "to", "the", "closure", "and", "is", "closed", "after", "the", "closure", "returns", ".", "The", "writer", "will", "not", "write", "a", "BOM", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1721-L1723
12,850
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.newPrintWriter
public static PrintWriter newPrintWriter(Path self, String charset) throws IOException { return new GroovyPrintWriter(newWriter(self, charset)); }
java
public static PrintWriter newPrintWriter(Path self, String charset) throws IOException { return new GroovyPrintWriter(newWriter(self, charset)); }
[ "public", "static", "PrintWriter", "newPrintWriter", "(", "Path", "self", ",", "String", "charset", ")", "throws", "IOException", "{", "return", "new", "GroovyPrintWriter", "(", "newWriter", "(", "self", ",", "charset", ")", ")", ";", "}" ]
Create a new PrintWriter for this file, using specified charset. @param self a Path @param charset the charset @return a PrintWriter @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Create", "a", "new", "PrintWriter", "for", "this", "file", "using", "specified", "charset", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1747-L1749
12,851
apache/groovy
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.eachByte
public static void eachByte(Path self, int bufferLen, @ClosureParams(value = FromString.class, options = "byte[],Integer") Closure closure) throws IOException { BufferedInputStream is = newInputStream(self); IOGroovyMethods.eachByte(is, bufferLen, closure); }
java
public static void eachByte(Path self, int bufferLen, @ClosureParams(value = FromString.class, options = "byte[],Integer") Closure closure) throws IOException { BufferedInputStream is = newInputStream(self); IOGroovyMethods.eachByte(is, bufferLen, closure); }
[ "public", "static", "void", "eachByte", "(", "Path", "self", ",", "int", "bufferLen", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "\"byte[],Integer\"", ")", "Closure", "closure", ")", "throws", "IOException", "{", "BufferedInputStream", "is", "=", "newInputStream", "(", "self", ")", ";", "IOGroovyMethods", ".", "eachByte", "(", "is", ",", "bufferLen", ",", "closure", ")", ";", "}" ]
Traverse through the bytes of this Path, bufferLen bytes at a time. @param self a Path @param bufferLen the length of the buffer to use. @param closure a 2 parameter closure which is passed the byte[] and a number of bytes successfully read. @throws java.io.IOException if an IOException occurs. @see org.codehaus.groovy.runtime.IOGroovyMethods#eachByte(java.io.InputStream, int, groovy.lang.Closure) @since 2.3.0
[ "Traverse", "through", "the", "bytes", "of", "this", "Path", "bufferLen", "bytes", "at", "a", "time", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L1830-L1833
12,852
apache/groovy
subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyDoc.java
SimpleGroovyDoc.compareTo
public int compareTo(Object that) { if (that instanceof GroovyDoc) { return name.compareTo(((GroovyDoc) that).name()); } else { throw new ClassCastException(String.format("Cannot compare object of type %s.", that.getClass())); } }
java
public int compareTo(Object that) { if (that instanceof GroovyDoc) { return name.compareTo(((GroovyDoc) that).name()); } else { throw new ClassCastException(String.format("Cannot compare object of type %s.", that.getClass())); } }
[ "public", "int", "compareTo", "(", "Object", "that", ")", "{", "if", "(", "that", "instanceof", "GroovyDoc", ")", "{", "return", "name", ".", "compareTo", "(", "(", "(", "GroovyDoc", ")", "that", ")", ".", "name", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "ClassCastException", "(", "String", ".", "format", "(", "\"Cannot compare object of type %s.\"", ",", "that", ".", "getClass", "(", ")", ")", ")", ";", "}", "}" ]
Methods from Comparable
[ "Methods", "from", "Comparable" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyDoc.java#L188-L194
12,853
apache/groovy
src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
InvokerHelper.setProperties
public static void setProperties(Object object, Map map) { MetaClass mc = getMetaClass(object); for (Object o : map.entrySet()) { Map.Entry entry = (Map.Entry) o; String key = entry.getKey().toString(); Object value = entry.getValue(); setPropertySafe(object, mc, key, value); } }
java
public static void setProperties(Object object, Map map) { MetaClass mc = getMetaClass(object); for (Object o : map.entrySet()) { Map.Entry entry = (Map.Entry) o; String key = entry.getKey().toString(); Object value = entry.getValue(); setPropertySafe(object, mc, key, value); } }
[ "public", "static", "void", "setProperties", "(", "Object", "object", ",", "Map", "map", ")", "{", "MetaClass", "mc", "=", "getMetaClass", "(", "object", ")", ";", "for", "(", "Object", "o", ":", "map", ".", "entrySet", "(", ")", ")", "{", "Map", ".", "Entry", "entry", "=", "(", "Map", ".", "Entry", ")", "o", ";", "String", "key", "=", "entry", ".", "getKey", "(", ")", ".", "toString", "(", ")", ";", "Object", "value", "=", "entry", ".", "getValue", "(", ")", ";", "setPropertySafe", "(", "object", ",", "mc", ",", "key", ",", "value", ")", ";", "}", "}" ]
Sets the properties on the given object
[ "Sets", "the", "properties", "on", "the", "given", "object" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java#L513-L521
12,854
apache/groovy
src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
InvokerHelper.write
public static void write(Writer out, Object object) throws IOException { if (object instanceof String) { out.write((String) object); } else if (object instanceof Object[]) { out.write(toArrayString((Object[]) object)); } else if (object instanceof Map) { out.write(toMapString((Map) object)); } else if (object instanceof Collection) { out.write(toListString((Collection) object)); } else if (object instanceof Writable) { Writable writable = (Writable) object; writable.writeTo(out); } else if (object instanceof InputStream || object instanceof Reader) { // Copy stream to stream Reader reader; if (object instanceof InputStream) { reader = new InputStreamReader((InputStream) object); } else { reader = (Reader) object; } try (Reader r = reader) { char[] chars = new char[8192]; for (int i; (i = r.read(chars)) != -1; ) { out.write(chars, 0, i); } } } else { out.write(toString(object)); } }
java
public static void write(Writer out, Object object) throws IOException { if (object instanceof String) { out.write((String) object); } else if (object instanceof Object[]) { out.write(toArrayString((Object[]) object)); } else if (object instanceof Map) { out.write(toMapString((Map) object)); } else if (object instanceof Collection) { out.write(toListString((Collection) object)); } else if (object instanceof Writable) { Writable writable = (Writable) object; writable.writeTo(out); } else if (object instanceof InputStream || object instanceof Reader) { // Copy stream to stream Reader reader; if (object instanceof InputStream) { reader = new InputStreamReader((InputStream) object); } else { reader = (Reader) object; } try (Reader r = reader) { char[] chars = new char[8192]; for (int i; (i = r.read(chars)) != -1; ) { out.write(chars, 0, i); } } } else { out.write(toString(object)); } }
[ "public", "static", "void", "write", "(", "Writer", "out", ",", "Object", "object", ")", "throws", "IOException", "{", "if", "(", "object", "instanceof", "String", ")", "{", "out", ".", "write", "(", "(", "String", ")", "object", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Object", "[", "]", ")", "{", "out", ".", "write", "(", "toArrayString", "(", "(", "Object", "[", "]", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Map", ")", "{", "out", ".", "write", "(", "toMapString", "(", "(", "Map", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Collection", ")", "{", "out", ".", "write", "(", "toListString", "(", "(", "Collection", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Writable", ")", "{", "Writable", "writable", "=", "(", "Writable", ")", "object", ";", "writable", ".", "writeTo", "(", "out", ")", ";", "}", "else", "if", "(", "object", "instanceof", "InputStream", "||", "object", "instanceof", "Reader", ")", "{", "// Copy stream to stream", "Reader", "reader", ";", "if", "(", "object", "instanceof", "InputStream", ")", "{", "reader", "=", "new", "InputStreamReader", "(", "(", "InputStream", ")", "object", ")", ";", "}", "else", "{", "reader", "=", "(", "Reader", ")", "object", ";", "}", "try", "(", "Reader", "r", "=", "reader", ")", "{", "char", "[", "]", "chars", "=", "new", "char", "[", "8192", "]", ";", "for", "(", "int", "i", ";", "(", "i", "=", "r", ".", "read", "(", "chars", ")", ")", "!=", "-", "1", ";", ")", "{", "out", ".", "write", "(", "chars", ",", "0", ",", "i", ")", ";", "}", "}", "}", "else", "{", "out", ".", "write", "(", "toString", "(", "object", ")", ")", ";", "}", "}" ]
Writes an object to a Writer using Groovy's default representation for the object.
[ "Writes", "an", "object", "to", "a", "Writer", "using", "Groovy", "s", "default", "representation", "for", "the", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java#L538-L568
12,855
apache/groovy
src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
InvokerHelper.append
public static void append(Appendable out, Object object) throws IOException { if (object instanceof String) { out.append((String) object); } else if (object instanceof Object[]) { out.append(toArrayString((Object[]) object)); } else if (object instanceof Map) { out.append(toMapString((Map) object)); } else if (object instanceof Collection) { out.append(toListString((Collection) object)); } else if (object instanceof Writable) { Writable writable = (Writable) object; Writer stringWriter = new StringBuilderWriter(); writable.writeTo(stringWriter); out.append(stringWriter.toString()); } else if (object instanceof InputStream || object instanceof Reader) { // Copy stream to stream Reader reader; if (object instanceof InputStream) { reader = new InputStreamReader((InputStream) object); } else { reader = (Reader) object; } char[] chars = new char[8192]; int i; while ((i = reader.read(chars)) != -1) { for (int j = 0; j < i; j++) { out.append(chars[j]); } } reader.close(); } else { out.append(toString(object)); } }
java
public static void append(Appendable out, Object object) throws IOException { if (object instanceof String) { out.append((String) object); } else if (object instanceof Object[]) { out.append(toArrayString((Object[]) object)); } else if (object instanceof Map) { out.append(toMapString((Map) object)); } else if (object instanceof Collection) { out.append(toListString((Collection) object)); } else if (object instanceof Writable) { Writable writable = (Writable) object; Writer stringWriter = new StringBuilderWriter(); writable.writeTo(stringWriter); out.append(stringWriter.toString()); } else if (object instanceof InputStream || object instanceof Reader) { // Copy stream to stream Reader reader; if (object instanceof InputStream) { reader = new InputStreamReader((InputStream) object); } else { reader = (Reader) object; } char[] chars = new char[8192]; int i; while ((i = reader.read(chars)) != -1) { for (int j = 0; j < i; j++) { out.append(chars[j]); } } reader.close(); } else { out.append(toString(object)); } }
[ "public", "static", "void", "append", "(", "Appendable", "out", ",", "Object", "object", ")", "throws", "IOException", "{", "if", "(", "object", "instanceof", "String", ")", "{", "out", ".", "append", "(", "(", "String", ")", "object", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Object", "[", "]", ")", "{", "out", ".", "append", "(", "toArrayString", "(", "(", "Object", "[", "]", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Map", ")", "{", "out", ".", "append", "(", "toMapString", "(", "(", "Map", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Collection", ")", "{", "out", ".", "append", "(", "toListString", "(", "(", "Collection", ")", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Writable", ")", "{", "Writable", "writable", "=", "(", "Writable", ")", "object", ";", "Writer", "stringWriter", "=", "new", "StringBuilderWriter", "(", ")", ";", "writable", ".", "writeTo", "(", "stringWriter", ")", ";", "out", ".", "append", "(", "stringWriter", ".", "toString", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "InputStream", "||", "object", "instanceof", "Reader", ")", "{", "// Copy stream to stream", "Reader", "reader", ";", "if", "(", "object", "instanceof", "InputStream", ")", "{", "reader", "=", "new", "InputStreamReader", "(", "(", "InputStream", ")", "object", ")", ";", "}", "else", "{", "reader", "=", "(", "Reader", ")", "object", ";", "}", "char", "[", "]", "chars", "=", "new", "char", "[", "8192", "]", ";", "int", "i", ";", "while", "(", "(", "i", "=", "reader", ".", "read", "(", "chars", ")", ")", "!=", "-", "1", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "i", ";", "j", "++", ")", "{", "out", ".", "append", "(", "chars", "[", "j", "]", ")", ";", "}", "}", "reader", ".", "close", "(", ")", ";", "}", "else", "{", "out", ".", "append", "(", "toString", "(", "object", ")", ")", ";", "}", "}" ]
Appends an object to an Appendable using Groovy's default representation for the object.
[ "Appends", "an", "object", "to", "an", "Appendable", "using", "Groovy", "s", "default", "representation", "for", "the", "object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java#L573-L606
12,856
apache/groovy
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
Groovyc.setSrcdir
public void setSrcdir(Path srcDir) { if (src == null) { src = srcDir; } else { src.append(srcDir); } }
java
public void setSrcdir(Path srcDir) { if (src == null) { src = srcDir; } else { src.append(srcDir); } }
[ "public", "void", "setSrcdir", "(", "Path", "srcDir", ")", "{", "if", "(", "src", "==", "null", ")", "{", "src", "=", "srcDir", ";", "}", "else", "{", "src", ".", "append", "(", "srcDir", ")", ";", "}", "}" ]
Set the source directories to find the source Java files. @param srcDir the source directories as a path
[ "Set", "the", "source", "directories", "to", "find", "the", "source", "Java", "files", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java#L251-L257
12,857
apache/groovy
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
Groovyc.setSourcepath
public void setSourcepath(Path sourcepath) { if (compileSourcepath == null) { compileSourcepath = sourcepath; } else { compileSourcepath.append(sourcepath); } }
java
public void setSourcepath(Path sourcepath) { if (compileSourcepath == null) { compileSourcepath = sourcepath; } else { compileSourcepath.append(sourcepath); } }
[ "public", "void", "setSourcepath", "(", "Path", "sourcepath", ")", "{", "if", "(", "compileSourcepath", "==", "null", ")", "{", "compileSourcepath", "=", "sourcepath", ";", "}", "else", "{", "compileSourcepath", ".", "append", "(", "sourcepath", ")", ";", "}", "}" ]
Set the sourcepath to be used for this compilation. @param sourcepath the source path
[ "Set", "the", "sourcepath", "to", "be", "used", "for", "this", "compilation", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java#L343-L349
12,858
apache/groovy
subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java
BindPath.updatePath
public synchronized void updatePath(PropertyChangeListener listener, Object newObject, Set updateSet) { if (currentObject != newObject) { removeListeners(); } if ((children != null) && (children.length > 0)) { try { Object newValue = null; if (newObject != null) { updateSet.add(newObject); newValue = extractNewValue(newObject); } for (BindPath child : children) { child.updatePath(listener, newValue, updateSet); } } catch (Exception e) { //LOGME // do we ignore it, or fail? } } if (currentObject != newObject) { addListeners(listener, newObject, updateSet); } }
java
public synchronized void updatePath(PropertyChangeListener listener, Object newObject, Set updateSet) { if (currentObject != newObject) { removeListeners(); } if ((children != null) && (children.length > 0)) { try { Object newValue = null; if (newObject != null) { updateSet.add(newObject); newValue = extractNewValue(newObject); } for (BindPath child : children) { child.updatePath(listener, newValue, updateSet); } } catch (Exception e) { //LOGME // do we ignore it, or fail? } } if (currentObject != newObject) { addListeners(listener, newObject, updateSet); } }
[ "public", "synchronized", "void", "updatePath", "(", "PropertyChangeListener", "listener", ",", "Object", "newObject", ",", "Set", "updateSet", ")", "{", "if", "(", "currentObject", "!=", "newObject", ")", "{", "removeListeners", "(", ")", ";", "}", "if", "(", "(", "children", "!=", "null", ")", "&&", "(", "children", ".", "length", ">", "0", ")", ")", "{", "try", "{", "Object", "newValue", "=", "null", ";", "if", "(", "newObject", "!=", "null", ")", "{", "updateSet", ".", "add", "(", "newObject", ")", ";", "newValue", "=", "extractNewValue", "(", "newObject", ")", ";", "}", "for", "(", "BindPath", "child", ":", "children", ")", "{", "child", ".", "updatePath", "(", "listener", ",", "newValue", ",", "updateSet", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "//LOGME", "// do we ignore it, or fail?", "}", "}", "if", "(", "currentObject", "!=", "newObject", ")", "{", "addListeners", "(", "listener", ",", "newObject", ",", "updateSet", ")", ";", "}", "}" ]
Called when we detect a change somewhere down our path. First, check to see if our object is changing. If so remove our old listener Next, update the reference object the children have and recurse Finally, add listeners if we have a different object @param listener This listener to attach. @param newObject The object we should read our property off of. @param updateSet The list of objects we have added listeners to
[ "Called", "when", "we", "detect", "a", "change", "somewhere", "down", "our", "path", ".", "First", "check", "to", "see", "if", "our", "object", "is", "changing", ".", "If", "so", "remove", "our", "old", "listener", "Next", "update", "the", "reference", "object", "the", "children", "have", "and", "recurse", "Finally", "add", "listeners", "if", "we", "have", "a", "different", "object" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java#L71-L93
12,859
apache/groovy
subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java
BindPath.addAllListeners
public void addAllListeners(PropertyChangeListener listener, Object newObject, Set updateSet) { addListeners(listener, newObject, updateSet); if ((children != null) && (children.length > 0)) { try { Object newValue = null; if (newObject != null) { updateSet.add(newObject); newValue = extractNewValue(newObject); } for (BindPath child : children) { child.addAllListeners(listener, newValue, updateSet); } } catch (Exception e) { e.printStackTrace(System.out); //LOGME // do we ignore it, or fail? } } }
java
public void addAllListeners(PropertyChangeListener listener, Object newObject, Set updateSet) { addListeners(listener, newObject, updateSet); if ((children != null) && (children.length > 0)) { try { Object newValue = null; if (newObject != null) { updateSet.add(newObject); newValue = extractNewValue(newObject); } for (BindPath child : children) { child.addAllListeners(listener, newValue, updateSet); } } catch (Exception e) { e.printStackTrace(System.out); //LOGME // do we ignore it, or fail? } } }
[ "public", "void", "addAllListeners", "(", "PropertyChangeListener", "listener", ",", "Object", "newObject", ",", "Set", "updateSet", ")", "{", "addListeners", "(", "listener", ",", "newObject", ",", "updateSet", ")", ";", "if", "(", "(", "children", "!=", "null", ")", "&&", "(", "children", ".", "length", ">", "0", ")", ")", "{", "try", "{", "Object", "newValue", "=", "null", ";", "if", "(", "newObject", "!=", "null", ")", "{", "updateSet", ".", "add", "(", "newObject", ")", ";", "newValue", "=", "extractNewValue", "(", "newObject", ")", ";", "}", "for", "(", "BindPath", "child", ":", "children", ")", "{", "child", ".", "addAllListeners", "(", "listener", ",", "newValue", ",", "updateSet", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", "System", ".", "out", ")", ";", "//LOGME", "// do we ignore it, or fail?", "}", "}", "}" ]
Adds all the listeners to the objects in the bind path. This assumes that we are not added as listeners to any of them, hence it is not idempotent. @param listener This listener to attach. @param newObject The object we should read our property off of. @param updateSet The list of objects we have added listeners to
[ "Adds", "all", "the", "listeners", "to", "the", "objects", "in", "the", "bind", "path", ".", "This", "assumes", "that", "we", "are", "not", "added", "as", "listeners", "to", "any", "of", "them", "hence", "it", "is", "not", "idempotent", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java#L104-L122
12,860
apache/groovy
subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java
BindPath.addListeners
public void addListeners(PropertyChangeListener listener, Object newObject, Set updateSet) { removeListeners(); if (newObject != null) { // check for local synthetics TriggerBinding syntheticTrigger = getSyntheticTriggerBinding(newObject); MetaClass mc = InvokerHelper.getMetaClass(newObject); if (syntheticTrigger != null) { PropertyBinding psb = new PropertyBinding(newObject, propertyName); PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding(newObject, propertyName, listener); syntheticFullBinding = syntheticTrigger.createBinding(psb, proxytb); syntheticFullBinding.bind(); updateSet.add(newObject); } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", NAME_PARAMS).isEmpty()) { InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", new Object[] {propertyName, listener}); localListener = listener; updateSet.add(newObject); } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", GLOBAL_PARAMS).isEmpty()) { InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", listener); globalListener = listener; updateSet.add(newObject); } } currentObject = newObject; }
java
public void addListeners(PropertyChangeListener listener, Object newObject, Set updateSet) { removeListeners(); if (newObject != null) { // check for local synthetics TriggerBinding syntheticTrigger = getSyntheticTriggerBinding(newObject); MetaClass mc = InvokerHelper.getMetaClass(newObject); if (syntheticTrigger != null) { PropertyBinding psb = new PropertyBinding(newObject, propertyName); PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding(newObject, propertyName, listener); syntheticFullBinding = syntheticTrigger.createBinding(psb, proxytb); syntheticFullBinding.bind(); updateSet.add(newObject); } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", NAME_PARAMS).isEmpty()) { InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", new Object[] {propertyName, listener}); localListener = listener; updateSet.add(newObject); } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", GLOBAL_PARAMS).isEmpty()) { InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", listener); globalListener = listener; updateSet.add(newObject); } } currentObject = newObject; }
[ "public", "void", "addListeners", "(", "PropertyChangeListener", "listener", ",", "Object", "newObject", ",", "Set", "updateSet", ")", "{", "removeListeners", "(", ")", ";", "if", "(", "newObject", "!=", "null", ")", "{", "// check for local synthetics", "TriggerBinding", "syntheticTrigger", "=", "getSyntheticTriggerBinding", "(", "newObject", ")", ";", "MetaClass", "mc", "=", "InvokerHelper", ".", "getMetaClass", "(", "newObject", ")", ";", "if", "(", "syntheticTrigger", "!=", "null", ")", "{", "PropertyBinding", "psb", "=", "new", "PropertyBinding", "(", "newObject", ",", "propertyName", ")", ";", "PropertyChangeProxyTargetBinding", "proxytb", "=", "new", "PropertyChangeProxyTargetBinding", "(", "newObject", ",", "propertyName", ",", "listener", ")", ";", "syntheticFullBinding", "=", "syntheticTrigger", ".", "createBinding", "(", "psb", ",", "proxytb", ")", ";", "syntheticFullBinding", ".", "bind", "(", ")", ";", "updateSet", ".", "add", "(", "newObject", ")", ";", "}", "else", "if", "(", "!", "mc", ".", "respondsTo", "(", "newObject", ",", "\"addPropertyChangeListener\"", ",", "NAME_PARAMS", ")", ".", "isEmpty", "(", ")", ")", "{", "InvokerHelper", ".", "invokeMethod", "(", "newObject", ",", "\"addPropertyChangeListener\"", ",", "new", "Object", "[", "]", "{", "propertyName", ",", "listener", "}", ")", ";", "localListener", "=", "listener", ";", "updateSet", ".", "add", "(", "newObject", ")", ";", "}", "else", "if", "(", "!", "mc", ".", "respondsTo", "(", "newObject", ",", "\"addPropertyChangeListener\"", ",", "GLOBAL_PARAMS", ")", ".", "isEmpty", "(", ")", ")", "{", "InvokerHelper", ".", "invokeMethod", "(", "newObject", ",", "\"addPropertyChangeListener\"", ",", "listener", ")", ";", "globalListener", "=", "listener", ";", "updateSet", ".", "add", "(", "newObject", ")", ";", "}", "}", "currentObject", "=", "newObject", ";", "}" ]
Add listeners to a specific object. Updates the bould flags and update set @param listener This listener to attach. @param newObject The object we should read our property off of. @param updateSet The list of objects we have added listeners to
[ "Add", "listeners", "to", "a", "specific", "object", ".", "Updates", "the", "bould", "flags", "and", "update", "set" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java#L155-L179
12,861
apache/groovy
subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java
BindPath.removeListeners
public void removeListeners() { if (globalListener != null) { try { InvokerHelper.invokeMethod(currentObject, "removePropertyChangeListener", globalListener); } catch (Exception e) { //LOGME ignore the failure } globalListener = null; } if (localListener != null) { try { InvokerHelper.invokeMethod(currentObject, "removePropertyChangeListener", new Object[] {propertyName, localListener}); } catch (Exception e) { //LOGME ignore the failure } localListener = null; } if (syntheticFullBinding != null) { syntheticFullBinding.unbind(); } }
java
public void removeListeners() { if (globalListener != null) { try { InvokerHelper.invokeMethod(currentObject, "removePropertyChangeListener", globalListener); } catch (Exception e) { //LOGME ignore the failure } globalListener = null; } if (localListener != null) { try { InvokerHelper.invokeMethod(currentObject, "removePropertyChangeListener", new Object[] {propertyName, localListener}); } catch (Exception e) { //LOGME ignore the failure } localListener = null; } if (syntheticFullBinding != null) { syntheticFullBinding.unbind(); } }
[ "public", "void", "removeListeners", "(", ")", "{", "if", "(", "globalListener", "!=", "null", ")", "{", "try", "{", "InvokerHelper", ".", "invokeMethod", "(", "currentObject", ",", "\"removePropertyChangeListener\"", ",", "globalListener", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "//LOGME ignore the failure", "}", "globalListener", "=", "null", ";", "}", "if", "(", "localListener", "!=", "null", ")", "{", "try", "{", "InvokerHelper", ".", "invokeMethod", "(", "currentObject", ",", "\"removePropertyChangeListener\"", ",", "new", "Object", "[", "]", "{", "propertyName", ",", "localListener", "}", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "//LOGME ignore the failure", "}", "localListener", "=", "null", ";", "}", "if", "(", "syntheticFullBinding", "!=", "null", ")", "{", "syntheticFullBinding", ".", "unbind", "(", ")", ";", "}", "}" ]
Remove listeners, believing that our bould flags are accurate and it removes only as declared.
[ "Remove", "listeners", "believing", "that", "our", "bould", "flags", "are", "accurate", "and", "it", "removes", "only", "as", "declared", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/BindPath.java#L185-L205
12,862
apache/groovy
subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/transform/MacroCallTransformingVisitor.java
MacroCallTransformingVisitor.tryMacroMethod
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) { Expression result = (Expression) InvokerHelper.invokeStaticMethod( macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(), macroMethod.getName(), macroArguments ); if (result == null) { // Allow macro methods to return null as an indicator that they didn't match a method call return false; } call.setObjectExpression(MACRO_STUB_INSTANCE); call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME)); // TODO check that we reset everything here call.setSpreadSafe(false); call.setSafe(false); call.setImplicitThis(false); call.setArguments(result); call.setGenericsTypes(GenericsType.EMPTY_ARRAY); return true; }
java
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) { Expression result = (Expression) InvokerHelper.invokeStaticMethod( macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(), macroMethod.getName(), macroArguments ); if (result == null) { // Allow macro methods to return null as an indicator that they didn't match a method call return false; } call.setObjectExpression(MACRO_STUB_INSTANCE); call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME)); // TODO check that we reset everything here call.setSpreadSafe(false); call.setSafe(false); call.setImplicitThis(false); call.setArguments(result); call.setGenericsTypes(GenericsType.EMPTY_ARRAY); return true; }
[ "private", "boolean", "tryMacroMethod", "(", "MethodCallExpression", "call", ",", "ExtensionMethodNode", "macroMethod", ",", "Object", "[", "]", "macroArguments", ")", "{", "Expression", "result", "=", "(", "Expression", ")", "InvokerHelper", ".", "invokeStaticMethod", "(", "macroMethod", ".", "getExtensionMethodNode", "(", ")", ".", "getDeclaringClass", "(", ")", ".", "getTypeClass", "(", ")", ",", "macroMethod", ".", "getName", "(", ")", ",", "macroArguments", ")", ";", "if", "(", "result", "==", "null", ")", "{", "// Allow macro methods to return null as an indicator that they didn't match a method call", "return", "false", ";", "}", "call", ".", "setObjectExpression", "(", "MACRO_STUB_INSTANCE", ")", ";", "call", ".", "setMethod", "(", "new", "ConstantExpression", "(", "MACRO_STUB_METHOD_NAME", ")", ")", ";", "// TODO check that we reset everything here", "call", ".", "setSpreadSafe", "(", "false", ")", ";", "call", ".", "setSafe", "(", "false", ")", ";", "call", ".", "setImplicitThis", "(", "false", ")", ";", "call", ".", "setArguments", "(", "result", ")", ";", "call", ".", "setGenericsTypes", "(", "GenericsType", ".", "EMPTY_ARRAY", ")", ";", "return", "true", ";", "}" ]
Attempts to call given macroMethod @param call MethodCallExpression before the transformation @param macroMethod a macro method candidate @param macroArguments arguments to pass to @return true if call succeeded and current call was transformed
[ "Attempts", "to", "call", "given", "macroMethod" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/transform/MacroCallTransformingVisitor.java#L140-L163
12,863
apache/groovy
src/main/java/org/codehaus/groovy/reflection/CachedField.java
CachedField.setProperty
public void setProperty(final Object object, Object newValue) { AccessPermissionChecker.checkAccessPermission(field); final Object goalValue = DefaultTypeTransformation.castToType(newValue, field.getType()); if (isFinal()) { throw new GroovyRuntimeException("Cannot set the property '" + name + "' because the backing field is final."); } try { field.set(object, goalValue); } catch (IllegalAccessException ex) { throw new GroovyRuntimeException("Cannot set the property '" + name + "'.", ex); } }
java
public void setProperty(final Object object, Object newValue) { AccessPermissionChecker.checkAccessPermission(field); final Object goalValue = DefaultTypeTransformation.castToType(newValue, field.getType()); if (isFinal()) { throw new GroovyRuntimeException("Cannot set the property '" + name + "' because the backing field is final."); } try { field.set(object, goalValue); } catch (IllegalAccessException ex) { throw new GroovyRuntimeException("Cannot set the property '" + name + "'.", ex); } }
[ "public", "void", "setProperty", "(", "final", "Object", "object", ",", "Object", "newValue", ")", "{", "AccessPermissionChecker", ".", "checkAccessPermission", "(", "field", ")", ";", "final", "Object", "goalValue", "=", "DefaultTypeTransformation", ".", "castToType", "(", "newValue", ",", "field", ".", "getType", "(", ")", ")", ";", "if", "(", "isFinal", "(", ")", ")", "{", "throw", "new", "GroovyRuntimeException", "(", "\"Cannot set the property '\"", "+", "name", "+", "\"' because the backing field is final.\"", ")", ";", "}", "try", "{", "field", ".", "set", "(", "object", ",", "goalValue", ")", ";", "}", "catch", "(", "IllegalAccessException", "ex", ")", "{", "throw", "new", "GroovyRuntimeException", "(", "\"Cannot set the property '\"", "+", "name", "+", "\"'.\"", ",", "ex", ")", ";", "}", "}" ]
Sets 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
[ "Sets", "the", "property", "on", "the", "given", "object", "to", "the", "new", "value" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/reflection/CachedField.java#L68-L80
12,864
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v5/PluginDefaultGroovyMethods.java
PluginDefaultGroovyMethods.putAt
public static void putAt(StringBuilder self, IntRange range, Object value) { RangeInfo info = subListBorders(self.length(), range); self.replace(info.from, info.to, value.toString()); }
java
public static void putAt(StringBuilder self, IntRange range, Object value) { RangeInfo info = subListBorders(self.length(), range); self.replace(info.from, info.to, value.toString()); }
[ "public", "static", "void", "putAt", "(", "StringBuilder", "self", ",", "IntRange", "range", ",", "Object", "value", ")", "{", "RangeInfo", "info", "=", "subListBorders", "(", "self", ".", "length", "(", ")", ",", "range", ")", ";", "self", ".", "replace", "(", "info", ".", "from", ",", "info", ".", "to", ",", "value", ".", "toString", "(", ")", ")", ";", "}" ]
Support the range subscript operator for StringBuilder. Index values are treated as characters within the builder. @param self a StringBuilder @param range a Range @param value the object that's toString() will be inserted
[ "Support", "the", "range", "subscript", "operator", "for", "StringBuilder", ".", "Index", "values", "are", "treated", "as", "characters", "within", "the", "builder", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v5/PluginDefaultGroovyMethods.java#L118-L121
12,865
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java
XmlParser.parse
public Node parse(File file) throws IOException, SAXException { InputSource input = new InputSource(new FileInputStream(file)); input.setSystemId("file://" + file.getAbsolutePath()); getXMLReader().parse(input); return parent; }
java
public Node parse(File file) throws IOException, SAXException { InputSource input = new InputSource(new FileInputStream(file)); input.setSystemId("file://" + file.getAbsolutePath()); getXMLReader().parse(input); return parent; }
[ "public", "Node", "parse", "(", "File", "file", ")", "throws", "IOException", ",", "SAXException", "{", "InputSource", "input", "=", "new", "InputSource", "(", "new", "FileInputStream", "(", "file", ")", ")", ";", "input", ".", "setSystemId", "(", "\"file://\"", "+", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "getXMLReader", "(", ")", ".", "parse", "(", "input", ")", ";", "return", "parent", ";", "}" ]
Parses the content of the given file as XML turning it into a tree of Nodes. @param file the File containing the XML to be parsed @return the root node of the parsed tree of Nodes @throws SAXException Any SAX exception, possibly wrapping another exception. @throws IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
[ "Parses", "the", "content", "of", "the", "given", "file", "as", "XML", "turning", "it", "into", "a", "tree", "of", "Nodes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java#L185-L191
12,866
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java
XmlParser.parse
public Node parse(InputSource input) throws IOException, SAXException { getXMLReader().parse(input); return parent; }
java
public Node parse(InputSource input) throws IOException, SAXException { getXMLReader().parse(input); return parent; }
[ "public", "Node", "parse", "(", "InputSource", "input", ")", "throws", "IOException", ",", "SAXException", "{", "getXMLReader", "(", ")", ".", "parse", "(", "input", ")", ";", "return", "parent", ";", "}" ]
Parse the content of the specified input source into a tree of Nodes. @param input the InputSource for the XML to parse @return the root node of the parsed tree of Nodes @throws SAXException Any SAX exception, possibly wrapping another exception. @throws IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
[ "Parse", "the", "content", "of", "the", "specified", "input", "source", "into", "a", "tree", "of", "Nodes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java#L204-L207
12,867
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java
XmlParser.parse
public Node parse(String uri) throws IOException, SAXException { InputSource is = new InputSource(uri); getXMLReader().parse(is); return parent; }
java
public Node parse(String uri) throws IOException, SAXException { InputSource is = new InputSource(uri); getXMLReader().parse(is); return parent; }
[ "public", "Node", "parse", "(", "String", "uri", ")", "throws", "IOException", ",", "SAXException", "{", "InputSource", "is", "=", "new", "InputSource", "(", "uri", ")", ";", "getXMLReader", "(", ")", ".", "parse", "(", "is", ")", ";", "return", "parent", ";", "}" ]
Parse the content of the specified URI into a tree of Nodes. @param uri a String containing a uri pointing to the XML to be parsed @return the root node of the parsed tree of Nodes @throws SAXException Any SAX exception, possibly wrapping another exception. @throws IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
[ "Parse", "the", "content", "of", "the", "specified", "URI", "into", "a", "tree", "of", "Nodes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java#L260-L264
12,868
apache/groovy
subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java
XmlParser.getElementName
protected Object getElementName(String namespaceURI, String localName, String qName) { String name = localName; String prefix = ""; if ((name == null) || (name.length() < 1)) { name = qName; } if (namespaceURI == null || namespaceURI.length() <= 0) { return name; } if (qName != null && qName.length() > 0 && namespaceAware) { int index = qName.lastIndexOf(":"); if (index > 0) { prefix = qName.substring(0, index); } } return new QName(namespaceURI, name, prefix); }
java
protected Object getElementName(String namespaceURI, String localName, String qName) { String name = localName; String prefix = ""; if ((name == null) || (name.length() < 1)) { name = qName; } if (namespaceURI == null || namespaceURI.length() <= 0) { return name; } if (qName != null && qName.length() > 0 && namespaceAware) { int index = qName.lastIndexOf(":"); if (index > 0) { prefix = qName.substring(0, index); } } return new QName(namespaceURI, name, prefix); }
[ "protected", "Object", "getElementName", "(", "String", "namespaceURI", ",", "String", "localName", ",", "String", "qName", ")", "{", "String", "name", "=", "localName", ";", "String", "prefix", "=", "\"\"", ";", "if", "(", "(", "name", "==", "null", ")", "||", "(", "name", ".", "length", "(", ")", "<", "1", ")", ")", "{", "name", "=", "qName", ";", "}", "if", "(", "namespaceURI", "==", "null", "||", "namespaceURI", ".", "length", "(", ")", "<=", "0", ")", "{", "return", "name", ";", "}", "if", "(", "qName", "!=", "null", "&&", "qName", ".", "length", "(", ")", ">", "0", "&&", "namespaceAware", ")", "{", "int", "index", "=", "qName", ".", "lastIndexOf", "(", "\":\"", ")", ";", "if", "(", "index", ">", "0", ")", "{", "prefix", "=", "qName", ".", "substring", "(", "0", ",", "index", ")", ";", "}", "}", "return", "new", "QName", "(", "namespaceURI", ",", "name", ",", "prefix", ")", ";", "}" ]
Return a name given the namespaceURI, localName and qName. @param namespaceURI the namespace URI @param localName the local name @param qName the qualified name @return the newly created representation of the name
[ "Return", "a", "name", "given", "the", "namespaceURI", "localName", "and", "qName", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-xml/src/main/java/groovy/util/XmlParser.java#L485-L501
12,869
apache/groovy
src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java
ClosureSignatureHint.pickGenericType
public static ClassNode pickGenericType(ClassNode type, int gtIndex) { final GenericsType[] genericsTypes = type.getGenericsTypes(); if (genericsTypes==null || genericsTypes.length<gtIndex) { return ClassHelper.OBJECT_TYPE; } return genericsTypes[gtIndex].getType(); }
java
public static ClassNode pickGenericType(ClassNode type, int gtIndex) { final GenericsType[] genericsTypes = type.getGenericsTypes(); if (genericsTypes==null || genericsTypes.length<gtIndex) { return ClassHelper.OBJECT_TYPE; } return genericsTypes[gtIndex].getType(); }
[ "public", "static", "ClassNode", "pickGenericType", "(", "ClassNode", "type", ",", "int", "gtIndex", ")", "{", "final", "GenericsType", "[", "]", "genericsTypes", "=", "type", ".", "getGenericsTypes", "(", ")", ";", "if", "(", "genericsTypes", "==", "null", "||", "genericsTypes", ".", "length", "<", "gtIndex", ")", "{", "return", "ClassHelper", ".", "OBJECT_TYPE", ";", "}", "return", "genericsTypes", "[", "gtIndex", "]", ".", "getType", "(", ")", ";", "}" ]
A helper method which will extract the n-th generic type from a class node. @param type the class node from which to pick a generic type @param gtIndex the index of the generic type to extract @return the n-th generic type, or {@link org.codehaus.groovy.ast.ClassHelper#OBJECT_TYPE} if it doesn't exist.
[ "A", "helper", "method", "which", "will", "extract", "the", "n", "-", "th", "generic", "type", "from", "a", "class", "node", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java#L61-L67
12,870
apache/groovy
src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java
ClosureSignatureHint.pickGenericType
public static ClassNode pickGenericType(MethodNode node, int parameterIndex, int gtIndex) { final Parameter[] parameters = node.getParameters(); final ClassNode type = parameters[parameterIndex].getOriginType(); return pickGenericType(type, gtIndex); }
java
public static ClassNode pickGenericType(MethodNode node, int parameterIndex, int gtIndex) { final Parameter[] parameters = node.getParameters(); final ClassNode type = parameters[parameterIndex].getOriginType(); return pickGenericType(type, gtIndex); }
[ "public", "static", "ClassNode", "pickGenericType", "(", "MethodNode", "node", ",", "int", "parameterIndex", ",", "int", "gtIndex", ")", "{", "final", "Parameter", "[", "]", "parameters", "=", "node", ".", "getParameters", "(", ")", ";", "final", "ClassNode", "type", "=", "parameters", "[", "parameterIndex", "]", ".", "getOriginType", "(", ")", ";", "return", "pickGenericType", "(", "type", ",", "gtIndex", ")", ";", "}" ]
A helper method which will extract the n-th generic type from the n-th parameter of a method node. @param node the method node from which the generic type should be picked @param parameterIndex the index of the parameter in the method parameter list @param gtIndex the index of the generic type to extract @return the generic type, or {@link org.codehaus.groovy.ast.ClassHelper#OBJECT_TYPE} if it doesn't exist.
[ "A", "helper", "method", "which", "will", "extract", "the", "n", "-", "th", "generic", "type", "from", "the", "n", "-", "th", "parameter", "of", "a", "method", "node", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java#L76-L80
12,871
apache/groovy
src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java
ClosureSignatureHint.findClassNode
protected ClassNode findClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String className) { if (className.endsWith("[]")) { return findClassNode(sourceUnit, compilationUnit, className.substring(0, className.length() - 2)).makeArray(); } ClassNode cn = compilationUnit.getClassNode(className); if (cn == null) { try { cn = ClassHelper.make(Class.forName(className, false, sourceUnit.getClassLoader())); } catch (ClassNotFoundException e) { cn = ClassHelper.make(className); } } return cn; }
java
protected ClassNode findClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String className) { if (className.endsWith("[]")) { return findClassNode(sourceUnit, compilationUnit, className.substring(0, className.length() - 2)).makeArray(); } ClassNode cn = compilationUnit.getClassNode(className); if (cn == null) { try { cn = ClassHelper.make(Class.forName(className, false, sourceUnit.getClassLoader())); } catch (ClassNotFoundException e) { cn = ClassHelper.make(className); } } return cn; }
[ "protected", "ClassNode", "findClassNode", "(", "final", "SourceUnit", "sourceUnit", ",", "final", "CompilationUnit", "compilationUnit", ",", "final", "String", "className", ")", "{", "if", "(", "className", ".", "endsWith", "(", "\"[]\"", ")", ")", "{", "return", "findClassNode", "(", "sourceUnit", ",", "compilationUnit", ",", "className", ".", "substring", "(", "0", ",", "className", ".", "length", "(", ")", "-", "2", ")", ")", ".", "makeArray", "(", ")", ";", "}", "ClassNode", "cn", "=", "compilationUnit", ".", "getClassNode", "(", "className", ")", ";", "if", "(", "cn", "==", "null", ")", "{", "try", "{", "cn", "=", "ClassHelper", ".", "make", "(", "Class", ".", "forName", "(", "className", ",", "false", ",", "sourceUnit", ".", "getClassLoader", "(", ")", ")", ")", ";", "}", "catch", "(", "ClassNotFoundException", "e", ")", "{", "cn", "=", "ClassHelper", ".", "make", "(", "className", ")", ";", "}", "}", "return", "cn", ";", "}" ]
Finds a class node given a string representing the type. Performs a lookup in the compilation unit to check if it is done in the same source unit. @param sourceUnit source unit @param compilationUnit compilation unit @param className the name of the class we want to get a {@link org.codehaus.groovy.ast.ClassNode} for @return a ClassNode representing the type
[ "Finds", "a", "class", "node", "given", "a", "string", "representing", "the", "type", ".", "Performs", "a", "lookup", "in", "the", "compilation", "unit", "to", "check", "if", "it", "is", "done", "in", "the", "same", "source", "unit", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/groovy/groovy/transform/stc/ClosureSignatureHint.java#L129-L142
12,872
apache/groovy
src/main/java/org/codehaus/groovy/runtime/powerassert/AssertionRenderer.java
AssertionRenderer.render
public static String render(String text, ValueRecorder recorder) { return new AssertionRenderer(text, recorder).render(); }
java
public static String render(String text, ValueRecorder recorder) { return new AssertionRenderer(text, recorder).render(); }
[ "public", "static", "String", "render", "(", "String", "text", ",", "ValueRecorder", "recorder", ")", "{", "return", "new", "AssertionRenderer", "(", "text", ",", "recorder", ")", ".", "render", "(", ")", ";", "}" ]
Creates a string representation of an assertion and its recorded values. @param text the assertion's source text @param recorder a recorder holding the values recorded during evaluation of the assertion @return a string representation of the assertion and its recorded values
[ "Creates", "a", "string", "representation", "of", "an", "assertion", "and", "its", "recorded", "values", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/powerassert/AssertionRenderer.java#L54-L56
12,873
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
IndyGuardsFiltersAndSignatures.setBeanProperties
public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) { for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = entry.getKey().toString(); Object value = entry.getValue(); mc.setProperty(bean, key, value); } return bean; }
java
public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) { for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = entry.getKey().toString(); Object value = entry.getValue(); mc.setProperty(bean, key, value); } return bean; }
[ "public", "static", "Object", "setBeanProperties", "(", "MetaClass", "mc", ",", "Object", "bean", ",", "Map", "properties", ")", "{", "for", "(", "Iterator", "iter", "=", "properties", ".", "entrySet", "(", ")", ".", "iterator", "(", ")", ";", "iter", ".", "hasNext", "(", ")", ";", ")", "{", "Map", ".", "Entry", "entry", "=", "(", "Map", ".", "Entry", ")", "iter", ".", "next", "(", ")", ";", "String", "key", "=", "entry", ".", "getKey", "(", ")", ".", "toString", "(", ")", ";", "Object", "value", "=", "entry", ".", "getValue", "(", ")", ";", "mc", ".", "setProperty", "(", "bean", ",", "key", ",", "value", ")", ";", "}", "return", "bean", ";", "}" ]
This method is called by he handle to realize the bean constructor with property map.
[ "This", "method", "is", "called", "by", "he", "handle", "to", "realize", "the", "bean", "constructor", "with", "property", "map", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java#L133-L142
12,874
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
IndyGuardsFiltersAndSignatures.isSameMetaClass
public static boolean isSameMetaClass(MetaClass mc, Object receiver) { //TODO: remove this method if possible by switchpoint usage return receiver instanceof GroovyObject && mc==((GroovyObject)receiver).getMetaClass(); }
java
public static boolean isSameMetaClass(MetaClass mc, Object receiver) { //TODO: remove this method if possible by switchpoint usage return receiver instanceof GroovyObject && mc==((GroovyObject)receiver).getMetaClass(); }
[ "public", "static", "boolean", "isSameMetaClass", "(", "MetaClass", "mc", ",", "Object", "receiver", ")", "{", "//TODO: remove this method if possible by switchpoint usage", "return", "receiver", "instanceof", "GroovyObject", "&&", "mc", "==", "(", "(", "GroovyObject", ")", "receiver", ")", ".", "getMetaClass", "(", ")", ";", "}" ]
called by handle
[ "called", "by", "handle" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java#L181-L184
12,875
apache/groovy
src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
IndyGuardsFiltersAndSignatures.sameClass
public static boolean sameClass(Class c, Object o) { if (o==null) return false; return o.getClass() == c; }
java
public static boolean sameClass(Class c, Object o) { if (o==null) return false; return o.getClass() == c; }
[ "public", "static", "boolean", "sameClass", "(", "Class", "c", ",", "Object", "o", ")", "{", "if", "(", "o", "==", "null", ")", "return", "false", ";", "return", "o", ".", "getClass", "(", ")", "==", "c", ";", "}" ]
Guard to check if the provided Object has the same class as the provided Class. This method will return false if the Object is null.
[ "Guard", "to", "check", "if", "the", "provided", "Object", "has", "the", "same", "class", "as", "the", "provided", "Class", ".", "This", "method", "will", "return", "false", "if", "the", "Object", "is", "null", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java#L210-L213
12,876
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
DefaultGroovyStaticMethods.start
public static Thread start(Thread self, Closure closure) { return createThread(null, false, closure); }
java
public static Thread start(Thread self, Closure closure) { return createThread(null, false, closure); }
[ "public", "static", "Thread", "start", "(", "Thread", "self", ",", "Closure", "closure", ")", "{", "return", "createThread", "(", "null", ",", "false", ",", "closure", ")", ";", "}" ]
Start a Thread with the given closure as a Runnable instance. @param self placeholder variable used by Groovy categories; ignored for default static methods @param closure the Runnable closure @return the started thread @since 1.0
[ "Start", "a", "Thread", "with", "the", "given", "closure", "as", "a", "Runnable", "instance", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java#L50-L52
12,877
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
DefaultGroovyStaticMethods.start
public static Thread start(Thread self, String name, Closure closure) { return createThread(name, false, closure); }
java
public static Thread start(Thread self, String name, Closure closure) { return createThread(name, false, closure); }
[ "public", "static", "Thread", "start", "(", "Thread", "self", ",", "String", "name", ",", "Closure", "closure", ")", "{", "return", "createThread", "(", "name", ",", "false", ",", "closure", ")", ";", "}" ]
Start a Thread with a given name and the given closure as a Runnable instance. @param self placeholder variable used by Groovy categories; ignored for default static methods @param name the name to give the thread @param closure the Runnable closure @return the started thread @since 1.6
[ "Start", "a", "Thread", "with", "a", "given", "name", "and", "the", "given", "closure", "as", "a", "Runnable", "instance", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java#L64-L66
12,878
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
DefaultGroovyStaticMethods.startDaemon
public static Thread startDaemon(Thread self, Closure closure) { return createThread(null, true, closure); }
java
public static Thread startDaemon(Thread self, Closure closure) { return createThread(null, true, closure); }
[ "public", "static", "Thread", "startDaemon", "(", "Thread", "self", ",", "Closure", "closure", ")", "{", "return", "createThread", "(", "null", ",", "true", ",", "closure", ")", ";", "}" ]
Start a daemon Thread with the given closure as a Runnable instance. @param self placeholder variable used by Groovy categories; ignored for default static methods @param closure the Runnable closure @return the started thread @since 1.0
[ "Start", "a", "daemon", "Thread", "with", "the", "given", "closure", "as", "a", "Runnable", "instance", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java#L76-L78
12,879
apache/groovy
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
DefaultGroovyStaticMethods.startDaemon
public static Thread startDaemon(Thread self, String name, Closure closure) { return createThread(name, true, closure); }
java
public static Thread startDaemon(Thread self, String name, Closure closure) { return createThread(name, true, closure); }
[ "public", "static", "Thread", "startDaemon", "(", "Thread", "self", ",", "String", "name", ",", "Closure", "closure", ")", "{", "return", "createThread", "(", "name", ",", "true", ",", "closure", ")", ";", "}" ]
Start a daemon Thread with a given name and the given closure as a Runnable instance. @param self placeholder variable used by Groovy categories; ignored for default static methods @param name the name to give the thread @param closure the Runnable closure @return the started thread @since 1.6
[ "Start", "a", "daemon", "Thread", "with", "a", "given", "name", "and", "the", "given", "closure", "as", "a", "Runnable", "instance", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java#L90-L92
12,880
apache/groovy
src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
TraitComposer.createSuperForwarder
private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String,ClassNode> genericsSpec) { List<ClassNode> interfaces = new ArrayList<ClassNode>(Traits.collectAllInterfacesReverseOrder(targetNode, new LinkedHashSet<ClassNode>())); String name = forwarder.getName(); Parameter[] forwarderParameters = forwarder.getParameters(); LinkedHashSet<ClassNode> traits = new LinkedHashSet<ClassNode>(); List<MethodNode> superForwarders = new LinkedList<MethodNode>(); for (ClassNode node : interfaces) { if (Traits.isTrait(node)) { MethodNode method = node.getDeclaredMethod(name, forwarderParameters); if (method!=null) { // a similar method exists, we need a super bridge // trait$super$foo(Class currentTrait, ...) traits.add(node); superForwarders.add(method); } } } for (MethodNode superForwarder : superForwarders) { doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(ClassNode.EMPTY_ARRAY), genericsSpec); } }
java
private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String,ClassNode> genericsSpec) { List<ClassNode> interfaces = new ArrayList<ClassNode>(Traits.collectAllInterfacesReverseOrder(targetNode, new LinkedHashSet<ClassNode>())); String name = forwarder.getName(); Parameter[] forwarderParameters = forwarder.getParameters(); LinkedHashSet<ClassNode> traits = new LinkedHashSet<ClassNode>(); List<MethodNode> superForwarders = new LinkedList<MethodNode>(); for (ClassNode node : interfaces) { if (Traits.isTrait(node)) { MethodNode method = node.getDeclaredMethod(name, forwarderParameters); if (method!=null) { // a similar method exists, we need a super bridge // trait$super$foo(Class currentTrait, ...) traits.add(node); superForwarders.add(method); } } } for (MethodNode superForwarder : superForwarders) { doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(ClassNode.EMPTY_ARRAY), genericsSpec); } }
[ "private", "static", "void", "createSuperForwarder", "(", "ClassNode", "targetNode", ",", "MethodNode", "forwarder", ",", "final", "Map", "<", "String", ",", "ClassNode", ">", "genericsSpec", ")", "{", "List", "<", "ClassNode", ">", "interfaces", "=", "new", "ArrayList", "<", "ClassNode", ">", "(", "Traits", ".", "collectAllInterfacesReverseOrder", "(", "targetNode", ",", "new", "LinkedHashSet", "<", "ClassNode", ">", "(", ")", ")", ")", ";", "String", "name", "=", "forwarder", ".", "getName", "(", ")", ";", "Parameter", "[", "]", "forwarderParameters", "=", "forwarder", ".", "getParameters", "(", ")", ";", "LinkedHashSet", "<", "ClassNode", ">", "traits", "=", "new", "LinkedHashSet", "<", "ClassNode", ">", "(", ")", ";", "List", "<", "MethodNode", ">", "superForwarders", "=", "new", "LinkedList", "<", "MethodNode", ">", "(", ")", ";", "for", "(", "ClassNode", "node", ":", "interfaces", ")", "{", "if", "(", "Traits", ".", "isTrait", "(", "node", ")", ")", "{", "MethodNode", "method", "=", "node", ".", "getDeclaredMethod", "(", "name", ",", "forwarderParameters", ")", ";", "if", "(", "method", "!=", "null", ")", "{", "// a similar method exists, we need a super bridge", "// trait$super$foo(Class currentTrait, ...)", "traits", ".", "add", "(", "node", ")", ";", "superForwarders", ".", "add", "(", "method", ")", ";", "}", "}", "}", "for", "(", "MethodNode", "superForwarder", ":", "superForwarders", ")", "{", "doCreateSuperForwarder", "(", "targetNode", ",", "superForwarder", ",", "traits", ".", "toArray", "(", "ClassNode", ".", "EMPTY_ARRAY", ")", ",", "genericsSpec", ")", ";", "}", "}" ]
Creates, if necessary, a super forwarder method, for stackable traits. @param forwarder a forwarder method @param genericsSpec
[ "Creates", "if", "necessary", "a", "super", "forwarder", "method", "for", "stackable", "traits", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java#L458-L478
12,881
apache/groovy
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
AsmClassGenerator.visitConstantExpression
public void visitConstantExpression(ConstantExpression expression) { final String constantName = expression.getConstantName(); if (controller.isStaticConstructor() || constantName == null) { controller.getOperandStack().pushConstant(expression); } else { controller.getMethodVisitor().visitFieldInsn(GETSTATIC, controller.getInternalClassName(),constantName, BytecodeHelper.getTypeDescription(expression.getType())); controller.getOperandStack().push(expression.getType()); } }
java
public void visitConstantExpression(ConstantExpression expression) { final String constantName = expression.getConstantName(); if (controller.isStaticConstructor() || constantName == null) { controller.getOperandStack().pushConstant(expression); } else { controller.getMethodVisitor().visitFieldInsn(GETSTATIC, controller.getInternalClassName(),constantName, BytecodeHelper.getTypeDescription(expression.getType())); controller.getOperandStack().push(expression.getType()); } }
[ "public", "void", "visitConstantExpression", "(", "ConstantExpression", "expression", ")", "{", "final", "String", "constantName", "=", "expression", ".", "getConstantName", "(", ")", ";", "if", "(", "controller", ".", "isStaticConstructor", "(", ")", "||", "constantName", "==", "null", ")", "{", "controller", ".", "getOperandStack", "(", ")", ".", "pushConstant", "(", "expression", ")", ";", "}", "else", "{", "controller", ".", "getMethodVisitor", "(", ")", ".", "visitFieldInsn", "(", "GETSTATIC", ",", "controller", ".", "getInternalClassName", "(", ")", ",", "constantName", ",", "BytecodeHelper", ".", "getTypeDescription", "(", "expression", ".", "getType", "(", ")", ")", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "push", "(", "expression", ".", "getType", "(", ")", ")", ";", "}", "}" ]
Generate byte code for constants @see <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#14152">Class field types</a>
[ "Generate", "byte", "code", "for", "constants" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java#L752-L760
12,882
apache/groovy
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
AsmClassGenerator.visitBooleanExpression
public void visitBooleanExpression(BooleanExpression expression) { controller.getCompileStack().pushBooleanExpression(); int mark = controller.getOperandStack().getStackLength(); Expression inner = expression.getExpression(); inner.visit(this); controller.getOperandStack().castToBool(mark, true); controller.getCompileStack().pop(); }
java
public void visitBooleanExpression(BooleanExpression expression) { controller.getCompileStack().pushBooleanExpression(); int mark = controller.getOperandStack().getStackLength(); Expression inner = expression.getExpression(); inner.visit(this); controller.getOperandStack().castToBool(mark, true); controller.getCompileStack().pop(); }
[ "public", "void", "visitBooleanExpression", "(", "BooleanExpression", "expression", ")", "{", "controller", ".", "getCompileStack", "(", ")", ".", "pushBooleanExpression", "(", ")", ";", "int", "mark", "=", "controller", ".", "getOperandStack", "(", ")", ".", "getStackLength", "(", ")", ";", "Expression", "inner", "=", "expression", ".", "getExpression", "(", ")", ";", "inner", ".", "visit", "(", "this", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "castToBool", "(", "mark", ",", "true", ")", ";", "controller", ".", "getCompileStack", "(", ")", ".", "pop", "(", ")", ";", "}" ]
return a primitive boolean value of the BooleanExpression. @param expression
[ "return", "a", "primitive", "boolean", "value", "of", "the", "BooleanExpression", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java#L833-L840
12,883
apache/groovy
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
AsmClassGenerator.visitClassExpression
public void visitClassExpression(ClassExpression expression) { ClassNode type = expression.getType(); MethodVisitor mv = controller.getMethodVisitor(); if (BytecodeHelper.isClassLiteralPossible(type) || BytecodeHelper.isSameCompilationUnit(controller.getClassNode(), type)) { if (controller.getClassNode().isInterface()) { InterfaceHelperClassNode interfaceClassLoadingClass = controller.getInterfaceClassLoadingClass(); if (BytecodeHelper.isClassLiteralPossible(interfaceClassLoadingClass)) { BytecodeHelper.visitClassLiteral(mv, interfaceClassLoadingClass); controller.getOperandStack().push(ClassHelper.CLASS_Type); return; } } else { BytecodeHelper.visitClassLiteral(mv, type); controller.getOperandStack().push(ClassHelper.CLASS_Type); return; } } String staticFieldName = getStaticFieldName(type); referencedClasses.put(staticFieldName, type); String internalClassName = controller.getInternalClassName(); if (controller.getClassNode().isInterface()) { internalClassName = BytecodeHelper.getClassInternalName(controller.getInterfaceClassLoadingClass()); mv.visitFieldInsn(GETSTATIC, internalClassName, staticFieldName, "Ljava/lang/Class;"); } else { mv.visitMethodInsn(INVOKESTATIC, internalClassName, "$get$" + staticFieldName, "()Ljava/lang/Class;", false); } controller.getOperandStack().push(ClassHelper.CLASS_Type); }
java
public void visitClassExpression(ClassExpression expression) { ClassNode type = expression.getType(); MethodVisitor mv = controller.getMethodVisitor(); if (BytecodeHelper.isClassLiteralPossible(type) || BytecodeHelper.isSameCompilationUnit(controller.getClassNode(), type)) { if (controller.getClassNode().isInterface()) { InterfaceHelperClassNode interfaceClassLoadingClass = controller.getInterfaceClassLoadingClass(); if (BytecodeHelper.isClassLiteralPossible(interfaceClassLoadingClass)) { BytecodeHelper.visitClassLiteral(mv, interfaceClassLoadingClass); controller.getOperandStack().push(ClassHelper.CLASS_Type); return; } } else { BytecodeHelper.visitClassLiteral(mv, type); controller.getOperandStack().push(ClassHelper.CLASS_Type); return; } } String staticFieldName = getStaticFieldName(type); referencedClasses.put(staticFieldName, type); String internalClassName = controller.getInternalClassName(); if (controller.getClassNode().isInterface()) { internalClassName = BytecodeHelper.getClassInternalName(controller.getInterfaceClassLoadingClass()); mv.visitFieldInsn(GETSTATIC, internalClassName, staticFieldName, "Ljava/lang/Class;"); } else { mv.visitMethodInsn(INVOKESTATIC, internalClassName, "$get$" + staticFieldName, "()Ljava/lang/Class;", false); } controller.getOperandStack().push(ClassHelper.CLASS_Type); }
[ "public", "void", "visitClassExpression", "(", "ClassExpression", "expression", ")", "{", "ClassNode", "type", "=", "expression", ".", "getType", "(", ")", ";", "MethodVisitor", "mv", "=", "controller", ".", "getMethodVisitor", "(", ")", ";", "if", "(", "BytecodeHelper", ".", "isClassLiteralPossible", "(", "type", ")", "||", "BytecodeHelper", ".", "isSameCompilationUnit", "(", "controller", ".", "getClassNode", "(", ")", ",", "type", ")", ")", "{", "if", "(", "controller", ".", "getClassNode", "(", ")", ".", "isInterface", "(", ")", ")", "{", "InterfaceHelperClassNode", "interfaceClassLoadingClass", "=", "controller", ".", "getInterfaceClassLoadingClass", "(", ")", ";", "if", "(", "BytecodeHelper", ".", "isClassLiteralPossible", "(", "interfaceClassLoadingClass", ")", ")", "{", "BytecodeHelper", ".", "visitClassLiteral", "(", "mv", ",", "interfaceClassLoadingClass", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "push", "(", "ClassHelper", ".", "CLASS_Type", ")", ";", "return", ";", "}", "}", "else", "{", "BytecodeHelper", ".", "visitClassLiteral", "(", "mv", ",", "type", ")", ";", "controller", ".", "getOperandStack", "(", ")", ".", "push", "(", "ClassHelper", ".", "CLASS_Type", ")", ";", "return", ";", "}", "}", "String", "staticFieldName", "=", "getStaticFieldName", "(", "type", ")", ";", "referencedClasses", ".", "put", "(", "staticFieldName", ",", "type", ")", ";", "String", "internalClassName", "=", "controller", ".", "getInternalClassName", "(", ")", ";", "if", "(", "controller", ".", "getClassNode", "(", ")", ".", "isInterface", "(", ")", ")", "{", "internalClassName", "=", "BytecodeHelper", ".", "getClassInternalName", "(", "controller", ".", "getInterfaceClassLoadingClass", "(", ")", ")", ";", "mv", ".", "visitFieldInsn", "(", "GETSTATIC", ",", "internalClassName", ",", "staticFieldName", ",", "\"Ljava/lang/Class;\"", ")", ";", "}", "else", "{", "mv", ".", "visitMethodInsn", "(", "INVOKESTATIC", ",", "internalClassName", ",", "\"$get$\"", "+", "staticFieldName", ",", "\"()Ljava/lang/Class;\"", ",", "false", ")", ";", "}", "controller", ".", "getOperandStack", "(", ")", ".", "push", "(", "ClassHelper", ".", "CLASS_Type", ")", ";", "}" ]
load class object on stack
[ "load", "class", "object", "on", "stack" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java#L1539-L1567
12,884
apache/groovy
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
AsmClassGenerator.visitAnnotationAttributes
private void visitAnnotationAttributes(AnnotationNode an, AnnotationVisitor av) { Map<String, Object> constantAttrs = new HashMap<String, Object>(); Map<String, PropertyExpression> enumAttrs = new HashMap<String, PropertyExpression>(); Map<String, Object> atAttrs = new HashMap<String, Object>(); Map<String, ListExpression> arrayAttrs = new HashMap<String, ListExpression>(); for (String name : an.getMembers().keySet()) { Expression expr = an.getMember(name); if (expr instanceof AnnotationConstantExpression) { atAttrs.put(name, ((AnnotationConstantExpression) expr).getValue()); } else if (expr instanceof ConstantExpression) { constantAttrs.put(name, ((ConstantExpression) expr).getValue()); } else if (expr instanceof ClassExpression) { constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription((expr.getType())))); } else if (expr instanceof PropertyExpression) { enumAttrs.put(name, (PropertyExpression) expr); } else if (expr instanceof ListExpression) { arrayAttrs.put(name, (ListExpression) expr); } else if (expr instanceof ClosureExpression) { ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) expr, ACC_PUBLIC); constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription(closureClass))); } } for (Map.Entry entry : constantAttrs.entrySet()) { av.visit((String) entry.getKey(), entry.getValue()); } for (Map.Entry entry : enumAttrs.entrySet()) { PropertyExpression propExp = (PropertyExpression) entry.getValue(); av.visitEnum((String) entry.getKey(), BytecodeHelper.getTypeDescription(propExp.getObjectExpression().getType()), String.valueOf(((ConstantExpression) propExp.getProperty()).getValue())); } for (Map.Entry entry : atAttrs.entrySet()) { AnnotationNode atNode = (AnnotationNode) entry.getValue(); AnnotationVisitor av2 = av.visitAnnotation((String) entry.getKey(), BytecodeHelper.getTypeDescription(atNode.getClassNode())); visitAnnotationAttributes(atNode, av2); av2.visitEnd(); } visitArrayAttributes(an, arrayAttrs, av); }
java
private void visitAnnotationAttributes(AnnotationNode an, AnnotationVisitor av) { Map<String, Object> constantAttrs = new HashMap<String, Object>(); Map<String, PropertyExpression> enumAttrs = new HashMap<String, PropertyExpression>(); Map<String, Object> atAttrs = new HashMap<String, Object>(); Map<String, ListExpression> arrayAttrs = new HashMap<String, ListExpression>(); for (String name : an.getMembers().keySet()) { Expression expr = an.getMember(name); if (expr instanceof AnnotationConstantExpression) { atAttrs.put(name, ((AnnotationConstantExpression) expr).getValue()); } else if (expr instanceof ConstantExpression) { constantAttrs.put(name, ((ConstantExpression) expr).getValue()); } else if (expr instanceof ClassExpression) { constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription((expr.getType())))); } else if (expr instanceof PropertyExpression) { enumAttrs.put(name, (PropertyExpression) expr); } else if (expr instanceof ListExpression) { arrayAttrs.put(name, (ListExpression) expr); } else if (expr instanceof ClosureExpression) { ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) expr, ACC_PUBLIC); constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription(closureClass))); } } for (Map.Entry entry : constantAttrs.entrySet()) { av.visit((String) entry.getKey(), entry.getValue()); } for (Map.Entry entry : enumAttrs.entrySet()) { PropertyExpression propExp = (PropertyExpression) entry.getValue(); av.visitEnum((String) entry.getKey(), BytecodeHelper.getTypeDescription(propExp.getObjectExpression().getType()), String.valueOf(((ConstantExpression) propExp.getProperty()).getValue())); } for (Map.Entry entry : atAttrs.entrySet()) { AnnotationNode atNode = (AnnotationNode) entry.getValue(); AnnotationVisitor av2 = av.visitAnnotation((String) entry.getKey(), BytecodeHelper.getTypeDescription(atNode.getClassNode())); visitAnnotationAttributes(atNode, av2); av2.visitEnd(); } visitArrayAttributes(an, arrayAttrs, av); }
[ "private", "void", "visitAnnotationAttributes", "(", "AnnotationNode", "an", ",", "AnnotationVisitor", "av", ")", "{", "Map", "<", "String", ",", "Object", ">", "constantAttrs", "=", "new", "HashMap", "<", "String", ",", "Object", ">", "(", ")", ";", "Map", "<", "String", ",", "PropertyExpression", ">", "enumAttrs", "=", "new", "HashMap", "<", "String", ",", "PropertyExpression", ">", "(", ")", ";", "Map", "<", "String", ",", "Object", ">", "atAttrs", "=", "new", "HashMap", "<", "String", ",", "Object", ">", "(", ")", ";", "Map", "<", "String", ",", "ListExpression", ">", "arrayAttrs", "=", "new", "HashMap", "<", "String", ",", "ListExpression", ">", "(", ")", ";", "for", "(", "String", "name", ":", "an", ".", "getMembers", "(", ")", ".", "keySet", "(", ")", ")", "{", "Expression", "expr", "=", "an", ".", "getMember", "(", "name", ")", ";", "if", "(", "expr", "instanceof", "AnnotationConstantExpression", ")", "{", "atAttrs", ".", "put", "(", "name", ",", "(", "(", "AnnotationConstantExpression", ")", "expr", ")", ".", "getValue", "(", ")", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "ConstantExpression", ")", "{", "constantAttrs", ".", "put", "(", "name", ",", "(", "(", "ConstantExpression", ")", "expr", ")", ".", "getValue", "(", ")", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "ClassExpression", ")", "{", "constantAttrs", ".", "put", "(", "name", ",", "Type", ".", "getType", "(", "BytecodeHelper", ".", "getTypeDescription", "(", "(", "expr", ".", "getType", "(", ")", ")", ")", ")", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "PropertyExpression", ")", "{", "enumAttrs", ".", "put", "(", "name", ",", "(", "PropertyExpression", ")", "expr", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "ListExpression", ")", "{", "arrayAttrs", ".", "put", "(", "name", ",", "(", "ListExpression", ")", "expr", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "ClosureExpression", ")", "{", "ClassNode", "closureClass", "=", "controller", ".", "getClosureWriter", "(", ")", ".", "getOrAddClosureClass", "(", "(", "ClosureExpression", ")", "expr", ",", "ACC_PUBLIC", ")", ";", "constantAttrs", ".", "put", "(", "name", ",", "Type", ".", "getType", "(", "BytecodeHelper", ".", "getTypeDescription", "(", "closureClass", ")", ")", ")", ";", "}", "}", "for", "(", "Map", ".", "Entry", "entry", ":", "constantAttrs", ".", "entrySet", "(", ")", ")", "{", "av", ".", "visit", "(", "(", "String", ")", "entry", ".", "getKey", "(", ")", ",", "entry", ".", "getValue", "(", ")", ")", ";", "}", "for", "(", "Map", ".", "Entry", "entry", ":", "enumAttrs", ".", "entrySet", "(", ")", ")", "{", "PropertyExpression", "propExp", "=", "(", "PropertyExpression", ")", "entry", ".", "getValue", "(", ")", ";", "av", ".", "visitEnum", "(", "(", "String", ")", "entry", ".", "getKey", "(", ")", ",", "BytecodeHelper", ".", "getTypeDescription", "(", "propExp", ".", "getObjectExpression", "(", ")", ".", "getType", "(", ")", ")", ",", "String", ".", "valueOf", "(", "(", "(", "ConstantExpression", ")", "propExp", ".", "getProperty", "(", ")", ")", ".", "getValue", "(", ")", ")", ")", ";", "}", "for", "(", "Map", ".", "Entry", "entry", ":", "atAttrs", ".", "entrySet", "(", ")", ")", "{", "AnnotationNode", "atNode", "=", "(", "AnnotationNode", ")", "entry", ".", "getValue", "(", ")", ";", "AnnotationVisitor", "av2", "=", "av", ".", "visitAnnotation", "(", "(", "String", ")", "entry", ".", "getKey", "(", ")", ",", "BytecodeHelper", ".", "getTypeDescription", "(", "atNode", ".", "getClassNode", "(", ")", ")", ")", ";", "visitAnnotationAttributes", "(", "atNode", ",", "av2", ")", ";", "av2", ".", "visitEnd", "(", ")", ";", "}", "visitArrayAttributes", "(", "an", ",", "arrayAttrs", ",", "av", ")", ";", "}" ]
Generate the annotation attributes. @param an the node with an annotation @param av the visitor to use
[ "Generate", "the", "annotation", "attributes", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java#L2090-L2133
12,885
apache/groovy
src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java
NewifyASTTransformation.determineClasses
private ListExpression determineClasses(Expression expr, boolean searchSourceUnit) { ListExpression list = new ListExpression(); if (expr instanceof ClassExpression) { list.addExpression(expr); } else if (expr instanceof VariableExpression && searchSourceUnit) { VariableExpression ve = (VariableExpression) expr; ClassNode fromSourceUnit = getSourceUnitClass(ve); if (fromSourceUnit != null) { ClassExpression found = classX(fromSourceUnit); found.setSourcePosition(ve); list.addExpression(found); } else { addError(BASE_BAD_PARAM_ERROR + "an unresolvable reference to '" + ve.getName() + "'.", expr); } } else if (expr instanceof ListExpression) { list = (ListExpression) expr; final List<Expression> expressions = list.getExpressions(); for (int i = 0; i < expressions.size(); i++) { Expression next = expressions.get(i); if (next instanceof VariableExpression && searchSourceUnit) { VariableExpression ve = (VariableExpression) next; ClassNode fromSourceUnit = getSourceUnitClass(ve); if (fromSourceUnit != null) { ClassExpression found = classX(fromSourceUnit); found.setSourcePosition(ve); expressions.set(i, found); } else { addError(BASE_BAD_PARAM_ERROR + "a list containing an unresolvable reference to '" + ve.getName() + "'.", next); } } else if (!(next instanceof ClassExpression)) { addError(BASE_BAD_PARAM_ERROR + "a list containing type: " + next.getType().getName() + ".", next); } } checkDuplicateNameClashes(list); } else if (expr != null) { addError(BASE_BAD_PARAM_ERROR + "a type: " + expr.getType().getName() + ".", expr); } return list; }
java
private ListExpression determineClasses(Expression expr, boolean searchSourceUnit) { ListExpression list = new ListExpression(); if (expr instanceof ClassExpression) { list.addExpression(expr); } else if (expr instanceof VariableExpression && searchSourceUnit) { VariableExpression ve = (VariableExpression) expr; ClassNode fromSourceUnit = getSourceUnitClass(ve); if (fromSourceUnit != null) { ClassExpression found = classX(fromSourceUnit); found.setSourcePosition(ve); list.addExpression(found); } else { addError(BASE_BAD_PARAM_ERROR + "an unresolvable reference to '" + ve.getName() + "'.", expr); } } else if (expr instanceof ListExpression) { list = (ListExpression) expr; final List<Expression> expressions = list.getExpressions(); for (int i = 0; i < expressions.size(); i++) { Expression next = expressions.get(i); if (next instanceof VariableExpression && searchSourceUnit) { VariableExpression ve = (VariableExpression) next; ClassNode fromSourceUnit = getSourceUnitClass(ve); if (fromSourceUnit != null) { ClassExpression found = classX(fromSourceUnit); found.setSourcePosition(ve); expressions.set(i, found); } else { addError(BASE_BAD_PARAM_ERROR + "a list containing an unresolvable reference to '" + ve.getName() + "'.", next); } } else if (!(next instanceof ClassExpression)) { addError(BASE_BAD_PARAM_ERROR + "a list containing type: " + next.getType().getName() + ".", next); } } checkDuplicateNameClashes(list); } else if (expr != null) { addError(BASE_BAD_PARAM_ERROR + "a type: " + expr.getType().getName() + ".", expr); } return list; }
[ "private", "ListExpression", "determineClasses", "(", "Expression", "expr", ",", "boolean", "searchSourceUnit", ")", "{", "ListExpression", "list", "=", "new", "ListExpression", "(", ")", ";", "if", "(", "expr", "instanceof", "ClassExpression", ")", "{", "list", ".", "addExpression", "(", "expr", ")", ";", "}", "else", "if", "(", "expr", "instanceof", "VariableExpression", "&&", "searchSourceUnit", ")", "{", "VariableExpression", "ve", "=", "(", "VariableExpression", ")", "expr", ";", "ClassNode", "fromSourceUnit", "=", "getSourceUnitClass", "(", "ve", ")", ";", "if", "(", "fromSourceUnit", "!=", "null", ")", "{", "ClassExpression", "found", "=", "classX", "(", "fromSourceUnit", ")", ";", "found", ".", "setSourcePosition", "(", "ve", ")", ";", "list", ".", "addExpression", "(", "found", ")", ";", "}", "else", "{", "addError", "(", "BASE_BAD_PARAM_ERROR", "+", "\"an unresolvable reference to '\"", "+", "ve", ".", "getName", "(", ")", "+", "\"'.\"", ",", "expr", ")", ";", "}", "}", "else", "if", "(", "expr", "instanceof", "ListExpression", ")", "{", "list", "=", "(", "ListExpression", ")", "expr", ";", "final", "List", "<", "Expression", ">", "expressions", "=", "list", ".", "getExpressions", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "expressions", ".", "size", "(", ")", ";", "i", "++", ")", "{", "Expression", "next", "=", "expressions", ".", "get", "(", "i", ")", ";", "if", "(", "next", "instanceof", "VariableExpression", "&&", "searchSourceUnit", ")", "{", "VariableExpression", "ve", "=", "(", "VariableExpression", ")", "next", ";", "ClassNode", "fromSourceUnit", "=", "getSourceUnitClass", "(", "ve", ")", ";", "if", "(", "fromSourceUnit", "!=", "null", ")", "{", "ClassExpression", "found", "=", "classX", "(", "fromSourceUnit", ")", ";", "found", ".", "setSourcePosition", "(", "ve", ")", ";", "expressions", ".", "set", "(", "i", ",", "found", ")", ";", "}", "else", "{", "addError", "(", "BASE_BAD_PARAM_ERROR", "+", "\"a list containing an unresolvable reference to '\"", "+", "ve", ".", "getName", "(", ")", "+", "\"'.\"", ",", "next", ")", ";", "}", "}", "else", "if", "(", "!", "(", "next", "instanceof", "ClassExpression", ")", ")", "{", "addError", "(", "BASE_BAD_PARAM_ERROR", "+", "\"a list containing type: \"", "+", "next", ".", "getType", "(", ")", ".", "getName", "(", ")", "+", "\".\"", ",", "next", ")", ";", "}", "}", "checkDuplicateNameClashes", "(", "list", ")", ";", "}", "else", "if", "(", "expr", "!=", "null", ")", "{", "addError", "(", "BASE_BAD_PARAM_ERROR", "+", "\"a type: \"", "+", "expr", ".", "getType", "(", ")", ".", "getName", "(", ")", "+", "\".\"", ",", "expr", ")", ";", "}", "return", "list", ";", "}" ]
allow non-strict mode in scripts because parsing not complete at that point
[ "allow", "non", "-", "strict", "mode", "in", "scripts", "because", "parsing", "not", "complete", "at", "that", "point" ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java#L249-L287
12,886
apache/groovy
src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
MethodNodeUtils.methodDescriptorWithoutReturnType
public static String methodDescriptorWithoutReturnType(MethodNode mNode) { StringBuilder sb = new StringBuilder(); sb.append(mNode.getName()).append(':'); for (Parameter p : mNode.getParameters()) { sb.append(ClassNodeUtils.formatTypeName(p.getType())).append(','); } return sb.toString(); }
java
public static String methodDescriptorWithoutReturnType(MethodNode mNode) { StringBuilder sb = new StringBuilder(); sb.append(mNode.getName()).append(':'); for (Parameter p : mNode.getParameters()) { sb.append(ClassNodeUtils.formatTypeName(p.getType())).append(','); } return sb.toString(); }
[ "public", "static", "String", "methodDescriptorWithoutReturnType", "(", "MethodNode", "mNode", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "mNode", ".", "getName", "(", ")", ")", ".", "append", "(", "'", "'", ")", ";", "for", "(", "Parameter", "p", ":", "mNode", ".", "getParameters", "(", ")", ")", "{", "sb", ".", "append", "(", "ClassNodeUtils", ".", "formatTypeName", "(", "p", ".", "getType", "(", ")", ")", ")", ".", "append", "(", "'", "'", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Return the method node's descriptor including its name and parameter types without generics. @param mNode the method node @return the method node's abbreviated descriptor excluding the return type
[ "Return", "the", "method", "node", "s", "descriptor", "including", "its", "name", "and", "parameter", "types", "without", "generics", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java#L38-L45
12,887
apache/groovy
src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
MethodNodeUtils.methodDescriptor
public static String methodDescriptor(MethodNode mNode) { StringBuilder sb = new StringBuilder(mNode.getName().length() + mNode.getParameters().length * 10); sb.append(mNode.getReturnType().getName()); sb.append(' '); sb.append(mNode.getName()); sb.append('('); for (int i = 0; i < mNode.getParameters().length; i++) { if (i > 0) { sb.append(", "); } Parameter p = mNode.getParameters()[i]; sb.append(ClassNodeUtils.formatTypeName(p.getType())); } sb.append(')'); return sb.toString(); }
java
public static String methodDescriptor(MethodNode mNode) { StringBuilder sb = new StringBuilder(mNode.getName().length() + mNode.getParameters().length * 10); sb.append(mNode.getReturnType().getName()); sb.append(' '); sb.append(mNode.getName()); sb.append('('); for (int i = 0; i < mNode.getParameters().length; i++) { if (i > 0) { sb.append(", "); } Parameter p = mNode.getParameters()[i]; sb.append(ClassNodeUtils.formatTypeName(p.getType())); } sb.append(')'); return sb.toString(); }
[ "public", "static", "String", "methodDescriptor", "(", "MethodNode", "mNode", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "mNode", ".", "getName", "(", ")", ".", "length", "(", ")", "+", "mNode", ".", "getParameters", "(", ")", ".", "length", "*", "10", ")", ";", "sb", ".", "append", "(", "mNode", ".", "getReturnType", "(", ")", ".", "getName", "(", ")", ")", ";", "sb", ".", "append", "(", "'", "'", ")", ";", "sb", ".", "append", "(", "mNode", ".", "getName", "(", ")", ")", ";", "sb", ".", "append", "(", "'", "'", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mNode", ".", "getParameters", "(", ")", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", ">", "0", ")", "{", "sb", ".", "append", "(", "\", \"", ")", ";", "}", "Parameter", "p", "=", "mNode", ".", "getParameters", "(", ")", "[", "i", "]", ";", "sb", ".", "append", "(", "ClassNodeUtils", ".", "formatTypeName", "(", "p", ".", "getType", "(", ")", ")", ")", ";", "}", "sb", ".", "append", "(", "'", "'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Return the method node's descriptor which includes its return type, name and parameter types without generics. @param mNode the method node @return the method node's descriptor
[ "Return", "the", "method", "node", "s", "descriptor", "which", "includes", "its", "return", "type", "name", "and", "parameter", "types", "without", "generics", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java#L54-L69
12,888
apache/groovy
src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
MethodNodeUtils.getPropertyName
public static String getPropertyName(MethodNode mNode) { String name = mNode.getName(); if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) { String pname = decapitalize(name.substring(name.startsWith("is") ? 2 : 3)); if (!pname.isEmpty()) { if (name.startsWith("set")) { if (mNode.getParameters().length == 1) { return pname; } } else if (mNode.getParameters().length == 0 && !ClassHelper.VOID_TYPE.equals(mNode.getReturnType())) { if (name.startsWith("get") || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) { return pname; } } } } return null; }
java
public static String getPropertyName(MethodNode mNode) { String name = mNode.getName(); if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) { String pname = decapitalize(name.substring(name.startsWith("is") ? 2 : 3)); if (!pname.isEmpty()) { if (name.startsWith("set")) { if (mNode.getParameters().length == 1) { return pname; } } else if (mNode.getParameters().length == 0 && !ClassHelper.VOID_TYPE.equals(mNode.getReturnType())) { if (name.startsWith("get") || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) { return pname; } } } } return null; }
[ "public", "static", "String", "getPropertyName", "(", "MethodNode", "mNode", ")", "{", "String", "name", "=", "mNode", ".", "getName", "(", ")", ";", "if", "(", "name", ".", "startsWith", "(", "\"set\"", ")", "||", "name", ".", "startsWith", "(", "\"get\"", ")", "||", "name", ".", "startsWith", "(", "\"is\"", ")", ")", "{", "String", "pname", "=", "decapitalize", "(", "name", ".", "substring", "(", "name", ".", "startsWith", "(", "\"is\"", ")", "?", "2", ":", "3", ")", ")", ";", "if", "(", "!", "pname", ".", "isEmpty", "(", ")", ")", "{", "if", "(", "name", ".", "startsWith", "(", "\"set\"", ")", ")", "{", "if", "(", "mNode", ".", "getParameters", "(", ")", ".", "length", "==", "1", ")", "{", "return", "pname", ";", "}", "}", "else", "if", "(", "mNode", ".", "getParameters", "(", ")", ".", "length", "==", "0", "&&", "!", "ClassHelper", ".", "VOID_TYPE", ".", "equals", "(", "mNode", ".", "getReturnType", "(", ")", ")", ")", "{", "if", "(", "name", ".", "startsWith", "(", "\"get\"", ")", "||", "ClassHelper", ".", "boolean_TYPE", ".", "equals", "(", "mNode", ".", "getReturnType", "(", ")", ")", ")", "{", "return", "pname", ";", "}", "}", "}", "}", "return", "null", ";", "}" ]
For a method node potentially representing a property, returns the name of the property. @param mNode a MethodNode @return the property name without the get/set/is prefix if a property or null
[ "For", "a", "method", "node", "potentially", "representing", "a", "property", "returns", "the", "name", "of", "the", "property", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java#L77-L94
12,889
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.isIntCategory
public static boolean isIntCategory(ClassNode type) { return type==byte_TYPE || type==char_TYPE || type==int_TYPE || type==short_TYPE; }
java
public static boolean isIntCategory(ClassNode type) { return type==byte_TYPE || type==char_TYPE || type==int_TYPE || type==short_TYPE; }
[ "public", "static", "boolean", "isIntCategory", "(", "ClassNode", "type", ")", "{", "return", "type", "==", "byte_TYPE", "||", "type", "==", "char_TYPE", "||", "type", "==", "int_TYPE", "||", "type", "==", "short_TYPE", ";", "}" ]
It is of an int category, if the provided type is a byte, char, short, int.
[ "It", "is", "of", "an", "int", "category", "if", "the", "provided", "type", "is", "a", "byte", "char", "short", "int", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L134-L137
12,890
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.lowestUpperBound
public static ClassNode lowestUpperBound(List<ClassNode> nodes) { if (nodes.size()==1) return nodes.get(0); return lowestUpperBound(nodes.get(0), lowestUpperBound(nodes.subList(1, nodes.size()))); }
java
public static ClassNode lowestUpperBound(List<ClassNode> nodes) { if (nodes.size()==1) return nodes.get(0); return lowestUpperBound(nodes.get(0), lowestUpperBound(nodes.subList(1, nodes.size()))); }
[ "public", "static", "ClassNode", "lowestUpperBound", "(", "List", "<", "ClassNode", ">", "nodes", ")", "{", "if", "(", "nodes", ".", "size", "(", ")", "==", "1", ")", "return", "nodes", ".", "get", "(", "0", ")", ";", "return", "lowestUpperBound", "(", "nodes", ".", "get", "(", "0", ")", ",", "lowestUpperBound", "(", "nodes", ".", "subList", "(", "1", ",", "nodes", ".", "size", "(", ")", ")", ")", ")", ";", "}" ]
Given a list of class nodes, returns the first common supertype. For example, Double and Float would return Number, while Set and String would return Object. @param nodes the list of nodes for which to find the first common super type. @return first common supertype
[ "Given", "a", "list", "of", "class", "nodes", "returns", "the", "first", "common", "supertype", ".", "For", "example", "Double", "and", "Float", "would", "return", "Number", "while", "Set", "and", "String", "would", "return", "Object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L187-L190
12,891
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.lowestUpperBound
public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) { ClassNode lub = lowestUpperBound(a, b, null, null); if (lub==null || !lub.isUsingGenerics()) return lub; // types may be parameterized. If so, we must ensure that generic type arguments // are made compatible if (lub instanceof LowestUpperBoundClassNode) { // no parent super class representing both types could be found // or both class nodes implement common interfaces which may have // been parameterized differently. // We must create a classnode for which the "superclass" is potentially parameterized // plus the interfaces ClassNode superClass = lub.getSuperClass(); ClassNode psc = superClass.isUsingGenerics()?parameterizeLowestUpperBound(superClass, a, b, lub):superClass; ClassNode[] interfaces = lub.getInterfaces(); ClassNode[] pinterfaces = new ClassNode[interfaces.length]; for (int i = 0, interfacesLength = interfaces.length; i < interfacesLength; i++) { final ClassNode icn = interfaces[i]; if (icn.isUsingGenerics()) { pinterfaces[i] = parameterizeLowestUpperBound(icn, a, b, lub); } else { pinterfaces[i] = icn; } } return new LowestUpperBoundClassNode(((LowestUpperBoundClassNode)lub).name, psc, pinterfaces); } else { return parameterizeLowestUpperBound(lub, a, b, lub); } }
java
public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) { ClassNode lub = lowestUpperBound(a, b, null, null); if (lub==null || !lub.isUsingGenerics()) return lub; // types may be parameterized. If so, we must ensure that generic type arguments // are made compatible if (lub instanceof LowestUpperBoundClassNode) { // no parent super class representing both types could be found // or both class nodes implement common interfaces which may have // been parameterized differently. // We must create a classnode for which the "superclass" is potentially parameterized // plus the interfaces ClassNode superClass = lub.getSuperClass(); ClassNode psc = superClass.isUsingGenerics()?parameterizeLowestUpperBound(superClass, a, b, lub):superClass; ClassNode[] interfaces = lub.getInterfaces(); ClassNode[] pinterfaces = new ClassNode[interfaces.length]; for (int i = 0, interfacesLength = interfaces.length; i < interfacesLength; i++) { final ClassNode icn = interfaces[i]; if (icn.isUsingGenerics()) { pinterfaces[i] = parameterizeLowestUpperBound(icn, a, b, lub); } else { pinterfaces[i] = icn; } } return new LowestUpperBoundClassNode(((LowestUpperBoundClassNode)lub).name, psc, pinterfaces); } else { return parameterizeLowestUpperBound(lub, a, b, lub); } }
[ "public", "static", "ClassNode", "lowestUpperBound", "(", "ClassNode", "a", ",", "ClassNode", "b", ")", "{", "ClassNode", "lub", "=", "lowestUpperBound", "(", "a", ",", "b", ",", "null", ",", "null", ")", ";", "if", "(", "lub", "==", "null", "||", "!", "lub", ".", "isUsingGenerics", "(", ")", ")", "return", "lub", ";", "// types may be parameterized. If so, we must ensure that generic type arguments", "// are made compatible", "if", "(", "lub", "instanceof", "LowestUpperBoundClassNode", ")", "{", "// no parent super class representing both types could be found", "// or both class nodes implement common interfaces which may have", "// been parameterized differently.", "// We must create a classnode for which the \"superclass\" is potentially parameterized", "// plus the interfaces", "ClassNode", "superClass", "=", "lub", ".", "getSuperClass", "(", ")", ";", "ClassNode", "psc", "=", "superClass", ".", "isUsingGenerics", "(", ")", "?", "parameterizeLowestUpperBound", "(", "superClass", ",", "a", ",", "b", ",", "lub", ")", ":", "superClass", ";", "ClassNode", "[", "]", "interfaces", "=", "lub", ".", "getInterfaces", "(", ")", ";", "ClassNode", "[", "]", "pinterfaces", "=", "new", "ClassNode", "[", "interfaces", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ",", "interfacesLength", "=", "interfaces", ".", "length", ";", "i", "<", "interfacesLength", ";", "i", "++", ")", "{", "final", "ClassNode", "icn", "=", "interfaces", "[", "i", "]", ";", "if", "(", "icn", ".", "isUsingGenerics", "(", ")", ")", "{", "pinterfaces", "[", "i", "]", "=", "parameterizeLowestUpperBound", "(", "icn", ",", "a", ",", "b", ",", "lub", ")", ";", "}", "else", "{", "pinterfaces", "[", "i", "]", "=", "icn", ";", "}", "}", "return", "new", "LowestUpperBoundClassNode", "(", "(", "(", "LowestUpperBoundClassNode", ")", "lub", ")", ".", "name", ",", "psc", ",", "pinterfaces", ")", ";", "}", "else", "{", "return", "parameterizeLowestUpperBound", "(", "lub", ",", "a", ",", "b", ",", "lub", ")", ";", "}", "}" ]
Given two class nodes, returns the first common supertype, or the class itself if there are equal. For example, Double and Float would return Number, while Set and String would return Object. This method is not guaranteed to return a class node which corresponds to a real type. For example, if two types have more than one interface in common and are not in the same hierarchy branch, then the returned type will be a virtual type implementing all those interfaces. Calls to this method are supposed to be made with resolved generics. This means that you can have wildcards, but no placeholder. @param a first class node @param b second class node @return first common supertype
[ "Given", "two", "class", "nodes", "returns", "the", "first", "common", "supertype", "or", "the", "class", "itself", "if", "there", "are", "equal", ".", "For", "example", "Double", "and", "Float", "would", "return", "Number", "while", "Set", "and", "String", "would", "return", "Object", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L209-L240
12,892
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.parameterizeLowestUpperBound
private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final ClassNode a, final ClassNode b, final ClassNode fallback) { if (!lub.isUsingGenerics()) return lub; // a common super type exists, all we have to do is to parameterize // it according to the types provided by the two class nodes ClassNode holderForA = findGenericsTypeHolderForClass(a, lub); ClassNode holderForB = findGenericsTypeHolderForClass(b, lub); // let's compare their generics type GenericsType[] agt = holderForA == null ? null : holderForA.getGenericsTypes(); GenericsType[] bgt = holderForB == null ? null : holderForB.getGenericsTypes(); if (agt==null || bgt==null || agt.length!=bgt.length) { return lub; } GenericsType[] lubgt = new GenericsType[agt.length]; for (int i = 0; i < agt.length; i++) { ClassNode t1 = agt[i].getType(); ClassNode t2 = bgt[i].getType(); ClassNode basicType; if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) { // we are facing a self referencing type ! basicType = fallback; } else { basicType = lowestUpperBound(t1, t2); } if (t1.equals(t2)) { lubgt[i] = new GenericsType(basicType); } else { lubgt[i] = GenericsUtils.buildWildcardType(basicType); } } ClassNode plain = lub.getPlainNodeReference(); plain.setGenericsTypes(lubgt); return plain; }
java
private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final ClassNode a, final ClassNode b, final ClassNode fallback) { if (!lub.isUsingGenerics()) return lub; // a common super type exists, all we have to do is to parameterize // it according to the types provided by the two class nodes ClassNode holderForA = findGenericsTypeHolderForClass(a, lub); ClassNode holderForB = findGenericsTypeHolderForClass(b, lub); // let's compare their generics type GenericsType[] agt = holderForA == null ? null : holderForA.getGenericsTypes(); GenericsType[] bgt = holderForB == null ? null : holderForB.getGenericsTypes(); if (agt==null || bgt==null || agt.length!=bgt.length) { return lub; } GenericsType[] lubgt = new GenericsType[agt.length]; for (int i = 0; i < agt.length; i++) { ClassNode t1 = agt[i].getType(); ClassNode t2 = bgt[i].getType(); ClassNode basicType; if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) { // we are facing a self referencing type ! basicType = fallback; } else { basicType = lowestUpperBound(t1, t2); } if (t1.equals(t2)) { lubgt[i] = new GenericsType(basicType); } else { lubgt[i] = GenericsUtils.buildWildcardType(basicType); } } ClassNode plain = lub.getPlainNodeReference(); plain.setGenericsTypes(lubgt); return plain; }
[ "private", "static", "ClassNode", "parameterizeLowestUpperBound", "(", "final", "ClassNode", "lub", ",", "final", "ClassNode", "a", ",", "final", "ClassNode", "b", ",", "final", "ClassNode", "fallback", ")", "{", "if", "(", "!", "lub", ".", "isUsingGenerics", "(", ")", ")", "return", "lub", ";", "// a common super type exists, all we have to do is to parameterize", "// it according to the types provided by the two class nodes", "ClassNode", "holderForA", "=", "findGenericsTypeHolderForClass", "(", "a", ",", "lub", ")", ";", "ClassNode", "holderForB", "=", "findGenericsTypeHolderForClass", "(", "b", ",", "lub", ")", ";", "// let's compare their generics type", "GenericsType", "[", "]", "agt", "=", "holderForA", "==", "null", "?", "null", ":", "holderForA", ".", "getGenericsTypes", "(", ")", ";", "GenericsType", "[", "]", "bgt", "=", "holderForB", "==", "null", "?", "null", ":", "holderForB", ".", "getGenericsTypes", "(", ")", ";", "if", "(", "agt", "==", "null", "||", "bgt", "==", "null", "||", "agt", ".", "length", "!=", "bgt", ".", "length", ")", "{", "return", "lub", ";", "}", "GenericsType", "[", "]", "lubgt", "=", "new", "GenericsType", "[", "agt", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "agt", ".", "length", ";", "i", "++", ")", "{", "ClassNode", "t1", "=", "agt", "[", "i", "]", ".", "getType", "(", ")", ";", "ClassNode", "t2", "=", "bgt", "[", "i", "]", ".", "getType", "(", ")", ";", "ClassNode", "basicType", ";", "if", "(", "areEqualWithGenerics", "(", "t1", ",", "a", ")", "&&", "areEqualWithGenerics", "(", "t2", ",", "b", ")", ")", "{", "// we are facing a self referencing type !", "basicType", "=", "fallback", ";", "}", "else", "{", "basicType", "=", "lowestUpperBound", "(", "t1", ",", "t2", ")", ";", "}", "if", "(", "t1", ".", "equals", "(", "t2", ")", ")", "{", "lubgt", "[", "i", "]", "=", "new", "GenericsType", "(", "basicType", ")", ";", "}", "else", "{", "lubgt", "[", "i", "]", "=", "GenericsUtils", ".", "buildWildcardType", "(", "basicType", ")", ";", "}", "}", "ClassNode", "plain", "=", "lub", ".", "getPlainNodeReference", "(", ")", ";", "plain", ".", "setGenericsTypes", "(", "lubgt", ")", ";", "return", "plain", ";", "}" ]
Given a lowest upper bound computed without generic type information but which requires to be parameterized and the two implementing classnodes which are parameterized with potentially two different types, returns a parameterized lowest upper bound. For example, if LUB is Set&lt;T&gt; and a is Set&lt;String&gt; and b is Set&lt;StringBuffer&gt;, this will return a LUB which parameterized type matches Set&lt;? extends CharSequence&gt; @param lub the type to be parameterized @param a parameterized type a @param b parameterized type b @param fallback if we detect a recursive call, use this LUB as the parameterized type instead of computing a value @return the class node representing the parameterized lowest upper bound
[ "Given", "a", "lowest", "upper", "bound", "computed", "without", "generic", "type", "information", "but", "which", "requires", "to", "be", "parameterized", "and", "the", "two", "implementing", "classnodes", "which", "are", "parameterized", "with", "potentially", "two", "different", "types", "returns", "a", "parameterized", "lowest", "upper", "bound", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L255-L287
12,893
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.keepLowestCommonInterfaces
private static List<ClassNode> keepLowestCommonInterfaces(List<ClassNode> fromA, List<ClassNode> fromB) { if (fromA==null||fromB==null) return EMPTY_CLASSNODE_LIST; Set<ClassNode> common = new HashSet<ClassNode>(fromA); common.retainAll(fromB); List<ClassNode> result = new ArrayList<ClassNode>(common.size()); for (ClassNode classNode : common) { addMostSpecificInterface(classNode, result); } return result; }
java
private static List<ClassNode> keepLowestCommonInterfaces(List<ClassNode> fromA, List<ClassNode> fromB) { if (fromA==null||fromB==null) return EMPTY_CLASSNODE_LIST; Set<ClassNode> common = new HashSet<ClassNode>(fromA); common.retainAll(fromB); List<ClassNode> result = new ArrayList<ClassNode>(common.size()); for (ClassNode classNode : common) { addMostSpecificInterface(classNode, result); } return result; }
[ "private", "static", "List", "<", "ClassNode", ">", "keepLowestCommonInterfaces", "(", "List", "<", "ClassNode", ">", "fromA", ",", "List", "<", "ClassNode", ">", "fromB", ")", "{", "if", "(", "fromA", "==", "null", "||", "fromB", "==", "null", ")", "return", "EMPTY_CLASSNODE_LIST", ";", "Set", "<", "ClassNode", ">", "common", "=", "new", "HashSet", "<", "ClassNode", ">", "(", "fromA", ")", ";", "common", ".", "retainAll", "(", "fromB", ")", ";", "List", "<", "ClassNode", ">", "result", "=", "new", "ArrayList", "<", "ClassNode", ">", "(", "common", ".", "size", "(", ")", ")", ";", "for", "(", "ClassNode", "classNode", ":", "common", ")", "{", "addMostSpecificInterface", "(", "classNode", ",", "result", ")", ";", "}", "return", "result", ";", "}" ]
Given the list of interfaces implemented by two class nodes, returns the list of the most specific common implemented interfaces. @param fromA @param fromB @return the list of the most specific common implemented interfaces
[ "Given", "the", "list", "of", "interfaces", "implemented", "by", "two", "class", "nodes", "returns", "the", "list", "of", "the", "most", "specific", "common", "implemented", "interfaces", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L484-L493
12,894
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.buildTypeWithInterfaces
private static ClassNode buildTypeWithInterfaces(ClassNode baseType1, ClassNode baseType2, Collection<ClassNode> interfaces) { boolean noInterface = interfaces.isEmpty(); if (noInterface) { if (baseType1.equals(baseType2)) return baseType1; if (baseType1.isDerivedFrom(baseType2)) return baseType2; if (baseType2.isDerivedFrom(baseType1)) return baseType1; } if (OBJECT_TYPE.equals(baseType1) && OBJECT_TYPE.equals(baseType2) && interfaces.size()==1) { if (interfaces instanceof List) { return ((List<ClassNode>) interfaces).get(0); } return interfaces.iterator().next(); } LowestUpperBoundClassNode type; ClassNode superClass; String name; if (baseType1.equals(baseType2)) { if (OBJECT_TYPE.equals(baseType1)) { superClass = baseType1; name = "Virtual$Object"; } else { superClass = baseType1; name = "Virtual$"+baseType1.getName(); } } else { superClass = OBJECT_TYPE; if (baseType1.isDerivedFrom(baseType2)) { superClass = baseType2; } else if (baseType2.isDerivedFrom(baseType1)) { superClass = baseType1; } name = "CommonAssignOf$"+baseType1.getName()+"$"+baseType2.getName(); } Iterator<ClassNode> itcn = interfaces.iterator(); while (itcn.hasNext()) { ClassNode next = itcn.next(); if (superClass.isDerivedFrom(next) || superClass.implementsInterface(next)) { itcn.remove(); } } ClassNode[] interfaceArray = interfaces.toArray(ClassNode.EMPTY_ARRAY); Arrays.sort(interfaceArray, INTERFACE_CLASSNODE_COMPARATOR); type = new LowestUpperBoundClassNode(name, superClass, interfaceArray); return type; }
java
private static ClassNode buildTypeWithInterfaces(ClassNode baseType1, ClassNode baseType2, Collection<ClassNode> interfaces) { boolean noInterface = interfaces.isEmpty(); if (noInterface) { if (baseType1.equals(baseType2)) return baseType1; if (baseType1.isDerivedFrom(baseType2)) return baseType2; if (baseType2.isDerivedFrom(baseType1)) return baseType1; } if (OBJECT_TYPE.equals(baseType1) && OBJECT_TYPE.equals(baseType2) && interfaces.size()==1) { if (interfaces instanceof List) { return ((List<ClassNode>) interfaces).get(0); } return interfaces.iterator().next(); } LowestUpperBoundClassNode type; ClassNode superClass; String name; if (baseType1.equals(baseType2)) { if (OBJECT_TYPE.equals(baseType1)) { superClass = baseType1; name = "Virtual$Object"; } else { superClass = baseType1; name = "Virtual$"+baseType1.getName(); } } else { superClass = OBJECT_TYPE; if (baseType1.isDerivedFrom(baseType2)) { superClass = baseType2; } else if (baseType2.isDerivedFrom(baseType1)) { superClass = baseType1; } name = "CommonAssignOf$"+baseType1.getName()+"$"+baseType2.getName(); } Iterator<ClassNode> itcn = interfaces.iterator(); while (itcn.hasNext()) { ClassNode next = itcn.next(); if (superClass.isDerivedFrom(next) || superClass.implementsInterface(next)) { itcn.remove(); } } ClassNode[] interfaceArray = interfaces.toArray(ClassNode.EMPTY_ARRAY); Arrays.sort(interfaceArray, INTERFACE_CLASSNODE_COMPARATOR); type = new LowestUpperBoundClassNode(name, superClass, interfaceArray); return type; }
[ "private", "static", "ClassNode", "buildTypeWithInterfaces", "(", "ClassNode", "baseType1", ",", "ClassNode", "baseType2", ",", "Collection", "<", "ClassNode", ">", "interfaces", ")", "{", "boolean", "noInterface", "=", "interfaces", ".", "isEmpty", "(", ")", ";", "if", "(", "noInterface", ")", "{", "if", "(", "baseType1", ".", "equals", "(", "baseType2", ")", ")", "return", "baseType1", ";", "if", "(", "baseType1", ".", "isDerivedFrom", "(", "baseType2", ")", ")", "return", "baseType2", ";", "if", "(", "baseType2", ".", "isDerivedFrom", "(", "baseType1", ")", ")", "return", "baseType1", ";", "}", "if", "(", "OBJECT_TYPE", ".", "equals", "(", "baseType1", ")", "&&", "OBJECT_TYPE", ".", "equals", "(", "baseType2", ")", "&&", "interfaces", ".", "size", "(", ")", "==", "1", ")", "{", "if", "(", "interfaces", "instanceof", "List", ")", "{", "return", "(", "(", "List", "<", "ClassNode", ">", ")", "interfaces", ")", ".", "get", "(", "0", ")", ";", "}", "return", "interfaces", ".", "iterator", "(", ")", ".", "next", "(", ")", ";", "}", "LowestUpperBoundClassNode", "type", ";", "ClassNode", "superClass", ";", "String", "name", ";", "if", "(", "baseType1", ".", "equals", "(", "baseType2", ")", ")", "{", "if", "(", "OBJECT_TYPE", ".", "equals", "(", "baseType1", ")", ")", "{", "superClass", "=", "baseType1", ";", "name", "=", "\"Virtual$Object\"", ";", "}", "else", "{", "superClass", "=", "baseType1", ";", "name", "=", "\"Virtual$\"", "+", "baseType1", ".", "getName", "(", ")", ";", "}", "}", "else", "{", "superClass", "=", "OBJECT_TYPE", ";", "if", "(", "baseType1", ".", "isDerivedFrom", "(", "baseType2", ")", ")", "{", "superClass", "=", "baseType2", ";", "}", "else", "if", "(", "baseType2", ".", "isDerivedFrom", "(", "baseType1", ")", ")", "{", "superClass", "=", "baseType1", ";", "}", "name", "=", "\"CommonAssignOf$\"", "+", "baseType1", ".", "getName", "(", ")", "+", "\"$\"", "+", "baseType2", ".", "getName", "(", ")", ";", "}", "Iterator", "<", "ClassNode", ">", "itcn", "=", "interfaces", ".", "iterator", "(", ")", ";", "while", "(", "itcn", ".", "hasNext", "(", ")", ")", "{", "ClassNode", "next", "=", "itcn", ".", "next", "(", ")", ";", "if", "(", "superClass", ".", "isDerivedFrom", "(", "next", ")", "||", "superClass", ".", "implementsInterface", "(", "next", ")", ")", "{", "itcn", ".", "remove", "(", ")", ";", "}", "}", "ClassNode", "[", "]", "interfaceArray", "=", "interfaces", ".", "toArray", "(", "ClassNode", ".", "EMPTY_ARRAY", ")", ";", "Arrays", ".", "sort", "(", "interfaceArray", ",", "INTERFACE_CLASSNODE_COMPARATOR", ")", ";", "type", "=", "new", "LowestUpperBoundClassNode", "(", "name", ",", "superClass", ",", "interfaceArray", ")", ";", "return", "type", ";", "}" ]
Given two class nodes supposedly at the upper common level, returns a class node which is able to represent their lowest upper bound. @param baseType1 @param baseType2 @param interfaces interfaces both class nodes share, which their lowest common super class do not implement. @return the class node representing the lowest upper bound
[ "Given", "two", "class", "nodes", "supposedly", "at", "the", "upper", "common", "level", "returns", "a", "class", "node", "which", "is", "able", "to", "represent", "their", "lowest", "upper", "bound", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L537-L581
12,895
apache/groovy
src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
WideningCategories.areEqualWithGenerics
private static boolean areEqualWithGenerics(ClassNode a, ClassNode b) { if (a==null) return b==null; if (!a.equals(b)) return false; if (a.isUsingGenerics() && !b.isUsingGenerics()) return false; GenericsType[] gta = a.getGenericsTypes(); GenericsType[] gtb = b.getGenericsTypes(); if (gta==null && gtb!=null) return false; if (gtb==null && gta!=null) return false; if (gta!=null && gtb!=null) { if (gta.length!=gtb.length) return false; for (int i = 0; i < gta.length; i++) { GenericsType ga = gta[i]; GenericsType gb = gtb[i]; boolean result = ga.isPlaceholder()==gb.isPlaceholder() && ga.isWildcard()==gb.isWildcard(); result = result && ga.isResolved() && gb.isResolved(); result = result && ga.getName().equals(gb.getName()); result = result && areEqualWithGenerics(ga.getType(), gb.getType()); result = result && areEqualWithGenerics(ga.getLowerBound(), gb.getLowerBound()); if (result) { ClassNode[] upA = ga.getUpperBounds(); if (upA!=null) { ClassNode[] upB = gb.getUpperBounds(); if (upB==null || upB.length!=upA.length) return false; for (int j = 0; j < upA.length; j++) { if (!areEqualWithGenerics(upA[j],upB[j])) return false; } } } if (!result) return false; } } return true; }
java
private static boolean areEqualWithGenerics(ClassNode a, ClassNode b) { if (a==null) return b==null; if (!a.equals(b)) return false; if (a.isUsingGenerics() && !b.isUsingGenerics()) return false; GenericsType[] gta = a.getGenericsTypes(); GenericsType[] gtb = b.getGenericsTypes(); if (gta==null && gtb!=null) return false; if (gtb==null && gta!=null) return false; if (gta!=null && gtb!=null) { if (gta.length!=gtb.length) return false; for (int i = 0; i < gta.length; i++) { GenericsType ga = gta[i]; GenericsType gb = gtb[i]; boolean result = ga.isPlaceholder()==gb.isPlaceholder() && ga.isWildcard()==gb.isWildcard(); result = result && ga.isResolved() && gb.isResolved(); result = result && ga.getName().equals(gb.getName()); result = result && areEqualWithGenerics(ga.getType(), gb.getType()); result = result && areEqualWithGenerics(ga.getLowerBound(), gb.getLowerBound()); if (result) { ClassNode[] upA = ga.getUpperBounds(); if (upA!=null) { ClassNode[] upB = gb.getUpperBounds(); if (upB==null || upB.length!=upA.length) return false; for (int j = 0; j < upA.length; j++) { if (!areEqualWithGenerics(upA[j],upB[j])) return false; } } } if (!result) return false; } } return true; }
[ "private", "static", "boolean", "areEqualWithGenerics", "(", "ClassNode", "a", ",", "ClassNode", "b", ")", "{", "if", "(", "a", "==", "null", ")", "return", "b", "==", "null", ";", "if", "(", "!", "a", ".", "equals", "(", "b", ")", ")", "return", "false", ";", "if", "(", "a", ".", "isUsingGenerics", "(", ")", "&&", "!", "b", ".", "isUsingGenerics", "(", ")", ")", "return", "false", ";", "GenericsType", "[", "]", "gta", "=", "a", ".", "getGenericsTypes", "(", ")", ";", "GenericsType", "[", "]", "gtb", "=", "b", ".", "getGenericsTypes", "(", ")", ";", "if", "(", "gta", "==", "null", "&&", "gtb", "!=", "null", ")", "return", "false", ";", "if", "(", "gtb", "==", "null", "&&", "gta", "!=", "null", ")", "return", "false", ";", "if", "(", "gta", "!=", "null", "&&", "gtb", "!=", "null", ")", "{", "if", "(", "gta", ".", "length", "!=", "gtb", ".", "length", ")", "return", "false", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "gta", ".", "length", ";", "i", "++", ")", "{", "GenericsType", "ga", "=", "gta", "[", "i", "]", ";", "GenericsType", "gb", "=", "gtb", "[", "i", "]", ";", "boolean", "result", "=", "ga", ".", "isPlaceholder", "(", ")", "==", "gb", ".", "isPlaceholder", "(", ")", "&&", "ga", ".", "isWildcard", "(", ")", "==", "gb", ".", "isWildcard", "(", ")", ";", "result", "=", "result", "&&", "ga", ".", "isResolved", "(", ")", "&&", "gb", ".", "isResolved", "(", ")", ";", "result", "=", "result", "&&", "ga", ".", "getName", "(", ")", ".", "equals", "(", "gb", ".", "getName", "(", ")", ")", ";", "result", "=", "result", "&&", "areEqualWithGenerics", "(", "ga", ".", "getType", "(", ")", ",", "gb", ".", "getType", "(", ")", ")", ";", "result", "=", "result", "&&", "areEqualWithGenerics", "(", "ga", ".", "getLowerBound", "(", ")", ",", "gb", ".", "getLowerBound", "(", ")", ")", ";", "if", "(", "result", ")", "{", "ClassNode", "[", "]", "upA", "=", "ga", ".", "getUpperBounds", "(", ")", ";", "if", "(", "upA", "!=", "null", ")", "{", "ClassNode", "[", "]", "upB", "=", "gb", ".", "getUpperBounds", "(", ")", ";", "if", "(", "upB", "==", "null", "||", "upB", ".", "length", "!=", "upA", ".", "length", ")", "return", "false", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "upA", ".", "length", ";", "j", "++", ")", "{", "if", "(", "!", "areEqualWithGenerics", "(", "upA", "[", "j", "]", ",", "upB", "[", "j", "]", ")", ")", "return", "false", ";", "}", "}", "}", "if", "(", "!", "result", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Compares two class nodes, but including their generics types. @param a @param b @return true if the class nodes are equal, false otherwise
[ "Compares", "two", "class", "nodes", "but", "including", "their", "generics", "types", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L695-L727
12,896
apache/groovy
subprojects/groovy-json/src/main/java/groovy/json/JsonSlurper.java
JsonSlurper.parse
public Object parse(char [] chars) { if (chars == null) { throw new IllegalArgumentException("chars must not be null"); } Object content; content = createParser().parse(chars); return content; }
java
public Object parse(char [] chars) { if (chars == null) { throw new IllegalArgumentException("chars must not be null"); } Object content; content = createParser().parse(chars); return content; }
[ "public", "Object", "parse", "(", "char", "[", "]", "chars", ")", "{", "if", "(", "chars", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"chars must not be null\"", ")", ";", "}", "Object", "content", ";", "content", "=", "createParser", "(", ")", ".", "parse", "(", "chars", ")", ";", "return", "content", ";", "}" ]
Parse a JSON data structure from content from a char array. @param chars buffer of JSON content @return a data structure of lists and maps @since 2.3
[ "Parse", "a", "JSON", "data", "structure", "from", "content", "from", "a", "char", "array", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-json/src/main/java/groovy/json/JsonSlurper.java#L307-L315
12,897
apache/groovy
subprojects/groovy-swing/src/main/java/groovy/model/ValueHolder.java
ValueHolder.addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener) { if ( propertyChangeSupport == null ) { propertyChangeSupport = new PropertyChangeSupport(this); } propertyChangeSupport.addPropertyChangeListener(listener); }
java
public void addPropertyChangeListener(PropertyChangeListener listener) { if ( propertyChangeSupport == null ) { propertyChangeSupport = new PropertyChangeSupport(this); } propertyChangeSupport.addPropertyChangeListener(listener); }
[ "public", "void", "addPropertyChangeListener", "(", "PropertyChangeListener", "listener", ")", "{", "if", "(", "propertyChangeSupport", "==", "null", ")", "{", "propertyChangeSupport", "=", "new", "PropertyChangeSupport", "(", "this", ")", ";", "}", "propertyChangeSupport", ".", "addPropertyChangeListener", "(", "listener", ")", ";", "}" ]
Add a PropertyChangeListener to the listener list. @param listener The listener to add.
[ "Add", "a", "PropertyChangeListener", "to", "the", "listener", "list", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/subprojects/groovy-swing/src/main/java/groovy/model/ValueHolder.java#L51-L56
12,898
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Numbers.java
Numbers.parseInteger
public static Number parseInteger(AST reportNode, String text) { // remove place holder underscore before starting text = text.replace("_", ""); char c = ' '; int length = text.length(); // // Strip off the sign, if present boolean negative = false; if ((c = text.charAt(0)) == '-' || c == '+') { negative = (c == '-'); text = text.substring(1, length); length -= 1; } // // Determine radix (default is 10). int radix = 10; if (text.charAt(0) == '0' && length > 1) { c = text.charAt(1); if (c == 'X' || c == 'x') { radix = 16; text = text.substring(2, length); length -= 2; } else if (c == 'B' || c == 'b') { radix = 2; text = text.substring(2, length); length -= 2; } else { radix = 8; } } // // Strip off any type specifier and convert it to lower // case, if present. char type = 'x'; // pick best fit if (isNumericTypeSpecifier(text.charAt(length - 1), false)) { type = Character.toLowerCase(text.charAt(length - 1)); text = text.substring(0, length - 1); length -= 1; } // // Add the sign back, if necessary if (negative) { text = "-" + text; } // // Build the specified type or, if no type was specified, the // smallest type in which the number will fit. BigInteger value = new BigInteger(text, radix); switch (type) { case 'i': if (radix == 10 && (value.compareTo(MAX_INTEGER) > 0 || value.compareTo(MIN_INTEGER) < 0)) { throw new ASTRuntimeException(reportNode, "Number of value " + value + " does not fit in the range of int, but int was enforced."); } else { return value.intValue(); } case 'l': if (radix == 10 && (value.compareTo(MAX_LONG) > 0 || value.compareTo(MIN_LONG) < 0)) { throw new ASTRuntimeException(reportNode, "Number of value " + value + " does not fit in the range of long, but long was enforced."); } else { return value.longValue(); } case 'g': return value; default: // If not specified, we will return the narrowest possible // of Integer, Long, and BigInteger. if (value.compareTo(MAX_INTEGER) <= 0 && value.compareTo(MIN_INTEGER) >= 0) { return value.intValue(); } else if (value.compareTo(MAX_LONG) <= 0 && value.compareTo(MIN_LONG) >= 0) { return value.longValue(); } return value; } }
java
public static Number parseInteger(AST reportNode, String text) { // remove place holder underscore before starting text = text.replace("_", ""); char c = ' '; int length = text.length(); // // Strip off the sign, if present boolean negative = false; if ((c = text.charAt(0)) == '-' || c == '+') { negative = (c == '-'); text = text.substring(1, length); length -= 1; } // // Determine radix (default is 10). int radix = 10; if (text.charAt(0) == '0' && length > 1) { c = text.charAt(1); if (c == 'X' || c == 'x') { radix = 16; text = text.substring(2, length); length -= 2; } else if (c == 'B' || c == 'b') { radix = 2; text = text.substring(2, length); length -= 2; } else { radix = 8; } } // // Strip off any type specifier and convert it to lower // case, if present. char type = 'x'; // pick best fit if (isNumericTypeSpecifier(text.charAt(length - 1), false)) { type = Character.toLowerCase(text.charAt(length - 1)); text = text.substring(0, length - 1); length -= 1; } // // Add the sign back, if necessary if (negative) { text = "-" + text; } // // Build the specified type or, if no type was specified, the // smallest type in which the number will fit. BigInteger value = new BigInteger(text, radix); switch (type) { case 'i': if (radix == 10 && (value.compareTo(MAX_INTEGER) > 0 || value.compareTo(MIN_INTEGER) < 0)) { throw new ASTRuntimeException(reportNode, "Number of value " + value + " does not fit in the range of int, but int was enforced."); } else { return value.intValue(); } case 'l': if (radix == 10 && (value.compareTo(MAX_LONG) > 0 || value.compareTo(MIN_LONG) < 0)) { throw new ASTRuntimeException(reportNode, "Number of value " + value + " does not fit in the range of long, but long was enforced."); } else { return value.longValue(); } case 'g': return value; default: // If not specified, we will return the narrowest possible // of Integer, Long, and BigInteger. if (value.compareTo(MAX_INTEGER) <= 0 && value.compareTo(MIN_INTEGER) >= 0) { return value.intValue(); } else if (value.compareTo(MAX_LONG) <= 0 && value.compareTo(MIN_LONG) >= 0) { return value.longValue(); } return value; } }
[ "public", "static", "Number", "parseInteger", "(", "AST", "reportNode", ",", "String", "text", ")", "{", "// remove place holder underscore before starting", "text", "=", "text", ".", "replace", "(", "\"_\"", ",", "\"\"", ")", ";", "char", "c", "=", "'", "'", ";", "int", "length", "=", "text", ".", "length", "(", ")", ";", "//", "// Strip off the sign, if present", "boolean", "negative", "=", "false", ";", "if", "(", "(", "c", "=", "text", ".", "charAt", "(", "0", ")", ")", "==", "'", "'", "||", "c", "==", "'", "'", ")", "{", "negative", "=", "(", "c", "==", "'", "'", ")", ";", "text", "=", "text", ".", "substring", "(", "1", ",", "length", ")", ";", "length", "-=", "1", ";", "}", "//", "// Determine radix (default is 10).", "int", "radix", "=", "10", ";", "if", "(", "text", ".", "charAt", "(", "0", ")", "==", "'", "'", "&&", "length", ">", "1", ")", "{", "c", "=", "text", ".", "charAt", "(", "1", ")", ";", "if", "(", "c", "==", "'", "'", "||", "c", "==", "'", "'", ")", "{", "radix", "=", "16", ";", "text", "=", "text", ".", "substring", "(", "2", ",", "length", ")", ";", "length", "-=", "2", ";", "}", "else", "if", "(", "c", "==", "'", "'", "||", "c", "==", "'", "'", ")", "{", "radix", "=", "2", ";", "text", "=", "text", ".", "substring", "(", "2", ",", "length", ")", ";", "length", "-=", "2", ";", "}", "else", "{", "radix", "=", "8", ";", "}", "}", "//", "// Strip off any type specifier and convert it to lower", "// case, if present.", "char", "type", "=", "'", "'", ";", "// pick best fit", "if", "(", "isNumericTypeSpecifier", "(", "text", ".", "charAt", "(", "length", "-", "1", ")", ",", "false", ")", ")", "{", "type", "=", "Character", ".", "toLowerCase", "(", "text", ".", "charAt", "(", "length", "-", "1", ")", ")", ";", "text", "=", "text", ".", "substring", "(", "0", ",", "length", "-", "1", ")", ";", "length", "-=", "1", ";", "}", "//", "// Add the sign back, if necessary", "if", "(", "negative", ")", "{", "text", "=", "\"-\"", "+", "text", ";", "}", "//", "// Build the specified type or, if no type was specified, the", "// smallest type in which the number will fit.", "BigInteger", "value", "=", "new", "BigInteger", "(", "text", ",", "radix", ")", ";", "switch", "(", "type", ")", "{", "case", "'", "'", ":", "if", "(", "radix", "==", "10", "&&", "(", "value", ".", "compareTo", "(", "MAX_INTEGER", ")", ">", "0", "||", "value", ".", "compareTo", "(", "MIN_INTEGER", ")", "<", "0", ")", ")", "{", "throw", "new", "ASTRuntimeException", "(", "reportNode", ",", "\"Number of value \"", "+", "value", "+", "\" does not fit in the range of int, but int was enforced.\"", ")", ";", "}", "else", "{", "return", "value", ".", "intValue", "(", ")", ";", "}", "case", "'", "'", ":", "if", "(", "radix", "==", "10", "&&", "(", "value", ".", "compareTo", "(", "MAX_LONG", ")", ">", "0", "||", "value", ".", "compareTo", "(", "MIN_LONG", ")", "<", "0", ")", ")", "{", "throw", "new", "ASTRuntimeException", "(", "reportNode", ",", "\"Number of value \"", "+", "value", "+", "\" does not fit in the range of long, but long was enforced.\"", ")", ";", "}", "else", "{", "return", "value", ".", "longValue", "(", ")", ";", "}", "case", "'", "'", ":", "return", "value", ";", "default", ":", "// If not specified, we will return the narrowest possible", "// of Integer, Long, and BigInteger.", "if", "(", "value", ".", "compareTo", "(", "MAX_INTEGER", ")", "<=", "0", "&&", "value", ".", "compareTo", "(", "MIN_INTEGER", ")", ">=", "0", ")", "{", "return", "value", ".", "intValue", "(", ")", ";", "}", "else", "if", "(", "value", ".", "compareTo", "(", "MAX_LONG", ")", "<=", "0", "&&", "value", ".", "compareTo", "(", "MIN_LONG", ")", ">=", "0", ")", "{", "return", "value", ".", "longValue", "(", ")", ";", "}", "return", "value", ";", "}", "}" ]
Builds a Number from the given integer descriptor. Creates the narrowest type possible, or a specific type, if specified. @param reportNode at node for error reporting in the parser @param text literal text to parse @return instantiated Number object @throws NumberFormatException if the number does not fit within the type requested by the type specifier suffix (invalid numbers don't make it here)
[ "Builds", "a", "Number", "from", "the", "given", "integer", "descriptor", ".", "Creates", "the", "narrowest", "type", "possible", "or", "a", "specific", "type", "if", "specified", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Numbers.java#L134-L225
12,899
apache/groovy
src/main/java/org/codehaus/groovy/syntax/Numbers.java
Numbers.parseDecimal
public static Number parseDecimal(String text) { text = text.replace("_", ""); int length = text.length(); // // Strip off any type specifier and convert it to lower // case, if present. char type = 'x'; if (isNumericTypeSpecifier(text.charAt(length - 1), true)) { type = Character.toLowerCase(text.charAt(length - 1)); text = text.substring(0, length - 1); } // // Build the specified type or default to BigDecimal BigDecimal value = new BigDecimal(text); switch (type) { case 'f': if (value.compareTo(MAX_FLOAT) <= 0 && value.compareTo(MIN_FLOAT) >= 0) { return Float.parseFloat(text); } throw new NumberFormatException("out of range"); case 'd': if (value.compareTo(MAX_DOUBLE) <= 0 && value.compareTo(MIN_DOUBLE) >= 0) { return Double.parseDouble(text); } throw new NumberFormatException("out of range"); case 'g': default: return value; } }
java
public static Number parseDecimal(String text) { text = text.replace("_", ""); int length = text.length(); // // Strip off any type specifier and convert it to lower // case, if present. char type = 'x'; if (isNumericTypeSpecifier(text.charAt(length - 1), true)) { type = Character.toLowerCase(text.charAt(length - 1)); text = text.substring(0, length - 1); } // // Build the specified type or default to BigDecimal BigDecimal value = new BigDecimal(text); switch (type) { case 'f': if (value.compareTo(MAX_FLOAT) <= 0 && value.compareTo(MIN_FLOAT) >= 0) { return Float.parseFloat(text); } throw new NumberFormatException("out of range"); case 'd': if (value.compareTo(MAX_DOUBLE) <= 0 && value.compareTo(MIN_DOUBLE) >= 0) { return Double.parseDouble(text); } throw new NumberFormatException("out of range"); case 'g': default: return value; } }
[ "public", "static", "Number", "parseDecimal", "(", "String", "text", ")", "{", "text", "=", "text", ".", "replace", "(", "\"_\"", ",", "\"\"", ")", ";", "int", "length", "=", "text", ".", "length", "(", ")", ";", "//", "// Strip off any type specifier and convert it to lower", "// case, if present.", "char", "type", "=", "'", "'", ";", "if", "(", "isNumericTypeSpecifier", "(", "text", ".", "charAt", "(", "length", "-", "1", ")", ",", "true", ")", ")", "{", "type", "=", "Character", ".", "toLowerCase", "(", "text", ".", "charAt", "(", "length", "-", "1", ")", ")", ";", "text", "=", "text", ".", "substring", "(", "0", ",", "length", "-", "1", ")", ";", "}", "//", "// Build the specified type or default to BigDecimal", "BigDecimal", "value", "=", "new", "BigDecimal", "(", "text", ")", ";", "switch", "(", "type", ")", "{", "case", "'", "'", ":", "if", "(", "value", ".", "compareTo", "(", "MAX_FLOAT", ")", "<=", "0", "&&", "value", ".", "compareTo", "(", "MIN_FLOAT", ")", ">=", "0", ")", "{", "return", "Float", ".", "parseFloat", "(", "text", ")", ";", "}", "throw", "new", "NumberFormatException", "(", "\"out of range\"", ")", ";", "case", "'", "'", ":", "if", "(", "value", ".", "compareTo", "(", "MAX_DOUBLE", ")", "<=", "0", "&&", "value", ".", "compareTo", "(", "MIN_DOUBLE", ")", ">=", "0", ")", "{", "return", "Double", ".", "parseDouble", "(", "text", ")", ";", "}", "throw", "new", "NumberFormatException", "(", "\"out of range\"", ")", ";", "case", "'", "'", ":", "default", ":", "return", "value", ";", "}", "}" ]
Builds a Number from the given decimal descriptor. Uses BigDecimal, unless, Double or Float is requested. @param text literal text to parse @return instantiated Number object @throws NumberFormatException if the number does not fit within the type requested by the type specifier suffix (invalid numbers don't make it here)
[ "Builds", "a", "Number", "from", "the", "given", "decimal", "descriptor", ".", "Uses", "BigDecimal", "unless", "Double", "or", "Float", "is", "requested", "." ]
71cf20addb611bb8d097a59e395fd20bc7f31772
https://github.com/apache/groovy/blob/71cf20addb611bb8d097a59e395fd20bc7f31772/src/main/java/org/codehaus/groovy/syntax/Numbers.java#L238-L274