use of org.apache.tapestry5.func.F in project tapestry-5 by apache.
the class TranslatorSourceImplTest method bigdecimal_with_localized_symbols.
@Test
public void bigdecimal_with_localized_symbols() throws ParseException {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ENGLISH);
symbols.setGroupingSeparator('_');
symbols.setMinusSign('*');
symbols.setDecimalSeparator('#');
BigDecimalNumericFormatter f = new BigDecimalNumericFormatter(symbols);
BigDecimal big = new BigDecimal("-123456.797956563434");
assertEquals(f.parse("*123_456#797956563434"), big);
assertEquals(f.toClient(big), "*123456#797956563434");
}
use of org.apache.tapestry5.func.F in project tapestry-5 by apache.
the class BasicVerifier method binaryOperation.
@Override
public BasicValue binaryOperation(final AbstractInsnNode insn, final BasicValue value1, final BasicValue value2) throws AnalyzerException {
BasicValue expected1;
BasicValue expected2;
switch(insn.getOpcode()) {
case IALOAD:
expected1 = newValue(Type.getType("[I"));
expected2 = BasicValue.INT_VALUE;
break;
case BALOAD:
if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
expected1 = newValue(Type.getType("[Z"));
} else {
expected1 = newValue(Type.getType("[B"));
}
expected2 = BasicValue.INT_VALUE;
break;
case CALOAD:
expected1 = newValue(Type.getType("[C"));
expected2 = BasicValue.INT_VALUE;
break;
case SALOAD:
expected1 = newValue(Type.getType("[S"));
expected2 = BasicValue.INT_VALUE;
break;
case LALOAD:
expected1 = newValue(Type.getType("[J"));
expected2 = BasicValue.INT_VALUE;
break;
case FALOAD:
expected1 = newValue(Type.getType("[F"));
expected2 = BasicValue.INT_VALUE;
break;
case DALOAD:
expected1 = newValue(Type.getType("[D"));
expected2 = BasicValue.INT_VALUE;
break;
case AALOAD:
expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
expected2 = BasicValue.INT_VALUE;
break;
case IADD:
case ISUB:
case IMUL:
case IDIV:
case IREM:
case ISHL:
case ISHR:
case IUSHR:
case IAND:
case IOR:
case IXOR:
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
expected1 = BasicValue.INT_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case FADD:
case FSUB:
case FMUL:
case FDIV:
case FREM:
case FCMPL:
case FCMPG:
expected1 = BasicValue.FLOAT_VALUE;
expected2 = BasicValue.FLOAT_VALUE;
break;
case LADD:
case LSUB:
case LMUL:
case LDIV:
case LREM:
case LAND:
case LOR:
case LXOR:
case LCMP:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.LONG_VALUE;
break;
case LSHL:
case LSHR:
case LUSHR:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case DADD:
case DSUB:
case DMUL:
case DDIV:
case DREM:
case DCMPL:
case DCMPG:
expected1 = BasicValue.DOUBLE_VALUE;
expected2 = BasicValue.DOUBLE_VALUE;
break;
case IF_ACMPEQ:
case IF_ACMPNE:
expected1 = BasicValue.REFERENCE_VALUE;
expected2 = BasicValue.REFERENCE_VALUE;
break;
case PUTFIELD:
FieldInsnNode fieldInsn = (FieldInsnNode) insn;
expected1 = newValue(Type.getObjectType(fieldInsn.owner));
expected2 = newValue(Type.getType(fieldInsn.desc));
break;
default:
throw new AssertionError();
}
if (!isSubTypeOf(value1, expected1)) {
throw new AnalyzerException(insn, "First argument", expected1, value1);
} else if (!isSubTypeOf(value2, expected2)) {
throw new AnalyzerException(insn, "Second argument", expected2, value2);
}
if (insn.getOpcode() == AALOAD) {
return getElementValue(value1);
} else {
return super.binaryOperation(insn, value1, value2);
}
}
use of org.apache.tapestry5.func.F in project tapestry-5 by apache.
the class ContextResourceSymbolProviderTest method access.
@Test
public void access() throws Exception {
File f = File.createTempFile("foo", ".properties");
setupFile(f);
Context context = mockContext();
expect(context.getRealFile("/bar/" + f.getName())).andReturn(f);
replay();
ContextResourceSymbolProvider provider = new ContextResourceSymbolProvider(context, "bar/" + f.getName());
/* test general access */
assertEquals(provider.valueForSymbol("homer"), "simpson");
assertEquals(provider.valueForSymbol("monty"), "burns");
/* check for case-insensitivity */
assertEquals(provider.valueForSymbol("HOMER"), "simpson");
/* non-existent keys should return null */
assertNull(provider.valueForSymbol("marge"));
verify();
f.delete();
}
use of org.apache.tapestry5.func.F in project tapestry-5 by apache.
the class TapestryAppInitializer method announceStartup.
/**
* Announce application startup, by logging (at INFO level) the names of all pages,
* components, mixins and services.
*/
public void announceStartup() {
if (// if info logging is off we can stop now
!logger.isInfoEnabled()) {
return;
}
long toFinish = System.currentTimeMillis();
SymbolSource source = registry.getService("SymbolSource", SymbolSource.class);
StringBuilder buffer = new StringBuilder("Startup status:\n\nServices:\n\n");
Formatter f = new Formatter(buffer);
int unrealized = 0;
ServiceActivityScoreboard scoreboard = registry.getService(ServiceActivityScoreboard.class);
List<ServiceActivity> serviceActivity = scoreboard.getServiceActivity();
int longest = 0;
for (ServiceActivity activity : serviceActivity) {
Status status = activity.getStatus();
longest = Math.max(longest, activity.getServiceId().length());
if (status == Status.DEFINED || status == Status.VIRTUAL)
unrealized++;
}
String formatString = "%" + longest + "s: %s\n";
for (ServiceActivity activity : serviceActivity) {
f.format(formatString, activity.getServiceId(), activity.getStatus().name());
}
f.format("\n%4.2f%% unrealized services (%d/%d)\n", 100. * unrealized / serviceActivity.size(), unrealized, serviceActivity.size());
f.format("\nApplication '%s' (version %s) startup time: %,d ms to build IoC Registry, %,d ms overall.", appName, source.valueForSymbol(TapestryHttpSymbolConstants.APPLICATION_VERSION), registryCreatedTime - startTime, toFinish - startTime);
String version = source.valueForSymbol(TapestryHttpSymbolConstants.TAPESTRY_VERSION);
boolean productionMode = Boolean.parseBoolean(source.valueForSymbol(TapestryHttpSymbolConstants.PRODUCTION_MODE));
buffer.append("\n\n");
buffer.append(" ______ __ ____\n");
buffer.append("/_ __/__ ____ ___ ___ / /_______ __ / __/\n");
buffer.append(" / / / _ `/ _ \\/ -_|_-</ __/ __/ // / /__ \\ \n");
buffer.append("/_/ \\_,_/ .__/\\__/___/\\__/_/ \\_, / /____/\n");
f.format(" /_/ /___/ %s%s\n\n", version, productionMode ? "" : " (development mode)");
// log multi-line string with OS-specific line endings (TAP5-2294)
logger.info(buffer.toString().replaceAll("\\n", System.getProperty("line.separator")));
}
use of org.apache.tapestry5.func.F in project tapestry-5 by apache.
the class ASMifier method appendConstant.
/**
* Appends a string representation of the given constant to {@link #stringBuilder}.
*
* @param value a {@link String}, {@link Type}, {@link Handle}, {@link Byte}, {@link Short},
* {@link Character}, {@link Integer}, {@link Float}, {@link Long} or {@link Double} object,
* or an array of primitive values. May be {@literal null}.
*/
protected void appendConstant(final Object value) {
if (value == null) {
stringBuilder.append("null");
} else if (value instanceof String) {
appendString(stringBuilder, (String) value);
} else if (value instanceof Type) {
stringBuilder.append("Type.getType(\"");
stringBuilder.append(((Type) value).getDescriptor());
stringBuilder.append("\")");
} else if (value instanceof Handle) {
stringBuilder.append("new Handle(");
Handle handle = (Handle) value;
stringBuilder.append("Opcodes.").append(HANDLE_TAG[handle.getTag()]).append(", \"");
stringBuilder.append(handle.getOwner()).append(COMMA);
stringBuilder.append(handle.getName()).append(COMMA);
stringBuilder.append(handle.getDesc()).append("\", ");
stringBuilder.append(handle.isInterface()).append(")");
} else if (value instanceof ConstantDynamic) {
stringBuilder.append("new ConstantDynamic(\"");
ConstantDynamic constantDynamic = (ConstantDynamic) value;
stringBuilder.append(constantDynamic.getName()).append(COMMA);
stringBuilder.append(constantDynamic.getDescriptor()).append("\", ");
appendConstant(constantDynamic.getBootstrapMethod());
stringBuilder.append(NEW_OBJECT_ARRAY);
int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
appendConstant(constantDynamic.getBootstrapMethodArgument(i));
if (i != bootstrapMethodArgumentCount - 1) {
stringBuilder.append(", ");
}
}
stringBuilder.append("})");
} else if (value instanceof Byte) {
stringBuilder.append("new Byte((byte)").append(value).append(')');
} else if (value instanceof Boolean) {
stringBuilder.append(((Boolean) value).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE");
} else if (value instanceof Short) {
stringBuilder.append("new Short((short)").append(value).append(')');
} else if (value instanceof Character) {
stringBuilder.append("new Character((char)").append((int) ((Character) value).charValue()).append(')');
} else if (value instanceof Integer) {
stringBuilder.append("new Integer(").append(value).append(')');
} else if (value instanceof Float) {
stringBuilder.append("new Float(\"").append(value).append("\")");
} else if (value instanceof Long) {
stringBuilder.append("new Long(").append(value).append("L)");
} else if (value instanceof Double) {
stringBuilder.append("new Double(\"").append(value).append("\")");
} else if (value instanceof byte[]) {
byte[] byteArray = (byte[]) value;
stringBuilder.append("new byte[] {");
for (int i = 0; i < byteArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(byteArray[i]);
}
stringBuilder.append('}');
} else if (value instanceof boolean[]) {
boolean[] booleanArray = (boolean[]) value;
stringBuilder.append("new boolean[] {");
for (int i = 0; i < booleanArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(booleanArray[i]);
}
stringBuilder.append('}');
} else if (value instanceof short[]) {
short[] shortArray = (short[]) value;
stringBuilder.append("new short[] {");
for (int i = 0; i < shortArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append("(short)").append(shortArray[i]);
}
stringBuilder.append('}');
} else if (value instanceof char[]) {
char[] charArray = (char[]) value;
stringBuilder.append("new char[] {");
for (int i = 0; i < charArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append("(char)").append((int) charArray[i]);
}
stringBuilder.append('}');
} else if (value instanceof int[]) {
int[] intArray = (int[]) value;
stringBuilder.append("new int[] {");
for (int i = 0; i < intArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(intArray[i]);
}
stringBuilder.append('}');
} else if (value instanceof long[]) {
long[] longArray = (long[]) value;
stringBuilder.append("new long[] {");
for (int i = 0; i < longArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(longArray[i]).append('L');
}
stringBuilder.append('}');
} else if (value instanceof float[]) {
float[] floatArray = (float[]) value;
stringBuilder.append("new float[] {");
for (int i = 0; i < floatArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(floatArray[i]).append('f');
}
stringBuilder.append('}');
} else if (value instanceof double[]) {
double[] doubleArray = (double[]) value;
stringBuilder.append("new double[] {");
for (int i = 0; i < doubleArray.length; i++) {
stringBuilder.append(i == 0 ? "" : ",").append(doubleArray[i]).append('d');
}
stringBuilder.append('}');
}
}
Aggregations