1
0
mirror of https://github.com/chylex/Code-Statistics.git synced 2025-07-26 22:59:07 +02:00

Move global Java info from JavaState to JavaGlobalInfo class

This commit is contained in:
chylex 2016-03-10 17:25:27 +01:00
parent 3e30a964db
commit 3862f3005b
4 changed files with 39 additions and 29 deletions

View File

@ -101,6 +101,7 @@
<Compile Include="Handling\Languages\Java\Elements\Primitives.cs" />
<Compile Include="Handling\Languages\Java\Elements\Type.cs" />
<Compile Include="Handling\Languages\Java\Elements\TypeOf.cs" />
<Compile Include="Handling\Languages\Java\JavaGlobalInfo.cs" />
<Compile Include="Handling\Languages\Java\Utils\JavaCharacters.cs" />
<Compile Include="Handling\Languages\Java\JavaCodeParser.cs" />
<Compile Include="Handling\Languages\Java\JavaFileInfo.cs" />

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using CodeStatistics.Collections;
using CodeStatistics.Handling.Languages.Java.Elements;
namespace CodeStatistics.Handling.Languages.Java{
class JavaGlobalInfo{
public readonly CounterDictionary<string> AnnotationUses = new CounterDictionary<string>(8);
public readonly CounterDictionary<string> FieldTypes = new CounterDictionary<string>(10);
public readonly CounterDictionary<string> MethodReturnTypes = new CounterDictionary<string>(10);
public readonly CounterDictionary<string> MethodParameterTypes = new CounterDictionary<string>(10);
public readonly TopElementList<TypeIdentifier> IdentifiersSimpleTop = new TopElementList<TypeIdentifier>(10,(x,y) => y.Name.Length-x.Name.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersSimpleBottom = new TopElementList<TypeIdentifier>(10,(x,y) => x.Name.Length-y.Name.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersFullTop = new TopElementList<TypeIdentifier>(10,(x,y) => y.FullName.Length-x.FullName.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersFullBottom = new TopElementList<TypeIdentifier>(10,(x,y) => x.FullName.Length-y.FullName.Length);
}
}

View File

@ -2,22 +2,13 @@
using System.Collections.Generic;
using CodeStatistics.Handling.Languages.Java.Elements;
using CodeStatistics.Handling.Languages.Java.Utils;
using CodeStatistics.Collections;
namespace CodeStatistics.Handling.Languages.Java{
class JavaState{
private readonly Dictionary<File,JavaFileInfo> fileInfo = new Dictionary<File,JavaFileInfo>();
private readonly HashSet<string> packages = new HashSet<string>();
public readonly CounterDictionary<string> AnnotationUses = new CounterDictionary<string>(8);
public readonly CounterDictionary<string> FieldTypes = new CounterDictionary<string>(10);
public readonly CounterDictionary<string> MethodReturnTypes = new CounterDictionary<string>(10);
public readonly CounterDictionary<string> MethodParameterTypes = new CounterDictionary<string>(10);
public readonly TopElementList<TypeIdentifier> IdentifiersSimpleTop = new TopElementList<TypeIdentifier>(10,(x,y) => y.Name.Length-x.Name.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersSimpleBottom = new TopElementList<TypeIdentifier>(10,(x,y) => x.Name.Length-y.Name.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersFullTop = new TopElementList<TypeIdentifier>(10,(x,y) => y.FullName.Length-x.FullName.Length);
public readonly TopElementList<TypeIdentifier> IdentifiersFullBottom = new TopElementList<TypeIdentifier>(10,(x,y) => x.FullName.Length-y.FullName.Length);
public readonly JavaGlobalInfo GlobalInfo = new JavaGlobalInfo();
public int PackageCount { get { return packages.Count; } }
@ -31,7 +22,7 @@ namespace CodeStatistics.Handling.Languages.Java{
JavaCodeParser parser = new JavaCodeParser(JavaParseUtils.PrepareCodeFile(file.Contents));
parser.AnnotationCallback += IncrementAnnotation;
parser.CodeBlockCallback += blockParser => ReadCodeBlock(blockParser,info);
parser.CodeBlockCallback += blockParser => ReadCodeBlock(blockParser,GlobalInfo);
ReadPackage(parser,info);
ReadImportList(parser,info);
@ -56,20 +47,20 @@ namespace CodeStatistics.Handling.Languages.Java{
}
foreach(Field field in type.GetData().Fields){
FieldTypes.Increment(field.Type.ToStringGeneral());
GlobalInfo.FieldTypes.Increment(field.Type.ToStringGeneral());
}
foreach(Method method in type.GetData().Methods){
MethodReturnTypes.Increment(method.ReturnType.ToStringGeneral());
GlobalInfo.MethodReturnTypes.Increment(method.ReturnType.ToStringGeneral());
foreach(TypeOf parameterType in method.ParameterTypes){
MethodParameterTypes.Increment(parameterType.ToStringGeneral());
GlobalInfo.MethodParameterTypes.Increment(parameterType.ToStringGeneral());
}
}
}
private void IncrementAnnotation(Annotation annotation){
AnnotationUses.Increment(annotation.SimpleName);
GlobalInfo.AnnotationUses.Increment(annotation.SimpleName);
}
private static void ReadPackage(JavaCodeParser parser, JavaFileInfo info){
@ -103,7 +94,7 @@ namespace CodeStatistics.Handling.Languages.Java{
}
}
private static void ReadCodeBlock(JavaCodeParser blockParser, JavaFileInfo info){
private static void ReadCodeBlock(JavaCodeParser blockParser, JavaGlobalInfo info){
// TODO
}
}

View File

@ -77,11 +77,11 @@ namespace CodeStatistics.Handling.Languages{
variables.Minimum("javaNamesFullMin",fullLength);
variables.Maximum("javaNamesFullMax",fullLength);
JavaState state = variables.GetStateObject<JavaState>(this);
state.IdentifiersSimpleTop.Add(identifier);
state.IdentifiersSimpleBottom.Add(identifier);
state.IdentifiersFullTop.Add(identifier);
state.IdentifiersFullBottom.Add(identifier);
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
@ -158,6 +158,7 @@ namespace CodeStatistics.Handling.Languages{
base.FinalizeProject(variables);
JavaState state = variables.GetStateObject<JavaState>(this);
JavaGlobalInfo global = state.GlobalInfo;
// general
variables.SetVariable("javaPackages",state.PackageCount);
@ -168,19 +169,19 @@ namespace CodeStatistics.Handling.Languages{
variables.Average("javaNamesFullAvg","javaNamesFullTotal","javaTypesTotal");
// identifiers
foreach(TypeIdentifier identifier in state.IdentifiersSimpleTop){
foreach(TypeIdentifier identifier in global.IdentifiersSimpleTop){
variables.AddToArray("javaNamesSimpleTop",new { package = identifier.Prefix, name = identifier.Name });
}
foreach(TypeIdentifier identifier in state.IdentifiersSimpleBottom.Reverse()){
foreach(TypeIdentifier identifier in global.IdentifiersSimpleBottom.Reverse()){
variables.AddToArray("javaNamesSimpleBottom",new { package = identifier.Prefix, name = identifier.Name });
}
foreach(TypeIdentifier identifier in state.IdentifiersFullTop){
foreach(TypeIdentifier identifier in global.IdentifiersFullTop){
variables.AddToArray("javaNamesFullTop",new { package = identifier.Prefix, name = identifier.Name });
}
foreach(TypeIdentifier identifier in state.IdentifiersFullBottom.Reverse()){
foreach(TypeIdentifier identifier in global.IdentifiersFullBottom.Reverse()){
variables.AddToArray("javaNamesFullBottom",new { package = identifier.Prefix, name = identifier.Name });
}
@ -196,20 +197,20 @@ namespace CodeStatistics.Handling.Languages{
variables.Average("javaMethodParametersAvg","javaMethodParametersTotal","javaMethodsTotal");
foreach(KeyValuePair<string,int> fieldType in state.FieldTypes.ListFromTop()){
foreach(KeyValuePair<string,int> fieldType in global.FieldTypes.ListFromTop()){
variables.AddToArray("javaFieldTypes",new { type = fieldType.Key, amount = fieldType.Value });
}
foreach(KeyValuePair<string,int> methodReturnType in state.MethodReturnTypes.ListFromTop()){
foreach(KeyValuePair<string,int> methodReturnType in global.MethodReturnTypes.ListFromTop()){
variables.AddToArray("javaMethodReturnTypes",new { type = methodReturnType.Key, amount = methodReturnType.Value });
}
foreach(KeyValuePair<string,int> methodParameterType in state.MethodParameterTypes.ListFromTop()){
foreach(KeyValuePair<string,int> methodParameterType in global.MethodParameterTypes.ListFromTop()){
variables.AddToArray("javaMethodParameterTypes",new { type = methodParameterType.Key, amount = methodParameterType.Value });
}
// annotations
List<KeyValuePair<string,int>> annotationUses = state.AnnotationUses.ListFromTop();
List<KeyValuePair<string,int>> annotationUses = global.AnnotationUses.ListFromTop();
int totalAnnotationsUsed = annotationUses.Sum(kvp => kvp.Value);
for(int annotationIndex = 0; annotationIndex < Math.Min(annotationUses.Count,10); annotationIndex++){