Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial (incomplete) definition for java/lang/Exception and java/lang/Throwable. #334

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ cc_library(
deps = [
":jni_dep",
"//class_defs:java_lang_classes",
"//class_defs:java_lang_exception",
"//class_defs:java_lang_throwable",
"//class_defs:java_util_array_list",
"//class_defs:java_util_classes",
"//implementation:array",
Expand Down
32 changes: 32 additions & 0 deletions class_defs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ filegroup(

exports_files(["LICENSE"])

cc_library(
name = "java_lang_exception",
hdrs = ["java_lang_exception.h"],
deps = [
":java_lang_throwable",
"//:jni_dep",
"//implementation:class",
"//implementation:constructor",
"//implementation:method",
"//implementation:params",
"//implementation:return",
"//implementation:self",
"//implementation:static",
],
)

cc_library(
name = "java_lang_throwable",
hdrs = ["java_lang_throwable.h"],
deps = [
"//:jni_dep",
"//implementation:array",
"//implementation:class",
"//implementation:constructor",
"//implementation:method",
"//implementation:params",
"//implementation:return",
"//implementation:self",
"//implementation:static",
],
)

cc_library(
name = "java_lang_classes",
hdrs = ["java_lang_classes.h"],
Expand Down
8 changes: 8 additions & 0 deletions class_defs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
** WARNING **

Class definitions in this directory may have their path change in the future, you may be better suited creating copies until full scrapes of APIs are provided in the future.

These are used to bootstrap JNI Bind, but may change in the future, and may also be superseded by separate more complete definitions.

Some definitions in this directory exist solely for phase 1 compilation and as such may be incomplete.

7 changes: 0 additions & 7 deletions class_defs/java_lang_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ static constexpr Class kJavaLangString{
Method{"toString", Return{jstring{}}, Params<>{}},
};

static constexpr Class kJavaLangException{
"java/lang/Exception",
Method{"getMessage", Return{jstring{}}, Params<>{}},
Method{"printStackTrace", Return{}, Params<>{}},
Method{"toString", Return{jstring{}}, Params<>{}},
};

// clang-format on

} // namespace jni
Expand Down
45 changes: 45 additions & 0 deletions class_defs/java_lang_exception.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef JNI_BIND_CLASS_DEFS_JAVA_LANG_EXCEPTION_H_
#define JNI_BIND_CLASS_DEFS_JAVA_LANG_EXCEPTION_H_

#include "class_defs/java_lang_throwable.h"
#include "implementation/class.h"
#include "implementation/constructor.h"
#include "implementation/method.h"
#include "implementation/params.h"
#include "implementation/return.h"
#include "jni_dep.h"

namespace jni {

static constexpr Class kJavaLangException{
"java/lang/Exception",
Constructor{},
Constructor<jstring>{},
Constructor{jstring{}, kJavaLangThrowable, jboolean{}, jboolean{}},
Constructor{kJavaLangThrowable},

// Inherited.
Method{"getMessage", Return{jstring{}}, Params<>{}},
Method{"printStackTrace", Return{}, Params<>{}},
Method{"toString", Return{jstring{}}, Params<>{}},
};

} // namespace jni

#endif // JNI_BIND_CLASS_DEFS_JAVA_LANG_EXCEPTION_H_
37 changes: 37 additions & 0 deletions class_defs/java_lang_throwable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef JNI_BIND_CLASS_DEFS_JAVA_LANG_THROWABLE_H_
#define JNI_BIND_CLASS_DEFS_JAVA_LANG_THROWABLE_H_

#include "implementation/class.h"
#include "implementation/constructor.h"
#include "implementation/self.h"
#include "jni_dep.h"

namespace jni {

static constexpr Class kJavaLangThrowable{
"java/lang/Throwable",
Constructor{},
Constructor<jstring>{},
Constructor{jstring{}, Self{}},
Constructor{jstring{}, Self{}, jboolean{}, jboolean{}},
Constructor{Self{}}};

} // namespace jni

#endif // JNI_BIND_CLASS_DEFS_JAVA_LANG_THROWABLE_H_
2 changes: 2 additions & 0 deletions jni_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static constexpr Configuration kConfig{

// Convenience headers for system libraries.
#include "class_defs/java_lang_classes.h"
#include "class_defs/java_lang_exception.h"
#include "class_defs/java_lang_throwable.h"
#include "class_defs/java_util_array_list.h"
#include "class_defs/java_util_classes.h"

Expand Down