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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
16,900
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
|
WhiteboxImpl.concatenateStrings
|
private static String concatenateStrings(String... stringsToConcatenate) {
StringBuilder builder = new StringBuilder();
final int stringsLength = stringsToConcatenate.length;
for (int i = 0; i < stringsLength; i++) {
if (i == stringsLength - 1 && stringsLength != 1) {
builder.append(" or ");
} else if (i != 0) {
builder.append(", ");
}
builder.append(stringsToConcatenate[i]);
}
return builder.toString();
}
|
java
|
private static String concatenateStrings(String... stringsToConcatenate) {
StringBuilder builder = new StringBuilder();
final int stringsLength = stringsToConcatenate.length;
for (int i = 0; i < stringsLength; i++) {
if (i == stringsLength - 1 && stringsLength != 1) {
builder.append(" or ");
} else if (i != 0) {
builder.append(", ");
}
builder.append(stringsToConcatenate[i]);
}
return builder.toString();
}
|
[
"private",
"static",
"String",
"concatenateStrings",
"(",
"String",
"...",
"stringsToConcatenate",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"int",
"stringsLength",
"=",
"stringsToConcatenate",
".",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"stringsLength",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"==",
"stringsLength",
"-",
"1",
"&&",
"stringsLength",
"!=",
"1",
")",
"{",
"builder",
".",
"append",
"(",
"\" or \"",
")",
";",
"}",
"else",
"if",
"(",
"i",
"!=",
"0",
")",
"{",
"builder",
".",
"append",
"(",
"\", \"",
")",
";",
"}",
"builder",
".",
"append",
"(",
"stringsToConcatenate",
"[",
"i",
"]",
")",
";",
"}",
"return",
"builder",
".",
"toString",
"(",
")",
";",
"}"
] |
Concatenate strings.
@param stringsToConcatenate the strings to concatenate
@return the string
|
[
"Concatenate",
"strings",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java#L2366-L2378
|
16,901
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
|
WhiteboxImpl.isPotentialVarArgsMethod
|
private static boolean isPotentialVarArgsMethod(Method method, Object[] arguments) {
return doesParameterTypesMatchForVarArgsInvocation(method.isVarArgs(), method.getParameterTypes(), arguments);
}
|
java
|
private static boolean isPotentialVarArgsMethod(Method method, Object[] arguments) {
return doesParameterTypesMatchForVarArgsInvocation(method.isVarArgs(), method.getParameterTypes(), arguments);
}
|
[
"private",
"static",
"boolean",
"isPotentialVarArgsMethod",
"(",
"Method",
"method",
",",
"Object",
"[",
"]",
"arguments",
")",
"{",
"return",
"doesParameterTypesMatchForVarArgsInvocation",
"(",
"method",
".",
"isVarArgs",
"(",
")",
",",
"method",
".",
"getParameterTypes",
"(",
")",
",",
"arguments",
")",
";",
"}"
] |
Checks if is potential var args method.
@param method the method
@param arguments the arguments
@return true, if is potential var args method
|
[
"Checks",
"if",
"is",
"potential",
"var",
"args",
"method",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java#L2387-L2389
|
16,902
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
|
WhiteboxImpl.doesParameterTypesMatchForVarArgsInvocation
|
static boolean doesParameterTypesMatchForVarArgsInvocation(boolean isVarArgs, Class<?>[] parameterTypes,
Object[] arguments) {
if (isVarArgs && arguments != null && arguments.length >= 1 && parameterTypes != null
&& parameterTypes.length >= 1) {
final Class<?> componentType = parameterTypes[parameterTypes.length - 1].getComponentType();
final Object lastArgument = arguments[arguments.length - 1];
if (lastArgument != null) {
final Class<?> lastArgumentTypeAsPrimitive = getTypeAsPrimitiveIfWrapped(lastArgument);
final Class<?> varArgsParameterTypeAsPrimitive = getTypeAsPrimitiveIfWrapped(componentType);
isVarArgs = varArgsParameterTypeAsPrimitive.isAssignableFrom(lastArgumentTypeAsPrimitive);
}
}
return isVarArgs && checkArgumentTypesMatchParameterTypes(isVarArgs, parameterTypes, arguments);
}
|
java
|
static boolean doesParameterTypesMatchForVarArgsInvocation(boolean isVarArgs, Class<?>[] parameterTypes,
Object[] arguments) {
if (isVarArgs && arguments != null && arguments.length >= 1 && parameterTypes != null
&& parameterTypes.length >= 1) {
final Class<?> componentType = parameterTypes[parameterTypes.length - 1].getComponentType();
final Object lastArgument = arguments[arguments.length - 1];
if (lastArgument != null) {
final Class<?> lastArgumentTypeAsPrimitive = getTypeAsPrimitiveIfWrapped(lastArgument);
final Class<?> varArgsParameterTypeAsPrimitive = getTypeAsPrimitiveIfWrapped(componentType);
isVarArgs = varArgsParameterTypeAsPrimitive.isAssignableFrom(lastArgumentTypeAsPrimitive);
}
}
return isVarArgs && checkArgumentTypesMatchParameterTypes(isVarArgs, parameterTypes, arguments);
}
|
[
"static",
"boolean",
"doesParameterTypesMatchForVarArgsInvocation",
"(",
"boolean",
"isVarArgs",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"parameterTypes",
",",
"Object",
"[",
"]",
"arguments",
")",
"{",
"if",
"(",
"isVarArgs",
"&&",
"arguments",
"!=",
"null",
"&&",
"arguments",
".",
"length",
">=",
"1",
"&&",
"parameterTypes",
"!=",
"null",
"&&",
"parameterTypes",
".",
"length",
">=",
"1",
")",
"{",
"final",
"Class",
"<",
"?",
">",
"componentType",
"=",
"parameterTypes",
"[",
"parameterTypes",
".",
"length",
"-",
"1",
"]",
".",
"getComponentType",
"(",
")",
";",
"final",
"Object",
"lastArgument",
"=",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"lastArgument",
"!=",
"null",
")",
"{",
"final",
"Class",
"<",
"?",
">",
"lastArgumentTypeAsPrimitive",
"=",
"getTypeAsPrimitiveIfWrapped",
"(",
"lastArgument",
")",
";",
"final",
"Class",
"<",
"?",
">",
"varArgsParameterTypeAsPrimitive",
"=",
"getTypeAsPrimitiveIfWrapped",
"(",
"componentType",
")",
";",
"isVarArgs",
"=",
"varArgsParameterTypeAsPrimitive",
".",
"isAssignableFrom",
"(",
"lastArgumentTypeAsPrimitive",
")",
";",
"}",
"}",
"return",
"isVarArgs",
"&&",
"checkArgumentTypesMatchParameterTypes",
"(",
"isVarArgs",
",",
"parameterTypes",
",",
"arguments",
")",
";",
"}"
] |
Does parameter types match for var args invocation.
@param isVarArgs the is var args
@param parameterTypes the parameter types
@param arguments the arguments
@return true, if successful
|
[
"Does",
"parameter",
"types",
"match",
"for",
"var",
"args",
"invocation",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java#L2399-L2412
|
16,903
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
|
WhiteboxImpl.copyState
|
static void copyState(Object object, Object context, FieldMatchingStrategy strategy) {
if (object == null) {
throw new IllegalArgumentException("object to set state cannot be null");
} else if (context == null) {
throw new IllegalArgumentException("context cannot be null");
} else if (strategy == null) {
throw new IllegalArgumentException("strategy cannot be null");
}
Set<Field> allFields = isClass(context) ? getAllStaticFields(getType(context)) : getAllInstanceFields(context);
for (Field field : allFields) {
try {
final boolean isStaticField = Modifier.isStatic(field.getModifiers());
setInternalState(isStaticField ? getType(object) : object, field.getType(), field.get(context));
} catch (FieldNotFoundException e) {
if (strategy == FieldMatchingStrategy.STRICT) {
throw e;
}
} catch (IllegalAccessException e) {
// Should never happen
throw new RuntimeException(
"Internal Error: Failed to get the field value in method setInternalStateFromContext.", e);
}
}
}
|
java
|
static void copyState(Object object, Object context, FieldMatchingStrategy strategy) {
if (object == null) {
throw new IllegalArgumentException("object to set state cannot be null");
} else if (context == null) {
throw new IllegalArgumentException("context cannot be null");
} else if (strategy == null) {
throw new IllegalArgumentException("strategy cannot be null");
}
Set<Field> allFields = isClass(context) ? getAllStaticFields(getType(context)) : getAllInstanceFields(context);
for (Field field : allFields) {
try {
final boolean isStaticField = Modifier.isStatic(field.getModifiers());
setInternalState(isStaticField ? getType(object) : object, field.getType(), field.get(context));
} catch (FieldNotFoundException e) {
if (strategy == FieldMatchingStrategy.STRICT) {
throw e;
}
} catch (IllegalAccessException e) {
// Should never happen
throw new RuntimeException(
"Internal Error: Failed to get the field value in method setInternalStateFromContext.", e);
}
}
}
|
[
"static",
"void",
"copyState",
"(",
"Object",
"object",
",",
"Object",
"context",
",",
"FieldMatchingStrategy",
"strategy",
")",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"object to set state cannot be null\"",
")",
";",
"}",
"else",
"if",
"(",
"context",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"context cannot be null\"",
")",
";",
"}",
"else",
"if",
"(",
"strategy",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"strategy cannot be null\"",
")",
";",
"}",
"Set",
"<",
"Field",
">",
"allFields",
"=",
"isClass",
"(",
"context",
")",
"?",
"getAllStaticFields",
"(",
"getType",
"(",
"context",
")",
")",
":",
"getAllInstanceFields",
"(",
"context",
")",
";",
"for",
"(",
"Field",
"field",
":",
"allFields",
")",
"{",
"try",
"{",
"final",
"boolean",
"isStaticField",
"=",
"Modifier",
".",
"isStatic",
"(",
"field",
".",
"getModifiers",
"(",
")",
")",
";",
"setInternalState",
"(",
"isStaticField",
"?",
"getType",
"(",
"object",
")",
":",
"object",
",",
"field",
".",
"getType",
"(",
")",
",",
"field",
".",
"get",
"(",
"context",
")",
")",
";",
"}",
"catch",
"(",
"FieldNotFoundException",
"e",
")",
"{",
"if",
"(",
"strategy",
"==",
"FieldMatchingStrategy",
".",
"STRICT",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"// Should never happen",
"throw",
"new",
"RuntimeException",
"(",
"\"Internal Error: Failed to get the field value in method setInternalStateFromContext.\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Copy state.
@param object the object
@param context the context
@param strategy The field matching strategy.
|
[
"Copy",
"state",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java#L2534-L2558
|
16,904
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
|
WhiteboxImpl.convertParameterTypesToPrimitive
|
private static Class<?>[] convertParameterTypesToPrimitive(Class<?>[] parameterTypes) {
Class<?>[] converted = new Class<?>[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> primitiveWrapperType = PrimitiveWrapper.getPrimitiveFromWrapperType(parameterTypes[i]);
if (primitiveWrapperType == null) {
converted[i] = parameterTypes[i];
} else {
converted[i] = primitiveWrapperType;
}
}
return converted;
}
|
java
|
private static Class<?>[] convertParameterTypesToPrimitive(Class<?>[] parameterTypes) {
Class<?>[] converted = new Class<?>[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> primitiveWrapperType = PrimitiveWrapper.getPrimitiveFromWrapperType(parameterTypes[i]);
if (primitiveWrapperType == null) {
converted[i] = parameterTypes[i];
} else {
converted[i] = primitiveWrapperType;
}
}
return converted;
}
|
[
"private",
"static",
"Class",
"<",
"?",
">",
"[",
"]",
"convertParameterTypesToPrimitive",
"(",
"Class",
"<",
"?",
">",
"[",
"]",
"parameterTypes",
")",
"{",
"Class",
"<",
"?",
">",
"[",
"]",
"converted",
"=",
"new",
"Class",
"<",
"?",
">",
"[",
"parameterTypes",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parameterTypes",
".",
"length",
";",
"i",
"++",
")",
"{",
"Class",
"<",
"?",
">",
"primitiveWrapperType",
"=",
"PrimitiveWrapper",
".",
"getPrimitiveFromWrapperType",
"(",
"parameterTypes",
"[",
"i",
"]",
")",
";",
"if",
"(",
"primitiveWrapperType",
"==",
"null",
")",
"{",
"converted",
"[",
"i",
"]",
"=",
"parameterTypes",
"[",
"i",
"]",
";",
"}",
"else",
"{",
"converted",
"[",
"i",
"]",
"=",
"primitiveWrapperType",
";",
"}",
"}",
"return",
"converted",
";",
"}"
] |
Convert parameter types to primitive.
@param parameterTypes the parameter types
@return the class[]
|
[
"Convert",
"parameter",
"types",
"to",
"primitive",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java#L2577-L2588
|
16,905
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createMock
|
public static <T> T createMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, methods);
}
|
java
|
public static <T> T createMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, methods);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"ConstructorArgs",
"constructorArgs",
",",
"Method",
"...",
"methods",
")",
"{",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"DefaultMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"methods",
")",
";",
"}"
] |
Creates a mock object that supports mocking of final and native methods
and invokes a specific constructor.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArgs The constructor arguments that will be used to invoke a
special constructor.
@param methods optionally what methods to mock
@return the mock object.
|
[
"Creates",
"a",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L109-L111
|
16,906
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createMock
|
public static <T> T createMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, (Method[]) null);
}
|
java
|
public static <T> T createMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, (Method[]) null);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"constructorArguments",
")",
"{",
"Constructor",
"<",
"?",
">",
"constructor",
"=",
"WhiteboxImpl",
".",
"findUniqueConstructorOrThrowException",
"(",
"type",
",",
"constructorArguments",
")",
";",
"ConstructorArgs",
"constructorArgs",
"=",
"new",
"ConstructorArgs",
"(",
"constructor",
",",
"constructorArguments",
")",
";",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"DefaultMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}"
] |
Creates a mock object that supports mocking of final and native methods
and invokes a specific constructor based on the supplied argument values.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArguments The constructor arguments that will be used to invoke a
certain constructor.
@return the mock object.
|
[
"Creates",
"a",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"based",
"on",
"the",
"supplied",
"argument",
"values",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L123-L127
|
16,907
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictMock
|
public static synchronized <T> T createStrictMock(Class<T> type, Method... methods) {
return doMock(type, false, new StrictMockStrategy(), null, methods);
}
|
java
|
public static synchronized <T> T createStrictMock(Class<T> type, Method... methods) {
return doMock(type, false, new StrictMockStrategy(), null, methods);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createStrictMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Method",
"...",
"methods",
")",
"{",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"StrictMockStrategy",
"(",
")",
",",
"null",
",",
"methods",
")",
";",
"}"
] |
Creates a strict mock object that supports mocking of final and native
methods.
@param <T> the type of the mock object
@param type the type of the mock object
@param methods optionally what methods to mock
@return the mock object.
|
[
"Creates",
"a",
"strict",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L138-L140
|
16,908
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNiceMock
|
public static synchronized <T> T createNiceMock(Class<T> type) {
return doMock(type, false, new NiceMockStrategy(), null, (Method[]) null);
}
|
java
|
public static synchronized <T> T createNiceMock(Class<T> type) {
return doMock(type, false, new NiceMockStrategy(), null, (Method[]) null);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createNiceMock",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"NiceMockStrategy",
"(",
")",
",",
"null",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}"
] |
Creates a nice mock object that supports mocking of final and native
methods.
@param <T> the type of the mock object
@param type the type of the mock object
@return the mock object.
|
[
"Creates",
"a",
"nice",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L175-L177
|
16,909
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictMock
|
public static <T> T createStrictMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new StrictMockStrategy(), constructorArgs, methods);
}
|
java
|
public static <T> T createStrictMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new StrictMockStrategy(), constructorArgs, methods);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createStrictMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"ConstructorArgs",
"constructorArgs",
",",
"Method",
"...",
"methods",
")",
"{",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"StrictMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"methods",
")",
";",
"}"
] |
Creates a strict mock object that supports mocking of final and native
methods and invokes a specific constructor.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArgs The constructor arguments that will be used to invoke a
special constructor.
@param methods optionally what methods to mock
@return the mock object.
|
[
"Creates",
"a",
"strict",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L190-L192
|
16,910
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNiceMock
|
public static <T> T createNiceMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new NiceMockStrategy(), constructorArgs, methods);
}
|
java
|
public static <T> T createNiceMock(Class<T> type, ConstructorArgs constructorArgs, Method... methods) {
return doMock(type, false, new NiceMockStrategy(), constructorArgs, methods);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createNiceMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"ConstructorArgs",
"constructorArgs",
",",
"Method",
"...",
"methods",
")",
"{",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"NiceMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"methods",
")",
";",
"}"
] |
Creates a nice mock object that supports mocking of final and native
methods and invokes a specific constructor.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArgs The constructor arguments that will be used to invoke a
special constructor.
@param methods optionally what methods to mock
@return the mock object.
|
[
"Creates",
"a",
"nice",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L205-L207
|
16,911
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictMock
|
public static <T> T createStrictMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new StrictMockStrategy(), constructorArgs, (Method[]) null);
}
|
java
|
public static <T> T createStrictMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new StrictMockStrategy(), constructorArgs, (Method[]) null);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createStrictMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"constructorArguments",
")",
"{",
"Constructor",
"<",
"?",
">",
"constructor",
"=",
"WhiteboxImpl",
".",
"findUniqueConstructorOrThrowException",
"(",
"type",
",",
"constructorArguments",
")",
";",
"ConstructorArgs",
"constructorArgs",
"=",
"new",
"ConstructorArgs",
"(",
"constructor",
",",
"constructorArguments",
")",
";",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"StrictMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}"
] |
Creates a strict mock object that supports mocking of final and native
methods and invokes a specific constructor based on the supplied argument
values.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArguments The constructor arguments that will be used to invoke a
certain constructor.
@return the mock object.
|
[
"Creates",
"a",
"strict",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"based",
"on",
"the",
"supplied",
"argument",
"values",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L220-L224
|
16,912
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNiceMock
|
public static <T> T createNiceMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new NiceMockStrategy(), constructorArgs, (Method[]) null);
}
|
java
|
public static <T> T createNiceMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new NiceMockStrategy(), constructorArgs, (Method[]) null);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"createNiceMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"constructorArguments",
")",
"{",
"Constructor",
"<",
"?",
">",
"constructor",
"=",
"WhiteboxImpl",
".",
"findUniqueConstructorOrThrowException",
"(",
"type",
",",
"constructorArguments",
")",
";",
"ConstructorArgs",
"constructorArgs",
"=",
"new",
"ConstructorArgs",
"(",
"constructor",
",",
"constructorArguments",
")",
";",
"return",
"doMock",
"(",
"type",
",",
"false",
",",
"new",
"NiceMockStrategy",
"(",
")",
",",
"constructorArgs",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}"
] |
Creates a nice mock object that supports mocking of final and native
methods and invokes a specific constructor based on the supplied argument
values.
@param <T> the type of the mock object
@param type the type of the mock object
@param constructorArguments The constructor arguments that will be used to invoke a
certain constructor.
@return the mock object.
|
[
"Creates",
"a",
"nice",
"mock",
"object",
"that",
"supports",
"mocking",
"of",
"final",
"and",
"native",
"methods",
"and",
"invokes",
"a",
"specific",
"constructor",
"based",
"on",
"the",
"supplied",
"argument",
"values",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L237-L241
|
16,913
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.mockStatic
|
public static synchronized void mockStatic(Class<?> type, Method... methods) {
doMock(type, true, new DefaultMockStrategy(), null, methods);
}
|
java
|
public static synchronized void mockStatic(Class<?> type, Method... methods) {
doMock(type, true, new DefaultMockStrategy(), null, methods);
}
|
[
"public",
"static",
"synchronized",
"void",
"mockStatic",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Method",
"...",
"methods",
")",
"{",
"doMock",
"(",
"type",
",",
"true",
",",
"new",
"DefaultMockStrategy",
"(",
")",
",",
"null",
",",
"methods",
")",
";",
"}"
] |
Enable static mocking for a class.
@param type the class to enable static mocking
@param methods optionally what methods to mock
|
[
"Enable",
"static",
"mocking",
"for",
"a",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L249-L251
|
16,914
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.mockStaticStrict
|
public static synchronized void mockStaticStrict(Class<?> type) {
doMock(type, true, new StrictMockStrategy(), null, (Method[]) null);
}
|
java
|
public static synchronized void mockStaticStrict(Class<?> type) {
doMock(type, true, new StrictMockStrategy(), null, (Method[]) null);
}
|
[
"public",
"static",
"synchronized",
"void",
"mockStaticStrict",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"doMock",
"(",
"type",
",",
"true",
",",
"new",
"StrictMockStrategy",
"(",
")",
",",
"null",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}"
] |
Enable strict static mocking for a class.
@param type the class to enable static mocking
|
[
"Enable",
"strict",
"static",
"mocking",
"for",
"a",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L277-L279
|
16,915
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.mockStaticNice
|
public static synchronized void mockStaticNice(Class<?> type, Method... methods) {
doMock(type, true, new NiceMockStrategy(), null, methods);
}
|
java
|
public static synchronized void mockStaticNice(Class<?> type, Method... methods) {
doMock(type, true, new NiceMockStrategy(), null, methods);
}
|
[
"public",
"static",
"synchronized",
"void",
"mockStaticNice",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Method",
"...",
"methods",
")",
"{",
"doMock",
"(",
"type",
",",
"true",
",",
"new",
"NiceMockStrategy",
"(",
")",
",",
"null",
",",
"methods",
")",
";",
"}"
] |
Enable nice static mocking for a class.
@param type the class to enable static mocking
@param methods optionally what methods to mock
|
[
"Enable",
"nice",
"static",
"mocking",
"for",
"a",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L287-L289
|
16,916
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createPartialMockForAllMethodsExcept
|
public static synchronized <T> T createPartialMockForAllMethodsExcept(Class<T> type, String methodNameToExclude,
Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
java
|
public static synchronized <T> T createPartialMockForAllMethodsExcept(Class<T> type, String methodNameToExclude,
Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createPartialMockForAllMethodsExcept",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToExclude",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"moreTypes",
")",
"{",
"/*\n * The reason why we've split the first and \"additional types\" is\n * because it should not intervene with the mockAllExcept(type,\n * String...methodNames) method.\n */",
"final",
"Class",
"<",
"?",
">",
"[",
"]",
"argumentTypes",
"=",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"moreTypes",
")",
";",
"return",
"createMock",
"(",
"type",
",",
"WhiteboxImpl",
".",
"getAllMethodsExcept",
"(",
"type",
",",
"methodNameToExclude",
",",
"argumentTypes",
")",
")",
";",
"}"
] |
Mock all methods of a class except for a specific one. Use this method
only if you have several overloaded methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToExclude The name of the method not to mock.
@param firstArgumentType The type of the first parameter of the method not to mock
@param moreTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Mock",
"all",
"methods",
"of",
"a",
"class",
"except",
"for",
"a",
"specific",
"one",
".",
"Use",
"this",
"method",
"only",
"if",
"you",
"have",
"several",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L396-L406
|
16,917
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNicePartialMockForAllMethodsExcept
|
public static synchronized <T> T createNicePartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createNiceMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
java
|
public static synchronized <T> T createNicePartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createNiceMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createNicePartialMockForAllMethodsExcept",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToExclude",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"moreTypes",
")",
"{",
"/*\n * The reason why we've split the first and \"additional types\" is\n * because it should not intervene with the mockAllExcept(type,\n * String...methodNames) method.\n */",
"final",
"Class",
"<",
"?",
">",
"[",
"]",
"argumentTypes",
"=",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"moreTypes",
")",
";",
"return",
"createNiceMock",
"(",
"type",
",",
"WhiteboxImpl",
".",
"getAllMethodsExcept",
"(",
"type",
",",
"methodNameToExclude",
",",
"argumentTypes",
")",
")",
";",
"}"
] |
Mock all methods of a class except for a specific one nicely. Use this
method only if you have several overloaded methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToExclude The name of the method not to mock.
@param firstArgumentType The type of the first parameter of the method not to mock
@param moreTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Mock",
"all",
"methods",
"of",
"a",
"class",
"except",
"for",
"a",
"specific",
"one",
"nicely",
".",
"Use",
"this",
"method",
"only",
"if",
"you",
"have",
"several",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L420-L430
|
16,918
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictPartialMockForAllMethodsExcept
|
public static synchronized <T> T createStrictPartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createStrictMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
java
|
public static synchronized <T> T createStrictPartialMockForAllMethodsExcept(Class<T> type,
String methodNameToExclude, Class<?> firstArgumentType, Class<?>... moreTypes) {
/*
* The reason why we've split the first and "additional types" is
* because it should not intervene with the mockAllExcept(type,
* String...methodNames) method.
*/
final Class<?>[] argumentTypes = mergeArgumentTypes(firstArgumentType, moreTypes);
return createStrictMock(type, WhiteboxImpl.getAllMethodsExcept(type, methodNameToExclude, argumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createStrictPartialMockForAllMethodsExcept",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToExclude",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"moreTypes",
")",
"{",
"/*\n * The reason why we've split the first and \"additional types\" is\n * because it should not intervene with the mockAllExcept(type,\n * String...methodNames) method.\n */",
"final",
"Class",
"<",
"?",
">",
"[",
"]",
"argumentTypes",
"=",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"moreTypes",
")",
";",
"return",
"createStrictMock",
"(",
"type",
",",
"WhiteboxImpl",
".",
"getAllMethodsExcept",
"(",
"type",
",",
"methodNameToExclude",
",",
"argumentTypes",
")",
")",
";",
"}"
] |
Mock all methods of a class except for a specific one strictly. Use this
method only if you have several overloaded methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToExclude The name of the method not to mock.
@param firstArgumentType The type of the first parameter of the method not to mock
@param moreTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Mock",
"all",
"methods",
"of",
"a",
"class",
"except",
"for",
"a",
"specific",
"one",
"strictly",
".",
"Use",
"this",
"method",
"only",
"if",
"you",
"have",
"several",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L444-L454
|
16,919
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createPartialMock
|
public static synchronized <T> T createPartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new DefaultMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
java
|
public static synchronized <T> T createPartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new DefaultMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createPartialMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToMock",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"additionalArgumentTypes",
")",
"{",
"return",
"doMockSpecific",
"(",
"type",
",",
"new",
"DefaultMockStrategy",
"(",
")",
",",
"new",
"String",
"[",
"]",
"{",
"methodNameToMock",
"}",
",",
"null",
",",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"additionalArgumentTypes",
")",
")",
";",
"}"
] |
Mock a single specific method. Use this to handle overloaded methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToMock The name of the method to mock
@param firstArgumentType The type of the first parameter of the method to mock
@param additionalArgumentTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Mock",
"a",
"single",
"specific",
"method",
".",
"Use",
"this",
"to",
"handle",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L467-L471
|
16,920
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictPartialMock
|
public static synchronized <T> T createStrictPartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new StrictMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
java
|
public static synchronized <T> T createStrictPartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new StrictMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createStrictPartialMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToMock",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"additionalArgumentTypes",
")",
"{",
"return",
"doMockSpecific",
"(",
"type",
",",
"new",
"StrictMockStrategy",
"(",
")",
",",
"new",
"String",
"[",
"]",
"{",
"methodNameToMock",
"}",
",",
"null",
",",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"additionalArgumentTypes",
")",
")",
";",
"}"
] |
Strictly mock a single specific method. Use this to handle overloaded
methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToMock The name of the method to mock
@param firstArgumentType The type of the first parameter of the method to mock
@param additionalArgumentTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Strictly",
"mock",
"a",
"single",
"specific",
"method",
".",
"Use",
"this",
"to",
"handle",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L485-L489
|
16,921
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNicePartialMock
|
public static synchronized <T> T createNicePartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new NiceMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
java
|
public static synchronized <T> T createNicePartialMock(Class<T> type, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
return doMockSpecific(type, new NiceMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createNicePartialMock",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"String",
"methodNameToMock",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"additionalArgumentTypes",
")",
"{",
"return",
"doMockSpecific",
"(",
"type",
",",
"new",
"NiceMockStrategy",
"(",
")",
",",
"new",
"String",
"[",
"]",
"{",
"methodNameToMock",
"}",
",",
"null",
",",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"additionalArgumentTypes",
")",
")",
";",
"}"
] |
Nicely mock a single specific method. Use this to handle overloaded
methods.
@param <T> The type of the mock.
@param type The type that'll be used to create a mock instance.
@param methodNameToMock The name of the method to mock
@param firstArgumentType The type of the first parameter of the method to mock
@param additionalArgumentTypes Optionally more parameter types that defines the method. Note
that this is only needed to separate overloaded methods.
@return A mock object of type <T>.
|
[
"Nicely",
"mock",
"a",
"single",
"specific",
"method",
".",
"Use",
"this",
"to",
"handle",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L503-L507
|
16,922
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.mockStaticPartial
|
public static synchronized void mockStaticPartial(Class<?> clazz, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
doMockSpecific(clazz, new DefaultMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
java
|
public static synchronized void mockStaticPartial(Class<?> clazz, String methodNameToMock,
Class<?> firstArgumentType, Class<?>... additionalArgumentTypes) {
doMockSpecific(clazz, new DefaultMockStrategy(), new String[]{methodNameToMock}, null,
mergeArgumentTypes(firstArgumentType, additionalArgumentTypes));
}
|
[
"public",
"static",
"synchronized",
"void",
"mockStaticPartial",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"methodNameToMock",
",",
"Class",
"<",
"?",
">",
"firstArgumentType",
",",
"Class",
"<",
"?",
">",
"...",
"additionalArgumentTypes",
")",
"{",
"doMockSpecific",
"(",
"clazz",
",",
"new",
"DefaultMockStrategy",
"(",
")",
",",
"new",
"String",
"[",
"]",
"{",
"methodNameToMock",
"}",
",",
"null",
",",
"mergeArgumentTypes",
"(",
"firstArgumentType",
",",
"additionalArgumentTypes",
")",
")",
";",
"}"
] |
Mock a single static method.
@param clazz The class where the method is specified in.
@param methodNameToMock The first argument
@param firstArgumentType The first argument type.
@param additionalArgumentTypes Optional additional argument types.
|
[
"Mock",
"a",
"single",
"static",
"method",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L517-L521
|
16,923
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.expectPrivate
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Class<?> clazz, Method method,
Object... arguments) throws Exception {
return doExpectPrivate(clazz, method, arguments);
}
|
java
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Class<?> clazz, Method method,
Object... arguments) throws Exception {
return doExpectPrivate(clazz, method, arguments);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"IExpectationSetters",
"<",
"T",
">",
"expectPrivate",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"Method",
"method",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"return",
"doExpectPrivate",
"(",
"clazz",
",",
"method",
",",
"arguments",
")",
";",
"}"
] |
Used to specify expectations on private static methods. If possible use
variant with only method name.
|
[
"Used",
"to",
"specify",
"expectations",
"on",
"private",
"static",
"methods",
".",
"If",
"possible",
"use",
"variant",
"with",
"only",
"method",
"name",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1140-L1143
|
16,924
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.expectPrivate
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, Method method,
Object... arguments) throws Exception {
return doExpectPrivate(instance, method, arguments);
}
|
java
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, Method method,
Object... arguments) throws Exception {
return doExpectPrivate(instance, method, arguments);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"IExpectationSetters",
"<",
"T",
">",
"expectPrivate",
"(",
"Object",
"instance",
",",
"Method",
"method",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"return",
"doExpectPrivate",
"(",
"instance",
",",
"method",
",",
"arguments",
")",
";",
"}"
] |
Used to specify expectations on private methods. If possible use variant
with only method name.
|
[
"Used",
"to",
"specify",
"expectations",
"on",
"private",
"methods",
".",
"If",
"possible",
"use",
"variant",
"with",
"only",
"method",
"name",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1149-L1152
|
16,925
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.expectPrivate
|
@SuppressWarnings("all")
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (arguments == null) {
arguments = new Object[0];
}
if (instance == null) {
throw new IllegalArgumentException("instance cannot be null.");
} else if (arguments.length != parameterTypes.length) {
throw new IllegalArgumentException(
"The length of the arguments must be equal to the number of parameter types.");
}
Method foundMethod = Whitebox.getMethod(instance.getClass(), methodName, parameterTypes);
WhiteboxImpl.throwExceptionIfMethodWasNotFound(instance.getClass(), methodName, foundMethod, parameterTypes);
return doExpectPrivate(instance, foundMethod, arguments);
}
|
java
|
@SuppressWarnings("all")
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (arguments == null) {
arguments = new Object[0];
}
if (instance == null) {
throw new IllegalArgumentException("instance cannot be null.");
} else if (arguments.length != parameterTypes.length) {
throw new IllegalArgumentException(
"The length of the arguments must be equal to the number of parameter types.");
}
Method foundMethod = Whitebox.getMethod(instance.getClass(), methodName, parameterTypes);
WhiteboxImpl.throwExceptionIfMethodWasNotFound(instance.getClass(), methodName, foundMethod, parameterTypes);
return doExpectPrivate(instance, foundMethod, arguments);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"all\"",
")",
"public",
"static",
"synchronized",
"<",
"T",
">",
"IExpectationSetters",
"<",
"T",
">",
"expectPrivate",
"(",
"Object",
"instance",
",",
"String",
"methodName",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"parameterTypes",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"if",
"(",
"arguments",
"==",
"null",
")",
"{",
"arguments",
"=",
"new",
"Object",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"instance",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"instance cannot be null.\"",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"!=",
"parameterTypes",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The length of the arguments must be equal to the number of parameter types.\"",
")",
";",
"}",
"Method",
"foundMethod",
"=",
"Whitebox",
".",
"getMethod",
"(",
"instance",
".",
"getClass",
"(",
")",
",",
"methodName",
",",
"parameterTypes",
")",
";",
"WhiteboxImpl",
".",
"throwExceptionIfMethodWasNotFound",
"(",
"instance",
".",
"getClass",
"(",
")",
",",
"methodName",
",",
"foundMethod",
",",
"parameterTypes",
")",
";",
"return",
"doExpectPrivate",
"(",
"instance",
",",
"foundMethod",
",",
"arguments",
")",
";",
"}"
] |
Used to specify expectations on private methods. Use this method to
handle overloaded methods.
|
[
"Used",
"to",
"specify",
"expectations",
"on",
"private",
"methods",
".",
"Use",
"this",
"method",
"to",
"handle",
"overloaded",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1158-L1178
|
16,926
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.expectPrivate
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Object... arguments) throws Exception {
if (instance == null) {
throw new IllegalArgumentException("Instance or class cannot be null.");
}
return expectPrivate(instance, methodName, Whitebox.getType(instance), arguments);
}
|
java
|
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Object... arguments) throws Exception {
if (instance == null) {
throw new IllegalArgumentException("Instance or class cannot be null.");
}
return expectPrivate(instance, methodName, Whitebox.getType(instance), arguments);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"IExpectationSetters",
"<",
"T",
">",
"expectPrivate",
"(",
"Object",
"instance",
",",
"String",
"methodName",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"if",
"(",
"instance",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Instance or class cannot be null.\"",
")",
";",
"}",
"return",
"expectPrivate",
"(",
"instance",
",",
"methodName",
",",
"Whitebox",
".",
"getType",
"(",
"instance",
")",
",",
"arguments",
")",
";",
"}"
] |
Used to specify expectations on methods using the method name. Works on
for example private or package private methods.
|
[
"Used",
"to",
"specify",
"expectations",
"on",
"methods",
"using",
"the",
"method",
"name",
".",
"Works",
"on",
"for",
"example",
"private",
"or",
"package",
"private",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1184-L1191
|
16,927
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.isEasyMocked
|
private static boolean isEasyMocked(Object mock) {
return Enhancer.isEnhanced(mock.getClass()) || Proxy.isProxyClass(mock.getClass());
}
|
java
|
private static boolean isEasyMocked(Object mock) {
return Enhancer.isEnhanced(mock.getClass()) || Proxy.isProxyClass(mock.getClass());
}
|
[
"private",
"static",
"boolean",
"isEasyMocked",
"(",
"Object",
"mock",
")",
"{",
"return",
"Enhancer",
".",
"isEnhanced",
"(",
"mock",
".",
"getClass",
"(",
")",
")",
"||",
"Proxy",
".",
"isProxyClass",
"(",
"mock",
".",
"getClass",
"(",
")",
")",
";",
"}"
] |
Test if a object is a mock created by EasyMock or not.
|
[
"Test",
"if",
"a",
"object",
"is",
"a",
"mock",
"created",
"by",
"EasyMock",
"or",
"not",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1270-L1272
|
16,928
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.reset
|
public static synchronized void reset(Class<?>... classMocks) {
for (Class<?> type : classMocks) {
final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type);
if (invocationHandler != null) {
invocationHandler.reset();
}
NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type);
if (newInvocationControl != null) {
try {
newInvocationControl.reset();
} catch (AssertionError e) {
NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
}
}
}
|
java
|
public static synchronized void reset(Class<?>... classMocks) {
for (Class<?> type : classMocks) {
final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type);
if (invocationHandler != null) {
invocationHandler.reset();
}
NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type);
if (newInvocationControl != null) {
try {
newInvocationControl.reset();
} catch (AssertionError e) {
NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
}
}
}
|
[
"public",
"static",
"synchronized",
"void",
"reset",
"(",
"Class",
"<",
"?",
">",
"...",
"classMocks",
")",
"{",
"for",
"(",
"Class",
"<",
"?",
">",
"type",
":",
"classMocks",
")",
"{",
"final",
"MethodInvocationControl",
"invocationHandler",
"=",
"MockRepository",
".",
"getStaticMethodInvocationControl",
"(",
"type",
")",
";",
"if",
"(",
"invocationHandler",
"!=",
"null",
")",
"{",
"invocationHandler",
".",
"reset",
"(",
")",
";",
"}",
"NewInvocationControl",
"<",
"?",
">",
"newInvocationControl",
"=",
"MockRepository",
".",
"getNewInstanceControl",
"(",
"type",
")",
";",
"if",
"(",
"newInvocationControl",
"!=",
"null",
")",
"{",
"try",
"{",
"newInvocationControl",
".",
"reset",
"(",
")",
";",
"}",
"catch",
"(",
"AssertionError",
"e",
")",
"{",
"NewInvocationControlAssertionError",
".",
"throwAssertionErrorForNewSubstitutionFailure",
"(",
"e",
",",
"type",
")",
";",
"}",
"}",
"}",
"}"
] |
Reset a list of class mocks.
|
[
"Reset",
"a",
"list",
"of",
"class",
"mocks",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1340-L1355
|
16,929
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.reset
|
public static synchronized void reset(Object... mocks) {
try {
for (Object mock : mocks) {
if (mock instanceof Class<?>) {
reset((Class<?>) mock);
} else {
MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock);
if (invocationControl != null) {
invocationControl.reset();
} else {
if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
// ignore non-mock
} else {
/*
* Delegate to easy mock class extension if we have
* no handler registered for this object.
*/
try {
org.easymock.EasyMock.reset(mock);
} catch (RuntimeException e) {
throw new RuntimeException(mock + " is not a mock object", e);
}
}
}
}
}
} catch (Throwable t) {
MockRepository.putAdditionalState(NICE_REPLAY_AND_VERIFY_KEY, false);
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof Error) {
throw (Error) t;
}
throw new RuntimeException(t);
}
}
|
java
|
public static synchronized void reset(Object... mocks) {
try {
for (Object mock : mocks) {
if (mock instanceof Class<?>) {
reset((Class<?>) mock);
} else {
MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock);
if (invocationControl != null) {
invocationControl.reset();
} else {
if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
// ignore non-mock
} else {
/*
* Delegate to easy mock class extension if we have
* no handler registered for this object.
*/
try {
org.easymock.EasyMock.reset(mock);
} catch (RuntimeException e) {
throw new RuntimeException(mock + " is not a mock object", e);
}
}
}
}
}
} catch (Throwable t) {
MockRepository.putAdditionalState(NICE_REPLAY_AND_VERIFY_KEY, false);
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof Error) {
throw (Error) t;
}
throw new RuntimeException(t);
}
}
|
[
"public",
"static",
"synchronized",
"void",
"reset",
"(",
"Object",
"...",
"mocks",
")",
"{",
"try",
"{",
"for",
"(",
"Object",
"mock",
":",
"mocks",
")",
"{",
"if",
"(",
"mock",
"instanceof",
"Class",
"<",
"?",
">",
")",
"{",
"reset",
"(",
"(",
"Class",
"<",
"?",
">",
")",
"mock",
")",
";",
"}",
"else",
"{",
"MethodInvocationControl",
"invocationControl",
"=",
"MockRepository",
".",
"getInstanceMethodInvocationControl",
"(",
"mock",
")",
";",
"if",
"(",
"invocationControl",
"!=",
"null",
")",
"{",
"invocationControl",
".",
"reset",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isNiceReplayAndVerifyMode",
"(",
")",
"&&",
"!",
"isEasyMocked",
"(",
"mock",
")",
")",
"{",
"// ignore non-mock",
"}",
"else",
"{",
"/*\n * Delegate to easy mock class extension if we have\n * no handler registered for this object.\n */",
"try",
"{",
"org",
".",
"easymock",
".",
"EasyMock",
".",
"reset",
"(",
"mock",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"mock",
"+",
"\" is not a mock object\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MockRepository",
".",
"putAdditionalState",
"(",
"NICE_REPLAY_AND_VERIFY_KEY",
",",
"false",
")",
";",
"if",
"(",
"t",
"instanceof",
"RuntimeException",
")",
"{",
"throw",
"(",
"RuntimeException",
")",
"t",
";",
"}",
"else",
"if",
"(",
"t",
"instanceof",
"Error",
")",
"{",
"throw",
"(",
"Error",
")",
"t",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"t",
")",
";",
"}",
"}"
] |
Reset a list of mock objects or classes.
|
[
"Reset",
"a",
"list",
"of",
"mock",
"objects",
"or",
"classes",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1360-L1395
|
16,930
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.verify
|
public static synchronized void verify(Object... objects) {
for (Object mock : objects) {
if (mock instanceof Class<?>) {
verifyClass((Class<?>) mock);
} else {
EasyMockMethodInvocationControl invocationControl = (EasyMockMethodInvocationControl) MockRepository.getInstanceMethodInvocationControl(mock);
if (invocationControl != null) {
invocationControl.verify();
} else {
if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
// ignore non-mock
} else {
/*
* Delegate to easy mock class extension if we have no
* handler registered for this object.
*/
try {
org.easymock.EasyMock.verify(mock);
} catch (RuntimeException e) {
throw new RuntimeException(mock + " is not a mock object", e);
}
}
}
}
}
}
|
java
|
public static synchronized void verify(Object... objects) {
for (Object mock : objects) {
if (mock instanceof Class<?>) {
verifyClass((Class<?>) mock);
} else {
EasyMockMethodInvocationControl invocationControl = (EasyMockMethodInvocationControl) MockRepository.getInstanceMethodInvocationControl(mock);
if (invocationControl != null) {
invocationControl.verify();
} else {
if (isNiceReplayAndVerifyMode() && !isEasyMocked(mock)) {
// ignore non-mock
} else {
/*
* Delegate to easy mock class extension if we have no
* handler registered for this object.
*/
try {
org.easymock.EasyMock.verify(mock);
} catch (RuntimeException e) {
throw new RuntimeException(mock + " is not a mock object", e);
}
}
}
}
}
}
|
[
"public",
"static",
"synchronized",
"void",
"verify",
"(",
"Object",
"...",
"objects",
")",
"{",
"for",
"(",
"Object",
"mock",
":",
"objects",
")",
"{",
"if",
"(",
"mock",
"instanceof",
"Class",
"<",
"?",
">",
")",
"{",
"verifyClass",
"(",
"(",
"Class",
"<",
"?",
">",
")",
"mock",
")",
";",
"}",
"else",
"{",
"EasyMockMethodInvocationControl",
"invocationControl",
"=",
"(",
"EasyMockMethodInvocationControl",
")",
"MockRepository",
".",
"getInstanceMethodInvocationControl",
"(",
"mock",
")",
";",
"if",
"(",
"invocationControl",
"!=",
"null",
")",
"{",
"invocationControl",
".",
"verify",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isNiceReplayAndVerifyMode",
"(",
")",
"&&",
"!",
"isEasyMocked",
"(",
"mock",
")",
")",
"{",
"// ignore non-mock",
"}",
"else",
"{",
"/*\n * Delegate to easy mock class extension if we have no\n * handler registered for this object.\n */",
"try",
"{",
"org",
".",
"easymock",
".",
"EasyMock",
".",
"verify",
"(",
"mock",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"mock",
"+",
"\" is not a mock object\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] |
Switches the mocks or classes to verify mode. Note that you must use this
method when using PowerMock!
@param objects mock objects or classes loaded by PowerMock.
|
[
"Switches",
"the",
"mocks",
"or",
"classes",
"to",
"verify",
"mode",
".",
"Note",
"that",
"you",
"must",
"use",
"this",
"method",
"when",
"using",
"PowerMock!"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1469-L1494
|
16,931
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createMockAndExpectNew
|
public static synchronized <T> T createMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createMock(type);
expectNew(type, arguments).andReturn(mock);
return mock;
}
|
java
|
public static synchronized <T> T createMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createMock(type);
expectNew(type, arguments).andReturn(mock);
return mock;
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createMockAndExpectNew",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"T",
"mock",
"=",
"createMock",
"(",
"type",
")",
";",
"expectNew",
"(",
"type",
",",
"arguments",
")",
".",
"andReturn",
"(",
"mock",
")",
";",
"return",
"mock",
";",
"}"
] |
Convenience method for createMock followed by expectNew.
@param type The class that should be mocked.
@param arguments The constructor arguments.
@return A mock object of the same type as the mock.
@throws Exception
|
[
"Convenience",
"method",
"for",
"createMock",
"followed",
"by",
"expectNew",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1504-L1508
|
16,932
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createNiceMockAndExpectNew
|
public static synchronized <T> T createNiceMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createNiceMock(type);
IExpectationSetters<T> expectationSetters = expectNiceNew(type, arguments);
if (expectationSetters != null) {
expectationSetters.andReturn(mock);
}
return mock;
}
|
java
|
public static synchronized <T> T createNiceMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createNiceMock(type);
IExpectationSetters<T> expectationSetters = expectNiceNew(type, arguments);
if (expectationSetters != null) {
expectationSetters.andReturn(mock);
}
return mock;
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createNiceMockAndExpectNew",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"T",
"mock",
"=",
"createNiceMock",
"(",
"type",
")",
";",
"IExpectationSetters",
"<",
"T",
">",
"expectationSetters",
"=",
"expectNiceNew",
"(",
"type",
",",
"arguments",
")",
";",
"if",
"(",
"expectationSetters",
"!=",
"null",
")",
"{",
"expectationSetters",
".",
"andReturn",
"(",
"mock",
")",
";",
"}",
"return",
"mock",
";",
"}"
] |
Convenience method for createNiceMock followed by expectNew.
@param type The class that should be mocked.
@param arguments The constructor arguments.
@return A mock object of the same type as the mock.
@throws Exception
|
[
"Convenience",
"method",
"for",
"createNiceMock",
"followed",
"by",
"expectNew",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1538-L1545
|
16,933
|
powermock/powermock
|
powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java
|
PowerMock.createStrictMockAndExpectNew
|
public static synchronized <T> T createStrictMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createStrictMock(type);
expectStrictNew(type, arguments).andReturn(mock);
return mock;
}
|
java
|
public static synchronized <T> T createStrictMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createStrictMock(type);
expectStrictNew(type, arguments).andReturn(mock);
return mock;
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"createStrictMockAndExpectNew",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"T",
"mock",
"=",
"createStrictMock",
"(",
"type",
")",
";",
"expectStrictNew",
"(",
"type",
",",
"arguments",
")",
".",
"andReturn",
"(",
"mock",
")",
";",
"return",
"mock",
";",
"}"
] |
Convenience method for createStrictMock followed by expectNew.
@param type The class that should be mocked.
@param arguments The constructor arguments.
@return A mock object of the same type as the mock.
@throws Exception
|
[
"Convenience",
"method",
"for",
"createStrictMock",
"followed",
"by",
"expectNew",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-easymock/src/main/java/org/powermock/api/easymock/PowerMock.java#L1578-L1582
|
16,934
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/core/WildcardMatcher.java
|
WildcardMatcher.matches
|
public static boolean matches(String text, String pattern) {
if (text == null) {
throw new IllegalArgumentException("text cannot be null");
}
text += '\0';
pattern += '\0';
int N = pattern.length();
boolean[] states = new boolean[N + 1];
boolean[] old = new boolean[N + 1];
old[0] = true;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
states = new boolean[N + 1]; // initialized to false
for (int j = 0; j < N; j++) {
char p = pattern.charAt(j);
// hack to handle *'s that match 0 characters
if (old[j] && (p == WILDCARD))
old[j + 1] = true;
if (old[j] && (p == c))
states[j + 1] = true;
if (old[j] && (p == WILDCARD))
states[j] = true;
if (old[j] && (p == WILDCARD))
states[j + 1] = true;
}
old = states;
}
return states[N];
}
|
java
|
public static boolean matches(String text, String pattern) {
if (text == null) {
throw new IllegalArgumentException("text cannot be null");
}
text += '\0';
pattern += '\0';
int N = pattern.length();
boolean[] states = new boolean[N + 1];
boolean[] old = new boolean[N + 1];
old[0] = true;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
states = new boolean[N + 1]; // initialized to false
for (int j = 0; j < N; j++) {
char p = pattern.charAt(j);
// hack to handle *'s that match 0 characters
if (old[j] && (p == WILDCARD))
old[j + 1] = true;
if (old[j] && (p == c))
states[j + 1] = true;
if (old[j] && (p == WILDCARD))
states[j] = true;
if (old[j] && (p == WILDCARD))
states[j + 1] = true;
}
old = states;
}
return states[N];
}
|
[
"public",
"static",
"boolean",
"matches",
"(",
"String",
"text",
",",
"String",
"pattern",
")",
"{",
"if",
"(",
"text",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"text cannot be null\"",
")",
";",
"}",
"text",
"+=",
"'",
"'",
";",
"pattern",
"+=",
"'",
"'",
";",
"int",
"N",
"=",
"pattern",
".",
"length",
"(",
")",
";",
"boolean",
"[",
"]",
"states",
"=",
"new",
"boolean",
"[",
"N",
"+",
"1",
"]",
";",
"boolean",
"[",
"]",
"old",
"=",
"new",
"boolean",
"[",
"N",
"+",
"1",
"]",
";",
"old",
"[",
"0",
"]",
"=",
"true",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"text",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"char",
"c",
"=",
"text",
".",
"charAt",
"(",
"i",
")",
";",
"states",
"=",
"new",
"boolean",
"[",
"N",
"+",
"1",
"]",
";",
"// initialized to false",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"N",
";",
"j",
"++",
")",
"{",
"char",
"p",
"=",
"pattern",
".",
"charAt",
"(",
"j",
")",
";",
"// hack to handle *'s that match 0 characters",
"if",
"(",
"old",
"[",
"j",
"]",
"&&",
"(",
"p",
"==",
"WILDCARD",
")",
")",
"old",
"[",
"j",
"+",
"1",
"]",
"=",
"true",
";",
"if",
"(",
"old",
"[",
"j",
"]",
"&&",
"(",
"p",
"==",
"c",
")",
")",
"states",
"[",
"j",
"+",
"1",
"]",
"=",
"true",
";",
"if",
"(",
"old",
"[",
"j",
"]",
"&&",
"(",
"p",
"==",
"WILDCARD",
")",
")",
"states",
"[",
"j",
"]",
"=",
"true",
";",
"if",
"(",
"old",
"[",
"j",
"]",
"&&",
"(",
"p",
"==",
"WILDCARD",
")",
")",
"states",
"[",
"j",
"+",
"1",
"]",
"=",
"true",
";",
"}",
"old",
"=",
"states",
";",
"}",
"return",
"states",
"[",
"N",
"]",
";",
"}"
] |
Performs a wildcard matching for the text and pattern provided.
@param text
the text to be tested for matches.
@param pattern
the pattern to be matched for. This can contain the wildcard
character '*' (asterisk).
@return <tt>true</tt> if a match is found, <tt>false</tt> otherwise.
|
[
"Performs",
"a",
"wildcard",
"matching",
"for",
"the",
"text",
"and",
"pattern",
"provided",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/core/WildcardMatcher.java#L39-L74
|
16,935
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/mockpolicies/support/LogPolicySupport.java
|
LogPolicySupport.getLoggerMethods
|
public Method[] getLoggerMethods(String fullyQualifiedClassName, String methodName, String logFramework) {
try {
return Whitebox.getMethods(getType(fullyQualifiedClassName, logFramework), methodName);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
public Method[] getLoggerMethods(String fullyQualifiedClassName, String methodName, String logFramework) {
try {
return Whitebox.getMethods(getType(fullyQualifiedClassName, logFramework), methodName);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"Method",
"[",
"]",
"getLoggerMethods",
"(",
"String",
"fullyQualifiedClassName",
",",
"String",
"methodName",
",",
"String",
"logFramework",
")",
"{",
"try",
"{",
"return",
"Whitebox",
".",
"getMethods",
"(",
"getType",
"(",
"fullyQualifiedClassName",
",",
"logFramework",
")",
",",
"methodName",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Get the methods that should be mocked.
@param fullyQualifiedClassName
The fully-qualified name to the class that contains the
method.
@param methodName
The name of the method that should be mocked.
@param logFramework
The log framework that should be printed if the class
{@code fullyQualifiedClassName} cannot be found.
@return The array of {@link Method}'s that should be mocked.
|
[
"Get",
"the",
"methods",
"that",
"should",
"be",
"mocked",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/mockpolicies/support/LogPolicySupport.java#L39-L47
|
16,936
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/mockpolicies/support/LogPolicySupport.java
|
LogPolicySupport.getType
|
public Class<?> getType(String name, String logFramework) throws Exception {
final Class<?> loggerType;
try {
loggerType = Class.forName(name);
} catch (ClassNotFoundException e) {
final String message = String.format("Cannot find %s in the classpath which the %s policy requires.", logFramework, getClass()
.getSimpleName());
throw new RuntimeException(message, e);
}
return loggerType;
}
|
java
|
public Class<?> getType(String name, String logFramework) throws Exception {
final Class<?> loggerType;
try {
loggerType = Class.forName(name);
} catch (ClassNotFoundException e) {
final String message = String.format("Cannot find %s in the classpath which the %s policy requires.", logFramework, getClass()
.getSimpleName());
throw new RuntimeException(message, e);
}
return loggerType;
}
|
[
"public",
"Class",
"<",
"?",
">",
"getType",
"(",
"String",
"name",
",",
"String",
"logFramework",
")",
"throws",
"Exception",
"{",
"final",
"Class",
"<",
"?",
">",
"loggerType",
";",
"try",
"{",
"loggerType",
"=",
"Class",
".",
"forName",
"(",
"name",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"final",
"String",
"message",
"=",
"String",
".",
"format",
"(",
"\"Cannot find %s in the classpath which the %s policy requires.\"",
",",
"logFramework",
",",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"message",
",",
"e",
")",
";",
"}",
"return",
"loggerType",
";",
"}"
] |
Get the class type representing the fully-qualified name.
@param name
The fully-qualified name of a class to get.
@param logFramework
The log framework that should be printed if the class cannot
be found.
@return The class representing the fully-qualified name.
@throws Exception
If something unexpected goes wrong, for example if the class
cannot be found.
|
[
"Get",
"the",
"class",
"type",
"representing",
"the",
"fully",
"-",
"qualified",
"name",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/mockpolicies/support/LogPolicySupport.java#L62-L72
|
16,937
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java
|
ClassLoaderUtil.loadClass
|
@SuppressWarnings("unchecked")
public static <T> Class<T> loadClass(String className) {
return loadClass(className, ClassLoaderUtil.class.getClassLoader());
}
|
java
|
@SuppressWarnings("unchecked")
public static <T> Class<T> loadClass(String className) {
return loadClass(className, ClassLoaderUtil.class.getClassLoader());
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
">",
"Class",
"<",
"T",
">",
"loadClass",
"(",
"String",
"className",
")",
"{",
"return",
"loadClass",
"(",
"className",
",",
"ClassLoaderUtil",
".",
"class",
".",
"getClassLoader",
"(",
")",
")",
";",
"}"
] |
Loads a class from the current classloader
|
[
"Loads",
"a",
"class",
"from",
"the",
"current",
"classloader"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java#L32-L35
|
16,938
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java
|
ClassLoaderUtil.hasClass
|
@SuppressWarnings("unchecked")
public static <T> boolean hasClass(Class<T> type, ClassLoader classloader) {
try {
loadClass(type.getName(), classloader);
return true;
} catch (RuntimeException e) {
if(e.getCause() instanceof ClassNotFoundException) {
return false;
}
throw e;
}
}
|
java
|
@SuppressWarnings("unchecked")
public static <T> boolean hasClass(Class<T> type, ClassLoader classloader) {
try {
loadClass(type.getName(), classloader);
return true;
} catch (RuntimeException e) {
if(e.getCause() instanceof ClassNotFoundException) {
return false;
}
throw e;
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
">",
"boolean",
"hasClass",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"ClassLoader",
"classloader",
")",
"{",
"try",
"{",
"loadClass",
"(",
"type",
".",
"getName",
"(",
")",
",",
"classloader",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"if",
"(",
"e",
".",
"getCause",
"(",
")",
"instanceof",
"ClassNotFoundException",
")",
"{",
"return",
"false",
";",
"}",
"throw",
"e",
";",
"}",
"}"
] |
Check whether a classloader can load the given class.
|
[
"Check",
"whether",
"a",
"classloader",
"can",
"load",
"the",
"given",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java#L40-L51
|
16,939
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java
|
ClassLoaderUtil.loadClass
|
public static <T> Class<T> loadClass(String className, ClassLoader classloader) {
if(className == null) {
throw new IllegalArgumentException("className cannot be null");
}
if(classloader == null) {
throw new IllegalArgumentException("classloader cannot be null");
}
try {
return (Class<T>) Class.forName(className, false, classloader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
java
|
public static <T> Class<T> loadClass(String className, ClassLoader classloader) {
if(className == null) {
throw new IllegalArgumentException("className cannot be null");
}
if(classloader == null) {
throw new IllegalArgumentException("classloader cannot be null");
}
try {
return (Class<T>) Class.forName(className, false, classloader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"<",
"T",
">",
"Class",
"<",
"T",
">",
"loadClass",
"(",
"String",
"className",
",",
"ClassLoader",
"classloader",
")",
"{",
"if",
"(",
"className",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"className cannot be null\"",
")",
";",
"}",
"if",
"(",
"classloader",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"classloader cannot be null\"",
")",
";",
"}",
"try",
"{",
"return",
"(",
"Class",
"<",
"T",
">",
")",
"Class",
".",
"forName",
"(",
"className",
",",
"false",
",",
"classloader",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Load a class from a specific classloader
|
[
"Load",
"a",
"class",
"from",
"a",
"specific",
"classloader"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/ClassLoaderUtil.java#L56-L70
|
16,940
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/MethodProxy.java
|
MethodProxy.proxy
|
public static void proxy(Method method, InvocationHandler invocationHandler) {
assertInvocationHandlerNotNull(invocationHandler);
MockRepository.putMethodProxy(method, invocationHandler);
}
|
java
|
public static void proxy(Method method, InvocationHandler invocationHandler) {
assertInvocationHandlerNotNull(invocationHandler);
MockRepository.putMethodProxy(method, invocationHandler);
}
|
[
"public",
"static",
"void",
"proxy",
"(",
"Method",
"method",
",",
"InvocationHandler",
"invocationHandler",
")",
"{",
"assertInvocationHandlerNotNull",
"(",
"invocationHandler",
")",
";",
"MockRepository",
".",
"putMethodProxy",
"(",
"method",
",",
"invocationHandler",
")",
";",
"}"
] |
Add a proxy for this method. Each call to the method will be routed to
the invocationHandler instead.
|
[
"Add",
"a",
"proxy",
"for",
"this",
"method",
".",
"Each",
"call",
"to",
"the",
"method",
"will",
"be",
"routed",
"to",
"the",
"invocationHandler",
"instead",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/MethodProxy.java#L31-L34
|
16,941
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java
|
SuppressCode.suppressConstructor
|
public static synchronized void suppressConstructor(Constructor<?>... constructors) {
if (constructors == null) {
throw new IllegalArgumentException("constructors cannot be null.");
}
for (Constructor<?> constructor : constructors) {
MockRepository.addConstructorToSuppress(constructor);
// Also suppress all parent constructors
Class<?> declaringClass = constructor.getDeclaringClass();
if (declaringClass != null) {
suppressConstructor((Class<?>) declaringClass.getSuperclass());
}
}
}
|
java
|
public static synchronized void suppressConstructor(Constructor<?>... constructors) {
if (constructors == null) {
throw new IllegalArgumentException("constructors cannot be null.");
}
for (Constructor<?> constructor : constructors) {
MockRepository.addConstructorToSuppress(constructor);
// Also suppress all parent constructors
Class<?> declaringClass = constructor.getDeclaringClass();
if (declaringClass != null) {
suppressConstructor((Class<?>) declaringClass.getSuperclass());
}
}
}
|
[
"public",
"static",
"synchronized",
"void",
"suppressConstructor",
"(",
"Constructor",
"<",
"?",
">",
"...",
"constructors",
")",
"{",
"if",
"(",
"constructors",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"constructors cannot be null.\"",
")",
";",
"}",
"for",
"(",
"Constructor",
"<",
"?",
">",
"constructor",
":",
"constructors",
")",
"{",
"MockRepository",
".",
"addConstructorToSuppress",
"(",
"constructor",
")",
";",
"// Also suppress all parent constructors",
"Class",
"<",
"?",
">",
"declaringClass",
"=",
"constructor",
".",
"getDeclaringClass",
"(",
")",
";",
"if",
"(",
"declaringClass",
"!=",
"null",
")",
"{",
"suppressConstructor",
"(",
"(",
"Class",
"<",
"?",
">",
")",
"declaringClass",
".",
"getSuperclass",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Suppress constructor calls on specific constructors only.
|
[
"Suppress",
"constructor",
"calls",
"on",
"specific",
"constructors",
"only",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java#L30-L42
|
16,942
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java
|
SuppressCode.suppressConstructor
|
public static synchronized void suppressConstructor(Class<?>... classes) {
for (Class<?> clazz : classes) {
Class<?> tempClass = clazz;
while (tempClass != Object.class) {
suppressConstructor(tempClass, false);
tempClass = tempClass.getSuperclass();
}
}
}
|
java
|
public static synchronized void suppressConstructor(Class<?>... classes) {
for (Class<?> clazz : classes) {
Class<?> tempClass = clazz;
while (tempClass != Object.class) {
suppressConstructor(tempClass, false);
tempClass = tempClass.getSuperclass();
}
}
}
|
[
"public",
"static",
"synchronized",
"void",
"suppressConstructor",
"(",
"Class",
"<",
"?",
">",
"...",
"classes",
")",
"{",
"for",
"(",
"Class",
"<",
"?",
">",
"clazz",
":",
"classes",
")",
"{",
"Class",
"<",
"?",
">",
"tempClass",
"=",
"clazz",
";",
"while",
"(",
"tempClass",
"!=",
"Object",
".",
"class",
")",
"{",
"suppressConstructor",
"(",
"tempClass",
",",
"false",
")",
";",
"tempClass",
"=",
"tempClass",
".",
"getSuperclass",
"(",
")",
";",
"}",
"}",
"}"
] |
Suppress all constructors in the given class and it's super classes.
@param classes
The classes whose constructors will be suppressed.
|
[
"Suppress",
"all",
"constructors",
"in",
"the",
"given",
"class",
"and",
"it",
"s",
"super",
"classes",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java#L62-L70
|
16,943
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java
|
SuppressCode.suppressConstructor
|
public static synchronized void suppressConstructor(Class<?> clazz, boolean excludePrivateConstructors) {
Constructor<?>[] ctors = null;
if (excludePrivateConstructors) {
ctors = clazz.getConstructors();
} else {
ctors = clazz.getDeclaredConstructors();
}
for (Constructor<?> ctor : ctors) {
MockRepository.addConstructorToSuppress(ctor);
}
}
|
java
|
public static synchronized void suppressConstructor(Class<?> clazz, boolean excludePrivateConstructors) {
Constructor<?>[] ctors = null;
if (excludePrivateConstructors) {
ctors = clazz.getConstructors();
} else {
ctors = clazz.getDeclaredConstructors();
}
for (Constructor<?> ctor : ctors) {
MockRepository.addConstructorToSuppress(ctor);
}
}
|
[
"public",
"static",
"synchronized",
"void",
"suppressConstructor",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"boolean",
"excludePrivateConstructors",
")",
"{",
"Constructor",
"<",
"?",
">",
"[",
"]",
"ctors",
"=",
"null",
";",
"if",
"(",
"excludePrivateConstructors",
")",
"{",
"ctors",
"=",
"clazz",
".",
"getConstructors",
"(",
")",
";",
"}",
"else",
"{",
"ctors",
"=",
"clazz",
".",
"getDeclaredConstructors",
"(",
")",
";",
"}",
"for",
"(",
"Constructor",
"<",
"?",
">",
"ctor",
":",
"ctors",
")",
"{",
"MockRepository",
".",
"addConstructorToSuppress",
"(",
"ctor",
")",
";",
"}",
"}"
] |
Suppress all constructors in the given class.
@param clazz
The classes whose constructors will be suppressed.
@param excludePrivateConstructors
optionally keep code in private constructors
|
[
"Suppress",
"all",
"constructors",
"in",
"the",
"given",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java#L80-L92
|
16,944
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java
|
SuppressCode.suppressField
|
public static synchronized void suppressField(Class<?>[] classes) {
if (classes == null || classes.length == 0) {
throw new IllegalArgumentException("You must supply at least one class.");
}
for (Class<?> clazz : classes) {
suppressField(clazz.getDeclaredFields());
}
}
|
java
|
public static synchronized void suppressField(Class<?>[] classes) {
if (classes == null || classes.length == 0) {
throw new IllegalArgumentException("You must supply at least one class.");
}
for (Class<?> clazz : classes) {
suppressField(clazz.getDeclaredFields());
}
}
|
[
"public",
"static",
"synchronized",
"void",
"suppressField",
"(",
"Class",
"<",
"?",
">",
"[",
"]",
"classes",
")",
"{",
"if",
"(",
"classes",
"==",
"null",
"||",
"classes",
".",
"length",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"You must supply at least one class.\"",
")",
";",
"}",
"for",
"(",
"Class",
"<",
"?",
">",
"clazz",
":",
"classes",
")",
"{",
"suppressField",
"(",
"clazz",
".",
"getDeclaredFields",
"(",
")",
")",
";",
"}",
"}"
] |
Suppress all fields for these classes.
|
[
"Suppress",
"all",
"fields",
"for",
"these",
"classes",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java#L108-L115
|
16,945
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java
|
SuppressCode.suppressMethod
|
public static synchronized void suppressMethod(Class<?> clazz, boolean excludePrivateMethods) {
Method[] methods = null;
if (excludePrivateMethods) {
methods = clazz.getMethods();
} else {
methods = clazz.getDeclaredMethods();
}
for (Method method : methods) {
MockRepository.addMethodToSuppress(method);
}
}
|
java
|
public static synchronized void suppressMethod(Class<?> clazz, boolean excludePrivateMethods) {
Method[] methods = null;
if (excludePrivateMethods) {
methods = clazz.getMethods();
} else {
methods = clazz.getDeclaredMethods();
}
for (Method method : methods) {
MockRepository.addMethodToSuppress(method);
}
}
|
[
"public",
"static",
"synchronized",
"void",
"suppressMethod",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"boolean",
"excludePrivateMethods",
")",
"{",
"Method",
"[",
"]",
"methods",
"=",
"null",
";",
"if",
"(",
"excludePrivateMethods",
")",
"{",
"methods",
"=",
"clazz",
".",
"getMethods",
"(",
")",
";",
"}",
"else",
"{",
"methods",
"=",
"clazz",
".",
"getDeclaredMethods",
"(",
")",
";",
"}",
"for",
"(",
"Method",
"method",
":",
"methods",
")",
"{",
"MockRepository",
".",
"addMethodToSuppress",
"(",
"method",
")",
";",
"}",
"}"
] |
suSuppress all methods for this class.
@param clazz
The class which methods will be suppressed.
@param excludePrivateMethods
optionally not suppress private methods
|
[
"suSuppress",
"all",
"methods",
"for",
"this",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/SuppressCode.java#L218-L230
|
16,946
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/core/MockGateway.java
|
MockGateway.methodCall
|
@SuppressWarnings("UnusedDeclaration")
public static Object methodCall(Class<?> type, String methodName, Object[] args, Class<?>[] sig,
String returnTypeAsString) throws Throwable {
return doMethodCall(type, methodName, args, sig, returnTypeAsString);
}
|
java
|
@SuppressWarnings("UnusedDeclaration")
public static Object methodCall(Class<?> type, String methodName, Object[] args, Class<?>[] sig,
String returnTypeAsString) throws Throwable {
return doMethodCall(type, methodName, args, sig, returnTypeAsString);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"UnusedDeclaration\"",
")",
"public",
"static",
"Object",
"methodCall",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"String",
"methodName",
",",
"Object",
"[",
"]",
"args",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"sig",
",",
"String",
"returnTypeAsString",
")",
"throws",
"Throwable",
"{",
"return",
"doMethodCall",
"(",
"type",
",",
"methodName",
",",
"args",
",",
"sig",
",",
"returnTypeAsString",
")",
";",
"}"
] |
used for static methods
|
[
"used",
"for",
"static",
"methods"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/core/MockGateway.java#L142-L146
|
16,947
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/membermodification/MemberModifier.java
|
MemberModifier.suppress
|
public static void suppress(AccessibleObject[] accessibleObjects) {
if (accessibleObjects == null) {
throw new IllegalArgumentException("accessibleObjects cannot be null");
}
for (AccessibleObject accessibleObject : accessibleObjects) {
if (accessibleObject instanceof Constructor<?>) {
SuppressCode.suppressConstructor((Constructor<?>) accessibleObject);
} else if (accessibleObject instanceof Field) {
SuppressCode.suppressField((Field) accessibleObject);
} else if (accessibleObject instanceof Method) {
SuppressCode.suppressMethod((Method) accessibleObject);
}
}
}
|
java
|
public static void suppress(AccessibleObject[] accessibleObjects) {
if (accessibleObjects == null) {
throw new IllegalArgumentException("accessibleObjects cannot be null");
}
for (AccessibleObject accessibleObject : accessibleObjects) {
if (accessibleObject instanceof Constructor<?>) {
SuppressCode.suppressConstructor((Constructor<?>) accessibleObject);
} else if (accessibleObject instanceof Field) {
SuppressCode.suppressField((Field) accessibleObject);
} else if (accessibleObject instanceof Method) {
SuppressCode.suppressMethod((Method) accessibleObject);
}
}
}
|
[
"public",
"static",
"void",
"suppress",
"(",
"AccessibleObject",
"[",
"]",
"accessibleObjects",
")",
"{",
"if",
"(",
"accessibleObjects",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"accessibleObjects cannot be null\"",
")",
";",
"}",
"for",
"(",
"AccessibleObject",
"accessibleObject",
":",
"accessibleObjects",
")",
"{",
"if",
"(",
"accessibleObject",
"instanceof",
"Constructor",
"<",
"?",
">",
")",
"{",
"SuppressCode",
".",
"suppressConstructor",
"(",
"(",
"Constructor",
"<",
"?",
">",
")",
"accessibleObject",
")",
";",
"}",
"else",
"if",
"(",
"accessibleObject",
"instanceof",
"Field",
")",
"{",
"SuppressCode",
".",
"suppressField",
"(",
"(",
"Field",
")",
"accessibleObject",
")",
";",
"}",
"else",
"if",
"(",
"accessibleObject",
"instanceof",
"Method",
")",
"{",
"SuppressCode",
".",
"suppressMethod",
"(",
"(",
"Method",
")",
"accessibleObject",
")",
";",
"}",
"}",
"}"
] |
Suppress an array of accessible objects.
|
[
"Suppress",
"an",
"array",
"of",
"accessible",
"objects",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/membermodification/MemberModifier.java#L84-L98
|
16,948
|
powermock/powermock
|
powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/membermodification/MemberMatcher.java
|
MemberMatcher.constructor
|
@SuppressWarnings("unchecked")
public static <T> Constructor<T> constructor(Class<T> declaringClass, Class<?>... parameterTypes) {
return (Constructor<T>) WhiteboxImpl.findUniqueConstructorOrThrowException(declaringClass,
(Object[]) parameterTypes);
}
|
java
|
@SuppressWarnings("unchecked")
public static <T> Constructor<T> constructor(Class<T> declaringClass, Class<?>... parameterTypes) {
return (Constructor<T>) WhiteboxImpl.findUniqueConstructorOrThrowException(declaringClass,
(Object[]) parameterTypes);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
">",
"Constructor",
"<",
"T",
">",
"constructor",
"(",
"Class",
"<",
"T",
">",
"declaringClass",
",",
"Class",
"<",
"?",
">",
"...",
"parameterTypes",
")",
"{",
"return",
"(",
"Constructor",
"<",
"T",
">",
")",
"WhiteboxImpl",
".",
"findUniqueConstructorOrThrowException",
"(",
"declaringClass",
",",
"(",
"Object",
"[",
"]",
")",
"parameterTypes",
")",
";",
"}"
] |
Returns a constructor specified in declaringClass.
@param declaringClass
The declaringClass of the class where the constructor is
located.
@param parameterTypes
All parameter types of the constructor (may be
{@code null}).
@return A {@code java.lang.reflect.Constructor}.
@throws ConstructorNotFoundException
if the constructor cannot be found.
|
[
"Returns",
"a",
"constructor",
"specified",
"in",
"declaringClass",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-support/src/main/java/org/powermock/api/support/membermodification/MemberMatcher.java#L254-L258
|
16,949
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.mockStatic
|
public static synchronized void mockStatic(Class<?> type, Class<?>... types) {
DefaultMockCreator.mock(type, true, false, null, null, (Method[]) null);
if (types != null && types.length > 0) {
for (Class<?> aClass : types) {
DefaultMockCreator.mock(aClass, true, false, null, null, (Method[]) null);
}
}
}
|
java
|
public static synchronized void mockStatic(Class<?> type, Class<?>... types) {
DefaultMockCreator.mock(type, true, false, null, null, (Method[]) null);
if (types != null && types.length > 0) {
for (Class<?> aClass : types) {
DefaultMockCreator.mock(aClass, true, false, null, null, (Method[]) null);
}
}
}
|
[
"public",
"static",
"synchronized",
"void",
"mockStatic",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Class",
"<",
"?",
">",
"...",
"types",
")",
"{",
"DefaultMockCreator",
".",
"mock",
"(",
"type",
",",
"true",
",",
"false",
",",
"null",
",",
"null",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"if",
"(",
"types",
"!=",
"null",
"&&",
"types",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"Class",
"<",
"?",
">",
"aClass",
":",
"types",
")",
"{",
"DefaultMockCreator",
".",
"mock",
"(",
"aClass",
",",
"true",
",",
"false",
",",
"null",
",",
"null",
",",
"(",
"Method",
"[",
"]",
")",
"null",
")",
";",
"}",
"}",
"}"
] |
Enable static mocking for all methods of a class.
@param type the class to enable static mocking
|
[
"Enable",
"static",
"mocking",
"for",
"all",
"methods",
"of",
"a",
"class",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L61-L68
|
16,950
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.verifyPrivate
|
public static PrivateMethodVerification verifyPrivate(Object object, VerificationMode verificationMode) {
Mockito.verify(object, verificationMode);
return new DefaultPrivateMethodVerification(object);
}
|
java
|
public static PrivateMethodVerification verifyPrivate(Object object, VerificationMode verificationMode) {
Mockito.verify(object, verificationMode);
return new DefaultPrivateMethodVerification(object);
}
|
[
"public",
"static",
"PrivateMethodVerification",
"verifyPrivate",
"(",
"Object",
"object",
",",
"VerificationMode",
"verificationMode",
")",
"{",
"Mockito",
".",
"verify",
"(",
"object",
",",
"verificationMode",
")",
";",
"return",
"new",
"DefaultPrivateMethodVerification",
"(",
"object",
")",
";",
"}"
] |
Verify a private method invocation with a given verification mode.
@see Mockito#verify(Object)
|
[
"Verify",
"a",
"private",
"method",
"invocation",
"with",
"a",
"given",
"verification",
"mode",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L280-L283
|
16,951
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.verifyPrivate
|
public static PrivateMethodVerification verifyPrivate(Class<?> clazz, VerificationMode verificationMode) {
return verifyPrivate((Object) clazz, verificationMode);
}
|
java
|
public static PrivateMethodVerification verifyPrivate(Class<?> clazz, VerificationMode verificationMode) {
return verifyPrivate((Object) clazz, verificationMode);
}
|
[
"public",
"static",
"PrivateMethodVerification",
"verifyPrivate",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"VerificationMode",
"verificationMode",
")",
"{",
"return",
"verifyPrivate",
"(",
"(",
"Object",
")",
"clazz",
",",
"verificationMode",
")",
";",
"}"
] |
Verify a private method invocation for a class with a given verification
mode.
@see Mockito#verify(Object)
|
[
"Verify",
"a",
"private",
"method",
"invocation",
"for",
"a",
"class",
"with",
"a",
"given",
"verification",
"mode",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L301-L303
|
16,952
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.when
|
public static <T> WithOrWithoutExpectedArguments<T> when(Class<?> cls, Method method) {
return new DefaultMethodExpectationSetup<T>(cls, method);
}
|
java
|
public static <T> WithOrWithoutExpectedArguments<T> when(Class<?> cls, Method method) {
return new DefaultMethodExpectationSetup<T>(cls, method);
}
|
[
"public",
"static",
"<",
"T",
">",
"WithOrWithoutExpectedArguments",
"<",
"T",
">",
"when",
"(",
"Class",
"<",
"?",
">",
"cls",
",",
"Method",
"method",
")",
"{",
"return",
"new",
"DefaultMethodExpectationSetup",
"<",
"T",
">",
"(",
"cls",
",",
"method",
")",
";",
"}"
] |
Expect calls to private static methods.
@see PowerMockito#when(Object)
|
[
"Expect",
"calls",
"to",
"private",
"static",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L377-L379
|
16,953
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.when
|
public static <T> OngoingStubbing<T> when(Class<?> clazz, String methodToExpect, Object... arguments)
throws Exception {
return Mockito.when(Whitebox.<T>invokeMethod(clazz, methodToExpect, arguments));
}
|
java
|
public static <T> OngoingStubbing<T> when(Class<?> clazz, String methodToExpect, Object... arguments)
throws Exception {
return Mockito.when(Whitebox.<T>invokeMethod(clazz, methodToExpect, arguments));
}
|
[
"public",
"static",
"<",
"T",
">",
"OngoingStubbing",
"<",
"T",
">",
"when",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"methodToExpect",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"return",
"Mockito",
".",
"when",
"(",
"Whitebox",
".",
"<",
"T",
">",
"invokeMethod",
"(",
"clazz",
",",
"methodToExpect",
",",
"arguments",
")",
")",
";",
"}"
] |
Expect a static private or inner class method call.
@throws Exception If something unexpected goes wrong.
@see PowerMockito#when(Object)
|
[
"Expect",
"a",
"static",
"private",
"or",
"inner",
"class",
"method",
"call",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L399-L402
|
16,954
|
powermock/powermock
|
powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java
|
PowerMockito.when
|
public static <T> OngoingStubbing<T> when(Class<?> klass, Object... arguments) throws Exception {
return Mockito.when(Whitebox.<T>invokeMethod(klass, arguments));
}
|
java
|
public static <T> OngoingStubbing<T> when(Class<?> klass, Object... arguments) throws Exception {
return Mockito.when(Whitebox.<T>invokeMethod(klass, arguments));
}
|
[
"public",
"static",
"<",
"T",
">",
"OngoingStubbing",
"<",
"T",
">",
"when",
"(",
"Class",
"<",
"?",
">",
"klass",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"return",
"Mockito",
".",
"when",
"(",
"Whitebox",
".",
"<",
"T",
">",
"invokeMethod",
"(",
"klass",
",",
"arguments",
")",
")",
";",
"}"
] |
Expect calls to private static methods without having to specify the
method name. The method will be looked up using the parameter types if
possible
@throws Exception If something unexpected goes wrong.
@see PowerMockito#when(Object)
|
[
"Expect",
"calls",
"to",
"private",
"static",
"methods",
"without",
"having",
"to",
"specify",
"the",
"method",
"name",
".",
"The",
"method",
"will",
"be",
"looked",
"up",
"using",
"the",
"parameter",
"types",
"if",
"possible"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/PowerMockito.java#L412-L414
|
16,955
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/core/PowerMockUtils.java
|
PowerMockUtils.getClassIterator
|
@SuppressWarnings("unchecked")
public static Iterator<Class<?>> getClassIterator(ClassLoader classLoader) throws NoSuchFieldException, IllegalAccessException {
Class<?> classLoaderClass = classLoader.getClass();
while (classLoaderClass != ClassLoader.class) {
classLoaderClass = classLoaderClass.getSuperclass();
}
Field classesField = classLoaderClass.getDeclaredField("classes");
classesField.setAccessible(true);
Vector<Class<?>> classes = (Vector<Class<?>>) classesField.get(classLoader);
return classes.iterator();
}
|
java
|
@SuppressWarnings("unchecked")
public static Iterator<Class<?>> getClassIterator(ClassLoader classLoader) throws NoSuchFieldException, IllegalAccessException {
Class<?> classLoaderClass = classLoader.getClass();
while (classLoaderClass != ClassLoader.class) {
classLoaderClass = classLoaderClass.getSuperclass();
}
Field classesField = classLoaderClass.getDeclaredField("classes");
classesField.setAccessible(true);
Vector<Class<?>> classes = (Vector<Class<?>>) classesField.get(classLoader);
return classes.iterator();
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"Iterator",
"<",
"Class",
"<",
"?",
">",
">",
"getClassIterator",
"(",
"ClassLoader",
"classLoader",
")",
"throws",
"NoSuchFieldException",
",",
"IllegalAccessException",
"{",
"Class",
"<",
"?",
">",
"classLoaderClass",
"=",
"classLoader",
".",
"getClass",
"(",
")",
";",
"while",
"(",
"classLoaderClass",
"!=",
"ClassLoader",
".",
"class",
")",
"{",
"classLoaderClass",
"=",
"classLoaderClass",
".",
"getSuperclass",
"(",
")",
";",
"}",
"Field",
"classesField",
"=",
"classLoaderClass",
".",
"getDeclaredField",
"(",
"\"classes\"",
")",
";",
"classesField",
".",
"setAccessible",
"(",
"true",
")",
";",
"Vector",
"<",
"Class",
"<",
"?",
">",
">",
"classes",
"=",
"(",
"Vector",
"<",
"Class",
"<",
"?",
">",
">",
")",
"classesField",
".",
"get",
"(",
"classLoader",
")",
";",
"return",
"classes",
".",
"iterator",
"(",
")",
";",
"}"
] |
Get an iterator of all classes loaded by the specific classloader.
@param classLoader the class loader for that iterator with all loaded classes should be created.
@return the iterator with all classes loaded by the given {@code classLoader}
@throws NoSuchFieldException
@throws IllegalAccessException
|
[
"Get",
"an",
"iterator",
"of",
"all",
"classes",
"loaded",
"by",
"the",
"specific",
"classloader",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/core/PowerMockUtils.java#L32-L42
|
16,956
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/core/classloader/DeferSupportingClassLoader.java
|
DeferSupportingClassLoader.cache
|
public void cache(Class<?> cls) {
if (cls != null) {
classes.put(cls.getName(), new SoftReference<Class<?>>(cls));
}
}
|
java
|
public void cache(Class<?> cls) {
if (cls != null) {
classes.put(cls.getName(), new SoftReference<Class<?>>(cls));
}
}
|
[
"public",
"void",
"cache",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"if",
"(",
"cls",
"!=",
"null",
")",
"{",
"classes",
".",
"put",
"(",
"cls",
".",
"getName",
"(",
")",
",",
"new",
"SoftReference",
"<",
"Class",
"<",
"?",
">",
">",
"(",
"cls",
")",
")",
";",
"}",
"}"
] |
Register a class to the cache of this classloader
|
[
"Register",
"a",
"class",
"to",
"the",
"cache",
"of",
"this",
"classloader"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/core/classloader/DeferSupportingClassLoader.java#L85-L89
|
16,957
|
powermock/powermock
|
powermock-core/src/main/java/org/powermock/core/classloader/DeferSupportingClassLoader.java
|
DeferSupportingClassLoader.findResource
|
@Override
protected URL findResource(String name) {
try {
return Whitebox.invokeMethod(deferTo, "findResource", name);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
@Override
protected URL findResource(String name) {
try {
return Whitebox.invokeMethod(deferTo, "findResource", name);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"@",
"Override",
"protected",
"URL",
"findResource",
"(",
"String",
"name",
")",
"{",
"try",
"{",
"return",
"Whitebox",
".",
"invokeMethod",
"(",
"deferTo",
",",
"\"findResource\"",
",",
"name",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Finds the resource with the specified name on the search path.
@param name the name of the resource
@return a {@code URL} for the resource, or {@code null} if the
resource could not be found.
|
[
"Finds",
"the",
"resource",
"with",
"the",
"specified",
"name",
"on",
"the",
"search",
"path",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-core/src/main/java/org/powermock/core/classloader/DeferSupportingClassLoader.java#L123-L130
|
16,958
|
powermock/powermock
|
powermock-modules/powermock-module-javaagent/src/main/java/sun/tools/attach/HotSpotVirtualMachine.java
|
HotSpotVirtualMachine.setFlag
|
public InputStream setFlag(String name, String value) throws IOException {
return executeCommand("setflag", name, value);
}
|
java
|
public InputStream setFlag(String name, String value) throws IOException {
return executeCommand("setflag", name, value);
}
|
[
"public",
"InputStream",
"setFlag",
"(",
"String",
"name",
",",
"String",
"value",
")",
"throws",
"IOException",
"{",
"return",
"executeCommand",
"(",
"\"setflag\"",
",",
"name",
",",
"value",
")",
";",
"}"
] |
set JVM command line flag
|
[
"set",
"JVM",
"command",
"line",
"flag"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-modules/powermock-module-javaagent/src/main/java/sun/tools/attach/HotSpotVirtualMachine.java#L193-L195
|
16,959
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java
|
Whitebox.setInternalState
|
public static void setInternalState(Object object, String fieldName, Object value, Class<?> where) {
WhiteboxImpl.setInternalState(object, fieldName, value, where);
}
|
java
|
public static void setInternalState(Object object, String fieldName, Object value, Class<?> where) {
WhiteboxImpl.setInternalState(object, fieldName, value, where);
}
|
[
"public",
"static",
"void",
"setInternalState",
"(",
"Object",
"object",
",",
"String",
"fieldName",
",",
"Object",
"value",
",",
"Class",
"<",
"?",
">",
"where",
")",
"{",
"WhiteboxImpl",
".",
"setInternalState",
"(",
"object",
",",
"fieldName",
",",
"value",
",",
"where",
")",
";",
"}"
] |
Set the value of a field using reflection. Use this method when you need
to specify in which class the field is declared. This might be useful
when you have mocked the instance you are trying to modify.
@param object
the object to modify
@param fieldName
the name of the field
@param value
the new value of the field
@param where
the class in the hierarchy where the field is defined
|
[
"Set",
"the",
"value",
"of",
"a",
"field",
"using",
"reflection",
".",
"Use",
"this",
"method",
"when",
"you",
"need",
"to",
"specify",
"in",
"which",
"class",
"the",
"field",
"is",
"declared",
".",
"This",
"might",
"be",
"useful",
"when",
"you",
"have",
"mocked",
"the",
"instance",
"you",
"are",
"trying",
"to",
"modify",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java#L240-L242
|
16,960
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java
|
Whitebox.getInternalState
|
public static <T> T getInternalState(Object object, String fieldName, Class<?> where) {
return WhiteboxImpl.getInternalState(object, fieldName, where);
}
|
java
|
public static <T> T getInternalState(Object object, String fieldName, Class<?> where) {
return WhiteboxImpl.getInternalState(object, fieldName, where);
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"getInternalState",
"(",
"Object",
"object",
",",
"String",
"fieldName",
",",
"Class",
"<",
"?",
">",
"where",
")",
"{",
"return",
"WhiteboxImpl",
".",
"getInternalState",
"(",
"object",
",",
"fieldName",
",",
"where",
")",
";",
"}"
] |
Get the value of a field using reflection. Use this method when you need
to specify in which class the field is declared. This might be useful
when you have mocked the instance you are trying to access.
@param object
the object to modify
@param fieldName
the name of the field
@param where
which class the field is defined
|
[
"Get",
"the",
"value",
"of",
"a",
"field",
"using",
"reflection",
".",
"Use",
"this",
"method",
"when",
"you",
"need",
"to",
"specify",
"in",
"which",
"class",
"the",
"field",
"is",
"declared",
".",
"This",
"might",
"be",
"useful",
"when",
"you",
"have",
"mocked",
"the",
"instance",
"you",
"are",
"trying",
"to",
"access",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java#L307-L309
|
16,961
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java
|
Whitebox.invokeMethod
|
public static synchronized <T> T invokeMethod(Class<?> clazz, String methodToExecute, Object... arguments)
throws Exception {
return WhiteboxImpl.invokeMethod(clazz, methodToExecute, arguments);
}
|
java
|
public static synchronized <T> T invokeMethod(Class<?> clazz, String methodToExecute, Object... arguments)
throws Exception {
return WhiteboxImpl.invokeMethod(clazz, methodToExecute, arguments);
}
|
[
"public",
"static",
"synchronized",
"<",
"T",
">",
"T",
"invokeMethod",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"methodToExecute",
",",
"Object",
"...",
"arguments",
")",
"throws",
"Exception",
"{",
"return",
"WhiteboxImpl",
".",
"invokeMethod",
"(",
"clazz",
",",
"methodToExecute",
",",
"arguments",
")",
";",
"}"
] |
Invoke a static private or inner class method. This may be useful to test
private methods.
|
[
"Invoke",
"a",
"static",
"private",
"or",
"inner",
"class",
"method",
".",
"This",
"may",
"be",
"useful",
"to",
"test",
"private",
"methods",
"."
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java#L464-L467
|
16,962
|
powermock/powermock
|
powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java
|
Whitebox.getInnerClassType
|
public static Class<Object> getInnerClassType(Class<?> declaringClass, String name) throws ClassNotFoundException {
return WhiteboxImpl.getInnerClassType(declaringClass, name);
}
|
java
|
public static Class<Object> getInnerClassType(Class<?> declaringClass, String name) throws ClassNotFoundException {
return WhiteboxImpl.getInnerClassType(declaringClass, name);
}
|
[
"public",
"static",
"Class",
"<",
"Object",
">",
"getInnerClassType",
"(",
"Class",
"<",
"?",
">",
"declaringClass",
",",
"String",
"name",
")",
"throws",
"ClassNotFoundException",
"{",
"return",
"WhiteboxImpl",
".",
"getInnerClassType",
"(",
"declaringClass",
",",
"name",
")",
";",
"}"
] |
Get an inner class type
@param declaringClass
The class in which the inner class is declared.
@param name
The unqualified name (simple name) of the inner class.
@return The type.
|
[
"Get",
"an",
"inner",
"class",
"type"
] |
e8cd68026c284c6a7efe66959809eeebd8d1f9ad
|
https://github.com/powermock/powermock/blob/e8cd68026c284c6a7efe66959809eeebd8d1f9ad/powermock-reflect/src/main/java/org/powermock/reflect/Whitebox.java#L649-L651
|
16,963
|
zhegexiaohuozi/SeimiCrawler
|
seimicrawler/src/main/java/cn/wanghaomiao/seimi/spring/common/SeimiCrawlerBootstrapListener.java
|
SeimiCrawlerBootstrapListener.onApplicationEvent
|
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
if (isSpringBoot){
CrawlerProperties crawlerProperties = context.getBean(CrawlerProperties.class);
if (!crawlerProperties.isEnabled()){
logger.warn("{} is not enabled",Constants.SEIMI_CRAWLER_BOOTSTRAP_ENABLED);
return;
}
}
if (context != null) {
if (CollectionUtils.isEmpty(CrawlerCache.getCrawlers())) {
logger.info("Not find any crawler,may be you need to check.");
return;
}
workersPool = Executors.newFixedThreadPool(Constants.BASE_THREAD_NUM * Runtime.getRuntime().availableProcessors() * CrawlerCache.getCrawlers().size());
for (Class<? extends BaseSeimiCrawler> a : CrawlerCache.getCrawlers()) {
CrawlerModel crawlerModel = new CrawlerModel(a, context);
if (CrawlerCache.isExist(crawlerModel.getCrawlerName())) {
logger.error("Crawler:{} is repeated,please check", crawlerModel.getCrawlerName());
throw new SeimiInitExcepiton(StrFormatUtil.info("Crawler:{} is repeated,please check", crawlerModel.getCrawlerName()));
}
CrawlerCache.putCrawlerModel(crawlerModel.getCrawlerName(), crawlerModel);
}
for (Map.Entry<String, CrawlerModel> crawlerEntry : CrawlerCache.getCrawlerModelContext().entrySet()) {
for (int i = 0; i < Constants.BASE_THREAD_NUM * Runtime.getRuntime().availableProcessors(); i++) {
workersPool.execute(new SeimiProcessor(CrawlerCache.getInterceptors(), crawlerEntry.getValue()));
}
}
if (isSpringBoot){
CrawlerProperties crawlerProperties = context.getBean(CrawlerProperties.class);
String crawlerNames = crawlerProperties.getNames();
if (StringUtils.isBlank(crawlerNames)){
logger.info("Spring boot start [{}] as worker.",StringUtils.join(CrawlerCache.getCrawlerModelContext().keySet(),","));
}else {
String[] crawlers = crawlerNames.split(",");
for (String cn:crawlers){
CrawlerModel crawlerModel = CrawlerCache.getCrawlerModel(cn);
if (crawlerModel == null){
logger.warn("Crawler name = {} is not existent.",cn);
continue;
}
crawlerModel.startRequest();
}
}
//统一通用配置信息至 seimiConfig
SeimiConfig config = new SeimiConfig();
config.setBloomFilterExpectedInsertions(crawlerProperties.getBloomFilterExpectedInsertions());
config.setBloomFilterFalseProbability(crawlerProperties.getBloomFilterFalseProbability());
config.setSeimiAgentHost(crawlerProperties.getSeimiAgentHost());
config.setSeimiAgentPort(crawlerProperties.getSeimiAgentPort());
CrawlerCache.setConfig(config);
}
}
}
|
java
|
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
if (isSpringBoot){
CrawlerProperties crawlerProperties = context.getBean(CrawlerProperties.class);
if (!crawlerProperties.isEnabled()){
logger.warn("{} is not enabled",Constants.SEIMI_CRAWLER_BOOTSTRAP_ENABLED);
return;
}
}
if (context != null) {
if (CollectionUtils.isEmpty(CrawlerCache.getCrawlers())) {
logger.info("Not find any crawler,may be you need to check.");
return;
}
workersPool = Executors.newFixedThreadPool(Constants.BASE_THREAD_NUM * Runtime.getRuntime().availableProcessors() * CrawlerCache.getCrawlers().size());
for (Class<? extends BaseSeimiCrawler> a : CrawlerCache.getCrawlers()) {
CrawlerModel crawlerModel = new CrawlerModel(a, context);
if (CrawlerCache.isExist(crawlerModel.getCrawlerName())) {
logger.error("Crawler:{} is repeated,please check", crawlerModel.getCrawlerName());
throw new SeimiInitExcepiton(StrFormatUtil.info("Crawler:{} is repeated,please check", crawlerModel.getCrawlerName()));
}
CrawlerCache.putCrawlerModel(crawlerModel.getCrawlerName(), crawlerModel);
}
for (Map.Entry<String, CrawlerModel> crawlerEntry : CrawlerCache.getCrawlerModelContext().entrySet()) {
for (int i = 0; i < Constants.BASE_THREAD_NUM * Runtime.getRuntime().availableProcessors(); i++) {
workersPool.execute(new SeimiProcessor(CrawlerCache.getInterceptors(), crawlerEntry.getValue()));
}
}
if (isSpringBoot){
CrawlerProperties crawlerProperties = context.getBean(CrawlerProperties.class);
String crawlerNames = crawlerProperties.getNames();
if (StringUtils.isBlank(crawlerNames)){
logger.info("Spring boot start [{}] as worker.",StringUtils.join(CrawlerCache.getCrawlerModelContext().keySet(),","));
}else {
String[] crawlers = crawlerNames.split(",");
for (String cn:crawlers){
CrawlerModel crawlerModel = CrawlerCache.getCrawlerModel(cn);
if (crawlerModel == null){
logger.warn("Crawler name = {} is not existent.",cn);
continue;
}
crawlerModel.startRequest();
}
}
//统一通用配置信息至 seimiConfig
SeimiConfig config = new SeimiConfig();
config.setBloomFilterExpectedInsertions(crawlerProperties.getBloomFilterExpectedInsertions());
config.setBloomFilterFalseProbability(crawlerProperties.getBloomFilterFalseProbability());
config.setSeimiAgentHost(crawlerProperties.getSeimiAgentHost());
config.setSeimiAgentPort(crawlerProperties.getSeimiAgentPort());
CrawlerCache.setConfig(config);
}
}
}
|
[
"@",
"Override",
"public",
"void",
"onApplicationEvent",
"(",
"ContextRefreshedEvent",
"event",
")",
"{",
"ApplicationContext",
"context",
"=",
"event",
".",
"getApplicationContext",
"(",
")",
";",
"if",
"(",
"isSpringBoot",
")",
"{",
"CrawlerProperties",
"crawlerProperties",
"=",
"context",
".",
"getBean",
"(",
"CrawlerProperties",
".",
"class",
")",
";",
"if",
"(",
"!",
"crawlerProperties",
".",
"isEnabled",
"(",
")",
")",
"{",
"logger",
".",
"warn",
"(",
"\"{} is not enabled\"",
",",
"Constants",
".",
"SEIMI_CRAWLER_BOOTSTRAP_ENABLED",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"context",
"!=",
"null",
")",
"{",
"if",
"(",
"CollectionUtils",
".",
"isEmpty",
"(",
"CrawlerCache",
".",
"getCrawlers",
"(",
")",
")",
")",
"{",
"logger",
".",
"info",
"(",
"\"Not find any crawler,may be you need to check.\"",
")",
";",
"return",
";",
"}",
"workersPool",
"=",
"Executors",
".",
"newFixedThreadPool",
"(",
"Constants",
".",
"BASE_THREAD_NUM",
"*",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"availableProcessors",
"(",
")",
"*",
"CrawlerCache",
".",
"getCrawlers",
"(",
")",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Class",
"<",
"?",
"extends",
"BaseSeimiCrawler",
">",
"a",
":",
"CrawlerCache",
".",
"getCrawlers",
"(",
")",
")",
"{",
"CrawlerModel",
"crawlerModel",
"=",
"new",
"CrawlerModel",
"(",
"a",
",",
"context",
")",
";",
"if",
"(",
"CrawlerCache",
".",
"isExist",
"(",
"crawlerModel",
".",
"getCrawlerName",
"(",
")",
")",
")",
"{",
"logger",
".",
"error",
"(",
"\"Crawler:{} is repeated,please check\"",
",",
"crawlerModel",
".",
"getCrawlerName",
"(",
")",
")",
";",
"throw",
"new",
"SeimiInitExcepiton",
"(",
"StrFormatUtil",
".",
"info",
"(",
"\"Crawler:{} is repeated,please check\"",
",",
"crawlerModel",
".",
"getCrawlerName",
"(",
")",
")",
")",
";",
"}",
"CrawlerCache",
".",
"putCrawlerModel",
"(",
"crawlerModel",
".",
"getCrawlerName",
"(",
")",
",",
"crawlerModel",
")",
";",
"}",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"CrawlerModel",
">",
"crawlerEntry",
":",
"CrawlerCache",
".",
"getCrawlerModelContext",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Constants",
".",
"BASE_THREAD_NUM",
"*",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"availableProcessors",
"(",
")",
";",
"i",
"++",
")",
"{",
"workersPool",
".",
"execute",
"(",
"new",
"SeimiProcessor",
"(",
"CrawlerCache",
".",
"getInterceptors",
"(",
")",
",",
"crawlerEntry",
".",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"isSpringBoot",
")",
"{",
"CrawlerProperties",
"crawlerProperties",
"=",
"context",
".",
"getBean",
"(",
"CrawlerProperties",
".",
"class",
")",
";",
"String",
"crawlerNames",
"=",
"crawlerProperties",
".",
"getNames",
"(",
")",
";",
"if",
"(",
"StringUtils",
".",
"isBlank",
"(",
"crawlerNames",
")",
")",
"{",
"logger",
".",
"info",
"(",
"\"Spring boot start [{}] as worker.\"",
",",
"StringUtils",
".",
"join",
"(",
"CrawlerCache",
".",
"getCrawlerModelContext",
"(",
")",
".",
"keySet",
"(",
")",
",",
"\",\"",
")",
")",
";",
"}",
"else",
"{",
"String",
"[",
"]",
"crawlers",
"=",
"crawlerNames",
".",
"split",
"(",
"\",\"",
")",
";",
"for",
"(",
"String",
"cn",
":",
"crawlers",
")",
"{",
"CrawlerModel",
"crawlerModel",
"=",
"CrawlerCache",
".",
"getCrawlerModel",
"(",
"cn",
")",
";",
"if",
"(",
"crawlerModel",
"==",
"null",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Crawler name = {} is not existent.\"",
",",
"cn",
")",
";",
"continue",
";",
"}",
"crawlerModel",
".",
"startRequest",
"(",
")",
";",
"}",
"}",
"//统一通用配置信息至 seimiConfig",
"SeimiConfig",
"config",
"=",
"new",
"SeimiConfig",
"(",
")",
";",
"config",
".",
"setBloomFilterExpectedInsertions",
"(",
"crawlerProperties",
".",
"getBloomFilterExpectedInsertions",
"(",
")",
")",
";",
"config",
".",
"setBloomFilterFalseProbability",
"(",
"crawlerProperties",
".",
"getBloomFilterFalseProbability",
"(",
")",
")",
";",
"config",
".",
"setSeimiAgentHost",
"(",
"crawlerProperties",
".",
"getSeimiAgentHost",
"(",
")",
")",
";",
"config",
".",
"setSeimiAgentPort",
"(",
"crawlerProperties",
".",
"getSeimiAgentPort",
"(",
")",
")",
";",
"CrawlerCache",
".",
"setConfig",
"(",
"config",
")",
";",
"}",
"}",
"}"
] |
Handle an application event.
@param event the event to respond to
|
[
"Handle",
"an",
"application",
"event",
"."
] |
c9069490616c38c6de059ddc86b79febd6d17641
|
https://github.com/zhegexiaohuozi/SeimiCrawler/blob/c9069490616c38c6de059ddc86b79febd6d17641/seimicrawler/src/main/java/cn/wanghaomiao/seimi/spring/common/SeimiCrawlerBootstrapListener.java#L48-L105
|
16,964
|
line/armeria
|
benchmarks/src/jmh/java/com/linecorp/armeria/common/stream/StreamMessageBenchmark.java
|
StreamMessageBenchmark.notJmhEventLoop
|
@Benchmark
public long notJmhEventLoop(StreamObjects streamObjects) throws Exception {
ANOTHER_EVENT_LOOP.execute(() -> {
final StreamMessage<Integer> stream = newStream(streamObjects);
stream.subscribe(streamObjects.subscriber, ANOTHER_EVENT_LOOP);
streamObjects.writeAllValues(stream);
});
streamObjects.completedLatch.await(10, TimeUnit.SECONDS);
return streamObjects.computedSum();
}
|
java
|
@Benchmark
public long notJmhEventLoop(StreamObjects streamObjects) throws Exception {
ANOTHER_EVENT_LOOP.execute(() -> {
final StreamMessage<Integer> stream = newStream(streamObjects);
stream.subscribe(streamObjects.subscriber, ANOTHER_EVENT_LOOP);
streamObjects.writeAllValues(stream);
});
streamObjects.completedLatch.await(10, TimeUnit.SECONDS);
return streamObjects.computedSum();
}
|
[
"@",
"Benchmark",
"public",
"long",
"notJmhEventLoop",
"(",
"StreamObjects",
"streamObjects",
")",
"throws",
"Exception",
"{",
"ANOTHER_EVENT_LOOP",
".",
"execute",
"(",
"(",
")",
"->",
"{",
"final",
"StreamMessage",
"<",
"Integer",
">",
"stream",
"=",
"newStream",
"(",
"streamObjects",
")",
";",
"stream",
".",
"subscribe",
"(",
"streamObjects",
".",
"subscriber",
",",
"ANOTHER_EVENT_LOOP",
")",
";",
"streamObjects",
".",
"writeAllValues",
"(",
"stream",
")",
";",
"}",
")",
";",
"streamObjects",
".",
"completedLatch",
".",
"await",
"(",
"10",
",",
"TimeUnit",
".",
"SECONDS",
")",
";",
"return",
"streamObjects",
".",
"computedSum",
"(",
")",
";",
"}"
] |
to compare approaches.
|
[
"to",
"compare",
"approaches",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/benchmarks/src/jmh/java/com/linecorp/armeria/common/stream/StreamMessageBenchmark.java#L148-L157
|
16,965
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java
|
AbstractRequestContextBuilder.remoteAddress
|
protected final InetSocketAddress remoteAddress() {
if (remoteAddress == null) {
if (server) {
remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort());
} else {
remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST,
guessServerPort(sessionProtocol, authority));
}
}
return remoteAddress;
}
|
java
|
protected final InetSocketAddress remoteAddress() {
if (remoteAddress == null) {
if (server) {
remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort());
} else {
remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST,
guessServerPort(sessionProtocol, authority));
}
}
return remoteAddress;
}
|
[
"protected",
"final",
"InetSocketAddress",
"remoteAddress",
"(",
")",
"{",
"if",
"(",
"remoteAddress",
"==",
"null",
")",
"{",
"if",
"(",
"server",
")",
"{",
"remoteAddress",
"=",
"new",
"InetSocketAddress",
"(",
"NetUtil",
".",
"LOCALHOST",
",",
"randomClientPort",
"(",
")",
")",
";",
"}",
"else",
"{",
"remoteAddress",
"=",
"new",
"InetSocketAddress",
"(",
"NetUtil",
".",
"LOCALHOST",
",",
"guessServerPort",
"(",
"sessionProtocol",
",",
"authority",
")",
")",
";",
"}",
"}",
"return",
"remoteAddress",
";",
"}"
] |
Returns the remote socket address of the connection.
|
[
"Returns",
"the",
"remote",
"socket",
"address",
"of",
"the",
"connection",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java#L240-L250
|
16,966
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java
|
AbstractRequestContextBuilder.localAddress
|
protected final InetSocketAddress localAddress() {
if (localAddress == null) {
if (server) {
localAddress = new InetSocketAddress(NetUtil.LOCALHOST,
guessServerPort(sessionProtocol, authority));
} else {
localAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort());
}
}
return localAddress;
}
|
java
|
protected final InetSocketAddress localAddress() {
if (localAddress == null) {
if (server) {
localAddress = new InetSocketAddress(NetUtil.LOCALHOST,
guessServerPort(sessionProtocol, authority));
} else {
localAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort());
}
}
return localAddress;
}
|
[
"protected",
"final",
"InetSocketAddress",
"localAddress",
"(",
")",
"{",
"if",
"(",
"localAddress",
"==",
"null",
")",
"{",
"if",
"(",
"server",
")",
"{",
"localAddress",
"=",
"new",
"InetSocketAddress",
"(",
"NetUtil",
".",
"LOCALHOST",
",",
"guessServerPort",
"(",
"sessionProtocol",
",",
"authority",
")",
")",
";",
"}",
"else",
"{",
"localAddress",
"=",
"new",
"InetSocketAddress",
"(",
"NetUtil",
".",
"LOCALHOST",
",",
"randomClientPort",
"(",
")",
")",
";",
"}",
"}",
"return",
"localAddress",
";",
"}"
] |
Returns the local socket address of the connection.
|
[
"Returns",
"the",
"local",
"socket",
"address",
"of",
"the",
"connection",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java#L264-L274
|
16,967
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java
|
AbstractRequestContextBuilder.requestStartTime
|
public final B requestStartTime(long requestStartTimeNanos, long requestStartTimeMicros) {
this.requestStartTimeNanos = requestStartTimeNanos;
this.requestStartTimeMicros = requestStartTimeMicros;
requestStartTimeSet = true;
return self();
}
|
java
|
public final B requestStartTime(long requestStartTimeNanos, long requestStartTimeMicros) {
this.requestStartTimeNanos = requestStartTimeNanos;
this.requestStartTimeMicros = requestStartTimeMicros;
requestStartTimeSet = true;
return self();
}
|
[
"public",
"final",
"B",
"requestStartTime",
"(",
"long",
"requestStartTimeNanos",
",",
"long",
"requestStartTimeMicros",
")",
"{",
"this",
".",
"requestStartTimeNanos",
"=",
"requestStartTimeNanos",
";",
"this",
".",
"requestStartTimeMicros",
"=",
"requestStartTimeMicros",
";",
"requestStartTimeSet",
"=",
"true",
";",
"return",
"self",
"(",
")",
";",
"}"
] |
Sets the request start time of the request.
@param requestStartTimeNanos the {@link System#nanoTime()} value when the request started.
@param requestStartTimeMicros the number of microseconds since the epoch when the request started.
|
[
"Sets",
"the",
"request",
"start",
"time",
"of",
"the",
"request",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/common/AbstractRequestContextBuilder.java#L383-L388
|
16,968
|
line/armeria
|
thrift/src/main/java/com/linecorp/armeria/common/thrift/text/StructContext.java
|
StructContext.computeFieldNameMap
|
private Map<String, TField> computeFieldNameMap(Class<?> clazz) {
final Map<String, TField> map = new HashMap<>();
if (isTBase(clazz)) {
// Get the metaDataMap for this Thrift class
@SuppressWarnings("unchecked")
final Map<? extends TFieldIdEnum, FieldMetaData> metaDataMap =
FieldMetaData.getStructMetaDataMap((Class<? extends TBase<?, ?>>) clazz);
for (Entry<? extends TFieldIdEnum, FieldMetaData> e : metaDataMap.entrySet()) {
final String fieldName = e.getKey().getFieldName();
final FieldMetaData metaData = e.getValue();
final FieldValueMetaData elementMetaData;
if (metaData.valueMetaData.isContainer()) {
if (metaData.valueMetaData instanceof SetMetaData) {
elementMetaData = ((SetMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof ListMetaData) {
elementMetaData = ((ListMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof MapMetaData) {
elementMetaData = ((MapMetaData) metaData.valueMetaData).valueMetaData;
} else {
// Unrecognized container type, but let's still continue processing without
// special enum support.
elementMetaData = metaData.valueMetaData;
}
} else {
elementMetaData = metaData.valueMetaData;
}
if (elementMetaData instanceof EnumMetaData) {
classMap.put(fieldName, ((EnumMetaData) elementMetaData).enumClass);
} else if (elementMetaData instanceof StructMetaData) {
classMap.put(fieldName, ((StructMetaData) elementMetaData).structClass);
}
// Workaround a bug in the generated thrift message read()
// method by mapping the ENUM type to the INT32 type
// The thrift generated parsing code requires that, when expecting
// a value of enum, we actually parse a value of type int32. The
// generated read() method then looks up the enum value in a map.
final byte type = TType.ENUM == metaData.valueMetaData.type ? TType.I32
: metaData.valueMetaData.type;
map.put(fieldName,
new TField(fieldName,
type,
e.getKey().getThriftFieldId()));
}
} else { // TApplicationException
map.put("message", new TField("message", (byte)11, (short)1));
map.put("type", new TField("type", (byte)8, (short)2));
}
return map;
}
|
java
|
private Map<String, TField> computeFieldNameMap(Class<?> clazz) {
final Map<String, TField> map = new HashMap<>();
if (isTBase(clazz)) {
// Get the metaDataMap for this Thrift class
@SuppressWarnings("unchecked")
final Map<? extends TFieldIdEnum, FieldMetaData> metaDataMap =
FieldMetaData.getStructMetaDataMap((Class<? extends TBase<?, ?>>) clazz);
for (Entry<? extends TFieldIdEnum, FieldMetaData> e : metaDataMap.entrySet()) {
final String fieldName = e.getKey().getFieldName();
final FieldMetaData metaData = e.getValue();
final FieldValueMetaData elementMetaData;
if (metaData.valueMetaData.isContainer()) {
if (metaData.valueMetaData instanceof SetMetaData) {
elementMetaData = ((SetMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof ListMetaData) {
elementMetaData = ((ListMetaData) metaData.valueMetaData).elemMetaData;
} else if (metaData.valueMetaData instanceof MapMetaData) {
elementMetaData = ((MapMetaData) metaData.valueMetaData).valueMetaData;
} else {
// Unrecognized container type, but let's still continue processing without
// special enum support.
elementMetaData = metaData.valueMetaData;
}
} else {
elementMetaData = metaData.valueMetaData;
}
if (elementMetaData instanceof EnumMetaData) {
classMap.put(fieldName, ((EnumMetaData) elementMetaData).enumClass);
} else if (elementMetaData instanceof StructMetaData) {
classMap.put(fieldName, ((StructMetaData) elementMetaData).structClass);
}
// Workaround a bug in the generated thrift message read()
// method by mapping the ENUM type to the INT32 type
// The thrift generated parsing code requires that, when expecting
// a value of enum, we actually parse a value of type int32. The
// generated read() method then looks up the enum value in a map.
final byte type = TType.ENUM == metaData.valueMetaData.type ? TType.I32
: metaData.valueMetaData.type;
map.put(fieldName,
new TField(fieldName,
type,
e.getKey().getThriftFieldId()));
}
} else { // TApplicationException
map.put("message", new TField("message", (byte)11, (short)1));
map.put("type", new TField("type", (byte)8, (short)2));
}
return map;
}
|
[
"private",
"Map",
"<",
"String",
",",
"TField",
">",
"computeFieldNameMap",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"TField",
">",
"map",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"if",
"(",
"isTBase",
"(",
"clazz",
")",
")",
"{",
"// Get the metaDataMap for this Thrift class",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"final",
"Map",
"<",
"?",
"extends",
"TFieldIdEnum",
",",
"FieldMetaData",
">",
"metaDataMap",
"=",
"FieldMetaData",
".",
"getStructMetaDataMap",
"(",
"(",
"Class",
"<",
"?",
"extends",
"TBase",
"<",
"?",
",",
"?",
">",
">",
")",
"clazz",
")",
";",
"for",
"(",
"Entry",
"<",
"?",
"extends",
"TFieldIdEnum",
",",
"FieldMetaData",
">",
"e",
":",
"metaDataMap",
".",
"entrySet",
"(",
")",
")",
"{",
"final",
"String",
"fieldName",
"=",
"e",
".",
"getKey",
"(",
")",
".",
"getFieldName",
"(",
")",
";",
"final",
"FieldMetaData",
"metaData",
"=",
"e",
".",
"getValue",
"(",
")",
";",
"final",
"FieldValueMetaData",
"elementMetaData",
";",
"if",
"(",
"metaData",
".",
"valueMetaData",
".",
"isContainer",
"(",
")",
")",
"{",
"if",
"(",
"metaData",
".",
"valueMetaData",
"instanceof",
"SetMetaData",
")",
"{",
"elementMetaData",
"=",
"(",
"(",
"SetMetaData",
")",
"metaData",
".",
"valueMetaData",
")",
".",
"elemMetaData",
";",
"}",
"else",
"if",
"(",
"metaData",
".",
"valueMetaData",
"instanceof",
"ListMetaData",
")",
"{",
"elementMetaData",
"=",
"(",
"(",
"ListMetaData",
")",
"metaData",
".",
"valueMetaData",
")",
".",
"elemMetaData",
";",
"}",
"else",
"if",
"(",
"metaData",
".",
"valueMetaData",
"instanceof",
"MapMetaData",
")",
"{",
"elementMetaData",
"=",
"(",
"(",
"MapMetaData",
")",
"metaData",
".",
"valueMetaData",
")",
".",
"valueMetaData",
";",
"}",
"else",
"{",
"// Unrecognized container type, but let's still continue processing without",
"// special enum support.",
"elementMetaData",
"=",
"metaData",
".",
"valueMetaData",
";",
"}",
"}",
"else",
"{",
"elementMetaData",
"=",
"metaData",
".",
"valueMetaData",
";",
"}",
"if",
"(",
"elementMetaData",
"instanceof",
"EnumMetaData",
")",
"{",
"classMap",
".",
"put",
"(",
"fieldName",
",",
"(",
"(",
"EnumMetaData",
")",
"elementMetaData",
")",
".",
"enumClass",
")",
";",
"}",
"else",
"if",
"(",
"elementMetaData",
"instanceof",
"StructMetaData",
")",
"{",
"classMap",
".",
"put",
"(",
"fieldName",
",",
"(",
"(",
"StructMetaData",
")",
"elementMetaData",
")",
".",
"structClass",
")",
";",
"}",
"// Workaround a bug in the generated thrift message read()",
"// method by mapping the ENUM type to the INT32 type",
"// The thrift generated parsing code requires that, when expecting",
"// a value of enum, we actually parse a value of type int32. The",
"// generated read() method then looks up the enum value in a map.",
"final",
"byte",
"type",
"=",
"TType",
".",
"ENUM",
"==",
"metaData",
".",
"valueMetaData",
".",
"type",
"?",
"TType",
".",
"I32",
":",
"metaData",
".",
"valueMetaData",
".",
"type",
";",
"map",
".",
"put",
"(",
"fieldName",
",",
"new",
"TField",
"(",
"fieldName",
",",
"type",
",",
"e",
".",
"getKey",
"(",
")",
".",
"getThriftFieldId",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"// TApplicationException",
"map",
".",
"put",
"(",
"\"message\"",
",",
"new",
"TField",
"(",
"\"message\"",
",",
"(",
"byte",
")",
"11",
",",
"(",
"short",
")",
"1",
")",
")",
";",
"map",
".",
"put",
"(",
"\"type\"",
",",
"new",
"TField",
"(",
"\"type\"",
",",
"(",
"byte",
")",
"8",
",",
"(",
"short",
")",
"2",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
] |
Compute a new field name map for the current thrift message
we are parsing.
|
[
"Compute",
"a",
"new",
"field",
"name",
"map",
"for",
"the",
"current",
"thrift",
"message",
"we",
"are",
"parsing",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/thrift/src/main/java/com/linecorp/armeria/common/thrift/text/StructContext.java#L198-L253
|
16,969
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/EventLoopScheduler.java
|
EventLoopScheduler.cleanup
|
private void cleanup() {
if ((++counter & 0xFF) != 0) { // (++counter % 256) != 0
return;
}
final long currentTimeNanos = System.nanoTime();
if (currentTimeNanos - lastCleanupTimeNanos < CLEANUP_INTERVAL_NANOS) {
return;
}
for (final Iterator<State> i = map.values().iterator(); i.hasNext();) {
final State state = i.next();
final boolean remove;
synchronized (state) {
remove = state.allActiveRequests == 0 &&
currentTimeNanos - state.lastActivityTimeNanos >= CLEANUP_INTERVAL_NANOS;
}
if (remove) {
i.remove();
}
}
lastCleanupTimeNanos = System.nanoTime();
}
|
java
|
private void cleanup() {
if ((++counter & 0xFF) != 0) { // (++counter % 256) != 0
return;
}
final long currentTimeNanos = System.nanoTime();
if (currentTimeNanos - lastCleanupTimeNanos < CLEANUP_INTERVAL_NANOS) {
return;
}
for (final Iterator<State> i = map.values().iterator(); i.hasNext();) {
final State state = i.next();
final boolean remove;
synchronized (state) {
remove = state.allActiveRequests == 0 &&
currentTimeNanos - state.lastActivityTimeNanos >= CLEANUP_INTERVAL_NANOS;
}
if (remove) {
i.remove();
}
}
lastCleanupTimeNanos = System.nanoTime();
}
|
[
"private",
"void",
"cleanup",
"(",
")",
"{",
"if",
"(",
"(",
"++",
"counter",
"&",
"0xFF",
")",
"!=",
"0",
")",
"{",
"// (++counter % 256) != 0",
"return",
";",
"}",
"final",
"long",
"currentTimeNanos",
"=",
"System",
".",
"nanoTime",
"(",
")",
";",
"if",
"(",
"currentTimeNanos",
"-",
"lastCleanupTimeNanos",
"<",
"CLEANUP_INTERVAL_NANOS",
")",
"{",
"return",
";",
"}",
"for",
"(",
"final",
"Iterator",
"<",
"State",
">",
"i",
"=",
"map",
".",
"values",
"(",
")",
".",
"iterator",
"(",
")",
";",
"i",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"final",
"State",
"state",
"=",
"i",
".",
"next",
"(",
")",
";",
"final",
"boolean",
"remove",
";",
"synchronized",
"(",
"state",
")",
"{",
"remove",
"=",
"state",
".",
"allActiveRequests",
"==",
"0",
"&&",
"currentTimeNanos",
"-",
"state",
".",
"lastActivityTimeNanos",
">=",
"CLEANUP_INTERVAL_NANOS",
";",
"}",
"if",
"(",
"remove",
")",
"{",
"i",
".",
"remove",
"(",
")",
";",
"}",
"}",
"lastCleanupTimeNanos",
"=",
"System",
".",
"nanoTime",
"(",
")",
";",
"}"
] |
Cleans up empty entries with no activity for more than 1 minute. For reduced overhead, we perform this
only when 1) the last clean-up was more than 1 minute ago and 2) the number of acquisitions % 256 is 0.
|
[
"Cleans",
"up",
"empty",
"entries",
"with",
"no",
"activity",
"for",
"more",
"than",
"1",
"minute",
".",
"For",
"reduced",
"overhead",
"we",
"perform",
"this",
"only",
"when",
"1",
")",
"the",
"last",
"clean",
"-",
"up",
"was",
"more",
"than",
"1",
"minute",
"ago",
"and",
"2",
")",
"the",
"number",
"of",
"acquisitions",
"%",
"256",
"is",
"0",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/EventLoopScheduler.java#L76-L101
|
16,970
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroupBuilder.java
|
DnsEndpointGroupBuilder.serverAddresses
|
public final B serverAddresses(Iterable<InetSocketAddress> serverAddresses) {
requireNonNull(serverAddresses, "serverAddresses");
final DnsServerAddresses addrs = DnsServerAddresses.sequential(serverAddresses);
serverAddressStreamProvider = hostname -> addrs.stream();
return self();
}
|
java
|
public final B serverAddresses(Iterable<InetSocketAddress> serverAddresses) {
requireNonNull(serverAddresses, "serverAddresses");
final DnsServerAddresses addrs = DnsServerAddresses.sequential(serverAddresses);
serverAddressStreamProvider = hostname -> addrs.stream();
return self();
}
|
[
"public",
"final",
"B",
"serverAddresses",
"(",
"Iterable",
"<",
"InetSocketAddress",
">",
"serverAddresses",
")",
"{",
"requireNonNull",
"(",
"serverAddresses",
",",
"\"serverAddresses\"",
")",
";",
"final",
"DnsServerAddresses",
"addrs",
"=",
"DnsServerAddresses",
".",
"sequential",
"(",
"serverAddresses",
")",
";",
"serverAddressStreamProvider",
"=",
"hostname",
"->",
"addrs",
".",
"stream",
"(",
")",
";",
"return",
"self",
"(",
")",
";",
"}"
] |
Sets the DNS server addresses to send queries to. Operating system default is used by default.
|
[
"Sets",
"the",
"DNS",
"server",
"addresses",
"to",
"send",
"queries",
"to",
".",
"Operating",
"system",
"default",
"is",
"used",
"by",
"default",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroupBuilder.java#L123-L128
|
16,971
|
line/armeria
|
spring/boot-actuator-autoconfigure/src/main/java/com/linecorp/armeria/spring/actuate/WebOperationHttpService.java
|
WebOperationHttpService.streamResource
|
private static void streamResource(ServiceRequestContext ctx, HttpResponseWriter res,
ReadableByteChannel in, long remainingBytes) {
final int chunkSize = (int) Math.min(8192, remainingBytes);
final ByteBuf buf = ctx.alloc().buffer(chunkSize);
final int readBytes;
boolean success = false;
try {
readBytes = read(in, buf);
if (readBytes < 0) {
// Should not reach here because we only read up to the end of the stream.
// If reached, it may mean the stream has been truncated.
throw new EOFException();
}
success = true;
} catch (Exception e) {
close(res, in, e);
return;
} finally {
if (!success) {
buf.release();
}
}
final long nextRemainingBytes = remainingBytes - readBytes;
final boolean endOfStream = nextRemainingBytes == 0;
if (readBytes > 0) {
if (!res.tryWrite(new ByteBufHttpData(buf, endOfStream))) {
close(in);
return;
}
} else {
buf.release();
}
if (endOfStream) {
close(res, in);
return;
}
res.onDemand(() -> {
try {
ctx.blockingTaskExecutor().execute(() -> streamResource(ctx, res, in, nextRemainingBytes));
} catch (Exception e) {
close(res, in, e);
}
});
}
|
java
|
private static void streamResource(ServiceRequestContext ctx, HttpResponseWriter res,
ReadableByteChannel in, long remainingBytes) {
final int chunkSize = (int) Math.min(8192, remainingBytes);
final ByteBuf buf = ctx.alloc().buffer(chunkSize);
final int readBytes;
boolean success = false;
try {
readBytes = read(in, buf);
if (readBytes < 0) {
// Should not reach here because we only read up to the end of the stream.
// If reached, it may mean the stream has been truncated.
throw new EOFException();
}
success = true;
} catch (Exception e) {
close(res, in, e);
return;
} finally {
if (!success) {
buf.release();
}
}
final long nextRemainingBytes = remainingBytes - readBytes;
final boolean endOfStream = nextRemainingBytes == 0;
if (readBytes > 0) {
if (!res.tryWrite(new ByteBufHttpData(buf, endOfStream))) {
close(in);
return;
}
} else {
buf.release();
}
if (endOfStream) {
close(res, in);
return;
}
res.onDemand(() -> {
try {
ctx.blockingTaskExecutor().execute(() -> streamResource(ctx, res, in, nextRemainingBytes));
} catch (Exception e) {
close(res, in, e);
}
});
}
|
[
"private",
"static",
"void",
"streamResource",
"(",
"ServiceRequestContext",
"ctx",
",",
"HttpResponseWriter",
"res",
",",
"ReadableByteChannel",
"in",
",",
"long",
"remainingBytes",
")",
"{",
"final",
"int",
"chunkSize",
"=",
"(",
"int",
")",
"Math",
".",
"min",
"(",
"8192",
",",
"remainingBytes",
")",
";",
"final",
"ByteBuf",
"buf",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
"chunkSize",
")",
";",
"final",
"int",
"readBytes",
";",
"boolean",
"success",
"=",
"false",
";",
"try",
"{",
"readBytes",
"=",
"read",
"(",
"in",
",",
"buf",
")",
";",
"if",
"(",
"readBytes",
"<",
"0",
")",
"{",
"// Should not reach here because we only read up to the end of the stream.",
"// If reached, it may mean the stream has been truncated.",
"throw",
"new",
"EOFException",
"(",
")",
";",
"}",
"success",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"close",
"(",
"res",
",",
"in",
",",
"e",
")",
";",
"return",
";",
"}",
"finally",
"{",
"if",
"(",
"!",
"success",
")",
"{",
"buf",
".",
"release",
"(",
")",
";",
"}",
"}",
"final",
"long",
"nextRemainingBytes",
"=",
"remainingBytes",
"-",
"readBytes",
";",
"final",
"boolean",
"endOfStream",
"=",
"nextRemainingBytes",
"==",
"0",
";",
"if",
"(",
"readBytes",
">",
"0",
")",
"{",
"if",
"(",
"!",
"res",
".",
"tryWrite",
"(",
"new",
"ByteBufHttpData",
"(",
"buf",
",",
"endOfStream",
")",
")",
")",
"{",
"close",
"(",
"in",
")",
";",
"return",
";",
"}",
"}",
"else",
"{",
"buf",
".",
"release",
"(",
")",
";",
"}",
"if",
"(",
"endOfStream",
")",
"{",
"close",
"(",
"res",
",",
"in",
")",
";",
"return",
";",
"}",
"res",
".",
"onDemand",
"(",
"(",
")",
"->",
"{",
"try",
"{",
"ctx",
".",
"blockingTaskExecutor",
"(",
")",
".",
"execute",
"(",
"(",
")",
"->",
"streamResource",
"(",
"ctx",
",",
"res",
",",
"in",
",",
"nextRemainingBytes",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"close",
"(",
"res",
",",
"in",
",",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
] |
streaming a ReadableByteChannel and an InputStream.
|
[
"streaming",
"a",
"ReadableByteChannel",
"and",
"an",
"InputStream",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/spring/boot-actuator-autoconfigure/src/main/java/com/linecorp/armeria/spring/actuate/WebOperationHttpService.java#L203-L250
|
16,972
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/cors/CorsPolicy.java
|
CorsPolicy.generatePreflightResponseHeaders
|
public HttpHeaders generatePreflightResponseHeaders() {
final HttpHeaders headers = new DefaultHttpHeaders();
preflightResponseHeaders.forEach((key, value) -> {
final Object val = getValue(value);
if (val instanceof Iterable) {
headers.addObject(key, (Iterable<?>) val);
} else {
headers.addObject(key, val);
}
});
return headers.asImmutable();
}
|
java
|
public HttpHeaders generatePreflightResponseHeaders() {
final HttpHeaders headers = new DefaultHttpHeaders();
preflightResponseHeaders.forEach((key, value) -> {
final Object val = getValue(value);
if (val instanceof Iterable) {
headers.addObject(key, (Iterable<?>) val);
} else {
headers.addObject(key, val);
}
});
return headers.asImmutable();
}
|
[
"public",
"HttpHeaders",
"generatePreflightResponseHeaders",
"(",
")",
"{",
"final",
"HttpHeaders",
"headers",
"=",
"new",
"DefaultHttpHeaders",
"(",
")",
";",
"preflightResponseHeaders",
".",
"forEach",
"(",
"(",
"key",
",",
"value",
")",
"->",
"{",
"final",
"Object",
"val",
"=",
"getValue",
"(",
"value",
")",
";",
"if",
"(",
"val",
"instanceof",
"Iterable",
")",
"{",
"headers",
".",
"addObject",
"(",
"key",
",",
"(",
"Iterable",
"<",
"?",
">",
")",
"val",
")",
";",
"}",
"else",
"{",
"headers",
".",
"addObject",
"(",
"key",
",",
"val",
")",
";",
"}",
"}",
")",
";",
"return",
"headers",
".",
"asImmutable",
"(",
")",
";",
"}"
] |
Generates immutable HTTP response headers that should be added to a CORS preflight response.
@return {@link HttpHeaders} the HTTP response headers to be added.
|
[
"Generates",
"immutable",
"HTTP",
"response",
"headers",
"that",
"should",
"be",
"added",
"to",
"a",
"CORS",
"preflight",
"response",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/cors/CorsPolicy.java#L215-L226
|
16,973
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/internal/PooledObjects.java
|
PooledObjects.toUnpooled
|
public static <T> T toUnpooled(T o) {
if (o instanceof ByteBufHolder) {
o = copyAndRelease((ByteBufHolder) o);
} else if (o instanceof ByteBuf) {
o = copyAndRelease((ByteBuf) o);
}
return o;
}
|
java
|
public static <T> T toUnpooled(T o) {
if (o instanceof ByteBufHolder) {
o = copyAndRelease((ByteBufHolder) o);
} else if (o instanceof ByteBuf) {
o = copyAndRelease((ByteBuf) o);
}
return o;
}
|
[
"public",
"static",
"<",
"T",
">",
"T",
"toUnpooled",
"(",
"T",
"o",
")",
"{",
"if",
"(",
"o",
"instanceof",
"ByteBufHolder",
")",
"{",
"o",
"=",
"copyAndRelease",
"(",
"(",
"ByteBufHolder",
")",
"o",
")",
";",
"}",
"else",
"if",
"(",
"o",
"instanceof",
"ByteBuf",
")",
"{",
"o",
"=",
"copyAndRelease",
"(",
"(",
"ByteBuf",
")",
"o",
")",
";",
"}",
"return",
"o",
";",
"}"
] |
Converts the given object to an unpooled copy and releases the given object.
|
[
"Converts",
"the",
"given",
"object",
"to",
"an",
"unpooled",
"copy",
"and",
"releases",
"the",
"given",
"object",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/internal/PooledObjects.java#L32-L39
|
16,974
|
line/armeria
|
grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/StatusMessageEscaper.java
|
StatusMessageEscaper.doEscape
|
private static String doEscape(byte[] valueBytes, int ri) {
final byte[] escapedBytes = new byte[ri + (valueBytes.length - ri) * 3];
// copy over the good bytes
if (ri != 0) {
System.arraycopy(valueBytes, 0, escapedBytes, 0, ri);
}
int wi = ri;
for (; ri < valueBytes.length; ri++) {
final byte b = valueBytes[ri];
// Manually implement URL encoding, per the gRPC spec.
if (isEscapingChar(b)) {
escapedBytes[wi] = '%';
escapedBytes[wi + 1] = HEX[(b >> 4) & 0xF];
escapedBytes[wi + 2] = HEX[b & 0xF];
wi += 3;
continue;
}
escapedBytes[wi++] = b;
}
final byte[] dest = new byte[wi];
System.arraycopy(escapedBytes, 0, dest, 0, wi);
return new String(dest, StandardCharsets.US_ASCII);
}
|
java
|
private static String doEscape(byte[] valueBytes, int ri) {
final byte[] escapedBytes = new byte[ri + (valueBytes.length - ri) * 3];
// copy over the good bytes
if (ri != 0) {
System.arraycopy(valueBytes, 0, escapedBytes, 0, ri);
}
int wi = ri;
for (; ri < valueBytes.length; ri++) {
final byte b = valueBytes[ri];
// Manually implement URL encoding, per the gRPC spec.
if (isEscapingChar(b)) {
escapedBytes[wi] = '%';
escapedBytes[wi + 1] = HEX[(b >> 4) & 0xF];
escapedBytes[wi + 2] = HEX[b & 0xF];
wi += 3;
continue;
}
escapedBytes[wi++] = b;
}
final byte[] dest = new byte[wi];
System.arraycopy(escapedBytes, 0, dest, 0, wi);
return new String(dest, StandardCharsets.US_ASCII);
}
|
[
"private",
"static",
"String",
"doEscape",
"(",
"byte",
"[",
"]",
"valueBytes",
",",
"int",
"ri",
")",
"{",
"final",
"byte",
"[",
"]",
"escapedBytes",
"=",
"new",
"byte",
"[",
"ri",
"+",
"(",
"valueBytes",
".",
"length",
"-",
"ri",
")",
"*",
"3",
"]",
";",
"// copy over the good bytes",
"if",
"(",
"ri",
"!=",
"0",
")",
"{",
"System",
".",
"arraycopy",
"(",
"valueBytes",
",",
"0",
",",
"escapedBytes",
",",
"0",
",",
"ri",
")",
";",
"}",
"int",
"wi",
"=",
"ri",
";",
"for",
"(",
";",
"ri",
"<",
"valueBytes",
".",
"length",
";",
"ri",
"++",
")",
"{",
"final",
"byte",
"b",
"=",
"valueBytes",
"[",
"ri",
"]",
";",
"// Manually implement URL encoding, per the gRPC spec.",
"if",
"(",
"isEscapingChar",
"(",
"b",
")",
")",
"{",
"escapedBytes",
"[",
"wi",
"]",
"=",
"'",
"'",
";",
"escapedBytes",
"[",
"wi",
"+",
"1",
"]",
"=",
"HEX",
"[",
"(",
"b",
">>",
"4",
")",
"&",
"0xF",
"]",
";",
"escapedBytes",
"[",
"wi",
"+",
"2",
"]",
"=",
"HEX",
"[",
"b",
"&",
"0xF",
"]",
";",
"wi",
"+=",
"3",
";",
"continue",
";",
"}",
"escapedBytes",
"[",
"wi",
"++",
"]",
"=",
"b",
";",
"}",
"final",
"byte",
"[",
"]",
"dest",
"=",
"new",
"byte",
"[",
"wi",
"]",
";",
"System",
".",
"arraycopy",
"(",
"escapedBytes",
",",
"0",
",",
"dest",
",",
"0",
",",
"wi",
")",
";",
"return",
"new",
"String",
"(",
"dest",
",",
"StandardCharsets",
".",
"US_ASCII",
")",
";",
"}"
] |
Escapes the given byte array.
@param valueBytes the UTF-8 bytes
@param ri The reader index, pointed at the first byte that needs escaping.
|
[
"Escapes",
"the",
"given",
"byte",
"array",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/grpc-protocol/src/main/java/com/linecorp/armeria/common/grpc/protocol/StatusMessageEscaper.java#L86-L109
|
16,975
|
line/armeria
|
grpc/src/main/java/com/linecorp/armeria/server/grpc/ArmeriaServerCall.java
|
ArmeriaServerCall.encodeHeader
|
private static void encodeHeader(CharSequence name, CharSequence value, ByteBuf buf) {
final int nameLen = name.length();
final int valueLen = value.length();
final int entryLen = nameLen + valueLen + 4;
buf.ensureWritable(entryLen);
int offset = buf.writerIndex();
writeAscii(buf, offset, name, nameLen);
offset += nameLen;
buf.setByte(offset++, ':');
buf.setByte(offset++, ' ');
writeAscii(buf, offset, value, valueLen);
offset += valueLen;
buf.setByte(offset++, '\r');
buf.setByte(offset++, '\n');
buf.writerIndex(offset);
}
|
java
|
private static void encodeHeader(CharSequence name, CharSequence value, ByteBuf buf) {
final int nameLen = name.length();
final int valueLen = value.length();
final int entryLen = nameLen + valueLen + 4;
buf.ensureWritable(entryLen);
int offset = buf.writerIndex();
writeAscii(buf, offset, name, nameLen);
offset += nameLen;
buf.setByte(offset++, ':');
buf.setByte(offset++, ' ');
writeAscii(buf, offset, value, valueLen);
offset += valueLen;
buf.setByte(offset++, '\r');
buf.setByte(offset++, '\n');
buf.writerIndex(offset);
}
|
[
"private",
"static",
"void",
"encodeHeader",
"(",
"CharSequence",
"name",
",",
"CharSequence",
"value",
",",
"ByteBuf",
"buf",
")",
"{",
"final",
"int",
"nameLen",
"=",
"name",
".",
"length",
"(",
")",
";",
"final",
"int",
"valueLen",
"=",
"value",
".",
"length",
"(",
")",
";",
"final",
"int",
"entryLen",
"=",
"nameLen",
"+",
"valueLen",
"+",
"4",
";",
"buf",
".",
"ensureWritable",
"(",
"entryLen",
")",
";",
"int",
"offset",
"=",
"buf",
".",
"writerIndex",
"(",
")",
";",
"writeAscii",
"(",
"buf",
",",
"offset",
",",
"name",
",",
"nameLen",
")",
";",
"offset",
"+=",
"nameLen",
";",
"buf",
".",
"setByte",
"(",
"offset",
"++",
",",
"'",
"'",
")",
";",
"buf",
".",
"setByte",
"(",
"offset",
"++",
",",
"'",
"'",
")",
";",
"writeAscii",
"(",
"buf",
",",
"offset",
",",
"value",
",",
"valueLen",
")",
";",
"offset",
"+=",
"valueLen",
";",
"buf",
".",
"setByte",
"(",
"offset",
"++",
",",
"'",
"'",
")",
";",
"buf",
".",
"setByte",
"(",
"offset",
"++",
",",
"'",
"'",
")",
";",
"buf",
".",
"writerIndex",
"(",
"offset",
")",
";",
"}"
] |
Copied from io.netty.handler.codec.http.HttpHeadersEncoder
|
[
"Copied",
"from",
"io",
".",
"netty",
".",
"handler",
".",
"codec",
".",
"http",
".",
"HttpHeadersEncoder"
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/grpc/src/main/java/com/linecorp/armeria/server/grpc/ArmeriaServerCall.java#L575-L590
|
16,976
|
line/armeria
|
it/spring/boot-tomcat/src/main/java/com/linecorp/armeria/spring/tomcat/demo/SpringTomcatApplication.java
|
SpringTomcatApplication.armeriaTomcat
|
@Bean
public ArmeriaServerConfigurator armeriaTomcat() {
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
if (webServer instanceof TomcatWebServer) {
Tomcat tomcat = ((TomcatWebServer) webServer).getTomcat();
return serverBuilder -> serverBuilder.service("prefix:/tomcat/api/rest/v1",
TomcatService.forTomcat(tomcat));
}
return serverBuilder -> { };
}
|
java
|
@Bean
public ArmeriaServerConfigurator armeriaTomcat() {
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
if (webServer instanceof TomcatWebServer) {
Tomcat tomcat = ((TomcatWebServer) webServer).getTomcat();
return serverBuilder -> serverBuilder.service("prefix:/tomcat/api/rest/v1",
TomcatService.forTomcat(tomcat));
}
return serverBuilder -> { };
}
|
[
"@",
"Bean",
"public",
"ArmeriaServerConfigurator",
"armeriaTomcat",
"(",
")",
"{",
"WebServer",
"webServer",
"=",
"(",
"(",
"WebServerApplicationContext",
")",
"applicationContext",
")",
".",
"getWebServer",
"(",
")",
";",
"if",
"(",
"webServer",
"instanceof",
"TomcatWebServer",
")",
"{",
"Tomcat",
"tomcat",
"=",
"(",
"(",
"TomcatWebServer",
")",
"webServer",
")",
".",
"getTomcat",
"(",
")",
";",
"return",
"serverBuilder",
"->",
"serverBuilder",
".",
"service",
"(",
"\"prefix:/tomcat/api/rest/v1\"",
",",
"TomcatService",
".",
"forTomcat",
"(",
"tomcat",
")",
")",
";",
"}",
"return",
"serverBuilder",
"->",
"{",
"}",
";",
"}"
] |
Bean to configure Armeria Tomcat service.
@return configuration bean.
|
[
"Bean",
"to",
"configure",
"Armeria",
"Tomcat",
"service",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/it/spring/boot-tomcat/src/main/java/com/linecorp/armeria/spring/tomcat/demo/SpringTomcatApplication.java#L43-L53
|
16,977
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/Endpoint.java
|
Endpoint.withDefaultPort
|
public Endpoint withDefaultPort(int defaultPort) {
ensureSingle();
validatePort("defaultPort", defaultPort);
if (port != 0) {
return this;
}
return new Endpoint(host(), ipAddr(), defaultPort, weight(), hostType);
}
|
java
|
public Endpoint withDefaultPort(int defaultPort) {
ensureSingle();
validatePort("defaultPort", defaultPort);
if (port != 0) {
return this;
}
return new Endpoint(host(), ipAddr(), defaultPort, weight(), hostType);
}
|
[
"public",
"Endpoint",
"withDefaultPort",
"(",
"int",
"defaultPort",
")",
"{",
"ensureSingle",
"(",
")",
";",
"validatePort",
"(",
"\"defaultPort\"",
",",
"defaultPort",
")",
";",
"if",
"(",
"port",
"!=",
"0",
")",
"{",
"return",
"this",
";",
"}",
"return",
"new",
"Endpoint",
"(",
"host",
"(",
")",
",",
"ipAddr",
"(",
")",
",",
"defaultPort",
",",
"weight",
"(",
")",
",",
"hostType",
")",
";",
"}"
] |
Returns a new host endpoint with the specified default port number.
@return the new endpoint whose port is {@code defaultPort} if this endpoint does not have its port
specified. {@code this} if this endpoint already has its port specified.
@throws IllegalStateException if this endpoint is not a host but a group
|
[
"Returns",
"a",
"new",
"host",
"endpoint",
"with",
"the",
"specified",
"default",
"port",
"number",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/Endpoint.java#L317-L326
|
16,978
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/Endpoint.java
|
Endpoint.withWeight
|
public Endpoint withWeight(int weight) {
ensureSingle();
validateWeight(weight);
if (this.weight == weight) {
return this;
}
return new Endpoint(host(), ipAddr(), port, weight, hostType);
}
|
java
|
public Endpoint withWeight(int weight) {
ensureSingle();
validateWeight(weight);
if (this.weight == weight) {
return this;
}
return new Endpoint(host(), ipAddr(), port, weight, hostType);
}
|
[
"public",
"Endpoint",
"withWeight",
"(",
"int",
"weight",
")",
"{",
"ensureSingle",
"(",
")",
";",
"validateWeight",
"(",
"weight",
")",
";",
"if",
"(",
"this",
".",
"weight",
"==",
"weight",
")",
"{",
"return",
"this",
";",
"}",
"return",
"new",
"Endpoint",
"(",
"host",
"(",
")",
",",
"ipAddr",
"(",
")",
",",
"port",
",",
"weight",
",",
"hostType",
")",
";",
"}"
] |
Returns a new host endpoint with the specified weight.
@return the new endpoint with the specified weight. {@code this} if this endpoint has the same weight.
@throws IllegalStateException if this endpoint is not a host but a group
|
[
"Returns",
"a",
"new",
"host",
"endpoint",
"with",
"the",
"specified",
"weight",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/Endpoint.java#L391-L398
|
16,979
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/Endpoint.java
|
Endpoint.authority
|
public String authority() {
String authority = this.authority;
if (authority != null) {
return authority;
}
if (isGroup()) {
authority = "group:" + groupName;
} else if (port != 0) {
if (hostType == HostType.IPv6_ONLY) {
authority = '[' + host() + "]:" + port;
} else {
authority = host() + ':' + port;
}
} else if (hostType == HostType.IPv6_ONLY) {
authority = '[' + host() + ']';
} else {
authority = host();
}
return this.authority = authority;
}
|
java
|
public String authority() {
String authority = this.authority;
if (authority != null) {
return authority;
}
if (isGroup()) {
authority = "group:" + groupName;
} else if (port != 0) {
if (hostType == HostType.IPv6_ONLY) {
authority = '[' + host() + "]:" + port;
} else {
authority = host() + ':' + port;
}
} else if (hostType == HostType.IPv6_ONLY) {
authority = '[' + host() + ']';
} else {
authority = host();
}
return this.authority = authority;
}
|
[
"public",
"String",
"authority",
"(",
")",
"{",
"String",
"authority",
"=",
"this",
".",
"authority",
";",
"if",
"(",
"authority",
"!=",
"null",
")",
"{",
"return",
"authority",
";",
"}",
"if",
"(",
"isGroup",
"(",
")",
")",
"{",
"authority",
"=",
"\"group:\"",
"+",
"groupName",
";",
"}",
"else",
"if",
"(",
"port",
"!=",
"0",
")",
"{",
"if",
"(",
"hostType",
"==",
"HostType",
".",
"IPv6_ONLY",
")",
"{",
"authority",
"=",
"'",
"'",
"+",
"host",
"(",
")",
"+",
"\"]:\"",
"+",
"port",
";",
"}",
"else",
"{",
"authority",
"=",
"host",
"(",
")",
"+",
"'",
"'",
"+",
"port",
";",
"}",
"}",
"else",
"if",
"(",
"hostType",
"==",
"HostType",
".",
"IPv6_ONLY",
")",
"{",
"authority",
"=",
"'",
"'",
"+",
"host",
"(",
")",
"+",
"'",
"'",
";",
"}",
"else",
"{",
"authority",
"=",
"host",
"(",
")",
";",
"}",
"return",
"this",
".",
"authority",
"=",
"authority",
";",
"}"
] |
Converts this endpoint into the authority part of a URI.
@return the authority string
|
[
"Converts",
"this",
"endpoint",
"into",
"the",
"authority",
"part",
"of",
"a",
"URI",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/Endpoint.java#L413-L434
|
16,980
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroup.java
|
DnsEndpointGroup.close
|
@Override
public final void close() {
stopped = true;
super.close();
final ScheduledFuture<?> scheduledFuture = this.scheduledFuture;
if (scheduledFuture != null) {
scheduledFuture.cancel(true);
}
}
|
java
|
@Override
public final void close() {
stopped = true;
super.close();
final ScheduledFuture<?> scheduledFuture = this.scheduledFuture;
if (scheduledFuture != null) {
scheduledFuture.cancel(true);
}
}
|
[
"@",
"Override",
"public",
"final",
"void",
"close",
"(",
")",
"{",
"stopped",
"=",
"true",
";",
"super",
".",
"close",
"(",
")",
";",
"final",
"ScheduledFuture",
"<",
"?",
">",
"scheduledFuture",
"=",
"this",
".",
"scheduledFuture",
";",
"if",
"(",
"scheduledFuture",
"!=",
"null",
")",
"{",
"scheduledFuture",
".",
"cancel",
"(",
"true",
")",
";",
"}",
"}"
] |
Stops polling DNS servers for service updates.
|
[
"Stops",
"polling",
"DNS",
"servers",
"for",
"service",
"updates",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroup.java#L230-L238
|
16,981
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroup.java
|
DnsEndpointGroup.warnInvalidRecord
|
final void warnInvalidRecord(DnsRecordType type, ByteBuf content) {
if (logger().isWarnEnabled()) {
final String dump = ByteBufUtil.hexDump(content);
logger().warn("{} Skipping invalid {} record: {}",
logPrefix(), type.name(), dump.isEmpty() ? "<empty>" : dump);
}
}
|
java
|
final void warnInvalidRecord(DnsRecordType type, ByteBuf content) {
if (logger().isWarnEnabled()) {
final String dump = ByteBufUtil.hexDump(content);
logger().warn("{} Skipping invalid {} record: {}",
logPrefix(), type.name(), dump.isEmpty() ? "<empty>" : dump);
}
}
|
[
"final",
"void",
"warnInvalidRecord",
"(",
"DnsRecordType",
"type",
",",
"ByteBuf",
"content",
")",
"{",
"if",
"(",
"logger",
"(",
")",
".",
"isWarnEnabled",
"(",
")",
")",
"{",
"final",
"String",
"dump",
"=",
"ByteBufUtil",
".",
"hexDump",
"(",
"content",
")",
";",
"logger",
"(",
")",
".",
"warn",
"(",
"\"{} Skipping invalid {} record: {}\"",
",",
"logPrefix",
"(",
")",
",",
"type",
".",
"name",
"(",
")",
",",
"dump",
".",
"isEmpty",
"(",
")",
"?",
"\"<empty>\"",
":",
"dump",
")",
";",
"}",
"}"
] |
Logs a warning message about an invalid record.
|
[
"Logs",
"a",
"warning",
"message",
"about",
"an",
"invalid",
"record",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsEndpointGroup.java#L243-L249
|
16,982
|
line/armeria
|
spring/boot-autoconfigure/src/main/java/com/linecorp/armeria/spring/AbstractServiceRegistrationBean.java
|
AbstractServiceRegistrationBean.getDecorators
|
@NotNull
public final List<Function<Service<HttpRequest, HttpResponse>,
? extends Service<HttpRequest, HttpResponse>>> getDecorators() {
return decorators;
}
|
java
|
@NotNull
public final List<Function<Service<HttpRequest, HttpResponse>,
? extends Service<HttpRequest, HttpResponse>>> getDecorators() {
return decorators;
}
|
[
"@",
"NotNull",
"public",
"final",
"List",
"<",
"Function",
"<",
"Service",
"<",
"HttpRequest",
",",
"HttpResponse",
">",
",",
"?",
"extends",
"Service",
"<",
"HttpRequest",
",",
"HttpResponse",
">",
">",
">",
"getDecorators",
"(",
")",
"{",
"return",
"decorators",
";",
"}"
] |
Returns the decorators of the annotated service object.
|
[
"Returns",
"the",
"decorators",
"of",
"the",
"annotated",
"service",
"object",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/spring/boot-autoconfigure/src/main/java/com/linecorp/armeria/spring/AbstractServiceRegistrationBean.java#L94-L98
|
16,983
|
line/armeria
|
tomcat/src/main/java/com/linecorp/armeria/server/tomcat/TomcatServiceBuilder.java
|
TomcatServiceBuilder.baseDir
|
public TomcatServiceBuilder baseDir(Path baseDir) {
baseDir = requireNonNull(baseDir, "baseDir").toAbsolutePath();
if (!Files.isDirectory(baseDir)) {
throw new IllegalArgumentException("baseDir: " + baseDir + " (expected: a directory)");
}
this.baseDir = baseDir;
return this;
}
|
java
|
public TomcatServiceBuilder baseDir(Path baseDir) {
baseDir = requireNonNull(baseDir, "baseDir").toAbsolutePath();
if (!Files.isDirectory(baseDir)) {
throw new IllegalArgumentException("baseDir: " + baseDir + " (expected: a directory)");
}
this.baseDir = baseDir;
return this;
}
|
[
"public",
"TomcatServiceBuilder",
"baseDir",
"(",
"Path",
"baseDir",
")",
"{",
"baseDir",
"=",
"requireNonNull",
"(",
"baseDir",
",",
"\"baseDir\"",
")",
".",
"toAbsolutePath",
"(",
")",
";",
"if",
"(",
"!",
"Files",
".",
"isDirectory",
"(",
"baseDir",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"baseDir: \"",
"+",
"baseDir",
"+",
"\" (expected: a directory)\"",
")",
";",
"}",
"this",
".",
"baseDir",
"=",
"baseDir",
";",
"return",
"this",
";",
"}"
] |
Sets the base directory of an embedded Tomcat.
|
[
"Sets",
"the",
"base",
"directory",
"of",
"an",
"embedded",
"Tomcat",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/tomcat/src/main/java/com/linecorp/armeria/server/tomcat/TomcatServiceBuilder.java#L262-L270
|
16,984
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java
|
TypeSignature.ofBase
|
public static TypeSignature ofBase(String baseTypeName) {
checkBaseTypeName(baseTypeName, "baseTypeName");
return new TypeSignature(baseTypeName, ImmutableList.of());
}
|
java
|
public static TypeSignature ofBase(String baseTypeName) {
checkBaseTypeName(baseTypeName, "baseTypeName");
return new TypeSignature(baseTypeName, ImmutableList.of());
}
|
[
"public",
"static",
"TypeSignature",
"ofBase",
"(",
"String",
"baseTypeName",
")",
"{",
"checkBaseTypeName",
"(",
"baseTypeName",
",",
"\"baseTypeName\"",
")",
";",
"return",
"new",
"TypeSignature",
"(",
"baseTypeName",
",",
"ImmutableList",
".",
"of",
"(",
")",
")",
";",
"}"
] |
Creates a new type signature for a base type.
@throws IllegalArgumentException if the specified type name is not valid
|
[
"Creates",
"a",
"new",
"type",
"signature",
"for",
"a",
"base",
"type",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java#L67-L70
|
16,985
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java
|
TypeSignature.ofNamed
|
public static TypeSignature ofNamed(String name, Object namedTypeDescriptor) {
return new TypeSignature(requireNonNull(name, "name"),
requireNonNull(namedTypeDescriptor, "namedTypeDescriptor"));
}
|
java
|
public static TypeSignature ofNamed(String name, Object namedTypeDescriptor) {
return new TypeSignature(requireNonNull(name, "name"),
requireNonNull(namedTypeDescriptor, "namedTypeDescriptor"));
}
|
[
"public",
"static",
"TypeSignature",
"ofNamed",
"(",
"String",
"name",
",",
"Object",
"namedTypeDescriptor",
")",
"{",
"return",
"new",
"TypeSignature",
"(",
"requireNonNull",
"(",
"name",
",",
"\"name\"",
")",
",",
"requireNonNull",
"(",
"namedTypeDescriptor",
",",
"\"namedTypeDescriptor\"",
")",
")",
";",
"}"
] |
Creates a new named type signature for the provided name and arbitrary descriptor.
|
[
"Creates",
"a",
"new",
"named",
"type",
"signature",
"for",
"the",
"provided",
"name",
"and",
"arbitrary",
"descriptor",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java#L185-L188
|
16,986
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java
|
TypeSignature.ofUnresolved
|
public static TypeSignature ofUnresolved(String unresolvedTypeName) {
requireNonNull(unresolvedTypeName, "unresolvedTypeName");
return new TypeSignature('?' + unresolvedTypeName, ImmutableList.of());
}
|
java
|
public static TypeSignature ofUnresolved(String unresolvedTypeName) {
requireNonNull(unresolvedTypeName, "unresolvedTypeName");
return new TypeSignature('?' + unresolvedTypeName, ImmutableList.of());
}
|
[
"public",
"static",
"TypeSignature",
"ofUnresolved",
"(",
"String",
"unresolvedTypeName",
")",
"{",
"requireNonNull",
"(",
"unresolvedTypeName",
",",
"\"unresolvedTypeName\"",
")",
";",
"return",
"new",
"TypeSignature",
"(",
"'",
"'",
"+",
"unresolvedTypeName",
",",
"ImmutableList",
".",
"of",
"(",
")",
")",
";",
"}"
] |
Creates a new unresolved type signature with the specified type name.
|
[
"Creates",
"a",
"new",
"unresolved",
"type",
"signature",
"with",
"the",
"specified",
"type",
"name",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/docs/TypeSignature.java#L204-L207
|
16,987
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/encoding/HttpEncoders.java
|
HttpEncoders.determineEncoding
|
@Nullable
@SuppressWarnings("FloatingPointEquality")
private static HttpEncodingType determineEncoding(String acceptEncoding) {
float starQ = -1.0f;
float gzipQ = -1.0f;
float deflateQ = -1.0f;
for (String encoding : acceptEncoding.split(",")) {
float q = 1.0f;
final int equalsPos = encoding.indexOf('=');
if (equalsPos != -1) {
try {
q = Float.parseFloat(encoding.substring(equalsPos + 1));
} catch (NumberFormatException e) {
// Ignore encoding
q = 0.0f;
}
}
if (encoding.contains("*")) {
starQ = q;
} else if (encoding.contains("gzip") && q > gzipQ) {
gzipQ = q;
} else if (encoding.contains("deflate") && q > deflateQ) {
deflateQ = q;
}
}
if (gzipQ > 0.0f || deflateQ > 0.0f) {
if (gzipQ >= deflateQ) {
return HttpEncodingType.GZIP;
} else {
return HttpEncodingType.DEFLATE;
}
}
if (starQ > 0.0f) {
if (gzipQ == -1.0f) {
return HttpEncodingType.GZIP;
}
if (deflateQ == -1.0f) {
return HttpEncodingType.DEFLATE;
}
}
return null;
}
|
java
|
@Nullable
@SuppressWarnings("FloatingPointEquality")
private static HttpEncodingType determineEncoding(String acceptEncoding) {
float starQ = -1.0f;
float gzipQ = -1.0f;
float deflateQ = -1.0f;
for (String encoding : acceptEncoding.split(",")) {
float q = 1.0f;
final int equalsPos = encoding.indexOf('=');
if (equalsPos != -1) {
try {
q = Float.parseFloat(encoding.substring(equalsPos + 1));
} catch (NumberFormatException e) {
// Ignore encoding
q = 0.0f;
}
}
if (encoding.contains("*")) {
starQ = q;
} else if (encoding.contains("gzip") && q > gzipQ) {
gzipQ = q;
} else if (encoding.contains("deflate") && q > deflateQ) {
deflateQ = q;
}
}
if (gzipQ > 0.0f || deflateQ > 0.0f) {
if (gzipQ >= deflateQ) {
return HttpEncodingType.GZIP;
} else {
return HttpEncodingType.DEFLATE;
}
}
if (starQ > 0.0f) {
if (gzipQ == -1.0f) {
return HttpEncodingType.GZIP;
}
if (deflateQ == -1.0f) {
return HttpEncodingType.DEFLATE;
}
}
return null;
}
|
[
"@",
"Nullable",
"@",
"SuppressWarnings",
"(",
"\"FloatingPointEquality\"",
")",
"private",
"static",
"HttpEncodingType",
"determineEncoding",
"(",
"String",
"acceptEncoding",
")",
"{",
"float",
"starQ",
"=",
"-",
"1.0f",
";",
"float",
"gzipQ",
"=",
"-",
"1.0f",
";",
"float",
"deflateQ",
"=",
"-",
"1.0f",
";",
"for",
"(",
"String",
"encoding",
":",
"acceptEncoding",
".",
"split",
"(",
"\",\"",
")",
")",
"{",
"float",
"q",
"=",
"1.0f",
";",
"final",
"int",
"equalsPos",
"=",
"encoding",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"equalsPos",
"!=",
"-",
"1",
")",
"{",
"try",
"{",
"q",
"=",
"Float",
".",
"parseFloat",
"(",
"encoding",
".",
"substring",
"(",
"equalsPos",
"+",
"1",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"// Ignore encoding",
"q",
"=",
"0.0f",
";",
"}",
"}",
"if",
"(",
"encoding",
".",
"contains",
"(",
"\"*\"",
")",
")",
"{",
"starQ",
"=",
"q",
";",
"}",
"else",
"if",
"(",
"encoding",
".",
"contains",
"(",
"\"gzip\"",
")",
"&&",
"q",
">",
"gzipQ",
")",
"{",
"gzipQ",
"=",
"q",
";",
"}",
"else",
"if",
"(",
"encoding",
".",
"contains",
"(",
"\"deflate\"",
")",
"&&",
"q",
">",
"deflateQ",
")",
"{",
"deflateQ",
"=",
"q",
";",
"}",
"}",
"if",
"(",
"gzipQ",
">",
"0.0f",
"||",
"deflateQ",
">",
"0.0f",
")",
"{",
"if",
"(",
"gzipQ",
">=",
"deflateQ",
")",
"{",
"return",
"HttpEncodingType",
".",
"GZIP",
";",
"}",
"else",
"{",
"return",
"HttpEncodingType",
".",
"DEFLATE",
";",
"}",
"}",
"if",
"(",
"starQ",
">",
"0.0f",
")",
"{",
"if",
"(",
"gzipQ",
"==",
"-",
"1.0f",
")",
"{",
"return",
"HttpEncodingType",
".",
"GZIP",
";",
"}",
"if",
"(",
"deflateQ",
"==",
"-",
"1.0f",
")",
"{",
"return",
"HttpEncodingType",
".",
"DEFLATE",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Copied from netty's HttpContentCompressor.
|
[
"Copied",
"from",
"netty",
"s",
"HttpContentCompressor",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/encoding/HttpEncoders.java#L60-L101
|
16,988
|
line/armeria
|
it/spring/boot-tomcat/src/main/java/com/linecorp/armeria/spring/tomcat/demo/GreetingController.java
|
GreetingController.greetingSync
|
@GetMapping
public ResponseEntity<Greeting> greetingSync(
@RequestParam(value = "name", defaultValue = "World") String name) {
return ResponseEntity.ok(new Greeting(String.format(template, name)));
}
|
java
|
@GetMapping
public ResponseEntity<Greeting> greetingSync(
@RequestParam(value = "name", defaultValue = "World") String name) {
return ResponseEntity.ok(new Greeting(String.format(template, name)));
}
|
[
"@",
"GetMapping",
"public",
"ResponseEntity",
"<",
"Greeting",
">",
"greetingSync",
"(",
"@",
"RequestParam",
"(",
"value",
"=",
"\"name\"",
",",
"defaultValue",
"=",
"\"World\"",
")",
"String",
"name",
")",
"{",
"return",
"ResponseEntity",
".",
"ok",
"(",
"new",
"Greeting",
"(",
"String",
".",
"format",
"(",
"template",
",",
"name",
")",
")",
")",
";",
"}"
] |
Greeting endpoint.
@param name name to greet.
@return response the ResponseEntity.
|
[
"Greeting",
"endpoint",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/it/spring/boot-tomcat/src/main/java/com/linecorp/armeria/spring/tomcat/demo/GreetingController.java#L35-L39
|
16,989
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/common/stream/AbstractStreamMessage.java
|
AbstractStreamMessage.cleanupQueue
|
void cleanupQueue(SubscriptionImpl subscription, Queue<Object> queue) {
final Throwable cause = ClosedPublisherException.get();
for (;;) {
final Object e = queue.poll();
if (e == null) {
break;
}
try {
if (e instanceof CloseEvent) {
notifySubscriberOfCloseEvent(subscription, (CloseEvent) e);
continue;
}
if (e instanceof CompletableFuture) {
((CompletableFuture<?>) e).completeExceptionally(cause);
}
@SuppressWarnings("unchecked")
final T obj = (T) e;
onRemoval(obj);
} finally {
ReferenceCountUtil.safeRelease(e);
}
}
}
|
java
|
void cleanupQueue(SubscriptionImpl subscription, Queue<Object> queue) {
final Throwable cause = ClosedPublisherException.get();
for (;;) {
final Object e = queue.poll();
if (e == null) {
break;
}
try {
if (e instanceof CloseEvent) {
notifySubscriberOfCloseEvent(subscription, (CloseEvent) e);
continue;
}
if (e instanceof CompletableFuture) {
((CompletableFuture<?>) e).completeExceptionally(cause);
}
@SuppressWarnings("unchecked")
final T obj = (T) e;
onRemoval(obj);
} finally {
ReferenceCountUtil.safeRelease(e);
}
}
}
|
[
"void",
"cleanupQueue",
"(",
"SubscriptionImpl",
"subscription",
",",
"Queue",
"<",
"Object",
">",
"queue",
")",
"{",
"final",
"Throwable",
"cause",
"=",
"ClosedPublisherException",
".",
"get",
"(",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"final",
"Object",
"e",
"=",
"queue",
".",
"poll",
"(",
")",
";",
"if",
"(",
"e",
"==",
"null",
")",
"{",
"break",
";",
"}",
"try",
"{",
"if",
"(",
"e",
"instanceof",
"CloseEvent",
")",
"{",
"notifySubscriberOfCloseEvent",
"(",
"subscription",
",",
"(",
"CloseEvent",
")",
"e",
")",
";",
"continue",
";",
"}",
"if",
"(",
"e",
"instanceof",
"CompletableFuture",
")",
"{",
"(",
"(",
"CompletableFuture",
"<",
"?",
">",
")",
"e",
")",
".",
"completeExceptionally",
"(",
"cause",
")",
";",
"}",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"final",
"T",
"obj",
"=",
"(",
"T",
")",
"e",
";",
"onRemoval",
"(",
"obj",
")",
";",
"}",
"finally",
"{",
"ReferenceCountUtil",
".",
"safeRelease",
"(",
"e",
")",
";",
"}",
"}",
"}"
] |
Helper method for the common case of cleaning up all elements in a queue when shutting down the stream.
|
[
"Helper",
"method",
"for",
"the",
"common",
"case",
"of",
"cleaning",
"up",
"all",
"elements",
"in",
"a",
"queue",
"when",
"shutting",
"down",
"the",
"stream",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/common/stream/AbstractStreamMessage.java#L190-L215
|
16,990
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/encoding/ZlibStreamDecoder.java
|
ZlibStreamDecoder.fetchDecoderOutput
|
private byte[] fetchDecoderOutput() {
final CompositeByteBuf decoded = Unpooled.compositeBuffer();
for (;;) {
final ByteBuf buf = decoder.readInbound();
if (buf == null) {
break;
}
if (!buf.isReadable()) {
buf.release();
continue;
}
decoded.addComponent(true, buf);
}
final byte[] ret = ByteBufUtil.getBytes(decoded);
decoded.release();
return ret;
}
|
java
|
private byte[] fetchDecoderOutput() {
final CompositeByteBuf decoded = Unpooled.compositeBuffer();
for (;;) {
final ByteBuf buf = decoder.readInbound();
if (buf == null) {
break;
}
if (!buf.isReadable()) {
buf.release();
continue;
}
decoded.addComponent(true, buf);
}
final byte[] ret = ByteBufUtil.getBytes(decoded);
decoded.release();
return ret;
}
|
[
"private",
"byte",
"[",
"]",
"fetchDecoderOutput",
"(",
")",
"{",
"final",
"CompositeByteBuf",
"decoded",
"=",
"Unpooled",
".",
"compositeBuffer",
"(",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"final",
"ByteBuf",
"buf",
"=",
"decoder",
".",
"readInbound",
"(",
")",
";",
"if",
"(",
"buf",
"==",
"null",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"buf",
".",
"isReadable",
"(",
")",
")",
"{",
"buf",
".",
"release",
"(",
")",
";",
"continue",
";",
"}",
"decoded",
".",
"addComponent",
"(",
"true",
",",
"buf",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"ret",
"=",
"ByteBufUtil",
".",
"getBytes",
"(",
"decoded",
")",
";",
"decoded",
".",
"release",
"(",
")",
";",
"return",
"ret",
";",
"}"
] |
Mostly copied from netty's HttpContentDecoder.
|
[
"Mostly",
"copied",
"from",
"netty",
"s",
"HttpContentDecoder",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/encoding/ZlibStreamDecoder.java#L63-L79
|
16,991
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/endpoint/healthcheck/HttpHealthCheckedEndpointGroupBuilder.java
|
HttpHealthCheckedEndpointGroupBuilder.retryInterval
|
public HttpHealthCheckedEndpointGroupBuilder retryInterval(Duration retryInterval) {
requireNonNull(retryInterval, "retryInterval");
checkArgument(!retryInterval.isNegative() && !retryInterval.isZero(),
"retryInterval: %s (expected > 0)", retryInterval);
this.retryInterval = retryInterval;
return this;
}
|
java
|
public HttpHealthCheckedEndpointGroupBuilder retryInterval(Duration retryInterval) {
requireNonNull(retryInterval, "retryInterval");
checkArgument(!retryInterval.isNegative() && !retryInterval.isZero(),
"retryInterval: %s (expected > 0)", retryInterval);
this.retryInterval = retryInterval;
return this;
}
|
[
"public",
"HttpHealthCheckedEndpointGroupBuilder",
"retryInterval",
"(",
"Duration",
"retryInterval",
")",
"{",
"requireNonNull",
"(",
"retryInterval",
",",
"\"retryInterval\"",
")",
";",
"checkArgument",
"(",
"!",
"retryInterval",
".",
"isNegative",
"(",
")",
"&&",
"!",
"retryInterval",
".",
"isZero",
"(",
")",
",",
"\"retryInterval: %s (expected > 0)\"",
",",
"retryInterval",
")",
";",
"this",
".",
"retryInterval",
"=",
"retryInterval",
";",
"return",
"this",
";",
"}"
] |
Sets the interval between health check requests. Must be positive.
|
[
"Sets",
"the",
"interval",
"between",
"health",
"check",
"requests",
".",
"Must",
"be",
"positive",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/endpoint/healthcheck/HttpHealthCheckedEndpointGroupBuilder.java#L80-L86
|
16,992
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/common/stream/DeferredStreamMessage.java
|
DeferredStreamMessage.close
|
public void close(Throwable cause) {
requireNonNull(cause, "cause");
final DefaultStreamMessage<T> m = new DefaultStreamMessage<>();
m.close(cause);
delegate(m);
}
|
java
|
public void close(Throwable cause) {
requireNonNull(cause, "cause");
final DefaultStreamMessage<T> m = new DefaultStreamMessage<>();
m.close(cause);
delegate(m);
}
|
[
"public",
"void",
"close",
"(",
"Throwable",
"cause",
")",
"{",
"requireNonNull",
"(",
"cause",
",",
"\"cause\"",
")",
";",
"final",
"DefaultStreamMessage",
"<",
"T",
">",
"m",
"=",
"new",
"DefaultStreamMessage",
"<>",
"(",
")",
";",
"m",
".",
"close",
"(",
"cause",
")",
";",
"delegate",
"(",
"m",
")",
";",
"}"
] |
Closes the deferred stream without setting a delegate.
@throws IllegalStateException if the delegate has been set already or
if {@link #close()} or {@link #close(Throwable)} was called already.
|
[
"Closes",
"the",
"deferred",
"stream",
"without",
"setting",
"a",
"delegate",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/common/stream/DeferredStreamMessage.java#L136-L141
|
16,993
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/retry/RetryingClient.java
|
RetryingClient.scheduleNextRetry
|
protected static void scheduleNextRetry(ClientRequestContext ctx,
Consumer<? super Throwable> actionOnException,
Runnable retryTask, long nextDelayMillis) {
try {
if (nextDelayMillis == 0) {
ctx.contextAwareEventLoop().execute(retryTask);
} else {
@SuppressWarnings("unchecked")
final ScheduledFuture<Void> scheduledFuture = (ScheduledFuture<Void>) ctx
.contextAwareEventLoop().schedule(retryTask, nextDelayMillis, TimeUnit.MILLISECONDS);
scheduledFuture.addListener(future -> {
if (future.isCancelled()) {
// future is cancelled when the client factory is closed.
actionOnException.accept(new IllegalStateException(
ClientFactory.class.getSimpleName() + " has been closed."));
}
});
}
} catch (Throwable t) {
actionOnException.accept(t);
}
}
|
java
|
protected static void scheduleNextRetry(ClientRequestContext ctx,
Consumer<? super Throwable> actionOnException,
Runnable retryTask, long nextDelayMillis) {
try {
if (nextDelayMillis == 0) {
ctx.contextAwareEventLoop().execute(retryTask);
} else {
@SuppressWarnings("unchecked")
final ScheduledFuture<Void> scheduledFuture = (ScheduledFuture<Void>) ctx
.contextAwareEventLoop().schedule(retryTask, nextDelayMillis, TimeUnit.MILLISECONDS);
scheduledFuture.addListener(future -> {
if (future.isCancelled()) {
// future is cancelled when the client factory is closed.
actionOnException.accept(new IllegalStateException(
ClientFactory.class.getSimpleName() + " has been closed."));
}
});
}
} catch (Throwable t) {
actionOnException.accept(t);
}
}
|
[
"protected",
"static",
"void",
"scheduleNextRetry",
"(",
"ClientRequestContext",
"ctx",
",",
"Consumer",
"<",
"?",
"super",
"Throwable",
">",
"actionOnException",
",",
"Runnable",
"retryTask",
",",
"long",
"nextDelayMillis",
")",
"{",
"try",
"{",
"if",
"(",
"nextDelayMillis",
"==",
"0",
")",
"{",
"ctx",
".",
"contextAwareEventLoop",
"(",
")",
".",
"execute",
"(",
"retryTask",
")",
";",
"}",
"else",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"final",
"ScheduledFuture",
"<",
"Void",
">",
"scheduledFuture",
"=",
"(",
"ScheduledFuture",
"<",
"Void",
">",
")",
"ctx",
".",
"contextAwareEventLoop",
"(",
")",
".",
"schedule",
"(",
"retryTask",
",",
"nextDelayMillis",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"scheduledFuture",
".",
"addListener",
"(",
"future",
"->",
"{",
"if",
"(",
"future",
".",
"isCancelled",
"(",
")",
")",
"{",
"// future is cancelled when the client factory is closed.",
"actionOnException",
".",
"accept",
"(",
"new",
"IllegalStateException",
"(",
"ClientFactory",
".",
"class",
".",
"getSimpleName",
"(",
")",
"+",
"\" has been closed.\"",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"actionOnException",
".",
"accept",
"(",
"t",
")",
";",
"}",
"}"
] |
Schedules next retry.
|
[
"Schedules",
"next",
"retry",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/retry/RetryingClient.java#L152-L173
|
16,994
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/docs/DocServiceBuilder.java
|
DocServiceBuilder.guessAndSerializeExampleRequest
|
private static String[] guessAndSerializeExampleRequest(Object exampleRequest) {
checkArgument(!(exampleRequest instanceof CharSequence),
"can't guess service or method name from a string: ", exampleRequest);
boolean guessed = false;
for (DocServicePlugin plugin : DocService.plugins) {
// Skip if the plugin does not support it.
if (plugin.supportedExampleRequestTypes().stream()
.noneMatch(type -> type.isInstance(exampleRequest))) {
continue;
}
final Optional<String> serviceName = plugin.guessServiceName(exampleRequest);
final Optional<String> methodName = plugin.guessServiceMethodName(exampleRequest);
// Skip if the plugin cannot guess the service and method name.
if (!serviceName.isPresent() || !methodName.isPresent()) {
continue;
}
guessed = true;
final String s = serviceName.get();
final String f = methodName.get();
final Optional<String> serialized = plugin.serializeExampleRequest(s, f, exampleRequest);
if (serialized.isPresent()) {
return new String[] { s, f, serialized.get() };
}
}
if (guessed) {
throw new IllegalArgumentException(
"could not find a plugin that can serialize: " + exampleRequest);
} else {
throw new IllegalArgumentException(
"could not find a plugin that can guess the service and method name from: " +
exampleRequest);
}
}
|
java
|
private static String[] guessAndSerializeExampleRequest(Object exampleRequest) {
checkArgument(!(exampleRequest instanceof CharSequence),
"can't guess service or method name from a string: ", exampleRequest);
boolean guessed = false;
for (DocServicePlugin plugin : DocService.plugins) {
// Skip if the plugin does not support it.
if (plugin.supportedExampleRequestTypes().stream()
.noneMatch(type -> type.isInstance(exampleRequest))) {
continue;
}
final Optional<String> serviceName = plugin.guessServiceName(exampleRequest);
final Optional<String> methodName = plugin.guessServiceMethodName(exampleRequest);
// Skip if the plugin cannot guess the service and method name.
if (!serviceName.isPresent() || !methodName.isPresent()) {
continue;
}
guessed = true;
final String s = serviceName.get();
final String f = methodName.get();
final Optional<String> serialized = plugin.serializeExampleRequest(s, f, exampleRequest);
if (serialized.isPresent()) {
return new String[] { s, f, serialized.get() };
}
}
if (guessed) {
throw new IllegalArgumentException(
"could not find a plugin that can serialize: " + exampleRequest);
} else {
throw new IllegalArgumentException(
"could not find a plugin that can guess the service and method name from: " +
exampleRequest);
}
}
|
[
"private",
"static",
"String",
"[",
"]",
"guessAndSerializeExampleRequest",
"(",
"Object",
"exampleRequest",
")",
"{",
"checkArgument",
"(",
"!",
"(",
"exampleRequest",
"instanceof",
"CharSequence",
")",
",",
"\"can't guess service or method name from a string: \"",
",",
"exampleRequest",
")",
";",
"boolean",
"guessed",
"=",
"false",
";",
"for",
"(",
"DocServicePlugin",
"plugin",
":",
"DocService",
".",
"plugins",
")",
"{",
"// Skip if the plugin does not support it.",
"if",
"(",
"plugin",
".",
"supportedExampleRequestTypes",
"(",
")",
".",
"stream",
"(",
")",
".",
"noneMatch",
"(",
"type",
"->",
"type",
".",
"isInstance",
"(",
"exampleRequest",
")",
")",
")",
"{",
"continue",
";",
"}",
"final",
"Optional",
"<",
"String",
">",
"serviceName",
"=",
"plugin",
".",
"guessServiceName",
"(",
"exampleRequest",
")",
";",
"final",
"Optional",
"<",
"String",
">",
"methodName",
"=",
"plugin",
".",
"guessServiceMethodName",
"(",
"exampleRequest",
")",
";",
"// Skip if the plugin cannot guess the service and method name.",
"if",
"(",
"!",
"serviceName",
".",
"isPresent",
"(",
")",
"||",
"!",
"methodName",
".",
"isPresent",
"(",
")",
")",
"{",
"continue",
";",
"}",
"guessed",
"=",
"true",
";",
"final",
"String",
"s",
"=",
"serviceName",
".",
"get",
"(",
")",
";",
"final",
"String",
"f",
"=",
"methodName",
".",
"get",
"(",
")",
";",
"final",
"Optional",
"<",
"String",
">",
"serialized",
"=",
"plugin",
".",
"serializeExampleRequest",
"(",
"s",
",",
"f",
",",
"exampleRequest",
")",
";",
"if",
"(",
"serialized",
".",
"isPresent",
"(",
")",
")",
"{",
"return",
"new",
"String",
"[",
"]",
"{",
"s",
",",
"f",
",",
"serialized",
".",
"get",
"(",
")",
"}",
";",
"}",
"}",
"if",
"(",
"guessed",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"could not find a plugin that can serialize: \"",
"+",
"exampleRequest",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"could not find a plugin that can guess the service and method name from: \"",
"+",
"exampleRequest",
")",
";",
"}",
"}"
] |
Returns a tuple of a service name, a method name and a serialized example request.
|
[
"Returns",
"a",
"tuple",
"of",
"a",
"service",
"name",
"a",
"method",
"name",
"and",
"a",
"serialized",
"example",
"request",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/docs/DocServiceBuilder.java#L408-L445
|
16,995
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/file/DefaultEntityTagFunction.java
|
DefaultEntityTagFunction.appendLong
|
private static int appendLong(byte[] data, int offset, long value) {
offset = appendByte(data, offset, value >>> 56);
offset = appendByte(data, offset, value >>> 48);
offset = appendByte(data, offset, value >>> 40);
offset = appendByte(data, offset, value >>> 32);
offset = appendInt(data, offset, value);
return offset;
}
|
java
|
private static int appendLong(byte[] data, int offset, long value) {
offset = appendByte(data, offset, value >>> 56);
offset = appendByte(data, offset, value >>> 48);
offset = appendByte(data, offset, value >>> 40);
offset = appendByte(data, offset, value >>> 32);
offset = appendInt(data, offset, value);
return offset;
}
|
[
"private",
"static",
"int",
"appendLong",
"(",
"byte",
"[",
"]",
"data",
",",
"int",
"offset",
",",
"long",
"value",
")",
"{",
"offset",
"=",
"appendByte",
"(",
"data",
",",
"offset",
",",
"value",
">>>",
"56",
")",
";",
"offset",
"=",
"appendByte",
"(",
"data",
",",
"offset",
",",
"value",
">>>",
"48",
")",
";",
"offset",
"=",
"appendByte",
"(",
"data",
",",
"offset",
",",
"value",
">>>",
"40",
")",
";",
"offset",
"=",
"appendByte",
"(",
"data",
",",
"offset",
",",
"value",
">>>",
"32",
")",
";",
"offset",
"=",
"appendInt",
"(",
"data",
",",
"offset",
",",
"value",
")",
";",
"return",
"offset",
";",
"}"
] |
Appends a 64-bit integer without its leading zero bytes.
|
[
"Appends",
"a",
"64",
"-",
"bit",
"integer",
"without",
"its",
"leading",
"zero",
"bytes",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/file/DefaultEntityTagFunction.java#L57-L64
|
16,996
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/server/file/DefaultEntityTagFunction.java
|
DefaultEntityTagFunction.appendByte
|
private static int appendByte(byte[] dst, int offset, long value) {
if (value == 0) {
return offset;
}
dst[offset] = (byte) value;
return offset + 1;
}
|
java
|
private static int appendByte(byte[] dst, int offset, long value) {
if (value == 0) {
return offset;
}
dst[offset] = (byte) value;
return offset + 1;
}
|
[
"private",
"static",
"int",
"appendByte",
"(",
"byte",
"[",
"]",
"dst",
",",
"int",
"offset",
",",
"long",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"0",
")",
"{",
"return",
"offset",
";",
"}",
"dst",
"[",
"offset",
"]",
"=",
"(",
"byte",
")",
"value",
";",
"return",
"offset",
"+",
"1",
";",
"}"
] |
Appends a byte if it's not a leading zero.
|
[
"Appends",
"a",
"byte",
"if",
"it",
"s",
"not",
"a",
"leading",
"zero",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/server/file/DefaultEntityTagFunction.java#L80-L86
|
16,997
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
|
ClientFactoryBuilder.connectTimeoutMillis
|
public ClientFactoryBuilder connectTimeoutMillis(long connectTimeoutMillis) {
checkArgument(connectTimeoutMillis > 0,
"connectTimeoutMillis: %s (expected: > 0)", connectTimeoutMillis);
return channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS,
ConvertUtils.safeLongToInt(connectTimeoutMillis));
}
|
java
|
public ClientFactoryBuilder connectTimeoutMillis(long connectTimeoutMillis) {
checkArgument(connectTimeoutMillis > 0,
"connectTimeoutMillis: %s (expected: > 0)", connectTimeoutMillis);
return channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS,
ConvertUtils.safeLongToInt(connectTimeoutMillis));
}
|
[
"public",
"ClientFactoryBuilder",
"connectTimeoutMillis",
"(",
"long",
"connectTimeoutMillis",
")",
"{",
"checkArgument",
"(",
"connectTimeoutMillis",
">",
"0",
",",
"\"connectTimeoutMillis: %s (expected: > 0)\"",
",",
"connectTimeoutMillis",
")",
";",
"return",
"channelOption",
"(",
"ChannelOption",
".",
"CONNECT_TIMEOUT_MILLIS",
",",
"ConvertUtils",
".",
"safeLongToInt",
"(",
"connectTimeoutMillis",
")",
")",
";",
"}"
] |
Sets the timeout of a socket connection attempt in milliseconds.
|
[
"Sets",
"the",
"timeout",
"of",
"a",
"socket",
"connection",
"attempt",
"in",
"milliseconds",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java#L149-L154
|
16,998
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
|
ClientFactoryBuilder.idleTimeout
|
public ClientFactoryBuilder idleTimeout(Duration idleTimeout) {
requireNonNull(idleTimeout, "idleTimeout");
checkArgument(!idleTimeout.isNegative(), "idleTimeout: %s (expected: >= 0)", idleTimeout);
return idleTimeoutMillis(idleTimeout.toMillis());
}
|
java
|
public ClientFactoryBuilder idleTimeout(Duration idleTimeout) {
requireNonNull(idleTimeout, "idleTimeout");
checkArgument(!idleTimeout.isNegative(), "idleTimeout: %s (expected: >= 0)", idleTimeout);
return idleTimeoutMillis(idleTimeout.toMillis());
}
|
[
"public",
"ClientFactoryBuilder",
"idleTimeout",
"(",
"Duration",
"idleTimeout",
")",
"{",
"requireNonNull",
"(",
"idleTimeout",
",",
"\"idleTimeout\"",
")",
";",
"checkArgument",
"(",
"!",
"idleTimeout",
".",
"isNegative",
"(",
")",
",",
"\"idleTimeout: %s (expected: >= 0)\"",
",",
"idleTimeout",
")",
";",
"return",
"idleTimeoutMillis",
"(",
"idleTimeout",
".",
"toMillis",
"(",
")",
")",
";",
"}"
] |
Sets the idle timeout of a socket connection. The connection is closed if there is no request in
progress for this amount of time.
|
[
"Sets",
"the",
"idle",
"timeout",
"of",
"a",
"socket",
"connection",
".",
"The",
"connection",
"is",
"closed",
"if",
"there",
"is",
"no",
"request",
"in",
"progress",
"for",
"this",
"amount",
"of",
"time",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java#L321-L325
|
16,999
|
line/armeria
|
core/src/main/java/com/linecorp/armeria/client/circuitbreaker/SlidingWindowCounter.java
|
SlidingWindowCounter.trimAndSum
|
private EventCount trimAndSum(long tickerNanos) {
final long oldLimit = tickerNanos - slidingWindowNanos;
final Iterator<Bucket> iterator = reservoir.iterator();
long success = 0;
long failure = 0;
while (iterator.hasNext()) {
final Bucket bucket = iterator.next();
if (bucket.timestamp < oldLimit) {
// removes old bucket
iterator.remove();
} else {
success += bucket.success();
failure += bucket.failure();
}
}
return new EventCount(success, failure);
}
|
java
|
private EventCount trimAndSum(long tickerNanos) {
final long oldLimit = tickerNanos - slidingWindowNanos;
final Iterator<Bucket> iterator = reservoir.iterator();
long success = 0;
long failure = 0;
while (iterator.hasNext()) {
final Bucket bucket = iterator.next();
if (bucket.timestamp < oldLimit) {
// removes old bucket
iterator.remove();
} else {
success += bucket.success();
failure += bucket.failure();
}
}
return new EventCount(success, failure);
}
|
[
"private",
"EventCount",
"trimAndSum",
"(",
"long",
"tickerNanos",
")",
"{",
"final",
"long",
"oldLimit",
"=",
"tickerNanos",
"-",
"slidingWindowNanos",
";",
"final",
"Iterator",
"<",
"Bucket",
">",
"iterator",
"=",
"reservoir",
".",
"iterator",
"(",
")",
";",
"long",
"success",
"=",
"0",
";",
"long",
"failure",
"=",
"0",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"final",
"Bucket",
"bucket",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"bucket",
".",
"timestamp",
"<",
"oldLimit",
")",
"{",
"// removes old bucket",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"else",
"{",
"success",
"+=",
"bucket",
".",
"success",
"(",
")",
";",
"failure",
"+=",
"bucket",
".",
"failure",
"(",
")",
";",
"}",
"}",
"return",
"new",
"EventCount",
"(",
"success",
",",
"failure",
")",
";",
"}"
] |
Sums up buckets within the time window, and removes all the others.
|
[
"Sums",
"up",
"buckets",
"within",
"the",
"time",
"window",
"and",
"removes",
"all",
"the",
"others",
"."
] |
67d29e019fd35a35f89c45cc8f9119ff9b12b44d
|
https://github.com/line/armeria/blob/67d29e019fd35a35f89c45cc8f9119ff9b12b44d/core/src/main/java/com/linecorp/armeria/client/circuitbreaker/SlidingWindowCounter.java#L123-L140
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.