1 20 21 package spoon.aval.processing; 22 23 import java.lang.annotation.Annotation ; 24 import java.lang.annotation.ElementType ; 25 26 import spoon.aval.support.validator.problemFixer.AValFixer; 27 import spoon.processing.ProblemFixer; 28 import spoon.processing.Severity; 29 import spoon.reflect.declaration.CtAnnotation; 30 import spoon.reflect.declaration.CtElement; 31 import spoon.reflect.reference.CtReference; 32 33 55 public class ValidationPoint<V extends Annotation > { 56 57 static private boolean shouldStop = false; 58 59 60 61 72 public static void report(Severity severity, CtElement element, 73 String message,ProblemFixer... fix ) { 74 element.getFactory().getEnvironment().report(null, severity, element, 75 message,fix==null?new ProblemFixer[0]:fix); 76 shouldStop = shouldStop | severity == Severity.ERROR; 77 } 78 79 @SuppressWarnings ("unchecked") 80 public ProblemFixer[] fixerFactory(Class <? extends ProblemFixer>[] fixerType){ 81 ProblemFixer[] pf = new ProblemFixer[fixerType.length]; 82 try { 83 for (int i = 0; i < fixerType.length; i++) { 84 pf[i] = fixerType[i].newInstance(); 85 if (pf[i] instanceof AValFixer) { 86 AValFixer aF = (AValFixer) pf[i]; 87 aF.setValidationPoint(this); 88 } 89 } 90 } catch (InstantiationException e) { 91 e.printStackTrace(); 92 } catch (IllegalAccessException e) { 93 e.printStackTrace(); 94 } 95 return pf; 96 } 97 98 static boolean shouldStopProcessing(){ 99 return shouldStop; 100 } 101 102 static void resetShouldStopFlag(){ 103 shouldStop = false; 104 } 105 106 private CtElement programElement; 107 108 private CtAnnotation dslAnnotation; 109 110 private CtReference dslElement; 111 112 private V valAnnotation; 113 114 ValidationPoint(CtElement programElement, CtAnnotation dslAnnotation, 115 CtReference reference, V valAnnotation) { 116 this.programElement = programElement; 117 this.dslAnnotation = dslAnnotation; 118 this.dslElement = reference; 119 this.valAnnotation = valAnnotation; 120 } 121 122 128 public CtAnnotation getDslAnnotation() { 129 return dslAnnotation; 130 } 131 132 141 public CtReference getDslElement() { 142 return dslElement; 143 } 144 145 153 public CtElement getProgramElement() { 154 return programElement; 155 } 156 157 166 public V getValAnnotation() { 167 return valAnnotation; 168 } 169 170 } 171 | Popular Tags |