Changeset 53 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools
- Timestamp:
- 12/01/10 16:49:04 (14 years ago)
- Location:
- trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/validation
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/validation/DuplicateEntry.java
r50 r53 27 27 28 28 public void addRule(Rule r) { 29 rules.add(r); 29 if (!rules.contains(r)) 30 rules.add(r); 30 31 } 31 32 -
trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/validation/EbnfJavaValidator.java
r52 r53 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.Collections; 4 6 import java.util.HashMap; 5 7 import java.util.HashSet; … … 383 385 } 384 386 385 // create warnings386 387 // create longest matches 388 HashMap<String, RuleDuplication> rulePairMap = new HashMap<String, RuleDuplication>(); 387 389 Iterator<String> it = taggedEntries.iterator(); 388 390 … … 390 392 String entry = it.next(); 391 393 DuplicateEntry dupeEntry = dupesMap.get(entry); 394 392 395 if (dupeEntry.getRules().size() < 2) 393 396 continue; 394 397 395 String warningText = ""; 396 warningText += ">>" + entry + "<< is duplicated in the following rules: "; 398 ArrayList<Integer> matchingLines = new ArrayList<Integer>(); 397 399 for (int i=0; i < dupeEntry.getRules().size(); i++) { 398 400 Rule rule = dupeEntry.getRules().get(i); 399 401 CompositeNode parserNode = NodeUtil.getNodeAdapter(rule).getParserNode(); 400 401 if (rule.getRulenumber() > 0) { 402 String ruleNumber = Integer.toString(rule.getRulenumber()).replaceAll("[ \t\n\r]", ""); 403 warningText += ruleNumber; 404 } 405 warningText += " (Line "; 406 warningText += parserNode.getLine(); 407 warningText += ")"; 402 matchingLines.add(parserNode.getLine()); 403 } 404 405 Collections.sort(matchingLines); 406 407 RuleDuplication rulePair = rulePairMap.get(matchingLines.toString()); 408 if (rulePair == null) { 409 rulePair = new RuleDuplication(); 410 } 411 rulePair.addDupe(dupeEntry); 412 rulePairMap.put(matchingLines.toString(), rulePair); 413 } 414 415 // create warnings 416 Iterator<RuleDuplication> it2 = rulePairMap.values().iterator(); 417 418 while (it2.hasNext()) { 419 RuleDuplication rulePair = it2.next(); 420 List<DuplicateEntry> dupes = rulePair.getFilteredDupes(); 421 422 for (int i=0; i < dupes.size(); i++) { 423 DuplicateEntry dupeEntry = dupes.get(i); 408 424 409 if (i+1 < dupeEntry.getRules().size()) 410 warningText += ", "; 411 412 } 413 414 Rule rule = dupeEntry.getRules().get(0); 415 CompositeNode parserNode = NodeUtil.getNodeAdapter(rule).getParserNode(); 416 warning(warningText, parserNode.getElement(), 1); 417 } 418 425 String warningText = ""; 426 warningText += ">>" + dupeEntry.getSnippet() + "<< is duplicated in the following rules: "; 427 for (int j=0; j < dupeEntry.getRules().size(); j++) { 428 Rule rule = dupeEntry.getRules().get(j); 429 CompositeNode parserNode = NodeUtil.getNodeAdapter(rule).getParserNode(); 430 431 if (rule.getRulenumber() > 0) { 432 String ruleNumber = Integer.toString(rule.getRulenumber()).replaceAll("[ \t\n\r]", ""); 433 warningText += ruleNumber; 434 } 435 warningText += " (Line "; 436 warningText += parserNode.getLine(); 437 warningText += ")"; 438 439 if (j+1 < dupeEntry.getRules().size()) 440 warningText += ", "; 441 442 } 443 444 Rule rule = dupeEntry.getRules().get(0); 445 CompositeNode parserNode = NodeUtil.getNodeAdapter(rule).getParserNode(); 446 warning(warningText, parserNode.getElement(), 1); 447 } 448 } 419 449 } 420 450
Note: See TracChangeset
for help on using the changeset viewer.