-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUMLGenerator1.1.2
More file actions
101 lines (93 loc) · 3.23 KB
/
UMLGenerator1.1.2
File metadata and controls
101 lines (93 loc) · 3.23 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
import java.io.File;
import java.io.*;
import javax.swing.*;
public class UMLGen1_1 {
public static void main(String[] args){
String path1,path2,nomeClasse = new String("");
int val;
JFileChooser path3 = new JFileChooser();
val = path3.showOpenDialog(null);
if(val == JFileChooser.APPROVE_OPTION){
System.out.println("Apretura "+path3.getSelectedFile());
}
//path1 = JOptionPane.showInputDialog(null,"Inserisci il nome del file sorgente seguito da estensione: ");
path2 = JOptionPane.showInputDialog(null,"Inserisci il nome del file in cui scrivere l'UML: ");
try{
//Creo un colleamento al file
File file = new File(path3.getSelectedFile().getName());
//Creo una string che memorizza la linea del file
String line = new String();
//Creo una stringa che memorizza la linea che verra' stampata nel file
String fileLine;
//Apro il file in input
FileInputStream input = new FileInputStream(file);
//Lo unisco allo stream Buffered per leggere linea per linea
BufferedReader in = new BufferedReader(new InputStreamReader(input));
//Ora apro il file in modalita' output per poterci scrivere
File output = new File(path2);
if(!output.exists()){
if(output.createNewFile()){
System.out.println("File creato con successo");
}//if
else{
System.out.println("Errore nella creazione del file");
}
}
//Apro lo stream di lettura
//!FileOutputStream out = new FileOutputStream(output);
FileWriter out = new FileWriter(output);
//Ora lo unisco allo stream BufferedWriter per poter scrivere linnee intere
BufferedWriter writeFile = new BufferedWriter(out); //new OutputStreamWriter(out)
while((line = in.readLine()) != null){
line = line.trim();
if(line.length()>7){
if(line.startsWith("public class")){
if(line.charAt(line.length()-1)!='{'){
writeFile.write(line.substring(13,line.length())+"\n");
nomeClasse=line.substring(13,line.length()).trim();
}
else{
writeFile.write(line.substring(13,line.length()-1)+"\n");
nomeClasse=line.substring(13,line.length()-1).trim();
}
}//if
else{
if(!line.startsWith("public "+nomeClasse)){
if(line.startsWith("pu")){
if(line.charAt(line.length()-1)!='{'){
writeFile.write("+"+line.substring(7,line.length())+"\n");
}
else{
writeFile.write("+"+line.substring(7,line.length()-1)+"\n");
}
}//if
else{
if(line.startsWith("pri")){
if(line.charAt(line.length()-1)!='{'){
writeFile.write("-"+line.substring(8,line.length())+"\n");
}
else{
writeFile.write("-"+line.substring(8,line.length()-1)+"\n");
}
}//if
else{
if(line.startsWith("pro")){
if(line.charAt(line.length()-1)!='{'){
writeFile.write("#"+line.substring(10,line.length())+"\n");
}//if
else{
writeFile.write("#"+line.substring(10,line.length()-1)+"\n");
}
}//if
}//else
}//else
}//if
}//else
}//if
writeFile.flush();
}//while
}catch (IOException e) {
e.printStackTrace();
}
}//main
}//class