use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class BytecodeMethod method appendMethodC.
public void appendMethodC(StringBuilder b) {
if (nativeMethod) {
return;
}
appendCMethodPrefix(b, "");
b.append(" {\n");
if (eliminated) {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
return;
}
b.append(declaration);
boolean hasInstructions = true;
if (optimizerOn) {
hasInstructions = optimize();
}
if (hasInstructions) {
Set<String> added = new HashSet<String>();
for (LocalVariable lv : localVariables) {
String variableName = lv.getQualifier() + "locals_" + lv.getIndex() + "_";
if (!added.contains(variableName) && lv.getQualifier() != 'o') {
added.add(variableName);
b.append(" volatile ");
switch(lv.getQualifier()) {
case 'i':
b.append("JAVA_INT");
break;
case 'l':
b.append("JAVA_LONG");
break;
case 'f':
b.append("JAVA_FLOAT");
break;
case 'd':
b.append("JAVA_DOUBLE");
break;
}
b.append(" ").append(lv.getQualifier()).append("locals_").append(lv.getIndex()).append("_ = 0; /* ").append(lv.getOrigName()).append(" */\n");
}
}
if (staticMethod) {
if (methodName.equals("__CLINIT__")) {
b.append(" DEFINE_METHOD_STACK(");
} else {
b.append(" __STATIC_INITIALIZER_");
b.append(clsName.replace('/', '_').replace('$', '_'));
b.append("(threadStateData);\n DEFINE_METHOD_STACK(");
}
} else {
b.append(" DEFINE_INSTANCE_METHOD_STACK(");
}
b.append(maxStack);
b.append(", ");
b.append(maxLocals);
b.append(", 0, ");
b.append(Parser.addToConstantPool(clsName));
b.append(", ");
b.append(Parser.addToConstantPool(methodName));
b.append(");\n");
int startOffset = 0;
if (synchronizedMethod) {
if (staticMethod) {
b.append(" monitorEnter(threadStateData, (JAVA_OBJECT)&class__");
b.append(clsName);
b.append(");\n");
} else {
b.append(" monitorEnter(threadStateData, __cn1ThisObject);\n");
}
}
if (!staticMethod) {
b.append(" locals[0].data.o = __cn1ThisObject; locals[0].type = CN1_TYPE_OBJECT; ");
startOffset++;
}
int localsOffset = startOffset;
for (int iter = 0; iter < arguments.size(); iter++) {
ByteCodeMethodArg arg = arguments.get(iter);
if (arg.getQualifier() == 'o') {
b.append(" locals[");
b.append(localsOffset);
b.append("].data.");
b.append(arg.getQualifier());
b.append(" = __cn1Arg");
b.append(iter + 1);
b.append(";\n");
b.append(" locals[");
b.append(localsOffset);
b.append("].type = CN1_TYPE_OBJECT;\n");
} else {
b.append(" ");
if (!hasLocalVariableWithIndex(arg.getQualifier(), localsOffset)) {
switch(arg.getQualifier()) {
case 'i':
b.append("JAVA_INT");
break;
case 'f':
b.append("JAVA_FLOAT");
break;
case 'd':
b.append("JAVA_DOUBLE");
break;
case 'l':
b.append("JAVA_LONG");
break;
default:
b.append("JAVA_INT");
break;
}
b.append(" ");
}
b.append(arg.getQualifier());
b.append("locals_");
b.append(localsOffset);
b.append("_");
b.append(" = __cn1Arg");
b.append(iter + 1);
b.append(";\n");
}
// For now we'll still allocate space for locals that we're not using
// so we keep the indexes the same for objects.
localsOffset++;
if (arg.isDoubleOrLong()) {
localsOffset++;
}
}
}
BasicInstruction.setSynchronizedMethod(synchronizedMethod, staticMethod, clsName);
TryCatch.reset();
BasicInstruction.setHasInstructions(hasInstructions);
for (Instruction i : instructions) {
i.setMaxes(maxStack, maxLocals);
i.appendInstruction(b, instructions);
}
if (instructions.size() == 0) {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
return;
}
Instruction inst = instructions.get(instructions.size() - 1);
int lastInstruction = inst.getOpcode();
if (lastInstruction == -1 || inst instanceof LabelInstruction) {
if (instructions.size() > 2) {
inst = instructions.get(instructions.size() - 2);
lastInstruction = inst.getOpcode();
}
}
if (lastInstruction == Opcodes.RETURN || lastInstruction == Opcodes.ARETURN || lastInstruction == Opcodes.IRETURN || lastInstruction == Opcodes.LRETURN || lastInstruction == Opcodes.FRETURN || lastInstruction == Opcodes.DRETURN || lastInstruction == -1) {
b.append("}\n\n");
} else {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
}
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class CustomInvoke method appendExpression.
public boolean appendExpression(StringBuilder b) {
// special case for clone on an array which isn't a real method invocation
if (name.equals("clone") && owner.indexOf('[') > -1) {
if (targetObjectLiteral != null) {
b.append("cloneArray(").append(targetObjectLiteral).append(")");
} else {
b.append("cloneArray(POP_OBJ(1))");
}
return true;
}
StringBuilder bld = new StringBuilder();
if (origOpcode == Opcodes.INVOKEINTERFACE || origOpcode == Opcodes.INVOKEVIRTUAL) {
// b.append(" ");
bld.append("virtual_");
}
if (origOpcode == Opcodes.INVOKESTATIC) {
// find the actual class of the static method to workaround javac not defining it correctly
ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_'));
owner = findActualOwner(bc);
}
bld.append(owner.replace('/', '_').replace('$', '_'));
bld.append("_");
if (name.equals("<init>")) {
bld.append("__INIT__");
} else {
if (name.equals("<clinit>")) {
bld.append("__CLINIT__");
} else {
bld.append(name);
}
}
bld.append("__");
ArrayList<String> args = new ArrayList<String>();
String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args);
int numLiteralArgs = this.getNumLiteralArgs();
if (numLiteralArgs > 0) {
b.append("/* CustomInvoke */");
}
boolean noPop = false;
b.append(bld);
b.append("(threadStateData");
if (origOpcode != Opcodes.INVOKESTATIC) {
if (targetObjectLiteral == null) {
// b.append("].data.o");
return false;
} else {
b.append(", ").append(targetObjectLiteral);
numLiteralArgs++;
}
}
// int offset = args.size();
// int numArgs = offset;
int argIndex = 0;
for (String a : args) {
b.append(", ");
if (literalArgs != null && literalArgs[argIndex] != null) {
b.append(literalArgs[argIndex]);
} else {
return false;
// b.append("SP[-");
// b.append(offset);
// b.append("].data.");
// b.append(a);
// offset--;
}
argIndex++;
}
if (returnVal == null) {
return false;
}
b.append(")");
return true;
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class Invoke method appendInstruction.
@Override
public void appendInstruction(StringBuilder b) {
// special case for clone on an array which isn't a real method invocation
if (name.equals("clone") && owner.indexOf('[') > -1) {
b.append(" POP_MANY_AND_PUSH_OBJ(cloneArray(PEEK_OBJ(1)), 1);\n");
return;
}
StringBuilder bld = new StringBuilder();
if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) {
b.append(" ");
bld.append("virtual_");
} else {
b.append(" ");
}
if (opcode == Opcodes.INVOKESTATIC) {
// find the actual class of the static method to workaround javac not defining it correctly
ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_'));
owner = findActualOwner(bc);
}
// if(owner.replace('/', '_').replace('$', '_').equals("java_lang_System_1") && name.equals("sleep")) {
// System.out.println("Break");
// }
bld.append(owner.replace('/', '_').replace('$', '_'));
bld.append("_");
if (name.equals("<init>")) {
bld.append("__INIT__");
} else {
if (name.equals("<clinit>")) {
bld.append("__CLINIT__");
} else {
bld.append(name);
}
}
bld.append("__");
ArrayList<String> args = new ArrayList<String>();
String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args);
boolean noPop = false;
if (returnVal == null) {
b.append(bld);
} else {
if (args.size() == 0 && opcode == Opcodes.INVOKESTATIC) {
// special case for static method
if (returnVal.equals("JAVA_OBJECT")) {
b.append("PUSH_OBJ");
} else {
if (returnVal.equals("JAVA_INT")) {
b.append("PUSH_INT");
} else {
if (returnVal.equals("JAVA_LONG")) {
b.append("PUSH_LONG");
} else {
if (returnVal.equals("JAVA_DOUBLE")) {
b.append("PUSH_DOUBLE");
} else {
if (returnVal.equals("JAVA_FLOAT")) {
b.append("PUSH_FLOAT");
} else {
throw new UnsupportedOperationException("Unknown type: " + returnVal);
}
}
}
}
}
// b.append(returnVal);
noPop = true;
b.append("(");
} else {
// b.append("POP_MANY_AND_");
// b.append(returnVal);
b.append("{ ");
b.append(returnVal);
b.append(" tmpResult = ");
}
b.append(bld);
}
b.append("(threadStateData");
if (opcode != Opcodes.INVOKESTATIC) {
b.append(", SP[-");
b.append(args.size() + 1);
b.append("].data.o");
}
int offset = args.size();
// int numArgs = offset;
int argIndex = 0;
for (String a : args) {
b.append(", ");
b.append("SP[-");
b.append(offset);
b.append("].data.");
b.append(a);
offset--;
argIndex++;
}
if (noPop) {
b.append("));\n");
return;
}
if (returnVal != null) {
b.append(");\n");
if (opcode != Opcodes.INVOKESTATIC) {
if (args.size() > 0) {
b.append(" SP-=");
b.append(args.size());
b.append(";\n");
}
} else {
if (args.size() > 1) {
b.append(" SP-=");
b.append(args.size() - 1);
b.append(";\n");
}
}
if (returnVal.equals("JAVA_OBJECT")) {
b.append(" SP[-1].data.o = tmpResult; SP[-1].type = CN1_TYPE_OBJECT; }\n");
} else {
if (returnVal.equals("JAVA_INT")) {
b.append(" SP[-1].data.i = tmpResult; SP[-1].type = CN1_TYPE_INT; }\n");
} else {
if (returnVal.equals("JAVA_LONG")) {
b.append(" SP[-1].data.l = tmpResult; SP[-1].type = CN1_TYPE_LONG; }\n");
} else {
if (returnVal.equals("JAVA_DOUBLE")) {
b.append(" SP[-1].data.d = tmpResult; SP[-1].type = CN1_TYPE_DOUBLE; }\n");
} else {
if (returnVal.equals("JAVA_FLOAT")) {
b.append(" SP[-1].data.f = tmpResult; SP[-1].type = CN1_TYPE_FLOAT; }\n");
} else {
throw new UnsupportedOperationException("Unknown type: " + returnVal);
}
}
}
}
}
return;
}
b.append("); ");
int val;
if (opcode != Opcodes.INVOKESTATIC) {
val = args.size() + 1;
} else {
val = args.size();
}
if (val > 0) {
/*b.append("popMany(threadStateData, ");
b.append(val);
b.append(", stack, &stackPointer); \n"); */
b.append(" SP-= ");
b.append(val);
b.append(";\n");
} else {
b.append("\n");
}
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class HTMLComponent method handleInput.
/**
* Handles the INPUT tag
*
* @param element The input element
* @param align The current aligment
*/
private void handleInput(HTMLElement element, int align) {
String type = element.getAttributeById(HTMLElement.ATTR_TYPE);
if (type == null) {
return;
}
int typeID = INPUT_TYPES.indexOf(type.toLowerCase());
if (typeID == -1) {
if (htmlCallback != null) {
if (!htmlCallback.parsingError(HTMLCallback.ERROR_ATTIBUTE_VALUE_INVALID, element.getTagName(), element.getAttributeName(new Integer(HTMLElement.ATTR_TYPE)), type, "Unsupported input type '" + type + "'. Supported types: text, password, checkbox, radio, submit, reset, hidden, image")) {
cancel();
}
}
return;
}
String name = element.getAttributeById(HTMLElement.ATTR_NAME);
String id = element.getAttributeById(HTMLElement.ATTR_ID);
String value = element.getAttributeById(HTMLElement.ATTR_VALUE);
if (value == null) {
value = "";
}
Component cmp = null;
switch(typeID) {
case INPUT_CHECKBOX:
CheckBox cb = new CheckBox();
if (element.getAttributeById(HTMLElement.ATTR_CHECKED) != null) {
cb.setSelected(true);
}
cmp = cb;
if (curForm != null) {
curForm.addCheckBox(name, cb, value);
}
break;
case INPUT_HIDDEN:
if (curForm != null) {
curForm.addInput(name, value, null);
}
break;
case INPUT_EMAIL:
case INPUT_TEXT:
case INPUT_PASSWORD:
TextField tf = new TextField(value);
tf.setLeftAndRightEditingTrigger(false);
if (typeID == INPUT_PASSWORD) {
tf.setConstraint(TextField.PASSWORD);
}
if (typeID == INPUT_EMAIL) {
tf.setConstraint(TextField.EMAILADDR);
}
if (SUPPORT_INPUT_FORMAT) {
HTMLInputFormat inputFormat = HTMLInputFormat.getInputFormat(element.getAttributeById(HTMLElement.ATTR_FORMAT));
if (inputFormat != null) {
tf = (TextField) inputFormat.applyConstraints(tf);
if (curForm != null) {
curForm.setInputFormat(tf, inputFormat);
}
}
String emptyOk = element.getAttributeById(HTMLElement.ATTR_EMPTYOK);
if ((emptyOk != null) && (curForm != null)) {
if (emptyOk.equalsIgnoreCase("true")) {
curForm.setEmptyOK(tf, true);
} else if (emptyOk.equalsIgnoreCase("false")) {
curForm.setEmptyOK(tf, false);
}
}
}
int size = getInt(element.getAttributeById(HTMLElement.ATTR_SIZE));
int maxlen = getInt(element.getAttributeById(HTMLElement.ATTR_MAXLENGTH));
if (size == 0) {
size = DEFAULT_TEXTFIELD_SIZE;
}
if (maxlen != 0) {
tf.setMaxSize(maxlen);
if (size > maxlen) {
size = maxlen;
}
}
tf.setPreferredW(tf.getStyle().getFont().stringWidth("W") * size);
tf.getSelectedStyle().setFont(font.getFont());
tf.getUnselectedStyle().setFont(font.getFont());
if ((!PROCESS_HTML_MP1_ONLY) && (element.getAttributeById(HTMLElement.ATTR_READONLY) != null)) {
tf.setEditable(false);
}
cmp = tf;
if (curForm != null) {
curForm.addInput(name, cmp, value);
textfieldsToForms.put(tf, curForm);
}
break;
case INPUT_RADIO:
RadioButton rb = new RadioButton(" ");
if (element.getAttributeById(HTMLElement.ATTR_CHECKED) != null) {
rb.setSelected(true);
}
cmp = rb;
if (curForm != null) {
curForm.addRadioButton(name, rb, value);
}
break;
case INPUT_RESET:
Command resetCmd = null;
if (curForm != null) {
resetCmd = curForm.createResetCommand(value);
}
if (resetCmd == null) {
// dummy command - no form so it won't do anything
resetCmd = new Command(getUIManager().localize("html.reset", HTMLForm.DEFAULT_RESET_TEXT));
}
Button resetButton = new Button(resetCmd);
cmp = resetButton;
break;
case INPUT_BUTTON:
case INPUT_SUBMIT:
Command submitCmd = null;
if (curForm != null) {
submitCmd = curForm.createSubmitCommand(name, value);
}
if (submitCmd == null) {
// dummy command - no form so it won't do anything
submitCmd = new Command(value.equals("") ? value = getUIManager().localize("html.submit", HTMLForm.DEFAULT_SUBMIT_TEXT) : value);
}
Button submitButton = new Button(submitCmd);
cmp = submitButton;
break;
case // Image submit is not officially supported in XHTML-MP 1.0 but was added anyway, but pixel data submission is not supported (i.e. name.x=xx&name.y=yy)
INPUT_IMAGE:
submitCmd = null;
if (curForm != null) {
submitCmd = curForm.createSubmitCommand(name, value);
}
handleImage(element, align, submitCmd);
break;
}
if (cmp != null) {
if ((!PROCESS_HTML_MP1_ONLY) && (element.getAttributeById(HTMLElement.ATTR_DISABLED) != null)) {
cmp.setEnabled(false);
}
String aKey = element.getAttributeById(HTMLElement.ATTR_ACCESSKEY);
if ((aKey != null) && (aKey.length() == 1)) {
// accessKeys.put(new Integer(aKey.charAt(0)), cmp);
addAccessKey(aKey.charAt(0), cmp, false);
}
if (eventsListener != null) {
eventsListener.registerComponent(cmp, element);
}
// Even if CSS is off, we need to associate it for HTMLElement.getCurentValue
element.setAssociatedComponents(cmp);
if ((curForm != null) && (curForm.action == null)) {
// Form that submits to a forbidden link
cmp.setEnabled(false);
} else if (firstFocusable == null) {
firstFocusable = cmp;
}
if (id != null) {
inputFields.put(id, cmp);
}
}
addCmp(cmp, align);
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class HTMLTable method createCell.
/**
* This method is overriden to return the component that is contained in the HTMLTableModel
* (Since our model contains the actual component and does not store data that can be rendered using toString we can't use the original createCell method)
*
* @param value the new value object
* @param row row number, -1 for the header rows
* @param column column number
* @param editable true if the cell is editable
* @return cell component instance
*/
protected Component createCell(Object value, int row, int column, boolean editable) {
Component cmp = null;
if (value instanceof Component) {
cmp = (Component) value;
// TODO - table cells styling - needs to propogate downwards since the cell is usually a container, on the other hand can't wipe out the style of the container's components - TBD
// boolean isHeader=((HTMLTableModel)getModel()).isHeader(value);
// if (isHeader) {
// cmp.setUIID("TableHeader");
// } else {
// cmp.setUIID("TableCell");
// }
} else {
cmp = super.createCell(value, row, column, editable);
}
cmp.setFocusable(false);
return cmp;
}
Aggregations