Pages

Tuesday, October 30, 2012

JPF Configuration

Screen Shot 2012 10 30 at 5 06 55 PM
java -jar jpf/jpf-core/build/RunJPF.jar +shell.port=4242 A.jpf -v
http://javapathfinder.sourceforge.net/Configuring_JPF_Runtime_Options.html

Java Path Finder tutorial

Screen Shot 2012 10 30 at 4 59 11 PM https://dl.dropbox.com/u/10773282/papers/2012/JPF-lecture-2.pdf http://fm.csl.sri.com/SSFT11/JPF-lecture-2.pdf

Executing eclipse rename refactoring using LTK

With eclipse, one can use Language Tool Kit (LTK). This is an example of how to execute rename refactoring with the LTK API.

Finding a project

IProject is an interface to refer the Project object, and the project can be found using this code.
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(PROJECT_NAME);
project.open(null /* IProgressMonitor */);

Finding class

Then, we can find the class(IType), and from the type we can get CompilationUnit.
IJavaProject javaProject = JavaCore.create(project);
IType itype = javaProject.findType("smcho.NewName");
org.eclipse.jdt.core.ICompilationUnit icu = itype.getCompilationUnit();

Getting contribution and descriptor

We're renaming a class, so we use getRefactoringContribution() to get contribution, and from the contribution we can get the descriptor.
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_COMPILATION_UNIT);
RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) contribution.createDescriptor();
Then, you need to set the name of the project, new class name, and CompilationUnit.
descriptor.setProject(icu.getResource().getProject().getName( ));
descriptor.setNewName(NEW_CLASS_NAME); // new name for a Class
descriptor.setJavaElement(icu);

Executing the refactoring

One starts with the status and monitor. With them check initial and final conditions. And finally create change object and perform with a parameter monitor.
RefactoringStatus status = new RefactoringStatus();
try {
    Refactoring refactoring = descriptor.createRefactoring(status);

    IProgressMonitor monitor = new NullProgressMonitor();
    refactoring.checkInitialConditions(monitor);
    refactoring.checkFinalConditions(monitor);
    Change change = refactoring.createChange(monitor);
    change.perform(monitor);
} catch (CoreException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}    

The renameRefactor() method

Combining all of them, one can have this method to refactor from oldName to newName in the projeceName.
public void renameRefactor(String projectName, String oldName, String newName) throws CoreException
{
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    project.open(null /* IProgressMonitor */);
    
    IJavaProject javaProject = JavaCore.create(project);
    IType itype = javaProject.findType(oldName); // you need to include the package name also "smcho.NewName" 
    org.eclipse.jdt.core.ICompilationUnit icu = itype.getCompilationUnit();

    RefactoringContribution contribution =
                RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_COMPILATION_UNIT);
    RenameJavaElementDescriptor descriptor =
                (RenameJavaElementDescriptor) contribution.createDescriptor();
    descriptor.setProject(icu.getResource().getProject().getName( )); // maybe, you can just use the String
    descriptor.setNewName(newName); // new name for a Class
    descriptor.setJavaElement(icu);

    RefactoringStatus status = new RefactoringStatus();
    try {
        Refactoring refactoring = descriptor.createRefactoring(status);

        IProgressMonitor monitor = new NullProgressMonitor();
        refactoring.checkInitialConditions(monitor);
        refactoring.checkFinalConditions(monitor);
        Change change = refactoring.createChange(monitor);
        change.perform(monitor);

    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }        
}

Monday, October 29, 2012

Algorithm package of LaTeX

\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\subsubsection{group 1 : rename/move}
\begin{algorithm}
\caption{Euclid's algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
   \State $r\gets a\bmod b$
   \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
   \EndWhile\label{euclidendwhile}
   \State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
Screen Shot 2012 10 29 at 10 02 37 PM

Algorithm2e package of LaTeX

\usepackage[ruled,vlined]{algorithm2e}

\begin{algorithm}
 \SetAlgoLined
 \KwData{this text}
 \KwResult{how to write algorithm with \LaTeX2e }
 initialization\;
 \While{not at end of this document}{
  read current\;
  \eIf{understand}{
   go to next section\;
   current section becomes this one\;
   }{
   go back to the beginning of current section\;
  }
 }
 \caption{How to write algorithms}
\end{algorithm}
Screen Shot 2012 10 29 at 10 00 07 PM

References

  1. http://www.tex.ac.uk/tex-archive/macros/latex/contrib/algorithm2e/algorithm2e.pdf
  2. Algorithms in Latex

Adding local git repository to remote server

When you have a remote repository in bitbucket, you need to push the local repository for the first time.
You can use git remote add "BRANCH", to add the branch, and then push it.
git remote add origin ssh://git@bitbucket.org/smcho/refactoringvalidatorpaper.git
git push -u origin master   # to push changes for the first time

After this, you'll find that the config file in .git has the new section.
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
[remote "origin"]
	url = ssh://git@bitbucket.org/smcho/refactoringvalidatorpaper.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

Writing a paper with LaTeX

Writing a paper accompanies bibliography, and it makes the $latex:\LaTeX$ compilation process a little more complicated.
In short, one needs to three LaTeX compilation, and one bibtex compilation.
latex refvalidator.tex
bibtex refvalidator
latex refvalidator.tex
latex refvalidator.tex # resolve all the references
dvipdfmx refvalidator.dvi
You can use \cite{} for citation, and you can have the bibliography style and bibliography for correct referencing.
You don't need \section as it will be generated automatically.
\bibliographystyle{abbrv}
\bibliography{refvalidator}