-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEditClassValidation.java
More file actions
132 lines (121 loc) · 5.8 KB
/
EditClassValidation.java
File metadata and controls
132 lines (121 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package org.variantsync.diffdetective.experiments.esecfse22;
import org.variantsync.diffdetective.AnalysisRunner;
import org.variantsync.diffdetective.analysis.Analysis;
import org.variantsync.diffdetective.analysis.FilterAnalysis;
import org.variantsync.diffdetective.analysis.PreprocessingAnalysis;
import org.variantsync.diffdetective.analysis.StatisticsAnalysis;
import org.variantsync.diffdetective.datasets.PatchDiffParseOptions;
import org.variantsync.diffdetective.datasets.Repository;
import org.variantsync.diffdetective.editclass.proposed.ProposedEditClasses;
import org.variantsync.diffdetective.metadata.EditClassCount;
import org.variantsync.diffdetective.mining.formats.DirectedEdgeLabelFormat;
import org.variantsync.diffdetective.mining.formats.MiningNodeFormat;
import org.variantsync.diffdetective.mining.formats.ReleaseMiningDiffNodeFormat;
import org.variantsync.diffdetective.variation.DiffLinesLabel;
import org.variantsync.diffdetective.variation.Label;
import org.variantsync.diffdetective.variation.diff.filter.VariationDiffFilter;
import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions;
import org.variantsync.diffdetective.variation.diff.serialize.GraphFormat;
import org.variantsync.diffdetective.variation.diff.serialize.LineGraphExportOptions;
import org.variantsync.diffdetective.variation.diff.serialize.edgeformat.EdgeLabelFormat;
import org.variantsync.diffdetective.variation.diff.serialize.treeformat.CommitDiffVariationDiffLabelFormat;
import org.variantsync.diffdetective.variation.diff.transform.CutNonEditedSubtrees;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.function.BiFunction;
/**
* This is the validation from our ESEC/FSE'22 paper.
* It provides all configuration settings and facilities to setup the validation by
* creating a {@link Analysis} and run it.
* @author Paul Bittner
*/
public class EditClassValidation implements Analysis.Hooks {
// This is only needed for the `MarlinDebug` test.
public static final BiFunction<Repository, Path, Analysis> AnalysisFactory = (repo, repoOutputDir) -> new Analysis(
"EditClassValidation",
List.of(
new PreprocessingAnalysis(new CutNonEditedSubtrees<>()),
new FilterAnalysis(VariationDiffFilter.notEmpty()), // filters unwanted trees
new EditClassValidation(),
new StatisticsAnalysis()
),
repo,
repoOutputDir
);
/**
* Returns the node format that should be used for DiffNode IO.
*/
public static MiningNodeFormat NodeFormat() {
return new ReleaseMiningDiffNodeFormat();
}
/**
* Returns the edge format that should be used for IO of edges in VariationDiffs.
*/
private static EdgeLabelFormat<DiffLinesLabel> EdgeFormat(final MiningNodeFormat nodeFormat) {
final EdgeLabelFormat.Direction direction = EdgeLabelFormat.Direction.ParentToChild;
return new DirectedEdgeLabelFormat(nodeFormat, false, direction);
}
/**
* Creates new export options for running the validation on the given repository.
*/
public static LineGraphExportOptions<DiffLinesLabel> ValidationExportOptions(final Repository repository) {
final MiningNodeFormat nodeFormat = NodeFormat();
return new LineGraphExportOptions<DiffLinesLabel>(
GraphFormat.VARIATION_DIFF
// We have to ensure that all VariationDiffs have unique IDs, so use name of changed file and commit hash.
, new CommitDiffVariationDiffLabelFormat()
, nodeFormat
, EdgeFormat(nodeFormat)
, LineGraphExportOptions.LogError()
.andThen(LineGraphExportOptions.RenderError())
.andThen(LineGraphExportOptions.SysExitOnError())
);
}
/**
* Main method to start the validation.
* @param args Command-line options.
* @throws IOException When copying the log file fails.
*/
public static void main(String[] args) throws IOException {
final AnalysisRunner.Options defaultOptions = AnalysisRunner.Options.DEFAULT(args);
final AnalysisRunner.Options validationOptions = new AnalysisRunner.Options(
defaultOptions.repositoriesDirectory(),
defaultOptions.outputDirectory(),
defaultOptions.datasetsFile(),
repo -> {
final PatchDiffParseOptions defaultPatchDiffParseOptions = defaultOptions.getParseOptionsForRepo().apply(repo);
return new PatchDiffParseOptions(
defaultPatchDiffParseOptions.diffStoragePolicy(),
new VariationDiffParseOptions(
defaultPatchDiffParseOptions.variationDiffParseOptions().annotationParser(),
true,
true
)
);
},
defaultOptions.getFilterForRepo(),
true,
false
);
AnalysisRunner.run(validationOptions, (repo, repoOutputDir) ->
Analysis.forEachCommit(() -> AnalysisFactory.apply(repo, repoOutputDir))
);
}
@Override
public void initializeResults(Analysis analysis) {
analysis.append(EditClassCount.KEY, new EditClassCount(ProposedEditClasses.Instance));
}
@Override
public boolean analyzeVariationDiff(Analysis analysis) {
analysis.getCurrentVariationDiff().forAll(node -> {
if (node.isArtifact()) {
analysis.get(EditClassCount.KEY).reportOccurrenceFor(
ProposedEditClasses.Instance.match(node),
analysis.getCurrentCommitDiff()
);
}
});
return true;
}
}