当前位置: 首页>>代码示例>>Java>>正文


Java SearchUtils类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.corext.util.SearchUtils的典型用法代码示例。如果您正苦于以下问题:Java SearchUtils类的具体用法?Java SearchUtils怎么用?Java SearchUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SearchUtils类属于org.eclipse.jdt.internal.corext.util包,在下文中一共展示了SearchUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: searchForOuterTypesOfReferences

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm)
    throws CoreException {
  final Set<IType> outerTypesOfReferences = new HashSet<IType>();
  SearchPattern pattern =
      RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
  IJavaSearchScope scope = createRefactoringScope(getMethod());
  SearchRequestor requestor =
      new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          Object element = match.getElement();
          if (!(element instanceof IMember))
            return; // e.g. an IImportDeclaration for a static method import
          IMember member = (IMember) element;
          IType declaring = member.getDeclaringType();
          if (declaring == null) return;
          IType outer = declaring.getDeclaringType();
          if (outer != null) outerTypesOfReferences.add(declaring);
        }
      };
  new SearchEngine()
      .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameMethodProcessor.java

示例2: searchForDeclarationsOfClashingMethods

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm)
    throws CoreException {
  final List<IMethod> results = new ArrayList<IMethod>();
  SearchPattern pattern = createNewMethodPattern();
  IJavaSearchScope scope = RefactoringScopeFactory.create(getMethod().getJavaProject());
  SearchRequestor requestor =
      new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          Object method = match.getElement();
          if (method
              instanceof
              IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws
            // internal exception
            results.add((IMethod) method);
          else
            JavaPlugin.logErrorMessage(
                "Unexpected element in search match: " + match.toString()); // $NON-NLS-1$
        }
      };
  new SearchEngine()
      .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  return results.toArray(new IMethod[results.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameMethodProcessor.java

示例3: addTypeImports

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>.
 *
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void addTypeImports(SearchResultGroup typeReferences) throws CoreException {
  SearchMatch[] searchResults = typeReferences.getSearchResults();
  for (int i = 0; i < searchResults.length; i++) {
    SearchMatch result = searchResults[i];
    IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
    if (!(enclosingElement instanceof IImportDeclaration)) {
      String reference = getNormalizedTypeReference(result);
      if (!reference.startsWith(fPackage.getElementName())) {
        // is unqualified
        reference = cutOffInnerTypes(reference);
        ImportChange importChange =
            fImportsManager.getImportChange(typeReferences.getCompilationUnit());
        importChange.addImport(fPackage.getElementName() + '.' + reference);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:RenamePackageProcessor.java

示例4: updateTypeImports

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName
 * </code> and remove old import with <code>fPackage</code>.
 *
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException {
  SearchMatch[] searchResults = typeReferences.getSearchResults();
  for (int i = 0; i < searchResults.length; i++) {
    SearchMatch result = searchResults[i];
    IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
    if (enclosingElement instanceof IImportDeclaration) {
      IImportDeclaration importDeclaration = (IImportDeclaration) enclosingElement;
      updateImport(
          typeReferences.getCompilationUnit(),
          importDeclaration,
          getUpdatedImport(importDeclaration));
    } else {
      String reference = getNormalizedTypeReference(result);
      if (!reference.startsWith(fPackage.getElementName())) {
        reference = cutOffInnerTypes(reference);
        ImportChange importChange =
            fImportsManager.getImportChange(typeReferences.getCompilationUnit());
        importChange.removeImport(fPackage.getElementName() + '.' + reference);
        importChange.addImport(getNewPackageName() + '.' + reference);
      } // else: already found & updated with package reference search
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:RenamePackageProcessor.java

示例5: setPattern

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * Sets the search pattern to be used during search.
 *
 * <p>This method must be called before {@link
 * RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param elements the set of elements
 * @param limitTo determines the nature of the expected matches. This is a combination of {@link
 *     org.eclipse.jdt.core.search .IJavaSearchConstants}.
 */
public final void setPattern(final IJavaElement[] elements, final int limitTo) {
  Assert.isNotNull(elements);
  Assert.isTrue(elements.length > 0);
  SearchPattern pattern =
      SearchPattern.createPattern(elements[0], limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  IJavaElement element = null;
  for (int index = 1; index < elements.length; index++) {
    element = elements[index];
    pattern =
        SearchPattern.createOrPattern(
            pattern,
            SearchPattern.createPattern(
                element, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
  }
  setPattern(pattern);
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:RefactoringSearchEngine2.java

示例6: createSearchPattern

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * @param ctor
 * @param methodBinding
 * @return a <code>SearchPattern</code> that finds all calls to the constructor identified by the
 *     argument <code>methodBinding</code>.
 */
private SearchPattern createSearchPattern(IMethod ctor, IMethodBinding methodBinding) {
  Assert.isNotNull(
      methodBinding, RefactoringCoreMessages.IntroduceFactory_noBindingForSelectedConstructor);

  if (ctor != null)
    return SearchPattern.createPattern(
        ctor, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  else { // perhaps a synthetic method? (but apparently not always... hmmm...)
    // Can't find an IMethod for this method, so build a string pattern instead
    StringBuffer buf = new StringBuffer();

    buf.append(methodBinding.getDeclaringClass().getQualifiedName()).append("("); // $NON-NLS-1$
    for (int i = 0; i < fArgTypes.length; i++) {
      if (i != 0) buf.append(","); // $NON-NLS-1$
      buf.append(fArgTypes[i].getQualifiedName());
    }
    buf.append(")"); // $NON-NLS-1$
    return SearchPattern.createPattern(
        buf.toString(),
        IJavaSearchConstants.CONSTRUCTOR,
        IJavaSearchConstants.REFERENCES,
        SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:IntroduceFactoryRefactoring.java

示例7: internalSearch

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private static SearchResultGroup[] internalSearch(
    SearchEngine searchEngine,
    SearchPattern pattern,
    IJavaSearchScope scope,
    CollectingSearchRequestor requestor,
    IProgressMonitor monitor,
    RefactoringStatus status)
    throws JavaModelException {
  try {
    searchEngine.search(
        pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, monitor);
  } catch (CoreException e) {
    throw new JavaModelException(e);
  }
  return groupByCu(requestor.getResults(), status);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:RefactoringSearchEngine.java

示例8: hasNonMovedReferences

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
protected boolean hasNonMovedReferences(final IMember member, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	if (!fCachedMembersReferences.containsKey(member)) {
		final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
		engine.setFiltering(true, true);
		engine.setStatus(status);
		engine.setOwner(fOwner);
		engine.setScope(RefactoringScopeFactory.create(member));
		engine.searchPattern(new SubProgressMonitor(monitor, 1));
		fCachedMembersReferences.put(member, engine.getResults());
	}
	final SearchResultGroup[] groups= (SearchResultGroup[]) fCachedMembersReferences.get(member);
	if (groups.length == 0)
		return false;
	else if (groups.length > 1)
		return true;
	final ICompilationUnit unit= groups[0].getCompilationUnit();
	if (!getDeclaringType().getCompilationUnit().equals(unit))
		return true;
	final SearchMatch[] matches= groups[0].getSearchResults();
	for (int index= 0; index < matches.length; index++) {
		if (!isMovedReference(matches[index]))
			return true;
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:HierarchyProcessor.java

示例9: getReferencingElementsFromSameClass

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private static IJavaElement[] getReferencingElementsFromSameClass(IMember member, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
	Assert.isNotNull(member);
	final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
	engine.setFiltering(true, true);
	engine.setScope(SearchEngine.createJavaSearchScope(new IJavaElement[] { member.getDeclaringType() }));
	engine.setStatus(status);
	engine.searchPattern(new SubProgressMonitor(pm, 1));
	SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults();
	Set<IJavaElement> result= new HashSet<IJavaElement>(3);
	for (int i= 0; i < groups.length; i++) {
		SearchResultGroup group= groups[i];
		SearchMatch[] results= group.getSearchResults();
		for (int j= 0; j < results.length; j++) {
			SearchMatch searchResult= results[j];
			result.add(SearchUtils.getEnclosingJavaElement(searchResult));
		}
	}
	return result.toArray(new IJavaElement[result.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:PushDownRefactoringProcessor.java

示例10: createTypeReferencesMapping

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private Map<ICompilationUnit, SearchMatch[]> createTypeReferencesMapping(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
	final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(fType, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
	engine.setFiltering(true, true);
	engine.setScope(RefactoringScopeFactory.create(fType));
	engine.setStatus(status);
	engine.searchPattern(new SubProgressMonitor(pm, 1));
	final SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults();
	Map<ICompilationUnit, SearchMatch[]> result= new HashMap<ICompilationUnit, SearchMatch[]>();
	for (int i= 0; i < groups.length; i++) {
		SearchResultGroup group= groups[i];
		ICompilationUnit cu= group.getCompilationUnit();
		if (cu == null)
			continue;
		result.put(cu, group.getSearchResults());
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:MoveInnerToTopRefactoring.java

示例11: getImplicitConstructorReferencesInClassCreations

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
	//XXX workaround for jdt core bug 23112
	SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
	SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status);
	List<SearchMatch> result= new ArrayList<SearchMatch>();
	for (int i= 0; i < refs.length; i++) {
		SearchResultGroup group= refs[i];
		ICompilationUnit cu= group.getCompilationUnit();
		if (cu == null)
			continue;
		CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
		SearchMatch[] results= group.getSearchResults();
		for (int j= 0; j < results.length; j++) {
			SearchMatch searchResult= results[j];
			ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode);
			if (isImplicitConstructorReferenceNodeInClassCreations(node))
				result.add(searchResult);
		}
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:ConstructorReferenceFinder.java

示例12: computeMethodReferences

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * Searches for references to the original method.
 *
 * @param monitor
 *            the progress monitor to use
 * @param status
 *            the refactoring status to use
 * @return the array of search result groups
 * @throws CoreException
 *             if an error occurred during search
 */
protected SearchResultGroup[] computeMethodReferences(final IProgressMonitor monitor, final RefactoringStatus status) throws CoreException {
	Assert.isNotNull(monitor);
	Assert.isNotNull(status);
	try {
		monitor.beginTask("", 1); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking);
		SearchPattern pattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
		IJavaSearchScope scope= RefactoringScopeFactory.create(fMethod, true, false);

		String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , BasicElementLabels.getJavaElementName(fMethod.getElementName()));
		ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription);
		CollectingSearchRequestor requestor= new CollectingSearchRequestor(binaryRefs);
		SearchResultGroup[] result= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(monitor, 1), status);
		binaryRefs.addErrorIfNecessary(status);

		return result;
	} finally {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:MoveInstanceMethodProcessor.java

示例13: getReferencingCompilationUnits

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
/**
 * Computes the compilation units referencing the subtype to replace.
 *
 * @param type
 *            the subtype
 * @param monitor
 *            the progress monitor to use
 * @param status
 *            the refactoring status
 * @return the referenced compilation units (element type:
 *         <code>&lt;IJavaProject, Collection&lt;SearchResultGroup&gt;&gt;</code>)
 * @throws JavaModelException
 *             if an error occurs
 */
protected final Map<IJavaProject, Set<SearchResultGroup>> getReferencingCompilationUnits(final IType type, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	try {
		monitor.beginTask("", 100); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.SuperTypeRefactoringProcessor_creating);
		final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2();
		engine.setOwner(fOwner);
		engine.setFiltering(true, true);
		engine.setStatus(status);
		engine.setScope(RefactoringScopeFactory.create(type));
		engine.setPattern(SearchPattern.createPattern(type, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
		engine.searchPattern(new SubProgressMonitor(monitor, 100));
		@SuppressWarnings("unchecked")
		Map<IJavaProject, Set<SearchResultGroup>> result= (Map<IJavaProject, Set<SearchResultGroup>>) engine.getAffectedProjects();
		return result;
	} finally {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:SuperTypeRefactoringProcessor.java

示例14: addAccessorOccurrences

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private void addAccessorOccurrences(IProgressMonitor pm, IMethod accessor, String editName, String newAccessorName, RefactoringStatus status) throws CoreException {
	Assert.isTrue(accessor.exists());

	IJavaSearchScope scope= RefactoringScopeFactory.create(accessor);
	SearchPattern pattern= SearchPattern.createPattern(accessor, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	SearchResultGroup[] groupedResults= RefactoringSearchEngine.search(
		pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);

	for (int i= 0; i < groupedResults.length; i++) {
		ICompilationUnit cu= groupedResults[i].getCompilationUnit();
		if (cu == null)
			continue;
		SearchMatch[] results= groupedResults[i].getSearchResults();
		for (int j= 0; j < results.length; j++){
			SearchMatch searchResult= results[j];
			TextEdit edit= new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
			addTextEdit(fChangeManager.get(cu), editName, edit);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:RenameFieldProcessor.java

示例15: searchForOuterTypesOfReferences

import org.eclipse.jdt.internal.corext.util.SearchUtils; //导入依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
	final Set<IType> outerTypesOfReferences= new HashSet<IType>();
	SearchPattern pattern= RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
	IJavaSearchScope scope= createRefactoringScope(getMethod());
	SearchRequestor requestor= new SearchRequestor() {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			Object element= match.getElement();
			if (!(element instanceof IMember))
				return; // e.g. an IImportDeclaration for a static method import
			IMember member= (IMember) element;
			IType declaring= member.getDeclaringType();
			if (declaring == null)
				return;
			IType outer= declaring.getDeclaringType();
			if (outer != null)
				outerTypesOfReferences.add(declaring);
		}
	};
	new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(),
			scope, requestor, pm);
	return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:RenameMethodProcessor.java


注:本文中的org.eclipse.jdt.internal.corext.util.SearchUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。