(defun dojo-java-get-or-create-service-interface-class-by-resource (resource-id) (log-java (format "Called get-or-create-service-interface-class-by-resource for resource [%s]" resource-id)) (let* ((id-to-resource (dojo-workspace-id-to-resource dojo-current-workspace)) (resource (gethash resource-id id-to-resource)) (class nil)) (if (null resource) (progn (log-java (format "[WARNING] Could not locate resource with id [%s], will do nothing." resource-id)) nil) (if (not (dojo-core-util-resource-modified-since-last-parse-p resource)) (progn (log-java (format "Resource [%s] was not modified since last parse." resource-id)) (setq class (dojo-js-api-get-api-class-by-resource resource)))) (if class (progn (log-java (format "Will return already parsed class [%s]" (dojo-class-id class))) class) (setq class (dojo-js-api-get-or-create-api-class-by-resource resource-id)) (let* ((resource-type (if resource (dojo-resource-type resource) nil)) (resource-path (if resource (dojo-resource-path resource) nil)) (resource-file-path (if resource (dojo-resource-file-path resource) nil))) (log-java (format "Will parse service interface [%s] of type [%s]" resource-path resource-type)) (log-java (format "... file-path is [%s]" resource-file-path)) (log-java (format "... class-id is [%s]" (dojo-class-id class))) (with-temp-buffer (buffer-disable-undo (current-buffer)) (insert-file-contents resource-file-path) (dojo-java-parse-interface class) (setf (dojo-resource-last-parsed-utc-seconds resource) (float-time)) (setf (dojo-resource-last-parsed-size resource) (buffer-size (current-buffer))) (setf (dojo-resource-parsed-id resource) (if (dojo-class-p class) (dojo-class-id class) nil)) (setf (dojo-resource-state resource) (if (null class) "parse-failed" "parsed")) (dojo-core-util-register-resource-project-for-save dojo-current-workspace resource) (log-java (format "Parsed resource [%s] with path [%s], resulting state is [%s]" resource-id resource-path (dojo-resource-state resource))) class)))))) (defun dojo-java-parse-interface (class) (goto-char (point-min)) (log-java (format "Starting to parse the java interface.")) (let* ((next-normal-block-comment-start (dojo-java-search-token-forward "/*")) (next-javadoc-block-comment-start (dojo-java-search-token-forward "/**")) (next-line-comment-start (dojo-java-search-token-forward "//")) (next-interface (dojo-java-search-token-forward "interface")) (next-open-curly-bracket (dojo-java-search-token-forward "{")) (next-public (dojo-java-search-token-forward "public")) (next-semicolon (dojo-java-search-token-forward ";")) (next-token nil) (prev-javadoc-comment nil) (prev-block-comment nil) (prev-method-start nil) (curr-method nil) (state "initial") (this-symbol (dojo-class-this-symbol class)) (iteration 0) (stop nil)) (while (not stop) (setq next-token (dojo-common-math-nil-aware-min next-normal-block-comment-start next-javadoc-block-comment-start next-line-comment-start next-interface next-open-curly-bracket next-public next-semicolon)) (log-java (format "[%s]: /*=%s /**=%s //=%s i=%s {=%s p=%s ;=%s next=%s" iteration next-normal-block-comment-start next-javadoc-block-comment-start next-line-comment-start next-interface next-open-curly-bracket next-public next-semicolon next-token)) (cond ((null next-token) (setq stop t)) ((or (eq next-token next-javadoc-block-comment-start) (eq next-token next-normal-block-comment-start)) (let ((next-block-comment-end (dojo-java-search-token-forward "*/"))) (if (eq next-token next-javadoc-block-comment-start) (progn (setq prev-javadoc-comment (buffer-substring-no-properties next-token (if (null next-block-comment-end) (point-max) (+ next-block-comment-end 2)))) (log-java (format "... found javadoc-comment [%s]" prev-javadoc-comment))) (setq prev-block-comment (buffer-substring-no-properties next-token (if (null next-block-comment-end) (point-max) (+ next-block-comment-end 2)))) (log-java (format "... found normal block comment [%s]" prev-block-comment))) (goto-char (if (null next-block-comment-end) (point-max) (1+ next-block-comment-end))) (if (string= state "method") (progn (setq curr-method (concat (if curr-method curr-method "") (buffer-substring-no-properties prev-method-start next-token))) (setq prev-method-start (1+ (point))))) (setq next-normal-block-comment-start (dojo-java-search-token-forward "/*")) (setq next-javadoc-block-comment-start (dojo-java-search-token-forward "/**")) (if (and next-line-comment-start (< next-line-comment-start (point))) (setq next-line-comment-start (dojo-java-search-token-forward "//"))) (if (and next-interface (< next-interface (point))) (setq next-interface (dojo-java-search-token-forward "interface"))) (if (and next-open-curly-bracket (< next-open-curly-bracket (point))) (setq next-open-curly-bracket (dojo-java-search-token-forward "{"))) (if (and next-public (< next-public (point))) (setq next-public (dojo-java-search-token-forward "public"))) (if (and next-semicolon (< next-semicolon (point))) (setq next-semicolon (dojo-java-search-token-forward ";"))))) ((eq next-token next-line-comment-start) (goto-char (1+ next-token)) (move-end-of-line nil) (log-java (format "... skipping line comment at line [%s]" (line-number-at-pos))) (if (string= state "method") (progn (setq curr-method (concat (if curr-method curr-method "") (buffer-substring-no-properties prev-method-start next-token))) (setq prev-method-start (point)))) (if (and next-normal-block-comment-start (< next-normal-block-comment-start (point))) (setq next-normal-block-comment-start (dojo-java-search-token-forward "/*"))) (if (and next-javadoc-block-comment-start (< next-javadoc-block-comment-start (point))) (setq next-javadoc-block-comment-start (dojo-java-search-token-forward "/**"))) (setq next-line-comment-start (dojo-java-search-token-forward "//")) (if (and next-line-comment-start (< next-line-comment-start (point))) (setq next-line-comment-start (dojo-java-search-token-forward "//"))) (if (and next-interface (< next-interface (point))) (setq next-interface (dojo-java-search-token-forward "interface"))) (if (and next-open-curly-bracket (< next-open-curly-bracket (point))) (setq next-open-curly-bracket (dojo-java-search-token-forward "{"))) (if (and next-public (< next-public (point))) (setq next-public (dojo-java-search-token-forward "public"))) (if (and next-semicolon (< next-semicolon (point))) (setq next-semicolon (dojo-java-search-token-forward ";")))) ((eq next-token next-interface) (goto-char (1+ next-token)) (if (string= state "initial") (setq state "interface")) (log-java (format "... found interface keyword at position [%s]" next-token)) (setq next-interface (dojo-java-search-token-forward "interface"))) ((eq next-token next-open-curly-bracket) (goto-char (1+ next-token)) (if (string= state "interface") (setq state "block")) (log-java (format "... found open curly bracket at position [%s]" next-token)) (setq next-open-curly-bracket (dojo-java-search-token-forward "{"))) ((eq next-token next-public) (goto-char (1+ next-token)) (if (string= state "block") (progn (setq prev-method-start next-token) (setq state "method") (log-java (format "... found public within block, setting prev-method-start to [%s]" prev-method-start))) (log-java (format "... ignoring public outside block at [%s]" next-token))) (setq next-public (dojo-java-search-token-forward "public"))) ((eq next-token next-semicolon) (goto-char (1+ next-token)) (if (string= state "method") (progn (setq curr-method (concat (if curr-method curr-method "") (buffer-substring-no-properties prev-method-start (1+ next-token)))) (setq curr-method (replace-regexp-in-string "\n" " " curr-method)) (log-java (format "... found semicolon, extracted method [%s]" curr-method)) (dojo-java-register-method-symbol this-symbol curr-method) (setq prev-method-start nil) (setq curr-method nil) (setq state "block")) (log-java (format "... ignoring semicolon outside method at [%s]" next-token))) (setq next-semicolon (dojo-java-search-token-forward ";"))) (t (log-java (format "[WARNING] We should never fall through all cases, please inspect code.")) (setq stop t))) (incf iteration)) (log-java (format "Finished parsing interface in iteration [%s]." iteration)))) (defun dojo-java-search-token-forward (token) (let ((end-of-match (save-excursion (search-forward token nil t)))) (if (null end-of-match) nil (match-beginning 0)))) (defun dojo-java-register-method-symbol (this-symbol method-string) (log-java (format "Registering method-string [%s]" method-string)) ; E.g. method-string might be ; public void signCertificateRequestDirectly(Long certificateId, Long organisationPersonId, Long caId, Long signerId, String password); (let* ((open-round-bracket-pos (string-match-p "(" method-string)) (close-round-bracket-pos (string-match-p ")" method-string)) (prefix (if (null open-round-bracket-pos) nil (substring method-string 0 open-round-bracket-pos))) ; public void signCertificateRequestDirectly (end-of-name-index (if prefix (last-index-of prefix "[a-zA-Z0-9$_]") nil)) (name-prefix (if (null end-of-name-index) nil (substring prefix 0 (1+ end-of-name-index)))) ; public void signCertificateRequestDirectly (whitespace-before-name-index (if (null name-prefix) nil (last-index-of name-prefix "[ \f\t\n\r\v]"))) (name (if (null name-prefix) nil (substring name-prefix (1+ whitespace-before-name-index)))) (type-prefix (if (null name-prefix) nil (dojo-common-strings-trim (substring name-prefix 0 whitespace-before-name-index)))) (whitespace-before-type-index (if (null type-prefix) nil (last-index-of type-prefix "[ \f\t\n\r\v]"))) (type (if (null type-prefix) nil (dojo-common-strings-trim (substring type-prefix (if (null whitespace-before-type-index) 0 (1+ whitespace-before-type-index)))))) (return-symbol (construct-dojo-symbol dojo-current-workspace this-symbol nil (dojo-java-get-symbol-type-by-java-type type))) (argument-string (if (or (null open-round-bracket-pos) (null close-round-bracket-pos)) nil (substring method-string (1+ open-round-bracket-pos) close-round-bracket-pos))) (argument-tokens (if argument-string (split-string argument-string "," t "[ \f\t\n\r\v]") nil)) (argument-symbols ()) ) (log-java (format "(=%s, )=%s, prefix=[%s],end-of-name-index=[%s], name-prefix=[%s]" open-round-bracket-pos close-round-bracket-pos prefix end-of-name-index name-prefix)) (log-java (format "whitespace-before-name=[%s], name=[%s]" whitespace-before-name-index name)) (log-java (format "type-prefix=[%s], type=[%s]" type-prefix type)) (log-java (format "argument-string=[%s]" argument-string)) (dolist (argument-token argument-tokens) (log-java (format "... processing argument-token [%s]" argument-token)) (let* ((arg-tokens (split-string argument-token "[ \f\t\n\r\v]" t "[ \f\t\n\r\v]")) (type-token (nth 0 arg-tokens)) (name-token (nth 1 arg-tokens)) (argument-symbol (construct-dojo-symbol dojo-current-workspace this-symbol name-token (dojo-java-get-symbol-type-by-java-type type-token)))) (log-java (format "...... found argument-type [%s], argument-name [%s]" type-token name-token)) (push argument-symbol argument-symbols))) (let* ((function-symbol (construct-dojo-symbol-function dojo-current-workspace this-symbol name (nreverse argument-symbols) return-symbol))) (log-java (format "Will register object member function %s" (dojo-core-util-symbol-to-short-string function-symbol))) (dojo-symbol-register-object-member name function-symbol this-symbol)))) (defun dojo-java-get-symbol-type-by-java-type (java-type) (cond ((or (string= java-type "Long") (string= java-type "long")) 'DOJO-JSTYPE-LONG) ((or (string= java-type "Integer") (string= java-type "int")) 'DOJO-JSTYPE-INTEGER) ((or (string= java-type "Double") (string= java-type "double")) 'DOJO-JSTYPE-DOUBLE) ((or (string= java-type "Float") (string= java-type "float")) 'DOJO-JSTYPE-FLOAT) ((or (string= java-type "Boolean") (string= java-type "boolean")) 'DOJO-JSTYPE-BOOLEAN) ((string= java-type "String") 'DOJO-JSTYPE-STRING) (t 'DOJO-JSTYPE-OBJECT))) ;(split-string "public void signCertificateRequestDirectly(Long certificateId, Long organisationPersonId, Long caId, Long signerId, String password);") (provide 'dojo-java-parse)