groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blackd...@apache.org
Subject groovy git commit: introduction of Realms
Date Sun, 04 Sep 2016 11:27:37 GMT
Repository: groovy
Updated Branches:
  refs/heads/master f35bdac70 -> 9be5459c9


introduction of Realms


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9be5459c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9be5459c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9be5459c

Branch: refs/heads/master
Commit: 9be5459c906ba106f235d40ebe0f25b7193a0467
Parents: f35bdac
Author: Jochen Theodorou <blackdrag@gmx.org>
Authored: Sat Sep 3 10:50:21 2016 +0200
Committer: Jochen Theodorou <blackdrag@gmx.org>
Committed: Sun Sep 4 13:26:34 2016 +0200

----------------------------------------------------------------------
 src/main/groovy/lang/GroovySystem.java          |  2 +
 .../groovy/internal/util/UncheckedThrow.java    | 34 ++++++++++
 .../groovy/lang/annotation/Incubating.java      | 34 ++++++++++
 src/main/org/apache/groovy/metaclass/Realm.java | 67 ++++++++++++++++++++
 4 files changed, 137 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9be5459c/src/main/groovy/lang/GroovySystem.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovySystem.java b/src/main/groovy/lang/GroovySystem.java
index b652446..0a41035 100644
--- a/src/main/groovy/lang/GroovySystem.java
+++ b/src/main/groovy/lang/GroovySystem.java
@@ -39,6 +39,7 @@ public final class GroovySystem {
     /**
      * If true then the MetaClass will only use reflection for method dispatch, property
access, etc.
      */
+    @Deprecated
     private static final boolean USE_REFLECTION;
 
     /**
@@ -57,6 +58,7 @@ public final class GroovySystem {
         // Do not allow this class to be instantiated
     }
 
+    @Deprecated
     public static boolean isUseReflection() {
         return USE_REFLECTION;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9be5459c/src/main/org/apache/groovy/internal/util/UncheckedThrow.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/internal/util/UncheckedThrow.java b/src/main/org/apache/groovy/internal/util/UncheckedThrow.java
new file mode 100644
index 0000000..44be19b
--- /dev/null
+++ b/src/main/org/apache/groovy/internal/util/UncheckedThrow.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2003-2016 the original author or authors.
+ *
+ * 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.
+ */
+
+package org.apache.groovy.internal.util;
+
+import org.apache.groovy.lang.annotation.Incubating;
+
+/**
+ * Allows to throw a checked exception unchecked.
+ */
+@Incubating
+public class UncheckedThrow {
+    public static void rethrow( final Throwable checkedException ) {
+        UncheckedThrow.<RuntimeException>thrownInsteadOf( checkedException );
+    }
+    @SuppressWarnings("unchecked")
+    private static <T extends Throwable> void thrownInsteadOf(Throwable t) throws T
{
+        throw (T) t;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/groovy/blob/9be5459c/src/main/org/apache/groovy/lang/annotation/Incubating.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/lang/annotation/Incubating.java b/src/main/org/apache/groovy/lang/annotation/Incubating.java
new file mode 100644
index 0000000..e612f64
--- /dev/null
+++ b/src/main/org/apache/groovy/lang/annotation/Incubating.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2003-2016 the original author or authors.
+ *
+ * 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.
+ */
+
+package org.apache.groovy.lang.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Annotation to indicate experimental and still to be refined API, which may change at any
time
+ */
+@Incubating
+@Documented
+@Retention(value=RUNTIME)
+@Target(value={TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, ANNOTATION_TYPE, PACKAGE})
+public @interface Incubating {
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/9be5459c/src/main/org/apache/groovy/metaclass/Realm.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/metaclass/Realm.java b/src/main/org/apache/groovy/metaclass/Realm.java
new file mode 100644
index 0000000..16f3806
--- /dev/null
+++ b/src/main/org/apache/groovy/metaclass/Realm.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2003-2016 the original author or authors.
+ *
+ * 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.
+ */
+
+package org.apache.groovy.metaclass;
+
+import groovy.lang.GroovySystem;
+import groovy.lang.MetaClass;
+import groovy.lang.MetaClassImpl;
+import groovy.lang.MetaClassRegistry;
+import org.apache.groovy.lang.annotation.Incubating;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A Realm is the representation of a metaclass layer in a tree of realm objects.
+ */
+@Incubating
+public final class Realm {
+    public final static Realm ROOT = new Realm("Root", null);
+
+    private final String name;
+    private final Realm parent;
+    private final ClassValue<MetaClass> cv = new ClassValue() {
+        @Override
+        protected MetaClass computeValue(Class type) {
+            return new MetaClassImpl(type);
+        }
+    };
+
+    private Realm(String name, Realm parent) {
+        this.name = name;
+        this.parent = parent;
+    }
+
+    public Realm createRealm(String name) {
+        Objects.requireNonNull(name, "missing realm name");
+        return new Realm(name, this);
+    }
+
+    @Override
+    public String toString() {
+        return "Realm{" +
+                "name='" + name + '\'' +
+                ", parent=" + parent +
+                '}';
+    }
+
+    public MetaClass getMetaClass(Class<?> theClass) {
+        return cv.get(theClass);
+    }
+}


Mime
View raw message