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

项目: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    文件: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;
}
项目:cft    文件:JavaTypeResolver.java   
public IType[] getMainTypes(IProgressMonitor monitor) {
    IJavaProject javaProject = getJavaProject();

    if (javaProject != null) {
        // Returns main method types
        boolean includeSubtypes = true;
        MainMethodSearchEngine engine = new MainMethodSearchEngine();
        int constraints = IJavaSearchScope.SOURCES;
        constraints |= IJavaSearchScope.APPLICATION_LIBRARIES;
        IJavaSearchScope scope = SearchEngine.createJavaSearchScope(
                new IJavaElement[] { javaProject }, constraints);
        return engine.searchMainMethods(monitor, scope, includeSubtypes);
    }
    return new IType[] {};

}
项目: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    文件:MoveCuUpdateCreator.java   
private TypeReference(
    IJavaElement enclosingElement,
    int accuracy,
    int start,
    int length,
    boolean insideDocComment,
    IResource resource,
    int simpleNameStart,
    String simpleName) {
  super(
      enclosingElement,
      accuracy,
      start,
      length,
      insideDocComment,
      SearchEngine.getDefaultSearchParticipant(),
      resource);
  fSimpleNameStart = simpleNameStart;
  fSimpleTypeName = simpleName;
}
项目:che    文件:RefactoringScopeFactory.java   
/**
 * Creates a new search scope with all compilation units possibly referencing <code>javaElement
 * </code>.
 *
 * @param javaElement the java element
 * @param considerVisibility consider visibility of javaElement iff <code>true</code>
 * @param sourceReferencesOnly consider references in source only (no references in binary)
 * @return the search scope
 * @throws JavaModelException if an error occurs
 */
public static IJavaSearchScope create(
    IJavaElement javaElement, boolean considerVisibility, boolean sourceReferencesOnly)
    throws JavaModelException {
  if (considerVisibility & javaElement instanceof IMember) {
    IMember member = (IMember) javaElement;
    if (JdtFlags.isPrivate(member)) {
      if (member.getCompilationUnit() != null)
        return SearchEngine.createJavaSearchScope(
            new IJavaElement[] {member.getCompilationUnit()});
      else return SearchEngine.createJavaSearchScope(new IJavaElement[] {member});
    }
    // Removed code that does some optimizations regarding package visible members. The problem is
    // that
    // there can be a package fragment with the same name in a different source folder or project.
    // So we
    // have to treat package visible members like public or protected members.
  }

  IJavaProject javaProject = javaElement.getJavaProject();
  return SearchEngine.createJavaSearchScope(
      getAllScopeElements(javaProject, sourceReferencesOnly), false);
}
项目: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);
}
项目:che    文件:IndexManager.java   
public void cleanUpIndexes() {
  SimpleSet knownPaths = new SimpleSet();
  IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope();
  PatternSearchJob job =
      new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null);
  Index[] selectedIndexes = job.getIndexes(null);
  for (int i = 0, l = selectedIndexes.length; i < l; i++) {
    IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation();
    knownPaths.add(IndexLocation);
  }

  if (this.indexStates != null) {
    Object[] keys = this.indexStates.keyTable;
    IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize];
    int count = 0;
    for (int i = 0, l = keys.length; i < l; i++) {
      IndexLocation key = (IndexLocation) keys[i];
      if (key != null && !knownPaths.includes(key)) locations[count++] = key;
    }
    if (count > 0) removeIndexesState(locations);
  }
  deleteIndexFiles(knownPaths);
}
项目:che    文件:JavaDebuggerUtils.java   
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
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
          result.add(typeNameMatch.getType());
        }
      },
      IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
      new NullProgressMonitor());
  return result;
}
项目:datahierarchy    文件:SearchHelper.java   
/**
 * Blocks current thread until search is done
 */
