Skip to content

Commit

Permalink
Remove unecessary print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrodshn committed Dec 5, 2024
1 parent ab9daad commit a447e37
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
2 changes: 0 additions & 2 deletions pkg/concepts/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package concepts

import (
"log"
"sort"

"github.com/openshift-online/ocm-api-metamodel/pkg/names"
Expand Down Expand Up @@ -193,7 +192,6 @@ func (t *Type) RemoveAttribute(name *names.Name) {
}
for i, attribute := range t.attributes {
if attribute.Name().Equals(name) {
log.Printf("---------- Deleting attribute %s", name.String())
t.attributes = append(t.attributes[:i], t.attributes[i+1:]...)
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/concepts/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ func (v *Version) AddType(typ *Type) {
}
}

// AddType adds the given type to the version.
func (v *Version) AddTypeWithoutOwner(typ *Type) {
if typ != nil {
v.types[typ.Name().String()] = typ
}
}

// AddTypes adds the given types to the version.
func (v *Version) AddTypes(types []*Type) {
for _, typ := range types {
Expand Down
6 changes: 6 additions & 0 deletions pkg/generators/golang/builders_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (g *BuildersGenerator) generateStructBuilderFile(typ *concepts.Type) error
Function("builderName", g.builderName).
Function("fieldName", g.fieldName).
Function("fieldType", g.fieldType).
Function("selectorType", g.selectorType).
Function("objectName", g.objectName).
Function("setterName", g.setterName).
Function("setterType", g.setterType).
Expand Down Expand Up @@ -685,6 +686,11 @@ func (g *BuildersGenerator) fieldType(attribute *concepts.Attribute) *TypeRefere
return ref
}

func (g *BuildersGenerator) selectorType(attribute *concepts.Attribute) string {
ref := g.fieldType(attribute)
return ref.selector
}

func (g *BuildersGenerator) setterName(attribute *concepts.Attribute) string {
name := annotations.GoName(attribute)
if name == "" {
Expand Down
6 changes: 5 additions & 1 deletion pkg/generators/golang/types_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,14 @@ func (c *TypesCalculator) ValueReference(typ *concepts.Type) *TypeReference {
// the nil value.
func (c *TypesCalculator) NullableReference(typ *concepts.Type) *TypeReference {
switch {
case (typ.IsScalar() && !typ.IsInterface()) || typ.IsStruct():
case (typ.IsScalar() && !typ.IsInterface()):
ref := c.ValueReference(typ)
ref.text = fmt.Sprintf("*%s", ref.text)
return ref
case typ.IsStruct():
ref := c.ValueReference(typ)
ref.text = fmt.Sprintf("*%s.%s", ref.selector, ref.name)
return ref
default:
return c.ValueReference(typ)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/language/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ func (r *Reader) checkParameter(parameter *concepts.Parameter) {
}
if typ != nil && typ != parameter.Type() {
r.reporter.Errorf(
"Type of default value of parameter '%s' should be '%s', instead it was %s",
parameter, parameter.Type(), typ.Name().String(),
"Type of default value of parameter '%s' should be '%s'",
parameter, parameter.Type(),
)
}
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/language/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package language
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -440,12 +441,11 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) {
}

input := r.inputs[0]
currVersion := r.service.Versions()[0]
path = strings.TrimPrefix(path, "/")
components := strings.Split(path, "/")
referencedServiceName := components[0]
referencedVersion := components[1]
referencedType := components[2]
referencedTypeName := components[2]

// Create an ad-hoc reader and model for the specific referenced service.
refReader := NewReader().
Expand All @@ -462,31 +462,31 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) {
refVersion := refReader.service.FindVersion(names.ParseUsingSeparator(referencedVersion, "_"))
// Once loading the service, we find the reference type
// then recursively iterate the type tree and add the types to the current version.
for _, currType := range refVersion.Types() {
if strings.Compare(currType.Name().String(), referencedType) == 0 {
r.recursivelyAddTypeToVersion(currVersion, currType)
for _, referencedType := range refVersion.Types() {
if strings.Compare(referencedType.Name().String(), referencedTypeName) == 0 {
r.recursivelyAddTypeToVersion(typ, referencedType)
}
}
}
}

// A helper function to recursively add types to a version
func (r *Reader) recursivelyAddTypeToVersion(version *concepts.Version, typ *concepts.Type) {
var attributesToRemove concepts.AttributeSlice
for _, attribute := range typ.Attributes() {
// We wish to define links explicitly and not inherint them
// only the attribute fields.
if version.FindType(attribute.Type().Name()) == nil && !attribute.Link() {
r.recursivelyAddTypeToVersion(version, attribute.Type())
}
func (r *Reader) recursivelyAddTypeToVersion(currType *concepts.Type,
referencedType *concepts.Type) {
log.Printf("Adding type %s from version %s to version %s",
referencedType.Name().String(),
referencedType.Owner().Name().String(),
r.version.Name().String(),
)
for _, attribute := range referencedType.Attributes() {
if attribute.Link() {
attributesToRemove = append(attributesToRemove, attribute)
r.version.AddTypeWithoutOwner(attribute.Type())
}
if r.version.FindType(attribute.Type().Name()) == nil && !attribute.Link() {
r.recursivelyAddTypeToVersion(currType, attribute.Type())
}
}
for _, attribute := range attributesToRemove {
typ.RemoveAttribute(attribute.Name())
}
version.AddType(typ)
r.version.AddType(referencedType)
}

func (r *Reader) ExitStructDecl(ctx *StructDeclContext) {
Expand Down

0 comments on commit a447e37

Please sign in to comment.