]> source.dussan.org Git - aspectj.git/commitdiff
Fix 431976: avoid uninitialized messages if tjp used in if
authorAndy Clement <aclement@gopivotal.com>
Wed, 11 Jun 2014 17:33:12 +0000 (10:33 -0700)
committerAndy Clement <aclement@gopivotal.com>
Wed, 11 Jun 2014 17:33:12 +0000 (10:33 -0700)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java
tests/bugs181/431976/AbstractDependencyInjectionAspect.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/AllTests18.java
tests/src/org/aspectj/systemtest/ajc181/Ajc181Tests.java
tests/src/org/aspectj/systemtest/ajc181/ajc181.xml

index f795d617e17fbc037cef435b6ef994f074a3679a..f9b26b59a59cc485faccd3706e590d07495126ae 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Set;
 import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.DeclareAnnotationDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.IfMethodDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.Proceed;
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
@@ -518,7 +519,8 @@ public class AjProblemReporter extends ProblemReporter {
                        CharOperation.equals(binding.name, thisJoinPointStaticPartName) ||
                        CharOperation.equals(binding.name, thisEnclosingJoinPointStaticPartName)) {
                        // If in advice, this is not a problem
-                       if (binding.declaringScope!=null && binding.declaringScope.referenceContext() instanceof AdviceDeclaration) {
+                       if (binding.declaringScope!=null && (binding.declaringScope.referenceContext() instanceof AdviceDeclaration ||
+                                                                                                binding.declaringScope.referenceContext() instanceof IfMethodDeclaration)) {
                                return;
                        }
                }                       
diff --git a/tests/bugs181/431976/AbstractDependencyInjectionAspect.aj b/tests/bugs181/431976/AbstractDependencyInjectionAspect.aj
new file mode 100644 (file)
index 0000000..fa8fc64
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2002-2013 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.springframework.beans.factory.aspectj;
+
+import org.aspectj.lang.annotation.SuppressAjWarnings;
+import org.aspectj.lang.annotation.control.CodeGenerationHint;
+
+/**
+ * Abstract base aspect that can perform Dependency
+ * Injection on objects, however they may be created.
+ *
+ * @author Ramnivas Laddad
+ * @since 2.5.2
+ */
+public abstract aspect AbstractDependencyInjectionAspect {
+       /**
+        * Select construction join points for objects to inject dependencies
+        */
+       public abstract pointcut beanConstruction(Object bean);
+
+       /**
+        * Select deserialization join points for objects to inject dependencies
+        */
+       public abstract pointcut beanDeserialization(Object bean);
+
+       /**
+        * Select join points in a configurable bean
+        */
+       public abstract pointcut inConfigurableBean();
+
+       /**
+        * Select join points in beans to be configured prior to construction?
+        * By default, use post-construction injection matching the default in the Configurable annotation.
+        */
+       public pointcut preConstructionConfiguration() : if(false);
+
+       /**
+        * Select the most-specific initialization join point
+        * (most concrete class) for the initialization of an instance.
+        */
+       @CodeGenerationHint(ifNameSuffix="6f1")
+       public pointcut mostSpecificSubTypeConstruction() :
+               if(thisJoinPoint.getSignature().getDeclaringType() == thisJoinPoint.getThis().getClass());
+
+       /**
+        * Select least specific super type that is marked for DI (so that injection occurs only once with pre-construction inejection
+        */
+       public abstract pointcut leastSpecificSuperTypeConstruction();
+
+       /**
+        * Configure the bean
+        */
+       public abstract void configureBean(Object bean);
+
+
+       private pointcut preConstructionCondition() :
+               leastSpecificSuperTypeConstruction() && preConstructionConfiguration();
+
+       private pointcut postConstructionCondition() :
+               mostSpecificSubTypeConstruction() && !preConstructionConfiguration();
+
+       /**
+        * Pre-construction configuration.
+        */
+       @SuppressAjWarnings("adviceDidNotMatch")
+       before(Object bean) :
+               beanConstruction(bean) && preConstructionCondition() && inConfigurableBean()  {
+               configureBean(bean);
+       }
+
+       /**
+        * Post-construction configuration.
+        */
+       @SuppressAjWarnings("adviceDidNotMatch")
+       after(Object bean) returning :
+               beanConstruction(bean) && postConstructionCondition() && inConfigurableBean() {
+               configureBean(bean);
+       }
+
+       /**
+        * Post-deserialization configuration.
+        */
+       @SuppressAjWarnings("adviceDidNotMatch")
+       after(Object bean) returning :
+               beanDeserialization(bean) && inConfigurableBean() {
+               configureBean(bean);
+       }
+
+}
index ac1d9d6b5f59a1293efb92407c4367689dbbed32..c382ea5045fc0b5a6433c974436b16c878de7ef4 100644 (file)
@@ -24,8 +24,8 @@ public class AllTests18 {
                suite.addTest(AllTestsAspectJ181.suite()); 
                suite.addTest(AllTestsAspectJ180.suite()); 
                suite.addTest(AllTests17.suite());
-               suite.addTest(AllTests16.suite());
-               suite.addTest(AllTests15.suite());
+//             suite.addTest(AllTests16.suite());
+//             suite.addTest(AllTests15.suite());
                // $JUnit-END$
                return suite;
        }
index 2a466af6ac8c8d8e27d0a0f49925debcfece610b..5c298300e0f9e492ba7aa82f3e31aefc88fb8b11 100644 (file)
@@ -21,7 +21,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  * @author Andy Clement
  */
 public class Ajc181Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
-
+       
+       public void testVariableNotInitialized_431976() {
+               runTest("variable not initialized");
+       }
 
        public void testThisEnclosingJoinPointStaticPartNotInitialized_431976() {
                runTest("thisEnclosingJoinPointStaticPart not initialized");
index 80bb5d20a60eae0025168a8592b421d88ebd7a40..5d091ca8c5644259b2fdfae2cf700d1196b5d329 100644 (file)
@@ -2,6 +2,10 @@
 
 <suite>
 
+       <ajc-test dir="bugs181/431976" title="variable not initialized">
+               <compile options="-1.8" files="AbstractDependencyInjectionAspect.aj"/>
+       </ajc-test>
+       
        <ajc-test dir="bugs181/431976" title="thisEnclosingJoinPointStaticPart not initialized">
                <compile options="-1.8" files="Code.java"/>
        </ajc-test>