Java 类org.eclipse.jdt.core.search.SearchPattern 实例源码

项目:gemoc-studio-modeldebugging    文件:PlainK3ExecutionEngine.java   
/**
 * search the bundle that contains the Main class. The search is done in the
 * workspace scope (ie. if it is defined in the current workspace it will
 * find it
 * 
 * @return the name of the bundle containing the Main class or null if not
 *         found
 */
private IType getITypeMainByWorkspaceScope(String className) {
    SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

    final List<IType> binaryType = new ArrayList<IType>();

    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            binaryType.add((IType) match.getElement());
        }
    };
    SearchEngine engine = new SearchEngine();

    try {
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                requestor, null);
    } catch (CoreException e1) {
        throw new RuntimeException("Error while searching the bundle: " + e1.getMessage());
        // return new Status(IStatus.ERROR, Activator.PLUGIN_ID, );
    }

    return binaryType.isEmpty() ? null : binaryType.get(0);
}
项目:egradle    文件:JDTDataAccess.java   
/**
 * Find type
 * 
 * @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) {
        EditorUtil.INSTANCE.logError("Was not able to search all type names",e);
    }
    return result[0];
}
项目:google-cloud-eclipse    文件:WebXmlValidator.java   
/**
 * Searches for a class that matches a pattern.
 */
@VisibleForTesting
static boolean performSearch(SearchPattern pattern, IJavaSearchScope scope,
    IProgressMonitor monitor) {
  try {
    SearchEngine searchEngine = new SearchEngine();
    TypeSearchRequestor requestor = new TypeSearchRequestor();
    searchEngine.search(pattern,
        new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
        scope, requestor, monitor);
    return requestor.foundMatch();
  } catch (CoreException ex) {
    logger.log(Level.SEVERE, ex.getMessage());
    return false;
  }
}
项目:eclipse.jdt.ls    文件:RippleMethodFinder.java   
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
    fDeclarations = new ArrayList<>();

    class MethodRequestor extends SearchRequestor {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IMethod method = (IMethod) match.getElement();
            boolean isBinary = method.isBinary();
            if (!isBinary) {
                fDeclarations.add(method);
            }
        }
    }

    int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
    int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
    MethodRequestor requestor = new MethodRequestor();
    SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

    searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
