01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * tyeung@bea.com - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.apt.core.internal.declaration;
11:
12: import com.sun.mirror.declaration.AnnotationTypeDeclaration;
13: import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
14: import com.sun.mirror.declaration.AnnotationValue;
15: import com.sun.mirror.declaration.ParameterDeclaration;
16: import com.sun.mirror.util.DeclarationVisitor;
17: import java.util.Collection;
18: import java.util.Collections;
19:
20: import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
21: import org.eclipse.jdt.apt.core.internal.util.Factory;
22: import org.eclipse.jdt.core.dom.ASTNode;
23: import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
24: import org.eclipse.jdt.core.dom.IMethodBinding;
25:
26: public class AnnotationElementDeclarationImpl extends
27: MethodDeclarationImpl implements
28: AnnotationTypeElementDeclaration {
29: public AnnotationElementDeclarationImpl(
30: final IMethodBinding binding, final BaseProcessorEnv env) {
31: super (binding, env);
32: }
33:
34: public void accept(DeclarationVisitor visitor) {
35: visitor.visitAnnotationTypeElementDeclaration(this );
36: }
37:
38: public AnnotationTypeDeclaration getDeclaringType() {
39: return (AnnotationTypeDeclaration) super .getDeclaringType();
40: }
41:
42: /**
43: * @return the default value of this annotation element if one exists.
44: * Return null if the annotation element is defined in binary (feature not available right now).
45: * Return null if the annotation element is part of a seconary type that is defined outside
46: * the file associated with the environment.
47: */
48: public AnnotationValue getDefaultValue() {
49: final IMethodBinding binding = getDeclarationBinding();
50: final Object defaultValue = binding.getDefaultValue();
51: return Factory.createDefaultValue(defaultValue, this , _env);
52: }
53:
54: ASTNode getAstNodeForDefault() {
55: final AnnotationTypeMemberDeclaration decl = (AnnotationTypeMemberDeclaration) getAstNode();
56: if (decl != null)
57: return decl.getDefault();
58:
59: return null;
60: }
61:
62: public Collection<ParameterDeclaration> getParameters() {
63: return Collections.emptyList();
64: }
65:
66: public MirrorKind kind() {
67: return MirrorKind.ANNOTATION_ELEMENT;
68: }
69: }
|