1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 14 import org.eclipse.jdt.apt.core.internal.util.Factory; 15 import org.eclipse.jdt.core.dom.ITypeBinding; 16 import org.eclipse.jdt.core.dom.IVariableBinding; 17 18 import com.sun.mirror.declaration.FieldDeclaration; 19 import com.sun.mirror.declaration.TypeDeclaration; 20 import com.sun.mirror.type.TypeMirror; 21 import com.sun.mirror.util.DeclarationVisitor; 22 23 public class FieldDeclarationImpl extends MemberDeclarationImpl implements FieldDeclaration 24 { 25 public FieldDeclarationImpl(final IVariableBinding binding, final BaseProcessorEnv env) 26 { 27 super(binding, env); 28 assert binding.isField() : "binding doesn't represent a field"; } 30 31 public void accept(DeclarationVisitor visitor) 32 { 33 visitor.visitFieldDeclaration(this); 34 } 35 36 public String getConstantExpression() 37 { 38 final IVariableBinding field = getDeclarationBinding(); 39 final Object constant = field.getConstantValue(); 40 if( constant == null ) return null; 41 return constant.toString(); 42 } 43 44 public Object getConstantValue() 45 { 46 final IVariableBinding field = getDeclarationBinding(); 47 return field.getConstantValue(); 48 } 49 50 public TypeDeclaration getDeclaringType() 51 { 52 final IVariableBinding field = getDeclarationBinding(); 53 final ITypeBinding outer = field.getDeclaringClass(); 54 return Factory.createReferenceType(outer, _env); 55 } 56 57 public String getSimpleName() 58 { 59 final IVariableBinding field = getDeclarationBinding(); 60 final String name = field.getName(); 61 return name == null ? "" : name; } 63 64 public TypeMirror getType() 65 { 66 final IVariableBinding field = getDeclarationBinding(); 67 final TypeMirror typeMirror = Factory.createTypeMirror( field.getType(), _env ); 68 if( typeMirror == null ) 69 return Factory.createErrorClassType(field.getType()); 70 return typeMirror; 71 } 72 73 public IVariableBinding getDeclarationBinding() 74 { 75 return (IVariableBinding)_binding; 76 } 77 78 public String toString() 79 { 80 90 return getSimpleName(); 91 } 92 93 public MirrorKind kind(){ return MirrorKind.FIELD; } 94 95 public boolean isFromSource() 96 { 97 final ITypeBinding type = getDeclarationBinding().getDeclaringClass(); 98 return ( type != null && type.isFromSource() ); 99 } 100 } 101 | Popular Tags |