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 4, 2024
1 parent ab9daad commit 8c3fbcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 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
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
43 changes: 26 additions & 17 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 @@ -422,14 +423,6 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) {
// Add the annotations:
r.addAnnotations(typ, ctx.GetAnnotations())

// Add the attributes:
memberCtxs := ctx.GetMembers()
if len(memberCtxs) > 0 {
for _, memberCtx := range ctx.GetMembers() {
typ.AddAttribute(memberCtx.GetResult())
}
}

if path := annotations.ReferencePath(typ); path != "" {
if len(r.inputs) > 1 {
panic("refernced service with multiple inputs in undefined")
Expand All @@ -445,7 +438,7 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) {
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 +455,47 @@ 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(currVersion, typ, referencedType)
}
}
}

// Add the attributes:
memberCtxs := ctx.GetMembers()
if len(memberCtxs) > 0 {
for _, memberCtx := range ctx.GetMembers() {
typ.AddAttribute(memberCtx.GetResult())
}
}
}

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

log.Printf("Adding type %s from version %s to version %s",
referencedType.Name().String(), referencedType.Owner().Name().String(), version.Name().String())
version.AddType(referencedType)
}

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

0 comments on commit 8c3fbcf

Please sign in to comment.