Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.virgo.kernel.core/src/main/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcer.aj')
-rw-r--r--org.eclipse.virgo.kernel.core/src/main/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcer.aj73
1 files changed, 73 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.core/src/main/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcer.aj b/org.eclipse.virgo.kernel.core/src/main/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcer.aj
new file mode 100644
index 00000000..5dc94533
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/main/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcer.aj
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.serviceability.enforcement;
+
+import org.aspectj.lang.annotation.SuppressAjWarnings;
+import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
+
+
+/**
+ * Aspect that enforces that parameters annotated with {@link NonNull} are, in fact, non null.
+ * <p/>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe.
+ *
+ */
+public final aspect NonNullAssertionEnforcer {
+
+ pointcut serviceability() : within(org.eclipse.virgo.kernel.serviceability..*);
+
+ pointcut executingOperationWithNonNullFirstParameter(Object obj) :
+ !serviceability() &&
+ (execution(* *(@NonNull (*), ..)) || preinitialization(*.new(@NonNull (*), ..))) && args(obj, ..) ;
+
+ pointcut executingOperationWithNonNullSecondParameter(Object obj) :
+ !serviceability() &&
+ (execution(* *(*, @NonNull (*), ..)) || preinitialization(*.new(*, @NonNull (*), ..))) && args(*, obj, ..);
+
+ pointcut executingOperationWithNonNullThirdParameter(Object obj) :
+ !serviceability() &&
+ (execution(* *(*, *, @NonNull (*), ..)) || preinitialization(*.new(*, *, @NonNull (*), ..))) && args(*, * , obj, ..);
+
+ pointcut executingOperationWithNonNullFourthParameter(Object obj) :
+ !serviceability() &&
+ (execution(* *(*, *, *, @NonNull (*), ..)) || preinitialization(*.new(*, *, *, @NonNull (*), ..))) && args(*, *, *, obj, ..);
+
+ pointcut executingOperationWithNonNullFifthParameter(Object obj) :
+ !serviceability() &&
+ (execution(* *(*, *, *, *, @NonNull (*), ..)) || preinitialization(*.new(*, *, *, *, @NonNull (*), ..))) && args(*, *, *, *, obj, ..);
+
+ before(Object argValue) : executingOperationWithNonNullFirstParameter(argValue) {
+ Assert.notNull(argValue, "Argument [1] cannot be null");
+ }
+
+ before(Object argValue) : executingOperationWithNonNullSecondParameter(argValue) {
+ Assert.notNull(argValue, "Argument [2] cannot be null");
+ }
+
+ before(Object argValue) : executingOperationWithNonNullThirdParameter(argValue) {
+ Assert.notNull(argValue, "Argument [3] cannot be null");
+ }
+
+ @SuppressAjWarnings({"adviceDidNotMatch"})
+ before(Object argValue) : executingOperationWithNonNullFourthParameter(argValue) {
+ Assert.notNull(argValue, "Argument [4] cannot be null");
+ }
+
+ @SuppressAjWarnings({"adviceDidNotMatch"})
+ before(Object argValue) : executingOperationWithNonNullFifthParameter(argValue) {
+ Assert.notNull(argValue, "Argument [5] cannot be null");
+ }
+}

Back to the top