public AddProperty ( string name, |
||
name | string | |
prop | ||
return | void |
/// <exception cref="Kirikiri.Tjs2.CompileException"></exception> /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public virtual void ToJavaCode(string text, bool isexpression, bool isresultneeded ) { if (text == null) { return; } if (text.Length == 0) { return; } mScript = text; Parse(text, isexpression, isresultneeded); AList<JavaCodeIntermediate> clazz = new AList<JavaCodeIntermediate>(); int count = mInterCodeGeneratorList.Count; for (int i = 0; i < count; i++) { InterCodeGenerator v = mInterCodeGeneratorList[i]; if (v != null) { int type = v.GetContextType(); AList<string> codes; switch (type) { case ContextType.TOP_LEVEL: { break; } case ContextType.FUNCTION: { InterCodeGenerator parent = v.GetParent(); if (parent.GetContextType() == ContextType.CLASS) { string parentName = parent.GetName(); codes = v.ToJavaCode(0, 0); int ccount = clazz.Count; bool inserted = false; for (int j = 0; j < ccount; j++) { JavaCodeIntermediate ci = clazz[j]; if (ci.GetName().Equals(parentName)) { ci.AddMember(new JavaCodeIntermediate.ClosureCode(v.GetName(), type, codes)); inserted = true; break; } } if (inserted == false) { JavaCodeIntermediate ci = new JavaCodeIntermediate(parentName); ci.AddMember(new JavaCodeIntermediate.ClosureCode(v.GetName(), type, codes)); clazz.AddItem(ci); } } break; } case ContextType.EXPR_FUNCTION: { break; } case ContextType.PROPERTY: { InterCodeGenerator parent = v.GetParent(); if (parent.GetContextType() == ContextType.CLASS) { string parentName = parent.GetName(); int ccount = clazz.Count; bool inserted = false; for (int j = 0; j < ccount; j++) { JavaCodeIntermediate ci = clazz[j]; if (ci.GetName().Equals(parentName)) { ci.AddProperty(v.GetName(), new JavaCodeIntermediate.Property(v.GetName())); inserted = true; break; } } if (inserted == false) { JavaCodeIntermediate ci = new JavaCodeIntermediate(parentName); ci.AddProperty(v.GetName(), new JavaCodeIntermediate.Property(v.GetName())); clazz.AddItem(ci); } } break; } case ContextType.PROPERTY_SETTER: case ContextType.PROPERTY_GETTER: { InterCodeGenerator parent = v.GetParent(); if (parent.GetContextType() == ContextType.PROPERTY) { InterCodeGenerator parentparent = parent.GetParent(); if (parentparent.GetContextType() == ContextType.CLASS) { string propName = parent.GetName(); string className = parentparent.GetName(); int ccount = clazz.Count; bool inserted = false; JavaCodeIntermediate target = null; for (int j = 0; j < ccount; j++) { JavaCodeIntermediate ci = clazz[j]; if (ci.GetName().Equals(className)) { target = ci; inserted = true; break; } } if (inserted == false) { JavaCodeIntermediate ci = new JavaCodeIntermediate(className); target = ci; clazz.AddItem(ci); } JavaCodeIntermediate.Property prop = target.GetProperty(propName); if (prop == null) { prop = new JavaCodeIntermediate.Property(propName); target.AddProperty(propName, prop); } codes = v.ToJavaCode(0, 0); if (type == ContextType.PROPERTY_SETTER) { prop.SetSetter(codes); } else { prop.SetGetter(codes); } } } break; } case ContextType.CLASS: { JavaCodeIntermediate ci = new JavaCodeIntermediate(v.GetName()); codes = v.ToJavaCode(0, 0); ci.SetInitializer(codes); clazz.AddItem(ci); break; } case ContextType.SUPER_CLASS_GETTER: { break; } } } } int ccount_1 = clazz.Count; for (int j_1 = 0; j_1 < ccount_1; j_1++) { JavaCodeIntermediate ci = clazz[j_1]; ci.Write(); } }