GithubHelp home page GithubHelp logo

ast-info-plugin's Introduction

AST Info plugin

Author - Dmitrii Abramov.

This plugin shows AST of selected code fragment and following statistics:

  • Number of variable declarations inside selection
  • Number of read variable accesses in selection
  • Number of exceptions which may be thrown during execution of selected fragment

screenshot

Usage

The easiest way to run the plugin is:
./gradlew runIde

To display AST and info for selection:

  1. Select some code in editor.
  2. Press AST Info button under AST Info menu-bar entry.
  3. Tool Window with AST and statistics will appear.
  4. To see info for another code fragment: GOTO 1.

Implementation Details

Plugin uses ToolWindow from Intellij API to present it's UI.

Internal Intellij AST representation - PSI (Program Structure Interface) is used to present tree structure in plugin.

AST by selection

Algorithm:

  • Retrieve nodes of AST which correspond to begin and end of the selection.
  • Find lowest common ancestor for begin and end node.
  • If all ancestor children intersect with selection, return the subtree with root in ancestor.
  • Otherwise the list of subtrees with roots in each ancestor child which intersects with the selection is returned.

Statistics by selection

Considering variable as local variable or field.

Declarations

Visiting all nodes in AST corresponding to selection and counting all variable and field declaration nodes.

Usages

Visiting all nodes in AST corresponding to selection and counting all Reference Expression nodes which are read access (i.e. this reference is not on the left of assignment operator).

Exceptions

Here I reused functionality of Intellij API (method com.intellij.codeInsight.ExceptionUtil::getThrownExceptions).

It traverses AST and processes all function calls and gets all exceptions from their function declaration throws list.

Also it processes all throw expressions and try statements (for try statement it correctly doesn't count exceptions which are catch by catch close).

ast-info-plugin's People

Contributors

karvozavr avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.