[7] | 1 | package elements;
|
---|
| 2 |
|
---|
| 3 | import java.util.LinkedList;
|
---|
| 4 | import java.util.regex.Matcher;
|
---|
| 5 | import java.util.regex.Pattern;
|
---|
| 6 | import org.apache.commons.lang.*;
|
---|
| 7 | import org.etsi.t3d.T3D;
|
---|
| 8 |
|
---|
| 9 | import de.ugoe.cs.swe.trex.core.analyzer.rfparser.LocationAST;
|
---|
| 10 | import de.ugoe.cs.swe.trex.core.analyzer.rfparser.TTCN3ParserTokenTypes;
|
---|
| 11 |
|
---|
| 12 | public class TTCN3Comment {
|
---|
| 13 | private String commentsXML;
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | private LinkedList<String> desc = new LinkedList<String>();
|
---|
| 18 | private LinkedList<String> author = new LinkedList<String>();
|
---|
| 19 | private LinkedList<String> config = new LinkedList<String>();
|
---|
| 20 | private LinkedList<String> exception = new LinkedList<String>();
|
---|
| 21 | private LinkedList<String> member = new LinkedList<String>();
|
---|
| 22 | private LinkedList<String> param = new LinkedList<String>();
|
---|
| 23 | private LinkedList<String> purpose = new LinkedList<String>();
|
---|
| 24 | private LinkedList<String> remark = new LinkedList<String>();
|
---|
| 25 | private LinkedList<String> Return = new LinkedList<String>();
|
---|
| 26 | private LinkedList<String> see = new LinkedList<String>();
|
---|
| 27 | private LinkedList<String> since = new LinkedList<String>();
|
---|
| 28 | private LinkedList<String> status = new LinkedList<String>();
|
---|
| 29 | private LinkedList<String> url = new LinkedList<String>();
|
---|
| 30 | private LinkedList<String> verdict = new LinkedList<String>();
|
---|
| 31 | private LinkedList<String> version = new LinkedList<String>();
|
---|
| 32 |
|
---|
| 33 | private LinkedList<String> warnings = new LinkedList<String>();
|
---|
| 34 | private LinkedList<String> seeRefs = new LinkedList<String>();
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | public TTCN3Comment(LocationAST node){
|
---|
| 38 |
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | //TODO: WHY WHY WHY OH WHY?!?!?!?!?!??! REORGANIZE AND REFACTOR
|
---|
| 44 | public TTCN3Comment(String rawComments, int elementType){
|
---|
| 45 | if(rawComments != null && !rawComments.equals("")){
|
---|
| 46 | rawComments = "\n" + rawComments;
|
---|
| 47 | rawComments = rawComments.replaceAll("\\r", "");
|
---|
| 48 | rawComments = rawComments.replaceAll("\\n(\\s|\\*|/)*", "\n").replaceAll("\\n+","\n");
|
---|
| 49 | rawComments = rawComments.trim() + "\r___NEWTAG___";
|
---|
| 50 | rawComments = rawComments.replaceAll(" @see", " @esee").replaceAll(" @url", " @eurl");
|
---|
| 51 | rawComments = rawComments.replaceAll("\\n@", "\r___NEWTAG___@");
|
---|
| 52 |
|
---|
| 53 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getDescTag(), desc);
|
---|
| 54 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getAuthorTag(), author);
|
---|
| 55 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getConfigTag(), config);
|
---|
| 56 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getExceptionTag(), exception);
|
---|
| 57 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getMemberTag(), member);
|
---|
| 58 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getParamTag(), param);
|
---|
| 59 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getPurposeTag(), purpose);
|
---|
| 60 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getRemarkTag(), remark);
|
---|
| 61 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getReturnTag(), Return);
|
---|
| 62 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getSeeTag(), see);
|
---|
| 63 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getSinceTag(), since);
|
---|
| 64 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getStatusTag(), status);
|
---|
| 65 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getUrlTag(), url);
|
---|
| 66 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getVerdictTag(), verdict);
|
---|
| 67 | getComments(rawComments, T3D.activeProfile.getCommentTagsConfiguration().getVersionTag(), version);
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | if (T3D.activeProfile.isCheckConsistentTagUsage()) {
|
---|
| 71 | if (config.size() >= 2)
|
---|
| 72 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getConfigTag()));
|
---|
| 73 | if (purpose.size() >= 2)
|
---|
| 74 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getPurposeTag()));
|
---|
| 75 | if (Return.size() >= 2)
|
---|
| 76 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getReturnTag()));
|
---|
| 77 | if (since.size() >= 2)
|
---|
| 78 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getSinceTag()));
|
---|
| 79 | if (status.size() >= 2)
|
---|
| 80 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getStatusTag()));
|
---|
| 81 | if (version.size() >= 2)
|
---|
| 82 | warnings.add(getWarningMultipleTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getVersionTag()));
|
---|
| 83 |
|
---|
| 84 | if (elementType != TTCN3ParserTokenTypes.TestcaseDef && config.size() >= 1) {
|
---|
| 85 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getConfigTag()));
|
---|
| 86 | }
|
---|
| 87 | if (elementType != TTCN3ParserTokenTypes.SignatureDef && exception.size() >= 1) {
|
---|
| 88 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getExceptionTag()));
|
---|
| 89 | }
|
---|
| 90 | if (elementType != TTCN3ParserTokenTypes.TypeDef
|
---|
| 91 | && elementType != TTCN3ParserTokenTypes.TemplateDef
|
---|
| 92 | && elementType != TTCN3ParserTokenTypes.ModuleParDef
|
---|
| 93 | && elementType != TTCN3ParserTokenTypes.ConstDef
|
---|
| 94 | && member.size() >= 1) {
|
---|
| 95 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getMemberTag()));
|
---|
| 96 | }
|
---|
| 97 | if (elementType != TTCN3ParserTokenTypes.TemplateDef
|
---|
| 98 | && elementType != TTCN3ParserTokenTypes.SignatureDef
|
---|
| 99 | && elementType != TTCN3ParserTokenTypes.FunctionDef
|
---|
| 100 | && elementType != TTCN3ParserTokenTypes.AltstepDef
|
---|
| 101 | && elementType != TTCN3ParserTokenTypes.TestcaseDef
|
---|
[36] | 102 | && elementType != TTCN3ParserTokenTypes.ExtFunctionDef
|
---|
[7] | 103 | && param.size() >= 1) {
|
---|
| 104 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getParamTag()));
|
---|
| 105 | }
|
---|
| 106 | if (elementType != TTCN3ParserTokenTypes.TestcaseDef && purpose.size() >= 1) {
|
---|
| 107 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getPurposeTag()));
|
---|
| 108 | }
|
---|
[36] | 109 | if (elementType != TTCN3ParserTokenTypes.FunctionDef
|
---|
| 110 | && elementType != TTCN3ParserTokenTypes.SignatureDef
|
---|
| 111 | && elementType != TTCN3ParserTokenTypes.ExtFunctionDef
|
---|
| 112 | && Return.size() >= 1) {
|
---|
[7] | 113 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getReturnTag()));
|
---|
| 114 | }
|
---|
| 115 | if (elementType != TTCN3ParserTokenTypes.FunctionDef
|
---|
| 116 | && elementType != TTCN3ParserTokenTypes.TestcaseDef
|
---|
| 117 | && elementType != TTCN3ParserTokenTypes.AltstepDef
|
---|
| 118 | && verdict.size() >= 1) {
|
---|
| 119 | warnings.add(getWarningExtraTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getVerdictTag()));
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[35] | 122 | if (T3D.activeProfile.isCheckFunctionDescTagsRequired())
|
---|
| 123 | if (elementType != TTCN3ParserTokenTypes.FunctionDef
|
---|
| 124 | // && elementType != TTCN3ParserTokenTypes.TestcaseDef
|
---|
| 125 | // && elementType != TTCN3ParserTokenTypes.AltstepDef
|
---|
| 126 | && desc.size() <= 0) {
|
---|
| 127 | warnings.add(getWarningMissingTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getDescTag()));
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
[7] | 131 | for (String d : desc)
|
---|
| 132 | if (d.length() <= 0)
|
---|
| 133 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getDescTag()));
|
---|
| 134 | for (String d : author)
|
---|
| 135 | if (d.length() <= 0)
|
---|
| 136 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getAuthorTag()));
|
---|
| 137 | for (String d : config)
|
---|
| 138 | if (d.length() <= 0)
|
---|
| 139 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getConfigTag()));
|
---|
| 140 | for (String d : exception)
|
---|
| 141 | if (d.length() <= 0)
|
---|
| 142 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getExceptionTag()));
|
---|
| 143 | for (String d : member)
|
---|
| 144 | if (d.length() <= 0)
|
---|
| 145 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getMemberTag()));
|
---|
| 146 | for (String d : param)
|
---|
| 147 | if (d.length() <= 0)
|
---|
| 148 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getParamTag()));
|
---|
| 149 | for (String d : purpose)
|
---|
| 150 | if (d.length() <= 0)
|
---|
| 151 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getPurposeTag()));
|
---|
| 152 | for (String d : remark)
|
---|
| 153 | if (d.length() <= 0)
|
---|
| 154 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getRemarkTag()));
|
---|
| 155 | for (String d : Return)
|
---|
| 156 | if (d.length() <= 0)
|
---|
| 157 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getReturnTag()));
|
---|
| 158 | for (String d : see)
|
---|
| 159 | if (d.length() <= 0)
|
---|
| 160 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getSeeTag()));
|
---|
| 161 | for (String d : since)
|
---|
| 162 | if (d.length() <= 0)
|
---|
| 163 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getSinceTag()));
|
---|
| 164 | for (String d : status)
|
---|
| 165 | if (d.length() <= 0)
|
---|
| 166 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getStatusTag()));
|
---|
| 167 | for (String d : url)
|
---|
| 168 | if (d.length() <= 0)
|
---|
| 169 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getUrlTag()));
|
---|
| 170 | for (String d : verdict)
|
---|
| 171 | if (d.length() <= 0)
|
---|
| 172 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getVerdictTag()));
|
---|
| 173 | for (String d : version)
|
---|
| 174 | if (d.length() <= 0)
|
---|
| 175 | warnings.add(getWarningEmptyTags("@" + T3D.activeProfile.getCommentTagsConfiguration().getVersionTag()));
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | for(String seeRef : see)
|
---|
| 180 | seeRefs.add(seeRef);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | private String getWarningMultipleTags(String tagname){
|
---|
| 184 | return "Multiple " + tagname + " tags found (may only contain one)";
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | private String getWarningExtraTags(String tagname){
|
---|
| 188 | return tagname + " tag found (may not be used here)";
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | private String getWarningEmptyTags(String tagname){
|
---|
| 192 | return "Empty tag found: " + tagname;
|
---|
| 193 | }
|
---|
[35] | 194 |
|
---|
| 195 | private String getWarningMissingTags(String tagname){
|
---|
| 196 | return "Required " + tagname + " tag is missing";
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[7] | 199 |
|
---|
| 200 | private String getIdentifier(String comment, int pos){
|
---|
| 201 | String subString = comment.substring(pos, comment.length());
|
---|
| 202 |
|
---|
| 203 | int endpos = subString.indexOf(" ");
|
---|
| 204 | if(endpos == -1)
|
---|
| 205 | endpos = subString.length();
|
---|
| 206 | // System.out.println("-" + subString.substring(0, endpos) + "-");
|
---|
| 207 | return subString.substring(0, endpos).trim();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | private String replaceTag(String c, String tag){
|
---|
| 211 | int pos;
|
---|
| 212 | c += " ";
|
---|
| 213 | while(c.contains(" @" + tag + " ")){
|
---|
| 214 | pos = c.indexOf(" @" + tag + " ");
|
---|
| 215 | if(pos != -1){
|
---|
| 216 | String identifier = getIdentifier(c, pos+ (tag.length() + 3));
|
---|
| 217 | c = c.replaceAll("@" + tag + " " + identifier + " ", "<" + tag + ">" + identifier + "</" + tag + ">");
|
---|
| 218 | }else
|
---|
| 219 | break;
|
---|
| 220 | }
|
---|
| 221 | return c.trim();
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | private String replaceSee(String c){
|
---|
| 225 | return replaceTag(c, "esee");
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | private String replaceUrl(String c){
|
---|
| 229 | return replaceTag(c, "eurl");
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | private String formatComment(String c){
|
---|
| 233 | return StringEscapeUtils.escapeXml(c).replaceAll(" ", " ").replaceAll("\n", " ").replaceAll("\t", " ").replaceAll("\r", "");
|
---|
| 234 |
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | public String toString(){
|
---|
| 238 | commentsXML = "";
|
---|
| 239 | if(!isEmpty()){
|
---|
| 240 | commentsXML += "\n<comment>";
|
---|
| 241 | for(String d : desc)
|
---|
| 242 | commentsXML += ("\n<desc>" + replaceUrl(replaceSee(formatComment(d))) + "</desc>");
|
---|
| 243 |
|
---|
| 244 | for(String d : author)
|
---|
| 245 | commentsXML += ("\n<author>" + replaceUrl(replaceSee(formatComment(d))) + "</author>");
|
---|
| 246 |
|
---|
| 247 | for(String d : config)
|
---|
| 248 | commentsXML += ("\n<config>" + replaceUrl(replaceSee(formatComment(d))) + "</config>");
|
---|
| 249 |
|
---|
| 250 | for(String d : exception)
|
---|
| 251 | commentsXML += ("\n<exception>" + replaceUrl(replaceSee(formatComment(d))) + "</exception>");
|
---|
| 252 |
|
---|
| 253 | for(String d : member)
|
---|
| 254 | commentsXML += ("\n<member>" + replaceUrl(replaceSee(formatComment(d))) + "</member>");
|
---|
| 255 |
|
---|
| 256 | for(String d : param)
|
---|
| 257 | commentsXML += ("\n<param>" + replaceUrl(replaceSee(formatComment(d))) + "</param>");
|
---|
| 258 | for(String d : purpose)
|
---|
| 259 | commentsXML += ("\n<purpose>" + replaceUrl(replaceSee(formatComment(d))) + "</purpose>");
|
---|
| 260 |
|
---|
| 261 | for(String d : remark)
|
---|
| 262 | commentsXML += ("\n<remark>" + replaceUrl(replaceSee(formatComment(d))) + "</remark>");
|
---|
| 263 |
|
---|
| 264 | for(String d : Return)
|
---|
| 265 | commentsXML += ("\n<return>" + replaceUrl(replaceSee(formatComment(d))) + "</return>");
|
---|
| 266 |
|
---|
| 267 | for(String d : see)
|
---|
| 268 | commentsXML += ("\n<see>" + formatComment(d) + "</see>");
|
---|
| 269 |
|
---|
| 270 | for(String d : since)
|
---|
| 271 | commentsXML += ("\n<since>" + replaceUrl(replaceSee(formatComment(d))) + "</since>");
|
---|
| 272 |
|
---|
| 273 | for(String d : status)
|
---|
| 274 | commentsXML += ("\n<status>" + replaceUrl(replaceSee(formatComment(d))) + "</status>");
|
---|
| 275 |
|
---|
| 276 | for(String d : url)
|
---|
| 277 | commentsXML += ("\n<url>" + formatComment(d) + "</url>");
|
---|
| 278 |
|
---|
| 279 | for(String d : verdict)
|
---|
| 280 | commentsXML += ("\n<verdict>" + replaceUrl(replaceSee(formatComment(d))) + "</verdict>");
|
---|
| 281 |
|
---|
| 282 | for(String d : version)
|
---|
| 283 | commentsXML += ("\n<version>" + replaceUrl(replaceSee(formatComment(d))) + "</version>");
|
---|
| 284 |
|
---|
| 285 | commentsXML += "</comment>";
|
---|
| 286 |
|
---|
| 287 | }
|
---|
| 288 | if(commentsXML.length() > 20)
|
---|
| 289 | return commentsXML;
|
---|
| 290 | else
|
---|
| 291 | return "";
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | private boolean isEmpty(){
|
---|
| 295 | return false;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | private void getComments(String commentblock, String tag, LinkedList<String> vector){
|
---|
| 299 | Pattern p = Pattern.compile("@" + tag + "(.|\\n)*\\r___NEWTAG___");
|
---|
| 300 | Matcher m = p.matcher(commentblock);
|
---|
| 301 | while (m.find() == true){
|
---|
| 302 | String comment = m.group().replaceFirst("@"+tag, "").replaceFirst("\r___NEWTAG___", "").trim();
|
---|
| 303 | vector.add(comment);
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | public LinkedList<String> getDocumentedParameters(){
|
---|
| 308 | LinkedList <String> docParNames = new LinkedList<String>();
|
---|
| 309 | for(String parString : param){
|
---|
| 310 | if(parString.indexOf(" ") > 0)
|
---|
| 311 | docParNames.add(parString.substring(0, parString.indexOf(" ")));
|
---|
| 312 | }
|
---|
| 313 | return docParNames;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | public LinkedList<String> getDescriptions(){
|
---|
| 317 | LinkedList <String> descriptions = new LinkedList<String>();
|
---|
| 318 | for(String descString : desc)
|
---|
| 319 | descriptions.add(descString);
|
---|
| 320 | return descriptions;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | public LinkedList<String> getWarnings() {
|
---|
| 324 | return warnings;
|
---|
| 325 | }
|
---|
| 326 | }
|
---|