• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Implementing Refactorings in IntelliJ IDEA
 

Implementing Refactorings in IntelliJ IDEA

on

  • 4,109 views

Presentation on Second ACM Workshop on Refactoring Tools https://netfiles.uiuc.edu/dig/RefactoringInfo/WRT08/

Presentation on Second ACM Workshop on Refactoring Tools https://netfiles.uiuc.edu/dig/RefactoringInfo/WRT08/

Statistics

Views

Total Views
4,109
Views on SlideShare
4,072
Embed Views
37

Actions

Likes
3
Downloads
0
Comments
0

7 Embeds 37

http://www.linkedin.com 13
http://nnmatveev.blogspot.com 12
http://www.slideshare.net 6
http://www.docshut.com 2
https://www.linkedin.com 2
http://nnmatveev.blogspot.com.au 1
http://nnmatveev.blogspot.se 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Implementing Refactorings in IntelliJ IDEA Implementing Refactorings in IntelliJ IDEA Presentation Transcript

    • Implementing Refactorings in IntelliJ IDEA Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/
    • Agenda
      • Demo of new refactoring features
      • Refactoring building blocks
      • Structural search and replace
      • Problems and future directions
    • Agenda
      • Demo of new refactoring features
      • Refactoring building blocks
      • Structural search and replace
      • Problems and future directions
    • Building Blocks
      • Not a set of Lego bricks
      • A workflow framework into which you can plug your code
      • And a set of utility functions and classes to implement the essence of refactoring
      • Every refactoring is somewhat different
    • Lexing and Parsing
      • Lexer converts text into stream of lexems
      • Recursive-descent parser builds PSI (Program Structure Interface) tree
        • Contains all tokens including whitespace
        • Error markers at places of syntax errors
        • Supports high-level semantic operations
        • Supports write operations (add, replace, delete)
    •  
    • References
      • Usages of an element declared elsewhere
      • Can cross languages (e.g. XML to Java)
      • Key operations:
        • Resolve (get declaration by usage)
        • Callbacks on move/rename of target
    • General Refactoring Workflow
      • Show UI for entering options
      • Find usages of target element
      • Check for conflicts (accessibility etc.)
      • Show list of affected usages, allow user to exclude some
      • Modify target element and each usage as appropriate
    • Find Usages
      • Finds all references to PSI element
      • Based on inverted index of all identifiers
      • All words that look like a reference are checked if they indeed resolve to target
    • Code Modification
      • Stub of new element created from text
      • Targets of references in fragment to be moved are remembered
      • Stub contents is replaced with fragment to be moved
      • Modifiers etc. are updated via PSI
      • References are updated so that they point to the same targets
      • Updated fragment is reformatted
    • Formatter
      • Defines a set of constraints on layout of pairs of elements
        • Minimum spacing / line breaks
        • Indentation
        • Alignment
      • Whitespace not violating constraints is preserved
    • Agenda
      • Demo of new refactoring features
      • Refactoring building blocks
      • Structural search and replace
      • Problems and future directions
    • Structural Search
      • QBE interface for navigating and modifying Java and XML/HTML code
        • Code fragment with some variables
        • Constraints for variables
        • Replacement pattern specifying how occurrences should be changed (optional)
      • Allows to perform custom refactoring operations
    • Structural Search Template
    •  
    • Structural Search Problems
      • Very hard to use by non-expert users
      • Patterns are written in a non-obvious way
      • Unintuitive UI
      • Doesn’t cover all operations
      • No façade around internal API for writing scripts
    • Agenda
      • Demo of new refactoring features
      • Refactoring building blocks
      • Structural search and replace
      • Problems and future directions
    • Context Dependence in Java
      • Java language is not uniform
      • Many contexts in which only certain code is allowed
        • Constructors, super constructor calls
        • Enum constants
        • Anonymous classes
        • Initializer blocks
      • Lots of special-case code needed to handle weird context changes
    • Refactoring Quality
      • Users typically don’t review the results of applying an automated refactoring
      • Expect their tool to be 100% correct
      • Solutions which provide 90% correctness with simple implementation aren’t acceptable
      • No way to escape hand-coding corner cases
    •  
    • DSL for Code Transformations
      • If the complexity can’t be avoided, maybe it can be compressed?
      • Desire to replace verbose Java code with a domain-specific language
        • Internal DSL
        • Groovy/Ruby
        • JetBrains MPS
    • Patterns
      • Internal DSL for matching AST fragments
    • Language Independent Refactorings
      • Currently only the basic refactorings (Rename and Move) are mostly language-agnostic
      • All other refactorings are reimplemented from scratch for every new language
      • Desire to extract language-independent essence to common part
    • Summary
      • Refactorings in IntelliJ IDEA involve a lot of complex code with limited reuse
      • Complexity caused by large number of concepts in Java language
      • Necessity of 100% correctness means that complexity is essential
      • Main hope for improvement is building powerful code transformation DSLs
    • Q&A Dmitry Jemerov [email_address]
    • Implementing Refactorings in IntelliJ IDEA Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/