-
Notifications
You must be signed in to change notification settings - Fork 0
/
gargoyle.el
130 lines (102 loc) · 3.92 KB
/
gargoyle.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; gargoyle.el --- Java in Emacs
;; Copyright (C) 2016 Jess Balint
;; Author: Jess Balint <[email protected]>
;; Maintainer: Jess Balint <[email protected]>
;; Created: 13 Feb 2016
;; Keywords: java
;; Homepage: https://github.com/jbalint/emacs-gargoyle
;; This file is free software
;; along with this file. If not, see <http://www.gnu.org/licenses/>.
;; The MIT License (MIT)
;;
;; Copyright (c) 2016 Jess Balint
;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;; This file is not part of GNU Emacs.
;;; Commentary:
;; The Gargoyle system provides a facility for combining Java and
;; Emacs/Elisp. This file is the Emacs side of the bridge. The
;; remainder is implemented as a dynamic module (must be enabled in
;; Emacs 25 builds).
;;; Change Log:
;;; Code:
(require 'gargoyle-dm)
(require 'cl-lib)
(defvar gg-to-java-mappings nil
"Mappings to Java objects")
(defvar gg--class-hierarchy (make-hash-table)
"Class hierarchy (c.f. internals.org)")
;; type predicates - mainly for internal use
(defun gg--type-arrayp (type)
"Return t if `type' is an array type."
(and
(listp type)
(eq (car type) 'gg-array)))
(defun gg--type-array-component (array-type)
"Return the component type of the given array type."
(if (gg--type-arrayp array-type)
(cdr array-type)
nil))
(defun gg--type-primitivep (type)
"Return t if `type' is a primitive type."
(and
(listp type)
(eq (car type) 'gg-prim)))
(defun gg--type-classp (type)
"Return t if `type' is a Java class type."
(eq (type-of type) 'symbol))
;; object type predicates
(defun gg-objectp (object)
"Return t if `object' is a Java object."
(and
(listp object)
(eq (car object) 'gg-obj)))
(defun gg-classp (class)
"Return t if `class' is a Java class."
(and
(listp class)
(eq (car class) 'gg-obj)
(eq (nth 2 class) 'java.lang.Class)))
(defun gg--new-object (ptr class-name-sym)
"Create a new object from a raw JNI pointer."
(list 'gg-obj ptr class-name-sym))
(defun gg-toString (obj)
"Return the string representation of the object."
(gg--toString-raw (cadr obj)))
(defun gg-new (class-or-name &rest ctor-args)
"Create a new instance."
(let ((class (cond
((stringp class-or-name) (gg-find-class class-or-name))
((gg-objectp class-or-name) class-or-name)
(t (signal 'wrong-type-argument `("Expected class object or class name string:"
,(type-of class-or-name)
,class-or-name))))))
(gg--new-raw (cadr class))))
(define-error 'java-exception
"A Java exception. The cdr is the exception.")
(defun gg--class-add-by-name (class-name-sym)
"Add a class to the class hierarchy by providing the name of the class"
(unless (gethash class-name-sym gg--class-hierarchy)))
(defun gg--class-add-by-obj (class))
(defun gg-get-class-name (class)
(gg--get-class-name-raw (cadr class)))
(defun gg-get-superclass (class)
(gg--get-superclass-raw (cadr class)))
(provide 'gargoyle)
;;; gargoyle.el ends here