22
33import com .fasterxml .jackson .databind .ObjectMapper ;
44import de .fraunhofer .iem .swan .data .Method ;
5+ import de .fraunhofer .iem .swan .io .doc .Javadoc ;
6+ import de .fraunhofer .iem .swan .io .doc .ssldoclet .MethodBlockType ;
57import edu .stanford .nlp .util .StringUtils ;
68import org .slf4j .Logger ;
79import org .slf4j .LoggerFactory ;
810
911import java .io .File ;
1012import java .io .IOException ;
13+ import java .util .ArrayList ;
1114import java .util .HashSet ;
1215import java .util .List ;
1316import java .util .Set ;
@@ -24,6 +27,7 @@ public class SrmListUtils {
2427
2528 /**
2629 * Imports SRMs from JSON file.
30+ *
2731 * @param file JSON File that stores security-relevant methods
2832 * @return object containing all security-relevant methods
2933 */
@@ -38,8 +42,9 @@ public static SrmList importFile(String file) throws IOException {
3842
3943 /**
4044 * Exports SRM list to JSON file.
45+ *
4146 * @param srmList list of SRMa
42- * @param file path of JSON file
47+ * @param file path of JSON file
4348 */
4449 public static void exportFile (SrmList srmList , String file ) throws IOException {
4550
@@ -58,4 +63,41 @@ public static void removeUndocumentedMethods(SrmList list) {
5863 list .getMethods ().remove (method );
5964 }
6065 }
66+
67+ /**
68+ * Adds doc comments to method set.
69+ * @param methods methods to be updated
70+ * @param javadocs list of Javadoc objects
71+ * @return updated method set
72+ */
73+ public static Set <Method > addDocComments (Set <Method > methods , ArrayList <Javadoc > javadocs ) {
74+
75+ for (Javadoc doc : javadocs ) {
76+
77+ for (MethodBlockType methodBlock : doc .getMethodBlocks ().values ()) {
78+
79+ Method method = methods .stream ().filter (m -> methodBlock .getSignature ()
80+ .equals (m .getJavaSignature ())).findAny ().orElse (null );
81+
82+ if (method != null ) {
83+
84+ de .fraunhofer .iem .swan .data .Javadoc javadoc = new de .fraunhofer .iem .swan .data .Javadoc ();
85+
86+ if (doc .getPackageBlock ().getClassBlock ().getClassCommentBlock () != null ) {
87+ String classComment = doc .getPackageBlock ().getClassBlock ().getClassCommentBlock ().getClassComment ().getValue ();
88+
89+ javadoc .setClassComment (classComment );
90+ }
91+
92+ if (methodBlock .getMethodCommentBlock () != null ) {
93+ String methodComment = methodBlock .getMethodCommentBlock ().getMethodComment ().getValue ();
94+
95+ javadoc .setMethodComment (methodComment );
96+ }
97+ method .setJavadoc (javadoc );
98+ }
99+ }
100+ }
101+ return methods ;
102+ }
61103}
0 commit comments