List of usage examples for org.eclipse.jdt.core.search SearchPattern R_PREFIX_MATCH
int R_PREFIX_MATCH
To view the source code for org.eclipse.jdt.core.search SearchPattern R_PREFIX_MATCH.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java
License:Open Source License
private void createSubtypeProposals(final ContentAssistRequest contentAssistRequest, final CompletionProposalInvocationContext context, IType superType) { IJavaProject jproject = findProject(contentAssistRequest); try {//from www . j ava2s .co m IJavaSearchScope hierarchyScope = SearchEngine.createHierarchyScope(superType); IJavaSearchScope projectScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { jproject }); IJavaSearchScope scope = new IntersectingJavaSearchScope(projectScope, hierarchyScope); SearchEngine searchEngine = new SearchEngine(); char[] typeName = null; char[] packageName = null; if (!contentAssistRequest.getMatchString().isEmpty()) { typeName = contentAssistRequest.getMatchString().toCharArray(); } searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { String sPackageName = new String(packageName); int priority = PRIORITY_LOWER_1; if (sPackageName.startsWith("com.sun.javafx")) { priority -= 10; } StyledString s = new StyledString(new String(simpleTypeName)); s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER); FXMLCompletionProposal prop = createElementProposal(contentAssistRequest, context, sPackageName + "." + new String(simpleTypeName) + " ", s, false, priority, IconKeys.getIcon(IconKeys.CLASS_KEY), FQN_MATCHER); if (prop != null) { prop.setMatcher(FQN_MATCHER); prop.setTextApplier(new IReplacementTextApplier() { @Override public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException { String proposalReplacementString = proposal.getReplacementString(); List<String> s = getImportedTypes(contentAssistRequest); String shortened = proposalReplacementString .substring(proposalReplacementString.lastIndexOf('.') + 1); if (s.contains(proposalReplacementString.trim())) { proposal.setCursorPosition(shortened.length()); document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), shortened); } else { DocumentRewriteSession rewriteSession = null; try { if (document instanceof IDocumentExtension4) { rewriteSession = ((IDocumentExtension4) document) .startRewriteSession( DocumentRewriteSessionType.UNRESTRICTED_SMALL); } } finally { if (rewriteSession != null) { ((IDocumentExtension4) document) .stopRewriteSession(rewriteSession); } // if (viewerExtension != null) // viewerExtension.setRedraw(true); } boolean startWithLineBreak = true; boolean endWithLineBreak = false; Document xmlDoc = contentAssistRequest.getNode().getOwnerDocument(); NodeList list = xmlDoc.getChildNodes(); int offset = 0; List<Node> prs = new ArrayList<Node>(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { prs.add(n); } } if (!prs.isEmpty()) { offset = ((IDOMNode) prs.get(prs.size() - 1)).getEndOffset(); } offset = Math.min(proposal.getReplacementOffset(), offset); proposal.setCursorPosition(shortened.length()); document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), shortened); String importStatement = (startWithLineBreak ? "\n<?import " : "import ") + proposalReplacementString.trim(); importStatement += "?>"; if (endWithLineBreak) importStatement += "\n\n"; document.replace(offset, 0, importStatement.toString()); proposal.setCursorPosition( proposal.getCursorPosition() + importStatement.length()); } } }); contentAssistRequest.addProposal(prop); } } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java
License:Open Source License
@Override protected void addAttributeValueProposals(final ContentAssistRequest contentAssistRequest, final CompletionProposalInvocationContext context) { IDOMNode n = (IDOMNode) contentAssistRequest.getNode(); if (Character.isUpperCase(n.getNodeName().charAt(0))) { NamedNodeMap m = n.getAttributes(); IDOMNode attribute = null;/*from w w w . j a v a2s. c o m*/ for (int i = 0; i < m.getLength(); i++) { IDOMNode a = (IDOMNode) m.item(i); if (a.contains(contentAssistRequest.getStartOffset())) { attribute = a; } } if (attribute != null) { if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) { if ("constant".equals(attribute.getLocalName())) { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { try { List<IField> fields = new ArrayList<IField>(); collectStaticFields(fields, type); for (IField f : fields) { StyledString s = new StyledString(f.getElementName() + " : " + Signature.getSimpleName(Signature.toString(f.getTypeSignature()))); String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName(); s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + f.getElementName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if ("controller".equals(attribute.getLocalName())) { IJavaProject jproject = findProject(contentAssistRequest); char[] typeName = null; char[] packageName = null; if (!contentAssistRequest.getMatchString().isEmpty()) { if (contentAssistRequest.getMatchString().startsWith("\"")) { typeName = contentAssistRequest.getMatchString().substring(1).toCharArray(); } else { typeName = contentAssistRequest.getMatchString().toCharArray(); } } IJavaSearchScope searchScope = SearchEngine .createJavaSearchScope(new IJavaElement[] { jproject }); SearchEngine searchEngine = new SearchEngine(); try { searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.TYPE, searchScope, new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { String sPackageName = new String(packageName); int priority = PRIORITY_LOWER_1; if (sPackageName.startsWith("com.sun")) { priority -= 10; } StyledString s = new StyledString(new String(simpleTypeName)); s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + sPackageName + "." + new String(simpleTypeName), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if (attribute.getNodeName().contains(".")) { String[] parts = attribute.getNodeName().split("\\."); IType type = findType(parts[0], contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getStaticProperty(parts[1]); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } } } } else { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getProperty(attribute.getNodeName()); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } else if (p instanceof IFXEventHandlerProperty) { createAttributeValueEventHandlerProposals(contentAssistRequest, context, (IFXEventHandlerProperty) p); } } } } } } }
From source file:bndtools.editor.components.ComponentNameProposalProvider.java
License:Open Source License
@Override protected List<IContentProposal> doGenerateProposals(String contents, int position) { final String prefix = contents.substring(0, position); IJavaProject javaProject = searchContext.getJavaProject(); final List<IContentProposal> result = new ArrayList<IContentProposal>(100); // Resource matches IProject project = javaProject.getProject(); try {/*from w ww. jav a 2 s. c o m*/ project.accept(new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() == IResource.FILE) { if (proxy.getName().toLowerCase().startsWith(prefix) && proxy.getName().toLowerCase().endsWith(XML_SUFFIX)) { result.add(new ResourceProposal(proxy.requestResource())); } return false; } // Recurse into everything else return true; } }, 0); } catch (CoreException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for resources.", e)); } // Class matches final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final TypeNameRequestor requestor = new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (!Flags.isAbstract(modifiers) && (Flags.isPublic(modifiers) || Flags.isProtected(modifiers))) { result.add(new JavaContentProposal(new String(packageName), new String(simpleTypeName), false)); } }; }; final IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(), SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS, scope, requestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }; IRunnableContext runContext = searchContext.getRunContext(); try { if (runContext != null) { runContext.run(false, false, runnable); } else { runnable.run(new NullProgressMonitor()); } } catch (InvocationTargetException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for classes.", e.getTargetException())); } catch (InterruptedException e) { // Reset the interruption status and continue Thread.currentThread().interrupt(); } return result; }
From source file:bndtools.editor.components.SvcInterfaceProposalProvider.java
License:Open Source License
@Override protected List<IContentProposal> doGenerateProposals(String contents, int position) { final String prefix = contents.substring(0, position); final IJavaSearchScope scope = SearchEngine .createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() }); final ArrayList<IContentProposal> result = new ArrayList<IContentProposal>(100); final TypeNameRequestor typeNameRequestor = new TypeNameRequestor() { @Override/*ww w.ja va 2 s . c o m*/ public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { boolean isInterface = Flags.isInterface(modifiers); result.add( new JavaContentProposal(new String(packageName), new String(simpleTypeName), isInterface)); } }; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(), SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, typeNameRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }; try { if (searchContext.getRunContext() == null) { runnable.run(new NullProgressMonitor()); } else { searchContext.getRunContext().run(false, false, runnable); } } catch (InvocationTargetException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for Java types.", e.getTargetException())); return Collections.emptyList(); } catch (InterruptedException e) { // Reset interrupted status and return empty Thread.currentThread().interrupt(); return Collections.emptyList(); } return result; }
From source file:ccw.editors.clojure.ClojureProposalProcessor.java
License:Open Source License
private List<ICompletionProposal> computeAndAddJavaInstanceMethodCompletionProposal( final PrefixInfo prefixInfo) { final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); if (!checkJavaPrefixLength(prefixInfo)) { return Collections.emptyList(); }//from w w w . j a v a 2s. co m final String methodPrefix = prefixInfo.prefix.substring(1); System.out.println("method prefix:" + methodPrefix); boolean isPattern = (methodPrefix.contains("*") || methodPrefix.contains("?")); boolean autoAddEndWildcard = isPattern && !methodPrefix.endsWith("*"); SearchPattern pattern = SearchPattern.createPattern(autoAddEndWildcard ? methodPrefix + "*" : methodPrefix, IJavaSearchConstants.METHOD, // | IJavaSearchConstants.FIELD, // IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, isPattern ? SearchPattern.R_PATTERN_MATCH : SearchPattern.R_PREFIX_MATCH); if (pattern != null) { IJavaProject editedFileProject = editor.getAssociatedProject(); if (editedFileProject != null) { IJavaSearchScope scope = SearchEngine .createJavaSearchScope(new IJavaElement[] { editedFileProject }); SearchRequestor requestor = new SearchRequestor() { private int counter; @Override public void beginReporting() { super.beginReporting(); System.out.println("begin reporting"); counter = 0; } @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { counter++; if (counter >= MAX_JAVA_SEARCH_RESULT_NUMBER) { System.out.println("too much results (>" + MAX_JAVA_SEARCH_RESULT_NUMBER + "), throwing exception"); throw new CoreException(Status.OK_STATUS); } proposals.add(new MethodLazyCompletionProposal((IMethod) match.getElement(), methodPrefix, prefixInfo.prefixOffset + 1, null, editor)); } @Override public void endReporting() { super.endReporting(); System.out.println("end reporting : count=" + counter); } }; SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null /* no progress monitor */); assistant.setStatusMessage(MESSAGE_JAVA_COMPLETION); } catch (CoreException e) { if (e.getStatus() != Status.OK_STATUS) { CCWPlugin.logWarning("java code proposal search error in clojure dev", e); } else { errorMessage = ERROR_MESSAGE_TOO_MANY_COMPLETIONS; assistant.setStatusMessage(ERROR_MESSAGE_TOO_MANY_COMPLETIONS); } } } } return proposals; }
From source file:com.siteview.mde.internal.ui.editor.contentassist.TypePackageCompletionProcessor.java
License:Open Source License
protected void generateTypeProposals(String currentContent, IProject project, final Collection c, final int startOffset, final int length, int typeScope) { // Dynamically adjust the search scope depending on the current // state of the project IJavaSearchScope scope = PDEJavaHelper.getSearchScope(project); char[] packageName = null; char[] typeName = null; int index = currentContent.lastIndexOf('.'); if (index == -1) { // There is no package qualification // Perform the search only on the type name typeName = currentContent.toCharArray(); } else if ((index + 1) == currentContent.length()) { // There is a package qualification and the last character is a // dot/* w w w.j a v a 2 s . co m*/ // Perform the search for all types under the given package // Pattern for all types typeName = "".toCharArray(); //$NON-NLS-1$ // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } else { // There is a package qualification, followed by a dot, and // a type fragment // Type name without the package qualification typeName = currentContent.substring(index + 1).toCharArray(); // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } try { TypeNameRequestor req = new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Accept search results from the JDT SearchEngine String cName = new String(simpleTypeName); String pName = new String(packageName); String label = cName + " - " + pName; //$NON-NLS-1$ String content = pName + "." + cName; //$NON-NLS-1$ Image image = (Flags.isInterface(modifiers)) ? MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_INTERFACE) : MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_CLASS); addProposalToCollection(c, startOffset, length, label, content, image); } }; // Note: Do not use the search() method, its performance is // bad compared to the searchAllTypeNames() method fSearchEngine.searchAllTypeNames(packageName, SearchPattern.R_EXACT_MATCH, typeName, SearchPattern.R_PREFIX_MATCH, typeScope, scope, req, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { fErrorMessage = e.getMessage(); } }
From source file:net.harawata.mybatipse.mybatis.ProposalComputorHelper.java
License:Open Source License
public static void searchJavaType(String matchString, IJavaSearchScope scope, TypeNameRequestor requestor) throws JavaModelException { char[] searchPkg = null; char[] searchType = null; if (matchString != null && matchString.length() > 0) { char[] match = matchString.toCharArray(); int lastDotPos = matchString.lastIndexOf('.'); if (lastDotPos == -1) { searchType = match;/*from w w w . j ava2s. co m*/ } else { if (lastDotPos + 1 < match.length) { searchType = CharOperation.lastSegment(match, '.'); } searchPkg = Arrays.copyOfRange(match, 0, lastDotPos); } } SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(searchPkg, SearchPattern.R_PREFIX_MATCH, searchType, SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void searchPackage(String matchString, IJavaSearchScope scope, SearchRequestor requestor) throws CoreException { SearchPattern pattern = SearchPattern.createPattern(matchString + "*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PREFIX_MATCH); SearchEngine searchEngine = new SearchEngine(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null);//from w ww.ja v a 2 s . c om }
From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java
License:Open Source License
private void searchJavaType(String matchString, IJavaSearchScope scope, TypeNameRequestor requestor) throws JavaModelException { char[] searchPkg = null; char[] searchType = null; if (matchString != null && matchString.length() > 0) { char[] match = matchString.toCharArray(); int lastDotPos = matchString.lastIndexOf('.'); if (lastDotPos == -1) { searchType = match;/*from w ww. j a v a 2 s . co m*/ } else { if (lastDotPos + 1 < match.length) { searchType = CharOperation.lastSegment(match, '.'); } searchPkg = Arrays.copyOfRange(match, 0, lastDotPos); } } SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(searchPkg, SearchPattern.R_PREFIX_MATCH, searchType, SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); }
From source file:org.eclipse.bpmn2.modeler.core.utils.JavaProjectClassLoader.java
License:Open Source License
public void findClasses(String classNamePattern, final List<IType> results) { SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine .createJavaSearchScope((IJavaElement[]) new IJavaProject[] { javaProject }); char[] packageName = null; char[] typeName = null; int index = classNamePattern.lastIndexOf('.'); int packageMatch = SearchPattern.R_EXACT_MATCH; int typeMatch = SearchPattern.R_PREFIX_MATCH; if (index == -1) { // There is no package qualification // Perform the search only on the type name typeName = classNamePattern.toCharArray(); } else if ((index + 1) == classNamePattern.length()) { // There is a package qualification and the last character is a // dot/*w w w . j a v a 2s .co m*/ // Perform the search for all types under the given package // Pattern for all types typeName = "".toCharArray(); //$NON-NLS-1$ // Package name without the trailing dot packageName = classNamePattern.substring(0, index).toCharArray(); } else { // There is a package qualification, followed by a dot, and // a type fragment // Type name without the package qualification typeName = classNamePattern.substring(index + 1).toCharArray(); // Package name without the trailing dot packageName = classNamePattern.substring(0, index).toCharArray(); } try { TypeNameMatchRequestor req = new TypeNameMatchRequestor() { public void acceptTypeNameMatch(TypeNameMatch match) { results.add(match.getType()); } }; // Note: Do not use the search() method, its performance is // bad compared to the searchAllTypeNames() method searchEngine.searchAllTypeNames(packageName, packageMatch, typeName, typeMatch, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, req, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { } }