Skip to content

Commit

Permalink
refactor: removed unwanted code
Browse files Browse the repository at this point in the history
  • Loading branch information
shivasurya committed Feb 19, 2025
1 parent 9544aa4 commit e667178
Showing 1 changed file with 91 additions and 92 deletions.
183 changes: 91 additions & 92 deletions sourcecode-parser/tree/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,59 @@ import (
parser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/db"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/model"
utilities "github.com/shivasurya/code-pathfinder/sourcecode-parser/util"
)

type Env struct {
Node *model.Node
}

func (env *Env) GetVisibility() string {
return env.Node.Modifier
}
// func (env *Env) GetVisibility() string {
// return env.Node.Modifier
// }

func (env *Env) GetAnnotations() []string {
return env.Node.Annotation
}
// func (env *Env) GetAnnotations() []string {
// return env.Node.Annotation
// }

func (env *Env) GetReturnType() string {
return env.Node.ReturnType
}
// func (env *Env) GetReturnType() string {
// return env.Node.ReturnType
// }

func (env *Env) GetName() string {
return env.Node.Name
}
// func (env *Env) GetName() string {
// return env.Node.Name
// }

func (env *Env) GetArgumentTypes() []string {
return env.Node.MethodArgumentsType
}
// func (env *Env) GetArgumentTypes() []string {
// return env.Node.MethodArgumentsType
// }

func (env *Env) GetArgumentNames() []string {
return env.Node.MethodArgumentsValue
}
// func (env *Env) GetArgumentNames() []string {
// return env.Node.MethodArgumentsValue
// }

func (env *Env) GetSuperClass() string {
return env.Node.SuperClass
}
// func (env *Env) GetSuperClass() string {
// return env.Node.SuperClass
// }

func (env *Env) GetInterfaces() []string {
return env.Node.Interface
}
// func (env *Env) GetInterfaces() []string {
// return env.Node.Interface
// }

func (env *Env) GetScope() string {
return env.Node.Scope
}
// func (env *Env) GetScope() string {
// return env.Node.Scope
// }

func (env *Env) GetVariableValue() string {
return env.Node.VariableValue
}
// func (env *Env) GetVariableValue() string {
// return env.Node.VariableValue
// }

func (env *Env) GetVariableDataType() string {
return env.Node.DataType
}
// func (env *Env) GetVariableDataType() string {
// return env.Node.DataType
// }

func (env *Env) GetThrowsTypes() []string {
return env.Node.ThrowsExceptions
}
// func (env *Env) GetThrowsTypes() []string {
// return env.Node.ThrowsExceptions
// }

