1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.crosscuts.joinpoints.*; 28 import org.aspectj.util.FuzzyBoolean; 29 30 import org.aspectj.compiler.base.JavaCompiler; 31 32 import java.util.*; 33 34 39 public abstract class DecPattern extends ASTObject { 40 public abstract String toShortString(); 41 42 protected String makeDeclaringTypeString() { 43 if (getDeclaringTypeName() == null) return ""; 44 return getDeclaringTypeName().toShortString() + '.'; 45 } 46 47 public abstract String getLookupId(); 48 49 private boolean shownWarning = false; 50 51 public FuzzyBoolean matches(JoinPoint jp) { 52 if (!(modifiers.matches(jp.getTargetSO().getModifiers()))) { 53 return FuzzyBoolean.NO; 54 } 55 56 if (getDeclaringTypeName() != null) { 57 Type targetType = jp.getTargetType(); 58 if (targetType == null) { 59 for (Iterator i = jp.getTargetTypes().iterator(); i.hasNext(); ) { 60 targetType = (Type)i.next(); 61 if (!matchDeclaringTypeName(jp, targetType, jp.getTargetSO())) { 64 return FuzzyBoolean.NEVER; 65 } 66 } 68 return FuzzyBoolean.YES; 69 } else { 70 if(matchDeclaringTypeName(jp, jp.getTargetType(), jp.getTargetSO())) { 71 return FuzzyBoolean.YES; 72 } else { 73 return FuzzyBoolean.NO; 74 } 75 } 76 } else { 77 return FuzzyBoolean.YES; 78 } 79 } 80 81 82 protected boolean isStaticMatch(SemanticObject so) { 83 return so.isStatic(); 84 } 85 86 boolean matchDeclaringTypeName(JoinPoint joinPoint, Type inType, SemanticObject so) { 87 89 SemanticObject matchingSO = inType.findMatchingSemanticObject(so); 92 if (matchingSO == null) return false; 93 94 if (isStaticMatch(so)) { 95 if (matchingSO != so) return false; 96 } 97 98 if (getDeclaringTypeName().matches(inType)) { 99 return true; 100 } 101 102 for (Iterator i = inType.getDirectSuperTypes().iterator(); i.hasNext(); ) { 105 if(matchDeclaringTypeName(joinPoint, (Type)i.next(), so)) return true; 106 } 107 108 return false; 109 } 110 111 protected Modifiers modifiers; 113 public Modifiers getModifiers() { return modifiers; } 114 public void setModifiers(Modifiers _modifiers) { 115 if (_modifiers != null) _modifiers.setParent(this); 116 modifiers = _modifiers; 117 } 118 119 protected GenTypeName declaringTypeName; 120 public GenTypeName getDeclaringTypeName() { return declaringTypeName; } 121 public void setDeclaringTypeName(GenTypeName _declaringTypeName) { 122 if (_declaringTypeName != null) _declaringTypeName.setParent(this); 123 declaringTypeName = _declaringTypeName; 124 } 125 126 public DecPattern(SourceLocation location, Modifiers _modifiers, GenTypeName _declaringTypeName) { 127 super(location); 128 setModifiers(_modifiers); 129 setDeclaringTypeName(_declaringTypeName); 130 } 131 protected DecPattern(SourceLocation source) { 132 super(source); 133 } 134 135 public ASTObject getChildAt(int childIndex) { 136 switch(childIndex) { 137 case 0: return modifiers; 138 case 1: return declaringTypeName; 139 default: return super.getChildAt(childIndex); 140 } 141 } 142 public String getChildNameAt(int childIndex) { 143 switch(childIndex) { 144 case 0: return "modifiers"; 145 case 1: return "declaringTypeName"; 146 default: return super.getChildNameAt(childIndex); 147 } 148 } 149 public void setChildAt(int childIndex, ASTObject child) { 150 switch(childIndex) { 151 case 0: setModifiers((Modifiers)child); return; 152 case 1: setDeclaringTypeName((GenTypeName)child); return; 153 default: super.setChildAt(childIndex, child); return; 154 } 155 } 156 public int getChildCount() { 157 return 2; 158 } 159 160 public String getDefaultDisplayName() { 161 return "DecPattern()"; 162 } 163 164 } 166 167 | Popular Tags |