KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > extractor > FieldPropertyHandler


1 /**
2  *
3  */

4 package org.hibernate.eclipse.mapper.extractor;
5
6 import org.eclipse.jdt.core.IField;
7 import org.eclipse.jdt.core.IJavaElement;
8 import org.eclipse.jdt.core.IJavaProject;
9 import org.eclipse.jdt.core.IType;
10 import org.eclipse.jdt.core.JavaModelException;
11 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
12 import org.eclipse.jface.text.contentassist.ICompletionProposal;
13 import org.w3c.dom.Attr JavaDoc;
14 import org.w3c.dom.Node JavaDoc;
15
16 class FieldPropertyHandler implements HBMInfoHandler {
17
18     /**
19      *
20      */

21     private final HBMInfoExtractor extractor;
22
23     /**
24      * @param extractor
25      */

26     FieldPropertyHandler(HBMInfoExtractor extractor) {
27         this.extractor = extractor;
28     }
29
30     public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node JavaDoc node, String JavaDoc attributeName, String JavaDoc start, int offset) {
31         // TODO: should also try to find properties getXXX()
32
if(project!=null) {
33             String JavaDoc typename = this.extractor.getNearestType(node);
34                         
35             HBMXMLResultCollector rc = null;
36             try {
37                 IType type = project.findType(typename);
38                 if(type==null) return new ICompletionProposal[0]; //nothing to look for then
39
rc = new HBMXMLResultCollector(project);
40                 rc.setAccepts(false,false,false,false,true,false); // TODO: only handle properties ?
41
//rc.reset(offset, javaProject, null);
42

43                 
44                 type.codeComplete(start.toCharArray(), -1, start.length(), new char[0][0], new char[0][0], new int[0], false, rc);
45             } catch(JavaModelException jme) {
46                 // TODO: report
47
}
48             
49             IJavaCompletionProposal[] results = rc.getJavaCompletionProposals();
50             this.extractor.transpose(start, offset, results);
51             return results;
52         }
53         
54         return new ICompletionProposal[0];
55     }
56
57     public IJavaElement getJavaElement(IJavaProject project, Node JavaDoc currentNode, Attr JavaDoc currentAttrNode) {
58         IType type = extractor.getNearestTypeJavaElement(project, currentNode.getParentNode());
59         if(type!=null) {
60             IField field = type.getField(currentAttrNode.getValue());
61             return field;
62         }
63         
64         return null;
65     }
66 }
Popular Tags