aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-11-03 17:12:01 +0000
committeracolyer <acolyer>2005-11-03 17:12:01 +0000
commit97b20efcc65e4ffa5a6b027fb4d6c575d1857879 (patch)
tree1e51b9befc6f4c8f88c8bf7594e83c8f30d1e05e /org.aspectj.ajdt.core
parentac15d777ac6d2604317976926007e8bd70c64656 (diff)
downloadaspectj-97b20efcc65e4ffa5a6b027fb4d6c575d1857879.tar.gz
aspectj-97b20efcc65e4ffa5a6b027fb4d6c575d1857879.zip
fix for pr62606 - raises a lint warning when itdc does not contain an explicit call to a constructor. Can be suppressed using @SuppressAjWarnings
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java
index 2decb4cc0..fec167383 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java
@@ -15,7 +15,10 @@ package org.aspectj.ajdt.internal.compiler.ast;
import java.lang.reflect.Modifier;
import org.aspectj.ajdt.internal.compiler.lookup.*;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.weaver.*;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral;
import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.*;
@@ -32,6 +35,8 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
* @author Jim Hugunin
*/
public class InterTypeConstructorDeclaration extends InterTypeDeclaration {
+ private static final String SUPPRESSAJWARNINGS = "Lorg/aspectj/lang/annotation/SuppressAjWarnings;";
+ private static final String NOEXPLICITCONSTRUCTORCALL = "noExplicitConstructorCall";
private MethodDeclaration preMethod;
private ExplicitConstructorCall explicitConstructorCall = null;
@@ -69,8 +74,53 @@ public class InterTypeConstructorDeclaration extends InterTypeDeclaration {
this.arguments);
super.resolve(upperScope);
+
+ // after annotations have been resolved...
+ if (explicitConstructorCall == null) {
+ raiseNoFieldInitializersWarning();
+ }
}
+ /**
+ * Warning added in response to PR 62606 - if an ITD constructor does not make an explicit constructor
+ * call then field initializers in the target class will not be executed leading to unexpected behaviour.
+ */
+ private void raiseNoFieldInitializersWarning() {
+ if (suppressingNoExplicitConstructorCall()) return;
+ EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(scope);
+ ISourceLocation location =
+ new EclipseSourceLocation(scope.problemReporter().referenceContext.compilationResult(),
+ sourceStart(),sourceEnd());
+ world.getWorld().getLint().noExplicitConstructorCall.signal(null, location);
+ }
+
+ /**
+ * true iff constructor has @SuppressAjWarnings or @SuppressAjWarnings("xyz,noExplicitConstructorCall,def,...")
+ * @return
+ */
+ private boolean suppressingNoExplicitConstructorCall() {
+ if (this.annotations == null) return false;
+ for (int i = 0; i < this.annotations.length; i++) {
+ if (new String(this.annotations[i].resolvedType.signature()).equals(SUPPRESSAJWARNINGS)) {
+ if (this.annotations[i] instanceof MarkerAnnotation) {
+ return true;
+ } else if (this.annotations[i] instanceof SingleMemberAnnotation){
+ SingleMemberAnnotation sma = (SingleMemberAnnotation) this.annotations[i];
+ if (sma.memberValue instanceof ArrayInitializer) {
+ ArrayInitializer memberValue = (ArrayInitializer) sma.memberValue;
+ for (int j = 0; j < memberValue.expressions.length; j++) {
+ if (memberValue.expressions[j] instanceof StringLiteral) {
+ StringLiteral val = (StringLiteral) memberValue.expressions[j];
+ if (new String(val.source()).equals(NOEXPLICITCONSTRUCTORCALL)) return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
private MethodDeclaration makePreMethod(ClassScope scope,
ExplicitConstructorCall explicitConstructorCall)
{