1 package spoon.reflect.visitor; 2 3 import java.util.Stack ; 4 5 import spoon.processing.Environment; 6 import spoon.processing.Severity; 7 import spoon.reflect.declaration.CtElement; 8 9 15 public class ModelConsistencyChecker extends CtScanner { 16 17 boolean fixInconsistencies = false; 18 19 Environment environment; 20 21 Stack <CtElement> stack = new Stack <CtElement>(); 22 23 32 public ModelConsistencyChecker(Environment environment, 33 boolean fixInconsistencies) { 34 this.fixInconsistencies = fixInconsistencies; 35 this.environment = environment; 36 } 37 38 41 @Override 42 public void enter(CtElement element) { 43 if (!stack.isEmpty()) { 44 if (element.getParent() != stack.peek()) { 45 if (fixInconsistencies) { 46 element.setParent(stack.peek()); 47 } else { 48 environment.report(null, Severity.WARNING, 49 "inconsistent parent for " + element); 50 } 51 } 52 } 53 stack.push(element); 54 } 55 56 59 @Override 60 protected void exit(CtElement e) { 61 stack.pop(); 62 } 63 64 } 65 | Popular Tags |