From 93a7164cec47ef5b8b38f639b50248c80309bf1c Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 30 Oct 2009 23:05:40 +0000 Subject: [PATCH] formatted --- .../ThisOrTargetAnnotationPointcut.java | 286 ++++++++++-------- 1 file changed, 168 insertions(+), 118 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java index 350a19254..4cf1202e8 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java @@ -34,9 +34,9 @@ import org.aspectj.weaver.ast.Var; /** * @author colyer - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code + * Templates */ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { @@ -44,22 +44,26 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { private boolean alreadyWarnedAboutDEoW = false; private ExactAnnotationTypePattern annotationTypePattern; private String declarationText; - + private static final int thisKindSet; private static final int targetKindSet; - + static { int thisFlags = Shadow.ALL_SHADOW_KINDS_BITS; int targFlags = Shadow.ALL_SHADOW_KINDS_BITS; for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; - if (kind.neverHasThis()) thisFlags-=kind.bit; - if (kind.neverHasTarget()) targFlags-=kind.bit; + if (kind.neverHasThis()) { + thisFlags -= kind.bit; + } + if (kind.neverHasTarget()) { + targFlags -= kind.bit; + } } thisKindSet = thisFlags; - targetKindSet=targFlags; + targetKindSet = targFlags; } - + /** * */ @@ -72,63 +76,79 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { } public ThisOrTargetAnnotationPointcut(boolean isThis, ExactAnnotationTypePattern type, ShadowMunger munger) { - this(isThis,type); + this(isThis, type); } - public ExactAnnotationTypePattern getAnnotationTypePattern() { - return annotationTypePattern; - } + public ExactAnnotationTypePattern getAnnotationTypePattern() { + return annotationTypePattern; + } + @Override public int couldMatchKinds() { return isThis ? thisKindSet : targetKindSet; } - - public Pointcut parameterizeWith(Map typeVariableMap,World w) { - ExactAnnotationTypePattern newPattern = (ExactAnnotationTypePattern) this.annotationTypePattern.parameterizeWith(typeVariableMap,w); + + @Override + public Pointcut parameterizeWith(Map typeVariableMap, World w) { + ExactAnnotationTypePattern newPattern = (ExactAnnotationTypePattern) this.annotationTypePattern.parameterizeWith( + typeVariableMap, w); if (newPattern.getAnnotationType() instanceof ResolvedType) { verifyRuntimeRetention(newPattern.getResolvedAnnotationType()); } - ThisOrTargetAnnotationPointcut ret = new ThisOrTargetAnnotationPointcut(isThis,(ExactAnnotationTypePattern)annotationTypePattern.parameterizeWith(typeVariableMap,w)); + ThisOrTargetAnnotationPointcut ret = new ThisOrTargetAnnotationPointcut(isThis, + (ExactAnnotationTypePattern) annotationTypePattern.parameterizeWith(typeVariableMap, w)); ret.copyLocationFrom(this); return ret; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.Pointcut#fastMatch(org.aspectj.weaver.patterns.FastMatchInfo) */ + @Override public FuzzyBoolean fastMatch(FastMatchInfo info) { return FuzzyBoolean.MAYBE; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.Pointcut#match(org.aspectj.weaver.Shadow) */ + @Override protected FuzzyBoolean matchInternal(Shadow shadow) { - if (!couldMatch(shadow)) return FuzzyBoolean.NO; - ResolvedType toMatchAgainst = - (isThis ? shadow.getThisType() : shadow.getTargetType() ).resolve(shadow.getIWorld()); - annotationTypePattern.resolve(shadow.getIWorld()); - if (annotationTypePattern.matchesRuntimeType(toMatchAgainst).alwaysTrue()) { - return FuzzyBoolean.YES; - } else { - // a subtype may match at runtime - return FuzzyBoolean.MAYBE; - } + if (!couldMatch(shadow)) { + return FuzzyBoolean.NO; + } + ResolvedType toMatchAgainst = (isThis ? shadow.getThisType() : shadow.getTargetType()).resolve(shadow.getIWorld()); + annotationTypePattern.resolve(shadow.getIWorld()); + if (annotationTypePattern.matchesRuntimeType(toMatchAgainst).alwaysTrue()) { + return FuzzyBoolean.YES; + } else { + // a subtype may match at runtime + return FuzzyBoolean.MAYBE; + } } - public boolean isThis() { return isThis; } - - /* (non-Javadoc) - * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings) + public boolean isThis() { + return isThis; + } + + /* + * (non-Javadoc) + * + * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, + * org.aspectj.weaver.patterns.Bindings) */ + @Override protected void resolveBindings(IScope scope, Bindings bindings) { if (!scope.getWorld().isInJava5Mode()) { - scope.message(MessageUtil.error(WeaverMessages.format( - isThis ? WeaverMessages.ATTHIS_ONLY_SUPPORTED_AT_JAVA5_LEVEL : WeaverMessages.ATTARGET_ONLY_SUPPORTED_AT_JAVA5_LEVEL), - getSourceLocation())); + scope.message(MessageUtil.error(WeaverMessages.format(isThis ? WeaverMessages.ATTHIS_ONLY_SUPPORTED_AT_JAVA5_LEVEL + : WeaverMessages.ATTARGET_ONLY_SUPPORTED_AT_JAVA5_LEVEL), getSourceLocation())); return; } - annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true); + annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope, bindings, true); // must be either a Var, or an annotation type pattern // if annotationType does not have runtime retention, this is an error if (annotationTypePattern.annotationType == null) { @@ -136,152 +156,182 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { return; } ResolvedType rAnnotationType = (ResolvedType) annotationTypePattern.annotationType; - if (rAnnotationType.isTypeVariableReference()) return; // we'll deal with this next check when the type var is actually bound... + if (rAnnotationType.isTypeVariableReference()) { + return; // we'll deal with this next check when the type var is actually bound... + } verifyRuntimeRetention(rAnnotationType); - + } private void verifyRuntimeRetention(ResolvedType rAnnotationType) { if (!(rAnnotationType.isAnnotationWithRuntimeRetention())) { - IMessage m = MessageUtil.error( - WeaverMessages.format(WeaverMessages.BINDING_NON_RUNTIME_RETENTION_ANNOTATION,rAnnotationType.getName()), - getSourceLocation()); + IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.BINDING_NON_RUNTIME_RETENTION_ANNOTATION, + rAnnotationType.getName()), getSourceLocation()); rAnnotationType.getWorld().getMessageHandler().handleMessage(m); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.Pointcut#concretize1(org.aspectj.weaver.ResolvedType, org.aspectj.weaver.IntMap) */ + @Override protected Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) { if (isDeclare(bindings.getEnclosingAdvice())) { - // Enforce rule about which designators are supported in declare - if (!alreadyWarnedAboutDEoW) { - inAspect.getWorld().showMessage(IMessage.ERROR, - WeaverMessages.format(WeaverMessages.THIS_OR_TARGET_IN_DECLARE,isThis?"this":"target"), + // Enforce rule about which designators are supported in declare + if (!alreadyWarnedAboutDEoW) { + inAspect.getWorld().showMessage(IMessage.ERROR, + WeaverMessages.format(WeaverMessages.THIS_OR_TARGET_IN_DECLARE, isThis ? "this" : "target"), bindings.getEnclosingAdvice().getSourceLocation(), null); - alreadyWarnedAboutDEoW = true; - } - return Pointcut.makeMatchesNothing(Pointcut.CONCRETE); + alreadyWarnedAboutDEoW = true; + } + return Pointcut.makeMatchesNothing(Pointcut.CONCRETE); } - ExactAnnotationTypePattern newType = (ExactAnnotationTypePattern) annotationTypePattern.remapAdviceFormals(bindings); - ThisOrTargetAnnotationPointcut ret = - new ThisOrTargetAnnotationPointcut(isThis, newType, bindings.getEnclosingAdvice()); + ExactAnnotationTypePattern newType = (ExactAnnotationTypePattern) annotationTypePattern.remapAdviceFormals(bindings); + ThisOrTargetAnnotationPointcut ret = new ThisOrTargetAnnotationPointcut(isThis, newType, bindings.getEnclosingAdvice()); ret.alreadyWarnedAboutDEoW = alreadyWarnedAboutDEoW; - ret.copyLocationFrom(this); - return ret; + ret.copyLocationFrom(this); + return ret; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.Pointcut#findResidue(org.aspectj.weaver.Shadow, org.aspectj.weaver.patterns.ExposedState) */ /** - * The guard here is going to be the hasAnnotation() test - if it gets through (which we cannot determine until runtime) then - * we must have a TypeAnnotationAccessVar in place - this means we must *always* have one in place. + * The guard here is going to be the hasAnnotation() test - if it gets through (which we cannot determine until runtime) then we + * must have a TypeAnnotationAccessVar in place - this means we must *always* have one in place. */ + @Override protected Test findResidueInternal(Shadow shadow, ExposedState state) { - if (!couldMatch(shadow)) return Literal.FALSE; - boolean alwaysMatches = match(shadow).alwaysTrue(); - Var var = isThis ? shadow.getThisVar() : shadow.getTargetVar(); - Var annVar = null; - - // Are annotations being bound? - UnresolvedType annotationType = annotationTypePattern.annotationType; + if (!couldMatch(shadow)) { + return Literal.FALSE; + } + boolean alwaysMatches = match(shadow).alwaysTrue(); + Var var = isThis ? shadow.getThisVar() : shadow.getTargetVar(); + Var annVar = null; + + // Are annotations being bound? + UnresolvedType annotationType = annotationTypePattern.annotationType; if (annotationTypePattern instanceof BindingAnnotationTypePattern) { - BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)annotationTypePattern; + BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern) annotationTypePattern; annotationType = btp.annotationType; - - annVar = isThis ? shadow.getThisAnnotationVar(annotationType) : - shadow.getTargetAnnotationVar(annotationType); - if (annVar == null) + + annVar = isThis ? shadow.getThisAnnotationVar(annotationType) : shadow.getTargetAnnotationVar(annotationType); + if (annVar == null) { throw new RuntimeException("Impossible!"); + } - state.set(btp.getFormalIndex(),annVar); + state.set(btp.getFormalIndex(), annVar); } - if (alwaysMatches && (annVar == null)) {//change check to verify if its the 'generic' annVar that is being used - return Literal.TRUE; + if (alwaysMatches && (annVar == null)) {// change check to verify if its the 'generic' annVar that is being used + return Literal.TRUE; } else { - ResolvedType rType = annotationType.resolve(shadow.getIWorld()); - return Test.makeHasAnnotation(var,rType); + ResolvedType rType = annotationType.resolve(shadow.getIWorld()); + return Test.makeHasAnnotation(var, rType); } } - private boolean couldMatch(Shadow shadow) { return isThis ? shadow.hasThis() : shadow.hasTarget(); } - - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.NameBindingPointcut#getBindingAnnotationTypePatterns() */ + @Override public List getBindingAnnotationTypePatterns() { if (annotationTypePattern instanceof BindingAnnotationTypePattern) { List l = new ArrayList(); l.add(annotationTypePattern); return l; - } else return Collections.EMPTY_LIST; + } else { + return Collections.EMPTY_LIST; + } } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.NameBindingPointcut#getBindingTypePatterns() */ + @Override public List getBindingTypePatterns() { return Collections.EMPTY_LIST; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream) */ + @Override public void write(DataOutputStream s) throws IOException { - s.writeByte(Pointcut.ATTHIS_OR_TARGET); - s.writeBoolean(isThis); + s.writeByte(Pointcut.ATTHIS_OR_TARGET); + s.writeBoolean(isThis); annotationTypePattern.write(s); writeLocation(s); } - + public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException { - boolean isThis = s.readBoolean(); + boolean isThis = s.readBoolean(); AnnotationTypePattern type = AnnotationTypePattern.read(s, context); - ThisOrTargetAnnotationPointcut ret = new ThisOrTargetAnnotationPointcut(isThis,(ExactAnnotationTypePattern)type); + ThisOrTargetAnnotationPointcut ret = new ThisOrTargetAnnotationPointcut(isThis, (ExactAnnotationTypePattern) type); ret.readLocation(context, s); return ret; } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (!(obj instanceof ThisOrTargetAnnotationPointcut)) return false; - ThisOrTargetAnnotationPointcut other = (ThisOrTargetAnnotationPointcut) obj; - return ( other.annotationTypePattern.equals(this.annotationTypePattern) && - (other.isThis == this.isThis) ); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return 17 + 37*annotationTypePattern.hashCode() + (isThis ? 49 : 13); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - private void buildDeclarationText() { + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ThisOrTargetAnnotationPointcut)) { + return false; + } + ThisOrTargetAnnotationPointcut other = (ThisOrTargetAnnotationPointcut) obj; + return (other.annotationTypePattern.equals(this.annotationTypePattern) && (other.isThis == this.isThis)); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return 17 + 37 * annotationTypePattern.hashCode() + (isThis ? 49 : 13); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + private void buildDeclarationText() { StringBuffer buf = new StringBuffer(); buf.append(isThis ? "@this(" : "@target("); String annPatt = annotationTypePattern.toString(); buf.append(annPatt.startsWith("@") ? annPatt.substring(1) : annPatt); buf.append(")"); - this.declarationText = buf.toString(); + this.declarationText = buf.toString(); } - - public String toString() { return this.declarationText; } - public Object accept(PatternNodeVisitor visitor, Object data) { - return visitor.visit(this, data); - } + @Override + public String toString() { + return this.declarationText; + } + + @Override + public Object accept(PatternNodeVisitor visitor, Object data) { + return visitor.visit(this, data); + } } -- 2.39.5