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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
14,000
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.lastElementSibling
|
public Element lastElementSibling() {
List<Element> siblings = parent().childElementsList();
return siblings.size() > 1 ? siblings.get(siblings.size() - 1) : null;
}
|
java
|
public Element lastElementSibling() {
List<Element> siblings = parent().childElementsList();
return siblings.size() > 1 ? siblings.get(siblings.size() - 1) : null;
}
|
[
"public",
"Element",
"lastElementSibling",
"(",
")",
"{",
"List",
"<",
"Element",
">",
"siblings",
"=",
"parent",
"(",
")",
".",
"childElementsList",
"(",
")",
";",
"return",
"siblings",
".",
"size",
"(",
")",
">",
"1",
"?",
"siblings",
".",
"get",
"(",
"siblings",
".",
"size",
"(",
")",
"-",
"1",
")",
":",
"null",
";",
"}"
] |
Gets the last element sibling of this element
@return the last sibling that is an element (aka the parent's last element child)
|
[
"Gets",
"the",
"last",
"element",
"sibling",
"of",
"this",
"element"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L766-L769
|
14,001
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByTag
|
public Elements getElementsByTag(String tagName) {
Validate.notEmpty(tagName);
tagName = normalize(tagName);
return Collector.collect(new Evaluator.Tag(tagName), this);
}
|
java
|
public Elements getElementsByTag(String tagName) {
Validate.notEmpty(tagName);
tagName = normalize(tagName);
return Collector.collect(new Evaluator.Tag(tagName), this);
}
|
[
"public",
"Elements",
"getElementsByTag",
"(",
"String",
"tagName",
")",
"{",
"Validate",
".",
"notEmpty",
"(",
"tagName",
")",
";",
"tagName",
"=",
"normalize",
"(",
"tagName",
")",
";",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"Tag",
"(",
"tagName",
")",
",",
"this",
")",
";",
"}"
] |
Finds elements, including and recursively under this element, with the specified tag name.
@param tagName The tag name to search for (case insensitively).
@return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
|
[
"Finds",
"elements",
"including",
"and",
"recursively",
"under",
"this",
"element",
"with",
"the",
"specified",
"tag",
"name",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L787-L792
|
14,002
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttribute
|
public Elements getElementsByAttribute(String key) {
Validate.notEmpty(key);
key = key.trim();
return Collector.collect(new Evaluator.Attribute(key), this);
}
|
java
|
public Elements getElementsByAttribute(String key) {
Validate.notEmpty(key);
key = key.trim();
return Collector.collect(new Evaluator.Attribute(key), this);
}
|
[
"public",
"Elements",
"getElementsByAttribute",
"(",
"String",
"key",
")",
"{",
"Validate",
".",
"notEmpty",
"(",
"key",
")",
";",
"key",
"=",
"key",
".",
"trim",
"(",
")",
";",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"Attribute",
"(",
"key",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that have a named attribute set. Case insensitive.
@param key name of the attribute, e.g. {@code href}
@return elements that have this attribute, empty if none
|
[
"Find",
"elements",
"that",
"have",
"a",
"named",
"attribute",
"set",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L836-L841
|
14,003
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttributeValue
|
public Elements getElementsByAttributeValue(String key, String value) {
return Collector.collect(new Evaluator.AttributeWithValue(key, value), this);
}
|
java
|
public Elements getElementsByAttributeValue(String key, String value) {
return Collector.collect(new Evaluator.AttributeWithValue(key, value), this);
}
|
[
"public",
"Elements",
"getElementsByAttributeValue",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"AttributeWithValue",
"(",
"key",
",",
"value",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that have an attribute with the specific value. Case insensitive.
@param key name of the attribute
@param value value of the attribute
@return elements that have this attribute with this value, empty if none
|
[
"Find",
"elements",
"that",
"have",
"an",
"attribute",
"with",
"the",
"specific",
"value",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L863-L865
|
14,004
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttributeValueNot
|
public Elements getElementsByAttributeValueNot(String key, String value) {
return Collector.collect(new Evaluator.AttributeWithValueNot(key, value), this);
}
|
java
|
public Elements getElementsByAttributeValueNot(String key, String value) {
return Collector.collect(new Evaluator.AttributeWithValueNot(key, value), this);
}
|
[
"public",
"Elements",
"getElementsByAttributeValueNot",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"AttributeWithValueNot",
"(",
"key",
",",
"value",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that either do not have this attribute, or have it with a different value. Case insensitive.
@param key name of the attribute
@param value value of the attribute
@return elements that do not have a matching attribute
|
[
"Find",
"elements",
"that",
"either",
"do",
"not",
"have",
"this",
"attribute",
"or",
"have",
"it",
"with",
"a",
"different",
"value",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L874-L876
|
14,005
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttributeValueStarting
|
public Elements getElementsByAttributeValueStarting(String key, String valuePrefix) {
return Collector.collect(new Evaluator.AttributeWithValueStarting(key, valuePrefix), this);
}
|
java
|
public Elements getElementsByAttributeValueStarting(String key, String valuePrefix) {
return Collector.collect(new Evaluator.AttributeWithValueStarting(key, valuePrefix), this);
}
|
[
"public",
"Elements",
"getElementsByAttributeValueStarting",
"(",
"String",
"key",
",",
"String",
"valuePrefix",
")",
"{",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"AttributeWithValueStarting",
"(",
"key",
",",
"valuePrefix",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that have attributes that start with the value prefix. Case insensitive.
@param key name of the attribute
@param valuePrefix start of attribute value
@return elements that have attributes that start with the value prefix
|
[
"Find",
"elements",
"that",
"have",
"attributes",
"that",
"start",
"with",
"the",
"value",
"prefix",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L885-L887
|
14,006
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttributeValueEnding
|
public Elements getElementsByAttributeValueEnding(String key, String valueSuffix) {
return Collector.collect(new Evaluator.AttributeWithValueEnding(key, valueSuffix), this);
}
|
java
|
public Elements getElementsByAttributeValueEnding(String key, String valueSuffix) {
return Collector.collect(new Evaluator.AttributeWithValueEnding(key, valueSuffix), this);
}
|
[
"public",
"Elements",
"getElementsByAttributeValueEnding",
"(",
"String",
"key",
",",
"String",
"valueSuffix",
")",
"{",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"AttributeWithValueEnding",
"(",
"key",
",",
"valueSuffix",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that have attributes that end with the value suffix. Case insensitive.
@param key name of the attribute
@param valueSuffix end of the attribute value
@return elements that have attributes that end with the value suffix
|
[
"Find",
"elements",
"that",
"have",
"attributes",
"that",
"end",
"with",
"the",
"value",
"suffix",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L896-L898
|
14,007
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsByAttributeValueContaining
|
public Elements getElementsByAttributeValueContaining(String key, String match) {
return Collector.collect(new Evaluator.AttributeWithValueContaining(key, match), this);
}
|
java
|
public Elements getElementsByAttributeValueContaining(String key, String match) {
return Collector.collect(new Evaluator.AttributeWithValueContaining(key, match), this);
}
|
[
"public",
"Elements",
"getElementsByAttributeValueContaining",
"(",
"String",
"key",
",",
"String",
"match",
")",
"{",
"return",
"Collector",
".",
"collect",
"(",
"new",
"Evaluator",
".",
"AttributeWithValueContaining",
"(",
"key",
",",
"match",
")",
",",
"this",
")",
";",
"}"
] |
Find elements that have attributes whose value contains the match string. Case insensitive.
@param key name of the attribute
@param match substring of value to search for
@return elements that have attributes containing this text
|
[
"Find",
"elements",
"that",
"have",
"attributes",
"whose",
"value",
"contains",
"the",
"match",
"string",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L907-L909
|
14,008
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.getElementsMatchingText
|
public Elements getElementsMatchingText(String regex) {
Pattern pattern;
try {
pattern = Pattern.compile(regex);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Pattern syntax error: " + regex, e);
}
return getElementsMatchingText(pattern);
}
|
java
|
public Elements getElementsMatchingText(String regex) {
Pattern pattern;
try {
pattern = Pattern.compile(regex);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Pattern syntax error: " + regex, e);
}
return getElementsMatchingText(pattern);
}
|
[
"public",
"Elements",
"getElementsMatchingText",
"(",
"String",
"regex",
")",
"{",
"Pattern",
"pattern",
";",
"try",
"{",
"pattern",
"=",
"Pattern",
".",
"compile",
"(",
"regex",
")",
";",
"}",
"catch",
"(",
"PatternSyntaxException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Pattern syntax error: \"",
"+",
"regex",
",",
"e",
")",
";",
"}",
"return",
"getElementsMatchingText",
"(",
"pattern",
")",
";",
"}"
] |
Find elements whose text matches the supplied regular expression.
@param regex regular expression to match text against. You can use <a href="http://java.sun.com/docs/books/tutorial/essential/regex/pattern.html#embedded">embedded flags</a> (such as (?i) and (?m) to control regex options.
@return elements matching the supplied regular expression.
@see Element#text()
|
[
"Find",
"elements",
"whose",
"text",
"matches",
"the",
"supplied",
"regular",
"expression",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L1003-L1011
|
14,009
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/ConstrainableInputStream.java
|
ConstrainableInputStream.wrap
|
public static ConstrainableInputStream wrap(InputStream in, int bufferSize, int maxSize) {
return in instanceof ConstrainableInputStream
? (ConstrainableInputStream) in
: new ConstrainableInputStream(in, bufferSize, maxSize);
}
|
java
|
public static ConstrainableInputStream wrap(InputStream in, int bufferSize, int maxSize) {
return in instanceof ConstrainableInputStream
? (ConstrainableInputStream) in
: new ConstrainableInputStream(in, bufferSize, maxSize);
}
|
[
"public",
"static",
"ConstrainableInputStream",
"wrap",
"(",
"InputStream",
"in",
",",
"int",
"bufferSize",
",",
"int",
"maxSize",
")",
"{",
"return",
"in",
"instanceof",
"ConstrainableInputStream",
"?",
"(",
"ConstrainableInputStream",
")",
"in",
":",
"new",
"ConstrainableInputStream",
"(",
"in",
",",
"bufferSize",
",",
"maxSize",
")",
";",
"}"
] |
If this InputStream is not already a ConstrainableInputStream, let it be one.
@param in the input stream to (maybe) wrap
@param bufferSize the buffer size to use when reading
@param maxSize the maximum size to allow to be read. 0 == infinite.
@return a constrainable input stream
|
[
"If",
"this",
"InputStream",
"is",
"not",
"already",
"a",
"ConstrainableInputStream",
"let",
"it",
"be",
"one",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/ConstrainableInputStream.java#L42-L46
|
14,010
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/ConstrainableInputStream.java
|
ConstrainableInputStream.readToByteBuffer
|
public ByteBuffer readToByteBuffer(int max) throws IOException {
Validate.isTrue(max >= 0, "maxSize must be 0 (unlimited) or larger");
final boolean localCapped = max > 0; // still possibly capped in total stream
final int bufferSize = localCapped && max < DefaultSize ? max : DefaultSize;
final byte[] readBuffer = new byte[bufferSize];
final ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);
int read;
int remaining = max;
while (true) {
read = read(readBuffer);
if (read == -1) break;
if (localCapped) { // this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)
if (read >= remaining) {
outStream.write(readBuffer, 0, remaining);
break;
}
remaining -= read;
}
outStream.write(readBuffer, 0, read);
}
return ByteBuffer.wrap(outStream.toByteArray());
}
|
java
|
public ByteBuffer readToByteBuffer(int max) throws IOException {
Validate.isTrue(max >= 0, "maxSize must be 0 (unlimited) or larger");
final boolean localCapped = max > 0; // still possibly capped in total stream
final int bufferSize = localCapped && max < DefaultSize ? max : DefaultSize;
final byte[] readBuffer = new byte[bufferSize];
final ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);
int read;
int remaining = max;
while (true) {
read = read(readBuffer);
if (read == -1) break;
if (localCapped) { // this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)
if (read >= remaining) {
outStream.write(readBuffer, 0, remaining);
break;
}
remaining -= read;
}
outStream.write(readBuffer, 0, read);
}
return ByteBuffer.wrap(outStream.toByteArray());
}
|
[
"public",
"ByteBuffer",
"readToByteBuffer",
"(",
"int",
"max",
")",
"throws",
"IOException",
"{",
"Validate",
".",
"isTrue",
"(",
"max",
">=",
"0",
",",
"\"maxSize must be 0 (unlimited) or larger\"",
")",
";",
"final",
"boolean",
"localCapped",
"=",
"max",
">",
"0",
";",
"// still possibly capped in total stream",
"final",
"int",
"bufferSize",
"=",
"localCapped",
"&&",
"max",
"<",
"DefaultSize",
"?",
"max",
":",
"DefaultSize",
";",
"final",
"byte",
"[",
"]",
"readBuffer",
"=",
"new",
"byte",
"[",
"bufferSize",
"]",
";",
"final",
"ByteArrayOutputStream",
"outStream",
"=",
"new",
"ByteArrayOutputStream",
"(",
"bufferSize",
")",
";",
"int",
"read",
";",
"int",
"remaining",
"=",
"max",
";",
"while",
"(",
"true",
")",
"{",
"read",
"=",
"read",
"(",
"readBuffer",
")",
";",
"if",
"(",
"read",
"==",
"-",
"1",
")",
"break",
";",
"if",
"(",
"localCapped",
")",
"{",
"// this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)",
"if",
"(",
"read",
">=",
"remaining",
")",
"{",
"outStream",
".",
"write",
"(",
"readBuffer",
",",
"0",
",",
"remaining",
")",
";",
"break",
";",
"}",
"remaining",
"-=",
"read",
";",
"}",
"outStream",
".",
"write",
"(",
"readBuffer",
",",
"0",
",",
"read",
")",
";",
"}",
"return",
"ByteBuffer",
".",
"wrap",
"(",
"outStream",
".",
"toByteArray",
"(",
")",
")",
";",
"}"
] |
Reads this inputstream to a ByteBuffer. The supplied max may be less than the inputstream's max, to support
reading just the first bytes.
|
[
"Reads",
"this",
"inputstream",
"to",
"a",
"ByteBuffer",
".",
"The",
"supplied",
"max",
"may",
"be",
"less",
"than",
"the",
"inputstream",
"s",
"max",
"to",
"support",
"reading",
"just",
"the",
"first",
"bytes",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/ConstrainableInputStream.java#L76-L99
|
14,011
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
|
HtmlTreeBuilder.popStackToClose
|
void popStackToClose(String... elNames) {
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
stack.remove(pos);
if (inSorted(next.normalName(), elNames))
break;
}
}
|
java
|
void popStackToClose(String... elNames) {
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
stack.remove(pos);
if (inSorted(next.normalName(), elNames))
break;
}
}
|
[
"void",
"popStackToClose",
"(",
"String",
"...",
"elNames",
")",
"{",
"for",
"(",
"int",
"pos",
"=",
"stack",
".",
"size",
"(",
")",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"{",
"Element",
"next",
"=",
"stack",
".",
"get",
"(",
"pos",
")",
";",
"stack",
".",
"remove",
"(",
"pos",
")",
";",
"if",
"(",
"inSorted",
"(",
"next",
".",
"normalName",
"(",
")",
",",
"elNames",
")",
")",
"break",
";",
"}",
"}"
] |
elnames is sorted, comes from Constants
|
[
"elnames",
"is",
"sorted",
"comes",
"from",
"Constants"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java#L343-L350
|
14,012
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
|
HtmlTreeBuilder.pushActiveFormattingElements
|
void pushActiveFormattingElements(Element in) {
int numSeen = 0;
for (int pos = formattingElements.size() -1; pos >= 0; pos--) {
Element el = formattingElements.get(pos);
if (el == null) // marker
break;
if (isSameFormattingElement(in, el))
numSeen++;
if (numSeen == 3) {
formattingElements.remove(pos);
break;
}
}
formattingElements.add(in);
}
|
java
|
void pushActiveFormattingElements(Element in) {
int numSeen = 0;
for (int pos = formattingElements.size() -1; pos >= 0; pos--) {
Element el = formattingElements.get(pos);
if (el == null) // marker
break;
if (isSameFormattingElement(in, el))
numSeen++;
if (numSeen == 3) {
formattingElements.remove(pos);
break;
}
}
formattingElements.add(in);
}
|
[
"void",
"pushActiveFormattingElements",
"(",
"Element",
"in",
")",
"{",
"int",
"numSeen",
"=",
"0",
";",
"for",
"(",
"int",
"pos",
"=",
"formattingElements",
".",
"size",
"(",
")",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"{",
"Element",
"el",
"=",
"formattingElements",
".",
"get",
"(",
"pos",
")",
";",
"if",
"(",
"el",
"==",
"null",
")",
"// marker",
"break",
";",
"if",
"(",
"isSameFormattingElement",
"(",
"in",
",",
"el",
")",
")",
"numSeen",
"++",
";",
"if",
"(",
"numSeen",
"==",
"3",
")",
"{",
"formattingElements",
".",
"remove",
"(",
"pos",
")",
";",
"break",
";",
"}",
"}",
"formattingElements",
".",
"add",
"(",
"in",
")",
";",
"}"
] |
active formatting elements
|
[
"active",
"formatting",
"elements"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java#L598-L614
|
14,013
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.checkCapacity
|
private void checkCapacity(int minNewSize) {
Validate.isTrue(minNewSize >= size);
int curSize = keys.length;
if (curSize >= minNewSize)
return;
int newSize = curSize >= InitialCapacity ? size * GrowthFactor : InitialCapacity;
if (minNewSize > newSize)
newSize = minNewSize;
keys = copyOf(keys, newSize);
vals = copyOf(vals, newSize);
}
|
java
|
private void checkCapacity(int minNewSize) {
Validate.isTrue(minNewSize >= size);
int curSize = keys.length;
if (curSize >= minNewSize)
return;
int newSize = curSize >= InitialCapacity ? size * GrowthFactor : InitialCapacity;
if (minNewSize > newSize)
newSize = minNewSize;
keys = copyOf(keys, newSize);
vals = copyOf(vals, newSize);
}
|
[
"private",
"void",
"checkCapacity",
"(",
"int",
"minNewSize",
")",
"{",
"Validate",
".",
"isTrue",
"(",
"minNewSize",
">=",
"size",
")",
";",
"int",
"curSize",
"=",
"keys",
".",
"length",
";",
"if",
"(",
"curSize",
">=",
"minNewSize",
")",
"return",
";",
"int",
"newSize",
"=",
"curSize",
">=",
"InitialCapacity",
"?",
"size",
"*",
"GrowthFactor",
":",
"InitialCapacity",
";",
"if",
"(",
"minNewSize",
">",
"newSize",
")",
"newSize",
"=",
"minNewSize",
";",
"keys",
"=",
"copyOf",
"(",
"keys",
",",
"newSize",
")",
";",
"vals",
"=",
"copyOf",
"(",
"vals",
",",
"newSize",
")",
";",
"}"
] |
check there's room for more
|
[
"check",
"there",
"s",
"room",
"for",
"more"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L48-L60
|
14,014
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.copyOf
|
private static String[] copyOf(String[] orig, int size) {
final String[] copy = new String[size];
System.arraycopy(orig, 0, copy, 0,
Math.min(orig.length, size));
return copy;
}
|
java
|
private static String[] copyOf(String[] orig, int size) {
final String[] copy = new String[size];
System.arraycopy(orig, 0, copy, 0,
Math.min(orig.length, size));
return copy;
}
|
[
"private",
"static",
"String",
"[",
"]",
"copyOf",
"(",
"String",
"[",
"]",
"orig",
",",
"int",
"size",
")",
"{",
"final",
"String",
"[",
"]",
"copy",
"=",
"new",
"String",
"[",
"size",
"]",
";",
"System",
".",
"arraycopy",
"(",
"orig",
",",
"0",
",",
"copy",
",",
"0",
",",
"Math",
".",
"min",
"(",
"orig",
".",
"length",
",",
"size",
")",
")",
";",
"return",
"copy",
";",
"}"
] |
simple implementation of Arrays.copy, for support of Android API 8.
|
[
"simple",
"implementation",
"of",
"Arrays",
".",
"copy",
"for",
"support",
"of",
"Android",
"API",
"8",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L63-L68
|
14,015
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.get
|
public String get(String key) {
int i = indexOfKey(key);
return i == NotFound ? EmptyString : checkNotNull(vals[i]);
}
|
java
|
public String get(String key) {
int i = indexOfKey(key);
return i == NotFound ? EmptyString : checkNotNull(vals[i]);
}
|
[
"public",
"String",
"get",
"(",
"String",
"key",
")",
"{",
"int",
"i",
"=",
"indexOfKey",
"(",
"key",
")",
";",
"return",
"i",
"==",
"NotFound",
"?",
"EmptyString",
":",
"checkNotNull",
"(",
"vals",
"[",
"i",
"]",
")",
";",
"}"
] |
Get an attribute value by key.
@param key the (case-sensitive) attribute key
@return the attribute value if set; or empty string if not set (or a boolean attribute).
@see #hasKey(String)
|
[
"Get",
"an",
"attribute",
"value",
"by",
"key",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L99-L102
|
14,016
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.getIgnoreCase
|
public String getIgnoreCase(String key) {
int i = indexOfKeyIgnoreCase(key);
return i == NotFound ? EmptyString : checkNotNull(vals[i]);
}
|
java
|
public String getIgnoreCase(String key) {
int i = indexOfKeyIgnoreCase(key);
return i == NotFound ? EmptyString : checkNotNull(vals[i]);
}
|
[
"public",
"String",
"getIgnoreCase",
"(",
"String",
"key",
")",
"{",
"int",
"i",
"=",
"indexOfKeyIgnoreCase",
"(",
"key",
")",
";",
"return",
"i",
"==",
"NotFound",
"?",
"EmptyString",
":",
"checkNotNull",
"(",
"vals",
"[",
"i",
"]",
")",
";",
"}"
] |
Get an attribute's value by case-insensitive key
@param key the attribute name
@return the first matching attribute value if set; or empty string if not set (ora boolean attribute).
|
[
"Get",
"an",
"attribute",
"s",
"value",
"by",
"case",
"-",
"insensitive",
"key"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L109-L112
|
14,017
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.add
|
private void add(String key, String value) {
checkCapacity(size + 1);
keys[size] = key;
vals[size] = value;
size++;
}
|
java
|
private void add(String key, String value) {
checkCapacity(size + 1);
keys[size] = key;
vals[size] = value;
size++;
}
|
[
"private",
"void",
"add",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"checkCapacity",
"(",
"size",
"+",
"1",
")",
";",
"keys",
"[",
"size",
"]",
"=",
"key",
";",
"vals",
"[",
"size",
"]",
"=",
"value",
";",
"size",
"++",
";",
"}"
] |
adds without checking if this key exists
|
[
"adds",
"without",
"checking",
"if",
"this",
"key",
"exists"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L115-L120
|
14,018
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.put
|
public Attributes put(String key, boolean value) {
if (value)
putIgnoreCase(key, null);
else
remove(key);
return this;
}
|
java
|
public Attributes put(String key, boolean value) {
if (value)
putIgnoreCase(key, null);
else
remove(key);
return this;
}
|
[
"public",
"Attributes",
"put",
"(",
"String",
"key",
",",
"boolean",
"value",
")",
"{",
"if",
"(",
"value",
")",
"putIgnoreCase",
"(",
"key",
",",
"null",
")",
";",
"else",
"remove",
"(",
"key",
")",
";",
"return",
"this",
";",
"}"
] |
Set a new boolean attribute, remove attribute if value is false.
@param key case <b>insensitive</b> attribute key
@param value attribute value
@return these attributes, for chaining
|
[
"Set",
"a",
"new",
"boolean",
"attribute",
"remove",
"attribute",
"if",
"value",
"is",
"false",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L154-L160
|
14,019
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.remove
|
private void remove(int index) {
Validate.isFalse(index >= size);
int shifted = size - index - 1;
if (shifted > 0) {
System.arraycopy(keys, index + 1, keys, index, shifted);
System.arraycopy(vals, index + 1, vals, index, shifted);
}
size--;
keys[size] = null; // release hold
vals[size] = null;
}
|
java
|
private void remove(int index) {
Validate.isFalse(index >= size);
int shifted = size - index - 1;
if (shifted > 0) {
System.arraycopy(keys, index + 1, keys, index, shifted);
System.arraycopy(vals, index + 1, vals, index, shifted);
}
size--;
keys[size] = null; // release hold
vals[size] = null;
}
|
[
"private",
"void",
"remove",
"(",
"int",
"index",
")",
"{",
"Validate",
".",
"isFalse",
"(",
"index",
">=",
"size",
")",
";",
"int",
"shifted",
"=",
"size",
"-",
"index",
"-",
"1",
";",
"if",
"(",
"shifted",
">",
"0",
")",
"{",
"System",
".",
"arraycopy",
"(",
"keys",
",",
"index",
"+",
"1",
",",
"keys",
",",
"index",
",",
"shifted",
")",
";",
"System",
".",
"arraycopy",
"(",
"vals",
",",
"index",
"+",
"1",
",",
"vals",
",",
"index",
",",
"shifted",
")",
";",
"}",
"size",
"--",
";",
"keys",
"[",
"size",
"]",
"=",
"null",
";",
"// release hold",
"vals",
"[",
"size",
"]",
"=",
"null",
";",
"}"
] |
removes and shifts up
|
[
"removes",
"and",
"shifts",
"up"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L175-L185
|
14,020
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.addAll
|
public void addAll(Attributes incoming) {
if (incoming.size() == 0)
return;
checkCapacity(size + incoming.size);
for (Attribute attr : incoming) {
// todo - should this be case insensitive?
put(attr);
}
}
|
java
|
public void addAll(Attributes incoming) {
if (incoming.size() == 0)
return;
checkCapacity(size + incoming.size);
for (Attribute attr : incoming) {
// todo - should this be case insensitive?
put(attr);
}
}
|
[
"public",
"void",
"addAll",
"(",
"Attributes",
"incoming",
")",
"{",
"if",
"(",
"incoming",
".",
"size",
"(",
")",
"==",
"0",
")",
"return",
";",
"checkCapacity",
"(",
"size",
"+",
"incoming",
".",
"size",
")",
";",
"for",
"(",
"Attribute",
"attr",
":",
"incoming",
")",
"{",
"// todo - should this be case insensitive?",
"put",
"(",
"attr",
")",
";",
"}",
"}"
] |
Add all the attributes from the incoming set to this set.
@param incoming attributes to add to these attributes.
|
[
"Add",
"all",
"the",
"attributes",
"from",
"the",
"incoming",
"set",
"to",
"this",
"set",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L237-L247
|
14,021
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.asList
|
public List<Attribute> asList() {
ArrayList<Attribute> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Attribute attr = vals[i] == null ?
new BooleanAttribute(keys[i]) : // deprecated class, but maybe someone still wants it
new Attribute(keys[i], vals[i], Attributes.this);
list.add(attr);
}
return Collections.unmodifiableList(list);
}
|
java
|
public List<Attribute> asList() {
ArrayList<Attribute> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Attribute attr = vals[i] == null ?
new BooleanAttribute(keys[i]) : // deprecated class, but maybe someone still wants it
new Attribute(keys[i], vals[i], Attributes.this);
list.add(attr);
}
return Collections.unmodifiableList(list);
}
|
[
"public",
"List",
"<",
"Attribute",
">",
"asList",
"(",
")",
"{",
"ArrayList",
"<",
"Attribute",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
"size",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"Attribute",
"attr",
"=",
"vals",
"[",
"i",
"]",
"==",
"null",
"?",
"new",
"BooleanAttribute",
"(",
"keys",
"[",
"i",
"]",
")",
":",
"// deprecated class, but maybe someone still wants it",
"new",
"Attribute",
"(",
"keys",
"[",
"i",
"]",
",",
"vals",
"[",
"i",
"]",
",",
"Attributes",
".",
"this",
")",
";",
"list",
".",
"add",
"(",
"attr",
")",
";",
"}",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"list",
")",
";",
"}"
] |
Get the attributes as a List, for iteration.
@return an view of the attributes as an unmodifialbe List.
|
[
"Get",
"the",
"attributes",
"as",
"a",
"List",
"for",
"iteration",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L276-L285
|
14,022
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.html
|
public String html() {
StringBuilder sb = StringUtil.borrowBuilder();
try {
html(sb, (new Document("")).outputSettings()); // output settings a bit funky, but this html() seldom used
} catch (IOException e) { // ought never happen
throw new SerializationException(e);
}
return StringUtil.releaseBuilder(sb);
}
|
java
|
public String html() {
StringBuilder sb = StringUtil.borrowBuilder();
try {
html(sb, (new Document("")).outputSettings()); // output settings a bit funky, but this html() seldom used
} catch (IOException e) { // ought never happen
throw new SerializationException(e);
}
return StringUtil.releaseBuilder(sb);
}
|
[
"public",
"String",
"html",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"try",
"{",
"html",
"(",
"sb",
",",
"(",
"new",
"Document",
"(",
"\"\"",
")",
")",
".",
"outputSettings",
"(",
")",
")",
";",
"// output settings a bit funky, but this html() seldom used",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// ought never happen",
"throw",
"new",
"SerializationException",
"(",
"e",
")",
";",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"sb",
")",
";",
"}"
] |
Get the HTML representation of these attributes.
@return HTML
@throws SerializationException if the HTML representation of the attributes cannot be constructed.
|
[
"Get",
"the",
"HTML",
"representation",
"of",
"these",
"attributes",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L301-L309
|
14,023
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attributes.java
|
Attributes.normalize
|
public void normalize() {
for (int i = 0; i < size; i++) {
keys[i] = lowerCase(keys[i]);
}
}
|
java
|
public void normalize() {
for (int i = 0; i < size; i++) {
keys[i] = lowerCase(keys[i]);
}
}
|
[
"public",
"void",
"normalize",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"keys",
"[",
"i",
"]",
"=",
"lowerCase",
"(",
"keys",
"[",
"i",
"]",
")",
";",
"}",
"}"
] |
Internal method. Lowercases all keys.
|
[
"Internal",
"method",
".",
"Lowercases",
"all",
"keys",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attributes.java#L379-L383
|
14,024
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/TextNode.java
|
TextNode.splitText
|
public TextNode splitText(int offset) {
final String text = coreValue();
Validate.isTrue(offset >= 0, "Split offset must be not be negative");
Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");
String head = text.substring(0, offset);
String tail = text.substring(offset);
text(head);
TextNode tailNode = new TextNode(tail);
if (parent() != null)
parent().addChildren(siblingIndex()+1, tailNode);
return tailNode;
}
|
java
|
public TextNode splitText(int offset) {
final String text = coreValue();
Validate.isTrue(offset >= 0, "Split offset must be not be negative");
Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");
String head = text.substring(0, offset);
String tail = text.substring(offset);
text(head);
TextNode tailNode = new TextNode(tail);
if (parent() != null)
parent().addChildren(siblingIndex()+1, tailNode);
return tailNode;
}
|
[
"public",
"TextNode",
"splitText",
"(",
"int",
"offset",
")",
"{",
"final",
"String",
"text",
"=",
"coreValue",
"(",
")",
";",
"Validate",
".",
"isTrue",
"(",
"offset",
">=",
"0",
",",
"\"Split offset must be not be negative\"",
")",
";",
"Validate",
".",
"isTrue",
"(",
"offset",
"<",
"text",
".",
"length",
"(",
")",
",",
"\"Split offset must not be greater than current text length\"",
")",
";",
"String",
"head",
"=",
"text",
".",
"substring",
"(",
"0",
",",
"offset",
")",
";",
"String",
"tail",
"=",
"text",
".",
"substring",
"(",
"offset",
")",
";",
"text",
"(",
"head",
")",
";",
"TextNode",
"tailNode",
"=",
"new",
"TextNode",
"(",
"tail",
")",
";",
"if",
"(",
"parent",
"(",
")",
"!=",
"null",
")",
"parent",
"(",
")",
".",
"addChildren",
"(",
"siblingIndex",
"(",
")",
"+",
"1",
",",
"tailNode",
")",
";",
"return",
"tailNode",
";",
"}"
] |
Split this text node into two nodes at the specified string offset. After splitting, this node will contain the
original text up to the offset, and will have a new text node sibling containing the text after the offset.
@param offset string offset point to split node at.
@return the newly created text node containing the text after the offset.
|
[
"Split",
"this",
"text",
"node",
"into",
"two",
"nodes",
"at",
"the",
"specified",
"string",
"offset",
".",
"After",
"splitting",
"this",
"node",
"will",
"contain",
"the",
"original",
"text",
"up",
"to",
"the",
"offset",
"and",
"will",
"have",
"a",
"new",
"text",
"node",
"sibling",
"containing",
"the",
"text",
"after",
"the",
"offset",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/TextNode.java#L81-L94
|
14,025
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/TokenQueue.java
|
TokenQueue.matches
|
public boolean matches(String seq) {
return queue.regionMatches(true, pos, seq, 0, seq.length());
}
|
java
|
public boolean matches(String seq) {
return queue.regionMatches(true, pos, seq, 0, seq.length());
}
|
[
"public",
"boolean",
"matches",
"(",
"String",
"seq",
")",
"{",
"return",
"queue",
".",
"regionMatches",
"(",
"true",
",",
"pos",
",",
"seq",
",",
"0",
",",
"seq",
".",
"length",
"(",
")",
")",
";",
"}"
] |
Tests if the next characters on the queue match the sequence. Case insensitive.
@param seq String to check queue for.
@return true if the next characters match.
|
[
"Tests",
"if",
"the",
"next",
"characters",
"on",
"the",
"queue",
"match",
"the",
"sequence",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/TokenQueue.java#L69-L71
|
14,026
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/TokenQueue.java
|
TokenQueue.matchesAny
|
public boolean matchesAny(String... seq) {
for (String s : seq) {
if (matches(s))
return true;
}
return false;
}
|
java
|
public boolean matchesAny(String... seq) {
for (String s : seq) {
if (matches(s))
return true;
}
return false;
}
|
[
"public",
"boolean",
"matchesAny",
"(",
"String",
"...",
"seq",
")",
"{",
"for",
"(",
"String",
"s",
":",
"seq",
")",
"{",
"if",
"(",
"matches",
"(",
"s",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Tests if the next characters match any of the sequences. Case insensitive.
@param seq list of strings to case insensitively check for
@return true of any matched, false if none did
|
[
"Tests",
"if",
"the",
"next",
"characters",
"match",
"any",
"of",
"the",
"sequences",
".",
"Case",
"insensitive",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/TokenQueue.java#L88-L94
|
14,027
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/TokenQueue.java
|
TokenQueue.consumeTo
|
public String consumeTo(String seq) {
int offset = queue.indexOf(seq, pos);
if (offset != -1) {
String consumed = queue.substring(pos, offset);
pos += consumed.length();
return consumed;
} else {
return remainder();
}
}
|
java
|
public String consumeTo(String seq) {
int offset = queue.indexOf(seq, pos);
if (offset != -1) {
String consumed = queue.substring(pos, offset);
pos += consumed.length();
return consumed;
} else {
return remainder();
}
}
|
[
"public",
"String",
"consumeTo",
"(",
"String",
"seq",
")",
"{",
"int",
"offset",
"=",
"queue",
".",
"indexOf",
"(",
"seq",
",",
"pos",
")",
";",
"if",
"(",
"offset",
"!=",
"-",
"1",
")",
"{",
"String",
"consumed",
"=",
"queue",
".",
"substring",
"(",
"pos",
",",
"offset",
")",
";",
"pos",
"+=",
"consumed",
".",
"length",
"(",
")",
";",
"return",
"consumed",
";",
"}",
"else",
"{",
"return",
"remainder",
"(",
")",
";",
"}",
"}"
] |
Pulls a string off the queue, up to but exclusive of the match sequence, or to the queue running out.
@param seq String to end on (and not include in return, but leave on queue). <b>Case sensitive.</b>
@return The matched data consumed from queue.
|
[
"Pulls",
"a",
"string",
"off",
"the",
"queue",
"up",
"to",
"but",
"exclusive",
"of",
"the",
"match",
"sequence",
"or",
"to",
"the",
"queue",
"running",
"out",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/TokenQueue.java#L180-L189
|
14,028
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/TokenQueue.java
|
TokenQueue.unescape
|
public static String unescape(String in) {
StringBuilder out = StringUtil.borrowBuilder();
char last = 0;
for (char c : in.toCharArray()) {
if (c == ESC) {
if (last != 0 && last == ESC)
out.append(c);
}
else
out.append(c);
last = c;
}
return StringUtil.releaseBuilder(out);
}
|
java
|
public static String unescape(String in) {
StringBuilder out = StringUtil.borrowBuilder();
char last = 0;
for (char c : in.toCharArray()) {
if (c == ESC) {
if (last != 0 && last == ESC)
out.append(c);
}
else
out.append(c);
last = c;
}
return StringUtil.releaseBuilder(out);
}
|
[
"public",
"static",
"String",
"unescape",
"(",
"String",
"in",
")",
"{",
"StringBuilder",
"out",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"char",
"last",
"=",
"0",
";",
"for",
"(",
"char",
"c",
":",
"in",
".",
"toCharArray",
"(",
")",
")",
"{",
"if",
"(",
"c",
"==",
"ESC",
")",
"{",
"if",
"(",
"last",
"!=",
"0",
"&&",
"last",
"==",
"ESC",
")",
"out",
".",
"append",
"(",
"c",
")",
";",
"}",
"else",
"out",
".",
"append",
"(",
"c",
")",
";",
"last",
"=",
"c",
";",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"out",
")",
";",
"}"
] |
Unescape a \ escaped string.
@param in backslash escaped string
@return unescaped string
|
[
"Unescape",
"a",
"\\",
"escaped",
"string",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/TokenQueue.java#L304-L317
|
14,029
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/XmlDeclaration.java
|
XmlDeclaration.getWholeDeclaration
|
public String getWholeDeclaration() {
StringBuilder sb = StringUtil.borrowBuilder();
try {
getWholeDeclaration(sb, new Document.OutputSettings());
} catch (IOException e) {
throw new SerializationException(e);
}
return StringUtil.releaseBuilder(sb).trim();
}
|
java
|
public String getWholeDeclaration() {
StringBuilder sb = StringUtil.borrowBuilder();
try {
getWholeDeclaration(sb, new Document.OutputSettings());
} catch (IOException e) {
throw new SerializationException(e);
}
return StringUtil.releaseBuilder(sb).trim();
}
|
[
"public",
"String",
"getWholeDeclaration",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"try",
"{",
"getWholeDeclaration",
"(",
"sb",
",",
"new",
"Document",
".",
"OutputSettings",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"SerializationException",
"(",
"e",
")",
";",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"sb",
")",
".",
"trim",
"(",
")",
";",
"}"
] |
Get the unencoded XML declaration.
@return XML declaration
|
[
"Get",
"the",
"unencoded",
"XML",
"declaration",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/XmlDeclaration.java#L55-L63
|
14,030
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/ParseSettings.java
|
ParseSettings.normalizeTag
|
public String normalizeTag(String name) {
name = name.trim();
if (!preserveTagCase)
name = lowerCase(name);
return name;
}
|
java
|
public String normalizeTag(String name) {
name = name.trim();
if (!preserveTagCase)
name = lowerCase(name);
return name;
}
|
[
"public",
"String",
"normalizeTag",
"(",
"String",
"name",
")",
"{",
"name",
"=",
"name",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"preserveTagCase",
")",
"name",
"=",
"lowerCase",
"(",
"name",
")",
";",
"return",
"name",
";",
"}"
] |
Normalizes a tag name according to the case preservation setting.
|
[
"Normalizes",
"a",
"tag",
"name",
"according",
"to",
"the",
"case",
"preservation",
"setting",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/ParseSettings.java#L41-L46
|
14,031
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/ParseSettings.java
|
ParseSettings.normalizeAttribute
|
public String normalizeAttribute(String name) {
name = name.trim();
if (!preserveAttributeCase)
name = lowerCase(name);
return name;
}
|
java
|
public String normalizeAttribute(String name) {
name = name.trim();
if (!preserveAttributeCase)
name = lowerCase(name);
return name;
}
|
[
"public",
"String",
"normalizeAttribute",
"(",
"String",
"name",
")",
"{",
"name",
"=",
"name",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"preserveAttributeCase",
")",
"name",
"=",
"lowerCase",
"(",
"name",
")",
";",
"return",
"name",
";",
"}"
] |
Normalizes an attribute according to the case preservation setting.
|
[
"Normalizes",
"an",
"attribute",
"according",
"to",
"the",
"case",
"preservation",
"setting",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/ParseSettings.java#L51-L56
|
14,032
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/Parser.java
|
Parser.setTrackErrors
|
public Parser setTrackErrors(int maxErrors) {
errors = maxErrors > 0 ? ParseErrorList.tracking(maxErrors) : ParseErrorList.noTracking();
return this;
}
|
java
|
public Parser setTrackErrors(int maxErrors) {
errors = maxErrors > 0 ? ParseErrorList.tracking(maxErrors) : ParseErrorList.noTracking();
return this;
}
|
[
"public",
"Parser",
"setTrackErrors",
"(",
"int",
"maxErrors",
")",
"{",
"errors",
"=",
"maxErrors",
">",
"0",
"?",
"ParseErrorList",
".",
"tracking",
"(",
"maxErrors",
")",
":",
"ParseErrorList",
".",
"noTracking",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
Enable or disable parse error tracking for the next parse.
@param maxErrors the maximum number of errors to track. Set to 0 to disable.
@return this, for chaining
|
[
"Enable",
"or",
"disable",
"parse",
"error",
"tracking",
"for",
"the",
"next",
"parse",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/Parser.java#L74-L77
|
14,033
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/Parser.java
|
Parser.parse
|
public static Document parse(String html, String baseUri) {
TreeBuilder treeBuilder = new HtmlTreeBuilder();
return treeBuilder.parse(new StringReader(html), baseUri, new Parser(treeBuilder));
}
|
java
|
public static Document parse(String html, String baseUri) {
TreeBuilder treeBuilder = new HtmlTreeBuilder();
return treeBuilder.parse(new StringReader(html), baseUri, new Parser(treeBuilder));
}
|
[
"public",
"static",
"Document",
"parse",
"(",
"String",
"html",
",",
"String",
"baseUri",
")",
"{",
"TreeBuilder",
"treeBuilder",
"=",
"new",
"HtmlTreeBuilder",
"(",
")",
";",
"return",
"treeBuilder",
".",
"parse",
"(",
"new",
"StringReader",
"(",
"html",
")",
",",
"baseUri",
",",
"new",
"Parser",
"(",
"treeBuilder",
")",
")",
";",
"}"
] |
Parse HTML into a Document.
@param html HTML to parse
@param baseUri base URI of document (i.e. original fetch location), for resolving relative URLs.
@return parsed Document
|
[
"Parse",
"HTML",
"into",
"a",
"Document",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/Parser.java#L105-L108
|
14,034
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/Parser.java
|
Parser.parseXmlFragment
|
public static List<Node> parseXmlFragment(String fragmentXml, String baseUri) {
XmlTreeBuilder treeBuilder = new XmlTreeBuilder();
return treeBuilder.parseFragment(fragmentXml, baseUri, new Parser(treeBuilder));
}
|
java
|
public static List<Node> parseXmlFragment(String fragmentXml, String baseUri) {
XmlTreeBuilder treeBuilder = new XmlTreeBuilder();
return treeBuilder.parseFragment(fragmentXml, baseUri, new Parser(treeBuilder));
}
|
[
"public",
"static",
"List",
"<",
"Node",
">",
"parseXmlFragment",
"(",
"String",
"fragmentXml",
",",
"String",
"baseUri",
")",
"{",
"XmlTreeBuilder",
"treeBuilder",
"=",
"new",
"XmlTreeBuilder",
"(",
")",
";",
"return",
"treeBuilder",
".",
"parseFragment",
"(",
"fragmentXml",
",",
"baseUri",
",",
"new",
"Parser",
"(",
"treeBuilder",
")",
")",
";",
"}"
] |
Parse a fragment of XML into a list of nodes.
@param fragmentXml the fragment of XML to parse
@param baseUri base URI of document (i.e. original fetch location), for resolving relative URLs.
@return list of nodes parsed from the input XML.
|
[
"Parse",
"a",
"fragment",
"of",
"XML",
"into",
"a",
"list",
"of",
"nodes",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/Parser.java#L150-L153
|
14,035
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/Parser.java
|
Parser.unescapeEntities
|
public static String unescapeEntities(String string, boolean inAttribute) {
Tokeniser tokeniser = new Tokeniser(new CharacterReader(string), ParseErrorList.noTracking());
return tokeniser.unescapeEntities(inAttribute);
}
|
java
|
public static String unescapeEntities(String string, boolean inAttribute) {
Tokeniser tokeniser = new Tokeniser(new CharacterReader(string), ParseErrorList.noTracking());
return tokeniser.unescapeEntities(inAttribute);
}
|
[
"public",
"static",
"String",
"unescapeEntities",
"(",
"String",
"string",
",",
"boolean",
"inAttribute",
")",
"{",
"Tokeniser",
"tokeniser",
"=",
"new",
"Tokeniser",
"(",
"new",
"CharacterReader",
"(",
"string",
")",
",",
"ParseErrorList",
".",
"noTracking",
"(",
")",
")",
";",
"return",
"tokeniser",
".",
"unescapeEntities",
"(",
"inAttribute",
")",
";",
"}"
] |
Utility method to unescape HTML entities from a string
@param string HTML escaped string
@param inAttribute if the string is to be escaped in strict mode (as attributes are)
@return an unescaped string
|
[
"Utility",
"method",
"to",
"unescape",
"HTML",
"entities",
"from",
"a",
"string"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/Parser.java#L183-L186
|
14,036
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/Tokeniser.java
|
Tokeniser.unescapeEntities
|
String unescapeEntities(boolean inAttribute) {
StringBuilder builder = StringUtil.borrowBuilder();
while (!reader.isEmpty()) {
builder.append(reader.consumeTo('&'));
if (reader.matches('&')) {
reader.consume();
int[] c = consumeCharacterReference(null, inAttribute);
if (c == null || c.length==0)
builder.append('&');
else {
builder.appendCodePoint(c[0]);
if (c.length == 2)
builder.appendCodePoint(c[1]);
}
}
}
return StringUtil.releaseBuilder(builder);
}
|
java
|
String unescapeEntities(boolean inAttribute) {
StringBuilder builder = StringUtil.borrowBuilder();
while (!reader.isEmpty()) {
builder.append(reader.consumeTo('&'));
if (reader.matches('&')) {
reader.consume();
int[] c = consumeCharacterReference(null, inAttribute);
if (c == null || c.length==0)
builder.append('&');
else {
builder.appendCodePoint(c[0]);
if (c.length == 2)
builder.appendCodePoint(c[1]);
}
}
}
return StringUtil.releaseBuilder(builder);
}
|
[
"String",
"unescapeEntities",
"(",
"boolean",
"inAttribute",
")",
"{",
"StringBuilder",
"builder",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"while",
"(",
"!",
"reader",
".",
"isEmpty",
"(",
")",
")",
"{",
"builder",
".",
"append",
"(",
"reader",
".",
"consumeTo",
"(",
"'",
"'",
")",
")",
";",
"if",
"(",
"reader",
".",
"matches",
"(",
"'",
"'",
")",
")",
"{",
"reader",
".",
"consume",
"(",
")",
";",
"int",
"[",
"]",
"c",
"=",
"consumeCharacterReference",
"(",
"null",
",",
"inAttribute",
")",
";",
"if",
"(",
"c",
"==",
"null",
"||",
"c",
".",
"length",
"==",
"0",
")",
"builder",
".",
"append",
"(",
"'",
"'",
")",
";",
"else",
"{",
"builder",
".",
"appendCodePoint",
"(",
"c",
"[",
"0",
"]",
")",
";",
"if",
"(",
"c",
".",
"length",
"==",
"2",
")",
"builder",
".",
"appendCodePoint",
"(",
"c",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"builder",
")",
";",
"}"
] |
Utility method to consume reader and unescape entities found within.
@param inAttribute if the text to be unescaped is in an attribute
@return unescaped string from reader
|
[
"Utility",
"method",
"to",
"consume",
"reader",
"and",
"unescape",
"entities",
"found",
"within",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/Tokeniser.java#L277-L295
|
14,037
|
jhy/jsoup
|
src/main/java/org/jsoup/examples/HtmlToPlainText.java
|
HtmlToPlainText.getPlainText
|
public String getPlainText(Element element) {
FormattingVisitor formatter = new FormattingVisitor();
NodeTraversor.traverse(formatter, element); // walk the DOM, and call .head() and .tail() for each node
return formatter.toString();
}
|
java
|
public String getPlainText(Element element) {
FormattingVisitor formatter = new FormattingVisitor();
NodeTraversor.traverse(formatter, element); // walk the DOM, and call .head() and .tail() for each node
return formatter.toString();
}
|
[
"public",
"String",
"getPlainText",
"(",
"Element",
"element",
")",
"{",
"FormattingVisitor",
"formatter",
"=",
"new",
"FormattingVisitor",
"(",
")",
";",
"NodeTraversor",
".",
"traverse",
"(",
"formatter",
",",
"element",
")",
";",
"// walk the DOM, and call .head() and .tail() for each node",
"return",
"formatter",
".",
"toString",
"(",
")",
";",
"}"
] |
Format an Element to plain-text
@param element the root element to format
@return formatted text
|
[
"Format",
"an",
"Element",
"to",
"plain",
"-",
"text"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/examples/HtmlToPlainText.java#L61-L66
|
14,038
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Comment.java
|
Comment.isXmlDeclaration
|
public boolean isXmlDeclaration() {
String data = getData();
return (data.length() > 1 && (data.startsWith("!") || data.startsWith("?")));
}
|
java
|
public boolean isXmlDeclaration() {
String data = getData();
return (data.length() > 1 && (data.startsWith("!") || data.startsWith("?")));
}
|
[
"public",
"boolean",
"isXmlDeclaration",
"(",
")",
"{",
"String",
"data",
"=",
"getData",
"(",
")",
";",
"return",
"(",
"data",
".",
"length",
"(",
")",
">",
"1",
"&&",
"(",
"data",
".",
"startsWith",
"(",
"\"!\"",
")",
"||",
"data",
".",
"startsWith",
"(",
"\"?\"",
")",
")",
")",
";",
"}"
] |
Check if this comment looks like an XML Declaration.
@return true if it looks like, maybe, it's an XML Declaration.
|
[
"Check",
"if",
"this",
"comment",
"looks",
"like",
"an",
"XML",
"Declaration",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Comment.java#L65-L68
|
14,039
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Comment.java
|
Comment.asXmlDeclaration
|
public XmlDeclaration asXmlDeclaration() {
String data = getData();
Document doc = Jsoup.parse("<" + data.substring(1, data.length() -1) + ">", baseUri(), Parser.xmlParser());
XmlDeclaration decl = null;
if (doc.children().size() > 0) {
Element el = doc.child(0);
decl = new XmlDeclaration(NodeUtils.parser(doc).settings().normalizeTag(el.tagName()), data.startsWith("!"));
decl.attributes().addAll(el.attributes());
}
return decl;
}
|
java
|
public XmlDeclaration asXmlDeclaration() {
String data = getData();
Document doc = Jsoup.parse("<" + data.substring(1, data.length() -1) + ">", baseUri(), Parser.xmlParser());
XmlDeclaration decl = null;
if (doc.children().size() > 0) {
Element el = doc.child(0);
decl = new XmlDeclaration(NodeUtils.parser(doc).settings().normalizeTag(el.tagName()), data.startsWith("!"));
decl.attributes().addAll(el.attributes());
}
return decl;
}
|
[
"public",
"XmlDeclaration",
"asXmlDeclaration",
"(",
")",
"{",
"String",
"data",
"=",
"getData",
"(",
")",
";",
"Document",
"doc",
"=",
"Jsoup",
".",
"parse",
"(",
"\"<\"",
"+",
"data",
".",
"substring",
"(",
"1",
",",
"data",
".",
"length",
"(",
")",
"-",
"1",
")",
"+",
"\">\"",
",",
"baseUri",
"(",
")",
",",
"Parser",
".",
"xmlParser",
"(",
")",
")",
";",
"XmlDeclaration",
"decl",
"=",
"null",
";",
"if",
"(",
"doc",
".",
"children",
"(",
")",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"Element",
"el",
"=",
"doc",
".",
"child",
"(",
"0",
")",
";",
"decl",
"=",
"new",
"XmlDeclaration",
"(",
"NodeUtils",
".",
"parser",
"(",
"doc",
")",
".",
"settings",
"(",
")",
".",
"normalizeTag",
"(",
"el",
".",
"tagName",
"(",
")",
")",
",",
"data",
".",
"startsWith",
"(",
"\"!\"",
")",
")",
";",
"decl",
".",
"attributes",
"(",
")",
".",
"addAll",
"(",
"el",
".",
"attributes",
"(",
")",
")",
";",
"}",
"return",
"decl",
";",
"}"
] |
Attempt to cast this comment to an XML Declaration note.
@return an XML declaration if it could be parsed as one, null otherwise.
|
[
"Attempt",
"to",
"cast",
"this",
"comment",
"to",
"an",
"XML",
"Declaration",
"note",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Comment.java#L74-L84
|
14,040
|
jhy/jsoup
|
src/main/java/org/jsoup/select/QueryParser.java
|
QueryParser.parse
|
public static Evaluator parse(String query) {
try {
QueryParser p = new QueryParser(query);
return p.parse();
} catch (IllegalArgumentException e) {
throw new Selector.SelectorParseException(e.getMessage());
}
}
|
java
|
public static Evaluator parse(String query) {
try {
QueryParser p = new QueryParser(query);
return p.parse();
} catch (IllegalArgumentException e) {
throw new Selector.SelectorParseException(e.getMessage());
}
}
|
[
"public",
"static",
"Evaluator",
"parse",
"(",
"String",
"query",
")",
"{",
"try",
"{",
"QueryParser",
"p",
"=",
"new",
"QueryParser",
"(",
"query",
")",
";",
"return",
"p",
".",
"parse",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"Selector",
".",
"SelectorParseException",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Parse a CSS query into an Evaluator.
@param query CSS query
@return Evaluator
|
[
"Parse",
"a",
"CSS",
"query",
"into",
"an",
"Evaluator",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/QueryParser.java#L39-L46
|
14,041
|
jhy/jsoup
|
src/main/java/org/jsoup/select/QueryParser.java
|
QueryParser.parse
|
Evaluator parse() {
tq.consumeWhitespace();
if (tq.matchesAny(combinators)) { // if starts with a combinator, use root as elements
evals.add(new StructuralEvaluator.Root());
combinator(tq.consume());
} else {
findElements();
}
while (!tq.isEmpty()) {
// hierarchy and extras
boolean seenWhite = tq.consumeWhitespace();
if (tq.matchesAny(combinators)) {
combinator(tq.consume());
} else if (seenWhite) {
combinator(' ');
} else { // E.class, E#id, E[attr] etc. AND
findElements(); // take next el, #. etc off queue
}
}
if (evals.size() == 1)
return evals.get(0);
return new CombiningEvaluator.And(evals);
}
|
java
|
Evaluator parse() {
tq.consumeWhitespace();
if (tq.matchesAny(combinators)) { // if starts with a combinator, use root as elements
evals.add(new StructuralEvaluator.Root());
combinator(tq.consume());
} else {
findElements();
}
while (!tq.isEmpty()) {
// hierarchy and extras
boolean seenWhite = tq.consumeWhitespace();
if (tq.matchesAny(combinators)) {
combinator(tq.consume());
} else if (seenWhite) {
combinator(' ');
} else { // E.class, E#id, E[attr] etc. AND
findElements(); // take next el, #. etc off queue
}
}
if (evals.size() == 1)
return evals.get(0);
return new CombiningEvaluator.And(evals);
}
|
[
"Evaluator",
"parse",
"(",
")",
"{",
"tq",
".",
"consumeWhitespace",
"(",
")",
";",
"if",
"(",
"tq",
".",
"matchesAny",
"(",
"combinators",
")",
")",
"{",
"// if starts with a combinator, use root as elements",
"evals",
".",
"add",
"(",
"new",
"StructuralEvaluator",
".",
"Root",
"(",
")",
")",
";",
"combinator",
"(",
"tq",
".",
"consume",
"(",
")",
")",
";",
"}",
"else",
"{",
"findElements",
"(",
")",
";",
"}",
"while",
"(",
"!",
"tq",
".",
"isEmpty",
"(",
")",
")",
"{",
"// hierarchy and extras",
"boolean",
"seenWhite",
"=",
"tq",
".",
"consumeWhitespace",
"(",
")",
";",
"if",
"(",
"tq",
".",
"matchesAny",
"(",
"combinators",
")",
")",
"{",
"combinator",
"(",
"tq",
".",
"consume",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"seenWhite",
")",
"{",
"combinator",
"(",
"'",
"'",
")",
";",
"}",
"else",
"{",
"// E.class, E#id, E[attr] etc. AND",
"findElements",
"(",
")",
";",
"// take next el, #. etc off queue",
"}",
"}",
"if",
"(",
"evals",
".",
"size",
"(",
")",
"==",
"1",
")",
"return",
"evals",
".",
"get",
"(",
"0",
")",
";",
"return",
"new",
"CombiningEvaluator",
".",
"And",
"(",
"evals",
")",
";",
"}"
] |
Parse the query
@return Evaluator
|
[
"Parse",
"the",
"query"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/QueryParser.java#L52-L79
|
14,042
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/NodeUtils.java
|
NodeUtils.parser
|
static Parser parser(Node node) {
Document doc = node.ownerDocument();
return doc != null && doc.parser() != null ? doc.parser() : new Parser(new HtmlTreeBuilder());
}
|
java
|
static Parser parser(Node node) {
Document doc = node.ownerDocument();
return doc != null && doc.parser() != null ? doc.parser() : new Parser(new HtmlTreeBuilder());
}
|
[
"static",
"Parser",
"parser",
"(",
"Node",
"node",
")",
"{",
"Document",
"doc",
"=",
"node",
".",
"ownerDocument",
"(",
")",
";",
"return",
"doc",
"!=",
"null",
"&&",
"doc",
".",
"parser",
"(",
")",
"!=",
"null",
"?",
"doc",
".",
"parser",
"(",
")",
":",
"new",
"Parser",
"(",
"new",
"HtmlTreeBuilder",
"(",
")",
")",
";",
"}"
] |
Get the parser that was used to make this node, or the default HTML parser if it has no parent.
|
[
"Get",
"the",
"parser",
"that",
"was",
"used",
"to",
"make",
"this",
"node",
"or",
"the",
"default",
"HTML",
"parser",
"if",
"it",
"has",
"no",
"parent",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/NodeUtils.java#L23-L26
|
14,043
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Selector.java
|
Selector.selectFirst
|
public static Element selectFirst(String cssQuery, Element root) {
Validate.notEmpty(cssQuery);
return Collector.findFirst(QueryParser.parse(cssQuery), root);
}
|
java
|
public static Element selectFirst(String cssQuery, Element root) {
Validate.notEmpty(cssQuery);
return Collector.findFirst(QueryParser.parse(cssQuery), root);
}
|
[
"public",
"static",
"Element",
"selectFirst",
"(",
"String",
"cssQuery",
",",
"Element",
"root",
")",
"{",
"Validate",
".",
"notEmpty",
"(",
"cssQuery",
")",
";",
"return",
"Collector",
".",
"findFirst",
"(",
"QueryParser",
".",
"parse",
"(",
"cssQuery",
")",
",",
"root",
")",
";",
"}"
] |
Find the first element that matches the query.
@param cssQuery CSS selector
@param root root element to descend into
@return the matching element, or <b>null</b> if none.
|
[
"Find",
"the",
"first",
"element",
"that",
"matches",
"the",
"query",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Selector.java#L157-L160
|
14,044
|
alibaba/transmittable-thread-local
|
src/main/java/com/alibaba/ttl/TtlRecursiveTask.java
|
TtlRecursiveTask.exec
|
protected final boolean exec() {
Object backup = replay(captured);
try {
result = compute();
return true;
} finally {
restore(backup);
}
}
|
java
|
protected final boolean exec() {
Object backup = replay(captured);
try {
result = compute();
return true;
} finally {
restore(backup);
}
}
|
[
"protected",
"final",
"boolean",
"exec",
"(",
")",
"{",
"Object",
"backup",
"=",
"replay",
"(",
"captured",
")",
";",
"try",
"{",
"result",
"=",
"compute",
"(",
")",
";",
"return",
"true",
";",
"}",
"finally",
"{",
"restore",
"(",
"backup",
")",
";",
"}",
"}"
] |
Implements execution conventions for RecursiveTask.
|
[
"Implements",
"execution",
"conventions",
"for",
"RecursiveTask",
"."
] |
30b4d99cdb7064b4c1797d2e40bfa07adce8e7f9
|
https://github.com/alibaba/transmittable-thread-local/blob/30b4d99cdb7064b4c1797d2e40bfa07adce8e7f9/src/main/java/com/alibaba/ttl/TtlRecursiveTask.java#L52-L60
|
14,045
|
kiegroup/drools
|
drools-verifier/drools-verifier-drl/src/main/java/org/drools/verifier/report/components/MissingRange.java
|
MissingRange.getReversedOperator
|
public static Operator getReversedOperator(Operator e) {
if ( e.equals( Operator.NOT_EQUAL ) ) {
return Operator.EQUAL;
} else if ( e.equals( Operator.EQUAL ) ) {
return Operator.NOT_EQUAL;
} else if ( e.equals( Operator.GREATER ) ) {
return Operator.LESS_OR_EQUAL;
} else if ( e.equals( Operator.LESS ) ) {
return Operator.GREATER_OR_EQUAL;
} else if ( e.equals( Operator.GREATER_OR_EQUAL ) ) {
return Operator.LESS;
} else if ( e.equals( Operator.LESS_OR_EQUAL ) ) {
return Operator.GREATER;
} else {
return Operator.determineOperator( e.getOperatorString(),
!e.isNegated() );
}
}
|
java
|
public static Operator getReversedOperator(Operator e) {
if ( e.equals( Operator.NOT_EQUAL ) ) {
return Operator.EQUAL;
} else if ( e.equals( Operator.EQUAL ) ) {
return Operator.NOT_EQUAL;
} else if ( e.equals( Operator.GREATER ) ) {
return Operator.LESS_OR_EQUAL;
} else if ( e.equals( Operator.LESS ) ) {
return Operator.GREATER_OR_EQUAL;
} else if ( e.equals( Operator.GREATER_OR_EQUAL ) ) {
return Operator.LESS;
} else if ( e.equals( Operator.LESS_OR_EQUAL ) ) {
return Operator.GREATER;
} else {
return Operator.determineOperator( e.getOperatorString(),
!e.isNegated() );
}
}
|
[
"public",
"static",
"Operator",
"getReversedOperator",
"(",
"Operator",
"e",
")",
"{",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"NOT_EQUAL",
")",
")",
"{",
"return",
"Operator",
".",
"EQUAL",
";",
"}",
"else",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"EQUAL",
")",
")",
"{",
"return",
"Operator",
".",
"NOT_EQUAL",
";",
"}",
"else",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"GREATER",
")",
")",
"{",
"return",
"Operator",
".",
"LESS_OR_EQUAL",
";",
"}",
"else",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"LESS",
")",
")",
"{",
"return",
"Operator",
".",
"GREATER_OR_EQUAL",
";",
"}",
"else",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"GREATER_OR_EQUAL",
")",
")",
"{",
"return",
"Operator",
".",
"LESS",
";",
"}",
"else",
"if",
"(",
"e",
".",
"equals",
"(",
"Operator",
".",
"LESS_OR_EQUAL",
")",
")",
"{",
"return",
"Operator",
".",
"GREATER",
";",
"}",
"else",
"{",
"return",
"Operator",
".",
"determineOperator",
"(",
"e",
".",
"getOperatorString",
"(",
")",
",",
"!",
"e",
".",
"isNegated",
"(",
")",
")",
";",
"}",
"}"
] |
Takes the given operator e, and returns a reversed version of it.
@return operator
|
[
"Takes",
"the",
"given",
"operator",
"e",
"and",
"returns",
"a",
"reversed",
"version",
"of",
"it",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-verifier/drools-verifier-drl/src/main/java/org/drools/verifier/report/components/MissingRange.java#L49-L66
|
14,046
|
kiegroup/drools
|
drools-workbench-models/drools-workbench-models-guided-template/src/main/java/org/drools/workbench/models/guided/template/shared/TemplateModel.java
|
TemplateModel.addRow
|
private String addRow(String rowId, String[] row) {
Map<InterpolationVariable, Integer> vars = getInterpolationVariables();
if (row.length != vars.size() - 1) {
throw new IllegalArgumentException("Invalid numbers of columns: " + row.length + " expected: "
+ (vars.size() - 1));
}
if (rowId == null || rowId.length() == 0) {
rowId = getNewIdColValue();
}
for (Map.Entry<InterpolationVariable, Integer> entry : vars.entrySet()) {
List<String> list = table.get(entry.getKey().getVarName());
if (list == null) {
list = new ArrayList<String>();
table.put(entry.getKey().getVarName(),
list);
}
if (rowsCount != list.size()) {
throw new IllegalArgumentException("invalid list size for " + entry.getKey() + ", expected: "
+ rowsCount + " was: " + list.size());
}
if (ID_COLUMN_NAME.equals(entry.getKey().getVarName())) {
list.add(rowId);
} else {
list.add(row[entry.getValue()]);
}
}
rowsCount++;
return rowId;
}
|
java
|
private String addRow(String rowId, String[] row) {
Map<InterpolationVariable, Integer> vars = getInterpolationVariables();
if (row.length != vars.size() - 1) {
throw new IllegalArgumentException("Invalid numbers of columns: " + row.length + " expected: "
+ (vars.size() - 1));
}
if (rowId == null || rowId.length() == 0) {
rowId = getNewIdColValue();
}
for (Map.Entry<InterpolationVariable, Integer> entry : vars.entrySet()) {
List<String> list = table.get(entry.getKey().getVarName());
if (list == null) {
list = new ArrayList<String>();
table.put(entry.getKey().getVarName(),
list);
}
if (rowsCount != list.size()) {
throw new IllegalArgumentException("invalid list size for " + entry.getKey() + ", expected: "
+ rowsCount + " was: " + list.size());
}
if (ID_COLUMN_NAME.equals(entry.getKey().getVarName())) {
list.add(rowId);
} else {
list.add(row[entry.getValue()]);
}
}
rowsCount++;
return rowId;
}
|
[
"private",
"String",
"addRow",
"(",
"String",
"rowId",
",",
"String",
"[",
"]",
"row",
")",
"{",
"Map",
"<",
"InterpolationVariable",
",",
"Integer",
">",
"vars",
"=",
"getInterpolationVariables",
"(",
")",
";",
"if",
"(",
"row",
".",
"length",
"!=",
"vars",
".",
"size",
"(",
")",
"-",
"1",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid numbers of columns: \"",
"+",
"row",
".",
"length",
"+",
"\" expected: \"",
"+",
"(",
"vars",
".",
"size",
"(",
")",
"-",
"1",
")",
")",
";",
"}",
"if",
"(",
"rowId",
"==",
"null",
"||",
"rowId",
".",
"length",
"(",
")",
"==",
"0",
")",
"{",
"rowId",
"=",
"getNewIdColValue",
"(",
")",
";",
"}",
"for",
"(",
"Map",
".",
"Entry",
"<",
"InterpolationVariable",
",",
"Integer",
">",
"entry",
":",
"vars",
".",
"entrySet",
"(",
")",
")",
"{",
"List",
"<",
"String",
">",
"list",
"=",
"table",
".",
"get",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"getVarName",
"(",
")",
")",
";",
"if",
"(",
"list",
"==",
"null",
")",
"{",
"list",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"table",
".",
"put",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"getVarName",
"(",
")",
",",
"list",
")",
";",
"}",
"if",
"(",
"rowsCount",
"!=",
"list",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid list size for \"",
"+",
"entry",
".",
"getKey",
"(",
")",
"+",
"\", expected: \"",
"+",
"rowsCount",
"+",
"\" was: \"",
"+",
"list",
".",
"size",
"(",
")",
")",
";",
"}",
"if",
"(",
"ID_COLUMN_NAME",
".",
"equals",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"getVarName",
"(",
")",
")",
")",
"{",
"list",
".",
"add",
"(",
"rowId",
")",
";",
"}",
"else",
"{",
"list",
".",
"add",
"(",
"row",
"[",
"entry",
".",
"getValue",
"(",
")",
"]",
")",
";",
"}",
"}",
"rowsCount",
"++",
";",
"return",
"rowId",
";",
"}"
] |
Append a row of data
@param rowId
@param row
@return
|
[
"Append",
"a",
"row",
"of",
"data"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-workbench-models/drools-workbench-models-guided-template/src/main/java/org/drools/workbench/models/guided/template/shared/TemplateModel.java#L50-L78
|
14,047
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java
|
KnowledgeBuilderImpl.addPackageFromDrl
|
public void addPackageFromDrl(final Reader reader) throws DroolsParserException,
IOException {
addPackageFromDrl(reader, new ReaderResource(reader, ResourceType.DRL));
}
|
java
|
public void addPackageFromDrl(final Reader reader) throws DroolsParserException,
IOException {
addPackageFromDrl(reader, new ReaderResource(reader, ResourceType.DRL));
}
|
[
"public",
"void",
"addPackageFromDrl",
"(",
"final",
"Reader",
"reader",
")",
"throws",
"DroolsParserException",
",",
"IOException",
"{",
"addPackageFromDrl",
"(",
"reader",
",",
"new",
"ReaderResource",
"(",
"reader",
",",
"ResourceType",
".",
"DRL",
")",
")",
";",
"}"
] |
Load a rule package from DRL source.
@throws DroolsParserException
@throws java.io.IOException
|
[
"Load",
"a",
"rule",
"package",
"from",
"DRL",
"source",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java#L344-L347
|
14,048
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java
|
KnowledgeBuilderImpl.addPackageFromDrl
|
public void addPackageFromDrl(final Reader reader,
final Resource sourceResource) throws DroolsParserException,
IOException {
this.resource = sourceResource;
final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
final PackageDescr pkg = parser.parse(sourceResource, reader);
this.results.addAll(parser.getErrors());
if (pkg == null) {
addBuilderResult(new ParserError(sourceResource, "Parser returned a null Package", 0, 0));
}
if (!parser.hasErrors()) {
addPackage(pkg);
}
this.resource = null;
}
|
java
|
public void addPackageFromDrl(final Reader reader,
final Resource sourceResource) throws DroolsParserException,
IOException {
this.resource = sourceResource;
final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
final PackageDescr pkg = parser.parse(sourceResource, reader);
this.results.addAll(parser.getErrors());
if (pkg == null) {
addBuilderResult(new ParserError(sourceResource, "Parser returned a null Package", 0, 0));
}
if (!parser.hasErrors()) {
addPackage(pkg);
}
this.resource = null;
}
|
[
"public",
"void",
"addPackageFromDrl",
"(",
"final",
"Reader",
"reader",
",",
"final",
"Resource",
"sourceResource",
")",
"throws",
"DroolsParserException",
",",
"IOException",
"{",
"this",
".",
"resource",
"=",
"sourceResource",
";",
"final",
"DrlParser",
"parser",
"=",
"new",
"DrlParser",
"(",
"configuration",
".",
"getLanguageLevel",
"(",
")",
")",
";",
"final",
"PackageDescr",
"pkg",
"=",
"parser",
".",
"parse",
"(",
"sourceResource",
",",
"reader",
")",
";",
"this",
".",
"results",
".",
"addAll",
"(",
"parser",
".",
"getErrors",
"(",
")",
")",
";",
"if",
"(",
"pkg",
"==",
"null",
")",
"{",
"addBuilderResult",
"(",
"new",
"ParserError",
"(",
"sourceResource",
",",
"\"Parser returned a null Package\"",
",",
"0",
",",
"0",
")",
")",
";",
"}",
"if",
"(",
"!",
"parser",
".",
"hasErrors",
"(",
")",
")",
"{",
"addPackage",
"(",
"pkg",
")",
";",
"}",
"this",
".",
"resource",
"=",
"null",
";",
"}"
] |
Load a rule package from DRL source and associate all loaded artifacts
with the given resource.
@param reader
@param sourceResource the source resource for the read artifacts
@throws DroolsParserException
@throws IOException
|
[
"Load",
"a",
"rule",
"package",
"from",
"DRL",
"source",
"and",
"associate",
"all",
"loaded",
"artifacts",
"with",
"the",
"given",
"resource",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java#L358-L373
|
14,049
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java
|
KnowledgeBuilderImpl.addPackageFromXml
|
public void addPackageFromXml(final Reader reader) throws DroolsParserException,
IOException {
this.resource = new ReaderResource(reader, ResourceType.XDRL);
final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
xmlReader.getParser().setClassLoader(this.rootClassLoader);
try {
xmlReader.read(reader);
} catch (final SAXException e) {
throw new DroolsParserException(e.toString(),
e.getCause());
}
addPackage(xmlReader.getPackageDescr());
this.resource = null;
}
|
java
|
public void addPackageFromXml(final Reader reader) throws DroolsParserException,
IOException {
this.resource = new ReaderResource(reader, ResourceType.XDRL);
final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
xmlReader.getParser().setClassLoader(this.rootClassLoader);
try {
xmlReader.read(reader);
} catch (final SAXException e) {
throw new DroolsParserException(e.toString(),
e.getCause());
}
addPackage(xmlReader.getPackageDescr());
this.resource = null;
}
|
[
"public",
"void",
"addPackageFromXml",
"(",
"final",
"Reader",
"reader",
")",
"throws",
"DroolsParserException",
",",
"IOException",
"{",
"this",
".",
"resource",
"=",
"new",
"ReaderResource",
"(",
"reader",
",",
"ResourceType",
".",
"XDRL",
")",
";",
"final",
"XmlPackageReader",
"xmlReader",
"=",
"new",
"XmlPackageReader",
"(",
"this",
".",
"configuration",
".",
"getSemanticModules",
"(",
")",
")",
";",
"xmlReader",
".",
"getParser",
"(",
")",
".",
"setClassLoader",
"(",
"this",
".",
"rootClassLoader",
")",
";",
"try",
"{",
"xmlReader",
".",
"read",
"(",
"reader",
")",
";",
"}",
"catch",
"(",
"final",
"SAXException",
"e",
")",
"{",
"throw",
"new",
"DroolsParserException",
"(",
"e",
".",
"toString",
"(",
")",
",",
"e",
".",
"getCause",
"(",
")",
")",
";",
"}",
"addPackage",
"(",
"xmlReader",
".",
"getPackageDescr",
"(",
")",
")",
";",
"this",
".",
"resource",
"=",
"null",
";",
"}"
] |
Load a rule package from XML source.
@param reader
@throws DroolsParserException
@throws IOException
|
[
"Load",
"a",
"rule",
"package",
"from",
"XML",
"source",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java#L586-L601
|
14,050
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java
|
KnowledgeBuilderImpl.addPackageFromDrl
|
public void addPackageFromDrl(final Reader source,
final Reader dsl) throws DroolsParserException,
IOException {
this.resource = new ReaderResource(source, ResourceType.DSLR);
final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
final PackageDescr pkg = parser.parse(source, dsl);
this.results.addAll(parser.getErrors());
if (!parser.hasErrors()) {
addPackage(pkg);
}
this.resource = null;
}
|
java
|
public void addPackageFromDrl(final Reader source,
final Reader dsl) throws DroolsParserException,
IOException {
this.resource = new ReaderResource(source, ResourceType.DSLR);
final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
final PackageDescr pkg = parser.parse(source, dsl);
this.results.addAll(parser.getErrors());
if (!parser.hasErrors()) {
addPackage(pkg);
}
this.resource = null;
}
|
[
"public",
"void",
"addPackageFromDrl",
"(",
"final",
"Reader",
"source",
",",
"final",
"Reader",
"dsl",
")",
"throws",
"DroolsParserException",
",",
"IOException",
"{",
"this",
".",
"resource",
"=",
"new",
"ReaderResource",
"(",
"source",
",",
"ResourceType",
".",
"DSLR",
")",
";",
"final",
"DrlParser",
"parser",
"=",
"new",
"DrlParser",
"(",
"configuration",
".",
"getLanguageLevel",
"(",
")",
")",
";",
"final",
"PackageDescr",
"pkg",
"=",
"parser",
".",
"parse",
"(",
"source",
",",
"dsl",
")",
";",
"this",
".",
"results",
".",
"addAll",
"(",
"parser",
".",
"getErrors",
"(",
")",
")",
";",
"if",
"(",
"!",
"parser",
".",
"hasErrors",
"(",
")",
")",
"{",
"addPackage",
"(",
"pkg",
")",
";",
"}",
"this",
".",
"resource",
"=",
"null",
";",
"}"
] |
Load a rule package from DRL source using the supplied DSL configuration.
@param source The source of the rules.
@param dsl The source of the domain specific language configuration.
@throws DroolsParserException
@throws IOException
|
[
"Load",
"a",
"rule",
"package",
"from",
"DRL",
"source",
"using",
"the",
"supplied",
"DSL",
"configuration",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java#L638-L650
|
14,051
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java
|
KnowledgeBuilderImpl.inheritPackageAttributes
|
private void inheritPackageAttributes(Map<String, AttributeDescr> pkgAttributes,
RuleDescr ruleDescr) {
if (pkgAttributes == null) {
return;
}
for (AttributeDescr attrDescr : pkgAttributes.values()) {
ruleDescr.getAttributes().putIfAbsent(attrDescr.getName(), attrDescr);
}
}
|
java
|
private void inheritPackageAttributes(Map<String, AttributeDescr> pkgAttributes,
RuleDescr ruleDescr) {
if (pkgAttributes == null) {
return;
}
for (AttributeDescr attrDescr : pkgAttributes.values()) {
ruleDescr.getAttributes().putIfAbsent(attrDescr.getName(), attrDescr);
}
}
|
[
"private",
"void",
"inheritPackageAttributes",
"(",
"Map",
"<",
"String",
",",
"AttributeDescr",
">",
"pkgAttributes",
",",
"RuleDescr",
"ruleDescr",
")",
"{",
"if",
"(",
"pkgAttributes",
"==",
"null",
")",
"{",
"return",
";",
"}",
"for",
"(",
"AttributeDescr",
"attrDescr",
":",
"pkgAttributes",
".",
"values",
"(",
")",
")",
"{",
"ruleDescr",
".",
"getAttributes",
"(",
")",
".",
"putIfAbsent",
"(",
"attrDescr",
".",
"getName",
"(",
")",
",",
"attrDescr",
")",
";",
"}",
"}"
] |
Entity rules inherit package attributes
|
[
"Entity",
"rules",
"inherit",
"package",
"attributes"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderImpl.java#L2090-L2098
|
14,052
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/management/DroolsManagementAgent.java
|
DroolsManagementAgent.getKnowledgeSessionBean
|
private GenericKieSessionMonitoringImpl getKnowledgeSessionBean(CBSKey cbsKey, KieRuntimeEventManager ksession) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
if (ksession instanceof StatelessKnowledgeSession) {
synchronized (mbeansRefs) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
try {
StatelessKieSessionMonitoringImpl mbean = new StatelessKieSessionMonitoringImpl( cbsKey.kcontainerId, cbsKey.kbaseId, cbsKey.ksessionName );
registerMBean( cbsKey, mbean, mbean.getName() );
mbeansRefs.put(cbsKey, mbean);
return mbean;
} catch ( Exception e ) {
logger.error("Unable to instantiate and register StatelessKieSessionMonitoringMBean");
}
return null;
}
}
} else {
synchronized (mbeansRefs) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
try {
KieSessionMonitoringImpl mbean = new KieSessionMonitoringImpl( cbsKey.kcontainerId, cbsKey.kbaseId, cbsKey.ksessionName );
registerMBean( cbsKey, mbean, mbean.getName() );
mbeansRefs.put(cbsKey, mbean);
return mbean;
} catch ( Exception e ) {
logger.error("Unable to instantiate and register (stateful) KieSessionMonitoringMBean");
}
return null;
}
}
}
}
}
|
java
|
private GenericKieSessionMonitoringImpl getKnowledgeSessionBean(CBSKey cbsKey, KieRuntimeEventManager ksession) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
if (ksession instanceof StatelessKnowledgeSession) {
synchronized (mbeansRefs) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
try {
StatelessKieSessionMonitoringImpl mbean = new StatelessKieSessionMonitoringImpl( cbsKey.kcontainerId, cbsKey.kbaseId, cbsKey.ksessionName );
registerMBean( cbsKey, mbean, mbean.getName() );
mbeansRefs.put(cbsKey, mbean);
return mbean;
} catch ( Exception e ) {
logger.error("Unable to instantiate and register StatelessKieSessionMonitoringMBean");
}
return null;
}
}
} else {
synchronized (mbeansRefs) {
if (mbeansRefs.get(cbsKey) != null) {
return (GenericKieSessionMonitoringImpl) mbeansRefs.get(cbsKey);
} else {
try {
KieSessionMonitoringImpl mbean = new KieSessionMonitoringImpl( cbsKey.kcontainerId, cbsKey.kbaseId, cbsKey.ksessionName );
registerMBean( cbsKey, mbean, mbean.getName() );
mbeansRefs.put(cbsKey, mbean);
return mbean;
} catch ( Exception e ) {
logger.error("Unable to instantiate and register (stateful) KieSessionMonitoringMBean");
}
return null;
}
}
}
}
}
|
[
"private",
"GenericKieSessionMonitoringImpl",
"getKnowledgeSessionBean",
"(",
"CBSKey",
"cbsKey",
",",
"KieRuntimeEventManager",
"ksession",
")",
"{",
"if",
"(",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
"!=",
"null",
")",
"{",
"return",
"(",
"GenericKieSessionMonitoringImpl",
")",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
";",
"}",
"else",
"{",
"if",
"(",
"ksession",
"instanceof",
"StatelessKnowledgeSession",
")",
"{",
"synchronized",
"(",
"mbeansRefs",
")",
"{",
"if",
"(",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
"!=",
"null",
")",
"{",
"return",
"(",
"GenericKieSessionMonitoringImpl",
")",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
";",
"}",
"else",
"{",
"try",
"{",
"StatelessKieSessionMonitoringImpl",
"mbean",
"=",
"new",
"StatelessKieSessionMonitoringImpl",
"(",
"cbsKey",
".",
"kcontainerId",
",",
"cbsKey",
".",
"kbaseId",
",",
"cbsKey",
".",
"ksessionName",
")",
";",
"registerMBean",
"(",
"cbsKey",
",",
"mbean",
",",
"mbean",
".",
"getName",
"(",
")",
")",
";",
"mbeansRefs",
".",
"put",
"(",
"cbsKey",
",",
"mbean",
")",
";",
"return",
"mbean",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to instantiate and register StatelessKieSessionMonitoringMBean\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"}",
"}",
"else",
"{",
"synchronized",
"(",
"mbeansRefs",
")",
"{",
"if",
"(",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
"!=",
"null",
")",
"{",
"return",
"(",
"GenericKieSessionMonitoringImpl",
")",
"mbeansRefs",
".",
"get",
"(",
"cbsKey",
")",
";",
"}",
"else",
"{",
"try",
"{",
"KieSessionMonitoringImpl",
"mbean",
"=",
"new",
"KieSessionMonitoringImpl",
"(",
"cbsKey",
".",
"kcontainerId",
",",
"cbsKey",
".",
"kbaseId",
",",
"cbsKey",
".",
"ksessionName",
")",
";",
"registerMBean",
"(",
"cbsKey",
",",
"mbean",
",",
"mbean",
".",
"getName",
"(",
")",
")",
";",
"mbeansRefs",
".",
"put",
"(",
"cbsKey",
",",
"mbean",
")",
";",
"return",
"mbean",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to instantiate and register (stateful) KieSessionMonitoringMBean\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"}",
"}",
"}",
"}"
] |
Get currently registered session monitor, eventually creating it if necessary.
@return the currently registered or newly created session monitor, or null if unable to create and register it on the JMX server.
|
[
"Get",
"currently",
"registered",
"session",
"monitor",
"eventually",
"creating",
"it",
"if",
"necessary",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/management/DroolsManagementAgent.java#L150-L188
|
14,053
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/phreak/PhreakBranchNode.java
|
PhreakBranchNode.getBranchTuples
|
private BranchTuples getBranchTuples(LeftTupleSink sink, LeftTuple leftTuple) {
BranchTuples branchTuples = new BranchTuples();
LeftTuple child = leftTuple.getFirstChild();
if ( child != null ) {
// assigns the correct main or rtn LeftTuple based on the identified sink
if ( child.getTupleSink() == sink ) {
branchTuples.mainLeftTuple = child;
} else {
branchTuples.rtnLeftTuple = child;
}
child = child.getHandleNext();
if ( child != null ) {
if ( child.getTupleSink() == sink ) {
branchTuples.mainLeftTuple = child;
} else {
branchTuples.rtnLeftTuple = child;
}
}
}
return branchTuples;
}
|
java
|
private BranchTuples getBranchTuples(LeftTupleSink sink, LeftTuple leftTuple) {
BranchTuples branchTuples = new BranchTuples();
LeftTuple child = leftTuple.getFirstChild();
if ( child != null ) {
// assigns the correct main or rtn LeftTuple based on the identified sink
if ( child.getTupleSink() == sink ) {
branchTuples.mainLeftTuple = child;
} else {
branchTuples.rtnLeftTuple = child;
}
child = child.getHandleNext();
if ( child != null ) {
if ( child.getTupleSink() == sink ) {
branchTuples.mainLeftTuple = child;
} else {
branchTuples.rtnLeftTuple = child;
}
}
}
return branchTuples;
}
|
[
"private",
"BranchTuples",
"getBranchTuples",
"(",
"LeftTupleSink",
"sink",
",",
"LeftTuple",
"leftTuple",
")",
"{",
"BranchTuples",
"branchTuples",
"=",
"new",
"BranchTuples",
"(",
")",
";",
"LeftTuple",
"child",
"=",
"leftTuple",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"child",
"!=",
"null",
")",
"{",
"// assigns the correct main or rtn LeftTuple based on the identified sink",
"if",
"(",
"child",
".",
"getTupleSink",
"(",
")",
"==",
"sink",
")",
"{",
"branchTuples",
".",
"mainLeftTuple",
"=",
"child",
";",
"}",
"else",
"{",
"branchTuples",
".",
"rtnLeftTuple",
"=",
"child",
";",
"}",
"child",
"=",
"child",
".",
"getHandleNext",
"(",
")",
";",
"if",
"(",
"child",
"!=",
"null",
")",
"{",
"if",
"(",
"child",
".",
"getTupleSink",
"(",
")",
"==",
"sink",
")",
"{",
"branchTuples",
".",
"mainLeftTuple",
"=",
"child",
";",
"}",
"else",
"{",
"branchTuples",
".",
"rtnLeftTuple",
"=",
"child",
";",
"}",
"}",
"}",
"return",
"branchTuples",
";",
"}"
] |
A branch has two potential sinks. rtnSink is for the sink if the contained logic returns true.
mainSink is for propagations after the branch node, if they are allowed.
it may have one or the other or both. there is no state that indicates whether one or the other or both
are present, so all tuple children must be inspected and references coalesced from that.
when handling updates and deletes it must search the child tuples to colasce the references.
This is done by checking the tuple sink with the known main or rtn sink.
|
[
"A",
"branch",
"has",
"two",
"potential",
"sinks",
".",
"rtnSink",
"is",
"for",
"the",
"sink",
"if",
"the",
"contained",
"logic",
"returns",
"true",
".",
"mainSink",
"is",
"for",
"propagations",
"after",
"the",
"branch",
"node",
"if",
"they",
"are",
"allowed",
".",
"it",
"may",
"have",
"one",
"or",
"the",
"other",
"or",
"both",
".",
"there",
"is",
"no",
"state",
"that",
"indicates",
"whether",
"one",
"or",
"the",
"other",
"or",
"both",
"are",
"present",
"so",
"all",
"tuple",
"children",
"must",
"be",
"inspected",
"and",
"references",
"coalesced",
"from",
"that",
".",
"when",
"handling",
"updates",
"and",
"deletes",
"it",
"must",
"search",
"the",
"child",
"tuples",
"to",
"colasce",
"the",
"references",
".",
"This",
"is",
"done",
"by",
"checking",
"the",
"tuple",
"sink",
"with",
"the",
"known",
"main",
"or",
"rtn",
"sink",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/phreak/PhreakBranchNode.java#L220-L240
|
14,054
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.buildClassHeader
|
protected ClassWriter buildClassHeader(ClassLoader classLoader,
ClassDefinition classDef) {
boolean reactive = classDef.isReactive();
String[] original = classDef.getInterfaces();
int interfacesNr = original.length + (reactive ? 2 : 1);
String[] interfaces = new String[interfacesNr];
for ( int i = 0; i < original.length; i++ ) {
interfaces[i] = BuildUtils.getInternalType( original[i] );
}
interfaces[original.length] = BuildUtils.getInternalType( GeneratedFact.class.getName() );
if (reactive) {
interfaces[original.length+1] = BuildUtils.getInternalType( ReactiveObject.class.getName() );
}
int classModifiers = Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER;
if ( classDef.isAbstrakt() ) {
classModifiers += Opcodes.ACC_ABSTRACT;
}
ClassWriter cw = createClassWriter( classLoader,
classModifiers,
BuildUtils.getInternalType( classDef.getClassName() ),
null,
BuildUtils.getInternalType( classDef.getSuperClass() ),
interfaces );
buildClassAnnotations(classDef, cw);
cw.visitSource( classDef.getClassName() + ".java",
null );
return cw;
}
|
java
|
protected ClassWriter buildClassHeader(ClassLoader classLoader,
ClassDefinition classDef) {
boolean reactive = classDef.isReactive();
String[] original = classDef.getInterfaces();
int interfacesNr = original.length + (reactive ? 2 : 1);
String[] interfaces = new String[interfacesNr];
for ( int i = 0; i < original.length; i++ ) {
interfaces[i] = BuildUtils.getInternalType( original[i] );
}
interfaces[original.length] = BuildUtils.getInternalType( GeneratedFact.class.getName() );
if (reactive) {
interfaces[original.length+1] = BuildUtils.getInternalType( ReactiveObject.class.getName() );
}
int classModifiers = Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER;
if ( classDef.isAbstrakt() ) {
classModifiers += Opcodes.ACC_ABSTRACT;
}
ClassWriter cw = createClassWriter( classLoader,
classModifiers,
BuildUtils.getInternalType( classDef.getClassName() ),
null,
BuildUtils.getInternalType( classDef.getSuperClass() ),
interfaces );
buildClassAnnotations(classDef, cw);
cw.visitSource( classDef.getClassName() + ".java",
null );
return cw;
}
|
[
"protected",
"ClassWriter",
"buildClassHeader",
"(",
"ClassLoader",
"classLoader",
",",
"ClassDefinition",
"classDef",
")",
"{",
"boolean",
"reactive",
"=",
"classDef",
".",
"isReactive",
"(",
")",
";",
"String",
"[",
"]",
"original",
"=",
"classDef",
".",
"getInterfaces",
"(",
")",
";",
"int",
"interfacesNr",
"=",
"original",
".",
"length",
"+",
"(",
"reactive",
"?",
"2",
":",
"1",
")",
";",
"String",
"[",
"]",
"interfaces",
"=",
"new",
"String",
"[",
"interfacesNr",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"original",
".",
"length",
";",
"i",
"++",
")",
"{",
"interfaces",
"[",
"i",
"]",
"=",
"BuildUtils",
".",
"getInternalType",
"(",
"original",
"[",
"i",
"]",
")",
";",
"}",
"interfaces",
"[",
"original",
".",
"length",
"]",
"=",
"BuildUtils",
".",
"getInternalType",
"(",
"GeneratedFact",
".",
"class",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"reactive",
")",
"{",
"interfaces",
"[",
"original",
".",
"length",
"+",
"1",
"]",
"=",
"BuildUtils",
".",
"getInternalType",
"(",
"ReactiveObject",
".",
"class",
".",
"getName",
"(",
")",
")",
";",
"}",
"int",
"classModifiers",
"=",
"Opcodes",
".",
"ACC_PUBLIC",
"+",
"Opcodes",
".",
"ACC_SUPER",
";",
"if",
"(",
"classDef",
".",
"isAbstrakt",
"(",
")",
")",
"{",
"classModifiers",
"+=",
"Opcodes",
".",
"ACC_ABSTRACT",
";",
"}",
"ClassWriter",
"cw",
"=",
"createClassWriter",
"(",
"classLoader",
",",
"classModifiers",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"null",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getSuperClass",
"(",
")",
")",
",",
"interfaces",
")",
";",
"buildClassAnnotations",
"(",
"classDef",
",",
"cw",
")",
";",
"cw",
".",
"visitSource",
"(",
"classDef",
".",
"getClassName",
"(",
")",
"+",
"\".java\"",
",",
"null",
")",
";",
"return",
"cw",
";",
"}"
] |
Defines the class header for the given class definition
|
[
"Defines",
"the",
"class",
"header",
"for",
"the",
"given",
"class",
"definition"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L851-L884
|
14,055
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.buildField
|
protected void buildField( ClassVisitor cw,
FieldDefinition fieldDef) {
FieldVisitor fv = cw.visitField( Opcodes.ACC_PROTECTED,
fieldDef.getName(),
BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ),
null,
null );
buildFieldAnnotations( fieldDef, fv );
fv.visitEnd();
}
|
java
|
protected void buildField( ClassVisitor cw,
FieldDefinition fieldDef) {
FieldVisitor fv = cw.visitField( Opcodes.ACC_PROTECTED,
fieldDef.getName(),
BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ),
null,
null );
buildFieldAnnotations( fieldDef, fv );
fv.visitEnd();
}
|
[
"protected",
"void",
"buildField",
"(",
"ClassVisitor",
"cw",
",",
"FieldDefinition",
"fieldDef",
")",
"{",
"FieldVisitor",
"fv",
"=",
"cw",
".",
"visitField",
"(",
"Opcodes",
".",
"ACC_PROTECTED",
",",
"fieldDef",
".",
"getName",
"(",
")",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
",",
"null",
",",
"null",
")",
";",
"buildFieldAnnotations",
"(",
"fieldDef",
",",
"fv",
")",
";",
"fv",
".",
"visitEnd",
"(",
")",
";",
"}"
] |
Creates the field defined by the given FieldDefinition
@param cw
@param fieldDef
|
[
"Creates",
"the",
"field",
"defined",
"by",
"the",
"given",
"FieldDefinition"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L894-L906
|
14,056
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.buildDefaultConstructor
|
protected void buildDefaultConstructor(ClassVisitor cw,
ClassDefinition classDef) {
MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
"<init>",
Type.getMethodDescriptor( Type.VOID_TYPE,
new Type[]{} ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
boolean hasObjects = defaultConstructorStart( mv, classDef );
mv.visitInsn(Opcodes.RETURN);
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
}
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
|
java
|
protected void buildDefaultConstructor(ClassVisitor cw,
ClassDefinition classDef) {
MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
"<init>",
Type.getMethodDescriptor( Type.VOID_TYPE,
new Type[]{} ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
boolean hasObjects = defaultConstructorStart( mv, classDef );
mv.visitInsn(Opcodes.RETURN);
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
}
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
|
[
"protected",
"void",
"buildDefaultConstructor",
"(",
"ClassVisitor",
"cw",
",",
"ClassDefinition",
"classDef",
")",
"{",
"MethodVisitor",
"mv",
"=",
"cw",
".",
"visitMethod",
"(",
"Opcodes",
".",
"ACC_PUBLIC",
",",
"\"<init>\"",
",",
"Type",
".",
"getMethodDescriptor",
"(",
"Type",
".",
"VOID_TYPE",
",",
"new",
"Type",
"[",
"]",
"{",
"}",
")",
",",
"null",
",",
"null",
")",
";",
"mv",
".",
"visitCode",
"(",
")",
";",
"Label",
"l0",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l0",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l0",
")",
";",
"}",
"boolean",
"hasObjects",
"=",
"defaultConstructorStart",
"(",
"mv",
",",
"classDef",
")",
";",
"mv",
".",
"visitInsn",
"(",
"Opcodes",
".",
"RETURN",
")",
";",
"Label",
"l1",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l1",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l1",
")",
";",
"mv",
".",
"visitLocalVariable",
"(",
"\"this\"",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"null",
",",
"l0",
",",
"l1",
",",
"0",
")",
";",
"}",
"mv",
".",
"visitMaxs",
"(",
"0",
",",
"0",
")",
";",
"mv",
".",
"visitEnd",
"(",
")",
";",
"}"
] |
Creates a default constructor for the class
@param cw
|
[
"Creates",
"a",
"default",
"constructor",
"for",
"the",
"class"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L915-L950
|
14,057
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.initializeDynamicTypeStructures
|
protected void initializeDynamicTypeStructures( MethodVisitor mv, ClassDefinition classDef) {
if ( classDef.isFullTraiting() ) {
mv.visitVarInsn( ALOAD, 0 );
mv.visitTypeInsn( NEW, Type.getInternalName( TraitFieldTMSImpl.class ) );
mv.visitInsn( DUP );
mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TraitFieldTMSImpl.class ), "<init>", "()V" );
mv.visitFieldInsn( PUTFIELD, BuildUtils.getInternalType( classDef.getClassName() ), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor( TraitFieldTMS.class ) );
for ( FactField hardField : classDef.getFields() ) {
FieldDefinition fld = (FieldDefinition) hardField;
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( classDef.getClassName() ), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor( TraitFieldTMS.class ) );
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( classDef.getClassName() ) ) );
mv.visitLdcInsn( fld.resolveAlias() );
if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) {
// mv.visitFieldInsn( GETSTATIC, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ), "TYPE", Type.getDescriptor( Class.class ) );
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( BuildUtils.box( fld.getTypeName() ) ) ) );
} else {
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( fld.getTypeName() ) ) );
}
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( classDef.getClassName() ), BuildUtils.getterName( fld.getName(), fld.getTypeName() ), "()" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) );
if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) {
mv.visitMethodInsn( INVOKESTATIC, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ), "valueOf", "(" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) + ")" + BuildUtils.getTypeDescriptor( BuildUtils.box( fld.getTypeName() ) ) );
}
if ( fld.getInitExpr() != null ) {
mv.visitLdcInsn( fld.getInitExpr() );
} else {
mv.visitInsn( ACONST_NULL );
}
mv.visitMethodInsn( INVOKEINTERFACE,
Type.getInternalName( TraitFieldTMS.class ),
"registerField",
Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.getType( Class.class ), Type.getType( String.class ), Type.getType( Class.class ), Type.getType( Object.class ), Type.getType( String.class ) } ) );
}
}
}
|
java
|
protected void initializeDynamicTypeStructures( MethodVisitor mv, ClassDefinition classDef) {
if ( classDef.isFullTraiting() ) {
mv.visitVarInsn( ALOAD, 0 );
mv.visitTypeInsn( NEW, Type.getInternalName( TraitFieldTMSImpl.class ) );
mv.visitInsn( DUP );
mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TraitFieldTMSImpl.class ), "<init>", "()V" );
mv.visitFieldInsn( PUTFIELD, BuildUtils.getInternalType( classDef.getClassName() ), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor( TraitFieldTMS.class ) );
for ( FactField hardField : classDef.getFields() ) {
FieldDefinition fld = (FieldDefinition) hardField;
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( classDef.getClassName() ), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor( TraitFieldTMS.class ) );
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( classDef.getClassName() ) ) );
mv.visitLdcInsn( fld.resolveAlias() );
if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) {
// mv.visitFieldInsn( GETSTATIC, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ), "TYPE", Type.getDescriptor( Class.class ) );
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( BuildUtils.box( fld.getTypeName() ) ) ) );
} else {
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( fld.getTypeName() ) ) );
}
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( classDef.getClassName() ), BuildUtils.getterName( fld.getName(), fld.getTypeName() ), "()" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) );
if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) {
mv.visitMethodInsn( INVOKESTATIC, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ), "valueOf", "(" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) + ")" + BuildUtils.getTypeDescriptor( BuildUtils.box( fld.getTypeName() ) ) );
}
if ( fld.getInitExpr() != null ) {
mv.visitLdcInsn( fld.getInitExpr() );
} else {
mv.visitInsn( ACONST_NULL );
}
mv.visitMethodInsn( INVOKEINTERFACE,
Type.getInternalName( TraitFieldTMS.class ),
"registerField",
Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.getType( Class.class ), Type.getType( String.class ), Type.getType( Class.class ), Type.getType( Object.class ), Type.getType( String.class ) } ) );
}
}
}
|
[
"protected",
"void",
"initializeDynamicTypeStructures",
"(",
"MethodVisitor",
"mv",
",",
"ClassDefinition",
"classDef",
")",
"{",
"if",
"(",
"classDef",
".",
"isFullTraiting",
"(",
")",
")",
"{",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"0",
")",
";",
"mv",
".",
"visitTypeInsn",
"(",
"NEW",
",",
"Type",
".",
"getInternalName",
"(",
"TraitFieldTMSImpl",
".",
"class",
")",
")",
";",
"mv",
".",
"visitInsn",
"(",
"DUP",
")",
";",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKESPECIAL",
",",
"Type",
".",
"getInternalName",
"(",
"TraitFieldTMSImpl",
".",
"class",
")",
",",
"\"<init>\"",
",",
"\"()V\"",
")",
";",
"mv",
".",
"visitFieldInsn",
"(",
"PUTFIELD",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"TraitableBean",
".",
"FIELDTMS_FIELD_NAME",
",",
"Type",
".",
"getDescriptor",
"(",
"TraitFieldTMS",
".",
"class",
")",
")",
";",
"for",
"(",
"FactField",
"hardField",
":",
"classDef",
".",
"getFields",
"(",
")",
")",
"{",
"FieldDefinition",
"fld",
"=",
"(",
"FieldDefinition",
")",
"hardField",
";",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"0",
")",
";",
"mv",
".",
"visitFieldInsn",
"(",
"GETFIELD",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"TraitableBean",
".",
"FIELDTMS_FIELD_NAME",
",",
"Type",
".",
"getDescriptor",
"(",
"TraitFieldTMS",
".",
"class",
")",
")",
";",
"mv",
".",
"visitLdcInsn",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
")",
")",
";",
"mv",
".",
"visitLdcInsn",
"(",
"fld",
".",
"resolveAlias",
"(",
")",
")",
";",
"if",
"(",
"BuildUtils",
".",
"isPrimitive",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
"{",
"// mv.visitFieldInsn( GETSTATIC, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ), \"TYPE\", Type.getDescriptor( Class.class ) );",
"mv",
".",
"visitLdcInsn",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"BuildUtils",
".",
"box",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"mv",
".",
"visitLdcInsn",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
")",
";",
"}",
"mv",
".",
"visitVarInsn",
"(",
"ALOAD",
",",
"0",
")",
";",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKEVIRTUAL",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"BuildUtils",
".",
"getterName",
"(",
"fld",
".",
"getName",
"(",
")",
",",
"fld",
".",
"getTypeName",
"(",
")",
")",
",",
"\"()\"",
"+",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
";",
"if",
"(",
"BuildUtils",
".",
"isPrimitive",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
"{",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKESTATIC",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"BuildUtils",
".",
"box",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
",",
"\"valueOf\"",
",",
"\"(\"",
"+",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
"+",
"\")\"",
"+",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"BuildUtils",
".",
"box",
"(",
"fld",
".",
"getTypeName",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"fld",
".",
"getInitExpr",
"(",
")",
"!=",
"null",
")",
"{",
"mv",
".",
"visitLdcInsn",
"(",
"fld",
".",
"getInitExpr",
"(",
")",
")",
";",
"}",
"else",
"{",
"mv",
".",
"visitInsn",
"(",
"ACONST_NULL",
")",
";",
"}",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKEINTERFACE",
",",
"Type",
".",
"getInternalName",
"(",
"TraitFieldTMS",
".",
"class",
")",
",",
"\"registerField\"",
",",
"Type",
".",
"getMethodDescriptor",
"(",
"Type",
".",
"VOID_TYPE",
",",
"new",
"Type",
"[",
"]",
"{",
"Type",
".",
"getType",
"(",
"Class",
".",
"class",
")",
",",
"Type",
".",
"getType",
"(",
"String",
".",
"class",
")",
",",
"Type",
".",
"getType",
"(",
"Class",
".",
"class",
")",
",",
"Type",
".",
"getType",
"(",
"Object",
".",
"class",
")",
",",
"Type",
".",
"getType",
"(",
"String",
".",
"class",
")",
"}",
")",
")",
";",
"}",
"}",
"}"
] |
Initializes the trait map and dynamic property map to empty values
@param mv
@param classDef
|
[
"Initializes",
"the",
"trait",
"map",
"and",
"dynamic",
"property",
"map",
"to",
"empty",
"values"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L1058-L1101
|
14,058
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.buildConstructorWithFields
|
protected void buildConstructorWithFields(ClassVisitor cw,
ClassDefinition classDef,
Collection<FieldDefinition> fieldDefs) {
Type[] params = new Type[fieldDefs.size()];
int index = 0;
for ( FieldDefinition field : fieldDefs ) {
params[index++] = Type.getType( BuildUtils.getTypeDescriptor( field.getTypeName() ) );
}
MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
"<init>",
Type.getMethodDescriptor( Type.VOID_TYPE,
params ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
fieldConstructorStart( mv, classDef, fieldDefs );
mv.visitInsn( Opcodes.RETURN );
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
for ( FieldDefinition field : classDef.getFieldsDefinitions() ) {
Label l11 = new Label();
mv.visitLabel( l11 );
mv.visitLocalVariable( field.getName(),
BuildUtils.getTypeDescriptor( field.getTypeName() ),
null,
l0,
l1,
0 );
}
}
mv.visitMaxs( 0,
0 );
mv.visitEnd();
}
|
java
|
protected void buildConstructorWithFields(ClassVisitor cw,
ClassDefinition classDef,
Collection<FieldDefinition> fieldDefs) {
Type[] params = new Type[fieldDefs.size()];
int index = 0;
for ( FieldDefinition field : fieldDefs ) {
params[index++] = Type.getType( BuildUtils.getTypeDescriptor( field.getTypeName() ) );
}
MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
"<init>",
Type.getMethodDescriptor( Type.VOID_TYPE,
params ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
fieldConstructorStart( mv, classDef, fieldDefs );
mv.visitInsn( Opcodes.RETURN );
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
for ( FieldDefinition field : classDef.getFieldsDefinitions() ) {
Label l11 = new Label();
mv.visitLabel( l11 );
mv.visitLocalVariable( field.getName(),
BuildUtils.getTypeDescriptor( field.getTypeName() ),
null,
l0,
l1,
0 );
}
}
mv.visitMaxs( 0,
0 );
mv.visitEnd();
}
|
[
"protected",
"void",
"buildConstructorWithFields",
"(",
"ClassVisitor",
"cw",
",",
"ClassDefinition",
"classDef",
",",
"Collection",
"<",
"FieldDefinition",
">",
"fieldDefs",
")",
"{",
"Type",
"[",
"]",
"params",
"=",
"new",
"Type",
"[",
"fieldDefs",
".",
"size",
"(",
")",
"]",
";",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"FieldDefinition",
"field",
":",
"fieldDefs",
")",
"{",
"params",
"[",
"index",
"++",
"]",
"=",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"field",
".",
"getTypeName",
"(",
")",
")",
")",
";",
"}",
"MethodVisitor",
"mv",
"=",
"cw",
".",
"visitMethod",
"(",
"Opcodes",
".",
"ACC_PUBLIC",
",",
"\"<init>\"",
",",
"Type",
".",
"getMethodDescriptor",
"(",
"Type",
".",
"VOID_TYPE",
",",
"params",
")",
",",
"null",
",",
"null",
")",
";",
"mv",
".",
"visitCode",
"(",
")",
";",
"Label",
"l0",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l0",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l0",
")",
";",
"}",
"fieldConstructorStart",
"(",
"mv",
",",
"classDef",
",",
"fieldDefs",
")",
";",
"mv",
".",
"visitInsn",
"(",
"Opcodes",
".",
"RETURN",
")",
";",
"Label",
"l1",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l1",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l1",
")",
";",
"mv",
".",
"visitLocalVariable",
"(",
"\"this\"",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"null",
",",
"l0",
",",
"l1",
",",
"0",
")",
";",
"for",
"(",
"FieldDefinition",
"field",
":",
"classDef",
".",
"getFieldsDefinitions",
"(",
")",
")",
"{",
"Label",
"l11",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l11",
")",
";",
"mv",
".",
"visitLocalVariable",
"(",
"field",
".",
"getName",
"(",
")",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"field",
".",
"getTypeName",
"(",
")",
")",
",",
"null",
",",
"l0",
",",
"l1",
",",
"0",
")",
";",
"}",
"}",
"mv",
".",
"visitMaxs",
"(",
"0",
",",
"0",
")",
";",
"mv",
".",
"visitEnd",
"(",
")",
";",
"}"
] |
Creates a constructor that takes and assigns values to all
fields in the order they are declared.
@param cw
@param classDef
|
[
"Creates",
"a",
"constructor",
"that",
"takes",
"and",
"assigns",
"values",
"to",
"all",
"fields",
"in",
"the",
"order",
"they",
"are",
"declared",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L1110-L1162
|
14,059
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java
|
DefaultBeanClassBuilder.buildGetMethod
|
protected void buildGetMethod(ClassVisitor cw,
ClassDefinition classDef,
FieldDefinition fieldDef) {
MethodVisitor mv;
// Get method
{
mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
fieldDef.getReadMethod(),
Type.getMethodDescriptor( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) ),
new Type[]{} ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
mv.visitVarInsn( Opcodes.ALOAD,
0 );
if ( ! fieldDef.hasOverride() ) {
mv.visitFieldInsn( Opcodes.GETFIELD,
BuildUtils.getInternalType( classDef.getClassName() ),
fieldDef.getName(),
BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) );
mv.visitInsn( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) ).getOpcode( Opcodes.IRETURN ) );
} else {
mv.visitMethodInsn( INVOKESPECIAL,
BuildUtils.getInternalType( classDef.getSuperClass() ),
BuildUtils.getterName( fieldDef.getName(), fieldDef.getOverriding() ),
Type.getMethodDescriptor( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getOverriding() ) ), new Type[]{} ),
false );
mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( fieldDef.getTypeName() ) );
mv.visitInsn( BuildUtils.returnType( fieldDef.getTypeName() ) );
}
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
}
mv.visitMaxs( 0,
0 );
mv.visitEnd();
}
}
|
java
|
protected void buildGetMethod(ClassVisitor cw,
ClassDefinition classDef,
FieldDefinition fieldDef) {
MethodVisitor mv;
// Get method
{
mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
fieldDef.getReadMethod(),
Type.getMethodDescriptor( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) ),
new Type[]{} ),
null,
null );
mv.visitCode();
Label l0 = null;
if ( this.debug ) {
l0 = new Label();
mv.visitLabel( l0 );
}
mv.visitVarInsn( Opcodes.ALOAD,
0 );
if ( ! fieldDef.hasOverride() ) {
mv.visitFieldInsn( Opcodes.GETFIELD,
BuildUtils.getInternalType( classDef.getClassName() ),
fieldDef.getName(),
BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) );
mv.visitInsn( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getTypeName() ) ).getOpcode( Opcodes.IRETURN ) );
} else {
mv.visitMethodInsn( INVOKESPECIAL,
BuildUtils.getInternalType( classDef.getSuperClass() ),
BuildUtils.getterName( fieldDef.getName(), fieldDef.getOverriding() ),
Type.getMethodDescriptor( Type.getType( BuildUtils.getTypeDescriptor( fieldDef.getOverriding() ) ), new Type[]{} ),
false );
mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( fieldDef.getTypeName() ) );
mv.visitInsn( BuildUtils.returnType( fieldDef.getTypeName() ) );
}
Label l1 = null;
if ( this.debug ) {
l1 = new Label();
mv.visitLabel( l1 );
mv.visitLocalVariable( "this",
BuildUtils.getTypeDescriptor( classDef.getClassName() ),
null,
l0,
l1,
0 );
}
mv.visitMaxs( 0,
0 );
mv.visitEnd();
}
}
|
[
"protected",
"void",
"buildGetMethod",
"(",
"ClassVisitor",
"cw",
",",
"ClassDefinition",
"classDef",
",",
"FieldDefinition",
"fieldDef",
")",
"{",
"MethodVisitor",
"mv",
";",
"// Get method",
"{",
"mv",
"=",
"cw",
".",
"visitMethod",
"(",
"Opcodes",
".",
"ACC_PUBLIC",
",",
"fieldDef",
".",
"getReadMethod",
"(",
")",
",",
"Type",
".",
"getMethodDescriptor",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
")",
",",
"new",
"Type",
"[",
"]",
"{",
"}",
")",
",",
"null",
",",
"null",
")",
";",
"mv",
".",
"visitCode",
"(",
")",
";",
"Label",
"l0",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l0",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l0",
")",
";",
"}",
"mv",
".",
"visitVarInsn",
"(",
"Opcodes",
".",
"ALOAD",
",",
"0",
")",
";",
"if",
"(",
"!",
"fieldDef",
".",
"hasOverride",
"(",
")",
")",
"{",
"mv",
".",
"visitFieldInsn",
"(",
"Opcodes",
".",
"GETFIELD",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"fieldDef",
".",
"getName",
"(",
")",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
")",
";",
"mv",
".",
"visitInsn",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
")",
".",
"getOpcode",
"(",
"Opcodes",
".",
"IRETURN",
")",
")",
";",
"}",
"else",
"{",
"mv",
".",
"visitMethodInsn",
"(",
"INVOKESPECIAL",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"classDef",
".",
"getSuperClass",
"(",
")",
")",
",",
"BuildUtils",
".",
"getterName",
"(",
"fieldDef",
".",
"getName",
"(",
")",
",",
"fieldDef",
".",
"getOverriding",
"(",
")",
")",
",",
"Type",
".",
"getMethodDescriptor",
"(",
"Type",
".",
"getType",
"(",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"fieldDef",
".",
"getOverriding",
"(",
")",
")",
")",
",",
"new",
"Type",
"[",
"]",
"{",
"}",
")",
",",
"false",
")",
";",
"mv",
".",
"visitTypeInsn",
"(",
"CHECKCAST",
",",
"BuildUtils",
".",
"getInternalType",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
")",
";",
"mv",
".",
"visitInsn",
"(",
"BuildUtils",
".",
"returnType",
"(",
"fieldDef",
".",
"getTypeName",
"(",
")",
")",
")",
";",
"}",
"Label",
"l1",
"=",
"null",
";",
"if",
"(",
"this",
".",
"debug",
")",
"{",
"l1",
"=",
"new",
"Label",
"(",
")",
";",
"mv",
".",
"visitLabel",
"(",
"l1",
")",
";",
"mv",
".",
"visitLocalVariable",
"(",
"\"this\"",
",",
"BuildUtils",
".",
"getTypeDescriptor",
"(",
"classDef",
".",
"getClassName",
"(",
")",
")",
",",
"null",
",",
"l0",
",",
"l1",
",",
"0",
")",
";",
"}",
"mv",
".",
"visitMaxs",
"(",
"0",
",",
"0",
")",
";",
"mv",
".",
"visitEnd",
"(",
")",
";",
"}",
"}"
] |
Creates the get method for the given field definition
@param cw
@param classDef
@param fieldDef
|
[
"Creates",
"the",
"get",
"method",
"for",
"the",
"given",
"field",
"definition"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/factmodel/DefaultBeanClassBuilder.java#L1307-L1358
|
14,060
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java
|
ExtensibleXmlParser.startElementBuilder
|
public void startElementBuilder(final String tagName,
final Attributes attrs) {
this.attrs = attrs;
this.characters = new StringBuilder();
final Element element = this.document.createElement( tagName );
//final DefaultConfiguration config = new DefaultConfiguration( tagName );
final int numAttrs = attrs.getLength();
for ( int i = 0; i < numAttrs; ++i ) {
element.setAttribute( attrs.getLocalName( i ),
attrs.getValue( i ) );
}
if ( this.configurationStack.isEmpty() ) {
this.configurationStack.addLast( element );
} else {
((Element) this.configurationStack.getLast()).appendChild( element );
this.configurationStack.addLast( element );
}
}
|
java
|
public void startElementBuilder(final String tagName,
final Attributes attrs) {
this.attrs = attrs;
this.characters = new StringBuilder();
final Element element = this.document.createElement( tagName );
//final DefaultConfiguration config = new DefaultConfiguration( tagName );
final int numAttrs = attrs.getLength();
for ( int i = 0; i < numAttrs; ++i ) {
element.setAttribute( attrs.getLocalName( i ),
attrs.getValue( i ) );
}
if ( this.configurationStack.isEmpty() ) {
this.configurationStack.addLast( element );
} else {
((Element) this.configurationStack.getLast()).appendChild( element );
this.configurationStack.addLast( element );
}
}
|
[
"public",
"void",
"startElementBuilder",
"(",
"final",
"String",
"tagName",
",",
"final",
"Attributes",
"attrs",
")",
"{",
"this",
".",
"attrs",
"=",
"attrs",
";",
"this",
".",
"characters",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"Element",
"element",
"=",
"this",
".",
"document",
".",
"createElement",
"(",
"tagName",
")",
";",
"//final DefaultConfiguration config = new DefaultConfiguration( tagName );",
"final",
"int",
"numAttrs",
"=",
"attrs",
".",
"getLength",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numAttrs",
";",
"++",
"i",
")",
"{",
"element",
".",
"setAttribute",
"(",
"attrs",
".",
"getLocalName",
"(",
"i",
")",
",",
"attrs",
".",
"getValue",
"(",
"i",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"configurationStack",
".",
"isEmpty",
"(",
")",
")",
"{",
"this",
".",
"configurationStack",
".",
"addLast",
"(",
"element",
")",
";",
"}",
"else",
"{",
"(",
"(",
"Element",
")",
"this",
".",
"configurationStack",
".",
"getLast",
"(",
")",
")",
".",
"appendChild",
"(",
"element",
")",
";",
"this",
".",
"configurationStack",
".",
"addLast",
"(",
"element",
")",
";",
"}",
"}"
] |
Start a configuration node.
@param tagName
Tag name.
@param attrs
Tag attributes.
|
[
"Start",
"a",
"configuration",
"node",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java#L532-L556
|
14,061
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java
|
ExtensibleXmlParser.endElementBuilder
|
public Element endElementBuilder() {
final Element element = (Element) this.configurationStack.removeLast();
if ( this.characters != null ) {
element.appendChild( this.document.createTextNode( this.characters.toString() ) );
}
this.characters = null;
return element;
}
|
java
|
public Element endElementBuilder() {
final Element element = (Element) this.configurationStack.removeLast();
if ( this.characters != null ) {
element.appendChild( this.document.createTextNode( this.characters.toString() ) );
}
this.characters = null;
return element;
}
|
[
"public",
"Element",
"endElementBuilder",
"(",
")",
"{",
"final",
"Element",
"element",
"=",
"(",
"Element",
")",
"this",
".",
"configurationStack",
".",
"removeLast",
"(",
")",
";",
"if",
"(",
"this",
".",
"characters",
"!=",
"null",
")",
"{",
"element",
".",
"appendChild",
"(",
"this",
".",
"document",
".",
"createTextNode",
"(",
"this",
".",
"characters",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"this",
".",
"characters",
"=",
"null",
";",
"return",
"element",
";",
"}"
] |
End a configuration node.
@return The configuration.
|
[
"End",
"a",
"configuration",
"node",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java#L589-L598
|
14,062
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java
|
ExtensibleXmlParser.initEntityResolver
|
private void initEntityResolver() {
final String entityResolveClazzName = System.getProperty( ExtensibleXmlParser.ENTITY_RESOLVER_PROPERTY_NAME );
if ( entityResolveClazzName != null && entityResolveClazzName.length() > 0 ) {
try {
final Class entityResolverClazz = classLoader.loadClass( entityResolveClazzName );
this.entityResolver = (EntityResolver) entityResolverClazz.newInstance();
} catch ( final Exception ignoreIt ) {
}
}
}
|
java
|
private void initEntityResolver() {
final String entityResolveClazzName = System.getProperty( ExtensibleXmlParser.ENTITY_RESOLVER_PROPERTY_NAME );
if ( entityResolveClazzName != null && entityResolveClazzName.length() > 0 ) {
try {
final Class entityResolverClazz = classLoader.loadClass( entityResolveClazzName );
this.entityResolver = (EntityResolver) entityResolverClazz.newInstance();
} catch ( final Exception ignoreIt ) {
}
}
}
|
[
"private",
"void",
"initEntityResolver",
"(",
")",
"{",
"final",
"String",
"entityResolveClazzName",
"=",
"System",
".",
"getProperty",
"(",
"ExtensibleXmlParser",
".",
"ENTITY_RESOLVER_PROPERTY_NAME",
")",
";",
"if",
"(",
"entityResolveClazzName",
"!=",
"null",
"&&",
"entityResolveClazzName",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"try",
"{",
"final",
"Class",
"entityResolverClazz",
"=",
"classLoader",
".",
"loadClass",
"(",
"entityResolveClazzName",
")",
";",
"this",
".",
"entityResolver",
"=",
"(",
"EntityResolver",
")",
"entityResolverClazz",
".",
"newInstance",
"(",
")",
";",
"}",
"catch",
"(",
"final",
"Exception",
"ignoreIt",
")",
"{",
"}",
"}",
"}"
] |
Initializes EntityResolver that is configured via system property ENTITY_RESOLVER_PROPERTY_NAME.
|
[
"Initializes",
"EntityResolver",
"that",
"is",
"configured",
"via",
"system",
"property",
"ENTITY_RESOLVER_PROPERTY_NAME",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/xml/ExtensibleXmlParser.java#L767-L777
|
14,063
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/ProcessPackage.java
|
ProcessPackage.getOrCreate
|
public static ProcessPackage getOrCreate(ResourceTypePackageRegistry rtps) {
ProcessPackage rtp = (ProcessPackage) rtps.get(ResourceType.BPMN2);
if (rtp == null) {
rtp = new ProcessPackage();
// register the same instance for all types. There is no distinction
rtps.put(ResourceType.BPMN2, rtp);
rtps.put(ResourceType.DRF, rtp);
rtps.put(ResourceType.CMMN, rtp);
}
return rtp;
}
|
java
|
public static ProcessPackage getOrCreate(ResourceTypePackageRegistry rtps) {
ProcessPackage rtp = (ProcessPackage) rtps.get(ResourceType.BPMN2);
if (rtp == null) {
rtp = new ProcessPackage();
// register the same instance for all types. There is no distinction
rtps.put(ResourceType.BPMN2, rtp);
rtps.put(ResourceType.DRF, rtp);
rtps.put(ResourceType.CMMN, rtp);
}
return rtp;
}
|
[
"public",
"static",
"ProcessPackage",
"getOrCreate",
"(",
"ResourceTypePackageRegistry",
"rtps",
")",
"{",
"ProcessPackage",
"rtp",
"=",
"(",
"ProcessPackage",
")",
"rtps",
".",
"get",
"(",
"ResourceType",
".",
"BPMN2",
")",
";",
"if",
"(",
"rtp",
"==",
"null",
")",
"{",
"rtp",
"=",
"new",
"ProcessPackage",
"(",
")",
";",
"// register the same instance for all types. There is no distinction",
"rtps",
".",
"put",
"(",
"ResourceType",
".",
"BPMN2",
",",
"rtp",
")",
";",
"rtps",
".",
"put",
"(",
"ResourceType",
".",
"DRF",
",",
"rtp",
")",
";",
"rtps",
".",
"put",
"(",
"ResourceType",
".",
"CMMN",
",",
"rtp",
")",
";",
"}",
"return",
"rtp",
";",
"}"
] |
Finds or creates and registers a package in the given registry instance
@return the package that has been found
|
[
"Finds",
"or",
"creates",
"and",
"registers",
"a",
"package",
"in",
"the",
"given",
"registry",
"instance"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/ProcessPackage.java#L37-L47
|
14,064
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/descr/ForallDescr.java
|
ForallDescr.getBasePattern
|
public PatternDescr getBasePattern() {
if ( this.patterns.size() > 1 ) {
return (PatternDescr) this.patterns.get( 0 );
} else if ( this.patterns.size() == 1 ) {
// in case there is only one pattern, we do a rewrite, so:
// forall( Cheese( type == "stilton" ) )
// becomes
// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) )
PatternDescr original = (PatternDescr) this.patterns.get( 0 );
PatternDescr base = (PatternDescr) original.clone();
base.getDescrs().clear();
base.setIdentifier( BASE_IDENTIFIER );
base.setResource(original.getResource());
return base;
}
return null;
}
|
java
|
public PatternDescr getBasePattern() {
if ( this.patterns.size() > 1 ) {
return (PatternDescr) this.patterns.get( 0 );
} else if ( this.patterns.size() == 1 ) {
// in case there is only one pattern, we do a rewrite, so:
// forall( Cheese( type == "stilton" ) )
// becomes
// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) )
PatternDescr original = (PatternDescr) this.patterns.get( 0 );
PatternDescr base = (PatternDescr) original.clone();
base.getDescrs().clear();
base.setIdentifier( BASE_IDENTIFIER );
base.setResource(original.getResource());
return base;
}
return null;
}
|
[
"public",
"PatternDescr",
"getBasePattern",
"(",
")",
"{",
"if",
"(",
"this",
".",
"patterns",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"return",
"(",
"PatternDescr",
")",
"this",
".",
"patterns",
".",
"get",
"(",
"0",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"patterns",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"// in case there is only one pattern, we do a rewrite, so:",
"// forall( Cheese( type == \"stilton\" ) )",
"// becomes",
"// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == \"stilton\" ) )",
"PatternDescr",
"original",
"=",
"(",
"PatternDescr",
")",
"this",
".",
"patterns",
".",
"get",
"(",
"0",
")",
";",
"PatternDescr",
"base",
"=",
"(",
"PatternDescr",
")",
"original",
".",
"clone",
"(",
")",
";",
"base",
".",
"getDescrs",
"(",
")",
".",
"clear",
"(",
")",
";",
"base",
".",
"setIdentifier",
"(",
"BASE_IDENTIFIER",
")",
";",
"base",
".",
"setResource",
"(",
"original",
".",
"getResource",
"(",
")",
")",
";",
"return",
"base",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the base pattern from the forall CE
@return
|
[
"Returns",
"the",
"base",
"pattern",
"from",
"the",
"forall",
"CE"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/descr/ForallDescr.java#L61-L77
|
14,065
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/descr/ForallDescr.java
|
ForallDescr.getRemainingPatterns
|
public List<BaseDescr> getRemainingPatterns() {
if ( this.patterns.size() > 1 ) {
return this.patterns.subList( 1,
this.patterns.size() );
} else if ( this.patterns.size() == 1 ) {
// in case there is only one pattern, we do a rewrite, so:
// forall( Cheese( type == "stilton" ) )
// becomes
// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) )
PatternDescr original = (PatternDescr) this.patterns.get( 0 );
PatternDescr remaining = (PatternDescr) original.clone();
remaining.addConstraint( new ExprConstraintDescr( "this == " + BASE_IDENTIFIER ) );
remaining.setResource(original.getResource());
return Collections.singletonList( (BaseDescr)remaining );
}
return Collections.emptyList();
}
|
java
|
public List<BaseDescr> getRemainingPatterns() {
if ( this.patterns.size() > 1 ) {
return this.patterns.subList( 1,
this.patterns.size() );
} else if ( this.patterns.size() == 1 ) {
// in case there is only one pattern, we do a rewrite, so:
// forall( Cheese( type == "stilton" ) )
// becomes
// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) )
PatternDescr original = (PatternDescr) this.patterns.get( 0 );
PatternDescr remaining = (PatternDescr) original.clone();
remaining.addConstraint( new ExprConstraintDescr( "this == " + BASE_IDENTIFIER ) );
remaining.setResource(original.getResource());
return Collections.singletonList( (BaseDescr)remaining );
}
return Collections.emptyList();
}
|
[
"public",
"List",
"<",
"BaseDescr",
">",
"getRemainingPatterns",
"(",
")",
"{",
"if",
"(",
"this",
".",
"patterns",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"return",
"this",
".",
"patterns",
".",
"subList",
"(",
"1",
",",
"this",
".",
"patterns",
".",
"size",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"patterns",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"// in case there is only one pattern, we do a rewrite, so:",
"// forall( Cheese( type == \"stilton\" ) )",
"// becomes",
"// forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == \"stilton\" ) )",
"PatternDescr",
"original",
"=",
"(",
"PatternDescr",
")",
"this",
".",
"patterns",
".",
"get",
"(",
"0",
")",
";",
"PatternDescr",
"remaining",
"=",
"(",
"PatternDescr",
")",
"original",
".",
"clone",
"(",
")",
";",
"remaining",
".",
"addConstraint",
"(",
"new",
"ExprConstraintDescr",
"(",
"\"this == \"",
"+",
"BASE_IDENTIFIER",
")",
")",
";",
"remaining",
".",
"setResource",
"(",
"original",
".",
"getResource",
"(",
")",
")",
";",
"return",
"Collections",
".",
"singletonList",
"(",
"(",
"BaseDescr",
")",
"remaining",
")",
";",
"}",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}"
] |
Returns the remaining patterns from the forall CE
@return
|
[
"Returns",
"the",
"remaining",
"patterns",
"from",
"the",
"forall",
"CE"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/descr/ForallDescr.java#L83-L99
|
14,066
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/rule/Forall.java
|
Forall.getInnerDeclarations
|
public Map<String, Declaration> getInnerDeclarations() {
final Map inner = new HashMap( this.basePattern.getOuterDeclarations() );
for ( Pattern pattern : remainingPatterns ) {
inner.putAll( pattern.getOuterDeclarations() );
}
return inner;
}
|
java
|
public Map<String, Declaration> getInnerDeclarations() {
final Map inner = new HashMap( this.basePattern.getOuterDeclarations() );
for ( Pattern pattern : remainingPatterns ) {
inner.putAll( pattern.getOuterDeclarations() );
}
return inner;
}
|
[
"public",
"Map",
"<",
"String",
",",
"Declaration",
">",
"getInnerDeclarations",
"(",
")",
"{",
"final",
"Map",
"inner",
"=",
"new",
"HashMap",
"(",
"this",
".",
"basePattern",
".",
"getOuterDeclarations",
"(",
")",
")",
";",
"for",
"(",
"Pattern",
"pattern",
":",
"remainingPatterns",
")",
"{",
"inner",
".",
"putAll",
"(",
"pattern",
".",
"getOuterDeclarations",
"(",
")",
")",
";",
"}",
"return",
"inner",
";",
"}"
] |
Forall inner declarations are only provided by the base patterns
since it negates the remaining patterns
|
[
"Forall",
"inner",
"declarations",
"are",
"only",
"provided",
"by",
"the",
"base",
"patterns",
"since",
"it",
"negates",
"the",
"remaining",
"patterns"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/rule/Forall.java#L85-L91
|
14,067
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java
|
KnowledgePackageImpl.addProcess
|
public void addProcess(Process process) {
ResourceTypePackageRegistry rtps = getResourceTypePackages();
ProcessPackage rtp = ProcessPackage.getOrCreate(rtps);
rtp.add(process);
}
|
java
|
public void addProcess(Process process) {
ResourceTypePackageRegistry rtps = getResourceTypePackages();
ProcessPackage rtp = ProcessPackage.getOrCreate(rtps);
rtp.add(process);
}
|
[
"public",
"void",
"addProcess",
"(",
"Process",
"process",
")",
"{",
"ResourceTypePackageRegistry",
"rtps",
"=",
"getResourceTypePackages",
"(",
")",
";",
"ProcessPackage",
"rtp",
"=",
"ProcessPackage",
".",
"getOrCreate",
"(",
"rtps",
")",
";",
"rtp",
".",
"add",
"(",
"process",
")",
";",
"}"
] |
Add a rule flow to this package.
|
[
"Add",
"a",
"rule",
"flow",
"to",
"this",
"package",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java#L484-L488
|
14,068
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java
|
KnowledgePackageImpl.getRuleFlows
|
public Map<String, Process> getRuleFlows() {
ProcessPackage rtp = (ProcessPackage) getResourceTypePackages().get(ResourceType.BPMN2);
return rtp == null? Collections.emptyMap() : rtp.getRuleFlows();
}
|
java
|
public Map<String, Process> getRuleFlows() {
ProcessPackage rtp = (ProcessPackage) getResourceTypePackages().get(ResourceType.BPMN2);
return rtp == null? Collections.emptyMap() : rtp.getRuleFlows();
}
|
[
"public",
"Map",
"<",
"String",
",",
"Process",
">",
"getRuleFlows",
"(",
")",
"{",
"ProcessPackage",
"rtp",
"=",
"(",
"ProcessPackage",
")",
"getResourceTypePackages",
"(",
")",
".",
"get",
"(",
"ResourceType",
".",
"BPMN2",
")",
";",
"return",
"rtp",
"==",
"null",
"?",
"Collections",
".",
"emptyMap",
"(",
")",
":",
"rtp",
".",
"getRuleFlows",
"(",
")",
";",
"}"
] |
Get the rule flows for this package. The key is the ruleflow id. It will
be Collections.EMPTY_MAP if none have been added.
|
[
"Get",
"the",
"rule",
"flows",
"for",
"this",
"package",
".",
"The",
"key",
"is",
"the",
"ruleflow",
"id",
".",
"It",
"will",
"be",
"Collections",
".",
"EMPTY_MAP",
"if",
"none",
"have",
"been",
"added",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java#L494-L497
|
14,069
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java
|
KnowledgePackageImpl.removeRuleFlow
|
public void removeRuleFlow(String id) {
ProcessPackage rtp = (ProcessPackage) getResourceTypePackages().get(ResourceType.BPMN2);
if (rtp == null || rtp.lookup(id) == null) {
throw new IllegalArgumentException("The rule flow with id [" + id + "] is not part of this package.");
}
rtp.remove(id);
}
|
java
|
public void removeRuleFlow(String id) {
ProcessPackage rtp = (ProcessPackage) getResourceTypePackages().get(ResourceType.BPMN2);
if (rtp == null || rtp.lookup(id) == null) {
throw new IllegalArgumentException("The rule flow with id [" + id + "] is not part of this package.");
}
rtp.remove(id);
}
|
[
"public",
"void",
"removeRuleFlow",
"(",
"String",
"id",
")",
"{",
"ProcessPackage",
"rtp",
"=",
"(",
"ProcessPackage",
")",
"getResourceTypePackages",
"(",
")",
".",
"get",
"(",
"ResourceType",
".",
"BPMN2",
")",
";",
"if",
"(",
"rtp",
"==",
"null",
"||",
"rtp",
".",
"lookup",
"(",
"id",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The rule flow with id [\"",
"+",
"id",
"+",
"\"] is not part of this package.\"",
")",
";",
"}",
"rtp",
".",
"remove",
"(",
"id",
")",
";",
"}"
] |
Rule flows can be removed by ID.
|
[
"Rule",
"flows",
"can",
"be",
"removed",
"by",
"ID",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/impl/KnowledgePackageImpl.java#L502-L508
|
14,070
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.addDSLMapping
|
public void addDSLMapping(final DSLMapping mapping) {
for ( DSLMappingEntry entry : mapping.getEntries() ) {
if ( DSLMappingEntry.KEYWORD.equals( entry.getSection() ) ) {
this.keywords.add( entry );
} else if ( DSLMappingEntry.CONDITION.equals( entry.getSection() ) ) {
this.condition.add( entry );
} else if ( DSLMappingEntry.CONSEQUENCE.equals( entry.getSection() ) ) {
this.consequence.add( entry );
} else {
// if any, then add to them both condition and consequence
this.condition.add( entry );
this.consequence.add( entry );
}
}
if ( mapping.getOption( "result" ) ) showResult = true;
if ( mapping.getOption( "steps" ) ) showSteps = true;
if ( mapping.getOption( "keyword" ) ) showKeyword = true;
if ( mapping.getOption( "when" ) ) showWhen = true;
if ( mapping.getOption( "then" ) ) showThen = true;
if ( mapping.getOption( "usage" ) ) showUsage = true;
}
|
java
|
public void addDSLMapping(final DSLMapping mapping) {
for ( DSLMappingEntry entry : mapping.getEntries() ) {
if ( DSLMappingEntry.KEYWORD.equals( entry.getSection() ) ) {
this.keywords.add( entry );
} else if ( DSLMappingEntry.CONDITION.equals( entry.getSection() ) ) {
this.condition.add( entry );
} else if ( DSLMappingEntry.CONSEQUENCE.equals( entry.getSection() ) ) {
this.consequence.add( entry );
} else {
// if any, then add to them both condition and consequence
this.condition.add( entry );
this.consequence.add( entry );
}
}
if ( mapping.getOption( "result" ) ) showResult = true;
if ( mapping.getOption( "steps" ) ) showSteps = true;
if ( mapping.getOption( "keyword" ) ) showKeyword = true;
if ( mapping.getOption( "when" ) ) showWhen = true;
if ( mapping.getOption( "then" ) ) showThen = true;
if ( mapping.getOption( "usage" ) ) showUsage = true;
}
|
[
"public",
"void",
"addDSLMapping",
"(",
"final",
"DSLMapping",
"mapping",
")",
"{",
"for",
"(",
"DSLMappingEntry",
"entry",
":",
"mapping",
".",
"getEntries",
"(",
")",
")",
"{",
"if",
"(",
"DSLMappingEntry",
".",
"KEYWORD",
".",
"equals",
"(",
"entry",
".",
"getSection",
"(",
")",
")",
")",
"{",
"this",
".",
"keywords",
".",
"add",
"(",
"entry",
")",
";",
"}",
"else",
"if",
"(",
"DSLMappingEntry",
".",
"CONDITION",
".",
"equals",
"(",
"entry",
".",
"getSection",
"(",
")",
")",
")",
"{",
"this",
".",
"condition",
".",
"add",
"(",
"entry",
")",
";",
"}",
"else",
"if",
"(",
"DSLMappingEntry",
".",
"CONSEQUENCE",
".",
"equals",
"(",
"entry",
".",
"getSection",
"(",
")",
")",
")",
"{",
"this",
".",
"consequence",
".",
"add",
"(",
"entry",
")",
";",
"}",
"else",
"{",
"// if any, then add to them both condition and consequence",
"this",
".",
"condition",
".",
"add",
"(",
"entry",
")",
";",
"this",
".",
"consequence",
".",
"add",
"(",
"entry",
")",
";",
"}",
"}",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"result\"",
")",
")",
"showResult",
"=",
"true",
";",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"steps\"",
")",
")",
"showSteps",
"=",
"true",
";",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"keyword\"",
")",
")",
"showKeyword",
"=",
"true",
";",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"when\"",
")",
")",
"showWhen",
"=",
"true",
";",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"then\"",
")",
")",
"showThen",
"=",
"true",
";",
"if",
"(",
"mapping",
".",
"getOption",
"(",
"\"usage\"",
")",
")",
"showUsage",
"=",
"true",
";",
"}"
] |
Add the new mapping to this expander.
@param mapping
|
[
"Add",
"the",
"new",
"mapping",
"to",
"this",
"expander",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L117-L138
|
14,071
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.expandConstructions
|
private StringBuffer expandConstructions(final String drl) {
// display keys if requested
if ( showKeyword ) {
for ( DSLMappingEntry entry : this.keywords ) {
logger.info( "keyword: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
}
}
if ( showWhen ) {
for ( DSLMappingEntry entry : this.condition ) {
logger.info( "when: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
// logger.info( " " + entry.getValuePattern() );
}
}
if ( showThen ) {
for ( DSLMappingEntry entry : this.consequence ) {
logger.info( "then: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
}
}
// parse and expand specific areas
final Matcher m = finder.matcher( drl );
final StringBuffer buf = new StringBuffer();
int drlPos = 0;
int linecount = 0;
while ( m.find() ) {
final StringBuilder expanded = new StringBuilder();
int newPos = m.start();
linecount += countNewlines( drl,
drlPos,
newPos );
drlPos = newPos;
String constr = m.group().trim();
if ( constr.startsWith( "rule" ) ) {
String headerFragment = m.group( 1 );
expanded.append( headerFragment ); // adding rule header and attributes
String lhsFragment = m.group( 2 );
expanded.append( this.expandLHS( lhsFragment,
linecount + countNewlines( drl,
drlPos,
m.start( 2 ) ) + 1 ) );
String thenFragment = m.group( 3 );
expanded.append( thenFragment ); // adding "then" header
String rhsFragment = this.expandRHS( m.group( 4 ),
linecount + countNewlines( drl,
drlPos,
m.start( 4 ) ) + 1 );
expanded.append( rhsFragment );
expanded.append( m.group( 5 ) ); // adding rule trailer
} else if ( constr.startsWith( "query" ) ) {
String fragment = m.group( 6 );
expanded.append( fragment ); // adding query header and attributes
String lhsFragment = this.expandLHS( m.group( 7 ),
linecount + countNewlines( drl,
drlPos,
m.start( 7 ) ) + 1 );
expanded.append( lhsFragment );
expanded.append( m.group( 8 ) ); // adding query trailer
} else {
// strange behavior
this.addError( new ExpanderException( "Unable to expand statement: " + constr,
0 ) );
}
m.appendReplacement( buf,
Matcher.quoteReplacement( expanded.toString() ) );
}
m.appendTail( buf );
return buf;
}
|
java
|
private StringBuffer expandConstructions(final String drl) {
// display keys if requested
if ( showKeyword ) {
for ( DSLMappingEntry entry : this.keywords ) {
logger.info( "keyword: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
}
}
if ( showWhen ) {
for ( DSLMappingEntry entry : this.condition ) {
logger.info( "when: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
// logger.info( " " + entry.getValuePattern() );
}
}
if ( showThen ) {
for ( DSLMappingEntry entry : this.consequence ) {
logger.info( "then: " + entry.getMappingKey() );
logger.info( " " + entry.getKeyPattern() );
}
}
// parse and expand specific areas
final Matcher m = finder.matcher( drl );
final StringBuffer buf = new StringBuffer();
int drlPos = 0;
int linecount = 0;
while ( m.find() ) {
final StringBuilder expanded = new StringBuilder();
int newPos = m.start();
linecount += countNewlines( drl,
drlPos,
newPos );
drlPos = newPos;
String constr = m.group().trim();
if ( constr.startsWith( "rule" ) ) {
String headerFragment = m.group( 1 );
expanded.append( headerFragment ); // adding rule header and attributes
String lhsFragment = m.group( 2 );
expanded.append( this.expandLHS( lhsFragment,
linecount + countNewlines( drl,
drlPos,
m.start( 2 ) ) + 1 ) );
String thenFragment = m.group( 3 );
expanded.append( thenFragment ); // adding "then" header
String rhsFragment = this.expandRHS( m.group( 4 ),
linecount + countNewlines( drl,
drlPos,
m.start( 4 ) ) + 1 );
expanded.append( rhsFragment );
expanded.append( m.group( 5 ) ); // adding rule trailer
} else if ( constr.startsWith( "query" ) ) {
String fragment = m.group( 6 );
expanded.append( fragment ); // adding query header and attributes
String lhsFragment = this.expandLHS( m.group( 7 ),
linecount + countNewlines( drl,
drlPos,
m.start( 7 ) ) + 1 );
expanded.append( lhsFragment );
expanded.append( m.group( 8 ) ); // adding query trailer
} else {
// strange behavior
this.addError( new ExpanderException( "Unable to expand statement: " + constr,
0 ) );
}
m.appendReplacement( buf,
Matcher.quoteReplacement( expanded.toString() ) );
}
m.appendTail( buf );
return buf;
}
|
[
"private",
"StringBuffer",
"expandConstructions",
"(",
"final",
"String",
"drl",
")",
"{",
"// display keys if requested",
"if",
"(",
"showKeyword",
")",
"{",
"for",
"(",
"DSLMappingEntry",
"entry",
":",
"this",
".",
"keywords",
")",
"{",
"logger",
".",
"info",
"(",
"\"keyword: \"",
"+",
"entry",
".",
"getMappingKey",
"(",
")",
")",
";",
"logger",
".",
"info",
"(",
"\" \"",
"+",
"entry",
".",
"getKeyPattern",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"showWhen",
")",
"{",
"for",
"(",
"DSLMappingEntry",
"entry",
":",
"this",
".",
"condition",
")",
"{",
"logger",
".",
"info",
"(",
"\"when: \"",
"+",
"entry",
".",
"getMappingKey",
"(",
")",
")",
";",
"logger",
".",
"info",
"(",
"\" \"",
"+",
"entry",
".",
"getKeyPattern",
"(",
")",
")",
";",
"// logger.info( \" \" + entry.getValuePattern() );",
"}",
"}",
"if",
"(",
"showThen",
")",
"{",
"for",
"(",
"DSLMappingEntry",
"entry",
":",
"this",
".",
"consequence",
")",
"{",
"logger",
".",
"info",
"(",
"\"then: \"",
"+",
"entry",
".",
"getMappingKey",
"(",
")",
")",
";",
"logger",
".",
"info",
"(",
"\" \"",
"+",
"entry",
".",
"getKeyPattern",
"(",
")",
")",
";",
"}",
"}",
"// parse and expand specific areas",
"final",
"Matcher",
"m",
"=",
"finder",
".",
"matcher",
"(",
"drl",
")",
";",
"final",
"StringBuffer",
"buf",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"int",
"drlPos",
"=",
"0",
";",
"int",
"linecount",
"=",
"0",
";",
"while",
"(",
"m",
".",
"find",
"(",
")",
")",
"{",
"final",
"StringBuilder",
"expanded",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"int",
"newPos",
"=",
"m",
".",
"start",
"(",
")",
";",
"linecount",
"+=",
"countNewlines",
"(",
"drl",
",",
"drlPos",
",",
"newPos",
")",
";",
"drlPos",
"=",
"newPos",
";",
"String",
"constr",
"=",
"m",
".",
"group",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"constr",
".",
"startsWith",
"(",
"\"rule\"",
")",
")",
"{",
"String",
"headerFragment",
"=",
"m",
".",
"group",
"(",
"1",
")",
";",
"expanded",
".",
"append",
"(",
"headerFragment",
")",
";",
"// adding rule header and attributes",
"String",
"lhsFragment",
"=",
"m",
".",
"group",
"(",
"2",
")",
";",
"expanded",
".",
"append",
"(",
"this",
".",
"expandLHS",
"(",
"lhsFragment",
",",
"linecount",
"+",
"countNewlines",
"(",
"drl",
",",
"drlPos",
",",
"m",
".",
"start",
"(",
"2",
")",
")",
"+",
"1",
")",
")",
";",
"String",
"thenFragment",
"=",
"m",
".",
"group",
"(",
"3",
")",
";",
"expanded",
".",
"append",
"(",
"thenFragment",
")",
";",
"// adding \"then\" header",
"String",
"rhsFragment",
"=",
"this",
".",
"expandRHS",
"(",
"m",
".",
"group",
"(",
"4",
")",
",",
"linecount",
"+",
"countNewlines",
"(",
"drl",
",",
"drlPos",
",",
"m",
".",
"start",
"(",
"4",
")",
")",
"+",
"1",
")",
";",
"expanded",
".",
"append",
"(",
"rhsFragment",
")",
";",
"expanded",
".",
"append",
"(",
"m",
".",
"group",
"(",
"5",
")",
")",
";",
"// adding rule trailer",
"}",
"else",
"if",
"(",
"constr",
".",
"startsWith",
"(",
"\"query\"",
")",
")",
"{",
"String",
"fragment",
"=",
"m",
".",
"group",
"(",
"6",
")",
";",
"expanded",
".",
"append",
"(",
"fragment",
")",
";",
"// adding query header and attributes",
"String",
"lhsFragment",
"=",
"this",
".",
"expandLHS",
"(",
"m",
".",
"group",
"(",
"7",
")",
",",
"linecount",
"+",
"countNewlines",
"(",
"drl",
",",
"drlPos",
",",
"m",
".",
"start",
"(",
"7",
")",
")",
"+",
"1",
")",
";",
"expanded",
".",
"append",
"(",
"lhsFragment",
")",
";",
"expanded",
".",
"append",
"(",
"m",
".",
"group",
"(",
"8",
")",
")",
";",
"// adding query trailer",
"}",
"else",
"{",
"// strange behavior",
"this",
".",
"addError",
"(",
"new",
"ExpanderException",
"(",
"\"Unable to expand statement: \"",
"+",
"constr",
",",
"0",
")",
")",
";",
"}",
"m",
".",
"appendReplacement",
"(",
"buf",
",",
"Matcher",
".",
"quoteReplacement",
"(",
"expanded",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"m",
".",
"appendTail",
"(",
"buf",
")",
";",
"return",
"buf",
";",
"}"
] |
Expand constructions like rules and queries
@param drl
@return
|
[
"Expand",
"constructions",
"like",
"rules",
"and",
"queries"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L230-L304
|
14,072
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.cleanupExpressions
|
private String cleanupExpressions(String drl) {
// execute cleanup
for ( final DSLMappingEntry entry : this.cleanup ) {
drl = entry.getKeyPattern().matcher( drl ).replaceAll( entry.getValuePattern() );
}
return drl;
}
|
java
|
private String cleanupExpressions(String drl) {
// execute cleanup
for ( final DSLMappingEntry entry : this.cleanup ) {
drl = entry.getKeyPattern().matcher( drl ).replaceAll( entry.getValuePattern() );
}
return drl;
}
|
[
"private",
"String",
"cleanupExpressions",
"(",
"String",
"drl",
")",
"{",
"// execute cleanup",
"for",
"(",
"final",
"DSLMappingEntry",
"entry",
":",
"this",
".",
"cleanup",
")",
"{",
"drl",
"=",
"entry",
".",
"getKeyPattern",
"(",
")",
".",
"matcher",
"(",
"drl",
")",
".",
"replaceAll",
"(",
"entry",
".",
"getValuePattern",
"(",
")",
")",
";",
"}",
"return",
"drl",
";",
"}"
] |
Clean up constructions that exists only in the unexpanded code
@param drl
@return
|
[
"Clean",
"up",
"constructions",
"that",
"exists",
"only",
"in",
"the",
"unexpanded",
"code"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L312-L318
|
14,073
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.expandKeywords
|
private String expandKeywords(String drl) {
substitutions = new ArrayList<Map<String, String>>();
// apply all keywords templates
drl = substitute( drl,
this.keywords,
0,
useKeyword,
false );
substitutions = null;
return drl;
}
|
java
|
private String expandKeywords(String drl) {
substitutions = new ArrayList<Map<String, String>>();
// apply all keywords templates
drl = substitute( drl,
this.keywords,
0,
useKeyword,
false );
substitutions = null;
return drl;
}
|
[
"private",
"String",
"expandKeywords",
"(",
"String",
"drl",
")",
"{",
"substitutions",
"=",
"new",
"ArrayList",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"(",
")",
";",
"// apply all keywords templates",
"drl",
"=",
"substitute",
"(",
"drl",
",",
"this",
".",
"keywords",
",",
"0",
",",
"useKeyword",
",",
"false",
")",
";",
"substitutions",
"=",
"null",
";",
"return",
"drl",
";",
"}"
] |
Expand all configured keywords
@param drl
@return
|
[
"Expand",
"all",
"configured",
"keywords"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L338-L348
|
14,074
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.expandLHS
|
private String expandLHS(final String lhs,
int lineOffset) {
substitutions = new ArrayList<Map<String, String>>();
// logger.info( "*** LHS>" + lhs + "<" );
final StringBuilder buf = new StringBuilder();
final String[] lines = lhs.split( (lhs.indexOf("\r\n") >= 0 ? "\r\n":"\n"),
-1 ); // since we assembled the string, we know line breaks are \n
final String[] expanded = new String[lines.length]; // buffer for expanded lines
int lastExpanded = -1;
int lastPattern = -1;
for ( int i = 0; i < lines.length - 1; i++ ) {
final String trimmed = lines[i].trim();
expanded[++lastExpanded] = lines[i];
if ( trimmed.length() == 0 || trimmed.startsWith( "#" ) || trimmed.startsWith( "//" ) ) {
// comments - do nothing
} else if ( trimmed.startsWith( ">" ) ) {
// passthrough code - simply remove the passthrough mark character
expanded[lastExpanded] = lines[i].replaceFirst( ">",
" " );
lastPattern = lastExpanded;
} else {
// regular expansion - expand the expression
expanded[lastExpanded] =
substitute( expanded[lastExpanded],
this.condition,
i + lineOffset,
useWhen,
showSteps );
// do we need to report errors for that?
if ( lines[i].equals( expanded[lastExpanded] ) ) {
// report error
this.addError( new ExpanderException( "Unable to expand: " + lines[i].replaceAll( "[\n\r]",
"" ).trim(),
i + lineOffset ) );
}
// but if the original starts with a "-", it means we need to add it
// as a constraint to the previous pattern
if ( trimmed.startsWith( "-" ) && (!lines[i].equals( expanded[lastExpanded] )) ) {
if ( lastPattern >= 0 ) {
ConstraintInformation c = ConstraintInformation.findConstraintInformationInPattern( expanded[lastPattern] );
if ( c.start > -1 ) {
// rebuilding previous pattern structure
expanded[lastPattern] = expanded[lastPattern].substring( 0,
c.start ) + c.constraints + ((c.constraints.trim().length() == 0) ? "" : ", ") + expanded[lastExpanded].trim() + expanded[lastPattern].substring( c.end );
} else {
// error, pattern not found to add constraint to
this.addError( new ExpanderException( "No pattern was found to add the constraint to: " + lines[i].trim(),
i + lineOffset ) );
}
}
lastExpanded--;
} else {
lastPattern = lastExpanded;
}
}
}
for ( int i = 0; i <= lastExpanded; i++ ) {
buf.append( expanded[i] );
buf.append( nl );
}
return buf.toString();
}
|
java
|
private String expandLHS(final String lhs,
int lineOffset) {
substitutions = new ArrayList<Map<String, String>>();
// logger.info( "*** LHS>" + lhs + "<" );
final StringBuilder buf = new StringBuilder();
final String[] lines = lhs.split( (lhs.indexOf("\r\n") >= 0 ? "\r\n":"\n"),
-1 ); // since we assembled the string, we know line breaks are \n
final String[] expanded = new String[lines.length]; // buffer for expanded lines
int lastExpanded = -1;
int lastPattern = -1;
for ( int i = 0; i < lines.length - 1; i++ ) {
final String trimmed = lines[i].trim();
expanded[++lastExpanded] = lines[i];
if ( trimmed.length() == 0 || trimmed.startsWith( "#" ) || trimmed.startsWith( "//" ) ) {
// comments - do nothing
} else if ( trimmed.startsWith( ">" ) ) {
// passthrough code - simply remove the passthrough mark character
expanded[lastExpanded] = lines[i].replaceFirst( ">",
" " );
lastPattern = lastExpanded;
} else {
// regular expansion - expand the expression
expanded[lastExpanded] =
substitute( expanded[lastExpanded],
this.condition,
i + lineOffset,
useWhen,
showSteps );
// do we need to report errors for that?
if ( lines[i].equals( expanded[lastExpanded] ) ) {
// report error
this.addError( new ExpanderException( "Unable to expand: " + lines[i].replaceAll( "[\n\r]",
"" ).trim(),
i + lineOffset ) );
}
// but if the original starts with a "-", it means we need to add it
// as a constraint to the previous pattern
if ( trimmed.startsWith( "-" ) && (!lines[i].equals( expanded[lastExpanded] )) ) {
if ( lastPattern >= 0 ) {
ConstraintInformation c = ConstraintInformation.findConstraintInformationInPattern( expanded[lastPattern] );
if ( c.start > -1 ) {
// rebuilding previous pattern structure
expanded[lastPattern] = expanded[lastPattern].substring( 0,
c.start ) + c.constraints + ((c.constraints.trim().length() == 0) ? "" : ", ") + expanded[lastExpanded].trim() + expanded[lastPattern].substring( c.end );
} else {
// error, pattern not found to add constraint to
this.addError( new ExpanderException( "No pattern was found to add the constraint to: " + lines[i].trim(),
i + lineOffset ) );
}
}
lastExpanded--;
} else {
lastPattern = lastExpanded;
}
}
}
for ( int i = 0; i <= lastExpanded; i++ ) {
buf.append( expanded[i] );
buf.append( nl );
}
return buf.toString();
}
|
[
"private",
"String",
"expandLHS",
"(",
"final",
"String",
"lhs",
",",
"int",
"lineOffset",
")",
"{",
"substitutions",
"=",
"new",
"ArrayList",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"(",
")",
";",
"// logger.info( \"*** LHS>\" + lhs + \"<\" );",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"String",
"[",
"]",
"lines",
"=",
"lhs",
".",
"split",
"(",
"(",
"lhs",
".",
"indexOf",
"(",
"\"\\r\\n\"",
")",
">=",
"0",
"?",
"\"\\r\\n\"",
":",
"\"\\n\"",
")",
",",
"-",
"1",
")",
";",
"// since we assembled the string, we know line breaks are \\n",
"final",
"String",
"[",
"]",
"expanded",
"=",
"new",
"String",
"[",
"lines",
".",
"length",
"]",
";",
"// buffer for expanded lines",
"int",
"lastExpanded",
"=",
"-",
"1",
";",
"int",
"lastPattern",
"=",
"-",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"final",
"String",
"trimmed",
"=",
"lines",
"[",
"i",
"]",
".",
"trim",
"(",
")",
";",
"expanded",
"[",
"++",
"lastExpanded",
"]",
"=",
"lines",
"[",
"i",
"]",
";",
"if",
"(",
"trimmed",
".",
"length",
"(",
")",
"==",
"0",
"||",
"trimmed",
".",
"startsWith",
"(",
"\"#\"",
")",
"||",
"trimmed",
".",
"startsWith",
"(",
"\"//\"",
")",
")",
"{",
"// comments - do nothing",
"}",
"else",
"if",
"(",
"trimmed",
".",
"startsWith",
"(",
"\">\"",
")",
")",
"{",
"// passthrough code - simply remove the passthrough mark character",
"expanded",
"[",
"lastExpanded",
"]",
"=",
"lines",
"[",
"i",
"]",
".",
"replaceFirst",
"(",
"\">\"",
",",
"\" \"",
")",
";",
"lastPattern",
"=",
"lastExpanded",
";",
"}",
"else",
"{",
"// regular expansion - expand the expression",
"expanded",
"[",
"lastExpanded",
"]",
"=",
"substitute",
"(",
"expanded",
"[",
"lastExpanded",
"]",
",",
"this",
".",
"condition",
",",
"i",
"+",
"lineOffset",
",",
"useWhen",
",",
"showSteps",
")",
";",
"// do we need to report errors for that?",
"if",
"(",
"lines",
"[",
"i",
"]",
".",
"equals",
"(",
"expanded",
"[",
"lastExpanded",
"]",
")",
")",
"{",
"// report error",
"this",
".",
"addError",
"(",
"new",
"ExpanderException",
"(",
"\"Unable to expand: \"",
"+",
"lines",
"[",
"i",
"]",
".",
"replaceAll",
"(",
"\"[\\n\\r]\"",
",",
"\"\"",
")",
".",
"trim",
"(",
")",
",",
"i",
"+",
"lineOffset",
")",
")",
";",
"}",
"// but if the original starts with a \"-\", it means we need to add it",
"// as a constraint to the previous pattern",
"if",
"(",
"trimmed",
".",
"startsWith",
"(",
"\"-\"",
")",
"&&",
"(",
"!",
"lines",
"[",
"i",
"]",
".",
"equals",
"(",
"expanded",
"[",
"lastExpanded",
"]",
")",
")",
")",
"{",
"if",
"(",
"lastPattern",
">=",
"0",
")",
"{",
"ConstraintInformation",
"c",
"=",
"ConstraintInformation",
".",
"findConstraintInformationInPattern",
"(",
"expanded",
"[",
"lastPattern",
"]",
")",
";",
"if",
"(",
"c",
".",
"start",
">",
"-",
"1",
")",
"{",
"// rebuilding previous pattern structure",
"expanded",
"[",
"lastPattern",
"]",
"=",
"expanded",
"[",
"lastPattern",
"]",
".",
"substring",
"(",
"0",
",",
"c",
".",
"start",
")",
"+",
"c",
".",
"constraints",
"+",
"(",
"(",
"c",
".",
"constraints",
".",
"trim",
"(",
")",
".",
"length",
"(",
")",
"==",
"0",
")",
"?",
"\"\"",
":",
"\", \"",
")",
"+",
"expanded",
"[",
"lastExpanded",
"]",
".",
"trim",
"(",
")",
"+",
"expanded",
"[",
"lastPattern",
"]",
".",
"substring",
"(",
"c",
".",
"end",
")",
";",
"}",
"else",
"{",
"// error, pattern not found to add constraint to",
"this",
".",
"addError",
"(",
"new",
"ExpanderException",
"(",
"\"No pattern was found to add the constraint to: \"",
"+",
"lines",
"[",
"i",
"]",
".",
"trim",
"(",
")",
",",
"i",
"+",
"lineOffset",
")",
")",
";",
"}",
"}",
"lastExpanded",
"--",
";",
"}",
"else",
"{",
"lastPattern",
"=",
"lastExpanded",
";",
"}",
"}",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<=",
"lastExpanded",
";",
"i",
"++",
")",
"{",
"buf",
".",
"append",
"(",
"expanded",
"[",
"i",
"]",
")",
";",
"buf",
".",
"append",
"(",
"nl",
")",
";",
"}",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] |
Expand LHS for a construction
@param lhs
@param lineOffset
@return
|
[
"Expand",
"LHS",
"for",
"a",
"construction"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L541-L607
|
14,075
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java
|
DefaultExpander.loadDrlFile
|
private String loadDrlFile(final Reader drl) throws IOException {
final StringBuilder buf = new StringBuilder();
final BufferedReader input = new BufferedReader( drl );
String line;
while ( (line = input.readLine()) != null ) {
buf.append( line );
buf.append( nl );
}
return buf.toString();
}
|
java
|
private String loadDrlFile(final Reader drl) throws IOException {
final StringBuilder buf = new StringBuilder();
final BufferedReader input = new BufferedReader( drl );
String line;
while ( (line = input.readLine()) != null ) {
buf.append( line );
buf.append( nl );
}
return buf.toString();
}
|
[
"private",
"String",
"loadDrlFile",
"(",
"final",
"Reader",
"drl",
")",
"throws",
"IOException",
"{",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"BufferedReader",
"input",
"=",
"new",
"BufferedReader",
"(",
"drl",
")",
";",
"String",
"line",
";",
"while",
"(",
"(",
"line",
"=",
"input",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"buf",
".",
"append",
"(",
"line",
")",
";",
"buf",
".",
"append",
"(",
"nl",
")",
";",
"}",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] |
Reads the stream into a String
|
[
"Reads",
"the",
"stream",
"into",
"a",
"String"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/dsl/DefaultExpander.java#L695-L704
|
14,076
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/common/DefaultAgenda.java
|
DefaultAgenda.addItemToActivationGroup
|
public void addItemToActivationGroup(final AgendaItem item) {
if ( item.isRuleAgendaItem() ) {
throw new UnsupportedOperationException("defensive programming, making sure this isn't called, before removing");
}
String group = item.getRule().getActivationGroup();
if ( group != null && group.length() > 0 ) {
InternalActivationGroup actgroup = getActivationGroup( group );
// Don't allow lazy activations to activate, from before it's last trigger point
if ( actgroup.getTriggeredForRecency() != 0 &&
actgroup.getTriggeredForRecency() >= item.getPropagationContext().getFactHandle().getRecency() ) {
return;
}
actgroup.addActivation( item );
}
}
|
java
|
public void addItemToActivationGroup(final AgendaItem item) {
if ( item.isRuleAgendaItem() ) {
throw new UnsupportedOperationException("defensive programming, making sure this isn't called, before removing");
}
String group = item.getRule().getActivationGroup();
if ( group != null && group.length() > 0 ) {
InternalActivationGroup actgroup = getActivationGroup( group );
// Don't allow lazy activations to activate, from before it's last trigger point
if ( actgroup.getTriggeredForRecency() != 0 &&
actgroup.getTriggeredForRecency() >= item.getPropagationContext().getFactHandle().getRecency() ) {
return;
}
actgroup.addActivation( item );
}
}
|
[
"public",
"void",
"addItemToActivationGroup",
"(",
"final",
"AgendaItem",
"item",
")",
"{",
"if",
"(",
"item",
".",
"isRuleAgendaItem",
"(",
")",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"defensive programming, making sure this isn't called, before removing\"",
")",
";",
"}",
"String",
"group",
"=",
"item",
".",
"getRule",
"(",
")",
".",
"getActivationGroup",
"(",
")",
";",
"if",
"(",
"group",
"!=",
"null",
"&&",
"group",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"InternalActivationGroup",
"actgroup",
"=",
"getActivationGroup",
"(",
"group",
")",
";",
"// Don't allow lazy activations to activate, from before it's last trigger point",
"if",
"(",
"actgroup",
".",
"getTriggeredForRecency",
"(",
")",
"!=",
"0",
"&&",
"actgroup",
".",
"getTriggeredForRecency",
"(",
")",
">=",
"item",
".",
"getPropagationContext",
"(",
")",
".",
"getFactHandle",
"(",
")",
".",
"getRecency",
"(",
")",
")",
"{",
"return",
";",
"}",
"actgroup",
".",
"addActivation",
"(",
"item",
")",
";",
"}",
"}"
] |
If the item belongs to an activation group, add it
@param item
|
[
"If",
"the",
"item",
"belongs",
"to",
"an",
"activation",
"group",
"add",
"it"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/common/DefaultAgenda.java#L319-L335
|
14,077
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/lang/DRL6Lexer.java
|
DRL6Lexer.emit
|
public Token emit() {
Token t = new DroolsToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1);
t.setLine(state.tokenStartLine);
t.setText(state.text);
t.setCharPositionInLine(state.tokenStartCharPositionInLine);
emit(t);
return t;
}
|
java
|
public Token emit() {
Token t = new DroolsToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1);
t.setLine(state.tokenStartLine);
t.setText(state.text);
t.setCharPositionInLine(state.tokenStartCharPositionInLine);
emit(t);
return t;
}
|
[
"public",
"Token",
"emit",
"(",
")",
"{",
"Token",
"t",
"=",
"new",
"DroolsToken",
"(",
"input",
",",
"state",
".",
"type",
",",
"state",
".",
"channel",
",",
"state",
".",
"tokenStartCharIndex",
",",
"getCharIndex",
"(",
")",
"-",
"1",
")",
";",
"t",
".",
"setLine",
"(",
"state",
".",
"tokenStartLine",
")",
";",
"t",
".",
"setText",
"(",
"state",
".",
"text",
")",
";",
"t",
".",
"setCharPositionInLine",
"(",
"state",
".",
"tokenStartCharPositionInLine",
")",
";",
"emit",
"(",
"t",
")",
";",
"return",
"t",
";",
"}"
] |
The standard method called to automatically emit a token at the
outermost lexical rule. The token object should point into the
char buffer start..stop. If there is a text override in 'text',
use that to set the token's text. Override this method to emit
custom Token objects.
|
[
"The",
"standard",
"method",
"called",
"to",
"automatically",
"emit",
"a",
"token",
"at",
"the",
"outermost",
"lexical",
"rule",
".",
"The",
"token",
"object",
"should",
"point",
"into",
"the",
"char",
"buffer",
"start",
"..",
"stop",
".",
"If",
"there",
"is",
"a",
"text",
"override",
"in",
"text",
"use",
"that",
"to",
"set",
"the",
"token",
"s",
"text",
".",
"Override",
"this",
"method",
"to",
"emit",
"custom",
"Token",
"objects",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/lang/DRL6Lexer.java#L99-L106
|
14,078
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/reteoo/compiled/ObjectTypeNodeCompiler.java
|
ObjectTypeNodeCompiler.createClassDeclaration
|
private void createClassDeclaration() {
builder.append("package ").append(PACKAGE_NAME).append(";").append(NEWLINE);
builder.append("public class ").append(generatedClassSimpleName).append(" extends ").
append(CompiledNetwork.class.getName()).append("{ ").append(NEWLINE);
builder.append("org.drools.core.spi.InternalReadAccessor readAccessor;\n");
}
|
java
|
private void createClassDeclaration() {
builder.append("package ").append(PACKAGE_NAME).append(";").append(NEWLINE);
builder.append("public class ").append(generatedClassSimpleName).append(" extends ").
append(CompiledNetwork.class.getName()).append("{ ").append(NEWLINE);
builder.append("org.drools.core.spi.InternalReadAccessor readAccessor;\n");
}
|
[
"private",
"void",
"createClassDeclaration",
"(",
")",
"{",
"builder",
".",
"append",
"(",
"\"package \"",
")",
".",
"append",
"(",
"PACKAGE_NAME",
")",
".",
"append",
"(",
"\";\"",
")",
".",
"append",
"(",
"NEWLINE",
")",
";",
"builder",
".",
"append",
"(",
"\"public class \"",
")",
".",
"append",
"(",
"generatedClassSimpleName",
")",
".",
"append",
"(",
"\" extends \"",
")",
".",
"append",
"(",
"CompiledNetwork",
".",
"class",
".",
"getName",
"(",
")",
")",
".",
"append",
"(",
"\"{ \"",
")",
".",
"append",
"(",
"NEWLINE",
")",
";",
"builder",
".",
"append",
"(",
"\"org.drools.core.spi.InternalReadAccessor readAccessor;\\n\"",
")",
";",
"}"
] |
This method will output the package statement, followed by the opening of the class declaration
|
[
"This",
"method",
"will",
"output",
"the",
"package",
"statement",
"followed",
"by",
"the",
"opening",
"of",
"the",
"class",
"declaration"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/reteoo/compiled/ObjectTypeNodeCompiler.java#L137-L143
|
14,079
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/reteoo/compiled/ObjectTypeNodeCompiler.java
|
ObjectTypeNodeCompiler.createConstructor
|
private void createConstructor(Collection<HashedAlphasDeclaration> hashedAlphaDeclarations) {
builder.append("public ").append(generatedClassSimpleName).append("(org.drools.core.spi.InternalReadAccessor readAccessor) {").append(NEWLINE);
builder.append("this.readAccessor = readAccessor;\n");
// for each hashed alpha, we need to fill in the map member variable with the hashed values to node Ids
for (HashedAlphasDeclaration declaration : hashedAlphaDeclarations) {
String mapVariableName = declaration.getVariableName();
for (Object hashedValue : declaration.getHashedValues()) {
Object value = hashedValue;
if (value == null) {
// generate the map.put(hashedValue, nodeId) call
String nodeId = declaration.getNodeId(hashedValue);
builder.append(mapVariableName).append(".put(null,").append(nodeId).append(");");
builder.append(NEWLINE);
} else {
// need to quote value if it is a string
if (value.getClass().equals(String.class)) {
value = "\"" + value + "\"";
} else if (value instanceof BigDecimal) {
value = "new java.math.BigDecimal(\"" + value + "\")";
} else if (value instanceof BigInteger) {
value = "new java.math.BigInteger(\"" + value + "\")";
}
String nodeId = declaration.getNodeId(hashedValue);
// generate the map.put(hashedValue, nodeId) call
builder.append(mapVariableName).append(".put(").append(value).append(", ").append(nodeId).append(");");
builder.append(NEWLINE);
}
}
}
builder.append("}").append(NEWLINE);
}
|
java
|
private void createConstructor(Collection<HashedAlphasDeclaration> hashedAlphaDeclarations) {
builder.append("public ").append(generatedClassSimpleName).append("(org.drools.core.spi.InternalReadAccessor readAccessor) {").append(NEWLINE);
builder.append("this.readAccessor = readAccessor;\n");
// for each hashed alpha, we need to fill in the map member variable with the hashed values to node Ids
for (HashedAlphasDeclaration declaration : hashedAlphaDeclarations) {
String mapVariableName = declaration.getVariableName();
for (Object hashedValue : declaration.getHashedValues()) {
Object value = hashedValue;
if (value == null) {
// generate the map.put(hashedValue, nodeId) call
String nodeId = declaration.getNodeId(hashedValue);
builder.append(mapVariableName).append(".put(null,").append(nodeId).append(");");
builder.append(NEWLINE);
} else {
// need to quote value if it is a string
if (value.getClass().equals(String.class)) {
value = "\"" + value + "\"";
} else if (value instanceof BigDecimal) {
value = "new java.math.BigDecimal(\"" + value + "\")";
} else if (value instanceof BigInteger) {
value = "new java.math.BigInteger(\"" + value + "\")";
}
String nodeId = declaration.getNodeId(hashedValue);
// generate the map.put(hashedValue, nodeId) call
builder.append(mapVariableName).append(".put(").append(value).append(", ").append(nodeId).append(");");
builder.append(NEWLINE);
}
}
}
builder.append("}").append(NEWLINE);
}
|
[
"private",
"void",
"createConstructor",
"(",
"Collection",
"<",
"HashedAlphasDeclaration",
">",
"hashedAlphaDeclarations",
")",
"{",
"builder",
".",
"append",
"(",
"\"public \"",
")",
".",
"append",
"(",
"generatedClassSimpleName",
")",
".",
"append",
"(",
"\"(org.drools.core.spi.InternalReadAccessor readAccessor) {\"",
")",
".",
"append",
"(",
"NEWLINE",
")",
";",
"builder",
".",
"append",
"(",
"\"this.readAccessor = readAccessor;\\n\"",
")",
";",
"// for each hashed alpha, we need to fill in the map member variable with the hashed values to node Ids",
"for",
"(",
"HashedAlphasDeclaration",
"declaration",
":",
"hashedAlphaDeclarations",
")",
"{",
"String",
"mapVariableName",
"=",
"declaration",
".",
"getVariableName",
"(",
")",
";",
"for",
"(",
"Object",
"hashedValue",
":",
"declaration",
".",
"getHashedValues",
"(",
")",
")",
"{",
"Object",
"value",
"=",
"hashedValue",
";",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"// generate the map.put(hashedValue, nodeId) call",
"String",
"nodeId",
"=",
"declaration",
".",
"getNodeId",
"(",
"hashedValue",
")",
";",
"builder",
".",
"append",
"(",
"mapVariableName",
")",
".",
"append",
"(",
"\".put(null,\"",
")",
".",
"append",
"(",
"nodeId",
")",
".",
"append",
"(",
"\");\"",
")",
";",
"builder",
".",
"append",
"(",
"NEWLINE",
")",
";",
"}",
"else",
"{",
"// need to quote value if it is a string",
"if",
"(",
"value",
".",
"getClass",
"(",
")",
".",
"equals",
"(",
"String",
".",
"class",
")",
")",
"{",
"value",
"=",
"\"\\\"\"",
"+",
"value",
"+",
"\"\\\"\"",
";",
"}",
"else",
"if",
"(",
"value",
"instanceof",
"BigDecimal",
")",
"{",
"value",
"=",
"\"new java.math.BigDecimal(\\\"\"",
"+",
"value",
"+",
"\"\\\")\"",
";",
"}",
"else",
"if",
"(",
"value",
"instanceof",
"BigInteger",
")",
"{",
"value",
"=",
"\"new java.math.BigInteger(\\\"\"",
"+",
"value",
"+",
"\"\\\")\"",
";",
"}",
"String",
"nodeId",
"=",
"declaration",
".",
"getNodeId",
"(",
"hashedValue",
")",
";",
"// generate the map.put(hashedValue, nodeId) call",
"builder",
".",
"append",
"(",
"mapVariableName",
")",
".",
"append",
"(",
"\".put(\"",
")",
".",
"append",
"(",
"value",
")",
".",
"append",
"(",
"\", \"",
")",
".",
"append",
"(",
"nodeId",
")",
".",
"append",
"(",
"\");\"",
")",
";",
"builder",
".",
"append",
"(",
"NEWLINE",
")",
";",
"}",
"}",
"}",
"builder",
".",
"append",
"(",
"\"}\"",
")",
".",
"append",
"(",
"NEWLINE",
")",
";",
"}"
] |
Creates the constructor for the generated class. If the hashedAlphaDeclarations is empty, it will just
output a empty default constructor; if it is not, the constructor will contain code to fill the hash
alpha maps with the values and node ids.
@param hashedAlphaDeclarations declarations used for creating statements to populate the hashed alpha
maps for the generate class
|
[
"Creates",
"the",
"constructor",
"for",
"the",
"generated",
"class",
".",
"If",
"the",
"hashedAlphaDeclarations",
"is",
"empty",
"it",
"will",
"just",
"output",
"a",
"empty",
"default",
"constructor",
";",
"if",
"it",
"is",
"not",
"the",
"constructor",
"will",
"contain",
"code",
"to",
"fill",
"the",
"hash",
"alpha",
"maps",
"with",
"the",
"values",
"and",
"node",
"ids",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/reteoo/compiled/ObjectTypeNodeCompiler.java#L153-L192
|
14,080
|
kiegroup/drools
|
drools-workbench-models/drools-workbench-models-datamodel-api/src/main/java/org/drools/workbench/models/datamodel/auditlog/DefaultAuditLogFilter.java
|
DefaultAuditLogFilter.accept
|
@Override
public boolean accept( final AuditLogEntry entry ) {
if ( !acceptedTypes.containsKey( entry.getGenericType() ) ) {
return false;
}
return acceptedTypes.get( entry.getGenericType() );
}
|
java
|
@Override
public boolean accept( final AuditLogEntry entry ) {
if ( !acceptedTypes.containsKey( entry.getGenericType() ) ) {
return false;
}
return acceptedTypes.get( entry.getGenericType() );
}
|
[
"@",
"Override",
"public",
"boolean",
"accept",
"(",
"final",
"AuditLogEntry",
"entry",
")",
"{",
"if",
"(",
"!",
"acceptedTypes",
".",
"containsKey",
"(",
"entry",
".",
"getGenericType",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"acceptedTypes",
".",
"get",
"(",
"entry",
".",
"getGenericType",
"(",
")",
")",
";",
"}"
] |
This is the filtering method. When an AuditLogEntry is added to an
AuditLog the AuditLog calls this method to determine whether the
AuditLogEntry should be added.
@param entry
@return true if the AuditLogEntry should be added to the AuditLog
|
[
"This",
"is",
"the",
"filtering",
"method",
".",
"When",
"an",
"AuditLogEntry",
"is",
"added",
"to",
"an",
"AuditLog",
"the",
"AuditLog",
"calls",
"this",
"method",
"to",
"determine",
"whether",
"the",
"AuditLogEntry",
"should",
"be",
"added",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-workbench-models/drools-workbench-models-datamodel-api/src/main/java/org/drools/workbench/models/datamodel/auditlog/DefaultAuditLogFilter.java#L47-L53
|
14,081
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/base/mvel/MVELDebugHandler.java
|
MVELDebugHandler.onBreak
|
private final static int onBreak(Frame frame) {
// We always fall back to Debugger.CONTINUE after each onBreak to avoid eternal step-over flag
//int oldReturn = onBreakReturn;
//onBreakReturn = Debugger.CONTINUE;
//return oldReturn;
if (verbose) {
logger.info("Continuing with "+(onBreakReturn==Debugger.CONTINUE?"continue":"step-over"));
}
return onBreakReturn;
}
|
java
|
private final static int onBreak(Frame frame) {
// We always fall back to Debugger.CONTINUE after each onBreak to avoid eternal step-over flag
//int oldReturn = onBreakReturn;
//onBreakReturn = Debugger.CONTINUE;
//return oldReturn;
if (verbose) {
logger.info("Continuing with "+(onBreakReturn==Debugger.CONTINUE?"continue":"step-over"));
}
return onBreakReturn;
}
|
[
"private",
"final",
"static",
"int",
"onBreak",
"(",
"Frame",
"frame",
")",
"{",
"// We always fall back to Debugger.CONTINUE after each onBreak to avoid eternal step-over flag",
"//int oldReturn = onBreakReturn;",
"//onBreakReturn = Debugger.CONTINUE;",
"//return oldReturn;",
"if",
"(",
"verbose",
")",
"{",
"logger",
".",
"info",
"(",
"\"Continuing with \"",
"+",
"(",
"onBreakReturn",
"==",
"Debugger",
".",
"CONTINUE",
"?",
"\"continue\"",
":",
"\"step-over\"",
")",
")",
";",
"}",
"return",
"onBreakReturn",
";",
"}"
] |
This is catched by the remote debugger
@param frame
|
[
"This",
"is",
"catched",
"by",
"the",
"remote",
"debugger"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/base/mvel/MVELDebugHandler.java#L55-L64
|
14,082
|
kiegroup/drools
|
drools-workbench-models/drools-workbench-models-datamodel-api/src/main/java/org/drools/workbench/models/datamodel/rule/FactPattern.java
|
FactPattern.addConstraint
|
public void addConstraint( final FieldConstraint constraint ) {
if ( constraintList == null ) {
constraintList = new CompositeFieldConstraint();
}
this.constraintList.addConstraint( constraint );
}
|
java
|
public void addConstraint( final FieldConstraint constraint ) {
if ( constraintList == null ) {
constraintList = new CompositeFieldConstraint();
}
this.constraintList.addConstraint( constraint );
}
|
[
"public",
"void",
"addConstraint",
"(",
"final",
"FieldConstraint",
"constraint",
")",
"{",
"if",
"(",
"constraintList",
"==",
"null",
")",
"{",
"constraintList",
"=",
"new",
"CompositeFieldConstraint",
"(",
")",
";",
"}",
"this",
".",
"constraintList",
".",
"addConstraint",
"(",
"constraint",
")",
";",
"}"
] |
This will add a top level constraint.
|
[
"This",
"will",
"add",
"a",
"top",
"level",
"constraint",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-workbench-models/drools-workbench-models-datamodel-api/src/main/java/org/drools/workbench/models/datamodel/rule/FactPattern.java#L66-L71
|
14,083
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/builder/impl/TypeDeclarationFactory.java
|
TypeDeclarationFactory.mergeTypeDeclarations
|
protected void mergeTypeDeclarations(TypeDeclaration oldDeclaration,
TypeDeclaration newDeclaration) {
if (oldDeclaration == null) {
return;
}
//add the missing fields (if any) to newDeclaration
for (FieldDefinition oldFactField : oldDeclaration.getTypeClassDef().getFieldsDefinitions()) {
FieldDefinition newFactField = newDeclaration.getTypeClassDef().getField(oldFactField.getName());
if (newFactField == null) {
newDeclaration.getTypeClassDef().addField(oldFactField);
}
}
//copy the defined class
newDeclaration.setTypeClass( oldDeclaration.getTypeClass() );
}
|
java
|
protected void mergeTypeDeclarations(TypeDeclaration oldDeclaration,
TypeDeclaration newDeclaration) {
if (oldDeclaration == null) {
return;
}
//add the missing fields (if any) to newDeclaration
for (FieldDefinition oldFactField : oldDeclaration.getTypeClassDef().getFieldsDefinitions()) {
FieldDefinition newFactField = newDeclaration.getTypeClassDef().getField(oldFactField.getName());
if (newFactField == null) {
newDeclaration.getTypeClassDef().addField(oldFactField);
}
}
//copy the defined class
newDeclaration.setTypeClass( oldDeclaration.getTypeClass() );
}
|
[
"protected",
"void",
"mergeTypeDeclarations",
"(",
"TypeDeclaration",
"oldDeclaration",
",",
"TypeDeclaration",
"newDeclaration",
")",
"{",
"if",
"(",
"oldDeclaration",
"==",
"null",
")",
"{",
"return",
";",
"}",
"//add the missing fields (if any) to newDeclaration",
"for",
"(",
"FieldDefinition",
"oldFactField",
":",
"oldDeclaration",
".",
"getTypeClassDef",
"(",
")",
".",
"getFieldsDefinitions",
"(",
")",
")",
"{",
"FieldDefinition",
"newFactField",
"=",
"newDeclaration",
".",
"getTypeClassDef",
"(",
")",
".",
"getField",
"(",
"oldFactField",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"newFactField",
"==",
"null",
")",
"{",
"newDeclaration",
".",
"getTypeClassDef",
"(",
")",
".",
"addField",
"(",
"oldFactField",
")",
";",
"}",
"}",
"//copy the defined class",
"newDeclaration",
".",
"setTypeClass",
"(",
"oldDeclaration",
".",
"getTypeClass",
"(",
")",
")",
";",
"}"
] |
Merges all the missing FactFields from oldDefinition into newDeclaration.
|
[
"Merges",
"all",
"the",
"missing",
"FactFields",
"from",
"oldDefinition",
"into",
"newDeclaration",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/builder/impl/TypeDeclarationFactory.java#L191-L207
|
14,084
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java
|
KnowledgeBaseImpl.populateGlobalsMap
|
private void populateGlobalsMap(Map<String, String> globs) throws ClassNotFoundException {
this.globals = new HashMap<String, Class<?>>();
for (Map.Entry<String, String> entry : globs.entrySet()) {
addGlobal( entry.getKey(),
this.rootClassLoader.loadClass( entry.getValue() ) );
}
}
|
java
|
private void populateGlobalsMap(Map<String, String> globs) throws ClassNotFoundException {
this.globals = new HashMap<String, Class<?>>();
for (Map.Entry<String, String> entry : globs.entrySet()) {
addGlobal( entry.getKey(),
this.rootClassLoader.loadClass( entry.getValue() ) );
}
}
|
[
"private",
"void",
"populateGlobalsMap",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"globs",
")",
"throws",
"ClassNotFoundException",
"{",
"this",
".",
"globals",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Class",
"<",
"?",
">",
">",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"globs",
".",
"entrySet",
"(",
")",
")",
"{",
"addGlobal",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"this",
".",
"rootClassLoader",
".",
"loadClass",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}"
] |
globals class types must be re-wired after serialization
@throws ClassNotFoundException
|
[
"globals",
"class",
"types",
"must",
"be",
"re",
"-",
"wired",
"after",
"serialization"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java#L588-L594
|
14,085
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java
|
KnowledgeBaseImpl.populateTypeDeclarationMaps
|
private void populateTypeDeclarationMaps() throws ClassNotFoundException {
for (InternalKnowledgePackage pkg : this.pkgs.values()) {
for (TypeDeclaration type : pkg.getTypeDeclarations().values()) {
type.setTypeClass(this.rootClassLoader.loadClass(type.getTypeClassName()));
this.classTypeDeclaration.put(type.getTypeClassName(),
type);
}
}
}
|
java
|
private void populateTypeDeclarationMaps() throws ClassNotFoundException {
for (InternalKnowledgePackage pkg : this.pkgs.values()) {
for (TypeDeclaration type : pkg.getTypeDeclarations().values()) {
type.setTypeClass(this.rootClassLoader.loadClass(type.getTypeClassName()));
this.classTypeDeclaration.put(type.getTypeClassName(),
type);
}
}
}
|
[
"private",
"void",
"populateTypeDeclarationMaps",
"(",
")",
"throws",
"ClassNotFoundException",
"{",
"for",
"(",
"InternalKnowledgePackage",
"pkg",
":",
"this",
".",
"pkgs",
".",
"values",
"(",
")",
")",
"{",
"for",
"(",
"TypeDeclaration",
"type",
":",
"pkg",
".",
"getTypeDeclarations",
"(",
")",
".",
"values",
"(",
")",
")",
"{",
"type",
".",
"setTypeClass",
"(",
"this",
".",
"rootClassLoader",
".",
"loadClass",
"(",
"type",
".",
"getTypeClassName",
"(",
")",
")",
")",
";",
"this",
".",
"classTypeDeclaration",
".",
"put",
"(",
"type",
".",
"getTypeClassName",
"(",
")",
",",
"type",
")",
";",
"}",
"}",
"}"
] |
type classes must be re-wired after serialization
@throws ClassNotFoundException
|
[
"type",
"classes",
"must",
"be",
"re",
"-",
"wired",
"after",
"serialization"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java#L601-L609
|
14,086
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/rule/JavaDialectRuntimeData.java
|
JavaDialectRuntimeData.reload
|
public void reload() {
// drops the classLoader and adds a new one
this.classLoader = makeClassLoader();
// Wire up invokers
try {
for (Entry<String, Wireable> entry : invokerLookups.entrySet()) {
wire( classLoader, entry.getKey(), entry.getValue(), true );
}
} catch (final ClassNotFoundException e) {
throw new RuntimeException( e );
} catch (final InstantiationError e) {
throw new RuntimeException( e );
} catch (final IllegalAccessException e) {
throw new RuntimeException( e );
} catch (final InstantiationException e) {
throw new RuntimeException( e );
}
this.dirty = false;
}
|
java
|
public void reload() {
// drops the classLoader and adds a new one
this.classLoader = makeClassLoader();
// Wire up invokers
try {
for (Entry<String, Wireable> entry : invokerLookups.entrySet()) {
wire( classLoader, entry.getKey(), entry.getValue(), true );
}
} catch (final ClassNotFoundException e) {
throw new RuntimeException( e );
} catch (final InstantiationError e) {
throw new RuntimeException( e );
} catch (final IllegalAccessException e) {
throw new RuntimeException( e );
} catch (final InstantiationException e) {
throw new RuntimeException( e );
}
this.dirty = false;
}
|
[
"public",
"void",
"reload",
"(",
")",
"{",
"// drops the classLoader and adds a new one",
"this",
".",
"classLoader",
"=",
"makeClassLoader",
"(",
")",
";",
"// Wire up invokers",
"try",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"Wireable",
">",
"entry",
":",
"invokerLookups",
".",
"entrySet",
"(",
")",
")",
"{",
"wire",
"(",
"classLoader",
",",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"catch",
"(",
"final",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"final",
"InstantiationError",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"final",
"IllegalAccessException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"final",
"InstantiationException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"this",
".",
"dirty",
"=",
"false",
";",
"}"
] |
This class drops the classLoader and reloads it. During this process it must re-wire all the invokeables.
|
[
"This",
"class",
"drops",
"the",
"classLoader",
"and",
"reloads",
"it",
".",
"During",
"this",
"process",
"it",
"must",
"re",
"-",
"wire",
"all",
"the",
"invokeables",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/rule/JavaDialectRuntimeData.java#L482-L502
|
14,087
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java
|
StatefulKnowledgeSessionImpl.fireUntilHalt
|
public void fireUntilHalt(final AgendaFilter agendaFilter) {
if ( isSequential() ) {
throw new IllegalStateException( "fireUntilHalt() can not be called in sequential mode." );
}
try {
startOperation();
agenda.fireUntilHalt( agendaFilter );
} finally {
endOperation();
}
}
|
java
|
public void fireUntilHalt(final AgendaFilter agendaFilter) {
if ( isSequential() ) {
throw new IllegalStateException( "fireUntilHalt() can not be called in sequential mode." );
}
try {
startOperation();
agenda.fireUntilHalt( agendaFilter );
} finally {
endOperation();
}
}
|
[
"public",
"void",
"fireUntilHalt",
"(",
"final",
"AgendaFilter",
"agendaFilter",
")",
"{",
"if",
"(",
"isSequential",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"fireUntilHalt() can not be called in sequential mode.\"",
")",
";",
"}",
"try",
"{",
"startOperation",
"(",
")",
";",
"agenda",
".",
"fireUntilHalt",
"(",
"agendaFilter",
")",
";",
"}",
"finally",
"{",
"endOperation",
"(",
")",
";",
"}",
"}"
] |
Keeps firing activations until a halt is called. If in a given moment,
there is no activation to fire, it will wait for an activation to be
added to an active agenda group or rule flow group.
@param agendaFilter
filters the activations that may fire
@throws IllegalStateException
if this method is called when running in sequential mode
|
[
"Keeps",
"firing",
"activations",
"until",
"a",
"halt",
"is",
"called",
".",
"If",
"in",
"a",
"given",
"moment",
"there",
"is",
"no",
"activation",
"to",
"fire",
"it",
"will",
"wait",
"for",
"an",
"activation",
"to",
"be",
"added",
"to",
"an",
"active",
"agenda",
"group",
"or",
"rule",
"flow",
"group",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java#L1362-L1373
|
14,088
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java
|
StatefulKnowledgeSessionImpl.endOperation
|
public void endOperation() {
if (this.opCounter.decrementAndGet() == 0) {
// means the engine is idle, so, set the timestamp
this.lastIdleTimestamp.set(this.timerService.getCurrentTime());
if (this.endOperationListener != null) {
this.endOperationListener.endOperation(this.getKnowledgeRuntime());
}
}
}
|
java
|
public void endOperation() {
if (this.opCounter.decrementAndGet() == 0) {
// means the engine is idle, so, set the timestamp
this.lastIdleTimestamp.set(this.timerService.getCurrentTime());
if (this.endOperationListener != null) {
this.endOperationListener.endOperation(this.getKnowledgeRuntime());
}
}
}
|
[
"public",
"void",
"endOperation",
"(",
")",
"{",
"if",
"(",
"this",
".",
"opCounter",
".",
"decrementAndGet",
"(",
")",
"==",
"0",
")",
"{",
"// means the engine is idle, so, set the timestamp",
"this",
".",
"lastIdleTimestamp",
".",
"set",
"(",
"this",
".",
"timerService",
".",
"getCurrentTime",
"(",
")",
")",
";",
"if",
"(",
"this",
".",
"endOperationListener",
"!=",
"null",
")",
"{",
"this",
".",
"endOperationListener",
".",
"endOperation",
"(",
"this",
".",
"getKnowledgeRuntime",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
This method must be called after finishing any work in the engine,
like inserting a new fact or firing a new rule. It will reset the engine
idle time counter.
This method must be extremely light to avoid contentions when called by
multiple threads/entry-points
|
[
"This",
"method",
"must",
"be",
"called",
"after",
"finishing",
"any",
"work",
"in",
"the",
"engine",
"like",
"inserting",
"a",
"new",
"fact",
"or",
"firing",
"a",
"new",
"rule",
".",
"It",
"will",
"reset",
"the",
"engine",
"idle",
"time",
"counter",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java#L2021-L2029
|
14,089
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/rule/impl/RuleImpl.java
|
RuleImpl.isEffective
|
public boolean isEffective(Tuple tuple,
RuleTerminalNode rtn,
WorkingMemory workingMemory) {
if ( !this.enabled.getValue( tuple,
rtn.getEnabledDeclarations(),
this,
workingMemory ) ) {
return false;
}
if ( this.dateEffective == null && this.dateExpires == null ) {
return true;
} else {
Calendar now = Calendar.getInstance();
now.setTimeInMillis( workingMemory.getSessionClock().getCurrentTime() );
if ( this.dateEffective != null && this.dateExpires != null ) {
return (now.after( this.dateEffective ) && now.before( this.dateExpires ));
} else if ( this.dateEffective != null ) {
return (now.after( this.dateEffective ));
} else {
return (now.before( this.dateExpires ));
}
}
}
|
java
|
public boolean isEffective(Tuple tuple,
RuleTerminalNode rtn,
WorkingMemory workingMemory) {
if ( !this.enabled.getValue( tuple,
rtn.getEnabledDeclarations(),
this,
workingMemory ) ) {
return false;
}
if ( this.dateEffective == null && this.dateExpires == null ) {
return true;
} else {
Calendar now = Calendar.getInstance();
now.setTimeInMillis( workingMemory.getSessionClock().getCurrentTime() );
if ( this.dateEffective != null && this.dateExpires != null ) {
return (now.after( this.dateEffective ) && now.before( this.dateExpires ));
} else if ( this.dateEffective != null ) {
return (now.after( this.dateEffective ));
} else {
return (now.before( this.dateExpires ));
}
}
}
|
[
"public",
"boolean",
"isEffective",
"(",
"Tuple",
"tuple",
",",
"RuleTerminalNode",
"rtn",
",",
"WorkingMemory",
"workingMemory",
")",
"{",
"if",
"(",
"!",
"this",
".",
"enabled",
".",
"getValue",
"(",
"tuple",
",",
"rtn",
".",
"getEnabledDeclarations",
"(",
")",
",",
"this",
",",
"workingMemory",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"this",
".",
"dateEffective",
"==",
"null",
"&&",
"this",
".",
"dateExpires",
"==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"Calendar",
"now",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
";",
"now",
".",
"setTimeInMillis",
"(",
"workingMemory",
".",
"getSessionClock",
"(",
")",
".",
"getCurrentTime",
"(",
")",
")",
";",
"if",
"(",
"this",
".",
"dateEffective",
"!=",
"null",
"&&",
"this",
".",
"dateExpires",
"!=",
"null",
")",
"{",
"return",
"(",
"now",
".",
"after",
"(",
"this",
".",
"dateEffective",
")",
"&&",
"now",
".",
"before",
"(",
"this",
".",
"dateExpires",
")",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"dateEffective",
"!=",
"null",
")",
"{",
"return",
"(",
"now",
".",
"after",
"(",
"this",
".",
"dateEffective",
")",
")",
";",
"}",
"else",
"{",
"return",
"(",
"now",
".",
"before",
"(",
"this",
".",
"dateExpires",
")",
")",
";",
"}",
"}",
"}"
] |
This returns true is the rule is effective.
If the rule is not effective, it cannot activate.
This uses the dateEffective, dateExpires and enabled flag to decide this.
|
[
"This",
"returns",
"true",
"is",
"the",
"rule",
"is",
"effective",
".",
"If",
"the",
"rule",
"is",
"not",
"effective",
"it",
"cannot",
"activate",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/rule/impl/RuleImpl.java#L419-L442
|
14,090
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/definitions/rule/impl/RuleImpl.java
|
RuleImpl.getTransformedLhs
|
public GroupElement[] getTransformedLhs( LogicTransformer transformer, Map<String, Class<?>> globals ) throws InvalidPatternException {
//Moved to getExtendedLhs --final GroupElement cloned = (GroupElement) this.lhsRoot.clone();
return transformer.transform( getExtendedLhs( this,
null ),
globals );
}
|
java
|
public GroupElement[] getTransformedLhs( LogicTransformer transformer, Map<String, Class<?>> globals ) throws InvalidPatternException {
//Moved to getExtendedLhs --final GroupElement cloned = (GroupElement) this.lhsRoot.clone();
return transformer.transform( getExtendedLhs( this,
null ),
globals );
}
|
[
"public",
"GroupElement",
"[",
"]",
"getTransformedLhs",
"(",
"LogicTransformer",
"transformer",
",",
"Map",
"<",
"String",
",",
"Class",
"<",
"?",
">",
">",
"globals",
")",
"throws",
"InvalidPatternException",
"{",
"//Moved to getExtendedLhs --final GroupElement cloned = (GroupElement) this.lhsRoot.clone();",
"return",
"transformer",
".",
"transform",
"(",
"getExtendedLhs",
"(",
"this",
",",
"null",
")",
",",
"globals",
")",
";",
"}"
] |
Uses the LogicTransformer to process the Rule patters - if no ORs are
used this will return an array of a single AND element. If there are Ors
it will return an And element for each possible logic branch. The
processing uses as a clone of the Rule's patterns, so they are not
changed.
@return
@throws org.drools.core.rule.InvalidPatternException
|
[
"Uses",
"the",
"LogicTransformer",
"to",
"process",
"the",
"Rule",
"patters",
"-",
"if",
"no",
"ORs",
"are",
"used",
"this",
"will",
"return",
"an",
"array",
"of",
"a",
"single",
"AND",
"element",
".",
"If",
"there",
"are",
"Ors",
"it",
"will",
"return",
"an",
"And",
"element",
"for",
"each",
"possible",
"logic",
"branch",
".",
"The",
"processing",
"uses",
"as",
"a",
"clone",
"of",
"the",
"Rule",
"s",
"patterns",
"so",
"they",
"are",
"not",
"changed",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/definitions/rule/impl/RuleImpl.java#L596-L601
|
14,091
|
kiegroup/drools
|
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/FEELParser.java
|
FEELParser.isVariableNamePartValid
|
public static boolean isVariableNamePartValid( String namePart, Scope scope ) {
if ( DIGITS_PATTERN.matcher(namePart).matches() ) {
return true;
}
if ( REUSABLE_KEYWORDS.contains(namePart) ) {
return scope.followUp(namePart, true);
}
return isVariableNameValid(namePart);
}
|
java
|
public static boolean isVariableNamePartValid( String namePart, Scope scope ) {
if ( DIGITS_PATTERN.matcher(namePart).matches() ) {
return true;
}
if ( REUSABLE_KEYWORDS.contains(namePart) ) {
return scope.followUp(namePart, true);
}
return isVariableNameValid(namePart);
}
|
[
"public",
"static",
"boolean",
"isVariableNamePartValid",
"(",
"String",
"namePart",
",",
"Scope",
"scope",
")",
"{",
"if",
"(",
"DIGITS_PATTERN",
".",
"matcher",
"(",
"namePart",
")",
".",
"matches",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"REUSABLE_KEYWORDS",
".",
"contains",
"(",
"namePart",
")",
")",
"{",
"return",
"scope",
".",
"followUp",
"(",
"namePart",
",",
"true",
")",
";",
"}",
"return",
"isVariableNameValid",
"(",
"namePart",
")",
";",
"}"
] |
Either namePart is a string of digits, or it must be a valid name itself
|
[
"Either",
"namePart",
"is",
"a",
"string",
"of",
"digits",
"or",
"it",
"must",
"be",
"a",
"valid",
"name",
"itself"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/FEELParser.java#L82-L90
|
14,092
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/rule/ImportDeclaration.java
|
ImportDeclaration.matches
|
public boolean matches( Class<?> clazz ) {
// fully qualified import?
if( this.target.equals( clazz.getName() ) ) {
return true;
}
// wild card imports
if( this.target.endsWith( ".*" ) ) {
String prefix = this.target.substring( 0, this.target.indexOf( ".*" ) );
// package import: import my.package.*
if( prefix.equals( clazz.getPackage().getName() ) ) {
return true;
}
// inner class imports with wild card?
// by looking at the ClassTypeResolver class, it seems we do not support
// the usage of wild cards when importing static inner classes like the
// java static imports allow
}
return false;
}
|
java
|
public boolean matches( Class<?> clazz ) {
// fully qualified import?
if( this.target.equals( clazz.getName() ) ) {
return true;
}
// wild card imports
if( this.target.endsWith( ".*" ) ) {
String prefix = this.target.substring( 0, this.target.indexOf( ".*" ) );
// package import: import my.package.*
if( prefix.equals( clazz.getPackage().getName() ) ) {
return true;
}
// inner class imports with wild card?
// by looking at the ClassTypeResolver class, it seems we do not support
// the usage of wild cards when importing static inner classes like the
// java static imports allow
}
return false;
}
|
[
"public",
"boolean",
"matches",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"// fully qualified import?",
"if",
"(",
"this",
".",
"target",
".",
"equals",
"(",
"clazz",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"// wild card imports",
"if",
"(",
"this",
".",
"target",
".",
"endsWith",
"(",
"\".*\"",
")",
")",
"{",
"String",
"prefix",
"=",
"this",
".",
"target",
".",
"substring",
"(",
"0",
",",
"this",
".",
"target",
".",
"indexOf",
"(",
"\".*\"",
")",
")",
";",
"// package import: import my.package.*",
"if",
"(",
"prefix",
".",
"equals",
"(",
"clazz",
".",
"getPackage",
"(",
")",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"// inner class imports with wild card?",
"// by looking at the ClassTypeResolver class, it seems we do not support",
"// the usage of wild cards when importing static inner classes like the",
"// java static imports allow",
"}",
"return",
"false",
";",
"}"
] |
Returns true if this ImportDeclaration correctly matches to
the given clazz
@param name
@return
|
[
"Returns",
"true",
"if",
"this",
"ImportDeclaration",
"correctly",
"matches",
"to",
"the",
"given",
"clazz"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/rule/ImportDeclaration.java#L90-L111
|
14,093
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufInputMarshaller.java
|
ProtobufInputMarshaller.readSession
|
public static StatefulKnowledgeSessionImpl readSession(StatefulKnowledgeSessionImpl session,
MarshallerReaderContext context) throws IOException,
ClassNotFoundException {
ProtobufMessages.KnowledgeSession _session = loadAndParseSession( context );
InternalAgenda agenda = resetSession( session,
context,
_session );
readSession( _session,
session,
agenda,
context );
return session;
}
|
java
|
public static StatefulKnowledgeSessionImpl readSession(StatefulKnowledgeSessionImpl session,
MarshallerReaderContext context) throws IOException,
ClassNotFoundException {
ProtobufMessages.KnowledgeSession _session = loadAndParseSession( context );
InternalAgenda agenda = resetSession( session,
context,
_session );
readSession( _session,
session,
agenda,
context );
return session;
}
|
[
"public",
"static",
"StatefulKnowledgeSessionImpl",
"readSession",
"(",
"StatefulKnowledgeSessionImpl",
"session",
",",
"MarshallerReaderContext",
"context",
")",
"throws",
"IOException",
",",
"ClassNotFoundException",
"{",
"ProtobufMessages",
".",
"KnowledgeSession",
"_session",
"=",
"loadAndParseSession",
"(",
"context",
")",
";",
"InternalAgenda",
"agenda",
"=",
"resetSession",
"(",
"session",
",",
"context",
",",
"_session",
")",
";",
"readSession",
"(",
"_session",
",",
"session",
",",
"agenda",
",",
"context",
")",
";",
"return",
"session",
";",
"}"
] |
Stream the data into an existing session
@param session
@param context
@return
@throws IOException
@throws ClassNotFoundException
|
[
"Stream",
"the",
"data",
"into",
"an",
"existing",
"session"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufInputMarshaller.java#L108-L124
|
14,094
|
kiegroup/drools
|
drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufInputMarshaller.java
|
ProtobufInputMarshaller.readSession
|
public static ReadSessionResult readSession(MarshallerReaderContext context,
int id) throws IOException, ClassNotFoundException {
return readSession( context,
id,
EnvironmentFactory.newEnvironment(),
new SessionConfigurationImpl() );
}
|
java
|
public static ReadSessionResult readSession(MarshallerReaderContext context,
int id) throws IOException, ClassNotFoundException {
return readSession( context,
id,
EnvironmentFactory.newEnvironment(),
new SessionConfigurationImpl() );
}
|
[
"public",
"static",
"ReadSessionResult",
"readSession",
"(",
"MarshallerReaderContext",
"context",
",",
"int",
"id",
")",
"throws",
"IOException",
",",
"ClassNotFoundException",
"{",
"return",
"readSession",
"(",
"context",
",",
"id",
",",
"EnvironmentFactory",
".",
"newEnvironment",
"(",
")",
",",
"new",
"SessionConfigurationImpl",
"(",
")",
")",
";",
"}"
] |
Create a new session into which to read the stream data
|
[
"Create",
"a",
"new",
"session",
"into",
"which",
"to",
"read",
"the",
"stream",
"data"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufInputMarshaller.java#L129-L135
|
14,095
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/JavaDialect.java
|
JavaDialect.compileAll
|
public void compileAll() {
if (this.generatedClassList.isEmpty()) {
this.errorHandlers.clear();
return;
}
final String[] classes = new String[this.generatedClassList.size()];
this.generatedClassList.toArray(classes);
File dumpDir = this.configuration.getPackageBuilderConfiguration().getDumpDir();
if (dumpDir != null) {
dumpResources(classes,
dumpDir);
}
final CompilationResult result = this.compiler.compile(classes,
this.src,
this.packageStoreWrapper,
rootClassLoader);
//this will sort out the errors based on what class/file they happened in
if (result.getErrors().length > 0) {
for (int i = 0; i < result.getErrors().length; i++) {
final CompilationProblem err = result.getErrors()[i];
final ErrorHandler handler = this.errorHandlers.get(err.getFileName());
handler.addError(err);
}
final Collection errors = this.errorHandlers.values();
for (Object error : errors) {
final ErrorHandler handler = (ErrorHandler) error;
if (handler.isInError()) {
this.results.add(handler.getError());
}
}
}
// We've compiled everthing, so clear it for the next set of additions
this.generatedClassList.clear();
this.errorHandlers.clear();
}
|
java
|
public void compileAll() {
if (this.generatedClassList.isEmpty()) {
this.errorHandlers.clear();
return;
}
final String[] classes = new String[this.generatedClassList.size()];
this.generatedClassList.toArray(classes);
File dumpDir = this.configuration.getPackageBuilderConfiguration().getDumpDir();
if (dumpDir != null) {
dumpResources(classes,
dumpDir);
}
final CompilationResult result = this.compiler.compile(classes,
this.src,
this.packageStoreWrapper,
rootClassLoader);
//this will sort out the errors based on what class/file they happened in
if (result.getErrors().length > 0) {
for (int i = 0; i < result.getErrors().length; i++) {
final CompilationProblem err = result.getErrors()[i];
final ErrorHandler handler = this.errorHandlers.get(err.getFileName());
handler.addError(err);
}
final Collection errors = this.errorHandlers.values();
for (Object error : errors) {
final ErrorHandler handler = (ErrorHandler) error;
if (handler.isInError()) {
this.results.add(handler.getError());
}
}
}
// We've compiled everthing, so clear it for the next set of additions
this.generatedClassList.clear();
this.errorHandlers.clear();
}
|
[
"public",
"void",
"compileAll",
"(",
")",
"{",
"if",
"(",
"this",
".",
"generatedClassList",
".",
"isEmpty",
"(",
")",
")",
"{",
"this",
".",
"errorHandlers",
".",
"clear",
"(",
")",
";",
"return",
";",
"}",
"final",
"String",
"[",
"]",
"classes",
"=",
"new",
"String",
"[",
"this",
".",
"generatedClassList",
".",
"size",
"(",
")",
"]",
";",
"this",
".",
"generatedClassList",
".",
"toArray",
"(",
"classes",
")",
";",
"File",
"dumpDir",
"=",
"this",
".",
"configuration",
".",
"getPackageBuilderConfiguration",
"(",
")",
".",
"getDumpDir",
"(",
")",
";",
"if",
"(",
"dumpDir",
"!=",
"null",
")",
"{",
"dumpResources",
"(",
"classes",
",",
"dumpDir",
")",
";",
"}",
"final",
"CompilationResult",
"result",
"=",
"this",
".",
"compiler",
".",
"compile",
"(",
"classes",
",",
"this",
".",
"src",
",",
"this",
".",
"packageStoreWrapper",
",",
"rootClassLoader",
")",
";",
"//this will sort out the errors based on what class/file they happened in",
"if",
"(",
"result",
".",
"getErrors",
"(",
")",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"result",
".",
"getErrors",
"(",
")",
".",
"length",
";",
"i",
"++",
")",
"{",
"final",
"CompilationProblem",
"err",
"=",
"result",
".",
"getErrors",
"(",
")",
"[",
"i",
"]",
";",
"final",
"ErrorHandler",
"handler",
"=",
"this",
".",
"errorHandlers",
".",
"get",
"(",
"err",
".",
"getFileName",
"(",
")",
")",
";",
"handler",
".",
"addError",
"(",
"err",
")",
";",
"}",
"final",
"Collection",
"errors",
"=",
"this",
".",
"errorHandlers",
".",
"values",
"(",
")",
";",
"for",
"(",
"Object",
"error",
":",
"errors",
")",
"{",
"final",
"ErrorHandler",
"handler",
"=",
"(",
"ErrorHandler",
")",
"error",
";",
"if",
"(",
"handler",
".",
"isInError",
"(",
")",
")",
"{",
"this",
".",
"results",
".",
"add",
"(",
"handler",
".",
"getError",
"(",
")",
")",
";",
"}",
"}",
"}",
"// We've compiled everthing, so clear it for the next set of additions",
"this",
".",
"generatedClassList",
".",
"clear",
"(",
")",
";",
"this",
".",
"errorHandlers",
".",
"clear",
"(",
")",
";",
"}"
] |
This actually triggers the compiling of all the resources.
Errors are mapped back to the element that originally generated the semantic
code.
|
[
"This",
"actually",
"triggers",
"the",
"compiling",
"of",
"all",
"the",
"resources",
".",
"Errors",
"are",
"mapped",
"back",
"to",
"the",
"element",
"that",
"originally",
"generated",
"the",
"semantic",
"code",
"."
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/JavaDialect.java#L406-L446
|
14,096
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/JavaDialect.java
|
JavaDialect.addRule
|
public void addRule(final RuleBuildContext context) {
final RuleImpl rule = context.getRule();
final RuleDescr ruleDescr = context.getRuleDescr();
RuleClassBuilder classBuilder = context.getDialect().getRuleClassBuilder();
String ruleClass = classBuilder.buildRule(context);
// return if there is no ruleclass name;
if (ruleClass == null) {
return;
}
// The compilation result is for the entire rule, so difficult to associate with any descr
addClassCompileTask(this.pkg.getName() + "." + ruleDescr.getClassName(),
ruleDescr,
ruleClass,
this.src,
new RuleErrorHandler(ruleDescr,
rule,
"Rule Compilation error"));
JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData(ID);
for (Map.Entry<String, String> invokers : context.getInvokers().entrySet()) {
final String className = invokers.getKey();
// Check if an invoker - returnvalue, predicate, eval or consequence has been associated
// If so we add it to the PackageCompilationData as it will get wired up on compilation
final Object invoker = context.getInvokerLookup(className);
if (invoker instanceof Wireable) {
data.putInvoker(className, (Wireable)invoker);
}
final String text = invokers.getValue();
final BaseDescr descr = context.getDescrLookup(className);
addClassCompileTask(className,
descr,
text,
this.src,
new RuleInvokerErrorHandler(descr,
rule,
"Unable to generate rule invoker."));
}
// setup the line mappins for this rule
final String name = this.pkg.getName() + "." + StringUtils.ucFirst(ruleDescr.getClassName());
final LineMappings mapping = new LineMappings(name);
mapping.setStartLine(ruleDescr.getConsequenceLine());
mapping.setOffset(ruleDescr.getConsequenceOffset());
this.pkg.getDialectRuntimeRegistry().getLineMappings().put(name,
mapping);
}
|
java
|
public void addRule(final RuleBuildContext context) {
final RuleImpl rule = context.getRule();
final RuleDescr ruleDescr = context.getRuleDescr();
RuleClassBuilder classBuilder = context.getDialect().getRuleClassBuilder();
String ruleClass = classBuilder.buildRule(context);
// return if there is no ruleclass name;
if (ruleClass == null) {
return;
}
// The compilation result is for the entire rule, so difficult to associate with any descr
addClassCompileTask(this.pkg.getName() + "." + ruleDescr.getClassName(),
ruleDescr,
ruleClass,
this.src,
new RuleErrorHandler(ruleDescr,
rule,
"Rule Compilation error"));
JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData(ID);
for (Map.Entry<String, String> invokers : context.getInvokers().entrySet()) {
final String className = invokers.getKey();
// Check if an invoker - returnvalue, predicate, eval or consequence has been associated
// If so we add it to the PackageCompilationData as it will get wired up on compilation
final Object invoker = context.getInvokerLookup(className);
if (invoker instanceof Wireable) {
data.putInvoker(className, (Wireable)invoker);
}
final String text = invokers.getValue();
final BaseDescr descr = context.getDescrLookup(className);
addClassCompileTask(className,
descr,
text,
this.src,
new RuleInvokerErrorHandler(descr,
rule,
"Unable to generate rule invoker."));
}
// setup the line mappins for this rule
final String name = this.pkg.getName() + "." + StringUtils.ucFirst(ruleDescr.getClassName());
final LineMappings mapping = new LineMappings(name);
mapping.setStartLine(ruleDescr.getConsequenceLine());
mapping.setOffset(ruleDescr.getConsequenceOffset());
this.pkg.getDialectRuntimeRegistry().getLineMappings().put(name,
mapping);
}
|
[
"public",
"void",
"addRule",
"(",
"final",
"RuleBuildContext",
"context",
")",
"{",
"final",
"RuleImpl",
"rule",
"=",
"context",
".",
"getRule",
"(",
")",
";",
"final",
"RuleDescr",
"ruleDescr",
"=",
"context",
".",
"getRuleDescr",
"(",
")",
";",
"RuleClassBuilder",
"classBuilder",
"=",
"context",
".",
"getDialect",
"(",
")",
".",
"getRuleClassBuilder",
"(",
")",
";",
"String",
"ruleClass",
"=",
"classBuilder",
".",
"buildRule",
"(",
"context",
")",
";",
"// return if there is no ruleclass name;",
"if",
"(",
"ruleClass",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// The compilation result is for the entire rule, so difficult to associate with any descr",
"addClassCompileTask",
"(",
"this",
".",
"pkg",
".",
"getName",
"(",
")",
"+",
"\".\"",
"+",
"ruleDescr",
".",
"getClassName",
"(",
")",
",",
"ruleDescr",
",",
"ruleClass",
",",
"this",
".",
"src",
",",
"new",
"RuleErrorHandler",
"(",
"ruleDescr",
",",
"rule",
",",
"\"Rule Compilation error\"",
")",
")",
";",
"JavaDialectRuntimeData",
"data",
"=",
"(",
"JavaDialectRuntimeData",
")",
"this",
".",
"pkg",
".",
"getDialectRuntimeRegistry",
"(",
")",
".",
"getDialectData",
"(",
"ID",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"invokers",
":",
"context",
".",
"getInvokers",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"final",
"String",
"className",
"=",
"invokers",
".",
"getKey",
"(",
")",
";",
"// Check if an invoker - returnvalue, predicate, eval or consequence has been associated",
"// If so we add it to the PackageCompilationData as it will get wired up on compilation",
"final",
"Object",
"invoker",
"=",
"context",
".",
"getInvokerLookup",
"(",
"className",
")",
";",
"if",
"(",
"invoker",
"instanceof",
"Wireable",
")",
"{",
"data",
".",
"putInvoker",
"(",
"className",
",",
"(",
"Wireable",
")",
"invoker",
")",
";",
"}",
"final",
"String",
"text",
"=",
"invokers",
".",
"getValue",
"(",
")",
";",
"final",
"BaseDescr",
"descr",
"=",
"context",
".",
"getDescrLookup",
"(",
"className",
")",
";",
"addClassCompileTask",
"(",
"className",
",",
"descr",
",",
"text",
",",
"this",
".",
"src",
",",
"new",
"RuleInvokerErrorHandler",
"(",
"descr",
",",
"rule",
",",
"\"Unable to generate rule invoker.\"",
")",
")",
";",
"}",
"// setup the line mappins for this rule",
"final",
"String",
"name",
"=",
"this",
".",
"pkg",
".",
"getName",
"(",
")",
"+",
"\".\"",
"+",
"StringUtils",
".",
"ucFirst",
"(",
"ruleDescr",
".",
"getClassName",
"(",
")",
")",
";",
"final",
"LineMappings",
"mapping",
"=",
"new",
"LineMappings",
"(",
"name",
")",
";",
"mapping",
".",
"setStartLine",
"(",
"ruleDescr",
".",
"getConsequenceLine",
"(",
")",
")",
";",
"mapping",
".",
"setOffset",
"(",
"ruleDescr",
".",
"getConsequenceOffset",
"(",
")",
")",
";",
"this",
".",
"pkg",
".",
"getDialectRuntimeRegistry",
"(",
")",
".",
"getLineMappings",
"(",
")",
".",
"put",
"(",
"name",
",",
"mapping",
")",
";",
"}"
] |
This will add the rule for compiling later on.
It will not actually call the compiler
|
[
"This",
"will",
"add",
"the",
"rule",
"for",
"compiling",
"later",
"on",
".",
"It",
"will",
"not",
"actually",
"call",
"the",
"compiler"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/JavaDialect.java#L485-L537
|
14,097
|
kiegroup/drools
|
drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/mvel/MVELEvalBuilder.java
|
MVELEvalBuilder.build
|
public RuleConditionElement build(final RuleBuildContext context,
final BaseDescr descr,
final Pattern prefixPattern) {
boolean typesafe = context.isTypesafe();
// it must be an EvalDescr
final EvalDescr evalDescr = (EvalDescr) descr;
try {
MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );
Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
evalDescr,
evalDescr.getContent(),
new BoundIdentifiers( DeclarationScopeResolver.getDeclarationClasses( decls ),
context ) );
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
int i = usedIdentifiers.getDeclrClasses().keySet().size();
Declaration[] previousDeclarations = new Declaration[i];
i = 0;
for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
previousDeclarations[i++] = decls.get( id );
}
Arrays.sort( previousDeclarations, SortDeclarations.instance );
MVELCompilationUnit unit = dialect.getMVELCompilationUnit( (String) evalDescr.getContent(),
analysis,
previousDeclarations,
null,
null,
context,
"drools",
KnowledgeHelper.class,
false,
MVELCompilationUnit.Scope.EXPRESSION );
final EvalCondition eval = new EvalCondition( previousDeclarations );
MVELEvalExpression expr = new MVELEvalExpression( unit,
dialect.getId() );
eval.setEvalExpression( KiePolicyHelper.isPolicyEnabled() ? new SafeEvalExpression(expr) : expr );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
data.addCompileable( eval,
expr );
expr.compile( data, context.getRule() );
return eval;
} catch ( final Exception e ) {
copyErrorLocation(e, evalDescr);
context.addError( new DescrBuildError( context.getParentDescr(),
evalDescr,
e,
"Unable to build expression for 'eval':" + e.getMessage() + " '" + evalDescr.getContent() + "'" ) );
return null;
} finally {
context.setTypesafe( typesafe );
}
}
|
java
|
public RuleConditionElement build(final RuleBuildContext context,
final BaseDescr descr,
final Pattern prefixPattern) {
boolean typesafe = context.isTypesafe();
// it must be an EvalDescr
final EvalDescr evalDescr = (EvalDescr) descr;
try {
MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );
Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
evalDescr,
evalDescr.getContent(),
new BoundIdentifiers( DeclarationScopeResolver.getDeclarationClasses( decls ),
context ) );
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
int i = usedIdentifiers.getDeclrClasses().keySet().size();
Declaration[] previousDeclarations = new Declaration[i];
i = 0;
for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
previousDeclarations[i++] = decls.get( id );
}
Arrays.sort( previousDeclarations, SortDeclarations.instance );
MVELCompilationUnit unit = dialect.getMVELCompilationUnit( (String) evalDescr.getContent(),
analysis,
previousDeclarations,
null,
null,
context,
"drools",
KnowledgeHelper.class,
false,
MVELCompilationUnit.Scope.EXPRESSION );
final EvalCondition eval = new EvalCondition( previousDeclarations );
MVELEvalExpression expr = new MVELEvalExpression( unit,
dialect.getId() );
eval.setEvalExpression( KiePolicyHelper.isPolicyEnabled() ? new SafeEvalExpression(expr) : expr );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
data.addCompileable( eval,
expr );
expr.compile( data, context.getRule() );
return eval;
} catch ( final Exception e ) {
copyErrorLocation(e, evalDescr);
context.addError( new DescrBuildError( context.getParentDescr(),
evalDescr,
e,
"Unable to build expression for 'eval':" + e.getMessage() + " '" + evalDescr.getContent() + "'" ) );
return null;
} finally {
context.setTypesafe( typesafe );
}
}
|
[
"public",
"RuleConditionElement",
"build",
"(",
"final",
"RuleBuildContext",
"context",
",",
"final",
"BaseDescr",
"descr",
",",
"final",
"Pattern",
"prefixPattern",
")",
"{",
"boolean",
"typesafe",
"=",
"context",
".",
"isTypesafe",
"(",
")",
";",
"// it must be an EvalDescr",
"final",
"EvalDescr",
"evalDescr",
"=",
"(",
"EvalDescr",
")",
"descr",
";",
"try",
"{",
"MVELDialect",
"dialect",
"=",
"(",
"MVELDialect",
")",
"context",
".",
"getDialect",
"(",
"\"mvel\"",
")",
";",
"Map",
"<",
"String",
",",
"Declaration",
">",
"decls",
"=",
"context",
".",
"getDeclarationResolver",
"(",
")",
".",
"getDeclarations",
"(",
"context",
".",
"getRule",
"(",
")",
")",
";",
"AnalysisResult",
"analysis",
"=",
"context",
".",
"getDialect",
"(",
")",
".",
"analyzeExpression",
"(",
"context",
",",
"evalDescr",
",",
"evalDescr",
".",
"getContent",
"(",
")",
",",
"new",
"BoundIdentifiers",
"(",
"DeclarationScopeResolver",
".",
"getDeclarationClasses",
"(",
"decls",
")",
",",
"context",
")",
")",
";",
"final",
"BoundIdentifiers",
"usedIdentifiers",
"=",
"analysis",
".",
"getBoundIdentifiers",
"(",
")",
";",
"int",
"i",
"=",
"usedIdentifiers",
".",
"getDeclrClasses",
"(",
")",
".",
"keySet",
"(",
")",
".",
"size",
"(",
")",
";",
"Declaration",
"[",
"]",
"previousDeclarations",
"=",
"new",
"Declaration",
"[",
"i",
"]",
";",
"i",
"=",
"0",
";",
"for",
"(",
"String",
"id",
":",
"usedIdentifiers",
".",
"getDeclrClasses",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"previousDeclarations",
"[",
"i",
"++",
"]",
"=",
"decls",
".",
"get",
"(",
"id",
")",
";",
"}",
"Arrays",
".",
"sort",
"(",
"previousDeclarations",
",",
"SortDeclarations",
".",
"instance",
")",
";",
"MVELCompilationUnit",
"unit",
"=",
"dialect",
".",
"getMVELCompilationUnit",
"(",
"(",
"String",
")",
"evalDescr",
".",
"getContent",
"(",
")",
",",
"analysis",
",",
"previousDeclarations",
",",
"null",
",",
"null",
",",
"context",
",",
"\"drools\"",
",",
"KnowledgeHelper",
".",
"class",
",",
"false",
",",
"MVELCompilationUnit",
".",
"Scope",
".",
"EXPRESSION",
")",
";",
"final",
"EvalCondition",
"eval",
"=",
"new",
"EvalCondition",
"(",
"previousDeclarations",
")",
";",
"MVELEvalExpression",
"expr",
"=",
"new",
"MVELEvalExpression",
"(",
"unit",
",",
"dialect",
".",
"getId",
"(",
")",
")",
";",
"eval",
".",
"setEvalExpression",
"(",
"KiePolicyHelper",
".",
"isPolicyEnabled",
"(",
")",
"?",
"new",
"SafeEvalExpression",
"(",
"expr",
")",
":",
"expr",
")",
";",
"MVELDialectRuntimeData",
"data",
"=",
"(",
"MVELDialectRuntimeData",
")",
"context",
".",
"getPkg",
"(",
")",
".",
"getDialectRuntimeRegistry",
"(",
")",
".",
"getDialectData",
"(",
"\"mvel\"",
")",
";",
"data",
".",
"addCompileable",
"(",
"eval",
",",
"expr",
")",
";",
"expr",
".",
"compile",
"(",
"data",
",",
"context",
".",
"getRule",
"(",
")",
")",
";",
"return",
"eval",
";",
"}",
"catch",
"(",
"final",
"Exception",
"e",
")",
"{",
"copyErrorLocation",
"(",
"e",
",",
"evalDescr",
")",
";",
"context",
".",
"addError",
"(",
"new",
"DescrBuildError",
"(",
"context",
".",
"getParentDescr",
"(",
")",
",",
"evalDescr",
",",
"e",
",",
"\"Unable to build expression for 'eval':\"",
"+",
"e",
".",
"getMessage",
"(",
")",
"+",
"\" '\"",
"+",
"evalDescr",
".",
"getContent",
"(",
")",
"+",
"\"'\"",
")",
")",
";",
"return",
"null",
";",
"}",
"finally",
"{",
"context",
".",
"setTypesafe",
"(",
"typesafe",
")",
";",
"}",
"}"
] |
Builds and returns an Eval Conditional Element
@param context The current build context
@param descr The Eval Descriptor to build the eval conditional element from
@return the Eval Conditional Element
|
[
"Builds",
"and",
"returns",
"an",
"Eval",
"Conditional",
"Element"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/mvel/MVELEvalBuilder.java#L63-L122
|
14,098
|
kiegroup/drools
|
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java
|
CompiledFEELSemanticMappings.div
|
public static Object div(Object left, BigDecimal right) {
return right == null || right.signum() == 0 ? null : InfixOpNode.div(left, right, null);
}
|
java
|
public static Object div(Object left, BigDecimal right) {
return right == null || right.signum() == 0 ? null : InfixOpNode.div(left, right, null);
}
|
[
"public",
"static",
"Object",
"div",
"(",
"Object",
"left",
",",
"BigDecimal",
"right",
")",
"{",
"return",
"right",
"==",
"null",
"||",
"right",
".",
"signum",
"(",
")",
"==",
"0",
"?",
"null",
":",
"InfixOpNode",
".",
"div",
"(",
"left",
",",
"right",
",",
"null",
")",
";",
"}"
] |
to ground to null if right = 0
|
[
"to",
"ground",
"to",
"null",
"if",
"right",
"=",
"0"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java#L327-L329
|
14,099
|
kiegroup/drools
|
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java
|
CompiledFEELSemanticMappings.ne
|
public static Boolean ne(Object left, Object right) {
return not(EvalHelper.isEqual(left, right, null));
}
|
java
|
public static Boolean ne(Object left, Object right) {
return not(EvalHelper.isEqual(left, right, null));
}
|
[
"public",
"static",
"Boolean",
"ne",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"return",
"not",
"(",
"EvalHelper",
".",
"isEqual",
"(",
"left",
",",
"right",
",",
"null",
")",
")",
";",
"}"
] |
FEEL spec Table 39
|
[
"FEEL",
"spec",
"Table",
"39"
] |
22b0275d6dbe93070b8090948502cf46eda543c4
|
https://github.com/kiegroup/drools/blob/22b0275d6dbe93070b8090948502cf46eda543c4/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java#L414-L416
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.