Skip to content

Tutorial 7. Supported IDE Features Explained

Linghui Luo edited this page Jun 16, 2020 · 6 revisions

MagpieBridge focuses on the features related to analysis results. You need make sure you analysis results can be converted to class which implements the AnalysisResult interface.

class YourAnalysisResult implements AnalysisResult{
   /**
   * Kind.
   *
   * @return the kind
   */
   public Kind kind();{...}

  /**
   * The message of this result.
   *
   * @param useMarkdown the use markdown
   * @return the string
   */
  public String toString(boolean useMarkdown){...}

  /**
   * The source code position this result refers to.
   *
   * @return the position
   */
  public Position position(){}

  /**
   * The related information (source code position and corresponding message) of this result.
   *
   * @return the related information
   */
  public Iterable<Pair<Position, String>> related(){...}

  /**
   * Severity of this result, usually used for diagnostics.
   *
   * @return the diagnostic severity
   */
  public DiagnosticSeverity severity(){...}

  /**
   * The suggested repair, if any.
   *
   * @return a pair of source code position and the new code.
   */
  public Pair<Position, String> repair(){...}

  /**
   * The code which this result refers to.
   *
   * @return the code
   */
  public String code(){...}

}

Once your analysis produces a set of AnalysisResult objects, use the method MagpieServer.consume(...) to consume them. For AnalysisResult with Kind equals to Diagnostic, the MagpieServer will convert it into diagnostic message which can be consumed by the clients (IDEs). Usually the clients will show the diagnostics in a Problem View, the relevant line of code will be marked by different kinds of markers (error, warning or information depends on DiagnosticSeverity return by the serverity method), the message explaining this diagnostic will also be shown in a hover message. The following screenshot shows an example in Eclipse.

You can also provide quick fix for the diagnostic, all you need to do is to provide the information in the repair method, the MagpieServer will convert it into code action which can be consumed by the IDEs. A repair is basically a code position + the source code to be inserted at this position. In the above screenshot, a quick fix is also shown in the hover message.

In addition, you can also have trace information displayed in hover message. The following screen shows for example the data flow path related to a SQL injection vulnerability. All you need to do is to prove the trace in the related method. A list of code position + information to be shown for that position

to be continued...

Clone this wiki locally