private void saveMap() { // Speichern der Datei: Translator tr = new Translator(); List<ClassContainer> liste = new List<ClassContainer>(); Map map2 = new Map(); map2.solarsystems = systemList; map2.randomArea = loadedMap.randomArea; map2.systemcount = loadedMap.systemcount; map2.min_distance = loadedMap.min_distance; ClassContainer container2 = new ClassContainer(); container2.objekt = map2; container2.type = ClassType.Map; liste.Add(container2); tr.writeData(liste, "created.map"); }
private static CodeBlock CreateBlockFromMethodeInizialiser(VariableInitializerContext tmpInizialiser, ClassContainer inParentClass, VariableDeclaration inVarDeclaration) { if (tmpInizialiser != null) { var tmpBlock = new CodeBlock(); if (tmpInizialiser.arrayInitializer() != null) { throw new NotImplementedException("Array Inizialiser not implemented"); } else { new JavaMethodeCodeResolver() { ParentClass = inParentClass } .HandleExpressionContext(tmpBlock, tmpInizialiser.expression(), inVarDeclaration); } return(tmpBlock); } return(null); }
public void save(string filename) { Translator tr = new Translator(); ClassContainer container = new ClassContainer(); container.type = ClassType.Main; container.objekt = this; List<ClassContainer> list = new List<ClassContainer>(); list.Add(container); tr.writeData(list, filename); }
/// <summary> /// Resolve an Interface Declaration /// </summary> /// <param name="tmpClass"></param> /// <param name="tmpComment"></param> /// <param name="tmpSubChild"></param> private static void ResolveInterfaceDeclaration(ClassContainer tmpClass, string tmpComment, IParseTree tmpSubChild) { var tmpBodyPart = (tmpSubChild as InterfaceBodyDeclarationContext).interfaceMemberDeclaration(); if (tmpBodyPart.interfaceMethodDeclaration() != null) { var tmpIntDec = tmpBodyPart.interfaceMethodDeclaration(); var tmpMethode = new MethodeContainer { Name = tmpIntDec.IDENTIFIER().GetText(), ReturnType = GetTypeContainer(tmpIntDec.typeTypeOrVoid().typeType()), Comment = tmpComment, AntlrCode = tmpIntDec.methodBody(), }; foreach (var tmpEntry in tmpIntDec.interfaceMethodModifier()) { if (tmpEntry.annotation() != null) { throw new NotImplementedException("Methode modifier annotation not Implemented"); } tmpMethode.ModifierList.Add(tmpEntry.GetText()); } var tmpParams = tmpIntDec.formalParameters()?.formalParameterList()?.formalParameter(); if (tmpParams != null) { foreach (var tmpParam in tmpParams) { var tmpModifier = tmpParam.variableModifier(); var tmpFieldContainer = new FieldContainer { Name = tmpParam.variableDeclaratorId().IDENTIFIER().GetText(), Type = GetTypeContainer(tmpParam.typeType()), }; foreach (var tmpInfo in tmpParam.variableModifier()) { tmpFieldContainer.ModifierList.Add(tmpInfo.GetText()); } tmpMethode.Parameter.Add(tmpFieldContainer); } } tmpClass.AddMethode(tmpMethode); } else if (tmpBodyPart.constDeclaration() != null) { var tmpConstDef = tmpBodyPart.constDeclaration(); var tmpDeclarator = tmpConstDef.constantDeclarator()[0]; var tmpFieldContainer = new FieldContainer { Name = tmpDeclarator.IDENTIFIER().GetText(), Type = GetTypeContainer(tmpConstDef.typeType()), Comment = tmpComment, }; var tmpInizialiser = tmpDeclarator.variableInitializer(); tmpFieldContainer.DefaultValue = CreateBlockFromMethodeInizialiser(tmpInizialiser, tmpClass, tmpFieldContainer); tmpClass.FieldList.Add(tmpFieldContainer); } else if (tmpBodyPart.classDeclaration() != null) { var tmpSubClass = new ClassContainer { UsingList = tmpClass.UsingList, Namespace = tmpClass.Namespace, Comment = tmpComment, }; tmpSubClass.Type = tmpBodyPart.classDeclaration().IDENTIFIER().GetText(); if (tmpBodyPart.classDeclaration().typeParameters() != null) { //Fill Type Parameters foreach (var tmpParam in tmpBodyPart.classDeclaration().typeParameters().typeParameter()) { var tmpInnerType = new TypeContainer(tmpParam.IDENTIFIER().GetText()); if (tmpParam.annotation().Length > 0 || tmpParam.EXTENDS() != null) { throw new NotImplementedException("Type Param Fill error"); } tmpSubClass.Type.GenericTypes.Add(tmpInnerType); } } FillClassContext(tmpSubClass, tmpBodyPart.classDeclaration()); tmpClass.InnerClasses.Add(tmpSubClass); } else { } }
/// <summary> /// Create Types from IParseTree Type arguments /// </summary> /// <param name="tmpClass"></param> /// <param name="inGenericTypeChildren"></param> /// <returns></returns> private static List <TypeContainer> GetGenericTypesFromGenericArgumentsChildren(ClassContainer tmpClass, IEnumerable <IParseTree> inGenericTypeChildren) { TypeContainer tmpCurrentGenericType = null; var tmpReturnTypes = new List <TypeContainer>(); foreach (var tmpGenericClassDeclarationChild in inGenericTypeChildren) { if (tmpGenericClassDeclarationChild is TypeParameterContext) { var tmpParam = tmpGenericClassDeclarationChild as TypeParameterContext; tmpCurrentGenericType = new TypeContainer(tmpParam.IDENTIFIER().GetText()); tmpReturnTypes.Add(tmpCurrentGenericType); if (tmpParam.annotation().Length > 0 || tmpParam.EXTENDS() != null) { throw new NotImplementedException("TypeParametersContext Extenmsion und Annotiations sind nicht Implementiert"); } } else if (tmpGenericClassDeclarationChild is TypeTypeOrVoidContext) { var tmpTypeOrVoid = tmpGenericClassDeclarationChild as TypeTypeOrVoidContext; tmpCurrentGenericType = new TypeContainer(); tmpReturnTypes.Add(tmpCurrentGenericType); if (tmpTypeOrVoid.typeType() != null) { //TODO Replace with GetTypeContainer(), if it's the same if (tmpTypeOrVoid.typeType().classOrInterfaceType() != null) { var tmpType = tmpTypeOrVoid.typeType().classOrInterfaceType(); if (tmpType.IDENTIFIER().Length > 1) { throw new NotImplementedException($"Identifier to Long at {tmpClass.Name}"); } tmpCurrentGenericType.Name = tmpType.IDENTIFIER(0).GetText(); foreach (var tmpTypeArgument in tmpType.typeArguments().SelectMany(inItem => inItem.typeArgument())) { var tmpGenericInnerType = new TypeContainer(tmpTypeArgument.GetText()); tmpCurrentGenericType.GenericTypes.Add(tmpGenericInnerType); //TODO Handling of Stacked Generics } } else if (tmpTypeOrVoid.typeType().primitiveType() != null) { var tmpPrimitveType = tmpTypeOrVoid.typeType().primitiveType(); tmpCurrentGenericType.Name = tmpPrimitveType.GetText(); } else { throw new NotImplementedException($"Unknown Type inside tmpGenericClassDeclarationChild of Class {tmpClass.Name}"); } } else { tmpCurrentGenericType.Name = tmpTypeOrVoid.GetText(); } } else if (tmpGenericClassDeclarationChild is ErrorNodeImpl) { if (tmpCurrentGenericType != null) { var tmpGEnericText = tmpGenericClassDeclarationChild.GetText(); if (tmpGEnericText == "[" || tmpGEnericText == "]") { tmpCurrentGenericType.IsArray = true; } else if (tmpGEnericText == ">") { //TODO Handling of Stacked Generics } else if (tmpGEnericText == "<") { //TODO Handling of Stacked Generics throw new NotImplementedException($"Unknown Type inside Generic Class Header as Class {tmpClass.Name}"); } else if (tmpGEnericText == ",") { tmpCurrentGenericType = null; } else { throw new NotImplementedException($"Unknown Type inside Generic Class Header as Class {tmpClass.Name}"); } } else if (!TypeNonNumberChars.Contains(tmpGenericClassDeclarationChild.GetText())) { tmpCurrentGenericType = tmpGenericClassDeclarationChild.GetText(); tmpReturnTypes.Add(tmpCurrentGenericType); } } else if (tmpGenericClassDeclarationChild is TerminalNodeImpl) { if (tmpGenericClassDeclarationChild.GetText() == ",") { tmpCurrentGenericType = null; } } else { throw new NotImplementedException($"Unknown Type inside tmpGenericClassDeclarationChild of Class {tmpClass.Name}"); } } return(tmpReturnTypes); }
public static List <ClassContainer> LoaderOptimization(string inFile) { var tmpClassList = new List <ClassContainer>(); var tmpPackage = ""; var tmpUsingList = new List <string>(); ICharStream stream = new AntlrInputStream(inFile); ITokenSource lexer = new JavaLexerLexer(stream); ITokenStream tokens = new CommonTokenStream(lexer); var parser = new JavaParser(tokens); parser.BuildParseTree = true; IParseTree tree = parser.compilationUnit(); var tmpClasses = new List <TypeDeclarationContext>(); var tmpClassComments = new List <IParseTree>(); var tmpPrePackageComments = new List <IParseTree>(); for (var tmpI = 0; tmpI < tree.ChildCount; tmpI++) { var tmpChild = tree.GetChild(tmpI); var tmpType = tmpChild.GetType().Name; if (tmpChild is PackageDeclarationContext) { tmpPackage = (tmpChild as PackageDeclarationContext).qualifiedName().GetText(); } else if (tmpChild is ImportDeclarationContext) { tmpUsingList.Add((tmpChild as ImportDeclarationContext).qualifiedName().GetText()); } else if (tmpChild is TypeDeclarationContext) { tmpClasses.Add(tmpChild as TypeDeclarationContext); } else if (tmpChild is IErrorNode) { if (string.IsNullOrEmpty(tmpPackage)) { tmpPrePackageComments.Add(tmpChild); } else { if (tmpChild.GetText() != "}") { tmpClassComments.Add(tmpChild); } } } else { } } //Load all Classes from File foreach (var tmpElement in tmpClasses) { var tmpClass = new ClassContainer(); tmpClass.Namespace = tmpPackage; tmpClass.UsingList = tmpUsingList; //Add Namespace-comment, if existing if (tmpPrePackageComments.Count > 0) { tmpClass.NamespaceComment = tmpPrePackageComments[0].GetText(); } //Add Class Comments if (tmpClassComments.Count > 0) { tmpClass.Comment = tmpClassComments[0].GetText(); tmpClassComments.RemoveAt(0); } if (ExtractClassFromTreeTypeDeclaration(tmpElement, tmpClass)) { tmpClassList.Add(tmpClass); } } return(tmpClassList); }
/// <summary> /// Find or Create Class for Name and Using-List /// </summary> /// <param name="inProject"></param> /// <param name="inClassName"></param> /// <param name="inPossibleNamespaces"></param> /// <returns></returns> public static ClassContainer GetClassOrUnknownForType(this ProjectInformation inProject, string inClassName, ClassContainer inParentClass) { if (string.IsNullOrEmpty(inClassName)) { return(null); } var tmpClass = inProject.ClassForNameAndNamespaces(inClassName, inParentClass.FullUsingList); if (tmpClass != null) { return(tmpClass); } if (inProject.GetAliasType(inClassName) != null) { return(inProject.GetAliasType(inClassName)); } if (inParentClass.Type == null) { return(null); } var tmpGenericType = inParentClass.Type.GenericTypes.FirstOrDefault(inItem => inItem.Name == inClassName); if (tmpGenericType != null) { return(new ClassContainer { Type = tmpGenericType, Parent = inProject }); } var tmpParentClass = inParentClass; while (tmpParentClass != null) { var tmpField = tmpParentClass.FieldList.FirstOrDefault(inItem => inItem.Name == inClassName); if (tmpField != null) { return(new ClassContainer { Type = tmpField.Type, Parent = inProject }); } tmpParentClass = tmpParentClass.GetParentClass(); } var tmpUnknown = inProject.UnknownClassForNameAndNamespaces(inClassName, inParentClass.FullUsingList); if (tmpUnknown == null) { tmpUnknown = new UnknownTypeClass(inClassName) { PossibleNamespace = inParentClass.FullUsingList, Parent = inProject }; inProject.AddUnknownClass(tmpUnknown); } return(tmpUnknown); }
private void speichernToolStripMenuItem_Click(object sender, EventArgs e) { try { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Map-File | *.map"; if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Translator tr = new Translator(); List<ClassContainer> list = new List<ClassContainer>(); Map map = new Map(); map.solarsystems = solarsystemMap; map.randomArea = randomArea; map.systemcount = int.Parse(Systemcount.Text); map.min_distance = int.Parse(Min_distance.Text); ClassContainer container = new ClassContainer(); container.objekt = map; container.type = ClassType.Map; list.Add(container); tr.writeData(list, save.FileName); } } catch (Exception ex) { MessageBox.Show("Fehler: " + ex.Message); } }