Skip to content

Commit

Permalink
Elixir is revised (SpoonLabs#195)
Browse files Browse the repository at this point in the history
* JKali revised and fixed

* jkali ground-truth testing updated

* ground-truth tests added

* pattern used in ground-truth testing are saved into an object

* patterns and filters checked and fixed

* elixir is tested

* elixir revised and tested

* FinalResult is logged at debug level

* travis output is shortened

* using null-output instead of empty-output

* ignoring arja and nopol ground tests for now
  • Loading branch information
khaes-kth authored and martinezmatias committed Nov 21, 2019
1 parent eeff21e commit 0eeed95
Show file tree
Hide file tree
Showing 47 changed files with 757 additions and 1,903 deletions.
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>coming</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install: true

# this is where all tests are executed
script:
- mvn test
- mvn test -Dexecuted_by_travis=true
- find . -name "*.json"

after_success:
Expand Down
45 changes: 25 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<!-- DO NOT CHANGE THIS VERSION, VERSION NUMBER IS AUTOMATICALLY HANDLED
IN .buildscript/deploy_to_maven.sh -->
<version>0-SNAPSHOT</version>
<description>Coming</description>
<url>https://github.com/Spirals-Team/coming</url>
<description>Coming</description>
<url>https://github.com/Spirals-Team/coming</url>

<packaging>jar</packaging>
<name>coming-parent</name>
<properties>
Expand Down Expand Up @@ -148,11 +148,11 @@
<version>0.1.3</version>
</dependency>

<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>4.0</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
Expand Down Expand Up @@ -238,6 +238,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>

Expand All @@ -246,18 +251,18 @@
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.inria.coming.core.entities.output;

import org.apache.log4j.Logger;

import fr.inria.coming.changeminer.analyzer.commitAnalyzer.FineGrainDifftAnalyzer;
import fr.inria.coming.changeminer.entity.FinalResult;
import fr.inria.coming.core.entities.RevisionResult;
import fr.inria.coming.core.entities.interfaces.IOutput;
Expand All @@ -10,11 +13,10 @@
*
*/
public class StdOutput implements IOutput {

@Override
public void generateFinalOutput(FinalResult finalResult) {
System.out.println(finalResult);

}

@Override
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/fr/inria/coming/main/ComingMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import fr.inria.coming.core.entities.output.FeaturesOutput;
import fr.inria.coming.core.entities.output.JSonChangeFrequencyOutput;
import fr.inria.coming.core.entities.output.JSonPatternInstanceOutput;
import fr.inria.coming.core.entities.output.NullOutput;
import fr.inria.coming.core.entities.output.StdOutput;
import fr.inria.coming.core.extensionpoints.PlugInLoader;
import fr.inria.coming.core.extensionpoints.changepattern.PatternFileParser;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class ComingMain {

options.addOption(Option.builder("mode").argName("mineinstance | diff | features").hasArg()
.desc("the mode of execution of the analysis").build());

options.addOption(Option.builder("featuretype").argName("S4R | P4J").hasArg()
.desc("the type of feature extraction").build());

Expand Down Expand Up @@ -116,8 +117,8 @@ public class ComingMain {
"If -mode=repairability, this option specifies which repair tools should we consider in our analysis. "
+ "Can be a list separated by " + File.pathSeparator)
.build());
// feature module parameter

// feature module parameter
options.addOption(Option.builder("featuretype").argName("S4R | P4J").hasArg().desc(
"If -mode=features, this option specifies which feature extraction types should we consider in our analysis. "
+ "Can be a list separated by " + File.pathSeparator)
Expand Down Expand Up @@ -218,11 +219,10 @@ public boolean createEngine(String[] args) {
String featureType = ComingProperties.getProperty("featuretype");
String input = ComingProperties.getProperty("input");


// CONFIGURATION:
loadInput(input);

loadModelAnalyzers(mode,featureType);
loadModelAnalyzers(mode, featureType);

loadFilters();

Expand All @@ -245,7 +245,13 @@ private void loadFilters() {
private void loadOutput() {
String outputs = ComingProperties.getProperty("outputprocessor");
if (outputs == null) {
navigatorEngine.getOutputProcessors().add(0, new StdOutput());
if (Boolean.valueOf(System.getProperty("executed_by_travis"))) {
navigatorEngine.getOutputProcessors().add(0, new NullOutput());
System.out.println("****EXECUTED_BY_TRAVIS****");
} else {
navigatorEngine.getOutputProcessors().add(0, new StdOutput());
System.out.println("**NOT_EXECUTED_BY_TRAVIS**");
}
} else {
loadOutputProcessors(outputs);
}
Expand Down Expand Up @@ -292,17 +298,16 @@ private void loadModelAnalyzers(String modes, String featureType) {

} else if ("features".equals(mode)) {
navigatorEngine.getAnalyzers().clear();

navigatorEngine.getAnalyzers().add(new FineGrainDifftAnalyzer());

if ("P4J".equals(featureType)) {
//for P4J:
navigatorEngine.getAnalyzers().add(new P4JFeatureAnalyzer());
// for P4J:
navigatorEngine.getAnalyzers().add(new P4JFeatureAnalyzer());
} else {
//for S4R or by default
navigatorEngine.getAnalyzers().add(new FeatureAnalyzer());
// for S4R or by default
navigatorEngine.getAnalyzers().add(new FeatureAnalyzer());
}


navigatorEngine.getOutputProcessors().add(new FeaturesOutput());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.inria.coming.core.entities.RevisionResult;
import fr.inria.coming.main.ComingProperties;
import fr.inria.coming.repairability.repairtools.AbstractRepairTool;
import gumtree.spoon.diff.Diff;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -84,7 +85,7 @@ public AnalysisResult analyze(IRevision input, RevisionResult previousResults) {
}
}

patternInstanceList = filterResult(patternInstanceList);
patternInstanceList = filterResult(patternInstanceList, instancesPerDiff.getDiff());

// this PatternInstancesFromDiff contains only filtered elements
allInstances.add(new PatternInstancesFromDiff(
Expand All @@ -99,7 +100,7 @@ public AnalysisResult analyze(IRevision input, RevisionResult previousResults) {
return finalResult;
}

private List<ChangePatternInstance> filterResult(List<ChangePatternInstance> patternInstanceList) {
private List<ChangePatternInstance> filterResult(List<ChangePatternInstance> patternInstanceList, Diff diff) {
List<ChangePatternInstance> res = new ArrayList<>();
Map<String, List> toolToInstances = new HashMap<>();
for(ChangePatternInstance instance : patternInstanceList){
Expand All @@ -112,7 +113,7 @@ private List<ChangePatternInstance> filterResult(List<ChangePatternInstance> pat
String toolName = entry.getKey();
List<ChangePatternInstance> instances = entry.getValue();
AbstractRepairTool tool = RepairTools.getRepairToolInstance(toolName);
res.addAll(tool.filterSelectedInstances(instances));
res.addAll(tool.filterSelectedInstances(instances, diff));
}
return res;
}
Expand Down
96 changes: 96 additions & 0 deletions src/main/java/fr/inria/coming/repairability/models/ASTData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package fr.inria.coming.repairability.models;

import fr.inria.coming.utils.ASTInfoResolver;
import spoon.reflect.code.*;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtVariable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ASTData {
private static final String NAME_SEPARATOR = "###";

private Set<String> executableInvocations;
private Set<String> variablesAndLiterals;

public ASTData(CtElement rootNode) {
executableInvocations = new HashSet<>();
variablesAndLiterals = new HashSet<>();

List<CtElement> allElements = rootNode.getElements(null);
for (CtElement element : allElements) {
if (element instanceof CtAbstractInvocation) {
executableInvocations.add(getExecutableQualifiedSignature(element));
} else if (element instanceof CtVariableAccess || element instanceof CtLiteral) {
variablesAndLiterals.add(ASTInfoResolver.getCleanedName(element));
} else if (element instanceof CtMethod) {
executableInvocations.add(getExecutableQualifiedSignature(element));
} else if (element instanceof CtVariable) {
variablesAndLiterals.add(((CtVariable) element).getReference().toString());
}
}
}

public boolean canElixirGenerateNode(CtElement mappedElement, CtElement newNode) {
Set<String> validInvocationsAsArguments = new HashSet<>();
if (mappedElement != null && mappedElement instanceof CtAbstractInvocation) {
List<CtExpression> arguments = ((CtAbstractInvocation) mappedElement).getArguments();
for (CtExpression argument : arguments) {
if (argument instanceof CtAbstractInvocation) {
validInvocationsAsArguments.add(argument.toString());
}
}
}
if (newNode instanceof CtAbstractInvocation) {
if (!executableInvocations.contains(getExecutableQualifiedSignature(newNode)))
return false;
List<CtExpression> arguments = ((CtAbstractInvocation) newNode).getArguments();
for (CtExpression argument : arguments) {
if (argument.toString().equals("null"))
continue;
if (validInvocationsAsArguments.contains(argument.toString()))
continue;
if (!(argument instanceof CtVariableAccess || argument instanceof CtLiteral)
|| !variablesAndLiterals.contains(ASTInfoResolver.getCleanedName(argument))) {
return false;
}
}
return true;
} else if (newNode instanceof CtVariableAccess || newNode instanceof CtLiteral) {
return variablesAndLiterals.contains(ASTInfoResolver.getCleanedName(newNode));
}
return false;
}

private String getExecutableQualifiedSignature(CtElement element) {
if (element instanceof CtAbstractInvocation) {
CtAbstractInvocation invocation = (CtAbstractInvocation) element;
return invocation.getExecutable().getDeclaringType() == null ? "null" : invocation.getExecutable().getDeclaringType().toString()
+ NAME_SEPARATOR + invocation.getExecutable().getSignature();
} else if (element instanceof CtMethod) {
CtMethod method = (CtMethod) element;
return method.getDeclaringType().getQualifiedName().toString() + NAME_SEPARATOR + method.getSignature();
}

return null;
}

public Set<String> getExecutableInvocations() {
return executableInvocations;
}

public void setExecutableInvocations(Set<String> executableInvocations) {
this.executableInvocations = executableInvocations;
}

public Set<String> getVariablesAndLiterals() {
return variablesAndLiterals;
}

public void setVariablesAndLiterals(Set<String> variablesAndLiterals) {
this.variablesAndLiterals = variablesAndLiterals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fr.inria.coming.changeminer.analyzer.instancedetector.ChangePatternInstance;
import fr.inria.coming.changeminer.analyzer.patternspecification.ChangePatternSpecification;
import fr.inria.coming.changeminer.entity.IRevision;
import fr.inria.coming.utils.EntityTypesInfoResolver;
import fr.inria.coming.utils.ASTInfoResolver;
import gumtree.spoon.diff.Diff;
import gumtree.spoon.diff.operations.Operation;
import spoon.reflect.declaration.CtElement;
Expand Down Expand Up @@ -100,7 +100,7 @@ public String getPathFromResources(String name) {
}

public boolean coversTheWholeDiff(ChangePatternInstance instancePattern, Diff diff) {
Set<CtElement> instanceNodes = getInstanceCoveredNodes(instancePattern);
Set<CtElement> instanceNodes = getInstanceCoveredNodes(instancePattern, diff);
for (Operation diffOperation : diff.getRootOperations()) {
boolean found = coveredByInstanceNodes(instancePattern, instanceNodes, diffOperation);
if(found == false)
Expand All @@ -127,7 +127,7 @@ public boolean coversTheWholeDiff(ChangePatternInstance instancePattern, Diff di
CtElement node
) {
List<CtElement> pathToDiffRoot =
EntityTypesInfoResolver.getPathToRootNode(node);
ASTInfoResolver.getPathToRootNode(node);
for(CtElement element : pathToDiffRoot){
for(CtElement instanceNode : instanceCoveredNodes) {
if (element == instanceNode)
Expand All @@ -138,13 +138,13 @@ public boolean coversTheWholeDiff(ChangePatternInstance instancePattern, Diff di
}

// the abstract implementation only returns nodes in the Dst AST.
protected Set<CtElement> getInstanceCoveredNodes(ChangePatternInstance instance) {
protected Set<CtElement> getInstanceCoveredNodes(ChangePatternInstance instance, Diff diff) {
return instance.getActions().stream()
.map(action -> (action.getDstNode() != null ? action.getDstNode() : action.getSrcNode()))
.collect(Collectors.toSet());
}

public List<ChangePatternInstance> filterSelectedInstances(List<ChangePatternInstance> lst){
public List<ChangePatternInstance> filterSelectedInstances(List<ChangePatternInstance> lst, Diff diff){
return lst;
}
}
Loading

0 comments on commit 0eeed95

Please sign in to comment.