| 1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 27 import org.aspectj.compiler.crosscuts.joinpoints.*; 28 29 import org.aspectj.compiler.base.ast.*; 30 import org.aspectj.compiler.base.cst.*; 31 32 import org.aspectj.compiler.base.JavaCompiler; 33 import org.aspectj.compiler.crosscuts.AspectJCompiler; 34 35 41 42 public class ShowErrorDec extends Dec implements JpPlannerMaker { 43 44 public Modifiers getModifiers() { return getAST().makeModifiers(0); } 45 46 public String getId() { return "declare"; } 47 public String toShortString() { 48 return getKind() + ": " + pcd.toShortString(); 49 } 50 public String getKind() { 51 return "declare " + (isWarning ? "warning" : "error"); 52 } 53 54 55 public void checkSpec() { 56 pcd.checkStatic(); 57 58 if (! (message instanceof StringLiteralExpr) ) { 59 message.showError("error message must be a constant string"); 60 } 61 } 62 63 public JpPlanner makePlanner(PlanData planData) { 64 return new ErrorPlanner(getPcd().makePlanner(planData)); 65 } 66 67 private String getMessageString() { 68 if (! (message instanceof StringLiteralExpr)) return ""; 69 return ((StringLiteralExpr)message).getStringValue(); 70 } 71 72 private class ErrorPlanner extends WrappedJpPlanner { 73 public ErrorPlanner(JpPlanner planner) { super(planner); } 74 75 public JpPlan makePlan(JoinPoint jp) { 76 if (jp.getSourceLocation() == null) return JpPlan.NO_PLAN; 78 if (alwaysMatches(jp)) { 79 showErrorAt(jp); 80 } 81 return JpPlan.NO_PLAN; 82 } 83 84 public boolean isStaticPlanner() { return true; } 85 } 86 87 public void showErrorAt(JoinPoint point) { 88 if (isWarning) { 89 getCompiler().showWarning(point.getSourceLocation(), getMessageString()); 90 } else { 91 getCompiler().showError(point.getSourceLocation(), getMessageString()); 92 } 93 } 94 95 protected Pcd pcd; 97 public Pcd getPcd() { return pcd; } 98 public void setPcd(Pcd _pcd) { 99 if (_pcd != null) _pcd.setParent(this); 100 pcd = _pcd; 101 } 102 103 protected Expr message; 104 public Expr getMessage() { return message; } 105 public void setMessage(Expr _message) { 106 if (_message != null) _message.setParent(this); 107 message = _message; 108 } 109 110 protected boolean isWarning; 111 public boolean getIsWarning() { return isWarning; } 112 public void setIsWarning(boolean _isWarning) { isWarning = _isWarning; } 113 114 public ShowErrorDec(SourceLocation location, Pcd _pcd, Expr _message, boolean _isWarning) { 115 super(location); 116 setPcd(_pcd); 117 setMessage(_message); 118 setIsWarning(_isWarning); 119 } 120 protected ShowErrorDec(SourceLocation source) { 121 super(source); 122 } 123 124 public ASTObject copyWalk(CopyWalker walker) { 125 ShowErrorDec ret = new ShowErrorDec(getSourceLocation()); 126 ret.preCopy(walker, this); 127 if (pcd != null) ret.setPcd( (Pcd)walker.process(pcd) ); 128 if (message != null) ret.setMessage( (Expr)walker.process(message) ); 129 ret.isWarning = isWarning; 130 return ret; 131 } 132 133 public ASTObject getChildAt(int childIndex) { 134 switch(childIndex) { 135 case 0: return pcd; 136 case 1: return message; 137 default: return super.getChildAt(childIndex); 138 } 139 } 140 public String getChildNameAt(int childIndex) { 141 switch(childIndex) { 142 case 0: return "pcd"; 143 case 1: return "message"; 144 default: return super.getChildNameAt(childIndex); 145 } 146 } 147 public void setChildAt(int childIndex, ASTObject child) { 148 switch(childIndex) { 149 case 0: setPcd((Pcd)child); return; 150 case 1: setMessage((Expr)child); return; 151 default: super.setChildAt(childIndex, child); return; 152 } 153 } 154 public int getChildCount() { 155 return 2; 156 } 157 158 public String getDefaultDisplayName() { 159 return "ShowErrorDec(isWarning: "+isWarning+")"; 160 } 161 162 } 164 165 166 167 | Popular Tags |