Ejemplo n.º 1
0
		public static void Parse(CsInterface pCsInterface, CodeBuilder pBuilder, FactoryExpressionCreator pCreator) {
			StringBuilder sb = new StringBuilder();
			TheClass myClass = TheClassFactory.Get(pCsInterface, pCreator);

			sb.AppendFormat("{1}interface {0}",
							myClass.Name,
							As3Helpers.ConvertModifiers(myClass.Modifiers, _notValidClassMod));

			if (myClass.Implements.Count != 0) {
				sb.Append(" extends ");
				foreach (string s in myClass.Implements) {
					sb.Append(As3Helpers.Convert(s));
					sb.Append(", ");
				}

				sb.Remove(sb.Length - 2, 2);
			}

			sb.Append(" {");
			sb.AppendLine();

			pBuilder.Append(sb.ToString());
			pBuilder.AppendLineAndIndent();

			if (pCsInterface.member_declarations != null) {
				foreach (CsNode memberDeclaration in pCsInterface.member_declarations) {
					//if (memberDeclaration is CsConstructor) {
					//    MethodParser.Parse(myClass.GetConstructor((CsConstructor)memberDeclaration), pBuilder);
					//} else 
				if (memberDeclaration is CsMethod) {
						MethodParser.Parse(myClass.GetMethod((CsMethod)memberDeclaration), pBuilder, pCreator);

					} else if (memberDeclaration is CsIndexer) {
						IndexerParser.Parse(myClass.GetIndexer((CsIndexer)memberDeclaration), pBuilder, pCreator);

					} else if (memberDeclaration is CsVariableDeclaration) {
						VariableParser.Parse(myClass.GetVariable((CsVariableDeclaration)memberDeclaration), pBuilder);
					} else 
					//if (memberDeclaration is CsConstantDeclaration) {
					//    ConstantParser.Parse(myClass.GetConstant((CsConstantDeclaration)memberDeclaration), pBuilder);
					//} else 
					//if (memberDeclaration is CsDelegate) {
					//    DelegateParser.Parse(myClass.GetDelegate((CsDelegate)memberDeclaration), pBuilder);
					//} else 
					//if (memberDeclaration is CsEvent) {
					//    EventParser.Parse(myClass.GetEvent(((CsEvent)memberDeclaration).declarators.First.Value.identifier.identifier),
					//                      pBuilder);
					//} else 
					if (memberDeclaration is CsProperty) {
						PropertyParser.Parse(myClass.GetProperty((CsProperty)memberDeclaration), pBuilder, pCreator);
					//} else if (memberDeclaration is CsInterface) {
					//    Parse((CsInterface)memberDeclaration, privateClasses);
					} else {
						throw new NotSupportedException();
					}
				}
			}

			pBuilder.AppendLineAndUnindent("}");
			pBuilder.AppendLineAndUnindent("}");
			pBuilder.AppendLine();
			string imports = ClassParser.getImports();
			pBuilder.Replace(ClassParser.IMPORT_MARKER, imports);
		}
Ejemplo n.º 2
0
		public TheClass(CsInterface pCsInterface, FactoryExpressionCreator pCreator) {
			IsInterface = true;
			List<string> name = new List<string>();
			CsNamespace parent = pCsInterface.parent as CsNamespace;

			if (parent != null) {
				name.AddRange(parent.qualified_identifier.Select(pArt => pArt.identifier.identifier));
			}

			NameSpace = string.Join(".", name.ToArray());
			Name = pCsInterface.identifier.identifier;
			FullName = NameSpace + "." + Name;

			if (pCsInterface.type_base != null && pCsInterface.type_base.base_list.Count != 0) {
				foreach (CsTypeRef typeRef in pCsInterface.type_base.base_list) {
					object u = typeRef.entity_typeref.u;
					if (u == null) continue;

					if (u is CsEntityClass) {
						Extends.Add(Helpers.GetType(typeRef.type_name));
						_baseTyperef = typeRef;

					} else if (u is CsEntityInterface) {
						Implements.Add(Helpers.GetType(typeRef.type_name));

					} else if (u is CsEntityInstanceSpecifier) {
						Implements.Add(Helpers.GetType(typeRef.type_name));

					} else {
						throw new NotSupportedException();
					}
				}
			}

			Dictionary<string, int> methodNames = new Dictionary<string, int>();
			bool methodsDone = false;

			if (pCsInterface.member_declarations != null) {
				foreach (CsNode memberDeclaration in pCsInterface.member_declarations) {
					CsMethod m = memberDeclaration as CsMethod;
					if (m != null) {
						if (m.interface_type != null)
							continue;

						TheMethod tm = new TheMethod(m, this, pCreator);
						if (methodNames.ContainsKey(tm.Name)) {
							methodNames[tm.Name]++;
							int index = tm._index = methodNames[tm.Name];

							if (!methodsDone) {
								methodsDone = true;
								foreach (KeyValuePair<CsMethod, TheMethod> method in _methods) {
									method.Value._isUnique = false;
									method.Value._index = --index;
								}
							}

							tm._isUnique = false;

						} else {
							methodNames[tm.Name] = tm._index = 1;
						}

						_methods.Add(m, tm);
						continue;
					}

					CsIndexer i = memberDeclaration as CsIndexer;
					if (i != null) {
						_indexers.Add(i, new TheIndexer(i, this, pCreator));
						continue;
					}

					CsVariableDeclaration v = memberDeclaration as CsVariableDeclaration;
					if (v != null) {
						_variables.Add(v, new TheVariable(v, this, pCreator));
						continue;
					}

					CsProperty p = memberDeclaration as CsProperty;
					if (p != null) {
						if (p.interface_type == null)
							_properties.Add(p, new TheProperty(p, this, pCreator));
						continue;
					}

					throw new NotImplementedException("Unknown type not implemented");
				}
			}

			Modifiers.AddRange(Helpers.GetModifiers(pCsInterface.modifiers));
		}