1 18 package org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.declaration; 19 20 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 22 import org.apache.beehive.netui.compiler.typesystem.type.AnnotationType; 23 import org.apache.beehive.netui.compiler.typesystem.util.SourcePosition; 24 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.DelegatingImpl; 25 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.env.SourcePositionImpl; 26 import org.apache.beehive.netui.xdoclet.XDocletCompilerUtils; 27 import xjavadoc.XProgramElement; 28 import xjavadoc.XTag; 29 30 import java.util.ArrayList ; 31 import java.util.HashMap ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 public class AnnotationInstanceImpl 36 extends DelegatingImpl 37 implements AnnotationInstance 38 { 39 40 private AnnotationType _type; 41 private SourcePosition _sourcePosition; 42 43 private HashMap _elementValues; 45 46 public AnnotationInstanceImpl( XTag tag, XProgramElement element, AnnotationType type, HashMap elementValues ) 47 { 48 super( tag ); 49 _sourcePosition = SourcePositionImpl.get( tag, element ); 50 _type = type; 51 _elementValues = elementValues; 52 } 53 54 public AnnotationType getAnnotationType() 55 { 56 return _type; 57 } 58 59 public SourcePosition getPosition() 60 { 61 return _sourcePosition; 62 } 63 64 public void addElementValue( String memberName, boolean memberIsArray, Object value, SourcePosition sourcePosition ) 65 { 66 AnnotationTypeElementDeclaration elementDecl = _type.getAnnotationTypeDeclaration().getMember( memberName ); 67 68 if ( elementDecl == null ) 69 { 70 XDocletCompilerUtils.addError( getPosition(), "error.no-such-member", 71 new String []{ memberName, _type.getAnnotationTypeDeclaration().getQualifiedName() } ); 72 } 73 else if ( memberIsArray ) 74 { 75 AnnotationValueImpl av = ( AnnotationValueImpl ) _elementValues.get( elementDecl ); 76 List list; 77 78 if ( av == null ) 79 { 80 list = new ArrayList (); 81 av = new AnnotationValueImpl( list, sourcePosition, elementDecl ); 82 _elementValues.put( elementDecl, av ); 83 } 84 else 85 { 86 list = ( List ) av.getValue(); 87 } 88 89 list.add( new AnnotationValueImpl( value, sourcePosition, null ) ); 90 } 91 else 92 { 93 _elementValues.put( elementDecl, new AnnotationValueImpl( value, sourcePosition, elementDecl ) ); 94 } 95 } 96 97 public Map getElementValues() 99 { 100 return _elementValues; 101 } 102 103 public boolean equals( Object o ) 104 { 105 if ( o == null ) return false; 106 if ( o == this ) return true; 107 if ( ! ( o instanceof AnnotationInstanceImpl ) ) return false; 108 assert false : "didn't finish equals()"; 109 return false; 110 } 111 112 public String toString() 113 { 114 assert false : "NYI"; 115 throw new UnsupportedOperationException ( "NYI" ); 116 } 117 118 public XTag getDelegateXTag() 119 { 120 return ( XTag ) super.getDelegate(); 121 } 122 } 123 | Popular Tags |