Skip to content
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

SBFL_improvemment #76

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions com.gzoltar.cli.examples/src/org/gzoltar/examples/javaAST.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;

import java.io.File;
import java.io.FileInputStream;

public class JavaASTExample {

public static void main(String[] args) throws Exception {
// Path to the Java file you want to parse
FileInputStream in = new FileInputStream(new File("/CharacterCounter.java"));

// Parse the file
CompilationUnit cu = JavaParser.parse(in);

// Visit and print the AST
cu.accept(new VoidVisitorAdapter<Void>() {
@Override
public void visit(CompilationUnit n, Void arg) {
super.visit(n, arg);
System.out.println(n.toString());
}
}, null);
}
}
5 changes: 5 additions & 0 deletions com.gzoltar.cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<artifactId>classgraph</artifactId>
<version>4.8.160</version>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class FaultLocalizationReport extends AbstractReport {
required = false)
private String formula = SFLFormulas.OCHIAI.name();

@Option(name = "--improveMultiplication", usage = "multiplication to improve general score", metaVar = "<improveMultiplication>", required = false)
private Boolean improveMultiplication = false;

@Option(name = "--metric", usage = "fault localization ranking metric (use ':' to define more than one metric)", metaVar = "<metric>",
required = false)
private String metric = Metric.AMBIGUITY.name();
Expand Down Expand Up @@ -98,6 +101,7 @@ protected void generateReport(final Locale locale) throws Exception {
this.agentConfigs.setInclDeprecatedMethods(this.inclDeprecatedMethods);
this.agentConfigs.setIncludes(this.includes);
this.agentConfigs.setExcludes(this.excludes);
this.agentConfigs.setImproveMultiplication(this.improveMultiplication);

final ConfigFaultLocalizationFamily configFlFamily = new ConfigFaultLocalizationFamily();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ public final class AgentConfigs {

public static final InstrumentationLevel DEFAULT_INSTRUMENTATION_LEVEL = InstrumentationLevel.FULL;

/**
* Specifies whether to use the improvement multiplication. Default is <code>false</code>.
*/
public static final String IMPROVEMULTIPLICATION_KEY = "improveMultiplication";

public static final boolean DEFAULT_IMPROVEMULTIPLICATION = false;

private final Map<String, String> configs;

private static final Collection<String> VALID_CONFIGS =
Expand Down Expand Up @@ -441,7 +448,7 @@ public Boolean getInclStaticConstructors() {
/**
* Sets whether public static constructors should be instrumented.
*
* @param inclPublicMethods <code>true</code> if public static constructors should be instrumented
* @param inclStaticConstructors <code>true</code> if public static constructors should be instrumented
*/
public void setInclStaticConstructors(final boolean inclStaticConstructors) {
this.setConfig(INCLSTATICCONSTRUCTORS_KEY, inclStaticConstructors);
Expand All @@ -466,6 +473,24 @@ public void setInclDeprecatedMethods(final boolean inclDeprecatedMethods) {
this.setConfig(INCLDEPRECATEDMETHODS_KEY, inclDeprecatedMethods);
}

/**
* Returns whether the improvement multiplication should be executed.
*
* @return <code>true</code> if improvement multiplication should be executed
*/
public Boolean getImproveMultiplication() {
return this.getConfig(IMPROVEMULTIPLICATION_KEY, DEFAULT_IMPROVEMULTIPLICATION);
}

/**
* Sets whether improve multiplication should be executed.
*
* @param improveMultiplication <code>true</code> if improvement multiplication should be executed
*/
public void setImproveMultiplication(final boolean improveMultiplication) {
this.setConfig(IMPROVEMULTIPLICATION_KEY, improveMultiplication);
}

/**
* Returns which instrumentation level should be performed.
*
Expand Down
68 changes: 30 additions & 38 deletions com.gzoltar.core/src/main/java/com/gzoltar/core/model/Node.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2020 GZoltar contributors.
*
*
* This file is part of GZoltar.
*
*
* GZoltar is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
*
* GZoltar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License along with GZoltar. If
* not, see <https://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -42,8 +42,9 @@ public class Node {

private Map<String, Double> suspiciousnessValues = null;


/**
*
*
* @param name
* @param lineNumber
* @param type
Expand All @@ -53,7 +54,7 @@ public Node(final String name, final int lineNumber, final boolean startBlock, f
}

/**
*
*
* @param name
* @param type
* @param parent
Expand All @@ -67,23 +68,23 @@ public Node(final String name, final int lineNumber, final boolean startBlock, f
}

/**
*
*
* @return
*/
public String getName() {
return this.name;
}

/**
*
*
* @param name
*/
public void setName(final String name) {
this.name = name;
}

/**
*
*
* @return
*/
public String getShortName() {
Expand All @@ -96,64 +97,64 @@ public String getShortName() {
}

/**
*
*
* @return
*/
public String getNameWithLineNumber() {
return this.getName()
+ (this.type != NodeType.LINE ? NodeType.LINE.getSymbol() + this.lineNumber : "");
+ (this.type != NodeType.LINE ? NodeType.LINE.getSymbol() + this.lineNumber : "");
}

/**
*
*
* @return
*/
public int getLineNumber() {
return this.lineNumber;
}

/**
*
*
* @return
*/
public NodeType getNodeType() {
return this.type;
}

/**
*
*
* @param type
*/
public void setNodeType(final NodeType type) {
this.type = type;
}

/**
*
*
* @return
*/
public boolean isStartBlock() {
return this.startBlock;
}

/**
*
*
* @param startBlock
*/
public void setStartBlock(final boolean startBlock) {
this.startBlock = startBlock;
}

/**
*
*
* @return
*/
public int getDepth() {
return this.depth;
}

/**
*
*
* @param parent
*/
public void setParent(Node parent) {
Expand All @@ -170,31 +171,31 @@ public void setParent(Node parent) {
}

/**
*
*
* @return
*/
public Node getParent() {
return this.parent;
}

/**
*
*
* @return
*/
public boolean isRoot() {
return this.parent == null;
}

/**
*
*
* @return
*/
public List<Node> getChildren() {
return new ArrayList<Node>(this.children.values());
}

/**
*
*
* @param name
* @return
*/
Expand All @@ -203,7 +204,7 @@ public Node getChild(final String name) {
}

/**
*
*
* @param type
* @return
*/
Expand All @@ -217,15 +218,15 @@ public boolean hasChildrenOfType(final NodeType type) {
}

/**
*
*
* @return
*/
public boolean isLeaf() {
return this.children.isEmpty();
}

/**
*
*
* @return
*/
public List<Node> getLeafNodes() {
Expand All @@ -245,7 +246,7 @@ private void getLeafNodes(final List<Node> nodes) {
}

/**
*
*
* @param formulaName
* @param suspiciousnessValue
*/
Expand All @@ -257,7 +258,7 @@ public void addSuspiciousnessValue(String formulaName, Double suspiciousnessValu
}

/**
*
*
* @return
*/
public boolean hasSuspiciousnessValues() {
Expand All @@ -268,15 +269,15 @@ public boolean hasSuspiciousnessValues() {
}

/**
*
*
* @return
*/
public Map<String, Double> getSuspiciousnessValues() {
return this.suspiciousnessValues;
}

/**
*
*
* @param formulaName
* @return
*/
Expand All @@ -293,15 +294,6 @@ public Double getSuspiciousnessValue(String formulaName) {
return this.suspiciousnessValues.get(formulaName);
}

/**
*
* @return
*/
public int getNumberOfSuspiciousnessValues() {
assert this.suspiciousnessValues != null;
return this.suspiciousnessValues.size();
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ISpectrum diagnose(final String buildLocation, final AgentConfigs agentCo
FilteredSpectrum filter = new FilteredSpectrum(agentConfigs);
ISpectrum filteredSpectrum = filter.filter(spectrum);

this.fl.diagnose(filteredSpectrum);
this.fl.diagnose(filteredSpectrum, agentConfigs.getImproveMultiplication());

return filteredSpectrum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public interface IFaultLocalization<F extends IFormula> {
*
* @param spectrum a {@link com.gzoltar.core.spectrum.ISpectrum} object
*/
public void diagnose(final ISpectrum spectrum);
public void diagnose(final ISpectrum spectrum, boolean improveMultiplication);
}
2 changes: 1 addition & 1 deletion com.gzoltar.fl/src/main/java/com/gzoltar/fl/IFormula.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IFormula {
*
* @param spectrum
*/
public void diagnose(final ISpectrum spectrum);
public void diagnose(final ISpectrum spectrum, boolean improveMultiplication);

/**
* Returns the name of the SBL formula
Expand Down
4 changes: 2 additions & 2 deletions com.gzoltar.fl/src/main/java/com/gzoltar/sfl/SFL.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public SFL(final List<F> sflFormulas) {
/**
* {@inheritDoc}
*/
public void diagnose(final ISpectrum spectrum) {
public void diagnose(final ISpectrum spectrum, boolean improveMultiplication) {
for (F formula : this.formulas) {
formula.diagnose(spectrum);
formula.diagnose(spectrum, improveMultiplication);
}
}
}
Loading