Vesper

Vesper: Code transformation utilities

Vesper is Vesperin’s curation library for parsing, manipulating, and reconstructing Java code. Vesper is built atop Eclipse’s JDT Java Parser and AST/DOM transformation utilities. This mechanism allows Vesperin to work with partial and non-compiling programs, not just complete ones.

The following code shows how one can start using the Vesper library.

import static edu.ucsc.refactor.ChangeRequest.forIssue;
import static edu.ucsc.refactor.ChangeRequest.reformatSource;

final Source  code  = new Source(...);
// using your own configuration:
// refactorer = Vesper.createRefactorer(new MyConfiguration());
// using default configuration
final Refactorer  refactorer = Vesper.createRefactorer();

final Map<String, Parameter>  userInput = ...;

// I. Ask the Refactorer to recommend changes for you

// print the reason for the change
final Introspector introspector = Vesper.createIntrospector();
final Set<Issue>  issues = introspector.detectIssues(code);
final List<Change>  changes = Recommender.recommendChanges(
	refactorer, 
	code, 
	issues
);

for(Change each : changes){
   System.out.println(each.getCause().getName());
}

// perform a single recommended change

final Commit applied = refactor.apply(changes.get(0));
System.out.println(applied.more());

// or handle All recommended changes

List<Change>  recommended = Recommender.recommendChanges(
	refactorer, 
	code, 
	issues
);

while(!recommended.isEmpty()){
    final Commit applied = refactor.apply(recommended.get(0));
    System.out.println(applied.more());
    final Introspector introspector = Vesper.createIntrospector();
    final Set  badStuff = introspector.detectIssues(code);
    recommended = Recommender.recommendChanges(
			refactorer, 
			code, 
			badStuff
		); // get an updated list of changes
}


// II. Dealing with random edits started by the user

// reformat Source's content

Change reformat = refactorer.createChange(reformatSource(code));
final Commit applied = refactor.apply(reformat);
System.out.println(applied.more());
  

Vesper’s code is available here.