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
|
---|---|---|---|---|---|---|---|---|---|---|---|
158,600 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/Analyser.java
|
Analyser.hasToBuilderMethod
|
private boolean hasToBuilderMethod(
DeclaredType builder,
boolean isExtensible,
Iterable<ExecutableElement> methods) {
for (ExecutableElement method : methods) {
if (isToBuilderMethod(builder, method)) {
if (!isExtensible) {
messager.printMessage(ERROR,
"No accessible no-args Builder constructor available to implement toBuilder",
method);
}
return true;
}
}
return false;
}
|
java
|
private boolean hasToBuilderMethod(
DeclaredType builder,
boolean isExtensible,
Iterable<ExecutableElement> methods) {
for (ExecutableElement method : methods) {
if (isToBuilderMethod(builder, method)) {
if (!isExtensible) {
messager.printMessage(ERROR,
"No accessible no-args Builder constructor available to implement toBuilder",
method);
}
return true;
}
}
return false;
}
|
[
"private",
"boolean",
"hasToBuilderMethod",
"(",
"DeclaredType",
"builder",
",",
"boolean",
"isExtensible",
",",
"Iterable",
"<",
"ExecutableElement",
">",
"methods",
")",
"{",
"for",
"(",
"ExecutableElement",
"method",
":",
"methods",
")",
"{",
"if",
"(",
"isToBuilderMethod",
"(",
"builder",
",",
"method",
")",
")",
"{",
"if",
"(",
"!",
"isExtensible",
")",
"{",
"messager",
".",
"printMessage",
"(",
"ERROR",
",",
"\"No accessible no-args Builder constructor available to implement toBuilder\"",
",",
"method",
")",
";",
"}",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Find a toBuilder method, if the user has provided one.
|
[
"Find",
"a",
"toBuilder",
"method",
"if",
"the",
"user",
"has",
"provided",
"one",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/Analyser.java#L279-L294
|
158,601 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/Analyser.java
|
Analyser.generatedBuilderSimpleName
|
private String generatedBuilderSimpleName(TypeElement type) {
String packageName = elements.getPackageOf(type).getQualifiedName().toString();
String originalName = type.getQualifiedName().toString();
checkState(originalName.startsWith(packageName + "."));
String nameWithoutPackage = originalName.substring(packageName.length() + 1);
return String.format(BUILDER_SIMPLE_NAME_TEMPLATE, nameWithoutPackage.replaceAll("\\.", "_"));
}
|
java
|
private String generatedBuilderSimpleName(TypeElement type) {
String packageName = elements.getPackageOf(type).getQualifiedName().toString();
String originalName = type.getQualifiedName().toString();
checkState(originalName.startsWith(packageName + "."));
String nameWithoutPackage = originalName.substring(packageName.length() + 1);
return String.format(BUILDER_SIMPLE_NAME_TEMPLATE, nameWithoutPackage.replaceAll("\\.", "_"));
}
|
[
"private",
"String",
"generatedBuilderSimpleName",
"(",
"TypeElement",
"type",
")",
"{",
"String",
"packageName",
"=",
"elements",
".",
"getPackageOf",
"(",
"type",
")",
".",
"getQualifiedName",
"(",
")",
".",
"toString",
"(",
")",
";",
"String",
"originalName",
"=",
"type",
".",
"getQualifiedName",
"(",
")",
".",
"toString",
"(",
")",
";",
"checkState",
"(",
"originalName",
".",
"startsWith",
"(",
"packageName",
"+",
"\".\"",
")",
")",
";",
"String",
"nameWithoutPackage",
"=",
"originalName",
".",
"substring",
"(",
"packageName",
".",
"length",
"(",
")",
"+",
"1",
")",
";",
"return",
"String",
".",
"format",
"(",
"BUILDER_SIMPLE_NAME_TEMPLATE",
",",
"nameWithoutPackage",
".",
"replaceAll",
"(",
"\"\\\\.\"",
",",
"\"_\"",
")",
")",
";",
"}"
] |
Returns the simple name of the builder class that should be generated for the given type.
<p>This is simply the {@link #BUILDER_SIMPLE_NAME_TEMPLATE} with the original type name
substituted in. (If the original type is nested, its enclosing classes will be included,
separated with underscores, to ensure uniqueness.)
|
[
"Returns",
"the",
"simple",
"name",
"of",
"the",
"builder",
"class",
"that",
"should",
"be",
"generated",
"for",
"the",
"given",
"type",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/Analyser.java#L587-L593
|
158,602 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java
|
ToStringGenerator.addToString
|
public static void addToString(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
boolean forPartial) {
String typename = (forPartial ? "partial " : "") + datatype.getType().getSimpleName();
Predicate<PropertyCodeGenerator> isOptional = generator -> {
Initially initially = generator.initialState();
return (initially == Initially.OPTIONAL || (initially == Initially.REQUIRED && forPartial));
};
boolean anyOptional = generatorsByProperty.values().stream().anyMatch(isOptional);
boolean allOptional = generatorsByProperty.values().stream().allMatch(isOptional)
&& !generatorsByProperty.isEmpty();
code.addLine("")
.addLine("@%s", Override.class)
.addLine("public %s toString() {", String.class);
if (allOptional) {
bodyWithBuilderAndSeparator(code, datatype, generatorsByProperty, typename);
} else if (anyOptional) {
bodyWithBuilder(code, datatype, generatorsByProperty, typename, isOptional);
} else {
bodyWithConcatenation(code, generatorsByProperty, typename);
}
code.addLine("}");
}
|
java
|
public static void addToString(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
boolean forPartial) {
String typename = (forPartial ? "partial " : "") + datatype.getType().getSimpleName();
Predicate<PropertyCodeGenerator> isOptional = generator -> {
Initially initially = generator.initialState();
return (initially == Initially.OPTIONAL || (initially == Initially.REQUIRED && forPartial));
};
boolean anyOptional = generatorsByProperty.values().stream().anyMatch(isOptional);
boolean allOptional = generatorsByProperty.values().stream().allMatch(isOptional)
&& !generatorsByProperty.isEmpty();
code.addLine("")
.addLine("@%s", Override.class)
.addLine("public %s toString() {", String.class);
if (allOptional) {
bodyWithBuilderAndSeparator(code, datatype, generatorsByProperty, typename);
} else if (anyOptional) {
bodyWithBuilder(code, datatype, generatorsByProperty, typename, isOptional);
} else {
bodyWithConcatenation(code, generatorsByProperty, typename);
}
code.addLine("}");
}
|
[
"public",
"static",
"void",
"addToString",
"(",
"SourceBuilder",
"code",
",",
"Datatype",
"datatype",
",",
"Map",
"<",
"Property",
",",
"PropertyCodeGenerator",
">",
"generatorsByProperty",
",",
"boolean",
"forPartial",
")",
"{",
"String",
"typename",
"=",
"(",
"forPartial",
"?",
"\"partial \"",
":",
"\"\"",
")",
"+",
"datatype",
".",
"getType",
"(",
")",
".",
"getSimpleName",
"(",
")",
";",
"Predicate",
"<",
"PropertyCodeGenerator",
">",
"isOptional",
"=",
"generator",
"->",
"{",
"Initially",
"initially",
"=",
"generator",
".",
"initialState",
"(",
")",
";",
"return",
"(",
"initially",
"==",
"Initially",
".",
"OPTIONAL",
"||",
"(",
"initially",
"==",
"Initially",
".",
"REQUIRED",
"&&",
"forPartial",
")",
")",
";",
"}",
";",
"boolean",
"anyOptional",
"=",
"generatorsByProperty",
".",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"anyMatch",
"(",
"isOptional",
")",
";",
"boolean",
"allOptional",
"=",
"generatorsByProperty",
".",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"allMatch",
"(",
"isOptional",
")",
"&&",
"!",
"generatorsByProperty",
".",
"isEmpty",
"(",
")",
";",
"code",
".",
"addLine",
"(",
"\"\"",
")",
".",
"addLine",
"(",
"\"@%s\"",
",",
"Override",
".",
"class",
")",
".",
"addLine",
"(",
"\"public %s toString() {\"",
",",
"String",
".",
"class",
")",
";",
"if",
"(",
"allOptional",
")",
"{",
"bodyWithBuilderAndSeparator",
"(",
"code",
",",
"datatype",
",",
"generatorsByProperty",
",",
"typename",
")",
";",
"}",
"else",
"if",
"(",
"anyOptional",
")",
"{",
"bodyWithBuilder",
"(",
"code",
",",
"datatype",
",",
"generatorsByProperty",
",",
"typename",
",",
"isOptional",
")",
";",
"}",
"else",
"{",
"bodyWithConcatenation",
"(",
"code",
",",
"generatorsByProperty",
",",
"typename",
")",
";",
"}",
"code",
".",
"addLine",
"(",
"\"}\"",
")",
";",
"}"
] |
Generates a toString method using concatenation or a StringBuilder.
|
[
"Generates",
"a",
"toString",
"method",
"using",
"concatenation",
"or",
"a",
"StringBuilder",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java#L23-L48
|
158,603 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java
|
ToStringGenerator.bodyWithConcatenation
|
private static void bodyWithConcatenation(
SourceBuilder code,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename) {
code.add(" return \"%s{", typename);
String prefix = "";
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
code.add("%s%s=\" + %s + \"",
prefix, property.getName(), (Excerpt) generator::addToStringValue);
prefix = ", ";
}
code.add("}\";%n");
}
|
java
|
private static void bodyWithConcatenation(
SourceBuilder code,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename) {
code.add(" return \"%s{", typename);
String prefix = "";
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
code.add("%s%s=\" + %s + \"",
prefix, property.getName(), (Excerpt) generator::addToStringValue);
prefix = ", ";
}
code.add("}\";%n");
}
|
[
"private",
"static",
"void",
"bodyWithConcatenation",
"(",
"SourceBuilder",
"code",
",",
"Map",
"<",
"Property",
",",
"PropertyCodeGenerator",
">",
"generatorsByProperty",
",",
"String",
"typename",
")",
"{",
"code",
".",
"add",
"(",
"\" return \\\"%s{\"",
",",
"typename",
")",
";",
"String",
"prefix",
"=",
"\"\"",
";",
"for",
"(",
"Property",
"property",
":",
"generatorsByProperty",
".",
"keySet",
"(",
")",
")",
"{",
"PropertyCodeGenerator",
"generator",
"=",
"generatorsByProperty",
".",
"get",
"(",
"property",
")",
";",
"code",
".",
"add",
"(",
"\"%s%s=\\\" + %s + \\\"\"",
",",
"prefix",
",",
"property",
".",
"getName",
"(",
")",
",",
"(",
"Excerpt",
")",
"generator",
"::",
"addToStringValue",
")",
";",
"prefix",
"=",
"\", \"",
";",
"}",
"code",
".",
"add",
"(",
"\"}\\\";%n\"",
")",
";",
"}"
] |
Generate the body of a toString method that uses plain concatenation.
<p>Conventionally, we join properties with comma separators. If all of the properties are
always present, this can be done with a long block of unconditional code. We could use a
StringBuilder for this, but in fact the Java compiler will do this for us under the hood
if we use simple string concatenation, so we use the more readable approach.
|
[
"Generate",
"the",
"body",
"of",
"a",
"toString",
"method",
"that",
"uses",
"plain",
"concatenation",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java#L58-L71
|
158,604 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java
|
ToStringGenerator.bodyWithBuilder
|
private static void bodyWithBuilder(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename,
Predicate<PropertyCodeGenerator> isOptional) {
Variable result = new Variable("result");
code.add(" %1$s %2$s = new %1$s(\"%3$s{", StringBuilder.class, result, typename);
boolean midStringLiteral = true;
boolean midAppends = true;
boolean prependCommas = false;
PropertyCodeGenerator lastOptionalGenerator = generatorsByProperty.values()
.stream()
.filter(isOptional)
.reduce((first, second) -> second)
.get();
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
if (isOptional.test(generator)) {
if (midStringLiteral) {
code.add("\")");
}
if (midAppends) {
code.add(";%n ");
}
code.add("if (");
if (generator.initialState() == Initially.OPTIONAL) {
generator.addToStringCondition(code);
} else {
code.add("!%s.contains(%s.%s)",
UNSET_PROPERTIES, datatype.getPropertyEnum(), property.getAllCapsName());
}
code.add(") {%n %s.append(\"", result);
if (prependCommas) {
code.add(", ");
}
code.add("%s=\").append(%s)", property.getName(), property.getField());
if (!prependCommas) {
code.add(".append(\", \")");
}
code.add(";%n }%n ");
if (generator.equals(lastOptionalGenerator)) {
code.add("return %s.append(\"", result);
midStringLiteral = true;
midAppends = true;
} else {
midStringLiteral = false;
midAppends = false;
}
} else {
if (!midAppends) {
code.add("%s", result);
}
if (!midStringLiteral) {
code.add(".append(\"");
}
if (prependCommas) {
code.add(", ");
}
code.add("%s=\").append(%s)", property.getName(), (Excerpt) generator::addToStringValue);
midStringLiteral = false;
midAppends = true;
prependCommas = true;
}
}
checkState(prependCommas, "Unexpected state at end of toString method");
checkState(midAppends, "Unexpected state at end of toString method");
if (!midStringLiteral) {
code.add(".append(\"");
}
code.add("}\").toString();%n", result);
}
|
java
|
private static void bodyWithBuilder(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename,
Predicate<PropertyCodeGenerator> isOptional) {
Variable result = new Variable("result");
code.add(" %1$s %2$s = new %1$s(\"%3$s{", StringBuilder.class, result, typename);
boolean midStringLiteral = true;
boolean midAppends = true;
boolean prependCommas = false;
PropertyCodeGenerator lastOptionalGenerator = generatorsByProperty.values()
.stream()
.filter(isOptional)
.reduce((first, second) -> second)
.get();
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
if (isOptional.test(generator)) {
if (midStringLiteral) {
code.add("\")");
}
if (midAppends) {
code.add(";%n ");
}
code.add("if (");
if (generator.initialState() == Initially.OPTIONAL) {
generator.addToStringCondition(code);
} else {
code.add("!%s.contains(%s.%s)",
UNSET_PROPERTIES, datatype.getPropertyEnum(), property.getAllCapsName());
}
code.add(") {%n %s.append(\"", result);
if (prependCommas) {
code.add(", ");
}
code.add("%s=\").append(%s)", property.getName(), property.getField());
if (!prependCommas) {
code.add(".append(\", \")");
}
code.add(";%n }%n ");
if (generator.equals(lastOptionalGenerator)) {
code.add("return %s.append(\"", result);
midStringLiteral = true;
midAppends = true;
} else {
midStringLiteral = false;
midAppends = false;
}
} else {
if (!midAppends) {
code.add("%s", result);
}
if (!midStringLiteral) {
code.add(".append(\"");
}
if (prependCommas) {
code.add(", ");
}
code.add("%s=\").append(%s)", property.getName(), (Excerpt) generator::addToStringValue);
midStringLiteral = false;
midAppends = true;
prependCommas = true;
}
}
checkState(prependCommas, "Unexpected state at end of toString method");
checkState(midAppends, "Unexpected state at end of toString method");
if (!midStringLiteral) {
code.add(".append(\"");
}
code.add("}\").toString();%n", result);
}
|
[
"private",
"static",
"void",
"bodyWithBuilder",
"(",
"SourceBuilder",
"code",
",",
"Datatype",
"datatype",
",",
"Map",
"<",
"Property",
",",
"PropertyCodeGenerator",
">",
"generatorsByProperty",
",",
"String",
"typename",
",",
"Predicate",
"<",
"PropertyCodeGenerator",
">",
"isOptional",
")",
"{",
"Variable",
"result",
"=",
"new",
"Variable",
"(",
"\"result\"",
")",
";",
"code",
".",
"add",
"(",
"\" %1$s %2$s = new %1$s(\\\"%3$s{\"",
",",
"StringBuilder",
".",
"class",
",",
"result",
",",
"typename",
")",
";",
"boolean",
"midStringLiteral",
"=",
"true",
";",
"boolean",
"midAppends",
"=",
"true",
";",
"boolean",
"prependCommas",
"=",
"false",
";",
"PropertyCodeGenerator",
"lastOptionalGenerator",
"=",
"generatorsByProperty",
".",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"isOptional",
")",
".",
"reduce",
"(",
"(",
"first",
",",
"second",
")",
"->",
"second",
")",
".",
"get",
"(",
")",
";",
"for",
"(",
"Property",
"property",
":",
"generatorsByProperty",
".",
"keySet",
"(",
")",
")",
"{",
"PropertyCodeGenerator",
"generator",
"=",
"generatorsByProperty",
".",
"get",
"(",
"property",
")",
";",
"if",
"(",
"isOptional",
".",
"test",
"(",
"generator",
")",
")",
"{",
"if",
"(",
"midStringLiteral",
")",
"{",
"code",
".",
"add",
"(",
"\"\\\")\"",
")",
";",
"}",
"if",
"(",
"midAppends",
")",
"{",
"code",
".",
"add",
"(",
"\";%n \"",
")",
";",
"}",
"code",
".",
"add",
"(",
"\"if (\"",
")",
";",
"if",
"(",
"generator",
".",
"initialState",
"(",
")",
"==",
"Initially",
".",
"OPTIONAL",
")",
"{",
"generator",
".",
"addToStringCondition",
"(",
"code",
")",
";",
"}",
"else",
"{",
"code",
".",
"add",
"(",
"\"!%s.contains(%s.%s)\"",
",",
"UNSET_PROPERTIES",
",",
"datatype",
".",
"getPropertyEnum",
"(",
")",
",",
"property",
".",
"getAllCapsName",
"(",
")",
")",
";",
"}",
"code",
".",
"add",
"(",
"\") {%n %s.append(\\\"\"",
",",
"result",
")",
";",
"if",
"(",
"prependCommas",
")",
"{",
"code",
".",
"add",
"(",
"\", \"",
")",
";",
"}",
"code",
".",
"add",
"(",
"\"%s=\\\").append(%s)\"",
",",
"property",
".",
"getName",
"(",
")",
",",
"property",
".",
"getField",
"(",
")",
")",
";",
"if",
"(",
"!",
"prependCommas",
")",
"{",
"code",
".",
"add",
"(",
"\".append(\\\", \\\")\"",
")",
";",
"}",
"code",
".",
"add",
"(",
"\";%n }%n \"",
")",
";",
"if",
"(",
"generator",
".",
"equals",
"(",
"lastOptionalGenerator",
")",
")",
"{",
"code",
".",
"add",
"(",
"\"return %s.append(\\\"\"",
",",
"result",
")",
";",
"midStringLiteral",
"=",
"true",
";",
"midAppends",
"=",
"true",
";",
"}",
"else",
"{",
"midStringLiteral",
"=",
"false",
";",
"midAppends",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"midAppends",
")",
"{",
"code",
".",
"add",
"(",
"\"%s\"",
",",
"result",
")",
";",
"}",
"if",
"(",
"!",
"midStringLiteral",
")",
"{",
"code",
".",
"add",
"(",
"\".append(\\\"\"",
")",
";",
"}",
"if",
"(",
"prependCommas",
")",
"{",
"code",
".",
"add",
"(",
"\", \"",
")",
";",
"}",
"code",
".",
"add",
"(",
"\"%s=\\\").append(%s)\"",
",",
"property",
".",
"getName",
"(",
")",
",",
"(",
"Excerpt",
")",
"generator",
"::",
"addToStringValue",
")",
";",
"midStringLiteral",
"=",
"false",
";",
"midAppends",
"=",
"true",
";",
"prependCommas",
"=",
"true",
";",
"}",
"}",
"checkState",
"(",
"prependCommas",
",",
"\"Unexpected state at end of toString method\"",
")",
";",
"checkState",
"(",
"midAppends",
",",
"\"Unexpected state at end of toString method\"",
")",
";",
"if",
"(",
"!",
"midStringLiteral",
")",
"{",
"code",
".",
"add",
"(",
"\".append(\\\"\"",
")",
";",
"}",
"code",
".",
"add",
"(",
"\"}\\\").toString();%n\"",
",",
"result",
")",
";",
"}"
] |
Generates the body of a toString method that uses a StringBuilder.
<p>Conventionally, we join properties with comma separators. If all of the properties are
optional, we have no choice but to track the separators at runtime, but if any of them will
always be present, we can actually do the hard work at compile time. Specifically, we can pick
the first such and output it without a comma; any property before it will have a comma
<em>appended</em>, and any property after it will have a comma <em>prepended</em>. This gives
us the right number of commas in the right places in all circumstances.
<p>As well as keeping track of whether we are <b>prepending commas</b> yet (initially false),
we also keep track of whether we have just finished an if-then block for an optional property,
or if we are in the <b>middle of an append chain</b>, and if so, whether we are in the
<b>middle of a string literal</b>. This lets us output the fewest literals and statements,
much as a mildly compulsive programmer would when writing the same code.
|
[
"Generates",
"the",
"body",
"of",
"a",
"toString",
"method",
"that",
"uses",
"a",
"StringBuilder",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java#L89-L164
|
158,605 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java
|
ToStringGenerator.bodyWithBuilderAndSeparator
|
private static void bodyWithBuilderAndSeparator(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename) {
Variable result = new Variable("result");
Variable separator = new Variable("separator");
code.addLine(" %1$s %2$s = new %1$s(\"%3$s{\");", StringBuilder.class, result, typename);
if (generatorsByProperty.size() > 1) {
// If there's a single property, we don't actually use the separator variable
code.addLine(" %s %s = \"\";", String.class, separator);
}
Property first = generatorsByProperty.keySet().iterator().next();
Property last = getLast(generatorsByProperty.keySet());
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
switch (generator.initialState()) {
case HAS_DEFAULT:
throw new RuntimeException("Internal error: unexpected default field");
case OPTIONAL:
code.addLine(" if (%s) {", (Excerpt) generator::addToStringCondition);
break;
case REQUIRED:
code.addLine(" if (!%s.contains(%s.%s)) {",
UNSET_PROPERTIES, datatype.getPropertyEnum(), property.getAllCapsName());
break;
}
code.add(" ").add(result);
if (property != first) {
code.add(".append(%s)", separator);
}
code.add(".append(\"%s=\").append(%s)",
property.getName(), (Excerpt) generator::addToStringValue);
if (property != last) {
code.add(";%n %s = \", \"", separator);
}
code.add(";%n }%n");
}
code.addLine(" return %s.append(\"}\").toString();", result);
}
|
java
|
private static void bodyWithBuilderAndSeparator(
SourceBuilder code,
Datatype datatype,
Map<Property, PropertyCodeGenerator> generatorsByProperty,
String typename) {
Variable result = new Variable("result");
Variable separator = new Variable("separator");
code.addLine(" %1$s %2$s = new %1$s(\"%3$s{\");", StringBuilder.class, result, typename);
if (generatorsByProperty.size() > 1) {
// If there's a single property, we don't actually use the separator variable
code.addLine(" %s %s = \"\";", String.class, separator);
}
Property first = generatorsByProperty.keySet().iterator().next();
Property last = getLast(generatorsByProperty.keySet());
for (Property property : generatorsByProperty.keySet()) {
PropertyCodeGenerator generator = generatorsByProperty.get(property);
switch (generator.initialState()) {
case HAS_DEFAULT:
throw new RuntimeException("Internal error: unexpected default field");
case OPTIONAL:
code.addLine(" if (%s) {", (Excerpt) generator::addToStringCondition);
break;
case REQUIRED:
code.addLine(" if (!%s.contains(%s.%s)) {",
UNSET_PROPERTIES, datatype.getPropertyEnum(), property.getAllCapsName());
break;
}
code.add(" ").add(result);
if (property != first) {
code.add(".append(%s)", separator);
}
code.add(".append(\"%s=\").append(%s)",
property.getName(), (Excerpt) generator::addToStringValue);
if (property != last) {
code.add(";%n %s = \", \"", separator);
}
code.add(";%n }%n");
}
code.addLine(" return %s.append(\"}\").toString();", result);
}
|
[
"private",
"static",
"void",
"bodyWithBuilderAndSeparator",
"(",
"SourceBuilder",
"code",
",",
"Datatype",
"datatype",
",",
"Map",
"<",
"Property",
",",
"PropertyCodeGenerator",
">",
"generatorsByProperty",
",",
"String",
"typename",
")",
"{",
"Variable",
"result",
"=",
"new",
"Variable",
"(",
"\"result\"",
")",
";",
"Variable",
"separator",
"=",
"new",
"Variable",
"(",
"\"separator\"",
")",
";",
"code",
".",
"addLine",
"(",
"\" %1$s %2$s = new %1$s(\\\"%3$s{\\\");\"",
",",
"StringBuilder",
".",
"class",
",",
"result",
",",
"typename",
")",
";",
"if",
"(",
"generatorsByProperty",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"// If there's a single property, we don't actually use the separator variable",
"code",
".",
"addLine",
"(",
"\" %s %s = \\\"\\\";\"",
",",
"String",
".",
"class",
",",
"separator",
")",
";",
"}",
"Property",
"first",
"=",
"generatorsByProperty",
".",
"keySet",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
";",
"Property",
"last",
"=",
"getLast",
"(",
"generatorsByProperty",
".",
"keySet",
"(",
")",
")",
";",
"for",
"(",
"Property",
"property",
":",
"generatorsByProperty",
".",
"keySet",
"(",
")",
")",
"{",
"PropertyCodeGenerator",
"generator",
"=",
"generatorsByProperty",
".",
"get",
"(",
"property",
")",
";",
"switch",
"(",
"generator",
".",
"initialState",
"(",
")",
")",
"{",
"case",
"HAS_DEFAULT",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"Internal error: unexpected default field\"",
")",
";",
"case",
"OPTIONAL",
":",
"code",
".",
"addLine",
"(",
"\" if (%s) {\"",
",",
"(",
"Excerpt",
")",
"generator",
"::",
"addToStringCondition",
")",
";",
"break",
";",
"case",
"REQUIRED",
":",
"code",
".",
"addLine",
"(",
"\" if (!%s.contains(%s.%s)) {\"",
",",
"UNSET_PROPERTIES",
",",
"datatype",
".",
"getPropertyEnum",
"(",
")",
",",
"property",
".",
"getAllCapsName",
"(",
")",
")",
";",
"break",
";",
"}",
"code",
".",
"add",
"(",
"\" \"",
")",
".",
"add",
"(",
"result",
")",
";",
"if",
"(",
"property",
"!=",
"first",
")",
"{",
"code",
".",
"add",
"(",
"\".append(%s)\"",
",",
"separator",
")",
";",
"}",
"code",
".",
"add",
"(",
"\".append(\\\"%s=\\\").append(%s)\"",
",",
"property",
".",
"getName",
"(",
")",
",",
"(",
"Excerpt",
")",
"generator",
"::",
"addToStringValue",
")",
";",
"if",
"(",
"property",
"!=",
"last",
")",
"{",
"code",
".",
"add",
"(",
"\";%n %s = \\\", \\\"\"",
",",
"separator",
")",
";",
"}",
"code",
".",
"add",
"(",
"\";%n }%n\"",
")",
";",
"}",
"code",
".",
"addLine",
"(",
"\" return %s.append(\\\"}\\\").toString();\"",
",",
"result",
")",
";",
"}"
] |
Generates the body of a toString method that uses a StringBuilder and a separator variable.
<p>Conventionally, we join properties with comma separators. If all of the properties are
optional, we have no choice but to track the separators at runtime, as apart from the first
one, all properties will need to have a comma prepended. We could do this with a boolean,
maybe called "separatorNeeded", or "firstValueOutput", but then we need either a ternary
operator or an extra nested if block. More readable is to use an initially-empty "separator"
string, which has a comma placed in it once the first value is written.
<p>For extra tidiness, we note that the first if block need not try writing the separator
(it is always empty), and the last one need not update it (it will not be used again).
|
[
"Generates",
"the",
"body",
"of",
"a",
"toString",
"method",
"that",
"uses",
"a",
"StringBuilder",
"and",
"a",
"separator",
"variable",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/ToStringGenerator.java#L179-L222
|
158,606 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/source/LazyName.java
|
LazyName.addLazyDefinitions
|
public static void addLazyDefinitions(SourceBuilder code) {
Set<Declaration> defined = new HashSet<>();
// Definitions may lazily declare new names; ensure we add them all
List<Declaration> declarations =
code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
while (!defined.containsAll(declarations)) {
for (Declaration declaration : declarations) {
if (defined.add(declaration)) {
code.add(code.scope().get(declaration).definition);
}
}
declarations = code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
}
}
|
java
|
public static void addLazyDefinitions(SourceBuilder code) {
Set<Declaration> defined = new HashSet<>();
// Definitions may lazily declare new names; ensure we add them all
List<Declaration> declarations =
code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
while (!defined.containsAll(declarations)) {
for (Declaration declaration : declarations) {
if (defined.add(declaration)) {
code.add(code.scope().get(declaration).definition);
}
}
declarations = code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
}
}
|
[
"public",
"static",
"void",
"addLazyDefinitions",
"(",
"SourceBuilder",
"code",
")",
"{",
"Set",
"<",
"Declaration",
">",
"defined",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"// Definitions may lazily declare new names; ensure we add them all",
"List",
"<",
"Declaration",
">",
"declarations",
"=",
"code",
".",
"scope",
"(",
")",
".",
"keysOfType",
"(",
"Declaration",
".",
"class",
")",
".",
"stream",
"(",
")",
".",
"sorted",
"(",
")",
".",
"collect",
"(",
"toList",
"(",
")",
")",
";",
"while",
"(",
"!",
"defined",
".",
"containsAll",
"(",
"declarations",
")",
")",
"{",
"for",
"(",
"Declaration",
"declaration",
":",
"declarations",
")",
"{",
"if",
"(",
"defined",
".",
"add",
"(",
"declaration",
")",
")",
"{",
"code",
".",
"add",
"(",
"code",
".",
"scope",
"(",
")",
".",
"get",
"(",
"declaration",
")",
".",
"definition",
")",
";",
"}",
"}",
"declarations",
"=",
"code",
".",
"scope",
"(",
")",
".",
"keysOfType",
"(",
"Declaration",
".",
"class",
")",
".",
"stream",
"(",
")",
".",
"sorted",
"(",
")",
".",
"collect",
"(",
"toList",
"(",
")",
")",
";",
"}",
"}"
] |
Finds all lazily-declared classes and methods and adds their definitions to the source.
|
[
"Finds",
"all",
"lazily",
"-",
"declared",
"classes",
"and",
"methods",
"and",
"adds",
"their",
"definitions",
"to",
"the",
"source",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/source/LazyName.java#L31-L45
|
158,607 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/property/PropertyCodeGenerator.java
|
PropertyCodeGenerator.addPartialFieldAssignment
|
public void addPartialFieldAssignment(
SourceBuilder code, Excerpt finalField, String builder) {
addFinalFieldAssignment(code, finalField, builder);
}
|
java
|
public void addPartialFieldAssignment(
SourceBuilder code, Excerpt finalField, String builder) {
addFinalFieldAssignment(code, finalField, builder);
}
|
[
"public",
"void",
"addPartialFieldAssignment",
"(",
"SourceBuilder",
"code",
",",
"Excerpt",
"finalField",
",",
"String",
"builder",
")",
"{",
"addFinalFieldAssignment",
"(",
"code",
",",
"finalField",
",",
"builder",
")",
";",
"}"
] |
Add the final assignment of the property to the partial value object's source code.
|
[
"Add",
"the",
"final",
"assignment",
"of",
"the",
"property",
"to",
"the",
"partial",
"value",
"object",
"s",
"source",
"code",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/property/PropertyCodeGenerator.java#L151-L154
|
158,608 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/property/MergeAction.java
|
MergeAction.addActionsTo
|
public static void addActionsTo(
SourceBuilder code,
Set<MergeAction> mergeActions,
boolean forBuilder) {
SetMultimap<String, String> nounsByVerb = TreeMultimap.create();
mergeActions.forEach(mergeAction -> {
if (forBuilder || !mergeAction.builderOnly) {
nounsByVerb.put(mergeAction.verb, mergeAction.noun);
}
});
List<String> verbs = ImmutableList.copyOf(nounsByVerb.keySet());
String lastVerb = getLast(verbs, null);
for (String verb : nounsByVerb.keySet()) {
code.add(", %s%s", (verbs.size() > 1 && verb.equals(lastVerb)) ? "and " : "", verb);
List<String> nouns = ImmutableList.copyOf(nounsByVerb.get(verb));
for (int i = 0; i < nouns.size(); ++i) {
String separator = (i == 0) ? "" : (i == nouns.size() - 1) ? " and" : ",";
code.add("%s %s", separator, nouns.get(i));
}
}
}
|
java
|
public static void addActionsTo(
SourceBuilder code,
Set<MergeAction> mergeActions,
boolean forBuilder) {
SetMultimap<String, String> nounsByVerb = TreeMultimap.create();
mergeActions.forEach(mergeAction -> {
if (forBuilder || !mergeAction.builderOnly) {
nounsByVerb.put(mergeAction.verb, mergeAction.noun);
}
});
List<String> verbs = ImmutableList.copyOf(nounsByVerb.keySet());
String lastVerb = getLast(verbs, null);
for (String verb : nounsByVerb.keySet()) {
code.add(", %s%s", (verbs.size() > 1 && verb.equals(lastVerb)) ? "and " : "", verb);
List<String> nouns = ImmutableList.copyOf(nounsByVerb.get(verb));
for (int i = 0; i < nouns.size(); ++i) {
String separator = (i == 0) ? "" : (i == nouns.size() - 1) ? " and" : ",";
code.add("%s %s", separator, nouns.get(i));
}
}
}
|
[
"public",
"static",
"void",
"addActionsTo",
"(",
"SourceBuilder",
"code",
",",
"Set",
"<",
"MergeAction",
">",
"mergeActions",
",",
"boolean",
"forBuilder",
")",
"{",
"SetMultimap",
"<",
"String",
",",
"String",
">",
"nounsByVerb",
"=",
"TreeMultimap",
".",
"create",
"(",
")",
";",
"mergeActions",
".",
"forEach",
"(",
"mergeAction",
"->",
"{",
"if",
"(",
"forBuilder",
"||",
"!",
"mergeAction",
".",
"builderOnly",
")",
"{",
"nounsByVerb",
".",
"put",
"(",
"mergeAction",
".",
"verb",
",",
"mergeAction",
".",
"noun",
")",
";",
"}",
"}",
")",
";",
"List",
"<",
"String",
">",
"verbs",
"=",
"ImmutableList",
".",
"copyOf",
"(",
"nounsByVerb",
".",
"keySet",
"(",
")",
")",
";",
"String",
"lastVerb",
"=",
"getLast",
"(",
"verbs",
",",
"null",
")",
";",
"for",
"(",
"String",
"verb",
":",
"nounsByVerb",
".",
"keySet",
"(",
")",
")",
"{",
"code",
".",
"add",
"(",
"\", %s%s\"",
",",
"(",
"verbs",
".",
"size",
"(",
")",
">",
"1",
"&&",
"verb",
".",
"equals",
"(",
"lastVerb",
")",
")",
"?",
"\"and \"",
":",
"\"\"",
",",
"verb",
")",
";",
"List",
"<",
"String",
">",
"nouns",
"=",
"ImmutableList",
".",
"copyOf",
"(",
"nounsByVerb",
".",
"get",
"(",
"verb",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nouns",
".",
"size",
"(",
")",
";",
"++",
"i",
")",
"{",
"String",
"separator",
"=",
"(",
"i",
"==",
"0",
")",
"?",
"\"\"",
":",
"(",
"i",
"==",
"nouns",
".",
"size",
"(",
")",
"-",
"1",
")",
"?",
"\" and\"",
":",
"\",\"",
";",
"code",
".",
"add",
"(",
"\"%s %s\"",
",",
"separator",
",",
"nouns",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"}",
"}"
] |
Emits a sentence fragment combining all the merge actions.
|
[
"Emits",
"a",
"sentence",
"fragment",
"combining",
"all",
"the",
"merge",
"actions",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/property/MergeAction.java#L39-L59
|
158,609 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/Declarations.java
|
Declarations.upcastToGeneratedBuilder
|
public static Variable upcastToGeneratedBuilder(
SourceBuilder code, Datatype datatype, String builder) {
return code.scope().computeIfAbsent(Declaration.UPCAST, () -> {
Variable base = new Variable("base");
code.addLine(UPCAST_COMMENT)
.addLine("%s %s = %s;", datatype.getGeneratedBuilder(), base, builder);
return base;
});
}
|
java
|
public static Variable upcastToGeneratedBuilder(
SourceBuilder code, Datatype datatype, String builder) {
return code.scope().computeIfAbsent(Declaration.UPCAST, () -> {
Variable base = new Variable("base");
code.addLine(UPCAST_COMMENT)
.addLine("%s %s = %s;", datatype.getGeneratedBuilder(), base, builder);
return base;
});
}
|
[
"public",
"static",
"Variable",
"upcastToGeneratedBuilder",
"(",
"SourceBuilder",
"code",
",",
"Datatype",
"datatype",
",",
"String",
"builder",
")",
"{",
"return",
"code",
".",
"scope",
"(",
")",
".",
"computeIfAbsent",
"(",
"Declaration",
".",
"UPCAST",
",",
"(",
")",
"->",
"{",
"Variable",
"base",
"=",
"new",
"Variable",
"(",
"\"base\"",
")",
";",
"code",
".",
"addLine",
"(",
"UPCAST_COMMENT",
")",
".",
"addLine",
"(",
"\"%s %s = %s;\"",
",",
"datatype",
".",
"getGeneratedBuilder",
"(",
")",
",",
"base",
",",
"builder",
")",
";",
"return",
"base",
";",
"}",
")",
";",
"}"
] |
Upcasts a Builder instance to the generated superclass, to allow access to private fields.
<p>Reuses an existing upcast instance if one was already declared in this scope.
@param code the {@link SourceBuilder} to add the declaration to
@param datatype metadata about the user type the builder is being generated for
@param builder the Builder instance to upcast
@returns a variable holding the upcasted instance
|
[
"Upcasts",
"a",
"Builder",
"instance",
"to",
"the",
"generated",
"superclass",
"to",
"allow",
"access",
"to",
"private",
"fields",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/Declarations.java#L35-L43
|
158,610 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/Declarations.java
|
Declarations.freshBuilder
|
public static Optional<Variable> freshBuilder(SourceBuilder code, Datatype datatype) {
if (!datatype.getBuilderFactory().isPresent()) {
return Optional.empty();
}
return Optional.of(code.scope().computeIfAbsent(Declaration.FRESH_BUILDER, () -> {
Variable defaults = new Variable("defaults");
code.addLine("%s %s = %s;",
datatype.getGeneratedBuilder(),
defaults,
datatype.getBuilderFactory().get()
.newBuilder(datatype.getBuilder(), TypeInference.INFERRED_TYPES));
return defaults;
}));
}
|
java
|
public static Optional<Variable> freshBuilder(SourceBuilder code, Datatype datatype) {
if (!datatype.getBuilderFactory().isPresent()) {
return Optional.empty();
}
return Optional.of(code.scope().computeIfAbsent(Declaration.FRESH_BUILDER, () -> {
Variable defaults = new Variable("defaults");
code.addLine("%s %s = %s;",
datatype.getGeneratedBuilder(),
defaults,
datatype.getBuilderFactory().get()
.newBuilder(datatype.getBuilder(), TypeInference.INFERRED_TYPES));
return defaults;
}));
}
|
[
"public",
"static",
"Optional",
"<",
"Variable",
">",
"freshBuilder",
"(",
"SourceBuilder",
"code",
",",
"Datatype",
"datatype",
")",
"{",
"if",
"(",
"!",
"datatype",
".",
"getBuilderFactory",
"(",
")",
".",
"isPresent",
"(",
")",
")",
"{",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}",
"return",
"Optional",
".",
"of",
"(",
"code",
".",
"scope",
"(",
")",
".",
"computeIfAbsent",
"(",
"Declaration",
".",
"FRESH_BUILDER",
",",
"(",
")",
"->",
"{",
"Variable",
"defaults",
"=",
"new",
"Variable",
"(",
"\"defaults\"",
")",
";",
"code",
".",
"addLine",
"(",
"\"%s %s = %s;\"",
",",
"datatype",
".",
"getGeneratedBuilder",
"(",
")",
",",
"defaults",
",",
"datatype",
".",
"getBuilderFactory",
"(",
")",
".",
"get",
"(",
")",
".",
"newBuilder",
"(",
"datatype",
".",
"getBuilder",
"(",
")",
",",
"TypeInference",
".",
"INFERRED_TYPES",
")",
")",
";",
"return",
"defaults",
";",
"}",
")",
")",
";",
"}"
] |
Declares a fresh Builder to copy default property values from.
<p>Reuses an existing fresh Builder instance if one was already declared in this scope.
@returns a variable holding a fresh Builder, if a no-args factory method is available to
create one with
|
[
"Declares",
"a",
"fresh",
"Builder",
"to",
"copy",
"default",
"property",
"values",
"from",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/Declarations.java#L53-L66
|
158,611 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/source/Type.java
|
Type.javadocMethodLink
|
public JavadocLink javadocMethodLink(String memberName, Type... types) {
return new JavadocLink("%s#%s(%s)",
getQualifiedName(),
memberName,
(Excerpt) code -> {
String separator = "";
for (Type type : types) {
code.add("%s%s", separator, type.getQualifiedName());
separator = ", ";
}
});
}
|
java
|
public JavadocLink javadocMethodLink(String memberName, Type... types) {
return new JavadocLink("%s#%s(%s)",
getQualifiedName(),
memberName,
(Excerpt) code -> {
String separator = "";
for (Type type : types) {
code.add("%s%s", separator, type.getQualifiedName());
separator = ", ";
}
});
}
|
[
"public",
"JavadocLink",
"javadocMethodLink",
"(",
"String",
"memberName",
",",
"Type",
"...",
"types",
")",
"{",
"return",
"new",
"JavadocLink",
"(",
"\"%s#%s(%s)\"",
",",
"getQualifiedName",
"(",
")",
",",
"memberName",
",",
"(",
"Excerpt",
")",
"code",
"->",
"{",
"String",
"separator",
"=",
"\"\"",
";",
"for",
"(",
"Type",
"type",
":",
"types",
")",
"{",
"code",
".",
"add",
"(",
"\"%s%s\"",
",",
"separator",
",",
"type",
".",
"getQualifiedName",
"(",
")",
")",
";",
"separator",
"=",
"\", \"",
";",
"}",
"}",
")",
";",
"}"
] |
Returns a source excerpt of a JavaDoc link to a method on this type.
|
[
"Returns",
"a",
"source",
"excerpt",
"of",
"a",
"JavaDoc",
"link",
"to",
"a",
"method",
"on",
"this",
"type",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/source/Type.java#L117-L128
|
158,612 |
inferred/FreeBuilder
|
src/main/java/org/inferred/freebuilder/processor/source/Type.java
|
Type.typeParameters
|
public Excerpt typeParameters() {
if (getTypeParameters().isEmpty()) {
return Excerpts.EMPTY;
} else {
return Excerpts.add("<%s>", Excerpts.join(", ", getTypeParameters()));
}
}
|
java
|
public Excerpt typeParameters() {
if (getTypeParameters().isEmpty()) {
return Excerpts.EMPTY;
} else {
return Excerpts.add("<%s>", Excerpts.join(", ", getTypeParameters()));
}
}
|
[
"public",
"Excerpt",
"typeParameters",
"(",
")",
"{",
"if",
"(",
"getTypeParameters",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Excerpts",
".",
"EMPTY",
";",
"}",
"else",
"{",
"return",
"Excerpts",
".",
"add",
"(",
"\"<%s>\"",
",",
"Excerpts",
".",
"join",
"(",
"\", \"",
",",
"getTypeParameters",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Returns a source excerpt of the type parameters of this type, including angle brackets.
Always an empty string if the type class is not generic.
<p>e.g. {@code <N, C>}
|
[
"Returns",
"a",
"source",
"excerpt",
"of",
"the",
"type",
"parameters",
"of",
"this",
"type",
"including",
"angle",
"brackets",
".",
"Always",
"an",
"empty",
"string",
"if",
"the",
"type",
"class",
"is",
"not",
"generic",
"."
] |
d5a222f90648aece135da4b971c55a60afe8649c
|
https://github.com/inferred/FreeBuilder/blob/d5a222f90648aece135da4b971c55a60afe8649c/src/main/java/org/inferred/freebuilder/processor/source/Type.java#L136-L142
|
158,613 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractRule.java
|
AbstractRule.createViolation
|
protected Violation createViolation(Integer lineNumber, String sourceLine, String message) {
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine(sourceLine);
violation.setLineNumber(lineNumber);
violation.setMessage(message);
return violation;
}
|
java
|
protected Violation createViolation(Integer lineNumber, String sourceLine, String message) {
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine(sourceLine);
violation.setLineNumber(lineNumber);
violation.setMessage(message);
return violation;
}
|
[
"protected",
"Violation",
"createViolation",
"(",
"Integer",
"lineNumber",
",",
"String",
"sourceLine",
",",
"String",
"message",
")",
"{",
"Violation",
"violation",
"=",
"new",
"Violation",
"(",
")",
";",
"violation",
".",
"setRule",
"(",
"this",
")",
";",
"violation",
".",
"setSourceLine",
"(",
"sourceLine",
")",
";",
"violation",
".",
"setLineNumber",
"(",
"lineNumber",
")",
";",
"violation",
".",
"setMessage",
"(",
"message",
")",
";",
"return",
"violation",
";",
"}"
] |
Create and return a new Violation for this rule and the specified values
@param lineNumber - the line number for the violation; may be null
@param sourceLine - the source line for the violation; may be null
@param message - the message for the violation; may be null
@return a new Violation object
|
[
"Create",
"and",
"return",
"a",
"new",
"Violation",
"for",
"this",
"rule",
"and",
"the",
"specified",
"values"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractRule.java#L195-L202
|
158,614 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractRule.java
|
AbstractRule.createViolation
|
protected Violation createViolation(SourceCode sourceCode, ASTNode node, String message) {
String sourceLine = sourceCode.line(node.getLineNumber()-1);
return createViolation(node.getLineNumber(), sourceLine, message);
}
|
java
|
protected Violation createViolation(SourceCode sourceCode, ASTNode node, String message) {
String sourceLine = sourceCode.line(node.getLineNumber()-1);
return createViolation(node.getLineNumber(), sourceLine, message);
}
|
[
"protected",
"Violation",
"createViolation",
"(",
"SourceCode",
"sourceCode",
",",
"ASTNode",
"node",
",",
"String",
"message",
")",
"{",
"String",
"sourceLine",
"=",
"sourceCode",
".",
"line",
"(",
"node",
".",
"getLineNumber",
"(",
")",
"-",
"1",
")",
";",
"return",
"createViolation",
"(",
"node",
".",
"getLineNumber",
"(",
")",
",",
"sourceLine",
",",
"message",
")",
";",
"}"
] |
Create a new Violation for the AST node.
@param sourceCode - the SourceCode
@param node - the Groovy AST Node
@param message - the message for the violation; defaults to null
|
[
"Create",
"a",
"new",
"Violation",
"for",
"the",
"AST",
"node",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractRule.java#L210-L213
|
158,615 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractRule.java
|
AbstractRule.createViolationForImport
|
protected Violation createViolationForImport(SourceCode sourceCode, ImportNode importNode, String message) {
Map importInfo = ImportUtil.sourceLineAndNumberForImport(sourceCode, importNode);
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine((String) importInfo.get("sourceLine"));
violation.setLineNumber((Integer) importInfo.get("lineNumber"));
violation.setMessage(message);
return violation;
}
|
java
|
protected Violation createViolationForImport(SourceCode sourceCode, ImportNode importNode, String message) {
Map importInfo = ImportUtil.sourceLineAndNumberForImport(sourceCode, importNode);
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine((String) importInfo.get("sourceLine"));
violation.setLineNumber((Integer) importInfo.get("lineNumber"));
violation.setMessage(message);
return violation;
}
|
[
"protected",
"Violation",
"createViolationForImport",
"(",
"SourceCode",
"sourceCode",
",",
"ImportNode",
"importNode",
",",
"String",
"message",
")",
"{",
"Map",
"importInfo",
"=",
"ImportUtil",
".",
"sourceLineAndNumberForImport",
"(",
"sourceCode",
",",
"importNode",
")",
";",
"Violation",
"violation",
"=",
"new",
"Violation",
"(",
")",
";",
"violation",
".",
"setRule",
"(",
"this",
")",
";",
"violation",
".",
"setSourceLine",
"(",
"(",
"String",
")",
"importInfo",
".",
"get",
"(",
"\"sourceLine\"",
")",
")",
";",
"violation",
".",
"setLineNumber",
"(",
"(",
"Integer",
")",
"importInfo",
".",
"get",
"(",
"\"lineNumber\"",
")",
")",
";",
"violation",
".",
"setMessage",
"(",
"message",
")",
";",
"return",
"violation",
";",
"}"
] |
Create and return a new Violation for this rule and the specified import
@param sourceCode - the SourceCode
@param importNode - the ImportNode for the import triggering the violation
@return a new Violation object
|
[
"Create",
"and",
"return",
"a",
"new",
"Violation",
"for",
"this",
"rule",
"and",
"the",
"specified",
"import"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractRule.java#L221-L229
|
158,616 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractRule.java
|
AbstractRule.createViolationForImport
|
protected Violation createViolationForImport(SourceCode sourceCode, String className, String alias, String violationMessage) {
Map importInfo = ImportUtil.sourceLineAndNumberForImport(sourceCode, className, alias);
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine((String) importInfo.get("sourceLine"));
violation.setLineNumber((Integer) importInfo.get("lineNumber"));
violation.setMessage(violationMessage);
return violation;
}
|
java
|
protected Violation createViolationForImport(SourceCode sourceCode, String className, String alias, String violationMessage) {
Map importInfo = ImportUtil.sourceLineAndNumberForImport(sourceCode, className, alias);
Violation violation = new Violation();
violation.setRule(this);
violation.setSourceLine((String) importInfo.get("sourceLine"));
violation.setLineNumber((Integer) importInfo.get("lineNumber"));
violation.setMessage(violationMessage);
return violation;
}
|
[
"protected",
"Violation",
"createViolationForImport",
"(",
"SourceCode",
"sourceCode",
",",
"String",
"className",
",",
"String",
"alias",
",",
"String",
"violationMessage",
")",
"{",
"Map",
"importInfo",
"=",
"ImportUtil",
".",
"sourceLineAndNumberForImport",
"(",
"sourceCode",
",",
"className",
",",
"alias",
")",
";",
"Violation",
"violation",
"=",
"new",
"Violation",
"(",
")",
";",
"violation",
".",
"setRule",
"(",
"this",
")",
";",
"violation",
".",
"setSourceLine",
"(",
"(",
"String",
")",
"importInfo",
".",
"get",
"(",
"\"sourceLine\"",
")",
")",
";",
"violation",
".",
"setLineNumber",
"(",
"(",
"Integer",
")",
"importInfo",
".",
"get",
"(",
"\"lineNumber\"",
")",
")",
";",
"violation",
".",
"setMessage",
"(",
"violationMessage",
")",
";",
"return",
"violation",
";",
"}"
] |
Create and return a new Violation for this rule and the specified import className and alias
@param sourceCode - the SourceCode
@param className - the class name (as specified within the import statement)
@param alias - the alias for the import statement
@param violationMessage - the violation message; may be null
@return a new Violation object
|
[
"Create",
"and",
"return",
"a",
"new",
"Violation",
"for",
"this",
"rule",
"and",
"the",
"specified",
"import",
"className",
"and",
"alias"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractRule.java#L239-L247
|
158,617 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractAstVisitorRule.java
|
AbstractAstVisitorRule.shouldApplyThisRuleTo
|
protected boolean shouldApplyThisRuleTo(ClassNode classNode) {
// TODO Consider caching applyTo, doNotApplyTo and associated WildcardPatterns
boolean shouldApply = true;
String applyTo = getApplyToClassNames();
String doNotApplyTo = getDoNotApplyToClassNames();
if (applyTo != null && applyTo.length() > 0) {
WildcardPattern pattern = new WildcardPattern(applyTo, true);
shouldApply = pattern.matches(classNode.getNameWithoutPackage()) || pattern.matches(classNode.getName());
}
if (shouldApply && doNotApplyTo != null && doNotApplyTo.length() > 0) {
WildcardPattern pattern = new WildcardPattern(doNotApplyTo, true);
shouldApply = !pattern.matches(classNode.getNameWithoutPackage()) && !pattern.matches(classNode.getName());
}
return shouldApply;
}
|
java
|
protected boolean shouldApplyThisRuleTo(ClassNode classNode) {
// TODO Consider caching applyTo, doNotApplyTo and associated WildcardPatterns
boolean shouldApply = true;
String applyTo = getApplyToClassNames();
String doNotApplyTo = getDoNotApplyToClassNames();
if (applyTo != null && applyTo.length() > 0) {
WildcardPattern pattern = new WildcardPattern(applyTo, true);
shouldApply = pattern.matches(classNode.getNameWithoutPackage()) || pattern.matches(classNode.getName());
}
if (shouldApply && doNotApplyTo != null && doNotApplyTo.length() > 0) {
WildcardPattern pattern = new WildcardPattern(doNotApplyTo, true);
shouldApply = !pattern.matches(classNode.getNameWithoutPackage()) && !pattern.matches(classNode.getName());
}
return shouldApply;
}
|
[
"protected",
"boolean",
"shouldApplyThisRuleTo",
"(",
"ClassNode",
"classNode",
")",
"{",
"// TODO Consider caching applyTo, doNotApplyTo and associated WildcardPatterns\r",
"boolean",
"shouldApply",
"=",
"true",
";",
"String",
"applyTo",
"=",
"getApplyToClassNames",
"(",
")",
";",
"String",
"doNotApplyTo",
"=",
"getDoNotApplyToClassNames",
"(",
")",
";",
"if",
"(",
"applyTo",
"!=",
"null",
"&&",
"applyTo",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"WildcardPattern",
"pattern",
"=",
"new",
"WildcardPattern",
"(",
"applyTo",
",",
"true",
")",
";",
"shouldApply",
"=",
"pattern",
".",
"matches",
"(",
"classNode",
".",
"getNameWithoutPackage",
"(",
")",
")",
"||",
"pattern",
".",
"matches",
"(",
"classNode",
".",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"shouldApply",
"&&",
"doNotApplyTo",
"!=",
"null",
"&&",
"doNotApplyTo",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"WildcardPattern",
"pattern",
"=",
"new",
"WildcardPattern",
"(",
"doNotApplyTo",
",",
"true",
")",
";",
"shouldApply",
"=",
"!",
"pattern",
".",
"matches",
"(",
"classNode",
".",
"getNameWithoutPackage",
"(",
")",
")",
"&&",
"!",
"pattern",
".",
"matches",
"(",
"classNode",
".",
"getName",
"(",
")",
")",
";",
"}",
"return",
"shouldApply",
";",
"}"
] |
Return true if this rule should be applied for the specified ClassNode, based on the
configuration of this rule.
@param classNode - the ClassNode
@return true if this rule should be applied for the specified ClassNode
|
[
"Return",
"true",
"if",
"this",
"rule",
"should",
"be",
"applied",
"for",
"the",
"specified",
"ClassNode",
"based",
"on",
"the",
"configuration",
"of",
"this",
"rule",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractAstVisitorRule.java#L121-L139
|
158,618 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/ant/AntFileSetSourceAnalyzer.java
|
AntFileSetSourceAnalyzer.analyze
|
public Results analyze(RuleSet ruleSet) {
long startTime = System.currentTimeMillis();
DirectoryResults reportResults = new DirectoryResults();
int numThreads = Runtime.getRuntime().availableProcessors() - 1;
numThreads = numThreads > 0 ? numThreads : 1;
ExecutorService pool = Executors.newFixedThreadPool(numThreads);
for (FileSet fileSet : fileSets) {
processFileSet(fileSet, ruleSet, pool);
}
pool.shutdown();
try {
boolean completed = pool.awaitTermination(POOL_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (!completed) {
throw new IllegalStateException("Thread Pool terminated before comp<FileResults>letion");
}
} catch (InterruptedException e) {
throw new IllegalStateException("Thread Pool interrupted before completion");
}
addDirectoryResults(reportResults);
LOG.info("Analysis time=" + (System.currentTimeMillis() - startTime) + "ms");
return reportResults;
}
|
java
|
public Results analyze(RuleSet ruleSet) {
long startTime = System.currentTimeMillis();
DirectoryResults reportResults = new DirectoryResults();
int numThreads = Runtime.getRuntime().availableProcessors() - 1;
numThreads = numThreads > 0 ? numThreads : 1;
ExecutorService pool = Executors.newFixedThreadPool(numThreads);
for (FileSet fileSet : fileSets) {
processFileSet(fileSet, ruleSet, pool);
}
pool.shutdown();
try {
boolean completed = pool.awaitTermination(POOL_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (!completed) {
throw new IllegalStateException("Thread Pool terminated before comp<FileResults>letion");
}
} catch (InterruptedException e) {
throw new IllegalStateException("Thread Pool interrupted before completion");
}
addDirectoryResults(reportResults);
LOG.info("Analysis time=" + (System.currentTimeMillis() - startTime) + "ms");
return reportResults;
}
|
[
"public",
"Results",
"analyze",
"(",
"RuleSet",
"ruleSet",
")",
"{",
"long",
"startTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"DirectoryResults",
"reportResults",
"=",
"new",
"DirectoryResults",
"(",
")",
";",
"int",
"numThreads",
"=",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"availableProcessors",
"(",
")",
"-",
"1",
";",
"numThreads",
"=",
"numThreads",
">",
"0",
"?",
"numThreads",
":",
"1",
";",
"ExecutorService",
"pool",
"=",
"Executors",
".",
"newFixedThreadPool",
"(",
"numThreads",
")",
";",
"for",
"(",
"FileSet",
"fileSet",
":",
"fileSets",
")",
"{",
"processFileSet",
"(",
"fileSet",
",",
"ruleSet",
",",
"pool",
")",
";",
"}",
"pool",
".",
"shutdown",
"(",
")",
";",
"try",
"{",
"boolean",
"completed",
"=",
"pool",
".",
"awaitTermination",
"(",
"POOL_TIMEOUT_SECONDS",
",",
"TimeUnit",
".",
"SECONDS",
")",
";",
"if",
"(",
"!",
"completed",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Thread Pool terminated before comp<FileResults>letion\"",
")",
";",
"}",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Thread Pool interrupted before completion\"",
")",
";",
"}",
"addDirectoryResults",
"(",
"reportResults",
")",
";",
"LOG",
".",
"info",
"(",
"\"Analysis time=\"",
"+",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"startTime",
")",
"+",
"\"ms\"",
")",
";",
"return",
"reportResults",
";",
"}"
] |
Analyze all source code using the specified RuleSet and return the report results.
@param ruleSet - the RuleSet to apply to each source component; must not be null.
@return the results from applying the RuleSet to all of the source
|
[
"Analyze",
"all",
"source",
"code",
"using",
"the",
"specified",
"RuleSet",
"and",
"return",
"the",
"report",
"results",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/ant/AntFileSetSourceAnalyzer.java#L95-L122
|
158,619 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isPredefinedConstant
|
private static boolean isPredefinedConstant(Expression expression) {
if (expression instanceof PropertyExpression) {
Expression object = ((PropertyExpression) expression).getObjectExpression();
Expression property = ((PropertyExpression) expression).getProperty();
if (object instanceof VariableExpression) {
List<String> predefinedConstantNames = PREDEFINED_CONSTANTS.get(((VariableExpression) object).getName());
if (predefinedConstantNames != null && predefinedConstantNames.contains(property.getText())) {
return true;
}
}
}
return false;
}
|
java
|
private static boolean isPredefinedConstant(Expression expression) {
if (expression instanceof PropertyExpression) {
Expression object = ((PropertyExpression) expression).getObjectExpression();
Expression property = ((PropertyExpression) expression).getProperty();
if (object instanceof VariableExpression) {
List<String> predefinedConstantNames = PREDEFINED_CONSTANTS.get(((VariableExpression) object).getName());
if (predefinedConstantNames != null && predefinedConstantNames.contains(property.getText())) {
return true;
}
}
}
return false;
}
|
[
"private",
"static",
"boolean",
"isPredefinedConstant",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"PropertyExpression",
")",
"{",
"Expression",
"object",
"=",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getObjectExpression",
"(",
")",
";",
"Expression",
"property",
"=",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getProperty",
"(",
")",
";",
"if",
"(",
"object",
"instanceof",
"VariableExpression",
")",
"{",
"List",
"<",
"String",
">",
"predefinedConstantNames",
"=",
"PREDEFINED_CONSTANTS",
".",
"get",
"(",
"(",
"(",
"VariableExpression",
")",
"object",
")",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"predefinedConstantNames",
"!=",
"null",
"&&",
"predefinedConstantNames",
".",
"contains",
"(",
"property",
".",
"getText",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Tells you if the expression is a predefined constant like TRUE or FALSE.
@param expression
any expression
@return
as described
|
[
"Tells",
"you",
"if",
"the",
"expression",
"is",
"a",
"predefined",
"constant",
"like",
"TRUE",
"or",
"FALSE",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L85-L98
|
158,620 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isMapLiteralWithOnlyConstantValues
|
public static boolean isMapLiteralWithOnlyConstantValues(Expression expression) {
if (expression instanceof MapExpression) {
List<MapEntryExpression> entries = ((MapExpression) expression).getMapEntryExpressions();
for (MapEntryExpression entry : entries) {
if (!isConstantOrConstantLiteral(entry.getKeyExpression()) ||
!isConstantOrConstantLiteral(entry.getValueExpression())) {
return false;
}
}
return true;
}
return false;
}
|
java
|
public static boolean isMapLiteralWithOnlyConstantValues(Expression expression) {
if (expression instanceof MapExpression) {
List<MapEntryExpression> entries = ((MapExpression) expression).getMapEntryExpressions();
for (MapEntryExpression entry : entries) {
if (!isConstantOrConstantLiteral(entry.getKeyExpression()) ||
!isConstantOrConstantLiteral(entry.getValueExpression())) {
return false;
}
}
return true;
}
return false;
}
|
[
"public",
"static",
"boolean",
"isMapLiteralWithOnlyConstantValues",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"MapExpression",
")",
"{",
"List",
"<",
"MapEntryExpression",
">",
"entries",
"=",
"(",
"(",
"MapExpression",
")",
"expression",
")",
".",
"getMapEntryExpressions",
"(",
")",
";",
"for",
"(",
"MapEntryExpression",
"entry",
":",
"entries",
")",
"{",
"if",
"(",
"!",
"isConstantOrConstantLiteral",
"(",
"entry",
".",
"getKeyExpression",
"(",
")",
")",
"||",
"!",
"isConstantOrConstantLiteral",
"(",
"entry",
".",
"getValueExpression",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if a Map literal that contains only entries where both key and value are constants.
@param expression - any expression
|
[
"Returns",
"true",
"if",
"a",
"Map",
"literal",
"that",
"contains",
"only",
"entries",
"where",
"both",
"key",
"and",
"value",
"are",
"constants",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L116-L128
|
158,621 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isListLiteralWithOnlyConstantValues
|
public static boolean isListLiteralWithOnlyConstantValues(Expression expression) {
if (expression instanceof ListExpression) {
List<Expression> expressions = ((ListExpression) expression).getExpressions();
for (Expression e : expressions) {
if (!isConstantOrConstantLiteral(e)) {
return false;
}
}
return true;
}
return false;
}
|
java
|
public static boolean isListLiteralWithOnlyConstantValues(Expression expression) {
if (expression instanceof ListExpression) {
List<Expression> expressions = ((ListExpression) expression).getExpressions();
for (Expression e : expressions) {
if (!isConstantOrConstantLiteral(e)) {
return false;
}
}
return true;
}
return false;
}
|
[
"public",
"static",
"boolean",
"isListLiteralWithOnlyConstantValues",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"ListExpression",
")",
"{",
"List",
"<",
"Expression",
">",
"expressions",
"=",
"(",
"(",
"ListExpression",
")",
"expression",
")",
".",
"getExpressions",
"(",
")",
";",
"for",
"(",
"Expression",
"e",
":",
"expressions",
")",
"{",
"if",
"(",
"!",
"isConstantOrConstantLiteral",
"(",
"e",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if a List literal that contains only entries that are constants.
@param expression - any expression
|
[
"Returns",
"true",
"if",
"a",
"List",
"literal",
"that",
"contains",
"only",
"entries",
"that",
"are",
"constants",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L134-L145
|
158,622 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isConstant
|
public static boolean isConstant(Expression expression, Object expected) {
return expression instanceof ConstantExpression && expected.equals(((ConstantExpression) expression).getValue());
}
|
java
|
public static boolean isConstant(Expression expression, Object expected) {
return expression instanceof ConstantExpression && expected.equals(((ConstantExpression) expression).getValue());
}
|
[
"public",
"static",
"boolean",
"isConstant",
"(",
"Expression",
"expression",
",",
"Object",
"expected",
")",
"{",
"return",
"expression",
"instanceof",
"ConstantExpression",
"&&",
"expected",
".",
"equals",
"(",
"(",
"(",
"ConstantExpression",
")",
"expression",
")",
".",
"getValue",
"(",
")",
")",
";",
"}"
] |
Tells you if an expression is the expected constant.
@param expression
any expression
@param expected
the expected int or String
@return
as described
|
[
"Tells",
"you",
"if",
"an",
"expression",
"is",
"the",
"expected",
"constant",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L156-L158
|
158,623 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getMethodArguments
|
public static List<? extends Expression> getMethodArguments(ASTNode methodCall) {
if (methodCall instanceof ConstructorCallExpression) {
return extractExpressions(((ConstructorCallExpression) methodCall).getArguments());
} else if (methodCall instanceof MethodCallExpression) {
return extractExpressions(((MethodCallExpression) methodCall).getArguments());
} else if (methodCall instanceof StaticMethodCallExpression) {
return extractExpressions(((StaticMethodCallExpression) methodCall).getArguments());
} else if (respondsTo(methodCall, "getArguments")) {
throw new RuntimeException(); // TODO: remove, should never happen
}
return new ArrayList<Expression>();
}
|
java
|
public static List<? extends Expression> getMethodArguments(ASTNode methodCall) {
if (methodCall instanceof ConstructorCallExpression) {
return extractExpressions(((ConstructorCallExpression) methodCall).getArguments());
} else if (methodCall instanceof MethodCallExpression) {
return extractExpressions(((MethodCallExpression) methodCall).getArguments());
} else if (methodCall instanceof StaticMethodCallExpression) {
return extractExpressions(((StaticMethodCallExpression) methodCall).getArguments());
} else if (respondsTo(methodCall, "getArguments")) {
throw new RuntimeException(); // TODO: remove, should never happen
}
return new ArrayList<Expression>();
}
|
[
"public",
"static",
"List",
"<",
"?",
"extends",
"Expression",
">",
"getMethodArguments",
"(",
"ASTNode",
"methodCall",
")",
"{",
"if",
"(",
"methodCall",
"instanceof",
"ConstructorCallExpression",
")",
"{",
"return",
"extractExpressions",
"(",
"(",
"(",
"ConstructorCallExpression",
")",
"methodCall",
")",
".",
"getArguments",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"methodCall",
"instanceof",
"MethodCallExpression",
")",
"{",
"return",
"extractExpressions",
"(",
"(",
"(",
"MethodCallExpression",
")",
"methodCall",
")",
".",
"getArguments",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"methodCall",
"instanceof",
"StaticMethodCallExpression",
")",
"{",
"return",
"extractExpressions",
"(",
"(",
"(",
"StaticMethodCallExpression",
")",
"methodCall",
")",
".",
"getArguments",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"respondsTo",
"(",
"methodCall",
",",
"\"getArguments\"",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
")",
";",
"// TODO: remove, should never happen\r",
"}",
"return",
"new",
"ArrayList",
"<",
"Expression",
">",
"(",
")",
";",
"}"
] |
Return the List of Arguments for the specified MethodCallExpression or a ConstructorCallExpression.
The returned List contains either ConstantExpression or MapEntryExpression objects.
@param methodCall - the AST MethodCallExpression or ConstructorCalLExpression
@return the List of argument objects
|
[
"Return",
"the",
"List",
"of",
"Arguments",
"for",
"the",
"specified",
"MethodCallExpression",
"or",
"a",
"ConstructorCallExpression",
".",
"The",
"returned",
"List",
"contains",
"either",
"ConstantExpression",
"or",
"MapEntryExpression",
"objects",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L226-L237
|
158,624 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isMethodNamed
|
public static boolean isMethodNamed(MethodCallExpression methodCall, String methodNamePattern, Integer numArguments) {
Expression method = methodCall.getMethod();
// !important: performance enhancement
boolean IS_NAME_MATCH = false;
if (method instanceof ConstantExpression) {
if (((ConstantExpression) method).getValue() instanceof String) {
IS_NAME_MATCH = ((String)((ConstantExpression) method).getValue()).matches(methodNamePattern);
}
}
if (IS_NAME_MATCH && numArguments != null) {
return AstUtil.getMethodArguments(methodCall).size() == numArguments;
}
return IS_NAME_MATCH;
}
|
java
|
public static boolean isMethodNamed(MethodCallExpression methodCall, String methodNamePattern, Integer numArguments) {
Expression method = methodCall.getMethod();
// !important: performance enhancement
boolean IS_NAME_MATCH = false;
if (method instanceof ConstantExpression) {
if (((ConstantExpression) method).getValue() instanceof String) {
IS_NAME_MATCH = ((String)((ConstantExpression) method).getValue()).matches(methodNamePattern);
}
}
if (IS_NAME_MATCH && numArguments != null) {
return AstUtil.getMethodArguments(methodCall).size() == numArguments;
}
return IS_NAME_MATCH;
}
|
[
"public",
"static",
"boolean",
"isMethodNamed",
"(",
"MethodCallExpression",
"methodCall",
",",
"String",
"methodNamePattern",
",",
"Integer",
"numArguments",
")",
"{",
"Expression",
"method",
"=",
"methodCall",
".",
"getMethod",
"(",
")",
";",
"// !important: performance enhancement\r",
"boolean",
"IS_NAME_MATCH",
"=",
"false",
";",
"if",
"(",
"method",
"instanceof",
"ConstantExpression",
")",
"{",
"if",
"(",
"(",
"(",
"ConstantExpression",
")",
"method",
")",
".",
"getValue",
"(",
")",
"instanceof",
"String",
")",
"{",
"IS_NAME_MATCH",
"=",
"(",
"(",
"String",
")",
"(",
"(",
"ConstantExpression",
")",
"method",
")",
".",
"getValue",
"(",
")",
")",
".",
"matches",
"(",
"methodNamePattern",
")",
";",
"}",
"}",
"if",
"(",
"IS_NAME_MATCH",
"&&",
"numArguments",
"!=",
"null",
")",
"{",
"return",
"AstUtil",
".",
"getMethodArguments",
"(",
"methodCall",
")",
".",
"size",
"(",
")",
"==",
"numArguments",
";",
"}",
"return",
"IS_NAME_MATCH",
";",
"}"
] |
Return true only if the MethodCallExpression represents a method call for the specified method name
@param methodCall - the AST MethodCallExpression
@param methodNamePattern - the expected name of the method being called
@param numArguments - The number of expected arguments
@return true only if the method call name matches
|
[
"Return",
"true",
"only",
"if",
"the",
"MethodCallExpression",
"represents",
"a",
"method",
"call",
"for",
"the",
"specified",
"method",
"name"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L425-L440
|
158,625 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isConstructorCall
|
public static boolean isConstructorCall(Expression expression, List<String> classNames) {
return expression instanceof ConstructorCallExpression && classNames.contains(expression.getType().getName());
}
|
java
|
public static boolean isConstructorCall(Expression expression, List<String> classNames) {
return expression instanceof ConstructorCallExpression && classNames.contains(expression.getType().getName());
}
|
[
"public",
"static",
"boolean",
"isConstructorCall",
"(",
"Expression",
"expression",
",",
"List",
"<",
"String",
">",
"classNames",
")",
"{",
"return",
"expression",
"instanceof",
"ConstructorCallExpression",
"&&",
"classNames",
".",
"contains",
"(",
"expression",
".",
"getType",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}"
] |
Return true if the expression is a constructor call on any of the named classes, with any number of parameters.
@param expression - the expression
@param classNames - the possible List of class names
@return as described
|
[
"Return",
"true",
"if",
"the",
"expression",
"is",
"a",
"constructor",
"call",
"on",
"any",
"of",
"the",
"named",
"classes",
"with",
"any",
"number",
"of",
"parameters",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L452-L454
|
158,626 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isConstructorCall
|
public static boolean isConstructorCall(Expression expression, String classNamePattern) {
return expression instanceof ConstructorCallExpression && expression.getType().getName().matches(classNamePattern);
}
|
java
|
public static boolean isConstructorCall(Expression expression, String classNamePattern) {
return expression instanceof ConstructorCallExpression && expression.getType().getName().matches(classNamePattern);
}
|
[
"public",
"static",
"boolean",
"isConstructorCall",
"(",
"Expression",
"expression",
",",
"String",
"classNamePattern",
")",
"{",
"return",
"expression",
"instanceof",
"ConstructorCallExpression",
"&&",
"expression",
".",
"getType",
"(",
")",
".",
"getName",
"(",
")",
".",
"matches",
"(",
"classNamePattern",
")",
";",
"}"
] |
Return true if the expression is a constructor call on a class that matches the supplied.
@param expression - the expression
@param classNamePattern - the possible List of class names
@return as described
|
[
"Return",
"true",
"if",
"the",
"expression",
"is",
"a",
"constructor",
"call",
"on",
"a",
"class",
"that",
"matches",
"the",
"supplied",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L462-L464
|
158,627 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getAnnotation
|
public static AnnotationNode getAnnotation(AnnotatedNode node, String name) {
List<AnnotationNode> annotations = node.getAnnotations();
for (AnnotationNode annot : annotations) {
if (annot.getClassNode().getName().equals(name)) {
return annot;
}
}
return null;
}
|
java
|
public static AnnotationNode getAnnotation(AnnotatedNode node, String name) {
List<AnnotationNode> annotations = node.getAnnotations();
for (AnnotationNode annot : annotations) {
if (annot.getClassNode().getName().equals(name)) {
return annot;
}
}
return null;
}
|
[
"public",
"static",
"AnnotationNode",
"getAnnotation",
"(",
"AnnotatedNode",
"node",
",",
"String",
"name",
")",
"{",
"List",
"<",
"AnnotationNode",
">",
"annotations",
"=",
"node",
".",
"getAnnotations",
"(",
")",
";",
"for",
"(",
"AnnotationNode",
"annot",
":",
"annotations",
")",
"{",
"if",
"(",
"annot",
".",
"getClassNode",
"(",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"return",
"annot",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Return the AnnotationNode for the named annotation, or else null.
Supports Groovy 1.5 and Groovy 1.6.
@param node - the AnnotatedNode
@param name - the name of the annotation
@return the AnnotationNode or else null
|
[
"Return",
"the",
"AnnotationNode",
"for",
"the",
"named",
"annotation",
"or",
"else",
"null",
".",
"Supports",
"Groovy",
"1",
".",
"5",
"and",
"Groovy",
"1",
".",
"6",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L473-L481
|
158,628 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.hasAnnotation
|
public static boolean hasAnnotation(AnnotatedNode node, String name) {
return AstUtil.getAnnotation(node, name) != null;
}
|
java
|
public static boolean hasAnnotation(AnnotatedNode node, String name) {
return AstUtil.getAnnotation(node, name) != null;
}
|
[
"public",
"static",
"boolean",
"hasAnnotation",
"(",
"AnnotatedNode",
"node",
",",
"String",
"name",
")",
"{",
"return",
"AstUtil",
".",
"getAnnotation",
"(",
"node",
",",
"name",
")",
"!=",
"null",
";",
"}"
] |
Return true only if the node has the named annotation
@param node - the AST Node to check
@param name - the name of the annotation
@return true only if the node has the named annotation
|
[
"Return",
"true",
"only",
"if",
"the",
"node",
"has",
"the",
"named",
"annotation"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L489-L491
|
158,629 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.hasAnyAnnotation
|
public static boolean hasAnyAnnotation(AnnotatedNode node, String... names) {
for (String name : names) {
if (hasAnnotation(node, name)) {
return true;
}
}
return false;
}
|
java
|
public static boolean hasAnyAnnotation(AnnotatedNode node, String... names) {
for (String name : names) {
if (hasAnnotation(node, name)) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"boolean",
"hasAnyAnnotation",
"(",
"AnnotatedNode",
"node",
",",
"String",
"...",
"names",
")",
"{",
"for",
"(",
"String",
"name",
":",
"names",
")",
"{",
"if",
"(",
"hasAnnotation",
"(",
"node",
",",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Return true only if the node has any of the named annotations
@param node - the AST Node to check
@param names - the names of the annotations
@return true only if the node has any of the named annotations
|
[
"Return",
"true",
"only",
"if",
"the",
"node",
"has",
"any",
"of",
"the",
"named",
"annotations"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L499-L506
|
158,630 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getVariableExpressions
|
public static List<Expression> getVariableExpressions(DeclarationExpression declarationExpression) {
Expression leftExpression = declarationExpression.getLeftExpression();
// !important: performance enhancement
if (leftExpression instanceof ArrayExpression) {
List<Expression> expressions = ((ArrayExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof ListExpression) {
List<Expression> expressions = ((ListExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof VariableExpression) {
return Arrays.asList(leftExpression);
}
// todo: write warning
return Collections.emptyList();
}
|
java
|
public static List<Expression> getVariableExpressions(DeclarationExpression declarationExpression) {
Expression leftExpression = declarationExpression.getLeftExpression();
// !important: performance enhancement
if (leftExpression instanceof ArrayExpression) {
List<Expression> expressions = ((ArrayExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof ListExpression) {
List<Expression> expressions = ((ListExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) leftExpression).getExpressions();
return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
} else if (leftExpression instanceof VariableExpression) {
return Arrays.asList(leftExpression);
}
// todo: write warning
return Collections.emptyList();
}
|
[
"public",
"static",
"List",
"<",
"Expression",
">",
"getVariableExpressions",
"(",
"DeclarationExpression",
"declarationExpression",
")",
"{",
"Expression",
"leftExpression",
"=",
"declarationExpression",
".",
"getLeftExpression",
"(",
")",
";",
"// !important: performance enhancement\r",
"if",
"(",
"leftExpression",
"instanceof",
"ArrayExpression",
")",
"{",
"List",
"<",
"Expression",
">",
"expressions",
"=",
"(",
"(",
"ArrayExpression",
")",
"leftExpression",
")",
".",
"getExpressions",
"(",
")",
";",
"return",
"expressions",
".",
"isEmpty",
"(",
")",
"?",
"Arrays",
".",
"asList",
"(",
"leftExpression",
")",
":",
"expressions",
";",
"}",
"else",
"if",
"(",
"leftExpression",
"instanceof",
"ListExpression",
")",
"{",
"List",
"<",
"Expression",
">",
"expressions",
"=",
"(",
"(",
"ListExpression",
")",
"leftExpression",
")",
".",
"getExpressions",
"(",
")",
";",
"return",
"expressions",
".",
"isEmpty",
"(",
")",
"?",
"Arrays",
".",
"asList",
"(",
"leftExpression",
")",
":",
"expressions",
";",
"}",
"else",
"if",
"(",
"leftExpression",
"instanceof",
"TupleExpression",
")",
"{",
"List",
"<",
"Expression",
">",
"expressions",
"=",
"(",
"(",
"TupleExpression",
")",
"leftExpression",
")",
".",
"getExpressions",
"(",
")",
";",
"return",
"expressions",
".",
"isEmpty",
"(",
")",
"?",
"Arrays",
".",
"asList",
"(",
"leftExpression",
")",
":",
"expressions",
";",
"}",
"else",
"if",
"(",
"leftExpression",
"instanceof",
"VariableExpression",
")",
"{",
"return",
"Arrays",
".",
"asList",
"(",
"leftExpression",
")",
";",
"}",
"// todo: write warning\r",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}"
] |
Return the List of VariableExpression objects referenced by the specified DeclarationExpression.
@param declarationExpression - the DeclarationExpression
@return the List of VariableExpression objects
|
[
"Return",
"the",
"List",
"of",
"VariableExpression",
"objects",
"referenced",
"by",
"the",
"specified",
"DeclarationExpression",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L513-L531
|
158,631 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isFinalVariable
|
public static boolean isFinalVariable(DeclarationExpression declarationExpression, SourceCode sourceCode) {
if (isFromGeneratedSourceCode(declarationExpression)) {
return false;
}
List<Expression> variableExpressions = getVariableExpressions(declarationExpression);
if (!variableExpressions.isEmpty()) {
Expression variableExpression = variableExpressions.get(0);
int startOfDeclaration = declarationExpression.getColumnNumber();
int startOfVariableName = variableExpression.getColumnNumber();
int sourceLineNumber = findFirstNonAnnotationLine(declarationExpression, sourceCode);
String sourceLine = sourceCode.getLines().get(sourceLineNumber-1);
String modifiers = (startOfDeclaration >= 0 && startOfVariableName >= 0 && sourceLine.length() >= startOfVariableName) ?
sourceLine.substring(startOfDeclaration - 1, startOfVariableName - 1) : "";
return modifiers.contains("final");
}
return false;
}
|
java
|
public static boolean isFinalVariable(DeclarationExpression declarationExpression, SourceCode sourceCode) {
if (isFromGeneratedSourceCode(declarationExpression)) {
return false;
}
List<Expression> variableExpressions = getVariableExpressions(declarationExpression);
if (!variableExpressions.isEmpty()) {
Expression variableExpression = variableExpressions.get(0);
int startOfDeclaration = declarationExpression.getColumnNumber();
int startOfVariableName = variableExpression.getColumnNumber();
int sourceLineNumber = findFirstNonAnnotationLine(declarationExpression, sourceCode);
String sourceLine = sourceCode.getLines().get(sourceLineNumber-1);
String modifiers = (startOfDeclaration >= 0 && startOfVariableName >= 0 && sourceLine.length() >= startOfVariableName) ?
sourceLine.substring(startOfDeclaration - 1, startOfVariableName - 1) : "";
return modifiers.contains("final");
}
return false;
}
|
[
"public",
"static",
"boolean",
"isFinalVariable",
"(",
"DeclarationExpression",
"declarationExpression",
",",
"SourceCode",
"sourceCode",
")",
"{",
"if",
"(",
"isFromGeneratedSourceCode",
"(",
"declarationExpression",
")",
")",
"{",
"return",
"false",
";",
"}",
"List",
"<",
"Expression",
">",
"variableExpressions",
"=",
"getVariableExpressions",
"(",
"declarationExpression",
")",
";",
"if",
"(",
"!",
"variableExpressions",
".",
"isEmpty",
"(",
")",
")",
"{",
"Expression",
"variableExpression",
"=",
"variableExpressions",
".",
"get",
"(",
"0",
")",
";",
"int",
"startOfDeclaration",
"=",
"declarationExpression",
".",
"getColumnNumber",
"(",
")",
";",
"int",
"startOfVariableName",
"=",
"variableExpression",
".",
"getColumnNumber",
"(",
")",
";",
"int",
"sourceLineNumber",
"=",
"findFirstNonAnnotationLine",
"(",
"declarationExpression",
",",
"sourceCode",
")",
";",
"String",
"sourceLine",
"=",
"sourceCode",
".",
"getLines",
"(",
")",
".",
"get",
"(",
"sourceLineNumber",
"-",
"1",
")",
";",
"String",
"modifiers",
"=",
"(",
"startOfDeclaration",
">=",
"0",
"&&",
"startOfVariableName",
">=",
"0",
"&&",
"sourceLine",
".",
"length",
"(",
")",
">=",
"startOfVariableName",
")",
"?",
"sourceLine",
".",
"substring",
"(",
"startOfDeclaration",
"-",
"1",
",",
"startOfVariableName",
"-",
"1",
")",
":",
"\"\"",
";",
"return",
"modifiers",
".",
"contains",
"(",
"\"final\"",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Return true if the DeclarationExpression represents a 'final' variable declaration.
NOTE: THIS IS A WORKAROUND.
There does not seem to be an easy way to determine whether the 'final' modifier has been
specified for a variable declaration. Return true if the 'final' is present before the variable name.
|
[
"Return",
"true",
"if",
"the",
"DeclarationExpression",
"represents",
"a",
"final",
"variable",
"declaration",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L541-L558
|
158,632 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isTrue
|
public static boolean isTrue(Expression expression) {
if (expression == null) {
return false;
}
if (expression instanceof PropertyExpression
&& classNodeImplementsType(((PropertyExpression) expression).getObjectExpression().getType(), Boolean.class)) {
if (((PropertyExpression) expression).getProperty() instanceof ConstantExpression
&& "TRUE".equals(((ConstantExpression) ((PropertyExpression) expression).getProperty()).getValue())) {
return true;
}
}
return ((expression instanceof ConstantExpression) && ((ConstantExpression) expression).isTrueExpression()) ||
"Boolean.TRUE".equals(expression.getText());
}
|
java
|
public static boolean isTrue(Expression expression) {
if (expression == null) {
return false;
}
if (expression instanceof PropertyExpression
&& classNodeImplementsType(((PropertyExpression) expression).getObjectExpression().getType(), Boolean.class)) {
if (((PropertyExpression) expression).getProperty() instanceof ConstantExpression
&& "TRUE".equals(((ConstantExpression) ((PropertyExpression) expression).getProperty()).getValue())) {
return true;
}
}
return ((expression instanceof ConstantExpression) && ((ConstantExpression) expression).isTrueExpression()) ||
"Boolean.TRUE".equals(expression.getText());
}
|
[
"public",
"static",
"boolean",
"isTrue",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"expression",
"instanceof",
"PropertyExpression",
"&&",
"classNodeImplementsType",
"(",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getObjectExpression",
"(",
")",
".",
"getType",
"(",
")",
",",
"Boolean",
".",
"class",
")",
")",
"{",
"if",
"(",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getProperty",
"(",
")",
"instanceof",
"ConstantExpression",
"&&",
"\"TRUE\"",
".",
"equals",
"(",
"(",
"(",
"ConstantExpression",
")",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getProperty",
"(",
")",
")",
".",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"(",
"(",
"expression",
"instanceof",
"ConstantExpression",
")",
"&&",
"(",
"(",
"ConstantExpression",
")",
"expression",
")",
".",
"isTrueExpression",
"(",
")",
")",
"||",
"\"Boolean.TRUE\"",
".",
"equals",
"(",
"expression",
".",
"getText",
"(",
")",
")",
";",
"}"
] |
Tells you if the expression is true, which can be true or Boolean.TRUE.
@param expression
expression
@return
as described
|
[
"Tells",
"you",
"if",
"the",
"expression",
"is",
"true",
"which",
"can",
"be",
"true",
"or",
"Boolean",
".",
"TRUE",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L574-L587
|
158,633 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isFalse
|
public static boolean isFalse(Expression expression) {
if (expression == null) {
return false;
}
if (expression instanceof PropertyExpression && classNodeImplementsType(((PropertyExpression) expression).getObjectExpression().getType(), Boolean.class)) {
if (((PropertyExpression) expression).getProperty() instanceof ConstantExpression
&& "FALSE".equals(((ConstantExpression) ((PropertyExpression) expression).getProperty()).getValue())) {
return true;
}
}
return ((expression instanceof ConstantExpression) && ((ConstantExpression) expression).isFalseExpression())
|| "Boolean.FALSE".equals(expression.getText());
}
|
java
|
public static boolean isFalse(Expression expression) {
if (expression == null) {
return false;
}
if (expression instanceof PropertyExpression && classNodeImplementsType(((PropertyExpression) expression).getObjectExpression().getType(), Boolean.class)) {
if (((PropertyExpression) expression).getProperty() instanceof ConstantExpression
&& "FALSE".equals(((ConstantExpression) ((PropertyExpression) expression).getProperty()).getValue())) {
return true;
}
}
return ((expression instanceof ConstantExpression) && ((ConstantExpression) expression).isFalseExpression())
|| "Boolean.FALSE".equals(expression.getText());
}
|
[
"public",
"static",
"boolean",
"isFalse",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"expression",
"instanceof",
"PropertyExpression",
"&&",
"classNodeImplementsType",
"(",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getObjectExpression",
"(",
")",
".",
"getType",
"(",
")",
",",
"Boolean",
".",
"class",
")",
")",
"{",
"if",
"(",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getProperty",
"(",
")",
"instanceof",
"ConstantExpression",
"&&",
"\"FALSE\"",
".",
"equals",
"(",
"(",
"(",
"ConstantExpression",
")",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"getProperty",
"(",
")",
")",
".",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"(",
"(",
"expression",
"instanceof",
"ConstantExpression",
")",
"&&",
"(",
"(",
"ConstantExpression",
")",
"expression",
")",
".",
"isFalseExpression",
"(",
")",
")",
"||",
"\"Boolean.FALSE\"",
".",
"equals",
"(",
"expression",
".",
"getText",
"(",
")",
")",
";",
"}"
] |
Tells you if the expression is the false expression, either literal or constant.
@param expression
expression
@return
as described
|
[
"Tells",
"you",
"if",
"the",
"expression",
"is",
"the",
"false",
"expression",
"either",
"literal",
"or",
"constant",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L618-L630
|
158,634 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.respondsTo
|
public static boolean respondsTo(Object object, String methodName) {
MetaClass metaClass = DefaultGroovyMethods.getMetaClass(object);
if (!metaClass.respondsTo(object, methodName).isEmpty()) {
return true;
}
Map properties = DefaultGroovyMethods.getProperties(object);
return properties.containsKey(methodName);
}
|
java
|
public static boolean respondsTo(Object object, String methodName) {
MetaClass metaClass = DefaultGroovyMethods.getMetaClass(object);
if (!metaClass.respondsTo(object, methodName).isEmpty()) {
return true;
}
Map properties = DefaultGroovyMethods.getProperties(object);
return properties.containsKey(methodName);
}
|
[
"public",
"static",
"boolean",
"respondsTo",
"(",
"Object",
"object",
",",
"String",
"methodName",
")",
"{",
"MetaClass",
"metaClass",
"=",
"DefaultGroovyMethods",
".",
"getMetaClass",
"(",
"object",
")",
";",
"if",
"(",
"!",
"metaClass",
".",
"respondsTo",
"(",
"object",
",",
"methodName",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"Map",
"properties",
"=",
"DefaultGroovyMethods",
".",
"getProperties",
"(",
"object",
")",
";",
"return",
"properties",
".",
"containsKey",
"(",
"methodName",
")",
";",
"}"
] |
Return true only if the specified object responds to the named method
@param object - the object to check
@param methodName - the name of the method
@return true if the object responds to the named method
|
[
"Return",
"true",
"only",
"if",
"the",
"specified",
"object",
"responds",
"to",
"the",
"named",
"method"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L638-L645
|
158,635 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.classNodeImplementsType
|
public static boolean classNodeImplementsType(ClassNode node, Class target) {
ClassNode targetNode = ClassHelper.make(target);
if (node.implementsInterface(targetNode)) {
return true;
}
if (node.isDerivedFrom(targetNode)) {
return true;
}
if (node.getName().equals(target.getName())) {
return true;
}
if (node.getName().equals(target.getSimpleName())) {
return true;
}
if (node.getSuperClass() != null && node.getSuperClass().getName().equals(target.getName())) {
return true;
}
if (node.getSuperClass() != null && node.getSuperClass().getName().equals(target.getSimpleName())) {
return true;
}
if (node.getInterfaces() != null) {
for (ClassNode declaredInterface : node.getInterfaces()) {
if (classNodeImplementsType(declaredInterface, target)) {
return true;
}
}
}
return false;
}
|
java
|
public static boolean classNodeImplementsType(ClassNode node, Class target) {
ClassNode targetNode = ClassHelper.make(target);
if (node.implementsInterface(targetNode)) {
return true;
}
if (node.isDerivedFrom(targetNode)) {
return true;
}
if (node.getName().equals(target.getName())) {
return true;
}
if (node.getName().equals(target.getSimpleName())) {
return true;
}
if (node.getSuperClass() != null && node.getSuperClass().getName().equals(target.getName())) {
return true;
}
if (node.getSuperClass() != null && node.getSuperClass().getName().equals(target.getSimpleName())) {
return true;
}
if (node.getInterfaces() != null) {
for (ClassNode declaredInterface : node.getInterfaces()) {
if (classNodeImplementsType(declaredInterface, target)) {
return true;
}
}
}
return false;
}
|
[
"public",
"static",
"boolean",
"classNodeImplementsType",
"(",
"ClassNode",
"node",
",",
"Class",
"target",
")",
"{",
"ClassNode",
"targetNode",
"=",
"ClassHelper",
".",
"make",
"(",
"target",
")",
";",
"if",
"(",
"node",
".",
"implementsInterface",
"(",
"targetNode",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"isDerivedFrom",
"(",
"targetNode",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"target",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"target",
".",
"getSimpleName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"getSuperClass",
"(",
")",
"!=",
"null",
"&&",
"node",
".",
"getSuperClass",
"(",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"target",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"getSuperClass",
"(",
")",
"!=",
"null",
"&&",
"node",
".",
"getSuperClass",
"(",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"target",
".",
"getSimpleName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"getInterfaces",
"(",
")",
"!=",
"null",
")",
"{",
"for",
"(",
"ClassNode",
"declaredInterface",
":",
"node",
".",
"getInterfaces",
"(",
")",
")",
"{",
"if",
"(",
"classNodeImplementsType",
"(",
"declaredInterface",
",",
"target",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
This method tells you if a ClassNode implements or extends a certain class.
@param node
the node
@param target
the class
@return
true if the class node 'is a' target
|
[
"This",
"method",
"tells",
"you",
"if",
"a",
"ClassNode",
"implements",
"or",
"extends",
"a",
"certain",
"class",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L656-L684
|
158,636 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isClosureDeclaration
|
public static boolean isClosureDeclaration(ASTNode expression) {
if (expression instanceof DeclarationExpression) {
if (((DeclarationExpression) expression).getRightExpression() instanceof ClosureExpression) {
return true;
}
}
if (expression instanceof FieldNode) {
ClassNode type = ((FieldNode) expression).getType();
if (AstUtil.classNodeImplementsType(type, Closure.class)) {
return true;
} else if (((FieldNode) expression).getInitialValueExpression() instanceof ClosureExpression) {
return true;
}
}
return false;
}
|
java
|
public static boolean isClosureDeclaration(ASTNode expression) {
if (expression instanceof DeclarationExpression) {
if (((DeclarationExpression) expression).getRightExpression() instanceof ClosureExpression) {
return true;
}
}
if (expression instanceof FieldNode) {
ClassNode type = ((FieldNode) expression).getType();
if (AstUtil.classNodeImplementsType(type, Closure.class)) {
return true;
} else if (((FieldNode) expression).getInitialValueExpression() instanceof ClosureExpression) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"boolean",
"isClosureDeclaration",
"(",
"ASTNode",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"DeclarationExpression",
")",
"{",
"if",
"(",
"(",
"(",
"DeclarationExpression",
")",
"expression",
")",
".",
"getRightExpression",
"(",
")",
"instanceof",
"ClosureExpression",
")",
"{",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"expression",
"instanceof",
"FieldNode",
")",
"{",
"ClassNode",
"type",
"=",
"(",
"(",
"FieldNode",
")",
"expression",
")",
".",
"getType",
"(",
")",
";",
"if",
"(",
"AstUtil",
".",
"classNodeImplementsType",
"(",
"type",
",",
"Closure",
".",
"class",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"(",
"(",
"FieldNode",
")",
"expression",
")",
".",
"getInitialValueExpression",
"(",
")",
"instanceof",
"ClosureExpression",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the ASTNode is a declaration of a closure, either as a declaration
or a field.
@param expression
the target expression
@return
as described
|
[
"Returns",
"true",
"if",
"the",
"ASTNode",
"is",
"a",
"declaration",
"of",
"a",
"closure",
"either",
"as",
"a",
"declaration",
"or",
"a",
"field",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L694-L709
|
158,637 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getParameterNames
|
public static List<String> getParameterNames(MethodNode node) {
ArrayList<String> result = new ArrayList<String>();
if (node.getParameters() != null) {
for (Parameter parameter : node.getParameters()) {
result.add(parameter.getName());
}
}
return result;
}
|
java
|
public static List<String> getParameterNames(MethodNode node) {
ArrayList<String> result = new ArrayList<String>();
if (node.getParameters() != null) {
for (Parameter parameter : node.getParameters()) {
result.add(parameter.getName());
}
}
return result;
}
|
[
"public",
"static",
"List",
"<",
"String",
">",
"getParameterNames",
"(",
"MethodNode",
"node",
")",
"{",
"ArrayList",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"node",
".",
"getParameters",
"(",
")",
"!=",
"null",
")",
"{",
"for",
"(",
"Parameter",
"parameter",
":",
"node",
".",
"getParameters",
"(",
")",
")",
"{",
"result",
".",
"add",
"(",
"parameter",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Gets the parameter names of a method node.
@param node
the node to search parameter names on
@return
argument names, never null
|
[
"Gets",
"the",
"parameter",
"names",
"of",
"a",
"method",
"node",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L718-L727
|
158,638 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getArgumentNames
|
public static List<String> getArgumentNames(MethodCallExpression methodCall) {
ArrayList<String> result = new ArrayList<String>();
Expression arguments = methodCall.getArguments();
List<Expression> argExpressions = null;
if (arguments instanceof ArrayExpression) {
argExpressions = ((ArrayExpression) arguments).getExpressions();
} else if (arguments instanceof ListExpression) {
argExpressions = ((ListExpression) arguments).getExpressions();
} else if (arguments instanceof TupleExpression) {
argExpressions = ((TupleExpression) arguments).getExpressions();
} else {
LOG.warn("getArgumentNames arguments is not an expected type");
}
if (argExpressions != null) {
for (Expression exp : argExpressions) {
if (exp instanceof VariableExpression) {
result.add(((VariableExpression) exp).getName());
}
}
}
return result;
}
|
java
|
public static List<String> getArgumentNames(MethodCallExpression methodCall) {
ArrayList<String> result = new ArrayList<String>();
Expression arguments = methodCall.getArguments();
List<Expression> argExpressions = null;
if (arguments instanceof ArrayExpression) {
argExpressions = ((ArrayExpression) arguments).getExpressions();
} else if (arguments instanceof ListExpression) {
argExpressions = ((ListExpression) arguments).getExpressions();
} else if (arguments instanceof TupleExpression) {
argExpressions = ((TupleExpression) arguments).getExpressions();
} else {
LOG.warn("getArgumentNames arguments is not an expected type");
}
if (argExpressions != null) {
for (Expression exp : argExpressions) {
if (exp instanceof VariableExpression) {
result.add(((VariableExpression) exp).getName());
}
}
}
return result;
}
|
[
"public",
"static",
"List",
"<",
"String",
">",
"getArgumentNames",
"(",
"MethodCallExpression",
"methodCall",
")",
"{",
"ArrayList",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"Expression",
"arguments",
"=",
"methodCall",
".",
"getArguments",
"(",
")",
";",
"List",
"<",
"Expression",
">",
"argExpressions",
"=",
"null",
";",
"if",
"(",
"arguments",
"instanceof",
"ArrayExpression",
")",
"{",
"argExpressions",
"=",
"(",
"(",
"ArrayExpression",
")",
"arguments",
")",
".",
"getExpressions",
"(",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
"instanceof",
"ListExpression",
")",
"{",
"argExpressions",
"=",
"(",
"(",
"ListExpression",
")",
"arguments",
")",
".",
"getExpressions",
"(",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
"instanceof",
"TupleExpression",
")",
"{",
"argExpressions",
"=",
"(",
"(",
"TupleExpression",
")",
"arguments",
")",
".",
"getExpressions",
"(",
")",
";",
"}",
"else",
"{",
"LOG",
".",
"warn",
"(",
"\"getArgumentNames arguments is not an expected type\"",
")",
";",
"}",
"if",
"(",
"argExpressions",
"!=",
"null",
")",
"{",
"for",
"(",
"Expression",
"exp",
":",
"argExpressions",
")",
"{",
"if",
"(",
"exp",
"instanceof",
"VariableExpression",
")",
"{",
"result",
".",
"add",
"(",
"(",
"(",
"VariableExpression",
")",
"exp",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] |
Gets the argument names of a method call. If the arguments are not VariableExpressions then a null
will be returned.
@param methodCall
the method call to search
@return
a list of strings, never null, but some elements may be null
|
[
"Gets",
"the",
"argument",
"names",
"of",
"a",
"method",
"call",
".",
"If",
"the",
"arguments",
"are",
"not",
"VariableExpressions",
"then",
"a",
"null",
"will",
"be",
"returned",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L737-L760
|
158,639 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isSafe
|
public static boolean isSafe(Expression expression) {
if (expression instanceof MethodCallExpression) {
return ((MethodCallExpression) expression).isSafe();
}
if (expression instanceof PropertyExpression) {
return ((PropertyExpression) expression).isSafe();
}
return false;
}
|
java
|
public static boolean isSafe(Expression expression) {
if (expression instanceof MethodCallExpression) {
return ((MethodCallExpression) expression).isSafe();
}
if (expression instanceof PropertyExpression) {
return ((PropertyExpression) expression).isSafe();
}
return false;
}
|
[
"public",
"static",
"boolean",
"isSafe",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"MethodCallExpression",
")",
"{",
"return",
"(",
"(",
"MethodCallExpression",
")",
"expression",
")",
".",
"isSafe",
"(",
")",
";",
"}",
"if",
"(",
"expression",
"instanceof",
"PropertyExpression",
")",
"{",
"return",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"isSafe",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Tells you if the expression is a null safe dereference.
@param expression
expression
@return
true if is null safe dereference.
|
[
"Tells",
"you",
"if",
"the",
"expression",
"is",
"a",
"null",
"safe",
"dereference",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L802-L810
|
158,640 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isSpreadSafe
|
public static boolean isSpreadSafe(Expression expression) {
if (expression instanceof MethodCallExpression) {
return ((MethodCallExpression) expression).isSpreadSafe();
}
if (expression instanceof PropertyExpression) {
return ((PropertyExpression) expression).isSpreadSafe();
}
return false;
}
|
java
|
public static boolean isSpreadSafe(Expression expression) {
if (expression instanceof MethodCallExpression) {
return ((MethodCallExpression) expression).isSpreadSafe();
}
if (expression instanceof PropertyExpression) {
return ((PropertyExpression) expression).isSpreadSafe();
}
return false;
}
|
[
"public",
"static",
"boolean",
"isSpreadSafe",
"(",
"Expression",
"expression",
")",
"{",
"if",
"(",
"expression",
"instanceof",
"MethodCallExpression",
")",
"{",
"return",
"(",
"(",
"MethodCallExpression",
")",
"expression",
")",
".",
"isSpreadSafe",
"(",
")",
";",
"}",
"if",
"(",
"expression",
"instanceof",
"PropertyExpression",
")",
"{",
"return",
"(",
"(",
"PropertyExpression",
")",
"expression",
")",
".",
"isSpreadSafe",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Tells you if the expression is a spread operator call
@param expression
expression
@return
true if is spread expression
|
[
"Tells",
"you",
"if",
"the",
"expression",
"is",
"a",
"spread",
"operator",
"call"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L819-L827
|
158,641 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isMethodNode
|
public static boolean isMethodNode(ASTNode node, String methodNamePattern, Integer numArguments, Class returnType) {
if (!(node instanceof MethodNode)) {
return false;
}
if (!(((MethodNode) node).getName().matches(methodNamePattern))) {
return false;
}
if (numArguments != null && ((MethodNode)node).getParameters() != null && ((MethodNode)node).getParameters().length != numArguments) {
return false;
}
if (returnType != null && !AstUtil.classNodeImplementsType(((MethodNode) node).getReturnType(), returnType)) {
return false;
}
return true;
}
|
java
|
public static boolean isMethodNode(ASTNode node, String methodNamePattern, Integer numArguments, Class returnType) {
if (!(node instanceof MethodNode)) {
return false;
}
if (!(((MethodNode) node).getName().matches(methodNamePattern))) {
return false;
}
if (numArguments != null && ((MethodNode)node).getParameters() != null && ((MethodNode)node).getParameters().length != numArguments) {
return false;
}
if (returnType != null && !AstUtil.classNodeImplementsType(((MethodNode) node).getReturnType(), returnType)) {
return false;
}
return true;
}
|
[
"public",
"static",
"boolean",
"isMethodNode",
"(",
"ASTNode",
"node",
",",
"String",
"methodNamePattern",
",",
"Integer",
"numArguments",
",",
"Class",
"returnType",
")",
"{",
"if",
"(",
"!",
"(",
"node",
"instanceof",
"MethodNode",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"(",
"(",
"(",
"MethodNode",
")",
"node",
")",
".",
"getName",
"(",
")",
".",
"matches",
"(",
"methodNamePattern",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"numArguments",
"!=",
"null",
"&&",
"(",
"(",
"MethodNode",
")",
"node",
")",
".",
"getParameters",
"(",
")",
"!=",
"null",
"&&",
"(",
"(",
"MethodNode",
")",
"node",
")",
".",
"getParameters",
"(",
")",
".",
"length",
"!=",
"numArguments",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"returnType",
"!=",
"null",
"&&",
"!",
"AstUtil",
".",
"classNodeImplementsType",
"(",
"(",
"(",
"MethodNode",
")",
"node",
")",
".",
"getReturnType",
"(",
")",
",",
"returnType",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Tells you if the ASTNode is a method node for the given name, arity, and return type.
@param node
the node to inspect
@param methodNamePattern
the expected name of the method
@param numArguments
the expected number of arguments, optional
@param returnType
the expected return type, optional
@return
true if this node is a MethodNode meeting the parameters. false otherwise
|
[
"Tells",
"you",
"if",
"the",
"ASTNode",
"is",
"a",
"method",
"node",
"for",
"the",
"given",
"name",
"arity",
"and",
"return",
"type",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L842-L856
|
158,642 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.isVariable
|
public static boolean isVariable(ASTNode expression, String pattern) {
return (expression instanceof VariableExpression && ((VariableExpression) expression).getName().matches(pattern));
}
|
java
|
public static boolean isVariable(ASTNode expression, String pattern) {
return (expression instanceof VariableExpression && ((VariableExpression) expression).getName().matches(pattern));
}
|
[
"public",
"static",
"boolean",
"isVariable",
"(",
"ASTNode",
"expression",
",",
"String",
"pattern",
")",
"{",
"return",
"(",
"expression",
"instanceof",
"VariableExpression",
"&&",
"(",
"(",
"VariableExpression",
")",
"expression",
")",
".",
"getName",
"(",
")",
".",
"matches",
"(",
"pattern",
")",
")",
";",
"}"
] |
Tells you if the given ASTNode is a VariableExpression with the given name.
@param expression
any AST Node
@param pattern
a string pattern to match
@return
true if the node is a variable with the specified name
|
[
"Tells",
"you",
"if",
"the",
"given",
"ASTNode",
"is",
"a",
"VariableExpression",
"with",
"the",
"given",
"name",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L874-L876
|
158,643 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.getClassForClassNode
|
private static Class getClassForClassNode(ClassNode type) {
// todo hamlet - move to a different "InferenceUtil" object
Class primitiveType = getPrimitiveType(type);
if (primitiveType != null) {
return primitiveType;
} else if (classNodeImplementsType(type, String.class)) {
return String.class;
} else if (classNodeImplementsType(type, ReentrantLock.class)) {
return ReentrantLock.class;
} else if (type.getName() != null && type.getName().endsWith("[]")) {
return Object[].class; // better type inference could be done, but oh well
}
return null;
}
|
java
|
private static Class getClassForClassNode(ClassNode type) {
// todo hamlet - move to a different "InferenceUtil" object
Class primitiveType = getPrimitiveType(type);
if (primitiveType != null) {
return primitiveType;
} else if (classNodeImplementsType(type, String.class)) {
return String.class;
} else if (classNodeImplementsType(type, ReentrantLock.class)) {
return ReentrantLock.class;
} else if (type.getName() != null && type.getName().endsWith("[]")) {
return Object[].class; // better type inference could be done, but oh well
}
return null;
}
|
[
"private",
"static",
"Class",
"getClassForClassNode",
"(",
"ClassNode",
"type",
")",
"{",
"// todo hamlet - move to a different \"InferenceUtil\" object\r",
"Class",
"primitiveType",
"=",
"getPrimitiveType",
"(",
"type",
")",
";",
"if",
"(",
"primitiveType",
"!=",
"null",
")",
"{",
"return",
"primitiveType",
";",
"}",
"else",
"if",
"(",
"classNodeImplementsType",
"(",
"type",
",",
"String",
".",
"class",
")",
")",
"{",
"return",
"String",
".",
"class",
";",
"}",
"else",
"if",
"(",
"classNodeImplementsType",
"(",
"type",
",",
"ReentrantLock",
".",
"class",
")",
")",
"{",
"return",
"ReentrantLock",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
".",
"getName",
"(",
")",
"!=",
"null",
"&&",
"type",
".",
"getName",
"(",
")",
".",
"endsWith",
"(",
"\"[]\"",
")",
")",
"{",
"return",
"Object",
"[",
"]",
".",
"class",
";",
"// better type inference could be done, but oh well\r",
"}",
"return",
"null",
";",
"}"
] |
This is private. It is a helper function for the utils.
|
[
"This",
"is",
"private",
".",
"It",
"is",
"a",
"helper",
"function",
"for",
"the",
"utils",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L1009-L1022
|
158,644 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/util/AstUtil.java
|
AstUtil.findFirstNonAnnotationLine
|
public static int findFirstNonAnnotationLine(ASTNode node, SourceCode sourceCode) {
if (node instanceof AnnotatedNode && !((AnnotatedNode) node).getAnnotations().isEmpty()) {
// HACK: Groovy line numbers are broken when annotations have a parameter :(
// so we must look at the lineNumber, not the lastLineNumber
AnnotationNode lastAnnotation = null;
for (AnnotationNode annotation : ((AnnotatedNode) node).getAnnotations()) {
if (lastAnnotation == null) lastAnnotation = annotation;
else if (lastAnnotation.getLineNumber() < annotation.getLineNumber()) lastAnnotation = annotation;
}
String rawLine = getRawLine(sourceCode, lastAnnotation.getLastLineNumber()-1);
if(rawLine == null) {
return node.getLineNumber();
}
// is the annotation the last thing on the line?
if (rawLine.length() > lastAnnotation.getLastColumnNumber()) {
// no it is not
return lastAnnotation.getLastLineNumber();
}
// yes it is the last thing, return the next thing
return lastAnnotation.getLastLineNumber() + 1;
}
return node.getLineNumber();
}
|
java
|
public static int findFirstNonAnnotationLine(ASTNode node, SourceCode sourceCode) {
if (node instanceof AnnotatedNode && !((AnnotatedNode) node).getAnnotations().isEmpty()) {
// HACK: Groovy line numbers are broken when annotations have a parameter :(
// so we must look at the lineNumber, not the lastLineNumber
AnnotationNode lastAnnotation = null;
for (AnnotationNode annotation : ((AnnotatedNode) node).getAnnotations()) {
if (lastAnnotation == null) lastAnnotation = annotation;
else if (lastAnnotation.getLineNumber() < annotation.getLineNumber()) lastAnnotation = annotation;
}
String rawLine = getRawLine(sourceCode, lastAnnotation.getLastLineNumber()-1);
if(rawLine == null) {
return node.getLineNumber();
}
// is the annotation the last thing on the line?
if (rawLine.length() > lastAnnotation.getLastColumnNumber()) {
// no it is not
return lastAnnotation.getLastLineNumber();
}
// yes it is the last thing, return the next thing
return lastAnnotation.getLastLineNumber() + 1;
}
return node.getLineNumber();
}
|
[
"public",
"static",
"int",
"findFirstNonAnnotationLine",
"(",
"ASTNode",
"node",
",",
"SourceCode",
"sourceCode",
")",
"{",
"if",
"(",
"node",
"instanceof",
"AnnotatedNode",
"&&",
"!",
"(",
"(",
"AnnotatedNode",
")",
"node",
")",
".",
"getAnnotations",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"// HACK: Groovy line numbers are broken when annotations have a parameter :(\r",
"// so we must look at the lineNumber, not the lastLineNumber\r",
"AnnotationNode",
"lastAnnotation",
"=",
"null",
";",
"for",
"(",
"AnnotationNode",
"annotation",
":",
"(",
"(",
"AnnotatedNode",
")",
"node",
")",
".",
"getAnnotations",
"(",
")",
")",
"{",
"if",
"(",
"lastAnnotation",
"==",
"null",
")",
"lastAnnotation",
"=",
"annotation",
";",
"else",
"if",
"(",
"lastAnnotation",
".",
"getLineNumber",
"(",
")",
"<",
"annotation",
".",
"getLineNumber",
"(",
")",
")",
"lastAnnotation",
"=",
"annotation",
";",
"}",
"String",
"rawLine",
"=",
"getRawLine",
"(",
"sourceCode",
",",
"lastAnnotation",
".",
"getLastLineNumber",
"(",
")",
"-",
"1",
")",
";",
"if",
"(",
"rawLine",
"==",
"null",
")",
"{",
"return",
"node",
".",
"getLineNumber",
"(",
")",
";",
"}",
"// is the annotation the last thing on the line?\r",
"if",
"(",
"rawLine",
".",
"length",
"(",
")",
">",
"lastAnnotation",
".",
"getLastColumnNumber",
"(",
")",
")",
"{",
"// no it is not\r",
"return",
"lastAnnotation",
".",
"getLastLineNumber",
"(",
")",
";",
"}",
"// yes it is the last thing, return the next thing\r",
"return",
"lastAnnotation",
".",
"getLastLineNumber",
"(",
")",
"+",
"1",
";",
"}",
"return",
"node",
".",
"getLineNumber",
"(",
")",
";",
"}"
] |
gets the first non annotation line number of a node, taking into account annotations.
|
[
"gets",
"the",
"first",
"non",
"annotation",
"line",
"number",
"of",
"a",
"node",
"taking",
"into",
"account",
"annotations",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/util/AstUtil.java#L1076-L1102
|
158,645 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractAstVisitor.java
|
AbstractAstVisitor.isFirstVisit
|
protected boolean isFirstVisit(Object expression) {
if (visited.contains(expression)) {
return false;
}
visited.add(expression);
return true;
}
|
java
|
protected boolean isFirstVisit(Object expression) {
if (visited.contains(expression)) {
return false;
}
visited.add(expression);
return true;
}
|
[
"protected",
"boolean",
"isFirstVisit",
"(",
"Object",
"expression",
")",
"{",
"if",
"(",
"visited",
".",
"contains",
"(",
"expression",
")",
")",
"{",
"return",
"false",
";",
"}",
"visited",
".",
"add",
"(",
"expression",
")",
";",
"return",
"true",
";",
"}"
] |
Return true if the AST expression has not already been visited. If it is
the first visit, register the expression so that the next visit will return false.
@param expression - the AST expression to check
@return true if the AST expression has NOT already been visited
|
[
"Return",
"true",
"if",
"the",
"AST",
"expression",
"has",
"not",
"already",
"been",
"visited",
".",
"If",
"it",
"is",
"the",
"first",
"visit",
"register",
"the",
"expression",
"so",
"that",
"the",
"next",
"visit",
"will",
"return",
"false",
"."
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractAstVisitor.java#L49-L55
|
158,646 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractAstVisitor.java
|
AbstractAstVisitor.sourceLineTrimmed
|
protected String sourceLineTrimmed(ASTNode node) {
return sourceCode.line(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1);
}
|
java
|
protected String sourceLineTrimmed(ASTNode node) {
return sourceCode.line(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1);
}
|
[
"protected",
"String",
"sourceLineTrimmed",
"(",
"ASTNode",
"node",
")",
"{",
"return",
"sourceCode",
".",
"line",
"(",
"AstUtil",
".",
"findFirstNonAnnotationLine",
"(",
"node",
",",
"sourceCode",
")",
"-",
"1",
")",
";",
"}"
] |
Return the trimmed source line corresponding to the specified AST node
@param node - the Groovy AST node
|
[
"Return",
"the",
"trimmed",
"source",
"line",
"corresponding",
"to",
"the",
"specified",
"AST",
"node"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractAstVisitor.java#L62-L64
|
158,647 |
CodeNarc/CodeNarc
|
src/main/java/org/codenarc/rule/AbstractAstVisitor.java
|
AbstractAstVisitor.sourceLine
|
protected String sourceLine(ASTNode node) {
return sourceCode.getLines().get(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1);
}
|
java
|
protected String sourceLine(ASTNode node) {
return sourceCode.getLines().get(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1);
}
|
[
"protected",
"String",
"sourceLine",
"(",
"ASTNode",
"node",
")",
"{",
"return",
"sourceCode",
".",
"getLines",
"(",
")",
".",
"get",
"(",
"AstUtil",
".",
"findFirstNonAnnotationLine",
"(",
"node",
",",
"sourceCode",
")",
"-",
"1",
")",
";",
"}"
] |
Return the raw source line corresponding to the specified AST node
@param node - the Groovy AST node
|
[
"Return",
"the",
"raw",
"source",
"line",
"corresponding",
"to",
"the",
"specified",
"AST",
"node"
] |
9a7cec02cb8cbaf845030f2434309e8968f5d7a7
|
https://github.com/CodeNarc/CodeNarc/blob/9a7cec02cb8cbaf845030f2434309e8968f5d7a7/src/main/java/org/codenarc/rule/AbstractAstVisitor.java#L71-L73
|
158,648 |
seratch/jslack
|
src/main/java/com/github/seratch/jslack/common/http/SlackHttpClient.java
|
SlackHttpClient.buildJsonResponse
|
@Deprecated
public static <T> T buildJsonResponse(Response response, Class<T> clazz) throws IOException, SlackApiException {
if (response.code() == 200) {
String body = response.body().string();
DETAILED_LOGGER.accept(new HttpResponseListener.State(SlackConfig.DEFAULT, response, body));
return GsonFactory.createSnakeCase().fromJson(body, clazz);
} else {
String body = response.body().string();
throw new SlackApiException(response, body);
}
}
|
java
|
@Deprecated
public static <T> T buildJsonResponse(Response response, Class<T> clazz) throws IOException, SlackApiException {
if (response.code() == 200) {
String body = response.body().string();
DETAILED_LOGGER.accept(new HttpResponseListener.State(SlackConfig.DEFAULT, response, body));
return GsonFactory.createSnakeCase().fromJson(body, clazz);
} else {
String body = response.body().string();
throw new SlackApiException(response, body);
}
}
|
[
"@",
"Deprecated",
"public",
"static",
"<",
"T",
">",
"T",
"buildJsonResponse",
"(",
"Response",
"response",
",",
"Class",
"<",
"T",
">",
"clazz",
")",
"throws",
"IOException",
",",
"SlackApiException",
"{",
"if",
"(",
"response",
".",
"code",
"(",
")",
"==",
"200",
")",
"{",
"String",
"body",
"=",
"response",
".",
"body",
"(",
")",
".",
"string",
"(",
")",
";",
"DETAILED_LOGGER",
".",
"accept",
"(",
"new",
"HttpResponseListener",
".",
"State",
"(",
"SlackConfig",
".",
"DEFAULT",
",",
"response",
",",
"body",
")",
")",
";",
"return",
"GsonFactory",
".",
"createSnakeCase",
"(",
")",
".",
"fromJson",
"(",
"body",
",",
"clazz",
")",
";",
"}",
"else",
"{",
"String",
"body",
"=",
"response",
".",
"body",
"(",
")",
".",
"string",
"(",
")",
";",
"throw",
"new",
"SlackApiException",
"(",
"response",
",",
"body",
")",
";",
"}",
"}"
] |
use parseJsonResponse instead
|
[
"use",
"parseJsonResponse",
"instead"
] |
4a09680f13c97b33f59bc9b8271fef488c8e1c3a
|
https://github.com/seratch/jslack/blob/4a09680f13c97b33f59bc9b8271fef488c8e1c3a/src/main/java/com/github/seratch/jslack/common/http/SlackHttpClient.java#L91-L101
|
158,649 |
seratch/jslack
|
src/main/java/com/github/seratch/jslack/Slack.java
|
Slack.send
|
public WebhookResponse send(String url, Payload payload) throws IOException {
SlackHttpClient httpClient = getHttpClient();
Response httpResponse = httpClient.postJsonPostRequest(url, payload);
String body = httpResponse.body().string();
httpClient.runHttpResponseListeners(httpResponse, body);
return WebhookResponse.builder()
.code(httpResponse.code())
.message(httpResponse.message())
.body(body)
.build();
}
|
java
|
public WebhookResponse send(String url, Payload payload) throws IOException {
SlackHttpClient httpClient = getHttpClient();
Response httpResponse = httpClient.postJsonPostRequest(url, payload);
String body = httpResponse.body().string();
httpClient.runHttpResponseListeners(httpResponse, body);
return WebhookResponse.builder()
.code(httpResponse.code())
.message(httpResponse.message())
.body(body)
.build();
}
|
[
"public",
"WebhookResponse",
"send",
"(",
"String",
"url",
",",
"Payload",
"payload",
")",
"throws",
"IOException",
"{",
"SlackHttpClient",
"httpClient",
"=",
"getHttpClient",
"(",
")",
";",
"Response",
"httpResponse",
"=",
"httpClient",
".",
"postJsonPostRequest",
"(",
"url",
",",
"payload",
")",
";",
"String",
"body",
"=",
"httpResponse",
".",
"body",
"(",
")",
".",
"string",
"(",
")",
";",
"httpClient",
".",
"runHttpResponseListeners",
"(",
"httpResponse",
",",
"body",
")",
";",
"return",
"WebhookResponse",
".",
"builder",
"(",
")",
".",
"code",
"(",
"httpResponse",
".",
"code",
"(",
")",
")",
".",
"message",
"(",
"httpResponse",
".",
"message",
"(",
")",
")",
".",
"body",
"(",
"body",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Send a data to Incoming Webhook endpoint.
|
[
"Send",
"a",
"data",
"to",
"Incoming",
"Webhook",
"endpoint",
"."
] |
4a09680f13c97b33f59bc9b8271fef488c8e1c3a
|
https://github.com/seratch/jslack/blob/4a09680f13c97b33f59bc9b8271fef488c8e1c3a/src/main/java/com/github/seratch/jslack/Slack.java#L72-L83
|
158,650 |
seratch/jslack
|
src/main/java/com/github/seratch/jslack/api/rtm/RTMClient.java
|
RTMClient.updateSession
|
private void updateSession(Session newSession) {
if (this.currentSession == null) {
this.currentSession = newSession;
} else {
synchronized (this.currentSession) {
this.currentSession = newSession;
}
}
}
|
java
|
private void updateSession(Session newSession) {
if (this.currentSession == null) {
this.currentSession = newSession;
} else {
synchronized (this.currentSession) {
this.currentSession = newSession;
}
}
}
|
[
"private",
"void",
"updateSession",
"(",
"Session",
"newSession",
")",
"{",
"if",
"(",
"this",
".",
"currentSession",
"==",
"null",
")",
"{",
"this",
".",
"currentSession",
"=",
"newSession",
";",
"}",
"else",
"{",
"synchronized",
"(",
"this",
".",
"currentSession",
")",
"{",
"this",
".",
"currentSession",
"=",
"newSession",
";",
"}",
"}",
"}"
] |
Overwrites the underlying WebSocket session.
@param newSession new session
|
[
"Overwrites",
"the",
"underlying",
"WebSocket",
"session",
"."
] |
4a09680f13c97b33f59bc9b8271fef488c8e1c3a
|
https://github.com/seratch/jslack/blob/4a09680f13c97b33f59bc9b8271fef488c8e1c3a/src/main/java/com/github/seratch/jslack/api/rtm/RTMClient.java#L198-L206
|
158,651 |
seratch/jslack
|
src/main/java/com/github/seratch/jslack/api/rtm/RTMEventHandler.java
|
RTMEventHandler.getEventClass
|
public Class<E> getEventClass() {
if (cachedClazz != null) {
return cachedClazz;
}
Class<?> clazz = this.getClass();
while (clazz != Object.class) {
try {
Type mySuperclass = clazz.getGenericSuperclass();
Type tType = ((ParameterizedType) mySuperclass).getActualTypeArguments()[0];
cachedClazz = (Class<E>) Class.forName(tType.getTypeName());
return cachedClazz;
} catch (Exception e) {
}
clazz = clazz.getSuperclass();
}
throw new IllegalStateException("Failed to load event class - " + this.getClass().getCanonicalName());
}
|
java
|
public Class<E> getEventClass() {
if (cachedClazz != null) {
return cachedClazz;
}
Class<?> clazz = this.getClass();
while (clazz != Object.class) {
try {
Type mySuperclass = clazz.getGenericSuperclass();
Type tType = ((ParameterizedType) mySuperclass).getActualTypeArguments()[0];
cachedClazz = (Class<E>) Class.forName(tType.getTypeName());
return cachedClazz;
} catch (Exception e) {
}
clazz = clazz.getSuperclass();
}
throw new IllegalStateException("Failed to load event class - " + this.getClass().getCanonicalName());
}
|
[
"public",
"Class",
"<",
"E",
">",
"getEventClass",
"(",
")",
"{",
"if",
"(",
"cachedClazz",
"!=",
"null",
")",
"{",
"return",
"cachedClazz",
";",
"}",
"Class",
"<",
"?",
">",
"clazz",
"=",
"this",
".",
"getClass",
"(",
")",
";",
"while",
"(",
"clazz",
"!=",
"Object",
".",
"class",
")",
"{",
"try",
"{",
"Type",
"mySuperclass",
"=",
"clazz",
".",
"getGenericSuperclass",
"(",
")",
";",
"Type",
"tType",
"=",
"(",
"(",
"ParameterizedType",
")",
"mySuperclass",
")",
".",
"getActualTypeArguments",
"(",
")",
"[",
"0",
"]",
";",
"cachedClazz",
"=",
"(",
"Class",
"<",
"E",
">",
")",
"Class",
".",
"forName",
"(",
"tType",
".",
"getTypeName",
"(",
")",
")",
";",
"return",
"cachedClazz",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"clazz",
"=",
"clazz",
".",
"getSuperclass",
"(",
")",
";",
"}",
"throw",
"new",
"IllegalStateException",
"(",
"\"Failed to load event class - \"",
"+",
"this",
".",
"getClass",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
";",
"}"
] |
Returns the Class object of the Event implementation.
|
[
"Returns",
"the",
"Class",
"object",
"of",
"the",
"Event",
"implementation",
"."
] |
4a09680f13c97b33f59bc9b8271fef488c8e1c3a
|
https://github.com/seratch/jslack/blob/4a09680f13c97b33f59bc9b8271fef488c8e1c3a/src/main/java/com/github/seratch/jslack/api/rtm/RTMEventHandler.java#L40-L56
|
158,652 |
thymeleaf/thymeleaf-spring
|
thymeleaf-spring5/src/main/java/org/thymeleaf/spring5/processor/AbstractSpringFieldTagProcessor.java
|
AbstractSpringFieldTagProcessor.computeId
|
protected final String computeId(
final ITemplateContext context,
final IProcessableElementTag tag,
final String name, final boolean sequence) {
String id = tag.getAttributeValue(this.idAttributeDefinition.getAttributeName());
if (!org.thymeleaf.util.StringUtils.isEmptyOrWhitespace(id)) {
return (StringUtils.hasText(id) ? id : null);
}
id = FieldUtils.idFromName(name);
if (sequence) {
final Integer count = context.getIdentifierSequences().getAndIncrementIDSeq(id);
return id + count.toString();
}
return id;
}
|
java
|
protected final String computeId(
final ITemplateContext context,
final IProcessableElementTag tag,
final String name, final boolean sequence) {
String id = tag.getAttributeValue(this.idAttributeDefinition.getAttributeName());
if (!org.thymeleaf.util.StringUtils.isEmptyOrWhitespace(id)) {
return (StringUtils.hasText(id) ? id : null);
}
id = FieldUtils.idFromName(name);
if (sequence) {
final Integer count = context.getIdentifierSequences().getAndIncrementIDSeq(id);
return id + count.toString();
}
return id;
}
|
[
"protected",
"final",
"String",
"computeId",
"(",
"final",
"ITemplateContext",
"context",
",",
"final",
"IProcessableElementTag",
"tag",
",",
"final",
"String",
"name",
",",
"final",
"boolean",
"sequence",
")",
"{",
"String",
"id",
"=",
"tag",
".",
"getAttributeValue",
"(",
"this",
".",
"idAttributeDefinition",
".",
"getAttributeName",
"(",
")",
")",
";",
"if",
"(",
"!",
"org",
".",
"thymeleaf",
".",
"util",
".",
"StringUtils",
".",
"isEmptyOrWhitespace",
"(",
"id",
")",
")",
"{",
"return",
"(",
"StringUtils",
".",
"hasText",
"(",
"id",
")",
"?",
"id",
":",
"null",
")",
";",
"}",
"id",
"=",
"FieldUtils",
".",
"idFromName",
"(",
"name",
")",
";",
"if",
"(",
"sequence",
")",
"{",
"final",
"Integer",
"count",
"=",
"context",
".",
"getIdentifierSequences",
"(",
")",
".",
"getAndIncrementIDSeq",
"(",
"id",
")",
";",
"return",
"id",
"+",
"count",
".",
"toString",
"(",
")",
";",
"}",
"return",
"id",
";",
"}"
] |
This method is designed to be called from the diverse subclasses
|
[
"This",
"method",
"is",
"designed",
"to",
"be",
"called",
"from",
"the",
"diverse",
"subclasses"
] |
9aa15a19017a0938e57646e3deefb8a90ab78dcb
|
https://github.com/thymeleaf/thymeleaf-spring/blob/9aa15a19017a0938e57646e3deefb8a90ab78dcb/thymeleaf-spring5/src/main/java/org/thymeleaf/spring5/processor/AbstractSpringFieldTagProcessor.java#L207-L224
|
158,653 |
thymeleaf/thymeleaf-spring
|
thymeleaf-spring5/src/main/java/org/thymeleaf/spring5/expression/Themes.java
|
Themes.code
|
public String code(final String code) {
if (this.theme == null) {
throw new TemplateProcessingException("Theme cannot be resolved because RequestContext was not found. "
+ "Are you using a Context object without a RequestContext variable?");
}
return this.theme.getMessageSource().getMessage(code, null, "", this.locale);
}
|
java
|
public String code(final String code) {
if (this.theme == null) {
throw new TemplateProcessingException("Theme cannot be resolved because RequestContext was not found. "
+ "Are you using a Context object without a RequestContext variable?");
}
return this.theme.getMessageSource().getMessage(code, null, "", this.locale);
}
|
[
"public",
"String",
"code",
"(",
"final",
"String",
"code",
")",
"{",
"if",
"(",
"this",
".",
"theme",
"==",
"null",
")",
"{",
"throw",
"new",
"TemplateProcessingException",
"(",
"\"Theme cannot be resolved because RequestContext was not found. \"",
"+",
"\"Are you using a Context object without a RequestContext variable?\"",
")",
";",
"}",
"return",
"this",
".",
"theme",
".",
"getMessageSource",
"(",
")",
".",
"getMessage",
"(",
"code",
",",
"null",
",",
"\"\"",
",",
"this",
".",
"locale",
")",
";",
"}"
] |
Looks up and returns the value of the given key in the properties file of
the currently-selected theme.
@param code Key to look up in the theme properties file.
@return The value of the code in the current theme properties file, or an
empty string if the code could not be resolved.
|
[
"Looks",
"up",
"and",
"returns",
"the",
"value",
"of",
"the",
"given",
"key",
"in",
"the",
"properties",
"file",
"of",
"the",
"currently",
"-",
"selected",
"theme",
"."
] |
9aa15a19017a0938e57646e3deefb8a90ab78dcb
|
https://github.com/thymeleaf/thymeleaf-spring/blob/9aa15a19017a0938e57646e3deefb8a90ab78dcb/thymeleaf-spring5/src/main/java/org/thymeleaf/spring5/expression/Themes.java#L66-L72
|
158,654 |
wildfly/wildfly-core
|
host-controller/src/main/java/org/jboss/as/host/controller/ManagedServerBootCmdFactory.java
|
ManagedServerBootCmdFactory.resolveDirectoryGrouping
|
private static DirectoryGrouping resolveDirectoryGrouping(final ModelNode model, final ExpressionResolver expressionResolver) {
try {
return DirectoryGrouping.forName(HostResourceDefinition.DIRECTORY_GROUPING.resolveModelAttribute(expressionResolver, model).asString());
} catch (OperationFailedException e) {
throw new IllegalStateException(e);
}
}
|
java
|
private static DirectoryGrouping resolveDirectoryGrouping(final ModelNode model, final ExpressionResolver expressionResolver) {
try {
return DirectoryGrouping.forName(HostResourceDefinition.DIRECTORY_GROUPING.resolveModelAttribute(expressionResolver, model).asString());
} catch (OperationFailedException e) {
throw new IllegalStateException(e);
}
}
|
[
"private",
"static",
"DirectoryGrouping",
"resolveDirectoryGrouping",
"(",
"final",
"ModelNode",
"model",
",",
"final",
"ExpressionResolver",
"expressionResolver",
")",
"{",
"try",
"{",
"return",
"DirectoryGrouping",
".",
"forName",
"(",
"HostResourceDefinition",
".",
"DIRECTORY_GROUPING",
".",
"resolveModelAttribute",
"(",
"expressionResolver",
",",
"model",
")",
".",
"asString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"OperationFailedException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
")",
";",
"}",
"}"
] |
Returns the value of found in the model.
@param model the model that contains the key and value.
@param expressionResolver the expression resolver to use to resolve expressions
@return the directory grouping found in the model.
@throws IllegalArgumentException if the {@link org.jboss.as.controller.descriptions.ModelDescriptionConstants#DIRECTORY_GROUPING directory grouping}
was not found in the model.
|
[
"Returns",
"the",
"value",
"of",
"found",
"in",
"the",
"model",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/host-controller/src/main/java/org/jboss/as/host/controller/ManagedServerBootCmdFactory.java#L238-L244
|
158,655 |
wildfly/wildfly-core
|
host-controller/src/main/java/org/jboss/as/host/controller/ManagedServerBootCmdFactory.java
|
ManagedServerBootCmdFactory.addPathProperty
|
private String addPathProperty(final List<String> command, final String typeName, final String propertyName, final Map<String, String> properties, final DirectoryGrouping directoryGrouping,
final File typeDir, File serverDir) {
final String result;
final String value = properties.get(propertyName);
if (value == null) {
switch (directoryGrouping) {
case BY_TYPE:
result = getAbsolutePath(typeDir, "servers", serverName);
break;
case BY_SERVER:
default:
result = getAbsolutePath(serverDir, typeName);
break;
}
properties.put(propertyName, result);
} else {
final File dir = new File(value);
switch (directoryGrouping) {
case BY_TYPE:
result = getAbsolutePath(dir, "servers", serverName);
break;
case BY_SERVER:
default:
result = getAbsolutePath(dir, serverName);
break;
}
}
command.add(String.format("-D%s=%s", propertyName, result));
return result;
}
|
java
|
private String addPathProperty(final List<String> command, final String typeName, final String propertyName, final Map<String, String> properties, final DirectoryGrouping directoryGrouping,
final File typeDir, File serverDir) {
final String result;
final String value = properties.get(propertyName);
if (value == null) {
switch (directoryGrouping) {
case BY_TYPE:
result = getAbsolutePath(typeDir, "servers", serverName);
break;
case BY_SERVER:
default:
result = getAbsolutePath(serverDir, typeName);
break;
}
properties.put(propertyName, result);
} else {
final File dir = new File(value);
switch (directoryGrouping) {
case BY_TYPE:
result = getAbsolutePath(dir, "servers", serverName);
break;
case BY_SERVER:
default:
result = getAbsolutePath(dir, serverName);
break;
}
}
command.add(String.format("-D%s=%s", propertyName, result));
return result;
}
|
[
"private",
"String",
"addPathProperty",
"(",
"final",
"List",
"<",
"String",
">",
"command",
",",
"final",
"String",
"typeName",
",",
"final",
"String",
"propertyName",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"properties",
",",
"final",
"DirectoryGrouping",
"directoryGrouping",
",",
"final",
"File",
"typeDir",
",",
"File",
"serverDir",
")",
"{",
"final",
"String",
"result",
";",
"final",
"String",
"value",
"=",
"properties",
".",
"get",
"(",
"propertyName",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"switch",
"(",
"directoryGrouping",
")",
"{",
"case",
"BY_TYPE",
":",
"result",
"=",
"getAbsolutePath",
"(",
"typeDir",
",",
"\"servers\"",
",",
"serverName",
")",
";",
"break",
";",
"case",
"BY_SERVER",
":",
"default",
":",
"result",
"=",
"getAbsolutePath",
"(",
"serverDir",
",",
"typeName",
")",
";",
"break",
";",
"}",
"properties",
".",
"put",
"(",
"propertyName",
",",
"result",
")",
";",
"}",
"else",
"{",
"final",
"File",
"dir",
"=",
"new",
"File",
"(",
"value",
")",
";",
"switch",
"(",
"directoryGrouping",
")",
"{",
"case",
"BY_TYPE",
":",
"result",
"=",
"getAbsolutePath",
"(",
"dir",
",",
"\"servers\"",
",",
"serverName",
")",
";",
"break",
";",
"case",
"BY_SERVER",
":",
"default",
":",
"result",
"=",
"getAbsolutePath",
"(",
"dir",
",",
"serverName",
")",
";",
"break",
";",
"}",
"}",
"command",
".",
"add",
"(",
"String",
".",
"format",
"(",
"\"-D%s=%s\"",
",",
"propertyName",
",",
"result",
")",
")",
";",
"return",
"result",
";",
"}"
] |
Adds the absolute path to command.
@param command the command to add the arguments to.
@param typeName the type of directory.
@param propertyName the name of the property.
@param properties the properties where the path may already be defined.
@param directoryGrouping the directory group type.
@param typeDir the domain level directory for the given directory type; to be used for by-type grouping
@param serverDir the root directory for the server, to be used for 'by-server' grouping
@return the absolute path that was added.
|
[
"Adds",
"the",
"absolute",
"path",
"to",
"command",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/host-controller/src/main/java/org/jboss/as/host/controller/ManagedServerBootCmdFactory.java#L530-L559
|
158,656 |
wildfly/wildfly-core
|
logging/src/main/java/org/jboss/as/logging/deployments/LoggingProfileDeploymentProcessor.java
|
LoggingProfileDeploymentProcessor.findLoggingProfile
|
private String findLoggingProfile(final ResourceRoot resourceRoot) {
final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
final String loggingProfile = manifest.getMainAttributes().getValue(LOGGING_PROFILE);
if (loggingProfile != null) {
LoggingLogger.ROOT_LOGGER.debugf("Logging profile '%s' found in '%s'.", loggingProfile, resourceRoot);
return loggingProfile;
}
}
return null;
}
|
java
|
private String findLoggingProfile(final ResourceRoot resourceRoot) {
final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
final String loggingProfile = manifest.getMainAttributes().getValue(LOGGING_PROFILE);
if (loggingProfile != null) {
LoggingLogger.ROOT_LOGGER.debugf("Logging profile '%s' found in '%s'.", loggingProfile, resourceRoot);
return loggingProfile;
}
}
return null;
}
|
[
"private",
"String",
"findLoggingProfile",
"(",
"final",
"ResourceRoot",
"resourceRoot",
")",
"{",
"final",
"Manifest",
"manifest",
"=",
"resourceRoot",
".",
"getAttachment",
"(",
"Attachments",
".",
"MANIFEST",
")",
";",
"if",
"(",
"manifest",
"!=",
"null",
")",
"{",
"final",
"String",
"loggingProfile",
"=",
"manifest",
".",
"getMainAttributes",
"(",
")",
".",
"getValue",
"(",
"LOGGING_PROFILE",
")",
";",
"if",
"(",
"loggingProfile",
"!=",
"null",
")",
"{",
"LoggingLogger",
".",
"ROOT_LOGGER",
".",
"debugf",
"(",
"\"Logging profile '%s' found in '%s'.\"",
",",
"loggingProfile",
",",
"resourceRoot",
")",
";",
"return",
"loggingProfile",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Find the logging profile attached to any resource.
@param resourceRoot the root resource
@return the logging profile name or {@code null} if one was not found
|
[
"Find",
"the",
"logging",
"profile",
"attached",
"to",
"any",
"resource",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/logging/src/main/java/org/jboss/as/logging/deployments/LoggingProfileDeploymentProcessor.java#L108-L118
|
158,657 |
wildfly/wildfly-core
|
cli/src/main/java/org/jboss/as/cli/parsing/arguments/ArgumentValueState.java
|
ArgumentValueState.getBytesToken
|
public static int getBytesToken(ParsingContext ctx) {
String input = ctx.getInput().substring(ctx.getLocation());
int tokenOffset = 0;
int i = 0;
char[] inputChars = input.toCharArray();
for (; i < input.length(); i += 1) {
char c = inputChars[i];
if (c == ' ') {
continue;
}
if (c != BYTES_TOKEN_CHARS[tokenOffset]) {
return -1;
} else {
tokenOffset += 1;
if (tokenOffset == BYTES_TOKEN_CHARS.length) {
// Found the token.
return i;
}
}
}
return -1;
}
|
java
|
public static int getBytesToken(ParsingContext ctx) {
String input = ctx.getInput().substring(ctx.getLocation());
int tokenOffset = 0;
int i = 0;
char[] inputChars = input.toCharArray();
for (; i < input.length(); i += 1) {
char c = inputChars[i];
if (c == ' ') {
continue;
}
if (c != BYTES_TOKEN_CHARS[tokenOffset]) {
return -1;
} else {
tokenOffset += 1;
if (tokenOffset == BYTES_TOKEN_CHARS.length) {
// Found the token.
return i;
}
}
}
return -1;
}
|
[
"public",
"static",
"int",
"getBytesToken",
"(",
"ParsingContext",
"ctx",
")",
"{",
"String",
"input",
"=",
"ctx",
".",
"getInput",
"(",
")",
".",
"substring",
"(",
"ctx",
".",
"getLocation",
"(",
")",
")",
";",
"int",
"tokenOffset",
"=",
"0",
";",
"int",
"i",
"=",
"0",
";",
"char",
"[",
"]",
"inputChars",
"=",
"input",
".",
"toCharArray",
"(",
")",
";",
"for",
"(",
";",
"i",
"<",
"input",
".",
"length",
"(",
")",
";",
"i",
"+=",
"1",
")",
"{",
"char",
"c",
"=",
"inputChars",
"[",
"i",
"]",
";",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"c",
"!=",
"BYTES_TOKEN_CHARS",
"[",
"tokenOffset",
"]",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"tokenOffset",
"+=",
"1",
";",
"if",
"(",
"tokenOffset",
"==",
"BYTES_TOKEN_CHARS",
".",
"length",
")",
"{",
"// Found the token.",
"return",
"i",
";",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
handle white spaces.
|
[
"handle",
"white",
"spaces",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/cli/src/main/java/org/jboss/as/cli/parsing/arguments/ArgumentValueState.java#L111-L132
|
158,658 |
wildfly/wildfly-core
|
domain-management/src/main/java/org/jboss/as/domain/management/access/RbacSanityCheckOperation.java
|
RbacSanityCheckOperation.addOperation
|
public static void addOperation(final OperationContext context) {
RbacSanityCheckOperation added = context.getAttachment(KEY);
if (added == null) {
// TODO support managed domain
if (!context.isNormalServer()) return;
context.addStep(createOperation(), INSTANCE, Stage.MODEL);
context.attach(KEY, INSTANCE);
}
}
|
java
|
public static void addOperation(final OperationContext context) {
RbacSanityCheckOperation added = context.getAttachment(KEY);
if (added == null) {
// TODO support managed domain
if (!context.isNormalServer()) return;
context.addStep(createOperation(), INSTANCE, Stage.MODEL);
context.attach(KEY, INSTANCE);
}
}
|
[
"public",
"static",
"void",
"addOperation",
"(",
"final",
"OperationContext",
"context",
")",
"{",
"RbacSanityCheckOperation",
"added",
"=",
"context",
".",
"getAttachment",
"(",
"KEY",
")",
";",
"if",
"(",
"added",
"==",
"null",
")",
"{",
"// TODO support managed domain",
"if",
"(",
"!",
"context",
".",
"isNormalServer",
"(",
")",
")",
"return",
";",
"context",
".",
"addStep",
"(",
"createOperation",
"(",
")",
",",
"INSTANCE",
",",
"Stage",
".",
"MODEL",
")",
";",
"context",
".",
"attach",
"(",
"KEY",
",",
"INSTANCE",
")",
";",
"}",
"}"
] |
Add the operation at the end of Stage MODEL if this operation has not already been registered.
This operation should be added if any of the following occur: -
- The authorization configuration is removed from a security realm.
- The rbac provider is changed to rbac.
- A role is removed.
- An include is removed from a role.
- A management interface is removed.
Note: This list only includes actions that could invalidate the configuration, actions that would not invalidate the
configuration do not need this operation registering. e.g. Adding a role, if the configuration was already valid this
could not invalidate it.
@param context - The OperationContext to use to register the step.
|
[
"Add",
"the",
"operation",
"at",
"the",
"end",
"of",
"Stage",
"MODEL",
"if",
"this",
"operation",
"has",
"not",
"already",
"been",
"registered",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/domain-management/src/main/java/org/jboss/as/domain/management/access/RbacSanityCheckOperation.java#L123-L131
|
158,659 |
wildfly/wildfly-core
|
controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java
|
Operations.getFailureDescription
|
public static ModelNode getFailureDescription(final ModelNode result) {
if (isSuccessfulOutcome(result)) {
throw ControllerClientLogger.ROOT_LOGGER.noFailureDescription();
}
if (result.hasDefined(FAILURE_DESCRIPTION)) {
return result.get(FAILURE_DESCRIPTION);
}
return new ModelNode();
}
|
java
|
public static ModelNode getFailureDescription(final ModelNode result) {
if (isSuccessfulOutcome(result)) {
throw ControllerClientLogger.ROOT_LOGGER.noFailureDescription();
}
if (result.hasDefined(FAILURE_DESCRIPTION)) {
return result.get(FAILURE_DESCRIPTION);
}
return new ModelNode();
}
|
[
"public",
"static",
"ModelNode",
"getFailureDescription",
"(",
"final",
"ModelNode",
"result",
")",
"{",
"if",
"(",
"isSuccessfulOutcome",
"(",
"result",
")",
")",
"{",
"throw",
"ControllerClientLogger",
".",
"ROOT_LOGGER",
".",
"noFailureDescription",
"(",
")",
";",
"}",
"if",
"(",
"result",
".",
"hasDefined",
"(",
"FAILURE_DESCRIPTION",
")",
")",
"{",
"return",
"result",
".",
"get",
"(",
"FAILURE_DESCRIPTION",
")",
";",
"}",
"return",
"new",
"ModelNode",
"(",
")",
";",
"}"
] |
Parses the result and returns the failure description.
@param result the result of executing an operation
@return the failure description if defined, otherwise a new undefined model node
@throws IllegalArgumentException if the outcome of the operation was successful
|
[
"Parses",
"the",
"result",
"and",
"returns",
"the",
"failure",
"description",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java#L99-L107
|
158,660 |
wildfly/wildfly-core
|
controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java
|
Operations.getOperationAddress
|
public static ModelNode getOperationAddress(final ModelNode op) {
return op.hasDefined(OP_ADDR) ? op.get(OP_ADDR) : new ModelNode();
}
|
java
|
public static ModelNode getOperationAddress(final ModelNode op) {
return op.hasDefined(OP_ADDR) ? op.get(OP_ADDR) : new ModelNode();
}
|
[
"public",
"static",
"ModelNode",
"getOperationAddress",
"(",
"final",
"ModelNode",
"op",
")",
"{",
"return",
"op",
".",
"hasDefined",
"(",
"OP_ADDR",
")",
"?",
"op",
".",
"get",
"(",
"OP_ADDR",
")",
":",
"new",
"ModelNode",
"(",
")",
";",
"}"
] |
Returns the address for the operation.
@param op the operation
@return the operation address or a new undefined model node
|
[
"Returns",
"the",
"address",
"for",
"the",
"operation",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java#L155-L157
|
158,661 |
wildfly/wildfly-core
|
controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java
|
Operations.getOperationName
|
public static String getOperationName(final ModelNode op) {
if (op.hasDefined(OP)) {
return op.get(OP).asString();
}
throw ControllerClientLogger.ROOT_LOGGER.operationNameNotFound();
}
|
java
|
public static String getOperationName(final ModelNode op) {
if (op.hasDefined(OP)) {
return op.get(OP).asString();
}
throw ControllerClientLogger.ROOT_LOGGER.operationNameNotFound();
}
|
[
"public",
"static",
"String",
"getOperationName",
"(",
"final",
"ModelNode",
"op",
")",
"{",
"if",
"(",
"op",
".",
"hasDefined",
"(",
"OP",
")",
")",
"{",
"return",
"op",
".",
"get",
"(",
"OP",
")",
".",
"asString",
"(",
")",
";",
"}",
"throw",
"ControllerClientLogger",
".",
"ROOT_LOGGER",
".",
"operationNameNotFound",
"(",
")",
";",
"}"
] |
Returns the name of the operation.
@param op the operation
@return the name of the operation
@throws IllegalArgumentException if the operation was not defined.
|
[
"Returns",
"the",
"name",
"of",
"the",
"operation",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java#L168-L173
|
158,662 |
wildfly/wildfly-core
|
controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java
|
Operations.createReadResourceOperation
|
public static ModelNode createReadResourceOperation(final ModelNode address, final boolean recursive) {
final ModelNode op = createOperation(READ_RESOURCE_OPERATION, address);
op.get(RECURSIVE).set(recursive);
return op;
}
|
java
|
public static ModelNode createReadResourceOperation(final ModelNode address, final boolean recursive) {
final ModelNode op = createOperation(READ_RESOURCE_OPERATION, address);
op.get(RECURSIVE).set(recursive);
return op;
}
|
[
"public",
"static",
"ModelNode",
"createReadResourceOperation",
"(",
"final",
"ModelNode",
"address",
",",
"final",
"boolean",
"recursive",
")",
"{",
"final",
"ModelNode",
"op",
"=",
"createOperation",
"(",
"READ_RESOURCE_OPERATION",
",",
"address",
")",
";",
"op",
".",
"get",
"(",
"RECURSIVE",
")",
".",
"set",
"(",
"recursive",
")",
";",
"return",
"op",
";",
"}"
] |
Creates an operation to read a resource.
@param address the address to create the read for
@param recursive whether to search recursively or not
@return the operation
|
[
"Creates",
"an",
"operation",
"to",
"read",
"a",
"resource",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller-client/src/main/java/org/jboss/as/controller/client/helpers/Operations.java#L245-L249
|
158,663 |
wildfly/wildfly-core
|
cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationRequestBuilder.java
|
DefaultOperationRequestBuilder.buildRequest
|
public ModelNode buildRequest() throws OperationFormatException {
ModelNode address = request.get(Util.ADDRESS);
if(prefix.isEmpty()) {
address.setEmptyList();
} else {
Iterator<Node> iterator = prefix.iterator();
while (iterator.hasNext()) {
OperationRequestAddress.Node node = iterator.next();
if (node.getName() != null) {
address.add(node.getType(), node.getName());
} else if (iterator.hasNext()) {
throw new OperationFormatException(
"The node name is not specified for type '"
+ node.getType() + "'");
}
}
}
if(!request.hasDefined(Util.OPERATION)) {
throw new OperationFormatException("The operation name is missing or the format of the operation request is wrong.");
}
return request;
}
|
java
|
public ModelNode buildRequest() throws OperationFormatException {
ModelNode address = request.get(Util.ADDRESS);
if(prefix.isEmpty()) {
address.setEmptyList();
} else {
Iterator<Node> iterator = prefix.iterator();
while (iterator.hasNext()) {
OperationRequestAddress.Node node = iterator.next();
if (node.getName() != null) {
address.add(node.getType(), node.getName());
} else if (iterator.hasNext()) {
throw new OperationFormatException(
"The node name is not specified for type '"
+ node.getType() + "'");
}
}
}
if(!request.hasDefined(Util.OPERATION)) {
throw new OperationFormatException("The operation name is missing or the format of the operation request is wrong.");
}
return request;
}
|
[
"public",
"ModelNode",
"buildRequest",
"(",
")",
"throws",
"OperationFormatException",
"{",
"ModelNode",
"address",
"=",
"request",
".",
"get",
"(",
"Util",
".",
"ADDRESS",
")",
";",
"if",
"(",
"prefix",
".",
"isEmpty",
"(",
")",
")",
"{",
"address",
".",
"setEmptyList",
"(",
")",
";",
"}",
"else",
"{",
"Iterator",
"<",
"Node",
">",
"iterator",
"=",
"prefix",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"OperationRequestAddress",
".",
"Node",
"node",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"node",
".",
"getName",
"(",
")",
"!=",
"null",
")",
"{",
"address",
".",
"add",
"(",
"node",
".",
"getType",
"(",
")",
",",
"node",
".",
"getName",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"throw",
"new",
"OperationFormatException",
"(",
"\"The node name is not specified for type '\"",
"+",
"node",
".",
"getType",
"(",
")",
"+",
"\"'\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"request",
".",
"hasDefined",
"(",
"Util",
".",
"OPERATION",
")",
")",
"{",
"throw",
"new",
"OperationFormatException",
"(",
"\"The operation name is missing or the format of the operation request is wrong.\"",
")",
";",
"}",
"return",
"request",
";",
"}"
] |
Makes sure that the operation name and the address have been set and returns a ModelNode
representing the operation request.
|
[
"Makes",
"sure",
"that",
"the",
"operation",
"name",
"and",
"the",
"address",
"have",
"been",
"set",
"and",
"returns",
"a",
"ModelNode",
"representing",
"the",
"operation",
"request",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationRequestBuilder.java#L61-L85
|
158,664 |
wildfly/wildfly-core
|
domain-management/src/main/java/org/jboss/as/domain/management/parsing/ManagementXml_5.java
|
ManagementXml_5.parseUsersAuthentication
|
private void parseUsersAuthentication(final XMLExtendedStreamReader reader,
final ModelNode realmAddress, final List<ModelNode> list)
throws XMLStreamException {
final ModelNode usersAddress = realmAddress.clone().add(AUTHENTICATION, USERS);
list.add(Util.getEmptyOperation(ADD, usersAddress));
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
requireNamespace(reader, namespace);
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case USER: {
parseUser(reader, usersAddress, list);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
|
java
|
private void parseUsersAuthentication(final XMLExtendedStreamReader reader,
final ModelNode realmAddress, final List<ModelNode> list)
throws XMLStreamException {
final ModelNode usersAddress = realmAddress.clone().add(AUTHENTICATION, USERS);
list.add(Util.getEmptyOperation(ADD, usersAddress));
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
requireNamespace(reader, namespace);
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case USER: {
parseUser(reader, usersAddress, list);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
|
[
"private",
"void",
"parseUsersAuthentication",
"(",
"final",
"XMLExtendedStreamReader",
"reader",
",",
"final",
"ModelNode",
"realmAddress",
",",
"final",
"List",
"<",
"ModelNode",
">",
"list",
")",
"throws",
"XMLStreamException",
"{",
"final",
"ModelNode",
"usersAddress",
"=",
"realmAddress",
".",
"clone",
"(",
")",
".",
"add",
"(",
"AUTHENTICATION",
",",
"USERS",
")",
";",
"list",
".",
"add",
"(",
"Util",
".",
"getEmptyOperation",
"(",
"ADD",
",",
"usersAddress",
")",
")",
";",
"while",
"(",
"reader",
".",
"hasNext",
"(",
")",
"&&",
"reader",
".",
"nextTag",
"(",
")",
"!=",
"END_ELEMENT",
")",
"{",
"requireNamespace",
"(",
"reader",
",",
"namespace",
")",
";",
"final",
"Element",
"element",
"=",
"Element",
".",
"forName",
"(",
"reader",
".",
"getLocalName",
"(",
")",
")",
";",
"switch",
"(",
"element",
")",
"{",
"case",
"USER",
":",
"{",
"parseUser",
"(",
"reader",
",",
"usersAddress",
",",
"list",
")",
";",
"break",
";",
"}",
"default",
":",
"{",
"throw",
"unexpectedElement",
"(",
"reader",
")",
";",
"}",
"}",
"}",
"}"
] |
The users element defines users within the domain model, it is a simple authentication for some out of the box users.
|
[
"The",
"users",
"element",
"defines",
"users",
"within",
"the",
"domain",
"model",
"it",
"is",
"a",
"simple",
"authentication",
"for",
"some",
"out",
"of",
"the",
"box",
"users",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/domain-management/src/main/java/org/jboss/as/domain/management/parsing/ManagementXml_5.java#L1238-L1257
|
158,665 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/access/JmxAction.java
|
JmxAction.getActionEffects
|
public Set<Action.ActionEffect> getActionEffects() {
switch(getImpact()) {
case CLASSLOADING:
case WRITE:
return WRITES;
case READ_ONLY:
return READS;
default:
throw new IllegalStateException();
}
}
|
java
|
public Set<Action.ActionEffect> getActionEffects() {
switch(getImpact()) {
case CLASSLOADING:
case WRITE:
return WRITES;
case READ_ONLY:
return READS;
default:
throw new IllegalStateException();
}
}
|
[
"public",
"Set",
"<",
"Action",
".",
"ActionEffect",
">",
"getActionEffects",
"(",
")",
"{",
"switch",
"(",
"getImpact",
"(",
")",
")",
"{",
"case",
"CLASSLOADING",
":",
"case",
"WRITE",
":",
"return",
"WRITES",
";",
"case",
"READ_ONLY",
":",
"return",
"READS",
";",
"default",
":",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"}",
"}"
] |
Gets the effects of this action.
@return the effects. Will not be {@code null}
|
[
"Gets",
"the",
"effects",
"of",
"this",
"action",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/access/JmxAction.java#L86-L97
|
158,666 |
wildfly/wildfly-core
|
host-controller/src/main/java/org/jboss/as/host/controller/parsing/HostXml_4.java
|
HostXml_4.addLocalHost
|
private ModelNode addLocalHost(final ModelNode address, final List<ModelNode> operationList, final String hostName) {
String resolvedHost = hostName != null ? hostName : defaultHostControllerName;
// All further operations should modify the newly added host so the address passed in is updated.
address.add(HOST, resolvedHost);
// Add a step to setup the ManagementResourceRegistrations for the root host resource
final ModelNode hostAddOp = new ModelNode();
hostAddOp.get(OP).set(HostAddHandler.OPERATION_NAME);
hostAddOp.get(OP_ADDR).set(address);
operationList.add(hostAddOp);
// Add a step to store the HC name
ModelNode nameValue = hostName == null ? new ModelNode() : new ModelNode(hostName);
final ModelNode writeName = Util.getWriteAttributeOperation(address, NAME, nameValue);
operationList.add(writeName);
return hostAddOp;
}
|
java
|
private ModelNode addLocalHost(final ModelNode address, final List<ModelNode> operationList, final String hostName) {
String resolvedHost = hostName != null ? hostName : defaultHostControllerName;
// All further operations should modify the newly added host so the address passed in is updated.
address.add(HOST, resolvedHost);
// Add a step to setup the ManagementResourceRegistrations for the root host resource
final ModelNode hostAddOp = new ModelNode();
hostAddOp.get(OP).set(HostAddHandler.OPERATION_NAME);
hostAddOp.get(OP_ADDR).set(address);
operationList.add(hostAddOp);
// Add a step to store the HC name
ModelNode nameValue = hostName == null ? new ModelNode() : new ModelNode(hostName);
final ModelNode writeName = Util.getWriteAttributeOperation(address, NAME, nameValue);
operationList.add(writeName);
return hostAddOp;
}
|
[
"private",
"ModelNode",
"addLocalHost",
"(",
"final",
"ModelNode",
"address",
",",
"final",
"List",
"<",
"ModelNode",
">",
"operationList",
",",
"final",
"String",
"hostName",
")",
"{",
"String",
"resolvedHost",
"=",
"hostName",
"!=",
"null",
"?",
"hostName",
":",
"defaultHostControllerName",
";",
"// All further operations should modify the newly added host so the address passed in is updated.",
"address",
".",
"add",
"(",
"HOST",
",",
"resolvedHost",
")",
";",
"// Add a step to setup the ManagementResourceRegistrations for the root host resource",
"final",
"ModelNode",
"hostAddOp",
"=",
"new",
"ModelNode",
"(",
")",
";",
"hostAddOp",
".",
"get",
"(",
"OP",
")",
".",
"set",
"(",
"HostAddHandler",
".",
"OPERATION_NAME",
")",
";",
"hostAddOp",
".",
"get",
"(",
"OP_ADDR",
")",
".",
"set",
"(",
"address",
")",
";",
"operationList",
".",
"add",
"(",
"hostAddOp",
")",
";",
"// Add a step to store the HC name",
"ModelNode",
"nameValue",
"=",
"hostName",
"==",
"null",
"?",
"new",
"ModelNode",
"(",
")",
":",
"new",
"ModelNode",
"(",
"hostName",
")",
";",
"final",
"ModelNode",
"writeName",
"=",
"Util",
".",
"getWriteAttributeOperation",
"(",
"address",
",",
"NAME",
",",
"nameValue",
")",
";",
"operationList",
".",
"add",
"(",
"writeName",
")",
";",
"return",
"hostAddOp",
";",
"}"
] |
Add the operation to add the local host definition.
|
[
"Add",
"the",
"operation",
"to",
"add",
"the",
"local",
"host",
"definition",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/host-controller/src/main/java/org/jboss/as/host/controller/parsing/HostXml_4.java#L468-L487
|
158,667 |
wildfly/wildfly-core
|
deployment-repository/src/main/java/org/jboss/as/repository/HashUtil.java
|
HashUtil.hashPath
|
public static byte[] hashPath(MessageDigest messageDigest, Path path) throws IOException {
try (InputStream in = getRecursiveContentStream(path)) {
return hashContent(messageDigest, in);
}
}
|
java
|
public static byte[] hashPath(MessageDigest messageDigest, Path path) throws IOException {
try (InputStream in = getRecursiveContentStream(path)) {
return hashContent(messageDigest, in);
}
}
|
[
"public",
"static",
"byte",
"[",
"]",
"hashPath",
"(",
"MessageDigest",
"messageDigest",
",",
"Path",
"path",
")",
"throws",
"IOException",
"{",
"try",
"(",
"InputStream",
"in",
"=",
"getRecursiveContentStream",
"(",
"path",
")",
")",
"{",
"return",
"hashContent",
"(",
"messageDigest",
",",
"in",
")",
";",
"}",
"}"
] |
Hashes a path, if the path points to a directory then hashes the contents recursively.
@param messageDigest the digest used to hash.
@param path the file/directory we want to hash.
@return the resulting hash.
@throws IOException
|
[
"Hashes",
"a",
"path",
"if",
"the",
"path",
"points",
"to",
"a",
"directory",
"then",
"hashes",
"the",
"contents",
"recursively",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/deployment-repository/src/main/java/org/jboss/as/repository/HashUtil.java#L111-L115
|
158,668 |
wildfly/wildfly-core
|
cli/src/main/java/org/jboss/as/cli/gui/CommandExecutor.java
|
CommandExecutor.doCommand
|
public synchronized ModelNode doCommand(String command) throws CommandFormatException, IOException {
ModelNode request = cmdCtx.buildRequest(command);
return execute(request, isSlowCommand(command)).getResponseNode();
}
|
java
|
public synchronized ModelNode doCommand(String command) throws CommandFormatException, IOException {
ModelNode request = cmdCtx.buildRequest(command);
return execute(request, isSlowCommand(command)).getResponseNode();
}
|
[
"public",
"synchronized",
"ModelNode",
"doCommand",
"(",
"String",
"command",
")",
"throws",
"CommandFormatException",
",",
"IOException",
"{",
"ModelNode",
"request",
"=",
"cmdCtx",
".",
"buildRequest",
"(",
"command",
")",
";",
"return",
"execute",
"(",
"request",
",",
"isSlowCommand",
"(",
"command",
")",
")",
".",
"getResponseNode",
"(",
")",
";",
"}"
] |
Submit a command to the server.
@param command The CLI command
@return The DMR response as a ModelNode
@throws CommandFormatException
@throws IOException
|
[
"Submit",
"a",
"command",
"to",
"the",
"server",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/cli/src/main/java/org/jboss/as/cli/gui/CommandExecutor.java#L75-L78
|
158,669 |
wildfly/wildfly-core
|
cli/src/main/java/org/jboss/as/cli/gui/CommandExecutor.java
|
CommandExecutor.doCommandFullResponse
|
public synchronized Response doCommandFullResponse(String command) throws CommandFormatException, IOException {
ModelNode request = cmdCtx.buildRequest(command);
boolean replacedBytes = replaceFilePathsWithBytes(request);
OperationResponse response = execute(request, isSlowCommand(command) || replacedBytes);
return new Response(command, request, response);
}
|
java
|
public synchronized Response doCommandFullResponse(String command) throws CommandFormatException, IOException {
ModelNode request = cmdCtx.buildRequest(command);
boolean replacedBytes = replaceFilePathsWithBytes(request);
OperationResponse response = execute(request, isSlowCommand(command) || replacedBytes);
return new Response(command, request, response);
}
|
[
"public",
"synchronized",
"Response",
"doCommandFullResponse",
"(",
"String",
"command",
")",
"throws",
"CommandFormatException",
",",
"IOException",
"{",
"ModelNode",
"request",
"=",
"cmdCtx",
".",
"buildRequest",
"(",
"command",
")",
";",
"boolean",
"replacedBytes",
"=",
"replaceFilePathsWithBytes",
"(",
"request",
")",
";",
"OperationResponse",
"response",
"=",
"execute",
"(",
"request",
",",
"isSlowCommand",
"(",
"command",
")",
"||",
"replacedBytes",
")",
";",
"return",
"new",
"Response",
"(",
"command",
",",
"request",
",",
"response",
")",
";",
"}"
] |
User-initiated commands use this method.
@param command The CLI command
@return A Response object containing the command line, DMR request, and DMR response
@throws CommandFormatException
@throws IOException
|
[
"User",
"-",
"initiated",
"commands",
"use",
"this",
"method",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/cli/src/main/java/org/jboss/as/cli/gui/CommandExecutor.java#L88-L93
|
158,670 |
wildfly/wildfly-core
|
server/src/main/java/org/jboss/as/server/ServerEnvironment.java
|
ServerEnvironment.getFilesFromProperty
|
private File[] getFilesFromProperty(final String name, final Properties props) {
String sep = WildFlySecurityManager.getPropertyPrivileged("path.separator", null);
String value = props.getProperty(name, null);
if (value != null) {
final String[] paths = value.split(Pattern.quote(sep));
final int len = paths.length;
final File[] files = new File[len];
for (int i = 0; i < len; i++) {
files[i] = new File(paths[i]);
}
return files;
}
return NO_FILES;
}
|
java
|
private File[] getFilesFromProperty(final String name, final Properties props) {
String sep = WildFlySecurityManager.getPropertyPrivileged("path.separator", null);
String value = props.getProperty(name, null);
if (value != null) {
final String[] paths = value.split(Pattern.quote(sep));
final int len = paths.length;
final File[] files = new File[len];
for (int i = 0; i < len; i++) {
files[i] = new File(paths[i]);
}
return files;
}
return NO_FILES;
}
|
[
"private",
"File",
"[",
"]",
"getFilesFromProperty",
"(",
"final",
"String",
"name",
",",
"final",
"Properties",
"props",
")",
"{",
"String",
"sep",
"=",
"WildFlySecurityManager",
".",
"getPropertyPrivileged",
"(",
"\"path.separator\"",
",",
"null",
")",
";",
"String",
"value",
"=",
"props",
".",
"getProperty",
"(",
"name",
",",
"null",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"final",
"String",
"[",
"]",
"paths",
"=",
"value",
".",
"split",
"(",
"Pattern",
".",
"quote",
"(",
"sep",
")",
")",
";",
"final",
"int",
"len",
"=",
"paths",
".",
"length",
";",
"final",
"File",
"[",
"]",
"files",
"=",
"new",
"File",
"[",
"len",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"files",
"[",
"i",
"]",
"=",
"new",
"File",
"(",
"paths",
"[",
"i",
"]",
")",
";",
"}",
"return",
"files",
";",
"}",
"return",
"NO_FILES",
";",
"}"
] |
Get a File path list from configuration.
@param name the name of the property
@param props the set of configuration properties
@return the CanonicalFile form for the given name.
|
[
"Get",
"a",
"File",
"path",
"list",
"from",
"configuration",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/server/src/main/java/org/jboss/as/server/ServerEnvironment.java#L1212-L1225
|
158,671 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/registry/AtomicMapFieldUpdater.java
|
AtomicMapFieldUpdater.putAtomic
|
public boolean putAtomic(C instance, K key, V value, Map<K, V> snapshot) {
Assert.checkNotNullParam("key", key);
final Map<K, V> newMap;
final int oldSize = snapshot.size();
if (oldSize == 0) {
newMap = Collections.singletonMap(key, value);
} else if (oldSize == 1) {
final Map.Entry<K, V> entry = snapshot.entrySet().iterator().next();
final K oldKey = entry.getKey();
if (oldKey.equals(key)) {
return false;
} else {
newMap = new FastCopyHashMap<K, V>(snapshot);
newMap.put(key, value);
}
} else {
newMap = new FastCopyHashMap<K, V>(snapshot);
newMap.put(key, value);
}
return updater.compareAndSet(instance, snapshot, newMap);
}
|
java
|
public boolean putAtomic(C instance, K key, V value, Map<K, V> snapshot) {
Assert.checkNotNullParam("key", key);
final Map<K, V> newMap;
final int oldSize = snapshot.size();
if (oldSize == 0) {
newMap = Collections.singletonMap(key, value);
} else if (oldSize == 1) {
final Map.Entry<K, V> entry = snapshot.entrySet().iterator().next();
final K oldKey = entry.getKey();
if (oldKey.equals(key)) {
return false;
} else {
newMap = new FastCopyHashMap<K, V>(snapshot);
newMap.put(key, value);
}
} else {
newMap = new FastCopyHashMap<K, V>(snapshot);
newMap.put(key, value);
}
return updater.compareAndSet(instance, snapshot, newMap);
}
|
[
"public",
"boolean",
"putAtomic",
"(",
"C",
"instance",
",",
"K",
"key",
",",
"V",
"value",
",",
"Map",
"<",
"K",
",",
"V",
">",
"snapshot",
")",
"{",
"Assert",
".",
"checkNotNullParam",
"(",
"\"key\"",
",",
"key",
")",
";",
"final",
"Map",
"<",
"K",
",",
"V",
">",
"newMap",
";",
"final",
"int",
"oldSize",
"=",
"snapshot",
".",
"size",
"(",
")",
";",
"if",
"(",
"oldSize",
"==",
"0",
")",
"{",
"newMap",
"=",
"Collections",
".",
"singletonMap",
"(",
"key",
",",
"value",
")",
";",
"}",
"else",
"if",
"(",
"oldSize",
"==",
"1",
")",
"{",
"final",
"Map",
".",
"Entry",
"<",
"K",
",",
"V",
">",
"entry",
"=",
"snapshot",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
";",
"final",
"K",
"oldKey",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"if",
"(",
"oldKey",
".",
"equals",
"(",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"newMap",
"=",
"new",
"FastCopyHashMap",
"<",
"K",
",",
"V",
">",
"(",
"snapshot",
")",
";",
"newMap",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"else",
"{",
"newMap",
"=",
"new",
"FastCopyHashMap",
"<",
"K",
",",
"V",
">",
"(",
"snapshot",
")",
";",
"newMap",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"}",
"return",
"updater",
".",
"compareAndSet",
"(",
"instance",
",",
"snapshot",
",",
"newMap",
")",
";",
"}"
] |
Put a value if and only if the map has not changed since the given snapshot was taken. If the put fails,
it is the caller's responsibility to retry.
@param instance the instance with the map field
@param key the key
@param value the value
@param snapshot the map snapshot
@return {@code false} if the snapshot is out of date and we could not update, {@code true} if the put succeeded
|
[
"Put",
"a",
"value",
"if",
"and",
"only",
"if",
"the",
"map",
"has",
"not",
"changed",
"since",
"the",
"given",
"snapshot",
"was",
"taken",
".",
"If",
"the",
"put",
"fails",
"it",
"is",
"the",
"caller",
"s",
"responsibility",
"to",
"retry",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/registry/AtomicMapFieldUpdater.java#L97-L117
|
158,672 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ListAttributeDefinition.java
|
ListAttributeDefinition.parseAndSetParameter
|
@Deprecated
public void parseAndSetParameter(String value, ModelNode operation, XMLStreamReader reader) throws XMLStreamException {
//we use manual parsing here, and not #getParser().. to preserve backward compatibility.
if (value != null) {
for (String element : value.split(",")) {
parseAndAddParameterElement(element.trim(), operation, reader);
}
}
}
|
java
|
@Deprecated
public void parseAndSetParameter(String value, ModelNode operation, XMLStreamReader reader) throws XMLStreamException {
//we use manual parsing here, and not #getParser().. to preserve backward compatibility.
if (value != null) {
for (String element : value.split(",")) {
parseAndAddParameterElement(element.trim(), operation, reader);
}
}
}
|
[
"@",
"Deprecated",
"public",
"void",
"parseAndSetParameter",
"(",
"String",
"value",
",",
"ModelNode",
"operation",
",",
"XMLStreamReader",
"reader",
")",
"throws",
"XMLStreamException",
"{",
"//we use manual parsing here, and not #getParser().. to preserve backward compatibility.",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"element",
":",
"value",
".",
"split",
"(",
"\",\"",
")",
")",
"{",
"parseAndAddParameterElement",
"(",
"element",
".",
"trim",
"(",
")",
",",
"operation",
",",
"reader",
")",
";",
"}",
"}",
"}"
] |
Parses whole value as list attribute
@deprecated in favour of using {@link AttributeParser attribute parser}
@param value String with "," separated string elements
@param operation operation to with this list elements are added
@param reader xml reader from where reading is be done
@throws XMLStreamException if {@code value} is not valid
|
[
"Parses",
"whole",
"value",
"as",
"list",
"attribute"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ListAttributeDefinition.java#L240-L248
|
158,673 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lock
|
boolean lock(final Integer permit, final long timeout, final TimeUnit unit) {
boolean result = false;
try {
result = lockInterruptibly(permit, timeout, unit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return result;
}
|
java
|
boolean lock(final Integer permit, final long timeout, final TimeUnit unit) {
boolean result = false;
try {
result = lockInterruptibly(permit, timeout, unit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return result;
}
|
[
"boolean",
"lock",
"(",
"final",
"Integer",
"permit",
",",
"final",
"long",
"timeout",
",",
"final",
"TimeUnit",
"unit",
")",
"{",
"boolean",
"result",
"=",
"false",
";",
"try",
"{",
"result",
"=",
"lockInterruptibly",
"(",
"permit",
",",
"timeout",
",",
"unit",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Attempts exclusive acquisition with a max wait time.
@param permit - the permit Integer for this operation. May not be {@code null}.
@param timeout - the time value to wait for acquiring the lock
@param unit - See {@code TimeUnit} for valid values
@return {@code boolean} true on success.
|
[
"Attempts",
"exclusive",
"acquisition",
"with",
"a",
"max",
"wait",
"time",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L74-L82
|
158,674 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lockShared
|
boolean lockShared(final Integer permit, final long timeout, final TimeUnit unit) {
boolean result = false;
try {
result = lockSharedInterruptibly(permit, timeout, unit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return result;
}
|
java
|
boolean lockShared(final Integer permit, final long timeout, final TimeUnit unit) {
boolean result = false;
try {
result = lockSharedInterruptibly(permit, timeout, unit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return result;
}
|
[
"boolean",
"lockShared",
"(",
"final",
"Integer",
"permit",
",",
"final",
"long",
"timeout",
",",
"final",
"TimeUnit",
"unit",
")",
"{",
"boolean",
"result",
"=",
"false",
";",
"try",
"{",
"result",
"=",
"lockSharedInterruptibly",
"(",
"permit",
",",
"timeout",
",",
"unit",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Attempts shared acquisition with a max wait time.
@param permit - the permit Integer for this operation. May not be {@code null}.
@param timeout - the time value to wait for acquiring the lock
@param unit - See {@code TimeUnit} for valid values
@return {@code boolean} true on success.
|
[
"Attempts",
"shared",
"acquisition",
"with",
"a",
"max",
"wait",
"time",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L90-L98
|
158,675 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lockInterruptibly
|
void lockInterruptibly(final Integer permit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
sync.acquireInterruptibly(permit);
}
|
java
|
void lockInterruptibly(final Integer permit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
sync.acquireInterruptibly(permit);
}
|
[
"void",
"lockInterruptibly",
"(",
"final",
"Integer",
"permit",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"permit",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"sync",
".",
"acquireInterruptibly",
"(",
"permit",
")",
";",
"}"
] |
Acquire the exclusive lock allowing the acquisition to be interrupted.
@param permit - the permit Integer for this operation. May not be {@code null}.
@throws InterruptedException - if the acquiring thread is interrupted.
@throws IllegalArgumentException if {@code permit} is null.
|
[
"Acquire",
"the",
"exclusive",
"lock",
"allowing",
"the",
"acquisition",
"to",
"be",
"interrupted",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L106-L111
|
158,676 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lockSharedInterruptibly
|
void lockSharedInterruptibly(final Integer permit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
sync.acquireSharedInterruptibly(permit);
}
|
java
|
void lockSharedInterruptibly(final Integer permit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
sync.acquireSharedInterruptibly(permit);
}
|
[
"void",
"lockSharedInterruptibly",
"(",
"final",
"Integer",
"permit",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"permit",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"sync",
".",
"acquireSharedInterruptibly",
"(",
"permit",
")",
";",
"}"
] |
Acquire the shared lock allowing the acquisition to be interrupted.
@param permit - the permit Integer for this operation. May not be {@code null}.
@throws InterruptedException - if the acquiring thread is interrupted.
@throws IllegalArgumentException if {@code permit} is null.
|
[
"Acquire",
"the",
"shared",
"lock",
"allowing",
"the",
"acquisition",
"to",
"be",
"interrupted",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L119-L124
|
158,677 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lockInterruptibly
|
boolean lockInterruptibly(final Integer permit, final long timeout, final TimeUnit unit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
return sync.tryAcquireNanos(permit, unit.toNanos(timeout));
}
|
java
|
boolean lockInterruptibly(final Integer permit, final long timeout, final TimeUnit unit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
return sync.tryAcquireNanos(permit, unit.toNanos(timeout));
}
|
[
"boolean",
"lockInterruptibly",
"(",
"final",
"Integer",
"permit",
",",
"final",
"long",
"timeout",
",",
"final",
"TimeUnit",
"unit",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"permit",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"return",
"sync",
".",
"tryAcquireNanos",
"(",
"permit",
",",
"unit",
".",
"toNanos",
"(",
"timeout",
")",
")",
";",
"}"
] |
Acquire the exclusive lock, with a max wait timeout to acquire.
@param permit - the permit Integer for this operation. May not be {@code null}.
@param timeout - the timeout scalar quantity.
@param unit - see {@code TimeUnit} for quantities.
@return {@code boolean} true on successful acquire.
@throws InterruptedException - if the acquiring thread was interrupted.
@throws IllegalArgumentException if {@code permit} is null.
|
[
"Acquire",
"the",
"exclusive",
"lock",
"with",
"a",
"max",
"wait",
"timeout",
"to",
"acquire",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L135-L140
|
158,678 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java
|
ModelControllerLock.lockSharedInterruptibly
|
boolean lockSharedInterruptibly(final Integer permit, final long timeout, final TimeUnit unit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
return sync.tryAcquireSharedNanos(permit, unit.toNanos(timeout));
}
|
java
|
boolean lockSharedInterruptibly(final Integer permit, final long timeout, final TimeUnit unit) throws InterruptedException {
if (permit == null) {
throw new IllegalArgumentException();
}
return sync.tryAcquireSharedNanos(permit, unit.toNanos(timeout));
}
|
[
"boolean",
"lockSharedInterruptibly",
"(",
"final",
"Integer",
"permit",
",",
"final",
"long",
"timeout",
",",
"final",
"TimeUnit",
"unit",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"permit",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"return",
"sync",
".",
"tryAcquireSharedNanos",
"(",
"permit",
",",
"unit",
".",
"toNanos",
"(",
"timeout",
")",
")",
";",
"}"
] |
Acquire the shared lock, with a max wait timeout to acquire.
@param permit - the permit Integer for this operation. May not be {@code null}.
@param timeout - the timeout scalar quantity.
@param unit - see {@code TimeUnit} for quantities.
@return {@code boolean} true on successful acquire.
@throws InterruptedException - if the acquiring thread was interrupted.
@throws IllegalArgumentException if {@code permit} is null.
|
[
"Acquire",
"the",
"shared",
"lock",
"with",
"a",
"max",
"wait",
"timeout",
"to",
"acquire",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/ModelControllerLock.java#L151-L156
|
158,679 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java
|
CapabilityRegistry.createShadowCopy
|
CapabilityRegistry createShadowCopy() {
CapabilityRegistry result = new CapabilityRegistry(forServer, this);
readLock.lock();
try {
try {
result.writeLock.lock();
copy(this, result);
} finally {
result.writeLock.unlock();
}
} finally {
readLock.unlock();
}
return result;
}
|
java
|
CapabilityRegistry createShadowCopy() {
CapabilityRegistry result = new CapabilityRegistry(forServer, this);
readLock.lock();
try {
try {
result.writeLock.lock();
copy(this, result);
} finally {
result.writeLock.unlock();
}
} finally {
readLock.unlock();
}
return result;
}
|
[
"CapabilityRegistry",
"createShadowCopy",
"(",
")",
"{",
"CapabilityRegistry",
"result",
"=",
"new",
"CapabilityRegistry",
"(",
"forServer",
",",
"this",
")",
";",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"try",
"{",
"result",
".",
"writeLock",
".",
"lock",
"(",
")",
";",
"copy",
"(",
"this",
",",
"result",
")",
";",
"}",
"finally",
"{",
"result",
".",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Creates updateable version of capability registry that on publish pushes all changes to main registry
this is used to create context local registry that only on completion commits changes to main registry
@return writable registry
|
[
"Creates",
"updateable",
"version",
"of",
"capability",
"registry",
"that",
"on",
"publish",
"pushes",
"all",
"changes",
"to",
"main",
"registry",
"this",
"is",
"used",
"to",
"create",
"context",
"local",
"registry",
"that",
"only",
"on",
"completion",
"commits",
"changes",
"to",
"main",
"registry"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java#L103-L117
|
158,680 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java
|
CapabilityRegistry.registerRequirement
|
private void registerRequirement(RuntimeRequirementRegistration requirement) {
assert writeLock.isHeldByCurrentThread();
CapabilityId dependentId = requirement.getDependentId();
if (!capabilities.containsKey(dependentId)) {
throw ControllerLogger.MGMT_OP_LOGGER.unknownCapabilityInContext(dependentId.getName(),
dependentId.getScope().getName());
}
Map<CapabilityId, Map<String, RuntimeRequirementRegistration>> requirementMap =
requirement.isRuntimeOnly() ? runtimeOnlyRequirements : requirements;
Map<String, RuntimeRequirementRegistration> dependents = requirementMap.get(dependentId);
if (dependents == null) {
dependents = new HashMap<>();
requirementMap.put(dependentId, dependents);
}
RuntimeRequirementRegistration existing = dependents.get(requirement.getRequiredName());
if (existing == null) {
dependents.put(requirement.getRequiredName(), requirement);
} else {
existing.addRegistrationPoint(requirement.getOldestRegistrationPoint());
}
modified = true;
}
|
java
|
private void registerRequirement(RuntimeRequirementRegistration requirement) {
assert writeLock.isHeldByCurrentThread();
CapabilityId dependentId = requirement.getDependentId();
if (!capabilities.containsKey(dependentId)) {
throw ControllerLogger.MGMT_OP_LOGGER.unknownCapabilityInContext(dependentId.getName(),
dependentId.getScope().getName());
}
Map<CapabilityId, Map<String, RuntimeRequirementRegistration>> requirementMap =
requirement.isRuntimeOnly() ? runtimeOnlyRequirements : requirements;
Map<String, RuntimeRequirementRegistration> dependents = requirementMap.get(dependentId);
if (dependents == null) {
dependents = new HashMap<>();
requirementMap.put(dependentId, dependents);
}
RuntimeRequirementRegistration existing = dependents.get(requirement.getRequiredName());
if (existing == null) {
dependents.put(requirement.getRequiredName(), requirement);
} else {
existing.addRegistrationPoint(requirement.getOldestRegistrationPoint());
}
modified = true;
}
|
[
"private",
"void",
"registerRequirement",
"(",
"RuntimeRequirementRegistration",
"requirement",
")",
"{",
"assert",
"writeLock",
".",
"isHeldByCurrentThread",
"(",
")",
";",
"CapabilityId",
"dependentId",
"=",
"requirement",
".",
"getDependentId",
"(",
")",
";",
"if",
"(",
"!",
"capabilities",
".",
"containsKey",
"(",
"dependentId",
")",
")",
"{",
"throw",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"unknownCapabilityInContext",
"(",
"dependentId",
".",
"getName",
"(",
")",
",",
"dependentId",
".",
"getScope",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"Map",
"<",
"CapabilityId",
",",
"Map",
"<",
"String",
",",
"RuntimeRequirementRegistration",
">",
">",
"requirementMap",
"=",
"requirement",
".",
"isRuntimeOnly",
"(",
")",
"?",
"runtimeOnlyRequirements",
":",
"requirements",
";",
"Map",
"<",
"String",
",",
"RuntimeRequirementRegistration",
">",
"dependents",
"=",
"requirementMap",
".",
"get",
"(",
"dependentId",
")",
";",
"if",
"(",
"dependents",
"==",
"null",
")",
"{",
"dependents",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"requirementMap",
".",
"put",
"(",
"dependentId",
",",
"dependents",
")",
";",
"}",
"RuntimeRequirementRegistration",
"existing",
"=",
"dependents",
".",
"get",
"(",
"requirement",
".",
"getRequiredName",
"(",
")",
")",
";",
"if",
"(",
"existing",
"==",
"null",
")",
"{",
"dependents",
".",
"put",
"(",
"requirement",
".",
"getRequiredName",
"(",
")",
",",
"requirement",
")",
";",
"}",
"else",
"{",
"existing",
".",
"addRegistrationPoint",
"(",
"requirement",
".",
"getOldestRegistrationPoint",
"(",
")",
")",
";",
"}",
"modified",
"=",
"true",
";",
"}"
] |
This must be called with the write lock held.
@param requirement the requirement
|
[
"This",
"must",
"be",
"called",
"with",
"the",
"write",
"lock",
"held",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java#L208-L230
|
158,681 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java
|
CapabilityRegistry.removeCapabilityRequirement
|
@Override
public void removeCapabilityRequirement(RuntimeRequirementRegistration requirementRegistration) {
// We don't know if this got registered as an runtime-only requirement or a hard one
// so clean it from both maps
writeLock.lock();
try {
removeRequirement(requirementRegistration, false);
removeRequirement(requirementRegistration, true);
} finally {
writeLock.unlock();
}
}
|
java
|
@Override
public void removeCapabilityRequirement(RuntimeRequirementRegistration requirementRegistration) {
// We don't know if this got registered as an runtime-only requirement or a hard one
// so clean it from both maps
writeLock.lock();
try {
removeRequirement(requirementRegistration, false);
removeRequirement(requirementRegistration, true);
} finally {
writeLock.unlock();
}
}
|
[
"@",
"Override",
"public",
"void",
"removeCapabilityRequirement",
"(",
"RuntimeRequirementRegistration",
"requirementRegistration",
")",
"{",
"// We don't know if this got registered as an runtime-only requirement or a hard one",
"// so clean it from both maps",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"removeRequirement",
"(",
"requirementRegistration",
",",
"false",
")",
";",
"removeRequirement",
"(",
"requirementRegistration",
",",
"true",
")",
";",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Remove a previously registered requirement for a capability.
@param requirementRegistration the requirement. Cannot be {@code null}
@see #registerAdditionalCapabilityRequirement(org.jboss.as.controller.capability.registry.RuntimeRequirementRegistration)
|
[
"Remove",
"a",
"previously",
"registered",
"requirement",
"for",
"a",
"capability",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java#L238-L249
|
158,682 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java
|
CapabilityRegistry.publish
|
void publish() {
assert publishedFullRegistry != null : "Cannot write directly to main registry";
writeLock.lock();
try {
if (!modified) {
return;
}
publishedFullRegistry.writeLock.lock();
try {
publishedFullRegistry.clear(true);
copy(this, publishedFullRegistry);
pendingRemoveCapabilities.clear();
pendingRemoveRequirements.clear();
modified = false;
} finally {
publishedFullRegistry.writeLock.unlock();
}
} finally {
writeLock.unlock();
}
}
|
java
|
void publish() {
assert publishedFullRegistry != null : "Cannot write directly to main registry";
writeLock.lock();
try {
if (!modified) {
return;
}
publishedFullRegistry.writeLock.lock();
try {
publishedFullRegistry.clear(true);
copy(this, publishedFullRegistry);
pendingRemoveCapabilities.clear();
pendingRemoveRequirements.clear();
modified = false;
} finally {
publishedFullRegistry.writeLock.unlock();
}
} finally {
writeLock.unlock();
}
}
|
[
"void",
"publish",
"(",
")",
"{",
"assert",
"publishedFullRegistry",
"!=",
"null",
":",
"\"Cannot write directly to main registry\"",
";",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"modified",
")",
"{",
"return",
";",
"}",
"publishedFullRegistry",
".",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"publishedFullRegistry",
".",
"clear",
"(",
"true",
")",
";",
"copy",
"(",
"this",
",",
"publishedFullRegistry",
")",
";",
"pendingRemoveCapabilities",
".",
"clear",
"(",
")",
";",
"pendingRemoveRequirements",
".",
"clear",
"(",
")",
";",
"modified",
"=",
"false",
";",
"}",
"finally",
"{",
"publishedFullRegistry",
".",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Publish the changes to main registry
|
[
"Publish",
"the",
"changes",
"to",
"main",
"registry"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java#L739-L760
|
158,683 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java
|
CapabilityRegistry.rollback
|
void rollback() {
if (publishedFullRegistry == null) {
return;
}
writeLock.lock();
try {
publishedFullRegistry.readLock.lock();
try {
clear(true);
copy(publishedFullRegistry, this);
modified = false;
} finally {
publishedFullRegistry.readLock.unlock();
}
} finally {
writeLock.unlock();
}
}
|
java
|
void rollback() {
if (publishedFullRegistry == null) {
return;
}
writeLock.lock();
try {
publishedFullRegistry.readLock.lock();
try {
clear(true);
copy(publishedFullRegistry, this);
modified = false;
} finally {
publishedFullRegistry.readLock.unlock();
}
} finally {
writeLock.unlock();
}
}
|
[
"void",
"rollback",
"(",
")",
"{",
"if",
"(",
"publishedFullRegistry",
"==",
"null",
")",
"{",
"return",
";",
"}",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"publishedFullRegistry",
".",
"readLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"clear",
"(",
"true",
")",
";",
"copy",
"(",
"publishedFullRegistry",
",",
"this",
")",
";",
"modified",
"=",
"false",
";",
"}",
"finally",
"{",
"publishedFullRegistry",
".",
"readLock",
".",
"unlock",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"writeLock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] |
Discard the changes.
|
[
"Discard",
"the",
"changes",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/CapabilityRegistry.java#L765-L782
|
158,684 |
wildfly/wildfly-core
|
logging/src/main/java/org/jboss/as/logging/LoggingSubsystemParser.java
|
LoggingSubsystemParser.addOperationAddress
|
static void addOperationAddress(final ModelNode operation, final PathAddress base, final String key, final String value) {
operation.get(OP_ADDR).set(base.append(key, value).toModelNode());
}
|
java
|
static void addOperationAddress(final ModelNode operation, final PathAddress base, final String key, final String value) {
operation.get(OP_ADDR).set(base.append(key, value).toModelNode());
}
|
[
"static",
"void",
"addOperationAddress",
"(",
"final",
"ModelNode",
"operation",
",",
"final",
"PathAddress",
"base",
",",
"final",
"String",
"key",
",",
"final",
"String",
"value",
")",
"{",
"operation",
".",
"get",
"(",
"OP_ADDR",
")",
".",
"set",
"(",
"base",
".",
"append",
"(",
"key",
",",
"value",
")",
".",
"toModelNode",
"(",
")",
")",
";",
"}"
] |
Appends the key and value to the address and sets the address on the operation.
@param operation the operation to set the address on
@param base the base address
@param key the key for the new address
@param value the value for the new address
|
[
"Appends",
"the",
"key",
"and",
"value",
"to",
"the",
"address",
"and",
"sets",
"the",
"address",
"on",
"the",
"operation",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/logging/src/main/java/org/jboss/as/logging/LoggingSubsystemParser.java#L69-L71
|
158,685 |
wildfly/wildfly-core
|
domain-management/src/main/java/org/jboss/as/domain/management/controller/FindNonProgressingOperationHandler.java
|
FindNonProgressingOperationHandler.findNonProgressingOp
|
static String findNonProgressingOp(Resource resource, boolean forServer, long timeout) throws OperationFailedException {
Resource.ResourceEntry nonProgressing = null;
for (Resource.ResourceEntry child : resource.getChildren(ACTIVE_OPERATION)) {
ModelNode model = child.getModel();
if (model.get(EXCLUSIVE_RUNNING_TIME).asLong() > timeout) {
nonProgressing = child;
ControllerLogger.MGMT_OP_LOGGER.tracef("non-progressing op: %s", nonProgressing.getModel());
break;
}
}
if (nonProgressing != null && !forServer) {
// WFCORE-263
// See if the op is non-progressing because it's the HC op waiting for commit
// from the DC while other ops (i.e. ops proxied to our servers) associated
// with the same domain-uuid are not completing
ModelNode model = nonProgressing.getModel();
if (model.get(DOMAIN_ROLLOUT).asBoolean()
&& OperationContext.ExecutionStatus.COMPLETING.toString().equals(model.get(EXECUTION_STATUS).asString())
&& model.hasDefined(DOMAIN_UUID)) {
ControllerLogger.MGMT_OP_LOGGER.trace("Potential domain rollout issue");
String domainUUID = model.get(DOMAIN_UUID).asString();
Set<String> relatedIds = null;
List<Resource.ResourceEntry> relatedExecutingOps = null;
for (Resource.ResourceEntry activeOp : resource.getChildren(ACTIVE_OPERATION)) {
if (nonProgressing.getName().equals(activeOp.getName())) {
continue; // ignore self
}
ModelNode opModel = activeOp.getModel();
if (opModel.hasDefined(DOMAIN_UUID) && domainUUID.equals(opModel.get(DOMAIN_UUID).asString())
&& opModel.get(RUNNING_TIME).asLong() > timeout) {
if (relatedIds == null) {
relatedIds = new TreeSet<String>(); // order these as an aid to unit testing
}
relatedIds.add(activeOp.getName());
// If the op is ExecutionStatus.EXECUTING that means it's still EXECUTING on the
// server or a prepare message got lost. It would be COMPLETING if the server
// had sent a prepare message, as that would result in ProxyStepHandler calling completeStep
if (OperationContext.ExecutionStatus.EXECUTING.toString().equals(opModel.get(EXECUTION_STATUS).asString())) {
if (relatedExecutingOps == null) {
relatedExecutingOps = new ArrayList<Resource.ResourceEntry>();
}
relatedExecutingOps.add(activeOp);
ControllerLogger.MGMT_OP_LOGGER.tracef("Related executing: %s", opModel);
} else ControllerLogger.MGMT_OP_LOGGER.tracef("Related non-executing: %s", opModel);
} else ControllerLogger.MGMT_OP_LOGGER.tracef("unrelated: %s", opModel);
}
if (relatedIds != null) {
// There are other ops associated with this domain-uuid that are also not completing
// in the desired time, so we can't treat the one holding the lock as the problem.
if (relatedExecutingOps != null && relatedExecutingOps.size() == 1) {
// There's a single related op that's executing for too long. So we can report that one.
// Note that it's possible that the same problem exists on other hosts as well
// and that this cancellation will not resolve the overall problem. But, we only
// get here on a slave HC and if the user is invoking this on a slave and not the
// master, we'll assume they have a reason for doing that and want us to treat this
// as a problem on this particular host.
nonProgressing = relatedExecutingOps.get(0);
} else {
// Fail and provide a useful failure message.
throw DomainManagementLogger.ROOT_LOGGER.domainRolloutNotProgressing(nonProgressing.getName(),
timeout, domainUUID, relatedIds);
}
}
}
}
return nonProgressing == null ? null : nonProgressing.getName();
}
|
java
|
static String findNonProgressingOp(Resource resource, boolean forServer, long timeout) throws OperationFailedException {
Resource.ResourceEntry nonProgressing = null;
for (Resource.ResourceEntry child : resource.getChildren(ACTIVE_OPERATION)) {
ModelNode model = child.getModel();
if (model.get(EXCLUSIVE_RUNNING_TIME).asLong() > timeout) {
nonProgressing = child;
ControllerLogger.MGMT_OP_LOGGER.tracef("non-progressing op: %s", nonProgressing.getModel());
break;
}
}
if (nonProgressing != null && !forServer) {
// WFCORE-263
// See if the op is non-progressing because it's the HC op waiting for commit
// from the DC while other ops (i.e. ops proxied to our servers) associated
// with the same domain-uuid are not completing
ModelNode model = nonProgressing.getModel();
if (model.get(DOMAIN_ROLLOUT).asBoolean()
&& OperationContext.ExecutionStatus.COMPLETING.toString().equals(model.get(EXECUTION_STATUS).asString())
&& model.hasDefined(DOMAIN_UUID)) {
ControllerLogger.MGMT_OP_LOGGER.trace("Potential domain rollout issue");
String domainUUID = model.get(DOMAIN_UUID).asString();
Set<String> relatedIds = null;
List<Resource.ResourceEntry> relatedExecutingOps = null;
for (Resource.ResourceEntry activeOp : resource.getChildren(ACTIVE_OPERATION)) {
if (nonProgressing.getName().equals(activeOp.getName())) {
continue; // ignore self
}
ModelNode opModel = activeOp.getModel();
if (opModel.hasDefined(DOMAIN_UUID) && domainUUID.equals(opModel.get(DOMAIN_UUID).asString())
&& opModel.get(RUNNING_TIME).asLong() > timeout) {
if (relatedIds == null) {
relatedIds = new TreeSet<String>(); // order these as an aid to unit testing
}
relatedIds.add(activeOp.getName());
// If the op is ExecutionStatus.EXECUTING that means it's still EXECUTING on the
// server or a prepare message got lost. It would be COMPLETING if the server
// had sent a prepare message, as that would result in ProxyStepHandler calling completeStep
if (OperationContext.ExecutionStatus.EXECUTING.toString().equals(opModel.get(EXECUTION_STATUS).asString())) {
if (relatedExecutingOps == null) {
relatedExecutingOps = new ArrayList<Resource.ResourceEntry>();
}
relatedExecutingOps.add(activeOp);
ControllerLogger.MGMT_OP_LOGGER.tracef("Related executing: %s", opModel);
} else ControllerLogger.MGMT_OP_LOGGER.tracef("Related non-executing: %s", opModel);
} else ControllerLogger.MGMT_OP_LOGGER.tracef("unrelated: %s", opModel);
}
if (relatedIds != null) {
// There are other ops associated with this domain-uuid that are also not completing
// in the desired time, so we can't treat the one holding the lock as the problem.
if (relatedExecutingOps != null && relatedExecutingOps.size() == 1) {
// There's a single related op that's executing for too long. So we can report that one.
// Note that it's possible that the same problem exists on other hosts as well
// and that this cancellation will not resolve the overall problem. But, we only
// get here on a slave HC and if the user is invoking this on a slave and not the
// master, we'll assume they have a reason for doing that and want us to treat this
// as a problem on this particular host.
nonProgressing = relatedExecutingOps.get(0);
} else {
// Fail and provide a useful failure message.
throw DomainManagementLogger.ROOT_LOGGER.domainRolloutNotProgressing(nonProgressing.getName(),
timeout, domainUUID, relatedIds);
}
}
}
}
return nonProgressing == null ? null : nonProgressing.getName();
}
|
[
"static",
"String",
"findNonProgressingOp",
"(",
"Resource",
"resource",
",",
"boolean",
"forServer",
",",
"long",
"timeout",
")",
"throws",
"OperationFailedException",
"{",
"Resource",
".",
"ResourceEntry",
"nonProgressing",
"=",
"null",
";",
"for",
"(",
"Resource",
".",
"ResourceEntry",
"child",
":",
"resource",
".",
"getChildren",
"(",
"ACTIVE_OPERATION",
")",
")",
"{",
"ModelNode",
"model",
"=",
"child",
".",
"getModel",
"(",
")",
";",
"if",
"(",
"model",
".",
"get",
"(",
"EXCLUSIVE_RUNNING_TIME",
")",
".",
"asLong",
"(",
")",
">",
"timeout",
")",
"{",
"nonProgressing",
"=",
"child",
";",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"tracef",
"(",
"\"non-progressing op: %s\"",
",",
"nonProgressing",
".",
"getModel",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"nonProgressing",
"!=",
"null",
"&&",
"!",
"forServer",
")",
"{",
"// WFCORE-263",
"// See if the op is non-progressing because it's the HC op waiting for commit",
"// from the DC while other ops (i.e. ops proxied to our servers) associated",
"// with the same domain-uuid are not completing",
"ModelNode",
"model",
"=",
"nonProgressing",
".",
"getModel",
"(",
")",
";",
"if",
"(",
"model",
".",
"get",
"(",
"DOMAIN_ROLLOUT",
")",
".",
"asBoolean",
"(",
")",
"&&",
"OperationContext",
".",
"ExecutionStatus",
".",
"COMPLETING",
".",
"toString",
"(",
")",
".",
"equals",
"(",
"model",
".",
"get",
"(",
"EXECUTION_STATUS",
")",
".",
"asString",
"(",
")",
")",
"&&",
"model",
".",
"hasDefined",
"(",
"DOMAIN_UUID",
")",
")",
"{",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"trace",
"(",
"\"Potential domain rollout issue\"",
")",
";",
"String",
"domainUUID",
"=",
"model",
".",
"get",
"(",
"DOMAIN_UUID",
")",
".",
"asString",
"(",
")",
";",
"Set",
"<",
"String",
">",
"relatedIds",
"=",
"null",
";",
"List",
"<",
"Resource",
".",
"ResourceEntry",
">",
"relatedExecutingOps",
"=",
"null",
";",
"for",
"(",
"Resource",
".",
"ResourceEntry",
"activeOp",
":",
"resource",
".",
"getChildren",
"(",
"ACTIVE_OPERATION",
")",
")",
"{",
"if",
"(",
"nonProgressing",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"activeOp",
".",
"getName",
"(",
")",
")",
")",
"{",
"continue",
";",
"// ignore self",
"}",
"ModelNode",
"opModel",
"=",
"activeOp",
".",
"getModel",
"(",
")",
";",
"if",
"(",
"opModel",
".",
"hasDefined",
"(",
"DOMAIN_UUID",
")",
"&&",
"domainUUID",
".",
"equals",
"(",
"opModel",
".",
"get",
"(",
"DOMAIN_UUID",
")",
".",
"asString",
"(",
")",
")",
"&&",
"opModel",
".",
"get",
"(",
"RUNNING_TIME",
")",
".",
"asLong",
"(",
")",
">",
"timeout",
")",
"{",
"if",
"(",
"relatedIds",
"==",
"null",
")",
"{",
"relatedIds",
"=",
"new",
"TreeSet",
"<",
"String",
">",
"(",
")",
";",
"// order these as an aid to unit testing",
"}",
"relatedIds",
".",
"add",
"(",
"activeOp",
".",
"getName",
"(",
")",
")",
";",
"// If the op is ExecutionStatus.EXECUTING that means it's still EXECUTING on the",
"// server or a prepare message got lost. It would be COMPLETING if the server",
"// had sent a prepare message, as that would result in ProxyStepHandler calling completeStep",
"if",
"(",
"OperationContext",
".",
"ExecutionStatus",
".",
"EXECUTING",
".",
"toString",
"(",
")",
".",
"equals",
"(",
"opModel",
".",
"get",
"(",
"EXECUTION_STATUS",
")",
".",
"asString",
"(",
")",
")",
")",
"{",
"if",
"(",
"relatedExecutingOps",
"==",
"null",
")",
"{",
"relatedExecutingOps",
"=",
"new",
"ArrayList",
"<",
"Resource",
".",
"ResourceEntry",
">",
"(",
")",
";",
"}",
"relatedExecutingOps",
".",
"add",
"(",
"activeOp",
")",
";",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"tracef",
"(",
"\"Related executing: %s\"",
",",
"opModel",
")",
";",
"}",
"else",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"tracef",
"(",
"\"Related non-executing: %s\"",
",",
"opModel",
")",
";",
"}",
"else",
"ControllerLogger",
".",
"MGMT_OP_LOGGER",
".",
"tracef",
"(",
"\"unrelated: %s\"",
",",
"opModel",
")",
";",
"}",
"if",
"(",
"relatedIds",
"!=",
"null",
")",
"{",
"// There are other ops associated with this domain-uuid that are also not completing",
"// in the desired time, so we can't treat the one holding the lock as the problem.",
"if",
"(",
"relatedExecutingOps",
"!=",
"null",
"&&",
"relatedExecutingOps",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"// There's a single related op that's executing for too long. So we can report that one.",
"// Note that it's possible that the same problem exists on other hosts as well",
"// and that this cancellation will not resolve the overall problem. But, we only",
"// get here on a slave HC and if the user is invoking this on a slave and not the",
"// master, we'll assume they have a reason for doing that and want us to treat this",
"// as a problem on this particular host.",
"nonProgressing",
"=",
"relatedExecutingOps",
".",
"get",
"(",
"0",
")",
";",
"}",
"else",
"{",
"// Fail and provide a useful failure message.",
"throw",
"DomainManagementLogger",
".",
"ROOT_LOGGER",
".",
"domainRolloutNotProgressing",
"(",
"nonProgressing",
".",
"getName",
"(",
")",
",",
"timeout",
",",
"domainUUID",
",",
"relatedIds",
")",
";",
"}",
"}",
"}",
"}",
"return",
"nonProgressing",
"==",
"null",
"?",
"null",
":",
"nonProgressing",
".",
"getName",
"(",
")",
";",
"}"
] |
Separate from other findNonProgressingOp variant to allow unit testing without needing a mock OperationContext
|
[
"Separate",
"from",
"other",
"findNonProgressingOp",
"variant",
"to",
"allow",
"unit",
"testing",
"without",
"needing",
"a",
"mock",
"OperationContext"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/domain-management/src/main/java/org/jboss/as/domain/management/controller/FindNonProgressingOperationHandler.java#L103-L174
|
158,686 |
wildfly/wildfly-core
|
deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java
|
FileSystemDeploymentService.bootTimeScan
|
void bootTimeScan(final DeploymentOperations deploymentOperations) {
// WFCORE-1579: skip the scan if deployment dir is not available
if (!checkDeploymentDir(this.deploymentDir)) {
DeploymentScannerLogger.ROOT_LOGGER.bootTimeScanFailed(deploymentDir.getAbsolutePath());
return;
}
this.establishDeployedContentList(this.deploymentDir, deploymentOperations);
deployedContentEstablished = true;
if (acquireScanLock()) {
try {
scan(true, deploymentOperations);
} finally {
releaseScanLock();
}
}
}
|
java
|
void bootTimeScan(final DeploymentOperations deploymentOperations) {
// WFCORE-1579: skip the scan if deployment dir is not available
if (!checkDeploymentDir(this.deploymentDir)) {
DeploymentScannerLogger.ROOT_LOGGER.bootTimeScanFailed(deploymentDir.getAbsolutePath());
return;
}
this.establishDeployedContentList(this.deploymentDir, deploymentOperations);
deployedContentEstablished = true;
if (acquireScanLock()) {
try {
scan(true, deploymentOperations);
} finally {
releaseScanLock();
}
}
}
|
[
"void",
"bootTimeScan",
"(",
"final",
"DeploymentOperations",
"deploymentOperations",
")",
"{",
"// WFCORE-1579: skip the scan if deployment dir is not available",
"if",
"(",
"!",
"checkDeploymentDir",
"(",
"this",
".",
"deploymentDir",
")",
")",
"{",
"DeploymentScannerLogger",
".",
"ROOT_LOGGER",
".",
"bootTimeScanFailed",
"(",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"return",
";",
"}",
"this",
".",
"establishDeployedContentList",
"(",
"this",
".",
"deploymentDir",
",",
"deploymentOperations",
")",
";",
"deployedContentEstablished",
"=",
"true",
";",
"if",
"(",
"acquireScanLock",
"(",
")",
")",
"{",
"try",
"{",
"scan",
"(",
"true",
",",
"deploymentOperations",
")",
";",
"}",
"finally",
"{",
"releaseScanLock",
"(",
")",
";",
"}",
"}",
"}"
] |
Perform a one-off scan during boot to establish deployment tasks to execute during boot
|
[
"Perform",
"a",
"one",
"-",
"off",
"scan",
"during",
"boot",
"to",
"establish",
"deployment",
"tasks",
"to",
"execute",
"during",
"boot"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java#L463-L479
|
158,687 |
wildfly/wildfly-core
|
deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java
|
FileSystemDeploymentService.scan
|
void scan() {
if (acquireScanLock()) {
boolean scheduleRescan = false;
try {
scheduleRescan = scan(false, deploymentOperations);
} finally {
try {
if (scheduleRescan) {
synchronized (this) {
if (scanEnabled) {
rescanIncompleteTask = scheduledExecutor.schedule(scanRunnable, 200, TimeUnit.MILLISECONDS);
}
}
}
} finally {
releaseScanLock();
}
}
}
}
|
java
|
void scan() {
if (acquireScanLock()) {
boolean scheduleRescan = false;
try {
scheduleRescan = scan(false, deploymentOperations);
} finally {
try {
if (scheduleRescan) {
synchronized (this) {
if (scanEnabled) {
rescanIncompleteTask = scheduledExecutor.schedule(scanRunnable, 200, TimeUnit.MILLISECONDS);
}
}
}
} finally {
releaseScanLock();
}
}
}
}
|
[
"void",
"scan",
"(",
")",
"{",
"if",
"(",
"acquireScanLock",
"(",
")",
")",
"{",
"boolean",
"scheduleRescan",
"=",
"false",
";",
"try",
"{",
"scheduleRescan",
"=",
"scan",
"(",
"false",
",",
"deploymentOperations",
")",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"scheduleRescan",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"scanEnabled",
")",
"{",
"rescanIncompleteTask",
"=",
"scheduledExecutor",
".",
"schedule",
"(",
"scanRunnable",
",",
"200",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"}",
"}",
"}",
"}",
"finally",
"{",
"releaseScanLock",
"(",
")",
";",
"}",
"}",
"}",
"}"
] |
Perform a normal scan
|
[
"Perform",
"a",
"normal",
"scan"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java#L489-L508
|
158,688 |
wildfly/wildfly-core
|
deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java
|
FileSystemDeploymentService.forcedUndeployScan
|
void forcedUndeployScan() {
if (acquireScanLock()) {
try {
ROOT_LOGGER.tracef("Performing a post-boot forced undeploy scan for scan directory %s", deploymentDir.getAbsolutePath());
ScanContext scanContext = new ScanContext(deploymentOperations);
// Add remove actions to the plan for anything we count as
// deployed that we didn't find on the scan
for (Map.Entry<String, DeploymentMarker> missing : scanContext.toRemove.entrySet()) {
// remove successful deployment and left will be removed
if (scanContext.registeredDeployments.containsKey(missing.getKey())) {
scanContext.registeredDeployments.remove(missing.getKey());
}
}
Set<String> scannedDeployments = new HashSet<String>(scanContext.registeredDeployments.keySet());
scannedDeployments.removeAll(scanContext.persistentDeployments);
List<ScannerTask> scannerTasks = scanContext.scannerTasks;
for (String toUndeploy : scannedDeployments) {
scannerTasks.add(new UndeployTask(toUndeploy, deploymentDir, scanContext.scanStartTime, true));
}
try {
executeScannerTasks(scannerTasks, deploymentOperations, true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
ROOT_LOGGER.tracef("Forced undeploy scan complete");
} catch (Exception e) {
ROOT_LOGGER.scanException(e, deploymentDir.getAbsolutePath());
} finally {
releaseScanLock();
}
}
}
|
java
|
void forcedUndeployScan() {
if (acquireScanLock()) {
try {
ROOT_LOGGER.tracef("Performing a post-boot forced undeploy scan for scan directory %s", deploymentDir.getAbsolutePath());
ScanContext scanContext = new ScanContext(deploymentOperations);
// Add remove actions to the plan for anything we count as
// deployed that we didn't find on the scan
for (Map.Entry<String, DeploymentMarker> missing : scanContext.toRemove.entrySet()) {
// remove successful deployment and left will be removed
if (scanContext.registeredDeployments.containsKey(missing.getKey())) {
scanContext.registeredDeployments.remove(missing.getKey());
}
}
Set<String> scannedDeployments = new HashSet<String>(scanContext.registeredDeployments.keySet());
scannedDeployments.removeAll(scanContext.persistentDeployments);
List<ScannerTask> scannerTasks = scanContext.scannerTasks;
for (String toUndeploy : scannedDeployments) {
scannerTasks.add(new UndeployTask(toUndeploy, deploymentDir, scanContext.scanStartTime, true));
}
try {
executeScannerTasks(scannerTasks, deploymentOperations, true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
ROOT_LOGGER.tracef("Forced undeploy scan complete");
} catch (Exception e) {
ROOT_LOGGER.scanException(e, deploymentDir.getAbsolutePath());
} finally {
releaseScanLock();
}
}
}
|
[
"void",
"forcedUndeployScan",
"(",
")",
"{",
"if",
"(",
"acquireScanLock",
"(",
")",
")",
"{",
"try",
"{",
"ROOT_LOGGER",
".",
"tracef",
"(",
"\"Performing a post-boot forced undeploy scan for scan directory %s\"",
",",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"ScanContext",
"scanContext",
"=",
"new",
"ScanContext",
"(",
"deploymentOperations",
")",
";",
"// Add remove actions to the plan for anything we count as",
"// deployed that we didn't find on the scan",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"DeploymentMarker",
">",
"missing",
":",
"scanContext",
".",
"toRemove",
".",
"entrySet",
"(",
")",
")",
"{",
"// remove successful deployment and left will be removed",
"if",
"(",
"scanContext",
".",
"registeredDeployments",
".",
"containsKey",
"(",
"missing",
".",
"getKey",
"(",
")",
")",
")",
"{",
"scanContext",
".",
"registeredDeployments",
".",
"remove",
"(",
"missing",
".",
"getKey",
"(",
")",
")",
";",
"}",
"}",
"Set",
"<",
"String",
">",
"scannedDeployments",
"=",
"new",
"HashSet",
"<",
"String",
">",
"(",
"scanContext",
".",
"registeredDeployments",
".",
"keySet",
"(",
")",
")",
";",
"scannedDeployments",
".",
"removeAll",
"(",
"scanContext",
".",
"persistentDeployments",
")",
";",
"List",
"<",
"ScannerTask",
">",
"scannerTasks",
"=",
"scanContext",
".",
"scannerTasks",
";",
"for",
"(",
"String",
"toUndeploy",
":",
"scannedDeployments",
")",
"{",
"scannerTasks",
".",
"add",
"(",
"new",
"UndeployTask",
"(",
"toUndeploy",
",",
"deploymentDir",
",",
"scanContext",
".",
"scanStartTime",
",",
"true",
")",
")",
";",
"}",
"try",
"{",
"executeScannerTasks",
"(",
"scannerTasks",
",",
"deploymentOperations",
",",
"true",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"}",
"ROOT_LOGGER",
".",
"tracef",
"(",
"\"Forced undeploy scan complete\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"ROOT_LOGGER",
".",
"scanException",
"(",
"e",
",",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"finally",
"{",
"releaseScanLock",
"(",
")",
";",
"}",
"}",
"}"
] |
Perform a post-boot scan to remove any deployments added during boot that failed to deploy properly.
This method isn't private solely to allow a unit test in the same package to call it.
|
[
"Perform",
"a",
"post",
"-",
"boot",
"scan",
"to",
"remove",
"any",
"deployments",
"added",
"during",
"boot",
"that",
"failed",
"to",
"deploy",
"properly",
".",
"This",
"method",
"isn",
"t",
"private",
"solely",
"to",
"allow",
"a",
"unit",
"test",
"in",
"the",
"same",
"package",
"to",
"call",
"it",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java#L514-L549
|
158,689 |
wildfly/wildfly-core
|
deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java
|
FileSystemDeploymentService.checkDeploymentDir
|
private boolean checkDeploymentDir(File directory) {
if (!directory.exists()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNonexistent(deploymentDir.getAbsolutePath());
}
}
else if (!directory.isDirectory()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.isNotADirectory(deploymentDir.getAbsolutePath());
}
}
else if (!directory.canRead()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNotReadable(deploymentDir.getAbsolutePath());
}
}
else if (!directory.canWrite()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNotWritable(deploymentDir.getAbsolutePath());
}
} else {
deploymentDirAccessible = true;
}
return deploymentDirAccessible;
}
|
java
|
private boolean checkDeploymentDir(File directory) {
if (!directory.exists()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNonexistent(deploymentDir.getAbsolutePath());
}
}
else if (!directory.isDirectory()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.isNotADirectory(deploymentDir.getAbsolutePath());
}
}
else if (!directory.canRead()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNotReadable(deploymentDir.getAbsolutePath());
}
}
else if (!directory.canWrite()) {
if (deploymentDirAccessible) {
deploymentDirAccessible = false;
ROOT_LOGGER.directoryIsNotWritable(deploymentDir.getAbsolutePath());
}
} else {
deploymentDirAccessible = true;
}
return deploymentDirAccessible;
}
|
[
"private",
"boolean",
"checkDeploymentDir",
"(",
"File",
"directory",
")",
"{",
"if",
"(",
"!",
"directory",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"deploymentDirAccessible",
")",
"{",
"deploymentDirAccessible",
"=",
"false",
";",
"ROOT_LOGGER",
".",
"directoryIsNonexistent",
"(",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"directory",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"deploymentDirAccessible",
")",
"{",
"deploymentDirAccessible",
"=",
"false",
";",
"ROOT_LOGGER",
".",
"isNotADirectory",
"(",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"directory",
".",
"canRead",
"(",
")",
")",
"{",
"if",
"(",
"deploymentDirAccessible",
")",
"{",
"deploymentDirAccessible",
"=",
"false",
";",
"ROOT_LOGGER",
".",
"directoryIsNotReadable",
"(",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"directory",
".",
"canWrite",
"(",
")",
")",
"{",
"if",
"(",
"deploymentDirAccessible",
")",
"{",
"deploymentDirAccessible",
"=",
"false",
";",
"ROOT_LOGGER",
".",
"directoryIsNotWritable",
"(",
"deploymentDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"deploymentDirAccessible",
"=",
"true",
";",
"}",
"return",
"deploymentDirAccessible",
";",
"}"
] |
Checks that given directory if readable & writable and prints a warning if the check fails. Warning is only
printed once and is not repeated until the condition is fixed and broken again.
@param directory deployment directory
@return does given directory exist and is readable and writable?
|
[
"Checks",
"that",
"given",
"directory",
"if",
"readable",
"&",
"writable",
"and",
"prints",
"a",
"warning",
"if",
"the",
"check",
"fails",
".",
"Warning",
"is",
"only",
"printed",
"once",
"and",
"is",
"not",
"repeated",
"until",
"the",
"condition",
"is",
"fixed",
"and",
"broken",
"again",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java#L808-L837
|
158,690 |
wildfly/wildfly-core
|
domain-management/src/main/java/org/jboss/as/domain/management/security/LdapCacheResourceDefinition.java
|
LdapCacheResourceDefinition.createOperation
|
private static ModelNode createOperation(final ModelNode operationToValidate) {
PathAddress pa = PathAddress.pathAddress(operationToValidate.require(OP_ADDR));
PathAddress validationAddress = pa.subAddress(0, pa.size() - 1);
return Util.getEmptyOperation("validate-cache", validationAddress.toModelNode());
}
|
java
|
private static ModelNode createOperation(final ModelNode operationToValidate) {
PathAddress pa = PathAddress.pathAddress(operationToValidate.require(OP_ADDR));
PathAddress validationAddress = pa.subAddress(0, pa.size() - 1);
return Util.getEmptyOperation("validate-cache", validationAddress.toModelNode());
}
|
[
"private",
"static",
"ModelNode",
"createOperation",
"(",
"final",
"ModelNode",
"operationToValidate",
")",
"{",
"PathAddress",
"pa",
"=",
"PathAddress",
".",
"pathAddress",
"(",
"operationToValidate",
".",
"require",
"(",
"OP_ADDR",
")",
")",
";",
"PathAddress",
"validationAddress",
"=",
"pa",
".",
"subAddress",
"(",
"0",
",",
"pa",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"return",
"Util",
".",
"getEmptyOperation",
"(",
"\"validate-cache\"",
",",
"validationAddress",
".",
"toModelNode",
"(",
")",
")",
";",
"}"
] |
Creates an operations that targets the valiadating handler.
@param operationToValidate the operation that this handler will validate
@return the validation operation
|
[
"Creates",
"an",
"operations",
"that",
"targets",
"the",
"valiadating",
"handler",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/domain-management/src/main/java/org/jboss/as/domain/management/security/LdapCacheResourceDefinition.java#L214-L219
|
158,691 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/capability/registry/RequirementRegistration.java
|
RequirementRegistration.getOldestRegistrationPoint
|
public synchronized RegistrationPoint getOldestRegistrationPoint() {
return registrationPoints.size() == 0 ? null : registrationPoints.values().iterator().next().get(0);
}
|
java
|
public synchronized RegistrationPoint getOldestRegistrationPoint() {
return registrationPoints.size() == 0 ? null : registrationPoints.values().iterator().next().get(0);
}
|
[
"public",
"synchronized",
"RegistrationPoint",
"getOldestRegistrationPoint",
"(",
")",
"{",
"return",
"registrationPoints",
".",
"size",
"(",
")",
"==",
"0",
"?",
"null",
":",
"registrationPoints",
".",
"values",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
".",
"get",
"(",
"0",
")",
";",
"}"
] |
Gets the registration point that been associated with the registration for the longest period.
@return the initial registration point, or {@code null} if there are no longer any registration points
|
[
"Gets",
"the",
"registration",
"point",
"that",
"been",
"associated",
"with",
"the",
"registration",
"for",
"the",
"longest",
"period",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/capability/registry/RequirementRegistration.java#L119-L121
|
158,692 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/capability/registry/RequirementRegistration.java
|
RequirementRegistration.getRegistrationPoints
|
public synchronized Set<RegistrationPoint> getRegistrationPoints() {
Set<RegistrationPoint> result = new HashSet<>();
for (List<RegistrationPoint> registrationPoints : registrationPoints.values()) {
result.addAll(registrationPoints);
}
return Collections.unmodifiableSet(result);
}
|
java
|
public synchronized Set<RegistrationPoint> getRegistrationPoints() {
Set<RegistrationPoint> result = new HashSet<>();
for (List<RegistrationPoint> registrationPoints : registrationPoints.values()) {
result.addAll(registrationPoints);
}
return Collections.unmodifiableSet(result);
}
|
[
"public",
"synchronized",
"Set",
"<",
"RegistrationPoint",
">",
"getRegistrationPoints",
"(",
")",
"{",
"Set",
"<",
"RegistrationPoint",
">",
"result",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"List",
"<",
"RegistrationPoint",
">",
"registrationPoints",
":",
"registrationPoints",
".",
"values",
"(",
")",
")",
"{",
"result",
".",
"addAll",
"(",
"registrationPoints",
")",
";",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"result",
")",
";",
"}"
] |
Get all registration points associated with this registration.
@return all registration points. Will not be {@code null} but may be empty
|
[
"Get",
"all",
"registration",
"points",
"associated",
"with",
"this",
"registration",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/capability/registry/RequirementRegistration.java#L128-L134
|
158,693 |
wildfly/wildfly-core
|
server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtils.java
|
DeploymentHandlerUtils.hasValidContentAdditionParameterDefined
|
public static boolean hasValidContentAdditionParameterDefined(ModelNode operation) {
for (String s : DeploymentAttributes.MANAGED_CONTENT_ATTRIBUTES.keySet()) {
if (operation.hasDefined(s)) {
return true;
}
}
return false;
}
|
java
|
public static boolean hasValidContentAdditionParameterDefined(ModelNode operation) {
for (String s : DeploymentAttributes.MANAGED_CONTENT_ATTRIBUTES.keySet()) {
if (operation.hasDefined(s)) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"boolean",
"hasValidContentAdditionParameterDefined",
"(",
"ModelNode",
"operation",
")",
"{",
"for",
"(",
"String",
"s",
":",
"DeploymentAttributes",
".",
"MANAGED_CONTENT_ATTRIBUTES",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"operation",
".",
"hasDefined",
"(",
"s",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks to see if a valid deployment parameter has been defined.
@param operation the operation to check.
@return {@code true} of the parameter is valid, otherwise {@code false}.
|
[
"Checks",
"to",
"see",
"if",
"a",
"valid",
"deployment",
"parameter",
"has",
"been",
"defined",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtils.java#L127-L134
|
158,694 |
wildfly/wildfly-core
|
patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java
|
LayersFactory.load
|
static InstalledIdentity load(final InstalledImage image, final ProductConfig productConfig, final List<File> moduleRoots, final List<File> bundleRoots) throws IOException {
// build the identity information
final String productVersion = productConfig.resolveVersion();
final String productName = productConfig.resolveName();
final Identity identity = new AbstractLazyIdentity() {
@Override
public String getName() {
return productName;
}
@Override
public String getVersion() {
return productVersion;
}
@Override
public InstalledImage getInstalledImage() {
return image;
}
};
final Properties properties = PatchUtils.loadProperties(identity.getDirectoryStructure().getInstallationInfo());
final List<String> allPatches = PatchUtils.readRefs(properties, Constants.ALL_PATCHES);
// Step 1 - gather the installed layers data
final InstalledConfiguration conf = createInstalledConfig(image);
// Step 2 - process the actual module and bundle roots
final ProcessedLayers processedLayers = process(conf, moduleRoots, bundleRoots);
final InstalledConfiguration config = processedLayers.getConf();
// Step 3 - create the actual config objects
// Process layers
final InstalledIdentityImpl installedIdentity = new InstalledIdentityImpl(identity, allPatches, image);
for (final LayerPathConfig layer : processedLayers.getLayers().values()) {
final String name = layer.name;
installedIdentity.putLayer(name, createPatchableTarget(name, layer, config.getLayerMetadataDir(name), image));
}
// Process add-ons
for (final LayerPathConfig addOn : processedLayers.getAddOns().values()) {
final String name = addOn.name;
installedIdentity.putAddOn(name, createPatchableTarget(name, addOn, config.getAddOnMetadataDir(name), image));
}
return installedIdentity;
}
|
java
|
static InstalledIdentity load(final InstalledImage image, final ProductConfig productConfig, final List<File> moduleRoots, final List<File> bundleRoots) throws IOException {
// build the identity information
final String productVersion = productConfig.resolveVersion();
final String productName = productConfig.resolveName();
final Identity identity = new AbstractLazyIdentity() {
@Override
public String getName() {
return productName;
}
@Override
public String getVersion() {
return productVersion;
}
@Override
public InstalledImage getInstalledImage() {
return image;
}
};
final Properties properties = PatchUtils.loadProperties(identity.getDirectoryStructure().getInstallationInfo());
final List<String> allPatches = PatchUtils.readRefs(properties, Constants.ALL_PATCHES);
// Step 1 - gather the installed layers data
final InstalledConfiguration conf = createInstalledConfig(image);
// Step 2 - process the actual module and bundle roots
final ProcessedLayers processedLayers = process(conf, moduleRoots, bundleRoots);
final InstalledConfiguration config = processedLayers.getConf();
// Step 3 - create the actual config objects
// Process layers
final InstalledIdentityImpl installedIdentity = new InstalledIdentityImpl(identity, allPatches, image);
for (final LayerPathConfig layer : processedLayers.getLayers().values()) {
final String name = layer.name;
installedIdentity.putLayer(name, createPatchableTarget(name, layer, config.getLayerMetadataDir(name), image));
}
// Process add-ons
for (final LayerPathConfig addOn : processedLayers.getAddOns().values()) {
final String name = addOn.name;
installedIdentity.putAddOn(name, createPatchableTarget(name, addOn, config.getAddOnMetadataDir(name), image));
}
return installedIdentity;
}
|
[
"static",
"InstalledIdentity",
"load",
"(",
"final",
"InstalledImage",
"image",
",",
"final",
"ProductConfig",
"productConfig",
",",
"final",
"List",
"<",
"File",
">",
"moduleRoots",
",",
"final",
"List",
"<",
"File",
">",
"bundleRoots",
")",
"throws",
"IOException",
"{",
"// build the identity information",
"final",
"String",
"productVersion",
"=",
"productConfig",
".",
"resolveVersion",
"(",
")",
";",
"final",
"String",
"productName",
"=",
"productConfig",
".",
"resolveName",
"(",
")",
";",
"final",
"Identity",
"identity",
"=",
"new",
"AbstractLazyIdentity",
"(",
")",
"{",
"@",
"Override",
"public",
"String",
"getName",
"(",
")",
"{",
"return",
"productName",
";",
"}",
"@",
"Override",
"public",
"String",
"getVersion",
"(",
")",
"{",
"return",
"productVersion",
";",
"}",
"@",
"Override",
"public",
"InstalledImage",
"getInstalledImage",
"(",
")",
"{",
"return",
"image",
";",
"}",
"}",
";",
"final",
"Properties",
"properties",
"=",
"PatchUtils",
".",
"loadProperties",
"(",
"identity",
".",
"getDirectoryStructure",
"(",
")",
".",
"getInstallationInfo",
"(",
")",
")",
";",
"final",
"List",
"<",
"String",
">",
"allPatches",
"=",
"PatchUtils",
".",
"readRefs",
"(",
"properties",
",",
"Constants",
".",
"ALL_PATCHES",
")",
";",
"// Step 1 - gather the installed layers data",
"final",
"InstalledConfiguration",
"conf",
"=",
"createInstalledConfig",
"(",
"image",
")",
";",
"// Step 2 - process the actual module and bundle roots",
"final",
"ProcessedLayers",
"processedLayers",
"=",
"process",
"(",
"conf",
",",
"moduleRoots",
",",
"bundleRoots",
")",
";",
"final",
"InstalledConfiguration",
"config",
"=",
"processedLayers",
".",
"getConf",
"(",
")",
";",
"// Step 3 - create the actual config objects",
"// Process layers",
"final",
"InstalledIdentityImpl",
"installedIdentity",
"=",
"new",
"InstalledIdentityImpl",
"(",
"identity",
",",
"allPatches",
",",
"image",
")",
";",
"for",
"(",
"final",
"LayerPathConfig",
"layer",
":",
"processedLayers",
".",
"getLayers",
"(",
")",
".",
"values",
"(",
")",
")",
"{",
"final",
"String",
"name",
"=",
"layer",
".",
"name",
";",
"installedIdentity",
".",
"putLayer",
"(",
"name",
",",
"createPatchableTarget",
"(",
"name",
",",
"layer",
",",
"config",
".",
"getLayerMetadataDir",
"(",
"name",
")",
",",
"image",
")",
")",
";",
"}",
"// Process add-ons",
"for",
"(",
"final",
"LayerPathConfig",
"addOn",
":",
"processedLayers",
".",
"getAddOns",
"(",
")",
".",
"values",
"(",
")",
")",
"{",
"final",
"String",
"name",
"=",
"addOn",
".",
"name",
";",
"installedIdentity",
".",
"putAddOn",
"(",
"name",
",",
"createPatchableTarget",
"(",
"name",
",",
"addOn",
",",
"config",
".",
"getAddOnMetadataDir",
"(",
"name",
")",
",",
"image",
")",
")",
";",
"}",
"return",
"installedIdentity",
";",
"}"
] |
Load the available layers.
@param image the installed image
@param productConfig the product config to establish the identity
@param moduleRoots the module roots
@param bundleRoots the bundle roots
@return the layers
@throws IOException
|
[
"Load",
"the",
"available",
"layers",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java#L58-L102
|
158,695 |
wildfly/wildfly-core
|
patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java
|
LayersFactory.process
|
static ProcessedLayers process(final InstalledConfiguration conf, final List<File> moduleRoots, final List<File> bundleRoots) throws IOException {
final ProcessedLayers layers = new ProcessedLayers(conf);
// Process module roots
final LayerPathSetter moduleSetter = new LayerPathSetter() {
@Override
public boolean setPath(final LayerPathConfig pending, final File root) {
if (pending.modulePath == null) {
pending.modulePath = root;
return true;
}
return false;
}
};
for (final File moduleRoot : moduleRoots) {
processRoot(moduleRoot, layers, moduleSetter);
}
// Process bundle root
final LayerPathSetter bundleSetter = new LayerPathSetter() {
@Override
public boolean setPath(LayerPathConfig pending, File root) {
if (pending.bundlePath == null) {
pending.bundlePath = root;
return true;
}
return false;
}
};
for (final File bundleRoot : bundleRoots) {
processRoot(bundleRoot, layers, bundleSetter);
}
// if (conf.getInstalledLayers().size() != layers.getLayers().size()) {
// throw processingError("processed layers don't match expected %s, but was %s", conf.getInstalledLayers(), layers.getLayers().keySet());
// }
// if (conf.getInstalledAddOns().size() != layers.getAddOns().size()) {
// throw processingError("processed add-ons don't match expected %s, but was %s", conf.getInstalledAddOns(), layers.getAddOns().keySet());
// }
return layers;
}
|
java
|
static ProcessedLayers process(final InstalledConfiguration conf, final List<File> moduleRoots, final List<File> bundleRoots) throws IOException {
final ProcessedLayers layers = new ProcessedLayers(conf);
// Process module roots
final LayerPathSetter moduleSetter = new LayerPathSetter() {
@Override
public boolean setPath(final LayerPathConfig pending, final File root) {
if (pending.modulePath == null) {
pending.modulePath = root;
return true;
}
return false;
}
};
for (final File moduleRoot : moduleRoots) {
processRoot(moduleRoot, layers, moduleSetter);
}
// Process bundle root
final LayerPathSetter bundleSetter = new LayerPathSetter() {
@Override
public boolean setPath(LayerPathConfig pending, File root) {
if (pending.bundlePath == null) {
pending.bundlePath = root;
return true;
}
return false;
}
};
for (final File bundleRoot : bundleRoots) {
processRoot(bundleRoot, layers, bundleSetter);
}
// if (conf.getInstalledLayers().size() != layers.getLayers().size()) {
// throw processingError("processed layers don't match expected %s, but was %s", conf.getInstalledLayers(), layers.getLayers().keySet());
// }
// if (conf.getInstalledAddOns().size() != layers.getAddOns().size()) {
// throw processingError("processed add-ons don't match expected %s, but was %s", conf.getInstalledAddOns(), layers.getAddOns().keySet());
// }
return layers;
}
|
[
"static",
"ProcessedLayers",
"process",
"(",
"final",
"InstalledConfiguration",
"conf",
",",
"final",
"List",
"<",
"File",
">",
"moduleRoots",
",",
"final",
"List",
"<",
"File",
">",
"bundleRoots",
")",
"throws",
"IOException",
"{",
"final",
"ProcessedLayers",
"layers",
"=",
"new",
"ProcessedLayers",
"(",
"conf",
")",
";",
"// Process module roots",
"final",
"LayerPathSetter",
"moduleSetter",
"=",
"new",
"LayerPathSetter",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"setPath",
"(",
"final",
"LayerPathConfig",
"pending",
",",
"final",
"File",
"root",
")",
"{",
"if",
"(",
"pending",
".",
"modulePath",
"==",
"null",
")",
"{",
"pending",
".",
"modulePath",
"=",
"root",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"}",
";",
"for",
"(",
"final",
"File",
"moduleRoot",
":",
"moduleRoots",
")",
"{",
"processRoot",
"(",
"moduleRoot",
",",
"layers",
",",
"moduleSetter",
")",
";",
"}",
"// Process bundle root",
"final",
"LayerPathSetter",
"bundleSetter",
"=",
"new",
"LayerPathSetter",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"setPath",
"(",
"LayerPathConfig",
"pending",
",",
"File",
"root",
")",
"{",
"if",
"(",
"pending",
".",
"bundlePath",
"==",
"null",
")",
"{",
"pending",
".",
"bundlePath",
"=",
"root",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"}",
";",
"for",
"(",
"final",
"File",
"bundleRoot",
":",
"bundleRoots",
")",
"{",
"processRoot",
"(",
"bundleRoot",
",",
"layers",
",",
"bundleSetter",
")",
";",
"}",
"// if (conf.getInstalledLayers().size() != layers.getLayers().size()) {",
"// throw processingError(\"processed layers don't match expected %s, but was %s\", conf.getInstalledLayers(), layers.getLayers().keySet());",
"// }",
"// if (conf.getInstalledAddOns().size() != layers.getAddOns().size()) {",
"// throw processingError(\"processed add-ons don't match expected %s, but was %s\", conf.getInstalledAddOns(), layers.getAddOns().keySet());",
"// }",
"return",
"layers",
";",
"}"
] |
Process the module and bundle roots and cross check with the installed information.
@param conf the installed configuration
@param moduleRoots the module roots
@param bundleRoots the bundle roots
@return the processed layers
@throws IOException
|
[
"Process",
"the",
"module",
"and",
"bundle",
"roots",
"and",
"cross",
"check",
"with",
"the",
"installed",
"information",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java#L113-L150
|
158,696 |
wildfly/wildfly-core
|
patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java
|
LayersFactory.processRoot
|
static void processRoot(final File root, final ProcessedLayers layers, final LayerPathSetter setter) throws IOException {
final LayersConfig layersConfig = LayersConfig.getLayersConfig(root);
// Process layers
final File layersDir = new File(root, layersConfig.getLayersPath());
if (!layersDir.exists()) {
if (layersConfig.isConfigured()) {
// Bad config from user
throw PatchLogger.ROOT_LOGGER.installationNoLayersConfigFound(layersDir.getAbsolutePath());
}
// else this isn't a root that has layers and add-ons
} else {
// check for a valid layer configuration
for (final String layer : layersConfig.getLayers()) {
File layerDir = new File(layersDir, layer);
if (!layerDir.exists()) {
if (layersConfig.isConfigured()) {
// Bad config from user
throw PatchLogger.ROOT_LOGGER.installationMissingLayer(layer, layersDir.getAbsolutePath());
}
// else this isn't a standard layers and add-ons structure
return;
}
layers.addLayer(layer, layerDir, setter);
}
}
// Finally process the add-ons
final File addOnsDir = new File(root, layersConfig.getAddOnsPath());
final File[] addOnsList = addOnsDir.listFiles();
if (addOnsList != null) {
for (final File addOn : addOnsList) {
layers.addAddOn(addOn.getName(), addOn, setter);
}
}
}
|
java
|
static void processRoot(final File root, final ProcessedLayers layers, final LayerPathSetter setter) throws IOException {
final LayersConfig layersConfig = LayersConfig.getLayersConfig(root);
// Process layers
final File layersDir = new File(root, layersConfig.getLayersPath());
if (!layersDir.exists()) {
if (layersConfig.isConfigured()) {
// Bad config from user
throw PatchLogger.ROOT_LOGGER.installationNoLayersConfigFound(layersDir.getAbsolutePath());
}
// else this isn't a root that has layers and add-ons
} else {
// check for a valid layer configuration
for (final String layer : layersConfig.getLayers()) {
File layerDir = new File(layersDir, layer);
if (!layerDir.exists()) {
if (layersConfig.isConfigured()) {
// Bad config from user
throw PatchLogger.ROOT_LOGGER.installationMissingLayer(layer, layersDir.getAbsolutePath());
}
// else this isn't a standard layers and add-ons structure
return;
}
layers.addLayer(layer, layerDir, setter);
}
}
// Finally process the add-ons
final File addOnsDir = new File(root, layersConfig.getAddOnsPath());
final File[] addOnsList = addOnsDir.listFiles();
if (addOnsList != null) {
for (final File addOn : addOnsList) {
layers.addAddOn(addOn.getName(), addOn, setter);
}
}
}
|
[
"static",
"void",
"processRoot",
"(",
"final",
"File",
"root",
",",
"final",
"ProcessedLayers",
"layers",
",",
"final",
"LayerPathSetter",
"setter",
")",
"throws",
"IOException",
"{",
"final",
"LayersConfig",
"layersConfig",
"=",
"LayersConfig",
".",
"getLayersConfig",
"(",
"root",
")",
";",
"// Process layers",
"final",
"File",
"layersDir",
"=",
"new",
"File",
"(",
"root",
",",
"layersConfig",
".",
"getLayersPath",
"(",
")",
")",
";",
"if",
"(",
"!",
"layersDir",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"layersConfig",
".",
"isConfigured",
"(",
")",
")",
"{",
"// Bad config from user",
"throw",
"PatchLogger",
".",
"ROOT_LOGGER",
".",
"installationNoLayersConfigFound",
"(",
"layersDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"// else this isn't a root that has layers and add-ons",
"}",
"else",
"{",
"// check for a valid layer configuration",
"for",
"(",
"final",
"String",
"layer",
":",
"layersConfig",
".",
"getLayers",
"(",
")",
")",
"{",
"File",
"layerDir",
"=",
"new",
"File",
"(",
"layersDir",
",",
"layer",
")",
";",
"if",
"(",
"!",
"layerDir",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"layersConfig",
".",
"isConfigured",
"(",
")",
")",
"{",
"// Bad config from user",
"throw",
"PatchLogger",
".",
"ROOT_LOGGER",
".",
"installationMissingLayer",
"(",
"layer",
",",
"layersDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"// else this isn't a standard layers and add-ons structure",
"return",
";",
"}",
"layers",
".",
"addLayer",
"(",
"layer",
",",
"layerDir",
",",
"setter",
")",
";",
"}",
"}",
"// Finally process the add-ons",
"final",
"File",
"addOnsDir",
"=",
"new",
"File",
"(",
"root",
",",
"layersConfig",
".",
"getAddOnsPath",
"(",
")",
")",
";",
"final",
"File",
"[",
"]",
"addOnsList",
"=",
"addOnsDir",
".",
"listFiles",
"(",
")",
";",
"if",
"(",
"addOnsList",
"!=",
"null",
")",
"{",
"for",
"(",
"final",
"File",
"addOn",
":",
"addOnsList",
")",
"{",
"layers",
".",
"addAddOn",
"(",
"addOn",
".",
"getName",
"(",
")",
",",
"addOn",
",",
"setter",
")",
";",
"}",
"}",
"}"
] |
Process a module or bundle root.
@param root the root
@param layers the processed layers
@param setter the bundle or module path setter
@throws IOException
|
[
"Process",
"a",
"module",
"or",
"bundle",
"root",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java#L160-L193
|
158,697 |
wildfly/wildfly-core
|
patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java
|
LayersFactory.createPatchableTarget
|
static AbstractLazyPatchableTarget createPatchableTarget(final String name, final LayerPathConfig layer, final File metadata, final InstalledImage image) throws IOException {
// patchable target
return new AbstractLazyPatchableTarget() {
@Override
public InstalledImage getInstalledImage() {
return image;
}
@Override
public File getModuleRoot() {
return layer.modulePath;
}
@Override
public File getBundleRepositoryRoot() {
return layer.bundlePath;
}
public File getPatchesMetadata() {
return metadata;
}
@Override
public String getName() {
return name;
}
};
}
|
java
|
static AbstractLazyPatchableTarget createPatchableTarget(final String name, final LayerPathConfig layer, final File metadata, final InstalledImage image) throws IOException {
// patchable target
return new AbstractLazyPatchableTarget() {
@Override
public InstalledImage getInstalledImage() {
return image;
}
@Override
public File getModuleRoot() {
return layer.modulePath;
}
@Override
public File getBundleRepositoryRoot() {
return layer.bundlePath;
}
public File getPatchesMetadata() {
return metadata;
}
@Override
public String getName() {
return name;
}
};
}
|
[
"static",
"AbstractLazyPatchableTarget",
"createPatchableTarget",
"(",
"final",
"String",
"name",
",",
"final",
"LayerPathConfig",
"layer",
",",
"final",
"File",
"metadata",
",",
"final",
"InstalledImage",
"image",
")",
"throws",
"IOException",
"{",
"// patchable target",
"return",
"new",
"AbstractLazyPatchableTarget",
"(",
")",
"{",
"@",
"Override",
"public",
"InstalledImage",
"getInstalledImage",
"(",
")",
"{",
"return",
"image",
";",
"}",
"@",
"Override",
"public",
"File",
"getModuleRoot",
"(",
")",
"{",
"return",
"layer",
".",
"modulePath",
";",
"}",
"@",
"Override",
"public",
"File",
"getBundleRepositoryRoot",
"(",
")",
"{",
"return",
"layer",
".",
"bundlePath",
";",
"}",
"public",
"File",
"getPatchesMetadata",
"(",
")",
"{",
"return",
"metadata",
";",
"}",
"@",
"Override",
"public",
"String",
"getName",
"(",
")",
"{",
"return",
"name",
";",
"}",
"}",
";",
"}"
] |
Create the actual patchable target.
@param name the layer name
@param layer the layer path config
@param metadata the metadata location for this target
@param image the installed image
@return the patchable target
@throws IOException
|
[
"Create",
"the",
"actual",
"patchable",
"target",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/patching/src/main/java/org/jboss/as/patching/installation/LayersFactory.java#L205-L233
|
158,698 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/AttributeDefinition.java
|
AttributeDefinition.getAllowedValues
|
public List<ModelNode> getAllowedValues() {
if (allowedValues == null) {
return Collections.emptyList();
}
return Arrays.asList(this.allowedValues);
}
|
java
|
public List<ModelNode> getAllowedValues() {
if (allowedValues == null) {
return Collections.emptyList();
}
return Arrays.asList(this.allowedValues);
}
|
[
"public",
"List",
"<",
"ModelNode",
">",
"getAllowedValues",
"(",
")",
"{",
"if",
"(",
"allowedValues",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}",
"return",
"Arrays",
".",
"asList",
"(",
"this",
".",
"allowedValues",
")",
";",
"}"
] |
returns array with all allowed values
@return allowed values
|
[
"returns",
"array",
"with",
"all",
"allowed",
"values"
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/AttributeDefinition.java#L443-L448
|
158,699 |
wildfly/wildfly-core
|
controller/src/main/java/org/jboss/as/controller/AttributeDefinition.java
|
AttributeDefinition.addAllowedValuesToDescription
|
protected void addAllowedValuesToDescription(ModelNode result, ParameterValidator validator) {
if (allowedValues != null) {
for (ModelNode allowedValue : allowedValues) {
result.get(ModelDescriptionConstants.ALLOWED).add(allowedValue);
}
} else if (validator instanceof AllowedValuesValidator) {
AllowedValuesValidator avv = (AllowedValuesValidator) validator;
List<ModelNode> allowed = avv.getAllowedValues();
if (allowed != null) {
for (ModelNode ok : allowed) {
result.get(ModelDescriptionConstants.ALLOWED).add(ok);
}
}
}
}
|
java
|
protected void addAllowedValuesToDescription(ModelNode result, ParameterValidator validator) {
if (allowedValues != null) {
for (ModelNode allowedValue : allowedValues) {
result.get(ModelDescriptionConstants.ALLOWED).add(allowedValue);
}
} else if (validator instanceof AllowedValuesValidator) {
AllowedValuesValidator avv = (AllowedValuesValidator) validator;
List<ModelNode> allowed = avv.getAllowedValues();
if (allowed != null) {
for (ModelNode ok : allowed) {
result.get(ModelDescriptionConstants.ALLOWED).add(ok);
}
}
}
}
|
[
"protected",
"void",
"addAllowedValuesToDescription",
"(",
"ModelNode",
"result",
",",
"ParameterValidator",
"validator",
")",
"{",
"if",
"(",
"allowedValues",
"!=",
"null",
")",
"{",
"for",
"(",
"ModelNode",
"allowedValue",
":",
"allowedValues",
")",
"{",
"result",
".",
"get",
"(",
"ModelDescriptionConstants",
".",
"ALLOWED",
")",
".",
"add",
"(",
"allowedValue",
")",
";",
"}",
"}",
"else",
"if",
"(",
"validator",
"instanceof",
"AllowedValuesValidator",
")",
"{",
"AllowedValuesValidator",
"avv",
"=",
"(",
"AllowedValuesValidator",
")",
"validator",
";",
"List",
"<",
"ModelNode",
">",
"allowed",
"=",
"avv",
".",
"getAllowedValues",
"(",
")",
";",
"if",
"(",
"allowed",
"!=",
"null",
")",
"{",
"for",
"(",
"ModelNode",
"ok",
":",
"allowed",
")",
"{",
"result",
".",
"get",
"(",
"ModelDescriptionConstants",
".",
"ALLOWED",
")",
".",
"add",
"(",
"ok",
")",
";",
"}",
"}",
"}",
"}"
] |
Adds the allowed values. Override for attributes who should not use the allowed values.
@param result the node to add the allowed values to
@param validator the validator to get the allowed values from
|
[
"Adds",
"the",
"allowed",
"values",
".",
"Override",
"for",
"attributes",
"who",
"should",
"not",
"use",
"the",
"allowed",
"values",
"."
] |
cfaf0479dcbb2d320a44c5374b93b944ec39fade
|
https://github.com/wildfly/wildfly-core/blob/cfaf0479dcbb2d320a44c5374b93b944ec39fade/controller/src/main/java/org/jboss/as/controller/AttributeDefinition.java#L1136-L1150
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.