List of usage examples for org.eclipse.jdt.core.search TypeNameMatchRequestor TypeNameMatchRequestor
TypeNameMatchRequestor
From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java
License:Open Source License
public List<TypeNameMatch> searchRawClassInfo(String className) throws JavaModelException { final List<TypeNameMatch> results = new ArrayList<TypeNameMatch>(); TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override//from w w w . ja v a2s. com public void acceptTypeNameMatch(TypeNameMatch match) { results.add(match); } }; new SearchEngine().searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, className.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return results; }
From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java
License:Open Source License
public List<TypeNameMatch> searchRawClassesInfo(String... classNames) throws JavaModelException { // name// w w w .j a v a 2s.c o m char[][] charClassNames = new char[classNames.length][]; for (int i = 0; i < charClassNames.length; i++) charClassNames[i] = classNames[i].toCharArray(); // requestor final List<TypeNameMatch> results = new ArrayList<TypeNameMatch>(); TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { results.add(match); } }; new SearchEngine().searchAllTypeNames(null, charClassNames, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return results; }
From source file:com.technophobia.substeps.junit.action.OpenEditorAction.java
License:Open Source License
protected final IType findType(final IJavaProject project, final String testClassName) { final IType[] result = { null }; final String dottedName = testClassName.replace('$', '.'); // for nested // classes... try {/*from ww w . j av a 2 s. c om*/ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (project != null) { result[0] = internalFindType(project, dottedName, new HashSet<IJavaProject>(), monitor); } if (result[0] == null) { final int lastDot = dottedName.lastIndexOf('.'); final TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(final TypeNameMatch match) { result[0] = match.getType(); } }; new SearchEngine().searchAllTypeNames( lastDot >= 0 ? dottedName.substring(0, lastDot).toCharArray() : null, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, (lastDot >= 0 ? dottedName.substring(lastDot + 1) : dottedName).toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } } catch (final JavaModelException e) { throw new InvocationTargetException(e); } } }); } catch (final InvocationTargetException e) { FeatureRunnerPlugin.log(e); } catch (final InterruptedException e) { // user cancelled } return result[0]; }
From source file:de.jcup.egradle.eclipse.gradleeditor.jdt.JDTDataAccess.java
License:Apache License
/** * Find type//from www.j av a2 s . co m * * @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:org.autorefactor.refactoring.rules.ReplaceQualifiedNamesBySimpleNamesRefactoring.java
License:Open Source License
private void importTypesFromPackage(final String pkgName, ASTNode node) { final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() { @Override/*from w w w . j av a2 s . c o m*/ 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 w w .ja v a 2 s.c o m*/ 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.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//ww w. ja v a2 s . c o 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) { } }
From source file:org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils.java
License:Open Source License
private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope) throws JavaModelException { List<IType> result = new ArrayList<>(); SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(packages, names, scope, new TypeNameMatchRequestor() { @Override//from w w w .j ava 2 s.co m public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { result.add(typeNameMatch.getType()); } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); return result; }
From source file:org.eclipse.gemoc.execution.concurrent.ccsljavaxdsml.ui.builder.GemocLanguageDesignerBuilder.java
License:Open Source License
private static IType findAnyTypeInWorkspace(char[][] qualifications, char[][] typeNames) throws JavaModelException { class ResultException extends RuntimeException { private static final long serialVersionUID = 1L; private final IType fType; public ResultException(IType type) { fType = type;/* ww w . j av a 2 s .co m*/ } } TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { throw new ResultException(match.getType()); } }; try { new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(), requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (ResultException e) { return e.fType; } return null; }
From source file:org.eclipse.mat.jdt.OpenSourceFileJob.java
License:Open Source License
private void collectMatches(IProgressMonitor monitor) throws JavaModelException { matches = new ArrayList<IType>(); new SearchEngine().searchAllTypeNames(packageName != null ? packageName.toCharArray() : null, // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // typeName.toCharArray(), // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // IJavaSearchConstants.TYPE, // SearchEngine.createWorkspaceScope(), // new TypeNameMatchRequestor() { @Override//from w w w.jav a2s .co m public void acceptTypeNameMatch(TypeNameMatch match) { try { IType type = match.getType(); type = resolveInnerTypes(type); matches.add(type); } catch (JavaModelException e) { throw new RuntimeException(e); } } }, // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, // monitor); }