Databases Reference
In-Depth Information
public byte [ ] readToByteArray (InputStream is) {
ByteArrayOutputStream bos =
new
ByteArrayOutputStream ( );
try {
byte [ ] buff = new byte [1024];
int
read = 0;
while ( ( read = is . read ( buff ) > 0) {
bos . write ( buff , 0 , read );
}
return bos . toByteArray ( );
}
catch ( IOException e ) {
return null
;
}
finally
{
close ( is ) ;
}
}
Fig. 11.1 Example snippet
mere existence of reusable source code is not sufficient; developers need a way to
locate it.
Code retrieval systems provide this functionality, giving developers the ability to
search for relevant units of source code within a large corpus of source code. Simple
code retrieval systems use standard text retrieval approaches, in which keyword-
based searches are used to match relevant lines of source code. These approaches
treat the source code as plain text, disregarding all the deeper semantic information
found in source code.
Source code, due to its formal nature, is a much richer source of information
than plain text. Software engineering researchers recognized this, and developed
advanced retrieval techniques that better utilize the semantic information embedded
in source code. Static program analysis provides the backbone of these systems, as
it provides a mechanism for extracting relevant information from the source code.
For the remainder of this chapter, we will use the snippet of source code in
Fig. 11.1 to illustrate techniques for code retrieval. We will begin by introducing
a few basic text retrieval approaches used for code search. We will then describe
how treating source code as structured text, requiring a basic form of static program
analysis, can improve retrieval results. Finally, we will cover link analysis, an ad-
vanced program analysis technique. We will show how links can be extracted from
source code and how they can be used to improve code retrieval. We will also in-
troduce dependency slicing, a link-analysis-based technique for improving search
result presentation.
11.2 Full Text Search
Imagine that a developer is interested in Java's ByteArrayOutputStream ,and
wants to see an example of it being used. Full text search provides an easy way to
Search WWH ::




Custom Search