func (env *Env) IsJavaSourceFile() bool {
return true

Check warning on line 68 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L68

Added line #L68 was not covered by tests
Expand Down Expand Up @@ -244,33 +243,33 @@ func generateCartesianProduct(db *db.StorageNode, selectList []parser.SelectList
typeIndex := make(map[string][]*model.Node)

Check warning on line 243 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L242-L243

Added lines #L242 - L243 were not covered by tests

// value and reference based reducing search space
for _, condition := range conditions {
// this code helps to reduce search space
// if there is single entity in select list, the condition is easy to reduce the search space
// if there are multiple entities in select list, the condition is hard to reduce the search space,
// but I have tried my best using O(n^2) time complexity to reduce the search space
if len(selectList) > 1 {
// get all entities from the database based on select list (n items)
// based on condition (a condition can have multiple entities)
// use the entity to join the entity to reduce the search space instead of generrating cartesian product
// ideally it should be less than O(n^2) time complexity

} else {
filteredNodes := db.GetEntity(selectList[0].Entity)
for _, node := range filteredNodes {
query := parser.Query{Expression: condition, SelectList: selectList}
if FilterEntities([]*model.Node{node}, query) {
typeIndex[node.Type] = utilities.AppendUnique(typeIndex[node.Type], node)
}
}
}
}

if len(conditions) == 0 {
for _, node := range treeHolder.Nodes {
typeIndex[node.Type] = append(typeIndex[node.Type], node)
}
}
// for _, condition := range conditions {
// // this code helps to reduce search space
// // if there is single entity in select list, the condition is easy to reduce the search space
// // if there are multiple entities in select list, the condition is hard to reduce the search space,
// // but I have tried my best using O(n^2) time complexity to reduce the search space
// if len(selectList) > 1 {
// // get all entities from the database based on select list (n items)
// // based on condition (a condition can have multiple entities)
// // use the entity to join the entity to reduce the search space instead of generrating cartesian product
// // ideally it should be less than O(n^2) time complexity

// } else {
// // filteredNodes := db.MethodDecl
// // for _, node := range filteredNodes {
// // query := parser.Query{Expression: condition, SelectList: selectList}
// // // if FilterEntities([]*model.Node{{MethodDecl: node}}, query) {
// // // //typeIndex[node.Type] = utilities.AppendUnique(typeIndex[node.Type], node)
// // // }
// // }
// }
// }

// if len(conditions) == 0 {
// for _, node := range treeHolder.Nodes {
// typeIndex[node.Type] = append(typeIndex[node.Type], node)
// }
// }

Check warning on line 272 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L246-L272

Added lines #L246 - L272 were not covered by tests

sets := make([][]interface{}, 0, len(selectList))

Expand Down Expand Up @@ -428,39 +427,39 @@ func generateProxyEnv(node *model.Node, query parser.Query) map[string]interface
env := map[string]interface{}{
"isJavaSourceFile": proxyenv.IsJavaSourceFile(),
methodDeclaration: map[string]interface{}{
"getVisibility": proxyenv.GetVisibility,
"getAnnotation": proxyenv.GetAnnotations,
"getReturnType": proxyenv.GetReturnType,
"getName": proxyenv.GetName,
"getArgumentType": proxyenv.GetArgumentTypes,
"getArgumentName": proxyenv.GetArgumentNames,
"getThrowsType": proxyenv.GetThrowsTypes,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,
// "getVisibility": proxyenv.GetVisibility,
// "getAnnotation": proxyenv.GetAnnotations,
// "getReturnType": proxyenv.GetReturnType,
// "getName": proxyenv.GetName,
// "getArgumentType": proxyenv.GetArgumentTypes,
// "getArgumentName": proxyenv.GetArgumentNames,
// "getThrowsType": proxyenv.GetThrowsTypes,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,

Check warning on line 438 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L430-L438

Added lines #L430 - L438 were not covered by tests
},
classDeclaration: map[string]interface{}{
"getSuperClass": proxyenv.GetSuperClass,
"getName": proxyenv.GetName,
"getAnnotation": proxyenv.GetAnnotations,
"getVisibility": proxyenv.GetVisibility,
"getInterface": proxyenv.GetInterfaces,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,
// "getSuperClass": proxyenv.GetSuperClass,
// "getName": proxyenv.GetName,
// "getAnnotation": proxyenv.GetAnnotations,
// "getVisibility": proxyenv.GetVisibility,
// "getInterface": proxyenv.GetInterfaces,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,

Check warning on line 447 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L441-L447

Added lines #L441 - L447 were not covered by tests
},
methodInvocation: map[string]interface{}{
"getArgumentName": proxyenv.GetArgumentNames,
"getName": proxyenv.GetName,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,
// "getArgumentName": proxyenv.GetArgumentNames,
// "getName": proxyenv.GetName,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,

Check warning on line 453 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L450-L453

Added lines #L450 - L453 were not covered by tests
},
variableDeclaration: map[string]interface{}{
"getName": proxyenv.GetName,
"getVisibility": proxyenv.GetVisibility,
"getVariableValue": proxyenv.GetVariableValue,
"getVariableDataType": proxyenv.GetVariableDataType,
"getScope": proxyenv.GetScope,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,
// "getName": proxyenv.GetName,
// "getVisibility": proxyenv.GetVisibility,
// "getVariableValue": proxyenv.GetVariableValue,
// "getVariableDataType": proxyenv.GetVariableDataType,
// "getScope": proxyenv.GetScope,
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,

Check warning on line 462 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L456-L462

Added lines #L456 - L462 were not covered by tests
},
binaryExpression: map[string]interface{}{
"getLeftOperand": proxyenv.GetLeftOperand,
Expand Down Expand Up @@ -548,7 +547,7 @@ func generateProxyEnv(node *model.Node, query parser.Query) map[string]interface
"toString": proxyenv.ToString,
},
classInstanceExpression: map[string]interface{}{
"getName": proxyenv.GetName,
// "getName": proxyenv.GetName,

Check warning on line 550 in sourcecode-parser/tree/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/tree/query.go#L550

Added line #L550 was not covered by tests
"getDoc": proxyenv.GetDoc,
"toString": proxyenv.ToString,
"getClassInstanceExpr": proxyenv.GetClassInstanceExpr,
Expand Down

0 comments on commit e667178

Please sign in to comment.