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 ConstructorPattern extends CodePattern { 40 public String toShortString() { 41 String mods = modifiers.toShortString(); 43 if (mods.length() > 0) mods += " "; 44 mods += makeDeclaringTypeString() + "new" + formalsPattern.toShortString(); 45 if (throwsPattern != null) { 46 mods += " throws ..."; 47 } 48 49 return mods; 50 } 51 52 public String getLookupId() { return "new"; } 53 54 protected boolean isStaticMatch(SemanticObject so) { 55 return true; 56 } 57 58 public FuzzyBoolean matches(JoinPoint jp) { 59 if (! (jp.getTargetSO() instanceof Constructor) ) { 60 return FuzzyBoolean.NO; 61 } 62 63 Constructor m = (Constructor)jp.getTargetSO(); 64 65 if (!formalsPattern.matches(m.getFormals())) { 66 return FuzzyBoolean.NO; 67 } 68 if (throwsPattern != null && !throwsPattern.matches(m.getThrows())) { 69 return FuzzyBoolean.NO; 70 } 71 72 return super.matches(jp); 73 } 74 75 protected FormalsPattern formalsPattern; 77 public FormalsPattern getFormalsPattern() { return formalsPattern; } 78 public void setFormalsPattern(FormalsPattern _formalsPattern) { 79 if (_formalsPattern != null) _formalsPattern.setParent(this); 80 formalsPattern = _formalsPattern; 81 } 82 83 protected NameTypeDsPattern throwsPattern; 84 public NameTypeDsPattern getThrowsPattern() { return throwsPattern; } 85 public void setThrowsPattern(NameTypeDsPattern _throwsPattern) { 86 if (_throwsPattern != null) _throwsPattern.setParent(this); 87 throwsPattern = _throwsPattern; 88 } 89 90 public ConstructorPattern(SourceLocation location, Modifiers _modifiers, GenTypeName _declaringTypeName, FormalsPattern _formalsPattern, NameTypeDsPattern _throwsPattern) { 91 super(location, _modifiers, _declaringTypeName); 92 setFormalsPattern(_formalsPattern); 93 setThrowsPattern(_throwsPattern); 94 } 95 protected ConstructorPattern(SourceLocation source) { 96 super(source); 97 } 98 99 public ASTObject copyWalk(CopyWalker walker) { 100 ConstructorPattern ret = new ConstructorPattern(getSourceLocation()); 101 ret.preCopy(walker, this); 102 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 103 if (declaringTypeName != null) ret.setDeclaringTypeName( (GenTypeName)walker.process(declaringTypeName) ); 104 if (formalsPattern != null) ret.setFormalsPattern( (FormalsPattern)walker.process(formalsPattern) ); 105 if (throwsPattern != null) ret.setThrowsPattern( (NameTypeDsPattern)walker.process(throwsPattern) ); 106 return ret; 107 } 108 109 public ASTObject getChildAt(int childIndex) { 110 switch(childIndex) { 111 case 2: return formalsPattern; 112 case 3: return throwsPattern; 113 default: return super.getChildAt(childIndex); 114 } 115 } 116 public String getChildNameAt(int childIndex) { 117 switch(childIndex) { 118 case 2: return "formalsPattern"; 119 case 3: return "throwsPattern"; 120 default: return super.getChildNameAt(childIndex); 121 } 122 } 123 public void setChildAt(int childIndex, ASTObject child) { 124 switch(childIndex) { 125 case 2: setFormalsPattern((FormalsPattern)child); return; 126 case 3: setThrowsPattern((NameTypeDsPattern)child); return; 127 default: super.setChildAt(childIndex, child); return; 128 } 129 } 130 public int getChildCount() { 131 return 4; 132 } 133 134 public String getDefaultDisplayName() { 135 return "ConstructorPattern()"; 136 } 137 138 } 140 141 | Popular Tags |