Skip to content

methods in JTD will be analysed (bugfix) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 129 additions & 162 deletions src/mujava/op/JTD.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*/
package mujava.op;

import java.io.*;
Expand All @@ -22,177 +22,144 @@

/**
* <p>Generate JTD (Java-specific this keyword deletion) --
* delete each occurrence of the keyword <i>this</i>
* delete each occurrence of the keyword <i>this</i>
* </p>
* @author Yu-Seung Ma
* @version 1.0
*/

public class JTD extends mujava.op.util.Mutator
{
Vector instanceVar = new Vector();
Vector localVar = new Vector();
boolean isJTDTarget = false;

public JTD(FileEnvironment file_env, ClassDeclaration cdecl, CompilationUnit comp_unit)
{
super( file_env, comp_unit );
}

public void visit( AssignmentExpression p ) throws ParseTreeException
*/

public class JTD extends mujava.op.util.Mutator {
Vector instanceVar = new Vector();
Vector localVar = new Vector();
boolean isJTDTarget = false;

public JTD(FileEnvironment file_env, ClassDeclaration cdecl, CompilationUnit comp_unit) {
super(file_env, comp_unit);
}
/*
public void visit( AssignmentExpression p ) throws ParseTreeException
{
System.err.println("Assign");
Expression newp = this.evaluateDown( p );
if (newp != p)
if (newp != p)
{
System.err.println("newp != p (1)");
p.replace( newp );
return;
}

p.childrenAccept( this );
newp = this.evaluateUp( p );
if (newp != p)
if (newp != p) {
System.err.println("newp != p (2)");
p.replace( newp );
}

boolean isTarget( Parameter p ) throws ParseTreeException
{
for (int i=0; i<instanceVar.size(); i++)
{
String field_name = instanceVar.get(i).toString();
if (field_name.equals(p.getVariable()))
{
localVar.add(p.getVariable());
return true;
}
}
return false;
}

public void visit( FieldDeclaration p ) throws ParseTreeException
{
instanceVar.add(p.getName());
}

public void visit( ConstructorDeclaration p ) throws ParseTreeException
{
ParameterList plist = p.getParameters();
localVar.removeAllElements();
for (int i=0; i<plist.size(); i++)
{
if (isTarget(plist.get(i)))
{
isJTDTarget = true;
}
}
if (isJTDTarget)
{
super.visit(p);
}
isJTDTarget = false;
}

public void visit( MethodDeclaration p ) throws ParseTreeException
{
ParameterList plist = p.getParameters();
localVar.removeAllElements();
for (int i=0; i<plist.size(); i++)
{
if (isTarget(plist.get(i)))
{
isJTDTarget = true;
}
}
if (isJTDTarget)
{
super.visit(p);
}
isJTDTarget = false;
}

public void visit( FieldAccess p ) throws ParseTreeException
{
Expression ref_exp = p.getReferenceExpr();
String var_name = p.getName();
if (ref_exp instanceof SelfAccess)
{
if (((SelfAccess)ref_exp).getAccessType() == SelfAccess.THIS)
{
for (int i=0; i<localVar.size(); i++)
{
if (var_name.equals(localVar.get(i).toString()))
{
FieldAccess mutant = (FieldAccess)p.makeRecursiveCopy();
mutant.setReferenceExpr(null);
outputToFile(p, mutant);
}
}
}
}
}

/**
* Output JTD mutants to files
* @param original
* @param mutant
*/
public void outputToFile(FieldAccess original, FieldAccess mutant)
{
if (comp_unit == null)
return;

String f_name;
num++;
f_name = getSourceName(this);
String mutant_dir = getMuantID();

try
{
PrintWriter out = getPrintWriter(f_name);
ISK_JTD_Writer writer = new ISK_JTD_Writer(mutant_dir, out);
writer.setMutant(original, mutant);
comp_unit.accept( writer );
out.flush();
out.close();
} catch ( IOException e )
{
System.err.println( "fails to create " + f_name );
} catch ( ParseTreeException e )
{
System.err.println( "errors during printing " + f_name );
e.printStackTrace();
}
}

/**
* Output JTD mutants to files
* @param original
* @param mutant
*/
public void outputToFile(MethodCall original, MethodCall mutant)
{
if (comp_unit == null)
return;

String f_name;
num++;
f_name = getSourceName(this);
String mutant_dir = getMuantID();

try
{
PrintWriter out = getPrintWriter(f_name);
ISK_JTD_Writer writer = new ISK_JTD_Writer(mutant_dir, out);
writer.setMutant(original, mutant);
comp_unit.accept( writer );
out.flush();
out.close();
} catch ( IOException e )
{
System.err.println( "fails to create " + f_name );
} catch ( ParseTreeException e )
{
System.err.println( "errors during printing " + f_name );
e.printStackTrace();
}
}
}
}*/

