Пример #1
0
        private void ProcessType(string prefix, Type type, Variables.Root variables, bool isNested)
        {
            foreach(Type nestedType in type.NestedTypes){
                ProcessType(prefix+"."+type.Identifier, nestedType, variables, true);
            }

            // declaration type
            variables.Increment("javaTypesTotal");

            string declPrefix = "javaUnknown";

            switch(type.Declaration){
                case Type.DeclarationType.Class: variables.Increment(declPrefix = "javaClasses"); break;
                case Type.DeclarationType.Interface: variables.Increment(declPrefix = "javaInterfaces"); break;
                case Type.DeclarationType.Enum: variables.Increment(declPrefix = "javaEnums"); break;
                case Type.DeclarationType.Annotation: variables.Increment(declPrefix = "javaAnnotations"); break;
            }

            if (isNested){
                variables.Increment(declPrefix+(type.Modifiers.HasFlag(Modifiers.Static) ? "NestedStatic" : "NestedInner"));
            }

            foreach(Modifiers modifier in JavaModifiers.Values.Where(modifier => type.Modifiers.HasFlag(modifier))){
                variables.Increment(declPrefix+JavaModifiers.ToString(modifier).CapitalizeFirst());
            }

            // identifier
            TypeIdentifier identifier = new TypeIdentifier(prefix, type.Identifier);

            int simpleNameLength = identifier.Name.Length;
            variables.Increment("javaNamesSimpleTotal", simpleNameLength);
            variables.Minimum("javaNamesSimpleMin", simpleNameLength);
            variables.Maximum("javaNamesSimpleMax", simpleNameLength);

            int fullLength = identifier.FullName.Length;
            variables.Increment("javaNamesFullTotal", fullLength);
            variables.Minimum("javaNamesFullMin", fullLength);
            variables.Maximum("javaNamesFullMax", fullLength);

            JavaGlobalInfo global = variables.GetStateObject<JavaState>(this).GlobalInfo;
            global.IdentifiersSimpleTop.Add(identifier);
            global.IdentifiersSimpleBottom.Add(identifier);
            global.IdentifiersFullTop.Add(identifier);
            global.IdentifiersFullBottom.Add(identifier);

            if (type.Declaration == Type.DeclarationType.Annotation){
                // annotation elements
                int methodCount = type.GetData().Methods.Count;
                variables.Increment("javaAnnotationsElementsTotal", methodCount);
                variables.Minimum("javaAnnotationsElementsMin", methodCount);
                variables.Maximum("javaAnnotationsElementsMax", methodCount);
            }
            else{
                // fields
                List<Field> fields = type.GetData().Fields;
                int fieldsDefault = fields.Count;

                variables.Increment(declPrefix+"FieldsTotal", fields.Count);
                variables.Minimum(declPrefix+"FieldsMin", fields.Count);
                variables.Maximum(declPrefix+"FieldsMax", fields.Count);

                foreach(Modifiers modifier in JavaModifiers.Values){
                    int count = fields.Count(field => field.Modifiers.HasFlag(modifier));
                    if (modifier == Modifiers.Public || modifier == Modifiers.Protected || modifier == Modifiers.Private)fieldsDefault -= count;

                    variables.Increment(declPrefix+"Fields"+JavaModifiers.ToString(modifier).CapitalizeFirst(), count);
                }

                variables.Increment(declPrefix+"FieldsDefaultVisibility", fieldsDefault);

                // methods
                List<Method> constructorMethods = type.GetData().Methods.Where(method => method.IsConstructor).ToList();
                List<Method> classMethods = type.GetData().Methods.Where(method => !method.IsConstructor).ToList();

                int methodsDefault = classMethods.Count;

                if (type.GetData().CanHaveConstructors){
                    variables.Increment(declPrefix+"ConstructorsTotal", Math.Max(1, constructorMethods.Count)); // if 0, count an implicit constructor
                }

                variables.Increment(declPrefix+"MethodsTotal", classMethods.Count);
                variables.Minimum(declPrefix+"MethodsMin", classMethods.Count);
                variables.Maximum(declPrefix+"MethodsMax", classMethods.Count);

                foreach(Modifiers modifier in JavaModifiers.Values){
                    int count = classMethods.Count(method => method.Modifiers.HasFlag(modifier));
                    if (modifier == Modifiers.Public || modifier == Modifiers.Protected || modifier == Modifiers.Protected)methodsDefault -= count;

                    variables.Increment(declPrefix+"Methods"+JavaModifiers.ToString(modifier).CapitalizeFirst(), count);
                }

                variables.Increment(declPrefix+"MethodsDefaultVisibility", methodsDefault);
            }

            // enums
            if (type.Declaration == Type.DeclarationType.Enum){
                Type.DataEnum enumData = type.GetData<Type.DataEnum>();

                variables.Increment("javaEnumsValuesTotal", enumData.EnumValues.Count);
                variables.Minimum("javaEnumsValuesMin", enumData.EnumValues.Count);
                variables.Maximum("javaEnumsValuesMax", enumData.EnumValues.Count);
            }

            // annotations
            variables.Increment("javaAnnotationsUsedClasses", type.Annotations.Count);

            foreach(Field field in type.GetData().Fields){
                variables.Increment("javaAnnotationsUsedFields", field.Annotations.Count);
            }

            foreach(Method method in type.GetData().Methods){
                variables.Increment("javaAnnotationsUsedMethods", method.Annotations.Count);
            }

            // field and method counting
            variables.Increment("javaFieldsTotal", type.GetData().Fields.Count);
            variables.Increment("javaMethodsTotal", type.GetData().Methods.Count);

            foreach(Method method in type.GetData().Methods){
                variables.Increment("javaMethodParametersTotal", method.ParameterTypes.Count);
                variables.Minimum("javaMethodParametersMin", method.ParameterTypes.Count);
                variables.Maximum("javaMethodParametersMax", method.ParameterTypes.Count);
            }
        }