public List<IField> getReferencedFields(IProgressMonitor monitor) throws CoreException {

    boolean searchOnlyStatics = conf.get(ISearchConfiguration.SEARCH_STATICS_ONLY);
    searchOnlyStatics = searchOnlyStatics && searchRoot.isVisibleRoot();
    FieldReferencesRequestor searchRequestor = SearchUtils.createFieldRequestor(conf,
            searchOnlyStatics);

    IType[] typesForAllElements = SearchUtils.getAlSuperTypesForAllElements(
            searchRoot, monitor);
    IJavaElement javaElement = searchRoot.getJavaElement();
    if(typesForAllElements.length == 0
            || javaElement instanceof IPackageFragmentRoot
            || javaElement instanceof IPackageFragment){
        pattern = SearchHelper.createAnyFieldPattern();
        scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{javaElement}, IJavaSearchScope.SOURCES);
    } else {
        pattern = SearchHelper.createAnyFieldPattern(typesForAllElements);
        scope = SearchEngine.createJavaSearchScope(typesForAllElements, IJavaSearchScope.SOURCES);
    }

    return search(searchRequestor, monitor);
}
项目:gwt-eclipse-plugin    文件:ClientBundleResourceDialog.java   
private IType chooseResourceType() {
  IJavaSearchScope scope;
  try {
    scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findResourcePrototypeType(javaProject));
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
        getShell(), false, PlatformUI.getWorkbench().getProgressService(),
        scope, IJavaSearchConstants.INTERFACE);
    dialog.setTitle("Resource Type Selection");
    dialog.setMessage("Choose a resource type:");

    if (dialog.open() == Window.OK) {
      return (IType) dialog.getFirstResult();
    }
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
项目:gwt-eclipse-plugin    文件:AddResourcesToClientBundleDialog.java   
private IType chooseClientBundleType() {
  try {
    // Create a search scope for finding ClientBundle subtypes
    IJavaSearchScope scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findClientBundleType(getJavaProject()));

    // Configure the type selection dialog
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
        getShell(), false, PlatformUI.getWorkbench().getProgressService(),
        scope, IJavaSearchConstants.INTERFACE);
    dialog.setTitle("ClientBundle Type Selection");
    dialog.setMessage("Choose a type:");

    if (dialog.open() == Window.OK) {
      return (IType) dialog.getFirstResult();
    }
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
项目: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);
}
项目:XRobot    文件:MainMethodSearchHelper.java   
public void searchMainMethods(IProgressMonitor pm, IJavaSearchScope scope, Collection<IType> dst) throws CoreException
{
    pm.beginTask("Searching for main methods...", 100);
    try
    {
        SearchPattern pattern = SearchPattern.createPattern("main(String[]) void",
                IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); //$NON-NLS-1$
        SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
        IProgressMonitor searchMonitor = new SubProgressMonitor(pm, 100);
        ResultAggregator collector = new ResultAggregator(dst);
        new SearchEngine().search(pattern, participants, scope, collector, searchMonitor);
    }
    finally
    {
        pm.done();
    }
}
项目: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-Juno38    文件:GenerateToStringDialog.java   
private void browseForBuilderClass() {
    try {
        IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { getType().getJavaProject() });
        SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), PlatformUI.getWorkbench().getProgressService(), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false, "*ToString", fExtension); //$NON-NLS-1$
        dialog.setTitle(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_windowTitle);
        dialog.setMessage(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_message);
        dialog.open();
        if (dialog.getReturnCode() == OK) {
            IType type= (IType)dialog.getResult()[0];
            fBuilderClassName.setText(type.getFullyQualifiedParameterizedName());
            List<String> suggestions= fValidator.getAppendMethodSuggestions(type);
            if (!suggestions.contains(fAppendMethodName.getText()))
                fAppendMethodName.setText(suggestions.get(0));
            suggestions= fValidator.getResultMethodSuggestions(type);
            if (!suggestions.contains(fResultMethodName.getText()))
                fResultMethodName.setText(suggestions.get(0));
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
}
项目: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    文件: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-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    文件: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    文件: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    文件: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    文件:IntroduceIndirectionInputPage.java   
private IType chooseIntermediaryType() {
    IJavaProject proj= getIntroduceIndirectionRefactoring().getProject();

    if (proj == null)
        return null;

    IJavaElement[] elements= new IJavaElement[] { proj };
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);

    int elementKinds= JavaModelUtil.is18OrHigher(proj) ? IJavaSearchConstants.CLASS_AND_INTERFACE : IJavaSearchConstants.CLASS;
    FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false, getWizard().getContainer(), scope, elementKinds);

    dialog.setTitle(RefactoringMessages.IntroduceIndirectionInputPage_dialog_choose_declaring_class);
    dialog.setMessage(RefactoringMessages.IntroduceIndirectionInputPage_dialog_choose_declaring_class_long);

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:IntroduceFactoryInputPage.java   
private IType chooseFactoryClass() {
    IJavaProject    proj= getUseFactoryRefactoring().getProject();

    if (proj == null)
        return null;

    IJavaElement[] elements= new IJavaElement[] { proj };
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);

    FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(
        getShell(), false, getWizard().getContainer(), scope, IJavaSearchConstants.CLASS);

    dialog.setTitle(RefactoringMessages.IntroduceFactoryInputPage_chooseFactoryClass_title);
    dialog.setMessage(RefactoringMessages.IntroduceFactoryInputPage_chooseFactoryClass_message);

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoFilter.java   
public TypeInfoFilter(String text, IJavaSearchScope scope, int elementKind, ITypeInfoFilterExtension extension) {
    fText= text;
    fSearchScope= scope;
    fIsWorkspaceScope= fSearchScope.equals(SearchEngine.createWorkspaceScope());
    fElementKind= elementKind;
    fFilterExtension= extension;

    int index= text.lastIndexOf("."); //$NON-NLS-1$
    if (index == -1) {
        fNameMatcher= new PatternMatcher(text);
        fPackageMatcher= null;
    } else {
        fPackageMatcher= new PatternMatcher(evaluatePackagePattern(text.substring(0, index)));
        String name= text.substring(index + 1);
        if (name.length() == 0)
            name= "*"; //$NON-NLS-1$
        fNameMatcher= new PatternMatcher(name);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件: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    文件:NewTypeWizardPage.java   
/**
 * Opens a selection dialog that allows to select a super class.
 *
 * @return returns the selected type or <code>null</code> if the dialog has been canceled.
 * The caller typically sets the result to the super class input field.
 *  <p>
 * Clients can override this method if they want to offer a different dialog.
 * </p>
 *
 * @since 3.2
 */
protected IType chooseSuperClass() {
    IJavaProject project= getJavaProject();
    if (project == null) {
        return null;
    }

    IJavaElement[] elements= new IJavaElement[] { project };
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);

    FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false,
        getWizard().getContainer(), scope, IJavaSearchConstants.CLASS);
    dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title);
    dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message);
    dialog.setInitialPattern(getSuperClass());

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:GotoTypeAction.java   
@Override
public void run() {
    Shell shell= JavaPlugin.getActiveWorkbenchShell();
    SelectionDialog dialog= null;
    try {
        dialog= JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
            SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false);
    } catch (JavaModelException e) {
        String title= getDialogTitle();
        String message= PackagesMessages.GotoType_error_message;
        ExceptionHandler.handle(e, title, message);
        return;
    }

    dialog.setTitle(getDialogTitle());
    dialog.setMessage(PackagesMessages.GotoType_dialog_message);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return;
    }

    Object[] types= dialog.getResult();
    if (types != null && types.length > 0) {
        gotoType((IType) types[0]);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ExpandWithConstructorsConfigurationBlock.java   
/**
 * Creates the type hierarchy for type selection.
 */
private void doBrowseTypes() {
    IRunnableContext context= new BusyIndicatorRunnableContext();
    IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
    int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
    try {
        SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
        dialog.setTitle(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title);
        dialog.setMessage(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description);
        if (dialog.open() == Window.OK) {
            IType res= (IType)dialog.getResult()[0];
            fNameDialogField.setText(res.getFullyQualifiedName('.'));
        }
    } catch (JavaModelException e) {
        ExceptionHandler.handle(e, getShell(), CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title,
                CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:FocusOnTypeAction.java   
@Override
public void run() {
    Shell parent= fViewPart.getSite().getShell();
    FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(parent, false,
        PlatformUI.getWorkbench().getProgressService(),
        SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);

    dialog.setTitle(TypeHierarchyMessages.FocusOnTypeAction_dialog_title);
    dialog.setMessage(TypeHierarchyMessages.FocusOnTypeAction_dialog_message);
    if (dialog.open() != IDialogConstants.OK_ID) {
        return;
    }

    Object[] types= dialog.getResult();
    if (types != null && types.length > 0) {
        IType type= (IType)types[0];
        fViewPart.setInputElement(type);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NewTypeWizardPage.java   
/**
 * Opens a selection dialog that allows to select an enclosing type.
 *
 * @return returns the selected type or <code>null</code> if the dialog has been canceled.
 * The caller typically sets the result to the enclosing type input field.
 * <p>
 * Clients can override this method if they want to offer a different dialog.
 * </p>
 *
 * @since 3.2
 */
protected IType chooseEnclosingType() {
    IPackageFragmentRoot root= getPackageFragmentRoot();
    if (root == null) {
        return null;
    }

    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { root });

    FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(),
        false, getWizard().getContainer(), scope, IJavaSearchConstants.TYPE);
    dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChooseEnclosingTypeDialog_title);
    dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChooseEnclosingTypeDialog_description);
    dialog.setInitialPattern(Signature.getSimpleName(getEnclosingTypeText()));

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:GenerateToStringDialog.java   
private void browseForBuilderClass() {
    try {
        IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { getType().getJavaProject() });
        SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), PlatformUI.getWorkbench().getProgressService(), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false, "*ToString", fExtension); //$NON-NLS-1$
        dialog.setTitle(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_windowTitle);
        dialog.setMessage(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_message);
        dialog.open();
        if (dialog.getReturnCode() == OK) {
            IType type= (IType)dialog.getResult()[0];
            fBuilderClassName.setText(type.getFullyQualifiedParameterizedName());
            List<String> suggestions= fValidator.getAppendMethodSuggestions(type);
            if (!suggestions.contains(fAppendMethodName.getText()))
                fAppendMethodName.setText(suggestions.get(0));
            suggestions= fValidator.getResultMethodSuggestions(type);
            if (!suggestions.contains(fResultMethodName.getText()))
                fResultMethodName.setText(suggestions.get(0));
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
}