void addTarget(Parameter p) throws ParseTreeException {
// add parameter to local list, iff exists a instance variable with the same name
for (int i = 0; i < instanceVar.size(); i++) {
String field_name = instanceVar.get(i).toString();
if (field_name.equals(p.getVariable())) {
localVar.add(p.getVariable());
}
}
}

public void visit(FieldDeclaration p) throws ParseTreeException {
instanceVar.add(p.getName());
}
public void visit(VariableDeclaration p) throws ParseTreeException {
localVar.add(p.getVariable());
}

public void visit(ConstructorDeclaration p) throws ParseTreeException {
ParameterList plist = p.getParameters();
localVar.removeAllElements();
for (int i = 0; i < plist.size(); i++) {
addTarget(plist.get(i));
}
super.visit(p);
}

public void visit(MethodDeclaration p) throws ParseTreeException {
ParameterList plist = p.getParameters();
localVar.removeAllElements();
for (int i = 0; i < plist.size(); i++) {
addTarget(plist.get(i));
}
super.visit(p);
}

public void visit(FieldAccess p) throws ParseTreeException {
Expression ref_exp = p.getReferenceExpr();
String var_name = p.getName();
if (ref_exp instanceof SelfAccess) {
if (((SelfAccess) ref_exp).getAccessType() == SelfAccess.THIS) {
for (int i = 0; i < localVar.size(); i++) {
if (var_name.equals(localVar.get(i).toString())) {
FieldAccess mutant = (FieldAccess) p.makeRecursiveCopy();
mutant.setReferenceExpr(null);
outputToFile(p, mutant);
}
}
}
}
}

/**
* Output JTD mutants to files
* @param original
* @param mutant
*/
public void outputToFile(FieldAccess original, FieldAccess mutant) {
if (comp_unit == null) return;

String f_name;
num++;
f_name = getSourceName(this);
String mutant_dir = getMuantID();

try {
PrintWriter out = getPrintWriter(f_name);
ISK_JTD_Writer writer = new ISK_JTD_Writer(mutant_dir, out);
writer.setMutant(original, mutant);
comp_unit.accept(writer);
out.flush();
out.close();
} catch (IOException e) {
System.err.println("fails to create " + f_name);
} catch (ParseTreeException e) {
System.err.println("errors during printing " + f_name);
e.printStackTrace();
}
}

/**
* Output JTD mutants to files
* @param original
* @param mutant
*/
public void outputToFile(MethodCall original, MethodCall mutant) {
if (comp_unit == null) return;

String f_name;
num++;
f_name = getSourceName(this);
String mutant_dir = getMuantID();

try {
PrintWriter out = getPrintWriter(f_name);
ISK_JTD_Writer writer = new ISK_JTD_Writer(mutant_dir, out);
writer.setMutant(original, mutant);
comp_unit.accept(writer);
out.flush();
out.close();
} catch (IOException e) {
System.err.println("fails to create " + f_name);
} catch (ParseTreeException e) {
System.err.println("errors during printing " + f_name);
e.printStackTrace();
}
}
}