public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream() .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass) .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass) .collect(toImmutableList()); checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString())); return getOnlyElement(combineFunctions); }
private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass) { // Only include methods that match this state class List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream() .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass)) .collect(toImmutableList()); if (stateSerializerFactories.isEmpty()) { return Optional.empty(); } checkArgument(stateSerializerFactories.size() == 1, String.format( "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s", stateClass.toGenericString(), stateSerializerFactories.size(), aggregationDefinition.toGenericString())); return Optional.of(getOnlyElement(stateSerializerFactories)); }
import java.util.ArrayList; class MyClass { ArrayList<String> stringList; public ArrayList<String> getStringList() { return stringList; } } public class Foo { public static void main(String... args) throws NoSuchMethodException { ArrayList<Integer> intList = new ArrayList<>(); System.out.println(intList.getClass().toGenericString()); System.out.println(MyClass.class.getMethod("getStringList").toGenericString()); } }
public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream() .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass) .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass) .collect(toImmutableList()); checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString())); return getOnlyElement(combineFunctions); }
@Override public String toString() { return MoreObjects .toStringHelper(this) .add("mFactoryClass", mFactoryClass) .add("mFactoryInstance", mFactoryInstance) .add("mFactoryMethodName", mFactoryMethodName) .add("mFactoryParamValues", mFactoryParamValues != null ? Joiner.on(",").join(mFactoryParamValues) : null) .add("mFactoryParamType", mFactoryParamType != null ? Joiner.on(",").join(mFactoryParamType) : null) .add("mParamType", mParamType != null ? Joiner.on(",").join(mParamType) : null) .add("mComponentPath", mComponentPath) .add("mFactoryEnable", mFactoryEnable) .add("mMethod", mMethod != null ? mMethod.getName() : null) .add("mMethodParam", mMethodParam != null ? Joiner.on(",").join(mMethodParam) : null) .add("mMethodClass", mMethodClass != null ? mMethodClass.getCanonicalName() : null) .add("mMethodClassInstance", mMethodClassInstance != null ? mMethodClassInstance.getClass().toGenericString() : null) .toString(); }
public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream() .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass) .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass) .collect(toImmutableList()); checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString())); return getOnlyElement(combineFunctions); }
private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass) { // Only include methods that match this state class List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream() .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass)) .collect(toImmutableList()); if (stateSerializerFactories.isEmpty()) { return Optional.empty(); } checkArgument(stateSerializerFactories.size() == 1, String.format( "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s", stateClass.toGenericString(), stateSerializerFactories.size(), aggregationDefinition.toGenericString())); return Optional.of(getOnlyElement(stateSerializerFactories)); }
public static void registerOverride(NamespacedKey origin, NamespacedKey override) { if (overrides.containsKey(origin)) { throw new IllegalArgumentException("Cannot override a already overridden power: " + origin + " " + override); } Class<? extends Power> originPower = getPower(origin); Class<? extends Power> overridePower = getPower(override); if (originPower == null) { throw new IllegalArgumentException("Overriding not registered power: " + origin); } if (overridePower == null) { throw new IllegalArgumentException("Override not found: " + override); } if (!originPower.isAssignableFrom(overridePower)) { throw new IllegalArgumentException("Not overrideable: " + origin + "@" + originPower.toGenericString() + " " + override + "@" + overridePower.toGenericString()); } overrides.put(origin, override); } }
public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn, final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet); final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName()); final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)}); if (method != null) { final Object o = dataType.cast(objectToInvokeJavaMethodOn); method.invoke(o, expressionResultType.cast(valueToSetObjectWith)); return o; } else { throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ")."); } } }
private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass) { // Only include methods that match this state class List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream() .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass)) .collect(toImmutableList()); if (stateSerializerFactories.isEmpty()) { return Optional.empty(); } checkArgument(stateSerializerFactories.size() == 1, String.format( "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s", stateClass.toGenericString(), stateSerializerFactories.size(), aggregationDefinition.toGenericString())); return Optional.of(getOnlyElement(stateSerializerFactories)); }
/** * The default strategy to search for keys is to *just* search for the email address (the part * between < and >). * * Set this flag to search for any part in the user id. * * @param strategy instance to use * * @return next build step */ public WithAlgorithmSuite withKeySelectionStrategy(final KeySelectionStrategy strategy) { requireNonNull(strategy, "strategy must not be null"); Preconditions.checkState( selectUidByEMailOnly == null && dateOfTimestampVerification == null, "selectUidByAnyUidPart/setReferenceDateForKeyValidityTo cannot be used together" + " with 'withKeySelectionStrategy' "); this.keySelectionStrategy = strategy; LOGGER.trace("WithKeySelectionStrategy: override strategy to {}", strategy.getClass().toGenericString()); return this; }
public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn, final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet); final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName()); final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)}); if (method != null) { final Object o = dataType.cast(objectToInvokeJavaMethodOn); method.invoke(o, expressionResultType.cast(valueToSetObjectWith)); return o; } else { throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ")."); } } }
/** * Gets the value. * * @param object the object * @param method the method * @param cls the cls * * @param <T> the generic type * * @return the value */ @SuppressWarnings("unchecked") private <T> Optional<T> getValue(Object object, Supplier<Object> method, Class<T> cls) { T source = null; if (cls.isInstance(method.get())) { source = (T) method.get(); } else { if (CoreParameters.DEVELOPER_MODE.get()) { throw new CoreRuntimeException("Cannot cast object " + method.get() + " to " + cls.toGenericString()); } } return Optional.ofNullable(source); }
@Override public String getMessage() { String typeNames = typesString(); String primary = primaryType == null ? "" : " primary: " + primaryType.toGenericString() + NL; String methodName = memberString(); String message = super.getMessage() == null ? "" : " message: " + super.getMessage() + NL; String fragment = fragmentClass == null ? "" : " fragmentClass: " + fragmentClass.getName() + NL; String valueType = this.valueType == null ? "" : " valueType: " + this.valueType.getTypeName() + NL; String module = this.module == null ? "" : " layer: " + this.module.layer().name() + NL + " module: " + this.module.name() + NL; return message + module + primary + fragment + methodName + valueType + typeNames; }
@Override public String getMessage() { String typeNames = typesString(); String primary = primaryType == null ? "" : " primary: " + primaryType.toGenericString() + NL; String methodName = memberString(); String message = super.getMessage() == null ? "" : " message: " + super.getMessage() + NL; String fragment = fragmentClass == null ? "" : " fragmentClass: " + fragmentClass.getName() + NL; String valueType = this.valueType == null ? "" : " valueType: " + this.valueType.getTypeName() + NL; String module = this.module == null ? "" : " layer: " + this.module.layer().name() + NL + " module: " + this.module.name() + NL; return message + module + primary + fragment + methodName + valueType + typeNames; }
/** * Check the exception that was caught. In case the exception was expected the type and message is shown in the cucumber logs. * Otherwise the exception is rethrown failing the test and dumping the stack trace to help resolving problems. */ public void verifyException(Exception ex) throws Exception { boolean exceptionExpected = stepData.contains("ExceptionExpected") ? (boolean)stepData.get("ExceptionExpected") : false; String exceptionName = stepData.contains("ExceptionName") ? (String)stepData.get("ExceptionName") : ""; String exceptionMessage = stepData.contains("ExceptionMessage") ? (String)stepData.get("ExceptionMessage") : ""; if (!exceptionExpected || (!exceptionName.isEmpty() && !ex.getClass().toGenericString().contains(exceptionName)) || (!exceptionMessage.isEmpty() && !exceptionMessage.trim().contentEquals("*") && !ex.getMessage().contains(exceptionMessage))) { scenario.write("An unexpected exception was raised!"); throw(ex); } scenario.write("Exception raised as expected: " + ex.getClass().getCanonicalName() + ", " + ex.getMessage()); stepData.put("ExceptionCaught", true); stepData.put("Exception", ex); } }
@Override public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) { long addrVal = this.upstream.eval(ctx, heap, params, pRecord); Object val = FishObject.get(heap, addrVal); if (val == null) { } else if (val instanceof Float) { } else if (val instanceof Long) { val = ((Long)val).floatValue(); } else if (val instanceof String) { val = Float.valueOf((String)val); } else if (val instanceof BigDecimal) { val = ((BigDecimal)val).floatValue(); } else if (val instanceof Double) { val = ((Double)val).floatValue(); } else { throw new CodingError(val.getClass().toGenericString()); } return FishObject.allocSet(heap, val); }
+ method.toGenericString() + NL + "Declaring Class:" + method.getDeclaringClass().toGenericString() + NL + "Types:" + mixinsModel.mixinTypes()
throw new CodingError(val.getClass().toGenericString());