Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

62
LINES

< > BotCompany Repo | #1029845 - ConceptsRefChecker

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13433L/91K).

sclass ConceptsRefChecker {
  Concepts cc;
  new L<Err> errors;
  
  sclass Err {}
  srecord ErrNoBackRef(Concept.Ref ref, Concept dest) > Err {}
  srecord ErrSuperfluousBackRef(Concept.Ref ref, Concept dest) > Err {}
  
  // a reference from a concept that is not in the concepts list
  srecord ErrDanglingSource(Concept.Ref ref, Concept dest) > Err {}
  
  // a reference to a concept that is not in the concepts list
  srecord ErrDanglingDestination(Concept.Ref ref, Concept dest) > Err {}
  
  *() {}
  *(Concepts *cc) {}
  
  L<Err> run() {
    errors.clear();
    if (cc == null) ret errors;
    for (Concept c : cc.allConcepts()) try {
      O badElement = firstElementNotSubclassing(c.backRefs, Concept.Ref.class);
      if (badElement != null) continue with print("Bad element in backRefs of " + c + ": " + badElement);
      
      for (Concept.Ref ref : cloneList(c.backRefs)) {
        if (ref! != c)
          errors.add(new ErrSuperfluousBackRef(ref, c));
        if (ref.concept()._concepts != cc)
          errors.add(new ErrDanglingSource(ref, c));
      }
          
      badElement = firstElementNotSubclassing(c.refs, Concept.Ref.class);
      if (badElement != null) continue with print("Bad element in backRefs of " + c + ": " + badElement);
      
      for (Concept.Ref ref : cloneList(c.refs))
        if (ref.has()) {
          if (!contains(ref->backRefs, ref))
            errors.add(new ErrNoBackRef(ref, c));
          if (ref->_concepts != cc)
            errors.add(new ErrDanglingDestination(ref, c));
      }
    } catch print e {
      print("Error processing concept " + c);
    }
    ret errors;
  }
  
  L<Err> errors() { ret errors; }
  
  S fixAll() {
    new LS out;
    for (Err err : cloneAndClear(errors)) {
      out.add("Processing " + err);
      if (err cast ErrNoBackRef) {
        err.ref.index();
        out.add("  reference added");
      } else
        out.add("  TODO - fix not implemented");
    }
    ret lines(out);
  }
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, tvejysmllsmz

No comments. add comment

Snippet ID: #1029845
Snippet name: ConceptsRefChecker
Eternal ID of this version: #1029845/10
Text MD5: a0df65d355bba56eb0f9f05aa3f705da
Transpilation MD5: 189868e7b4ab94ddc56c307463ba9675
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-31 11:33:58
Source code size: 2041 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 52 / 129
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1029845 & http://1029845.tinybrain.de