├── .gitignore
├── .vscode
└── settings.json
├── AST_GEN.md
├── AutoComment_ResearchPaper.pdf
├── JavaExtractor
├── JPredict
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.apt.core.prefs
│ │ └── org.eclipse.jdt.core.prefs
│ ├── JavaExtractor (1).iml
│ ├── JavaExtractor.iml
│ ├── dependency-reduced-pom.xml
│ ├── error_log.txt
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ ├── JavaExtractor
│ │ ├── App.java
│ │ ├── Common
│ │ │ ├── CommandLineValues.java
│ │ │ ├── Common.java
│ │ │ └── MethodContent.java
│ │ ├── ExtractFeaturesTask.java
│ │ ├── FeatureExtractor.java
│ │ ├── FeaturesEntities
│ │ │ ├── ProgramFeatures.java
│ │ │ ├── ProgramRelation.java
│ │ │ └── Property.java
│ │ ├── Main.java
│ │ └── Visitors
│ │ │ ├── FunctionVisitor.java
│ │ │ └── LeavesCollectorVisitor.java
│ │ └── Test.java
└── extract.py
├── README.md
├── bleu_score.py
├── code2seq_master
├── .gitignore
├── CSharpExtractor
│ ├── .gitattributes
│ ├── .gitignore
│ ├── CSharpExtractor
│ │ ├── .nuget
│ │ │ └── packages.config
│ │ ├── CSharpExtractor.sln
│ │ └── Extractor
│ │ │ ├── Extractor.cs
│ │ │ ├── Extractor.csproj
│ │ │ ├── PathFinder.cs
│ │ │ ├── Program.cs
│ │ │ ├── Properties
│ │ │ └── launchSettings.json
│ │ │ ├── Temp.cs
│ │ │ ├── Tree
│ │ │ └── Tree.cs
│ │ │ ├── Utilities.cs
│ │ │ └── Variable.cs
│ └── extract.py
├── Input.java
├── JavaExtractor
│ ├── JPredict
│ │ ├── .classpath
│ │ ├── .gitignore
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ ├── JavaExtractor
│ │ │ ├── App.java
│ │ │ ├── Common
│ │ │ │ ├── CommandLineValues.java
│ │ │ │ ├── Common.java
│ │ │ │ └── MethodContent.java
│ │ │ ├── ExtractFeaturesTask.java
│ │ │ ├── FeatureExtractor.java
│ │ │ ├── FeaturesEntities
│ │ │ │ ├── ProgramFeatures.java
│ │ │ │ ├── ProgramRelation.java
│ │ │ │ └── Property.java
│ │ │ └── Visitors
│ │ │ │ ├── FunctionVisitor.java
│ │ │ │ └── LeavesCollectorVisitor.java
│ │ │ └── Test.java
│ └── extract.py
├── LICENSE
├── README.md
├── __init__.py
├── baseline_tokenization
│ ├── input_example.txt
│ ├── javalang
│ │ ├── __init__.py
│ │ ├── ast.py
│ │ ├── javadoc.py
│ │ ├── parse.py
│ │ ├── parser.py
│ │ ├── test
│ │ │ ├── __init__.py
│ │ │ ├── source
│ │ │ │ └── package-info
│ │ │ │ │ ├── AnnotationJavadoc.java
│ │ │ │ │ ├── AnnotationOnly.java
│ │ │ │ │ ├── JavadocAnnotation.java
│ │ │ │ │ ├── JavadocOnly.java
│ │ │ │ │ └── NoAnnotationNoJavadoc.java
│ │ │ ├── test_java_8_syntax.py
│ │ │ ├── test_javadoc.py
│ │ │ ├── test_package_declaration.py
│ │ │ └── test_util.py
│ │ ├── tokenizer.py
│ │ ├── tree.py
│ │ └── util.py
│ └── subtokenize_nmt_baseline.py
├── code2seq.py
├── code2seq_ast_extractor.py
├── common.py
├── config.py
├── extract_ast.py
├── extractor.py
├── images
│ └── network.png
├── init.py
├── interactive_predict.py
├── java_files_creator.py
├── model.py
├── preprocess.py
├── preprocess.sh
├── preprocess_csharp.sh
├── preprocess_custom.sh
├── reader.py
├── test_extracted_ast.py
└── train.sh
├── data
├── .gitignore
└── data.7z
├── images
├── network_architecture.png
└── pipeline.png
├── poster
├── ML4SE_Poster_Group_3.pdf
└── source_code
│ ├── example.java
│ ├── img
│ ├── Embedding.png
│ ├── TU_P1_full-color.png
│ ├── distr.png
│ ├── link_to_github.png
│ ├── results_table.png
│ └── zoomedInLength.png
│ ├── poster.tex
│ └── tudelftposter.cls
├── preproc
├── __init__.py
├── common.py
├── feature_extractor.py
├── java_files_creator.py
├── preprocess.py
└── preprocess.sh
├── presentation
├── AutoComments_Presentation-Group3.pdf
└── link_to_presentation.txt
├── report
├── ML4SE_group_3_report.pdf
└── latex_code
│ ├── BasicEncoderDecoder.png
│ ├── BiLSTM.png
│ ├── Embedding.png
│ ├── Encoder(1).png
│ ├── ExampleAST.png
│ ├── LSTM.png
│ ├── blueprints.tex
│ ├── distr.png
│ ├── example.java
│ ├── main.tex
│ ├── reference.bib
│ ├── source-code
│ ├── 1.java
│ ├── 2.java
│ ├── 3.java
│ ├── 4.java
│ ├── 5.java
│ ├── 6.java
│ ├── 7.java
│ ├── 8.java
│ └── 9.java
│ └── zoomedInLength.png
└── scripts
└── multi-bleu.perl
/.gitignore:
--------------------------------------------------------------------------------
1 | /data/*.json
2 | code2vec_base
3 | .idea
4 | code2vec_model
5 | tmp
6 | code2seq-master/java_code_valid
7 | code2seq-master/java_code_train
8 | code2seq-master/java_code_test
9 | data/auto_comment_dataset
10 | code2seq-master
11 | apnews_dbow
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "java.configuration.updateBuildConfiguration": "automatic",
3 | "files.exclude": {
4 | "**/.classpath": true,
5 | "**/.project": true,
6 | "**/.settings": true,
7 | "**/.factorypath": true
8 | }
9 | }
--------------------------------------------------------------------------------
/AST_GEN.md:
--------------------------------------------------------------------------------
1 | # AutoComments
2 |
3 | ## Generation of AST - STEPS:
4 |
5 | Before everything, extract - 'data.7z' in data folder
6 |
7 | STEP 1 - Run this, python preproc/java_files_creator.py
8 |
9 | STEP 2 - Run this, bash preproc/preprocess_custom.sh
10 |
11 | RESULTS :
12 | You will see the ASTs of test, train, valid in folder - data/auto_comment_dataset
13 |
14 | NOTE:
15 | 1. Run all the above processes from the project's root directory
16 | 2. Toggle the boolean "get_ast_full_file", to extract AST for full dataset or only first 100 code snippets.
17 | i. True -> Runs for full dataset
18 | ii. Fasle -> Runs for first 100 code snippets
19 |
--------------------------------------------------------------------------------
/AutoComment_ResearchPaper.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRNavin/AutoComments/ed9ddadb00845daffe49f8513b81ddd32dfcd3aa/AutoComment_ResearchPaper.pdf
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | JavaExtractor
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.settings/org.eclipse.jdt.apt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.apt.aptEnabled=false
3 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7 | org.eclipse.jdt.core.compiler.processAnnotations=disabled
8 | org.eclipse.jdt.core.compiler.release=disabled
9 | org.eclipse.jdt.core.compiler.source=1.8
10 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/JavaExtractor (1).iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/JavaExtractor.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/dependency-reduced-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | JavaExtractor
5 | JavaExtractor
6 | JPredict
7 | 0.0.1-SNAPSHOT
8 | http://maven.apache.org
9 |
10 |
11 |
12 | maven-compiler-plugin
13 | 3.2
14 |
15 | 1.8
16 | 1.8
17 |
18 | Test.java
19 |
20 |
21 |
22 |
23 | maven-shade-plugin
24 | 2.1
25 |
26 |
27 | package
28 |
29 | shade
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | UTF-8
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/error_log.txt:
--------------------------------------------------------------------------------
1 | /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'JavaExtractor/extract.py': [Errno 2] No such file or directory
2 | /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'JavaExtractor/extract.py': [Errno 2] No such file or directory
3 | /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'JavaExtractor/extract.py': [Errno 2] No such file or directory
4 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | JavaExtractor
6 | JavaExtractor
7 | JPredict
8 | 0.0.1-SNAPSHOT
9 | http://maven.apache.org
10 |
11 |
12 |
13 | maven-compiler-plugin
14 | 3.2
15 |
16 | 1.8
17 | 1.8
18 |
19 | Test.java
20 |
21 |
22 |
23 |
24 | maven-shade-plugin
25 | 2.1
26 |
27 |
28 | package
29 |
30 | shade
31 |
32 |
33 |
34 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | com.github.javaparser
47 | javaparser-core
48 | 3.0.0-alpha.4
49 |
50 |
51 | commons-io
52 | commons-io
53 | 1.3.2
54 | compile
55 |
56 |
57 | com.fasterxml.jackson.core
58 | jackson-databind
59 | 2.9.8
60 |
61 |
62 | args4j
63 | args4j
64 | 2.33
65 |
66 |
67 | org.apache.commons
68 | commons-lang3
69 | 3.5
70 |
71 |
72 |
73 | UTF-8
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/App.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor;
2 |
3 | import JavaExtractor.Common.CommandLineValues;
4 | import org.kohsuke.args4j.CmdLineException;
5 |
6 | import java.io.IOException;
7 | import java.nio.file.Files;
8 | import java.nio.file.Paths;
9 | import java.util.LinkedList;
10 | import java.util.List;
11 | import java.util.concurrent.ExecutionException;
12 | import java.util.concurrent.Executors;
13 | import java.util.concurrent.Future;
14 | import java.util.concurrent.ThreadPoolExecutor;
15 |
16 | public class App {
17 | private static CommandLineValues s_CommandLineValues;
18 |
19 | public static void main(String[] args) {
20 | try {
21 | s_CommandLineValues = new CommandLineValues(args);
22 | } catch (CmdLineException e) {
23 | e.printStackTrace();
24 | return;
25 | }
26 |
27 | if (s_CommandLineValues.File != null) {
28 | ExtractFeaturesTask extractFeaturesTask = new ExtractFeaturesTask(s_CommandLineValues,
29 | s_CommandLineValues.File.toPath());
30 | extractFeaturesTask.processFile();
31 | } else if (s_CommandLineValues.Dir != null) {
32 | extractDir();
33 | }
34 | }
35 |
36 | private static void extractDir() {
37 | ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(s_CommandLineValues.NumThreads);
38 | LinkedList tasks = new LinkedList<>();
39 | try {
40 | Files.walk(Paths.get(s_CommandLineValues.Dir)).filter(Files::isRegularFile)
41 | .filter(p -> p.toString().toLowerCase().endsWith(".java")).forEach(f -> {
42 | ExtractFeaturesTask task = new ExtractFeaturesTask(s_CommandLineValues, f);
43 | tasks.add(task);
44 | });
45 | } catch (IOException e) {
46 | e.printStackTrace();
47 | return;
48 | }
49 | List> tasksResults = null;
50 | try {
51 | tasksResults = executor.invokeAll(tasks);
52 | } catch (InterruptedException e) {
53 | e.printStackTrace();
54 | } finally {
55 | executor.shutdown();
56 | }
57 | tasksResults.forEach(f -> {
58 | try {
59 | f.get();
60 | } catch (InterruptedException | ExecutionException e) {
61 | e.printStackTrace();
62 | }
63 | });
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/Common/CommandLineValues.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.Common;
2 |
3 | import org.kohsuke.args4j.CmdLineException;
4 | import org.kohsuke.args4j.CmdLineParser;
5 | import org.kohsuke.args4j.Option;
6 |
7 | import java.io.File;
8 |
9 | /**
10 | * This class handles the programs arguments.
11 | */
12 | public class CommandLineValues {
13 | @Option(name = "--file", required = false)
14 | public File File = null;
15 |
16 | @Option(name = "--dir", required = false, forbids = "--file")
17 | public String Dir = null;
18 |
19 | @Option(name = "--max_path_length", required = true)
20 | public int MaxPathLength;
21 |
22 | @Option(name = "--max_path_width", required = true)
23 | public int MaxPathWidth;
24 |
25 | @Option(name = "--num_threads", required = false)
26 | public int NumThreads = 64;
27 |
28 | @Option(name = "--min_code_len", required = false)
29 | public int MinCodeLength = 1;
30 |
31 | @Option(name = "--max_code_len", required = false)
32 | public int MaxCodeLength = -1;
33 |
34 | @Option(name = "--max_file_len", required = false)
35 | public int MaxFileLength = -1;
36 |
37 | @Option(name = "--pretty_print", required = false)
38 | public boolean PrettyPrint = false;
39 |
40 | @Option(name = "--max_child_id", required = false)
41 | public int MaxChildId = 3;
42 |
43 | public CommandLineValues(String... args) throws CmdLineException {
44 | CmdLineParser parser = new CmdLineParser(this);
45 | try {
46 | parser.parseArgument(args);
47 | } catch (CmdLineException e) {
48 | System.err.println(e.getMessage());
49 | parser.printUsage(System.err);
50 | throw e;
51 | }
52 | }
53 |
54 | public CommandLineValues() {
55 |
56 | }
57 | }
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/Common/Common.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.Common;
2 |
3 | import JavaExtractor.FeaturesEntities.Property;
4 | import com.github.javaparser.ast.Node;
5 | import com.github.javaparser.ast.UserDataKey;
6 |
7 | import java.util.ArrayList;
8 | import java.util.stream.Collectors;
9 | import java.util.stream.Stream;
10 |
11 | public final class Common {
12 | public static final UserDataKey PropertyKey = new UserDataKey() {
13 | };
14 | public static final UserDataKey ChildId = new UserDataKey() {
15 | };
16 | public static final String EmptyString = "";
17 |
18 | public static final String MethodDeclaration = "MethodDeclaration";
19 | public static final String NameExpr = "NameExpr";
20 | public static final String BlankWord = "BLANK";
21 |
22 | public static final int c_MaxLabelLength = 50;
23 | public static final String methodName = "METHOD_NAME";
24 | public static final String internalSeparator = "|";
25 |
26 | public static String normalizeName(String original, String defaultString) {
27 | original = original.toLowerCase().replaceAll("\\\\n", "") // escaped new
28 | // lines
29 | .replaceAll("//s+", "") // whitespaces
30 | .replaceAll("[\"',]", "") // quotes, apostrophies, commas
31 | .replaceAll("\\P{Print}", ""); // unicode weird characters
32 | String stripped = original.replaceAll("[^A-Za-z]", "");
33 | if (stripped.length() == 0) {
34 | String carefulStripped = original.replaceAll(" ", "_");
35 | if (carefulStripped.length() == 0) {
36 | return defaultString;
37 | } else {
38 | return carefulStripped;
39 | }
40 | } else {
41 | return stripped;
42 | }
43 | }
44 |
45 | public static boolean isMethod(Node node, String type) {
46 | Property parentProperty = node.getParentNode().getUserData(Common.PropertyKey);
47 | if (parentProperty == null) {
48 | return false;
49 | }
50 |
51 | String parentType = parentProperty.getType();
52 | return Common.NameExpr.equals(type) && Common.MethodDeclaration.equals(parentType);
53 | }
54 |
55 | public static ArrayList splitToSubtokens(String str1) {
56 | String str2 = str1.replace("|", " ");
57 | String str3 = str2.trim();
58 | return Stream.of(str3.split("(?<=[a-z])(?=[A-Z])|_|[0-9]|(?<=[A-Z])(?=[A-Z][a-z])|\\s+"))
59 | .filter(s -> s.length() > 0).map(s -> Common.normalizeName(s, Common.EmptyString))
60 | .filter(s -> s.length() > 0).collect(Collectors.toCollection(ArrayList::new));
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/Common/MethodContent.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.Common;
2 |
3 | import com.github.javaparser.ast.Node;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class MethodContent {
8 | private final ArrayList leaves;
9 | private final String name;
10 |
11 | public MethodContent(ArrayList leaves, String name) {
12 | this.leaves = leaves;
13 | this.name = name;
14 | }
15 |
16 | public ArrayList getLeaves() {
17 | return leaves;
18 | }
19 |
20 | public String getName() {
21 | return name;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/ExtractFeaturesTask.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor;
2 |
3 | import JavaExtractor.Common.CommandLineValues;
4 | import JavaExtractor.Common.Common;
5 | import JavaExtractor.FeaturesEntities.ProgramFeatures;
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import java.io.IOException;
9 | import java.nio.charset.Charset;
10 | import java.nio.file.Files;
11 | import java.nio.file.Path;
12 | import java.nio.file.Paths;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 | import java.util.concurrent.Callable;
16 |
17 | class ExtractFeaturesTask implements Callable {
18 | private final CommandLineValues m_CommandLineValues;
19 | private final Path filePath;
20 |
21 | public ExtractFeaturesTask(CommandLineValues commandLineValues, Path path) {
22 | m_CommandLineValues = commandLineValues;
23 | this.filePath = path;
24 | }
25 |
26 | @Override
27 | public Void call() {
28 | processFile();
29 | return null;
30 | }
31 |
32 | public void processFile() {
33 | ArrayList features;
34 | try {
35 | features = extractSingleFile();
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | return;
39 | }
40 | if (features == null) {
41 | return;
42 | }
43 | //Find out how to itterator over programFeatures
44 | String toPrint = featuresToString(features);
45 | if (toPrint.length() > 0) {
46 | System.out.println(toPrint);
47 | }
48 | }
49 |
50 | private ArrayList extractSingleFile() throws IOException {
51 | String code;
52 | String comment;
53 |
54 | if (m_CommandLineValues.MaxFileLength > 0 &&
55 | Files.lines(filePath, Charset.defaultCharset()).count() > m_CommandLineValues.MaxFileLength) {
56 | return new ArrayList<>();
57 | }
58 | try {
59 | code = new String(Files.readAllBytes(filePath));
60 | } catch (IOException e) {
61 | e.printStackTrace();
62 | code = Common.EmptyString;
63 | }
64 |
65 | if (code == Common.EmptyString){
66 | comment = Common.EmptyString;
67 | }
68 | else {
69 | String commentPath = filePath.toString();
70 | commentPath = commentPath.replace('\\', '/');
71 | int lst = commentPath.lastIndexOf("/");
72 | commentPath = commentPath.replace(commentPath.substring(lst + 1), "comment.txt");
73 | Path pathToComment = Paths.get(commentPath);
74 | comment = new String(Files.readAllBytes(pathToComment));
75 | }
76 | FeatureExtractor featureExtractor = new FeatureExtractor(m_CommandLineValues);
77 |
78 | return featureExtractor.extractFeatures(code, comment);
79 | }
80 |
81 | public String featuresToString(ArrayList features) {
82 | if (features == null || features.isEmpty()) {
83 | return Common.EmptyString;
84 | }
85 |
86 | List methodsOutputs = new ArrayList<>();
87 |
88 | for (ProgramFeatures singleMethodFeatures : features) {
89 | StringBuilder builder = new StringBuilder();
90 | String toPrint = singleMethodFeatures.toString();
91 | if (m_CommandLineValues.PrettyPrint) {
92 | toPrint = toPrint.replace(" ", "\n\t");
93 | }
94 | builder.append(toPrint);
95 | methodsOutputs.add(builder.toString());
96 |
97 | }
98 | return StringUtils.join(methodsOutputs, "\n");
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/FeaturesEntities/ProgramFeatures.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.FeaturesEntities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 |
5 | import java.util.ArrayList;
6 | import java.util.stream.Collectors;
7 |
8 | public class ProgramFeatures {
9 | private final String name;
10 |
11 | private final ArrayList features = new ArrayList<>();
12 |
13 | public ProgramFeatures(String name) {
14 | this.name = name;
15 | }
16 |
17 | @SuppressWarnings("StringBufferReplaceableByString")
18 | @Override
19 | public String toString() {
20 | StringBuilder stringBuilder = new StringBuilder();
21 | stringBuilder.append(name).append(" ");
22 | stringBuilder.append(features.stream().map(ProgramRelation::toString).collect(Collectors.joining(" ")));
23 |
24 | return stringBuilder.toString();
25 | }
26 |
27 | public void addFeature(Property source, String path, Property target) {
28 | ProgramRelation newRelation = new ProgramRelation(source, target, path);
29 | features.add(newRelation);
30 | }
31 |
32 | @JsonIgnore
33 | public boolean isEmpty() {
34 | return features.isEmpty();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/FeaturesEntities/ProgramRelation.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.FeaturesEntities;
2 |
3 | public class ProgramRelation {
4 | private final Property m_Source;
5 | private final Property m_Target;
6 | private final String m_Path;
7 |
8 | public ProgramRelation(Property sourceName, Property targetName, String path) {
9 | m_Source = sourceName;
10 | m_Target = targetName;
11 | m_Path = path;
12 | }
13 |
14 | public String toString() {
15 | return String.format("%s,%s,%s", m_Source.getName(), m_Path,
16 | m_Target.getName());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/Main.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor;
2 | import java.util.List;
3 |
4 | import com.github.javaparser.JavaParser;
5 | import com.github.javaparser.ast.CompilationUnit;
6 | import com.github.javaparser.ast.Node;
7 |
8 |
9 | public class Main {
10 | public static void main(String args[]) throws Exception {
11 | System.out.println("runs");
12 | String code = "public class Class{\nprivate void assign(HashMap labelMap,String label,DBIDRef id){\nif (labelMap.containsKey(label)) {\nDBIDs exist=labelMap.get(label);\nif (exist instanceof DBID) {\n ModifiableDBIDs n=DBIDUtil.newHashSet();\n n.add((DBID)exist);\nn.add(id);lnlabelMap.put(label,n);\n }\n else {\n assert (exist instanceof HashSetModifiableDBIDs);\n assert (exist.size() > 1);\n ((ModifiableDBIDs)exist).add(id);\n }\n }\n else {\n labelMap.put(label,DBIDUtil.deref(id));\n }\n}\n}";
13 |
14 | // CompilationUnit parsed = JavaParser.parse(code);
15 |
16 |
17 | System.out.printf("%-28s %-12s %s%n", "Node.class.simpleName", "Identifier", "Node.toString()");
18 | System.out.printf("%-28s %-12s %s%n", "=====================", "==========", "===============");
19 | CompilationUnit parsed = JavaParser.parse(code);
20 | // parsed.walk(node -> {
21 | // String identifier = "";
22 | // if (node instanceof NodeWithIdentifier)
23 | // identifier = ((NodeWithIdentifier>) node).getIdentifier();
24 | // System.out.printf("%-28s %-12s %s%n",
25 | // node.getClass().getSimpleName(),
26 | // identifier,
27 | // node.toString().replaceFirst("(?s)\\R.*", "..."));
28 | // });
29 |
30 | System.out.println(parsed);
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/JavaExtractor/JPredict/src/main/java/JavaExtractor/Visitors/FunctionVisitor.java:
--------------------------------------------------------------------------------
1 | package JavaExtractor.Visitors;
2 |
3 | import JavaExtractor.Common.CommandLineValues;
4 | import JavaExtractor.Common.Common;
5 | import JavaExtractor.Common.MethodContent;
6 | import com.github.javaparser.ast.Node;
7 | import com.github.javaparser.ast.body.MethodDeclaration;
8 | import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Arrays;
12 | import java.util.regex.Pattern;
13 |
14 | @SuppressWarnings("StringEquality")
15 | public class FunctionVisitor extends VoidVisitorAdapter