From 3938f0e5d501382517653964f4ed175288ca5cce Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 11 Mar 2005 12:25:29 +0000 Subject: [PATCH] Ensures on multiple compiles the method generated for a declare statement always has the same name. --- .../compiler/ast/AspectDeclaration.java | 3 +- .../ast/DeclareAnnotationDeclaration.java | 8 +++- .../compiler/ast/DeclareDeclaration.java | 39 +++++++++++-------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index a2f8fb22b..31eb13fe5 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -57,7 +57,8 @@ public class AspectDeclaration extends TypeDeclaration { public EclipseFactory factory; //??? should use this consistently public int adviceCounter = 1; // Used as a part of the generated name for advice methods - + public int declareCounter= 1; // Used as a part of the generated name for methods representing declares + // for better error messages in 1.0 to 1.1 transition public TypePattern dominatesPattern; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java index 158228a4c..d7da525e5 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java @@ -15,6 +15,7 @@ package org.aspectj.ajdt.internal.compiler.ast; import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.flow.FlowInfo; import org.aspectj.org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -32,7 +33,7 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration { addAnnotation(annotation); if (symbolicDeclare==null) return; // there is an error that will already be getting reported (e.g. incorrect pattern on decaf/decac) symbolicDeclare.setAnnotationString(annotation.toString()); - symbolicDeclare.setAnnotationMethod(new String(selector)); + } public void analyseCode(ClassScope classScope, @@ -76,5 +77,10 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration { } this.annotations[0] = ann; } + + public void postParse(TypeDeclaration typeDec) { + super.postParse(typeDec); + ((DeclareAnnotation)declareDecl).setAnnotationMethod(new String(selector)); + } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java index 990b3daaa..a34a36a61 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java @@ -19,6 +19,7 @@ import org.aspectj.ajdt.internal.compiler.lookup.EclipseScope; 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.CompilationUnitDeclaration; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser; @@ -33,9 +34,9 @@ public class DeclareDeclaration extends AjMethodDeclaration { /** * Constructor for IntraTypeDeclaration. */ - static int counter = 0; //XXX evil public DeclareDeclaration(CompilationResult result, Declare symbolicDeclare) { super(result); + this.declareDecl = symbolicDeclare; if (declareDecl != null) { // AMC added init of declarationSourceXXX fields which are used @@ -44,22 +45,7 @@ public class DeclareDeclaration extends AjMethodDeclaration { declarationSourceEnd = sourceEnd = declareDecl.getEnd(); } //??? we might need to set parameters to be empty - this.returnType = TypeReference.baseTypeReference(T_void, 0); - - StringBuffer sb = new StringBuffer(); - sb.append("ajc$declare"); - // Declares can choose to provide a piece of the name - to enable - // them to be easily distinguised at weave time (e.g. see declare annotation) - if (symbolicDeclare!=null) { - String suffix = symbolicDeclare.getNameSuffix(); - if (suffix.length()!=0) { - sb.append("_"); - sb.append(suffix); - } - } - sb.append("_"); - sb.append(counter++); - this.selector = sb.toString().toCharArray(); + this.returnType = TypeReference.baseTypeReference(T_void, 0); } @@ -132,4 +118,23 @@ public class DeclareDeclaration extends AjMethodDeclaration { return super.generateInfoAttributes(classFile,true); } + public void postParse(TypeDeclaration typeDec) { + super.postParse(typeDec); + int declareSequenceNumberInType = ((AspectDeclaration)typeDec).declareCounter++; + //FIXME asc the name should perhaps include the hashcode of the pattern (type/sig) for binary compatibility reasons! + StringBuffer sb = new StringBuffer(); + sb.append("ajc$declare"); + // Declares can choose to provide a piece of the name - to enable + // them to be easily distinguised at weave time (e.g. see declare annotation) + if (declareDecl!=null) { + String suffix = declareDecl.getNameSuffix(); + if (suffix.length()!=0) { + sb.append("_"); + sb.append(suffix); + } + } + sb.append("_"); + sb.append(declareSequenceNumberInType); + this.selector = sb.toString().toCharArray(); + } } -- 2.39.5