1 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 ; 14 import org.w3c.dom.Node ; 15 16 class FieldPropertyHandler implements HBMInfoHandler { 17 18 21 private final HBMInfoExtractor extractor; 22 23 26 FieldPropertyHandler(HBMInfoExtractor extractor) { 27 this.extractor = extractor; 28 } 29 30 public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node node, String attributeName, String start, int offset) { 31 if(project!=null) { 33 String 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]; rc = new HBMXMLResultCollector(project); 40 rc.setAccepts(false,false,false,false,true,false); 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 } 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 currentNode, Attr 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 |