Java: no namespace indent

This commit is contained in:
Max Kellermann 2021-03-28 13:15:38 +02:00 committed by Max Kellermann
parent a52ce7bb7b
commit f58c14a74a
9 changed files with 321 additions and 305 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -36,23 +36,24 @@
#include <cassert>
namespace Java {
/**
/**
* Wrapper for a local "jclass" reference.
*/
class Class : public LocalRef<jclass> {
public:
class Class : public LocalRef<jclass> {
public:
Class(JNIEnv *env, jclass cls) noexcept
:LocalRef<jclass>(env, cls) {}
Class(JNIEnv *env, const char *name) noexcept
:LocalRef<jclass>(env, env->FindClass(name)) {}
};
};
/**
/**
* Wrapper for a global "jclass" reference.
*/
class TrivialClass : public TrivialRef<jclass> {
public:
class TrivialClass : public TrivialRef<jclass> {
public:
void Find(JNIEnv *env, const char *name) noexcept {
assert(env != nullptr);
assert(name != nullptr);
@ -76,7 +77,8 @@ namespace Java {
env->DeleteLocalRef(cls);
return true;
}
};
}
};
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,28 +35,30 @@
#include <jni.h>
namespace Java {
class Exception : public std::runtime_error {
public:
explicit Exception(JNIEnv *env, jthrowable e) noexcept;
};
/**
class Exception : public std::runtime_error {
public:
explicit Exception(JNIEnv *env, jthrowable e) noexcept;
};
/**
* Check if a Java exception has occurred, and if yes, convert
* it to a C++ #Exception and throw that.
*/
void RethrowException(JNIEnv *env);
void RethrowException(JNIEnv *env);
/**
/**
* Check if an exception has occurred, and discard it.
*
* @return true if an exception was found (and discarded)
*/
static inline bool DiscardException(JNIEnv *env) noexcept {
static inline bool DiscardException(JNIEnv *env) noexcept {
bool result = env->ExceptionCheck();
if (result)
env->ExceptionClear();
return result;
}
}
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -37,13 +37,14 @@
class AllocatedPath;
namespace Java {
/**
/**
* Wrapper for a java.io.File object.
*/
class File : public LocalObject {
class File : public LocalObject {
static jmethodID getAbsolutePath_method;
public:
public:
gcc_nonnull_all
static void Initialise(JNIEnv *env) noexcept;
@ -60,7 +61,8 @@ namespace Java {
gcc_pure gcc_nonnull_all
static AllocatedPath ToAbsolutePath(JNIEnv *env,
jobject file) noexcept;
};
}
};
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,10 +30,12 @@
#include "Global.hxx"
namespace Java {
JavaVM *jvm;
void Init(JNIEnv *env) noexcept
{
JavaVM *jvm;
void Init(JNIEnv *env) noexcept
{
env->GetJavaVM(&jvm);
}
}
} // namespace Java

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,24 +35,26 @@
#include <jni.h>
namespace Java {
extern JavaVM *jvm;
void Init(JNIEnv *env) noexcept;
extern JavaVM *jvm;
static inline void
DetachCurrentThread() noexcept
{
void Init(JNIEnv *env) noexcept;
static inline void
DetachCurrentThread() noexcept
{
if (jvm != nullptr)
jvm->DetachCurrentThread();
}
}
static inline gcc_pure
JNIEnv *GetEnv() noexcept
{
static inline gcc_pure
JNIEnv *GetEnv() noexcept
{
JNIEnv *env;
jvm->AttachCurrentThread(&env, nullptr);
return env;
}
}
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -37,13 +37,14 @@
#include <cassert>
namespace Java {
/**
/**
* Wrapper for a local "jobject" reference.
*/
typedef LocalRef<jobject> LocalObject;
typedef LocalRef<jobject> LocalObject;
class GlobalObject : public GlobalRef<jobject> {
public:
class GlobalObject : public GlobalRef<jobject> {
public:
/**
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
@ -52,15 +53,15 @@ namespace Java {
GlobalObject(JNIEnv *env, jobject obj) noexcept
:GlobalRef<jobject>(env, obj) {}
};
};
/**
/**
* Utilities for java.net.Object.
*/
class Object {
class Object {
static jmethodID toString_method;
public:
public:
static void Initialise(JNIEnv *env);
static jstring toString(JNIEnv *env, jobject o) {
@ -70,7 +71,8 @@ namespace Java {
return (jstring)env->CallObjectMethod(o, toString_method);
}
};
}
};
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -38,15 +38,16 @@
#include <utility>
namespace Java {
/**
/**
* Hold a local reference on a JNI object.
*/
template<typename T>
class LocalRef {
template<typename T>
class LocalRef {
JNIEnv *env;
T value = nullptr;
public:
public:
LocalRef() noexcept = default;
/**
@ -90,16 +91,16 @@ namespace Java {
operator T() const noexcept {
return value;
}
};
};
/**
/**
* Hold a global reference on a JNI object.
*/
template<typename T>
class GlobalRef {
template<typename T>
class GlobalRef {
T value;
public:
public:
/**
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
@ -140,20 +141,20 @@ namespace Java {
operator T() const noexcept {
return value;
}
};
};
/**
/**
* Container for a global reference to a JNI object that gets
* initialised and deinitialised explicitly. Since there is
* no implicit initialisation in the default constructor, this
* is a trivial C++ class. It should only be used for global
* variables that are implicitly initialised with zeroes.
*/
template<typename T>
class TrivialRef {
template<typename T>
class TrivialRef {
T value;
public:
public:
TrivialRef() = default;
TrivialRef(const TrivialRef &other) = delete;
@ -201,7 +202,8 @@ namespace Java {
operator T() const noexcept {
return value;
}
};
}
};
} // namespace Java
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -38,11 +38,12 @@
#include <string>
namespace Java {
/**
/**
* Wrapper for a local "jstring" reference.
*/
class String : public LocalRef<jstring> {
public:
class String : public LocalRef<jstring> {
public:
String(JNIEnv *env, jstring value) noexcept
:LocalRef<jstring>(env, value) {}
@ -76,7 +77,8 @@ namespace Java {
std::string ToString() const noexcept {
return ToString(GetEnv(), Get());
}
};
}
};
} // namespace Java
#endif