01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso;
05:
06: import org.eclipse.jdt.core.IField;
07: import org.eclipse.jdt.core.IJavaProject;
08: import org.eclipse.jdt.core.IType;
09: import org.eclipse.jdt.core.JavaModelException;
10: import org.eclipse.jdt.core.dom.Annotation;
11: import org.eclipse.jdt.core.dom.IAnnotationBinding;
12:
13: import com.tc.aspectwerkz.reflect.ClassInfo;
14: import com.tc.aspectwerkz.reflect.FieldInfo;
15: import com.tc.backport175.bytecode.AnnotationElement;
16: import com.tc.exception.ImplementMe;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: public class JavaModelFieldInfo implements FieldInfo {
22: private ClassInfoFactory fClassInfoFactory;
23: private IField fField;
24: private List<AnnotationElement.Annotation> fAnnotations = new ArrayList<AnnotationElement.Annotation>();
25:
26: public JavaModelFieldInfo(ClassInfoFactory classInfoFactory,
27: IField field) {
28: fClassInfoFactory = classInfoFactory;
29: fField = field;
30: }
31:
32: public ClassInfo getType() {
33: return fClassInfoFactory.getClassInfo(determineFieldType());
34: }
35:
36: public IType determineFieldType() {
37: try {
38: String sig = fField.getTypeSignature();
39: IType declaringType = fField.getDeclaringType();
40: String typeName = JdtUtils.getResolvedTypeName(sig,
41: declaringType);
42: IJavaProject javaProject = fField.getJavaProject();
43:
44: if (typeName != null) {
45: return JdtUtils.findType(javaProject, typeName);
46: }
47: } catch (JavaModelException jme) {/**/
48: }
49:
50: return null;
51: }
52:
53: public ClassInfo getDeclaringType() {
54: return fClassInfoFactory
55: .getClassInfo(fField.getDeclaringType());
56: }
57:
58: public void clearAnnotations() {
59: fAnnotations.clear();
60: }
61:
62: public void addAnnotation(Annotation annotation) {
63: IAnnotationBinding binding = annotation
64: .resolveAnnotationBinding();
65: String name = binding.getAnnotationType().getQualifiedName();
66: fAnnotations.add(new AnnotationElement.Annotation(name));
67: }
68:
69: public AnnotationElement.Annotation[] getAnnotations() {
70: return fAnnotations
71: .toArray(new AnnotationElement.Annotation[0]);
72: }
73:
74: public String getGenericsSignature() {
75: throw new ImplementMe();
76: }
77:
78: public int getModifiers() {
79: throw new ImplementMe();
80: }
81:
82: public String getName() {
83: return fField.getElementName();
84: }
85:
86: public String getSignature() {
87: throw new ImplementMe();
88: }
89: }
|