项目:eclipse.jdt.ls    文件:RenameProcessor.java   
protected SearchPattern createOccurrenceSearchPattern(IJavaElement[] elements) throws CoreException {
    if (elements == null || elements.length == 0) {
        return null;
    }
    Set<IJavaElement> set = new HashSet<>(Arrays.asList(elements));
    Iterator<IJavaElement> iter = set.iterator();
    IJavaElement first = iter.next();
    SearchPattern pattern = SearchPattern.createPattern(first, IJavaSearchConstants.ALL_OCCURRENCES);
    if (pattern == null) {
        throw new CoreException(Status.CANCEL_STATUS);
    }
    while (iter.hasNext()) {
        IJavaElement each = iter.next();
        SearchPattern nextPattern = SearchPattern.createPattern(each, IJavaSearchConstants.ALL_OCCURRENCES);
        if (nextPattern == null) {
            throw new CoreException(Status.CANCEL_STATUS);
        }
        pattern = SearchPattern.createOrPattern(pattern, nextPattern);
    }
    return pattern;
}
项目:eclipse.jdt.ls    文件:ClassFileUtil.java   
public static String getURI(IProject project, String fqcn) throws JavaModelException {
    Assert.isNotNull(project, "Project can't be null");
    Assert.isNotNull(fqcn, "FQCN can't be null");

    IJavaProject javaProject = JavaCore.create(project);
    int lastDot = fqcn.lastIndexOf(".");
    String packageName = lastDot > 0? fqcn.substring(0, lastDot):"";
    String className = lastDot > 0? fqcn.substring(lastDot+1):fqcn;
    ClassUriExtractor extractor = new ClassUriExtractor();
    new SearchEngine().searchAllTypeNames(packageName.toCharArray(),SearchPattern.R_EXACT_MATCH,
            className.toCharArray(), SearchPattern.R_EXACT_MATCH,
            IJavaSearchConstants.TYPE,
            JDTUtils.createSearchScope(javaProject),
            extractor,
            IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
            new NullProgressMonitor());
    return extractor.uri;
}
项目:mesfavoris    文件:JavaTypeMemberBookmarkLocationProvider.java   
private List<IType> searchType(String classFQN, IProgressMonitor monitor) {
    classFQN = classFQN.replace('$', '.');
    final List<IType> types = new ArrayList<IType>();

    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    SearchEngine engine = new SearchEngine();
    SearchPattern pattern = SearchPattern.createPattern(classFQN, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

    SearchRequestor requestor = new SearchRequestor() {
        public void acceptSearchMatch(final SearchMatch match) throws CoreException {
            TypeDeclarationMatch typeMatch = (TypeDeclarationMatch) match;
            IType type = (IType) typeMatch.getElement();
            types.add(type);
        }
    };
    try {
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                requestor, monitor);
    } catch (final CoreException e) {
        return types;
    }

    return types;
}
项目:VRaptorEclipsePlugin    文件:SearchHelper.java   
private static List<Controller> search(IJavaProject project, SearchPattern namePattern) throws JavaModelException, CoreException {
    List<Controller> controllers = new ArrayList<Controller>();

    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(project.getPackageFragments());

    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            if (match.getElement() instanceof IJavaElement) {
                IJavaElement element = (IJavaElement) match.getElement();
                controllers.add(new Controller((IType) element));
            }
        }

    };

    SearchEngine searchEngine = new SearchEngine();
    searchEngine.search(namePattern, new SearchParticipant[] {SearchEngine
                    .getDefaultSearchParticipant()}, scope, requestor,
                    null);

    return controllers;
}
项目:che    文件:RenameMethodProcessor.java   
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()]);
}
项目:che    文件:RenameMethodProcessor.java   
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()]);
}
项目:che    文件:RefactoringSearchEngine2.java   
/**
 * 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);
}
项目:che    文件:InlineConstantRefactoring.java   
private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status)
    throws JavaModelException {
  final RefactoringSearchEngine2 engine =
      new RefactoringSearchEngine2(
          SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES));
  engine.setFiltering(true, true);
  engine.setScope(RefactoringScopeFactory.create(fField));
  engine.setStatus(status);
  engine.setRequestor(
      new IRefactoringSearchRequestor() {
        public SearchMatch acceptSearchMatch(SearchMatch match) {
          return match.isInsideDocComment() ? null : match;
        }
      });
  engine.searchPattern(new SubProgressMonitor(pm, 1));
  return (SearchResultGroup[]) engine.getResults();
}
项目:che    文件:IntroduceFactoryRefactoring.java   
/**
 * @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);
  }
}
项目:che    文件:MoveCuUpdateCreator.java   
private static SearchResultGroup[] getReferences(
    ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
  final SearchPattern pattern =
      RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES);
  if (pattern != null) {
    String binaryRefsDescription =
        Messages.format(
            RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description,
            BasicElementLabels.getFileName(unit));
    ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
    Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs);
    IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false);

    SearchResultGroup[] result =
        RefactoringSearchEngine.search(
            pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
    binaryRefs.addErrorIfNecessary(status);
    return result;
  }
  return new SearchResultGroup[] {};
}
项目:che    文件:RefactoringSearchEngine.java   
public static SearchResultGroup[] search(
    SearchPattern pattern,
    WorkingCopyOwner owner,
    IJavaSearchScope scope,
    CollectingSearchRequestor requestor,
    IProgressMonitor monitor,
    RefactoringStatus status)
    throws JavaModelException {
  return internalSearch(
      owner != null ? new SearchEngine(owner) : new SearchEngine(),
      pattern,
      scope,
      requestor,
      monitor,
      status);
}
项目:che    文件:RefactoringSearchEngine.java   
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);
}
项目:datahierarchy    文件:SearchHelper.java   
/**
 * Blocks current thread until search is done
 */
