1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.crosscuts.joinpoints.*; 28 29 import org.aspectj.compiler.base.JavaCompiler; 30 31 import java.util.*; 32 import org.aspectj.util.FuzzyBoolean; 33 34 39 public class FieldPattern extends DecPattern { 40 public String toShortString() { 41 String mods = modifiers.toShortString(); 42 if (mods.length() > 0) mods += " "; 43 mods += fieldTypeName.toShortString()+" "; 44 if (declaringTypeName != null) mods += declaringTypeName.toShortString() + "."; 45 String ret = mods + id.toShortString(); 46 47 return ret; 48 } 49 50 public String getLookupId() { return id.getLookupString(); } 51 52 public FuzzyBoolean matches(JoinPoint jp) { 53 if (! (jp.getTargetSO() instanceof Field) ) { 54 return FuzzyBoolean.NO; 55 } 56 57 Field m = (Field)jp.getTargetSO(); 58 59 61 if (!id.matches(m.getName())) return FuzzyBoolean.NO; 62 if (!fieldTypeName.matches(m.getFieldType())) return FuzzyBoolean.NO; 64 65 67 return super.matches(jp); 68 } 69 70 protected boolean isStaticMatch(SemanticObject so) { 71 return true; 72 } 73 74 protected GenTypeName fieldTypeName; 76 public GenTypeName getFieldTypeName() { return fieldTypeName; } 77 public void setFieldTypeName(GenTypeName _fieldTypeName) { 78 if (_fieldTypeName != null) _fieldTypeName.setParent(this); 79 fieldTypeName = _fieldTypeName; 80 } 81 82 protected NamePattern id; 83 public NamePattern getId() { return id; } 84 public void setId(NamePattern _id) { id = _id; } 85 86 public FieldPattern(SourceLocation location, Modifiers _modifiers, GenTypeName _declaringTypeName, GenTypeName _fieldTypeName, NamePattern _id) { 87 super(location, _modifiers, _declaringTypeName); 88 setFieldTypeName(_fieldTypeName); 89 setId(_id); 90 } 91 protected FieldPattern(SourceLocation source) { 92 super(source); 93 } 94 95 public ASTObject copyWalk(CopyWalker walker) { 96 FieldPattern ret = new FieldPattern(getSourceLocation()); 97 ret.preCopy(walker, this); 98 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 99 if (declaringTypeName != null) ret.setDeclaringTypeName( (GenTypeName)walker.process(declaringTypeName) ); 100 if (fieldTypeName != null) ret.setFieldTypeName( (GenTypeName)walker.process(fieldTypeName) ); 101 ret.id = id; 102 return ret; 103 } 104 105 public ASTObject getChildAt(int childIndex) { 106 switch(childIndex) { 107 case 2: return fieldTypeName; 108 default: return super.getChildAt(childIndex); 109 } 110 } 111 public String getChildNameAt(int childIndex) { 112 switch(childIndex) { 113 case 2: return "fieldTypeName"; 114 default: return super.getChildNameAt(childIndex); 115 } 116 } 117 public void setChildAt(int childIndex, ASTObject child) { 118 switch(childIndex) { 119 case 2: setFieldTypeName((GenTypeName)child); return; 120 default: super.setChildAt(childIndex, child); return; 121 } 122 } 123 public int getChildCount() { 124 return 3; 125 } 126 127 public String getDefaultDisplayName() { 128 return "FieldPattern(id: "+id+")"; 129 } 130 131 } 133 134 | Popular Tags |