private List<ICompletionProposal> proposeParameter( IJavaProject project, final int offset, final int length, Node statementNode, final boolean searchReadable, final String matchString) { List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); if (statementNode == null) return proposals; String statementId = null; String paramType = null; NamedNodeMap statementAttrs = statementNode.getAttributes(); for (int i = 0; i < statementAttrs.getLength(); i++) { Node attr = statementAttrs.item(i); String attrName = attr.getNodeName(); if ("id".equals(attrName)) statementId = attr.getNodeValue(); else if ("parameterType".equals(attrName)) paramType = attr.getNodeValue(); } if (statementId == null || statementId.length() == 0) return proposals; if (paramType != null) { String resolved = TypeAliasCache.getInstance().resolveAlias(project, paramType, null); proposals = ProposalComputorHelper.proposePropertyFor( project, offset, length, resolved != null ? resolved : paramType, searchReadable, -1, matchString); } else { try { final List<MapperMethodInfo> methodInfos = new ArrayList<MapperMethodInfo>(); String mapperFqn = MybatipseXmlUtil.getNamespace(statementNode.getOwnerDocument()); JavaMapperUtil.findMapperMethod( methodInfos, project, mapperFqn, statementId, true, new RejectStatementAnnotation()); if (methodInfos.size() > 0) { proposals = ProposalComputorHelper.proposeParameters( project, offset, length, methodInfos.get(0).getParams(), searchReadable, matchString); } } catch (XPathExpressionException e) { Activator.log(Status.ERROR, e.getMessage(), e); } } return proposals; }
private void generateResults( ContentAssistRequest contentAssistRequest, int offset, int length, Node parentNode, Node typeAttr) { if (typeAttr == null) return; String typeValue = typeAttr.getNodeValue(); if (typeValue == null || typeValue.length() == 0) return; IJavaProject project = getJavaProject(contentAssistRequest); // Try resolving the alias. String qualifiedName = TypeAliasCache.getInstance().resolveAlias(project, typeValue, null); if (qualifiedName == null) { // Assumed to be FQN. qualifiedName = typeValue; } BeanPropertyInfo beanProps = BeanPropertyCache.getBeanPropertyInfo(project, qualifiedName); try { Set<String> existingProps = new HashSet<String>(); NodeList existingPropNodes = XpathUtil.xpathNodes(parentNode, "*[@property]/@property"); for (int i = 0; i < existingPropNodes.getLength(); i++) { existingProps.add(existingPropNodes.item(i).getNodeValue()); } StringBuilder resultTags = new StringBuilder(); for (Entry<String, String> prop : beanProps.getWritableFields().entrySet()) { String propName = prop.getKey(); if (!existingProps.contains(propName)) { resultTags .append("<result property=\"") .append(propName) .append("\" column=\"") .append(propName) .append("\" />\n"); } } contentAssistRequest.addProposal( new CompletionProposal( resultTags.toString(), offset, length, resultTags.length(), Activator.getIcon(), "<result /> for properties", null, null)); } catch (XPathExpressionException e) { Activator.log(Status.ERROR, e.getMessage(), e); } }
private void proposeProperty( ContentAssistRequest contentAssistRequest, String matchString, int start, int length, IDOMNode node) throws JavaModelException { String javaType = MybatipseXmlUtil.findEnclosingType(node); if (javaType != null && !MybatipseXmlUtil.isDefaultTypeAlias(javaType)) { IJavaProject project = getJavaProject(contentAssistRequest); IType type = project.findType(javaType); if (type == null) { javaType = TypeAliasCache.getInstance().resolveAlias(project, javaType, null); if (javaType == null) return; } addProposals( contentAssistRequest, ProposalComputorHelper.proposePropertyFor( project, start, length, javaType, false, -1, matchString)); } }