public List<IJavaElement> getReferences(IProgressMonitor monitor) throws CoreException {

    pattern = SearchPattern.createPattern(searchRoot.getJavaElement(),
            IJavaSearchConstants.REFERENCES
                    | ~IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
            // | IJavaSearchConstants.IGNORE_DECLARING_TYPE,
            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE
                    | SearchPattern.R_ERASURE_MATCH);

    if (pattern == null) {
        // this is packages???
        // System.out.println("Search patter is null for: " + elt.getElementName());
        return new ArrayList<IJavaElement>();
    }

    scope = conf.createScope(searchRoot.getJavaElement());
    JavaReferencesRequestor searchRequestor = new JavaReferencesRequestor();

    return search(searchRequestor, monitor);
}
项目:datahierarchy    文件:SearchHelper.java   
private static SearchPattern createAnyFieldPattern(IType[] types) {
    if (types.length == 0) {
        return createAnyFieldPattern();
    }
    SearchPattern result = null;
    for (IType type : types) {
        SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName()
                + ".*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
        if(result == null){
            result = searchPattern;
        } else {
            result = SearchPattern.createOrPattern(result, searchPattern);
        }
    }
    return result;
}
项目:ModelDebugging    文件:PlainK3ExecutionEngine.java   
/**
 * search the bundle that contains the Main class. The search is done in the
 * workspace scope (ie. if it is defined in the current workspace it will
 * find it
 * 
 * @return the name of the bundle containing the Main class or null if not
 *         found
 */
private IType getITypeMainByWorkspaceScope(String className) {
    SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

    final List<IType> binaryType = new ArrayList<IType>();

    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            binaryType.add((IType) match.getElement());
        }
    };
    SearchEngine engine = new SearchEngine();

    try {
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                requestor, null);
    } catch (CoreException e1) {
        throw new RuntimeException("Error while searching the bundle: " + e1.getMessage());
        // return new Status(IStatus.ERROR, Activator.PLUGIN_ID, );
    }

    return binaryType.isEmpty() ? null : binaryType.get(0);
}
项目:Eclipse-Postfix-Code-Completion    文件:PushDownRefactoringProcessor.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInnerToTopRefactoring.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ConstructorReferenceFinder.java   
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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AddImportsOperation.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInstanceMethodProcessor.java   
/**
 * 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();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenamePackageProcessor.java   
private List<SearchResultGroup> getReferencesToTypesInPackage(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws CoreException {
    pm.beginTask("", 2); //$NON-NLS-1$
    IJavaSearchScope referencedFromNamesakesScope= RefactoringScopeFactory.create(fPackage, true, false);
    IPackageFragment[] namesakePackages= getNamesakePackages(referencedFromNamesakesScope, new SubProgressMonitor(pm, 1));
    if (namesakePackages.length == 0) {
        pm.done();
        return new ArrayList<SearchResultGroup>(0);
    }

    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(namesakePackages);
    IType[] typesToSearch= getTypesInPackage(fPackage);
    if (typesToSearch.length == 0) {
        pm.done();
        return new ArrayList<SearchResultGroup>(0);
    }
    SearchPattern pattern= RefactoringSearchEngine.createOrPattern(typesToSearch, IJavaSearchConstants.REFERENCES);
    CollectingSearchRequestor requestor= new CuCollectingSearchRequestor(binaryRefs);
    SearchResultGroup[] results= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
    pm.done();
    return new ArrayList<SearchResultGroup>(Arrays.asList(results));
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameFieldProcessor.java   
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);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameMethodProcessor.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:RenamePackageProcessor.java   
private List<SearchResultGroup> getReferencesToTypesInPackage(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws CoreException {
    pm.beginTask("", 2); //$NON-NLS-1$
    IJavaSearchScope referencedFromNamesakesScope= RefactoringScopeFactory.create(fPackage, true, false);
    IPackageFragment[] namesakePackages= getNamesakePackages(referencedFromNamesakesScope, new SubProgressMonitor(pm, 1));
    if (namesakePackages.length == 0) {
        pm.done();
        return new ArrayList<SearchResultGroup>(0);
    }

    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(namesakePackages);
    IType[] typesToSearch= getTypesInPackage(fPackage);
    if (typesToSearch.length == 0) {
        pm.done();
        return new ArrayList<SearchResultGroup>(0);
    }
    SearchPattern pattern= RefactoringSearchEngine.createOrPattern(typesToSearch, IJavaSearchConstants.REFERENCES);
    CollectingSearchRequestor requestor= new CuCollectingSearchRequestor(binaryRefs);
    SearchResultGroup[] results= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
    pm.done();
    return new ArrayList<SearchResultGroup>(Arrays.asList(results));
}
项目:Eclipse-Postfix-Code-Completion    文件:RenamePackageProcessor.java   
/**
 * @param scope search scope
 * @param pm mrogress monitor
 * @return all package fragments in <code>scope</code> with same name as <code>fPackage</code>, excluding fPackage
 * @throws CoreException if search failed
 */
