001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler.typesystem.impl.declaration;
020:
021: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
022: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
023: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
024: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
025: import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
026: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
027: import org.apache.beehive.netui.compiler.typesystem.impl.DelegatingImpl;
028: import org.apache.beehive.netui.compiler.typesystem.impl.WrapperFactory;
029: import org.apache.beehive.netui.compiler.typesystem.impl.env.SourcePositionImpl;
030: import org.apache.beehive.netui.compiler.typesystem.type.AnnotationType;
031: import org.apache.beehive.netui.compiler.typesystem.util.SourcePosition;
032: import org.apache.beehive.netui.compiler.typesystem.TypesystemElement;
033: import org.apache.beehive.netui.compiler.CompilerUtils;
034:
035: import java.util.HashMap;
036: import java.util.Map;
037: import java.util.Set;
038:
039: public class AnnotationInstanceImpl extends DelegatingImpl implements
040: AnnotationInstance {
041: private Map<AnnotationTypeElementDeclaration, AnnotationValue> _elementValues;
042: private TypesystemElement _containingElement;
043:
044: public AnnotationInstanceImpl(
045: com.sun.mirror.declaration.AnnotationMirror delegate,
046: TypesystemElement containingElement) {
047: super (delegate);
048:
049: assert containingElement != null;
050: assert containingElement instanceof AnnotationInstance
051: || containingElement instanceof MemberDeclaration : containingElement
052: .getClass().getName();
053: _containingElement = containingElement;
054: }
055:
056: public AnnotationType getAnnotationType() {
057: return WrapperFactory.get().getAnnotationType(
058: getDelegate().getAnnotationType());
059: }
060:
061: public SourcePosition getPosition() {
062: return SourcePositionImpl.get(getDelegate().getPosition());
063: }
064:
065: // Map<AnnotationTypeElementDeclaration, AnnotationValue> getElementValues();
066: public Map getElementValues() {
067: if (_elementValues == null) {
068: Set<Map.Entry<com.sun.mirror.declaration.AnnotationTypeElementDeclaration, com.sun.mirror.declaration.AnnotationValue>> entries = getDelegate()
069: .getElementValues().entrySet();
070: Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = new HashMap<AnnotationTypeElementDeclaration, AnnotationValue>();
071: for (Map.Entry<com.sun.mirror.declaration.AnnotationTypeElementDeclaration, com.sun.mirror.declaration.AnnotationValue> i : entries) {
072: elementValues.put(
073: WrapperFactory.get()
074: .getAnnotationTypeElementDeclaration(
075: i.getKey()), WrapperFactory
076: .get().getAnnotationValue(i.getValue(),
077: this ));
078: }
079: _elementValues = elementValues;
080: }
081:
082: return _elementValues;
083: }
084:
085: protected com.sun.mirror.declaration.AnnotationMirror getDelegate() {
086: return (com.sun.mirror.declaration.AnnotationMirror) super
087: .getDelegate();
088: }
089:
090: public TypeDeclaration getContainingType() {
091: TypesystemElement containingDeclaration = _containingElement;
092:
093: while (containingDeclaration instanceof AnnotationInstance) {
094: containingDeclaration = ((AnnotationInstance) containingDeclaration)
095: .getContainingType();
096: }
097:
098: assert containingDeclaration != null;
099: assert containingDeclaration instanceof MemberDeclaration : containingDeclaration
100: .getClass().getName();
101: return CompilerUtils
102: .getOuterClass((MemberDeclaration) containingDeclaration);
103: }
104: }
|