1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 30 public class SwitchCase extends Statement { 31 32 36 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 37 new ChildPropertyDescriptor(SwitchCase.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); 39 44 private static final List PROPERTY_DESCRIPTORS; 45 46 static { 47 List propertyList = new ArrayList (2); 48 createPropertyList(SwitchCase.class, propertyList); 49 addProperty(EXPRESSION_PROPERTY, propertyList); 50 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 51 } 52 53 63 public static List propertyDescriptors(int apiLevel) { 64 return PROPERTY_DESCRIPTORS; 65 } 66 67 72 private Expression optionalExpression = null; 73 74 77 private boolean expressionInitialized = false; 78 79 85 SwitchCase(AST ast) { 86 super(ast); 87 } 88 89 92 final List internalStructuralPropertiesForType(int apiLevel) { 93 return propertyDescriptors(apiLevel); 94 } 95 96 99 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 100 if (property == EXPRESSION_PROPERTY) { 101 if (get) { 102 return getExpression(); 103 } else { 104 setExpression((Expression) child); 105 return null; 106 } 107 } 108 return super.internalGetSetChildProperty(property, get, child); 110 } 111 112 115 final int getNodeType0() { 116 return SWITCH_CASE; 117 } 118 119 122 ASTNode clone0(AST target) { 123 SwitchCase result = new SwitchCase(target); 124 result.setSourceRange(this.getStartPosition(), this.getLength()); 125 result.copyLeadingComment(this); 126 result.setExpression( 127 (Expression) ASTNode.copySubtree(target, getExpression())); 128 return result; 129 } 130 131 134 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 135 return matcher.match(this, other); 137 } 138 139 142 void accept0(ASTVisitor visitor) { 143 boolean visitChildren = visitor.visit(this); 144 if (visitChildren) { 145 acceptChild(visitor, getExpression()); 146 } 147 visitor.endVisit(this); 148 } 149 150 156 public Expression getExpression() { 157 if (!this.expressionInitialized) { 158 synchronized (this) { 160 if (!this.expressionInitialized) { 161 preLazyInit(); 162 this.optionalExpression = new SimpleName(this.ast); 163 this.expressionInitialized = true; 164 postLazyInit(this.optionalExpression, EXPRESSION_PROPERTY); 165 } 166 } 167 } 168 return this.optionalExpression; 169 } 170 171 184 public void setExpression(Expression expression) { 185 ASTNode oldChild = this.optionalExpression; 186 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 187 this.optionalExpression = expression; 188 this.expressionInitialized = true; 189 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 190 } 191 192 202 public boolean isDefault() { 203 return getExpression() == null; 204 } 205 206 209 int memSize() { 210 return super.memSize() + 2 * 4; 211 } 212 213 216 int treeSize() { 217 return 218 memSize() 219 + (this.optionalExpression == null ? 0 : optionalExpression.treeSize()); 220 } 221 } 222 | Popular Tags |