List of usage examples for org.eclipse.jdt.core.search SearchEngine searchAllTypeNames
public void searchAllTypeNames(final char[] packageName, final int packageMatchRule, final char[] typeName, final int typeMatchRule, int searchFor, IJavaSearchScope scope, final TypeNameMatchRequestor nameMatchRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException
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 w w w . ja v a 2 s.c o 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 ww w . j a va 2 s .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:de.jcup.egradle.eclipse.gradleeditor.jdt.JDTDataAccess.java
License:Apache License
/** * Find type// www.j a v a 2 s . c om * * @param className * @param monitor * @return type or <code>null</code> */ public IType findType(String className, IProgressMonitor monitor) { final IType[] result = { null }; TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { result[0] = match.getType(); } }; int lastDot = className.lastIndexOf('.'); char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null; char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray(); SearchEngine engine = new SearchEngine(); int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; try { engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { EGradleUtil.log(e); } return result[0]; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void handleFindAll(String proj, String file, int start, int end, boolean defs, boolean refs, boolean impls, boolean equiv, boolean exact, boolean system, boolean typeof, boolean ronly, boolean wonly, IvyXmlWriter xw) throws BedrockException { IJavaProject ijp = getJavaProject(proj); IPath fp = new Path(file); int limit = 0; if (defs && refs) limit = IJavaSearchConstants.ALL_OCCURRENCES; else if (defs) limit = IJavaSearchConstants.DECLARATIONS; else if (refs) limit = IJavaSearchConstants.REFERENCES; int flimit = limit; if (ronly)/*from w w w. jav a 2 s . co m*/ flimit = IJavaSearchConstants.READ_ACCESSES; else if (wonly) flimit = IJavaSearchConstants.WRITE_ACCESSES; int mrule = -1; if (equiv) mrule = SearchPattern.R_EQUIVALENT_MATCH; else if (exact) mrule = SearchPattern.R_EXACT_MATCH; SearchPattern pat = null; IJavaSearchScope scp = null; ICompilationUnit icu = our_plugin.getProjectManager().getCompilationUnit(proj, file); if (icu == null) throw new BedrockException("Compilation unit not found for " + fp); icu = getCompilationElement(icu); ICompilationUnit[] working = null; FindFilter filter = null; IJavaElement cls = null; char[] packagename = null; char[] typename = null; try { BedrockPlugin.logD("Getting search scopes"); IJavaElement[] pelt; if (ijp != null) pelt = new IJavaElement[] { ijp }; else pelt = getAllProjects(); working = getWorkingElements(pelt); int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; if (system) fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES; scp = SearchEngine.createJavaSearchScope(pelt, fg); BedrockPlugin.logD("Locating item to search for"); IJavaElement[] elts = icu.codeSelect(start, end - start); if (typeof) { Set<IJavaElement> nelt = new LinkedHashSet<IJavaElement>(); for (int i = 0; i < elts.length; ++i) { IType typ = null; String tnm = null; switch (elts[i].getElementType()) { case IJavaElement.FIELD: tnm = ((IField) elts[i]).getTypeSignature(); break; case IJavaElement.LOCAL_VARIABLE: tnm = ((ILocalVariable) elts[i]).getTypeSignature(); break; case IJavaElement.METHOD: typ = ((IMethod) elts[i]).getDeclaringType(); break; default: nelt.add(elts[i]); break; } if (typ != null) nelt.add(typ); else if (tnm != null && ijp != null) { IJavaElement elt = ijp.findElement(tnm, null); if (elt != null) { nelt.add(elt); typ = null; } else { while (tnm.startsWith("[")) { String xtnm = tnm.substring(1); if (xtnm == null) break; tnm = xtnm; } int ln = tnm.length(); String xtnm = tnm; if (tnm.startsWith("L") && tnm.endsWith(";")) { xtnm = tnm.substring(1, ln - 1); } else if (tnm.startsWith("Q") && tnm.endsWith(";")) { xtnm = tnm.substring(1, ln - 1); } if (xtnm != null) tnm = xtnm; int idx1 = tnm.lastIndexOf("."); if (idx1 > 0) { String pkgnm = tnm.substring(0, idx1); xtnm = tnm.substring(idx1 + 1); if (xtnm != null) tnm = xtnm; pkgnm = pkgnm.replace('$', '.'); packagename = pkgnm.toCharArray(); } tnm = tnm.replace('$', '.'); typename = tnm.toCharArray(); } if (typename != null) { BedrockPlugin.logD("Handling type names"); FindTypeHandler fth = new FindTypeHandler(ijp); SearchEngine se = new SearchEngine(working); se.searchAllTypeNames(packagename, SearchPattern.R_EXACT_MATCH, typename, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scp, fth, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); nelt.addAll(fth.getFoundItems()); } } } IJavaElement[] nelts = new IJavaElement[nelt.size()]; elts = nelt.toArray(nelts); } if (elts.length == 1 && !typeof) { xw.begin("SEARCHFOR"); switch (elts[0].getElementType()) { case IJavaElement.FIELD: xw.field("TYPE", "Field"); break; case IJavaElement.LOCAL_VARIABLE: xw.field("TYPE", "Local"); break; case IJavaElement.METHOD: xw.field("TYPE", "Function"); break; case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: xw.field("TYPE", "Class"); cls = elts[0]; break; } xw.text(elts[0].getElementName()); xw.end("SEARCHFOR"); } int etyp = -1; for (int i = 0; i < elts.length; ++i) { SearchPattern sp; int xlimit = limit; switch (elts[i].getElementType()) { case IJavaElement.FIELD: case IJavaElement.LOCAL_VARIABLE: xlimit = flimit; break; case IJavaElement.TYPE: if (impls) xlimit = IJavaSearchConstants.IMPLEMENTORS; break; case IJavaElement.METHOD: if (impls) xlimit |= IJavaSearchConstants.IGNORE_DECLARING_TYPE; break; } if (mrule < 0) sp = SearchPattern.createPattern(elts[i], xlimit); else sp = SearchPattern.createPattern(elts[i], xlimit, mrule); if (pat == null) pat = sp; else pat = SearchPattern.createOrPattern(pat, sp); if (etyp < 0) etyp = elts[i].getElementType(); } if (etyp == IJavaElement.METHOD) { if (impls) { if (defs) filter = new ImplementFilter(elts); } else if (defs && !refs) filter = new ClassFilter(elts); } } catch (JavaModelException e) { BedrockPlugin.logE("SEARCH PROBLEM: " + e); e.printStackTrace(); throw new BedrockException("Can't find anything to search for", e); } if (pat == null) { BedrockPlugin.logW("Nothing to search for"); return; } BedrockPlugin.logD("Setting up search"); SearchEngine se = new SearchEngine(working); SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; FindHandler fh = new FindHandler(xw, filter, false); BedrockPlugin.logD( "BEGIN SEARCH " + pat + " " + parts.length + " " + " " + scp + " :: COPIES: " + working.length); try { se.search(pat, parts, scp, fh, null); } catch (Throwable e) { throw new BedrockException("Problem doing find all search for " + pat + ": " + e, e); } if (cls != null && defs) { // need to add the actual class definition BedrockUtil.outputJavaElement(cls, false, xw); } }
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. ja va 2 s. com*/ } 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.TypeAliasCache.java
License:Open Source License
private void collectTypesInPackages(final IJavaProject project, Set<String> packages, final TypeAliasMap aliasMap, Set<String> superTypes, IReporter reporter) { final Set<IType> superTypeSet = new HashSet<IType>(); try {//from w ww . j av a2 s . co m for (String supType : superTypes) { superTypeSet.add(project.findType(supType)); } } catch (JavaModelException e) { Activator.log(Status.ERROR, e.getMessage(), e); } int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, includeMask); TypeNameRequestor requestor = new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Ignore abstract classes. if (Flags.isAbstract(modifiers)) return; String qualifiedName = NameUtil.buildQualifiedName(packageName, simpleTypeName, enclosingTypeNames, false); try { IType foundType = project.findType(qualifiedName); if (superTypeSet.isEmpty() || isSuperTypeMatched(foundType, superTypeSet)) { String alias = getAliasAnnotationValue(foundType); if (alias == null) { alias = new String(simpleTypeName); } aliasMap.put(alias, qualifiedName); } } catch (JavaModelException e) { Activator.log(Status.WARNING, "Error occurred while searching type alias.", e); } } private boolean isSuperTypeMatched(IType foundType, Set<IType> superTypeSet) throws JavaModelException { for (IType superType : superTypeSet) { if (isAssignable(foundType, superType)) { return true; } } return false; } }; SearchEngine searchEngine = new SearchEngine(); for (String pkg : packages) { if (reporter != null && reporter.isCancelled()) { throw new OperationCanceledException(); } try { searchEngine.searchAllTypeNames(pkg.toCharArray(), SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (JavaModelException e) { Activator.log(Status.ERROR, e.getMessage(), e); } } }
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;// ww w. j a va2 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.autorefactor.refactoring.rules.ReplaceQualifiedNamesBySimpleNamesRefactoring.java
License:Open Source License
private void importTypesFromPackage(final String pkgName, ASTNode node) { final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() { @Override/*w w w .java 2s .com*/ public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { final boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null; if (isTopLevelType) { if (!pkgName.equals(typeNameMatch.getPackageName())) { // sanity check failed throw new IllegalStateException("Expected package '" + typeNameMatch.getPackageName() + "' to be equal to '" + pkgName + "'"); } QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName()); types.addName(FQN.fromImport(qname, true)); } } }; SubMonitor monitor = SubMonitor.convert(ctx.getProgressMonitor(), 1); final SubMonitor childMonitor = monitor.newChild(1); try { final SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(pkgName.toCharArray(), R_EXACT_MATCH, // search in this package null, R_EXACT_MATCH, // do not filter by type name TYPE, // look for all java types (class, interfaces, enums, etc.) createWorkspaceScope(), // search everywhere importTypeCollector, WAIT_UNTIL_READY_TO_SEARCH, // wait in case the indexer is indexing childMonitor); } catch (JavaModelException e) { throw new UnhandledException(node, e); } finally { childMonitor.done(); } }
From source file:org.autorefactor.refactoring.rules.SimpleNameRatherThanQualifiedNameRefactoring.java
License:Open Source License
private void importTypesFromPackage(final String pkgName, ASTNode node) { final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() { @Override/*from w ww .j a va 2 s .com*/ public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { final boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null; if (isTopLevelType) { if (!pkgName.equals(typeNameMatch.getPackageName())) { // sanity check failed throw new IllegalStateException("Expected package '" + typeNameMatch.getPackageName() + "' to be equal to '" + pkgName + "'"); } QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName()); types.addName(FQN.fromImport(qname, true)); } } }; try { final SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(pkgName.toCharArray(), R_EXACT_MATCH, // search in this package null, R_EXACT_MATCH, // do not filter by type name TYPE, // look for all java types (class, interfaces, enums, etc.) createWorkspaceScope(), // search everywhere importTypeCollector, WAIT_UNTIL_READY_TO_SEARCH, // wait in case the indexer is indexing ctx.getProgressMonitor()); } catch (JavaModelException e) { throw new UnhandledException(node, e); } }
From source file:org.codehaus.groovy.eclipse.codebrowsing.tests.BrowsingTestCase.java
License:Open Source License
public static void waitUntilIndexesReady() { // dummy query for waiting until the indexes are ready SearchEngine engine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); try {/*from w ww. ja va 2 s. com*/ engine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { } }