List of usage examples for org.eclipse.jdt.core.compiler CharOperation camelCaseMatch
public static final boolean camelCaseMatch(char[] pattern, char[] name)
From source file:net.harawata.mybatipse.mybatis.ProposalComputorHelper.java
License:Open Source License
private static void proposeXmlElements(List<ICompletionProposal> results, NodeList nodes, char[] matchChrs, int start, int length, String exclude) { for (int j = 0; j < nodes.getLength(); j++) { String id = nodes.item(j).getNodeValue(); if ((matchChrs.length == 0 || CharOperation.camelCaseMatch(matchChrs, id.toCharArray())) && (exclude == null || !exclude.equals(id))) { int cursorPos = id.length(); ICompletionProposal proposal = new JavaCompletionProposal(id.toString(), start, length, cursorPos, Activator.getIcon(), id, null, null, 200); results.add(proposal);//from w ww. j ava 2s. c o m } } }
From source file:net.harawata.mybatipse.mybatis.ProposalComputorHelper.java
License:Open Source License
private static void proposeNamespaces(List<ICompletionProposal> results, IJavaProject project, String partialNamespace, String currentNamespace, char[] matchChrs, int start, int length) { for (String namespace : MapperNamespaceCache.getInstance().getCacheMap(project, null).keySet()) { if (!namespace.equals(currentNamespace) && namespace.startsWith(partialNamespace) && !namespace.equals(partialNamespace)) { char[] simpleName = CharOperation.lastSegment(namespace.toCharArray(), '.'); if (matchChrs.length == 0 || CharOperation.camelCaseMatch(matchChrs, simpleName)) { StringBuilder replacementStr = new StringBuilder().append(namespace).append('.'); int cursorPos = replacementStr.length(); String displayString = new StringBuilder().append(simpleName).append(" - ").append(namespace) .toString();//from w w w . j a v a2s . c om results.add(new JavaCompletionProposal(replacementStr.toString(), start, length, cursorPos, Activator.getIcon("/icons/mybatis-ns.png"), displayString, null, null, 100)); } } } }
From source file:net.harawata.mybatipse.mybatis.ProposalComputorHelper.java
License:Open Source License
private static void addProposalIfMatch(final List<ICompletionProposal> proposals, final String matchString, String targetStr, String replacementStr, final int offset, final int length, String displayStr) { if (targetStr == null || targetStr.length() == 0) return;//w ww . ja v a 2s.c om if (matchString.length() == 0 || CharOperation.camelCaseMatch(matchString.toCharArray(), targetStr.toCharArray())) { proposals.add(new CompletionProposal(replacementStr, offset, length, replacementStr.length(), Activator.getIcon(), displayStr, null, null)); } }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void proposalFromNodes(ContentAssistRequest contentAssistRequest, NodeList nodes, String namespace, char[] matchChrs, int start, int length, String replacementSuffix) { for (int j = 0; j < nodes.getLength(); j++) { String id = nodes.item(j).getNodeValue(); if (matchChrs.length == 0 || CharOperation.camelCaseMatch(matchChrs, id.toCharArray())) { StringBuilder replacementStr = new StringBuilder(); if (namespace != null && namespace.length() > 0) replacementStr.append(namespace).append('.'); replacementStr.append(id);/* w ww . j av a2s . com*/ int cursorPos = replacementStr.length(); if (replacementSuffix != null) replacementStr.append(replacementSuffix); ICompletionProposal proposal = new CompletionProposal(replacementStr.toString(), start, length, cursorPos, Activator.getIcon(), id, null, null); contentAssistRequest.addProposal(proposal); } } }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void proposeNamespace(ContentAssistRequest contentAssistRequest, IJavaProject project, IDOMNode node, String partialNamespace, char[] matchChrs, int start, int length, String replacementSuffix) throws XPathExpressionException { String currentNamespace = XpathUtil.xpathString(node.getOwnerDocument(), "//mapper/@namespace"); final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>(); for (String namespace : MapperNamespaceCache.getInstance().getCacheMap(project, null).keySet()) { if (!namespace.equals(currentNamespace) && namespace.startsWith(partialNamespace) && !namespace.equals(partialNamespace)) { char[] simpleName = CharOperation.lastSegment(namespace.toCharArray(), '.'); if (matchChrs.length == 0 || CharOperation.camelCaseMatch(matchChrs, simpleName)) { StringBuilder replacementStr = new StringBuilder().append(namespace).append('.'); int cursorPos = replacementStr.length(); if (replacementSuffix != null) replacementStr.append(replacementSuffix); String displayString = new StringBuilder().append(simpleName).append(" - ").append(namespace) .toString();//from ww w.ja v a 2 s. co m results.add(new CompletionProposal(replacementStr.toString(), start, length, cursorPos, Activator.getIcon("/icons/mybatis-ns.png"), displayString, null, null)); } } } addProposals(contentAssistRequest, results); }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void proposeStatementId(ContentAssistRequest contentAssistRequest, IJavaProject project, String matchString, int start, int length, IDOMNode node) throws JavaModelException, XPathExpressionException { final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>(); String qualifiedName = MybatipseXmlUtil.getNamespace(node.getOwnerDocument()); IType type = project.findType(qualifiedName); for (IMethod method : type.getMethods()) { String statementId = method.getElementName(); if (matchString.length() == 0 || CharOperation.camelCaseMatch(matchString.toCharArray(), statementId.toCharArray())) { results.add(new CompletionProposal(statementId, start, length, statementId.length(), Activator.getIcon(), statementId, null, null)); }/*from www.j a v a 2 s.c om*/ } addProposals(contentAssistRequest, results); }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void proposeJavaType(final ContentAssistRequest contentAssistRequest, IJavaProject project, String matchString, final int start, final int length, boolean includeAlias) throws JavaModelException { final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>(); if (includeAlias) { TypeAliasMap typeAliasMap = TypeAliasCache.getInstance().getTypeAliasMap(project, null); for (TypeAliasInfo typeAliasInfo : typeAliasMap.values()) { String alias = typeAliasInfo.getAliasToInsert(); String qualifiedName = typeAliasInfo.getQualifiedName(); char[] aliasChrs = alias.toCharArray(); char[] matchChrs = matchString.toCharArray(); if (matchString.length() == 0 || CharOperation.camelCaseMatch(matchChrs, aliasChrs) || CharOperation.prefixEquals(matchChrs, aliasChrs, false)) { results.add(new CompletionProposal(alias, start, length, alias.length(), Activator.getIcon("/icons/mybatis-alias.png"), alias + " - " + qualifiedName, null, null));//from w ww . j a v a2s . c o m } } addProposals(contentAssistRequest, results); } results.clear(); int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; // Include application libraries only when package is specified (for better performance). boolean pkgSpecified = matchString != null && matchString.indexOf('.') > 0; if (pkgSpecified) includeMask |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, includeMask); TypeNameRequestor requestor = new JavaTypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (Flags.isAbstract(modifiers) || Flags.isInterface(modifiers)) return; addJavaTypeProposal(results, start, length, packageName, simpleTypeName, enclosingTypeNames); } }; searchJavaType(matchString, scope, requestor); addProposals(contentAssistRequest, results); }
From source file:org.ebayopensource.vjo.tool.codecompletion.proposaldata.integration.VjoEclipseCompletionProposalAdapter.java
License:Open Source License
/** * Case insensitive comparison of <code>prefix</code> with the start of * <code>string</code>. Returns <code>false</code> if * <code>prefix</code> is longer than <code>string</code> * //from w w w. ja va 2 s. co m * */ protected boolean isPrefix(String prefix, String string) { if (prefix == null || string == null || prefix.length() > string.length()) return false; String start = string.substring(0, prefix.length()); return start.equalsIgnoreCase(prefix) || CharOperation.camelCaseMatch(prefix.toCharArray(), string.toCharArray()); }
From source file:org.eclipse.jst.common.internal.annotations.ui.AbstractAnnotationTagProposal.java
License:Open Source License
/** * Case insensitive comparison of <code>prefix</code> with the start of <code>string</code>. * Returns <code>false</code> if <code>prefix</code> is longer than <code>string</code> * /*from w ww . ja v a2 s. c o m*/ * @since 3.2 */ protected boolean isPrefix(String prefix, String string) { if (prefix == null || string == null || prefix.length() > string.length()) return false; String start = string.substring(0, prefix.length()); return start.equalsIgnoreCase(prefix) || isCamelCaseMatching() && CharOperation.camelCaseMatch(prefix.toCharArray(), string.toCharArray()); }
From source file:org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.java
License:Open Source License
@Override public void process(final IProcessableProposal proposal) { String completionIdentifier = computeCompletionIdentifier(proposal, proposal.getCoreProposal().orNull()); final String matchingArea = CompletionContexts.getPrefixMatchingArea(completionIdentifier); proposal.getProposalProcessorManager().addProcessor(new ProposalProcessor() { int[] bestSequence = EMPTY_SEQUENCE; String prefix;// w w w. j av a 2 s . co m @Override public boolean isPrefix(String prefix) { if (this.prefix != prefix) { this.prefix = prefix; CompletionProposal coreProposal = proposal.getCoreProposal().orNull(); if (coreProposal != null && (coreProposal .getKind() == CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER || coreProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER)) { // This covers the case where the user starts with a prefix of "receiver.ge" and continues // typing 't' from there: In this case, prefix == "receiver.get" rather than "get". // I have only ever encountered this with proposal kinds of *_REF_WITH_CASTED_RECEIVER. int lastIndexOfDot = prefix.lastIndexOf('.'); bestSequence = LCSS.bestSubsequence(matchingArea, prefix.substring(lastIndexOfDot + 1)); } else { int lastIndexOfHash = prefix.lastIndexOf('#'); if (lastIndexOfHash >= 0) { // This covers the case where the user starts with a prefix of "Collections#" and continues // from there. bestSequence = LCSS.bestSubsequence(matchingArea, prefix.substring(lastIndexOfHash + 1)); } else { // Besides the obvious, this also covers the case where the user starts with a prefix of // "Collections#e", which manifests itself as just "e". bestSequence = LCSS.bestSubsequence(matchingArea, prefix); } } } return prefix.isEmpty() || bestSequence.length > 0; } @Override public void modifyDisplayString(StyledString displayString) { final int highlightAdjustment; CompletionProposal coreProposal = proposal.getCoreProposal().orNull(); if (coreProposal == null) { // HTML tag proposals are non-lazy(!) JavaCompletionProposals that don't have a core proposal. if (proposal instanceof JavaCompletionProposal && displayString.toString().startsWith("</")) { //$NON-NLS-1$ highlightAdjustment = 2; } else if (proposal instanceof JavaCompletionProposal && displayString.toString().startsWith("<")) { //$NON-NLS-1$ highlightAdjustment = 1; } else { highlightAdjustment = 0; } } else { switch (coreProposal.getKind()) { case CompletionProposal.JAVADOC_FIELD_REF: case CompletionProposal.JAVADOC_METHOD_REF: case CompletionProposal.JAVADOC_VALUE_REF: highlightAdjustment = displayString.toString().lastIndexOf('#') + 1; break; case CompletionProposal.JAVADOC_TYPE_REF: highlightAdjustment = JAVADOC_TYPE_REF_HIGHLIGHT_ADJUSTMENT; break; default: highlightAdjustment = 0; } } for (int index : bestSequence) { displayString.setStyle(index + highlightAdjustment, 1, StyledString.COUNTER_STYLER); } } /** * Since we may simulate completion triggers at positions before the actual triggering, we don't get JDT's * additional relevance for exact prefix matches. So we add the additional relevance ourselves, if is not * already supplied by the JDT which it does, if the prefix is shorter than the configured minimum prefix * length. * * The boost is the same one as JDT adds at * {@link org.eclipse.jdt.internal.codeassist.CompletionEngine#computeRelevanceForCaseMatching} * * The boost is further multiplied by 16 which reflects the same thing happening in * {@link org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal#computeRelevance} */ @Override public int modifyRelevance() { if (ArrayUtils.isEmpty(bestSequence)) { proposal.setTag(IS_PREFIX_MATCH, true); return 0; } int relevanceBoost = 0; if (minPrefixLengthForTypes < prefix.length() && StringUtils.equalsIgnoreCase(matchingArea, prefix)) { relevanceBoost += 16 * RelevanceConstants.R_EXACT_NAME; proposal.setTag(IS_EXACT_MATCH, true); } // We only apply case matching to genuine Java proposals, i.e., proposals link HTML tags are ranked // together with the case in-sensitive matches. if (StringUtils.startsWith(matchingArea, prefix) && isFromJavaCompletionProposalComputer(proposal)) { proposal.setTag(SUBWORDS_SCORE, null); proposal.setTag(IS_PREFIX_MATCH, true); // Don't adjust relevance. } else if (startsWithIgnoreCase(matchingArea, prefix)) { proposal.setTag(SUBWORDS_SCORE, null); proposal.setTag(IS_CASE_INSENSITIVE_PREFIX_MATCH, true); relevanceBoost = IGNORE_CASE_RANGE_START + relevanceBoost; } else if (CharOperation.camelCaseMatch(prefix.toCharArray(), matchingArea.toCharArray()) && isFromJavaCompletionProposalComputer(proposal)) { proposal.setTag(IS_PREFIX_MATCH, false); proposal.setTag(IS_CAMEL_CASE_MATCH, true); relevanceBoost = CAMEL_CASE_RANGE_START + relevanceBoost; } else { int score = LCSS.scoreSubsequence(bestSequence); proposal.setTag(IS_PREFIX_MATCH, false); proposal.setTag(SUBWORDS_SCORE, score); relevanceBoost = SUBWORDS_RANGE_START + relevanceBoost + score; } return relevanceBoost; } /** * Some {@link IProcessableProposal}s are not produced by the {@link JavaCompletionProposalComputer}, but by * some other {@link IJavaCompletionProposalComputer}, e.g., the {@link HTMLTagCompletionProposalComputer}. * These proposals do not have a core proposal. */ private boolean isFromJavaCompletionProposalComputer(final IProcessableProposal proposal) { return proposal.getCoreProposal().isPresent(); } }); }