You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/01/23 10:57:39 UTC
[isis] 02/10: ISIS-1846 introduces _Constants (internal API)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-1846_internal_utils
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 70a5f0df5029d7b937f19f38dbe922faf3f7e9a4
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Jan 23 09:02:35 2018 +0100
ISIS-1846 introduces _Constants (internal API)
---
.../apache/isis/applib/internal/_Constants.java | 46 ++++++
.../compare/_Comparators_SequenceCompare.java | 5 +
.../core/commons/exceptions/ExceptionUtils.java | 6 +-
.../isis/core/commons/reflection/Reflect.java | 167 ---------------------
4 files changed, 54 insertions(+), 170 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/_Constants.java b/core/applib/src/main/java/org/apache/isis/applib/internal/_Constants.java
new file mode 100644
index 0000000..ba03469
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/_Constants.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.isis.applib.internal;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * A collection of commonly used constants.
+ * <p>
+ * WARNING: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * Public access will be removed once we migrate to Java 9+ modules.
+ *
+ * @since 2.0.0
+ */
+public final class _Constants {
+
+ private _Constants(){}
+
+ /**
+ * Convenient e.g. for reflective invocation
+ */
+ public static Object[] emptyObjects = {};
+
+ /**
+ * Convenient e.g. for reflective invocation
+ */
+ public static Class<?>[] emptyClasses = {};
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/compare/_Comparators_SequenceCompare.java b/core/applib/src/main/java/org/apache/isis/applib/internal/compare/_Comparators_SequenceCompare.java
index 2bbf6f9..dfbacee 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/internal/compare/_Comparators_SequenceCompare.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/compare/_Comparators_SequenceCompare.java
@@ -24,6 +24,11 @@ import javax.annotation.Nullable;
import org.apache.isis.applib.internal.base._Strings;
+/**
+ *
+ * package private mixin for utility class {@link _Comparators}
+ *
+ */
final class _Comparators_SequenceCompare {
private _Comparators_SequenceCompare(){}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/commons/exceptions/ExceptionUtils.java b/core/metamodel/src/main/java/org/apache/isis/core/commons/exceptions/ExceptionUtils.java
index 1b313c6..f684dc8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/commons/exceptions/ExceptionUtils.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/commons/exceptions/ExceptionUtils.java
@@ -26,7 +26,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.isis.core.commons.reflection.Reflect;
+import org.apache.isis.applib.internal._Constants;
/**
* <p>Provides utilities for manipulating and examining
@@ -69,7 +69,7 @@ public class ExceptionUtils {
static {
Method causeMethod;
try {
- causeMethod = Throwable.class.getMethod("getCause", Reflect.emptyClasses);
+ causeMethod = Throwable.class.getMethod("getCause", _Constants.emptyClasses);
} catch (Exception e) {
causeMethod = null;
}
@@ -248,7 +248,7 @@ public class ExceptionUtils {
Class<?> cls = throwable.getClass();
for (final String causeMethodName : CAUSE_METHOD_NAMES) {
try {
- Method method = cls.getMethod(causeMethodName, Reflect.emptyClasses);
+ Method method = cls.getMethod(causeMethodName, _Constants.emptyClasses);
if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
return true;
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/commons/reflection/Reflect.java b/core/metamodel/src/main/java/org/apache/isis/core/commons/reflection/Reflect.java
deleted file mode 100644
index 82cc7e5..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/commons/reflection/Reflect.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.isis.core.commons.reflection;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.stream.Stream;
-
-/**
- *
- * Provides shortcuts for common java.lang.reflect idioms.
- *
- * @author ahuber@apache.org
- * @since 2.0.0
- *
- */
-public class Reflect {
-
- public static Object[] emptyObjects = {};
- public static Class<?>[] emptyClasses = {};
-
- // -- CLASS REFLECTION
-
- /**
- * Returns declared methods of this class/interface and all super classes/interfaces.
- * @param type
- * @return
- */
- public static List<Method> getAllDeclaredMethods(Class<?> type) {
- final List<Method> methods = new ArrayList<>();
-
- Stream.of(type.getDeclaredMethods()).forEach(methods::add);
- visitInterfaces(type,c->Stream.of(c.getDeclaredMethods()).forEach(methods::add));
- visitSuperclassesOf(type,c->Stream.of(c.getDeclaredMethods()).forEach(methods::add));
- return methods;
- }
-
- /**
- * Returns declared fields of this class/interface and all super classes/interfaces.
- * @param type
- * @return
- */
- public static List<Field> getAllDeclaredFields(Class<?> type) {
- final List<Field> fields = new ArrayList<>();
-
- Stream.of(type.getDeclaredFields()).forEach(fields::add);
- visitInterfaces(type,c->Stream.of(c.getDeclaredFields()).forEach(fields::add));
- visitSuperclassesOf(type,c->Stream.of(c.getDeclaredFields()).forEach(fields::add));
- return fields;
- }
-
- public static void visitSuperclassesOf(final Class<?> clazz, final Consumer<Class<?>> visitor){
- final Class<?> superclass = clazz.getSuperclass();
- if(superclass!=null){
- visitor.accept(superclass);
- visitSuperclassesOf(superclass, visitor);
- }
- }
-
- public static void visitInterfaces(final Class<?> clazz, final Consumer<Class<?>> visitor){
- if(clazz.isInterface())
- visitor.accept(clazz);
-
- for(Class<?> interf : clazz.getInterfaces())
- visitor.accept(interf);
- }
-
- public static Method getGetter(Object bean, String propertyName) throws IntrospectionException {
- final BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
- for(PropertyDescriptor pd:beanInfo.getPropertyDescriptors()){
- if(!pd.getName().equals(propertyName))
- continue;
- return pd.getReadMethod();
- }
- return null;
- }
-
- // -- PRIMITIVE TYPES
-
- private static final Set<Class<?>> primitives = new HashSet<>(Arrays.asList(
- boolean.class,
- byte.class,
- char.class,
- double.class,
- float.class,
- int.class,
- long.class,
- short.class
- //void.class //separated out into its own predicate: isVoid(...)
- ));
-
- private static final Set<Class<?>> primitiveWrappers = new HashSet<>(Arrays.asList(
- Boolean.class,
- Byte.class,
- Character.class,
- Double.class,
- Float.class,
- Integer.class,
- Long.class,
- Short.class
- //Void.class //separated out into its own predicate: isVoid(...)
- ));
-
- // -- TYPE PREDICATES
-
- public static boolean isVoid(Class<?> c) {
- Objects.requireNonNull(c);
- return c == void.class || c == Void.class;
- }
-
- public static boolean isPrimitive(Class<?> c) {
- Objects.requireNonNull(c);
- return primitives.contains(c);
- }
-
- public static boolean isPrimitiveWrapper(Class<?> c) {
- Objects.requireNonNull(c);
- return primitiveWrappers.contains(c);
- }
-
-
- // -- METHOD PREDICATES
-
- public static boolean isNoArg(Method m) {
- Objects.requireNonNull(m);
- return m.getParameterTypes().length==0;
- }
-
- public static boolean isPublic(Method m) {
- Objects.requireNonNull(m);
- return Modifier.isPublic(m.getModifiers());
- }
-
- public static boolean isVoid(Method m) {
- Objects.requireNonNull(m);
- return isVoid(m.getReturnType());
- }
-
-}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.