1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.List ; 22 import javax.jmi.reflect.ConstraintViolationException; 23 import org.netbeans.jmi.javamodel.CharLiteral; 24 import org.netbeans.jmi.javamodel.Element; 25 import org.netbeans.jmi.javamodel.JavaModelPackage; 26 import org.netbeans.jmi.javamodel.PrimitiveTypeKindEnum; 27 import org.netbeans.lib.java.parser.Token; 28 import org.netbeans.mdr.storagemodel.StorableObject; 29 30 34 public abstract class CharLiteralImpl extends LiteralImpl implements CharLiteral { 35 private String value; 36 37 public CharLiteralImpl(StorableObject o) { 38 super(o); 39 type = ((JavaModelPackage) refImmediatePackage()).getType().resolve(PrimitiveTypeKindEnum.CHAR.toString()); 40 } 41 42 public void setValue(String value) { 43 objectChanged(CHANGED_VALUE); 44 doValueChange(value); 45 } 46 47 public String getValue() { 48 if (isChanged(CHANGED_VALUE)) { 49 return value; 50 } else { 51 return "" + ((Token) getASTree()).getValue(); 52 } 53 } 54 55 public String getSourceText() { 56 String origElem; 57 if ((origElem = checkChange()) != null) 58 return origElem; 59 return getText(); 60 } 61 62 public void getDiff(List diff) { 63 replaceNode(diff, getParser(), getASTree(), getText(), 0, null); 64 } 65 66 private String getText() { 67 return "'" + String.valueOf(getValue()) + '\''; } 69 70 void setData(String value) { 71 doValueChange(value); 72 } 73 74 private void doValueChange(String value) { 75 if (value == null) { 76 this.value = "\000"; } else { 78 if (value.length() != 1) throw new ConstraintViolationException(null, null, "Must pass exactly one character."); this.value = value; 80 } 81 } 82 83 public Element duplicate(JavaModelPackage targetExtent) { 84 return targetExtent.getCharLiteral().createCharLiteral(getValue()); 85 } 86 } 87 | Popular Tags |