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


Java SearchEngine类代码示例

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


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

示例1: getITypeMainByWorkspaceScope

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:34,代码来源:PlainK3ExecutionEngine.java

示例2: findType

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
/**
 * 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];
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:30,代码来源:JDTDataAccess.java

示例3: performSearch

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
/**
 * 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;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:19,代码来源:WebXmlValidator.java

示例4: findAllDeclarations

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:RippleMethodFinder.java

示例5: getURI

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:ClassFileUtil.java

示例6: searchType

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:26,代码来源:JavaTypeMemberBookmarkLocationProvider.java

示例7: getMainTypes

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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[] {};

}
 
开发者ID:eclipse,项目名称:cft,代码行数:17,代码来源:JavaTypeResolver.java

示例8: search

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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;
}
 
开发者ID:abnervr,项目名称:VRaptorEclipsePlugin,代码行数:25,代码来源:SearchHelper.java

示例9: searchForOuterTypesOfReferences

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的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

示例10: searchForDeclarationsOfClashingMethods

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的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

示例11: TypeReference

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:MoveCuUpdateCreator.java

示例12: create

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:RefactoringScopeFactory.java

示例13: search

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:RefactoringSearchEngine.java

示例14: internalSearch

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的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

示例15: cleanUpIndexes

import org.eclipse.jdt.core.search.SearchEngine; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:IndexManager.java


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