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

66
LINES

< > BotCompany Repo | #1028893 // Code Safety Analysis

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (20973L/115K).

!7

concept EvaluationResult {
  S code;
  S safety;
  S comments;
  S date;
}

concept CAction {
  S action, date;
}

cmodule CodeSafetyAnalysis > DynCRUD<EvaluationResult> {
  transient ReliableSingleThread rstCalc = dm_rst(me(), r calc);
  transient SingleComponentPanel scpSuggestions;
  transient CRUD<CAction> crudActions;
  
  S code;
  PairS safety; // tested code + safety result
  Set<S> unknownIdentifiers;
  
  void start {
    addCountToName = false;
    super.start();
    crudActions = new CRUD(CAction);
    dm_useLocalMechListCopies();
    dm_watchFieldAndNow code(rstCalc);
  }
  
  visual withComputing(rstCalc, jvsplit(
    centerAndSouthWithMargins(
      jhsplit(
        dm_textAreaAsSection code(),
        jCenteredSection("Suggestions", scpSuggestions = singleComponentPanel())),
        centerAndEast(jCenteredSection("Safety", dm_calculatedLabel(() -> pairB(safety))), jbutton("Save result", rThreadEnter saveResult))
      ),

    jhsplit(
      jCenteredSection("Past Results", super),
      jCenteredSection("Last Actions", crudActions.visualize())));
    
  void calc {
    S code = this.code;
    setField(safety := pair(code, codeSafetyCheckResult(code)));
    setField(unknownIdentifiers := codeAnalysis_getUnknownIdentifiers(code));
    setComponent(scpSuggestions, () -> scrollableStackWithSpacing(
      map(unknownIdentifiers, id ->
        jLabelWithButtonsAndSideMargin(id,
          "Mark safe", rThreadEnter { recordAction(quote(id) + " marked safe"); markSafe(id); rstCalc.trigger(); },
          "Mark UNsafe", rThreadEnter { recordAction(quote(id) + " marked unsafe"); markUnsafe(id); rstCalc.trigger(); },
          "Mark...", rThreadEnter { inputText("Mark identifier " + quote(id), "unsafe", safety -> enter { assertIdentifier(safety = trim(safety)); recordAction(quote(id) + " marked " + safety); setIdentifierSafetyLevel(id, safety); rstCalc.trigger(); }) },
          ))));
  }
    
  void saveResult {
    rstCalc.waitUntilDone();
    PairS p = safety;
    if (p != null)
      cnew EvaluationResult(code := p.a, safety := p.b, date := formatLocalDateWithSeconds());
  }
  
  void recordAction(S action) {
    cnew(CAction, date := formatLocalDateWithSeconds(), +action);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028893
Snippet name: Code Safety Analysis
Eternal ID of this version: #1028893/26
Text MD5: c2053863035c04e5dadeb26afb7763a8
Transpilation MD5: 95f3beea2001a1f5f2214d70ebbe5fbc
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-11 13:35:59
Source code size: 2295 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 292 / 4208
Version history: 25 change(s)
Referenced in: [show references]