17
17
import com .github .javaparser .ast .CompilationUnit ;
18
18
import com .github .javaparser .Range ;
19
19
import com .github .javaparser .ast .Node ;
20
- import com .github .javaparser .ast .expr . VariableDeclarationExpr ;
20
+ import com .github .javaparser .ast .body . VariableDeclarator ;
21
21
import com .github .javaparser .ast .expr .SimpleName ;
22
22
import com .github .javaparser .ast .body .MethodDeclaration ;
23
23
import com .github .javaparser .ast .visitor .TreeVisitor ;
@@ -30,22 +30,27 @@ public class MethodLines extends VoidVisitorAdapter<Object> {
30
30
31
31
private ArrayList <Node > rem = new ArrayList <>();
32
32
public static ArrayList <String > acceptedNames = new ArrayList <>();
33
- private static File logFile ;
34
- public static FileWriter fr ;
35
33
public static boolean seq ;
36
34
37
35
private String typeToTarget ;
38
36
private String javaFilePath ;
37
+ private File logFile ;
38
+ private FileWriter fr ;
39
39
40
- MethodLines (String typeToTarget ) {
40
+ MethodLines (String typeToTarget , String logFile ) {
41
41
this .typeToTarget = typeToTarget ;
42
- }
42
+ /*
43
+ this.logFile = new File(logFile);
43
44
44
- public static void setLogPath (String path ) throws IOException {
45
- MethodLines .logFile = new File (path );
46
- MethodLines .fr = new FileWriter (MethodLines .logFile , true );
45
+ try {
46
+ this.fr = new FileWriter(logFile, true);
47
+ } catch (java.io.IOException e) {
48
+ System.out.println("file " + logFile + " invalid");
49
+ }
50
+ */
47
51
}
48
52
53
+
49
54
public static void set_clean_names (String fname ) {
50
55
File accNamesFile = new File (fname );
51
56
Scanner s ;
@@ -70,8 +75,19 @@ public void inspectSourceCode(File javaFile) {
70
75
if (root != null ) {
71
76
this .visit (root .clone (), null );
72
77
}
78
+
79
+ /*
80
+ try {
81
+ this.fr.close();
82
+ System.out.println("Closed file");
83
+ return;
84
+ } catch (IOException e) {
85
+ System.out.println("Can't close file");
86
+ }
87
+ */
73
88
}
74
89
90
+
75
91
@ Override
76
92
public void visit (CompilationUnit com , Object obj ) {
77
93
locateTargetStatements (com , obj , this .typeToTarget );
@@ -108,8 +124,8 @@ private boolean isTypeOfTarget(String typeToTarget, Node node){
108
124
case "MethodDeclaration" :
109
125
return (node instanceof MethodDeclaration );
110
126
111
- case "VariableDeclarationExpr " :
112
- return (node instanceof VariableDeclarationExpr );
127
+ case "VariableDeclarator " :
128
+ return (node instanceof VariableDeclarator );
113
129
114
130
default :
115
131
System .out .println ("ERROR: no support for target type: " + typeToTarget );
@@ -132,18 +148,21 @@ public void process(Node node) {
132
148
133
149
ArrayList <String > names = MethodLines .seq ? splitNameByToken (node_name ) : new ArrayList <String >(Arrays .asList (node_name ));
134
150
151
+ /*
135
152
for (int i=0; i<names.size(); i++) {
136
153
String token = names.get(i);
137
154
if(!acceptedNames.contains(token)){
138
155
rem.add(node);
139
156
break;
140
157
}
141
- }
158
+ }*/
142
159
143
160
break ;
144
161
145
- case "VariableDeclarationExpr" :
146
- Range r = node .getRange ().orElse (null );
162
+ case "VariableDeclarator" :
163
+ VariableDeclarator vd = (VariableDeclarator ) node ;
164
+
165
+ Range r = vd .getName ().getRange ().orElse (null );
147
166
try {
148
167
fr .write (javaFilePath + " : " + typeToTarget + " : " + r .toString () + "\n " );
149
168
} catch (IOException e ) {
@@ -180,20 +199,17 @@ private void applyManager(CompilationUnit com) {
180
199
}
181
200
182
201
public static void main (String [] args ){
183
- String inPath = "/data2/edinella/java-all-redist-fs/" ;
184
- Common .outputPath = "/data2/edinella/java-all-redist-g/" ;
202
+ //String inPath = "/data2/edinella/java-all-redist-g/training/";
203
+ String inPath = "/data2/edinella/java-all" ;
204
+ Common .outputPath = "/data2/edinella/test-java-all-seq/" ;
185
205
//Common.outputPath = "/data2/edinella/java-large-clean/";
186
206
187
- String typeToTarget = "VariableDeclarationExpr" ;
188
- //MethodLines.seq = false;
189
- //MethodLines.set_clean_names("/home/edinella/clean_names.txt");
190
207
191
- try {
192
- setLogPath (Common .outputPath + "log.txt" );
193
- } catch (IOException e ) {
194
- System .out .println (Common .outputPath + " can't write to!" );
195
- return ;
196
- }
208
+ String typeToTarget = "MethodDeclaration" ;
209
+ //String typeToTarget = "VariableDeclarator";
210
+ MethodLines .seq = true ;
211
+ MethodLines .set_clean_names ("/home/edinella/clean_seqs.txt" );
212
+
197
213
198
214
File programFolder = new File (inPath );
199
215
@@ -217,12 +233,6 @@ public static void main(String[] args){
217
233
218
234
executor .shutdown ();
219
235
220
- try {
221
- MethodLines .fr .close ();
222
- System .out .println ("Closed file" );
223
- return ;
224
- } catch (IOException e ) {
225
- System .out .println ("Can't close file" );
226
- }
236
+
227
237
}
228
238
}
0 commit comments