private IPackageFragment[] getNamesakePackages(IJavaSearchScope scope, IProgressMonitor pm) throws CoreException {
    SearchPattern pattern= SearchPattern.createPattern(fPackage.getElementName(), IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

    final HashSet<IPackageFragment> packageFragments= new HashSet<IPackageFragment>();
    SearchRequestor requestor= new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match);
            if (enclosingElement instanceof IPackageFragment) {
                IPackageFragment pack= (IPackageFragment) enclosingElement;
                if (! fPackage.equals(pack))
                    packageFragments.add(pack);
            }
        }
    };
    new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);

    return packageFragments.toArray(new IPackageFragment[packageFragments.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:FilteredTypesSelectionDialog.java   
private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException {
    try {
        new SearchEngine().searchAllTypeNames(
                null,
                0,
                // make sure we search a concrete name. This is faster according to Kent
                "_______________".toCharArray(), //$NON-NLS-1$
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
                IJavaSearchConstants.ENUM,
                SearchEngine.createWorkspaceScope(),
                new TypeNameRequestor() {},
                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
                monitor);
    } catch (JavaModelException e) {
        throw new InvocationTargetException(e);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IntroduceFactoryRefactoring.java   
/**
 * @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);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:IntroduceFactoryRefactoring.java   
private IType findNonPrimaryType(String fullyQualifiedName, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    SearchPattern p= SearchPattern.createPattern(fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(p);

    engine.setFiltering(true, true);
    engine.setScope(RefactoringScopeFactory.create(fCtorBinding.getJavaElement().getJavaProject()));
    engine.setStatus(status);
    engine.searchPattern(new SubProgressMonitor(pm, 1));

    SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults();

    if (groups.length != 0) {
        for(int i= 0; i < groups.length; i++) {
            SearchMatch[] matches= groups[i].getSearchResults();
            for(int j= 0; j < matches.length; j++) {
                if (matches[j].getAccuracy() == SearchMatch.A_ACCURATE)
                    return (IType) matches[j].getElement();
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MoveInstanceMethodProcessor.java   
/**
 * 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();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RefactoringSearchEngine.java   
public static SearchPattern createOrPattern(IJavaElement[] elements, int limitTo) {
    if (elements == null || elements.length == 0)
        return null;
    Set<IJavaElement> set= new HashSet<IJavaElement>(Arrays.asList(elements));
    Iterator<IJavaElement> iter= set.iterator();
    IJavaElement first= iter.next();
    SearchPattern pattern= SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    if (pattern == null) // check for bug 90138
        throw new IllegalArgumentException("Invalid java element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
    while(iter.hasNext()){
        IJavaElement each= iter.next();
        SearchPattern nextPattern= SearchPattern.createPattern(each, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
        if (nextPattern == null) // check for bug 90138
            throw new IllegalArgumentException("Invalid java element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
        pattern= SearchPattern.createOrPattern(pattern, nextPattern);
    }
    return pattern;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeContextChecker.java   
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException {
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true);
    IPackageFragment currPackage= contextType.getPackageFragment();
    ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm);

    List<TypeNameMatch> result= new ArrayList<TypeNameMatch>();
    for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) {
        TypeNameMatch curr= iter.next();
        IType type= curr.getType();
        if (type != null) {
            boolean visible=true;
            try {
                visible= JavaModelUtil.isVisible(type, currPackage);
            } catch (JavaModelException e) {
                //Assume visibile if not available
            }
            if (visible) {
                result.add(curr);
            }
        }
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuperTypeRefactoringProcessor.java   
/**
 * 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));
        return (Map<IJavaProject, Set<SearchResultGroup>>) engine.getAffectedProjects();
    } finally {
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaContext.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    new SearchEngine().searchAllTypeNames(null, 0, simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:AddImportsOperation.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameMethodProcessor.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:FilteredTypesSelectionDialog.java   
private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException {
    try {
        new SearchEngine().searchAllTypeNames(
                null,
                0,
                // make sure we search a concrete name. This is faster according to Kent
                "_______________".toCharArray(), //$NON-NLS-1$
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
                IJavaSearchConstants.ENUM,
                SearchEngine.createWorkspaceScope(),
                new TypeNameRequestor() { /* dummy */},
                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
                monitor);
    } catch (JavaModelException e) {
        throw new InvocationTargetException(e);
    }
}