Exemple #1
0
 public Method(string identifier, TypeOf returnType, Member info)
     : base(info)
 {
     this.Identifier = identifier;
     this.ReturnType = returnType;
     this.ParameterTypes = TypeOf.EmptyList();
 }
Exemple #2
0
 public Method(string identifier, TypeOf returnType, List<TypeOf> parameterTypes, Member info)
     : base(info)
 {
     this.Identifier = identifier;
     this.ReturnType = returnType;
     this.ParameterTypes = parameterTypes.AsReadOnly();
 }
Exemple #3
0
 protected Member(Member source)
 {
     this.Annotations = source.Annotations;
     this.Modifiers = source.Modifiers;
 }
Exemple #4
0
 public Member(Member source, Modifiers newModifiers)
 {
     this.Annotations = source.Annotations;
     this.Modifiers = newModifiers;
 }
        /// <summary>
        /// Recursively reads all members of a Type, including all nested Types. Called on a cloned JavaCodeParser that only
        /// contains contents of the Type block.
        /// </summary>
        private void ReadTypeContents(Type type)
        {
            // enum values
            if (type.Declaration == Type.DeclarationType.Enum){
                Type.DataEnum enumData = type.GetData<Type.DataEnum>();

                JavaCodeParser enumParser = ReadToIfBalanced(';');
                if (enumParser.Contents.Length == 0)enumParser = this;

                foreach(string enumValue in enumParser.ReadEnumValueList()){
                    enumData.EnumValues.Add(enumValue);
                }

                if (Char == ';')Skip();
            }

            // members
            int skippedMembers = 0;

            while(!IsEOF && skippedMembers < 50){
                Member memberInfo = SkipReadMemberInfo(); // skips spaces at the beginning and end

                // nested types
                Type.DeclarationType? declaration = ReadTypeDeclaration();

                if (declaration.HasValue){
                    string identifier = SkipSpaces().ReadIdentifier();
                    if (identifier.Length == 0)break; // error, break out

                    Type nestedType = new Type(declaration.Value, identifier, memberInfo);
                    ((JavaCodeParser)SkipTo('{').ReadBlock('{', '}')).ReadTypeContents(nestedType);

                    SkipSpacesAndSemicolons();

                    type.NestedTypes.Add(nestedType);
                    continue;
                }

                // static / instance initializer
                if (Char == '{'){
                    Method method = new Method(memberInfo.Modifiers.HasFlag(Modifiers.Static) ? "<clinit>" : "<init>", TypeOf.Void(), memberInfo);
                    SkipProcessCodeBlock();

                    type.GetData().Methods.Add(method);
                    continue;
                }

                // fields and methods
                TypeOf? returnOrFieldType = ReadTypeOf(false);

                if (returnOrFieldType.HasValue){
                    int prevCursor = cursor;
                    string identifier = SkipSpaces().ReadIdentifier();

                    if (identifier.Length == 0 && string.Equals(returnOrFieldType.Value.AsSimpleType(), type.Identifier)){ // constructor
                        identifier = Method.ConstructorIdentifier;
                        returnOrFieldType = TypeOf.Void();
                    }

                    if (identifier.Length == 0)break; // error, break out

                    if (SkipSpaces().Char == '('){ // method
                        List<TypeOf> parameterList = ((JavaCodeParser)ReadBlock('(', ')')).ReadMethodParameterList();

                        if (type.Declaration == Type.DeclarationType.Annotation){
                            if (SkipSpaces().SkipIfMatch("default^n")){
                                memberInfo = new Member(memberInfo, memberInfo.Modifiers | Modifiers.Default);
                                SkipTo(';');
                            }
                        }
                        else{
                            if (SkipSpaces().SkipIfMatch("throws^s")){
                                while(true){
                                    ReadFullTypeName();

                                    if (SkipSpaces().Char == ',')Skip().SkipSpaces();
                                    else break;
                                }
                            }
                        }

                        if (Char == ';')Skip();
                        else{
                            SkipProcessCodeBlock();
                            SkipSpacesAndSemicolons();
                        }

                        type.GetData().Methods.Add(new Method(identifier, returnOrFieldType.Value, parameterList, type.GetData().UpdateMethodInfo(memberInfo)));
                    }
                    else{ // field
                        Type.TypeData data = type.GetData();
                        cursor = prevCursor;

                        foreach(string fieldIdentifier in ReadToIfBalanced(';').ReadFieldIdentifierList()){
                            data.Fields.Add(new Field(fieldIdentifier, returnOrFieldType.Value, data.UpdateFieldInfo(memberInfo)));
                        }

                        Skip();
                    }

                    continue;
                }

                // extra checks before the skip
                if (Char == ';'){
                    Skip();
                    continue;
                }

                if (IsEOF)break;

                // skip
                if (skippedMembers == 0){
                    System.Diagnostics.Debugger.Break();
                }

                SkipBlock('{', '}');
                SkipSpacesAndSemicolons();
                ++skippedMembers;
            }
        }