Skip to content

Commit 71dc1d2

Browse files
authored
Merge pull request #50 from TheSoftwareDesignLab/develop
MO28 compilation errors solved and fix #43
2 parents d5e914f + 8fad91c commit 71dc1d2

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

src/uniandes/tsdl/mutapk/detectors/xml/InvalidColorDetector.java

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,71 +22,76 @@
2222
import uniandes.tsdl.mutapk.model.location.MutationLocation;
2323

2424
public class InvalidColorDetector extends TextBasedDetector {
25-
25+
2626
public InvalidColorDetector(){
2727
this.type = MutationType.INVALID_COLOR;
2828
}
29-
29+
3030
@Override
3131
public List<MutationLocation> analyzeApp(String rootPath) throws Exception {
3232
List<MutationLocation> locations = new ArrayList<MutationLocation>();
3333
List<Entry<String,String>> colorHex = new ArrayList<Entry<String,String>>();
34-
34+
3535

3636
String path = rootPath + File.separator+"res"+File.separator+"values"+File.separator + Helper.COLORS;
3737

3838
File fXmlFile = new File(path);
39-
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
40-
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
41-
Document doc = dBuilder.parse(fXmlFile);
42-
doc.getDocumentElement().normalize();
43-
44-
// Get all activities
45-
NodeList nodeList = doc.getElementsByTagName("color");
46-
for (int i = 0; i < nodeList.getLength(); i++) {
47-
Node node = nodeList.item(i);
48-
String colorName = node.getAttributes().getNamedItem("name").getNodeValue();
49-
colorHex.add(new SimpleEntry<String,String>(colorName,node.getTextContent()));
50-
}
51-
52-
// Read Source Code
53-
BufferedReader reader = new BufferedReader(new FileReader(
54-
new File(path)));
55-
String line = null;
56-
int startLine = 0;
57-
int startCol = 0;
58-
int endCol = 0;
59-
int lineNum = 0;
60-
String originalColor = "";
61-
String colorName = "";
62-
boolean isColorTag = false;
63-
int currentLine = 0;
64-
while ((line = reader.readLine()) != null) {
39+
if(fXmlFile.exists()) {
40+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
41+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
42+
Document doc = dBuilder.parse(fXmlFile);
43+
doc.getDocumentElement().normalize();
6544

66-
if (line.contains("<color")) {
67-
startLine = currentLine;
68-
isColorTag = true;
45+
// Get all activities
46+
NodeList nodeList = doc.getElementsByTagName("color");
47+
for (int i = 0; i < nodeList.getLength(); i++) {
48+
Node node = nodeList.item(i);
49+
String colorName = node.getAttributes().getNamedItem("name").getNodeValue();
50+
colorHex.add(new SimpleEntry<String,String>(colorName,node.getTextContent()));
6951
}
70-
if (isColorTag) {
71-
for(Entry<String,String> color : colorHex){
72-
if(line.contains(color.getKey())){
73-
startCol = line.indexOf(color.getValue())+1;
74-
endCol = startCol+color.getValue().length()-1;
75-
lineNum = currentLine;
76-
originalColor = color.getValue();
77-
colorName = color.getKey();
78-
}
52+
for(Entry<String,String> color : colorHex){
53+
System.out.println(color.getKey());
54+
System.out.println(color.getValue());
55+
}
56+
57+
// Read Source Code
58+
BufferedReader reader = new BufferedReader(new FileReader(
59+
new File(path)));
60+
String line = null;
61+
int startLine = 0;
62+
int startCol = 0;
63+
int endCol = 0;
64+
int lineNum = 0;
65+
String originalColor = "";
66+
String colorName = "";
67+
boolean isColorTag = false;
68+
int currentLine = 0;
69+
while ((line = reader.readLine()) != null) {
70+
71+
if (line.contains("<color")) {
72+
startLine = currentLine;
73+
isColorTag = true;
7974
}
80-
if (line.contains(">")) {
81-
locations.add(InvalidColorMutationLocation.buildLocation(path, startLine, currentLine, startCol, endCol, lineNum, -1, this.getType(), colorName, originalColor));
82-
isColorTag = false;
75+
if (isColorTag) {
76+
for(Entry<String,String> color : colorHex){
77+
if(line.contains("\""+color.getKey()+"\"")){
78+
startCol = line.indexOf(color.getValue())+1;
79+
endCol = startCol+color.getValue().length()-1;
80+
lineNum = currentLine;
81+
originalColor = color.getValue();
82+
colorName = color.getKey();
83+
}
84+
}
85+
if (line.contains(">")) {
86+
locations.add(InvalidColorMutationLocation.buildLocation(path, startLine, currentLine, startCol, endCol, lineNum, -1, this.getType(), colorName, originalColor));
87+
isColorTag = false;
88+
}
8389
}
84-
}
8590

86-
currentLine++;
91+
currentLine++;
92+
}
93+
reader.close();
8794
}
88-
reader.close();
89-
9095
return locations;
9196
}
9297

0 commit comments

Comments
 (0)