use of org.apache.tapestry5.beaneditor.Width in project tapestry-5 by apache.
the class InstructionBuilderState method startVariable.
LocalVariable startVariable(String type) {
Label start = newLabel();
Label end = new Label();
PrimitiveType ptype = PrimitiveType.getByName(type);
int width = (ptype != null && ptype.isWide()) ? 2 : 1;
int loadOpcode = ptype == null ? ALOAD : ptype.loadOpcode;
int storeOpcode = ptype == null ? ASTORE : ptype.storeOpcode;
LVInfo info = new LVInfo(width, localIndex, loadOpcode, storeOpcode, end);
localIndex += width;
LocalVariable var = new LocalVariableImpl(type);
locals.put(var, info);
visitor.visitLocalVariable(nextVarName(), nameCache.toDesc(type), null, start, end, info.offset);
return var;
}
use of org.apache.tapestry5.beaneditor.Width in project tapestry-5 by apache.
the class ExceptionReportWriterImpl method writeReport.
@Override
public void writeReport(final PrintWriter writer, ExceptionAnalysis analysis) {
writer.printf("EXCEPTION STACK:%n%n");
// Figure out what all the property names are so that we can set the width of the column that lists
// property names.
Flow<String> propertyNames = F.flow(analysis.getExceptionInfos()).mapcat(EXCEPTION_INFO_TO_PROPERTY_NAMES).append("Exception", "Message");
PropertyWriter pw = newPropertyWriter(writer, propertyNames);
boolean first = true;
for (ExceptionInfo info : analysis.getExceptionInfos()) {
if (first) {
writer.println();
first = false;
}
pw.write("Exception", info.getClassName());
pw.write("Message", info.getMessage());
for (String name : info.getPropertyNames()) {
pw.write(name, info.getProperty(name));
}
if (!info.getStackTrace().isEmpty()) {
writer.printf("%n Stack trace:%n%n");
for (StackTraceElement e : info.getStackTrace()) {
writer.printf(" - %s%n", e.toString());
}
}
writer.println();
}
Request request = requestGlobals.getRequest();
if (request != null) {
// New PropertyWriter based on the lengths of parameter names and header names, and a sample of
// the literal keys.
pw = newPropertyWriter(writer, F.flow(request.getParameterNames()).concat(request.getHeaderNames()).append("serverName", "removeHost"));
writer.printf("REQUEST:%n%nBasic Information:%n%n");
List<String> flags = CollectionFactory.newList();
if (request.isXHR()) {
flags.add("XHR");
}
if (request.isRequestedSessionIdValid()) {
flags.add("requestedSessionIdValid");
}
if (request.isSecure()) {
flags.add("secure");
}
pw.write("contextPath", contextPath);
if (!flags.isEmpty()) {
pw.write("flags", InternalUtils.joinSorted(flags));
}
pw.write("method", request.getMethod());
pw.write("path", request.getPath());
pw.write("locale", request.getLocale());
pw.write("serverName", request.getServerName());
pw.write("remoteHost", request.getRemoteHost());
writer.printf("%nHeaders:%n%n");
for (String name : request.getHeaderNames()) {
pw.write(name, request.getHeader(name));
}
if (!request.getParameterNames().isEmpty()) {
writer.printf("%nParameters:%n");
for (String name : request.getParameterNames()) {
// TODO: Support multi-value parameters
pw.write(name, request.getParameters(name));
}
}
Session session = request.getSession(false);
if (session != null) {
pw = newPropertyWriter(writer, session.getAttributeNames());
writer.printf("%nSESSION:%n%n");
for (String name : session.getAttributeNames()) {
pw.write(name, session.getAttribute(name));
}
}
}
writer.printf("%nSYSTEM INFORMATION:");
Runtime runtime = Runtime.getRuntime();
writer.printf("%n%nMemory:%n %,15d bytes free%n %,15d bytes total%n %,15d bytes max%n", runtime.freeMemory(), runtime.totalMemory(), runtime.maxMemory());
Thread[] threads = TapestryInternalUtils.getAllThreads();
int maxThreadNameLength = 0;
for (Thread t : threads) {
maxThreadNameLength = Math.max(maxThreadNameLength, t.getName().length());
}
String format = "%n%s %" + maxThreadNameLength + "s %s";
writer.printf("%n%,d Threads:", threads.length);
for (Thread t : threads) {
writer.printf(format, Thread.currentThread() == t ? "*" : " ", t.getName(), t.getState().name());
if (t.isDaemon()) {
writer.write(", daemon");
}
if (!t.isAlive()) {
writer.write(", NOT alive");
}
if (t.isInterrupted()) {
writer.write(", interrupted");
}
if (t.getPriority() != Thread.NORM_PRIORITY) {
writer.printf(", priority %d", t.getPriority());
}
}
// Finish the final line.
writer.println();
}
use of org.apache.tapestry5.beaneditor.Width in project tapestry-5 by apache.
the class MarkupWriterImplTest method attributes_odd_number.
@Test
public void attributes_odd_number() {
MarkupWriter w = new MarkupWriterImpl();
w.element("img");
try {
w.attributes("src", "foo.png", "width", 20, 30);
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, "Writing attributes of the element 'img' failed.", "An attribute name or value is omitted [src, foo.png, width, 20, 30].", "Please provide an even number of values, alternating names and values");
}
}
use of org.apache.tapestry5.beaneditor.Width in project tapestry-5 by apache.
the class MarkupWriterImplTest method element_with_attributes.
@Test
public void element_with_attributes() {
MarkupWriter w = new MarkupWriterImpl();
w.element("img", "src", "foo.png", "width", 20, "height", 20);
w.end();
// img is a tag with an end tag style of omit, so no close tag is written.
assertEquals(w.toString(), "<img height=\"20\" width=\"20\" src=\"foo.png\"/>");
}
use of org.apache.tapestry5.beaneditor.Width in project tapestry-5 by apache.
the class TapestryInternalUtilsTest method to_internal_property_conduit_wrapper.
@Test
public void to_internal_property_conduit_wrapper() {
PropertyConduit conduit = mockPropertyConduit();
Integer result = 123;
Width width = newMock(Width.class);
expect(conduit.get("")).andReturn(result);
expect(conduit.getAnnotation(Width.class)).andReturn(width);
expect(conduit.getPropertyType()).andReturn(Integer.class);
conduit.set("", 345);
replay();
InternalPropertyConduit conduit2 = TapestryInternalUtils.toInternalPropertyConduit(conduit);
assertNull(conduit2.getPropertyName());
assertSame(conduit2.get(""), result);
assertSame(conduit2.getAnnotation(Width.class), width);
assertSame(conduit2.getPropertyType(), Integer.class);
conduit2.set("", 345);
verify();
}
Aggregations