Mining Source Code to Automatically Split Identifiers for Software Analysis

Mining Source Code to Automatically Split Identifiers for Software Analysis

Mining Source Code to Automatically Split Identifiers for Software Analysis ∗ Eric Enslen, Emily Hill, Lori Pollock and K. Vijay-Shanker Department of Computer and Information Sciences University of Delaware Newark, DE 19716 USA fenslen, hill, pollock, [email protected] Abstract concepts and actions in terms of program structure, and helps to convey the intent and application domain concepts Automated software engineering tools (e.g., program to human readers through identifier names and comments. search, concern location, code reuse, quality assessment, Thus, many of the program search, concern location, code etc.) increasingly rely on natural language information reuse, and quality assessment tools for software engineers from comments and identifiers in code. The first step in are based on analyzing the words that programmers use in analyzing words from identifiers requires splitting identi- comments and identifiers. fiers into their constituent words. Unlike natural languages, Maintenance tools that analyze comments and identi- where space and punctuation are used to delineate words, fiers frequently rely on first automatically identifying the identifiers cannot contain spaces. One common way to individual words comprising the identifiers. Unlike nat- split identifiers is to follow programming language nam- ural languages, where space and punctuation are used to ing conventions. For example, Java programmers often use delineate words, identifiers cannot contain spaces. Often, camel case, where words are delineated by uppercase let- programmers create identifiers with multiple words, called ters or non-alphabetic characters. However, programmers multi-word identifiers, to name the entity they want to repre- also create identifiers by concatenating sequences of words sent (e.g., toString, ASTVisitorTree, newValidatingXML- together with no discernible delineation, which poses chal- InputStream, jLabel6, buildXMLforComposite). lenges to automatic identifier splitting. To split multi-word identifiers, most existing automatic In this paper, we present an algorithm to automatically software analysis tools that use natural language informa- split identifiers into sequences of words by mining word fre- tion rely on coding conventions [1, 10, 11, 13, 14, 15, 20]. quencies in source code. With these word frequencies, our When simple coding conventions such as camel casing and identifier splitter uses a scoring technique to automatically non-alphabetic characters (e.g., ‘ ’ and numbers) are used select the most appropriate partitioning for an identifier. to separate words and abbreviations, automatically split- In an evaluation of over 8000 identifiers from open source ting multi-word identifiers into their constituent words is Java programs, our Samurai approach outperforms the ex- straightforward. However, there are cases where existing isting state of the art techniques. coding conventions break down (e.g., DAYSforMONTH, GPSstate, SIMPLETYPENAME). Techniques to automatically split multi-word identifiers 1. Introduction into their constituent words can improve the effectiveness of a variety of natural language-based software maintenance tools. In program search, information retrieval (IR) tech- Today’s large, complex software systems require auto- niques are preferred over regular expression based tech- matic software analysis and recommendation systems to niques because IR better captures the lexical concepts and help the software engineer complete maintenance tasks ef- can order the search results based on document relevance. fectively and efficiently. The software maintainer must gain However, IR techniques will miss occurrences of concepts at least partial understanding of the concepts represented if identifiers are not split. Similarly, incorrect splitting can by, and the programmer’s intent in, existing source code decrease the accuracy of program search. before making modifications. A programmer codes the Consider searching for a feature that adds a text field to ∗This material is based upon work supported by the National Science a report in a GUI-based report processing system. In the Foundation Grant No. CCF-0702401. implementation, the developers are inconsistent with how 978-1-4244-3493-0/09/$25.00 © 2009 IEEE 71 MSR 2009 the concept of a “text field” is split. The methods responsi- • An experimental evaluation comparing the accuracy of ble for adding the text field to the system uses proper camel our frequency-based approach against the state-of-the- case, addTextField. However, the GUI method responsible art identifier splitting approaches. for initiating the action combines the concept as textfield. Thus, without correct identifier splitting, IR techniques will never return all relevant pieces of code for a single query 2. The Identifier (Token) Splitting Problem (either “text field” or “textfield”). In this example, incorrect multi-word identifier splitting led to inaccuracy in the client Although the motivation for splitting arises from multi- software analysis because the words from incorrectly split word identifiers, splitting can also be applied to string lit- identifiers misrepresent the source code’s lexical semantics. erals and comments. In fact, identifiers frequently appear Other tools that often rely on extracting individual con- in Java doc comments as well as in sections of code that cepts from the words used in the program are concern lo- have been commented. Thus, in this paper, we focus on cation [10, 11, 21, 22, 24, 26], documentation to source splitting tokens, which may be program identifiers or space- code traceability [1, 20, 25], or other software artifact anal- delimited strings appearing in code comments or string lit- yses [2, 4, 5, 7, 12, 14, 23]. In addition to IR techniques, erals. proper identifier splitting can help mine word relations from Token splitting is the problem of partitioning an arbitrary source code, by first extracting the correct individual words token into its constituent concept words, which are typically for analysis. dictionary words and abbreviations. The general form of a In this paper, we present a technique to automatically token is a sequence of letters, digits, and special characters. split identifiers into sequences of words by mining word In addition to using digits and special characters, another frequencies in source code. Our novel identifier splitting common convention for indicating word splits is camel cas- algorithm automatically selects the most appropriate word ing [3, 6, 17, 19]. When using camel case, the first letter partitioning for multi-word identifiers based on a scoring of every word in an identifier is capitalized (thus giving the function. Because our approach requires no predefined dic- identifier the look of a humped camel). Using capital let- tionary, our word partitions are not limited by the words ters to delimit words requires less typing than using spe- known to a manually created dictionary, and can naturally cial characters, while preserving readability. For example, evolve over time as new words and technologies are added parseTable is easier to read than parsetable. to the programmer’s vocabulary. Although initially used to improve readability, camel Our frequency-based approach, Samurai, is capable of casing can also help to split tokens in static analysis tools correctly splitting multi-word identifiers involving camel that use lexical information. However, camel casing is not case in which the straightforward split would be incorrect well-defined in certain situations, and may be modified to (e.g., getWSstring, InitPWforDB, ConvertASCIItoUTF) improve readability. Specifically, no convention exists for and can also split same-case multi-words (e.g., COUN- including acronyms within camel case tokens. For example, TRYCODE, actionparameters). We evaluate the effec- the whole abbreviation may be capitalized, as in Conver- tiveness of our automatic identifier splitting technique by tASCIItoUTF, or just the first letter, as in SqlList. The de- comparing mixed-case splitting with the only other auto- cision depends on the readability of the token. In particular, matic technique, which conservatively splits on division SqlList is arguably more readable than SQLList, and more markers (e.g., camel casing, numbers and special char- closely follows camel case guidelines than SQLlist. Strict acters), and by comparing same-case splitting with the camel casing may be sacrificed for readability, especially state of the art automatic technique by Feild, Binkley, and for prepositions and conjunctions, as in DAYSforMONTH, Lawrie [8]. In an evaluation of over 8000 identifiers from convertCEtoString, or PrintPRandOSError. In some in- open source Java programs, our Samurai approach outper- stances, no delimiters are used for very common multi-word forms the existing state of the art techniques. Although our concepts, such as sizeof or hostname. Thus, although current work focuses on Java programs predominantly writ- camel case conventions exist, different decisions are made ten in English, our approach can be applied to any program- in the interest of readability and faster typing. ming and natural language combination. Since camel case tokens are so easy to parse, pro- The major contributions of this paper are: grammers may not be aware how common they are. In • Detailed analyses of the form of identifiers found in a 330 KLOC program with 44,315 tokens, we observed software and the challenges in automatically splitting 32,817 multi-word tokens. Of this set, 1,856 tokens can- them not be partitioned using

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us